assert()
	setjmp()/longjmp()
	vsprintf()
This commit is contained in:
Mike Smith 1998-11-01 09:31:08 +00:00
parent 5fabcd1a00
commit 17bcf9c00a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=40805
5 changed files with 73 additions and 10 deletions

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.5 1998/10/04 08:10:29 msmith Exp $
# $Id: Makefile,v 1.6 1998/10/06 19:23:57 msmith Exp $
#
# Originally from $NetBSD: Makefile,v 1.21 1997/10/26 22:08:38 lukem Exp $
#
@ -20,9 +20,9 @@ CFLAGS+= -mno-fp-regs
.endif
# standalone components and stuff we have modified locally
SRCS+= __main.c bcd.c bswap.c environment.c getopt.c gets.c globals.c \
pager.c printf.c strdup.c strerror.c strtol.c random.c sbrk.c \
twiddle.c zalloc.c zalloc_malloc.c
SRCS+= __main.c assert.c bcd.c bswap.c environment.c getopt.c gets.c \
globals.c pager.c printf.c strdup.c strerror.c strtol.c random.c \
sbrk.c twiddle.c zalloc.c zalloc_malloc.c
# private (pruned) versions of libc string functions
SRCS+= strcasecmp.c
@ -90,6 +90,11 @@ __reml.S: ${.CURDIR}/../libc/alpha/gen/divrem.m4
.PATH: ${.CURDIR}/../libc/net
SRCS+= inet_ntoa.c inet_addr.c
# setjmp/longjmp
.PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/gen
CFLAGS+=-I${.CURDIR}/../libc/${MACHINE_ARCH}
SRCS+= setjmp.S
# decompression functionality from libz
.PATH: ${.CURDIR}/../libz
CFLAGS+=-DHAVE_MEMCPY

37
lib/libstand/assert.c Normal file
View File

@ -0,0 +1,37 @@
/*-
* Copyright (c) 1998 Michael Smith.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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.
*
* $Id$
*/
#include <stand.h>
#include <assert.h>
void
__assert(const char *file, int line, const char *expression)
{
printf("assertion \"%s\" failed: file \"%s\", line %d\n", expression, file, line);
exit();
}

View File

@ -22,7 +22,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $Id$
.\" $Id: libstand.3,v 1.1.1.1 1998/08/20 08:19:55 msmith Exp $
.\"
.Dd June 22, 1998
.Dt LIBSTAND 3
@ -124,6 +124,15 @@ may be used to prevent a variable being unset.
.Pp
Returns error messages for the subset of errno values supported by
.Nm No .
.It Fn "assert" "expression"
.Pp
Requires
.Fd #include <assert.h>
.It Fn "int setjmp" "jmp_buf env"
.It Fn "void longjmp" "jmp_buf env" "int val"
.Pp
Require
.Fd #include <setjmp.h>
.El
.Sh CHARACTER I/O
.Bl -hang -width 10n
@ -155,6 +164,7 @@ if successful, or -1 if a read error occurs.
.It Fn "int printf" "const char *fmt" "..."
.It Fn "void vprintf" "const char *fmt" "va_list ap"
.It Fn "int sprintf" "char *buf" "const char *fmt" "..."
.It Fn "void vsprintf" "char *buf" "const char *fmt" "va_list ap"
.Pp
The *printf functions implement a subset of the standard
.Fn printf
@ -448,6 +458,10 @@ and
.Nm libkern
from
.Fx 3.0 .
.It
.Nm zalloc
from
.An Matthew Dillon Aq dillon@backplane.com
.El
.Pp
The reorganisation and port to

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)subr_prf.c 8.3 (Berkeley) 1/21/94
* $Id: subr_prf.c,v 1.46 1998/05/28 09:30:20 phk Exp $
* $Id: printf.c,v 1.1.1.1 1998/08/20 08:19:55 msmith Exp $
*/
/*
@ -74,9 +74,6 @@ vprintf(const char *fmt, va_list ap)
kvprintf(fmt, putchar, NULL, 10, ap);
}
/*
* Scaled down version of sprintf(3).
*/
int
sprintf(char *buf, const char *cfmt, ...)
{
@ -90,6 +87,15 @@ sprintf(char *buf, const char *cfmt, ...)
return retval;
}
void
vsprintf(char *buf, const char *cfmt, va_list ap)
{
int retval;
retval = kvprintf(cfmt, NULL, (void *)buf, 10, ap);
buf[retval] = '\0';
}
/*
* Put a number (base <= 16) in a buffer in reverse order; return an
* optional length and a pointer to the NULL terminated (preceded?)

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: stand.h,v 1.8 1998/10/19 09:08:40 dfr Exp $
* $Id: stand.h,v 1.9 1998/10/31 02:48:29 msmith Exp $
* From $NetBSD: stand.h,v 1.22 1997/06/26 19:17:40 drochner Exp $
*/
@ -194,6 +194,7 @@ extern int dkcksum(struct disklabel *);
extern int printf(const char *fmt, ...);
extern void vprintf(const char *fmt, _BSD_VA_LIST_);
extern int sprintf(char *buf, const char *cfmt, ...);
extern void vsprintf(char *buf, const char *cfmt, _BSD_VA_LIST_);
extern void twiddle(void);