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

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       fgetc — get a byte from a stream
14

SYNOPSIS

16       #include <stdio.h>
17
18       int fgetc(FILE *stream);
19

DESCRIPTION

21       The functionality described on this reference page is aligned with  the
22       ISO C  standard.  Any  conflict between the requirements described here
23       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2008
24       defers to the ISO C standard.
25
26       If  the end-of-file indicator for the input stream pointed to by stream
27       is not set and a next byte  is  present,  the  fgetc()  function  shall
28       obtain  the next byte as an unsigned char converted to an int, from the
29       input stream pointed to by stream,  and  advance  the  associated  file
30       position  indicator for the stream (if defined). Since fgetc() operates
31       on bytes, reading a character consisting  of  multiple  bytes  (or  ``a
32       multi-byte character'') may require multiple calls to fgetc().
33
34       The  fgetc()  function  may  mark the last data access timestamp of the
35       file associated with stream for update. The last data access  timestamp
36       shall  be  marked  for  update  by  the  first  successful execution of
37       fgetc(), fgets(), fread(),  fscanf(),  getc(),  getchar(),  getdelim(),
38       getline(),  gets(),  or scanf() using stream that returns data not sup‐
39       plied by a prior call to ungetc().
40

RETURN VALUE

42       Upon successful completion, fgetc() shall return the next byte from the
43       input  stream  pointed  to by stream.  If the end-of-file indicator for
44       the stream is set, or if the stream is at end-of-file, the  end-of-file
45       indicator  for the stream shall be set and fgetc() shall return EOF. If
46       a read error occurs, the error indicator for the stream shall  be  set,
47       fgetc() shall return EOF, and shall set errno to indicate the error.
48

ERRORS

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

EXAMPLES

83       None.
84

APPLICATION USAGE

86       If the integer value returned by fgetc() is stored into a  variable  of
87       type  char and then compared against the integer constant EOF, the com‐
88       parison may never succeed, because sign-extension of a variable of type
89       char on widening to integer is implementation-defined.
90
91       The ferror() or feof() functions must be used to distinguish between an
92       error condition and an end-of-file condition.
93

RATIONALE

95       None.
96

FUTURE DIRECTIONS

98       None.
99

SEE ALSO

101       Section 2.5, Standard I/O Streams, feof(), ferror(), fgets(),  fread(),
102       fscanf(), getchar(), getc(), gets(), ungetc()
103
104       The Base Definitions volume of POSIX.1‐2008, <stdio.h>
105
107       Portions  of  this text are reprinted and reproduced in electronic form
108       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
109       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
110       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
111       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
112       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
113       event of any discrepancy between this version and the original IEEE and
114       The Open Group Standard, the original IEEE and The Open Group  Standard
115       is  the  referee document. The original Standard can be obtained online
116       at http://www.unix.org/online.html .
117
118       Any typographical or formatting errors that appear  in  this  page  are
119       most likely to have been introduced during the conversion of the source
120       files to man page format. To report such errors,  see  https://www.ker
121       nel.org/doc/man-pages/reporting_bugs.html .
122
123
124
125IEEE/The Open Group                  2013                            FGETC(3P)
Impressum