diff options
author | Joel Sherrill <joel.sherrill@OARcorp.com> | 1998-11-23 18:57:48 +0000 |
---|---|---|
committer | Joel Sherrill <joel.sherrill@OARcorp.com> | 1998-11-23 18:57:48 +0000 |
commit | 0895bdb89c1674d01ecb9886a0624096ef939ad1 (patch) | |
tree | 4bcea896c4f2ef42c786490c685bef6941be19c8 /c/src/tests/psxtests/filesupp/test_write.c | |
parent | Removed. (diff) | |
download | rtems-0895bdb89c1674d01ecb9886a0624096ef939ad1.tar.bz2 |
Added tests in support of the file system infrastructure.
Diffstat (limited to '')
-rw-r--r-- | c/src/tests/psxtests/filesupp/test_write.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/c/src/tests/psxtests/filesupp/test_write.c b/c/src/tests/psxtests/filesupp/test_write.c new file mode 100644 index 0000000000..d6acd00f85 --- /dev/null +++ b/c/src/tests/psxtests/filesupp/test_write.c @@ -0,0 +1,59 @@ +/* + * A test support function which performs a write() and + * handles implied open(), lseek(), write(), and close() operations. + * + * $Id$ + */ + +#include <stdio.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <string.h> + +#include <assert.h> + +/* + * test_write routine + */ + +void test_write( + char *file, + off_t offset, + char *buffer +) +{ + int fd; + int status; + int length; + + + length = strlen( buffer ); + + fd = open( file, O_WRONLY ); + if ( fd == -1 ) { + printf( "test_write: open( %s ) failed : %s\n", file, strerror( errno ) ); + exit( 0 ); + } + + status = lseek( fd, offset, SEEK_SET ); + assert( !status ); + + status = write( fd, buffer, length ); + if ( status == -1 ) { + printf( "test_write: write( %s ) failed : %s\n", file, strerror( errno ) ); + exit( 0 ); + } + + if ( status != length ) { + printf( "test_write: write( %s ) only wrote %d of %d bytes\n", + file, status, length ); + exit( 0 ); + } + + status = close( fd ); + assert( !status ); +} |