Home > Archive > Unix Programming > February 2006 > Symbolic link to non-existent file, legal?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Symbolic link to non-existent file, legal?
|
|
| ellips@yahoo.com 2006-02-16, 7:02 pm |
| Is it legal to make a symbolic link to a non existent file?
Under IRIX and Linux I've been able to do it but I wonder if
the behaviour is "legal".
Is the use defined in the OS or are we just lucky that it works
and it could break at any time?
The link to a non-existent file will later be passed as an output
for another program. The link gets followed and the actual file
is created. So it does work.
Just wondering if this is really portable?
Thanks.
| |
| Rainer Temme 2006-02-16, 7:02 pm |
| ellips@yahoo.com wrote:
> Is it legal to make a symbolic link to a non existent file?
Hi ellips,
let's see what the man-page of the underlying
system-call (symlink()) says ...
man 2 symlink ...
....
A symbolic link (also known as a soft link) may point to
an existing file or to a nonexistent one; the latter case is
known as a dangling link.
....
NOTES: No checking of oldpath is done.
....
.... Rainer
| |
| ellips@yahoo.com 2006-02-16, 7:02 pm |
|
Thanks. I was looking at the man page for ln and not finding much.
So, sounds like it is just fine.
| |
| Casper H.S. Dik 2006-02-16, 7:02 pm |
| ellips@yahoo.com writes:
> Is it legal to make a symbolic link to a non existent file?
> Under IRIX and Linux I've been able to do it but I wonder if
> the behaviour is "legal".
Considering the fact that error codes are defiend for looping links and
links pointing nowhere, I'd suggest yes.
> Is the use defined in the OS or are we just lucky that it works
> and it could break at any time?
It works and is used by some applications as a feature.
> The link to a non-existent file will later be passed as an output
> for another program. The link gets followed and the actual file
> is created. So it does work.
That works too, as long O_EXCL is not passed in the open() call.
Casper
--
Expressed in this posting are my opinions. They are in no way related
to opinions held by my employer, Sun Microsystems.
Statements on Sun products included here are not gospel and may
be fiction rather than truth.
| |
| Valentin Nechayev 2006-02-17, 3:58 am |
| Thu, Feb 16, 2006 at 06:55:54, ellips (ellips@yahoo.com) wrote about "Symbolic link to non-existent file, legal?":
> Is it legal to make a symbolic link to a non existent file?
> Under IRIX and Linux I've been able to do it but I wonder if
> the behaviour is "legal".
Yes, it can point to anything (ever not file). There is some
practice (but rare) to use symlink content as direct configuration
data, to avoid opening file for this. E.g. /etc/malloc.conf in
FreeBSD.
> The link to a non-existent file will later be passed as an output
> for another program. The link gets followed and the actual file
> is created. So it does work.
> Just wondering if this is really portable?
I can't find any objections :)
-netch-
|
|
|
|
|