Skip to content

Commit

Permalink
[libc] Fix fdopen bug introduced in #1923
Browse files Browse the repository at this point in the history
  • Loading branch information
ghaerr committed Sep 20, 2024
1 parent 8b061a9 commit a6a98ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
8 changes: 2 additions & 6 deletions libc/stdio/__fopen.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,6 @@ __fopen(const char * fname, int fd, FILE * fp, const char * mode)
break;
}

if (!fname) {
errno = EINVAL;
return 0;
}

/* Allocate the (FILE) before we do anything irreversable */
if (fp == 0)
{
Expand All @@ -88,7 +83,8 @@ __fopen(const char * fname, int fd, FILE * fp, const char * mode)
}

/* Open the file itself */
fd = open(fname, open_mode, 0666);
if (fname)
fd = open(fname, open_mode, 0666);
if (fd < 0) /* Grrrr */
{
if (nfp)
Expand Down
7 changes: 6 additions & 1 deletion libc/stdio/fopen.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#include <stdio.h>
#include <errno.h>

FILE * fopen (const char * file, const char * mode)
{
return __fopen(file, -1, (FILE*)0, mode);
if (file == NULL) {
errno = EINVAL;
return 0;
}
return __fopen(file, -1, (FILE *)0, mode);
}

0 comments on commit a6a98ee

Please sign in to comment.