I feel stupid -- determine the full path to a file

Shane Hathaway shane at hathawaymix.org
Thu Dec 6 13:46:23 MST 2007


Dave Smith wrote:
> int main( int argc, char **argv )
> {
>     if( argc != 2 )
>     {
>         printf( "Usage: %s <path>\n", argv[0] );
>         return 1;
>     }
> 
>     char output[PATH_MAX];
>     realpath( argv[1], output );
>     printf( "%s\n", output );
> 
>     return 0;
> }

Didn't your mother teach you to check error codes?  Your hard drive
might spontaneously combust during the realpath() call, yet this program
will happily print garbage and say it was miraculously successful anyway.

Shane



More information about the PLUG mailing list