aboutsummaryrefslogtreecommitdiff
path: root/newlib
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2020-08-03 12:40:43 +0200
committerCorinna Vinschen <corinna@vinschen.de>2020-08-03 12:41:45 +0200
commit5717262b8ecfed0f7fab63e2c09c78991e36f9dd (patch)
tree8e74c07a15132f8c507c4fb8c1ce759d64d69fb5 /newlib
parent3fbfcd11fb09d5f47af3043ee47ec5c7d863d872 (diff)
downloadnewlib-5717262b8ecfed0f7fab63e2c09c78991e36f9dd.zip
newlib-5717262b8ecfed0f7fab63e2c09c78991e36f9dd.tar.gz
newlib-5717262b8ecfed0f7fab63e2c09c78991e36f9dd.tar.bz2
select.h: update FD macros to latest FreeBSD, fix type conversion warning
Compiling #include <sys/select.h> void f(int X) {   fd_set set;   FD_ZERO(&set);   FD_SET(X,&set);   FD_CLR(X+1,&set);   (void)FD_ISSET(X+2,&set); } results in plenty of gcc warnings when compiled with -Wconversion -Wsign-conversion: fds.c:7:2: warning: conversion to ‘long unsigned int’ from ‘int’ may   FD_SET(X,&set);   ^~~~~~ [...] The unsigned NFDBITS macro combined with the signed 1L constant are causing lots of implicit signed/unsigned type conversions. Fix this by updating the FD_* macro code to the latest from FreeBSD and adding an (int) cast to _NFDBITS. As a side-effect, this fixes the visibility of NFDBITS and fds_bits (only if __BSD_VISIBLE). This also eliminates the old, outdated fd_set workaround. Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'newlib')
-rw-r--r--newlib/libc/include/sys/select.h68
1 files changed, 41 insertions, 27 deletions
diff --git a/newlib/libc/include/sys/select.h b/newlib/libc/include/sys/select.h
index 1e5d895..a5cd6c3 100644
--- a/newlib/libc/include/sys/select.h
+++ b/newlib/libc/include/sys/select.h
@@ -27,33 +27,47 @@ typedef __sigset_t sigset_t;
* FD_SETSIZE may be defined by the user, but the default here
* should be >= NOFILE (param.h).
*/
-# ifndef FD_SETSIZE
-# define FD_SETSIZE 64
-# endif
-
-typedef unsigned long fd_mask;
-# define NFDBITS (sizeof (fd_mask) * 8) /* bits per mask */
-# ifndef _howmany
-# define _howmany(x,y) (((x)+((y)-1))/(y))
-# endif
-
-/* We use a macro for fd_set so that including Sockets.h afterwards
- can work. */
-typedef struct _types_fd_set {
- fd_mask fds_bits[_howmany(FD_SETSIZE, NFDBITS)];
-} _types_fd_set;
-
-#define fd_set _types_fd_set
-
-# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS)))
-# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS)))
-# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS)))
-# define FD_ZERO(p) (__extension__ (void)({ \
- size_t __i; \
- char *__tmp = (char *)p; \
- for (__i = 0; __i < sizeof (*(p)); ++__i) \
- *__tmp++ = 0; \
-}))
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 64
+#endif
+
+typedef unsigned long __fd_mask;
+#if __BSD_VISIBLE
+typedef __fd_mask fd_mask;
+#endif
+
+#define _NFDBITS ((int)sizeof(__fd_mask) * 8) /* bits per mask */
+#if __BSD_VISIBLE
+#define NFDBITS _NFDBITS
+#endif
+
+#ifndef _howmany
+#define _howmany(x,y) (((x) + ((y) - 1)) / (y))
+#endif
+
+typedef struct fd_set {
+ __fd_mask __fds_bits[_howmany(FD_SETSIZE, _NFDBITS)];
+} fd_set;
+#if __BSD_VISIBLE
+#define fds_bits __fds_bits
+#endif
+
+#define __fdset_mask(n) ((__fd_mask)1 << ((n) % _NFDBITS))
+#define FD_CLR(n, p) ((p)->__fds_bits[(n)/_NFDBITS] &= ~__fdset_mask(n))
+#if __BSD_VISIBLE
+#define FD_COPY(f, t) (void)(*(t) = *(f))
+#endif
+#define FD_ISSET(n, p) (((p)->__fds_bits[(n)/_NFDBITS] & __fdset_mask(n)) != 0)
+#define FD_SET(n, p) ((p)->__fds_bits[(n)/_NFDBITS] |= __fdset_mask(n))
+#define FD_ZERO(p) do { \
+ fd_set *_p; \
+ __size_t _n; \
+ \
+ _p = (p); \
+ _n = _howmany(FD_SETSIZE, _NFDBITS); \
+ while (_n > 0) \
+ _p->__fds_bits[--_n] = 0; \
+} while (0)
#if !defined (__INSIDE_CYGWIN_NET__)