diff --git a/ChangeLog b/ChangeLog index 3ca7b5ae4e..91fbba5f5f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Mon Mar 19 16:58:52 2007 NAKAMURA Usaku + + * missing/{strlcat,strlcpy}.c, missing.h: new functions. + + * LEGAL: add copyright notice about above files. + + * configure.in: check whether strlcat and strlcpy are exist or not. + + * {bcc32,win32,wince}/Makefile.sub: use above files. + Mon Mar 19 14:12:25 2007 Yukihiro Matsumoto * lib/matrix.rb (Matrix::inverse_from): adding partial pivoting to diff --git a/LEGAL b/LEGAL index 8dd957bd3e..0c168b6ce3 100644 --- a/LEGAL +++ b/LEGAL @@ -219,6 +219,36 @@ missing/vsnprintf.c: From ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change paragraph 3 above is now null and void. +missing/strlcat.c +missing/strlcpy.c + + These files are under the new-style BSD license. + + Copyright (c) 1998 Todd C. Miller + 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. + ext/digest/md5/md5.[ch]: These files are under the following license. Ruby uses modified diff --git a/bcc32/Makefile.sub b/bcc32/Makefile.sub index fe095ad03a..0545816b89 100644 --- a/bcc32/Makefile.sub +++ b/bcc32/Makefile.sub @@ -136,7 +136,7 @@ EXTLIBS = MEMLIB = !endif LIBS = $(MEMLIB) cw32i.lib import32.lib ws2_32.lib $(EXTLIBS) -MISSING = acosh.obj crypt.obj erf.obj win32.obj +MISSING = acosh.obj crypt.obj erf.obj strlcat.obj strlcpy.obj win32.obj !ifndef STACK STACK = 0x2000000 @@ -357,7 +357,7 @@ s,@ARFLAGS@,$(ARFLAGS) ,;t t s,@LN_S@,$(LN_S),;t t s,@SET_MAKE@,$(SET_MAKE),;t t s,@CP@,copy > nul,;t t -s,@LIBOBJS@, acosh.obj crypt.obj erf.obj win32.obj,;t t +s,@LIBOBJS@, acosh.obj crypt.obj erf.obj strlcat.obj strlcpy.obj win32.obj,;t t s,@ALLOCA@,$(ALLOCA),;t t s,@DEFAULT_KCODE@,$(DEFAULT_KCODE),;t t s,@EXEEXT@,.exe,;t t diff --git a/configure.in b/configure.in index 3843ea0d80..094e2437ef 100644 --- a/configure.in +++ b/configure.in @@ -561,8 +561,8 @@ powerpc-darwin*) esac AC_FUNC_MEMCMP AC_REPLACE_FUNCS(dup2 memmove strcasecmp strncasecmp strerror strftime\ - strchr strstr strtoul crypt flock\ - isnan finite isinf hypot acosh erf) + strchr strstr strtoul crypt flock vsnprintf\ + isnan finite isinf hypot acosh erf strlcpy strlcat) AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd eaccess\ truncate chsize times utimes fcntl lockf lstat link symlink readlink\ setitimer setruid seteuid setreuid setresuid setproctitle socketpair\ diff --git a/missing.h b/missing.h index db37e3ae4c..81fdfecf72 100644 --- a/missing.h +++ b/missing.h @@ -137,4 +137,12 @@ extern int snprintf(char *, size_t n, char const *, ...); extern int vsnprintf(char *, size_t n, char const *, va_list); #endif +#ifndef HAVE_STRLCPY +extern size_t strlcpy(char *, const char*, size_t); +#endif + +#ifndef HAVE_STRLCAT +extern size_t strlcat(char *, const char*, size_t); +#endif + #endif /* MISSING_H */ diff --git a/missing/strlcat.c b/missing/strlcat.c new file mode 100644 index 0000000000..b309648155 --- /dev/null +++ b/missing/strlcat.c @@ -0,0 +1,73 @@ +/* $OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Appends src to string dst of size siz (unlike strncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst)). + * If retval >= siz, truncation occurred. + */ +size_t +strlcat(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/missing/strlcpy.c b/missing/strlcpy.c new file mode 100644 index 0000000000..5f586964b7 --- /dev/null +++ b/missing/strlcpy.c @@ -0,0 +1,69 @@ +/* $OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $ */ + +/* + * Copyright (c) 1998 Todd C. Miller + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$OpenBSD: strlcpy.c,v 1.5 2001/05/13 15:40:16 deraadt Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns strlen(src); if retval >= siz, truncation occurred. + */ +size_t +strlcpy(dst, src, siz) + char *dst; + const char *src; + size_t siz; +{ + register char *d = dst; + register const char *s = src; + register size_t n = siz; + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/win32/Makefile.sub b/win32/Makefile.sub index 011918b29a..c7df04ba99 100644 --- a/win32/Makefile.sub +++ b/win32/Makefile.sub @@ -144,7 +144,7 @@ RFLAGS = -r EXTLIBS = !endif LIBS = oldnames.lib user32.lib advapi32.lib shell32.lib version.lib ws2_32.lib $(EXTLIBS) -MISSING = acosh.obj crypt.obj erf.obj win32.obj +MISSING = acosh.obj crypt.obj erf.obj strlcpy.obj strlcat.obj win32.obj ARFLAGS = -machine:$(MACHINE) -out: CC = $(CC) -nologo @@ -404,7 +404,7 @@ s,@ARFLAGS@,$(ARFLAGS),;t t s,@LN_S@,$(LN_S),;t t s,@SET_MAKE@,$(SET_MAKE),;t t s,@CP@,copy > nul,;t t -s,@LIBOBJS@, acosh.obj crypt.obj erf.obj win32.obj,;t t +s,@LIBOBJS@, acosh.obj crypt.obj erf.obj strlcpy.obj strlcat.obj win32.obj,;t t s,@ALLOCA@,$(ALLOCA),;t t s,@DEFAULT_KCODE@,$(DEFAULT_KCODE),;t t s,@EXEEXT@,.exe,;t t diff --git a/wince/Makefile.sub b/wince/Makefile.sub index f2df2c754e..3931be20e5 100644 --- a/wince/Makefile.sub +++ b/wince/Makefile.sub @@ -133,7 +133,7 @@ EXTLIBS = !endif LIBS = coredll.lib ceshell.lib winsock.lib $(EXTLIBS) MISSING = acosh.obj crypt.obj dup2.obj erf.obj hypot.obj \ - isinf.obj isnan.obj strftime.obj win32.obj \ + isinf.obj isnan.obj strftime.obj strlcat.obj strlcpy.obj win32.obj \ assert.obj direct.obj errno.obj io_wce.obj process_wce.obj \ signal_wce.obj stdio.obj stdlib.obj string_wce.obj \ time_wce.obj wince.obj winsock2.obj \ @@ -371,7 +371,7 @@ s,@ARFLAGS@,$(ARFLAGS),;t t s,@LN_S@,$(LN_S),;t t s,@SET_MAKE@,$(SET_MAKE),;t t s,@CP@,copy > nul,;t t -s,@LIBOBJS@, acosh.obj crypt.obj erf.obj win32.obj isinf.obj isnan.obj,;t t +s,@LIBOBJS@, acosh.obj crypt.obj erf.obj strlcat.obj strlcpy.obj win32.obj isinf.obj isnan.obj,;t t s,@ALLOCA@,$(ALLOCA),;t t s,@DEFAULT_KCODE@,$(DEFAULT_KCODE),;t t s,@EXEEXT@,.exe,;t t