improved file creation on f[re]open()
authoreck <none@none>
Mon, 9 Apr 1990 15:21:43 +0000 (15:21 +0000)
committereck <none@none>
Mon, 9 Apr 1990 15:21:43 +0000 (15:21 +0000)
lang/cem/libcc.ansi/stdio/fopen.c
lang/cem/libcc.ansi/stdio/freopen.c

index bd1c1ef..5fe89be 100644 (file)
@@ -37,7 +37,6 @@
 
 int _open(const char *path, int flags);
 int _creat(const char *path, int mode);
-
 int _close(int d);
 
 FILE *
@@ -89,8 +88,13 @@ fopen(const char *name, const char *mode)
         */
        if ((rwflags & O_TRUNC)
            || (((fd = _open(name, rwmode)) < 0)
-                   && (flags & _IOWRITE)))
-               fd = _creat(name, PMODE);
+                   && (flags & _IOWRITE))) {
+               if (((fd = _creat(name, PMODE)) > 0) && flags  | _IOREAD) {
+                       (void) _close(fd);
+                       fd = _open(name, rwmode);
+               }
+                       
+       }
 
        if (fd < 0) return (FILE *)NULL;
 
index 9211119..af384b7 100644 (file)
@@ -68,8 +68,12 @@ freopen(const char *name, const char *mode, FILE *stream)
 
        if ((rwflags & O_TRUNC)
            || (((fd = _open(name, rwmode)) < 0)
-                   && (flags & _IOWRITE)))
-               fd = _creat(name, PMODE);
+                   && (flags & _IOWRITE))) {
+               if (((fd = _creat(name, PMODE)) < 0) && flags | _IOREAD) {
+                       (void) _close(fd);
+                       fd = _open(name, rwmode);
+               }
+       }
 
        if (fd < 0) {
                for( i = 0; i < FOPEN_MAX; i++) {