📄 wstring.c
字号:
register const Wchar * __restrict s2, size_t n){ Wchar *s = s1; const Wchar *p = s2;#ifdef __BCC__ while (n--) { if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */ ++s; } return s1 + (s2 - p);#else while (n) { if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */ ++s; --n; } return s1 + (s2 - p);#endif}#endif/**********************************************************************/#ifdef L_bzeroweak_alias(__bzero,bzero);void __bzero(void *s, size_t n){ register unsigned char *p = s;#ifdef __BCC__ /* bcc can optimize the counter if it thinks it is a pointer... */ register const char *np = (const char *) n;#else#define np n#endif while (np) { *p++ = 0; --np; }}#undef np#endif/**********************************************************************/#ifdef L_bcopyvoid bcopy(const void *s2, void *s1, size_t n){#if 1 memmove(s1, s2, n);#else#ifdef __BCC__ register char *s; register const char *p; s = s1; p = s2; if (p >= s) { while (n--) { *s++ = *p++; } } else { s += n; p += n; while (n--) { *--s = *--p; } }#else register char *s; register const char *p; s = s1; p = s2; if (p >= s) { while (n) { *s++ = *p++; --n; } } else { while (n) { --n; s[n] = p[n]; } }#endif#endif}#endif/**********************************************************************/#ifdef L_strcasestrchar *strcasestr(const char *s1, const char *s2){ register const char *s = s1; register const char *p = s2;#if 1 do { if (!*p) { return (char *) s1;; } if ((*p == *s) || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s))) ) { ++p; ++s; } else { p = s2; if (!*s) { return NULL; } s = ++s1; } } while (1);#else while (*p && *s) { if ((*p == *s) || (tolower(*((unsigned char *)p)) == tolower(*((unsigned char *)s))) ) { ++p; ++s; } else { p = s2; s = ++s1; } } return (*p) ? NULL : (char *) s1;#endif}#endif/**********************************************************************/#ifdef L_strndupchar *strndup(register const char *s1, size_t n){ register char *s; n = strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */ if ((s = malloc(n + 1)) != NULL) { memcpy(s, s1, n); s[n] = 0; } return s;}#endif/**********************************************************************/#ifdef L_strsepchar *strsep(char ** __restrict s1, const char * __restrict s2){ register char *s = *s1; register char *p;#if 1 p = NULL; if (s && *s && (p = strpbrk(s, s2))) { *p++ = 0; }#else if (s && *s && *(p = s + strcspn(s, s2))) { *p++ = 0; } else { p = NULL; }#endif *s1 = p; return s;}#endif/**********************************************************************/#ifdef L_wcschrnul#define L_strchrnul#define __Wstrchrnul __wcschrnul#define Wstrchrnul wcschrnul#else#define __Wstrchrnul __strchrnul#define Wstrchrnul strchrnul#endif#ifdef L_strchrnulextern Wchar *__Wstrchrnul(register const Wchar *s, Wint c);weak_alias(__Wstrchrnul, Wstrchrnul);Wchar *__Wstrchrnul(register const Wchar *s, Wint c){ --s; while (*++s && (*s != ((Wchar)c))); return (Wchar *) s;}#endif/**********************************************************************/#ifdef L_rawmemchrvoid *rawmemchr(const void *s, int c){ register const unsigned char *r = s; while (*r != ((unsigned char)c)) ++r; return (void *) r; /* silence the warning */}#endif/**********************************************************************/#ifdef L_basenamechar *basename(const char *path){ register const char *s; register const char *p; p = s = path; while (*s) { if (*s++ == '/') { p = s; } } return (char *) p;}#endif/**********************************************************************/#ifdef L___xpg_basenamechar *__xpg_basename(register char *path){ static const char null_or_empty[] = "."; char *first; register char *last; first = (char *) null_or_empty; if (path && *path) { first = path; last = path - 1; do { if ((*path != '/') && (path > ++last)) { last = first = path; } } while (*++path); if (*first == '/') { last = first; } last[1] = 0; } return first;}#endif/**********************************************************************/#ifdef L_dirnamechar *dirname(char *path){ static const char null_or_empty_or_noslash[] = "."; register char *s; register char *last; char *first; last = s = path; if (s != NULL) { LOOP: while (*s && (*s != '/')) ++s; first = s; while (*s == '/') ++s; if (*s) { last = first; goto LOOP; } if (last == path) { if (*last != '/') { goto DOT; } if ((*++last == '/') && (last[1] == 0)) { ++last; } } *last = 0; return path; } DOT: return (char *) null_or_empty_or_noslash;}#endif/**********************************************************************/#ifdef L_strlcat/* OpenBSD function: * Append at most n-1-strlen(dst) chars from src to dst and nul-terminate dst. * Returns strlen(src) + strlen({original} dst), so truncation occurred if the * return val is >= n. * Note: If dst doesn't contain a nul in the first n chars, strlen(dst) is * taken as n. */size_t strlcat(register char *__restrict dst, register const char *__restrict src, size_t n){ size_t len; char dummy[1]; len = 0; while (1) { if (len >= n) { dst = dummy; break; } if (!*dst) { break; } ++dst; ++len; } while ((*dst = *src) != 0) { if (++len < n) { ++dst; } ++src; } return len;}#endif/**********************************************************************/#ifdef WANT_WIDEextern size_t __wcslcpy(wchar_t *__restrict dst, const wchar_t *__restrict src, size_t n);#endif#ifdef L___wcslcpy#define L_strlcpy#define Wstrlcpy __wcslcpy#ifdef __LOCALE_C_ONLYweak_alias(__wcslcpy,wcsxfrm);#endif#endif#ifdef L_strlcpy#ifndef L___wcslcpy#define Wstrlcpy strlcpy#ifdef __LOCALE_C_ONLYweak_alias(strlcpy,strxfrm);#endif#endif/* OpenBSD function: * Copy at most n-1 chars from src to dst and nul-terminate dst. * Returns strlen(src), so truncation occurred if the return value is >= n. */size_t Wstrlcpy(register Wchar *__restrict dst, register const Wchar *__restrict src, size_t n){ const Wchar *src0 = src; Wchar dummy[1]; if (!n) { dst = dummy; } else { --n; } while ((*dst = *src) != 0) { if (n) { --n; ++dst; } ++src; } return src - src0;}#endif/**********************************************************************/#if defined(L__string_syssigmsgs) && defined(__UCLIBC_HAS_SIGNUM_MESSAGES__)const char _string_syssigmsgs[] = { /* 0: 0, 1 */ "\0" /* 1: 1, 7 */ "Hangup\0" /* 2: 8, 10 */ "Interrupt\0" /* 3: 18, 5 */ "Quit\0" /* 4: 23, 20 */ "Illegal instruction\0" /* 5: 43, 22 */ "Trace/breakpoint trap\0" /* 6: 65, 8 */ "Aborted\0" /* 7: 73, 10 */ "Bus error\0" /* 8: 83, 25 */ "Floating point exception\0" /* 9: 108, 7 */ "Killed\0" /* 10: 115, 22 */ "User defined signal 1\0" /* 11: 137, 19 */ "Segmentation fault\0" /* 12: 156, 22 */ "User defined signal 2\0" /* 13: 178, 12 */ "Broken pipe\0" /* 14: 190, 12 */ "Alarm clock\0" /* 15: 202, 11 */ "Terminated\0" /* 16: 213, 12 */ "Stack fault\0" /* 17: 225, 13 */ "Child exited\0" /* 18: 238, 10 */ "Continued\0" /* 19: 248, 17 */ "Stopped (signal)\0" /* 20: 265, 8 */ "Stopped\0" /* 21: 273, 20 */ "Stopped (tty input)\0" /* 22: 293, 21 */ "Stopped (tty output)\0" /* 23: 314, 21 */ "Urgent I/O condition\0" /* 24: 335, 24 */ "CPU time limit exceeded\0" /* 25: 359, 25 */ "File size limit exceeded\0" /* 26: 384, 22 */ "Virtual timer expired\0" /* 27: 406, 24 */ "Profiling timer expired\0" /* 28: 430, 15 */ "Window changed\0" /* 29: 445, 13 */ "I/O possible\0" /* 30: 458, 14 */ "Power failure\0" /* 31: 472, 16 */ "Bad system call"#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__) /* 32: 488, 9 */ "\0EMT trap"#endif};#endif/**********************************************************************/#if defined(L_sys_siglist) && defined(__UCLIBC_HAS_SYS_SIGLIST__)const char *const sys_siglist[_NSIG] = { [0] = NULL, [SIGHUP] = _string_syssigmsgs + 1, [SIGINT] = _string_syssigmsgs + 8, [SIGQUIT] = _string_syssigmsgs + 18, [SIGILL] = _string_syssigmsgs + 23, [SIGTRAP] = _string_syssigmsgs + 43, [SIGABRT] = _string_syssigmsgs + 65, [SIGBUS] = _string_syssigmsgs + 73, [SIGFPE] = _string_syssigmsgs + 83, [SIGKILL] = _string_syssigmsgs + 108, [SIGUSR1] = _string_syssigmsgs + 115, [SIGSEGV] = _string_syssigmsgs + 137, [SIGUSR2] = _string_syssigmsgs + 156, [SIGPIPE] = _string_syssigmsgs + 178, [SIGALRM] = _string_syssigmsgs + 190, [SIGTERM] = _string_syssigmsgs + 202,#if !(defined(__alpha__) || defined(__mips__) || defined(__sparc__)) [SIGSTKFLT] = _string_syssigmsgs + 213,#endif [SIGCHLD] = _string_syssigmsgs + 225, [SIGCONT] = _string_syssigmsgs + 238, [SIGSTOP] = _string_syssigmsgs + 248, [SIGTSTP] = _string_syssigmsgs + 265, [SIGTTIN] = _string_syssigmsgs + 273, [SIGTTOU] = _string_syssigmsgs + 293, [SIGURG] = _string_syssigmsgs + 314, [SIGXCPU] = _string_syssigmsgs + 335, [SIGXFSZ] = _string_syssigmsgs + 359, [SIGVTALRM] = _string_syssigmsgs + 384, [SIGPROF] = _string_syssigmsgs + 406, [SIGWINCH] = _string_syssigmsgs + 430, [SIGIO] = _string_syssigmsgs + 445, [SIGPWR] = _string_syssigmsgs + 458, [SIGSYS] = _string_syssigmsgs + 472,#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__) [SIGEMT] = _string_syssigmsgs + 488,#endif};#endif/**********************************************************************/#ifdef L_strsignal/* TODO: make a threadsafe version? */#ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__)static const unsigned char sstridx[] = { 0, SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGIOT, SIGBUS, SIGFPE, SIGKILL, SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGALRM, SIGTERM,#if defined(__alpha__) || defined(__mips__) || defined(__sparc__) 0,#else SIGSTKFLT,#endif SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGXCPU, SIGXFSZ, SIGVTALRM, SIGPROF, SIGWINCH, SIGIO, SIGPWR, SIGSYS,#if defined(__alpha__) || defined(__mips__) || defined(__hppa__) || defined(__sparc__) SIGEMT,#endif};#endifchar *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(__hppa__) || 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; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -