Tizen RT Libs&Environment  v1.1 D4
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 
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 
116 /* These APIs are not implemented and/or can be synthesized from
117  * supported APIs.
118  */
119 
126 #define putc(c, s) fputc((c), (s))
127 
133 #define putchar(c) fputc(c, stdout)
134 
140 #define getc(s) fgetc(s)
141 
147 #define getchar() fgetc(stdin)
148 
152 #define rewind(s) ((void)fseek((s), 0, SEEK_SET))
153 
157 /* Path to the directory where temporary files can be created */
158 
159 #ifndef CONFIG_LIBC_TMPDIR
160 #define CONFIG_LIBC_TMPDIR "/tmp"
161 #endif
162 
163 #define P_tmpdir CONFIG_LIBC_TMPDIR
164 
165 /* Maximum size of character array to hold tmpnam() output. */
166 
167 #ifndef CONFIG_LIBC_MAX_TMPFILE
168 #define CONFIG_LIBC_MAX_TMPFILE 32
169 #endif
170 
171 #define L_tmpnam CONFIG_LIBC_MAX_TMPFILE
172 
173 /* the maximum number of unique temporary file names that can be generated */
174 
175 #define TMP_MAX 56800235584ull
176 
177 /****************************************************************************
178  * Public Type Definitions
179  ****************************************************************************/
180 
181 /* Streams */
182 
183 typedef struct file_struct FILE;
184 
185 /****************************************************************************
186  * Public Variables
187  ****************************************************************************/
188 
189 #undef EXTERN
190 #if defined(__cplusplus)
191 #define EXTERN extern "C"
192 extern "C" {
193 #else
194 #define EXTERN extern
195 #endif
196 
197 /****************************************************************************
198  * Public Function Prototypes
199  ****************************************************************************/
200 
201 /* ANSI-like File System Interfaces */
202 
203 /* Operations on streams (FILE) */
208 void clearerr(register FILE *stream);
218 int fclose(FAR FILE *stream);
225 int fflush(FAR FILE *stream);
232 int feof(FAR FILE *stream);
239 int ferror(FAR FILE *stream);
246 int fileno(FAR FILE *stream);
253 int fgetc(FAR FILE *stream);
260 int fgetpos(FAR FILE *stream, FAR fpos_t *pos);
267 char *fgets(FAR char *s, int n, FAR FILE *stream);
274 FAR FILE *fopen(FAR const char *path, FAR const char *type);
281 FAR FILE *freopen(FAR const char *path, FAR const char *mode, FAR FILE *stream);
288 void setbuf(FAR FILE *stream, FAR char *buf);
295 int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size);
302 int fprintf(FAR FILE *stream, FAR const char *format, ...);
309 int fputc(int c, FAR FILE *stream);
316 int fputs(FAR const char *s, FAR FILE *stream);
323 size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
330 int fseek(FAR FILE *stream, long int offset, int whence);
337 int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
344 long ftell(FAR FILE *stream);
351 size_t fwrite(FAR const void *ptr, size_t size, size_t n_items, FAR FILE *stream);
358 FAR char *gets(FAR char *s);
384 FAR char *gets_s(FAR char *s, rsize_t n);
391 int ungetc(int c, FAR FILE *stream);
392 
393 /* Operations on the stdout stream, buffers, paths, and the whole printf-family */
394 
401 int printf(FAR const char *format, ...);
408 int puts(FAR const char *s);
413 int rename(FAR const char *oldpath, FAR const char *newpath);
423 int sprintf(FAR char *buf, FAR const char *format, ...);
438 int asprintf(FAR char **ptr, FAR const char *fmt, ...);
445 int snprintf(FAR char *buf, size_t size, FAR const char *format, ...);
452 int sscanf(FAR const char *buf, FAR const char *fmt, ...);
459 void perror(FAR const char *s);
460 
467 int vprintf(FAR const char *format, va_list ap);
474 int vfprintf(FAR FILE *stream, const char *format, va_list ap);
481 int vsprintf(FAR char *buf, const char *format, va_list ap);
486 int avsprintf(FAR char **ptr, const char *fmt, va_list ap);
496 int vsnprintf(FAR char *buf, size_t size, const char *format, va_list ap);
503 int vsscanf(FAR const char *buf, FAR const char *s, va_list ap);
504 
505 /* Operations on file descriptors including:
506  *
507  * POSIX-like File System Interfaces (fdopen), and
508  * Extensions from the Open Group Technical Standard, 2006, Extended API Set
509  * Part 1 (dprintf and vdprintf)
510  */
517 FAR FILE *fdopen(int fd, FAR const char *type);
522 int dprintf(int fd, FAR const char *fmt, ...);
526 int vdprintf(int fd, FAR const char *fmt, va_list ap);
527 
528 /* Operations on paths */
532 FAR char *tmpnam(FAR char *s);
536 FAR char *tempnam(FAR const char *dir, FAR const char *pfx);
543 int remove(FAR const char *path);
544 
545 #undef EXTERN
546 #if defined(__cplusplus)
547 }
548 #endif
549 
550 #endif /* __INCLUDE_STDIO_H */
551 
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:183
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