1FGETC(P)                   POSIX Programmer's Manual                  FGETC(P)
2
3
4

NAME

6       fgetc - get a byte from a stream
7

SYNOPSIS

9       #include <stdio.h>
10
11       int fgetc(FILE *stream);
12
13

DESCRIPTION

15       If  the end-of-file indicator for the input stream pointed to by stream
16       is not set and a next byte  is  present,  the  fgetc()  function  shall
17       obtain  the next byte as an unsigned char converted to an int, from the
18       input stream pointed to by stream,  and  advance  the  associated  file
19       position  indicator for the stream (if defined). Since fgetc() operates
20       on bytes, reading a character  consisting  of  multiple  bytes  (or  "a
21       multi-byte character") may require multiple calls to fgetc().
22
23       The fgetc() function may mark the st_atime field of the file associated
24       with stream for update. The st_atime field shall be marked  for  update
25       by  the  first  successful  execution  of  fgetc(),  fgets(), fgetwc(),
26       fgetws(), fread(), fscanf(),  getc(),  getchar(),  gets(),  or  scanf()
27       using stream that returns data not supplied by a prior call to ungetc()
28       or ungetwc().
29

RETURN VALUE

31       Upon successful completion, fgetc() shall return the next byte from the
32       input stream pointed to by stream. If the end-of-file indicator for the
33       stream is set, or if the stream  is  at  end-of-file,  the  end-of-file
34       indicator  for the stream shall be set and fgetc() shall return EOF. If
35       a read error occurs, the error indicator for the stream shall  be  set,
36       fgetc() shall return EOF,    and shall set errno to indicate the error.
37

ERRORS

39       The fgetc() function shall fail if data needs to be read and:
40
41       EAGAIN The  O_NONBLOCK  flag  is set for the file descriptor underlying
42              stream and the process would be delayed in  the  fgetc()  opera‐
43              tion.
44
45       EBADF  The  file  descriptor  underlying  stream  is  not  a valid file
46              descriptor open for reading.
47
48       EINTR  The read operation was terminated due to the receipt of  a  sig‐
49              nal, and no data was transferred.
50
51       EIO    A  physical I/O error has occurred, or the process is in a back‐
52              ground process group attempting to  read  from  its  controlling
53              terminal,  and  either  the  process is ignoring or blocking the
54              SIGTTIN signal or the process group is orphaned. This error  may
55              also be generated for implementation-defined reasons.
56
57       EOVERFLOW
58              The file is a regular file and an attempt was made to read at or
59              beyond the offset  maximum  associated  with  the  corresponding
60              stream.
61
62
63       The fgetc() function may fail if:
64
65       ENOMEM Insufficient storage space is available.
66
67       ENXIO  A  request  was made of a nonexistent device, or the request was
68              outside the capabilities of the device.
69
70
71       The following sections are informative.
72

EXAMPLES

74       None.
75

APPLICATION USAGE

77       If the integer value returned by fgetc() is stored into a  variable  of
78       type  char and then compared against the integer constant EOF, the com‐
79       parison may never succeed, because sign-extension of a variable of type
80       char on widening to integer is implementation-defined.
81
82       The ferror() or feof() functions must be used to distinguish between an
83       error condition and an end-of-file condition.
84

RATIONALE

86       None.
87

FUTURE DIRECTIONS

89       None.
90

SEE ALSO

92       feof() , ferror() , fopen() , getchar() , getc() , the Base Definitions
93       volume of IEEE Std 1003.1-2001, <stdio.h>
94
96       Portions  of  this text are reprinted and reproduced in electronic form
97       from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
98       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
99       Specifications Issue 6, Copyright (C) 2001-2003  by  the  Institute  of
100       Electrical  and  Electronics  Engineers, Inc and The Open Group. In the
101       event of any discrepancy between this version and the original IEEE and
102       The  Open Group Standard, the original IEEE and The Open Group Standard
103       is the referee document. The original Standard can be  obtained  online
104       at http://www.opengroup.org/unix/online.html .
105
106
107
108IEEE/The Open Group                  2003                             FGETC(P)
Impressum