Mail Archives: djgpp-workers/2002/06/02/08:32:54
Hello.
> Richard Dawe wrote:
>
> > I've just found that tests/libc/posix/unistd/append.c fails. I don't
> > believe this is down to my gcc 3.1-related changes, since it happens
> > with a check-out of DJGPP CVS without the gcc 3.1 changes.
> >
> > bash-2.04$ ./append.exe
> > wrong size 1!
> > Wrong character found: ' ', expected 'e'!
> > wrong size 2!
It turns out that some of the open calls were failing. This is because
the first call does not open the file with a mode argument. After changing
that to use S_IRUSR|S_IWUSR, it works. There's a diff below, which
also also adds more paranoia on open(), write(). OK to commit?
Bye, Rich =]
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
Index: tests/libc/posix/unistd/append.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/posix/unistd/append.c,v
retrieving revision 1.2
diff -p -u -3 -r1.2 append.c
--- tests/libc/posix/unistd/append.c 2002/05/26 16:10:20 1.2
+++ tests/libc/posix/unistd/append.c 2002/06/02 12:04:31
@@ -3,12 +3,24 @@
#include <unistd.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
#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 )
- Raw text -