Ticket #1516: stat_test.c

File stat_test.c, 838 bytes (added by mjw, 13 years ago)
Line 
1#include <stdio.h>
2#include <unistd.h>
3#include <sys/stat.h>
4
5/* A test case to test whether stat( "", &statbuf ) and access( "", F_OK )
6 * return -1 with errno set to ENOENT. If the program runs sucessfully,
7 * you should never see a "test failed" error message. */
8
9int
10main( int argc, char *argv[] )
11{
12 struct stat statbuf;
13 int r;
14
15 r = stat( "", &statbuf );
16 printf( "r=%d\n", r );
17 if( r != -1 )
18 {
19 printf( "stat(\"\", &statbuf) test failed\n" );
20 }
21
22 r = access( "", F_OK );
23 printf( "r=%d\n", r );
24 if( r != -1 )
25 {
26 printf( "access(\"\", F_OK) test failed\n" );
27 }
28
29 r = stat( NULL, &statbuf );
30 printf( "r=%d\n", r );
31 if( r != -1 )
32 {
33 printf( "stat(NULL, &statbuf) test failed\n" );
34 }
35
36 r = access( NULL, F_OK );
37 printf( "r=%d\n", r );
38 if( r != -1 )
39 {
40 printf( "access(NULL, F_OK) test failed\n" );
41 }
42
43 return 0;
44}