Warns; ANSIfy, constify and move declarations into a common header.

This commit is contained in:
Mark Murray 2002-04-28 12:55:35 +00:00
parent f5b7af34dd
commit a53809fd7e
3 changed files with 68 additions and 39 deletions

30
usr.bin/ldd/extern.h Normal file
View file

@ -0,0 +1,30 @@
/*
* Copyright (c) 2002 FreeBSD, Inc
* 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 ``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.
*
* $FreeBSD$
*/
extern void dump_file(const char *);
extern int error_count;

View file

@ -28,14 +28,15 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/wait.h>
#include <machine/elf.h>
#include <arpa/inet.h>
#include <a.out.h>
#include <dlfcn.h>
#include <err.h>
@ -44,20 +45,17 @@ static const char rcsid[] =
#include <stdlib.h>
#include <unistd.h>
extern void dump_file(const char *);
extern int error_count;
#include "extern.h"
void
usage()
static void
usage(void)
{
fprintf(stderr, "usage: ldd [-a] [-v] [-f format] program ...\n");
exit(1);
}
int
main(argc, argv)
int argc;
char *argv[];
main(int argc, char *argv[])
{
char *fmt1 = NULL, *fmt2 = NULL;
int rval;
@ -139,7 +137,7 @@ char *argv[];
file_ok = 1;
is_shlib = 0;
if (n >= sizeof hdr.aout && !N_BADMAG(hdr.aout)) {
if ((size_t)n >= sizeof hdr.aout && !N_BADMAG(hdr.aout)) {
/* a.out file */
if ((N_GETFLAG(hdr.aout) & EX_DPMASK) != EX_DYNAMIC
#if 1 /* Compatibility */
@ -149,7 +147,7 @@ char *argv[];
warnx("%s: not a dynamic executable", *argv);
file_ok = 0;
}
} else if (n >= sizeof hdr.elf && IS_ELF(hdr.elf)) {
} else if ((size_t)n >= sizeof hdr.elf && IS_ELF(hdr.elf)) {
Elf_Ehdr ehdr;
Elf_Phdr phdr;
int dynamic = 0, i;

View file

@ -23,29 +23,31 @@
* SUCH DAMAGE.
*/
#ifndef lint
static const char rcsid[] =
"$FreeBSD$";
#endif /* not lint */
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <machine/elf.h>
#include <arpa/inet.h>
#define FREEBSD_AOUT
#include <a.out.h>
#include <assert.h>
#include <ctype.h>
#include <err.h>
#include <fcntl.h>
#include <link.h>
#include <stab.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "extern.h"
#define PAGE_SIZE 4096 /* i386 specific */
@ -76,12 +78,12 @@ void dump_file(const char *);
static void dump_rels(const char *, const struct relocation_info *,
unsigned long, const char *(*)(unsigned long), unsigned char *);
static void dump_segs();
static void dump_sods();
static void dump_segs(void);
static void dump_sods(void);
static void dump_sym(const struct nlist *);
static void dump_syms();
static void dump_syms(void);
static void dump_rtsyms();
static void dump_rtsyms(void);
static const char *rtsym_name(unsigned long);
static const char *sym_name(unsigned long);
@ -348,15 +350,15 @@ dump_rels(const char *label, const struct relocation_info *base,
switch (size) {
case 1:
snprintf(contents, sizeof contents, " [%02x]",
*(unsigned char *)(text_addr + r->r_address));
*(unsigned const char *)(text_addr + r->r_address));
break;
case 2:
snprintf(contents, sizeof contents, " [%04x]",
*(unsigned short *)(text_addr + r->r_address));
*(unsigned const short *)(text_addr + r->r_address));
break;
case 4:
snprintf(contents, sizeof contents, "[%08lx]",
*(unsigned long *)(text_addr + r->r_address));
*(unsigned const long *)(text_addr + r->r_address));
break;
}
} else
@ -382,7 +384,7 @@ dump_rels(const char *label, const struct relocation_info *base,
}
static void
dump_rtsyms()
dump_rtsyms(void)
{
unsigned long i;
@ -395,7 +397,7 @@ dump_rtsyms()
}
static void
dump_segs()
dump_segs(void)
{
printf(" Text segment starts at address %lx\n", origin + N_TXTOFF(*ex));
if (N_GETFLAG(*ex) & EX_DYNAMIC) {
@ -418,7 +420,7 @@ dump_segs()
}
static void
dump_sods()
dump_sods(void)
{
long sod_offset;
long paths_offset;
@ -442,8 +444,7 @@ dump_sods()
paths_offset = sdt->sdt_paths;
printf(" Shared object additional paths:\n");
if (paths_offset != 0) {
char *path = (char *)(text_addr + paths_offset);
printf(" %s\n", path);
printf(" %s\n", (const char *)(text_addr + paths_offset));
} else {
printf(" (none)\n");
}
@ -520,7 +521,7 @@ dump_sym(const struct nlist *np)
}
static void
dump_syms()
dump_syms(void)
{
unsigned long i;