1fputc(3C)                Standard C Library Functions                fputc(3C)
2
3
4

NAME

6       fputc,  putc,  putc_unlocked,  putchar,  putchar_unlocked, putw - put a
7       byte on a stream
8

SYNOPSIS

10       #include <stdio.h>
11
12       int fputc(int c, FILE *stream);
13
14
15       int putc(int c, FILE *stream);
16
17
18       int putc_unlocked(int c, FILE *stream);
19
20
21       int putchar(int c);
22
23
24       int putchar_unlocked(int c);
25
26
27       int putw(int w, FILE *stream);
28
29

DESCRIPTION

31       The fputc() function writes the byte specified by c  (converted  to  an
32       unsigned  char) to the output stream pointed to by stream, at the posi‐
33       tion indicated by the associated file-position indicator for the stream
34       (if  defined),  and  advances  the indicator appropriately. If the file
35       cannot support positioning requests, or if the stream was  opened  with
36       append mode, the byte is appended to the output stream.
37
38
39       The  st_ctime and st_mtime fields of the file will be marked for update
40       between the successful execution of fputc()  and  the  next  successful
41       completion  of a call to fflush(3C) or fclose(3C) on the same stream or
42       a call to exit(3C) or abort(3C).
43
44
45       The putc() routine behaves like fputc(), except that it is  implemented
46       as a macro. It runs faster than fputc(), but it takes up more space per
47       invocation and its name cannot be passed as an argument to  a  function
48       call.
49
50
51       The  call  putchar(c)  is  equivalent to putc(c, stdout). The putchar()
52       routine is implemented as a macro.
53
54
55       The putc_unlocked() and putchar_unlocked()  routines  are  variants  of
56       putc() and putchar(), respectively, that do not lock the stream.  It is
57       the caller's responsibility to acquire the stream lock  before  calling
58       these routines and releasing the lock afterwards; see flockfile(3C) and
59       stdio(3C). These routines are implemented as macros.
60
61
62       The putw() function writes the word (that is, type int) w to the output
63       stream (at the position at which the file offset, if defined, is point‐
64       ing). The size of a word is the size of a  type  int  and  varies  from
65       machine  to  machine.   The  putw() function neither assumes nor causes
66       special alignment in the file.
67
68
69       The st_ctime and st_mtime fields of the file will be marked for  update
70       between the successful execution of putw() and the next successful com‐
71       pletion of a call to fflush(3C) or fclose(3C) on the same stream  or  a
72       call to exit(3C) or abort(3C).
73

RETURN VALUES

75       Upon   successful   completion,   fputc(),   putc(),   putc_unlocked(),
76       putchar(), and putchar_unlocked() return the value  that  was  written.
77       Otherwise,  these  functions  return  EOF,  the error indicator for the
78       stream is set, and errno is set to indicate the error.
79
80
81       Upon successful completion, putw() returns 0. Otherwise, it  returns  a
82       non-zero value, sets the error indicator for the associated stream, and
83       sets errno to indicate the error.
84
85
86       An unsuccessful completion will occur, for example, if the file associ‐
87       ated  with  stream is not open for writing or if the output file cannot
88       grow.
89

ERRORS

91       The fputc(), putc(),  putc_unlocked(),  putchar(),  putchar_unlocked(),
92       and  putw()  functions  will fail if either the stream is unbuffered or
93       the stream's buffer needs to be flushed, and:
94
95       EAGAIN    The O_NONBLOCK flag is set for the file descriptor underlying
96                 stream  and  the process would be delayed in the write opera‐
97                 tion.
98
99
100       EBADF     The file descriptor underlying stream is  not  a  valid  file
101                 descriptor open for writing.
102
103
104       EFBIG     An attempt was made to write to a file that exceeds the maxi‐
105                 mum file size  or the process' file size limit.
106
107
108       EFBIG     The file is a regular file and an attempt was made  to  write
109                 at or beyond the offset maximum.
110
111
112       EINTR     The  write  operation  was terminated due to the receipt of a
113                 signal, and no data was transferred.
114
115
116       EIO       A physical I/O error has occurred, or  the process is a  mem‐
117                 ber  of a background process group attempting to write to its
118                 controlling terminal, TOSTOP is set, the process  is  neither
119                 ignoring  nor  blocking  SIGTTOU and the process group of the
120                 process is orphaned. This error may also  be  returned  under
121                 implementation-dependent conditions.
122
123
124       ENOSPC    There  was  no  free space remaining on the device containing
125                 the file.
126
127
128       EPIPE     An attempt is made to write to a pipe or  FIFO  that  is  not
129                 open  for  reading by any process. A SIGPIPE signal will also
130                 be sent to the calling thread.
131
132
133
134       The fputc(), putc(),  putc_unlocked(),  putchar(),  putchar_unlocked(),
135       and putw() functions may fail if:
136
137       ENOMEM    Insufficient storage space is available.
138
139
140       ENXIO     A  request  was made of a non-existent device, or the request
141                 was outside the capabilities of the device.
142
143

USAGE

145       Functions  exist  for  the  putc(),  putc_unlocked(),  putchar(),   and
146       putchar_unlocked()  macros.  To  get  the function form, the macro name
147       must be undefined (for example, #undef putc).
148
149
150       When the macro forms are used, putc() and putc_unlocked() evaluate  the
151       stream  argument more than once. In particular, putc(c, *f++); does not
152       work sensibly.  The fputc() function should be used instead when evalu‐
153       ating the stream argument has side effects.
154
155
156       Because of possible differences in word length and byte ordering, files
157       written using putw() are implementation-dependent, and possibly  cannot
158       be read using getw(3C) by a different application or by the same appli‐
159       cation running in a different environment.
160
161
162       The putw() function is inherently byte stream oriented and is not  ten‐
163       able in the context of either multibyte character streams or wide-char‐
164       acter streams. Application programmers are encouraged to use one of the
165       character-based output functions instead.
166

ATTRIBUTES

168       See attributes(5) for descriptions of the following attributes:
169
170
171
172
173       ┌─────────────────────────────┬─────────────────────────────┐
174       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
175       ├─────────────────────────────┼─────────────────────────────┤
176       │Interface Stability          │fputc(),            putc(),  │
177       │                             │putc_unlocked(), putchar(),  │
178       │                             │and  putchar_unlocked() are  │
179       │                             │Standard.                    │
180       ├─────────────────────────────┼─────────────────────────────┤
181       │MT-Level                     │See NOTES below.             │
182       └─────────────────────────────┴─────────────────────────────┘
183

SEE ALSO

185       getrlimit(2),  ulimit(2)  write(2),  Intro(3),   abort(3C),   exit(3C),
186       fclose(3C),   ferror(3C),   fflush(3C),   flockfile(3C),   fopen(3UCB),
187       printf(3C), putc(3C), puts(3C), setbuf(3C),  stdio(3C),  attributes(5),
188       standards(5)
189

NOTES

191       The fputc(), putc(), putchar(), and putw() routines are MT-Safe in mul‐
192       tithreaded applications.  The  putc_unlocked()  and  putchar_unlocked()
193       routines are unsafe in multithreaded applications.
194
195
196
197SunOS 5.11                        1 Nov 2003                         fputc(3C)
Impressum