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  * and/or 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 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( int <[ch]>, FILE *<[fp]>);
41 
42 	#include <stdio.h>
43 	int fputc_unlocked( int <[ch]>, FILE *<[fp]>);
44 
45 DESCRIPTION
46 <<fputc>> converts the argument <[ch]> from an <<int>> to an
47 <<unsigned char>>, then writes it to the file or stream identified by
48 <[fp]>.
49 
50 If the file was opened with append mode (or if the stream cannot
51 support positioning), then the new character goes at the end of the
52 file or stream.  Otherwise, the new character is written at the
53 current value of the position indicator, and the position indicator
54 oadvances by one.
55 
56 For a macro version of this function, see <<putc>>.
57 
58 <<fputc_unlocked>> is a non-thread-safe version of <<fputc>>.
59 <<fputc_unlocked>> may only safely be used within a scope
60 protected by flockfile() (or ftrylockfile()) and funlockfile().  This
61 function may safely be used in a multi-threaded program if and only
62 if they are called while the invoking thread owns the (FILE *)
63 object, as is the case after a successful call to the flockfile() or
64 ftrylockfile() functions.  If threads are disabled, then
65 <<fputc_unlocked>> is equivalent to <<fputc>>.
66 
67 The <<_fputc_r>> and <<_fputc_unlocked_r>> functions are simply reentrant
68 versions of the above that take an additional reentrant structure
69 argument: <[ptr]>.
70 
71 RETURNS
72 If successful, <<fputc>> returns its argument <[ch]>.  If an error
73 intervenes, the result is <<EOF>>.  You can use `<<ferror(<[fp]>)>>' to
74 query for errors.
75 
76 PORTABILITY
77 <<fputc>> is required by ANSI C.
78 
79 <<fputc_unlocked>> is a BSD extension also provided by GNU libc.
80 
81 Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
82 <<lseek>>, <<read>>, <<sbrk>>, <<write>>.
83 */
84 
85 #define _DEFAULT_SOURCE
86 #include <_ansi.h>
87 #include <stdio.h>
88 #include "local.h"
89 
90 int
fputc(int ch,FILE * file)91 fputc (
92        int ch,
93        FILE * file)
94 {
95   int result;
96   CHECK_INIT(ptr, file);
97    _newlib_flockfile_start (file);
98   result = putc ( ch, file);
99   _newlib_flockfile_end (file);
100   return result;
101 }
102