Browse Source

So much for fcntl flags being resonably consistent across archs... (hopefully)
fix O_APPEND and O_LARGEFILE handling in _stdio_fopen(). Someone else will
have to check of course...

Manuel Novoa III 23 years ago
parent
commit
b6d85765b0
1 changed files with 14 additions and 10 deletions
  1. 14 10
      libc/stdio/stdio.c

+ 14 - 10
libc/stdio/stdio.c

@@ -2071,7 +2071,7 @@ FILE *fopen(const char * __restrict filename, const char * __restrict mode)
  *  fopen64  : filename != NULL, stream == NULL, filedes == -2
  *  fopen64  : filename != NULL, stream == NULL, filedes == -2
  */
  */
 
 
-#if O_ACCMODE != 3 || O_RDONLY != 0 || O_WRONLY != 1 || O_RDWR != 2 || O_APPEND != __FLAG_APPEND || O_LARGEFILE != __FLAG_LARGEFILE
+#if O_ACCMODE != 3 || O_RDONLY != 0 || O_WRONLY != 1 || O_RDWR != 2
 #error Assumption violated - mode constants
 #error Assumption violated - mode constants
 #endif
 #endif
 
 
@@ -2189,12 +2189,21 @@ FILE *_stdio_fopen(const char * __restrict filename,
 		return NULL;
 		return NULL;
 	}
 	}
 
 
+	stream->modeflags |=
 #ifdef __STDIO_BUFFERS
 #ifdef __STDIO_BUFFERS
-	stream->modeflags |= (isatty(stream->filedes) * __FLAG_LBF)
+		(isatty(stream->filedes) * __FLAG_LBF) |
-		| ((((open_mode & O_ACCMODE) + 1) ^ 0x03) * __FLAG_WRITEONLY)
+#endif /* __STDIO_BUFFERS */
-		| (open_mode & (O_APPEND|O_LARGEFILE));
+#if (O_APPEND == __FLAG_APPEND) && (O_LARGEFILE == __FLAG_LARGEFILE)
-
+		(open_mode & (O_APPEND|O_LARGEFILE)) | /* i386 linux and elks */
+#else  /* (O_APPEND == __FLAG_APPEND) && (O_LARGEFILE == __FLAG_LARGEFILE) */
+		((open_mode & O_APPEND) ? __FLAG_APPEND : 0) |
+#ifdef __STDIO_LARGE_FILES
+		((open_mode & O_LARGEFILE) ? __FLAG_LARGEFILE : 0) |
+#endif /* __STDIO_LARGE_FILES */
+#endif /* (O_APPEND == __FLAG_APPEND) && (O_LARGEFILE == __FLAG_LARGEFILE) */
+		((((open_mode & O_ACCMODE) + 1) ^ 0x03) * __FLAG_WRITEONLY);
 
 
+#ifdef __STDIO_BUFFERS
 #ifdef __STDIO_GETC_MACRO
 #ifdef __STDIO_GETC_MACRO
 	stream->bufgetc =
 	stream->bufgetc =
 #endif
 #endif
@@ -2202,11 +2211,6 @@ FILE *_stdio_fopen(const char * __restrict filename,
 	stream->bufputc =
 	stream->bufputc =
 #endif
 #endif
 	stream->bufwpos = stream->bufrpos = stream->bufstart;
 	stream->bufwpos = stream->bufrpos = stream->bufstart;
-
-#else  /* __STDIO_BUFFERS */
-	stream->modeflags |= 
-		((((open_mode & O_ACCMODE) + 1) ^ 0x03) * __FLAG_WRITEONLY)
-		| (open_mode & (O_APPEND|O_LARGEFILE));
 #endif /* __STDIO_BUFFERS */
 #endif /* __STDIO_BUFFERS */
 
 
 #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
 #ifdef __STDIO_GLIBC_CUSTOM_STREAMS