From a1aff7e19432a444611f190e7917e452a9488d8c Mon Sep 17 00:00:00 2001 From: tg Date: Mon, 7 Jul 2008 12:59:54 +0000 Subject: [PATCH] =?UTF-8?q?libc=20strlfun.c:=20=E2=80=A2=20fix=20file=20de?= =?UTF-8?q?scription,=20history,=20etc.=20=E2=80=A2=20require=20?= =?UTF-8?q?=20for=20portable=20size=5Ft=20declaration=20(if=20!=20kernel,?= =?UTF-8?q?=20bootloader)=20=E2=80=A2=20mention=20why=20we=20do=20=5Fnot?= =?UTF-8?q?=5F=20include=20=20(for=20building=20on=20obsd/mbsd)?= =?UTF-8?q?=20=E2=80=A2=20sync=20RCSID=20definition=20with=20that=20of=20m?= =?UTF-8?q?ksh=20(more=20portable)=20=E2=80=A2=20fix=20strlcat=20descripti?= =?UTF-8?q?on=20=E2=80=A2=20sync=20strlcpy=20obsd=20rcsid=20and=20licence?= =?UTF-8?q?=20header=20with=20obsd-current=20=20=20(their=20code=20change?= =?UTF-8?q?=201.10=E2=86=921.11=20was=20something=20we=20already=20did)=20?= =?UTF-8?q?=E2=80=A2=20use=20=E2=80=9Cdoes=20not=E2=80=9D,=20not=20?= =?UTF-8?q?=E2=80=9Cdoesn=E2=80=99t=E2=80=9D=20=E2=80=A2=20make=20it=20eas?= =?UTF-8?q?ier=20to=20produce=20wcslfun.c?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit libc wcslfun.c: • sync with strlfun.c (much easier now) mksh strlcpy.c: • sync with strlfun.c (in comments, mostly) no binary changes --- strlcpy.c | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/strlcpy.c b/strlcpy.c index c873c52..56df5af 100644 --- a/strlcpy.c +++ b/strlcpy.c @@ -1,6 +1,6 @@ /*- - * Copyright (c) 2006, 2007 - * Thorsten Glaser + * Copyright (c) 2006, 2008 + * Thorsten Glaser * Copyright (c) 1998 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any @@ -19,8 +19,21 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.2 2007/04/23 11:33:26 tg Exp $"); -__RCSID("$miros: src/lib/libc/string/strlfun.c,v 1.14 2007/01/07 02:11:40 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.3 2008/07/07 12:59:54 tg Stab $"); +__RCSID("$miros: src/lib/libc/string/strlfun.c,v 1.16 2008/07/07 12:59:51 tg Stab $"); + +#ifndef __predict_true +#define __predict_true(exp) ((exp) != 0) +#endif +#ifndef __predict_false +#define __predict_false(exp) ((exp) != 0) +#endif + +/* (multibyte) string functions */ +#undef NUL +#undef char_t +#define NUL '\0' +#define char_t char /* * Copy src to string dst of size siz. At most siz-1 characters @@ -28,11 +41,11 @@ __RCSID("$miros: src/lib/libc/string/strlfun.c,v 1.14 2007/01/07 02:11:40 tg Exp * Returns strlen(src); if retval >= siz, truncation occurred. */ size_t -strlcpy(char *dst, const char *src, size_t siz) +strlcpy(char_t *dst, const char_t *src, size_t siz) { - const char *s = src; + const char_t *s = src; - if (siz == 0) + if (__predict_false(siz == 0)) goto traverse_src; /* copy as many chars as will fit */ @@ -40,15 +53,15 @@ strlcpy(char *dst, const char *src, size_t siz) ; /* not enough room in dst */ - if (siz == 0) { + if (__predict_false(siz == 0)) { /* safe to NUL-terminate dst since we copied <= siz-1 chars */ - *dst = '\0'; + *dst = NUL; traverse_src: /* traverse rest of src */ while (*s++) ; } - /* count doesn't include NUL */ + /* count does not include NUL */ return (s - src - 1); }