summaryrefslogtreecommitdiff
path: root/libc/string/wstring.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/string/wstring.c')
-rw-r--r--libc/string/wstring.c3247
1 files changed, 0 insertions, 3247 deletions
diff --git a/libc/string/wstring.c b/libc/string/wstring.c
deleted file mode 100644
index 89c533951..000000000
--- a/libc/string/wstring.c
+++ /dev/null
@@ -1,3247 +0,0 @@
-/*
- * Copyright (C) 2002 Manuel Novoa III
- * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
- *
- * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
- */
-
-/* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
- *
- * Besides uClibc, I'm using this code in my libc for elks, which is
- * a 16-bit environment with a fairly limited compiler. It would make
- * things much easier for me if this file isn't modified unnecessarily.
- * In particular, please put any new or replacement functions somewhere
- * else, and modify the makefile to use your version instead.
- * Thanks. Manuel
- *
- * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
-
-/* Dec 20, 2002
- * Initial test implementation of strcoll, strxfrm, wcscoll, and wcsxfrm.
- * The code needs to be cleaned up a good bit, but I'd like to see people
- * test it out.
- *
- * Sep 11, 2003
- * Patch by Atsushi Nemoto <anemo@mba.ocn.ne.jp> to do arch-required
- * mapping of signal strings (alpha, mips, hppa, sparc).
- */
-
-#define _GNU_SOURCE
-#include <features.h>
-#include <string.h>
-#include <strings.h>
-#include <stdio.h>
-#include <limits.h>
-#include <ctype.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <signal.h>
-#include <assert.h>
-#include <locale.h>
-#include <bits/uClibc_uintmaxtostr.h>
-
-#ifdef WANT_WIDE
-#include <wchar.h>
-#include <wctype.h>
-#include <bits/uClibc_uwchar.h>
-
-#define Wvoid wchar_t
-#define Wchar wchar_t
-#define Wuchar __uwchar_t
-#define Wint wchar_t
-
-#else
-
-#define Wvoid void
-#define Wchar char
-typedef unsigned char __string_uchar_t;
-#define Wuchar __string_uchar_t
-#define Wint int
-
-#endif
-
-
-extern size_t __strnlen (__const char *__string, size_t __maxlen) attribute_hidden;
-extern char *__strpbrk (__const char *__s, __const char *__accept) attribute_hidden;
-extern size_t __strspn (__const char *__s, __const char *__accept) attribute_hidden;
-extern char *__strsignal (int __sig) attribute_hidden;
-extern char *__strtok_r (char *__restrict __s,
- __const char *__restrict __delim,
- char **__restrict __save_ptr) attribute_hidden;
-extern size_t __strlcpy(char *__restrict dst, const char *__restrict src,
- size_t n) attribute_hidden;
-
-#ifdef WANT_WIDE
-extern wchar_t *__wcsdup (__const wchar_t *__s) attribute_hidden;
-extern size_t __wcslen (__const wchar_t *__s) attribute_hidden;
-extern wchar_t *__wcscpy (wchar_t *__restrict __dest,
- __const wchar_t *__restrict __src) attribute_hidden;
-extern size_t __wcsspn (__const wchar_t *__wcs, __const wchar_t *__accept) attribute_hidden;
-extern wchar_t *__wcspbrk (__const wchar_t *__wcs, __const wchar_t *__accept) attribute_hidden;
-extern int __wcscmp (__const wchar_t *__s1, __const wchar_t *__s2) attribute_hidden;
-extern size_t __wcsxfrm (wchar_t *__restrict __s1,
- __const wchar_t *__restrict __s2, size_t __n) attribute_hidden;
-extern wint_t __towlower (wint_t __wc) __THROW attribute_hidden;
-#endif
-#ifdef __UCLIBC_HAS_XLOCALE__
-extern int __strcoll_l (__const char *__s1, __const char *__s2, __locale_t __l) attribute_hidden;
-extern size_t __strxfrm_l (char *__dest, __const char *__src, size_t __n, __locale_t __l) attribute_hidden;
-extern int __strcasecmp_l (__const char *__s1, __const char *__s2, __locale_t __loc) attribute_hidden;
-extern int __strncasecmp_l (__const char *__s1, __const char *__s2, size_t __n, __locale_t __loc) attribute_hidden;
-extern int __wcscasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, __locale_t __loc) attribute_hidden;
-extern int __wcsncasecmp_l (__const wchar_t *__s1, __const wchar_t *__s2, size_t __n, __locale_t __loc) attribute_hidden;
-extern int __wcscoll_l (__const wchar_t *__s1, __const wchar_t *__s2, __locale_t __loc) attribute_hidden;
-extern size_t __wcsxfrm_l (wchar_t *__s1, __const wchar_t *__s2, size_t __n, __locale_t __loc) attribute_hidden;
-#ifdef __UCLIBC_DO_XLOCALE
-extern wint_t __towlower_l(wint_t __wc, __locale_t __locale) __THROW;
-#endif
-#endif
-
-/**********************************************************************/
-/* NOTE: If we ever do internationalized syserr messages, this will
- * have to be changed! */
-
-#define _SYS_NERR 125
-#if defined(__mips__) || defined(__sparc__)
-/* sparce and mips have an extra error entry, as EDEADLK and EDEADLOCK have
- * different meanings on those platforms. */
-#undef _SYS_NERR
-#define _SYS_NERR 126
-#endif
-
-#ifdef __UCLIBC_HAS_ERRNO_MESSAGES__
-#define _SYS_ERRMSG_MAXLEN 50
-#else /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-#define _SYS_ERRMSG_MAXLEN 0
-#endif /* __UCLIBC_HAS_ERRNO_MESSAGES__ */
-
-
-extern const char _string_syserrmsgs[];
-
-#define _SYS_NSIG 32
-
-#ifdef __UCLIBC_HAS_SIGNUM_MESSAGES__
-#define _SYS_SIGMSG_MAXLEN 25
-#else /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
-#define _SYS_SIGMSG_MAXLEN 0
-#endif /* __UCLIBC_HAS_SIGNUM_MESSAGES__ */
-
-extern const char _string_syssigmsgs[];
-
-
-#if _SYS_ERRMSG_MAXLEN < __UIM_BUFLEN_INT + 14
-#define _STRERROR_BUFSIZE (__UIM_BUFLEN_INT + 14)
-#else
-#define _STRERROR_BUFSIZE _SYS_ERRMSG_MAXLEN
-#endif
-
-#if _SYS_SIGMSG_MAXLEN < __UIM_BUFLEN_INT + 15
-#define _STRSIGNAL_BUFSIZE (__UIM_BUFLEN_INT + 15)
-#else
-#define _STRSIGNAL_BUFSIZE _SYS_SIGMSG_MAXLEN
-#endif
-
-/**********************************************************************/
-#if defined(L__string_syserrmsgs) && defined(__UCLIBC_HAS_ERRNO_MESSAGES__)
-
-const char _string_syserrmsgs[] = {
- /* 0: 0, 8 */ "Success\0"
- /* 1: 8, 24 */ "Operation not permitted\0"
- /* 2: 32, 26 */ "No such file or directory\0"
- /* 3: 58, 16 */ "No such process\0"
- /* 4: 74, 24 */ "Interrupted system call\0"
- /* 5: 98, 19 */ "Input/output error\0"
- /* 6: 117, 26 */ "No such device or address\0"
- /* 7: 143, 23 */ "Argument list too long\0"
- /* 8: 166, 18 */ "Exec format error\0"
- /* 9: 184, 20 */ "Bad file descriptor\0"
- /* 10: 204, 19 */ "No child processes\0"
- /* 11: 223, 33 */ "Resource temporarily unavailable\0"
- /* 12: 256, 23 */ "Cannot allocate memory\0"
- /* 13: 279, 18 */ "Permission denied\0"
- /* 14: 297, 12 */ "Bad address\0"
- /* 15: 309, 22 */ "Block device required\0"
- /* 16: 331, 24 */ "Device or resource busy\0"
- /* 17: 355, 12 */ "File exists\0"
- /* 18: 367, 26 */ "Invalid cross-device link\0"
- /* 19: 393, 15 */ "No such device\0"
- /* 20: 408, 16 */ "Not a directory\0"
- /* 21: 424, 15 */ "Is a directory\0"
- /* 22: 439, 17 */ "Invalid argument\0"
- /* 23: 456, 30 */ "Too many open files in system\0"
- /* 24: 486, 20 */ "Too many open files\0"
- /* 25: 506, 31 */ "Inappropriate ioctl for device\0"
- /* 26: 537, 15 */ "Text file busy\0"
- /* 27: 552, 15 */ "File too large\0"
- /* 28: 567, 24 */ "No space left on device\0"
- /* 29: 591, 13 */ "Illegal seek\0"
- /* 30: 604, 22 */ "Read-only file system\0"
- /* 31: 626, 15 */ "Too many links\0"
- /* 32: 641, 12 */ "Broken pipe\0"
- /* 33: 653, 33 */ "Numerical argument out of domain\0"
- /* 34: 686, 30 */ "Numerical result out of range\0"
- /* 35: 716, 26 */ "Resource deadlock avoided\0"
- /* 36: 742, 19 */ "File name too long\0"
- /* 37: 761, 19 */ "No locks available\0"
- /* 38: 780, 25 */ "Function not implemented\0"
- /* 39: 805, 20 */ "Directory not empty\0"
- /* 40: 825, 34 */ "Too many levels of symbolic links\0"
- /* 41: 859, 1 */ "\0"
- /* 42: 860, 27 */ "No message of desired type\0"
- /* 43: 887, 19 */ "Identifier removed\0"
- /* 44: 906, 28 */ "Channel number out of range\0"
- /* 45: 934, 25 */ "Level 2 not synchronized\0"
- /* 46: 959, 15 */ "Level 3 halted\0"
- /* 47: 974, 14 */ "Level 3 reset\0"
- /* 48: 988, 25 */ "Link number out of range\0"
- /* 49: 1013, 29 */ "Protocol driver not attached\0"
- /* 50: 1042, 27 */ "No CSI structure available\0"
- /* 51: 1069, 15 */ "Level 2 halted\0"
- /* 52: 1084, 17 */ "Invalid exchange\0"
- /* 53: 1101, 27 */ "Invalid request descriptor\0"
- /* 54: 1128, 14 */ "Exchange full\0"
- /* 55: 1142, 9 */ "No anode\0"
- /* 56: 1151, 21 */ "Invalid request code\0"
- /* 57: 1172, 13 */ "Invalid slot\0"
- /* 58: 1185, 1 */ "\0"
- /* 59: 1186, 21 */ "Bad font file format\0"
- /* 60: 1207, 20 */ "Device not a stream\0"
- /* 61: 1227, 18 */ "No data available\0"
- /* 62: 1245, 14 */ "Timer expired\0"
- /* 63: 1259, 25 */ "Out of streams resources\0"
- /* 64: 1284, 30 */ "Machine is not on the network\0"
- /* 65: 1314, 22 */ "Package not installed\0"
- /* 66: 1336, 17 */ "Object is remote\0"
- /* 67: 1353, 22 */ "Link has been severed\0"
- /* 68: 1375, 16 */ "Advertise error\0"
- /* 69: 1391, 14 */ "Srmount error\0"
- /* 70: 1405, 28 */ "Communication error on send\0"
- /* 71: 1433, 15 */ "Protocol error\0"
- /* 72: 1448, 19 */ "Multihop attempted\0"
- /* 73: 1467, 19 */ "RFS specific error\0"
- /* 74: 1486, 12 */ "Bad message\0"
- /* 75: 1498, 38 */ "Value too large for defined data type\0"
- /* 76: 1536, 27 */ "Name not unique on network\0"
- /* 77: 1563, 29 */ "File descriptor in bad state\0"
- /* 78: 1592, 23 */ "Remote address changed\0"
- /* 79: 1615, 39 */ "Can not access a needed shared library\0"
- /* 80: 1654, 37 */ "Accessing a corrupted shared library\0"
- /* 81: 1691, 32 */ ".lib section in a.out corrupted\0"
- /* 82: 1723, 48 */ "Attempting to link in too many shared libraries\0"
- /* 83: 1771, 38 */ "Cannot exec a shared library directly\0"
- /* 84: 1809, 50 */ "Invalid or incomplete multibyte or wide character\0"
- /* 85: 1859, 44 */ "Interrupted system call should be restarted\0"
- /* 86: 1903, 19 */ "Streams pipe error\0"
- /* 87: 1922, 15 */ "Too many users\0"
- /* 88: 1937, 31 */ "Socket operation on non-socket\0"
- /* 89: 1968, 29 */ "Destination address required\0"
- /* 90: 1997, 17 */ "Message too long\0"
- /* 91: 2014, 31 */ "Protocol wrong type for socket\0"
- /* 92: 2045, 23 */ "Protocol not available\0"
- /* 93: 2068, 23 */ "Protocol not supported\0"
- /* 94: 2091, 26 */ "Socket type not supported\0"
- /* 95: 2117, 24 */ "Operation not supported\0"
- /* 96: 2141, 30 */ "Protocol family not supported\0"
- /* 97: 2171, 41 */ "Address family not supported by protocol\0"
- /* 98: 2212, 23 */ "Address already in use\0"
- /* 99: 2235, 32 */ "Cannot assign requested address\0"
- /* 100: 2267, 16 */ "Network is down\0"
- /* 101: 2283, 23 */ "Network is unreachable\0"
- /* 102: 2306, 36 */ "Network dropped connection on reset\0"
- /* 103: 2342, 33 */ "Software caused connection abort\0"
- /* 104: 2375, 25 */ "Connection reset by peer\0"
- /* 105: 2400, 26 */ "No buffer space available\0"
- /* 106: 2426, 40 */ "Transport endpoint is already connected\0"
- /* 107: 2466, 36 */ "Transport endpoint is not connected\0"
- /* 108: 2502, 46 */ "Cannot send after transport endpoint shutdown\0"
- /* 109: 2548, 35 */ "Too many references: cannot splice\0"
- /* 110: 2583, 21 */ "Connection timed out\0"
- /* 111: 2604, 19 */ "Connection refused\0"
- /* 112: 2623, 13 */ "Host is down\0"
- /* 113: 2636, 17 */ "No route to host\0"
- /* 114: 2653, 30 */ "Operation already in progress\0"
- /* 115: 2683, 26 */ "Operation now in progress\0"
- /* 116: 2709, 22 */ "Stale NFS file handle\0"
- /* 117: 2731, 25 */ "Structure needs cleaning\0"
- /* 118: 2756, 28 */ "Not a XENIX named type file\0"
- /* 119: 2784, 30 */ "No XENIX semaphores available\0"
- /* 120: 2814, 21 */ "Is a named type file\0"
- /* 121: 2835, 17 */ "Remote I/O error\0"
- /* 122: 2852, 20 */ "Disk quota exceeded\0"
- /* 123: 2872, 16 */ "No medium found\0"
- /* 124: 2888, 18 */ "Wrong medium type"
-#if defined(__mips__) || defined(__sparc__)
- "\0"
- /* 125: 2906, 28 */ "File locking deadlock error"
-#endif
- /* Note: for mips we are ignoring ECANCELED since glibc doesn't have a
- * corresponsding message.*/
-};
-
-#endif
-/**********************************************************************/
-#if defined(L_sys_errlist) && defined(__UCLIBC_HAS_SYS_ERRLIST__)
-
-link_warning(_sys_errlist, "sys_nerr and sys_errlist are obsolete and uClibc support for them (in at least some configurations) will probably be unavailable in the near future.")
-
-const char *const sys_errlist[] = {
- [0] = _string_syserrmsgs + 0,
- [EPERM] = _string_syserrmsgs + 8,
- [ENOENT] = _string_syserrmsgs + 32,
- [ESRCH] = _string_syserrmsgs + 58,
- [EINTR] = _string_syserrmsgs + 74,
- [EIO] = _string_syserrmsgs + 98,
- [ENXIO] = _string_syserrmsgs + 117,
- [E2BIG] = _string_syserrmsgs + 143,
- [ENOEXEC] = _string_syserrmsgs + 166,
- [EBADF] = _string_syserrmsgs + 184,
- [ECHILD] = _string_syserrmsgs + 204,
- [EAGAIN] = _string_syserrmsgs + 223,
- [ENOMEM] = _string_syserrmsgs + 256,
- [EACCES] = _string_syserrmsgs + 279,
- [EFAULT] = _string_syserrmsgs + 297,
- [ENOTBLK] = _string_syserrmsgs + 309,
- [EBUSY] = _string_syserrmsgs + 331,
- [EEXIST] = _string_syserrmsgs + 355,
- [EXDEV] = _string_syserrmsgs + 367,
- [ENODEV] = _string_syserrmsgs + 393,
- [ENOTDIR] = _string_syserrmsgs + 408,
- [EISDIR] = _string_syserrmsgs + 424,
- [EINVAL] = _string_syserrmsgs + 439,
- [ENFILE] = _string_syserrmsgs + 456,
- [EMFILE] = _string_syserrmsgs + 486,
- [ENOTTY] = _string_syserrmsgs + 506,
- [ETXTBSY] = _string_syserrmsgs + 537,
- [EFBIG] = _string_syserrmsgs + 552,
- [ENOSPC] = _string_syserrmsgs + 567,
- [ESPIPE] = _string_syserrmsgs + 591,
- [EROFS] = _string_syserrmsgs + 604,
- [EMLINK] = _string_syserrmsgs + 626,
- [EPIPE] = _string_syserrmsgs + 641,
- [EDOM] = _string_syserrmsgs + 653,
- [ERANGE] = _string_syserrmsgs + 686,
- [EDEADLK] = _string_syserrmsgs + 716,
- [ENAMETOOLONG] = _string_syserrmsgs + 742,
- [ENOLCK] = _string_syserrmsgs + 761,
- [ENOSYS] = _string_syserrmsgs + 780,
- [ENOTEMPTY] = _string_syserrmsgs + 805,
- [ELOOP] = _string_syserrmsgs + 825,
- /* _string_syserrmsgs + 859, */
- [ENOMSG] = _string_syserrmsgs + 860,
- [EIDRM] = _string_syserrmsgs + 887,
- [ECHRNG] = _string_syserrmsgs + 906,
- [EL2NSYNC] = _string_syserrmsgs + 934,
- [EL3HLT] = _string_syserrmsgs + 959,
- [EL3RST] = _string_syserrmsgs + 974,
- [ELNRNG] = _string_syserrmsgs + 988,
- [EUNATCH] = _string_syserrmsgs + 1013,
- [ENOCSI] = _string_syserrmsgs + 1042,
- [EL2HLT] = _string_syserrmsgs + 1069,
- [EBADE] = _string_syserrmsgs + 1084,
- [EBADR] = _string_syserrmsgs + 1101,
- [EXFULL] = _string_syserrmsgs + 1128,
- [ENOANO] = _string_syserrmsgs + 1142,
- [EBADRQC] = _string_syserrmsgs + 1151,
- [EBADSLT] = _string_syserrmsgs + 1172,
- /* _string_syserrmsgs + 1185, */
- [EBFONT] = _string_syserrmsgs + 1186,
- [ENOSTR] = _string_syserrmsgs + 1207,
- [ENODATA] = _string_syserrmsgs + 1227,
- [ETIME] = _string_syserrmsgs + 1245,
- [ENOSR] = _string_syserrmsgs + 1259,
- [ENONET] = _string_syserrmsgs + 1284,
- [ENOPKG] = _string_syserrmsgs + 1314,
- [EREMOTE] = _string_syserrmsgs + 1336,
- [ENOLINK] = _string_syserrmsgs + 1353,
- [EADV] = _string_syserrmsgs + 1375,
- [ESRMNT] = _string_syserrmsgs + 1391,
- [ECOMM] = _string_syserrmsgs + 1405,
- [EPROTO] = _string_syserrmsgs + 1433,
- [EMULTIHOP] = _string_syserrmsgs + 1448,
- [EDOTDOT] = _string_syserrmsgs + 1467,
- [EBADMSG] = _string_syserrmsgs + 1486,
- [EOVERFLOW] = _string_syserrmsgs + 1498,
- [ENOTUNIQ] = _string_syserrmsgs + 1536,
- [EBADFD] = _string_syserrmsgs + 1563,
- [EREMCHG] = _string_syserrmsgs + 1592,
- [ELIBACC] = _string_syserrmsgs + 1615,
- [ELIBBAD] = _string_syserrmsgs + 1654,
- [ELIBSCN] = _string_syserrmsgs + 1691,
- [ELIBMAX] = _string_syserrmsgs + 1723,
- [ELIBEXEC] = _string_syserrmsgs + 1771,
- [EILSEQ] = _string_syserrmsgs + 1809,
- [ERESTART] = _string_syserrmsgs + 1859,
- [ESTRPIPE] = _string_syserrmsgs + 1903,
- [EUSERS] = _string_syserrmsgs + 1922,
- [ENOTSOCK] = _string_syserrmsgs + 1937,
- [EDESTADDRREQ] = _string_syserrmsgs + 1968,
- [EMSGSIZE] = _string_syserrmsgs + 1997,
- [EPROTOTYPE] = _string_syserrmsgs + 2014,
- [ENOPROTOOPT] = _string_syserrmsgs + 2045,
- [EPROTONOSUPPORT] = _string_syserrmsgs + 2068,
- [ESOCKTNOSUPPORT] = _string_syserrmsgs + 2091,
- [EOPNOTSUPP] = _string_syserrmsgs + 2117,
- [EPFNOSUPPORT] = _string_syserrmsgs + 2141,
- [EAFNOSUPPORT] = _string_syserrmsgs + 2171,
- [EADDRINUSE] = _string_syserrmsgs + 2212,
- [EADDRNOTAVAIL] = _string_syserrmsgs + 2235,
- [ENETDOWN] = _string_syserrmsgs + 2267,
- [ENETUNREACH] = _string_syserrmsgs + 2283,
- [ENETRESET] = _string_syserrmsgs + 2306,
- [ECONNABORTED] = _string_syserrmsgs + 2342,
- [ECONNRESET] = _string_syserrmsgs + 2375,
- [ENOBUFS] = _string_syserrmsgs + 2400,
- [EISCONN] = _string_syserrmsgs + 2426,
- [ENOTCONN] = _string_syserrmsgs + 2466,
- [ESHUTDOWN] = _string_syserrmsgs + 2502,
- [ETOOMANYREFS] = _string_syserrmsgs + 2548,
- [ETIMEDOUT] = _string_syserrmsgs + 2583,
- [ECONNREFUSED] = _string_syserrmsgs + 2604,
- [EHOSTDOWN] = _string_syserrmsgs + 2623,
- [EHOSTUNREACH] = _string_syserrmsgs + 2636,
- [EALREADY] = _string_syserrmsgs + 2653,
- [EINPROGRESS] = _string_syserrmsgs + 2683,
- [ESTALE] = _string_syserrmsgs + 2709,
- [EUCLEAN] = _string_syserrmsgs + 2731,
- [ENOTNAM] = _string_syserrmsgs + 2756,
- [ENAVAIL] = _string_syserrmsgs + 2784,
- [EISNAM] = _string_syserrmsgs + 2814,
- [EREMOTEIO] = _string_syserrmsgs + 2835,
- [EDQUOT] = _string_syserrmsgs + 2852,
- [ENOMEDIUM] = _string_syserrmsgs + 2872,
- [EMEDIUMTYPE] = _string_syserrmsgs + 2888,
-
-#if EDEADLOCK != EDEADLK
- [EDEADLOCK] = _string_syserrmsgs + 2906,
-#endif
-
-#if EWOULDBLOCK != EAGAIN
-#error EWOULDBLOCK does not equal EAGAIN
-#endif
-
- /* For now, ignore the other arch-specific errors. glibc only maps EPROCLIM. */
-
- /* some other mips errors */
-#ifdef ECANCELED
-#endif
-#ifdef EINIT
-#endif
-#ifdef EREMDEV
-#endif
-
- /* some other sparc errors */
-#ifdef EPROCLIM
-#endif
-#ifdef ERREMOTE
-#endif
-};
-
-int sys_nerr = sizeof(sys_errlist)/sizeof(sys_errlist[0]);
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemcpy
-#define L_memcpy
-#define Wmemcpy wmemcpy
-#else
-#define Wmemcpy memcpy
-#endif
-#endif
-
-#ifdef L_memcpy
-
-#ifndef WANT_WIDE
-#undef memcpy
-#else
-#undef wmemcpy
-#endif
-Wvoid attribute_hidden *Wmemcpy(Wvoid * __restrict s1, const Wvoid * __restrict s2, size_t n)
-{
- register Wchar *r1 = s1;
- register const Wchar *r2 = s2;
-
-#ifdef __BCC__
- while (n--) {
- *r1++ = *r2++;
- }
-#else
- while (n) {
- *r1++ = *r2++;
- --n;
- }
-#endif
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemmove
-#define L_memmove
-#define Wmemmove wmemmove
-#else
-#define Wmemmove memmove
-#endif
-#endif
-
-#ifdef L_memmove
-
-#ifndef WANT_WIDE
-#undef memmove
-#else
-#undef wmemmove
-#endif
-Wvoid attribute_hidden *Wmemmove(Wvoid *s1, const Wvoid *s2, size_t n)
-{
-#ifdef __BCC__
- register Wchar *s = (Wchar *) s1;
- register const Wchar *p = (const Wchar *) s2;
-
- if (p >= s) {
- while (n--) {
- *s++ = *p++;
- }
- } else {
- s += n;
- p += n;
- while (n--) {
- *--s = *--p;
- }
- }
-
- return s1;
-#else
- register Wchar *s = (Wchar *) s1;
- register const Wchar *p = (const Wchar *) s2;
-
- if (p >= s) {
- while (n) {
- *s++ = *p++;
- --n;
- }
- } else {
- while (n) {
- --n;
- s[n] = p[n];
- }
- }
-
- return s1;
-#endif
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscpy
-#define L_strcpy
-#define Wstrcpy wcscpy
-#else
-#define Wstrcpy strcpy
-#endif
-#endif
-
-#ifdef L_strcpy
-
-#ifndef WANT_WIDE
-#undef strcpy
-#else
-#undef wcscpy
-#endif
-Wchar attribute_hidden *Wstrcpy(Wchar * __restrict s1, const Wchar * __restrict s2)
-{
- register Wchar *s = s1;
-
-#ifdef __BCC__
- do {
- *s = *s2++;
- } while (*s++ != 0);
-#else
- while ( (*s++ = *s2++) != 0 );
-#endif
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsncpy
-#define L_strncpy
-#define Wstrncpy wcsncpy
-#else
-#define Wstrncpy strncpy
-#endif
-#endif
-
-#ifdef L_strncpy
-
-#ifndef WANT_WIDE
-#undef strncpy
-#else
-#undef wcsncpy
-#endif
-Wchar attribute_hidden *Wstrncpy(Wchar * __restrict s1, register const Wchar * __restrict s2,
- size_t n)
-{
- register Wchar *s = s1;
-
-#ifdef __BCC__
- while (n--) {
- if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
- ++s;
- }
-#else
- while (n) {
- if ((*s = *s2) != 0) s2++; /* Need to fill tail with 0s. */
- ++s;
- --n;
- }
-#endif
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscat
-#define L_strcat
-#define Wstrcat wcscat
-#else
-#define Wstrcat strcat
-#endif
-#endif
-
-#ifdef L_strcat
-
-#ifndef WANT_WIDE
-#undef strcat
-#else
-#undef wcscat
-#endif
-Wchar attribute_hidden *Wstrcat(Wchar * __restrict s1, register const Wchar * __restrict s2)
-{
- register Wchar *s = s1;
-
- while (*s++);
- --s;
- while ((*s++ = *s2++) != 0);
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsncat
-#define L_strncat
-#define Wstrncat wcsncat
-#else
-#define Wstrncat strncat
-#endif
-#endif
-
-#ifdef L_strncat
-
-#ifndef WANT_WIDE
-#undef strncat
-#else
-#undef wcsncat
-#endif
-Wchar attribute_hidden *Wstrncat(Wchar * __restrict s1, register const Wchar * __restrict s2,
- size_t n)
-{
- register Wchar *s = s1;
-
- while (*s++);
- --s;
-#if __BCC__
- while (n-- && ((*s = *s2++) != 0)) ++s;
-#else
- while (n && ((*s = *s2++) != 0)) {
- --n;
- ++s;
- }
-#endif
- *s = 0;
-
- return s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemcmp
-#define L_memcmp
-#define Wmemcmp wmemcmp
-#else
-#define Wmemcmp memcmp
-#endif
-#endif
-
-#ifdef L_memcmp
-
-#ifndef WANT_WIDE
-#undef memcmp
-#else
-#undef wmemcmp
-#endif
-int attribute_hidden Wmemcmp(const Wvoid *s1, const Wvoid *s2, size_t n)
-{
- register const Wuchar *r1 = (const Wuchar *) s1;
- register const Wuchar *r2 = (const Wuchar *) s2;
-
-#ifdef WANT_WIDE
- while (n && (*r1 == *r2)) {
- ++r1;
- ++r2;
- --n;
- }
-
- return (n == 0) ? 0 : ((*r1 < *r2) ? -1 : 1);
-#else
- int r = 0;
-
- while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0));
-
- return r;
-#endif
-}
-
-#if 0 /* ndef L_wmemcmp */
-weak_alias(memcmp, bcmp)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscmp
-#define L_strcmp
-#define Wstrcmp wcscmp
-#else
-#define Wstrcmp strcmp
-#endif
-#endif
-
-#ifdef L_strcmp
-
-#ifndef WANT_WIDE
-#undef strcmp
-#else
-#undef wcscmp
-#endif
-int attribute_hidden Wstrcmp(register const Wchar *s1, register const Wchar *s2)
-{
-#ifdef WANT_WIDE
- while (*((Wuchar *)s1) == *((Wuchar *)s2)) {
- if (!*s1++) {
- return 0;
- }
- ++s2;
- }
-
- return (*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1;
-#else
- int r;
-
- while (((r = ((int)(*((Wuchar *)s1))) - *((Wuchar *)s2++))
- == 0) && *s1++);
-
- return r;
-#endif
-}
-
-#if 0 /* def __LOCALE_C_ONLY */
-#ifdef L_wcscmp
-weak_alias(wcscmp, wcscoll)
-#else /* L_wcscmp */
-weak_alias(strcmp, strcoll)
-#endif /* L_wcscmp */
-#endif /* __LOCALE_C_ONLY */
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsncmp
-#define L_strncmp
-#define Wstrncmp wcsncmp
-#else
-#define Wstrncmp strncmp
-#endif
-#endif
-
-#ifdef L_strncmp
-
-#ifndef WANT_WIDE
-#undef strncmp
-#else
-#undef wcsncmp
-#endif
-int attribute_hidden Wstrncmp(register const Wchar *s1, register const Wchar *s2, size_t n)
-{
-#ifdef WANT_WIDE
- while (n && (*((Wuchar *)s1) == *((Wuchar *)s2))) {
- if (!*s1++) {
- return 0;
- }
- ++s2;
- --n;
- }
-
- return (n == 0) ? 0 : ((*((Wuchar *)s1) < *((Wuchar *)s2)) ? -1 : 1);
-#else
- int r = 0;
-
- while (n--
- && ((r = ((int)(*((unsigned char *)s1))) - *((unsigned char *)s2++))
- == 0)
- && *s1++);
-
- return r;
-#endif
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemchr
-#define L_memchr
-#define Wmemchr wmemchr
-#else
-#define Wmemchr memchr
-#endif
-#endif
-
-#ifdef L_memchr
-
-#ifndef WANT_WIDE
-#undef memchr
-#else
-#undef wmemchr
-#endif
-Wvoid attribute_hidden *Wmemchr(const Wvoid *s, Wint c, size_t n)
-{
- register const Wuchar *r = (const Wuchar *) 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) {
- if (*r == ((Wuchar)c)) {
- return (Wvoid *) r; /* silence the warning */
- }
- ++r;
- --np;
- }
-
- return NULL;
-}
-#undef np
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcschr
-#define L_strchr
-#define Wstrchr wcschr
-#else
-#define Wstrchr strchr
-#endif
-#endif
-
-#ifdef L_strchr
-
-#ifndef WANT_WIDE
-#undef strchr
-#else
-#undef wcschr
-#endif
-Wchar attribute_hidden *Wstrchr(register const Wchar *s, Wint c)
-{
- do {
- if (*s == ((Wchar)c)) {
- return (Wchar *) s; /* silence the warning */
- }
- } while (*s++);
-
- return NULL;
-}
-
-#if 0 /* ndef L_wcschr */
-weak_alias(strchr, index)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcscspn
-#define L_strcspn
-#define Wstrcspn wcscspn
-#else
-#define Wstrcspn strcspn
-#endif
-#endif
-
-#ifdef L_strcspn
-
-#ifndef WANT_WIDE
-#undef strcspn
-#else
-#undef wcscspn
-#endif
-size_t attribute_hidden Wstrcspn(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s;
- register const Wchar *p;
-
- for ( s=s1 ; *s ; s++ ) {
- for ( p=s2 ; *p ; p++ ) {
- if (*p == *s) goto done;
- }
- }
- done:
- return s - s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcspbrk
-#define L_strpbrk
-#define Wstrpbrk wcspbrk
-#else
-#define Wstrpbrk strpbrk
-#endif
-#endif
-
-#ifdef L_strpbrk
-
-#ifndef WANT_WIDE
-#undef strpbrk
-#else
-#undef wcspbrk
-#endif
-Wchar attribute_hidden *Wstrpbrk(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s;
- register const Wchar *p;
-
- for ( s=s1 ; *s ; s++ ) {
- for ( p=s2 ; *p ; p++ ) {
- if (*p == *s) return (Wchar *) s; /* silence the warning */
- }
- }
- return NULL;
-}
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsrchr
-#define L_strrchr
-#define Wstrrchr wcsrchr
-#else
-#define Wstrrchr strrchr
-#endif
-#endif
-
-#ifdef L_strrchr
-
-#ifndef WANT_WIDE
-#undef strrchr
-#else
-#undef wcsrchr
-#endif
-Wchar attribute_hidden *Wstrrchr(register const Wchar *s, Wint c)
-{
- register const Wchar *p;
-
- p = NULL;
- do {
- if (*s == (Wchar) c) {
- p = s;
- }
- } while (*s++);
-
- return (Wchar *) p; /* silence the warning */
-}
-
-#if 0 /* ndef L_wcsrchr */
-weak_alias(strrchr, rindex)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsspn
-#define L_strspn
-#define Wstrspn wcsspn
-#else
-#define Wstrspn strspn
-#endif
-#endif
-
-#ifdef L_strspn
-
-#ifndef WANT_WIDE
-#undef strspn
-#else
-#undef wcsspn
-#endif
-size_t attribute_hidden Wstrspn(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s = s1;
- register const Wchar *p = s2;
-
- while (*p) {
- if (*p++ == *s) {
- ++s;
- p = s2;
- }
- }
- return s - s1;
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcsstr
-#define L_strstr
-#define Wstrstr wcsstr
-#else
-#define Wstrstr strstr
-#endif
-#endif
-
-#ifdef L_strstr
-
-/* NOTE: This is the simple-minded O(len(s1) * len(s2)) worst-case approach. */
-
-#ifndef WANT_WIDE
-#undef strstr
-#else
-#undef wcsstr
-#endif
-Wchar attribute_hidden *Wstrstr(const Wchar *s1, const Wchar *s2)
-{
- register const Wchar *s = s1;
- register const Wchar *p = s2;
-
- do {
- if (!*p) {
- return (Wchar *) s1;;
- }
- if (*p == *s) {
- ++p;
- ++s;
- } else {
- p = s2;
- if (!*s) {
- return NULL;
- }
- s = ++s1;
- }
- } while (1);
-}
-
-#if 0 /* def L_wcsstr */
-weak_alias(wcsstr, wcswcs)
-#endif
-
-#endif
-/**********************************************************************/
-#if 0
-#undef Wstrspn
-#undef Wstrpbrk
-
-#ifdef L_wcstok
-#define L_strtok_r
-#define Wstrtok_r wcstok
-#define Wstrspn wcsspn
-#define Wstrpbrk wcspbrk
-#else
-#define Wstrtok_r __strtok_r
-#define Wstrspn strspn
-#define Wstrpbrk strpbrk
-#endif
-#endif
-
-#ifdef L_strtok_r
-
-#ifndef WANT_WIDE
-#undef strtok_r
-#else
-#undef wcstok
-#endif
-Wchar attribute_hidden *Wstrtok_r(Wchar * __restrict s1, const Wchar * __restrict s2,
- Wchar ** __restrict next_start)
-{
- register Wchar *s;
- register Wchar *p;
-
-#if 1
- if (((s = s1) != NULL) || ((s = *next_start) != NULL)) {
- if (*(s += Wstrspn(s, s2))) {
- if ((p = Wstrpbrk(s, s2)) != NULL) {
- *p++ = 0;
- }
- } else {
- p = s = NULL;
- }
- *next_start = p;
- }
- return s;
-#else
- if (!(s = s1)) {
- s = *next_start;
- }
- if (s && *(s += Wstrspn(s, s2))) {
- if (*(p = s + Wstrcspn(s, s2))) {
- *p++ = 0;
- }
- *next_start = p;
- return s;
- }
- return NULL; /* TODO: set *next_start = NULL for safety? */
-#endif
-}
-
-#if 0 /* ndef L_wcstok */
-weak_alias(__strtok_r, strtok_r)
-#endif
-
-#endif
-/**********************************************************************/
-/* #ifdef L_wcstok */
-/* #define L_strtok */
-/* #define Wstrtok wcstok */
-/* #define Wstrtok_r wcstok_r */
-/* #else */
-/* #define Wstrtok strtok */
-/* #define Wstrtok_r strtok_r */
-/* #endif */
-
-#ifdef L_strtok
-#define Wstrtok strtok
-#define Wstrtok_r __strtok_r
-
-Wchar *Wstrtok(Wchar * __restrict s1, const Wchar * __restrict s2)
-{
- static Wchar *next_start; /* Initialized to 0 since in bss. */
- return Wstrtok_r(s1, s2, &next_start);
-}
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wmemset
-#define L_memset
-#define Wmemset wmemset
-#else
-#define Wmemset memset
-#endif
-#endif
-
-#ifdef L_memset
-
-#ifndef WANT_WIDE
-#undef memset
-#else
-#undef wmemset
-#endif
-Wvoid attribute_hidden *Wmemset(Wvoid *s, Wint c, size_t n)
-{
- register Wuchar *p = (Wuchar *) 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++ = (Wuchar) c;
- --np;
- }
-
- return s;
-}
-#undef np
-
-#endif
-/**********************************************************************/
-#if 0
-#ifdef L_wcslen
-#define L_strlen
-#define Wstrlen wcslen
-#else
-#define Wstrlen strlen
-#endif
-#endif
-
-#ifdef L_strlen
-
-#ifndef WANT_WIDE
-#undef strlen
-#else
-#undef wcslen
-#endif
-size_t attribute_hidden Wstrlen(const Wchar *s)
-{
- register const Wchar *p;
-
- for (p=s ; *p ; p++);
-
- return p - s;
-}
-
-#endif
-/**********************************************************************/
-/* ANSI/ISO end here */
-/**********************************************************************/
-#ifdef L_ffs
-
-#undef ffs
-int attribute_hidden __ffs(int i)
-{
-#if 1
- /* inlined binary search method */
- char n = 1;
-#if UINT_MAX == 0xffffU
- /* nothing to do here -- just trying to avoiding possible problems */
-#elif UINT_MAX == 0xffffffffU
- if (!(i & 0xffff)) {
- n += 16;
- i >>= 16;
- }
-#else
-#error ffs needs rewriting!
-#endif
-
- if (!(i & 0xff)) {
- n += 8;
- i >>= 8;
- }
- if (!(i & 0x0f)) {
- n += 4;
- i >>= 4;
- }
- if (!(i & 0x03)) {
- n += 2;
- i >>= 2;