Use glibc __progname convention (with retrofit) throughout.
CVS patchset: 5880 CVS date: 2002/11/26 22:34:21
This commit is contained in:
parent
5b5c816a46
commit
a496b09106
|
@ -230,6 +230,9 @@ Magdir/xenix \
|
|||
Magdir/zilog \
|
||||
Magdir/zyxel
|
||||
|
||||
listobjs:
|
||||
@echo $(libfmagic_la_SOURCES:.c=.lo) > $@
|
||||
|
||||
.PHONY: lint
|
||||
lint:
|
||||
$(LINT) $(DEFS) $(INCLUDES) $(file_SOURCES) $(libfmagic_la_SOURCES) $(pkginc_HEADERS) $(noinst_HEADERS)
|
||||
|
|
|
@ -804,7 +804,7 @@ apprentice_file(fmagic fm, /*@out@*/ struct magic **magicp,
|
|||
if (errno != ENOENT)
|
||||
(void) fprintf(stderr,
|
||||
"%s: can't read magic file %s (%s)\n",
|
||||
progname, fn, strerror(errno));
|
||||
__progname, fn, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -856,26 +856,26 @@ apprentice_compile(/*@unused@*/ const fmagic fm,
|
|||
|
||||
if ((fd = open(dbname, O_WRONLY|O_CREAT|O_TRUNC, 0644)) == -1) {
|
||||
(void)fprintf(stderr, "%s: Cannot open `%s' (%s)\n",
|
||||
progname, dbname, strerror(errno));
|
||||
__progname, dbname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (write(fd, ar, sizeof(ar)) != sizeof(ar)) {
|
||||
(void)fprintf(stderr, "%s: error writing `%s' (%s)\n",
|
||||
progname, dbname, strerror(errno));
|
||||
__progname, dbname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (lseek(fd, sizeof(**magicp), SEEK_SET) != sizeof(**magicp)) {
|
||||
(void)fprintf(stderr, "%s: error seeking `%s' (%s)\n",
|
||||
progname, dbname, strerror(errno));
|
||||
__progname, dbname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (write(fd, *magicp, sizeof(**magicp) * *nmagicp)
|
||||
!= sizeof(**magicp) * *nmagicp) {
|
||||
(void)fprintf(stderr, "%s: error writing `%s' (%s)\n",
|
||||
progname, dbname, strerror(errno));
|
||||
__progname, dbname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -909,7 +909,7 @@ apprentice_map(/*@unused@*/ const fmagic fm,
|
|||
|
||||
if (fstat(fd, &st) == -1) {
|
||||
(void)fprintf(stderr, "%s: Cannot stat `%s' (%s)\n",
|
||||
progname, dbname, strerror(errno));
|
||||
__progname, dbname, strerror(errno));
|
||||
goto errxit;
|
||||
}
|
||||
|
||||
|
@ -917,13 +917,13 @@ apprentice_map(/*@unused@*/ const fmagic fm,
|
|||
if ((mm = mmap(0, (size_t)st.st_size, PROT_READ|PROT_WRITE,
|
||||
MAP_PRIVATE|MAP_FILE, fd, (off_t)0)) == MAP_FAILED) {
|
||||
(void)fprintf(stderr, "%s: Cannot map `%s' (%s)\n",
|
||||
progname, dbname, strerror(errno));
|
||||
__progname, dbname, strerror(errno));
|
||||
goto errxit;
|
||||
}
|
||||
#else
|
||||
mm = xmalloc((size_t)st.st_size);
|
||||
if (read(fd, mm, (size_t)st.st_size) != (size_t)st.st_size) {
|
||||
(void) fprintf(stderr, "%s: Read failed (%s).\n", progname,
|
||||
(void) fprintf(stderr, "%s: Read failed (%s).\n", __progname,
|
||||
strerror(errno));
|
||||
goto errxit;
|
||||
}
|
||||
|
@ -935,7 +935,7 @@ apprentice_map(/*@unused@*/ const fmagic fm,
|
|||
if (*ptr != MAGICNO) {
|
||||
if (swap4(*ptr) != MAGICNO) {
|
||||
(void)fprintf(stderr, "%s: Bad magic in `%s'\n",
|
||||
progname, dbname);
|
||||
__progname, dbname);
|
||||
goto errxit;
|
||||
}
|
||||
needsbyteswap = 1;
|
||||
|
@ -948,7 +948,7 @@ apprentice_map(/*@unused@*/ const fmagic fm,
|
|||
if (version != VERSIONNO) {
|
||||
(void)fprintf(stderr,
|
||||
"%s: version mismatch (%d != %d) in `%s'\n",
|
||||
progname, version, VERSIONNO, dbname);
|
||||
__progname, version, VERSIONNO, dbname);
|
||||
goto errxit;
|
||||
}
|
||||
*nmagicp = (st.st_size / sizeof(**magicp)) - 1;
|
||||
|
@ -999,7 +999,7 @@ apprentice_1(fmagic fm, const char *fn, int action)
|
|||
#ifndef COMPILE_ONLY
|
||||
if ((rv = apprentice_map(fm, &magic, &nmagic, fn, action)) != 0)
|
||||
(void)fprintf(stderr, "%s: Using regular magic file `%s'\n",
|
||||
progname, fn);
|
||||
__progname, fn);
|
||||
|
||||
if (rv != 0)
|
||||
rv = apprentice_file(fm, &magic, &nmagic, fn, action);
|
||||
|
@ -1062,7 +1062,7 @@ fmagicSetup(fmagic fm, const char *fn, int action)
|
|||
/*@=branchstate@*/
|
||||
if (errs == -1)
|
||||
(void) fprintf(stderr, "%s: couldn't find any magic files!\n",
|
||||
progname);
|
||||
__progname);
|
||||
if (action == CHECK && errs)
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
|
@ -1081,13 +1081,10 @@ main(int argc, char *argv[])
|
|||
fmagic fm = &myfmagic;
|
||||
int ret;
|
||||
|
||||
if ((progname = strrchr(argv[0], '/')) != NULL)
|
||||
progname++;
|
||||
else
|
||||
progname = argv[0];
|
||||
setprogname(argv[0]); /* Retrofit glibc __progname */
|
||||
|
||||
if (argc != 2) {
|
||||
(void)fprintf(stderr, "usage: %s file\n", progname);
|
||||
(void)fprintf(stderr, "usage: %s file\n", __progname);
|
||||
exit(1);
|
||||
}
|
||||
fm->magicfile = argv[1];
|
||||
|
|
|
@ -199,7 +199,7 @@ uncompressgzipped(const unsigned char *old,
|
|||
rc = inflateInit2(&z, -15);
|
||||
/*@=type@*/
|
||||
if (rc != Z_OK) {
|
||||
(void) fprintf(stderr,"%s: zlib: %s\n", progname, z.msg);
|
||||
(void) fprintf(stderr,"%s: zlib: %s\n", __progname, z.msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ uncompressgzipped(const unsigned char *old,
|
|||
rc = inflate(&z, Z_SYNC_FLUSH);
|
||||
/*@=type@*/
|
||||
if (rc != Z_OK && rc != Z_STREAM_END) {
|
||||
fprintf(stderr,"%s: zlib: %s\n", progname, z.msg);
|
||||
fprintf(stderr,"%s: zlib: %s\n", __progname, z.msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
22
file/file.c
22
file/file.c
|
@ -59,9 +59,6 @@ int os2_apptype (const char *fn, char *buf, int nb);
|
|||
/*@unchecked@*/
|
||||
static int nobuffer = 0; /* Do not buffer stdout */
|
||||
|
||||
/*@unchecked@*/
|
||||
char *progname; /* used throughout */
|
||||
|
||||
/*
|
||||
* unwrap -- read a file of filenames, do each one.
|
||||
*/
|
||||
|
@ -113,8 +110,8 @@ usage(void)
|
|||
/*@globals fileSystem @*/
|
||||
/*@modifies fileSystem @*/
|
||||
{
|
||||
(void)fprintf(stderr, USAGE, progname);
|
||||
(void)fprintf(stderr, "Usage: %s -C [-m magic]\n", progname);
|
||||
(void)fprintf(stderr, USAGE, __progname);
|
||||
(void)fprintf(stderr, "Usage: %s -C [-m magic]\n", __progname);
|
||||
#ifdef HAVE_GETOPT_H
|
||||
(void)fputs("Try `file --help' for more information.\n", stderr);
|
||||
#endif
|
||||
|
@ -159,10 +156,10 @@ help(void)
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
/*@globals global_fmagic, nobuffer,
|
||||
default_magicfile, optind, progname,
|
||||
default_magicfile, optind,
|
||||
fileSystem, internalState @*/
|
||||
/*@modifies argv, global_fmagic, nobuffer,
|
||||
default_magicfile, optind, progname,
|
||||
/*@modifies global_fmagic, nobuffer,
|
||||
default_magicfile, optind,
|
||||
fileSystem, internalState @*/
|
||||
{
|
||||
int xx;
|
||||
|
@ -213,13 +210,6 @@ main(int argc, char **argv)
|
|||
_wildcard(&argc, &argv);
|
||||
#endif
|
||||
|
||||
/*@-modobserver@*/
|
||||
if ((progname = strrchr(argv[0], '/')) != NULL)
|
||||
progname++;
|
||||
else
|
||||
progname = argv[0];
|
||||
/*@=modobserver@*/
|
||||
|
||||
/*@-assignexpose@*/
|
||||
fm->magicfile = default_magicfile;
|
||||
/*@=assignexpose@*/
|
||||
|
@ -298,7 +288,7 @@ main(int argc, char **argv)
|
|||
fm->flags |= FMAGIC_FLAGS_SPECIAL;
|
||||
/*@switchbreak@*/ break;
|
||||
case 'v':
|
||||
(void) fprintf(stdout, "%s-%d.%d\n", progname,
|
||||
(void) fprintf(stdout, "%s-%d.%d\n", __progname,
|
||||
FILE_VERSION_MAJOR, patchlevel);
|
||||
(void) fprintf(stdout, "magic file from %s\n",
|
||||
fm->magicfile);
|
||||
|
|
|
@ -114,10 +114,6 @@ struct mlist {
|
|||
struct mlist *prev;
|
||||
};
|
||||
|
||||
/*@unchecked@*/ /*@observer@*/ /*@relnull@*/
|
||||
extern char *progname; /* the program name */
|
||||
/*@unchecked@*/
|
||||
|
||||
enum fmagicFlags_e {
|
||||
/*@-enummemuse@*/
|
||||
FMAGIC_FLAGS_NONE = 0,
|
||||
|
|
|
@ -143,8 +143,8 @@ error(int status, /*@unused@*/ int errnum, const char * format, ...)
|
|||
/* cuz we use stdout for most, stderr here */
|
||||
(void) fflush(stdout);
|
||||
|
||||
if (progname != NULL)
|
||||
(void) fprintf(stderr, "%s: ", progname);
|
||||
if (__progname != NULL)
|
||||
(void) fprintf(stderr, "%s: ", __progname);
|
||||
(void) vfprintf(stderr, format, va);
|
||||
va_end(va);
|
||||
#if NOTYET
|
||||
|
@ -165,9 +165,9 @@ magwarn(const char *f, ...)
|
|||
/* cuz we use stdout for most, stderr here */
|
||||
(void) fflush(stdout);
|
||||
|
||||
if (progname != NULL)
|
||||
if (__progname != NULL)
|
||||
(void) fprintf(stderr, "%s: %s, %d: ",
|
||||
progname, fm->magicfile, fm->lineno);
|
||||
__progname, fm->magicfile, fm->lineno);
|
||||
(void) vfprintf(stderr, f, va);
|
||||
va_end(va);
|
||||
(void) fputc('\n', stderr);
|
||||
|
|
|
@ -289,6 +289,22 @@ extern void muntrace (void) __THROW
|
|||
#define xstrdup(_str) (strcpy(xmalloc(strlen(_str)+1), (_str)))
|
||||
#endif
|
||||
|
||||
/* Retrofit glibc __progname */
|
||||
#if defined __GLIBC__ && __GLIBC__ >= 2
|
||||
#if __GLIBC_MINOR__ >= 1
|
||||
#define __progname __assert_program_name
|
||||
#endif
|
||||
#define setprogname(pn)
|
||||
#else
|
||||
#define __progname program_name
|
||||
#define setprogname(pn) \
|
||||
{ if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
|
||||
else __progname = pn; \
|
||||
}
|
||||
#endif
|
||||
/*@unchecked@*/
|
||||
const char *__progname;
|
||||
|
||||
#if HAVE_LOCALE_H
|
||||
# include <locale.h>
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue