The select() and pselect() system calls modify their arguments (the \'fd_set *
\' arguments), so the input value tells the system which file descriptors to check
I've done a little research on MacOS X, Linux, AIX, Solaris and HP-UX, and there are some interesting results. I used the following program:
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif /* __STDC_VERSION__ */
#ifdef SET_FD_SETSIZE
#define FD_SETSIZE SET_FD_SETSIZE
#endif
#ifdef USE_SYS_TIME_H
#include
#else
#include
#endif /* USE_SYS_TIME_H */
#include
int main(void)
{
printf("FD_SETSIZE = %d; sizeof(fd_set) = %d\n", (int)FD_SETSIZE, (int)sizeof(fd_set));
return 0;
}
It was compiled twice on each platform:
cc -o select select.c
cc -o select -DSET_FD_SETSIZE=16384
(And on one platform, HP-UX 11.11, I had to add -DUSE_SYS_TIME_H to get things to compile at all.) I separately did a visual check on FD_COPY - only MacOS X seemed to include it, and that had to be activated by ensuring that _POSIX_C_SOURCE
was not defined or by defining _DARWIN_C_SOURCE
.
header - use
instead
_DARWIN_C_SOURCE
is specifiedClearly, a trivial modification to the program allows automatic checking of FD_COPY:
#ifdef FD_COPY
printf("FD_COPY is a macro\n");
#endif
What is not necessarily trivial is finding out how to ensure that it is available; you end up doing the manual scan and working out how to trigger it.
On all these machines, it looks like an fd_set
can be copied by a structure copy without running into risk of undefined behaviour.