2008-09-01 22:35:41 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* include/stdio.h
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* 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
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2021-02-03 11:33:49 +01:00
|
|
|
* 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.
|
2007-02-18 00:21:28 +01:00
|
|
|
*
|
2008-09-01 22:35:41 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2009-07-12 22:48:44 +02:00
|
|
|
#ifndef __INCLUDE_STDIO_H
|
|
|
|
#define __INCLUDE_STDIO_H
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-09-01 22:35:41 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Included Files
|
2008-09-01 22:35:41 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2007-12-31 00:34:20 +01:00
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2012-03-21 19:01:07 +01:00
|
|
|
#include <nuttx/fs/fs.h>
|
2022-12-21 14:13:14 +01:00
|
|
|
#include <nuttx/lib/lib.h>
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-09-01 22:35:41 +02:00
|
|
|
/****************************************************************************
|
2009-12-15 00:32:23 +01:00
|
|
|
* Pre-processor Definitions
|
2008-09-01 22:35:41 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2008-09-01 22:35:41 +02:00
|
|
|
/* File System Definitions **************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-08-12 14:18:22 +02:00
|
|
|
#define FILENAME_MAX _POSIX_NAME_MAX
|
2022-12-12 10:26:06 +01:00
|
|
|
#define FOPEN_MAX _POSIX_STREAM_MAX
|
2014-08-12 14:18:22 +02:00
|
|
|
|
2017-02-09 16:24:44 +01:00
|
|
|
/* The (default) size of the I/O buffers */
|
2015-11-18 21:09:43 +01:00
|
|
|
|
2017-02-09 16:24:44 +01:00
|
|
|
#if defined(CONFIG_STDIO_BUFFER_SIZE) && CONFIG_STDIO_BUFFER_SIZE > 0
|
|
|
|
# define BUFSIZ CONFIG_STDIO_BUFFER_SIZE
|
|
|
|
#else
|
|
|
|
# define BUFSIZ 64
|
2015-11-18 21:09:43 +01:00
|
|
|
#endif
|
|
|
|
|
2017-02-08 17:33:18 +01:00
|
|
|
/* The following three definitions are for ANSI C, used by setvbuf */
|
|
|
|
|
|
|
|
#define _IOFBF 0 /* Fully buffered */
|
|
|
|
#define _IOLBF 1 /* Line buffered */
|
|
|
|
#define _IONBF 2 /* Unbuffered */
|
|
|
|
|
2015-11-18 21:09:43 +01:00
|
|
|
/* File system error values */
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#define EOF (-1)
|
|
|
|
|
|
|
|
/* The first three _iob entries are reserved for standard I/O */
|
|
|
|
|
2023-03-02 05:53:29 +01:00
|
|
|
#define stdin lib_get_stream(0)
|
|
|
|
#define stdout lib_get_stream(1)
|
|
|
|
#define stderr lib_get_stream(2)
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2014-11-05 17:43:17 +01:00
|
|
|
/* Path to the directory where temporary files can be created */
|
|
|
|
|
|
|
|
#ifndef CONFIG_LIBC_TMPDIR
|
|
|
|
# define CONFIG_LIBC_TMPDIR "/tmp"
|
|
|
|
#endif
|
|
|
|
|
2017-02-08 17:33:18 +01:00
|
|
|
#define P_tmpdir CONFIG_LIBC_TMPDIR
|
2014-11-05 17:43:17 +01:00
|
|
|
|
|
|
|
/* Maximum size of character array to hold tmpnam() output. */
|
|
|
|
|
|
|
|
#ifndef CONFIG_LIBC_MAX_TMPFILE
|
|
|
|
# define CONFIG_LIBC_MAX_TMPFILE 32
|
|
|
|
#endif
|
|
|
|
|
2017-02-08 17:33:18 +01:00
|
|
|
#define L_tmpnam CONFIG_LIBC_MAX_TMPFILE
|
2014-11-05 17:43:17 +01:00
|
|
|
|
2015-11-18 21:09:43 +01:00
|
|
|
/* The maximum number of unique temporary file names that can be generated */
|
2014-11-05 17:43:17 +01:00
|
|
|
|
|
|
|
#define TMP_MAX 56800235584ull
|
|
|
|
|
2023-02-25 09:02:11 +01:00
|
|
|
#if defined(CONFIG_FS_LARGEFILE)
|
2021-07-21 05:46:21 +02:00
|
|
|
# define tmpfile64 tmpfile
|
|
|
|
# define fopen64 fopen
|
|
|
|
# define freopen64 freopen
|
|
|
|
# define fseeko64 fseeko
|
|
|
|
# define ftello64 ftello
|
|
|
|
# define fgetpos64 fgetpos
|
|
|
|
# define fsetpos64 fsetpos
|
|
|
|
#endif
|
|
|
|
|
2021-11-26 10:52:57 +01:00
|
|
|
#define setlinebuf(stream) setvbuf(stream, NULL, _IOLBF, 0)
|
|
|
|
|
2008-09-01 22:35:41 +02:00
|
|
|
/****************************************************************************
|
2007-02-18 00:21:28 +01:00
|
|
|
* Public Type Definitions
|
2008-09-01 22:35:41 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
/* Streams */
|
|
|
|
|
2008-11-07 19:16:01 +01:00
|
|
|
typedef struct file_struct FILE;
|
2007-02-18 00:21:28 +01:00
|
|
|
|
lib_vsprintf: Add %pV format support
test case:
void test(const char *fmt, ...)
{
struct va_format vaf;
va_list ap;
va_start(ap, fmt);
vaf.fmt = fmt;
vaf.va = ≈
printf("func:%s, %pV, line:%d\n", __func__, &vaf, __LINE__);
va_end(ap);
}
int main(int argc, FAR char *argv[])
{
char str[] = "Hello Boy and Girl!";
int count = 10;
test("%s %d", str, count);
return 0;
}
>> test
func:test, Hello Boy and Girl! 10, line:49
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-08-24 16:14:23 +02:00
|
|
|
struct va_format
|
|
|
|
{
|
|
|
|
FAR const char *fmt;
|
|
|
|
FAR va_list *va;
|
|
|
|
};
|
|
|
|
|
2008-09-01 22:35:41 +02:00
|
|
|
/****************************************************************************
|
2015-10-03 00:30:35 +02:00
|
|
|
* Public Data
|
2008-09-01 22:35:41 +02:00
|
|
|
****************************************************************************/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
#define EXTERN extern "C"
|
2013-03-09 22:12:20 +01:00
|
|
|
extern "C"
|
|
|
|
{
|
2007-02-18 00:21:28 +01:00
|
|
|
#else
|
|
|
|
#define EXTERN extern
|
|
|
|
#endif
|
|
|
|
|
2013-03-09 22:12:20 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Function Prototypes
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
/* ANSI-like File System Interfaces */
|
|
|
|
|
2012-11-01 16:00:26 +01:00
|
|
|
/* Operations on streams (FILE) */
|
|
|
|
|
2020-05-06 11:24:42 +02:00
|
|
|
void clearerr(FAR FILE *stream);
|
2013-03-09 22:12:20 +01:00
|
|
|
int fclose(FAR FILE *stream);
|
|
|
|
int fflush(FAR FILE *stream);
|
|
|
|
int feof(FAR FILE *stream);
|
|
|
|
int ferror(FAR FILE *stream);
|
|
|
|
int fileno(FAR FILE *stream);
|
|
|
|
int fgetc(FAR FILE *stream);
|
|
|
|
int fgetpos(FAR FILE *stream, FAR fpos_t *pos);
|
2020-05-06 11:24:42 +02:00
|
|
|
FAR char *fgets(FAR char *s, int n, FAR FILE *stream);
|
2022-12-17 12:32:54 +01:00
|
|
|
FAR FILE *fopen(FAR const char *path, FAR const char *type) fopen_like;
|
2020-11-05 09:07:40 +01:00
|
|
|
int fprintf(FAR FILE *stream, FAR const IPTR char *format, ...)
|
2022-12-12 08:43:47 +01:00
|
|
|
printf_like(2, 3);
|
2013-03-09 22:12:20 +01:00
|
|
|
int fputc(int c, FAR FILE *stream);
|
2020-06-02 20:57:39 +02:00
|
|
|
int fputs(FAR const IPTR char *s, FAR FILE *stream);
|
2013-03-09 22:12:20 +01:00
|
|
|
size_t fread(FAR void *ptr, size_t size, size_t n_items, FAR FILE *stream);
|
2016-01-05 17:29:29 +01:00
|
|
|
FAR FILE *freopen(FAR const char *path, FAR const char *mode,
|
|
|
|
FAR FILE *stream);
|
2020-11-17 07:46:24 +01:00
|
|
|
int fscanf(FAR FILE *stream, FAR const IPTR char *fmt, ...)
|
2022-12-12 08:43:47 +01:00
|
|
|
scanf_like(2, 3);
|
2013-03-09 22:12:20 +01:00
|
|
|
int fseek(FAR FILE *stream, long int offset, int whence);
|
2020-06-26 08:40:13 +02:00
|
|
|
int fseeko(FAR FILE *stream, off_t offset, int whence);
|
2013-03-09 22:12:20 +01:00
|
|
|
int fsetpos(FAR FILE *stream, FAR fpos_t *pos);
|
|
|
|
long ftell(FAR FILE *stream);
|
2020-06-26 08:40:13 +02:00
|
|
|
off_t ftello(FAR FILE *stream);
|
2016-01-05 17:29:29 +01:00
|
|
|
size_t fwrite(FAR const void *ptr, size_t size, size_t n_items,
|
|
|
|
FAR FILE *stream);
|
2020-06-26 08:40:13 +02:00
|
|
|
int getc(FAR FILE *stream);
|
|
|
|
int getchar(void);
|
2019-11-13 01:58:50 +01:00
|
|
|
ssize_t getdelim(FAR char **lineptr, size_t *n, int delimiter,
|
|
|
|
FAR FILE *stream);
|
|
|
|
ssize_t getline(FAR char **lineptr, size_t *n, FAR FILE *stream);
|
2013-03-09 22:12:20 +01:00
|
|
|
FAR char *gets(FAR char *s);
|
2014-01-07 23:27:45 +01:00
|
|
|
FAR char *gets_s(FAR char *s, rsize_t n);
|
2020-06-24 06:54:30 +02:00
|
|
|
void rewind(FAR FILE *stream);
|
2020-07-19 17:23:26 +02:00
|
|
|
|
2017-02-09 22:04:17 +01:00
|
|
|
void setbuf(FAR FILE *stream, FAR char *buf);
|
2017-02-08 17:33:18 +01:00
|
|
|
int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size);
|
2020-07-19 17:23:26 +02:00
|
|
|
|
2013-03-09 22:12:20 +01:00
|
|
|
int ungetc(int c, FAR FILE *stream);
|
2012-11-01 16:00:26 +01:00
|
|
|
|
2022-04-25 18:13:41 +02:00
|
|
|
void flockfile(FAR FILE *stream);
|
|
|
|
int ftrylockfile(FAR FILE *stream);
|
|
|
|
void funlockfile(FAR FILE *stream);
|
|
|
|
|
2020-04-30 20:43:08 +02:00
|
|
|
/* Operations on the stdout stream, buffers, paths,
|
|
|
|
* and the whole printf-family
|
|
|
|
*/
|
2007-03-10 01:17:29 +01:00
|
|
|
|
2019-02-16 00:31:58 +01:00
|
|
|
void perror(FAR const char *s);
|
2022-12-12 08:43:47 +01:00
|
|
|
int printf(FAR const IPTR char *fmt, ...) printf_like(1, 2);
|
2020-06-26 08:40:13 +02:00
|
|
|
int putc(int c, FAR FILE *stream);
|
|
|
|
int putchar(int c);
|
2020-06-02 20:57:39 +02:00
|
|
|
int puts(FAR const IPTR char *s);
|
2013-03-09 22:12:20 +01:00
|
|
|
int rename(FAR const char *oldpath, FAR const char *newpath);
|
2023-02-04 02:00:49 +01:00
|
|
|
int renameat(int olddirfd, FAR const char *oldpath,
|
|
|
|
int newdirfd, FAR const char *newpath);
|
2020-11-05 09:07:40 +01:00
|
|
|
int sprintf(FAR char *buf, FAR const IPTR char *fmt, ...)
|
2022-12-12 08:43:47 +01:00
|
|
|
printf_like(2, 3);
|
2020-11-05 09:07:40 +01:00
|
|
|
int asprintf(FAR char **ptr, FAR const IPTR char *fmt, ...)
|
2022-12-12 08:43:47 +01:00
|
|
|
printf_like(2, 3);
|
2016-01-05 17:29:29 +01:00
|
|
|
int snprintf(FAR char *buf, size_t size,
|
2022-12-12 08:43:47 +01:00
|
|
|
FAR const IPTR char *fmt, ...) printf_like(3, 4);
|
2020-11-17 07:46:24 +01:00
|
|
|
int sscanf(FAR const char *buf, FAR const IPTR char *fmt, ...)
|
2022-12-12 08:43:47 +01:00
|
|
|
scanf_like(2, 3);
|
2013-03-09 22:12:20 +01:00
|
|
|
|
2022-12-12 08:43:47 +01:00
|
|
|
int scanf(FAR const IPTR char *fmt, ...) scanf_like(1, 2);
|
2020-11-05 09:07:40 +01:00
|
|
|
int vasprintf(FAR char **ptr, FAR const IPTR char *fmt, va_list ap)
|
2022-12-12 08:43:47 +01:00
|
|
|
printf_like(2, 0);
|
2019-02-16 00:31:58 +01:00
|
|
|
int vfprintf(FAR FILE *stream, FAR const IPTR char *fmt,
|
2022-12-12 08:43:47 +01:00
|
|
|
va_list ap) printf_like(2, 0);
|
2020-11-17 07:46:24 +01:00
|
|
|
int vfscanf(FAR FILE *stream, FAR const IPTR char *fmt, va_list ap)
|
2022-12-12 08:43:47 +01:00
|
|
|
scanf_like(2, 0);
|
|
|
|
int vprintf(FAR const IPTR char *fmt, va_list ap) printf_like(1, 0);
|
|
|
|
int vscanf(FAR const IPTR char *fmt, va_list ap) scanf_like(1, 0);
|
2019-02-16 00:31:58 +01:00
|
|
|
int vsnprintf(FAR char *buf, size_t size, FAR const IPTR char *fmt,
|
2022-12-12 08:43:47 +01:00
|
|
|
va_list ap) printf_like(3, 0);
|
2020-11-05 09:07:40 +01:00
|
|
|
int vsprintf(FAR char *buf, FAR const IPTR char *fmt, va_list ap)
|
2022-12-12 08:43:47 +01:00
|
|
|
printf_like(2, 0);
|
2020-11-17 07:46:24 +01:00
|
|
|
int vsscanf(FAR const char *buf, FAR const IPTR char *fmt, va_list ap)
|
2022-12-12 08:43:47 +01:00
|
|
|
scanf_like(2, 0);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2013-06-02 23:49:52 +02:00
|
|
|
/* Operations on file descriptors including:
|
|
|
|
*
|
|
|
|
* POSIX-like File System Interfaces (fdopen), and
|
|
|
|
* Extensions from the Open Group Technical Standard, 2006, Extended API Set
|
|
|
|
* Part 1 (dprintf and vdprintf)
|
|
|
|
*/
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2022-12-17 12:32:54 +01:00
|
|
|
FAR FILE *fdopen(int fd, FAR const char *type) fopen_like;
|
2022-12-12 08:43:47 +01:00
|
|
|
int dprintf(int fd, FAR const IPTR char *fmt, ...) printf_like(2, 3);
|
2020-11-05 09:07:40 +01:00
|
|
|
int vdprintf(int fd, FAR const IPTR char *fmt, va_list ap)
|
2022-12-12 08:43:47 +01:00
|
|
|
printf_like(2, 0);
|
2013-06-02 23:49:52 +02:00
|
|
|
|
|
|
|
/* Operations on paths */
|
|
|
|
|
2022-12-17 12:32:54 +01:00
|
|
|
FAR FILE *tmpfile(void) fopen_like;
|
2014-11-05 17:43:17 +01:00
|
|
|
FAR char *tmpnam(FAR char *s);
|
2022-12-12 09:03:43 +01:00
|
|
|
FAR char *tempnam(FAR const char *dir, FAR const char *pfx) malloc_like;
|
2016-08-25 16:40:34 +02:00
|
|
|
int remove(FAR const char *path);
|
2007-02-18 00:21:28 +01:00
|
|
|
|
2018-08-17 18:40:59 +02:00
|
|
|
/* Shell operations. These are not actually implemented in the OS. See
|
2020-04-29 21:21:23 +02:00
|
|
|
* apps/system/popen for implementation.
|
2018-08-17 18:40:59 +02:00
|
|
|
*/
|
|
|
|
|
2020-04-29 21:21:23 +02:00
|
|
|
#ifndef __KERNEL__
|
2018-08-17 18:40:59 +02:00
|
|
|
int pclose(FILE *stream);
|
2022-12-17 12:32:54 +01:00
|
|
|
FILE *popen(FAR const char *command, FAR const char *mode) popen_like;
|
2018-08-17 18:40:59 +02:00
|
|
|
#endif
|
|
|
|
|
2007-02-18 00:21:28 +01:00
|
|
|
#undef EXTERN
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-07-12 22:48:44 +02:00
|
|
|
#endif /* __INCLUDE_STDIO_H */
|