Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   errno    ( 3 )

номер последней ошибки (number of last error)

  Name  |  Synopsis  |  Description  |    Note    |  See also  |

Примечание (Note)

A common mistake is to do

if (somecall() == -1) { printf("somecall() failed\n"); if (errno == ...) { ... } }

where errno no longer needs to have the value it had upon return from somecall() (i.e., it may have been changed by the printf(3)). If the value of errno should be preserved across a library call, it must be saved:

if (somecall() == -1) { int errsv = errno; printf("somecall() failed\n"); if (errsv == ...) { ... } }

Note that the POSIX threads APIs do not set errno on error. Instead, on failure they return an error number as the function result. These error numbers have the same meanings as the error numbers returned in errno by other APIs.

On some ancient systems, <errno.h> was not present or did not declare errno, so that it was necessary to declare errno manually (i.e., extern int errno). Do not do this. It long ago ceased to be necessary, and it will cause problems with modern versions of the C library.