WARNSify, fix .Nm usage, deprecate register, s/bcopy/memmove

This commit is contained in:
lukem 1997-10-19 13:40:12 +00:00
parent 629a5006ed
commit 09c3e85663
6 changed files with 82 additions and 70 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: build.c,v 1.10 1997/10/19 05:50:28 mrg Exp $ */
/* $NetBSD: build.c,v 1.11 1997/10/19 13:40:12 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -36,11 +36,12 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)build.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: build.c,v 1.10 1997/10/19 05:50:28 mrg Exp $";
__RCSID("$NetBSD: build.c,v 1.11 1997/10/19 13:40:12 lukem Exp $");
#endif
#endif /* not lint */
@ -50,18 +51,17 @@ static char rcsid[] = "$NetBSD: build.c,v 1.10 1997/10/19 05:50:28 mrg Exp $";
#include <a.out.h>
#include <ar.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <ranlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "archive.h"
extern CHDR chdr; /* converted header */
extern char *archive; /* archive name */
extern char *tname; /* temporary file "name" */
#include "extern.h"
typedef struct _rlib {
struct _rlib *next; /* next structure */
@ -75,9 +75,10 @@ static FILE *fp;
static long symcnt; /* symbol count */
static long tsymlen; /* total string length */
static void rexec(), symobj();
extern void *emalloc();
static void rexec __P((int, int));
static void symobj __P((void));
int
build()
{
CF cf;
@ -128,18 +129,20 @@ build()
*/
static void
rexec(rfd, wfd)
register int rfd;
int rfd;
int wfd;
{
register RLIB *rp;
register long nsyms;
register int nr, symlen;
register char *strtab, *sym;
RLIB *rp;
long nsyms;
int nr, symlen;
char *strtab, *sym;
struct exec ebuf;
struct nlist nl;
off_t r_off, w_off;
long strsize;
strtab = NULL;
/* Get current offsets for original and tmp files. */
r_off = lseek(rfd, (off_t)0, SEEK_CUR);
w_off = lseek(wfd, (off_t)0, SEEK_CUR);
@ -155,7 +158,7 @@ rexec(rfd, wfd)
/* Seek to string table. */
if (lseek(rfd, r_off + N_STROFF(ebuf), SEEK_SET) == (off_t)-1)
error(archive);
err(1, "lseek %s", archive);
/* Read in size of the string table. */
nr = read(rfd, &strsize, sizeof(strsize));
@ -168,7 +171,7 @@ rexec(rfd, wfd)
nr = read(rfd, strtab, strsize);
if (nr != strsize) {
badread: if (nr < 0)
error(archive);
err(1, "read %s", archive);
goto bad2;
}
@ -182,7 +185,7 @@ badread: if (nr < 0)
if (!fread(&nl, sizeof(struct nlist), 1, fp)) {
if (feof(fp))
badfmt();
error(archive);
err(1, "fread %s", archive);
}
/* Ignore if no name or local. */
@ -202,7 +205,7 @@ badread: if (nr < 0)
rp = (RLIB *)emalloc(sizeof(RLIB));
rp->sym = (char *)emalloc(symlen);
bcopy(sym, rp->sym, symlen);
memmove(rp->sym, sym, symlen);
rp->symlen = symlen;
rp->pos = w_off;
@ -226,7 +229,7 @@ bad1: (void)lseek(rfd, r_off, SEEK_SET);
static void
symobj()
{
register RLIB *rp, *rnext;
RLIB *rp, *rnext;
struct ranlib rn;
off_t ransize;
long size, stroff;
@ -234,7 +237,7 @@ symobj()
/* Rewind the archive, leaving the magic number. */
if (fseek(fp, (long)SARMAG, SEEK_SET))
error(archive);
err(1, "fseek %s", archive);
/* Size of the ranlib archive file, pad if necessary. */
ransize = sizeof(long) +
@ -250,12 +253,12 @@ symobj()
(void)sprintf(hb, HDR2, RANLIBMAG, 0L, getuid(), getgid(),
DEFMODE & ~umask(0), (off_t)ransize, ARFMAG);
if (!fwrite(hb, sizeof(struct ar_hdr), 1, fp))
error(tname);
err(1, "fwrite %s", tname);
/* First long is the size of the ranlib structure section. */
size = symcnt * sizeof(struct ranlib);
if (!fwrite(&size, sizeof(size), 1, fp))
error(tname);
err(1, "fwrite %s", tname);
/* Offset of the first archive file. */
size = SARMAG + sizeof(struct ar_hdr) + ransize;
@ -270,24 +273,24 @@ symobj()
stroff += rp->symlen;
rn.ran_off = size + rp->pos;
if (!fwrite(&rn, sizeof(struct ranlib), 1, fp))
error(archive);
err(1, "fwrite %s", archive);
}
/* Second long is the size of the string table. */
if (!fwrite(&tsymlen, sizeof(tsymlen), 1, fp))
error(tname);
err(1, "fwrite %s", tname);
/* Write out the string table. */
for (rp = rhead; rp; rp = rnext) {
if (!fwrite(rp->sym, rp->symlen, 1, fp))
error(tname);
err(1, "fwrite %s", tname);
rnext = rp->next;
free(rp);
}
rhead = NULL;
if (pad && !fwrite(&pad, sizeof(pad), 1, fp))
error(tname);
err(1, "fwrite %s", tname);
(void)fflush(fp);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: misc.c,v 1.7 1997/10/19 05:50:29 mrg Exp $ */
/* $NetBSD: misc.c,v 1.8 1997/10/19 13:40:17 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -36,26 +36,31 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)misc.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: misc.c,v 1.7 1997/10/19 05:50:29 mrg Exp $";
__RCSID("$NetBSD: misc.c,v 1.8 1997/10/19 13:40:17 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/param.h>
#include <signal.h>
#include <dirent.h>
#include <err.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <archive.h>
#include "extern.h"
#include "pathnames.h"
extern char *archive; /* archive name */
char *tname = "temporary file";
int
tmp()
{
static char *envtmp;
@ -73,12 +78,12 @@ tmp()
(void)snprintf(path, MAXPATHLEN, "%s/%s", envtmp,
strrchr(_NAME_RANTMP, '/'));
else
bcopy(_PATH_RANTMP, path, sizeof(_PATH_RANTMP));
memmove(path, _PATH_RANTMP, sizeof(_PATH_RANTMP));
sigfillset(&set);
(void)sigprocmask(SIG_BLOCK, &set, &oset);
if ((fd = mkstemp(path)) == -1)
error(path);
err(1, "mkstemp %s", path);
(void)unlink(path);
(void)sigprocmask(SIG_SETMASK, &oset, NULL);
return(fd);
@ -86,12 +91,12 @@ tmp()
void *
emalloc(len)
int len;
size_t len;
{
void *p;
if ((p = malloc((u_int)len)) == NULL)
error(archive);
err(1, "malloc");
return(p);
}
@ -99,20 +104,14 @@ char *
rname(path)
char *path;
{
register char *ind;
char *ind;
return((ind = rindex(path, '/')) ? ind + 1 : path);
return((ind = strrchr(path, '/')) ? ind + 1 : path);
}
void
badfmt()
{
errno = EFTYPE;
error(archive);
}
error(name)
char *name;
{
(void)fprintf(stderr, "ranlib: %s: %s\n", name, strerror(errno));
exit(1);
err(1, "%s", archive);
}

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ranlib.1,v 1.5 1997/10/19 05:50:31 mrg Exp $
.\" $NetBSD: ranlib.1,v 1.6 1997/10/19 13:40:20 lukem Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
@ -40,11 +40,11 @@
.Nm ranlib
.Nd table-of-contents for archive libraries
.Sh SYNOPSIS
.Nm ranlib
.Nm
.Op Fl t
.Ar file ...
.Sh DESCRIPTION
.Nm Ranlib
.Nm
creates a table of external references for archive libraries,
normally used by the loader,
.Xr ld 1 .
@ -89,6 +89,6 @@ Temporary file names.
.Xr ranlib 5
.Sh HISTORY
A
.Nm ranlib
.Nm
command appeared in
.At v7 .

View File

@ -1,4 +1,4 @@
.\" $NetBSD: ranlib.5,v 1.3 1997/10/19 05:50:33 mrg Exp $
.\" $NetBSD: ranlib.5,v 1.4 1997/10/19 13:40:23 lukem Exp $
.\"
.\" Copyright (c) 1990, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@ -43,7 +43,7 @@
.Fd #include <ranlib.h>
.Sh DESCRIPTION
The archive table-of-contents command
.Nm ranlib
.Nm
creates a table of contents for archives, containing object files, to
be used by the link-editor
.Xr ld 1 .
@ -51,7 +51,7 @@ It operates on archives created with the utility
.Xr ar 1 .
.Pp
The
.Nm Ranlib
.Nm
function
prepends a new file to the archive which has three separate parts.
The first part is a standard archive header, which has a special name

View File

@ -1,4 +1,4 @@
/* $NetBSD: ranlib.c,v 1.5 1997/10/19 05:50:34 mrg Exp $ */
/* $NetBSD: ranlib.c,v 1.6 1997/10/19 13:40:27 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -36,30 +36,36 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n";
__COPYRIGHT("@(#) Copyright (c) 1990, 1993\n\
The Regents of the University of California. All rights reserved.\n");
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)ranlib.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: ranlib.c,v 1.5 1997/10/19 05:50:34 mrg Exp $";
__RCSID("$NetBSD: ranlib.c,v 1.6 1997/10/19 13:40:27 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <dirent.h>
#include <archive.h>
#include <stdio.h>
#include <stdlib.h>
#include <archive.h>
#include "extern.h"
CHDR chdr;
u_int options; /* UNUSED -- keep open_archive happy */
char *archive;
int main __P((int, char **));
void usage __P((void));
int
main(argc, argv)
int argc;
char **argv;
@ -67,7 +73,7 @@ main(argc, argv)
int ch, eval, tflag;
tflag = 0;
while ((ch = getopt(argc, argv, "t")) != EOF)
while ((ch = getopt(argc, argv, "t")) != -1)
switch(ch) {
case 't':
tflag = 1;
@ -82,11 +88,12 @@ main(argc, argv)
if (!*argv)
usage();
for (eval = 0; archive = *argv++;)
for (eval = 0; (archive = *argv++) != NULL;)
eval |= tflag ? touch() : build();
exit(eval);
}
void
usage()
{
(void)fprintf(stderr, "usage: ranlib [-t] archive ...\n");

View File

@ -1,4 +1,4 @@
/* $NetBSD: touch.c,v 1.5 1997/10/19 05:50:36 mrg Exp $ */
/* $NetBSD: touch.c,v 1.6 1997/10/19 13:40:31 lukem Exp $ */
/*-
* Copyright (c) 1990, 1993
@ -36,28 +36,30 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)touch.c 8.1 (Berkeley) 6/6/93";
#else
static char rcsid[] = "$NetBSD: touch.c,v 1.5 1997/10/19 05:50:36 mrg Exp $";
__RCSID("$NetBSD: touch.c,v 1.6 1997/10/19 13:40:31 lukem Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include <fcntl.h>
#include <dirent.h>
#include <ranlib.h>
#include <ar.h>
#include <time.h>
#include <unistd.h>
#include <err.h>
#include <dirent.h>
#include <fcntl.h>
#include <ranlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <archive.h>
extern CHDR chdr; /* converted header */
extern char *archive; /* archive name */
#include "extern.h"
int
touch()
{
int afd;
@ -75,6 +77,7 @@ touch()
return(0);
}
void
settime(afd)
int afd;
{
@ -84,8 +87,8 @@ settime(afd)
size = SARMAG + sizeof(hdr->ar_name);
if (lseek(afd, size, SEEK_SET) == (off_t)-1)
error(archive);
err(1, "%s", archive);
(void)sprintf(buf, "%-12ld", time((time_t *)NULL) + RANLIBSKEW);
if (write(afd, buf, sizeof(hdr->ar_date)) != sizeof(hdr->ar_date))
error(archive);
err(1, "%s", archive);
}