Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages


home | help
getc(3S)							      getc(3S)

       getc(), getc_unlocked(),	getchar(), getchar_unlocked(), fgetc(),	getw()
       - get character or word from a stream file

   Obsolescent Interface
       Returns the next	character (i.e., byte) from the	named input
		      stream, as an unsigned character converted to  an	 inte-
		      ger.   It	also moves the file pointer, if	defined, ahead
		      one character in stream.	is defined as and are  defined
		      both as macros and as functions.

       Same as	      but  is  a function rather than a	macro.	is slower than
		      but it takes less	space per invocation and its name  can
		      be passed	as an argument to a function.

       returns the next	word (i.e.,
		      in C) from the named input stream.  increments the asso-
		      ciated file pointer, if defined, to point	 to  the  next
		      word.   The size of a word is the	size of	an integer and
		      varies from machine  to  machine.	  assumes  no  special
		      alignment	in the file.

       and  are	 identical  to and respectively	except they do not perform any
       internal	locking	of the stream for multithreaded	applications.

   Obsolescent Interface
       gets character or word from a stream file.

       and interfaces should be	used by	multithread  applications  which  have
       already	used  to  acquire  a mutual exclusion lock for the stream (see

       After or	is applied to a	stream,	the stream becomes byte-oriented  (see

       Upon  successful	 completion,  and  return the next byte	from the input
       stream pointed to by stream for If the stream is	 at  end-of-file,  the
       end-of-file  indicator for the stream is	set and	EOF is returned.  If a
       read error occurs, the error indicator for the stream is	set, is	set to
       indicate	the error, and EOF is returned.

       Upon  successful	completion, return the next word from the input	stream
       pointed to by stream.  If the stream is at end-of-file, the end-of-file
       indicator  for  the  stream is set and return EOF.  If a	read error oc-
       curs, the error indicator for the stream	is set,	and return EOF and set
       to indicate the error.

       and  can	 be used to distinguish	between	an error condition and an end-
       of-file condition.

       and fail	if data	needs to be read into the stream's buffer, and:

	      [EAGAIN]	     The flag is set for the file descriptor  underly-
			     ing  stream  and  the process would be delayed in
			     the read operation.

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

	      [EINTR]	     The  read operation was terminated	due to the re-
			     ceipt of a	signal,	and either no data was	trans-
			     ferred or the implementation does not report par-
			     tial transfer for this file.

	      [EIO]	     A physical	I/O error has occurred,	or the process
			     is	 a  member  of a background process and	is at-
			     tempting to read from its	controlling  terminal,
			     and  either  the  process is ignoring or blocking
			     the signal	or the process group of	the process is

       Additional values may be	set by the underlying function (see read(2)).

       and  are	 implemented  both as library functions	and macros.  The macro
       versions, which are used	by default, are	defined	in To obtain  the  li-
       brary  function either use a to remove the macro	definition or, if com-
       piling in ANSI-C	mode, enclose the function name	in parenthesis or  use
       the  function address.  The following example illustrates each of these
       methods :

       If the integer value returned by	or is stored into a character variable
       then  compared  against	the  integer constant the comparison may never
       succeed because sign-extension of a character on	widening to integer is

       The macro version of incorrectly	treats a stream	argument with side ef-
       fects.  In particular, does not work sensibly.  The function version of
       or should be used instead.

       Because of possible differences in word length and byte ordering, files
       written using are machine-dependent, and	may be unreadable by on	a dif-
       ferent processor.

   Reentrant Interfaces
       If is defined before including the locked versions of the library func-
       tions for and are used by default.

       is an obsolescent interface supported only for compatibility  with  ex-
       isting DCE applications.	New multithreaded applications should use

       fclose(3S),  ferror(3S),	flockfile(3S), fopen(3S), fread(3S), gets(3S),
       putc(3S), read(2), scanf(3S), orientation(5), thread_safety(5).



Want to link to this manual page? Use this URL:

home | help