kill recently added 'check' functions, since they only add code to be more

expensive, i.e. they save nothing and add code.
This commit is contained in:
cgd 1996-09-30 23:49:27 +00:00
parent c04e2bf00c
commit 80fde3aab4
4 changed files with 15 additions and 75 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nlist.c,v 1.8 1996/09/27 22:23:04 cgd Exp $ */
/* $NetBSD: nlist.c,v 1.9 1996/09/30 23:49:27 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
#else
static char rcsid[] = "$NetBSD: nlist.c,v 1.8 1996/09/27 22:23:04 cgd Exp $";
static char rcsid[] = "$NetBSD: nlist.c,v 1.9 1996/09/30 23:49:27 cgd Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@ -56,20 +56,19 @@ static char rcsid[] = "$NetBSD: nlist.c,v 1.8 1996/09/27 22:23:04 cgd Exp $";
#include "nlist_private.h"
static struct {
int (*check) __P((int));
int (*fdnlist) __P((int, struct nlist *));
} fdnlist_fmts[] = {
#ifdef NLIST_AOUT
{ __fdnlist_is_aout, __fdnlist_aout },
{ __fdnlist_aout },
#endif
#ifdef NLIST_ECOFF
{ __fdnlist_is_ecoff, __fdnlist_ecoff },
{ __fdnlist_ecoff },
#endif
#ifdef NLIST_ELF32
{ __fdnlist_is_elf32, __fdnlist_elf32 },
{ __fdnlist_elf32 },
#endif
#ifdef NLIST_ELF64
{ __fdnlist_is_elf64, __fdnlist_elf64 },
{ __fdnlist_elf64 },
#endif
};
@ -96,7 +95,7 @@ __fdnlist(fd, list)
int i;
for (i = 0; i < sizeof(fdnlist_fmts) / sizeof(fdnlist_fmts[0]); i++)
if ((*fdnlist_fmts[i].check)(fd) != -1)
return ((*fdnlist_fmts[i].fdnlist)(fd, list));
if ((*fdnlist_fmts[i].fdnlist)(fd, list) != -1)
return;
return -1;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: nlist_aout.c,v 1.1 1996/09/27 22:23:04 cgd Exp $ */
/* $NetBSD: nlist_aout.c,v 1.2 1996/09/30 23:49:28 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
#else
static char rcsid[] = "$NetBSD: nlist_aout.c,v 1.1 1996/09/27 22:23:04 cgd Exp $";
static char rcsid[] = "$NetBSD: nlist_aout.c,v 1.2 1996/09/30 23:49:28 cgd Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@ -56,20 +56,6 @@ static char rcsid[] = "$NetBSD: nlist_aout.c,v 1.1 1996/09/27 22:23:04 cgd Exp $
#include "nlist_private.h"
#ifdef NLIST_AOUT
int
__fdnlist_is_aout(fd)
register int fd;
{
struct exec exec;
if (lseek(fd, (off_t)0, SEEK_SET) == -1 ||
read(fd, &exec, sizeof(exec)) != sizeof(exec) ||
N_BADMAG(exec))
return (-1);
return (0);
}
int
__fdnlist_aout(fd, list)
register int fd;
@ -86,10 +72,8 @@ __fdnlist_aout(fd, list)
struct stat st;
if (lseek(fd, (off_t)0, SEEK_SET) == -1 ||
read(fd, &exec, sizeof(exec)) != sizeof(exec))
return (-1);
if (fstat(fd, &st) < 0)
read(fd, &exec, sizeof(exec)) != sizeof(exec) ||
N_BADMAG(exec) || fstat(fd, &st) < 0)
return (-1);
symoff = N_SYMOFF(exec);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nlist_ecoff.c,v 1.1 1996/09/27 22:23:05 cgd Exp $ */
/* $NetBSD: nlist_ecoff.c,v 1.2 1996/09/30 23:49:29 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)nlist.c 8.1 (Berkeley) 6/4/93";
#else
static char rcsid[] = "$NetBSD: nlist_ecoff.c,v 1.1 1996/09/27 22:23:05 cgd Exp $";
static char rcsid[] = "$NetBSD: nlist_ecoff.c,v 1.2 1996/09/30 23:49:29 cgd Exp $";
#endif
#endif /* LIBC_SCCS and not lint */
@ -63,42 +63,6 @@ static char rcsid[] = "$NetBSD: nlist_ecoff.c,v 1.1 1996/09/27 22:23:05 cgd Exp
#define BAD do { rv = -1; goto out; } while (0)
#define BADUNMAP do { rv = -1; goto unmap; } while (0)
int
__fdnlist_is_ecoff(fd)
int fd;
{
struct stat st;
struct ecoff_exechdr *exechdrp;
char *mappedfile;
size_t mappedsize;
int rv = -1;
if (fstat(fd, &st) < 0)
BAD;
if (st.st_size > SIZE_T_MAX) {
errno = EFBIG;
BAD;
}
mappedsize = st.st_size;
mappedfile = mmap(NULL, mappedsize, PROT_READ, 0, fd, 0);
if (mappedfile == (char *)-1)
BAD;
if (check(0, sizeof *exechdrp))
BADUNMAP;
exechdrp = (struct ecoff_exechdr *)&mappedfile[0];
if (ECOFF_BADMAG(exechdrp))
BADUNMAP;
rv = 0;
unmap:
munmap(mappedfile, mappedsize);
out:
return (rv);
}
int
__fdnlist_ecoff(fd, list)
register int fd;

View File

@ -1,4 +1,4 @@
/* $NetBSD: nlist_private.h,v 1.2 1996/09/27 22:41:59 cgd Exp $ */
/* $NetBSD: nlist_private.h,v 1.3 1996/09/30 23:49:30 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All rights reserved.
@ -43,21 +43,14 @@
#define ISLAST(p) (p->n_un.n_name == 0 || p->n_un.n_name[0] == 0)
#ifdef NLIST_AOUT
int __fdnlist_is_aout __P((int));
int __fdnlist_aout __P((int, struct nlist *));
#endif
#ifdef NLIST_ECOFF
int __fdnlist_is_ecoff __P((int));
int __fdnlist_ecoff __P((int, struct nlist *));
#endif
#ifdef NLIST_ELF32
int __fdnlist_is_elf32 __P((int));
int __fdnlist_elf32 __P((int, struct nlist *));
#endif
#ifdef NLIST_ELF64
int __fdnlist_is_elf64 __P((int));
int __fdnlist_elf64 __P((int, struct nlist *));
#endif