int _open(const char *path, int flags);
int _creat(const char *path, int mode);
-
int _close(int d);
FILE *
*/
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;
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++) {