source: rtems/testsuites/psxtests/psxchroot01/test.c @ a978589

4.104.114.84.95
Last change on this file since a978589 was a978589, checked in by Joel Sherrill <joel.sherrill@…>, on 06/12/03 at 15:41:19

2003-06-12 Joel Sherrill <joel@…>

  • psxchroot01/test.c, psxreaddir/test.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 <rtems/userenv.h>
32#include <pmacros.h>
33
34void touch( char *file )
35{
36  int fd;
37
38  assert( file );
39
40  fd = open( file, O_RDWR|O_CREAT, 0777 );
41  assert( fd != -1 );
42  close( fd );
43}
44
45int fileexists( char *file )
46{
47  int         status;
48  struct stat statbuf;
49
50  assert( file );
51
52  status = stat( file, &statbuf );
53
54  if ( status == -1 ) {
55    /* printf( ": %s\n", strerror( errno ) ); */
56    return 0;
57  }
58  return 1;
59}
60
61#if defined(__rtems__)
62int test_main(void)
63#else
64int main(
65  int argc,
66  char **argv
67)
68#endif
69{
70  int status;
71
72/*
73 *  This test is the C equivalent of this sequence.
74#mkdir /one
75#mkdir /one/one
76#touch /one/one.test
77#touch /one/two/two.test
78#chroot /one
79#if !fileexists(/one/one.test) echo "SUCCESSFUL"
80#if fileexists(/two/two.test) echo "SUCCESSFUL"
81#rtems_set_private_env() ! reset at the global environment
82#if fileexists(/one/one.test) echo "SUCESSFUL"
83#if !fileexists(/two/two.test) echo "SUCCESSFUL"
84*/
85
86  printf( "\n\n*** CHROOT01 TEST ***\n" );
87
88  status = mkdir( "/one", 0777);
89  assert( status == 0 );
90
91  status = mkdir( "/one/one", 0777);
92  assert( status == 0 );
93
94  status = mkdir( "/one/two", 0777);
95  assert( status == 0 );
96
97  touch( "/one/one.test" );
98  touch( "/one/two/two.test" );
99 
100  status = chroot( "/one" );
101  assert( status == 0 );
102
103  status = fileexists( "/one/one.test" );
104  printf( "%s on /one/one.test\n", (!status) ? "SUCCESS" : "FAILURE" );
105   
106  status = fileexists( "/two/two.test" );
107  printf( "%s on /two/two.test\n", (status) ? "SUCCESS" : "FAILURE" );
108
109  puts( "Reset the private environment" );
110  rtems_libio_set_private_env();
111   
112  status = fileexists( "/one/one.test" );
113  printf( "%s on /one/one.test\n", ( status) ? "SUCCESS" : "FAILURE" );
114
115  status = fileexists( "/two/two.test" );
116  printf( "%s on /two/two.test\n", (!status) ? "SUCCESS" : "FAILURE" );
117
118  printf( "*** END OF CHROOT01 TEST ***\n" );
119  rtems_test_exit(0);
120}
121
Note: See TracBrowser for help on using the repository browser.