EWOULDBLOCK vs EAGAIN: a szabvány az szabvány

Kis érdekesség az errno értékeivel kapcsolatban.

AIX-on az errno.h a következő okossággal örvendeztet meg:

/* non-blocking and interrupt i/o */
/*
 * AIX returns EAGAIN where 4.3BSD used EWOULDBLOCK;
 * but, the standards insist on unique errno values for each errno.
 * A unique value is reserved for users that want to code case
 * statements for systems that return either EAGAIN or EWOULDBLOCK.
 */
#if _XOPEN_SOURCE_EXTENDED==1
#define EWOULDBLOCK     EAGAIN   /* Operation would block */
#else /* _XOPEN_SOURCE_EXTENDED */
#define EWOULDBLOCK     54
#endif /* _XOPEN_SOURCE_EXTENDED */

Szóval definiál egy EWOULDBLOCK értéket, ami kontextustól függően lesz 11 (EAGAIN) vagy 54, de az garantált, hogy a kernel nem fog 54-et visszaadni. Az ilyenek teszik széppé ezt az ipart.

Hozzászólások

Szabványtalan Linux-on a könnyen megtalálható /usr/include/asm-generic/errno.h file-ban:

#define EWOULDBLOCK EAGAIN /* Operation would block */

Valamint a /usr/include/asm-generic/errno-base.h file-ban:

#define EAGAIN 11  /* Try again */

Linuxon a read(2) manual a következőt írja:

EAGAIN or EWOULDBLOCK
  The file descriptor fd refers to a socket and has been marked
  nonblocking (O_NONBLOCK), and the read would block.
  POSIX.1-2001 allows either error to be returned for this case,
  and does not require these constants to have the same value,
  so a portable application should check for both possibilities.
Szerkesztve: 2025. 09. 11., cs – 13:46

Na én itt most két különböző látok felfedezni:

 

the standards insist on unique errno values for each errno.

vs

POSIX.1-2001 allows either error to be returned for this case,
  and does not require these constants to have the same value

 

Ez a két dolog baromira nem ugyanazt jelenti: mindenképp különböző érték kell (nem is lehet ugyanaz) vs nem muszáj ugyanannak lennie (de ettől még lehet ugyanaz).

És amúgy az AIX hülyeséget ír.
Benne van a szabványban, hogy: 

[EWOULDBLOCK]
Operation would block (may be the same value as [EAGAIN]).
 

Azaz szimplán nem igaz, hogy minden errno-nak különböző értéke kell legyen. És ezt a szabvány le is írja, hogy mely esetekben lehet ugyanaz:

The header shall define the following macros which shall expand to integer constant expressions with type int, distinct positive values (except as noted below), and which shall be suitable for use in #if preprocessing directives

Ilyen érték még az ENOTSUP:

[ENOTSUP]
Not supported (may be the same value as [EOPNOTSUPP]).