mirror of
https://github.com/RT-Thread/rt-thread.git
synced 2026-09-21 18:57:16 +08:00
[libc] Adjust libc.
1. Move struct stat to libc_stat.h; 2. Defined a new FD_SET macros in libc_fdset.h.
This commit is contained in:
@@ -80,15 +80,6 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct stat
|
||||
{
|
||||
struct rt_device* st_dev;
|
||||
uint16_t st_mode;
|
||||
uint32_t st_size;
|
||||
time_t st_mtime;
|
||||
uint32_t st_blksize;
|
||||
};
|
||||
|
||||
struct statfs
|
||||
{
|
||||
size_t f_bsize; /* block size */
|
||||
|
||||
@@ -1,65 +1,17 @@
|
||||
#ifndef DFS_SELECT_H__
|
||||
#define DFS_SELECT_H__
|
||||
|
||||
#ifdef RT_USING_LWIP
|
||||
/* we use lwIP's structure definitions. */
|
||||
#include <lwip/sockets.h>
|
||||
#elif defined(RT_USING_POSIX)
|
||||
#include <libc/libc_fdset.h>
|
||||
|
||||
#ifndef FD_SET
|
||||
|
||||
/* Get the total number of descriptors that we will have to support */
|
||||
|
||||
#define FD_SETSIZE (12)
|
||||
|
||||
/* We will use a 32-bit bitsets to represent the set of descriptors. How
|
||||
* many uint32_t's do we need to span all descriptors?
|
||||
*/
|
||||
|
||||
#if FD_SETSIZE <= 32
|
||||
# define __SELECT_NUINT32 1
|
||||
#elif FD_SETSIZE <= 64
|
||||
# define __SELECT_NUINT32 2
|
||||
#elif FD_SETSIZE <= 96
|
||||
# define __SELECT_NUINT32 3
|
||||
#elif FD_SETSIZE <= 128
|
||||
# define __SELECT_NUINT32 4
|
||||
#elif FD_SETSIZE <= 160
|
||||
# define __SELECT_NUINT32 5
|
||||
#elif FD_SETSIZE <= 192
|
||||
# define __SELECT_NUINT32 6
|
||||
#elif FD_SETSIZE <= 224
|
||||
# define __SELECT_NUINT32 7
|
||||
#elif FD_SETSIZE <= 256
|
||||
# define __SELECT_NUINT32 8
|
||||
#else
|
||||
# warning "Larger fd_set needed"
|
||||
#endif
|
||||
|
||||
/* These macros map a file descriptor to an index and bit number */
|
||||
|
||||
#define _FD_NDX(fd) ((fd) >> 5)
|
||||
#define _FD_BIT(fd) ((fd) & 0x1f)
|
||||
|
||||
/* Standard helper macros */
|
||||
|
||||
#define FD_CLR(fd,set) \
|
||||
((((fd_set*)(set))->arr)[_FD_NDX(fd)] &= ~(1 << _FD_BIT(fd)))
|
||||
#define FD_SET(fd,set) \
|
||||
((((fd_set*)(set))->arr)[_FD_NDX(fd)] |= (1 << _FD_BIT(fd)))
|
||||
#define FD_ISSET(fd,set) \
|
||||
(((((fd_set*)(set))->arr)[_FD_NDX(fd)] & (1 << _FD_BIT(fd))) != 0)
|
||||
#define FD_ZERO(set) \
|
||||
memset((set), 0, sizeof(fd_set))
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t arr[__SELECT_NUINT32];
|
||||
}fd_set;
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
|
||||
|
||||
#endif /* end of RT_USING_LWIP */
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user