0

The select(2) system call is defined as follows in chapter 6.3 of Unix Network Programming (2003) by Stevens, Fenner and Rudoff:

#include <sys/select.h>
#include <sys/time.h>
int select(int maxfdp1, fd_set *readset, fd_set *writeset,
        fd_set *exceptset, const struct timeval *timeout);

But none of modern Unixes such as FreeBSD, OpenBSD, NetBSD, Linux, and even the POSIX[1] standard, define the system call as such. However, it is noted in the book that "POSIX specifies the const qualifier". Is it an error in the book? Or, is it because of a historical reason? All systems define pselect(2) to have a constant timeout parameter, though.

http://pubs.opengroup.org/onlinepubs/009695399/functions/pselect.html

The book errata page does not list this as an error:

http://www.unixnetworkprogramming.com/errata.html

  • 1
    It's an error in the book: `Upon successful completion, the select() function may modify the object pointed to by the timeout argument.` [SUSv2](http://pubs.opengroup.org/onlinepubs/007908799/xsh/select.html) says something similar and it's from 1997. – cremno Apr 10 '15 at 00:37
  • It's debatable whether it's a mistake or not IMHO. The POSIX standard is ambiguous in that it says the timeout value "may" be modified. So any implementation can choose to not modify it and define that as a const. Even the Linux select man page hints at that ambiguity: "On Linux, select() modifies timeout to reflect the amount of time not slept; most other implementations do not do this. (POSIX.1-2001 permits either behavior.) ... Consider timeout to be undefined after select() returns." – kaylum Apr 10 '15 at 00:50
  • Thank you for the help. I've reported this error to the authors. – unix_newbie_programmer223 Apr 10 '15 at 01:40

1 Answers1

0

POSIX defines the interface to select() as:

int select(int nfds, fd_set *restrict readfds,
       fd_set *restrict writefds, fd_set *restrict errorfds,
       struct timeval *restrict timeout);

The select() function shall be equivalent to the pselect() function, except as follows:

  • ...
  • Upon successful completion, the select() function may modify the object pointed to by the timeout argument.

The pselect function takes a const struct timespec * restrict timeout argument (same page in the POSIX definition).

The const qualifier quoted by the book is a mistake.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278