Atlas - errno.c
Home / lab / trail / c / header Lines: 6 | Size: 5621 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/* SPDX-License-Identifier: GPL-3.0 2 * The Language Trail 3 * 4 * errno.c 5 * 6 * https://en.cppreference.com/w/c/header/errno.html 7 * 8 * COPYRIGHT NOTICE 9 * Copyright (C) 2025-2026 0x4248 and contributors 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the license is not changed. 12 * 13 * This software is free and open source. Licensed under the GNU general 14 * public license version 3.0 as published by the Free Software Foundation. 15*/ 16 17// Here is a rundown of some error codes: 18// Note: this can differ from compiler, compiler version and system 19// 0 Success 20// 1 Operation not permitted 21// 2 No such file or directory 22// 3 No such process 23// 4 Interrupted system call 24// 5 Input/output error 25// 6 No such device or address 26// 7 Argument list too long 27// 8 Exec format error 28// 9 Bad file descriptor 29// 10 No child processes 30// 11 Resource temporarily unavailable 31// 12 Cannot allocate memory 32// 13 Permission denied 33// 14 Bad address 34// 15 Block device required 35// 16 Device or resource busy 36// 17 File exists 37// 18 Invalid cross-device link 38// 19 No such device 39// 20 Not a directory 40// 21 Is a directory 41// 22 Invalid argument 42// 23 Too many open files in system 43// 24 Too many open files 44// 25 Inappropriate ioctl for device 45// 26 Text file busy 46// 27 File too large 47// 28 No space left on device 48// 29 Illegal seek 49// 30 Read-only file system 50// 31 Too many links 51// 32 Broken pipe 52// 33 Numerical argument out of domain 53// 34 Numerical result out of range 54// 35 Resource deadlock avoided 55// 36 File name too long 56// 37 No locks available 57// 38 Function not implemented 58// 39 Directory not empty 59// 40 Too many levels of symbolic links 60// 41 Unknown error 41 61// 42 No message of desired type 62// 43 Identifier removed 63// 44 Channel number out of range 64// 45 Level 2 not synchronized 65// 46 Level 3 halted 66// 47 Level 3 reset 67// 48 Link number out of range 68// 49 Protocol driver not attached 69// 50 No CSI structure available 70// 51 Level 2 halted 71// 52 Invalid exchange 72// 53 Invalid request descriptor 73// 54 Exchange full 74// 55 No anode 75// 56 Invalid request code 76// 57 Invalid slot 77// 58 Unknown error 58 78// 59 Bad font file format 79// 60 Device not a stream 80// 61 No data available 81// 62 Timer expired 82// 63 Out of streams resources 83// 64 Machine is not on the network 84// 65 Package not installed 85// 66 Object is remote 86// 67 Link has been severed 87// 68 Advertise error 88// 69 Srmount error 89// 70 Communication error on send 90// 71 Protocol error 91// 72 Multihop attempted 92// 73 RFS specific error 93// 74 Bad message 94// 75 Value too large for defined data type 95// 76 Name not unique on network 96// 77 File descriptor in bad state 97// 78 Remote address changed 98// 79 Can not access a needed shared library 99// 80 Accessing a corrupted shared library 100// 81 .lib section in a.out corrupted 101// 82 Attempting to link in too many shared libraries 102// 83 Cannot exec a shared library directly 103// 84 Invalid or incomplete multibyte or wide character 104// 85 Interrupted system call should be restarted 105// 86 Streams pipe error 106// 87 Too many users 107// 88 Socket operation on non-socket 108// 89 Destination address required 109// 90 Message too long 110// 91 Protocol wrong type for socket 111// 92 Protocol not available 112// 93 Protocol not supported 113// 94 Socket type not supported 114// 95 Operation not supported 115// 96 Protocol family not supported 116// 97 Address family not supported by protocol 117// 98 Address already in use 118// 99 Cannot assign requested address 119// 100 Network is down 120// 101 Network is unreachable 121// 102 Network dropped connection on reset 122// 103 Software caused connection abort 123// 104 Connection reset by peer 124// 105 No buffer space available 125// 106 Transport endpoint is already connected 126// 107 Transport endpoint is not connected 127// 108 Cannot send after transport endpoint shutdown 128// 109 Too many references: cannot splice 129// 110 Connection timed out 130// 111 Connection refused 131// 112 Host is down 132// 113 No route to host 133// 114 Operation already in progress 134// 115 Operation now in progress 135// 116 Stale file handle 136// 117 Structure needs cleaning 137// 118 Not a XENIX named type file 138// 119 No XENIX semaphores available 139// 120 Is a named type file 140// 121 Remote I/O error 141// 122 Disk quota exceeded 142// 123 No medium found 143// 124 Wrong medium type 144// 125 Operation canceled 145// 126 Required key not available 146// 127 Key has expired 147// 128 Key has been revoked 148// 129 Key was rejected by service 149// 130 Owner died 150// 131 State not recoverable 151// 132 Operation not possible due to RF-kill 152// 133 Memory page has hardware error 153 154/** 155 * Errno maps these values to constants which can make it much easier to write 156 */ 157 158#include <stdio.h> 159#include <errno.h> 160#include <string.h> 161 162int foo_1(){ 163 return -1; 164} 165 166void foo_2(){ 167 /* Rather than returning an error code we can just set errno to the error */ 168 errno = ENOENT; 169} 170 171void test_notUsingErrno(){ 172 int ret; 173 ret = foo_1(); 174 if(ret){ 175 printf("ERROR\n"); 176 } else { 177 printf("OK\n"); 178 } 179 return; 180} 181 182 183void test_usingErrno(){ 184 foo_2(); 185 /* We can read errno and then use strerror to tell the user what 186 * went wrong 187 */ 188 if(errno){ 189 /* ERROR: 2, No such file or directory */ 190 printf("ERROR: %d, %s\n",errno, strerror(errno)); 191 } else { 192 printf("OK\n"); 193 } 194 return; 195} 196 197void test_stderr(){ 198 /* In this demo we can het the name of an error number using stderr() 199 */ 200 for (int i=0 ; i < 150; i++) { 201 printf("%d\t%s\n", i,strerror(i)); 202 } 203} 204 205int main() { 206 test_notUsingErrno(); 207 test_usingErrno(); 208 209 return 0; 210} 211[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.