marck@cwi.nl (Marc H. Kool) (02/09/90)
Is the empty file name an alias for "." ?
I have the following program:
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
main()
{
FILE * fp;
struct stat s;
fp = fopen( "", "r" );
if (fp == NULL)
printf( "can't read \"\"\n" );
else
fclose( fp );
fp = fopen( "", "w" );
if (fp == NULL)
printf( "can't write \"\"\n" );
else
fclose( fp );
if (stat( "", &s ) < 0)
perror( "stat" );
else {
printf( "mode %07o\n", s.st_mode );
printf( "uid %d gid %d size %d ino %d\n", s.st_uid,
s.st_gid, s.st_size, s.st_ino );
}
}
and the output is:
can't read ""
can't write ""
mode 0040700
uid 406 gid 136 size 512 ino 47440
If I type 'ls -lid .' it occurs that the above is the same as "."
Is this OK ?
Why does fopen( "", "r" ) fails and fopen( ".", "r" ) not ?
-Marc
--
------------
Marc H. Kool, marck@cwi.nllm@snafu.Sun.COM (Larry McVoy) (02/10/90)
In article <8788@boring.cwi.nl> marck@cwi.nl (Marc H. Kool) writes: > >Is the empty file name an alias for "." ? On some systems (BSD based) it is. Don't count on it, though - this shortcut is forbidden in a POSIX conformant environment. --- What I say is my opinion. I am not paid to speak for Sun, I'm paid to hack. Besides, I frequently read news when I'm drjhgunghc, err, um, drunk. Larry McVoy, Sun Microsystems (415) 336-7627 ...!sun!lm or lm@sun.com
gwyn@smoke.BRL.MIL (Doug Gwyn) (02/10/90)
In article <8788@boring.cwi.nl> marck@cwi.nl (Marc H. Kool) writes: >Is the empty file name an alias for "." ? In some implementations it is, and in some it is not. Don't count on "" being accepted as a valid file name.