summaryrefslogtreecommitdiffstats
path: root/lib/libc/string
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/string')
-rw-r--r--lib/libc/string/memccpy.34
-rw-r--r--lib/libc/string/memchr.33
-rw-r--r--lib/libc/string/memcmp.34
-rw-r--r--lib/libc/string/memset.34
-rw-r--r--lib/libc/string/strcat.35
-rw-r--r--lib/libc/string/strcmp.32
-rw-r--r--lib/libc/string/strndup.c4
-rw-r--r--lib/libc/string/strsignal.c52
8 files changed, 64 insertions, 14 deletions
diff --git a/lib/libc/string/memccpy.3 b/lib/libc/string/memccpy.3
index 350f000..40a25be 100644
--- a/lib/libc/string/memccpy.3
+++ b/lib/libc/string/memccpy.3
@@ -50,7 +50,9 @@ to string
.Fa dst .
If the character
.Fa c
-(as converted to an unsigned char) occurs in the string
+(as converted to an
+.Vt "unsigned char" )
+occurs in the string
.Fa src ,
the copy stops and a pointer to the byte after the copy of
.Fa c
diff --git a/lib/libc/string/memchr.3 b/lib/libc/string/memchr.3
index ae883bf..6e33aef 100644
--- a/lib/libc/string/memchr.3
+++ b/lib/libc/string/memchr.3
@@ -52,7 +52,8 @@ The
function
locates the first occurrence of
.Fa c
-(converted to an unsigned char)
+(converted to an
+.Vt "unsigned char" )
in string
.Fa b .
.Pp
diff --git a/lib/libc/string/memcmp.3 b/lib/libc/string/memcmp.3
index 507b930..88ed9a2 100644
--- a/lib/libc/string/memcmp.3
+++ b/lib/libc/string/memcmp.3
@@ -61,7 +61,9 @@ The
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
+(treated as
+.Vt "unsigned char"
+values, so that
.Sq Li \e200
is greater than
.Sq Li \&\e0 ,
diff --git a/lib/libc/string/memset.3 b/lib/libc/string/memset.3
index 1dc287d..07bd7aa 100644
--- a/lib/libc/string/memset.3
+++ b/lib/libc/string/memset.3
@@ -52,7 +52,9 @@ writes
.Fa len
bytes of value
.Fa c
-(converted to an unsigned char) to the string
+(converted to an
+.Vt "unsigned char" )
+to the string
.Fa b .
.Sh RETURN VALUES
The
diff --git a/lib/libc/string/strcat.3 b/lib/libc/string/strcat.3
index 0290994..4c9fec9 100644
--- a/lib/libc/string/strcat.3
+++ b/lib/libc/string/strcat.3
@@ -32,11 +32,12 @@
.\" @(#)strcat.3 8.1 (Berkeley) 6/4/93
.\" $FreeBSD$
.\"
-.Dd June 4, 1993
+.Dd December 1, 2009
.Dt STRCAT 3
.Os
.Sh NAME
-.Nm strcat
+.Nm strcat ,
+.Nm strncat
.Nd concatenate strings
.Sh LIBRARY
.Lb libc
diff --git a/lib/libc/string/strcmp.3 b/lib/libc/string/strcmp.3
index 1e13ed8..74d1a5c 100644
--- a/lib/libc/string/strcmp.3
+++ b/lib/libc/string/strcmp.3
@@ -75,7 +75,7 @@ The
.Fn strcmp
and
.Fn strncmp
-return an integer greater than, equal to, or less than 0, according
+functions return an integer greater than, equal to, or less than 0, according
as the string
.Fa s1
is greater than, equal to, or less than the string
diff --git a/lib/libc/string/strndup.c b/lib/libc/string/strndup.c
index 56aa6a8..abb1e03 100644
--- a/lib/libc/string/strndup.c
+++ b/lib/libc/string/strndup.c
@@ -42,9 +42,7 @@ strndup(const char *str, size_t n)
size_t len;
char *copy;
- for (len = 0; len < n && str[len]; len++)
- continue;
-
+ len = strnlen(str, n);
if ((copy = malloc(len + 1)) == NULL)
return (NULL);
memcpy(copy, str, len);
diff --git a/lib/libc/string/strsignal.c b/lib/libc/string/strsignal.c
index e4267a3..c51f34d 100644
--- a/lib/libc/string/strsignal.c
+++ b/lib/libc/string/strsignal.c
@@ -33,22 +33,64 @@ static char sccsid[] = "@(#)strerror.c 8.1 (Berkeley) 6/4/93";
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include "namespace.h"
#if defined(NLS)
#include <nl_types.h>
#endif
-
#include <limits.h>
#include <errno.h>
+#include <stdlib.h>
#include <string.h>
#include <signal.h>
+#include "reentrant.h"
+#include "un-namespace.h"
#define UPREFIX "Unknown signal"
+static char sig_ebuf[NL_TEXTMAX];
+static char sig_ebuf_err[NL_TEXTMAX];
+static once_t sig_init_once = ONCE_INITIALIZER;
+static thread_key_t sig_key;
+static int sig_keycreated = 0;
+
+static void
+sig_keycreate(void)
+{
+ sig_keycreated = (thr_keycreate(&sig_key, free) == 0);
+}
+
+static char *
+sig_tlsalloc(void)
+{
+ char *ebuf = NULL;
+
+ if (thr_main() != 0)
+ ebuf = sig_ebuf;
+ else {
+ if (thr_once(&sig_init_once, sig_keycreate) != 0 ||
+ !sig_keycreated)
+ goto thr_err;
+ if ((ebuf = thr_getspecific(sig_key)) == NULL) {
+ if ((ebuf = malloc(sizeof(sig_ebuf))) == NULL)
+ goto thr_err;
+ if (thr_setspecific(sig_key, ebuf) != 0) {
+ free(ebuf);
+ ebuf = NULL;
+ goto thr_err;
+ }
+ }
+ }
+thr_err:
+ if (ebuf == NULL)
+ ebuf = sig_ebuf_err;
+ return (ebuf);
+}
+
/* XXX: negative 'num' ? (REGR) */
char *
strsignal(int num)
{
- static char ebuf[NL_TEXTMAX];
+ char *ebuf;
char tmp[20];
size_t n;
int signum;
@@ -60,6 +102,8 @@ strsignal(int num)
catd = catopen("libc", NL_CAT_LOCALE);
#endif
+ ebuf = sig_tlsalloc();
+
if (num > 0 && num < sys_nsig) {
n = strlcpy(ebuf,
#if defined(NLS)
@@ -67,7 +111,7 @@ strsignal(int num)
#else
sys_siglist[num],
#endif
- sizeof(ebuf));
+ sizeof(sig_ebuf));
} else {
n = strlcpy(ebuf,
#if defined(NLS)
@@ -75,7 +119,7 @@ strsignal(int num)
#else
UPREFIX,
#endif
- sizeof(ebuf));
+ sizeof(sig_ebuf));
}
signum = num;
OpenPOWER on IntegriCloud