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;
}
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;
}
if (fstat(fd, &st) == -1) {
(void)fprintf(stderr, "%s: Cannot stat `%s' (%s)\n",
- progname, dbname, strerror(errno));
+ __progname, dbname, strerror(errno));
goto errxit;
}
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;
}
if (*ptr != MAGICNO) {
if (swap4(*ptr) != MAGICNO) {
(void)fprintf(stderr, "%s: Bad magic in `%s'\n",
- progname, dbname);
+ __progname, dbname);
goto errxit;
}
needsbyteswap = 1;
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;
#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);
/*@=branchstate@*/
if (errs == -1)
(void) fprintf(stderr, "%s: couldn't find any magic files!\n",
- progname);
+ __progname);
if (action == CHECK && errs)
exit(EXIT_FAILURE);
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];
/*@unchecked@*/
static int nobuffer = 0; /* Do not buffer stdout */
-/*@unchecked@*/
-char *progname; /* used throughout */
-
/*
* unwrap -- read a file of filenames, do each one.
*/
/*@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
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;
_wildcard(&argc, &argv);
#endif
-/*@-modobserver@*/
- if ((progname = strrchr(argv[0], '/')) != NULL)
- progname++;
- else
- progname = argv[0];
-/*@=modobserver@*/
-
/*@-assignexpose@*/
fm->magicfile = default_magicfile;
/*@=assignexpose@*/
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);
/* 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
/* 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);