improved file creation on f[re]open()

This commit is contained in:
eck 1990-04-09 15:21:43 +00:00
parent aa4de95f26
commit d2516d4eaf
2 changed files with 13 additions and 5 deletions

View 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;

View 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++) {