4.104.114.84.95
Last change
on this file since 1ed9d57 was
2ada69a,
checked in by Jennifer Averett <Jennifer.Averett@…>, on 03/29/99 at 17:59:46
|
Changed expected status lseek to look for not failure (-1).
|
-
Property mode set to
100644
|
File size:
1.6 KB
|
Rev | Line | |
---|
[0895bdb] | 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 | /* |
---|
| 21 | * test_cat routine |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | unsigned char test_cat_buffer[ 1024 ]; |
---|
| 25 | |
---|
| 26 | void test_cat( |
---|
| 27 | char *file, |
---|
| 28 | int offset_arg, |
---|
| 29 | int length |
---|
| 30 | ) |
---|
| 31 | { |
---|
| 32 | int fd; |
---|
| 33 | int status; |
---|
| 34 | int is_printable = 0; |
---|
| 35 | int my_length; |
---|
| 36 | int i; |
---|
| 37 | unsigned char c; |
---|
| 38 | int count = 0; |
---|
| 39 | off_t offset = (off_t)offset_arg; |
---|
| 40 | |
---|
| 41 | my_length = (length) ? length : sizeof( test_cat_buffer ); |
---|
| 42 | assert( my_length <= sizeof( test_cat_buffer ) ); |
---|
| 43 | |
---|
| 44 | fd = open( file, O_RDONLY ); |
---|
| 45 | if ( fd == -1 ) { |
---|
| 46 | printf( "test_cat: open( %s ) failed : %s\n", file, strerror( errno ) ); |
---|
| 47 | exit( 0 ); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | for ( ;; ) { |
---|
| 51 | status = lseek( fd, offset, SEEK_SET ); |
---|
[2ada69a] | 52 | assert( status != -1 ); |
---|
[0895bdb] | 53 | |
---|
| 54 | status = read( fd, test_cat_buffer, sizeof(test_cat_buffer) ); |
---|
| 55 | if ( status <= 0 ) { |
---|
| 56 | if (!is_printable) |
---|
| 57 | printf( "(%d)", count ); |
---|
| 58 | puts( "" ); |
---|
| 59 | break; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | for ( i=0 ; i<status ; i++ ) { |
---|
| 63 | c = test_cat_buffer[i]; |
---|
| 64 | if (isprint(c) || isspace(c)) { |
---|
| 65 | if (!is_printable) { |
---|
| 66 | printf( "(%d)", count ); |
---|
| 67 | count = 0; |
---|
| 68 | is_printable = 1; |
---|
| 69 | } |
---|
| 70 | putchar(c); |
---|
| 71 | } else { |
---|
| 72 | is_printable = 0; |
---|
| 73 | count++; |
---|
| 74 | } |
---|
| 75 | } |
---|
| 76 | offset += status; |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | status = close( fd ); |
---|
| 80 | assert( !status ); |
---|
| 81 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.