#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: file.c,v 1.121 2008/07/03 15:48:18 christos Exp $")
+FILE_RCSID("@(#)$File: file.c,v 1.122 2008/10/01 14:30:45 christos Exp $")
#endif /* lint */
# define USAGE "Usage: %s [-bcik" SYMLINKFLAG "nNrsvz0] [-e test] [-f namefile] [-F separator] [-m magicfiles] file...\n %s -C -m magicfiles\n"
#ifndef MAXPATHLEN
-#define MAXPATHLEN 512
+#define MAXPATHLEN 1024
#endif
private int /* Global command-line options */
nobuffer = 0, /* Do not buffer stdout */
nulsep = 0; /* Append '\0' to the separator */
-private const char *magicfile = 0; /* where the magic is */
+private const char *magicfile; /* where the magic is */
private const char *default_magicfile = MAGIC;
private const char *separator = ":"; /* Default field separator */
int action = 0, didsomefiles = 0, errflg = 0;
int flags = 0;
char *home, *usermagic;
- struct stat sb;
static const char hmagic[] = "/.magic";
+ char magicpath[2 * MAXPATHLEN + 2];
#define OPTSTRING "bcCde:f:F:hikLm:nNprsvz0"
int longindex;
static const struct option long_options[] =
magicfile = usermagic;
else
if ((home = getenv("HOME")) != NULL) {
- if ((usermagic = malloc(strlen(home)
- + sizeof(hmagic))) != NULL) {
- (void)strcpy(usermagic, home);
- (void)strcat(usermagic, hmagic);
- if (stat(usermagic, &sb)<0)
- free(usermagic);
- else
- magicfile = usermagic;
+ (void)snprintf(magicpath, sizeof(magicpath), "%s%s",
+ home, hmagic);
+ if (access(magicpath, R_OK) == 0) {
+ (void)snprintf(magicpath, sizeof(magicpath),
+ "%s%s:%s", home, hmagic, magicfile);
+ magicfile = magicpath;
}
}
switch(action) {
case FILE_CHECK:
case FILE_COMPILE:
+ /*
+ * Don't try to check/compile ~/.magic unless we explicitly
+ * ask for it.
+ */
+ if (magicfile == magicpath)
+ magicfile = default_magicfile;
magic = magic_open(flags|MAGIC_CHECK);
if (magic == NULL) {
(void)fprintf(stderr, "%s: %s\n", progname,