4.104.114.84.95
Last change
on this file since cd3fb80 was
0895bdb,
checked in by Joel Sherrill <joel.sherrill@…>, on 11/23/98 at 18:57:48
|
Added tests in support of the file system infrastructure.
|
-
Property mode set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[0895bdb] | 1 | /* |
---|
| 2 | * A test support function which performs a write() and |
---|
| 3 | * handles implied open(), lseek(), write(), and close() operations. |
---|
| 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 | |
---|
| 17 | #include <assert.h> |
---|
| 18 | |
---|
| 19 | /* |
---|
| 20 | * test_write routine |
---|
| 21 | */ |
---|
| 22 | |
---|
| 23 | void test_write( |
---|
| 24 | char *file, |
---|
| 25 | off_t offset, |
---|
| 26 | char *buffer |
---|
| 27 | ) |
---|
| 28 | { |
---|
| 29 | int fd; |
---|
| 30 | int status; |
---|
| 31 | int length; |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | length = strlen( buffer ); |
---|
| 35 | |
---|
| 36 | fd = open( file, O_WRONLY ); |
---|
| 37 | if ( fd == -1 ) { |
---|
| 38 | printf( "test_write: open( %s ) failed : %s\n", file, strerror( errno ) ); |
---|
| 39 | exit( 0 ); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | status = lseek( fd, offset, SEEK_SET ); |
---|
| 43 | assert( !status ); |
---|
| 44 | |
---|
| 45 | status = write( fd, buffer, length ); |
---|
| 46 | if ( status == -1 ) { |
---|
| 47 | printf( "test_write: write( %s ) failed : %s\n", file, strerror( errno ) ); |
---|
| 48 | exit( 0 ); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | if ( status != length ) { |
---|
| 52 | printf( "test_write: write( %s ) only wrote %d of %d bytes\n", |
---|
| 53 | file, status, length ); |
---|
| 54 | exit( 0 ); |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | status = close( fd ); |
---|
| 58 | assert( !status ); |
---|
| 59 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.