Logo
Explore Help
Sign In
fluencelabs/musl
1
0
Fork 0
You've already forked musl
mirror of https://github.com/fluencelabs/musl synced 2025-06-14 23:41:40 +00:00
Code Issues Projects Releases Wiki Activity
Files
f313a1622448de578ab0b11a881f44a02c9082e6
musl/src/string/strerror_r.c

18 lines
295 B
C
Raw Normal View History

initial check-in, version 0.5.0
2011-02-12 00:22:29 -05:00
#include <string.h>
#include <errno.h>
int strerror_r(int err, char *buf, size_t buflen)
{
char *msg = strerror(err);
make strerror_r behave nicer on failure if the buffer is too short, at least return a partial string. this is helpful if the caller is lazy and does not check for failure. care is taken to avoid writing anything if the buffer length is zero, and to always null-terminate when the buffer length is non-zero.
2012-06-20 12:07:18 -04:00
size_t l = strlen(msg);
if (l >= buflen) {
if (buflen) {
memcpy(buf, msg, buflen-1);
buf[buflen-1] = 0;
}
initial check-in, version 0.5.0
2011-02-12 00:22:29 -05:00
return ERANGE;
make strerror_r behave nicer on failure if the buffer is too short, at least return a partial string. this is helpful if the caller is lazy and does not check for failure. care is taken to avoid writing anything if the buffer length is zero, and to always null-terminate when the buffer length is non-zero.
2012-06-20 12:07:18 -04:00
}
memcpy(buf, msg, l+1);
initial check-in, version 0.5.0
2011-02-12 00:22:29 -05:00
return 0;
}
Reference in New Issue Copy Permalink
Powered by Gitea Version: 1.24.0 Page: 317ms Template: 9ms
English
Bahasa Indonesia Deutsch English Español Français Gaeilge Italiano Latviešu Magyar nyelv Nederlands Polski Português de Portugal Português do Brasil Suomi Svenska Türkçe Čeština Ελληνικά Български Русский Українська فارسی മലയാളം 日本語 简体中文 繁體中文(台灣) 繁體中文(香港) 한국어
Licenses API