summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2009-08-10 15:56:52 -0700
committerH. Peter Anvin <hpa@zytor.com>2009-08-10 15:59:34 -0700
commiteaa68f1c85126fa48601f3a40e9c930b01f8660e (patch)
tree4bdea44a5e06cc5b1f5de2fc59391b8972a7a2d8
parent767750b666f0e66b25fa9d1c7b905a935c637786 (diff)
downloadnasm-eaa68f1c85126fa48601f3a40e9c930b01f8660e.tar.gz
nasm-eaa68f1c85126fa48601f3a40e9c930b01f8660e.tar.bz2
nasm-eaa68f1c85126fa48601f3a40e9c930b01f8660e.zip
Add strlcpy() function
Add strlcpy() function and implementation, and use configure to detect if strlcpy() is natively available on the system. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
-rw-r--r--Makefile.in18
-rw-r--r--Mkfiles/msvc.mak17
-rw-r--r--Mkfiles/netware.mak18
-rw-r--r--Mkfiles/openwcom.mak17
-rw-r--r--Mkfiles/owlinux.mak17
-rw-r--r--compiler.h4
-rw-r--r--configure.in2
-rw-r--r--lib/strlcpy.c53
8 files changed, 104 insertions, 42 deletions
diff --git a/Makefile.in b/Makefile.in
index fc10a5c..80af30a 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -72,7 +72,8 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
- strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
+ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \
+ lib/strlcpy.$(O)
NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -280,6 +281,7 @@ insnsn.$(O): insnsn.c compiler.h config.h insnsi.h tables.h
labels.$(O): labels.c compiler.h config.h directives.h hashtbl.h insnsi.h \
nasm.h nasmlib.h pptok.h preproc.h regs.h
lib/snprintf.$(O): lib/snprintf.c compiler.h config.h nasmlib.h
+lib/strlcpy.$(O): lib/strlcpy.c compiler.h config.h
lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h config.h nasmlib.h
listing.$(O): listing.c compiler.h config.h directives.h insnsi.h listing.h \
nasm.h nasmlib.h pptok.h preproc.h regs.h
@@ -321,8 +323,6 @@ output/outelf64.$(O): output/outelf64.c compiler.h config.h directives.h \
eval.h insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h \
output/elfcommon.h output/outelf.h output/outform.h output/outlib.h pptok.h \
preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-output/outexe.$(O): output/outexe.c compiler.h config.h directives.h \
- insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
output/outform.$(O): output/outform.c compiler.h config.h directives.h \
insnsi.h nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
output/outieee.$(O): output/outieee.c compiler.h config.h directives.h \
@@ -344,14 +344,14 @@ output/outrdf.$(O): output/outrdf.c compiler.h config.h directives.h \
output/outrdf2.$(O): output/outrdf2.c compiler.h config.h directives.h \
insnsi.h nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h \
preproc.h rdoff/rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h config.h directives.h float.h insns.h \
- insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h \
- tables.h tokens.h
+parser.$(O): parser.c compiler.h config.h directives.h eval.h float.h \
+ insns.h insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h \
+ stdscan.h tables.h tokens.h
pptok.$(O): pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h \
preproc.h
-preproc.$(O): preproc.c compiler.h config.h directives.h hashtbl.h insnsi.h \
- nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h \
- tokens.h
+preproc.$(O): preproc.c compiler.h config.h directives.h eval.h hashtbl.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h \
+ tables.h tokens.h
quote.$(O): quote.c compiler.h config.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h config.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h config.h rbtree.h
diff --git a/Mkfiles/msvc.mak b/Mkfiles/msvc.mak
index d1c744a..6318b22 100644
--- a/Mkfiles/msvc.mak
+++ b/Mkfiles/msvc.mak
@@ -47,7 +47,8 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
- strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
+ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \
+ lib/strlcpy.$(O)
NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -209,6 +210,7 @@ insnsn.$(O): insnsn.c compiler.h insnsi.h tables.h
labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
+lib/strlcpy.$(O): lib/strlcpy.c compiler.h
lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
@@ -250,8 +252,6 @@ output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \
insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h \
output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
rbtree.h regs.h saa.h stdscan.h
-output/outexe.$(O): output/outexe.c compiler.h directives.h insnsi.h nasm.h \
- nasmlib.h output/outform.h pptok.h preproc.h regs.h
output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \
nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
output/outieee.$(O): output/outieee.c compiler.h directives.h insnsi.h \
@@ -272,12 +272,13 @@ output/outrdf.$(O): output/outrdf.c compiler.h directives.h insnsi.h nasm.h \
output/outrdf2.$(O): output/outrdf2.c compiler.h directives.h insnsi.h \
nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h \
rdoff/rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h directives.h float.h insns.h insnsi.h \
- nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h \
- tokens.h
+parser.$(O): parser.c compiler.h directives.h eval.h float.h insns.h \
+ insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h \
+ tables.h tokens.h
pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h directives.h eval.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h \
+ tokens.h
quote.$(O): quote.c compiler.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h rbtree.h
diff --git a/Mkfiles/netware.mak b/Mkfiles/netware.mak
index e809c33..8811f36 100644
--- a/Mkfiles/netware.mak
+++ b/Mkfiles/netware.mak
@@ -43,7 +43,8 @@ NASM = nasm.o nasmlib.o ver.o \
outdbg.o outieee.o outmacho32.o \
outmacho64.o preproc.o quote.o pptok.o \
macros.o listing.o eval.o exprlib.o stdscan.o \
- strfunc.o tokhash.o regvals.o regflags.o
+ strfunc.o tokhash.o regvals.o regflags.o \
+ strlcpy.o
NDISASM = ndisasm.o disasm.o sync.o nasmlib.o ver.o \
insnsd.o insnsb.o insnsn.o regs.o regdis.o
@@ -150,6 +151,7 @@ insnsn.o: insnsn.c compiler.h config.h insnsi.h tables.h
labels.o: labels.c compiler.h config.h directives.h hashtbl.h insnsi.h \
nasm.h nasmlib.h pptok.h preproc.h regs.h
snprintf.o: snprintf.c compiler.h config.h nasmlib.h
+strlcpy.o: strlcpy.c compiler.h config.h
vsnprintf.o: vsnprintf.c compiler.h config.h nasmlib.h
listing.o: listing.c compiler.h config.h directives.h insnsi.h listing.h \
nasm.h nasmlib.h pptok.h preproc.h regs.h
@@ -185,8 +187,6 @@ outelf32.o: outelf32.c compiler.h config.h directives.h eval.h insnsi.h \
outelf64.o: outelf64.c compiler.h config.h directives.h eval.h insnsi.h \
nasm.h nasmlib.h dwarf.h elf64.h elfcommon.h outelf.h outform.h outlib.h \
pptok.h preproc.h raa.h rbtree.h regs.h saa.h stdscan.h
-outexe.o: outexe.c compiler.h config.h directives.h insnsi.h nasm.h \
- nasmlib.h outform.h pptok.h preproc.h regs.h
outform.o: outform.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h outform.h pptok.h preproc.h regs.h
outieee.o: outieee.c compiler.h config.h directives.h insnsi.h nasm.h \
@@ -203,13 +203,13 @@ outrdf.o: outrdf.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h outform.h pptok.h preproc.h regs.h
outrdf2.o: outrdf2.c compiler.h config.h directives.h insnsi.h nasm.h \
nasmlib.h outform.h outlib.h pptok.h preproc.h rdoff.h regs.h saa.h
-parser.o: parser.c compiler.h config.h directives.h float.h insns.h insnsi.h \
- nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h \
- tokens.h
+parser.o: parser.c compiler.h config.h directives.h eval.h float.h insns.h \
+ insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h \
+ tables.h tokens.h
pptok.o: pptok.c compiler.h config.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.o: preproc.c compiler.h config.h directives.h hashtbl.h insnsi.h \
- nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h \
- tokens.h
+preproc.o: preproc.c compiler.h config.h directives.h eval.h hashtbl.h \
+ insnsi.h nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h \
+ tables.h tokens.h
quote.o: quote.c compiler.h config.h nasmlib.h quote.h
raa.o: raa.c compiler.h config.h nasmlib.h raa.h
rbtree.o: rbtree.c compiler.h config.h rbtree.h
diff --git a/Mkfiles/openwcom.mak b/Mkfiles/openwcom.mak
index 663e80c..2e63634 100644
--- a/Mkfiles/openwcom.mak
+++ b/Mkfiles/openwcom.mak
@@ -59,7 +59,8 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) &
output\outdbg.$(O) output\outieee.$(O) output\outmacho32.$(O) &
output\outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) &
macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) &
- strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
+ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) &
+ lib\strlcpy.$(O)
NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) &
insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -238,6 +239,7 @@ insnsn.$(O): insnsn.c compiler.h insnsi.h tables.h
labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
nasmlib.h pptok.h preproc.h regs.h
lib\snprintf.$(O): lib\snprintf.c compiler.h nasmlib.h
+lib\strlcpy.$(O): lib\strlcpy.c compiler.h
lib\vsnprintf.$(O): lib\vsnprintf.c compiler.h nasmlib.h
listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h &
nasmlib.h pptok.h preproc.h regs.h
@@ -279,8 +281,6 @@ output\outelf64.$(O): output\outelf64.c compiler.h directives.h eval.h &
insnsi.h nasm.h nasmlib.h output\dwarf.h output\elf64.h output\elfcommon.h &
output\outelf.h output\outform.h output\outlib.h pptok.h preproc.h raa.h &
rbtree.h regs.h saa.h stdscan.h
-output\outexe.$(O): output\outexe.c compiler.h directives.h insnsi.h nasm.h &
- nasmlib.h output\outform.h pptok.h preproc.h regs.h
output\outform.$(O): output\outform.c compiler.h directives.h insnsi.h &
nasm.h nasmlib.h output\outform.h pptok.h preproc.h regs.h
output\outieee.$(O): output\outieee.c compiler.h directives.h insnsi.h &
@@ -301,12 +301,13 @@ output\outrdf.$(O): output\outrdf.c compiler.h directives.h insnsi.h nasm.h &
output\outrdf2.$(O): output\outrdf2.c compiler.h directives.h insnsi.h &
nasm.h nasmlib.h output\outform.h output\outlib.h pptok.h preproc.h &
rdoff\rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h directives.h float.h insns.h insnsi.h &
- nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h &
- tokens.h
+parser.$(O): parser.c compiler.h directives.h eval.h float.h insns.h &
+ insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h &
+ tables.h tokens.h
pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h directives.h hashtbl.h insnsi.h nasm.h &
- nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h directives.h eval.h hashtbl.h insnsi.h &
+ nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h &
+ tokens.h
quote.$(O): quote.c compiler.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h rbtree.h
diff --git a/Mkfiles/owlinux.mak b/Mkfiles/owlinux.mak
index 0c6f96f..8b3a824 100644
--- a/Mkfiles/owlinux.mak
+++ b/Mkfiles/owlinux.mak
@@ -70,7 +70,8 @@ NASM = nasm.$(O) nasmlib.$(O) ver.$(O) \
output/outdbg.$(O) output/outieee.$(O) output/outmacho32.$(O) \
output/outmacho64.$(O) preproc.$(O) quote.$(O) pptok.$(O) \
macros.$(O) listing.$(O) eval.$(O) exprlib.$(O) stdscan.$(O) \
- strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O)
+ strfunc.$(O) tokhash.$(O) regvals.$(O) regflags.$(O) \
+ lib/strlcpy.$(O)
NDISASM = ndisasm.$(O) disasm.$(O) sync.$(O) nasmlib.$(O) ver.$(O) \
insnsd.$(O) insnsb.$(O) insnsn.$(O) regs.$(O) regdis.$(O)
@@ -248,6 +249,7 @@ insnsn.$(O): insnsn.c compiler.h insnsi.h tables.h
labels.$(O): labels.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
lib/snprintf.$(O): lib/snprintf.c compiler.h nasmlib.h
+lib/strlcpy.$(O): lib/strlcpy.c compiler.h
lib/vsnprintf.$(O): lib/vsnprintf.c compiler.h nasmlib.h
listing.$(O): listing.c compiler.h directives.h insnsi.h listing.h nasm.h \
nasmlib.h pptok.h preproc.h regs.h
@@ -289,8 +291,6 @@ output/outelf64.$(O): output/outelf64.c compiler.h directives.h eval.h \
insnsi.h nasm.h nasmlib.h output/dwarf.h output/elf64.h output/elfcommon.h \
output/outelf.h output/outform.h output/outlib.h pptok.h preproc.h raa.h \
rbtree.h regs.h saa.h stdscan.h
-output/outexe.$(O): output/outexe.c compiler.h directives.h insnsi.h nasm.h \
- nasmlib.h output/outform.h pptok.h preproc.h regs.h
output/outform.$(O): output/outform.c compiler.h directives.h insnsi.h \
nasm.h nasmlib.h output/outform.h pptok.h preproc.h regs.h
output/outieee.$(O): output/outieee.c compiler.h directives.h insnsi.h \
@@ -311,12 +311,13 @@ output/outrdf.$(O): output/outrdf.c compiler.h directives.h insnsi.h nasm.h \
output/outrdf2.$(O): output/outrdf2.c compiler.h directives.h insnsi.h \
nasm.h nasmlib.h output/outform.h output/outlib.h pptok.h preproc.h \
rdoff/rdoff.h regs.h saa.h
-parser.$(O): parser.c compiler.h directives.h float.h insns.h insnsi.h \
- nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h tables.h \
- tokens.h
+parser.$(O): parser.c compiler.h directives.h eval.h float.h insns.h \
+ insnsi.h nasm.h nasmlib.h parser.h pptok.h preproc.h regs.h stdscan.h \
+ tables.h tokens.h
pptok.$(O): pptok.c compiler.h hashtbl.h nasmlib.h pptok.h preproc.h
-preproc.$(O): preproc.c compiler.h directives.h hashtbl.h insnsi.h nasm.h \
- nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h tokens.h
+preproc.$(O): preproc.c compiler.h directives.h eval.h hashtbl.h insnsi.h \
+ nasm.h nasmlib.h pptok.h preproc.h quote.h regs.h stdscan.h tables.h \
+ tokens.h
quote.$(O): quote.c compiler.h nasmlib.h quote.h
raa.$(O): raa.c compiler.h nasmlib.h raa.h
rbtree.$(O): rbtree.c compiler.h rbtree.h
diff --git a/compiler.h b/compiler.h
index d96ebcb..5805f5a 100644
--- a/compiler.h
+++ b/compiler.h
@@ -100,6 +100,10 @@ int vsnprintf(char *, size_t, const char *, va_list);
# endif
#endif
+#if !defined(HAVE_STRLCPY) || !HAVE_DECL_STRLCPY
+size_t strlcpy(char *, const char *, size_t);
+#endif
+
#ifndef __cplusplus /* C++ has false, true, bool as keywords */
# if defined(HAVE_STDBOOL_H) && defined(HAVE_WORKING_BOOL)
# include <stdbool.h>
diff --git a/configure.in b/configure.in
index b47675b..c23bac1 100644
--- a/configure.in
+++ b/configure.in
@@ -130,6 +130,7 @@ fi
AC_CHECK_FUNCS(strcasecmp stricmp)
AC_CHECK_FUNCS(strncasecmp strnicmp)
AC_CHECK_FUNCS(strsep)
+AC_CHECK_FUNCS(strlcpy)
AC_CHECK_FUNCS(getuid)
AC_CHECK_FUNCS(getgid)
@@ -142,6 +143,7 @@ AC_CHECK_DECLS(stricmp)
AC_CHECK_DECLS(strncasecmp)
AC_CHECK_DECLS(strnicmp)
AC_CHECK_DECLS(strsep)
+AC_CHECK_DECLS(strlcpy)
if test $ac_cv_prog_make_vpathok = no; then
echo Copying generated srcs into build directory to compensate for VPATH breakage
diff --git a/lib/strlcpy.c b/lib/strlcpy.c
new file mode 100644
index 0000000..4335359
--- /dev/null
+++ b/lib/strlcpy.c
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+#include <string.h>
+#include "compiler.h"
+
+/*
+ * Copy src to string dst of size siz. At most siz-1 characters
+ * will be copied. Always NUL terminates (unless siz == 0).
+ * Returns strlen(src); if retval >= siz, truncation occurred.
+ */
+#ifndef HAVE_STRLCPY
+
+size_t strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
+
+#endif