=================================================================== RCS file: /cvs/djgpp/djgpp/tests/libc/posix/unistd/append.c,v retrieving revision 1.2 retrieving revision 1.3 diff -p -u -r1.2 -r1.3 --- djgpp/tests/libc/posix/unistd/append.c 2002/05/26 16:10:20 1.2 +++ /cvs/djgpp/djgpp/tests/libc/posix/unistd/append.c 2002/06/08 11:04:42 1.3 @@ -3,12 +3,24 @@ #include #include #include +#include +#include #define FILE_NAME "append.dat" char str[] = "hello, there\n"; +static void +die (const char *progname, const int line) +{ + char buf[PATH_MAX + 1 + 4 + 1]; /* progname + colon + up to 4 digits + nul */ + + snprintf(buf, sizeof(buf), "%s:%d", progname, line); + perror(buf); + exit(EXIT_FAILURE); +} + int -main(void) +main (int argc, char *argv[]) { char in = 0; int fd; @@ -16,14 +28,20 @@ main(void) struct stat s; size_t len; - fd = open( FILE_NAME, O_WRONLY|O_CREAT|O_TRUNC ); - write( fd, str, strlen(str) ); + fd = open( FILE_NAME, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR ); + if (fd < 0) + die(argv[0], __LINE__); + if ( write( fd, str, strlen(str) ) < 0 ) + die(argv[0], __LINE__); close( fd ); stat( FILE_NAME, &s ); len = s.st_size; fd = open( FILE_NAME, O_APPEND|O_WRONLY); - write( fd, str, strlen(str) ); + if (fd < 0) + die(argv[0], __LINE__); + if ( write( fd, str, strlen(str) ) < 0 ) + die(argv[0], __LINE__); close( fd ); stat( FILE_NAME, &s ); if (s.st_size != len * 2) @@ -33,6 +51,8 @@ main(void) } fd = open( FILE_NAME, O_APPEND|O_RDWR ); + if (fd < 0) + die(argv[0], __LINE__); lseek( fd, 1, SEEK_SET ); read( fd, &in, 1 ); if( in != str[1] ) @@ -40,7 +60,8 @@ main(void) printf( "Wrong character found: '%c', expected '%c'!\n", in, str[1] ); status++; } - write( fd, str, strlen(str) ); + if ( write( fd, str, strlen(str) ) < 0 ) + die(argv[0], __LINE__); close( fd ); stat( FILE_NAME, &s ); if( s.st_size != len * 3 )