Skip to content

Commit 2af2019

Browse files
committed
Fix fgets() return type; should be (char *)
1 parent 96c76bb commit 2af2019

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

examples/stdlib.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3622,10 +3622,10 @@ static int fgetc(FILE *stream)
36223622
return result;
36233623
}
36243624

3625-
static int fgets_unlocked(char *s, int size, FILE *stream)
3625+
static char *fgets_unlocked(char *s, int size, FILE *stream)
36263626
{
36273627
if (stdio_stream_read_init(stream) < 0)
3628-
return EOF;
3628+
return NULL;
36293629
int i;
36303630
for (i = 0; i < size-1; i++)
36313631
{
@@ -3638,7 +3638,7 @@ static int fgets_unlocked(char *s, int size, FILE *stream)
36383638
if (feof_unlocked(stream))
36393639
break;
36403640
if (ferror_unlocked(stream))
3641-
return EOF;
3641+
return NULL;
36423642
}
36433643
s[i] = c;
36443644
if (c == '\n')
@@ -3648,13 +3648,13 @@ static int fgets_unlocked(char *s, int size, FILE *stream)
36483648
}
36493649
}
36503650
s[i] = '\0';
3651-
return 0;
3651+
return s;
36523652
}
36533653

3654-
static int fgets(char *s, int size, FILE *stream)
3654+
static char *fgets(char *s, int size, FILE *stream)
36553655
{
3656-
stdio_lock(stream, EOF);
3657-
int result = fgets_unlocked(s, size, stream);
3656+
stdio_lock(stream, NULL);
3657+
char *result = fgets_unlocked(s, size, stream);
36583658
stdio_unlock(stream);
36593659
return result;
36603660
}

0 commit comments

Comments
 (0)