source: trunk/libs/newlib/src/newlib/libc/stdio/fputc.c

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.5 KB
Line 
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/*
19FUNCTION
20<<fputc>>, <<fputc_unlocked>>---write a character on a stream or file
21
22INDEX
23        fputc
24INDEX
25        fputc_unlocked
26INDEX
27        _fputc_r
28INDEX
29        _fputc_unlocked_r
30
31SYNOPSIS
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
45DESCRIPTION
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
50If the file was opened with append mode (or if the stream cannot
51support positioning), then the new character goes at the end of the
52file or stream.  Otherwise, the new character is written at the
53current value of the position indicator, and the position indicator
54oadvances by one.
55
56For 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
60protected by flockfile() (or ftrylockfile()) and funlockfile().  This
61function may safely be used in a multi-threaded program if and only
62if they are called while the invoking thread owns the (FILE *)
63object, as is the case after a successful call to the flockfile() or
64ftrylockfile() functions.  If threads are disabled, then
65<<fputc_unlocked>> is equivalent to <<fputc>>.
66
67The <<_fputc_r>> and <<_fputc_unlocked_r>> functions are simply reentrant
68versions of the above that take an additional reentrant structure
69argument: <[ptr]>.
70
71RETURNS
72If successful, <<fputc>> returns its argument <[ch]>.  If an error
73intervenes, the result is <<EOF>>.  You can use `<<ferror(<[fp]>)>>' to
74query for errors.
75
76PORTABILITY
77<<fputc>> is required by ANSI C.
78
79<<fputc_unlocked>> is a BSD extension also provided by GNU libc.
80
81Supporting 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
89int
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
103int
104fputc (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 */
Note: See TracBrowser for help on using the repository browser.