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. <<fputc>>, <<fputc_unlocked>>---write a character on a stream or file
  21.  
  22. INDEX
  23.         fputc
  24. INDEX
  25.         fputc_unlocked
  26. INDEX
  27.         _fputc_r
  28. INDEX
  29.         _fputc_unlocked_r
  30.  
  31. ANSI_SYNOPSIS
  32.         #include <stdio.h>
  33.         int fputc(int <[ch]>, FILE *<[fp]>);
  34.  
  35.         #define _BSD_SOURCE
  36.         #include <stdio.h>
  37.         int fputc_unlocked(int <[ch]>, FILE *<[fp]>);
  38.  
  39.         #include <stdio.h>
  40.         int _fputc_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
  41.  
  42.         #include <stdio.h>
  43.         int _fputc_unlocked_r(struct _rent *<[ptr]>, int <[ch]>, FILE *<[fp]>);
  44.  
  45. TRAD_SYNOPSIS
  46.         #include <stdio.h>
  47.         int fputc(<[ch]>, <[fp]>)
  48.         int <[ch]>;
  49.         FILE *<[fp]>;
  50.  
  51.         #define _BSD_SOURCE
  52.         #include <stdio.h>
  53.         int fputc_unlocked(<[ch]>, <[fp]>)
  54.         int <[ch]>;
  55.         FILE *<[fp]>;
  56.  
  57.         #include <stdio.h>
  58.         int _fputc_r(<[ptr]>, <[ch]>, <[fp]>)
  59.         struct _reent *<[ptr]>;
  60.         int <[ch]>;
  61.         FILE *<[fp]>;
  62.  
  63.         #include <stdio.h>
  64.         int _fputc_unlocked_r(<[ptr]>, <[ch]>, <[fp]>)
  65.         struct _reent *<[ptr]>;
  66.         int <[ch]>;
  67.         FILE *<[fp]>;
  68.  
  69. DESCRIPTION
  70. <<fputc>> converts the argument <[ch]> from an <<int>> to an
  71. <<unsigned char>>, then writes it to the file or stream identified by
  72. <[fp]>.
  73.  
  74. If the file was opened with append mode (or if the stream cannot
  75. support positioning), then the new character goes at the end of the
  76. file or stream.  Otherwise, the new character is written at the
  77. current value of the position indicator, and the position indicator
  78. oadvances by one.
  79.  
  80. For a macro version of this function, see <<putc>>.
  81.  
  82. <<fputc_unlocked>> is a non-thread-safe version of <<fputc>>.
  83. <<fputc_unlocked>> may only safely be used within a scope
  84. protected by flockfile() (or ftrylockfile()) and funlockfile().  This
  85. function may safely be used in a multi-threaded program if and only
  86. if they are called while the invoking thread owns the (FILE *)
  87. object, as is the case after a successful call to the flockfile() or
  88. ftrylockfile() functions.  If threads are disabled, then
  89. <<fputc_unlocked>> is equivalent to <<fputc>>.
  90.  
  91. The <<_fputc_r>> and <<_fputc_unlocked_r>> functions are simply reentrant
  92. versions of the above that take an additional reentrant structure
  93. argument: <[ptr]>.
  94.  
  95. RETURNS
  96. If successful, <<fputc>> returns its argument <[ch]>.  If an error
  97. intervenes, the result is <<EOF>>.  You can use `<<ferror(<[fp]>)>>' to
  98. query for errors.
  99.  
  100. PORTABILITY
  101. <<fputc>> is required by ANSI C.
  102.  
  103. <<fputc_unlocked>> is a BSD extension also provided by GNU libc.
  104.  
  105. Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
  106. <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
  107. */
  108.  
  109. #include <_ansi.h>
  110. #include <stdio.h>
  111. #include "local.h"
  112.  
  113. int
  114. _DEFUN(_fputc_r, (ptr, ch, file),
  115.        struct _reent *ptr _AND
  116.        int ch _AND
  117.        FILE * file)
  118. {
  119.   int result;
  120.   CHECK_INIT(ptr, file);
  121.    _newlib_flockfile_start (file);
  122.   result = _putc_r (ptr, ch, file);
  123.   _newlib_flockfile_end (file);
  124.   return result;
  125. }
  126.  
  127. #ifndef _REENT_ONLY
  128. int
  129. _DEFUN(fputc, (ch, file),
  130.        int ch _AND
  131.        FILE * file)
  132. {
  133. #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED)
  134.   int result;
  135.   struct _reent *reent = _REENT;
  136.  
  137.   CHECK_INIT(reent, file);
  138.    _newlib_flockfile_start (file);
  139.   result = _putc_r (reent, ch, file);
  140.   _newlib_flockfile_end (file);
  141.   return result;
  142. #else
  143.   return _fputc_r (_REENT, ch, file);
  144. #endif
  145. }
  146. #endif /* !_REENT_ONLY */
  147.