Skip to content

Commit

Permalink
stdio.h:Remove unnecessary header file
Browse files Browse the repository at this point in the history
Signed-off-by: anjiahao <[email protected]>
  • Loading branch information
anjiahao1 committed Nov 8, 2024
1 parent db31e56 commit 4641d63
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 36 deletions.
29 changes: 1 addition & 28 deletions include/nuttx/fs/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

#include <sys/uio.h>
#include <sys/types.h>

#include <stdio.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdbool.h>
Expand Down Expand Up @@ -424,33 +424,6 @@ struct inode

#define FSNODE_SIZE(n) (sizeof(struct inode) + (n))

/* Definitions for custom stream operations with fopencookie. The
* implementation is as defined in Standard C library (libc). The only
* difference is that we use off_t instead of off64_t. This means
* off_t is int64_t if CONFIG_FS_LARGEFILE is defined and int32_t if not.
*
* These callbacks can either lead to custom functions if fopencookie is used
* or to standard file system functions if not.
*/

typedef CODE ssize_t cookie_read_function_t(FAR void *cookie, FAR char *buf,
size_t size);
typedef CODE ssize_t cookie_write_function_t(FAR void *cookie,
FAR const char *buf,
size_t size);
typedef CODE off_t cookie_seek_function_t(FAR void *cookie,
FAR off_t *offset,
int whence);
typedef CODE int cookie_close_function_t(FAR void *cookie);

typedef struct cookie_io_functions_t
{
FAR cookie_read_function_t *read;
FAR cookie_write_function_t *write;
FAR cookie_seek_function_t *seek;
FAR cookie_close_function_t *close;
} cookie_io_functions_t;

/* This is the underlying representation of an open file. A file
* descriptor is an index into an array of such types. The type associates
* the file descriptor to the file state and to a set of inode operations.
Expand Down
38 changes: 32 additions & 6 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
#include <stdarg.h>
#include <time.h>

#include <nuttx/fs/fs.h>
#include <nuttx/lib/lib.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down Expand Up @@ -65,9 +62,9 @@

/* The first three _iob entries are reserved for standard I/O */

#define stdin lib_get_stream(0)
#define stdout lib_get_stream(1)
#define stderr lib_get_stream(2)
#define stdin lib_get_stdio_stream(0)
#define stdout lib_get_stdio_stream(1)
#define stderr lib_get_stdio_stream(2)

/* Path to the directory where temporary files can be created */

Expand Down Expand Up @@ -126,6 +123,33 @@ extern "C"
#define EXTERN extern
#endif

/* Definitions for custom stream operations with fopencookie. The
* implementation is as defined in Standard C library (libc). The only
* difference is that we use off_t instead of off64_t. This means
* off_t is int64_t if CONFIG_FS_LARGEFILE is defined and int32_t if not.
*
* These callbacks can either lead to custom functions if fopencookie is used
* or to standard file system functions if not.
*/

typedef CODE ssize_t cookie_read_function_t(FAR void *cookie, FAR char *buf,
size_t size);
typedef CODE ssize_t cookie_write_function_t(FAR void *cookie,
FAR const char *buf,
size_t size);
typedef CODE off_t cookie_seek_function_t(FAR void *cookie,
FAR off_t *offset,
int whence);
typedef CODE int cookie_close_function_t(FAR void *cookie);

typedef struct cookie_io_functions_t
{
FAR cookie_read_function_t *read;
FAR cookie_write_function_t *write;
FAR cookie_seek_function_t *seek;
FAR cookie_close_function_t *close;
} cookie_io_functions_t;

/****************************************************************************
* Public Function Prototypes
****************************************************************************/
Expand Down Expand Up @@ -259,6 +283,8 @@ FAR char *tmpnam(FAR char *s);
FAR char *tempnam(FAR const char *dir, FAR const char *pfx) malloc_like;
int remove(FAR const char *path);

FAR FILE *lib_get_stdio_stream(int fd);

/* Shell operations. These are not actually implemented in the OS. See
* apps/system/popen for implementation.
*/
Expand Down
2 changes: 2 additions & 0 deletions libs/libc/locale/lib_iconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <stdint.h>
#include <locale.h>

#include <nuttx/lib/lib.h>

/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions libs/libc/misc/lib_ftok.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <errno.h>
#include <string.h>

#include <nuttx/lib/lib.h>

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions libs/libc/sched/sched_dumpstack.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/types.h>

#include <stdio.h>
#include <sched.h>
#include <debug.h>

/****************************************************************************
Expand Down
2 changes: 2 additions & 0 deletions libs/libc/signal/sig_psignal.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#include <errno.h>
#include <unistd.h>

#include <nuttx/sched.h>

/* Uses streams... not available to kernel code */

#ifndef __KERNEL__
Expand Down
3 changes: 2 additions & 1 deletion libs/libc/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ set(SRCS
lib_ultoa_invert.c
lib_renameat.c
lib_putwchar.c
lib_libbsprintf.c)
lib_libbsprintf.c
lib_getstream.c)

if(CONFIG_LIBC_FLOATINGPOINT)
list(APPEND SRCS lib_dtoa_engine.c lib_dtoa_data.c)
Expand Down
2 changes: 1 addition & 1 deletion libs/libc/stdio/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CSRCS += lib_perror.c lib_putchar.c lib_getchar.c lib_puts.c
CSRCS += lib_gets_s.c lib_gets.c lib_libdgets.c
CSRCS += lib_sscanf.c lib_vsscanf.c lib_libvscanf.c lib_libvsprintf.c
CSRCS += lib_remove.c lib_tempnam.c lib_tmpnam.c lib_ultoa_invert.c
CSRCS += lib_renameat.c lib_putwchar.c lib_libbsprintf.c
CSRCS += lib_renameat.c lib_putwchar.c lib_libbsprintf.c lib_getstream.c

ifeq ($(CONFIG_LIBC_FLOATINGPOINT),y)
CSRCS += lib_dtoa_engine.c lib_dtoa_data.c
Expand Down
2 changes: 2 additions & 0 deletions libs/libc/stdio/lib_fgetwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include <errno.h>
#include <string.h>

#include <nuttx/lib/lib.h>

#ifdef CONFIG_FILE_STREAM

/****************************************************************************
Expand Down
49 changes: 49 additions & 0 deletions libs/libc/stdio/lib_getstream.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/****************************************************************************
* libs/libc/stdio/lib_getstream.c
*
* 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.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdio.h>

#include <nuttx/lib/lib.h>

#ifdef CONFIG_FILE_STREAM

/****************************************************************************
* Public Functions
****************************************************************************/

/****************************************************************************
* Name: lib_get_stdio_stream
*
* Description:
* Get a pointer to the stream from the fd
****************************************************************************/

FAR inline FILE *lib_get_stdio_stream(int fd)
{
return lib_get_stream(fd);
}

#endif
2 changes: 2 additions & 0 deletions libs/libc/stdio/lib_remove.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <unistd.h>
#include <stdio.h>

#include <nuttx/lib/lib.h>

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions libs/libc/stdio/lib_ungetwc.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
#include <fcntl.h>
#include <string.h>

#include <nuttx/lib/lib.h>

#ifdef CONFIG_FILE_STREAM

/****************************************************************************
Expand Down
1 change: 1 addition & 0 deletions libs/libc/stdio/lib_vasprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
****************************************************************************/

#include <nuttx/streams.h>
#include <nuttx/lib/lib.h>

/****************************************************************************
* Pre-processor Definitions
Expand Down
1 change: 1 addition & 0 deletions libs/libc/unistd/lib_getpass.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
****************************************************************************/

#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>
Expand Down

0 comments on commit 4641d63

Please sign in to comment.