OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [psxtests/] [psxchroot01/] [test.c] - Blame information for rev 1779

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  test.c,v 1.3 2002/08/02 00:53:21 joel Exp
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
 
33
void 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
 
44
int 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__)
61
int test_main(void)
62
#else
63
int main(
64
  int argc,
65
  char **argv
66
)
67
#endif
68
{
69
  int fd;
70
  int i;
71
  int status;
72
  struct stat s;
73
 
74
/*
75
 *  This test is the C equivalent of this sequence.
76
#mkdir /one
77
#mkdir /one/one
78
#touch /one/one.test
79
#touch /one/two/two.test
80
#chroot /one
81
#if !fileexists(/one/one.test) echo "SUCCESSFUL"
82
#if fileexists(/two/two.test) echo "SUCCESSFUL"
83
#rtems_set_private_env() ! reset at the global environment
84
#if fileexists(/one/one.test) echo "SUCESSFUL"
85
#if !fileexists(/two/two.test) echo "SUCCESSFUL"
86
*/
87
 
88
  printf( "\n\n*** CHROOT01 TEST ***\n" );
89
 
90
  status = mkdir( "/one", 0777);
91
  assert( status == 0 );
92
 
93
  status = mkdir( "/one/one", 0777);
94
  assert( status == 0 );
95
 
96
  status = mkdir( "/one/two", 0777);
97
  assert( status == 0 );
98
 
99
  touch( "/one/one.test" );
100
  touch( "/one/two/two.test" );
101
 
102
  status = chroot( "/one" );
103
  assert( status == 0 );
104
 
105
  status = fileexists( "/one/one.test" );
106
  printf( "%s on /one/one.test\n", (!status) ? "SUCCESS" : "FAILURE" );
107
 
108
  status = fileexists( "/two/two.test" );
109
  printf( "%s on /two/two.test\n", (status) ? "SUCCESS" : "FAILURE" );
110
 
111
  puts( "Reset the private environment" );
112
  rtems_libio_set_private_env();
113
 
114
  status = fileexists( "/one/one.test" );
115
  printf( "%s on /one/one.test\n", ( status) ? "SUCCESS" : "FAILURE" );
116
 
117
  status = fileexists( "/two/two.test" );
118
  printf( "%s on /two/two.test\n", (!status) ? "SUCCESS" : "FAILURE" );
119
 
120
  printf( "*** END OF CHROOT01 TEST ***\n" );
121
  rtems_test_exit(0);
122
}
123
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.