* include/stdio.h
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_STDIO_H
#define __INCLUDE_STDIO_H
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdarg.h>
#include <time.h>
#include <nuttx/fs/fs.h>
#include <nuttx/lib/lib.h>
* Pre-processor Definitions
****************************************************************************/
#define FILENAME_MAX _POSIX_NAME_MAX
#define FOPEN_MAX _POSIX_STREAM_MAX
#if defined(CONFIG_STDIO_BUFFER_SIZE) && CONFIG_STDIO_BUFFER_SIZE > 0
# define BUFSIZ CONFIG_STDIO_BUFFER_SIZE
#else
# define BUFSIZ 64
#endif
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
#define EOF (-1)
#define stdin lib_get_stream(0)
#define stdout lib_get_stream(1)
#define stderr lib_get_stream(2)
#ifndef CONFIG_LIBC_TMPDIR
# define CONFIG_LIBC_TMPDIR "/tmp"
#endif
#define P_tmpdir CONFIG_LIBC_TMPDIR
#ifndef CONFIG_LIBC_MAX_TMPFILE
# define CONFIG_LIBC_MAX_TMPFILE 32
#endif
#define L_tmpnam CONFIG_LIBC_MAX_TMPFILE
#define TMP_MAX 308915776
#if defined(CONFIG_FS_LARGEFILE)
# define tmpfile64 tmpfile
# define fopen64 fopen
# define freopen64 freopen
# define fseeko64 fseeko
# define ftello64 ftello
# define fgetpos64 fgetpos
# define fsetpos64 fsetpos
#endif
#define setlinebuf(stream) setvbuf(stream, NULL, _IOLBF, 0)
#define feof_unlocked(stream) feof(stream)
#define ferror_unlocked(stream) ferror(stream)
#define fileno_unlocked(stream) fileno(stream)
* Public Type Definitions
****************************************************************************/
typedef struct file_struct FILE;
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
* Public Function Prototypes
****************************************************************************/
void clearerr(FAR FILE *);
void clearerr_unlocked(FAR FILE *);
int fclose(FAR FILE *);
int fflush(FAR FILE *);
int fflush_unlocked(FAR FILE *);
int feof(FAR FILE *);
int ferror(FAR FILE *);
int fileno(FAR FILE *);
int fgetc(FAR FILE *);
int fgetc_unlocked(FAR FILE *);
int fgetpos(FAR FILE *, FAR fpos_t *);
FAR char *fgets(FAR char *, int, FAR FILE *);
FAR char *fgets_unlocked(FAR char *, int, FAR FILE *);
FAR FILE *fopen(FAR const char *, FAR const char *) fopen_like;
int fprintf(FAR FILE *, FAR const IPTR char *, ...)
printf_like(2, 3);
int fputc(int, FAR FILE *);
int fputc_unlocked(int, FAR FILE *);
int fputs(FAR const IPTR char *, FAR FILE *);
int fputs_unlocked(FAR const IPTR char *, FAR FILE *);
size_t fread(FAR void *, size_t, size_t, FAR FILE *);
size_t fread_unlocked(FAR void *, size_t, size_t,
FAR FILE *);
FAR FILE *freopen(FAR const char *, FAR const char *,
FAR FILE *);
int fscanf(FAR FILE *, FAR const IPTR char *, ...)
scanf_like(2, 3);
int fseek(FAR FILE *, long int, int);
int fseeko(FAR FILE *, off_t, int);
int fsetpos(FAR FILE *, FAR const fpos_t *);
long ftell(FAR FILE *);
off_t ftello(FAR FILE *);
size_t fwrite(FAR const void *, size_t, size_t, FAR FILE *);
size_t fwrite_unlocked(FAR const void *, size_t, size_t, FAR FILE *);
int getc(FAR FILE *);
int getc_unlocked(FAR FILE *);
int getchar(void);
int getchar_unlocked(void);
ssize_t getdelim(FAR char **, size_t *, int, FAR FILE *);
ssize_t getline(FAR char **, size_t *, FAR FILE *);
FAR char *gets(FAR char *);
FAR char *gets_s(FAR char *, rsize_t);
void rewind(FAR FILE *);
void setbuf(FAR FILE *, FAR char *);
int setvbuf(FAR FILE *, FAR char *, int, size_t);
void setbuffer(FAR FILE *, FAR char *, size_t);
int ungetc(int, FAR FILE *);
void flockfile(FAR FILE *);
int ftrylockfile(FAR FILE *);
void funlockfile(FAR FILE *);
* and the whole printf-family
*/
void perror(FAR const char *);
int printf(FAR const IPTR char *, ...) printf_like(1, 2);
int putc(int, FAR FILE *);
int putc_unlocked(int, FAR FILE *);
int putchar(int);
int putchar_unlocked(int);
int puts(FAR const IPTR char *);
int rename(FAR const char *, FAR const char *);
int renameat(int, FAR const char *,
int, FAR const char *);
int sprintf(FAR char *, FAR const IPTR char *, ...)
printf_like(2, 3);
int asprintf(FAR char **, FAR const IPTR char *, ...)
printf_like(2, 3);
int snprintf(FAR char *, size_t,
FAR const IPTR char *, ...) printf_like(3, 4);
int sscanf(FAR const char *, FAR const IPTR char *, ...)
scanf_like(2, 3);
int scanf(FAR const IPTR char *, ...) scanf_like(1, 2);
int vasprintf(FAR char **, FAR const IPTR char *, va_list)
printf_like(2, 0);
int vfprintf(FAR FILE *, FAR const IPTR char *,
va_list) printf_like(2, 0);
int vfscanf(FAR FILE *, FAR const IPTR char *, va_list)
scanf_like(2, 0);
int vprintf(FAR const IPTR char *, va_list) printf_like(1, 0);
int vscanf(FAR const IPTR char *, va_list) scanf_like(1, 0);
int vsnprintf(FAR char *, size_t, FAR const IPTR char *,
va_list) printf_like(3, 0);
int vsprintf(FAR char *, FAR const IPTR char *, va_list)
printf_like(2, 0);
int vsscanf(FAR const char *, FAR const IPTR char *, va_list)
scanf_like(2, 0);
*
* POSIX-like File System Interfaces (fdopen), and
* Extensions from the Open Group Technical Standard, 2006, Extended API Set
* Part 1 (dprintf and vdprintf)
*/
FAR FILE *fdopen(int, FAR const char *) fopen_like;
int dprintf(int, FAR const IPTR char *, ...) printf_like(2, 3);
int vdprintf(int, FAR const IPTR char *, va_list)
printf_like(2, 0);
FAR FILE *fopencookie(FAR void *, FAR const char *,
cookie_io_functions_t);
FAR FILE *fmemopen(FAR void *, size_t, FAR const char *);
FAR FILE *open_memstream(FAR char **, FAR size_t *);
FAR FILE *tmpfile(void) fopen_like;
FAR char *tmpnam(FAR char *);
FAR char *tempnam(FAR const char *, FAR const char *) malloc_like;
int remove(FAR const char *);
* apps/system/popen for implementation.
*/
#ifndef __KERNEL__
int pclose(FILE *);
FILE *popen(FAR const char *, FAR const char *) popen_like;
#else
#define asprintf(p, f, ...) nx_asprintf(p, f, ##__VA_ARGS__)
#define vasprintf(p, f, a) nx_vasprintf(p, f, a)
#endif
int nx_asprintf(FAR char **, FAR const IPTR char *, ...)
printf_like(2, 3);
int nx_vasprintf(FAR char **, FAR const IPTR char *, va_list)
printf_like(2, 0);
#if CONFIG_FORTIFY_SOURCE > 0
fortify_function(fgets) FAR char *fgets(FAR char *s, int n, FAR FILE *stream)
{
fortify_assert((size_t)n <= fortify_size(s, 0));
return __real_fgets(s, n, stream);
}
fortify_function(fread) size_t fread(FAR void *ptr, size_t size,
size_t n_items, FAR FILE *stream)
{
fortify_assert(n_items == 0 || (n_items * size) / n_items == size);
fortify_assert(n_items * size <= fortify_size(ptr, 0));
return __real_fread(ptr, size, n_items, stream);
}
fortify_function(fwrite) size_t fwrite(FAR const void *ptr, size_t size,
size_t n_items, FAR FILE *stream)
{
fortify_assert(n_items == 0 || (n_items * size) / n_items == size);
fortify_assert(n_items * size <= fortify_size(ptr, 0));
return __real_fwrite(ptr, size, n_items, stream);
}
fortify_function(vsnprintf) int vsnprintf(FAR char *buf, size_t size,
FAR const IPTR char *format,
va_list ap)
{
fortify_assert(size <= fortify_size(buf, 0));
return __real_vsnprintf(buf, size, format, ap);
}
fortify_function(vsprintf) int vsprintf(FAR char *dest,
FAR const IPTR char *src,
va_list ap)
{
int ret;
ret = __real_vsprintf(dest, src, ap);
fortify_assert(ret == -1 || (size_t)ret <= fortify_size(dest, 0));
return ret;
}
#ifdef fortify_va_arg_pack
fortify_function(snprintf) int snprintf(FAR char *buf, size_t size,
FAR const IPTR char *format, ...)
{
fortify_assert(size <= fortify_size(buf, 0));
return __real_snprintf(buf, size, format, fortify_va_arg_pack());
}
fortify_function(sprintf) int sprintf(FAR char *buf,
FAR const IPTR char *fmt,
...)
{
int ret;
ret = __real_sprintf(buf, fmt, fortify_va_arg_pack());
fortify_assert(ret == -1 || (size_t)ret <= fortify_size(buf, 0));
return ret;
}
#endif
#endif
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif