am 29f06943
: Merge "Add GNU-compatible strerror_r."
* commit '29f06943a19ef2271a08f4223f597a3383f0d9c0': Add GNU-compatible strerror_r.
This commit is contained in:
@@ -75,10 +75,12 @@ struct BufferOutputStream {
|
||||
len = strlen(data);
|
||||
}
|
||||
|
||||
total += len;
|
||||
|
||||
while (len > 0) {
|
||||
int avail = end_ - pos_;
|
||||
if (avail == 0) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
if (avail > len) {
|
||||
avail = len;
|
||||
@@ -87,11 +89,10 @@ struct BufferOutputStream {
|
||||
pos_ += avail;
|
||||
pos_[0] = '\0';
|
||||
len -= avail;
|
||||
total += avail;
|
||||
}
|
||||
}
|
||||
|
||||
int total;
|
||||
size_t total;
|
||||
|
||||
private:
|
||||
char* buffer_;
|
||||
@@ -109,18 +110,19 @@ struct FdOutputStream {
|
||||
len = strlen(data);
|
||||
}
|
||||
|
||||
total += len;
|
||||
|
||||
while (len > 0) {
|
||||
int rc = TEMP_FAILURE_RETRY(write(fd_, data, len));
|
||||
if (rc == -1) {
|
||||
break;
|
||||
return;
|
||||
}
|
||||
data += rc;
|
||||
len -= rc;
|
||||
total += rc;
|
||||
}
|
||||
}
|
||||
|
||||
int total;
|
||||
size_t total;
|
||||
|
||||
private:
|
||||
int fd_;
|
||||
|
@@ -1,11 +1,16 @@
|
||||
/* $OpenBSD: strerror_r.c,v 1.6 2005/08/08 08:05:37 espie Exp $ */
|
||||
/* Public Domain <marc@snafu.org> */
|
||||
|
||||
// G++ automatically defines _GNU_SOURCE, which then means that <string.h>
|
||||
// gives us the GNU variant.
|
||||
#undef _GNU_SOURCE
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "private/ErrnoRestorer.h"
|
||||
#include "private/libc_logging.h"
|
||||
@@ -62,6 +67,12 @@ int strerror_r(int error_number, char* buf, size_t buf_len) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern "C" char* __gnu_strerror_r(int error_number, char* buf, size_t buf_len) {
|
||||
ErrnoRestorer errno_restorer; // The glibc strerror_r doesn't set errno if it truncates...
|
||||
strerror_r(error_number, buf, buf_len);
|
||||
return buf; // ...and just returns whatever fit.
|
||||
}
|
||||
|
||||
extern "C" __LIBC_HIDDEN__ const char* __strsignal(int signal_number, char* buf, size_t buf_len) {
|
||||
const char* signal_name = __strsignal_lookup(signal_number);
|
||||
if (signal_name != NULL) {
|
||||
|
@@ -67,8 +67,12 @@ extern char* strcasestr(const char *haystack, const char *needle) __purefunc;
|
||||
extern char* strtok(char* __restrict, const char* __restrict);
|
||||
extern char* strtok_r(char* __restrict, const char* __restrict, char** __restrict);
|
||||
|
||||
extern char* strerror(int);
|
||||
extern int strerror_r(int errnum, char *buf, size_t n);
|
||||
extern char* strerror(int);
|
||||
#if defined(__USE_GNU)
|
||||
extern char* strerror_r(int, char*, size_t) __RENAME(__gnu_strerror_r);
|
||||
#else /* POSIX */
|
||||
extern int strerror_r(int, char*, size_t);
|
||||
#endif
|
||||
|
||||
extern size_t strnlen(const char *, size_t) __purefunc;
|
||||
extern char* strncat(char* __restrict, const char* __restrict, size_t);
|
||||
|
Reference in New Issue
Block a user