source: rtems/c/src/tests/psxtests/psxchroot01/test.c @ bd2fab3f

Last change on this file since bd2fab3f was bd2fab3f, checked in by Joel Sherrill <joel.sherrill@…>, on 05/29/03 at 19:08:53

2003-05-29 Joel Sherrill <joel@…>

  • psx02/init.c, psx04/init.c, psx13/test.c, psxchroot01/test.c, psxhdrs/pthread07.c, psxmsgq01/init.c, psxreaddir/test.c, psxtimer/psxtimer.c: Removed warnings.
  • Property mode set to 100644
File size: 2.5 KB
Line 
1/*
2 *  This is a native test to explore how the readdir() family works.
3 *  Newlib supports the following readdir() family members:
4 *
5 *    closedir()   -
6 *    readdir()    -
7 *    scandir()    -
8 *    opendir()    -
9 *    rewinddir()  -
10 *    telldir()    - BSD not in POSIX
11 *    seekdir()    - BSD not in POSIX
12 *
13 *
14 *  seekdir() takes an offset which is a byte offset.  The Linux
15 *  implementation of this appears to seek to the ((off/DIRENT_SIZE) + 1)
16 *  record where DIRENT_SIZE seems to be 12 bytes.
17 *
18 *
19 *
20 *  $Id$
21 */
22
23#include <stdio.h>
24#include <sys/types.h>
25#include <fcntl.h>
26#include <string.h>
27#include <assert.h>
28#include <unistd.h>
29#include <errno.h>
30#include <rtems/libio.h>
31#include <pmacros.h>
32
33void touch( char *file )
34{
35  int fd;
36
37  assert( file );
38
39  fd = open( file, O_RDWR|O_CREAT, 0777 );
40  assert( fd != -1 );
41  close( fd );
42}
43
44int fileexists( char *file )
45{
46  int         status;
47  struct stat statbuf;
48
49  assert( file );
50
51  status = stat( file, &statbuf );
52
53  if ( status == -1 ) {
54    /* printf( ": %s\n", strerror( errno ) ); */
55    return 0;
56  }
57  return 1;
58}
59
60#if defined(__rtems__)
61int test_main(void)
62#else
63int main(
64  int argc,
65  char **argv
66)
67#endif
68{
69  int status;
70
71/*
72 *  This test is the C equivalent of this sequence.
73#mkdir /one
74#mkdir /one/one
75#touch /one/one.test
76#touch /one/two/two.test
77#chroot /one
78#if !fileexists(/one/one.test) echo "SUCCESSFUL"
79#if fileexists(/two/two.test) echo "SUCCESSFUL"
80#rtems_set_private_env() ! reset at the global environment
81#if fileexists(/one/one.test) echo "SUCESSFUL"
82#if !fileexists(/two/two.test) echo "SUCCESSFUL"
83*/
84
85  printf( "\n\n*** CHROOT01 TEST ***\n" );
86
87  status = mkdir( "/one", 0777);
88  assert( status == 0 );
89
90  status = mkdir( "/one/one", 0777);
91  assert( status == 0 );
92
93  status = mkdir( "/one/two", 0777);
94  assert( status == 0 );
95
96  touch( "/one/one.test" );
97  touch( "/one/two/two.test" );
98 
99  status = chroot( "/one" );
100  assert( status == 0 );
101
102  status = fileexists( "/one/one.test" );
103  printf( "%s on /one/one.test\n", (!status) ? "SUCCESS" : "FAILURE" );
104   
105  status = fileexists( "/two/two.test" );
106  printf( "%s on /two/two.test\n", (status) ? "SUCCESS" : "FAILURE" );
107
108  puts( "Reset the private environment" );
109  rtems_libio_set_private_env();
110   
111  status = fileexists( "/one/one.test" );
112  printf( "%s on /one/one.test\n", ( status) ? "SUCCESS" : "FAILURE" );
113
114  status = fileexists( "/two/two.test" );
115  printf( "%s on /two/two.test\n", (!status) ? "SUCCESS" : "FAILURE" );
116
117  printf( "*** END OF CHROOT01 TEST ***\n" );
118  rtems_test_exit(0);
119}
120
Note: See TracBrowser for help on using the repository browser.