TizenRT Libs&Environment  v2.0 M2
stdio.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * include/stdio.h
20  *
21  * Copyright (C) 2007-2009, 2011, 2013-2014 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
64 
67 #ifndef __INCLUDE_STDIO_H
68 #define __INCLUDE_STDIO_H
69 
70 /****************************************************************************
71  * Included Files
72  ****************************************************************************/
73 
74 #include <tinyara/config.h>
75 
76 #include <sys/types.h>
77 #include <stdarg.h>
78 #include <sched.h>
79 #include <semaphore.h>
80 #include <time.h>
81 
82 #include <tinyara/fs/fs.h>
83 
84 /****************************************************************************
85  * Pre-processor Definitions
86  ****************************************************************************/
87 
88 /* File System Definitions **************************************************/
89 
90 #define FILENAME_MAX _POSIX_NAME_MAX
91 
92 /* The (default) size of the I/O buffers */
93 
94 #if (CONFIG_STDIO_BUFFER_SIZE > 0)
95 # define BUFSSIZ CONFIG_STDIO_BUFFER_SIZE
96 #else
97 # define BUFSSIZ 64
98 #endif
99 
100 /* The following three definitions are for ANSI C, used by setvbuf */
101 
102 #define _IOFBF 0 /* Fully buffered */
103 #define _IOLBF 1 /* Line buffered */
104 #define _IONBF 2 /* Unbuffered */
105 
106 /* File system error values *************************************************/
107 
108 #define EOF (-1)
109 
110 /* The first three _iob entries are reserved for standard I/O */
111 #if CONFIG_NFILE_DESCRIPTORS > 0 && CONFIG_NFILE_STREAMS > 0
112 #define stdin (&sched_getstreams()->sl_streams[0])
113 #define stdout (&sched_getstreams()->sl_streams[1])
114 #define stderr (&sched_getstreams()->sl_streams[2])
115 #else
116 #define stdin (NULL)
117 #define stdout (NULL)
118 #define stderr (NULL)
119 #endif
120 
121 /* These APIs are not implemented and/or can be synthesized from
122  * supported APIs.
123  */
124 
131 #define putc(c, s) fputc((c), (s))
132 
138 #define putchar(c) fputc(c, stdout)
139 
145 #define getc(s) fgetc(s)
146 
152 #define getchar() fgetc(stdin)
153 
157 #define rewind(s) ((void)fseek((s), 0, SEEK_SET))
158 
162 /* Path to the directory where temporary files can be created */
163 
164 #ifndef CONFIG_LIBC_TMPDIR
165 #define CONFIG_LIBC_TMPDIR "/tmp"
166 #endif
167 
168 #define P_tmpdir CONFIG_LIBC_TMPDIR
169 
170 /* Maximum size of character array to hold tmpnam() output. */
171 
172 #ifndef CONFIG_LIBC_MAX_TMPFILE
173 #define CONFIG_LIBC_MAX_TMPFILE 32
174 #endif
175 
176 #define L_tmpnam CONFIG_LIBC_MAX_TMPFILE
177 
178 /* the maximum number of unique temporary file names that can be generated */
179 
180 #define TMP_MAX 56800235584ull
181 
182 /****************************************************************************
183  * Public Type Definitions
184  ****************************************************************************/
185 
186 /* Streams */
187 
188 typedef struct file_struct FILE;
189 
190 /****************************************************************************
191  * Public Variables
192  ****************************************************************************/
193 
194 #undef EXTERN
195 #if defined(__cplusplus)
196 #define EXTERN extern "C"
197 extern "C" {
198 #else
199 #define EXTERN extern
200 #endif
201 
202 /****************************************************************************
203  * Public Function Prototypes
204  ****************************************************************************/
205 
206 /* ANSI-like File System Interfaces */
207 
208 /* Operations on streams (FILE) */
213 void clearerr(register FILE *stream);
223 int fclose(FAR FILE *stream);
230 int fflush(FAR FILE *stream);
237 int feof(FAR FILE *stream);
244 int ferror(FAR FILE *stream);
251 int fileno(FAR FILE *stream);
258 int fgetc(FAR FILE *stream);
265 int fgetpos(FAR FILE *stream, FAR fpos_t *pos);
272 char *fgets(FAR char *s, int n, FAR FILE *stream);
279 FAR FILE *fopen(FAR const char *path, FAR const char *type);
286 FAR FILE *freopen(FAR const char *path, FAR const char *mode, FAR FILE *stream);
293 void setbuf(FAR FILE *stream, FAR char *buf);
300 int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size);
307 int fprintf(FAR FILE *stream, FAR const char *format, ...);
314 int fputc(int c, FAR FILE *stream);
321 int fputs(FAR const char *s, FAR FILE *stream);
328 size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
335 int fseek(FAR FILE *stream, long int offset, int whence);
342 int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
349 long ftell(FAR FILE *stream);
356 size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream);
363 FAR char *gets(FAR char *s);
389 FAR char *gets_s(FAR char *s, rsize_t n);
396 int ungetc(int c, FAR FILE *stream);
397 
398 /* Operations on the stdout stream, buffers, paths, and the whole printf-family */
399 
406 int printf(FAR const char *format, ...);
413 int puts(FAR const char *s);
418 int rename(FAR const char *oldpath, FAR const char *newpath);
428 int sprintf(FAR char *buf, FAR const char *format, ...);
443 int asprintf(FAR char **ptr, FAR const char *fmt, ...);
450 int snprintf(FAR char *buf, size_t size, FAR const char *format, ...);
457 int sscanf(FAR const char *buf, FAR const char *fmt, ...);
464 void perror(FAR const char *s);
465 
472 int vprintf(FAR const char *format, va_list ap);
479 int vfprintf(FAR FILE *stream, const char *format, va_list ap);
486 int vsprintf(FAR char *buf, const char *format, va_list ap);
491 int vasprintf(FAR char **ptr, const char *fmt, va_list ap);
501 int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap);
508 int vsscanf(FAR const char *buf, FAR const char *s, va_list ap);
509 
510 /* Operations on file descriptors including:
511  *
512  * POSIX-like File System Interfaces (fdopen), and
513  * Extensions from the Open Group Technical Standard, 2006, Extended API Set
514  * Part 1 (dprintf and vdprintf)
515  */
522 FAR FILE *fdopen(int fd, FAR const char *type);
527 int dprintf(int fd, FAR const char *fmt, ...);
531 int vdprintf(int fd, FAR const char *fmt, va_list ap);
532 
533 /* Operations on paths */
537 FAR char *tmpnam(FAR char *s);
541 FAR char *tempnam(FAR const char *dir, FAR const char *pfx);
548 int remove(FAR const char *path);
549 
550 #undef EXTERN
551 #if defined(__cplusplus)
552 }
553 #endif
554 
555 #endif /* __INCLUDE_STDIO_H */
556 
size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream)
binary input
int ungetc(int c, FAR FILE *stream)
push byte back into input stream
int sscanf(FAR const char *buf, FAR const char *fmt,...)
convert formatted input
int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
assign buffering to a stream
FAR char * gets_s(FAR char *s, rsize_t n)
reads a line from stdin into the buffer
int vprintf(FAR const char *format, va_list ap)
format output of a stdarg argument list
int fflush(FAR FILE *stream)
flush a stream
int ferror(FAR FILE *stream)
test error indicator on a stream
int fclose(FAR FILE *stream)
close a stream
int fseek(FAR FILE *stream, long int offset, int whence)
reposition a file-position indicator in a stream
int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap)
format output of a stdarg argument list
void perror(FAR const char *s)
write error messages to standard error
int puts(FAR const char *s)
put a string on standard output
int fprintf(FAR FILE *stream, FAR const char *format,...)
print formatted output
int asprintf(FAR char **ptr, FAR const char *fmt,...)
print formatted output
int printf(FAR const char *format,...)
print formatted output
FAR FILE * freopen(FAR const char *path, FAR const char *mode, FAR FILE *stream)
open a stream
int fgetc(FAR FILE *stream)
get a byte from a stream
FAR FILE * fdopen(int fd, FAR const char *type)
associate a stream with a file descriptor
int fputc(int c, FAR FILE *stream)
put a byte on a stream
int vfprintf(FAR FILE *stream, const char *format, va_list ap)
format output of a stdarg argument list
long ftell(FAR FILE *stream)
return a file offset in a stream
int vsscanf(FAR const char *buf, FAR const char *s, va_list ap)
format input of a stdarg argument list
int snprintf(FAR char *buf, size_t size, FAR const char *format,...)
print formatted output
FAR FILE * fopen(FAR const char *path, FAR const char *type)
open a stream
struct file_struct FILE
Definition: stdio.h:188
Semaphore APIs.
int fsetpos(FAR FILE *stream, FAR fpos_t *pos)
set current file position
void setbuf(FAR FILE *stream, FAR char *buf)
assign buffering to a stream
int fileno(FAR FILE *stream)
map a stream pointer to a file descriptor
FAR char * gets(FAR char *s)
get a string from a stdin stream
int fgetpos(FAR FILE *stream, FAR fpos_t *pos)
get current file position information
int sprintf(FAR char *buf, FAR const char *format,...)
print formatted output
size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream)
binary output
char * fgets(FAR char *s, int n, FAR FILE *stream)
get a string from a stream
int feof(FAR FILE *stream)
test end-of-file indicator on a stream
int fputs(FAR const char *s, FAR FILE *stream)
put a string on a stream
int vsprintf(FAR char *buf, const char *format, va_list ap)
format output of a stdarg argument list