Add strncpy().

Add prototypes for bcmp(), bzero() so the libsa compiles with WARNS=1
This commit is contained in:
simonb 1999-11-12 01:26:28 +00:00
parent 509864fa8f
commit 3f691021a6
3 changed files with 72 additions and 4 deletions

View File

@ -1,4 +1,4 @@
# $NetBSD: Makefile,v 1.38 1999/11/11 21:23:27 thorpej Exp $
# $NetBSD: Makefile,v 1.39 1999/11/12 01:26:28 simonb Exp $
LIB= sa
MKPIC= no
@ -20,8 +20,8 @@ CPPFLAGS= -I${SADIR} ${SACPPFLAGS} ${SAMISCCPPFLAGS} \
SRCS+= alloc.c bcmp.c bcopy.c bzero.c errno.c exit.c exec.c getfile.c gets.c \
globals.c htonl.c htons.c inet_addr.c intoa.c memcmp.c memcpy.c \
memset.c ntohs.c ntohl.c panic.c printf.c snprintf.c sprintf.c \
strlen.c strcmp.c strncmp.c strcpy.c strcat.c strerror.c subr_prf.c \
twiddle.c vsprintf.c checkpasswd.c
strlen.c strcmp.c strncmp.c strcpy.c strncpy.c strcat.c strerror.c \
subr_prf.c twiddle.c vsprintf.c checkpasswd.c
# io routines
SRCS+= closeall.c dev.c disklabel.c dkcksum.c ioctl.c nullfs.c stat.c fstat.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: stand.h,v 1.36 1999/11/11 21:23:27 thorpej Exp $ */
/* $NetBSD: stand.h,v 1.37 1999/11/12 01:26:28 simonb Exp $ */
/*
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
@ -228,7 +228,9 @@ int getfile __P((char *prompt, int mode));
char *strerror __P((int));
__dead void panic __P((const char *, ...)) __attribute__((noreturn));
__dead void _rtt __P((void)) __attribute__((noreturn));
int bcmp __P((const void *, const void *, size_t));
void bcopy __P((const void *, void *, size_t));
void bzero __P((void *, size_t));
void *memcpy __P((void *, const void *, size_t));
int memcmp __P((const void *, const void *, size_t));
void exec __P((char *, char *, int));
@ -244,6 +246,7 @@ size_t strlen __P((const char *));
int strcmp __P((const char *, const char *));
int strncmp __P((const char *, const char *, size_t));
char *strcpy __P((char *, const char *));
char *strncpy __P((char *, const char *, size_t));
char *strcat __P((char *, const char *));
u_int32_t inet_addr __P((const char *));

65
sys/lib/libsa/strncpy.c Normal file
View File

@ -0,0 +1,65 @@
/* $NetBSD: strncpy.c,v 1.1 1999/11/12 01:26:28 simonb 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. 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 "stand.h"
/*
* Copy src to dst, truncating or null-padding to always copy n bytes.
* Return dst.
*/
char *
strncpy(dst, src, n)
char *dst;
const char *src;
size_t n;
{
if (n != 0) {
char *d = dst;
const char *s = src;
do {
if ((*d++ = *s++) == 0) {
/* NUL pad the remaining n-1 bytes */
while (--n != 0)
*d++ = 0;
break;
}
} while (--n != 0);
}
return (dst);
}