Questions tagged [strerror]
25 questions
13
votes
7 answers
How can I print the symbolic name of an errno in C?
I can use perror() or strerror() to print the "human readable" error message belonging to an errno, but what if I also want to print the symbolic name (e.g., "EAGAIN") of the errno?
Any convenient function or macro to do that?
Edit from the future:…

Will
- 2,014
- 2
- 19
- 42
10
votes
2 answers
How to use strerror_l with current locale?
I'm fixing some Linux code which used strerror (not thread-safe) for multi-threading. I found that strerror_r and strerror_l are both thread-safe. Due to different definitions for strerror_r (depending on _GNU_SOURCE it is differently defined) I'd…

Anteru
- 19,042
- 12
- 77
- 121
3
votes
3 answers
Using strerror() twice with different values within one printf() triggers a bug on Windows
According to the Microsoft docs the API char * strerror(int errnum)
"maps errnum to an error-message string and returns a pointer to the
string"
On the practice it turned out that there is one important aspect which is not covered by the…

Alexander Samoylov
- 2,358
- 2
- 25
- 28
2
votes
0 answers
compatibility of strerror_r on different platforms
I am trying to use strerror_r() function for getting error string corresponding to an error code and I am targeting BSD and Linux platforms, but the man page of strerror_r() says:
int strerror_r(int errnum, char *buf, size_t buflen);
…

tkhurana96
- 919
- 7
- 25
2
votes
2 answers
GNU strerror_r buffer meaning
char *strerror_r(int errnum, char *buf, size_t buflen);
What are these buf/buflen parameters for?
Empty buffer works like a charm:
char* buf = nullptr;
fprintf(stderr, strerror_r(errno, buf, 0));
Also this buffer looks like unused:
char…

vp_arth
- 14,461
- 4
- 37
- 66
2
votes
3 answers
Why doesn't strerror return a const-qualified pointer?
I was just skimming the C99 standard, looking for something that I don't remember now, when I noticed that the pointer returned from the strerror() function (section 7.12.6.2) isn't const-qualified, even though the standard says:
The strerror…

manneorama
- 1,291
- 12
- 22
2
votes
1 answer
Maximum size of message for strerror_r on VxWorks
VxWorks provides a version of strerror_r that only takes two parameters.
STATUS strerror_r
(
int errcode, /* error number */
char *buffer /* string buffer */
)
cURL mentions MAXERRSTR_SIZE.
The vxworks-style strerror_r() does use the…

Jeroen Koekkoek
- 41
- 2
1
vote
1 answer
Element-wise sum of nested lists
I have a nested list called list_6:
[[-1, 1, -1, 1, -1, 1, 1, 0, -1, 0, -1, -1, 1, 1, 1, 0, 1, -1, -1, -1, 1, 1, 1, 0, 0, -1, 0, 0, 0, 1, 0, -1, 1, 1, -1, 0, 0, 1, 1, -1, 0, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1],...]]
each element of the list contains…

AndrewLittle1
- 131
- 8
1
vote
1 answer
Porting Zed Shaw's debug macros to MSVC
I've found Zed Shaw's debug macros on his website when his C book "Learn C the Hard Way" was free to read. It was designed for Linux initially, and it works pretty well, been using it for a while.
Now, I've started to write C code for Windows and…

pryon
- 23
- 5
1
vote
2 answers
Why can't the result of strerror() be returned
According to the man page strerror(errnum) returns a char *, but I get the following warning:
gcc temp.c -o temp
temp.c: In function ‘mystrerror’:
temp.c:10:4: warning: return makes pointer from integer without a cast [enabled by default]
I get a…

E-rich
- 9,243
- 11
- 48
- 79
0
votes
1 answer
Why is strerror_s() with ERROR_NOT_ENOUGH_MEMORY error code returning "Exec format error"
Given the following example C code snippet test case;
#include
#include
#define SMALL_BUFFER 256
int main()
{
char* cErrorMessage = malloc(sizeof(char) * SMALL_BUFFER);
if (cErrorMessage == NULL)
{
fprintf(stderr,…

Johnson_Doe
- 13
- 4
0
votes
1 answer
setlocale in C Does Not Effect Error Message Strings Given By strerror
I want to print error messages in Turkish on Mint Linux which is running on VMware Workstation 17 Player by strerror and fprintf. To do that, I try to call setlocale with necessary arguments as shown below. But somehow, It does not work as expected.…

necdetsanli
- 1
- 2
0
votes
4 answers
TypeError: __str__ returned non-string (type NoneType) in output
class Point4D(object):
def __init__(self,w, x, y, z):
self.w = w
self.x = x
self.y = y
self.z = z
def __str__(self):
print('{}, {}, {}, {}'.format(self.w, self.x, self.y, self.z))
my_4d_point =…

Confused_Noob
- 9
- 4
0
votes
1 answer
Example of strerror_r
I'm a newbie in error handling; in my code I need to test the returned value of a function and to print the error's description if an error happens.
In order to keep the code thread-safe I have to use strerror_r, but I have some difficult to use it.…

Gennaro Arguzzi
- 769
- 1
- 14
- 27
0
votes
2 answers
perror and strerror with close(2) involved
I have this code with close(2) implemented, as many of you know(including myself) this closes the standard error, but what are the main repercussions of closing it?
And why is "main: Success" printed? Shouldn't every directory have the "." dir that…

B.Castarunza
- 135
- 12