int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen) { register char *s; int i, retval; char buf[_STRERROR_BUFSIZE]; static const char unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' ' }; s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown); memcpy(s, unknown, sizeof(unknown)); if (!strerrbuf) { /* SUSv3 */ buflen = 0; } retval = EINVAL; i = buf + sizeof(buf) - s; if (i > buflen) { i = buflen; retval = ERANGE; } if (i) { memcpy(strerrbuf, s, i); strerrbuf[i-1] = 0; /* In case buf was too small. */ } __set_errno(retval); return retval; }
char *strsignal(int signum) { static char buf[_STRSIGNAL_BUFSIZE]; static const char unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' ' }; return memcpy(_int10tostr(buf + sizeof(buf)-1, signum) - sizeof(unknown), unknown, sizeof(unknown)); }
char *strsignal(int signum) { register char *s; int i; static char buf[_STRSIGNAL_BUFSIZE]; static const char unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 's', 'i', 'g', 'n', 'a', 'l', ' ' }; #if defined(__alpha__) || defined(__mips__) || defined(__sparc__) /* Need to translate signum to string index. */ for (i = 0; i < sizeof(sstridx)/sizeof(sstridx[0]); i++) { if (sstridx[i] == signum) { goto GOT_SSTRIDX; } } i = INT_MAX; /* Failed. */ GOT_SSTRIDX: #else /* No signum to string index translation needed. */ i = signum; #endif if (((unsigned int) signum) < _SYS_NSIG) { /* Trade time for space. This function should rarely be called * so rather than keeping an array of pointers for the different * messages, just run through the buffer until we find the * correct string. */ for (s = (char *) _string_syssigmsgs; i; ++s) { if (!*s) { --i; } } if (*s) { /* Make sure we have an actual message. */ goto DONE; } } s = _int10tostr(buf + sizeof(buf)-1, signum) - sizeof(unknown); memcpy(s, unknown, sizeof(unknown)); DONE: return s; }
char *inet_ntoa_r(struct in_addr in, char buf[INET_NTOA_MAX_LEN]) { in_addr_t addr = ntohl(in.s_addr); int i; char *p, *q; q = 0; p = buf + INET_NTOA_MAX_LEN - 1; /* cannot use sizeof(buf) here */ for (i = 0; i < 4; i++ ) { p = _int10tostr(p, addr & 0xff) - 1; addr >>= 8; if (q) { *q = '.'; } q = p; } return p+1; }
void __assert(const char *assertion, const char * filename, int linenumber, register const char * function) { char buf[__BUFLEN_INT10TOSTR]; _stdio_fdout(STDERR_FILENO, #ifdef ASSERT_SHOW_PROGNAME __progname, ": ", #endif filename, ":", _int10tostr(buf+sizeof(buf)-1, linenumber), ": ", /* Function name isn't available with some compilers. */ ((function == NULL) ? "?function?" : function), ": Assertion `", assertion, "' failed.\n", NULL ); abort(); }
int __xpg_strerror_r(int errnum, char *strerrbuf, size_t buflen) { register char *s; int i, retval; char buf[_STRERROR_BUFSIZE]; static const char unknown[] = { 'U', 'n', 'k', 'n', 'o', 'w', 'n', ' ', 'e', 'r', 'r', 'o', 'r', ' ' }; retval = EINVAL; #ifdef __UCLIBC_HAS_ERRNO_MESSAGES__ #if defined(__alpha__) || defined(__mips__) || defined(__sparc__) /* Need to translate errno to string index. */ for (i = 0 ; i < sizeof(estridx)/sizeof(estridx[0]) ; i++) { if (estridx[i] == errnum) { goto GOT_ESTRIDX; } } i = INT_MAX; /* Failed, but may need to check mips special case. */ #if EDQUOT > 200 /* Deal with large EDQUOT value on mips */ if (errnum == EDQUOT) i = 122; #endif GOT_ESTRIDX: #else /* No errno to string index translation needed. */ i = errnum; #endif if (((unsigned int) i) < _SYS_NERR) { /* Trade time for space. This function should rarely be called * so rather than keeping an array of pointers for the different * messages, just run through the buffer until we find the * correct string. */ for (s = (char *) _string_syserrmsgs ; i ; ++s) { if (!*s) { --i; } } if (*s) { /* Make sure we have an actual message. */ retval = 0; goto GOT_MESG; } } #endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */ s = _int10tostr(buf+sizeof(buf)-1, errnum) - sizeof(unknown); memcpy(s, unknown, sizeof(unknown)); GOT_MESG: if (!strerrbuf) { /* SUSv3 */ buflen = 0; } i = strlen(s) + 1; if (i > buflen) { i = buflen; retval = ERANGE; } if (i) { memcpy(strerrbuf, s, i); strerrbuf[i-1] = 0; /* In case buf was too small. */ } if (retval) { __set_errno(retval); } return retval; }