Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

fopen question

0 views
Skip to first unread message

root

unread,
Dec 16, 2009, 1:41:19 PM12/16/09
to
Hi when I use fopen on a sym bolic link, it will follow the link and open
thae target file. Most times this is what I want, but my question is: how
to get fopen to open the link itself (= file containing path to be
followed), what is the option I need.

Thanks.

/root


--
Learn more or lose your rights!
http://www.guncontrolkills.com/
http://www.gunbanobama.com/
Learn more or lose your rights!

Antoninus Twink

unread,
Dec 16, 2009, 1:52:05 PM12/16/09
to
On 16 Dec 2009 at 18:41, root wrote:
> how to get fopen to open the link itself (= file containing path to be
> followed), what is the option I need.

Don't use fopen - use readlink(2) instead.

If the file you give readlink isn't a symbolic link, it will return -1
and set errno to EINVAL, so that lets you tell whether or not a file is
a symlink.

Keith Thompson

unread,
Dec 16, 2009, 3:29:51 PM12/16/09
to
root <ro...@localhost.localdomain> writes:
> Hi when I use fopen on a sym bolic link, it will follow the link and open
> thae target file. Most times this is what I want, but my question is: how
> to get fopen to open the link itself (= file containing path to be
> followed), what is the option I need.

The C language has nothing to say about this; C is implemented on
plenty of systems that don't have symbolic links. I'm sure the nice
folks in comp.unix.programmer will be happy to answer your question.

<OT>Hint: readlink</OT>

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Richard

unread,
Dec 16, 2009, 3:57:08 PM12/16/09
to
Keith Thompson <ks...@mib.org> writes:

> root <ro...@localhost.localdomain> writes:
>> Hi when I use fopen on a sym bolic link, it will follow the link and open
>> thae target file. Most times this is what I want, but my question is: how
>> to get fopen to open the link itself (= file containing path to be
>> followed), what is the option I need.
>
> The C language has nothing to say about this; C is implemented on
> plenty of systems that don't have symbolic links. I'm sure the nice
> folks in comp.unix.programmer will be happy to answer your question.
>
> <OT>Hint: readlink</OT>

readlink is a C function. What do you mean it has nothing to do with
C? How ludicrous.

,----
| #include <unistd.h>
|
| ssize_t readlink(const char *path, char *buf, size_t
| bufsiz);
`----

Yup. Looks like C to me.

--
"Avoid hyperbole at all costs, its the most destructive argument on
the planet" - Mark McIntyre in comp.lang.c

Seebs

unread,
Dec 16, 2009, 4:59:43 PM12/16/09
to
On 2009-12-16, root <ro...@localhost.localdomain> wrote:
> Hi when I use fopen on a sym bolic link, it will follow the link and open
> thae target file. Most times this is what I want, but my question is: how
> to get fopen to open the link itself (= file containing path to be
> followed), what is the option I need.

You don't. If you asked in a Unix programming group, you might even get
an answer as to the question you should have asked. :)

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / usenet...@seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!

Richard

unread,
Dec 16, 2009, 5:19:39 PM12/16/09
to
Seebs <usenet...@seebs.net> writes:

> On 2009-12-16, root <ro...@localhost.localdomain> wrote:
>> Hi when I use fopen on a sym bolic link, it will follow the link and open
>> thae target file. Most times this is what I want, but my question is: how
>> to get fopen to open the link itself (= file containing path to be
>> followed), what is the option I need.
>
> You don't. If you asked in a Unix programming group, you might even get
> an answer as to the question you should have asked. :)
>
> -s

Had you not been such a killfile happy know all, you would have seen
that the OP already got a perfectly good reply. The question also raises
its head : how did you not see Keith's reply which said the same as you
(surprise) AND included the correct function reference. and don't come
the old "usenet delay" bullshit - it's not 1986 .... You just wanted to
see your name in lights net nannying once more.

William Ahern

unread,
Dec 16, 2009, 9:59:12 PM12/16/09
to
Richard <rgr...@gmail.com> wrote:
> Seebs <usenet...@seebs.net> writes:

> > On 2009-12-16, root <ro...@localhost.localdomain> wrote:
> >> Hi when I use fopen on a sym bolic link, it will follow the link and open
> >> thae target file. Most times this is what I want, but my question is: how
> >> to get fopen to open the link itself (= file containing path to be
> >> followed), what is the option I need.
> >
> > You don't. If you asked in a Unix programming group, you might even get
> > an answer as to the question you should have asked. :)
> >
> > -s

> Had you not been such a killfile happy know all, you would have seen
> that the OP already got a perfectly good reply.

Why do you assume that readlink is the better answer over the CopyFileEx,
CreateFile, FindFirstFile family of functions? Unix isn't the only platform
that has symbolic links.

Keith Thompson

unread,
Dec 16, 2009, 10:07:01 PM12/16/09
to
William Ahern <wil...@wilbur.25thandClement.com> writes:
> Richard <rgr...@gmail.com> wrote:
>> Seebs <usenet...@seebs.net> writes:
>> > On 2009-12-16, root <ro...@localhost.localdomain> wrote:
>> >> Hi when I use fopen on a sym bolic link, it will follow the link and open
>> >> thae target file. Most times this is what I want, but my question is: how
>> >> to get fopen to open the link itself (= file containing path to be
>> >> followed), what is the option I need.
>> >
>> > You don't. If you asked in a Unix programming group, you might even get
>> > an answer as to the question you should have asked. :)
>
>> Had you not been such a killfile happy know all, you would have seen
>> that the OP already got a perfectly good reply.
>
> Why do you assume that readlink is the better answer over the CopyFileEx,
> CreateFile, FindFirstFile family of functions? Unix isn't the only platform
> that has symbolic links.

Since I'm the person who gave the readlink hint, yes, I did assume
that the OP was using a Unix-like platform. I assumed (incorrectly,
apparently) that only Unix-like systems have symbolic links.

To the OP: If you're not using a Unix-like system (such as Linux),
ask in a newsgroup that deals with your OS. If it's MS Windows,
try comp.os.ms-windows.programmer.win32.

Seebs

unread,
Dec 16, 2009, 10:13:13 PM12/16/09
to
On 2009-12-17, Keith Thompson <ks...@mib.org> wrote:
> Since I'm the person who gave the readlink hint, yes, I did assume
> that the OP was using a Unix-like platform. I assumed (incorrectly,
> apparently) that only Unix-like systems have symbolic links.

It gets complicated. :)

There is a great deal of magic to deal with in trying to deal with links,
and if the OP wanted to, say, open the file so as to write to it, then
readlink isn't very helpful.

It is, it turns out, complicated.

Kaz Kylheku

unread,
Dec 16, 2009, 10:27:22 PM12/16/09
to

Right, since when do Windows users commonly post under the name

ro...@localhost.localdomain

?

Whether or not you can use readlink on Windows depends on which SDK you
install. Windows doesn't come with a toolchain, so you get to teach
Windows what symlink API it should speak. If you install Cygwin, you can
use readlink.

Keith Thompson

unread,
Dec 16, 2009, 11:04:05 PM12/16/09
to
Kaz Kylheku <kkyl...@gmail.com> writes:
[...]

> Right, since when do Windows users commonly post under the name
>
> ro...@localhost.localdomain
>
> ?

What's so odd about that? I use both Windows and Linux myself.

0 new messages