| Skip Navigation Links | |
| Exit Print View | |
![]() | man pages section 3: Basic Library Functions Oracle Solaris 11 Information Library |
enable_extended_FILE_stdio(3C)
posix_spawnattr_getschedparam(3C)
posix_spawnattr_getschedpolicy(3C)
posix_spawnattr_getsigdefault(3C)
posix_spawnattr_getsigignore_np(3C)
posix_spawnattr_getsigmask(3C)
posix_spawnattr_setschedparam(3C)
posix_spawnattr_setschedpolicy(3C)
posix_spawnattr_setsigdefault(3C)
posix_spawnattr_setsigignore_np(3C)
posix_spawnattr_setsigmask(3C)
posix_spawn_file_actions_addclose(3C)
posix_spawn_file_actions_addclosefrom_np(3C)
posix_spawn_file_actions_adddup2(3C)
posix_spawn_file_actions_addopen(3C)
posix_spawn_file_actions_destroy(3C)
posix_spawn_file_actions_init(3C)
pthread_attr_getdetachstate(3C)
pthread_attr_getinheritsched(3C)
pthread_attr_getschedparam(3C)
pthread_attr_getschedpolicy(3C)
pthread_attr_setdetachstate(3C)
pthread_attr_setinheritsched(3C)
pthread_attr_setschedparam(3C)
pthread_attr_setschedpolicy(3C)
pthread_barrierattr_destroy(3C)
pthread_barrierattr_getpshared(3C)
pthread_barrierattr_setpshared(3C)
pthread_condattr_getpshared(3C)
pthread_condattr_setpshared(3C)
pthread_cond_reltimedwait_np(3C)
pthread_key_create_once_np(3C)
pthread_mutexattr_getprioceiling(3C)
pthread_mutexattr_getprotocol(3C)
pthread_mutexattr_getpshared(3C)
pthread_mutexattr_getrobust(3C)
pthread_mutexattr_setprioceiling(3C)
pthread_mutexattr_setprotocol(3C)
pthread_mutexattr_setpshared(3C)
pthread_mutexattr_setrobust(3C)
pthread_mutex_getprioceiling(3C)
pthread_mutex_reltimedlock_np(3C)
pthread_mutex_setprioceiling(3C)
pthread_rwlockattr_destroy(3C)
pthread_rwlockattr_getpshared(3C)
pthread_rwlockattr_setpshared(3C)
pthread_rwlock_reltimedrdlock_np(3C)
pthread_rwlock_reltimedwrlock_np(3C)
pthread_rwlock_timedrdlock(3C)
pthread_rwlock_timedwrlock(3C)
rctlblk_get_enforced_value(3C)
- get a byte from a stream
#include <stdio.h>intfgetc(FILE *stream);
intgetc(FILE *stream);
intgetc_unlocked(FILE *stream);
intgetchar(void);
intgetchar_unlocked(void);
intgetw(FILE *stream);
Thefgetc() function obtains the next byte (if present) as anunsigned charconverted to anint, from the input stream pointed to bystream,and advances the associated file position indicator for the stream (if defined).
For standard-conforming (seestandards(5)) applications, if the end-of-file indicator for the streamis set,fgetc() returnsEOF whether or not a next byte ispresent.
Thefgetc() function may mark thest_atime field of the file associatedwithstream for update. Thest_atime field will be marked for updateby the first successful execution offgetc(),fgets(3C),fread(3C),fscanf(3C),getc(),getchar(),getdelim(3C),getline(3C),gets(3C) orscanf(3C) usingstream that returns data not suppliedby a prior call toungetc(3C) orungetwc(3C).
Thegetc() function is functionally identical tofgetc(), except that it isimplemented as a macro. It runs faster thanfgetc(), but it takesup more space per invocation and its name cannot be passed asan argument to a function call.
Thegetchar() routine is equivalent togetc(stdin). It is implemented as amacro.
Thegetc_unlocked() andgetchar_unlocked() routines are variants ofgetc() andgetchar(), respectively,that do not lock the stream. It is the caller's responsibilityto acquire the stream lock before calling these routines and releasing the lockafterwards; seeflockfile(3C) andstdio(3C). These routines are implemented as macros.
Thegetw() function reads the next word from thestream. The sizeof a word is the size of anint and may varyfrom environment to environment. Thegetw() function presumes no special alignmentin the file.
Thegetw() function may mark thest_atime field of the file associatedwithstream for update. Thest_atime field will be marked for updateby the first successful execution offgetc(),fgets(3C),fread(3C),getc(),getchar(),gets(3C),fscanf(3C) orscanf(3C) usingstream that returns data not supplied by aprior call toungetc(3C).
Upon successful completion,fgetc(),getc(),getc_unlocked(),getchar(),getchar_unlocked(), andgetw() return thenext byte from the input stream pointed to bystream. If the streamis at end-of-file, the end-of-file indicator for the stream is set andthese functions returnEOF. For standard-conforming (seestandards(5)) applications, if the end-of-fileindicator for the stream is set, these functions returnEOF whether ornot the stream is at end-of-file. If a read error occurs, theerror indicator for the stream is set, EOF is returned, anderrnois set to indicate the error.
Thefgetc(),getc(),getc_unlocked(),getchar(),getchar_unlocked(), andgetw() functions will fail ifdata needs to be read and:
TheO_NONBLOCK flag is set for the file descriptor underlyingstream and the process would be delayed in thefgetc() operation.
The file descriptor underlyingstream is not a valid file descriptor open for reading.
The read operation was terminated due to the receipt of a signal, and no data was transferred.
A physical I/O error has occurred, or the process is in a background process group attempting to read from its controlling terminal, and either the process is ignoring or blocking theSIGTTIN signal or the process group is orphaned. This error may also be generated for implementation-dependent reasons.
The file is a regular file and an attempt was made to read at or beyond the offset maximum associated with the corresponding stream.
Thefgetc(),getc(),getc_unlocked(),getchar(),getchar_unlocked(), andgetw() functions may fail if:
Insufficient storage space is available.
A request was made of a non-existent device, or the request was outside the capabilities of the device.
If the integer value returned byfgetc(),getc(),getc_unlocked(),getchar(),getchar_unlocked(), andgetw() is stored into a variable of typechar and then compared againstthe integer constant EOF, the comparison may never succeed, because sign-extension ofa variable of typechar on widening to integer is implementation-dependent.
Theferror(3C) orfeof(3C) functions must be used to distinguish between an errorcondition and an end-of-file condition.
Functions exist for thegetc(),getc_unlocked(),getchar(), andgetchar_unlocked() macros. To getthe function form, the macro name must be undefined (for example,#undef getc).
When the macro forms are used,getc() andgetc_unlocked() evaluate thestreamargument more than once. In particular,getc(*f++); does not work sensibly. Thefgetc() function should be used instead when evaluating thestream argumenthas side effects.
Because of possible differences in word length and byte ordering, files writtenusinggetw() are machine-dependent, and may not be read usinggetw() ona different processor.
Thegetw() function is inherently byte stream-oriented and is not tenable inthe context of either multibyte character streams or wide-character streams. Application programmersare recommended to use one of the character-based input functions instead.
Seeattributes(5) for descriptions of the following attributes:
|
Intro(3),__fsetlocking(3C),fclose(3C),feof(3C),fgets(3C),fgetwc(3C),fgetws(3C),flockfile(3C),fopen(3C),fread(3C),fscanf(3C),getdelim(3C),getline(3C),gets(3C),putc(3C),scanf(3C),stdio(3C),ungetc(3C),ungetwc(3C),attributes(5),standards(5)
Thefgetc(),getc(),getchar(), andgetw() routines are MT-Safe in multithreaded applications. Thegetc_unlocked() andgetchar_unlocked() routines are unsafe in multithreaded applications.
Copyright © 2011, Oracle and/or its affiliates. All rights reserved.Legal Notices | ![]() ![]() |