Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fgetc(3) — OSF/1 3.0 αXP

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

flockfile(3)

funlockfile(3)

gets(3)

getwc(3)

putc(3)

getc(3)  —  Subroutines

NAME

getc, fgetc, getc_unlocked, getchar, getchar_unlocked, getw − Get a character or word from an input stream

LIBRARY

Standard C Library (libc.a)

SYNOPSIS

#include <stdio.h>

int getc(
        FILE ∗stream);

int fgetc(
        FILE ∗stream);

int getc_unlocked(
        FILE ∗ stream);

int getchar(void);

int getchar_unlocked(void);

int getw(
        FILE ∗stream);

PARAMETERS

streamPoints to the file structure of an open file. 

DESCRIPTION

The getc() function  returns the next byte from the input specified by the stream parameter and moves the file pointer, if defined, ahead one byte in stream. The getc() function may be a macro (depending on compile-time definitions). See the NOTES section for more information. 

The fgetc() function performs the same function as getc(). 

The getchar() function returns the next byte from stdin, the standard input stream. Note that getchar() can also be a macro. 

The reentrant versions of these functions are all locked against multiple threads calling them simultaneously.  This will incur an overhead to ensure integrity of the stream. The unlocked versions of these calls, getc_unlocked() and getchar_unlocked() may be used to avoid the overhead. The getc_unlocked() and getchar_unlocked() functions are functionally identical to the getc() and getchar() functions, except that getc_unlocked() and getchar_unlocked() may be safely used only within a scope that is protected by the flockfile() and funlockfile() functions used as a pair.  The caller must ensure that the stream is locked before these functions are used. The getc() and getchar() functions can also be macros. 

The getw() function returns the next word (int) from the input specified by the stream parameter and increments the associated file pointer, if defined, to point to the next int.  The size of an int varies from one machine architecture to another.  The getw() function returns the constant EOF at the end of the file or when an error occurs. Since EOF is a valid integer value, the feof() and ferror() functions can be used to check the success of getw(). The getw() function assumes no special alignment in the file. 

Because of possible differences in int length and byte ordering from one machine architecture to another, files written using the putw() subroutine are machine dependent and may not be readable using getw() on a different type of processor. 

NOTES

AES Support Level:
Full use (getc(), fgetc(), getchar()). 
Trial use (getw()). 

RETURN VALUES

These functions and macros return the integer constant EOF at the end of the file or upon an error. 

ERRORS

If any of the following conditions occur, the getc(), getc(), getc_unlocked(), getchar(), getchar_unlocked(), and getw() functions set errno to the corresponding value:

[EAGAIN]The O_NONBLOCK flag is set for the underlying stream and the process would be delayed by the read operation. 

[EBADF]The file descriptor underlying the stream is not a valid file descriptor or is not open for reading. 

[EINTR]The read operation was interrupted by a signal which was caught and no data was transferred. 

[EIO]The call is attempting to read from the process’s controlling terminal and either the process is ignoring or blocking the SIGTTIN signal or the process group is orphaned. 

[ENOMEM]Insufficient memory is available for the operation. 

[ENXIO]Device associated with stream does not exist. 

RELATED INFORMATION

Functions: flockfile(3), funlockfile(3), gets(3), getwc(3), putc(3). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026