Full switch to clang/ELF. Drop ack. Simplify.
There is important information about booting non-ack images in docs/UPDATING. ack/aout-format images can't be built any more, and booting clang/ELF-format ones is a little different. Updating to the new boot monitor is recommended. Changes in this commit: . drop boot monitor -> allowing dropping ack support . facility to copy ELF boot files to /boot so that old boot monitor can still boot fairly easily, see UPDATING . no more ack-format libraries -> single-case libraries . some cleanup of OBJECT_FMT, COMPILER_TYPE, etc cases . drop several ack toolchain commands, but not all support commands (e.g. aal is gone but acksize is not yet). . a few libc files moved to netbsd libc dir . new /bin/date as minix date used code in libc/ . test compile fix . harmonize includes . /usr/lib is no longer special: without ack, /usr/lib plays no kind of special bootstrapping role any more and bootstrapping is done exclusively through packages, so releases depend even less on the state of the machine making them now. . rename nbsd_lib* to lib* . reduce mtree
This commit is contained in:
17
lib/libc/string/Lint_bcmp.c
Normal file
17
lib/libc/string/Lint_bcmp.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_bcmp.c,v 1.2 2000/06/14 06:49:07 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
bcmp(b1, b2, len)
|
||||
const void *b1, *b2;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_bcopy.c
Normal file
17
lib/libc/string/Lint_bcopy.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_bcopy.c,v 1.2 2000/06/14 06:49:07 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
bcopy(src, dst, len)
|
||||
const void *src;
|
||||
void *dst;
|
||||
size_t len;
|
||||
{
|
||||
}
|
||||
16
lib/libc/string/Lint_bzero.c
Normal file
16
lib/libc/string/Lint_bzero.c
Normal file
@@ -0,0 +1,16 @@
|
||||
/* $NetBSD: Lint_bzero.c,v 1.2 2000/06/14 06:49:07 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
bzero(src, len)
|
||||
void *src;
|
||||
size_t len;
|
||||
{
|
||||
}
|
||||
15
lib/libc/string/Lint_ffs.c
Normal file
15
lib/libc/string/Lint_ffs.c
Normal file
@@ -0,0 +1,15 @@
|
||||
/* $NetBSD: Lint_ffs.c,v 1.3 2009/08/05 16:08:00 joerg Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
ffs(int value)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
17
lib/libc/string/Lint_index.c
Normal file
17
lib/libc/string/Lint_index.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_index.c,v 1.2 2000/06/14 06:49:07 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
index(src, c)
|
||||
const char *src;
|
||||
int c;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
19
lib/libc/string/Lint_memccpy.c
Normal file
19
lib/libc/string/Lint_memccpy.c
Normal file
@@ -0,0 +1,19 @@
|
||||
/* $NetBSD: Lint_memccpy.c,v 1.1 1997/12/07 00:24:58 matthias Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Matthias Pfaller, December 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void *
|
||||
memccpy(dst, src, c, n)
|
||||
void *dst;
|
||||
const void *src;
|
||||
int c;
|
||||
size_t n;
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
18
lib/libc/string/Lint_memchr.c
Normal file
18
lib/libc/string/Lint_memchr.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* $NetBSD: Lint_memchr.c,v 1.2 2000/06/14 06:49:07 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void *
|
||||
memchr(b, c, len)
|
||||
const void *b;
|
||||
int c;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_memcmp.c
Normal file
17
lib/libc/string/Lint_memcmp.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_memcmp.c,v 1.2 2000/06/14 06:49:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
memcmp(b1, b2, len)
|
||||
const void *b1, *b2;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
18
lib/libc/string/Lint_memcpy.c
Normal file
18
lib/libc/string/Lint_memcpy.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* $NetBSD: Lint_memcpy.c,v 1.2 2000/06/14 06:49:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void *
|
||||
memcpy(dst, src, len)
|
||||
void *dst;
|
||||
const void *src;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
18
lib/libc/string/Lint_memmove.c
Normal file
18
lib/libc/string/Lint_memmove.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* $NetBSD: Lint_memmove.c,v 1.2 2000/06/14 06:49:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void *
|
||||
memmove(dst, src, len)
|
||||
void *dst;
|
||||
const void *src;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
18
lib/libc/string/Lint_memset.c
Normal file
18
lib/libc/string/Lint_memset.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* $NetBSD: Lint_memset.c,v 1.2 2000/06/14 06:49:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void *
|
||||
memset(b, c, len)
|
||||
void *b;
|
||||
int c;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_rindex.c
Normal file
17
lib/libc/string/Lint_rindex.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_rindex.c,v 1.2 2000/06/14 06:49:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
rindex(src, c)
|
||||
const char *src;
|
||||
int c;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_strcat.c
Normal file
17
lib/libc/string/Lint_strcat.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_strcat.c,v 1.2 2000/06/14 06:49:08 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
strcat(s, append)
|
||||
char *s;
|
||||
const char *append;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_strchr.c
Normal file
17
lib/libc/string/Lint_strchr.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_strchr.c,v 1.2 2000/06/14 06:49:09 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
strchr(src, c)
|
||||
const char *src;
|
||||
int c;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
16
lib/libc/string/Lint_strcmp.c
Normal file
16
lib/libc/string/Lint_strcmp.c
Normal file
@@ -0,0 +1,16 @@
|
||||
/* $NetBSD: Lint_strcmp.c,v 1.2 2000/06/14 06:49:09 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
strcmp(s1, s2)
|
||||
const char *s1, *s2;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_strcpy.c
Normal file
17
lib/libc/string/Lint_strcpy.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_strcpy.c,v 1.2 2000/06/14 06:49:09 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
strcpy(dst, src)
|
||||
char *dst;
|
||||
const char *src;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
16
lib/libc/string/Lint_strlen.c
Normal file
16
lib/libc/string/Lint_strlen.c
Normal file
@@ -0,0 +1,16 @@
|
||||
/* $NetBSD: Lint_strlen.c,v 1.2 2000/06/14 06:49:10 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
size_t
|
||||
strlen(s)
|
||||
const char *s;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
18
lib/libc/string/Lint_strncat.c
Normal file
18
lib/libc/string/Lint_strncat.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* $NetBSD: Lint_strncat.c,v 1.1 1997/12/07 00:24:58 matthias Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Matthias Pfaller, December 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
strncat(dst, src, n)
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t n;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_strncmp.c
Normal file
17
lib/libc/string/Lint_strncmp.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_strncmp.c,v 1.2 2000/06/14 06:49:10 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
int
|
||||
strncmp(s1, s2, len)
|
||||
const char *s1, *s2;
|
||||
size_t len;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
18
lib/libc/string/Lint_strncpy.c
Normal file
18
lib/libc/string/Lint_strncpy.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* $NetBSD: Lint_strncpy.c,v 1.1 1997/12/07 00:24:58 matthias Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Matthias Pfaller, December 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
strncpy(dst, src, n)
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t n;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
17
lib/libc/string/Lint_strrchr.c
Normal file
17
lib/libc/string/Lint_strrchr.c
Normal file
@@ -0,0 +1,17 @@
|
||||
/* $NetBSD: Lint_strrchr.c,v 1.2 2000/06/14 06:49:10 cgd Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
char *
|
||||
strrchr(src, c)
|
||||
const char *src;
|
||||
int c;
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
14
lib/libc/string/Lint_swab.c
Normal file
14
lib/libc/string/Lint_swab.c
Normal file
@@ -0,0 +1,14 @@
|
||||
/* $NetBSD: Lint_swab.c,v 1.3 2010/07/05 00:45:19 christos Exp $ */
|
||||
|
||||
/*
|
||||
* This file placed in the public domain.
|
||||
* Chris Demetriou, November 5, 1997.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
/*ARGSUSED*/
|
||||
void
|
||||
swab(const void *src, void *dst, ssize_t len)
|
||||
{
|
||||
}
|
||||
78
lib/libc/string/Makefile.inc
Normal file
78
lib/libc/string/Makefile.inc
Normal file
@@ -0,0 +1,78 @@
|
||||
# from: @(#)Makefile.inc 8.1 (Berkeley) 6/4/93
|
||||
# $NetBSD: Makefile.inc,v 1.75 2009/07/30 20:57:15 dsl Exp $
|
||||
|
||||
# string sources
|
||||
.PATH: ${ARCHDIR}/string ${.CURDIR}/string
|
||||
|
||||
# NB: if a .S version of any of these is added in the arch/*/Makefile
|
||||
# then the relevant .c file is automatically removed
|
||||
# Also adding the .c name to NO_SRCS will have the same effect
|
||||
|
||||
SRCS+= bm.c stpcpy.c stpncpy.c \
|
||||
strcasecmp.c strncasecmp.c strcasestr.c strcoll.c strdup.c \
|
||||
strerror.c strlcat.c strlcpy.c strnlen.c \
|
||||
strmode.c strsignal.c strtok.c \
|
||||
strtok_r.c strxfrm.c __strsignal.c strerror_r.c strndup.c \
|
||||
stresep.c memrchr.c
|
||||
|
||||
SRCS+= bcmp.c bcopy.c bzero.c ffs.c memchr.c memcmp.c memset.c
|
||||
SRCS+= strcat.c strcmp.c strcpy.c strcspn.c strlen.c
|
||||
SRCS+= strncat.c strncmp.c strncpy.c strpbrk.c strsep.c
|
||||
SRCS+= strspn.c strstr.c swab.c
|
||||
|
||||
SRCS+= memccpy.c memcpy.c memmem.c memmove.c
|
||||
SRCS+= strchr.c strrchr.c
|
||||
SRCS+= popcount32.c popcount64.c
|
||||
|
||||
# wide char
|
||||
SRCS+= wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \
|
||||
wcslen.c wcsncat.c wcscasecmp.c wcsdup.c wcsncasecmp.c \
|
||||
wcsncmp.c wcsncpy.c wcspbrk.c wcsrchr.c wcsspn.c wcsstr.c wcstok.c \
|
||||
wcswcs.c wmemchr.c wmemcmp.c wmemcpy.c wmemmove.c wmemset.c
|
||||
CPPFLAGS.wcscmp.c+= -I${LIBCDIR}/locale
|
||||
CPPFLAGS.wcsncmp.c+= -I${LIBCDIR}/locale
|
||||
CPPFLAGS.wmemcmp.c+= -I${LIBCDIR}/locale
|
||||
|
||||
# namespace protection wrappers
|
||||
SRCS+= _strlcat.c _strlcpy.c _strerror_r.c
|
||||
|
||||
.include "${ARCHDIR}/string/Makefile.inc"
|
||||
|
||||
MAN+= bm.3 bcmp.3 bcopy.3 bstring.3 bzero.3 ffs.3 index.3 \
|
||||
memccpy.3 memchr.3 memcmp.3 memcpy.3 memmem.3 memmove.3 memset.3 \
|
||||
popcount.3 \
|
||||
rindex.3 strcasecmp.3 strcat.3 strchr.3 strcmp.3 strcoll.3 \
|
||||
strcpy.3 strcspn.3 strdup.3 strerror.3 string.3 strings.3 strlcpy.3 \
|
||||
strlen.3 strmode.3 strpbrk.3 strrchr.3 strsep.3 \
|
||||
strsignal.3 strspn.3 strstr.3 strtok.3 strxfrm.3 \
|
||||
swab.3 wcstok.3 wcswidth.3 wmemchr.3 wcsdup.3 wcscasecmp.3
|
||||
|
||||
MLINKS+=bm.3 bm_comp.3 bm.3 bm_exec.3 bm.3 bm_free.3
|
||||
MLINKS+=popcount.3 popcountl.3
|
||||
MLINKS+=popcount.3 popcountll.3
|
||||
MLINKS+=popcount.3 popcount32.3
|
||||
MLINKS+=popcount.3 popcount64.3
|
||||
MLINKS+=strcasecmp.3 strncasecmp.3
|
||||
MLINKS+=strcat.3 strncat.3
|
||||
MLINKS+=strcmp.3 strncmp.3
|
||||
MLINKS+=strcpy.3 strncpy.3 strcpy.3 stpcpy.3 strcpy.3 stpncpy.3
|
||||
MLINKS+=strlcpy.3 strlcat.3
|
||||
MLINKS+=strlen.3 strnlen.3
|
||||
MLINKS+=strstr.3 strcasestr.3
|
||||
MLINKS+=memchr.3 memrchr.3
|
||||
MLINKS+=strtok.3 strtok_r.3
|
||||
MLINKS+=strerror.3 strerror_r.3 strerror.3 perror.3 \
|
||||
strerror.3 sys_errlist.3 strerror.3 sys_nerr.3
|
||||
MLINKS+=strdup.3 strndup.3
|
||||
MLINKS+=strsep.3 stresep.3
|
||||
MLINKS+=wmemchr.3 wmemcmp.3 wmemchr.3 wmemcpy.3 \
|
||||
wmemchr.3 wmemmove.3 wmemchr.3 wmemset.3 \
|
||||
wmemchr.3 wcscat.3 wmemchr.3 wcschr.3 \
|
||||
wmemchr.3 wcscmp.3 wmemchr.3 wcscpy.3 \
|
||||
wmemchr.3 wcscspn.3 wmemchr.3 wcslcat.3 \
|
||||
wmemchr.3 wcslcpy.3 wmemchr.3 wcslen.3 \
|
||||
wmemchr.3 wcsncat.3 wmemchr.3 wcsncmp.3 \
|
||||
wmemchr.3 wcsncpy.3 wmemchr.3 wcspbrk.3 \
|
||||
wmemchr.3 wcsrchr.3 wmemchr.3 wcsspn.3 \
|
||||
wmemchr.3 wcsstr.3 wmemchr.3 wcswcs.3
|
||||
MLINKS+=wcscasecmp.3 wcsncasecmp.3
|
||||
104
lib/libc/string/__strsignal.c
Normal file
104
lib/libc/string/__strsignal.c
Normal file
@@ -0,0 +1,104 @@
|
||||
/* $NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $ */
|
||||
|
||||
/*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char *sccsid = "@(#)strerror.c 5.6 (Berkeley) 5/4/91";
|
||||
#else
|
||||
__RCSID("$NetBSD: __strsignal.c,v 1.24 2003/08/07 16:43:46 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#ifdef NLS
|
||||
#include <limits.h>
|
||||
#include <nl_types.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "extern.h"
|
||||
#include <signal.h>
|
||||
#ifndef SIGRTMIN /* XXX: Until we remove the #ifdef _KERNEL */
|
||||
#define SIGRTMIN 33
|
||||
#define SIGRTMAX 63
|
||||
#endif
|
||||
|
||||
/* ARGSUSED */
|
||||
const char *
|
||||
__strsignal(num, buf, buflen)
|
||||
int num;
|
||||
char *buf;
|
||||
size_t buflen;
|
||||
{
|
||||
#define UPREFIX "Unknown signal: %u"
|
||||
#define RPREFIX "Real time signal %u"
|
||||
unsigned int signum;
|
||||
|
||||
#ifdef NLS
|
||||
nl_catd catd ;
|
||||
catd = catopen("libc", NL_CAT_LOCALE);
|
||||
#endif
|
||||
|
||||
_DIAGASSERT(buf != NULL);
|
||||
|
||||
signum = num; /* convert to unsigned */
|
||||
if (signum < (unsigned int) sys_nsig) {
|
||||
#ifdef NLS
|
||||
(void)strlcpy(buf, catgets(catd, 2, (int)signum,
|
||||
sys_siglist[signum]), buflen);
|
||||
#else
|
||||
return((char *)sys_siglist[signum]);
|
||||
#endif
|
||||
} else if (signum >= SIGRTMIN && signum <= SIGRTMAX) {
|
||||
#ifdef NLS
|
||||
(void)snprintf(buf, buflen,
|
||||
catgets(catd, 2, SIGRTMIN, RPREFIX), signum);
|
||||
#else
|
||||
(void)snprintf(buf, buflen, RPREFIX, signum);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef NLS
|
||||
(void)snprintf(buf, buflen,
|
||||
catgets(catd, 1, 0xffff, UPREFIX), signum);
|
||||
#else
|
||||
(void)snprintf(buf, buflen, UPREFIX, signum);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef NLS
|
||||
catclose(catd);
|
||||
#endif
|
||||
|
||||
return buf;
|
||||
}
|
||||
49
lib/libc/string/_strerror_r.c
Normal file
49
lib/libc/string/_strerror_r.c
Normal file
@@ -0,0 +1,49 @@
|
||||
/* $NetBSD: _strerror_r.c,v 1.3 2008/04/28 20:23:00 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: _strerror_r.c,v 1.3 2008/04/28 20:23:00 martin Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#if defined(__indr_reference)
|
||||
__indr_reference(_strerror_r, strerror_r)
|
||||
#else
|
||||
|
||||
#include <string.h>
|
||||
int _strerror_r(int, char *, size_t);
|
||||
|
||||
int
|
||||
strerror_r(int num, char *buf, size_t siz)
|
||||
{
|
||||
|
||||
return _strerror_r(num, buf, siz);
|
||||
}
|
||||
#endif
|
||||
45
lib/libc/string/_strlcat.c
Normal file
45
lib/libc/string/_strlcat.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* $NetBSD: _strlcat.c,v 1.5 2009/10/21 01:07:45 snj Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. 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 ``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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: _strlcat.c,v 1.5 2009/10/21 01:07:45 snj Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#if defined(__indr_reference)
|
||||
__indr_reference(_strlcat, strlcat)
|
||||
#else
|
||||
|
||||
#include <string.h>
|
||||
size_t _strlcat(char *, const char *, size_t);
|
||||
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
|
||||
return _strlcat(dst, src, siz);
|
||||
}
|
||||
#endif
|
||||
45
lib/libc/string/_strlcpy.c
Normal file
45
lib/libc/string/_strlcpy.c
Normal file
@@ -0,0 +1,45 @@
|
||||
/* $NetBSD: _strlcpy.c,v 1.5 2009/10/21 01:07:45 snj Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christos Zoulas. 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 ``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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: _strlcpy.c,v 1.5 2009/10/21 01:07:45 snj Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#if defined(__indr_reference)
|
||||
__indr_reference(_strlcpy, strlcpy)
|
||||
#else
|
||||
|
||||
#include <string.h>
|
||||
size_t _strlcpy(char *, const char *, size_t);
|
||||
|
||||
size_t
|
||||
strlcpy(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
|
||||
return _strlcpy(dst, src, siz);
|
||||
}
|
||||
#endif
|
||||
85
lib/libc/string/bcmp.3
Normal file
85
lib/libc/string/bcmp.3
Normal file
@@ -0,0 +1,85 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)bcmp.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: bcmp.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $
|
||||
.\"
|
||||
.Dd April 29, 2010
|
||||
.Dt BCMP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bcmp
|
||||
.Nd compare byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft int
|
||||
.Fn bcmp "const void *b1" "const void *b2" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn bcmp
|
||||
function
|
||||
compares byte string
|
||||
.Fa b1
|
||||
against byte string
|
||||
.Fa b2 ,
|
||||
returning zero if they are identical, non-zero otherwise.
|
||||
Both strings are assumed to be
|
||||
.Fa len
|
||||
bytes long.
|
||||
Zero-length strings are always identical.
|
||||
.Pp
|
||||
The strings may overlap.
|
||||
.Sh SEE ALSO
|
||||
.Xr memcmp 3 ,
|
||||
.Xr strcasecmp 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strcoll 3 ,
|
||||
.Xr strxfrm 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn bcmp
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
The
|
||||
.St -p1003.1-2004
|
||||
revision marked it as legacy and recommended the use of
|
||||
.Xr memcmp 3
|
||||
instead.
|
||||
The
|
||||
.St -p1003.1-2008
|
||||
revision removed
|
||||
.Fn bcmp
|
||||
from the specification.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Fn bcmp
|
||||
function first appeared in
|
||||
.Bx 4.2 .
|
||||
80
lib/libc/string/bcopy.3
Normal file
80
lib/libc/string/bcopy.3
Normal file
@@ -0,0 +1,80 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)bcopy.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: bcopy.3,v 1.13 2010/04/29 07:27:30 wiz Exp $
|
||||
.\"
|
||||
.Dd April 29, 2010
|
||||
.Dt BCOPY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bcopy
|
||||
.Nd copy byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft void
|
||||
.Fn bcopy "const void *src" "void *dst" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn bcopy
|
||||
function
|
||||
copies
|
||||
.Fa len
|
||||
bytes from string
|
||||
.Fa src
|
||||
to string
|
||||
.Fa dst .
|
||||
The two strings may overlap.
|
||||
If
|
||||
.Fa len
|
||||
is zero, no bytes are copied.
|
||||
.Sh SEE ALSO
|
||||
.Xr memccpy 3 ,
|
||||
.Xr memcpy 3 ,
|
||||
.Xr memmove 3 ,
|
||||
.Xr strcpy 3 ,
|
||||
.Xr strncpy 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn bcmp
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
The
|
||||
.St -p1003.1-2004
|
||||
revision marked it as legacy; the
|
||||
.St -p1003.1-2008
|
||||
revision removed it from the specification.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Fn bcopy
|
||||
function appeared in
|
||||
.Bx 4.2 .
|
||||
114
lib/libc/string/bm.3
Normal file
114
lib/libc/string/bm.3
Normal file
@@ -0,0 +1,114 @@
|
||||
.\" $NetBSD: bm.3,v 1.8 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1994
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Andrew Hume of AT&T Bell Laboratories.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)bm.3 8.4 (Berkeley) 6/21/94
|
||||
.\"
|
||||
.Dd April 8, 2001
|
||||
.Dt BM 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bm_comp ,
|
||||
.Nm bm_exec ,
|
||||
.Nm bm_free
|
||||
.Nd Boyer-Moore string search
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In sys/types.h
|
||||
.In bm.h
|
||||
.Ft bm_pat *
|
||||
.Fn bm_comp "u_char *pattern" "size_t patlen" "u_char freq[256]"
|
||||
.Ft u_char *
|
||||
.Fn bm_exec "bm_pat *pdesc" "u_char *text" "size_t len"
|
||||
.Ft void
|
||||
.Fn bm_free "bm_pat *pdesc"
|
||||
.Sh DESCRIPTION
|
||||
These routines implement an efficient mechanism to find an
|
||||
occurrence of a byte string within another byte string.
|
||||
.Pp
|
||||
.Fn bm_comp
|
||||
evaluates the
|
||||
.Fa patlen
|
||||
bytes starting at
|
||||
.Fa pattern ,
|
||||
and returns a pointer to a structure describing them.
|
||||
The bytes referenced by
|
||||
.Fa pattern
|
||||
may be of any value.
|
||||
.Pp
|
||||
The search takes advantage of the frequency distribution of the
|
||||
bytes in the text to be searched.
|
||||
If specified,
|
||||
.Fa freq
|
||||
should be an array of 256 values,
|
||||
with higher values indicating that the corresponding character occurs
|
||||
more frequently.
|
||||
(A less than optimal frequency distribution can only result in less
|
||||
than optimal performance, not incorrect results.)
|
||||
If
|
||||
.Fa freq
|
||||
is
|
||||
.Dv NULL ,
|
||||
a system default table is used.
|
||||
.Pp
|
||||
.Fn bm_exec
|
||||
returns a pointer to the leftmost occurrence of the string given to
|
||||
.Fn bm_comp
|
||||
within
|
||||
.Fa text ,
|
||||
or
|
||||
.Dv NULL
|
||||
if none occurs.
|
||||
The number of bytes in
|
||||
.Fa text
|
||||
must be specified by
|
||||
.Fa len .
|
||||
.Pp
|
||||
Space allocated for the returned description is discarded
|
||||
by calling
|
||||
.Fn bm_free
|
||||
with the returned description as an argument.
|
||||
.Pp
|
||||
The asymptotic speed of
|
||||
.Fn bm_exec
|
||||
is O(len/patlen).
|
||||
.Sh SEE ALSO
|
||||
.Xr regexp 3 ,
|
||||
.Xr strstr 3
|
||||
.Rs
|
||||
.%A Hume and Sunday
|
||||
.%D November 1991
|
||||
.%J "Software Practice and Experience"
|
||||
.%P pp. 1221-48
|
||||
.%T "Fast String Searching"
|
||||
.%V Vol. 21, 11
|
||||
.Re
|
||||
239
lib/libc/string/bm.c
Normal file
239
lib/libc/string/bm.c
Normal file
@@ -0,0 +1,239 @@
|
||||
/* $NetBSD: bm.c,v 1.11 2003/08/07 16:43:47 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Andrew Hume of AT&T Bell Laboratories.
|
||||
*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)bm.c 8.7 (Berkeley) 6/21/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: bm.c,v 1.11 2003/08/07 16:43:47 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS && not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <bm.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(bm_comp,_bm_comp)
|
||||
__weak_alias(bm_exec,_bm_exec)
|
||||
__weak_alias(bm_free,_bm_free)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* The default frequency table starts at 99 and counts down. The default
|
||||
* table should probably be oriented toward text, and will necessarily be
|
||||
* locale specific. This one is for English. It was derived from the
|
||||
* OSF/1 and 4.4BSD formatted and unformatted manual pages, and about 100Mb
|
||||
* of email and random text. Change it if you can find something better.
|
||||
*/
|
||||
static u_char const freq_def[256] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 77, 90, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
99, 28, 42, 27, 16, 14, 20, 51,
|
||||
66, 65, 59, 24, 75, 76, 84, 56,
|
||||
72, 74, 64, 55, 54, 47, 41, 37,
|
||||
44, 61, 70, 43, 23, 53, 49, 22,
|
||||
33, 58, 40, 46, 45, 57, 60, 26,
|
||||
30, 63, 21, 12, 32, 50, 38, 39,
|
||||
34, 11, 48, 67, 62, 35, 15, 29,
|
||||
71, 18, 9, 17, 25, 13, 10, 52,
|
||||
36, 95, 78, 86, 87, 98, 82, 80,
|
||||
88, 94, 19, 68, 89, 83, 93, 96,
|
||||
81, 7, 91, 92, 97, 85, 69, 73,
|
||||
31, 79, 8, 5, 4, 6, 3, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
};
|
||||
|
||||
bm_pat *
|
||||
bm_comp(pb, len, freq)
|
||||
u_char const *pb;
|
||||
size_t len;
|
||||
u_char const *freq;
|
||||
{
|
||||
u_char const *pe, *p;
|
||||
size_t *d, r;
|
||||
int j;
|
||||
int sv_errno;
|
||||
bm_pat *pat;
|
||||
|
||||
_DIAGASSERT(pb != NULL);
|
||||
/* freq may be NULL */
|
||||
|
||||
if (len == 0) {
|
||||
errno = EINVAL;
|
||||
return (NULL);
|
||||
}
|
||||
if ((pat = malloc(sizeof(*pat))) == NULL)
|
||||
return (NULL);
|
||||
pat->pat = NULL;
|
||||
pat->delta = NULL;
|
||||
|
||||
pat->patlen = len; /* copy pattern */
|
||||
if ((pat->pat = malloc(pat->patlen)) == NULL)
|
||||
goto mem;
|
||||
memcpy(pat->pat, pb, pat->patlen);
|
||||
/* get skip delta */
|
||||
if ((pat->delta = malloc(256 * sizeof(*d))) == NULL)
|
||||
goto mem;
|
||||
for (j = 0, d = pat->delta; j < 256; j++)
|
||||
d[j] = pat->patlen;
|
||||
for (pe = pb + pat->patlen - 1; pb <= pe; pb++)
|
||||
d[*pb] = pe - pb;
|
||||
|
||||
if (freq == NULL) /* default freq table */
|
||||
freq = freq_def;
|
||||
r = 0; /* get guard */
|
||||
for (pb = pat->pat, pe = pb + pat->patlen - 1; pb < pe; pb++)
|
||||
if (freq[*pb] < freq[pat->pat[r]])
|
||||
r = pb - pat->pat;
|
||||
pat->rarec = pat->pat[r];
|
||||
pat->rareoff = r - (pat->patlen - 1);
|
||||
|
||||
/* get md2 shift */
|
||||
for (pe = pat->pat + pat->patlen - 1, p = pe - 1; p >= pat->pat; p--)
|
||||
if (*p == *pe)
|
||||
break;
|
||||
|
||||
/* *p is first leftward reoccurrence of *pe */
|
||||
pat->md2 = pe - p;
|
||||
return (pat);
|
||||
|
||||
mem: sv_errno = errno;
|
||||
bm_free(pat);
|
||||
errno = sv_errno;
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
void
|
||||
bm_free(pat)
|
||||
bm_pat *pat;
|
||||
{
|
||||
|
||||
_DIAGASSERT(pat != NULL);
|
||||
|
||||
if (pat->pat != NULL)
|
||||
free(pat->pat);
|
||||
if (pat->delta != NULL)
|
||||
free(pat->delta);
|
||||
free(pat);
|
||||
}
|
||||
|
||||
u_char *
|
||||
bm_exec(pat, base, n)
|
||||
bm_pat *pat;
|
||||
u_char *base;
|
||||
size_t n;
|
||||
{
|
||||
u_char *e, *ep, *p, *q, *s;
|
||||
size_t *d0, k, md2, n1, ro;
|
||||
int rc;
|
||||
|
||||
_DIAGASSERT(pat != NULL);
|
||||
_DIAGASSERT(base != NULL);
|
||||
|
||||
if (n == 0)
|
||||
return (NULL);
|
||||
|
||||
d0 = pat->delta;
|
||||
n1 = pat->patlen - 1;
|
||||
md2 = pat->md2;
|
||||
ro = pat->rareoff;
|
||||
rc = pat->rarec;
|
||||
ep = pat->pat + pat->patlen - 1;
|
||||
s = base + (pat->patlen - 1);
|
||||
|
||||
/* fast loop up to n - 3 * patlen */
|
||||
e = base + n - 3 * pat->patlen;
|
||||
while (s < e) {
|
||||
k = d0[*s]; /* ufast skip loop */
|
||||
while (k) {
|
||||
k = d0[*(s += k)];
|
||||
k = d0[*(s += k)];
|
||||
}
|
||||
if (s >= e)
|
||||
break;
|
||||
if (s[ro] != rc) /* guard test */
|
||||
goto mismatch1;
|
||||
/* fwd match */
|
||||
for (p = pat->pat, q = s - n1; p < ep;)
|
||||
if (*q++ != *p++)
|
||||
goto mismatch1;
|
||||
return (s - n1);
|
||||
|
||||
mismatch1: s += md2; /* md2 shift */
|
||||
}
|
||||
|
||||
/* slow loop up to end */
|
||||
e = base + n;
|
||||
while (s < e) {
|
||||
s += d0[*s]; /* step */
|
||||
if (s >= e)
|
||||
break;
|
||||
if (s[ro] != rc) /* guard test */
|
||||
goto mismatch2;
|
||||
/* fwd match */
|
||||
for (p = pat->pat, q = s - n1; p <= ep;)
|
||||
if (*q++ != *p++)
|
||||
goto mismatch2;
|
||||
return (s - n1);
|
||||
|
||||
mismatch2: s += md2; /* md2 shift */
|
||||
}
|
||||
|
||||
return (NULL);
|
||||
}
|
||||
93
lib/libc/string/bstring.3
Normal file
93
lib/libc/string/bstring.3
Normal file
@@ -0,0 +1,93 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)bstring.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: bstring.3,v 1.11 2007/02/17 09:04:57 wiz Exp $
|
||||
.\"
|
||||
.Dd February 9, 2007
|
||||
.Dt BSTRING 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memccpy ,
|
||||
.Nm memchr ,
|
||||
.Nm memcmp ,
|
||||
.Nm memcpy ,
|
||||
.Nm memmem ,
|
||||
.Nm memmove ,
|
||||
.Nm memset
|
||||
.Nd byte string operations
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memchr "const void *b" "int c" "size_t len"
|
||||
.Ft int
|
||||
.Fn memcmp "const void *b1" "const void *b2" "size_t len"
|
||||
.Ft void *
|
||||
.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
|
||||
.Ft void *
|
||||
.Fn memcpy "void *dst" "const void *src" "size_t len"
|
||||
.Ft void *
|
||||
.Fn memmem "const void *block" "size_t blen" "const void *pat" "size_t plen"
|
||||
.Ft void *
|
||||
.Fn memmove "void *dst" "const void *src" "size_t len"
|
||||
.Ft void *
|
||||
.Fn memset "void *b" "int c" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
These functions operate on variable length strings of bytes.
|
||||
They do not check for terminating nul bytes as the routines
|
||||
listed in
|
||||
.Xr string 3
|
||||
do.
|
||||
.Pp
|
||||
See the specific manual pages for more information.
|
||||
.Sh SEE ALSO
|
||||
.Xr memccpy 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr memcmp 3 ,
|
||||
.Xr memcpy 3 ,
|
||||
.Xr memmem 3 ,
|
||||
.Xr memmove 3 ,
|
||||
.Xr memset 3
|
||||
.Sh STANDARDS
|
||||
The functions
|
||||
.Fn memchr ,
|
||||
.Fn memcmp ,
|
||||
.Fn memcpy ,
|
||||
.Fn memmove ,
|
||||
and
|
||||
.Fn memset
|
||||
conform to
|
||||
.St -ansiC .
|
||||
.Sh HISTORY
|
||||
The function
|
||||
.Fn memccpy
|
||||
appeared in
|
||||
.Bx 4.3 .
|
||||
82
lib/libc/string/bzero.3
Normal file
82
lib/libc/string/bzero.3
Normal file
@@ -0,0 +1,82 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)bzero.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: bzero.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $
|
||||
.\"
|
||||
.Dd April 29, 2010
|
||||
.Dt BZERO 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bzero
|
||||
.Nd write zeroes to a byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft void
|
||||
.Fn bzero "void *b" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn bzero
|
||||
function
|
||||
writes
|
||||
.Fa len
|
||||
zero bytes to the string
|
||||
.Fa b .
|
||||
If
|
||||
.Fa len
|
||||
is zero,
|
||||
.Fn bzero
|
||||
does nothing.
|
||||
.Sh SEE ALSO
|
||||
.Xr memset 3 ,
|
||||
.Xr swab 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn bzero
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
The
|
||||
.St -p1003.1-2004
|
||||
revision marked it as legacy and recommended the use of
|
||||
.Xr memset 3
|
||||
instead.
|
||||
The
|
||||
.St -p1003.1-2008
|
||||
revision removed
|
||||
.Fn bzero
|
||||
from the specification.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Fn bzero
|
||||
function
|
||||
appeared in
|
||||
.Bx 4.3 .
|
||||
74
lib/libc/string/ffs.3
Normal file
74
lib/libc/string/ffs.3
Normal file
@@ -0,0 +1,74 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)ffs.3 8.2 (Berkeley) 4/19/94
|
||||
.\" $NetBSD: ffs.3,v 1.13 2010/04/28 07:47:09 jruoho Exp $
|
||||
.\"
|
||||
.Dd April 28, 2010
|
||||
.Dt FFS 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm ffs
|
||||
.Nd find first bit set in a bit string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft int
|
||||
.Fn ffs "int value"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn ffs
|
||||
function finds the first bit set in
|
||||
.Fa value
|
||||
and returns the index of that bit.
|
||||
Bits are numbered starting from 1, starting at the right-most
|
||||
bit.
|
||||
A return value of 0 means that the argument was zero.
|
||||
.Sh SEE ALSO
|
||||
.Xr bitstring 3 ,
|
||||
.Xr ffs32 3 ,
|
||||
.Xr popcount 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn ffs
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn ffs
|
||||
function appeared in
|
||||
.Bx 4.3 .
|
||||
The prototype for it existed previously in the
|
||||
.In string.h
|
||||
header before it was moved to
|
||||
.In strings.h
|
||||
for
|
||||
.Tn POSIX
|
||||
compliance.
|
||||
94
lib/libc/string/index.3
Normal file
94
lib/libc/string/index.3
Normal file
@@ -0,0 +1,94 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)index.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: index.3,v 1.13 2010/04/29 06:54:26 jruoho Exp $
|
||||
.\"
|
||||
.Dd April 29, 2010
|
||||
.Dt INDEX 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm index
|
||||
.Nd locate character in string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft char *
|
||||
.Fn index "const char *s" "int c"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn index
|
||||
function
|
||||
locates the first character matching
|
||||
.Fa c
|
||||
(converted to a
|
||||
.Em char )
|
||||
in the nul-terminated string
|
||||
.Fa s .
|
||||
.Sh RETURN VALUES
|
||||
A pointer to the character is returned if it is found; otherwise
|
||||
.Dv NULL
|
||||
is returned.
|
||||
If
|
||||
.Fa c
|
||||
is '\e0',
|
||||
.Fn index
|
||||
locates the terminating '\e0'.
|
||||
.Sh SEE ALSO
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn index
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
The
|
||||
.St -p1003.1-2004
|
||||
revision marked it as legacy and recommended the use of
|
||||
.Xr strchr 3
|
||||
instead.
|
||||
The
|
||||
.St -p1003.1-2008
|
||||
revision removed
|
||||
.Fn index
|
||||
from the specification.
|
||||
.Sh HISTORY
|
||||
An
|
||||
.Fn index
|
||||
function appeared in
|
||||
.At v6 .
|
||||
3
lib/libc/string/index.c
Normal file
3
lib/libc/string/index.c
Normal file
@@ -0,0 +1,3 @@
|
||||
/* $NetBSD: index.c,v 1.15 2005/12/20 19:31:50 christos Exp $ */
|
||||
#define INDEX
|
||||
#include "strchr.c"
|
||||
72
lib/libc/string/memccpy.3
Normal file
72
lib/libc/string/memccpy.3
Normal file
@@ -0,0 +1,72 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)memccpy.3 8.1 (Berkeley) 6/9/93
|
||||
.\" $NetBSD: memccpy.3,v 1.10 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd June 9, 1993
|
||||
.Dt MEMCCPY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memccpy
|
||||
.Nd copy string until character found
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memccpy "void *dst" "const void *src" "int c" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memccpy
|
||||
function
|
||||
copies bytes from string
|
||||
.Fa src
|
||||
to string
|
||||
.Fa dst .
|
||||
If the character
|
||||
.Fa c
|
||||
(as converted to an unsigned char) occurs in the string
|
||||
.Fa src ,
|
||||
the copy stops and a pointer to the byte after the copy of
|
||||
.Fa c
|
||||
in the string
|
||||
.Fa dst
|
||||
is returned.
|
||||
Otherwise,
|
||||
.Fa len
|
||||
bytes are copied, and a null pointer is returned.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcopy 3 ,
|
||||
.Xr memcpy 3 ,
|
||||
.Xr memmove 3 ,
|
||||
.Xr strcpy 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn memccpy
|
||||
function first appeared in
|
||||
.Bx 4.4 .
|
||||
65
lib/libc/string/memccpy.c
Normal file
65
lib/libc/string/memccpy.c
Normal file
@@ -0,0 +1,65 @@
|
||||
/* $NetBSD: memccpy.c,v 1.12 2003/08/07 16:43:48 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)memccpy.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: memccpy.c,v 1.12 2003/08/07 16:43:48 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memccpy(t, f, c, n)
|
||||
void *t;
|
||||
const void *f;
|
||||
int c;
|
||||
size_t n;
|
||||
{
|
||||
|
||||
_DIAGASSERT(t != 0);
|
||||
_DIAGASSERT(f != 0);
|
||||
|
||||
if (n) {
|
||||
unsigned char *tp = t;
|
||||
const unsigned char *fp = f;
|
||||
unsigned char uc = c;
|
||||
do {
|
||||
if ((*tp++ = *fp++) == uc)
|
||||
return (tp);
|
||||
} while (--n != 0);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
94
lib/libc/string/memchr.3
Normal file
94
lib/libc/string/memchr.3
Normal file
@@ -0,0 +1,94 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)memchr.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: memchr.3,v 1.11 2009/04/10 23:24:35 wiz Exp $
|
||||
.\"
|
||||
.Dd April 10, 2009
|
||||
.Dt MEMCHR 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memchr ,
|
||||
.Nm memrchr
|
||||
.Nd locate byte in byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memchr "const void *b" "int c" "size_t len"
|
||||
.Ft void *
|
||||
.Fn memrchr "const void *b" "int c" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memchr
|
||||
function
|
||||
locates the first occurrence of
|
||||
.Fa c
|
||||
(converted to an unsigned char)
|
||||
in string
|
||||
.Fa b .
|
||||
The
|
||||
.Fn memrchr
|
||||
function
|
||||
locates the last occurrence of
|
||||
.Fa c
|
||||
(converted to an unsigned char)
|
||||
in string
|
||||
.Fa b .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn memchr
|
||||
and
|
||||
.Fn memrchr
|
||||
functions
|
||||
return a pointer to the byte located, or
|
||||
.Dv NULL
|
||||
if no such byte exists within
|
||||
.Fa len
|
||||
bytes.
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn memchr
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
81
lib/libc/string/memcmp.3
Normal file
81
lib/libc/string/memcmp.3
Normal file
@@ -0,0 +1,81 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)memcmp.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: memcmp.3,v 1.9 2003/08/07 16:43:48 agc Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt MEMCMP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memcmp
|
||||
.Nd compare byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft int
|
||||
.Fn memcmp "const void *b1" "const void *b2" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memcmp
|
||||
function
|
||||
compares byte string
|
||||
.Fa b1
|
||||
against byte string
|
||||
.Fa b2 .
|
||||
Both strings are assumed to be
|
||||
.Fa len
|
||||
bytes long.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn memcmp
|
||||
function
|
||||
returns zero if the two strings are identical,
|
||||
otherwise returns the difference between the first two differing bytes
|
||||
(treated as unsigned char values, so that
|
||||
.Sq Li \e200
|
||||
is greater than
|
||||
.Sq Li \&\e0 ,
|
||||
for example).
|
||||
Zero-length strings are always identical.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcmp 3 ,
|
||||
.Xr strcasecmp 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strcoll 3 ,
|
||||
.Xr strxfrm 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn memcmp
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
77
lib/libc/string/memcpy.3
Normal file
77
lib/libc/string/memcpy.3
Normal file
@@ -0,0 +1,77 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)memcpy.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: memcpy.3,v 1.13 2003/09/08 17:54:33 wiz Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt MEMCPY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memcpy
|
||||
.Nd copy byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memcpy "void * restrict dst" "const void * restrict src" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memcpy
|
||||
function
|
||||
copies
|
||||
.Fa len
|
||||
bytes from string
|
||||
.Fa src
|
||||
to string
|
||||
.Fa dst .
|
||||
The arguments must not overlap -- behavior if the arguments overlap is
|
||||
undefined.
|
||||
To copy byte strings that overlap, use
|
||||
.Xr memmove 3 .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn memcpy
|
||||
function
|
||||
returns the original value of
|
||||
.Fa dst .
|
||||
.Sh SEE ALSO
|
||||
.Xr bcopy 3 ,
|
||||
.Xr memccpy 3 ,
|
||||
.Xr memmove 3 ,
|
||||
.Xr strcpy 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn memcpy
|
||||
function
|
||||
conforms to
|
||||
.St -isoC-99 .
|
||||
84
lib/libc/string/memmem.3
Normal file
84
lib/libc/string/memmem.3
Normal file
@@ -0,0 +1,84 @@
|
||||
.\" $NetBSD: memmem.3,v 1.3 2008/04/30 13:10:51 martin Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Perry E. Metzger of Metzger, Dowdeswell & Co. LLC.
|
||||
.\"
|
||||
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
.\"
|
||||
.Dd March 12, 2005
|
||||
.Dt MEMMEM 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memmem
|
||||
.Nd locate substring in byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memmem "const void *block" "size_t blen" "const void *pat" "size_t plen"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memmem
|
||||
function locates the first occurrence of the binary string
|
||||
.Fa pat
|
||||
of size
|
||||
.Fa plen
|
||||
bytes in the byte string
|
||||
.Fa block
|
||||
of size
|
||||
.Fa blen
|
||||
bytes.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn memmem
|
||||
function returns a pointer to the substring located, or
|
||||
.Dv NULL
|
||||
if no such substring exists within
|
||||
.Fa block .
|
||||
.Pp
|
||||
If
|
||||
.Fa plen
|
||||
is zero,
|
||||
.Fa block
|
||||
is returned, i.e. a zero length
|
||||
.Fa pat
|
||||
is deemed to match the start of the string, as with
|
||||
.Xr strstr 3 .
|
||||
.Sh SEE ALSO
|
||||
.Xr bm 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strstr 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn memmem
|
||||
function is not currently standardized.
|
||||
However, it is meant to be API compatible with functions in
|
||||
.Fx
|
||||
and Linux.
|
||||
.Sh HISTORY
|
||||
.Fn memmem
|
||||
first appeared in the Free Software Foundation's glibc library.
|
||||
80
lib/libc/string/memmem.c
Normal file
80
lib/libc/string/memmem.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* $NetBSD: memmem.c,v 1.2 2008/04/28 20:23:00 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2005 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Perry E. Metzger of Metzger, Dowdeswell & Co. LLC.
|
||||
*
|
||||
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: memmem.c,v 1.2 2008/04/28 20:23:00 martin Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#if !defined(_KERNEL) && !defined(_STANDALONE)
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#else
|
||||
#include <lib/libkern/libkern.h>
|
||||
#define _DIAGASSERT(x) (void)0
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
void *
|
||||
memmem(const void *block, size_t blen, const void *pat, size_t plen)
|
||||
{
|
||||
const unsigned char *bp, *pp, *endp;
|
||||
|
||||
_DIAGASSERT(block != NULL);
|
||||
_DIAGASSERT(pat != NULL);
|
||||
|
||||
/*
|
||||
* Following the precedent in ststr(3) and glibc, a zero
|
||||
* length pattern matches the start of block.
|
||||
*/
|
||||
if (plen == 0)
|
||||
return __UNCONST(block);
|
||||
|
||||
if (blen < plen)
|
||||
return NULL;
|
||||
|
||||
bp = block;
|
||||
pp = pat;
|
||||
endp = bp + (blen - plen) + 1;
|
||||
|
||||
/*
|
||||
* As a cheezy optimization, check that the first chars are
|
||||
* the same before calling memcmp. Really we should use bm(3)
|
||||
* to speed this up if blen is large enough.
|
||||
*/
|
||||
while (bp < endp) {
|
||||
if ((*bp == *pp) && (memcmp(bp, pp, plen) == 0))
|
||||
return __UNCONST(bp);
|
||||
bp++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
74
lib/libc/string/memmove.3
Normal file
74
lib/libc/string/memmove.3
Normal file
@@ -0,0 +1,74 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)memmove.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: memmove.3,v 1.8 2003/08/07 16:43:48 agc Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt MEMMOVE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memmove
|
||||
.Nd copy byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memmove "void *dst" "const void *src" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memmove
|
||||
function
|
||||
copies
|
||||
.Fa len
|
||||
bytes from string
|
||||
.Fa src
|
||||
to string
|
||||
.Fa dst .
|
||||
The two strings may overlap;
|
||||
the copy is always done in a non-destructive manner.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn memmove
|
||||
function returns the original value of
|
||||
.Fa dst .
|
||||
.Sh SEE ALSO
|
||||
.Xr bcopy 3 ,
|
||||
.Xr memccpy 3 ,
|
||||
.Xr memcpy 3 ,
|
||||
.Xr strcpy 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn memmove
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
54
lib/libc/string/memrchr.c
Normal file
54
lib/libc/string/memrchr.c
Normal file
@@ -0,0 +1,54 @@
|
||||
/* $NetBSD: memrchr.c,v 1.2 2009/04/11 21:42:16 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Christos Zoulas.
|
||||
*
|
||||
* 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: memrchr.c,v 1.2 2009/04/11 21:42:16 christos Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void *
|
||||
memrchr(const void *s, int c, size_t n)
|
||||
{
|
||||
_DIAGASSERT(s != NULL);
|
||||
|
||||
if (n != 0) {
|
||||
const unsigned char *p = (const unsigned char *)s + n;
|
||||
const unsigned char cmp = c;
|
||||
|
||||
do {
|
||||
if (*--p == cmp)
|
||||
return __UNCONST(p);
|
||||
} while (--n != 0);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
71
lib/libc/string/memset.3
Normal file
71
lib/libc/string/memset.3
Normal file
@@ -0,0 +1,71 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)memset.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: memset.3,v 1.9 2003/08/07 16:43:49 agc Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt MEMSET 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm memset
|
||||
.Nd write a byte to byte string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft void *
|
||||
.Fn memset "void *b" "int c" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn memset
|
||||
function
|
||||
writes
|
||||
.Fa len
|
||||
bytes of value
|
||||
.Fa c
|
||||
(converted to an unsigned char) to the string
|
||||
.Fa b .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn memset
|
||||
function
|
||||
returns the original value of
|
||||
.Fa b .
|
||||
.Sh SEE ALSO
|
||||
.Xr bzero 3 ,
|
||||
.Xr swab 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn memset
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
70
lib/libc/string/popcount.3
Normal file
70
lib/libc/string/popcount.3
Normal file
@@ -0,0 +1,70 @@
|
||||
.\" $NetBSD: popcount.3,v 1.4 2009/07/22 07:07:27 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Joerg Sonnenberger.
|
||||
.\"
|
||||
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
.\"
|
||||
.Dd July 13, 2009
|
||||
.Dt POPCOUNT 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm popcount ,
|
||||
.Nm popcountl ,
|
||||
.Nm popcountll ,
|
||||
.Nm popcount32 ,
|
||||
.Nm popcount64
|
||||
.Nd count number of bits set in a bit string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft unsigned int
|
||||
.Fn popcount "unsigned int value"
|
||||
.Ft unsigned int
|
||||
.Fn popcountl "unsigned long value"
|
||||
.Ft unsigned int
|
||||
.Fn popcountll "unsigned long long value"
|
||||
.Ft unsigned int
|
||||
.Fn popcount32 "uint32_t value"
|
||||
.Ft unsigned int
|
||||
.Fn popcount64 "uint64_t value"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
functions returns the number of bits set in
|
||||
.Fa value .
|
||||
.Sh SEE ALSO
|
||||
.Xr ffs 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn popcount ,
|
||||
.Fn popcountl ,
|
||||
.Fn popcountll ,
|
||||
.Fn popcount32 ,
|
||||
and
|
||||
.Fn popcount64
|
||||
functions appeared in
|
||||
.Nx 6.0 .
|
||||
97
lib/libc/string/rindex.3
Normal file
97
lib/libc/string/rindex.3
Normal file
@@ -0,0 +1,97 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)rindex.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: rindex.3,v 1.12 2010/04/29 06:54:26 jruoho Exp $
|
||||
.\"
|
||||
.Dd April 29, 2010
|
||||
.Dt RINDEX 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm rindex
|
||||
.Nd locate character in string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft char *
|
||||
.Fn rindex "const char *s" "int c"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn rindex
|
||||
function
|
||||
locates the last character
|
||||
matching
|
||||
.Fa c
|
||||
(converted to a
|
||||
.Em char )
|
||||
in the nul-terminated string
|
||||
.Fa s .
|
||||
.Sh RETURN VALUES
|
||||
A pointer to the character is returned if it is found; otherwise
|
||||
.Dv NULL
|
||||
is returned.
|
||||
If
|
||||
.Fa c
|
||||
is
|
||||
.Ql \e0 ,
|
||||
.Fn rindex
|
||||
locates the terminating
|
||||
.Ql \e0 .
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn rindex
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
The
|
||||
.St -p1003.1-2004
|
||||
revision marked it as legacy and recommended the use of
|
||||
.Xr strrchr 3
|
||||
instead.
|
||||
The
|
||||
.St -p1003.1-2008
|
||||
revision removed
|
||||
.Fn rindex
|
||||
from the specification.
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Fn rindex
|
||||
function appeared in
|
||||
.At v6 .
|
||||
3
lib/libc/string/rindex.c
Normal file
3
lib/libc/string/rindex.c
Normal file
@@ -0,0 +1,3 @@
|
||||
/* $NetBSD: rindex.c,v 1.15 2005/12/20 19:31:50 christos Exp $ */
|
||||
#define RINDEX
|
||||
#include "strrchr.c"
|
||||
52
lib/libc/string/stpcpy.c
Normal file
52
lib/libc/string/stpcpy.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* $NetBSD: stpcpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999
|
||||
* David E. O'Brien
|
||||
* Copyright (c) 1988, 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strcpy.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: stpcpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
/* FreeBSD: src/lib/libc/string/stpcpy.c,v 1.2 2009/02/28 06:05:37 das Exp */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
stpcpy(char * __restrict to, const char * __restrict from)
|
||||
{
|
||||
|
||||
for (; (*to = *from); ++from, ++to);
|
||||
return(to);
|
||||
}
|
||||
50
lib/libc/string/stpncpy.c
Normal file
50
lib/libc/string/stpncpy.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* $NetBSD: stpncpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: stpncpy.c,v 1.1 2009/05/01 17:27:01 perry Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
/* FreeBSD: src/lib/libc/string/stpncpy.c,v 1.1 2009/02/28 06:00:58 das Exp */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
stpncpy(char * __restrict dst, const char * __restrict src, size_t n)
|
||||
{
|
||||
|
||||
for (; n--; dst++, src++) {
|
||||
if (!(*dst = *src)) {
|
||||
char *ret = dst;
|
||||
while (n--)
|
||||
*++dst = '\0';
|
||||
return (ret);
|
||||
}
|
||||
}
|
||||
return (dst);
|
||||
}
|
||||
93
lib/libc/string/strcasecmp.3
Normal file
93
lib/libc/string/strcasecmp.3
Normal file
@@ -0,0 +1,93 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)strcasecmp.3 8.1 (Berkeley) 6/9/93
|
||||
.\" $NetBSD: strcasecmp.3,v 1.17 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd June 9, 1993
|
||||
.Dt STRCASECMP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strcasecmp ,
|
||||
.Nm strncasecmp
|
||||
.Nd compare strings, ignoring case
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft int
|
||||
.Fn strcasecmp "const char *s1" "const char *s2"
|
||||
.Ft int
|
||||
.Fn strncasecmp "const char *s1" "const char *s2" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strcasecmp
|
||||
and
|
||||
.Fn strncasecmp
|
||||
functions
|
||||
compare the nul-terminated strings
|
||||
.Fa s1
|
||||
and
|
||||
.Fa s2
|
||||
and return an integer greater than, equal to, or less than 0,
|
||||
according to whether
|
||||
.Fa s1
|
||||
is lexicographically greater than, equal to, or less than
|
||||
.Fa s2
|
||||
after translation of each corresponding character to lower-case.
|
||||
The strings themselves are not modified.
|
||||
The comparison is done using unsigned characters, so that
|
||||
.Sq Li \e200
|
||||
is greater than
|
||||
.Ql \e0 .
|
||||
.Pp
|
||||
The
|
||||
.Fn strncasecmp
|
||||
compares at most
|
||||
.Fa len
|
||||
characters.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcmp 3 ,
|
||||
.Xr memcmp 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strcoll 3 ,
|
||||
.Xr strxfrm 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strcasecmp
|
||||
and
|
||||
.Fn strncasecmp
|
||||
functions first appeared in
|
||||
.Bx 4.4 .
|
||||
.Sh NOTES
|
||||
If
|
||||
.Fa len
|
||||
is zero
|
||||
.Fn strncasecmp
|
||||
returns always 0.
|
||||
69
lib/libc/string/strcasestr.c
Normal file
69
lib/libc/string/strcasestr.c
Normal file
@@ -0,0 +1,69 @@
|
||||
/* $NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: strcasestr.c,v 1.3 2005/11/29 03:12:00 christos Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Find the first occurrence of find in s, ignore case.
|
||||
*/
|
||||
char *
|
||||
strcasestr(const char *s, const char *find)
|
||||
{
|
||||
char c, sc;
|
||||
size_t len;
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(find != NULL);
|
||||
|
||||
if ((c = *find++) != 0) {
|
||||
c = tolower((unsigned char)c);
|
||||
len = strlen(find);
|
||||
do {
|
||||
do {
|
||||
if ((sc = *s++) == 0)
|
||||
return (NULL);
|
||||
} while ((char)tolower((unsigned char)sc) != c);
|
||||
} while (strncasecmp(s, find, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return __UNCONST(s);
|
||||
}
|
||||
138
lib/libc/string/strcat.3
Normal file
138
lib/libc/string/strcat.3
Normal file
@@ -0,0 +1,138 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strcat.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strcat.3,v 1.16 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd August 11, 2002
|
||||
.Dt STRCAT 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strcat ,
|
||||
.Nm strncat
|
||||
.Nd concatenate strings
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strcat "char * restrict s" "const char * restrict append"
|
||||
.Ft char *
|
||||
.Fn strncat "char * restrict s" "const char * restrict append" "size_t count"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strcat
|
||||
and
|
||||
.Fn strncat
|
||||
functions
|
||||
append a copy of the nul-terminated string
|
||||
.Fa append
|
||||
to the end of the nul-terminated string
|
||||
.Fa s ,
|
||||
then add a terminating
|
||||
.Ql \e0 .
|
||||
The string
|
||||
.Fa s
|
||||
must have sufficient space to hold the result.
|
||||
.Pp
|
||||
The
|
||||
.Fn strncat
|
||||
function
|
||||
appends not more than
|
||||
.Fa count
|
||||
characters where space for the terminating
|
||||
.Ql \e0
|
||||
should not be included in
|
||||
.Fa count .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strcat
|
||||
and
|
||||
.Fn strncat
|
||||
functions
|
||||
return the pointer
|
||||
.Fa s .
|
||||
.Sh EXAMPLES
|
||||
The following appends
|
||||
.Dq Li abc
|
||||
to
|
||||
.Dq Li chararray :
|
||||
.Bd -literal -offset indent
|
||||
char *letters = "abcdefghi";
|
||||
|
||||
(void)strncat(chararray, letters, 3);
|
||||
.Ed
|
||||
.Pp
|
||||
The following example shows how to use
|
||||
.Fn strncat
|
||||
safely in conjunction with
|
||||
.Xr strncpy 3 .
|
||||
.Bd -literal -offset indent
|
||||
char buf[BUFSIZ];
|
||||
char *input, *suffix;
|
||||
|
||||
(void)strncpy(buf, input, sizeof(buf) - 1);
|
||||
buf[sizeof(buf) - 1] = '\e0';
|
||||
(void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf));
|
||||
.Ed
|
||||
.Pp
|
||||
The above will copy as many characters from
|
||||
.Dq Li input
|
||||
to
|
||||
.Dq Li buf
|
||||
as will fit.
|
||||
It then appends as many characters from suffix as will fit (or none
|
||||
if there is no space).
|
||||
For operations like this, the
|
||||
.Xr strlcpy 3
|
||||
and
|
||||
.Xr strlcat 3
|
||||
functions are a better choice, as shown below.
|
||||
.Bd -literal -offset indent
|
||||
(void)strlcpy(buf, input, sizeof(buf));
|
||||
(void)strlcat(buf, suffix, sizeof(buf));
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr bcopy 3 ,
|
||||
.Xr memccpy 3 ,
|
||||
.Xr memcpy 3 ,
|
||||
.Xr memmove 3 ,
|
||||
.Xr strcpy 3 ,
|
||||
.Xr strlcat 3 ,
|
||||
.Xr strlcpy 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strcat
|
||||
and
|
||||
.Fn strncat
|
||||
functions
|
||||
conform to
|
||||
.St -isoC-99 .
|
||||
98
lib/libc/string/strchr.3
Normal file
98
lib/libc/string/strchr.3
Normal file
@@ -0,0 +1,98 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strchr.3 8.2 (Berkeley) 4/19/94
|
||||
.\" $NetBSD: strchr.3,v 1.11 2003/08/07 16:43:49 agc Exp $
|
||||
.\"
|
||||
.Dd August 11, 2002
|
||||
.Dt STRCHR 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strchr
|
||||
.Nd locate character in string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strchr "const char *s" "int c"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strchr
|
||||
function locates the first occurrence of
|
||||
.Ar c
|
||||
in the string pointed to by
|
||||
.Ar s .
|
||||
The terminating
|
||||
.Dv NUL
|
||||
character is considered part of the string.
|
||||
If
|
||||
.Fa c
|
||||
is
|
||||
.Ql \e0 ,
|
||||
.Fn strchr
|
||||
locates the terminating
|
||||
.Ql \e0 .
|
||||
.Sh RETURN VALUES
|
||||
The function
|
||||
.Fn strchr
|
||||
returns a pointer to the located character, or
|
||||
.Dv NULL
|
||||
if the character does not appear in the string.
|
||||
.Sh EXAMPLES
|
||||
After the following call to
|
||||
.Fn strchr ,
|
||||
.Va p
|
||||
will point to the string
|
||||
.Qq oobar :
|
||||
.Bd -literal -offset indent
|
||||
char *p;
|
||||
char *s = "foobar";
|
||||
|
||||
p = strchr(s, 'o');
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strchr
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
99
lib/libc/string/strcmp.3
Normal file
99
lib/libc/string/strcmp.3
Normal file
@@ -0,0 +1,99 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strcmp.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strcmp.3,v 1.13 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt STRCMP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strcmp ,
|
||||
.Nm strncmp
|
||||
.Nd compare strings
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft int
|
||||
.Fn strcmp "const char *s1" "const char *s2"
|
||||
.Ft int
|
||||
.Fn strncmp "const char *s1" "const char *s2" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strcmp
|
||||
and
|
||||
.Fn strncmp
|
||||
functions
|
||||
lexicographically compare the nul-terminated strings
|
||||
.Fa s1
|
||||
and
|
||||
.Fa s2 .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strcmp
|
||||
and
|
||||
.Fn strncmp
|
||||
return an integer greater than, equal to, or less than 0, according
|
||||
to whether the string
|
||||
.Fa s1
|
||||
is greater than, equal to, or less than the string
|
||||
.Fa s2 .
|
||||
The comparison is done using unsigned characters, so that
|
||||
.Ql \e200
|
||||
is greater than
|
||||
.Ql \e0 .
|
||||
.Pp
|
||||
The
|
||||
.Fn strncmp
|
||||
compares not more than
|
||||
.Fa len
|
||||
characters.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcmp 3 ,
|
||||
.Xr memcmp 3 ,
|
||||
.Xr strcasecmp 3 ,
|
||||
.Xr strcoll 3 ,
|
||||
.Xr strxfrm 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strcmp
|
||||
and
|
||||
.Fn strncmp
|
||||
functions
|
||||
conform to
|
||||
.St -ansiC .
|
||||
.Sh NOTES
|
||||
If
|
||||
.Fa len
|
||||
is zero
|
||||
.Fn strncmp
|
||||
returns always 0.
|
||||
73
lib/libc/string/strcoll.3
Normal file
73
lib/libc/string/strcoll.3
Normal file
@@ -0,0 +1,73 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strcoll.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strcoll.3,v 1.10 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt STRCOLL 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strcoll
|
||||
.Nd compare strings according to current collation
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft int
|
||||
.Fn strcoll "const char *s1" "const char *s2"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strcoll
|
||||
function
|
||||
lexicographically compares the nul-terminated strings
|
||||
.Fa s1
|
||||
and
|
||||
.Fa s2
|
||||
according to the current locale collation
|
||||
and returns an integer greater than, equal to, or less than 0,
|
||||
according to whether
|
||||
.Fa s1
|
||||
is greater than, equal to, or less than
|
||||
.Fa s2 .
|
||||
.Sh SEE ALSO
|
||||
.Xr bcmp 3 ,
|
||||
.Xr memcmp 3 ,
|
||||
.Xr setlocale 3 ,
|
||||
.Xr strcasecmp 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strxfrm 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strcoll
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
60
lib/libc/string/strcoll.c
Normal file
60
lib/libc/string/strcoll.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: strcoll.c,v 1.9 2003/08/07 16:43:50 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strcoll.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strcoll.c,v 1.9 2003/08/07 16:43:50 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Compare strings according to LC_COLLATE category of current locale.
|
||||
*/
|
||||
int
|
||||
strcoll(s1, s2)
|
||||
const char *s1, *s2;
|
||||
{
|
||||
|
||||
_DIAGASSERT(s1 != NULL);
|
||||
_DIAGASSERT(s2 != NULL);
|
||||
|
||||
/* LC_COLLATE is unimplemented, hence always "C" */
|
||||
return (strcmp(s1, s2));
|
||||
}
|
||||
220
lib/libc/string/strcpy.3
Normal file
220
lib/libc/string/strcpy.3
Normal file
@@ -0,0 +1,220 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strcpy.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strcpy.3,v 1.20 2009/05/02 09:37:32 wiz Exp $
|
||||
.\"
|
||||
.Dd May 1, 2009
|
||||
.Dt STRCPY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm stpcpy ,
|
||||
.Nm stpncpy ,
|
||||
.Nm strcpy ,
|
||||
.Nm strncpy
|
||||
.Nd copy strings
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn stpcpy "char * restrict dst" "const char * restrict src"
|
||||
.Ft char *
|
||||
.Fn stpncpy "char * restrict dst" "const char * restrict src" "size_t len"
|
||||
.Ft char *
|
||||
.Fn strcpy "char * restrict dst" "const char * restrict src"
|
||||
.Ft char *
|
||||
.Fn strncpy "char * restrict dst" "const char * restrict src" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn stpcpy
|
||||
and
|
||||
.Fn strcpy
|
||||
functions
|
||||
copy the string
|
||||
.Fa src
|
||||
to
|
||||
.Fa dst
|
||||
(including the terminating
|
||||
.Ql \e0
|
||||
character).
|
||||
.Pp
|
||||
The
|
||||
.Fn stpncpy
|
||||
and
|
||||
.Fn strncpy
|
||||
functions copy at most
|
||||
.Fa len
|
||||
characters from
|
||||
.Fa src
|
||||
into
|
||||
.Fa dst .
|
||||
If
|
||||
.Fa src
|
||||
is less than
|
||||
.Fa len
|
||||
characters long,
|
||||
the remainder of
|
||||
.Fa dst
|
||||
is filled with
|
||||
.Ql \e0
|
||||
characters.
|
||||
Otherwise,
|
||||
.Fa dst
|
||||
is
|
||||
.Em not
|
||||
terminated.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strcpy
|
||||
and
|
||||
.Fn strncpy
|
||||
functions
|
||||
return
|
||||
.Fa dst .
|
||||
The
|
||||
.Fn stpcpy
|
||||
and
|
||||
.Fn stpncpy
|
||||
functions return a pointer to the terminating
|
||||
.Ql \e0
|
||||
character of
|
||||
.Fa dst .
|
||||
If
|
||||
.Fn stpncpy
|
||||
does not terminate
|
||||
.Fa dst
|
||||
with a
|
||||
.Dv NUL
|
||||
character, it instead returns a pointer to
|
||||
.Li dst[len]
|
||||
(which does not necessarily refer to a valid memory location.)
|
||||
.Sh EXAMPLES
|
||||
The following sets
|
||||
.Va chararray
|
||||
to
|
||||
.Dq Li abc\e0\e0\e0 :
|
||||
.Bd -literal -offset indent
|
||||
char chararray[6];
|
||||
|
||||
(void)strncpy(chararray, "abc", sizeof(chararray));
|
||||
.Ed
|
||||
.Pp
|
||||
The following sets
|
||||
.Va chararray
|
||||
to
|
||||
.Dq Li abcdef :
|
||||
.Bd -literal -offset indent
|
||||
char chararray[6];
|
||||
|
||||
(void)strncpy(chararray, "abcdefgh", sizeof(chararray));
|
||||
.Ed
|
||||
.Pp
|
||||
Note that it does
|
||||
.Em not
|
||||
.Dv NUL Ns No -terminate
|
||||
.Va chararray
|
||||
because the length of the source string is greater than or equal
|
||||
to the length parameter.
|
||||
.Fn strncpy
|
||||
.Em only
|
||||
.Dv NUL Ns No -terminates
|
||||
the destination string when the length of the source
|
||||
string is less than the length parameter.
|
||||
.Pp
|
||||
The following copies as many characters from
|
||||
.Va input
|
||||
to
|
||||
.Va buf
|
||||
as will fit and
|
||||
.Dv NUL Ns No -terminates
|
||||
the result.
|
||||
Because
|
||||
.Fn strncpy
|
||||
does
|
||||
.Em not
|
||||
guarantee to
|
||||
.Dv NUL Ns No -terminate
|
||||
the string itself, this must be done explicitly.
|
||||
.Bd -literal -offset indent
|
||||
char buf[1024];
|
||||
|
||||
(void)strncpy(buf, input, sizeof(buf) - 1);
|
||||
buf[sizeof(buf) - 1] = '\e0';
|
||||
.Ed
|
||||
.Pp
|
||||
This could be better and more simply achieved using
|
||||
.Xr strlcpy 3 ,
|
||||
as shown in the following example:
|
||||
.Bd -literal -offset indent
|
||||
(void)strlcpy(buf, input, sizeof(buf));
|
||||
.Ed
|
||||
.Pp
|
||||
Note that because
|
||||
.Xr strlcpy 3
|
||||
is not defined in any standards, it should
|
||||
only be used when portability is not a concern.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcopy 3 ,
|
||||
.Xr memccpy 3 ,
|
||||
.Xr memcpy 3 ,
|
||||
.Xr memmove 3 ,
|
||||
.Xr strlcpy 3 ,
|
||||
.Xr wcscpy 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strcpy
|
||||
and
|
||||
.Fn strncpy
|
||||
functions
|
||||
conform to
|
||||
.St -isoC-99 .
|
||||
The
|
||||
.Fn stpcpy
|
||||
and
|
||||
.Fn stpncpy
|
||||
functions conform to
|
||||
.St -p1003.1-2008 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn stpcpy
|
||||
and
|
||||
.Fn stpncpy
|
||||
functions first appeared in
|
||||
.Nx 6.0 .
|
||||
.Sh SECURITY CONSIDERATIONS
|
||||
The
|
||||
.Fn strcpy
|
||||
and
|
||||
.Fn stpcpy
|
||||
functions are easily misused in a manner which enables malicious users
|
||||
to arbitrarily change a running program's functionality through a
|
||||
buffer overflow attack.
|
||||
97
lib/libc/string/strcspn.3
Normal file
97
lib/libc/string/strcspn.3
Normal file
@@ -0,0 +1,97 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strcspn.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strcspn.3,v 1.10 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd August 11, 2002
|
||||
.Dt STRCSPN 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strcspn
|
||||
.Nd span the complement of a string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft size_t
|
||||
.Fn strcspn "const char *s" "const char *charset"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strcspn
|
||||
function
|
||||
spans the initial part of the nul-terminated string
|
||||
.Fa s
|
||||
as long as the characters from
|
||||
.Fa s
|
||||
do not occur in string
|
||||
.Fa charset
|
||||
(it
|
||||
spans the
|
||||
.Em complement
|
||||
of
|
||||
.Fa charset ) .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strcspn
|
||||
function
|
||||
returns the number of characters spanned.
|
||||
.Sh EXAMPLES
|
||||
The following call to
|
||||
.Fn strcspn
|
||||
will return 3, since the first three characters of string
|
||||
.Fa s
|
||||
do not occur in string
|
||||
.Fa charset :
|
||||
.Bd -literal -offset indent
|
||||
char *s = "foobar";
|
||||
char *charset = "bar";
|
||||
size_t span;
|
||||
|
||||
span = strcspn(s, charset);
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strcspn
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
70
lib/libc/string/strcspn.c
Normal file
70
lib/libc/string/strcspn.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* $NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Joerg Sonnenberger
|
||||
* 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(S) ``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(S) 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 <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strcspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $");
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
/* 64bit version is in strspn.c */
|
||||
#if ULONG_MAX != 0xffffffffffffffffull
|
||||
|
||||
size_t
|
||||
strcspn(const char *s, const char *charset)
|
||||
{
|
||||
static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
|
||||
const char *t;
|
||||
uint8_t set[32];
|
||||
#define UC(a) ((unsigned int)(unsigned char)(a))
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(charset != NULL);
|
||||
|
||||
if (charset[0] == '\0')
|
||||
return strlen(s);
|
||||
if (charset[1] == '\0') {
|
||||
for (t = s; *t != '\0'; ++t)
|
||||
if (*t == *charset)
|
||||
break;
|
||||
return t - s;
|
||||
}
|
||||
|
||||
(void)memset(set, 0, sizeof(set));
|
||||
|
||||
for (; *charset != '\0'; ++charset)
|
||||
set[UC(*charset) >> 3] |= idx[UC(*charset) & 7];
|
||||
|
||||
for (t = s; *t != '\0'; ++t)
|
||||
if (set[UC(*t) >> 3] & idx[UC(*t) & 7])
|
||||
break;
|
||||
return t - s;
|
||||
}
|
||||
|
||||
#endif
|
||||
109
lib/libc/string/strdup.3
Normal file
109
lib/libc/string/strdup.3
Normal file
@@ -0,0 +1,109 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)strdup.3 8.1 (Berkeley) 6/9/93
|
||||
.\" $NetBSD: strdup.3,v 1.18 2009/01/29 10:15:39 wiz Exp $
|
||||
.\"
|
||||
.Dd January 28, 2009
|
||||
.Dt STRDUP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strdup ,
|
||||
.Nm strndup
|
||||
.Nd save a copy of a string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strdup "const char *str"
|
||||
.Ft char *
|
||||
.Fn strndup "const char *str" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strdup
|
||||
function
|
||||
allocates sufficient memory for a copy
|
||||
of the string
|
||||
.Fa str ,
|
||||
does the copy, and returns a pointer to it.
|
||||
The pointer may subsequently be used as an
|
||||
argument to the function
|
||||
.Xr free 3 .
|
||||
.Pp
|
||||
If insufficient memory is available,
|
||||
.Dv NULL
|
||||
is returned.
|
||||
.Pp
|
||||
The
|
||||
.Fn strndup
|
||||
function copies at most
|
||||
.Fa len
|
||||
characters from the string
|
||||
.Fa str
|
||||
always
|
||||
.Dv NUL
|
||||
terminating the copied string.
|
||||
.Sh EXAMPLES
|
||||
The following will point
|
||||
.Va p
|
||||
to an allocated area of memory containing the nul-terminated string
|
||||
.Qq foobar :
|
||||
.Bd -literal -offset indent
|
||||
char *p;
|
||||
|
||||
if ((p = strdup("foobar")) == NULL) {
|
||||
fprintf(stderr, "Out of memory.\en");
|
||||
exit(1);
|
||||
}
|
||||
.Ed
|
||||
.Sh ERRORS
|
||||
The
|
||||
.Fn strdup
|
||||
function may fail and set the external variable
|
||||
.Va errno
|
||||
for any of the errors specified for the library function
|
||||
.Xr malloc 3 .
|
||||
.Sh SEE ALSO
|
||||
.Xr free 3 ,
|
||||
.Xr malloc 3 ,
|
||||
.Xr strcpy 3 ,
|
||||
.Xr strlen 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strdup
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strdup
|
||||
function first appeared in
|
||||
.Bx 4.4 .
|
||||
The
|
||||
.Fn strndup
|
||||
function was added in
|
||||
.Nx 4.0 .
|
||||
66
lib/libc/string/strdup.c
Normal file
66
lib/libc/string/strdup.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/* $NetBSD: strdup.c,v 1.13 2003/08/07 16:43:50 agc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strdup.c,v 1.13 2003/08/07 16:43:50 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(strdup,_strdup)
|
||||
#endif
|
||||
|
||||
char *
|
||||
strdup(str)
|
||||
const char *str;
|
||||
{
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
_DIAGASSERT(str != NULL);
|
||||
|
||||
len = strlen(str) + 1;
|
||||
if (!(copy = malloc(len)))
|
||||
return (NULL);
|
||||
memcpy(copy, str, len);
|
||||
return (copy);
|
||||
}
|
||||
197
lib/libc/string/strerror.3
Normal file
197
lib/libc/string/strerror.3
Normal file
@@ -0,0 +1,197 @@
|
||||
.\" $NetBSD: strerror.3,v 1.17 2010/10/25 07:37:11 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the American National Standards Committee X3, on Information
|
||||
.\" Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" @(#)strerror.3 8.1 (Berkeley) 6/9/93
|
||||
.Dd October 24, 2010
|
||||
.Dt STRERROR 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm perror ,
|
||||
.Nm strerror ,
|
||||
.Nm strerror_r ,
|
||||
.Nm sys_errlist ,
|
||||
.Nm sys_nerr
|
||||
.Nd system error messages
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In stdio.h
|
||||
.Ft void
|
||||
.Fn perror "const char *string"
|
||||
.In errno.h
|
||||
.Vt extern const char * const sys_errlist[] ;
|
||||
.Vt extern const int sys_nerr ;
|
||||
.In string.h
|
||||
.Ft "char *"
|
||||
.Fn strerror "int errnum"
|
||||
.Ft int
|
||||
.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strerror ,
|
||||
.Fn strerror_r ,
|
||||
and
|
||||
.Fn perror
|
||||
functions look up the language-dependent error message
|
||||
string corresponding to an error number.
|
||||
.Pp
|
||||
The
|
||||
.Fn strerror
|
||||
function accepts an error number argument
|
||||
.Fa errnum
|
||||
and returns a pointer to the corresponding
|
||||
message string.
|
||||
.Pp
|
||||
The
|
||||
.Fn strerror_r
|
||||
function renders the same result into
|
||||
.Fa strerrbuf
|
||||
for a maximum of
|
||||
.Fa buflen
|
||||
characters and returns 0 upon success.
|
||||
.Pp
|
||||
The
|
||||
.Fn perror
|
||||
function finds the error message corresponding to the current
|
||||
value of the global variable
|
||||
.Va errno
|
||||
.Pq Xr intro 2
|
||||
and writes it, followed by a newline, to the
|
||||
standard error file descriptor.
|
||||
If the argument
|
||||
.Fa string
|
||||
is
|
||||
.Pf non- Dv NULL
|
||||
and does not point to the nul character,
|
||||
this string is prepended to the message
|
||||
string and separated from it by
|
||||
a colon and space
|
||||
.Pq Dq Li ":\ " ;
|
||||
otherwise, only the error message string is printed.
|
||||
Note that in most cases the
|
||||
.Xr err 3
|
||||
and
|
||||
.Xr warn 3
|
||||
family of functions is preferable to
|
||||
.Fn perror ;
|
||||
they are more flexible and also print the program name.
|
||||
.Pp
|
||||
If the error number is not recognized, these functions pass an error message
|
||||
string containing
|
||||
.Dq Li "Unknown error:\ "
|
||||
followed by the error number in decimal.
|
||||
To warn about this,
|
||||
.Fn strerror
|
||||
sets
|
||||
.Dv errno
|
||||
to
|
||||
.Er EINVAL ,
|
||||
and
|
||||
.Fn strerror_r
|
||||
returns
|
||||
.Er EINVAL .
|
||||
Error numbers recognized by this implementation fall in
|
||||
the range 0 \*[Lt]
|
||||
.Fa errnum
|
||||
\*[Lt]
|
||||
.Fa sys_nerr .
|
||||
.Pp
|
||||
If insufficient storage is provided in
|
||||
.Fa strerrbuf
|
||||
(as specified in
|
||||
.Fa buflen )
|
||||
to contain the error string,
|
||||
.Fn strerror_r
|
||||
returns
|
||||
.Er ERANGE
|
||||
and
|
||||
.Fa strerrbuf
|
||||
will contain an error message that has been truncated and
|
||||
.Dv NUL
|
||||
terminated to fit the length specified by
|
||||
.Fa buflen .
|
||||
.Pp
|
||||
The message strings can be accessed directly using the external
|
||||
array
|
||||
.Va sys_errlist .
|
||||
The external value
|
||||
.Va sys_nerr
|
||||
contains a count of the messages in
|
||||
.Va sys_errlist .
|
||||
The use of these variables is deprecated;
|
||||
.Fn strerror
|
||||
or
|
||||
.Fn strerror_r
|
||||
should be used instead.
|
||||
.Sh SEE ALSO
|
||||
.Xr intro 2 ,
|
||||
.Xr err 3 ,
|
||||
.Xr psignal 3 ,
|
||||
.Xr warn 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn perror
|
||||
and
|
||||
.Fn strerror
|
||||
functions conform to
|
||||
.St -isoC-99 .
|
||||
The
|
||||
.Fn strerror_r
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strerror
|
||||
and
|
||||
.Fn perror
|
||||
functions first appeared in
|
||||
.Bx 4.4 .
|
||||
The
|
||||
.Fn strerror_r
|
||||
function first appeared in
|
||||
.Nx 4.0 .
|
||||
.Sh BUGS
|
||||
For unknown error numbers, the
|
||||
.Fn strerror
|
||||
function will return its result in a static buffer which
|
||||
may be overwritten by subsequent calls.
|
||||
.Pp
|
||||
The return type for
|
||||
.Fn strerror
|
||||
is missing a type-qualifier; it should actually be
|
||||
.Vt const char * .
|
||||
.Pp
|
||||
Programs that use the deprecated
|
||||
.Va sys_errlist
|
||||
variable often fail to compile because they declare it
|
||||
inconsistently.
|
||||
60
lib/libc/string/strerror.c
Normal file
60
lib/libc/string/strerror.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: strerror.c,v 1.14 2006/01/26 11:13:42 kleink Exp $ */
|
||||
|
||||
/*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char *sccsid = "@(#)strerror.c 5.6 (Berkeley) 5/4/91";
|
||||
#else
|
||||
__RCSID("$NetBSD: strerror.c,v 1.14 2006/01/26 11:13:42 kleink Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
#include "extern.h"
|
||||
|
||||
/*
|
||||
* Since perror() is not allowed to change the contents of strerror()'s
|
||||
* static buffer, both functions supply their own buffers to strerror_r()
|
||||
*/
|
||||
|
||||
__aconst char *
|
||||
strerror(int num)
|
||||
{
|
||||
static char buf[NL_TEXTMAX];
|
||||
int error = strerror_r(num, buf, sizeof(buf));
|
||||
if (error)
|
||||
errno = error;
|
||||
return buf;
|
||||
}
|
||||
103
lib/libc/string/strerror_r.c
Normal file
103
lib/libc/string/strerror_r.c
Normal file
@@ -0,0 +1,103 @@
|
||||
/* $NetBSD: strerror_r.c,v 1.2 2005/07/30 15:21:21 christos Exp $ */
|
||||
|
||||
/*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char *sccsid = "@(#)strerror.c 5.6 (Berkeley) 5/4/91";
|
||||
#else
|
||||
__RCSID("$NetBSD: strerror_r.c,v 1.2 2005/07/30 15:21:21 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#ifdef NLS
|
||||
#include <limits.h>
|
||||
#include <nl_types.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "extern.h"
|
||||
|
||||
#ifdef _LIBC
|
||||
# ifdef __weak_alias
|
||||
__weak_alias(strerror_r, _strerror_r)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
int
|
||||
#ifdef _LIBC
|
||||
_strerror_r(int num, char *buf, size_t buflen)
|
||||
#else
|
||||
strerror_r(int num, char *buf, size_t buflen)
|
||||
#endif
|
||||
{
|
||||
#define UPREFIX "Unknown error: %u"
|
||||
unsigned int errnum = num;
|
||||
int retval = 0;
|
||||
size_t slen;
|
||||
#ifdef NLS
|
||||
int saved_errno = errno;
|
||||
nl_catd catd;
|
||||
catd = catopen("libc", NL_CAT_LOCALE);
|
||||
#endif
|
||||
_DIAGASSERT(buf != NULL);
|
||||
|
||||
if (errnum < (unsigned int) sys_nerr) {
|
||||
#ifdef NLS
|
||||
slen = strlcpy(buf, catgets(catd, 1, (int)errnum,
|
||||
sys_errlist[errnum]), buflen);
|
||||
#else
|
||||
slen = strlcpy(buf, sys_errlist[errnum], buflen);
|
||||
#endif
|
||||
} else {
|
||||
#ifdef NLS
|
||||
slen = snprintf(buf, buflen,
|
||||
catgets(catd, 1, 0xffff, UPREFIX), errnum);
|
||||
#else
|
||||
slen = snprintf(buf, buflen, UPREFIX, errnum);
|
||||
#endif
|
||||
retval = EINVAL;
|
||||
}
|
||||
|
||||
if (slen >= buflen)
|
||||
retval = ERANGE;
|
||||
|
||||
#ifdef NLS
|
||||
catclose(catd);
|
||||
errno = saved_errno;
|
||||
#endif
|
||||
|
||||
return retval;
|
||||
}
|
||||
94
lib/libc/string/stresep.c
Normal file
94
lib/libc/string/stresep.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/* $NetBSD: stresep.c,v 1.2 2007/12/06 22:07:07 seb Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: stresep.c,v 1.2 2007/12/06 22:07:07 seb Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(stresep,_stresep)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Get next token from string *stringp, where tokens are possibly-empty
|
||||
* strings separated by characters from delim. If esc is not NUL, then
|
||||
* the characters followed by esc are ignored and are not taken into account
|
||||
* when splitting the string.
|
||||
*
|
||||
* Writes NULs into the string at *stringp to end tokens.
|
||||
* delim need not remain constant from call to call.
|
||||
* On return, *stringp points past the last NUL written (if there might
|
||||
* be further tokens), or is NULL (if there are definitely no more tokens).
|
||||
*
|
||||
* If *stringp is NULL, stresep returns NULL.
|
||||
*/
|
||||
char *
|
||||
stresep(char **stringp, const char *delim, int esc)
|
||||
{
|
||||
char *s;
|
||||
const char *spanp;
|
||||
int c, sc;
|
||||
char *tok;
|
||||
|
||||
_DIAGASSERT(stringp != NULL);
|
||||
_DIAGASSERT(delim != NULL);
|
||||
|
||||
if ((s = *stringp) == NULL)
|
||||
return NULL;
|
||||
for (tok = s;;) {
|
||||
c = *s++;
|
||||
while (esc != '\0' && c == esc) {
|
||||
(void)strcpy(s - 1, s);
|
||||
c = *s++;
|
||||
}
|
||||
spanp = delim;
|
||||
do {
|
||||
if ((sc = *spanp++) == c) {
|
||||
if (c == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
*stringp = s;
|
||||
return tok;
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
}
|
||||
200
lib/libc/string/string.3
Normal file
200
lib/libc/string/string.3
Normal file
@@ -0,0 +1,200 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)string.3 8.2 (Berkeley) 12/11/93
|
||||
.\" $NetBSD: string.3,v 1.16 2009/05/01 17:27:01 perry Exp $
|
||||
.\"
|
||||
.Dd May 1, 2009
|
||||
.Dt STRING 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm stpcpy ,
|
||||
.Nm stpncpy ,
|
||||
.Nm strcat ,
|
||||
.Nm strlcat ,
|
||||
.Nm strncat ,
|
||||
.Nm strchr ,
|
||||
.Nm strrchr ,
|
||||
.Nm strcmp ,
|
||||
.Nm strncmp ,
|
||||
.Nm strcasecmp ,
|
||||
.Nm strncasecmp ,
|
||||
.Nm strcoll ,
|
||||
.Nm strcpy ,
|
||||
.Nm strlcpy ,
|
||||
.Nm strncpy ,
|
||||
.Nm strerror ,
|
||||
.Nm strerror_r ,
|
||||
.Nm strlen ,
|
||||
.Nm strnlen ,
|
||||
.Nm strpbrk ,
|
||||
.Nm strsep ,
|
||||
.Nm stresep ,
|
||||
.Nm strspn ,
|
||||
.Nm strcspn ,
|
||||
.Nm strdup ,
|
||||
.Nm strndup ,
|
||||
.Nm strstr ,
|
||||
.Nm strcasestr ,
|
||||
.Nm strtok ,
|
||||
.Nm strtok_r ,
|
||||
.Nm strxfrm
|
||||
.Nd string specific functions
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn stpcpy "char *dst" "const char *src"
|
||||
.Ft char *
|
||||
.Fn stpncpy "char *dst" "const char *src" "size_t count"
|
||||
.Ft char *
|
||||
.Fn strcat "char *s" "const char * append"
|
||||
.Ft size_t
|
||||
.Fn strlcat "char *dst" "const char *src" "size_t size"
|
||||
.Ft char *
|
||||
.Fn strncat "char *s" "const char *append" "size_t count"
|
||||
.Ft char *
|
||||
.Fn strchr "const char *s" "int c"
|
||||
.Ft char *
|
||||
.Fn strrchr "const char *s" "int c"
|
||||
.Ft int
|
||||
.Fn strcmp "const char *s1" "const char *s2"
|
||||
.Ft int
|
||||
.Fn strncmp "const char *s1" "const char *s2" "size_t count"
|
||||
.Ft int
|
||||
.Fn strcasecmp "const char *s1" "const char *s2"
|
||||
.Ft int
|
||||
.Fn strncasecmp "const char *s1" "const char *s2" "size_t count"
|
||||
.Ft int
|
||||
.Fn strcoll "const char *s1" "const char *s2"
|
||||
.Ft char *
|
||||
.Fn strcpy "char *dst" "const char *src"
|
||||
.Ft size_t
|
||||
.Fn strlcpy "char *dst" "const char *src" "size_t size"
|
||||
.Ft char *
|
||||
.Fn strncpy "char *dst" "const char *src" "size_t count"
|
||||
.Ft char *
|
||||
.Fn strerror "int errno"
|
||||
.Ft int
|
||||
.Fn strerror_r "int errnum" "char *strerrbuf" "size_t buflen"
|
||||
.Ft size_t
|
||||
.Fn strlen "const char *s"
|
||||
.Ft size_t
|
||||
.Fn strnlen "const char *s" "size_t count"
|
||||
.Ft char *
|
||||
.Fn strpbrk "const char *s" "const char *charset"
|
||||
.Ft char *
|
||||
.Fn strsep "char **stringp" "const char *delim"
|
||||
.Ft char *
|
||||
.Fn stresep "char **stringp" "const char *delim" "int escape"
|
||||
.Ft size_t
|
||||
.Fn strspn "const char *s" "const char *charset"
|
||||
.Ft size_t
|
||||
.Fn strcspn "const char *s" "const char *charset"
|
||||
.Ft char *
|
||||
.Fn strdup "const char *str"
|
||||
.Ft char *
|
||||
.Fn strndup "const char *str" "size_t len"
|
||||
.Ft char *
|
||||
.Fn strstr "const char *big" "const char *little"
|
||||
.Ft char *
|
||||
.Fn strcasestr "const char *big" "const char *little"
|
||||
.Ft char *
|
||||
.Fn strtok "char *s" "const char *delim"
|
||||
.Ft char *
|
||||
.Fn strtok_r "char *s" "const char *delim" "char **lasts"
|
||||
.Ft size_t
|
||||
.Fn strxfrm "char *dst" "const char *src" "size_t n"
|
||||
.Sh DESCRIPTION
|
||||
The string
|
||||
functions manipulate strings terminated by a
|
||||
nul byte.
|
||||
.Pp
|
||||
See the specific manual pages for more information.
|
||||
For manipulating variable length generic objects as byte
|
||||
strings (without the nul byte check), see
|
||||
.Xr bstring 3 .
|
||||
.Pp
|
||||
Except as noted in their specific manual pages,
|
||||
the string functions do not test the destination
|
||||
for size limitations.
|
||||
.Sh SEE ALSO
|
||||
.Xr bstring 3 ,
|
||||
.Xr strcat 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strcoll 3 ,
|
||||
.Xr strcpy 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strdup 3 ,
|
||||
.Xr strerror 3 ,
|
||||
.Xr strings 3 ,
|
||||
.Xr strlcat 3 ,
|
||||
.Xr strlen 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3 ,
|
||||
.Xr strxfrm 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strcat ,
|
||||
.Fn strncat ,
|
||||
.Fn strchr ,
|
||||
.Fn strrchr ,
|
||||
.Fn strcmp ,
|
||||
.Fn strncmp ,
|
||||
.Fn strcpy ,
|
||||
.Fn strncpy ,
|
||||
.Fn strcoll ,
|
||||
.Fn strerror ,
|
||||
.Fn strlen ,
|
||||
.Fn strpbrk ,
|
||||
.Fn strsep ,
|
||||
.Fn strspn ,
|
||||
.Fn strcspn ,
|
||||
.Fn strstr ,
|
||||
.Fn strtok ,
|
||||
and
|
||||
.Fn strxfrm
|
||||
functions conform to
|
||||
.St -ansiC .
|
||||
.Pp
|
||||
The
|
||||
.Fn strtok_r
|
||||
function conforms to
|
||||
.St -p1003.1c-95 .
|
||||
.Pp
|
||||
The
|
||||
.Fn strerror_r
|
||||
function conform to
|
||||
.St -p1003.1-2001 .
|
||||
98
lib/libc/string/strings.3
Normal file
98
lib/libc/string/strings.3
Normal file
@@ -0,0 +1,98 @@
|
||||
.\" $NetBSD: strings.3,v 1.1 2007/02/17 09:32:58 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2007 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Thomas Klausner.
|
||||
.\"
|
||||
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
.\"
|
||||
.Dd February 17, 2007
|
||||
.Dt STRINGS 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm bcmp ,
|
||||
.Nm bcopy ,
|
||||
.Nm bzero ,
|
||||
.Nm ffs ,
|
||||
.Nm index ,
|
||||
.Nm rindex ,
|
||||
.Nm strcasecmp ,
|
||||
.Nm strncasecmp
|
||||
.Nd string operations
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In strings.h
|
||||
.Ft int
|
||||
.Fn bcmp "const void *b1" "const void *b2" "size_t len"
|
||||
.Ft void
|
||||
.Fn bcopy "const void *src" "void *dst" "size_t len"
|
||||
.Ft void
|
||||
.Fn bzero "void *b" "size_t len"
|
||||
.Ft int
|
||||
.Fn ffs "int value"
|
||||
.Ft char *
|
||||
.Fn index "const char *s" "int c"
|
||||
.Ft char *
|
||||
.Fn rindex "const char *s" "int c"
|
||||
.Ft int
|
||||
.Fn strcasecmp "const char *s1" "const char *s2"
|
||||
.Ft int
|
||||
.Fn strncasecmp "const char *s1" "const char *s2" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
These functions all live in the
|
||||
.Pa strings.h
|
||||
header file.
|
||||
Except for
|
||||
.Fn ffs ,
|
||||
they operate on strings.
|
||||
.Fn index ,
|
||||
.Fn rindex ,
|
||||
and
|
||||
.Fn strcasecmp
|
||||
need nul-terminated strings.
|
||||
.Pp
|
||||
See the specific manual pages for more information.
|
||||
.Pp
|
||||
See
|
||||
.Xr string 3
|
||||
for string functions that follow
|
||||
.St -ansiC
|
||||
or
|
||||
.St -isoC-99 ,
|
||||
.Xr bstring 3
|
||||
for functions that operate on strings that are not nul-terminated, and
|
||||
.Xr bitstring 3
|
||||
for bit-string manipulation macros.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcmp 3 ,
|
||||
.Xr bcopy 3 ,
|
||||
.Xr bitstring 3 ,
|
||||
.Xr bstring 3 ,
|
||||
.Xr bzero 3 ,
|
||||
.Xr ffs 3 ,
|
||||
.Xr index 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strcasecmp 3 ,
|
||||
.Xr string 3
|
||||
212
lib/libc/string/strlcpy.3
Normal file
212
lib/libc/string/strlcpy.3
Normal file
@@ -0,0 +1,212 @@
|
||||
.\" $NetBSD: strlcpy.3,v 1.13 2010/04/14 13:07:51 wiz Exp $
|
||||
.\" from OpenBSD: strlcpy.3,v 1.11 2000/11/16 23:27:41 angelos Exp
|
||||
.\"
|
||||
.\" Copyright (c) 1998, 2000 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.
|
||||
.\"
|
||||
.Dd March 1, 2001
|
||||
.Dt STRLCPY 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strlcpy ,
|
||||
.Nm strlcat
|
||||
.Nd size-bounded string copying and concatenation
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft size_t
|
||||
.Fn strlcpy "char *dst" "const char *src" "size_t size"
|
||||
.Ft size_t
|
||||
.Fn strlcat "char *dst" "const char *src" "size_t size"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strlcpy
|
||||
and
|
||||
.Fn strlcat
|
||||
functions copy and concatenate strings respectively.
|
||||
They are designed
|
||||
to be safer, more consistent, and less error prone replacements for
|
||||
.Xr strncpy 3
|
||||
and
|
||||
.Xr strncat 3 .
|
||||
Unlike those functions,
|
||||
.Fn strlcpy
|
||||
and
|
||||
.Fn strlcat
|
||||
take the full size of the buffer (not just the length) and guarantee to
|
||||
NUL-terminate the result (as long as
|
||||
.Fa size
|
||||
is larger than 0 or, in the case of
|
||||
.Fn strlcat ,
|
||||
as long as there is at least one byte free in
|
||||
.Fa dst ) .
|
||||
Note that you should include a byte for the NUL in
|
||||
.Fa size .
|
||||
Also note that
|
||||
.Fn strlcpy
|
||||
and
|
||||
.Fn strlcat
|
||||
only operate on true
|
||||
.Dq C
|
||||
strings.
|
||||
This means that for
|
||||
.Fn strlcpy
|
||||
.Fa src
|
||||
must be NUL-terminated and for
|
||||
.Fn strlcat
|
||||
both
|
||||
.Fa src
|
||||
and
|
||||
.Fa dst
|
||||
must be NUL-terminated.
|
||||
.Pp
|
||||
The
|
||||
.Fn strlcpy
|
||||
function copies up to
|
||||
.Fa size
|
||||
- 1 characters from the NUL-terminated string
|
||||
.Fa src
|
||||
to
|
||||
.Fa dst ,
|
||||
NUL-terminating the result.
|
||||
.Pp
|
||||
The
|
||||
.Fn strlcat
|
||||
function appends the NUL-terminated string
|
||||
.Fa src
|
||||
to the end of
|
||||
.Fa dst .
|
||||
It will append at most
|
||||
.Fa size
|
||||
- strlen(dst) - 1 bytes, NUL-terminating the result.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strlcpy
|
||||
and
|
||||
.Fn strlcat
|
||||
functions return the total length of the string they tried to create.
|
||||
For
|
||||
.Fn strlcpy
|
||||
that means the length of
|
||||
.Fa src .
|
||||
For
|
||||
.Fn strlcat
|
||||
that means the initial length of
|
||||
.Fa dst
|
||||
plus
|
||||
the length of
|
||||
.Fa src .
|
||||
While this may seem somewhat confusing it was done to make
|
||||
truncation detection simple.
|
||||
.Pp
|
||||
Note however, that if
|
||||
.Fn strlcat
|
||||
traverses
|
||||
.Fa size
|
||||
characters without finding a NUL, the length of the string is considered
|
||||
to be
|
||||
.Fa size
|
||||
and the destination string will not be NUL-terminated (since there was
|
||||
no space for the NUL).
|
||||
This keeps
|
||||
.Fn strlcat
|
||||
from running off the end of a string.
|
||||
In practice this should not happen (as it means that either
|
||||
.Fa size
|
||||
is incorrect or that
|
||||
.Fa dst
|
||||
is not a proper
|
||||
.Dq C
|
||||
string).
|
||||
The check exists to prevent potential security problems in incorrect code.
|
||||
.Sh EXAMPLES
|
||||
The following code fragment illustrates the simple case:
|
||||
.Bd -literal -offset indent
|
||||
char *s, *p, buf[BUFSIZ];
|
||||
|
||||
\&...
|
||||
|
||||
(void)strlcpy(buf, s, sizeof(buf));
|
||||
(void)strlcat(buf, p, sizeof(buf));
|
||||
.Ed
|
||||
.Pp
|
||||
To detect truncation, perhaps while building a pathname, something
|
||||
like the following might be used:
|
||||
.Bd -literal -offset indent
|
||||
char *dir, *file, pname[MAXPATHLEN];
|
||||
|
||||
\&...
|
||||
|
||||
if (strlcpy(pname, dir, sizeof(pname)) \*[Ge] sizeof(pname))
|
||||
goto toolong;
|
||||
if (strlcat(pname, file, sizeof(pname)) \*[Ge] sizeof(pname))
|
||||
goto toolong;
|
||||
.Ed
|
||||
.Pp
|
||||
Since we know how many characters we copied the first time, we can
|
||||
speed things up a bit by using a copy instead of an append:
|
||||
.Bd -literal -offset indent
|
||||
char *dir, *file, pname[MAXPATHLEN];
|
||||
size_t n;
|
||||
|
||||
\&...
|
||||
|
||||
n = strlcpy(pname, dir, sizeof(pname));
|
||||
if (n \*[Ge] sizeof(pname))
|
||||
goto toolong;
|
||||
if (strlcpy(pname + n, file, sizeof(pname) - n) \*[Ge] sizeof(pname) - n)
|
||||
goto toolong;
|
||||
.Ed
|
||||
.Pp
|
||||
However, one may question the validity of such optimizations, as they
|
||||
defeat the whole purpose of
|
||||
.Fn strlcpy
|
||||
and
|
||||
.Fn strlcat .
|
||||
.Sh SEE ALSO
|
||||
.Xr snprintf 3 ,
|
||||
.Xr strncat 3 ,
|
||||
.Xr strncpy 3
|
||||
.Rs
|
||||
.%A Todd C. Miller
|
||||
.%A Theo de Raadt
|
||||
.%T strlcpy and strlcat -- Consistent, Safe, String Copy and Concatenation
|
||||
.%I USENIX Association
|
||||
.%B Proceedings of the FREENIX Track: 1999 USENIX Annual Technical Conference
|
||||
.%D June 6-11, 1999
|
||||
.%U http://www.usenix.org/publications/library/proceedings/usenix99/full_papers/millert/millert.pdf
|
||||
.Re
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strlcpy
|
||||
and
|
||||
.Fn strlcat
|
||||
functions first appeared in
|
||||
.Ox 2.4 ,
|
||||
then in
|
||||
.Nx 1.4.3
|
||||
and
|
||||
.Fx 3.3 .
|
||||
95
lib/libc/string/strlen.3
Normal file
95
lib/libc/string/strlen.3
Normal file
@@ -0,0 +1,95 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strlen.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strlen.3,v 1.9 2009/05/01 17:27:01 perry Exp $
|
||||
.\"
|
||||
.Dd May 1, 2009
|
||||
.Dt STRLEN 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strlen ,
|
||||
.Nm strnlen
|
||||
.Nd find length of string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft size_t
|
||||
.Fn strlen "const char *s"
|
||||
.Ft size_t
|
||||
.Fn strnlen "const char *s" "size_t maxlen"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strlen
|
||||
function
|
||||
computes the length of the string
|
||||
.Fa s .
|
||||
.Pp
|
||||
The
|
||||
.Fn strnlen
|
||||
function attempts to compute the length of
|
||||
.Fa s ,
|
||||
but never scans beyond the first
|
||||
.Fa maxlen
|
||||
bytes of
|
||||
.Fa s .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strlen
|
||||
function
|
||||
returns
|
||||
the number of characters that precede the
|
||||
terminating
|
||||
.Dv NUL
|
||||
character.
|
||||
.Pp
|
||||
The
|
||||
.Fn strnlen
|
||||
function returns either the same result as
|
||||
.Fn strlen
|
||||
or
|
||||
.Fa maxlen ,
|
||||
whichever is smaller.
|
||||
.Sh SEE ALSO
|
||||
.Xr string 3 ,
|
||||
.Xr wcslen 3 ,
|
||||
.Xr wcswidth 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strlen
|
||||
function
|
||||
conforms to
|
||||
.St -isoC .
|
||||
The
|
||||
.Fn strnlen
|
||||
function conforms to
|
||||
.St -p1003.1-2008 .
|
||||
156
lib/libc/string/strmode.3
Normal file
156
lib/libc/string/strmode.3
Normal file
@@ -0,0 +1,156 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)strmode.3 8.3 (Berkeley) 7/28/94
|
||||
.\" $NetBSD: strmode.3,v 1.17 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd July 28, 1994
|
||||
.Dt STRMODE 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strmode
|
||||
.Nd convert inode status information into a symbolic string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In unistd.h
|
||||
.Ft void
|
||||
.Fn strmode "mode_t mode" "char *bp"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strmode
|
||||
function
|
||||
converts a file
|
||||
.Fa mode
|
||||
(the type and permission information associated with an inode, see
|
||||
.Xr stat 2 )
|
||||
into a symbolic string which is stored in the location referenced by
|
||||
.Fa bp .
|
||||
This stored string is eleven characters in length plus a trailing nul byte.
|
||||
.Pp
|
||||
The first character is the inode type, and will be one of the following:
|
||||
.Pp
|
||||
.Bl -tag -width flag -offset indent -compact
|
||||
.It \-
|
||||
regular file
|
||||
.It a
|
||||
regular file in archive state 1
|
||||
.It A
|
||||
regular file in archive state 2
|
||||
.It b
|
||||
block special
|
||||
.It c
|
||||
character special
|
||||
.It d
|
||||
directory
|
||||
.It l
|
||||
symbolic link
|
||||
.It p
|
||||
fifo
|
||||
.It s
|
||||
socket
|
||||
.It w
|
||||
whiteout
|
||||
.It ?
|
||||
unknown inode type
|
||||
.El
|
||||
.Pp
|
||||
The next nine characters encode three sets of permissions, in three
|
||||
characters each.
|
||||
The first three characters are the permissions for the owner of the
|
||||
file, the second three for the group the file belongs to, and the
|
||||
third for the ``other'', or default, set of users.
|
||||
.Pp
|
||||
Permission checking is done as specifically as possible.
|
||||
If read permission is denied to the owner of a file in the first set
|
||||
of permissions, the owner of the file will not be able to read the file.
|
||||
This is true even if the owner is in the file's group and the group
|
||||
permissions allow reading or the ``other'' permissions allow reading.
|
||||
.Pp
|
||||
If the first character of the three character set is an ``r'', the file is
|
||||
readable for that set of users; if a dash ``\-'', it is not readable.
|
||||
.Pp
|
||||
If the second character of the three character set is a ``w'', the file is
|
||||
writable for that set of users; if a dash ``\-'', it is not writable.
|
||||
.Pp
|
||||
The third character is the first of the following characters that apply:
|
||||
.Bl -tag -width xxxx
|
||||
.It S
|
||||
If the character is part of the owner permissions and the file is not
|
||||
executable or the directory is not searchable by the owner, and the
|
||||
set-user-id bit is set.
|
||||
.It S
|
||||
If the character is part of the group permissions and the file is not
|
||||
executable or the directory is not searchable by the group, and the
|
||||
set-group-id bit is set.
|
||||
.It T
|
||||
If the character is part of the other permissions and the file is not
|
||||
executable or the directory is not searchable by others, and the ``sticky''
|
||||
.Pq Dv S_ISVTX
|
||||
bit is set.
|
||||
.It s
|
||||
If the character is part of the owner permissions and the file is
|
||||
executable or the directory searchable by the owner, and the set-user-id
|
||||
bit is set.
|
||||
.It s
|
||||
If the character is part of the group permissions and the file is
|
||||
executable or the directory searchable by the group, and the set-group-id
|
||||
bit is set.
|
||||
.It t
|
||||
If the character is part of the other permissions and the file is
|
||||
executable or the directory searchable by others, and the ``sticky''
|
||||
.Pq Dv S_ISVTX
|
||||
bit is set.
|
||||
.It x
|
||||
The file is executable or the directory is searchable.
|
||||
.It \-
|
||||
None of the above apply.
|
||||
.El
|
||||
.Pp
|
||||
The last character is a plus sign ``+'' if there are any alternative
|
||||
or additional access control methods associated with the inode, otherwise
|
||||
it will be a space.
|
||||
.Pp
|
||||
Archive state 1 and archive state 2 represent file system dependent
|
||||
archive state for a file.
|
||||
Most file systems do not retain file archive
|
||||
state, and so will not report files in either archive state.
|
||||
msdosfs will report a file in archive state 1 if it has been
|
||||
archived more recently than modified.
|
||||
Hierarchical storage systems may have multiple archive states for a
|
||||
file and may define archive states 1 and 2 as appropriate.
|
||||
.Sh SEE ALSO
|
||||
.Xr chmod 1 ,
|
||||
.Xr find 1 ,
|
||||
.Xr stat 2 ,
|
||||
.Xr getmode 3 ,
|
||||
.Xr setmode 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strmode
|
||||
function first appeared in
|
||||
.Bx 4.4 .
|
||||
182
lib/libc/string/strmode.c
Normal file
182
lib/libc/string/strmode.c
Normal file
@@ -0,0 +1,182 @@
|
||||
/* $NetBSD: strmode.c,v 1.18 2006/10/07 22:04:18 apb Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1990, 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strmode.c 8.3 (Berkeley) 8/15/94";
|
||||
#else
|
||||
__RCSID("$NetBSD: strmode.c,v 1.18 2006/10/07 22:04:18 apb Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#if !HAVE_STRMODE
|
||||
void
|
||||
strmode(mode_t mode, char *p)
|
||||
{
|
||||
|
||||
_DIAGASSERT(p != NULL);
|
||||
|
||||
/* print type */
|
||||
switch (mode & S_IFMT) {
|
||||
case S_IFDIR: /* directory */
|
||||
*p++ = 'd';
|
||||
break;
|
||||
case S_IFCHR: /* character special */
|
||||
*p++ = 'c';
|
||||
break;
|
||||
case S_IFBLK: /* block special */
|
||||
*p++ = 'b';
|
||||
break;
|
||||
case S_IFREG: /* regular */
|
||||
#ifdef S_ARCH2
|
||||
if ((mode & S_ARCH2) != 0) {
|
||||
*p++ = 'A';
|
||||
} else if ((mode & S_ARCH1) != 0) {
|
||||
*p++ = 'a';
|
||||
} else {
|
||||
#endif
|
||||
*p++ = '-';
|
||||
#ifdef S_ARCH2
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case S_IFLNK: /* symbolic link */
|
||||
*p++ = 'l';
|
||||
break;
|
||||
#ifdef S_IFSOCK
|
||||
case S_IFSOCK: /* socket */
|
||||
*p++ = 's';
|
||||
break;
|
||||
#endif
|
||||
#ifdef S_IFIFO
|
||||
case S_IFIFO: /* fifo */
|
||||
*p++ = 'p';
|
||||
break;
|
||||
#endif
|
||||
#ifdef S_IFWHT
|
||||
case S_IFWHT: /* whiteout */
|
||||
*p++ = 'w';
|
||||
break;
|
||||
#endif
|
||||
#ifdef S_IFDOOR
|
||||
case S_IFDOOR: /* door */
|
||||
*p++ = 'D';
|
||||
break;
|
||||
#endif
|
||||
default: /* unknown */
|
||||
*p++ = '?';
|
||||
break;
|
||||
}
|
||||
/* usr */
|
||||
if (mode & S_IRUSR)
|
||||
*p++ = 'r';
|
||||
else
|
||||
*p++ = '-';
|
||||
if (mode & S_IWUSR)
|
||||
*p++ = 'w';
|
||||
else
|
||||
*p++ = '-';
|
||||
switch (mode & (S_IXUSR | S_ISUID)) {
|
||||
case 0:
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IXUSR:
|
||||
*p++ = 'x';
|
||||
break;
|
||||
case S_ISUID:
|
||||
*p++ = 'S';
|
||||
break;
|
||||
case S_IXUSR | S_ISUID:
|
||||
*p++ = 's';
|
||||
break;
|
||||
}
|
||||
/* group */
|
||||
if (mode & S_IRGRP)
|
||||
*p++ = 'r';
|
||||
else
|
||||
*p++ = '-';
|
||||
if (mode & S_IWGRP)
|
||||
*p++ = 'w';
|
||||
else
|
||||
*p++ = '-';
|
||||
switch (mode & (S_IXGRP | S_ISGID)) {
|
||||
case 0:
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IXGRP:
|
||||
*p++ = 'x';
|
||||
break;
|
||||
case S_ISGID:
|
||||
*p++ = 'S';
|
||||
break;
|
||||
case S_IXGRP | S_ISGID:
|
||||
*p++ = 's';
|
||||
break;
|
||||
}
|
||||
/* other */
|
||||
if (mode & S_IROTH)
|
||||
*p++ = 'r';
|
||||
else
|
||||
*p++ = '-';
|
||||
if (mode & S_IWOTH)
|
||||
*p++ = 'w';
|
||||
else
|
||||
*p++ = '-';
|
||||
switch (mode & (S_IXOTH | S_ISVTX)) {
|
||||
case 0:
|
||||
*p++ = '-';
|
||||
break;
|
||||
case S_IXOTH:
|
||||
*p++ = 'x';
|
||||
break;
|
||||
case S_ISVTX:
|
||||
*p++ = 'T';
|
||||
break;
|
||||
case S_IXOTH | S_ISVTX:
|
||||
*p++ = 't';
|
||||
break;
|
||||
}
|
||||
*p++ = ' '; /* will be a '+' if ACL's implemented */
|
||||
*p = '\0';
|
||||
}
|
||||
#endif /* !HAVE_STRMODE */
|
||||
79
lib/libc/string/strncat.c
Normal file
79
lib/libc/string/strncat.c
Normal file
@@ -0,0 +1,79 @@
|
||||
/* $NetBSD: strncat.c,v 1.11 2007/06/03 17:39:27 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strncat.c,v 1.11 2007/06/03 17:39:27 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _FORTIFY_SOURCE
|
||||
#undef strncat
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes
|
||||
* are written at dst (at most n+1 bytes being appended). Return dst.
|
||||
*/
|
||||
char *
|
||||
strncat(dst, src, n)
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t n;
|
||||
{
|
||||
|
||||
_DIAGASSERT(dst != NULL);
|
||||
_DIAGASSERT(src != NULL);
|
||||
|
||||
if (n != 0) {
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
|
||||
while (*d != 0)
|
||||
d++;
|
||||
do {
|
||||
if ((*d = *s++) == 0)
|
||||
break;
|
||||
d++;
|
||||
} while (--n != 0);
|
||||
*d = 0;
|
||||
}
|
||||
return (dst);
|
||||
}
|
||||
74
lib/libc/string/strndup.c
Normal file
74
lib/libc/string/strndup.c
Normal file
@@ -0,0 +1,74 @@
|
||||
/* $NetBSD: strndup.c,v 1.4 2007/07/03 12:11:09 nakayama Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 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.
|
||||
*/
|
||||
|
||||
#if HAVE_NBTOOL_CONFIG_H
|
||||
#include "nbtool_config.h"
|
||||
#endif
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strdup.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strndup.c,v 1.4 2007/07/03 12:11:09 nakayama Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(strndup,_strndup)
|
||||
#endif
|
||||
|
||||
#if !HAVE_STRNDUP
|
||||
char *
|
||||
strndup(const char *str, size_t n)
|
||||
{
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
_DIAGASSERT(str != NULL);
|
||||
|
||||
for (len = 0; len < n && str[len]; len++)
|
||||
continue;
|
||||
|
||||
if (!(copy = malloc(len + 1)))
|
||||
return (NULL);
|
||||
memcpy(copy, str, len);
|
||||
copy[len] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
#endif /* !HAVE_STRNDUP */
|
||||
47
lib/libc/string/strnlen.c
Normal file
47
lib/libc/string/strnlen.c
Normal file
@@ -0,0 +1,47 @@
|
||||
/* $NetBSD: strnlen.c,v 1.1 2009/05/01 17:27:01 perry Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2009 David Schultz <das@FreeBSD.org>
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: strnlen.c,v 1.1 2009/05/01 17:27:01 perry Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
/* FreeBSD: src/lib/libc/string/strnlen.c,v 1.1 2009/02/28 06:00:58 das Exp */
|
||||
|
||||
#include <string.h>
|
||||
|
||||
size_t
|
||||
strnlen(const char *s, size_t maxlen)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len = 0; len < maxlen; len++, s++) {
|
||||
if (!*s)
|
||||
break;
|
||||
}
|
||||
return (len);
|
||||
}
|
||||
79
lib/libc/string/strpbrk.3
Normal file
79
lib/libc/string/strpbrk.3
Normal file
@@ -0,0 +1,79 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strpbrk.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strpbrk.3,v 1.9 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd June 4, 1993
|
||||
.Dt STRPBRK 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strpbrk
|
||||
.Nd locate multiple characters in string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strpbrk "const char *s" "const char *charset"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strpbrk
|
||||
function
|
||||
locates in the nul-terminated string
|
||||
.Fa s
|
||||
the first occurrence of any character in the string
|
||||
.Fa charset
|
||||
and returns a pointer to this character.
|
||||
If no characters from
|
||||
.Fa charset
|
||||
occur anywhere in
|
||||
.Fa s
|
||||
.Fn strpbrk
|
||||
returns
|
||||
.Dv NULL .
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strpbrk
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
70
lib/libc/string/strpbrk.c
Normal file
70
lib/libc/string/strpbrk.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/* $NetBSD: strpbrk.c,v 1.19 2008/09/24 16:58:53 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Joerg Sonnenberger
|
||||
* 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(S) ``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(S) 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 <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strpbrk.c,v 1.19 2008/09/24 16:58:53 christos Exp $");
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#define FAST_STRPBRK 1
|
||||
#define UC(a) ((unsigned int)(unsigned char)(a))
|
||||
|
||||
#ifdef FAST_STRPBRK
|
||||
#define ADD_NEW_TO_SET(i) (set[inv[i] = idx++] = (i))
|
||||
#define IS_IN_SET(i) (inv[i] < idx && set[inv[i]] == (i))
|
||||
#define ADD_TO_SET(i) (void)(IS_IN_SET(i) || /*LINTED no effect*/ADD_NEW_TO_SET(i))
|
||||
#else
|
||||
#define IS_IN_SET(i) (set[(i) >> 3] & idx[(i) & 7])
|
||||
#define ADD_TO_SET(i) (void)(set[(i) >> 3] |= idx[(i) & 7])
|
||||
#endif
|
||||
|
||||
char *
|
||||
strpbrk(const char *s, const char *charset)
|
||||
{
|
||||
#ifdef FAST_STRPBRK
|
||||
uint8_t set[256], inv[256], idx = 0;
|
||||
#else
|
||||
static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
|
||||
uint8_t set[32];
|
||||
|
||||
(void)memset(set, 0, sizeof(set));
|
||||
#endif
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(charset != NULL);
|
||||
|
||||
for (; *charset != '\0'; ++charset)
|
||||
ADD_TO_SET(UC(*charset));
|
||||
|
||||
for (; *s != '\0'; ++s)
|
||||
if (IS_IN_SET(UC(*s)))
|
||||
return __UNCONST(s);
|
||||
return NULL;
|
||||
}
|
||||
100
lib/libc/string/strrchr.3
Normal file
100
lib/libc/string/strrchr.3
Normal file
@@ -0,0 +1,100 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strrchr.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strrchr.3,v 1.10 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd August 11, 2002
|
||||
.Dt STRRCHR 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strrchr
|
||||
.Nd locate character in string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strrchr "const char *s" "int c"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strrchr
|
||||
function
|
||||
locates the last occurrence of
|
||||
.Fa c
|
||||
(converted to a char)
|
||||
in the string
|
||||
.Fa s .
|
||||
If
|
||||
.Fa c
|
||||
is
|
||||
.Ql \e0 ,
|
||||
.Fn strrchr
|
||||
locates the terminating
|
||||
.Ql \e0 .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strrchr
|
||||
function
|
||||
returns a pointer to the character,
|
||||
or a null pointer if
|
||||
.Fa c
|
||||
does not occur anywhere in
|
||||
.Fa s .
|
||||
.Sh EXAMPLES
|
||||
After the following call to
|
||||
.Fn strrchr ,
|
||||
.Va p
|
||||
will point to the string
|
||||
.Qq obar :
|
||||
.Bd -literal -offset indent
|
||||
char *p;
|
||||
char *s = "foobar";
|
||||
|
||||
p = strrchr(s, 'o');
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strrchr
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
120
lib/libc/string/strsep.3
Normal file
120
lib/libc/string/strsep.3
Normal file
@@ -0,0 +1,120 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)strsep.3 8.1 (Berkeley) 6/9/93
|
||||
.\" $NetBSD: strsep.3,v 1.19 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd August 12, 2006
|
||||
.Dt STRSEP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strsep ,
|
||||
.Nm stresep
|
||||
.Nd separate strings
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strsep "char **stringp" "const char *delim"
|
||||
.Ft char *
|
||||
.Fn stresep "char **stringp" "const char *delim" "int escape"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strsep
|
||||
function locates, in the nul-terminated string referenced by
|
||||
.Fa *stringp ,
|
||||
the first occurrence of any character in the string
|
||||
.Fa delim
|
||||
(or the terminating
|
||||
.Ql \e0
|
||||
character) and replaces it with a
|
||||
.Ql \e0 .
|
||||
The location of the next character after the delimiter character
|
||||
(or
|
||||
.Dv NULL ,
|
||||
if the end of the string was reached) is stored in
|
||||
.Fa *stringp .
|
||||
The original value of
|
||||
.Fa *stringp
|
||||
is returned.
|
||||
.Pp
|
||||
An
|
||||
.Dq empty
|
||||
field, i.e., one caused by two adjacent delimiter characters,
|
||||
can be detected by comparing the location referenced by the pointer returned
|
||||
by
|
||||
.Fn strsep
|
||||
to
|
||||
.Ql \e0 .
|
||||
.Pp
|
||||
If
|
||||
.Fa *stringp
|
||||
is initially
|
||||
.Dv NULL ,
|
||||
.Fn strsep
|
||||
returns
|
||||
.Dv NULL .
|
||||
The
|
||||
.Fn stresep
|
||||
function also takes an escape character that allows quoting the delimiter
|
||||
character so that it can be part of the source string.
|
||||
.Sh EXAMPLES
|
||||
The following uses
|
||||
.Fn strsep
|
||||
to parse a string, containing tokens delimited by white space, into an
|
||||
argument vector:
|
||||
.Bd -literal -offset indent
|
||||
char **ap, *argv[10], *inputstring;
|
||||
|
||||
for (ap = argv; ap \*[Lt] \*[Am]argv[9] \*[Am]\*[Am]
|
||||
(*ap = strsep(\*[Am]inputstring, " \et")) != NULL;) {
|
||||
if (**ap != '\e0')
|
||||
ap++;
|
||||
}
|
||||
.Ed
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn strsep
|
||||
function
|
||||
is intended as a replacement for the
|
||||
.Fn strtok
|
||||
function.
|
||||
While the
|
||||
.Fn strtok
|
||||
function should be preferred for portability reasons (it conforms to
|
||||
.St -ansiC )
|
||||
it is unable to handle empty fields, i.e., detect fields delimited by
|
||||
two adjacent delimiter characters, or to be used for more than a single
|
||||
string at a time.
|
||||
The
|
||||
.Fn strsep
|
||||
function first appeared in
|
||||
.Bx 4.4 .
|
||||
64
lib/libc/string/strsignal.3
Normal file
64
lib/libc/string/strsignal.3
Normal file
@@ -0,0 +1,64 @@
|
||||
.\" Copyright (c) 1980, 1991 Regents of the University of California.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the American National Standards Committee X3, on Information
|
||||
.\" Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strerror.3 6.9 (Berkeley) 6/29/91
|
||||
.\" $NetBSD: strsignal.3,v 1.10 2009/07/22 19:48:27 kleink Exp $
|
||||
.\"
|
||||
.Dd July 22, 2009
|
||||
.Dt STRSIGNAL 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strsignal
|
||||
.Nd get signal description string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strsignal "int sig"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strsignal
|
||||
function returns a pointer to the language-dependent string describing
|
||||
a signal.
|
||||
.Pp
|
||||
The array pointed to is not to be modified by the program, but may be
|
||||
overwritten by subsequent calls to
|
||||
.Fn strsignal .
|
||||
.Sh SEE ALSO
|
||||
.Xr intro 2 ,
|
||||
.Xr psignal 3 ,
|
||||
.Xr setlocale 3
|
||||
.\" .Sh STANDARDS
|
||||
.\" The
|
||||
.\" .Fn strsignal
|
||||
.\" function conforms to
|
||||
.\" .St -p1003.1-2008 .
|
||||
57
lib/libc/string/strsignal.c
Normal file
57
lib/libc/string/strsignal.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/* $NetBSD: strsignal.c,v 1.14 2009/07/22 19:48:27 kleink Exp $ */
|
||||
|
||||
/*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char *sccsid = "@(#)strerror.c 5.6 (Berkeley) 5/4/91";
|
||||
#else
|
||||
__RCSID("$NetBSD: strsignal.c,v 1.14 2009/07/22 19:48:27 kleink Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "extern.h"
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(strsignal,_strsignal)
|
||||
#endif
|
||||
|
||||
__aconst char *
|
||||
strsignal(sig)
|
||||
int sig;
|
||||
{
|
||||
static char buf[NL_TEXTMAX];
|
||||
|
||||
return __UNCONST(__strsignal(sig, buf, NL_TEXTMAX));
|
||||
}
|
||||
92
lib/libc/string/strspn.3
Normal file
92
lib/libc/string/strspn.3
Normal file
@@ -0,0 +1,92 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strspn.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strspn.3,v 1.11 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd August 11, 2002
|
||||
.Dt STRSPN 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strspn
|
||||
.Nd span a string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft size_t
|
||||
.Fn strspn "const char *s" "const char *charset"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strspn
|
||||
function
|
||||
spans the initial part of the nul-terminated string
|
||||
.Fa s
|
||||
as long as the characters from
|
||||
.Fa s
|
||||
occur in string
|
||||
.Fa charset .
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn strspn
|
||||
function
|
||||
returns the number of characters spanned.
|
||||
.Sh EXAMPLES
|
||||
The following call to
|
||||
.Fn strspn
|
||||
will return 3, since the first three characters of string
|
||||
.Fa s
|
||||
are part of string
|
||||
.Fa charset :
|
||||
.Bd -literal -offset indent
|
||||
char *s = "foobar";
|
||||
char *charset = "of";
|
||||
size_t span;
|
||||
|
||||
span = strspn(s, charset);
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strstr 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strspn
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
151
lib/libc/string/strspn.c
Normal file
151
lib/libc/string/strspn.c
Normal file
@@ -0,0 +1,151 @@
|
||||
/* $NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 Joerg Sonnenberger
|
||||
* 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(S) ``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(S) 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 <sys/cdefs.h>
|
||||
__RCSID("$NetBSD: strspn.c,v 1.17 2009/07/30 21:42:06 dsl Exp $");
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#if ULONG_MAX != 0xffffffffffffffffull
|
||||
|
||||
size_t
|
||||
strspn(const char *s, const char *charset)
|
||||
{
|
||||
static const size_t idx[8] = { 1, 2, 4, 8, 16, 32, 64, 128 };
|
||||
uint8_t set[32];
|
||||
const char *t;
|
||||
#define UC(a) ((unsigned int)(unsigned char)(a))
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(charset != NULL);
|
||||
|
||||
if (charset[0] == '\0')
|
||||
return 0;
|
||||
if (charset[1] == '\0') {
|
||||
for (t = s; *t != '\0'; ++t) {
|
||||
if (*t != *charset)
|
||||
break;
|
||||
}
|
||||
return t - s;
|
||||
}
|
||||
|
||||
(void)memset(set, 0, sizeof(set));
|
||||
|
||||
for (; *charset != '\0'; ++charset)
|
||||
set[UC(*charset) >> 3] |= idx[UC(*charset) & 7];
|
||||
|
||||
for (t = s; *t != '\0'; ++t)
|
||||
if ((set[UC(*t) >> 3] & idx[UC(*t) & 7]) == 0)
|
||||
break;
|
||||
return t - s;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
/* 64 bit system, use four 64 bits registers for bitmask */
|
||||
|
||||
static size_t
|
||||
strspn_x(const char *s_s, const char *charset_s, unsigned long invert)
|
||||
{
|
||||
const unsigned char *s = (const unsigned char *)s_s;
|
||||
const unsigned char *charset = (const unsigned char *)charset_s;
|
||||
unsigned long m_0, m_4, m_8, m_c;
|
||||
unsigned char ch, next_ch;
|
||||
unsigned long bit;
|
||||
unsigned long check;
|
||||
size_t count;
|
||||
|
||||
/* Four 64bit registers have one bit for each character value */
|
||||
m_0 = 0;
|
||||
m_4 = 0;
|
||||
m_8 = 0;
|
||||
m_c = 0;
|
||||
|
||||
for (ch = *charset; ch != 0; ch = next_ch) {
|
||||
next_ch = *++charset;
|
||||
bit = 1ul << (ch & 0x3f);
|
||||
if (__predict_true(ch < 0x80)) {
|
||||
if (ch < 0x40)
|
||||
m_0 |= bit;
|
||||
else
|
||||
m_4 |= bit;
|
||||
} else {
|
||||
if (ch < 0xc0)
|
||||
m_8 |= bit;
|
||||
else
|
||||
m_c |= bit;
|
||||
}
|
||||
}
|
||||
|
||||
/* For strcspn() we just invert the validity set */
|
||||
m_0 ^= invert;
|
||||
m_4 ^= invert;
|
||||
m_8 ^= invert;
|
||||
m_c ^= invert;
|
||||
|
||||
/*
|
||||
* We could do remove the lsb from m_0 to terminate at the
|
||||
* end of the input string.
|
||||
* However prefetching the next char is benifitial and we must
|
||||
* not read the byte after the \0 - as it might fault!
|
||||
* So we take the 'hit' of the compare against 0.
|
||||
*/
|
||||
|
||||
ch = *s++;
|
||||
for (count = 0; ch != 0; ch = next_ch) {
|
||||
next_ch = s[count];
|
||||
if (__predict_true(ch < 0x80)) {
|
||||
check = m_0;
|
||||
if (ch >= 0x40)
|
||||
check = m_4;
|
||||
} else {
|
||||
check = m_8;
|
||||
if (ch >= 0xc0)
|
||||
check = m_c;
|
||||
}
|
||||
if (!((check >> (ch & 0x3f)) & 1))
|
||||
break;
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t
|
||||
strspn(const char *s, const char *charset)
|
||||
{
|
||||
return strspn_x(s, charset, 0);
|
||||
}
|
||||
|
||||
size_t
|
||||
strcspn(const char *s, const char *charset)
|
||||
{
|
||||
return strspn_x(s, charset, ~0ul);
|
||||
}
|
||||
#endif
|
||||
109
lib/libc/string/strstr.3
Normal file
109
lib/libc/string/strstr.3
Normal file
@@ -0,0 +1,109 @@
|
||||
.\" Copyright (c) 2001 Mike Barcroft <mike@FreeBSD.org>
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strstr.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strstr.3,v 1.10 2006/10/16 08:48:45 wiz Exp $
|
||||
.\"
|
||||
.Dd July 3, 2004
|
||||
.Dt STRSTR 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strstr , strcasestr
|
||||
.Nd locate a substring in a string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strstr "const char *big" "const char *little"
|
||||
.Ft char *
|
||||
.Fn strcasestr "const char *big" "const char *little"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strstr
|
||||
function
|
||||
locates the first occurrence of the nul-terminated string
|
||||
.Fa little
|
||||
in the nul-terminated string
|
||||
.Fa big .
|
||||
.Pp
|
||||
The
|
||||
.Fn strcasestr
|
||||
function is similar to
|
||||
.Fn strstr ,
|
||||
but ignores the case of both strings.
|
||||
.Sh RETURN VALUES
|
||||
If
|
||||
.Fa little
|
||||
is an empty string,
|
||||
.Fa big
|
||||
is returned;
|
||||
if
|
||||
.Fa little
|
||||
occurs nowhere in
|
||||
.Fa big ,
|
||||
.Dv NULL
|
||||
is returned;
|
||||
otherwise a pointer to the first character of the first occurrence of
|
||||
.Fa little
|
||||
is returned.
|
||||
.Sh EXAMPLES
|
||||
The following sets the pointer
|
||||
.Va ptr
|
||||
to the
|
||||
.Qq Li Bar Baz
|
||||
portion of
|
||||
.Va largestring :
|
||||
.Bd -literal -offset indent
|
||||
const char *largestring = "Foo Bar Baz";
|
||||
const char *smallstring = "Bar";
|
||||
char *ptr;
|
||||
|
||||
ptr = strstr(largestring, smallstring);
|
||||
.Ed
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strtok 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strstr
|
||||
function
|
||||
conforms to
|
||||
.St -isoC .
|
||||
162
lib/libc/string/strtok.3
Normal file
162
lib/libc/string/strtok.3
Normal file
@@ -0,0 +1,162 @@
|
||||
.\" Copyright (c) 1988, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" the American National Standards Committee X3, on Information
|
||||
.\" Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strtok.3 8.2 (Berkeley) 2/3/94
|
||||
.\" $NetBSD: strtok.3,v 1.23 2008/08/29 05:48:40 dholland Exp $
|
||||
.\"
|
||||
.Dd August 11, 2002
|
||||
.Dt STRTOK 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strtok, strtok_r
|
||||
.Nd string tokens
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft char *
|
||||
.Fn strtok "char * restrict str" "const char * restrict sep"
|
||||
.Ft char *
|
||||
.Fn strtok_r "char *str" "const char *sep" "char **lasts"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn strtok
|
||||
function
|
||||
is used to isolate sequential tokens in a nul-terminated string,
|
||||
.Fa str .
|
||||
These tokens are separated in the string by at least one of the
|
||||
characters in
|
||||
.Fa sep .
|
||||
The first time that
|
||||
.Fn strtok
|
||||
is called,
|
||||
.Fa str
|
||||
should be specified; subsequent calls, wishing to obtain further tokens
|
||||
from the same string, should pass a null pointer instead.
|
||||
The separator string,
|
||||
.Fa sep ,
|
||||
must be supplied each time, and may change between calls.
|
||||
.Pp
|
||||
The
|
||||
.Fn strtok
|
||||
function
|
||||
returns a pointer to the beginning of each subsequent token in the string,
|
||||
after replacing the separator character itself with a
|
||||
.Dv NUL
|
||||
character.
|
||||
Separator characters at the beginning of the string or at the
|
||||
continuation point are skipped so that zero length tokens
|
||||
are not returned.
|
||||
When no more tokens remain, a null pointer is returned.
|
||||
.Pp
|
||||
The
|
||||
.Fn strtok_r
|
||||
function implements the functionality of
|
||||
.Fn strtok
|
||||
but is passed an additional argument,
|
||||
.Fa lasts ,
|
||||
which points to a user-provided pointer which is used by
|
||||
.Fn strtok_r
|
||||
to store state which needs to be kept between calls to scan the same string;
|
||||
unlike
|
||||
.Fn strtok ,
|
||||
it is not necessary to limit tokenizing to a single string at a time
|
||||
when using
|
||||
.Fn strtok_r .
|
||||
.Sh EXAMPLES
|
||||
The following will construct an array of pointers to each individual word in
|
||||
the string
|
||||
.Va s :
|
||||
.Bd -literal -offset indent
|
||||
#define MAXTOKENS 128
|
||||
|
||||
char s[512], *p, *tokens[MAXTOKENS];
|
||||
char *last;
|
||||
int i = 0;
|
||||
|
||||
snprintf(s, sizeof(s), "cat dog horse cow");
|
||||
|
||||
for ((p = strtok_r(s, " ", &last)); p;
|
||||
(p = strtok_r(NULL, " ", &last)), i++) {
|
||||
if (i < MAXTOKENS - 1)
|
||||
tokens[i] = p;
|
||||
}
|
||||
tokens[i] = NULL;
|
||||
.Ed
|
||||
.Pp
|
||||
That is,
|
||||
.Li tokens[0]
|
||||
will point to
|
||||
.Qq cat ,
|
||||
.Li tokens[1]
|
||||
will point to
|
||||
.Qq dog ,
|
||||
.Li tokens[2]
|
||||
will point to
|
||||
.Qq horse ,
|
||||
and
|
||||
.Li tokens[3]
|
||||
will point to
|
||||
.Qq cow .
|
||||
.Sh SEE ALSO
|
||||
.Xr index 3 ,
|
||||
.Xr memchr 3 ,
|
||||
.Xr rindex 3 ,
|
||||
.Xr strchr 3 ,
|
||||
.Xr strcspn 3 ,
|
||||
.Xr strpbrk 3 ,
|
||||
.Xr strrchr 3 ,
|
||||
.Xr strsep 3 ,
|
||||
.Xr strspn 3 ,
|
||||
.Xr strstr 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strtok
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
The
|
||||
.Fn strtok_r
|
||||
function conforms to
|
||||
.St -p1003.1c-95 .
|
||||
.Sh BUGS
|
||||
The System V
|
||||
.Fn strtok ,
|
||||
if handed a string containing only delimiter characters,
|
||||
will not alter the next starting point, so that a call to
|
||||
.Fn strtok
|
||||
with a different (or empty) delimiter string
|
||||
may return a
|
||||
.Pf non- Dv NULL
|
||||
value.
|
||||
Since this implementation always alters the next starting point,
|
||||
such a sequence of calls would always return
|
||||
.Dv NULL .
|
||||
50
lib/libc/string/strtok.c
Normal file
50
lib/libc/string/strtok.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* $NetBSD: strtok.c,v 1.12 2004/10/27 19:12:31 dsl Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strtok.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strtok.c,v 1.12 2004/10/27 19:12:31 dsl Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <namespace.h>
|
||||
#include <string.h>
|
||||
|
||||
char *
|
||||
strtok(char *s, const char *delim)
|
||||
{
|
||||
static char *lasts;
|
||||
|
||||
return strtok_r(s, delim, &lasts);
|
||||
}
|
||||
102
lib/libc/string/strtok_r.c
Normal file
102
lib/libc/string/strtok_r.c
Normal file
@@ -0,0 +1,102 @@
|
||||
/* $NetBSD: strtok_r.c,v 1.9 2003/08/07 16:43:53 agc Exp $ */
|
||||
|
||||
/*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char *sccsid = "@(#)strtok.c 5.8 (Berkeley) 2/24/91";
|
||||
#else
|
||||
__RCSID("$NetBSD: strtok_r.c,v 1.9 2003/08/07 16:43:53 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __weak_alias
|
||||
__weak_alias(strtok_r,_strtok_r)
|
||||
#endif
|
||||
|
||||
char *
|
||||
strtok_r(s, delim, lasts)
|
||||
char *s;
|
||||
const char *delim;
|
||||
char **lasts;
|
||||
{
|
||||
const char *spanp;
|
||||
int c, sc;
|
||||
char *tok;
|
||||
|
||||
/* s may be NULL */
|
||||
_DIAGASSERT(delim != NULL);
|
||||
_DIAGASSERT(lasts != NULL);
|
||||
|
||||
if (s == NULL && (s = *lasts) == NULL)
|
||||
return (NULL);
|
||||
|
||||
/*
|
||||
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
|
||||
*/
|
||||
cont:
|
||||
c = *s++;
|
||||
for (spanp = delim; (sc = *spanp++) != 0;) {
|
||||
if (c == sc)
|
||||
goto cont;
|
||||
}
|
||||
|
||||
if (c == 0) { /* no non-delimiter characters */
|
||||
*lasts = NULL;
|
||||
return (NULL);
|
||||
}
|
||||
tok = s - 1;
|
||||
|
||||
/*
|
||||
* Scan token (scan for delimiters: s += strcspn(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 == 0)
|
||||
s = NULL;
|
||||
else
|
||||
s[-1] = 0;
|
||||
*lasts = s;
|
||||
return (tok);
|
||||
}
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
78
lib/libc/string/strxfrm.3
Normal file
78
lib/libc/string/strxfrm.3
Normal file
@@ -0,0 +1,78 @@
|
||||
.\" Copyright (c) 1990, 1991, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to Berkeley by
|
||||
.\" Chris Torek and the American National Standards Committee X3,
|
||||
.\" on Information Processing Systems.
|
||||
.\"
|
||||
.\" 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.
|
||||
.\"
|
||||
.\" from: @(#)strxfrm.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: strxfrm.3,v 1.11 2007/02/18 00:46:47 wiz Exp $
|
||||
.\"
|
||||
.Dd February 18, 2007
|
||||
.Dt STRXFRM 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm strxfrm
|
||||
.Nd transform a string under locale
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In string.h
|
||||
.Ft size_t
|
||||
.Fn strxfrm "char * restrict dst" "const char * restrict src" "size_t n"
|
||||
.Sh DESCRIPTION
|
||||
The idea of
|
||||
.Fn strxfrm
|
||||
is to
|
||||
.Dq un-localize
|
||||
a string: the function transforms
|
||||
.Ar src ,
|
||||
storing the result in
|
||||
.Ar dst ,
|
||||
such that
|
||||
.Xr strcmp 3
|
||||
on transformed strings returns what
|
||||
.Xr strcoll 3
|
||||
on the original untransformed strings would return.
|
||||
.Sh SEE ALSO
|
||||
.Xr bcmp 3 ,
|
||||
.Xr memcmp 3 ,
|
||||
.\" .Xr setlocale 3 ,
|
||||
.Xr strcasecmp 3 ,
|
||||
.Xr strcmp 3 ,
|
||||
.Xr strcoll 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn strxfrm
|
||||
function
|
||||
conforms to
|
||||
.St -ansiC .
|
||||
.Sh BUGS
|
||||
Since locales are not fully implemented on
|
||||
.Nx ,
|
||||
.Fn strxfrm
|
||||
just returns a copy of the original string.
|
||||
73
lib/libc/string/strxfrm.c
Normal file
73
lib/libc/string/strxfrm.c
Normal file
@@ -0,0 +1,73 @@
|
||||
/* $NetBSD: strxfrm.c,v 1.11 2003/08/07 16:43:53 agc Exp $ */
|
||||
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strxfrm.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: strxfrm.c,v 1.11 2003/08/07 16:43:53 agc Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Transform src, storing the result in dst, such that
|
||||
* strcmp() on transformed strings returns what strcoll()
|
||||
* on the original untransformed strings would return.
|
||||
*/
|
||||
size_t
|
||||
strxfrm(dst, src, n)
|
||||
char *dst;
|
||||
const char *src;
|
||||
size_t n;
|
||||
{
|
||||
size_t srclen, copysize;
|
||||
|
||||
_DIAGASSERT(src != NULL);
|
||||
|
||||
/*
|
||||
* Since locales are unimplemented, this is just a copy.
|
||||
*/
|
||||
srclen = strlen(src);
|
||||
if (n != 0) {
|
||||
_DIAGASSERT(dst != NULL);
|
||||
copysize = srclen < n ? srclen : n - 1;
|
||||
(void)memcpy(dst, src, copysize);
|
||||
dst[copysize] = 0;
|
||||
}
|
||||
return (srclen);
|
||||
}
|
||||
92
lib/libc/string/swab.3
Normal file
92
lib/libc/string/swab.3
Normal file
@@ -0,0 +1,92 @@
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)swab.3 8.1 (Berkeley) 6/4/93
|
||||
.\" $NetBSD: swab.3,v 1.15 2010/04/30 03:52:13 jruoho Exp $
|
||||
.\"
|
||||
.Dd April 30, 2010
|
||||
.Dt SWAB 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm swab
|
||||
.Nd swap adjacent bytes
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In unistd.h
|
||||
.Ft void
|
||||
.Fn swab "const void * restrict src" "void * restrict dst" "ssize_t len"
|
||||
.Sh DESCRIPTION
|
||||
The function
|
||||
.Fn swab
|
||||
copies
|
||||
.Fa len
|
||||
bytes from the location referenced by
|
||||
.Fa src
|
||||
to the location referenced by
|
||||
.Fa dst ,
|
||||
swapping adjacent bytes.
|
||||
.Pp
|
||||
If
|
||||
.Fa len
|
||||
is negative or zero,
|
||||
.Fn swab
|
||||
does nothing.
|
||||
If
|
||||
.Fa len
|
||||
is odd,
|
||||
.Fn swab
|
||||
copies
|
||||
.Fa len - 1
|
||||
bytes and the disposition of the last byte is unspecified.
|
||||
.Sh SEE ALSO
|
||||
.Xr bzero 3 ,
|
||||
.Xr memset 3
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn swab
|
||||
function conforms to
|
||||
.St -p1003.1-2001 .
|
||||
.Sh HISTORY
|
||||
A
|
||||
.Fn swab
|
||||
function appeared in
|
||||
.At v7 .
|
||||
It was originally documented to be
|
||||
.Dq useful for carrying binary data between PDP11's and other machines .
|
||||
.Pp
|
||||
In
|
||||
.Nx 6.0
|
||||
the type of
|
||||
.Fa len
|
||||
was changed from
|
||||
.Vt size_t
|
||||
to
|
||||
.Vt ssize_t
|
||||
for
|
||||
.Tn POSIX
|
||||
compliance.
|
||||
80
lib/libc/string/swab.c
Normal file
80
lib/libc/string/swab.c
Normal file
@@ -0,0 +1,80 @@
|
||||
/* $NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1988, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Jeffrey Mogul.
|
||||
*
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)swab.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: swab.c,v 1.18 2011/01/04 17:14:07 martin Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void
|
||||
swab(const void * __restrict from, void * __restrict to, ssize_t len)
|
||||
{
|
||||
char temp;
|
||||
const char *fp;
|
||||
char *tp;
|
||||
|
||||
if (len <= 1)
|
||||
return;
|
||||
|
||||
_DIAGASSERT(from != NULL);
|
||||
_DIAGASSERT(to != NULL);
|
||||
|
||||
len /= 2;
|
||||
fp = (const char *)from;
|
||||
tp = (char *)to;
|
||||
#define STEP temp = *fp++,*tp++ = *fp++,*tp++ = temp
|
||||
|
||||
if (__predict_false(len == 1)) {
|
||||
STEP;
|
||||
return;
|
||||
}
|
||||
|
||||
/* round to multiple of 8 */
|
||||
while ((--len % 8) != 0)
|
||||
STEP;
|
||||
len /= 8;
|
||||
if (len == 0)
|
||||
return;
|
||||
while (len-- != 0) {
|
||||
STEP; STEP; STEP; STEP;
|
||||
STEP; STEP; STEP; STEP;
|
||||
}
|
||||
}
|
||||
86
lib/libc/string/wcscasecmp.3
Normal file
86
lib/libc/string/wcscasecmp.3
Normal file
@@ -0,0 +1,86 @@
|
||||
.\" $NetBSD: wcscasecmp.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)wcscasecmp.3 8.1 (Berkeley) 6/9/93
|
||||
.\"
|
||||
.Dd August 26, 2006
|
||||
.Dt WCSCASECMP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm wcscasecmp ,
|
||||
.Nm wcsncasecmp
|
||||
.Nd compare wide-character strings, ignoring case
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In wchar.h
|
||||
.Ft int
|
||||
.Fn wcscasecmp "const wchar_t *s1" "const wchar_t *s2"
|
||||
.Ft int
|
||||
.Fn wcsncasecmp "const wchar_t *s1" "const wchar_t *s2" "size_t len"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn wcscasecmp
|
||||
and
|
||||
.Fn wcsncasecmp
|
||||
functions
|
||||
compare the nul-terminated strings
|
||||
.Fa s1
|
||||
and
|
||||
.Fa s2
|
||||
and return an integer greater than, equal to, or less than 0,
|
||||
according to whether
|
||||
.Fa s1
|
||||
is lexicographically greater than, equal to, or less than
|
||||
.Fa s2
|
||||
after translation of each corresponding character to lower-case.
|
||||
The strings themselves are not modified.
|
||||
.Pp
|
||||
The
|
||||
.Fn wcsncasecmp
|
||||
compares at most
|
||||
.Fa len
|
||||
characters.
|
||||
.Sh SEE ALSO
|
||||
.Xr wcscmp 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn wcscasecmp
|
||||
and
|
||||
.Fn wcsncasecmp
|
||||
functions first appeared in
|
||||
.Nx 4.0 .
|
||||
.Sh NOTES
|
||||
If
|
||||
.Fa len
|
||||
is zero,
|
||||
.Fn wcsncasecmp
|
||||
returns always 0.
|
||||
50
lib/libc/string/wcscasecmp.c
Normal file
50
lib/libc/string/wcscasecmp.c
Normal file
@@ -0,0 +1,50 @@
|
||||
/* $NetBSD: wcscasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Aleksey Cheusov
|
||||
*
|
||||
* This material is provided "as is", with absolutely no warranty expressed
|
||||
* or implied. Any use is at your own risk.
|
||||
*
|
||||
* Permission to use or copy this software for any purpose is hereby granted
|
||||
* without fee. Permission to modify the code and to distribute modified
|
||||
* code is also granted without any restrictions.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: wcscasecmp.c,v 1.2 2006/08/26 22:45:52 christos Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include "namespace.h"
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
#include <wctype.h>
|
||||
|
||||
__weak_alias(wcscasecmp,_wcscasecmp)
|
||||
|
||||
int
|
||||
wcscasecmp(const wchar_t *s1, const wchar_t *s2)
|
||||
{
|
||||
int lc1 = 0;
|
||||
int lc2 = 0;
|
||||
int diff = 0;
|
||||
|
||||
_DIAGASSERT(s1);
|
||||
_DIAGASSERT(s2);
|
||||
|
||||
for (;;) {
|
||||
lc1 = towlower(*s1);
|
||||
lc2 = towlower(*s2);
|
||||
|
||||
diff = lc1 - lc2;
|
||||
if (diff)
|
||||
return diff;
|
||||
|
||||
if (!lc1)
|
||||
return 0;
|
||||
|
||||
++s1;
|
||||
++s2;
|
||||
}
|
||||
}
|
||||
60
lib/libc/string/wcscat.c
Normal file
60
lib/libc/string/wcscat.c
Normal file
@@ -0,0 +1,60 @@
|
||||
/* $NetBSD: wcscat.c,v 1.2 2001/01/03 14:29:36 lukem 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: wcscat.c,v 1.2 2001/01/03 14:29:36 lukem Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcscat(s1, s2)
|
||||
wchar_t *s1;
|
||||
const wchar_t *s2;
|
||||
{
|
||||
wchar_t *p;
|
||||
wchar_t *q;
|
||||
const wchar_t *r;
|
||||
|
||||
_DIAGASSERT(s1 != NULL);
|
||||
_DIAGASSERT(s2 != NULL);
|
||||
|
||||
p = s1;
|
||||
while (*p)
|
||||
p++;
|
||||
q = p;
|
||||
r = s2;
|
||||
while (*r)
|
||||
*q++ = *r++;
|
||||
*q = '\0';
|
||||
return s1;
|
||||
}
|
||||
53
lib/libc/string/wcschr.c
Normal file
53
lib/libc/string/wcschr.c
Normal file
@@ -0,0 +1,53 @@
|
||||
/* $NetBSD: wcschr.c,v 1.4 2005/06/04 20:09:56 dsl 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: wcschr.c,v 1.4 2005/06/04 20:09:56 dsl Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcschr(const wchar_t *p, wchar_t c)
|
||||
{
|
||||
_DIAGASSERT(p != NULL);
|
||||
|
||||
for (;; ++p) {
|
||||
if (*p == c) {
|
||||
/* LINTED interface specification */
|
||||
return __UNCONST(p);
|
||||
}
|
||||
if (!*p)
|
||||
return NULL;
|
||||
}
|
||||
/*NOTREACHED*/
|
||||
}
|
||||
64
lib/libc/string/wcscmp.c
Normal file
64
lib/libc/string/wcscmp.c
Normal file
@@ -0,0 +1,64 @@
|
||||
/* $NetBSD: wcscmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $ */
|
||||
|
||||
/*-
|
||||
* 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
#if 0
|
||||
static char sccsid[] = "@(#)strcmp.c 8.1 (Berkeley) 6/4/93";
|
||||
#else
|
||||
__RCSID("$NetBSD: wcscmp.c,v 1.8 2009/01/11 02:46:30 christos Exp $");
|
||||
#endif
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
#include "runetype_local.h"
|
||||
|
||||
/*
|
||||
* Compare strings.
|
||||
*/
|
||||
int
|
||||
wcscmp(s1, s2)
|
||||
const wchar_t *s1, *s2;
|
||||
{
|
||||
|
||||
_DIAGASSERT(s1 != NULL);
|
||||
_DIAGASSERT(s2 != NULL);
|
||||
|
||||
while (*s1 == *s2++)
|
||||
if (*s1++ == 0)
|
||||
return (0);
|
||||
/* XXX assumes wchar_t = int */
|
||||
return (*(const __nbrune_t *)s1 - *(const __nbrune_t *)--s2);
|
||||
}
|
||||
52
lib/libc/string/wcscpy.c
Normal file
52
lib/libc/string/wcscpy.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* $NetBSD: wcscpy.c,v 1.3 2005/10/13 21:13:05 tnozaki 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: wcscpy.c,v 1.3 2005/10/13 21:13:05 tnozaki Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
|
||||
wchar_t *
|
||||
wcscpy(s1, s2)
|
||||
wchar_t *s1;
|
||||
const wchar_t *s2;
|
||||
{
|
||||
wchar_t *p;
|
||||
|
||||
_DIAGASSERT(s1 != NULL);
|
||||
_DIAGASSERT(s2 != NULL);
|
||||
|
||||
for (p = s1; (*p = *s2) != L'\0'; ++p, ++s2);
|
||||
|
||||
return s1;
|
||||
}
|
||||
63
lib/libc/string/wcscspn.c
Normal file
63
lib/libc/string/wcscspn.c
Normal file
@@ -0,0 +1,63 @@
|
||||
/* $NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem 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 <sys/cdefs.h>
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
__RCSID("$NetBSD: wcscspn.c,v 1.2 2001/01/03 14:29:36 lukem Exp $");
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
|
||||
#include <assert.h>
|
||||
#include <wchar.h>
|
||||
|
||||
size_t
|
||||
wcscspn(s, set)
|
||||
const wchar_t *s;
|
||||
const wchar_t *set;
|
||||
{
|
||||
const wchar_t *p;
|
||||
const wchar_t *q;
|
||||
|
||||
_DIAGASSERT(s != NULL);
|
||||
_DIAGASSERT(set != NULL);
|
||||
|
||||
p = s;
|
||||
while (*p) {
|
||||
q = set;
|
||||
while (*q) {
|
||||
if (*p == *q)
|
||||
goto done;
|
||||
q++;
|
||||
}
|
||||
p++;
|
||||
}
|
||||
|
||||
done:
|
||||
return (p - s);
|
||||
}
|
||||
87
lib/libc/string/wcsdup.3
Normal file
87
lib/libc/string/wcsdup.3
Normal file
@@ -0,0 +1,87 @@
|
||||
.\" $NetBSD: wcsdup.3,v 1.3 2010/12/16 17:42:28 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1990, 1991, 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.
|
||||
.\"
|
||||
.\" from: @(#)strdup.3 8.1 (Berkeley) 6/9/93
|
||||
.\"
|
||||
.Dd August 25, 2006
|
||||
.Dt WCSDUP 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm wcsdup
|
||||
.Nd save a copy of a string
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In wchar.h
|
||||
.Ft wchar_t *
|
||||
.Fn wcsdup "const wchar_t *str"
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Fn wcsdup
|
||||
function
|
||||
allocates sufficient memory for a copy
|
||||
of the wide-character string
|
||||
.Fa str ,
|
||||
does the copy, and returns a pointer to it.
|
||||
The pointer may subsequently be used as an
|
||||
argument to the function
|
||||
.Xr free 3 .
|
||||
.Pp
|
||||
If insufficient memory is available,
|
||||
.Dv NULL
|
||||
is returned.
|
||||
.Sh EXAMPLES
|
||||
The following will point
|
||||
.Va p
|
||||
to an allocated area of memory containing the nul-terminated string
|
||||
.Qq foobar :
|
||||
.Bd -literal -offset indent
|
||||
wchar_t *p;
|
||||
|
||||
if (p = wcsdup(L"foobar"), p == NULL) {
|
||||
fprintf(stderr, "Out of memory.\en");
|
||||
exit(1);
|
||||
}
|
||||
.Ed
|
||||
.Sh ERRORS
|
||||
The
|
||||
.Fn wcsdup
|
||||
function may fail and set the external variable
|
||||
.Va errno
|
||||
for any of the errors specified for the library function
|
||||
.Xr malloc 3 .
|
||||
.Sh SEE ALSO
|
||||
.Xr free 3 ,
|
||||
.Xr malloc 3 ,
|
||||
.Xr strdup 3
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Fn wcsdup
|
||||
function first appeared in
|
||||
.Nx 4.0 .
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user