source: rtems/testsuites/psxtests/psxfile01/test_cat.c @ 1ace275

4.104.114.84.95
Last change on this file since 1ace275 was d802489, checked in by Joel Sherrill <joel.sherrill@…>, on 08/02/02 at 00:53:21

2002-08-01 Joel Sherrill <joel@…>

  • Per PR47 add support for buffered test output. This involved adding defines to redirect output to a buffer and dump it when full, at "test pause", and at exit. To avoid problems when redefining exit(), all tests were modified to call rtems_test_exit(). Some tests, notable psxtests, had to be modified to include the standard test macro .h file (pmacros.h or tmacros.h) to enable this support.
  • include/pmacros.h, psx01/task.c, psx02/init.c, psx02/task.c, psx03/init.c, psx04/init.c, psx05/init.c, psx06/init.c, psx07/init.c, psx08/task3.c, psx09/init.c, psx10/init.c, psx11/init.c, psx12/init.c, psx13/Makefile.am, psx13/main.c, psx13/test.c, psxcancel/init.c, psxchroot01/Makefile.am, psxchroot01/main.c, psxchroot01/test.c, psxfile01/Makefile.am, psxfile01/main.c, psxfile01/test.c, psxfile01/test_cat.c, psxfile01/test_extend.c, psxfile01/test_write.c, psxmount/Makefile.am, psxmount/main.c, psxmount/test.c, psxmsgq01/init.c, psxreaddir/Makefile.am, psxreaddir/main.c, psxreaddir/test.c, psxsem01/init.c, psxstat/Makefile.am, psxstat/main.c, psxstat/test.c, psxtime/main.c, psxtime/test.c, psxtimer/psxtimer.c: Modified.
  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 *  A test support function which performs a crude version of
3 *  "cat" so you can look at specific parts of a file.
4 *
5 *  $Id$
6 */
7
8#include <stdio.h>
9
10#include <sys/types.h>
11#include <sys/stat.h>
12#include <fcntl.h>
13#include <unistd.h>
14#include <errno.h>
15#include <string.h>
16#include <ctype.h>
17
18#include <assert.h>
19
20#include <pmacros.h>
21
22/*
23 *  test_cat routine
24 */
25
26unsigned char test_cat_buffer[ 1024 ];
27
28void test_cat(
29  char *file,
30  int   offset_arg,
31  int   length
32)
33{
34  int            fd;
35  int            status;
36  int            is_printable = 0;
37  int            my_length;
38  int            i;
39  unsigned char  c;
40  int            count = 0;
41  off_t          offset = (off_t)offset_arg;
42
43  my_length = (length) ? length : sizeof( test_cat_buffer );
44  assert( my_length <= sizeof( test_cat_buffer ) );
45
46  fd = open( file, O_RDONLY );
47  if ( fd == -1 ) {
48    printf( "test_cat: open( %s ) failed : %s\n", file, strerror( errno ) );
49    rtems_test_exit( 0 );
50  }
51
52  for ( ;; ) {
53    status = lseek( fd, offset, SEEK_SET );
54    assert( status != -1 );
55
56    status = read( fd, test_cat_buffer, sizeof(test_cat_buffer) );
57    if ( status <= 0 ) {
58      if (!is_printable)
59        printf( "(%d)", count );
60      puts( "" );
61      break;
62    }
63
64    for ( i=0 ; i<status ; i++ ) {
65      c = test_cat_buffer[i];
66      if (isprint(c) || isspace(c)) {
67        if (!is_printable) {
68          printf( "(%d)", count );
69          count = 0;
70          is_printable = 1;
71        }
72        putchar(c);
73      } else {
74        is_printable = 0;
75        count++;
76      }
77    }
78    offset += status;
79  }
80
81  status = close( fd );
82  assert( !status );
83}
Note: See TracBrowser for help on using the repository browser.