Skip to content

Commit

Permalink
stdio.h:Remove unnecessary header file
Browse files Browse the repository at this point in the history
Error: net/telnet.c:725:11: error: implicit declaration of function 'lib_free' [-Werror=implicit-function-declaration]
  725 |           lib_free(devpath);
      |           ^~~~~~~~

Error: /github/workspace/sources/nuttx/libs/libc/netdb/lib_netdb.h:117:1: error: unknown type name 'bool'
  117 | bool convert_hostent(FAR const struct hostent_s *in,
      | ^~~~

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
  • Loading branch information
anjiahao1 committed Nov 13, 2024
1 parent 1d1ef52 commit 9165b04
Show file tree
Hide file tree
Showing 17 changed files with 128 additions and 58 deletions.
1 change: 1 addition & 0 deletions drivers/net/telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <nuttx/signal.h>
#include <nuttx/mutex.h>
#include <nuttx/fs/fs.h>
#include <nuttx/lib/lib.h>
#include <nuttx/net/net.h>
#include <nuttx/net/telnet.h>

Expand Down
52 changes: 1 addition & 51 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 Expand Up @@ -542,29 +515,6 @@ struct filelist
*/

#ifdef CONFIG_FILE_STREAM
struct file_struct
{
sq_entry_t fs_entry; /* Entry of file stream */
rmutex_t fs_lock; /* Recursive lock */
cookie_io_functions_t fs_iofunc; /* Callbacks to user / system functions */
FAR void *fs_cookie; /* Pointer to file descriptor / cookie struct */
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
FAR char *fs_bufstart; /* Pointer to start of buffer */
FAR char *fs_bufend; /* Pointer to 1 past end of buffer */
FAR char *fs_bufpos; /* Current position in buffer */
FAR char *fs_bufread; /* Pointer to 1 past last buffered read char. */
# if CONFIG_STDIO_BUFFER_SIZE > 0
char fs_buffer[CONFIG_STDIO_BUFFER_SIZE];
# endif
#endif
uint16_t fs_oflags; /* Open mode flags */
uint8_t fs_flags; /* Stream flags */
#if CONFIG_NUNGET_CHARS > 0
uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
char fs_ungotten[CONFIG_NUNGET_CHARS];
#endif
};

struct streamlist
{
mutex_t sl_lock; /* For thread safety */
Expand Down
1 change: 1 addition & 0 deletions include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <unistd.h> /* For getpid */
#include <signal.h> /* Needed for sigset_t, includes this file */
#include <time.h> /* Needed for struct timespec */
#include <sched.h>

#ifdef CONFIG_PTHREAD_SPINLOCKS
/* The architecture specific spinlock.h header file must provide the
Expand Down
62 changes: 57 additions & 5 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#include <stdarg.h>
#include <time.h>

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

/****************************************************************************
* Pre-processor Definitions
Expand Down Expand Up @@ -65,9 +65,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 @@ -109,8 +109,58 @@
* Public Type Definitions
****************************************************************************/

/* 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;

/* Streams */

struct file_struct
{
sq_entry_t fs_entry; /* Entry of file stream */
rmutex_t fs_lock; /* Recursive lock */
cookie_io_functions_t fs_iofunc; /* Callbacks to user / system functions */
FAR void *fs_cookie; /* Pointer to file descriptor / cookie struct */
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
FAR char *fs_bufstart; /* Pointer to start of buffer */
FAR char *fs_bufend; /* Pointer to 1 past end of buffer */
FAR char *fs_bufpos; /* Current position in buffer */
FAR char *fs_bufread; /* Pointer to 1 past last buffered read char. */
# if CONFIG_STDIO_BUFFER_SIZE > 0
char fs_buffer[CONFIG_STDIO_BUFFER_SIZE];
# endif
#endif
uint16_t fs_oflags; /* Open mode flags */
uint8_t fs_flags; /* Stream flags */
#if CONFIG_NUNGET_CHARS > 0
uint8_t fs_nungotten; /* The number of characters buffered for ungetc */
char fs_ungotten[CONFIG_NUNGET_CHARS];
#endif
};

typedef struct file_struct FILE;

/****************************************************************************
Expand Down Expand Up @@ -259,6 +309,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 @@ -33,6 +33,8 @@
#include <string.h>
#include <stdio.h>

#include <nuttx/lib/lib.h>

/****************************************************************************
* Public Functions
****************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions libs/libc/netdb/lib_netdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <netdb.h>
#include <stdio.h>
#include <stdbool.h>

#ifdef CONFIG_LIBC_NETDB

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 9165b04

Please sign in to comment.