Question about stat( "", &s )

Marc H. Kool marck at cwi.nl
Sat Feb 10 01:30:26 AEST 1990


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 at cwi.nl



More information about the Comp.unix.wizards mailing list