newlib-2.4.0: wide character strings

git-svn-id: svn://kolibrios.org@6557 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2016-10-01 18:30:04 +00:00
parent 3c17dd1ccd
commit 01ff4a3818
54 changed files with 4439 additions and 52 deletions

View File

@ -211,42 +211,93 @@ STDLIB_SRCS= \
wctomb_r.c wctomb_r.c
STRING_SRCS= memcpy.c \ STRING_SRCS= \
memcmp.c \ bcmp.c \
memmove.c \ bcopy.c \
memset.c \ bzero.c \
memchr.c \ explicit_bzero.c \
stpcpy.c \ gnu_basename.c \
index.c \
memccpy.c \
memchr.c \
memcmp.c \
memcpy.c \
memmem.c \
memmove.c \
mempcpy.c \
memrchr.c \
memset.c \
rawmemchr.c \
rindex.c \
stpcpy.c \
stpncpy.c \ stpncpy.c \
strcat.c \ strcasecmp.c \
strchr.c \ strcasestr.c \
strcmp.c \ strcat.c \
strcoll.c \ strchr.c \
strcasecmp.c \ strchrnul.c \
strncasecmp.c \ strcmp.c \
strncat.c \ strcoll.c \
strncmp.c \ strcpy.c \
strncpy.c \ strcspn.c \
strndup.c \ strdup.c \
strndup_r.c \ strdup_r.c \
strnlen.c \ strerror.c \
strcasestr.c \ strerror_r.c \
strdup.c \ strlcat.c \
strdup_r.c \ strlcpy.c \
strerror.c \ strlen.c \
strlen.c \ strlwr.c \
strrchr.c \ strncasecmp.c \
strpbrk.c \ strncat.c \
strsep.c \ strncmp.c \
strstr.c \ strncpy.c \
strtok.c \ strndup.c \
strtok_r.c \ strndup_r.c \
strupr.c \ strnlen.c \
strxfrm.c \ strpbrk.c \
strcspn.c \ strrchr.c \
strspn.c \ strsep.c \
strcpy.c \ strspn.c \
u_strerr.c strstr.c \
strtok.c \
strtok_r.c \
strupr.c \
strxfrm.c \
swab.c \
u_strerr.c \
wcpcpy.c \
wcpncpy.c \
wcscasecmp.c \
wcscat.c \
wcschr.c \
wcscmp.c \
wcscoll.c \
wcscpy.c \
wcscspn.c \
wcsdup.c \
wcslcat.c \
wcslcpy.c \
wcslen.c \
wcsncasecmp.c \
wcsncat.c \
wcsncmp.c \
wcsncpy.c \
wcsnlen.c \
wcspbrk.c \
wcsrchr.c \
wcsspn.c \
wcsstr.c \
wcstok.c \
wcswidth.c \
wcsxfrm.c \
wcwidth.c \
wmemchr.c \
wmemcmp.c \
wmemcpy.c \
wmemmove.c \
wmemset.c
STDIO_SRCS= \ STDIO_SRCS= \
asiprintf.c \ asiprintf.c \

View File

@ -112,18 +112,43 @@ STDLIB_SRCS = {
"wctomb_r.c" "wctomb_r.c"
} }
STRING_SRCS = { STRING_SRCS = {
"memcpy.c", "bcmp.c",
"memcmp.c", "bcopy.c",
"memmove.c",
"memset.c", "bzero.c",
"explicit_bzero.c",
"gnu_basename.c",
"index.c",
"memccpy.c",
"memchr.c", "memchr.c",
"memcmp.c",
"memcpy.c",
"memmem.c",
"memmove.c",
"mempcpy.c",
"memrchr.c",
"memset.c",
"rawmemchr.c",
"rindex.c",
"stpcpy.c", "stpcpy.c",
"stpncpy.c", "stpncpy.c",
"strcasecmp.c",
"strcasestr.c",
"strcat.c", "strcat.c",
"strchr.c", "strchr.c",
"strchrnul.c",
"strcmp.c", "strcmp.c",
"strcoll.c", "strcoll.c",
"strcasecmp.c", "strcpy.c",
"strcspn.c",
"strdup.c",
"strdup_r.c",
"strerror.c",
"strerror_r.c",
"strlcat.c",
"strlcpy.c",
"strlen.c",
"strlwr.c",
"strncasecmp.c", "strncasecmp.c",
"strncat.c", "strncat.c",
"strncmp.c", "strncmp.c",
@ -131,23 +156,48 @@ STRING_SRCS = {
"strndup.c", "strndup.c",
"strndup_r.c", "strndup_r.c",
"strnlen.c", "strnlen.c",
"strcasestr.c",
"strdup.c",
"strdup_r.c",
"strerror.c",
"strlen.c",
"strrchr.c",
"strpbrk.c", "strpbrk.c",
"strrchr.c",
"strsep.c", "strsep.c",
"strspn.c",
"strstr.c", "strstr.c",
"strtok.c", "strtok.c",
"strtok_r.c", "strtok_r.c",
"strupr.c", "strupr.c",
"strxfrm.c", "strxfrm.c",
"strcspn.c", "swab.c",
"strspn.c", "u_strerr.c",
"strcpy.c", "wcpcpy.c",
"u_strerr.c" "wcpncpy.c",
"wcscasecmp.c",
"wcscat.c",
"wcschr.c",
"wcscmp.c",
"wcscoll.c",
"wcscpy.c",
"wcscspn.c",
"wcsdup.c",
"wcslcat.c",
"wcslcpy.c",
"wcslen.c",
"wcsncasecmp.c",
"wcsncat.c",
"wcsncmp.c",
"wcsncpy.c",
"wcsnlen.c",
"wcspbrk.c",
"wcsrchr.c",
"wcsspn.c",
"wcsstr.c",
"wcstok.c",
"wcswidth.c",
"wcsxfrm.c",
"wcwidth.c",
"wmemchr.c",
"wmemcmp.c",
"wmemcpy.c",
"wmemmove.c",
"wmemset.c"
} }
STDIO_SRCS = { STDIO_SRCS = {

View File

@ -15,7 +15,7 @@
/* C99 formats support (such as %a, %zu, ...) in IO functions like /* C99 formats support (such as %a, %zu, ...) in IO functions like
* printf/scanf enabled */ * printf/scanf enabled */
/* #undef _WANT_IO_C99_FORMATS */ #define _WANT_IO_C99_FORMATS
#define __DYNAMIC_REENT__ #define __DYNAMIC_REENT__
@ -56,7 +56,7 @@
#define _ATEXIT_DYNAMIC_ALLOC 1 #define _ATEXIT_DYNAMIC_ALLOC 1
/* True if long double supported. */ /* True if long double supported. */
#define _HAVE_LONG_DOUBLE 1 //#define _HAVE_LONG_DOUBLE 1
/* Define if compiler supports -fno-tree-loop-distribute-patterns. */ /* Define if compiler supports -fno-tree-loop-distribute-patterns. */
#define _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL 1 #define _HAVE_CC_INHIBIT_LOOP_TO_LIBCALL 1

View File

@ -1,4 +1,5 @@
OUTPUT_FORMAT(pei-i386) OUTPUT_FORMAT(pei-i386)
SEARCH_DIR("=/mingw32/lib")
ENTRY("_libc_crt_startup") ENTRY("_libc_crt_startup")

View File

@ -0,0 +1,49 @@
/*
FUNCTION
<<bcmp>>---compare two memory areas
INDEX
bcmp
ANSI_SYNOPSIS
#include <strings.h>
int bcmp(const void *<[s1]>, const void *<[s2]>, size_t <[n]>);
TRAD_SYNOPSIS
#include <strings.h>
int bcmp(<[s1]>, <[s2]>, <[n]>)
const void *<[s1]>;
const void *<[s2]>;
size_t <[n]>;
DESCRIPTION
This function compares not more than <[n]> bytes of the
object pointed to by <[s1]> with the object pointed to by <[s2]>.
This function is identical to <<memcmp>>.
RETURNS
The function returns an integer greater than, equal to or
less than zero according to whether the object pointed to by
<[s1]> is greater than, equal to or less than the object
pointed to by <[s2]>.
PORTABILITY
<<bcmp>> requires no supporting OS subroutines.
QUICKREF
bcmp ansi pure
*/
#include <string.h>
#include <strings.h>
int
_DEFUN (bcmp, (m1, m2, n),
_CONST void *m1 _AND
_CONST void *m2 _AND
size_t n)
{
return memcmp (m1, m2, n);
}

View File

@ -0,0 +1,39 @@
/*
FUNCTION
<<bcopy>>---copy memory regions
ANSI_SYNOPSIS
#include <strings.h>
void bcopy(const void *<[in]>, void *<[out]>, size_t <[n]>);
TRAD_SYNOPSIS
void bcopy(<[in]>, <[out]>, <[n]>
const void *<[in]>;
void *<[out]>;
size_t <[n]>;
DESCRIPTION
This function copies <[n]> bytes from the memory region
pointed to by <[in]> to the memory region pointed to by
<[out]>.
This function is implemented in term of <<memmove>>.
PORTABILITY
<<bcopy>> requires no supporting OS subroutines.
QUICKREF
bcopy - pure
*/
#include <string.h>
#include <strings.h>
void
_DEFUN (bcopy, (b1, b2, length),
_CONST void *b1 _AND
void *b2 _AND
size_t length)
{
memmove (b2, b1, length);
}

View File

@ -0,0 +1,43 @@
/*
FUNCTION
<<bzero>>---initialize memory to zero
INDEX
bzero
ANSI_SYNOPSIS
#include <strings.h>
void bzero(void *<[b]>, size_t <[length]>);
TRAD_SYNOPSIS
#include <strings.h>
void bzero(<[b]>, <[length]>)
void *<[b]>;
size_t <[length]>;
DESCRIPTION
<<bzero>> initializes <[length]> bytes of memory, starting at address
<[b]>, to zero.
RETURNS
<<bzero>> does not return a result.
PORTABILITY
<<bzero>> is in the Berkeley Software Distribution.
Neither ANSI C nor the System V Interface Definition (Issue 2) require
<<bzero>>.
<<bzero>> requires no supporting OS subroutines.
*/
#include <strings.h>
_VOID
_DEFUN (bzero, (b, length),
void *b _AND
size_t length)
{
char *ptr = (char *)b;
while (length--)
*ptr++ = 0;
}

View File

@ -0,0 +1,16 @@
/* $OpenBSD: explicit_bzero.c,v 1.2 2014/06/10 04:17:37 deraadt Exp $ */
/*
* Public domain.
* Written by Ted Unangst
*/
#include <string.h>
/*
* explicit_bzero - don't let the compiler optimize away bzero
*/
void
explicit_bzero(void *p, size_t n)
{
bzero(p, n);
}

View File

@ -0,0 +1,26 @@
#ifndef _NO_BASENAME
/* Copyright 2015 Red Hat, Inc.
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/* The differences with the POSIX version (unix/basename.c):
* - declared in <string.h> (instead of <libgen.h>);
* - the argument is never modified, and therefore is marked const;
* - the empty string is returned if path is an empty string, "/", or ends
* with a trailing slash.
*/
#include <string.h>
char *
_DEFUN (__gnu_basename, (path),
const char *path)
{
char *p;
if ((p = strrchr (path, '/')))
return p + 1;
return (char *) path;
}
#endif /* !_NO_BASENAME */

View File

@ -0,0 +1,45 @@
/*
FUNCTION
<<index>>---search for character in string
INDEX
index
ANSI_SYNOPSIS
#include <strings.h>
char * index(const char *<[string]>, int <[c]>);
TRAD_SYNOPSIS
#include <strings.h>
char * index(<[string]>, <[c]>);
char *<[string]>;
int *<[c]>;
DESCRIPTION
This function finds the first occurence of <[c]> (converted to
a char) in the string pointed to by <[string]> (including the
terminating null character).
This function is identical to <<strchr>>.
RETURNS
Returns a pointer to the located character, or a null pointer
if <[c]> does not occur in <[string]>.
PORTABILITY
<<index>> requires no supporting OS subroutines.
QUICKREF
index - pure
*/
#include <string.h>
#include <strings.h>
char *
_DEFUN (index, (s, c),
_CONST char *s _AND
int c)
{
return strchr (s, c);
}

View File

@ -0,0 +1,144 @@
/*
FUNCTION
<<memccpy>>---copy memory regions with end-token check
ANSI_SYNOPSIS
#include <string.h>
void* memccpy(void *restrict <[out]>, const void *restrict <[in]>,
int <[endchar]>, size_t <[n]>);
TRAD_SYNOPSIS
void *memccpy(<[out]>, <[in]>, <[endchar]>, <[n]>
void *<[out]>;
void *<[in]>;
int <[endchar]>;
size_t <[n]>;
DESCRIPTION
This function copies up to <[n]> bytes from the memory region
pointed to by <[in]> to the memory region pointed to by
<[out]>. If a byte matching the <[endchar]> is encountered,
the byte is copied and copying stops.
If the regions overlap, the behavior is undefined.
RETURNS
<<memccpy>> returns a pointer to the first byte following the
<[endchar]> in the <[out]> region. If no byte matching
<[endchar]> was copied, then <<NULL>> is returned.
PORTABILITY
<<memccpy>> is a GNU extension.
<<memccpy>> requires no supporting OS subroutines.
*/
#include <_ansi.h>
#include <stddef.h>
#include <string.h>
#include <limits.h>
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
#define UNALIGNED(X, Y) \
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
/* How many bytes are copied each iteration of the word copy loop. */
#define LITTLEBLOCKSIZE (sizeof (long))
/* Threshhold for punting to the byte copier. */
#define TOO_SMALL(LEN) ((LEN) < LITTLEBLOCKSIZE)
/* Macros for detecting endchar */
#if LONG_MAX == 2147483647L
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
#else
#if LONG_MAX == 9223372036854775807L
/* Nonzero if X (a long int) contains a NULL byte. */
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
#else
#error long int is not a 32bit or 64bit type.
#endif
#endif
_PTR
_DEFUN (memccpy, (dst0, src0, endchar, len0),
_PTR __restrict dst0 _AND
_CONST _PTR __restrict src0 _AND
int endchar0 _AND
size_t len0)
{
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
_PTR ptr = NULL;
char *dst = (char *) dst0;
char *src = (char *) src0;
char endchar = endchar0 & 0xff;
while (len0--)
{
if ((*dst++ = *src++) == endchar)
{
ptr = dst;
break;
}
}
return ptr;
#else
_PTR ptr = NULL;
char *dst = dst0;
_CONST char *src = src0;
long *aligned_dst;
_CONST long *aligned_src;
char endchar = endchar0 & 0xff;
/* If the size is small, or either SRC or DST is unaligned,
then punt into the byte copy loop. This should be rare. */
if (!TOO_SMALL(len0) && !UNALIGNED (src, dst))
{
unsigned int i;
unsigned long mask = 0;
aligned_dst = (long*)dst;
aligned_src = (long*)src;
/* The fast code reads the ASCII one word at a time and only
performs the bytewise search on word-sized segments if they
contain the search character, which is detected by XORing
the word-sized segment with a word-sized block of the search
character and then detecting for the presence of NULL in the
result. */
for (i = 0; i < LITTLEBLOCKSIZE; i++)
mask = (mask << 8) + endchar;
/* Copy one long word at a time if possible. */
while (len0 >= LITTLEBLOCKSIZE)
{
unsigned long buffer = (unsigned long)(*aligned_src);
buffer ^= mask;
if (DETECTNULL (buffer))
break; /* endchar is found, go byte by byte from here */
*aligned_dst++ = *aligned_src++;
len0 -= LITTLEBLOCKSIZE;
}
/* Pick up any residual with a byte copier. */
dst = (char*)aligned_dst;
src = (char*)aligned_src;
}
while (len0--)
{
if ((*dst++ = *src++) == endchar)
{
ptr = dst;
break;
}
}
return ptr;
#endif /* not PREFER_SIZE_OVER_SPEED */
}

View File

@ -0,0 +1,102 @@
/* Byte-wise substring search, using the Two-Way algorithm.
* Copyright (C) 2008 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*/
/*
FUNCTION
<<memmem>>---find memory segment
INDEX
memmem
ANSI_SYNOPSIS
#include <string.h>
char *memmem(const void *<[s1]>, size_t <[l1]>, const void *<[s2]>,
size_t <[l2]>);
DESCRIPTION
Locates the first occurrence in the memory region pointed to
by <[s1]> with length <[l1]> of the sequence of bytes pointed
to by <[s2]> of length <[l2]>. If you already know the
lengths of your haystack and needle, <<memmem>> can be much
faster than <<strstr>>.
RETURNS
Returns a pointer to the located segment, or a null pointer if
<[s2]> is not found. If <[l2]> is 0, <[s1]> is returned.
PORTABILITY
<<memmem>> is a newlib extension.
<<memmem>> requires no supporting OS subroutines.
QUICKREF
memmem pure
*/
#include <string.h>
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
# define RETURN_TYPE void *
# define AVAILABLE(h, h_l, j, n_l) ((j) <= (h_l) - (n_l))
# include "str-two-way.h"
#endif
void *
_DEFUN (memmem, (haystack_start, haystack_len, needle_start, needle_len),
const void *haystack_start _AND
size_t haystack_len _AND
const void *needle_start _AND
size_t needle_len)
{
/* Abstract memory is considered to be an array of 'unsigned char' values,
not an array of 'char' values. See ISO C 99 section 6.2.6.1. */
const unsigned char *haystack = (const unsigned char *) haystack_start;
const unsigned char *needle = (const unsigned char *) needle_start;
if (needle_len == 0)
/* The first occurrence of the empty string is deemed to occur at
the beginning of the string. */
return (void *) haystack;
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
/* Less code size, but quadratic performance in the worst case. */
while (needle_len <= haystack_len)
{
if (!memcmp (haystack, needle, needle_len))
return (void *) haystack;
haystack++;
haystack_len--;
}
return NULL;
#else /* compilation for speed */
/* Larger code size, but guaranteed linear performance. */
/* Sanity check, otherwise the loop might search through the whole
memory. */
if (haystack_len < needle_len)
return NULL;
/* Use optimizations in memchr when possible, to reduce the search
size of haystack using a linear algorithm with a smaller
coefficient. However, avoid memchr for long needles, since we
can often achieve sublinear performance. */
if (needle_len < LONG_NEEDLE_THRESHOLD)
{
haystack = memchr (haystack, *needle, haystack_len);
if (!haystack || needle_len == 1)
return (void *) haystack;
haystack_len -= haystack - (const unsigned char *) haystack_start;
if (haystack_len < needle_len)
return NULL;
return two_way_short_needle (haystack, haystack_len, needle, needle_len);
}
return two_way_long_needle (haystack, haystack_len, needle, needle_len);
#endif /* compilation for speed */
}

View File

@ -0,0 +1,107 @@
/*
FUNCTION
<<mempcpy>>---copy memory regions and return end pointer
ANSI_SYNOPSIS
#include <string.h>
void* mempcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
TRAD_SYNOPSIS
void *mempcpy(<[out]>, <[in]>, <[n]>
void *<[out]>;
void *<[in]>;
size_t <[n]>;
DESCRIPTION
This function copies <[n]> bytes from the memory region
pointed to by <[in]> to the memory region pointed to by
<[out]>.
If the regions overlap, the behavior is undefined.
RETURNS
<<mempcpy>> returns a pointer to the byte following the
last byte copied to the <[out]> region.
PORTABILITY
<<mempcpy>> is a GNU extension.
<<mempcpy>> requires no supporting OS subroutines.
*/
#include <_ansi.h>
#include <stddef.h>
#include <limits.h>
#include <string.h>
/* Nonzero if either X or Y is not aligned on a "long" boundary. */
#define UNALIGNED(X, Y) \
(((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
/* How many bytes are copied each iteration of the 4X unrolled loop. */
#define BIGBLOCKSIZE (sizeof (long) << 2)
/* How many bytes are copied each iteration of the word copy loop. */
#define LITTLEBLOCKSIZE (sizeof (long))
/* Threshhold for punting to the byte copier. */
#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
_PTR
_DEFUN (mempcpy, (dst0, src0, len0),
_PTR dst0 _AND
_CONST _PTR src0 _AND
size_t len0)
{
#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
char *dst = (char *) dst0;
char *src = (char *) src0;
while (len0--)
{
*dst++ = *src++;
}
return dst;
#else
char *dst = dst0;
_CONST char *src = src0;
long *aligned_dst;
_CONST long *aligned_src;
/* If the size is small, or either SRC or DST is unaligned,
then punt into the byte copy loop. This should be rare. */
if (!TOO_SMALL(len0) && !UNALIGNED (src, dst))
{
aligned_dst = (long*)dst;
aligned_src = (long*)src;
/* Copy 4X long words at a time if possible. */
while (len0 >= BIGBLOCKSIZE)
{
*aligned_dst++ = *aligned_src++;
*aligned_dst++ = *aligned_src++;
*aligned_dst++ = *aligned_src++;
*aligned_dst++ = *aligned_src++;
len0 -= BIGBLOCKSIZE;
}
/* Copy one long word at a time if possible. */
while (len0 >= LITTLEBLOCKSIZE)
{
*aligned_dst++ = *aligned_src++;
len0 -= LITTLEBLOCKSIZE;
}
/* Pick up any residual with a byte copier. */
dst = (char*)aligned_dst;
src = (char*)aligned_src;
}
while (len0--)
*dst++ = *src++;
return dst;
#endif /* not PREFER_SIZE_OVER_SPEED */
}

View File

@ -0,0 +1,134 @@
/*
FUNCTION
<<memrchr>>---reverse search for character in memory
INDEX
memrchr
ANSI_SYNOPSIS
#include <string.h>
void *memrchr(const void *<[src]>, int <[c]>, size_t <[length]>);
TRAD_SYNOPSIS
#include <string.h>
void *memrchr(<[src]>, <[c]>, <[length]>)
void *<[src]>;
void *<[c]>;
size_t <[length]>;
DESCRIPTION
This function searches memory starting at <[length]> bytes
beyond <<*<[src]>>> backwards for the character <[c]>.
The search only ends with the first occurrence of <[c]>; in
particular, <<NUL>> does not terminate the search.
RETURNS
If the character <[c]> is found within <[length]> characters
of <<*<[src]>>>, a pointer to the character is returned. If
<[c]> is not found, then <<NULL>> is returned.
PORTABILITY
<<memrchr>> is a GNU extension.
<<memrchr>> requires no supporting OS subroutines.
QUICKREF
memrchr
*/
#include <_ansi.h>
#include <string.h>
#include <limits.h>
/* Nonzero if X is not aligned on a "long" boundary. */
#define UNALIGNED(X) ((long)(X + 1) & (sizeof (long) - 1))
/* How many bytes are loaded each iteration of the word copy loop. */
#define LBLOCKSIZE (sizeof (long))
/* Threshhold for punting to the bytewise iterator. */
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
#if LONG_MAX == 2147483647L
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
#else
#if LONG_MAX == 9223372036854775807L
/* Nonzero if X (a long int) contains a NULL byte. */
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
#else
#error long int is not a 32bit or 64bit type.
#endif
#endif
#ifndef DETECTNULL
#error long int is not a 32bit or 64bit byte
#endif
/* DETECTCHAR returns nonzero if (long)X contains the byte used
to fill (long)MASK. */
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
_PTR
_DEFUN (memrchr, (src_void, c, length),
_CONST _PTR src_void _AND
int c _AND
size_t length)
{
_CONST unsigned char *src = (_CONST unsigned char *) src_void + length - 1;
unsigned char d = c;
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
unsigned long *asrc;
unsigned long mask;
unsigned int i;
while (UNALIGNED (src))
{
if (!length--)
return NULL;
if (*src == d)
return (void *) src;
src--;
}
if (!TOO_SMALL (length))
{
/* If we get this far, we know that length is large and src is
word-aligned. */
/* The fast code reads the source one word at a time and only
performs the bytewise search on word-sized segments if they
contain the search character, which is detected by XORing
the word-sized segment with a word-sized block of the search
character and then detecting for the presence of NUL in the
result. */
asrc = (unsigned long *) (src - LBLOCKSIZE + 1);
mask = d << 8 | d;
mask = mask << 16 | mask;
for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
mask = (mask << i) | mask;
while (length >= LBLOCKSIZE)
{
if (DETECTCHAR (*asrc, mask))
break;
length -= LBLOCKSIZE;
asrc--;
}
/* If there are fewer than LBLOCKSIZE characters left,
then we resort to the bytewise loop. */
src = (unsigned char *) asrc + LBLOCKSIZE - 1;
}
#endif /* not PREFER_SIZE_OVER_SPEED */
while (length--)
{
if (*src == d)
return (void *) src;
src--;
}
return NULL;
}

View File

@ -0,0 +1,121 @@
/*
FUNCTION
<<rawmemchr>>---find character in memory
INDEX
rawmemchr
ANSI_SYNOPSIS
#include <string.h>
void *rawmemchr(const void *<[src]>, int <[c]>);
TRAD_SYNOPSIS
#include <string.h>
void *rawmemchr(<[src]>, <[c]>)
void *<[src]>;
void *<[c]>;
DESCRIPTION
This function searches memory starting at <<*<[src]>>> for the
character <[c]>. The search only ends with the first occurrence
of <[c]>; in particular, <<NUL>> does not terminate the search.
No bounds checking is performed, so this function should only
be used when it is certain that the character <[c]> will be found.
RETURNS
A pointer to the first occurance of character <[c]>.
PORTABILITY
<<rawmemchr>> is a GNU extension.
<<rawmemchr>> requires no supporting OS subroutines.
QUICKREF
rawmemchr
*/
#include <_ansi.h>
#include <string.h>
#include <limits.h>
/* Nonzero if X is not aligned on a "long" boundary. */
#define UNALIGNED(X) ((long)X & (sizeof (long) - 1))
/* How many bytes are loaded each iteration of the word copy loop. */
#define LBLOCKSIZE (sizeof (long))
/* Threshhold for punting to the bytewise iterator. */
#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
#if LONG_MAX == 2147483647L
#define DETECTNULL(X) (((X) - 0x01010101) & ~(X) & 0x80808080)
#else
#if LONG_MAX == 9223372036854775807L
/* Nonzero if X (a long int) contains a NULL byte. */
#define DETECTNULL(X) (((X) - 0x0101010101010101) & ~(X) & 0x8080808080808080)
#else
#error long int is not a 32bit or 64bit type.
#endif
#endif
#ifndef DETECTNULL
#error long int is not a 32bit or 64bit byte
#endif
/* DETECTCHAR returns nonzero if (long)X contains the byte used
to fill (long)MASK. */
#define DETECTCHAR(X,MASK) (DETECTNULL(X ^ MASK))
_PTR
_DEFUN (rawmemchr, (src_void, c),
_CONST _PTR src_void _AND
int c)
{
_CONST unsigned char *src = (_CONST unsigned char *) src_void;
unsigned char d = c;
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
unsigned long *asrc;
unsigned long mask;
unsigned int i;
while (UNALIGNED (src))
{
if (*src == d)
return (void *) src;
src++;
}
/* If we get this far, we know that src is word-aligned. */
/* The fast code reads the source one word at a time and only
performs the bytewise search on word-sized segments if they
contain the search character, which is detected by XORing
the word-sized segment with a word-sized block of the search
character and then detecting for the presence of NUL in the
result. */
asrc = (unsigned long *) src;
mask = d << 8 | d;
mask = mask << 16 | mask;
for (i = 32; i < LBLOCKSIZE * 8; i <<= 1)
mask = (mask << i) | mask;
while (1)
{
if (DETECTCHAR (*asrc, mask))
break;
asrc++;
}
/* We have the matching word, now we resort to a bytewise loop. */
src = (unsigned char *) asrc;
#endif /* !PREFER_SIZE_OVER_SPEED && !__OPTIMIZE_SIZE__ */
while (1)
{
if (*src == d)
return (void *) src;
src++;
}
}

View File

@ -0,0 +1,45 @@
/*
FUNCTION
<<rindex>>---reverse search for character in string
INDEX
rindex
ANSI_SYNOPSIS
#include <string.h>
char * rindex(const char *<[string]>, int <[c]>);
TRAD_SYNOPSIS
#include <strings.h>
char * rindex(<[string]>, <[c]>);
char *<[string]>;
int *<[c]>;
DESCRIPTION
This function finds the last occurence of <[c]> (converted to
a char) in the string pointed to by <[string]> (including the
terminating null character).
This function is identical to <<strrchr>>.
RETURNS
Returns a pointer to the located character, or a null pointer
if <[c]> does not occur in <[string]>.
PORTABILITY
<<rindex>> requires no supporting OS subroutines.
QUICKREF
rindex - pure
*/
#include <string.h>
#include <strings.h>
char *
_DEFUN (rindex, (s, c),
_CONST char *s _AND
int c)
{
return strrchr (s, c);
}

View File

@ -0,0 +1,47 @@
/*
FUNCTION
<<strchrnul>>---search for character in string
INDEX
strchrnul
ANSI_SYNOPSIS
#include <string.h>
char * strchrnul(const char *<[string]>, int <[c]>);
TRAD_SYNOPSIS
#include <string.h>
char * strchrnul(<[string]>, <[c]>);
const char *<[string]>;
int <[c]>;
DESCRIPTION
This function finds the first occurence of <[c]> (converted to
a char) in the string pointed to by <[string]> (including the
terminating null character).
RETURNS
Returns a pointer to the located character, or a pointer
to the concluding null byte if <[c]> does not occur in <[string]>.
PORTABILITY
<<strchrnul>> is a GNU extension.
<<strchrnul>> requires no supporting OS subroutines. It uses
strchr() and strlen() from elsewhere in this library.
QUICKREF
strchrnul
*/
#include <string.h>
char *
_DEFUN (strchrnul, (s1, i),
_CONST char *s1 _AND
int i)
{
char *s = strchr(s1, i);
return s ? s : (char *)s1 + strlen(s1);
}

View File

@ -0,0 +1,85 @@
/* GNU variant of strerror_r. */
/*
FUNCTION
<<strerror_r>>---convert error number to string and copy to buffer
INDEX
strerror_r
ANSI_SYNOPSIS
#include <string.h>
#ifdef _GNU_SOURCE
char *strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>);
#else
int strerror_r(int <[errnum]>, char *<[buffer]>, size_t <[n]>);
#endif
TRAD_SYNOPSIS
#include <string.h>
char *strerror_r(<[errnum]>, <[buffer]>, <[n]>)
int <[errnum]>;
char *<[buffer]>;
size_t <[n]>;
DESCRIPTION
<<strerror_r>> converts the error number <[errnum]> into a
string and copies the result into the supplied <[buffer]> for
a length up to <[n]>, including the NUL terminator. The value of
<[errnum]> is usually a copy of <<errno>>. If <<errnum>> is not a known
error number, the result is the empty string.
See <<strerror>> for how strings are mapped to <<errnum>>.
RETURNS
There are two variants: the GNU version always returns a NUL-terminated
string, which is <[buffer]> if all went well, but which is another
pointer if <[n]> was too small (leaving <[buffer]> untouched). If the
return is not <[buffer]>, your application must not modify that string.
The POSIX version returns 0 on success, <[EINVAL]> if <<errnum>> was not
recognized, and <[ERANGE]> if <[n]> was too small. The variant chosen
depends on macros that you define before inclusion of <<string.h>>.
PORTABILITY
<<strerror_r>> with a <[char *]> result is a GNU extension.
<<strerror_r>> with an <[int]> result is required by POSIX 2001.
This function is compliant only if <<_user_strerror>> is not provided,
or if it is thread-safe and uses separate storage according to whether
the second argument of that function is non-zero. For more details
on <<_user_strerror>>, see the <<strerror>> documentation.
POSIX states that the contents of <[buf]> are unspecified on error,
although this implementation guarantees a NUL-terminated string for
all except <[n]> of 0.
POSIX recommends that unknown <[errnum]> result in a message including
that value, however it is not a requirement and this implementation
provides only an empty string (unless you provide <<_user_strerror>>).
POSIX also recommends that unknown <[errnum]> fail with EINVAL even
when providing such a message, however it is not a requirement and
this implementation will return success if <<_user_strerror>> provided
a non-empty alternate string without assigning into its third argument.
<<strerror_r>> requires no supporting OS subroutines.
*/
#undef __STRICT_ANSI__
#define _GNU_SOURCE
#include <errno.h>
#include <string.h>
#undef strerror_r
/* For backwards-compatible linking, this must be the GNU signature;
see xpg_strerror_r.c for the POSIX version. */
char *
_DEFUN (strerror_r, (errnum, buffer, n),
int errnum _AND
char *buffer _AND
size_t n)
{
char *error = _strerror_r (_REENT, errnum, 1, NULL);
if (strlen (error) >= n)
return error;
return strcpy (buffer, error);
}

View File

@ -0,0 +1,74 @@
/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <string.h>
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
size_t
_DEFUN (strlcat, (dst, src, siz),
char *dst _AND
_CONST char *src _AND
size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (n-- != 0 && *d != '\0')
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return(dlen + strlen(s));
while (*s != '\0') {
if (n != 1) {
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return(dlen + (s - src)); /* count does not include NUL */
}

View File

@ -0,0 +1,70 @@
/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
#include <string.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns strlen(src); if retval >= siz, truncation occurred.
*/
size_t
_DEFUN (strlcpy, (dst, src, siz),
char *dst _AND
_CONST char *src _AND
size_t siz)
{
register char *d = dst;
register const char *s = src;
register size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0) {
do {
if ((*d++ = *s++) == 0)
break;
} while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0) {
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return(s - src - 1); /* count does not include NUL */
}

View File

@ -0,0 +1,46 @@
/*
FUNCTION
<<strlwr>>---force string to lowercase
INDEX
strlwr
ANSI_SYNOPSIS
#include <string.h>
char *strlwr(char *<[a]>);
TRAD_SYNOPSIS
#include <string.h>
char *strlwr(<[a]>)
char *<[a]>;
DESCRIPTION
<<strlwr>> converts each character in the string at <[a]> to
lowercase.
RETURNS
<<strlwr>> returns its argument, <[a]>.
PORTABILITY
<<strlwr>> is not widely portable.
<<strlwr>> requires no supporting OS subroutines.
QUICKREF
strlwr
*/
#include <string.h>
#include <ctype.h>
char *
_DEFUN (strlwr, (s),
char *s)
{
unsigned char *ucs = (unsigned char *) s;
for ( ; *ucs != '\0'; ucs++)
{
*ucs = tolower(*ucs);
}
return s;
}

View File

@ -0,0 +1,256 @@
/*
FUNCTION
<<strsignal>>---convert signal number to string
INDEX
strsignal
ANSI_SYNOPSIS
#include <string.h>
char *strsignal(int <[signal]>);
TRAD_SYNOPSIS
#include <string.h>
char *strsignal(<[signal]>)
int <[signal]>;
DESCRIPTION
<<strsignal>> converts the signal number <[signal]> into a
string. If <[signal]> is not a known signal number, the result
will be of the form "Unknown signal NN" where NN is the <[signal]>
is a decimal number.
RETURNS
This function returns a pointer to a string. Your application must
not modify that string.
PORTABILITY
POSIX.1-2008 C requires <<strsignal>>, but does not specify the strings used
for each signal number.
<<strsignal>> requires no supporting OS subroutines.
QUICKREF
strsignal pure
*/
/*
* Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
*
* COPYRIGHT (c) 2010.
* On-Line Applications Research Corporation (OAR).
*
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
* OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
* SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*
* $Id$
*/
#include <string.h>
#include <signal.h>
#include <stdio.h>
#include <reent.h>
char *
_DEFUN (strsignal, (signal),
int signal)
{
char *buffer;
struct _reent *ptr;
ptr = _REENT;
_REENT_CHECK_SIGNAL_BUF(ptr);
buffer = _REENT_SIGNAL_BUF(ptr);
#if defined(SIGRTMIN) && defined(SIGRTMAX)
if ((signal >= SIGRTMIN) || (signal <= SIGRTMAX)) {
siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
return buffer;
}
#endif
switch (signal) {
#ifdef SIGHUP
case SIGHUP:
buffer = "Hangup";
break;
#endif
#ifdef SIGINT
case SIGINT:
buffer = "Interrupt";
break;
#endif
#ifdef SIGQUIT
case SIGQUIT:
buffer = "Quit";
break;
#endif
#ifdef SIGILL
case SIGILL:
buffer = "Illegal instruction";
break;
#endif
#ifdef SIGTRAP
case SIGTRAP:
buffer = "Trace/breakpoint trap";
break;
#endif
#ifdef SIGIOT
#if defined(SIGABRT) && (SIGIOT != SIGABRT)
case SIGABRT:
#endif
case SIGIOT:
buffer = "IOT trap";
break;
#endif
#ifdef SIGEMT
case SIGEMT:
buffer = "EMT trap";
break;
#endif
#ifdef SIGFPE
case SIGFPE:
buffer = "Floating point exception";
break;
#endif
#ifdef SIGKILL
case SIGKILL:
buffer = "Killed";
break;
#endif
#ifdef SIGBUS
case SIGBUS:
buffer = "Bus error";
break;
#endif
#ifdef SIGSEGV
case SIGSEGV:
buffer = "Segmentation fault";
break;
#endif
#ifdef SIGSYS
case SIGSYS:
buffer = "Bad system call";
break;
#endif
#ifdef SIGPIPE
case SIGPIPE:
buffer = "Broken pipe";
break;
#endif
#ifdef SIGALRM
case SIGALRM:
buffer = "Alarm clock";
break;
#endif
#ifdef SIGTERM
case SIGTERM:
buffer = "Terminated";
break;
#endif
#ifdef SIGURG
case SIGURG:
buffer = "Urgent I/O condition";
break;
#endif
#ifdef SIGSTOP
case SIGSTOP:
buffer = "Stopped (signal)";
break;
#endif
#ifdef SIGTSTP
case SIGTSTP:
buffer = "Stopped";
break;
#endif
#ifdef SIGCONT
case SIGCONT:
buffer = "Continued";
break;
#endif
#ifdef SIGCHLD
#if defined(SIGCLD) && (SIGCHLD != SIGCLD)
case SIGCLD:
#endif
case SIGCHLD:
buffer = "Child exited";
break;
#endif
#ifdef SIGTTIN
case SIGTTIN:
buffer = "Stopped (tty input)";
break;
#endif
#ifdef SIGTTOUT
case SIGTTOUT:
buffer = "Stopped (tty output)";
break;
#endif
#ifdef SIGIO
#if defined(SIGPOLL) && (SIGIO != SIGPOLL)
case SIGPOLL:
#endif
case SIGIO:
buffer = "I/O possible";
break;
#endif
#ifdef SIGWINCH
case SIGWINCH:
buffer = "Window changed";
break;
#endif
#ifdef SIGUSR1
case SIGUSR1:
buffer = "User defined signal 1";
break;
#endif
#ifdef SIGUSR2
case SIGUSR2:
buffer = "User defined signal 2";
break;
#endif
#ifdef SIGPWR
case SIGPWR:
buffer = "Power Failure";
break;
#endif
#ifdef SIGXCPU
case SIGXCPU:
buffer = "CPU time limit exceeded";
break;
#endif
#ifdef SIGXFSZ
case SIGXFSZ:
buffer = "File size limit exceeded";
break;
#endif
#ifdef SIGVTALRM
case SIGVTALRM :
buffer = "Virtual timer expired";
break;
#endif
#ifdef SIGPROF
case SIGPROF:
buffer = "Profiling timer expired";
break;
#endif
#if defined(SIGLOST) && SIGLOST != SIGPWR
case SIGLOST:
buffer = "Resource lost";
break;
#endif
default:
siprintf (buffer, "Unknown signal %d", signal);
break;
}
return buffer;
}

View File

@ -0,0 +1,44 @@
/*
FUNCTION
<<swab>>---swap adjacent bytes
ANSI_SYNOPSIS
#include <unistd.h>
void swab(const void *<[in]>, void *<[out]>, ssize_t <[n]>);
TRAD_SYNOPSIS
void swab(<[in]>, <[out]>, <[n]>
void *<[in]>;
void *<[out]>;
ssize_t <[n]>;
DESCRIPTION
This function copies <[n]> bytes from the memory region
pointed to by <[in]> to the memory region pointed to by
<[out]>, exchanging adjacent even and odd bytes.
PORTABILITY
<<swab>> requires no supporting OS subroutines.
*/
#include <unistd.h>
void
_DEFUN (swab, (b1, b2, length),
_CONST void *b1 _AND
void *b2 _AND
ssize_t length)
{
const char *from = b1;
char *to = b2;
ssize_t ptr;
for (ptr = 1; ptr < length; ptr += 2)
{
char p = from[ptr];
char q = from[ptr-1];
to[ptr-1] = p;
to[ptr ] = q;
}
if (ptr == length) /* I.e., if length is odd, */
to[ptr-1] = 0; /* then pad with a NUL. */
}

View File

@ -0,0 +1,41 @@
/*
FUNCTION
<<wcpcpy>>---copy a wide-character string returning a pointer to its end
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcpcpy(wchar_t *<[s1]>, const wchar_t *<[s2]>);
TRAD_SYNOPSIS
wchar_t *wcpcpy(<[s1]>, <[s2]>
wchar_t *__restrict <[s1]>;
const wchar_t *__restrict <[s2]>;
DESCRIPTION
The <<wcpcpy>> function copies the wide-character string pointed to by
<[s2]> (including the terminating null wide-character code) into the
array pointed to by <[s1]>. If copying takes place between objects that
overlap, the behaviour is undefined.
RETURNS
This function returns a pointer to the end of the destination string,
thus pointing to the trailing '\0'.
PORTABILITY
<<wcpcpy>> is a GNU extension.
No supporting OS subroutines are required.
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcpcpy, (s1, s2),
wchar_t *__restrict s1 _AND
_CONST wchar_t *__restrict s2)
{
while ((*s1++ = *s2++))
;
return --s1;
}

View File

@ -0,0 +1,62 @@
/*
FUNCTION
<<wcpncpy>>---copy part of a wide-character string returning a pointer to its end
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcpncpy(wchar_t *__restrict <[s1]>,
const wchar_t *__restrict <[s2]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wcpncpy(<[s1]>, <[s2]>, <[n]>
wchar_t *__restrict <[s1]>;
const wchar_t *__restrict <[s2]>;
size_t <[n]>;
DESCRIPTION
The <<wcpncpy>> function copies not more than n wide-character codes
(wide-character codes that follow a null wide-character code are not
copied) from the array pointed to by <[s2]> to the array pointed to
by <[s1]>. If copying takes place between objects that overlap, the
behaviour is undefined.
If the array pointed to by <[s2]> is a wide-character string that is
shorter than <[n]> wide-character codes, null wide-character codes are
appended to the copy in the array pointed to by <[s1]>, until <[n]>
wide-character codes in all are written.
RETURNS
The <<wcpncpy>> function returns <[s1]>; no return value is reserved to
indicate an error.
PORTABILITY
<<wcpncpy>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcpncpy, (dst, src, count),
wchar_t *__restrict dst _AND
_CONST wchar_t *__restrict src _AND
size_t count)
{
wchar_t *ret = NULL;
while (count > 0)
{
--count;
if ((*dst++ = *src++) == L'\0')
{
ret = dst - 1;
break;
}
}
while (count-- > 0)
*dst++ = L'\0';
return ret ? ret : dst;
}

View File

@ -0,0 +1,56 @@
/*
FUNCTION
<<wcscasecmp>>---case-insensitive wide character string compare
INDEX
wcscasecmp
ANSI_SYNOPSIS
#include <wchar.h>
int wcscasecmp(const wchar_t *<[a]>, const wchar_t *<[b]>);
TRAD_SYNOPSIS
#include <wchar.h>
int wcscasecmp(<[a]>, <[b]>)
wchar_t *<[a]>;
wchar_t *<[b]>;
DESCRIPTION
<<wcscasecmp>> compares the wide character string at <[a]> to
the wide character string at <[b]> in a case-insensitive manner.
RETURNS
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
both are converted to uppercase), <<wcscasecmp>> returns a
number greater than zero. If the two strings match,
<<wcscasecmp>> returns zero. If <<*<[a]>>> sorts
lexicographically before <<*<[b]>>>, <<wcscasecmp>> returns a
number less than zero.
PORTABILITY
POSIX-1.2008
<<wcscasecmp>> requires no supporting OS subroutines. It uses
tolower() from elsewhere in this library.
QUICKREF
wcscasecmp
*/
#include <wchar.h>
#include <wctype.h>
int
_DEFUN (wcscasecmp, (s1, s2),
_CONST wchar_t *s1 _AND
_CONST wchar_t *s2)
{
while (*s1 != '\0' && towlower(*s1) == towlower(*s2))
{
s1++;
s2++;
}
return towlower(*s1) - towlower(*s2);
}

View File

@ -0,0 +1,86 @@
/*
FUNCTION
<<wcscat>>---concatenate two wide-character strings
INDEX
wcscat
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcscat(wchar_t *__restrict <[s1]>,
const wchar_t *__restrict <[s2]>);
TRAD_SYNOPSIS
wchar_t *wcscat(<[s1]>, <[s2]>
wchar_t *__restrict <[s1]>;
const wchar_t *__restrict <[s2]>;
DESCRIPTION
The <<wcscat>> function appends a copy of the wide-character string
pointed to by <[s2]> (including the terminating null wide-character
code) to the end of the wide-character string pointed to by <[s1]>.
The initial wide-character code of <[s2]> overwrites the null
wide-character code at the end of <[s1]>. If copying takes place between
objects that overlap, the behaviour is undefined.
RETURNS
The <<wcscat>> function returns <[s1]>;
no return value is reserved to indicate an error.
PORTABILITY
<<wcscat>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcscat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcscat, (s1, s2),
wchar_t *__restrict s1 _AND
_CONST wchar_t *__restrict s2)
{
wchar_t *p;
wchar_t *q;
_CONST wchar_t *r;
p = s1;
while (*p)
p++;
q = p;
r = s2;
while (*r)
*q++ = *r++;
*q = '\0';
return s1;
}

View File

@ -0,0 +1,82 @@
/*
FUNCTION
<<wcschr>>---wide-character string scanning operation
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcschr(const wchar_t *<[s]>, wchar_t <[c]>);
TRAD_SYNOPSIS
wchar_t *wcschr(<[s]>, <[c]>
const wchar_t *<[s]>;
wchar_t <[c]>;
DESCRIPTION
The <<wcschr>> function locates the first occurrence of <[c]> in the
wide-character string pointed to by <[s]>. The value of <[c]> must be a
character representable as a type wchar_t and must be a wide-character
code corresponding to a valid character in the current locale.
The terminating null wide-character string.
RETURNS
Upon completion, <<wcschr>> returns a pointer to the wide-character
code, or a null pointer if the wide-character code is not found.
PORTABILITY
<<wcschr>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcschr.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcschr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
*/
#include <_ansi.h>
#include <stddef.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcschr, (s, c),
_CONST wchar_t * s _AND
wchar_t c)
{
_CONST wchar_t *p;
p = s;
do
{
if (*p == c)
{
/* LINTED interface specification */
return (wchar_t *) p;
}
} while (*p++);
return NULL;
}

View File

@ -0,0 +1,83 @@
/*
FUNCTION
<<wcscmp>>---compare two wide-character strings
ANSI_SYNOPSIS
#include <wchar.h>
int wcscmp(const wchar_t *<[s1]>, *<[s2]>);
TRAD_SYNOPSIS
int wcscmp(<[s1]>, <[s2]>
const wchar_t *<[s1]>, <[s2]>;
DESCRIPTION
The <<wcscmp>> function compares the wide-character string pointed to
by <[s1]> to the wide-character string pointed to by <[s2]>.
The sign of a non-zero return value is determined by the sign of the
difference between the values of the first pair of wide-character codes
that differ in the objects being compared.
RETURNS
Upon completion, <<wcscmp>> returns an integer greater than, equal to
or less than 0, if the wide-character string pointed to by <[s1]> is
greater than, equal to or less than the wide-character string pointed
to by <[s2]> respectively.
PORTABILITY
<<wcscmp>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD$ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <wchar.h>
/*
* Compare strings.
*/
int
_DEFUN (wcscmp, (s1, s2),
_CONST wchar_t * s1 _AND
_CONST wchar_t * s2)
{
while (*s1 == *s2++)
if (*s1++ == 0)
return (0);
return (*s1 - *--s2);
}

View File

@ -0,0 +1,48 @@
/*
FUNCTION
<<wcscoll>>---locale-specific wide-character string compare
INDEX
wcscoll
ANSI_SYNOPSIS
#include <wchar.h>
int wcscoll(const wchar_t *<[stra]>, const wchar_t * <[strb]>);
TRAD_SYNOPSIS
#include <wchar.h>
int wcscoll(<[stra]>, <[strb]>)
wchar_t *<[stra]>;
wchar_t *<[strb]>;
DESCRIPTION
<<wcscoll>> compares the wide-character string pointed to by
<[stra]> to the wide-character string pointed to by <[strb]>,
using an interpretation appropriate to the current <<LC_COLLATE>>
state.
The current implementation of <<wcscoll>> simply uses <<wcscmp>>
and does not support any language-specific sorting.
RETURNS
If the first string is greater than the second string,
<<wcscoll>> returns a number greater than zero. If the two
strings are equivalent, <<wcscoll>> returns zero. If the first
string is less than the second string, <<wcscoll>> returns a
number less than zero.
PORTABILITY
<<wcscoll>> is ISO/IEC 9899/AMD1:1995 (ISO C).
*/
#include <_ansi.h>
#include <wchar.h>
int
_DEFUN (wcscoll, (a, b),
_CONST wchar_t *a _AND
_CONST wchar_t *b)
{
return wcscmp (a, b);
}

View File

@ -0,0 +1,80 @@
/*
FUNCTION
<<wcscpy>>---copy a wide-character string
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcscpy(wchar_t *__restrict <[s1]>,
const wchar_t *__restrict <[s2]>);
TRAD_SYNOPSIS
wchar_t *wcscpy(<[s1]>, <[s2]>
wchar_t *__restrict <[s1]>;
const wchar_t *__restrict <[s2]>;
DESCRIPTION
The <<wcscpy>> function copies the wide-character string pointed to by
<[s2]> (including the terminating null wide-character code) into the
array pointed to by <[s1]>. If copying takes place between objects that
overlap, the behaviour is undefined.
RETURNS
The <<wcscpy>> function returns <[s1]>; no return value is reserved to
indicate an error.
PORTABILITY
<<wcscpy>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcscpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcscpy, (s1, s2),
wchar_t *__restrict s1 _AND
_CONST wchar_t *__restrict s2)
{
wchar_t *p;
_CONST wchar_t *q;
*s1 = '\0';
p = s1;
q = s2;
while (*q)
*p++ = *q++;
*p = '\0';
return s1;
}

View File

@ -0,0 +1,86 @@
/*
FUNCTION
<<wcscspn>>---get length of a complementary wide substring
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcscspn(const wchar_t *<[s]>, wchar_t *<[set]>);
TRAD_SYNOPSIS
size_t wcscspn(<[s]>, <[set]>
const wchar_t *<[s]>;
const wchar_t *<[set]>;
DESCRIPTION
The <<wcscspn>> function computes the length of the maximum initial
segment of the wide-character string pointed to by <[s]> which consists
entirely of wide-character codes not from the wide-character string
pointed to by <[set]>.
RETURNS
The <<wcscspn>> function returns the length of the initial substring of
<[s1]>; no return value is reserved to indicate an error.
PORTABILITY
<<wcscspn>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcscspn.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
*/
#include <_ansi.h>
#include <wchar.h>
size_t
_DEFUN (wcscspn, (s, set),
_CONST wchar_t * s _AND
_CONST wchar_t * set)
{
_CONST wchar_t *p;
_CONST wchar_t *q;
p = s;
while (*p)
{
q = set;
while (*q)
{
if (*p == *q)
goto done;
q++;
}
p++;
}
done:
return (p - s);
}

View File

@ -0,0 +1,62 @@
/*
FUNCTION
<<wcsdup>>---wide character string duplicate
INDEX
wcsdup
INDEX
_wcsdup_r
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcsdup(const wchar_t *<[str]>);
#include <wchar.h>
wchar_t *_wcsdup_r(struct _reent *<[ptr]>, const wchar_t *<[str]>);
TRAD_SYNOPSIS
#include <wchar.h>
wchar_t *wcsdup(<[ptr]>, <[str]>)
struct _reent *<[ptr]>;
wchar_t *<[str]>;
DESCRIPTION
<<wcsdup>> allocates a new wide character string using <<malloc>>,
and copies the content of the argument <[str]> into the newly
allocated string, thus making a copy of <[str]>.
RETURNS
<<wcsdup>> returns a pointer to the copy of <[str]> if enough
memory for the copy was available. Otherwise it returns NULL
and errno is set to ENOMEM.
PORTABILITY
POSIX-1.2008
QUICKREF
wcsdup
*/
#include <reent.h>
#include <stdlib.h>
#include <wchar.h>
wchar_t *
_wcsdup_r (struct _reent *p, const wchar_t *str)
{
size_t len = wcslen (str) + 1;
wchar_t *copy = _malloc_r (p, len * sizeof (wchar_t));
if (copy)
wmemcpy (copy, str, len);
return copy;
}
#ifndef _REENT_ONLY
wchar_t *
wcsdup (const wchar_t *str)
{
return _wcsdup_r (_REENT, str);
}
#endif /* !_REENT_ONLY */

View File

@ -0,0 +1,108 @@
/*
FUNCTION
<<wcslcat>>---concatenate wide-character strings to specified length
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcslcat(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
TRAD_SYNOPSIS
#include <wchar.h>
size_t wcslcat(<[dst]>, <[src]>, <[siz]>
wchar_t *<[dst]>;
const wchar_t *<[src]>;
size_t <[siz]>;
DESCRIPTION
The <<wcslcat>> function appends wide characters from <[src]> to
end of the <[dst]> wide-character string so that the resultant
wide-character string is not more than <[siz]> wide characters
including the terminating null wide-character code. A terminating
null wide character is always added unless <[siz]> is 0. Thus,
the maximum number of wide characters that can be appended from
<[src]> is <[siz]> - 1. If copying takes place between objects
that overlap, the behaviour is undefined.
RETURNS
Wide-character string length of initial <[dst]> plus the
wide-character string length of <[src]> (does not include
terminating null wide-characters). If the return value is
greater than or equal to <[siz]>, then truncation occurred and
not all wide characters from <[src]> were appended.
PORTABILITY
No supporting OS subroutines are required.
*/
/* $NetBSD: wcslcat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/* from OpenBSD: strlcat.c,v 1.3 2000/11/24 11:10:02 itojun Exp */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <_ansi.h>
#include <wchar.h>
/*
* Appends src to string dst of size siz (unlike wcsncat, siz is the
* full size of dst, not space left). At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns wcslen(initial dst) + wcslen(src); if retval >= siz,
* truncation occurred.
*/
size_t
_DEFUN (wcslcat, (dst, src, siz),
wchar_t * dst _AND
_CONST wchar_t * src _AND
size_t siz)
{
wchar_t *d = dst;
_CONST wchar_t *s = src;
size_t n = siz;
size_t dlen;
/* Find the end of dst and adjust bytes left but don't go past end */
while (*d != '\0' && n-- != 0)
d++;
dlen = d - dst;
n = siz - dlen;
if (n == 0)
return (dlen + wcslen (s));
while (*s != '\0')
{
if (n != 1)
{
*d++ = *s;
n--;
}
s++;
}
*d = '\0';
return (dlen + (s - src)); /* count does not include NUL */
}

View File

@ -0,0 +1,102 @@
/*
FUNCTION
<<wcslcpy>>---copy a wide-character string to specified length
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcslcpy(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
TRAD_SYNOPSIS
#include <wchar.h>
size_t wcslcpy(<[dst]>, <[src]>, <[siz]>)
wchar_t *<[dst]>;
const wchar_t *<[src]>;
size_t <[siz]>;
DESCRIPTION
<<wcslcpy>> copies wide characters from <[src]> to <[dst]>
such that up to <[siz]> - 1 characters are copied. A
terminating null is appended to the result, unless <[siz]>
is zero.
RETURNS
<<wcslcpy>> returns the number of wide characters in <[src]>,
not including the terminating null wide character. If the
return value is greater than or equal to <[siz]>, then
not all wide characters were copied from <[src]> and truncation
occurred.
PORTABILITY
No supporting OS subroutines are required.
*/
/* $NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */
/*
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <_ansi.h>
#include <wchar.h>
/*
* Copy src to string dst of size siz. At most siz-1 characters
* will be copied. Always NUL terminates (unless siz == 0).
* Returns wcslen(src); if retval >= siz, truncation occurred.
*/
size_t
_DEFUN (wcslcpy, (dst, src, siz),
wchar_t * dst _AND
_CONST wchar_t * src _AND
size_t siz)
{
wchar_t *d = dst;
_CONST wchar_t *s = src;
size_t n = siz;
/* Copy as many bytes as will fit */
if (n != 0 && --n != 0)
{
do
{
if ((*d++ = *s++) == 0)
break;
}
while (--n != 0);
}
/* Not enough room in dst, add NUL and traverse rest of src */
if (n == 0)
{
if (siz != 0)
*d = '\0'; /* NUL-terminate dst */
while (*s++)
;
}
return (s - src - 1); /* count does not include NUL */
}

View File

@ -0,0 +1,72 @@
/*
FUNCTION
<<wcslen>>---get wide-character string length
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcslen(const wchar_t *<[s]>);
TRAD_SYNOPSIS
size_t wcslen(<[s]>
const wchar_t *<[s]>;
DESCRIPTION
The <<wcslen>> function computes the number of wide-character codes
in the wide-character string to which <[s]> points, not including the
terminating null wide-character code.
RETURNS
The <<wcslen>> function returns the length of <[s]>; no return value is
reserved to indicate an error.
PORTABILITY
<<wcslen>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcslen.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
*/
#include <_ansi.h>
#include <wchar.h>
size_t
_DEFUN (wcslen, (s),
_CONST wchar_t * s)
{
_CONST wchar_t *p;
p = s;
while (*p)
p++;
return p - s;
}

View File

@ -0,0 +1,64 @@
/*
FUNCTION
<<wcsncasecmp>>---case-insensitive wide character string compare
INDEX
wcsncasecmp
ANSI_SYNOPSIS
#include <wchar.h>
int wcsncasecmp(const wchar_t *<[a]>, const wchar_t * <[b]>, size_t <[length]>);
TRAD_SYNOPSIS
#include <wchar.h>
int wcsncasecmp(<[a]>, <[b]>, <[length]>)
wchar_t *<[a]>;
wchar_t *<[b]>;
size_t <[length]>
DESCRIPTION
<<wcsncasecmp>> compares up to <[length]> wide characters
from the string at <[a]> to the string at <[b]> in a
case-insensitive manner.
RETURNS
If <<*<[a]>>> sorts lexicographically after <<*<[b]>>> (after
both are converted to uppercase), <<wcsncasecmp>> returns a
number greater than zero. If the two strings are equivalent,
<<wcsncasecmp>> returns zero. If <<*<[a]>>> sorts
lexicographically before <<*<[b]>>>, <<wcsncasecmp>> returns a
number less than zero.
PORTABILITY
POSIX-1.2008
<<wcsncasecmp>> requires no supporting OS subroutines. It uses
tolower() from elsewhere in this library.
QUICKREF
wcsncasecmp
*/
#include <wchar.h>
#include <wctype.h>
int
_DEFUN (wcsncasecmp, (s1, s2, n),
_CONST wchar_t *s1 _AND
_CONST wchar_t *s2 _AND
size_t n)
{
if (n == 0)
return 0;
while (n-- != 0 && towlower(*s1) == towlower(*s2))
{
if (n == 0 || *s1 == '\0' || *s2 == '\0')
break;
s1++;
s2++;
}
return towlower(*s1) - towlower(*s2);
}

View File

@ -0,0 +1,92 @@
/*
FUNCTION
<<wcsncat>>---concatenate part of two wide-character strings
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcsncat(wchar_t *__restrict <[s1]>,
const wchar_t *__restrict <[s2]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wcsncat(<[s1]>, <[s2]>, <[n]>
wchar_t *__restrict <[s1]>;
const wchar_t *__restrict <[s2]>;
size_t <[n]>;
DESCRIPTION
The <<wcsncat>> function appends not more than <[n]> wide-character
codes (a null wide-character code and wide-character codes that follow
it are not appended) from the array pointed to by <[s2]> to the end of
the wide-character string pointed to by <[s1]>. The initial
wide-character code of <[s2]> overwrites the null wide-character code
at the end of <[s1]>.
A terminating null wide-character code is always appended to the result.
If copying takes place between objects that overlap, the behaviour is
undefined.
RETURNS
The <<wcsncat>> function returns <[s1]>; no return value is reserved to
indicate an error.
PORTABILITY
<<wcsncat>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcsncat.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcsncat, (s1, s2, n),
wchar_t *__restrict s1 _AND
_CONST wchar_t *__restrict s2 _AND
size_t n)
{
wchar_t *p;
wchar_t *q;
_CONST wchar_t *r;
p = s1;
while (*p)
p++;
q = p;
r = s2;
while (*r && n)
{
*q++ = *r++;
n--;
}
*q = '\0';
return s1;
}

View File

@ -0,0 +1,91 @@
/*
FUNCTION
<<wcsncmp>>---compare part of two wide-character strings
ANSI_SYNOPSIS
#include <wchar.h>
int wcsncmp(const wchar_t *<[s1]>, const wchar_t *<[s2]>, size_t <[n]>);
TRAD_SYNOPSIS
int wcsncmp(<[s1]>, <[s2]>, <[n]>
const wchar_t *<[s1]>;
const wchar_t *<[s2]>;
size_t <[n]>;
DESCRIPTION
The <<wcsncmp>> function compares not more than <[n]> wide-character
codes (wide-character codes that follow a null wide-character code are
not compared) from the array pointed to by <[s1]> to the array pointed
to by <[s2]>.
The sign of a non-zero return value is determined by the sign of the
difference between the values of the first pair of wide-character codes
that differ in the objects being compared.
RETURNS
Upon successful completion, <<wcsncmp>> returns an integer greater than,
equal to or less than 0, if the possibly null-terminated array pointed
to by <[s1]> is greater than, equal to or less than the possibly
null-terminated array pointed to by <[s2]> respectively.
PORTABILITY
<<wcsncmp>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD$ */
/*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <wchar.h>
int
_DEFUN (wcsncmp, (s1, s2, n),
_CONST wchar_t * s1 _AND
_CONST wchar_t * s2 _AND
size_t n)
{
if (n == 0)
return (0);
do
{
if (*s1 != *s2++)
{
return (*s1 - *--s2);
}
if (*s1++ == 0)
break;
}
while (--n != 0);
return (0);
}

View File

@ -0,0 +1,59 @@
/*
FUNCTION
<<wcsncpy>>---copy part of a wide-character string
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcsncpy(wchar_t *__restrict <[s1]>,
const wchar_t *__restrict <[s2]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wcsncpy(<[s1]>, <[s2]>, <[n]>
wchar_t *__restrict <[s1]>;
const wchar_t *__restrict <[s2]>;
size_t <[n]>;
DESCRIPTION
The <<wcsncpy>> function copies not more than <[n]> wide-character codes
(wide-character codes that follow a null wide-character code are not
copied) from the array pointed to by <[s2]> to the array pointed to
by <[s1]>. If copying takes place between objects that overlap, the
behaviour is undefined. Note that if <[s1]> contains more than <[n]>
wide characters before its terminating null, the result is not
null-terminated.
If the array pointed to by <[s2]> is a wide-character string that is
shorter than <[n]> wide-character codes, null wide-character codes are
appended to the copy in the array pointed to by <[s1]>, until <[n]>
wide-character codes in all are written.
RETURNS
The <<wcsncpy>> function returns <[s1]>; no return value is reserved to
indicate an error.
PORTABILITY
ISO/IEC 9899; POSIX.1.
No supporting OS subroutines are required.
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcsncpy, (s1, s2, n),
wchar_t *__restrict s1 _AND
_CONST wchar_t *__restrict s2 _AND
size_t n)
{
wchar_t *dscan=s1;
while(n > 0)
{
--n;
if((*dscan++ = *s2++) == L'\0') break;
}
while(n-- > 0) *dscan++ = L'\0';
return s1;
}

View File

@ -0,0 +1,75 @@
/*
FUNCTION
<<wcsnlen>>---get fixed-size wide-character string length
INDEX
wcsnlen
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcsnlen(const wchar_t *<[s]>, size_t <[maxlen]>);
TRAD_SYNOPSIS
#include <wchar.h>
size_t wcsnlen(<[s]>, <[maxlen]>)
wchar_t *<[s]>;
size_t <[maxlen]>;
DESCRIPTION
The <<wcsnlen>> function computes the number of wide-character codes
in the wide-character string pointed to by <[s]> not including the
terminating L'\0' wide character but at most <[maxlen]> wide
characters.
RETURNS
<<wcsnlen>> returns the length of <[s]> if it is less then <[maxlen]>,
or <[maxlen]> if there is no L'\0' wide character in first <[maxlen]>
characters.
PORTABILITY
<<wcsnlen>> is a GNU extension.
<<wcsnlen>> requires no supporting OS subroutines.
*/
/*
* Copyright (c) 2003, Artem B. Bityuckiy (dedekind@mail.ru).
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the above copyright notice,
* this condition statement, and the following disclaimer are retained
* in any redistributions of the source code.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <_ansi.h>
#include <sys/types.h>
#include <wchar.h>
size_t
_DEFUN(wcsnlen, (s, maxlen),
_CONST wchar_t *s _AND
size_t maxlen)
{
_CONST wchar_t *p;
p = s;
while (*p && maxlen-- > 0)
p++;
return (size_t)(p - s);
}

View File

@ -0,0 +1,88 @@
/*
FUNCTION
<<wcspbrk>>----scan wide-character string for a wide-character code
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcspbrk(const wchar_t *<[s]>, const wchar_t *<[set]>);
TRAD_SYNOPSIS
wchar_t *wcspbrk(<[s]>, <[set]>
const wchar_t *<[s]>;
const wchar_t *<[set]>;
DESCRIPTION
The <<wcspbrk>> function locates the first occurrence in the
wide-character string pointed to by <[s]> of any wide-character code
from the wide-character string pointed to by <[set]>.
RETURNS
Upon successful completion, <<wcspbrk>> returns a pointer to the
wide-character code or a null pointer if no wide-character code from
<[set]> occurs in <[s]>.
PORTABILITY
<<wcspbrk>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcspbrk.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp
*/
#include <_ansi.h>
#include <stddef.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcspbrk, (s, set),
_CONST wchar_t * s _AND
_CONST wchar_t * set)
{
_CONST wchar_t *p;
_CONST wchar_t *q;
p = s;
while (*p)
{
q = set;
while (*q)
{
if (*p == *q)
{
/* LINTED interface specification */
return (wchar_t *) p;
}
q++;
}
p++;
}
return NULL;
}

View File

@ -0,0 +1,88 @@
/*
FUNCTION
<<wcsrchr>>---wide-character string scanning operation
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcsrchr(const wchar_t *<[s]>, wchar_t <[c]>);
TRAD_SYNOPSIS
#include <wchar.h>
wchar_t *wcsrchr(<[s]>, <[c]>
const wchar_t *<[s]>;
wchar_t <[c]>;
DESCRIPTION
The <<wcsrchr>> function locates the last occurrence of <[c]> in the
wide-character string pointed to by <[s]>. The value of <[c]> must be a
character representable as a type wchar_t and must be a wide-character
code corresponding to a valid character in the current locale.
The terminating null wide-character code is considered to be part of
the wide-character string.
RETURNS
Upon successful completion, <<wcsrchr>> returns a pointer to the
wide-character code or a null pointer if <[c]> does not occur in the
wide-character string.
PORTABILITY
<<wcsrchr>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcsrchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcsrchr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
*/
#include <_ansi.h>
#include <stddef.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcsrchr, (s, c),
_CONST wchar_t * s _AND
wchar_t c)
{
_CONST wchar_t *p;
p = s;
while (*p)
p++;
while (s <= p)
{
if (*p == c)
{
/* LINTED interface specification */
return (wchar_t *) p;
}
p--;
}
return NULL;
}

View File

@ -0,0 +1,88 @@
/*
FUNCTION
<<wcsspn>>---get length of a wide substring
ANSI_SYNOPSIS
#include <wchar.h>
size_t wcsspn(const wchar_t *<[s]>, const wchar_t *<[set]>);
TRAD_SYNOPSIS
size_t wcsspn(<[s]>, <[set]>
const wchar_t *<[s]>;
const wchar_t *<[set]>;
DESCRIPTION
The <<wcsspn>> function computes the length of the maximum initial
segment of the wide-character string pointed to by <[s]> which consists
entirely of wide-character codes from the wide-character string
pointed to by <[set]>.
RETURNS
The wcsspn() function returns the length <[s1]>; no return value is
reserved to indicate an error.
PORTABILITY
<<wcsspn>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wcsspn.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcsspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp
*/
#include <_ansi.h>
#include <wchar.h>
size_t
_DEFUN (wcsspn, (s, set),
_CONST wchar_t * s _AND
_CONST wchar_t * set)
{
_CONST wchar_t *p;
_CONST wchar_t *q;
p = s;
while (*p)
{
q = set;
while (*q)
{
if (*p == *q)
break;
q++;
}
if (!*q)
goto done;
p++;
}
done:
return (p - s);
}

View File

@ -0,0 +1,106 @@
/*
FUNCTION
<<wcsstr>>---find a wide-character substring
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcsstr(const wchar_t *__restrict <[big]>,
const wchar_t *__restrict <[little]>);
TRAD_SYNOPSIS
wchar_t *wcsstr(<[big]>, <[little]>
const wchar_t *__restrict <[big]>;
const wchar_t *__restrict <[little]>;
DESCRIPTION
The <<wcsstr>> function locates the first occurrence in the
wide-character string pointed to by <[big]> of the sequence of
wide characters (excluding the terminating null wide character) in the
wide-character string pointed to by <[little]>.
RETURNS
On successful completion, <<wcsstr>> returns a pointer to the located
wide-character string, or a null pointer if the wide-character string
is not found.
If <[little]> points to a wide-character string with zero length,
the function returns <[big]>.
PORTABILITY
<<wcsstr>> is ISO/IEC 9899/AMD1:1995 (ISO C).
*/
/* $NetBSD: wcsstr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp
*/
#include <_ansi.h>
#include <stddef.h>
#include <wchar.h>
wchar_t *
_DEFUN (wcsstr, (big, little),
_CONST wchar_t *__restrict big _AND
_CONST wchar_t *__restrict little)
{
_CONST wchar_t *p;
_CONST wchar_t *q;
_CONST wchar_t *r;
if (!*little)
{
/* LINTED interface specification */
return (wchar_t *) big;
}
if (wcslen (big) < wcslen (little))
return NULL;
p = big;
q = little;
while (*p)
{
q = little;
r = p;
while (*q)
{
if (*r != *q)
break;
q++;
r++;
}
if (!*q)
{
/* LINTED interface specification */
return (wchar_t *) p;
}
p++;
}
return NULL;
}

View File

@ -0,0 +1,182 @@
/*
FUNCTION
<<wcstok>>---get next token from a string
INDEX
wcstok
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wcstok(wchar_t *__restrict <[source]>,
const wchar_t *__restrict <[delimiters]>,
wchar_t **__restrict <[lasts]>);
TRAD_SYNOPSIS
#include <wchar.h>
wchar_t *wcstok(<[source]>, <[delimiters]>, <[lasts]>);
wchar_t *__restrict <[source]>;
wchar_t *__restrict <[delimiters]>;
wchar_t **__restrict <[lasts]>;
DESCRIPTION
The <<wcstok>> function is the wide-character equivalent of the
<<strtok_r>> function (which in turn is the same as the <<strtok>>
function with an added argument to make it thread-safe).
The <<wcstok>> function is used to isolate (one at a time)
sequential tokens in a null-terminated wide-character string,
<<*<[source]>>>. A token is defined as a substring not containing
any wide-characters from <<*<[delimiters]>>>.
The first time that <<wcstok>> is called, <<*<[source]>>> should
be specified with the wide-character string to be searched, and
<<*<[lasts]>>>--but not <<lasts>>, which must be non-NULL--may be
random; subsequent calls, wishing to obtain further tokens from
the same string, should pass a null pointer for <<*<[source]>>>
instead but must supply <<*<[lasts]>>> unchanged from the last
call. The separator wide-character string, <<*<[delimiters]>>>,
must be supplied each time and may change between calls.
A pointer to placeholder <<*<[lasts]>>> must be supplied by
the caller, and is set each time as needed to save the state
by <<wcstok>>. Every call to <<wcstok>> with <<*<[source]>>>
== <<NULL>> must pass the value of <<*<[lasts]>>> as last set
by <<wcstok>>.
The <<wcstok>> function returns a pointer to the beginning of each
subsequent token in the string, after replacing the separator
wide-character itself with a null wide-character. When no more tokens
remain, a null pointer is returned.
RETURNS
<<wcstok>> returns a pointer to the first wide character of a token, or
<<NULL>> if there is no token.
NOTES
<<wcstok>> is thread-safe (unlike <<strtok>>, but like <<strtok_r>>).
<<wcstok>> writes into the string being searched.
PORTABILITY
<<wcstok>> is C99 and POSIX.1-2001.
<<wcstok>> requires no supporting OS subroutines.
QUICKREF
strtok ansi pure
*/
/* wcstok for Newlib created by adapting strtok_r, 2008. */
/*
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <wchar.h>
wchar_t *
_DEFUN (wcstok, (s, delim, lasts),
register wchar_t *__restrict s _AND
register const wchar_t *__restrict delim _AND
wchar_t **__restrict lasts)
{
register const wchar_t *spanp;
register int c, sc;
wchar_t *tok;
if (s == NULL && (s = *lasts) == NULL)
return (NULL);
/*
* Skip (span) leading delimiters (s += wcsspn(s, delim), sort of).
*/
cont:
c = *s++;
for (spanp = delim; (sc = *spanp++) != L'\0';) {
if (c == sc) goto cont;
}
if (c == L'\0') { /* no non-delimiter characters */
*lasts = NULL;
return (NULL);
}
tok = s - 1;
/*
* Scan token (scan for delimiters: s += wcscspn(s, delim), sort of).
* Note that delim must have one NUL; we stop if we see that, too.
*/
for (;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == L'\0')
s = NULL;
else
s[-1] = L'\0';
*lasts = s;
return (tok);
}
} while (sc != L'\0');
}
/* NOTREACHED */
}
/* The remainder of this file can serve as a regression test. Compile
* with -D_REGRESSION_TEST. */
#if defined(_REGRESSION_TEST) /* [Test code: example from C99 standard */
#include <stdio.h>
#include <wchar.h>
/* example from C99 standard with minor additions to be a test */
int
main(void)
{
int errs=0;
static wchar_t str1[] = L"?a???b,,,#c";
static wchar_t str2[] = L"\t \t";
wchar_t *t, *ptr1, *ptr2;
t = wcstok(str1, L"?", &ptr1); // t points to the token L"a"
if(wcscmp(t,L"a")) errs++;
t = wcstok(NULL, L",", &ptr1); // t points to the token L"??b"
if(wcscmp(t,L"??b")) errs++;
t = wcstok(str2, L" \t", &ptr2); // t is a null pointer
if(t != NULL) errs++;
t = wcstok(NULL, L"#,", &ptr1); // t points to the token L"c"
if(wcscmp(t,L"c")) errs++;
t = wcstok(NULL, L"?", &ptr1); // t is a null pointer
if(t != NULL) errs++;
printf("wcstok() test ");
if(errs) printf("FAILED %d test cases", errs);
else printf("passed");
printf(".\n");
return(errs);
}
#endif /* defined(_REGRESSION_TEST) ] */

View File

@ -0,0 +1,73 @@
/*
FUNCTION
<<wcswidth>>---number of column positions of a wide-character string
INDEX
wcswidth
ANSI_SYNOPSIS
#include <wchar.h>
int wcswidth(const wchar_t *<[pwcs]>, size_t <[n]>);
TRAD_SYNOPSIS
#include <wchar.h>
int wcswidth(<[pwcs]>, <[n]>)
wchar_t *<[wc]>;
size_t <[n]>;
DESCRIPTION
The <<wcswidth>> function shall determine the number of column
positions required for <[n]> wide-character codes (or fewer than <[n]>
wide-character codes if a null wide-character code is encountered
before <[n]> wide-character codes are exhausted) in the string pointed
to by <[pwcs]>.
RETURNS
The <<wcswidth>> function either shall return 0 (if <[pwcs]> points to a
null wide-character code), or return the number of column positions
to be occupied by the wide-character string pointed to by <[pwcs]>, or
return -1 (if any of the first <[n]> wide-character codes in the
wide-character string pointed to by <[pwcs]> is not a printable
wide-character code).
PORTABILITY
<<wcswidth>> has been introduced in the Single UNIX Specification Volume 2.
<<wcswidth>> has been marked as an extension in the Single UNIX Specification Volume 3.
*/
#include <_ansi.h>
#include <wchar.h>
#include "local.h"
int
_DEFUN (wcswidth, (pwcs, n),
_CONST wchar_t *pwcs _AND
size_t n)
{
int w, len = 0;
if (!pwcs || n == 0)
return 0;
do {
wint_t wi = *pwcs;
#ifdef _MB_CAPABLE
wi = _jp2uc (wi);
/* First half of a surrogate pair? */
if (sizeof (wchar_t) == 2 && wi >= 0xd800 && wi <= 0xdbff)
{
wint_t wi2;
/* Extract second half and check for validity. */
if (--n == 0 || (wi2 = _jp2uc (*++pwcs)) < 0xdc00 || wi2 > 0xdfff)
return -1;
/* Compute actual unicode value to use in call to __wcwidth. */
wi = (((wi & 0x3ff) << 10) | (wi2 & 0x3ff)) + 0x10000;
}
#endif /* _MB_CAPABLE */
if ((w = __wcwidth (wi)) < 0)
return -1;
len += w;
} while (*pwcs++ && --n > 0);
return len;
}

View File

@ -0,0 +1,53 @@
/*
FUNCTION
<<wcsxfrm>>---locale-specific wide-character string transformation
INDEX
wcsxfrm
ANSI_SYNOPSIS
#include <wchar.h>
int wcsxfrm(wchar_t *__restrict <[stra]>,
const wchar_t *__restrict <[strb]>, size_t <[n]>);
TRAD_SYNOPSIS
#include <wchar.h>
size_t wcsxfrm(<[stra]>, <[strb]>, <[n]>)
wchar_t *__restrict <[stra]>;
wchar_t *__restrict <[strb]>;
size_t <[n]>
DESCRIPTION
<<wcsxfrm>> transforms the wide-character string pointed to by
<[strb]> to the wide-character string pointed to by <[stra]>,
Comparing two transformed wide strings with <<wcscmp>> should return
the same result as comparing the original strings with <<wcscoll>>.
No more than <[n]> wide characters are transformed, including the
trailing null character.
If <[n]> is 0, <[stra]> may be a NULL pointer.
The current implementation of <<wcsxfrm>> simply uses <<wcslcpy>>
and does not support any language-specific transformations.
RETURNS
<<wcsxfrm>> returns the length of the transformed wide character
string. if the return value is greater or equal to <[n]>, the
content of <[stra]> is undefined.
PORTABILITY
<<wcsxfrm>> is ISO/IEC 9899/AMD1:1995 (ISO C).
*/
#include <_ansi.h>
#include <wchar.h>
size_t
_DEFUN (wcsxfrm, (a, b, n),
wchar_t *__restrict a _AND
_CONST wchar_t *__restrict b _AND
size_t n)
{
return wcslcpy (a, b, n);
}

View File

@ -0,0 +1,346 @@
/*
FUNCTION
<<wcwidth>>---number of column positions of a wide-character code
INDEX
wcwidth
ANSI_SYNOPSIS
#include <wchar.h>
int wcwidth(const wchar_t <[wc]>);
TRAD_SYNOPSIS
#include <wchar.h>
int wcwidth(<[wc]>)
wchar_t *<[wc]>;
DESCRIPTION
The <<wcwidth>> function shall determine the number of column
positions required for the wide character <[wc]>. The application
shall ensure that the value of <[wc]> is a character representable
as a wchar_t, and is a wide-character code corresponding to a
valid character in the current locale.
RETURNS
The <<wcwidth>> function shall either return 0 (if <[wc]> is a null
wide-character code), or return the number of column positions to
be occupied by the wide-character code <[wc]>, or return -1 (if <[wc]>
does not correspond to a printable wide-character code).
PORTABILITY
<<wcwidth>> has been introduced in the Single UNIX Specification Volume 2.
<<wcwidth>> has been marked as an extension in the Single UNIX Specification Volume 3.
*/
/*
* This is an implementation of wcwidth() (defined in
* IEEE Std 1002.1-2001) for Unicode.
*
* http://www.opengroup.org/onlinepubs/007904975/functions/wcwidth.html
*
* In fixed-width output devices, Latin characters all occupy a single
* "cell" position of equal width, whereas ideographic CJK characters
* occupy two such cells. Interoperability between terminal-line
* applications and (teletype-style) character terminals using the
* UTF-8 encoding requires agreement on which character should advance
* the cursor by how many cell positions. No established formal
* standards exist at present on which Unicode character shall occupy
* how many cell positions on character terminals. These routines are
* a first attempt of defining such behavior based on simple rules
* applied to data provided by the Unicode Consortium.
*
* For some graphical characters, the Unicode standard explicitly
* defines a character-cell width via the definition of the East Asian
* FullWidth (F), Wide (W), Half-width (H), and Narrow (Na) classes.
* In all these cases, there is no ambiguity about which width a
* terminal shall use. For characters in the East Asian Ambiguous (A)
* class, the width choice depends purely on a preference of backward
* compatibility with either historic CJK or Western practice.
* Choosing single-width for these characters is easy to justify as
* the appropriate long-term solution, as the CJK practice of
* displaying these characters as double-width comes from historic
* implementation simplicity (8-bit encoded characters were displayed
* single-width and 16-bit ones double-width, even for Greek,
* Cyrillic, etc.) and not any typographic considerations.
*
* Much less clear is the choice of width for the Not East Asian
* (Neutral) class. Existing practice does not dictate a width for any
* of these characters. It would nevertheless make sense
* typographically to allocate two character cells to characters such
* as for instance EM SPACE or VOLUME INTEGRAL, which cannot be
* represented adequately with a single-width glyph. The following
* routines at present merely assign a single-cell width to all
* neutral characters, in the interest of simplicity. This is not
* entirely satisfactory and should be reconsidered before
* establishing a formal standard in this area. At the moment, the
* decision which Not East Asian (Neutral) characters should be
* represented by double-width glyphs cannot yet be answered by
* applying a simple rule from the Unicode database content. Setting
* up a proper standard for the behavior of UTF-8 character terminals
* will require a careful analysis not only of each Unicode character,
* but also of each presentation form, something the author of these
* routines has avoided to do so far.
*
* http://www.unicode.org/unicode/reports/tr11/
*
* Markus Kuhn -- 2007-05-26 (Unicode 5.0)
*
* Permission to use, copy, modify, and distribute this software
* for any purpose and without fee is hereby granted. The author
* disclaims all warranties with regard to this software.
*
* Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c
*/
#include <_ansi.h>
#include <wchar.h>
#ifndef _MB_CAPABLE
#include <wctype.h> /* iswprint, iswcntrl */
#endif
#include "local.h"
#ifdef _MB_CAPABLE
struct interval
{
int first;
int last;
};
/* auxiliary function for binary search in interval table */
static int
bisearch(wint_t ucs, const struct interval *table, int max)
{
int min = 0;
int mid;
if (ucs < table[0].first || ucs > table[max].last)
return 0;
while (max >= min)
{
mid = (min + max) / 2;
if (ucs > table[mid].last)
min = mid + 1;
else if (ucs < table[mid].first)
max = mid - 1;
else
return 1;
}
return 0;
}
#endif /* _MB_CAPABLE */
/* The following function defines the column width of an ISO 10646
* character as follows:
*
* - The null character (U+0000) has a column width of 0.
*
* - Other C0/C1 control characters and DEL will lead to a return
* value of -1.
*
* - If the current language is recognized as a language usually using
* CJK fonts, spacing characters in the East Asian Ambiguous (A)
* category as defined in Unicode Technical Report #11 have a column
* width of 2.
*
* - Non-spacing and enclosing combining characters (general
* category code Mn or Me in the Unicode database) have a
* column width of 0.
*
* - SOFT HYPHEN (U+00AD) has a column width of 1.
*
* - Other format characters (general category code Cf in the Unicode
* database) and ZERO WIDTH SPACE (U+200B) have a column width of 0.
*
* - Hangul Jamo medial vowels and final consonants (U+1160-U+11FF)
* have a column width of 0.
*
* - Spacing characters in the East Asian Wide (W) or East Asian
* Full-width (F) category as defined in Unicode Technical
* Report #11 have a column width of 2.
*
* - All remaining characters (including all printable
* ISO 8859-1 and WGL4 characters, Unicode control characters,
* etc.) have a column width of 1.
*
* This implementation assumes that wint_t characters are encoded
* in ISO 10646.
*/
int
_DEFUN (__wcwidth, (ucs),
_CONST wint_t ucs)
{
#ifdef _MB_CAPABLE
/* sorted list of non-overlapping intervals of East Asian Ambiguous
* characters, generated by "uniset +WIDTH-A -cat=Me -cat=Mn -cat=Cf c" */
static const struct interval ambiguous[] = {
{ 0x00A1, 0x00A1 }, { 0x00A4, 0x00A4 }, { 0x00A7, 0x00A8 },
{ 0x00AA, 0x00AA }, { 0x00AE, 0x00AE }, { 0x00B0, 0x00B4 },
{ 0x00B6, 0x00BA }, { 0x00BC, 0x00BF }, { 0x00C6, 0x00C6 },
{ 0x00D0, 0x00D0 }, { 0x00D7, 0x00D8 }, { 0x00DE, 0x00E1 },
{ 0x00E6, 0x00E6 }, { 0x00E8, 0x00EA }, { 0x00EC, 0x00ED },
{ 0x00F0, 0x00F0 }, { 0x00F2, 0x00F3 }, { 0x00F7, 0x00FA },
{ 0x00FC, 0x00FC }, { 0x00FE, 0x00FE }, { 0x0101, 0x0101 },
{ 0x0111, 0x0111 }, { 0x0113, 0x0113 }, { 0x011B, 0x011B },
{ 0x0126, 0x0127 }, { 0x012B, 0x012B }, { 0x0131, 0x0133 },
{ 0x0138, 0x0138 }, { 0x013F, 0x0142 }, { 0x0144, 0x0144 },
{ 0x0148, 0x014B }, { 0x014D, 0x014D }, { 0x0152, 0x0153 },
{ 0x0166, 0x0167 }, { 0x016B, 0x016B }, { 0x01CE, 0x01CE },
{ 0x01D0, 0x01D0 }, { 0x01D2, 0x01D2 }, { 0x01D4, 0x01D4 },
{ 0x01D6, 0x01D6 }, { 0x01D8, 0x01D8 }, { 0x01DA, 0x01DA },
{ 0x01DC, 0x01DC }, { 0x0251, 0x0251 }, { 0x0261, 0x0261 },
{ 0x02C4, 0x02C4 }, { 0x02C7, 0x02C7 }, { 0x02C9, 0x02CB },
{ 0x02CD, 0x02CD }, { 0x02D0, 0x02D0 }, { 0x02D8, 0x02DB },
{ 0x02DD, 0x02DD }, { 0x02DF, 0x02DF }, { 0x0391, 0x03A1 },
{ 0x03A3, 0x03A9 }, { 0x03B1, 0x03C1 }, { 0x03C3, 0x03C9 },
{ 0x0401, 0x0401 }, { 0x0410, 0x044F }, { 0x0451, 0x0451 },
{ 0x2010, 0x2010 }, { 0x2013, 0x2016 }, { 0x2018, 0x2019 },
{ 0x201C, 0x201D }, { 0x2020, 0x2022 }, { 0x2024, 0x2027 },
{ 0x2030, 0x2030 }, { 0x2032, 0x2033 }, { 0x2035, 0x2035 },
{ 0x203B, 0x203B }, { 0x203E, 0x203E }, { 0x2074, 0x2074 },
{ 0x207F, 0x207F }, { 0x2081, 0x2084 }, { 0x20AC, 0x20AC },
{ 0x2103, 0x2103 }, { 0x2105, 0x2105 }, { 0x2109, 0x2109 },
{ 0x2113, 0x2113 }, { 0x2116, 0x2116 }, { 0x2121, 0x2122 },
{ 0x2126, 0x2126 }, { 0x212B, 0x212B }, { 0x2153, 0x2154 },
{ 0x215B, 0x215E }, { 0x2160, 0x216B }, { 0x2170, 0x2179 },
{ 0x2190, 0x2199 }, { 0x21B8, 0x21B9 }, { 0x21D2, 0x21D2 },
{ 0x21D4, 0x21D4 }, { 0x21E7, 0x21E7 }, { 0x2200, 0x2200 },
{ 0x2202, 0x2203 }, { 0x2207, 0x2208 }, { 0x220B, 0x220B },
{ 0x220F, 0x220F }, { 0x2211, 0x2211 }, { 0x2215, 0x2215 },
{ 0x221A, 0x221A }, { 0x221D, 0x2220 }, { 0x2223, 0x2223 },
{ 0x2225, 0x2225 }, { 0x2227, 0x222C }, { 0x222E, 0x222E },
{ 0x2234, 0x2237 }, { 0x223C, 0x223D }, { 0x2248, 0x2248 },
{ 0x224C, 0x224C }, { 0x2252, 0x2252 }, { 0x2260, 0x2261 },
{ 0x2264, 0x2267 }, { 0x226A, 0x226B }, { 0x226E, 0x226F },
{ 0x2282, 0x2283 }, { 0x2286, 0x2287 }, { 0x2295, 0x2295 },
{ 0x2299, 0x2299 }, { 0x22A5, 0x22A5 }, { 0x22BF, 0x22BF },
{ 0x2312, 0x2312 }, { 0x2460, 0x24E9 }, { 0x24EB, 0x254B },
{ 0x2550, 0x2573 }, { 0x2580, 0x258F }, { 0x2592, 0x2595 },
{ 0x25A0, 0x25A1 }, { 0x25A3, 0x25A9 }, { 0x25B2, 0x25B3 },
{ 0x25B6, 0x25B7 }, { 0x25BC, 0x25BD }, { 0x25C0, 0x25C1 },
{ 0x25C6, 0x25C8 }, { 0x25CB, 0x25CB }, { 0x25CE, 0x25D1 },
{ 0x25E2, 0x25E5 }, { 0x25EF, 0x25EF }, { 0x2605, 0x2606 },
{ 0x2609, 0x2609 }, { 0x260E, 0x260F }, { 0x2614, 0x2615 },
{ 0x261C, 0x261C }, { 0x261E, 0x261E }, { 0x2640, 0x2640 },
{ 0x2642, 0x2642 }, { 0x2660, 0x2661 }, { 0x2663, 0x2665 },
{ 0x2667, 0x266A }, { 0x266C, 0x266D }, { 0x266F, 0x266F },
{ 0x273D, 0x273D }, { 0x2776, 0x277F }, { 0xE000, 0xF8FF },
{ 0xFFFD, 0xFFFD }, { 0xF0000, 0xFFFFD }, { 0x100000, 0x10FFFD }
};
/* sorted list of non-overlapping intervals of non-spacing characters */
/* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */
static const struct interval combining[] = {
{ 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 },
{ 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 },
{ 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 },
{ 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 },
{ 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED },
{ 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A },
{ 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 },
{ 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D },
{ 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 },
{ 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD },
{ 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C },
{ 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D },
{ 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC },
{ 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD },
{ 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C },
{ 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D },
{ 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 },
{ 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 },
{ 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC },
{ 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD },
{ 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D },
{ 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 },
{ 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E },
{ 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC },
{ 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 },
{ 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E },
{ 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 },
{ 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 },
{ 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 },
{ 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F },
{ 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 },
{ 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD },
{ 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD },
{ 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 },
{ 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B },
{ 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 },
{ 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 },
{ 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF },
{ 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 },
{ 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F },
{ 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B },
{ 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F },
{ 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB },
{ 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F },
{ 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 },
{ 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD },
{ 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F },
{ 0xE0100, 0xE01EF }
};
/* Test for NUL character */
if (ucs == 0)
return 0;
/* Test for printable ASCII characters */
if (ucs >= 0x20 && ucs < 0x7f)
return 1;
/* Test for control characters */
if (ucs < 0xa0)
return -1;
/* Test for surrogate pair values. */
if (ucs >= 0xd800 && ucs <= 0xdfff)
return -1;
/* binary search in table of ambiguous characters */
if (__locale_cjk_lang ()
&& bisearch(ucs, ambiguous,
sizeof(ambiguous) / sizeof(struct interval) - 1))
return 2;
/* binary search in table of non-spacing characters */
if (bisearch(ucs, combining,
sizeof(combining) / sizeof(struct interval) - 1))
return 0;
/* if we arrive here, ucs is not a combining or C0/C1 control character */
return 1 +
(ucs >= 0x1100 &&
(ucs <= 0x115f || /* Hangul Jamo init. consonants */
ucs == 0x2329 || ucs == 0x232a ||
(ucs >= 0x2e80 && ucs <= 0xa4cf &&
ucs != 0x303f) || /* CJK ... Yi */
(ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */
(ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */
(ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */
(ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */
(ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */
(ucs >= 0xffe0 && ucs <= 0xffe6) ||
(ucs >= 0x20000 && ucs <= 0x2fffd) ||
(ucs >= 0x30000 && ucs <= 0x3fffd)));
#else /* !_MB_CAPABLE */
if (iswprint (ucs))
return 1;
if (iswcntrl (ucs) || ucs == L'\0')
return 0;
return -1;
#endif /* _MB_CAPABLE */
}
int
_DEFUN (wcwidth, (wc),
_CONST wchar_t wc)
{
wint_t wi = wc;
#ifdef _MB_CAPABLE
wi = _jp2uc (wi);
#endif /* _MB_CAPABLE */
return __wcwidth (wi);
}

View File

@ -0,0 +1,89 @@
/*
FUNCTION
<<wmemchr>>---find a wide character in memory
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wmemchr(const wchar_t *<[s]>, wchar_t <[c]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wmemchr(<[s]>, <[c]>, <[n]>
const wchar_t *<[s]>;
wchar_t <[c]>;
size_t <[n]>;
DESCRIPTION
The <<wmemchr>> function locates the first occurrence of <[c]> in the
initial <[n]> wide characters of the object pointed to be <[s]>. This
function is not affected by locale and all wchar_t values are treated
identically. The null wide character and wchar_t values not
corresponding to valid characters are not treated specially.
If <[n]> is zero, <[s]> must be a valid pointer and the function
behaves as if no valid occurrence of <[c]> is found.
RETURNS
The <<wmemchr>> function returns a pointer to the located
wide character, or a null pointer if the wide character does not occur
in the object.
PORTABILITY
<<wmemchr>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wmemchr.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN (wmemchr, (s, c, n),
_CONST wchar_t * s _AND
wchar_t c _AND
size_t n)
{
size_t i;
for (i = 0; i < n; i++)
{
if (*s == c)
{
/* LINTED const castaway */
return (wchar_t *) s;
}
s++;
}
return NULL;
}

View File

@ -0,0 +1,89 @@
/*
FUNCTION
<<wmemcmp>>---compare wide characters in memory
ANSI_SYNOPSIS
#include <wchar.h>
int wmemcmp(const wchar_t *<[s1]>, const wchar_t *<[s2]>, size_t <[n]>);
TRAD_SYNOPSIS
int wmemcmp(<[s1]>, <[s2]>, <[n]>
const wchar_t *<[s1]>;
const wchar_t *<[s2]>;
size_t <[n]>;
DESCRIPTION
The <<wmemcmp>> function compares the first <[n]> wide characters of the
object pointed to by <[s1]> to the first <[n]> wide characters of the
object pointed to by <[s2]>. This function is not affected by locale
and all wchar_t values are treated identically. The null wide character
and wchar_t values not corresponding to valid characters are not treated
specially.
If <[n]> is zero, <[s1]> and <[s2]> must be a valid pointers and the
function behaves as if the two objects compare equal.
RETURNS
The <<wmemcmp>> function returns an integer greater than, equal to,
or less than zero, accordingly as the object pointed to by <[s1]> is
greater than, equal to, or less than the object pointed to by <[s2]>.
PORTABILITY
<<wmemcmp>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wmemcmp.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp
*/
#include <_ansi.h>
#include <wchar.h>
int
_DEFUN (wmemcmp, (s1, s2, n),
_CONST wchar_t * s1 _AND
_CONST wchar_t * s2 _AND
size_t n)
{
size_t i;
for (i = 0; i < n; i++)
{
if (*s1 != *s2)
{
/* wchar might be unsigned */
return *s1 > *s2 ? 1 : -1;
}
s1++;
s2++;
}
return 0;
}

View File

@ -0,0 +1,77 @@
/*
FUNCTION
<<wmemcpy>>---copy wide characters in memory
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wmemcpy(wchar_t *__restrict <[d]>,
const wchar_t *__restrict <[s]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wmemcpy(<[d]>, <[s]>, <[n]>
wchar_t *__restrict <[d]>;
const wchar_t *__restrict <[s]>;
size_t <[n]>;
DESCRIPTION
The <<wmemcpy>> function copies <[n]> wide characters from the object
pointed to by <[s]> to the object pointed to be <[d]>. This function
is not affected by locale and all wchar_t values are treated
identically. The null wide character and wchar_t values not
corresponding to valid characters are not treated specially.
If <[n]> is zero, <[d]> and <[s]> must be a valid pointers, and the
function copies zero wide characters.
RETURNS
The <<wmemcpy>> function returns the value of <[d]>.
PORTABILITY
<<wmemcpy>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wmemcpy.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp
*/
#include <_ansi.h>
#include <string.h>
#include <wchar.h>
wchar_t *
_DEFUN (wmemcpy, (d, s, n),
wchar_t *__restrict d _AND
_CONST wchar_t *__restrict s _AND
size_t n)
{
return (wchar_t *) memcpy (d, s, n * sizeof (wchar_t));
}

View File

@ -0,0 +1,82 @@
/*
FUNCTION
<<wmemmove>>---copy wide characters in memory with overlapping areas
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wmemmove(wchar_t *<[d]>, const wchar_t *<[s]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wmemmove(<[d]>, <[s]>, <[n]>
wchar_t *<[d]>;
const wchar_t *<[s]>;
size_t <[n]>;
DESCRIPTION
The <<wmemmove>> function copies <[n]> wide characters from the object
pointed to by <[s]> to the object pointed to by <[d]>. Copying takes
place as if the <[n]> wide characters from the object pointed to by
<[s]> are first copied into a temporary array of <[n]> wide characters
that does not overlap the objects pointed to by <[d]> or <[s]>, and then
the <[n]> wide characters from the temporary array are copied into the
object pointed to by <[d]>.
This function is not affected by locale and all wchar_t values are
treated identically. The null wide character and wchar_t values not
corresponding to valid characters are not treated specially.
If <[n]> is zero, <[d]> and <[s]> must be a valid pointers, and the
function copies zero wide characters.
RETURNS
The <<wmemmove>> function returns the value of <[d]>.
PORTABILITY
<<wmemmove>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wmemmove.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp
*/
#include <_ansi.h>
#include <string.h>
#include <wchar.h>
wchar_t *
_DEFUN (wmemmove, (d, s, n),
wchar_t * d _AND
_CONST wchar_t * s _AND
size_t n)
{
return (wchar_t *) memmove (d, s, n * sizeof (wchar_t));
}

View File

@ -0,0 +1,82 @@
/*
FUNCTION
<<wmemset>>---set wide characters in memory
ANSI_SYNOPSIS
#include <wchar.h>
wchar_t *wmemset(wchar_t *<[s]>, wchar_t <[c]>, size_t <[n]>);
TRAD_SYNOPSIS
wchar_t *wmemset(<[s]>, <[c]>, <[n]>
wchar_t *<[s]>;
wchar_t <[c]>;
size_t <[n]>;
DESCRIPTION
The <<wmemset>> function copies the value of <[c]> into each of the
first <[n]> wide characters of the object pointed to by <[s]>. This
function is not affected by locale and all wchar_t values are treated
identically. The null wide character and wchar_t values not
corresponding to valid characters are not treated specially.
If <[n]> is zero, <[s]> must be a valid pointer and the function
copies zero wide characters.
RETURNS
The <<wmemset>> function returns the value of <[s]>.
PORTABILITY
<<wmemset>> is ISO/IEC 9899/AMD1:1995 (ISO C).
No supporting OS subroutines are required.
*/
/* $NetBSD: wmemset.c,v 1.1 2000/12/23 23:14:37 itojun Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp
*/
#include <_ansi.h>
#include <wchar.h>
wchar_t *
_DEFUN(wmemset, (s, c, n),
wchar_t *s _AND
wchar_t c _AND
size_t n)
{
size_t i;
wchar_t *p;
p = (wchar_t *)s;
for (i = 0; i < n; i++) {
*p = c;
p++;
}
return s;
}