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 | 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 | 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 | #include <_ansi.h> |
---|
86 | #include <stdio.h> |
---|
87 | #include "local.h" |
---|
88 | |
---|
89 | int |
---|
90 | _fputc_r (struct _reent *ptr, |
---|
91 | int ch, |
---|
92 | FILE * file) |
---|
93 | { |
---|
94 | int result; |
---|
95 | CHECK_INIT(ptr, file); |
---|
96 | _newlib_flockfile_start (file); |
---|
97 | result = _putc_r (ptr, ch, file); |
---|
98 | _newlib_flockfile_end (file); |
---|
99 | return result; |
---|
100 | } |
---|
101 | |
---|
102 | #ifndef _REENT_ONLY |
---|
103 | int |
---|
104 | fputc (int ch, |
---|
105 | FILE * file) |
---|
106 | { |
---|
107 | #if !defined(__OPTIMIZE_SIZE__) && !defined(PREFER_SIZE_OVER_SPEED) |
---|
108 | int result; |
---|
109 | struct _reent *reent = _REENT; |
---|
110 | |
---|
111 | CHECK_INIT(reent, file); |
---|
112 | _newlib_flockfile_start (file); |
---|
113 | result = _putc_r (reent, ch, file); |
---|
114 | _newlib_flockfile_end (file); |
---|
115 | return result; |
---|
116 | #else |
---|
117 | return _fputc_r (_REENT, ch, file); |
---|
118 | #endif |
---|
119 | } |
---|
120 | #endif /* !_REENT_ONLY */ |
---|