Subversion Repositories Kolibri OS

Rev

Rev 4921 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /*
  2.  * Copyright (c) 1990 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. /*
  19. FUNCTION
  20. <<fgetc>>, <<fgetc_unlocked>>---get a character from a file or stream
  21.  
  22. INDEX
  23.         fgetc
  24. INDEX
  25.         fgetc_unlocked
  26. INDEX
  27.         _fgetc_r
  28. INDEX
  29.         _fgetc_unlocked_r
  30.  
  31. ANSI_SYNOPSIS
  32.         #include <stdio.h>
  33.         int fgetc(FILE *<[fp]>);
  34.  
  35.         #define _BSD_SOURCE
  36.         #include <stdio.h>
  37.         int fgetc_unlocked(FILE *<[fp]>);
  38.  
  39.         #include <stdio.h>
  40.         int _fgetc_r(struct _reent *<[ptr]>, FILE *<[fp]>);
  41.  
  42.         #define _BSD_SOURCE
  43.         #include <stdio.h>
  44.         int _fgetc_unlocked_r(struct _reent *<[ptr]>, FILE *<[fp]>);
  45.  
  46. TRAD_SYNOPSIS
  47.         #include <stdio.h>
  48.         int fgetc(<[fp]>)
  49.         FILE *<[fp]>;
  50.  
  51.         #define _BSD_SOURCE
  52.         #include <stdio.h>
  53.         int fgetc_unlocked(<[fp]>)
  54.         FILE *<[fp]>;
  55.  
  56.         #include <stdio.h>
  57.         int _fgetc_r(<[ptr]>, <[fp]>)
  58.         struct _reent *<[ptr]>;
  59.         FILE *<[fp]>;
  60.  
  61.         #define _BSD_SOURCE
  62.         #include <stdio.h>
  63.         int _fgetc_unlocked_r(<[ptr]>, <[fp]>)
  64.         struct _reent *<[ptr]>;
  65.         FILE *<[fp]>;
  66.  
  67. DESCRIPTION
  68. Use <<fgetc>> to get the next single character from the file or stream
  69. identified by <[fp]>.  As a side effect, <<fgetc>> advances the file's
  70. current position indicator.
  71.  
  72. For a macro version of this function, see <<getc>>.
  73.  
  74. <<fgetc_unlocked>> is a non-thread-safe version of <<fgetc>>.
  75. <<fgetc_unlocked>> may only safely be used within a scope
  76. protected by flockfile() (or ftrylockfile()) and funlockfile().  This
  77. function may safely be used in a multi-threaded program if and only
  78. if they are called while the invoking thread owns the (FILE *)
  79. object, as is the case after a successful call to the flockfile() or
  80. ftrylockfile() functions.  If threads are disabled, then
  81. <<fgetc_unlocked>> is equivalent to <<fgetc>>.
  82.  
  83. The functions <<_fgetc_r>> and <<_fgetc_unlocked_r>> are simply reentrant
  84. versions that are passed the additional reentrant structure pointer
  85. argument: <[ptr]>.
  86.  
  87. RETURNS
  88. The next character (read as an <<unsigned char>>, and cast to
  89. <<int>>), unless there is no more data, or the host system reports a
  90. read error; in either of these situations, <<fgetc>> returns <<EOF>>.
  91.  
  92. You can distinguish the two situations that cause an <<EOF>> result by
  93. using the <<ferror>> and <<feof>> functions.
  94.  
  95. PORTABILITY
  96. ANSI C requires <<fgetc>>.
  97.  
  98. <<fgetc_unlocked>> is a BSD extension also provided by GNU libc.
  99.  
  100. Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
  101. <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
  102. */
  103.  
  104. #include <_ansi.h>
  105. #include <stdio.h>
  106. #include "local.h"
  107.  
  108. int
  109. _DEFUN(_fgetc_r, (ptr, fp),
  110.        struct _reent * ptr _AND
  111.        FILE * fp)
  112. {
  113.   int result;
  114.   CHECK_INIT(ptr, fp);
  115.   _newlib_flockfile_start (fp);
  116.   result = __sgetc_r (ptr, fp);
  117.   _newlib_flockfile_end (fp);
  118.   return result;
  119. }
  120.  
  121. #ifndef _REENT_ONLY
  122.  
  123. int
  124. _DEFUN(fgetc, (fp),
  125.        FILE * fp)
  126. {
  127. #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
  128.   int result;
  129.   struct _reent *reent = _REENT;
  130.  
  131.   CHECK_INIT(reent, fp);
  132.   _newlib_flockfile_start (fp);
  133.   result = __sgetc_r (reent, fp);
  134.   _newlib_flockfile_end (fp);
  135.   return result;
  136. #else
  137.   return _fgetc_r (_REENT, fp);
  138. #endif
  139. }
  140.  
  141. #endif /* !_REENT_ONLY */
  142.  
  143.