You can use strerror()
to get a human-readable string for the error number. This is the same string printed by perror()
but it’s useful if you’re formatting the error message for something other than standard error output.
For example:
#include <errno.h> #include <string.h> /* ... */ if(read(fd, buf, 1)==-1) { printf("Oh dear, something went wrong with read()! %s\n", strerror(errno)); }
Linux also supports the explicitly-threadsafe variant strerror_r()
.
Related Posts:
- Bind failed: Address already in use
- Why should we check WIFEXITED after wait in order to kill child processes in Linux system call?
- malloc(): memory corruption
- Where is the
header file on Linux? Why can’t I find ? - Where does linux store my syslog?
- How to use shared memory with Linux in C
- Why does ENOENT mean “No such file or directory”?
- Undefined reference to pthread_create in Linux
- Openssl : error “self signed certificate in certificate chain”
- What is the LD_PRELOAD trick?
- Cannot assign requested address – possible causes?
- Does connect() block for TCP socket?
- Display value found at given address gdb
- waitpid, wnohang, wuntraced. How do I use these
- How to initialize array to 0 in C?
- Sign extend a nine-bit number in C
- Warning: assignment from incompatible pointer type
- C: error: expected ‘)’ before ‘;’ token
- valgrind – Address —- is 0 bytes after a block of size 8 alloc’d
- make: Nothing to be done for `all’
- Data argument not used by format strings in C
- execv vs execvp, why just one of them require the exact file’s path?
- difference between
and - expected expression before ‘{‘ token
- Setting std=c99 flag in GCC
- C Vector/ArrayList/LinkedList
- Returning an array using C
- warning: initializer element is not computable at load time
- error: ‘for’ loop initial declarations are only allowed in C99 mode [duplicate]
- c – warning: implicit declaration of function ‘printf’
- Flushing buffers in C
- What are 0x01 and 0x80 representative of in C bitwise operations?
- error: aggregate value used where an integer was expected
- Undefined Reference issues using Semaphores
- What is time(NULL) in C?
- Implementing shell in C and need help handling input/output redirection
- Portable way to check if directory exists [Windows/Linux, C]
- OpenGL — GL_LINE_LOOP —
- How to use EOF to run through a text file in C?
- Incorrect checksum for freed object on malloc
- Valgrind complains with “Invalid write of size 8”
- Read and write to binary files in C?
- Expression must be a pointer to a complete object type using simple pointer arithmetic
- Simple way to check if a string contains another string in C?
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Segmentation fault (core dumped) due to fgets – I think
- What does “request for member ‘*******’ in something not a structure or union” mean?
- Unknown ending signal when using debugger gdb
- Valgrind: invalid read of size 4 -> sigsegv, works fine without valgrind and in visual studio
- How to convert integer to char in C?
- Is there a good Valgrind substitute for Windows?
- Difference between sizeof(char) and sizeof(char *)
- Difference between “move” and “li” in MIPS assembly language
- Writing a simple shell in C using fork/execvp
- How to empty a char array?
- What is the difference between array and enum in C ?
- Implementation of multiple pipes in C
- How can one see content of stack with GDB?
- What does the term “empty loop” refer to exactly in C and C++?
- Is there a way to have printf() properly print out an array (of floats, say)?
- What integer hash function are good that accepts an integer hash key?
- Proper way to empty a C-String
- How do you allow spaces to be entered using scanf?
- X86 assembly – Handling the IDIV instruction
- Pause screen at program completion in C
- Is there an alternative sleep function in C to milliseconds?
- Difference between fgets and fscanf?
- What is the difference between %g and %f in C?
- Can’t understand the working of getint() in C as per K&R
- Structure padding and packing
- Lua – Number to string behaviour
- C fopen vs open
- What is `S_ISREG()`, and what does it do?
- Reading in double values with scanf in c
- Realloc Invalid Pointer in C
- What tools are there for functional programming in C?
- typedef fixed length array
- “-bash: gcc: command not found” using cygwin when compiling c?
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- In C, what exactly happens when you pass a NULL pointer to strcmp()?
- What are the differences between if, else, and else if?
- strtok segmentation fault
- Invalid write of size 1
- How to solve static declaration follows non-static declaration in GCC C code?
- realloc(): invalid next size when reallocating to make space for strcat on char *
- Constructor for structs in C
- C Error: declaration shadows a local variable — Won’t let me repeatedly replace the value of my float variable
- MIPS to C Translation
- Pointer to 2D arrays in C
- Pointer to a string in C?
- gdb: No symbol “i” in current context
- Cross Platform C library for GUI Apps?
- Implicit function declarations in C
- Pre increment vs Post increment in array
- Convert long long to string in C?
- Using pointer to char array, values in that array can be accessed?
- How can I create a dynamically sized array of structs?
- how to stop a loop arduino
- How to normalize a mantissa
- When is it ok to use a global variable in C?