Error checking
When a function executes an error, it generally returns a specific value, such as 1, a null pointer, which can only indicate that an error occurred, but the cause of the error is not stated, the header file <errno.h> defines the variable errno, which stores the error code at the time the error occurred. Error codes can be used to get the wrong description information,
#include <errno.h>
#ifndef errno
extern int errno;
#endif
When the program starts executing, the variable errno is initialized to 0, and many library functions encounter errors during execution to set errno to the corresponding error code, and when the function is successfully called, they do not modify the value of errno, so when a function is called successfully, the value of errno may not be 0, Its non-0 value is set by the preceding function, so it is not possible to determine the success of a function execution based on the value of errno, and when the function call fails, the value of errno is meaningful
Error code
#define EPERM 1/* Operation not permitted */
#define ENOENT 2 */No such file or directory */
#define ESRCH 3 */No such process */
#define EINTR 4/* Interrupted system call */
#define EIO 5 */I/O error */
#define ENXIO 6 */No such device or address */
#define E2BIG 7/* ARG list too long */
#define ENOEXEC 8/* Exec format Error */
#define EBADF 9/* Bad file number */
#define ECHILD/* No child processes */
#define EAGAIN/* Try again */
#define ENOMEM/* Out of memory */
#define EACCES/* Permission denied */
#define EFAULT/* Bad address */
#define ENOTBLK/* Block Device required */
#define EBUSY/* Device or resource busy */
#define EEXIST */* File exists */
#define EXDEV */* cross-device link */
#define ENODEV */No such device */
#define ENOTDIR/* Not a directory */
#define EISDIR/* is a directory */
#define EINVAL */* Invalid argument */
#define ENFILE/* File table overflow */
#define EMFILE/* Too many open files */
#define ENOTTY */Not a typewriter */
#define ETXTBSY/* Text file Busy */
#define EFBIG/* File too large */
#define ENOSPC/* No space left on device */
#define ESPIPE/* Illegal seek * *
#define EROFS/* read-only File System */
#define Emlink */Too Many links * *
#define EPIPE */broken pipe */
#define EDOM/* Math argument out of domain of func * *
#define ERANGE/* Math result not representable */
#define EDEADLK//Resource deadlock would occur * *
#define ENAMETOOLONG/*/File name too long */
#define ENOLCK Notoginseng */No record locks available */
#define ENOSYS */Function not implemented */
#define ENOTEMPTY/* Directory not empty */
#define ELOOP/* Too Many symbolic links encountered * *
#define EWOULDBLOCK eagain/* operation would block */
#define ENOMSG * * No message of desired type */
#define EIDRM */Identifier removed */
#define ECHRNG */* Channel number out of range */
#define EL2NSYNC */Level 2 not synchronized */
#define EL3HLT */Level 3 halted */
#define EL3RST/* Level 3 Reset */
#define ELNRNG/* Link number out of range */
#define Eunatch */Protocol driver not attached */
#define ENOCSI/* NO CSI structure available */
#define EL2HLT/* Level 2 halted */
#define EBADE//Invalid Exchange * *
#define EBADR-*/Invalid Request Descriptor */
#define EXFULL/* Exchange full */
#define Enoano/* No anode */
#define EBADRQC-*/Invalid Request code */
#define EBADSLT/* Invalid slot */
#define Edeadlock Edeadlk
#define EBFONT/* Bad font file format */
#define ENOSTR/* Device not a stream */
#define ENODATA/* NO data available */
#define ETIME */* Timer expired */
#define ENOSR */* out of streams resources * *
#define ENONET */Machine was not on the network */
#define ENOPKG/* Package not installed */
#define EREMOTE/* Object is remote */
#define ENOLINK/* Link has been severed */
#define EADV/* Advertise Error */
#define ESRMNT/* Srmount Error */
#define ECOMM/* Communication error on Send */
#define EPROTO/* Protocol Error */
#define EMULTIHOP */multihop attempted */
#define EDOTDOT */RFS specific error */
#define EBADMSG * */NOT a data message */
#define Eoverflow */Value too large for defined data type */
#define ENOTUNIQ/* Name not unique on network */
#define EBADFD */* File descriptor in Bad state */
#define EREMCHG/*/Remote address changed */
#define ELIBACC/* Can not access a needed shared library */
#define ELIBBAD */Accessing a corrupted shared library */
#define ELIBSCN Bayi/* lib section in a.out corrupted */
#define ELIBMAX/attempting to link in too many shared libraries */
#define ELIBEXEC */cannot exec a shared library directly */
#define EILSEQ/* Illegal byte sequence */
#define ERESTART//interrupted system call should be restarted */
#define ESTRPIPE-*/Streams Pipe error */
#define Eusers */Too Many users * *
#define ENOTSOCK */* Socket operation on Non-socket */
#define EDESTADDRREQ */Destination address required */
#define EMSGSIZE/* Message too long */
#define EPROTOTYPE/* Protocol wrong type for socket */
#define ENOPROTOOPT */Protocol Not available */
#define EPROTONOSUPPORT */Protocol not supported */
#define ESOCKTNOSUPPORT 94/* Socket type not supported */
#define EOPNOTSUPP */operation not supported on transport endpoint * *
#define Epfnosupport */Protocol family not supported */
#define Eafnosupport */Address family not supported by protocol */
#define EADDRINUSE 98/* Address already in use */
#define EADDRNOTAVAIL/* Cannot assign requested address * *
#define ENETDOWN/* Network is down */
#define ENETUNREACH 101/* Network is unreachable */
#define ENETRESET 102/* Network dropped connection because of reset */
#define ECONNABORTED 103/* Software caused connection abort */
#define ECONNRESET 104/* Connection Reset by Peer */
#define ENOBUFS */No Buffer space available */
#define EISCONN 106/* Transport endpoint is already connected * *
#define ENOTCONN 107/* Transport endpoint is not connected */
#define ESHUTDOWN 108/* Cannot send after transport endpoint shutdown */
#define ETOOMANYREFS 109/* Too many references:cannot splice * *
#define ETIMEDOUT */Connection timed out */
#define ECONNREFUSED 111/* Connection refused */
#define EHOSTDOWN. */* Host is down */
#define EHOSTUNREACH 113/* No route to host */
#define Ealready */operation already in progress */
#define EINPROGRESS-*/Operation now in progress */
#define ESTALE */* Stale NFS file handle */
#define EUCLEAN 117/* Structure needs cleaning * *
#define ENOTNAM 118/* Not a XENIX named type file */
#define ENAVAIL 119 */No XENIX semaphores Available * *
#define EISNAM/* is a named type file */
#define EREMOTEIO 121/* Remote I/O error */
#define EDQUOT 122/* Quota exceeded */
#define Enomedium 123 */No medium found */
#define EMEDIUMTYPE 124/* Wrong medium type */
Incorrect tip information
When the program error, you can print out the appropriate error message, so that users can modify the error, functions strerror and perror to get the standard error message through the error code
Char*strerror (int errnum);
Perror () is used to output the cause of an error in the previous function to a standard device (stderr). The string that the parameter S refers to is printed first, followed by the error reason string. The reason for this error is to determine the string to be output according to the value of the global variable errno.
#include <stdio.h>
void perror (const char *message);
Linux C Note Line program Control (iii)