fopen question

R

root

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
 
A

Antoninus Twink

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.
 
K

Keith Thompson

root said:
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>
 
S

Seebs

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
 
K

Keith Thompson

William Ahern said:
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.
 
S

Seebs

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.

-s
 
K

Kaz Kylheku

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.

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

(e-mail address removed)

?

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.
 
K

Keith Thompson

Kaz Kylheku said:
Right, since when do Windows users commonly post under the name

(e-mail address removed)

?

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

fopen 20
fopen 17
Problem with fopen 13
HELP:function at c returning (null) 4
Working with files 1
PHP failed to create file 13
fopen problem 10
fopen() questions 17

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top