Subject: Re: fgets prototype bug?
To: Simon Burge <simonb@netbsd.org>
From: Johan Danielsson <joda@pdc.kth.se>
List: tech-userlevel
Date: 11/16/1999 09:00:57
Simon Burge <simonb@netbsd.org> writes:
> Is is a bug that fgets() takes an "int" as the size of the object
> and not a size_t?
Yes, but we can't do much about it, since it's defined that way in
`ANSI C', and C9x. C doesn't have an ssize_t type.
You *could* have different prototypes if _ANSI_C_SOURCE (or something)
is defined, but I really hate such solutions.
7.13.7.2 The fgets function
Synopsis
#include <stdio.h>
char *fgets(char * restrict s, int n,
FILE * restrict stream);
Description
The fgets function reads at most one less than the number of
characters specified by n from the stream pointed to by stream into
the array pointed to by s. No additional characters are read after
a new-line character (which is retained) or after end-of-file. A
null character is written immediately after the last character read
into the array.
Returns
The fgets function returns s if successful. If end-of-file is
encountered and no characters have been read into the array, the
contents of the array remain unchanged and a null pointer is
returned. If a read error occurs during the operation, the array
contents are indeterminate and a null pointer is returned.
/Johan