-# Makefile.in generated by automake 1.7.3 from Makefile.am.
+# Makefile.in generated by automake 1.7.2 from Makefile.am.
# @configure_input@
-# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
# Free Software Foundation, Inc.
# This Makefile.in is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
am__include = @am__include@
-am__leading_dot = @am__leading_dot@
am__quote = @am__quote@
bindir = @bindir@
build = @build@
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: file.c,v 1.78 2003/07/10 17:01:38 christos Exp $")
+FILE_RCSID("@(#)$Id: file.c,v 1.79 2003/07/10 17:41:24 christos Exp $")
#endif /* lint */
bflag = 0, /* brief output format */
nopad = 0, /* Don't pad output */
nobuffer = 0, /* Do not buffer stdout */
- kflag = 0; /* Keep going after the first match */
+ kflag = 0, /* Keep going after the first match */
+ rflag = 0; /* Restore access times of files */
private const char *magicfile = 0; /* where the magic is */
private const char *default_magicfile = MAGIC;
int flags = 0;
char *mime, *home, *usermagic;
struct stat sb;
-#define OPTSTRING "bcdf:F:ikm:nNsvzCL"
+#define OPTSTRING "bcCdf:F:ikLm:nNpsvz"
#ifdef HAVE_GETOPT_LONG
int longindex;
private struct option long_options[] =
{"dereference", 0, 0, 'L'},
#endif
{"magic-file", 1, 0, 'm'},
+#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
+ {"preserve-dates", 0, 0, 'p'},
+#endif
{"uncompress", 0, 0, 'z'},
{"no-buffer", 0, 0, 'n'},
{"no-pad", 0, 0, 'N'},
case 'N':
++nopad;
break;
+#if defined(HAVE_UTIME) || defined(HAVE_UTIMES)
+ case 'p':
+ flags |= MAGIC_PRESERVE_ATIME;
+ break;
+#endif
case 's':
flags |= MAGIC_DEVICES;
break;
#ifdef QUICK
#include <sys/mman.h>
#endif
-#ifdef RESTORE_TIME
-# if (__COHERENT__ >= 0x420)
+
+#if defined(HAVE_UTIME)
+# if defined(HAVE_SYS_UTIME_H)
# include <sys/utime.h>
-# else
-# ifdef USE_UTIMES
-# include <sys/time.h>
-# else
-# include <utime.h>
-# endif
+# elif defined(HAVE_UTIME_H)
+# include <utime.h>
# endif
+#elif defined(HAVE_UTIMES)
+# include <sys/time.h>
#endif
+
#ifdef HAVE_UNISTD_H
#include <unistd.h> /* for read() */
#endif
+
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$Id: magic.c,v 1.8 2003/06/10 18:28:37 christos Exp $")
+FILE_RCSID("@(#)$Id: magic.c,v 1.9 2003/07/10 17:41:24 christos Exp $")
#endif /* lint */
#ifdef __EMX__
#endif
private void free_mlist(struct mlist *);
+private void close_and_restore(const struct magic_set *, const char *, int,
+ const struct stat *);
public struct magic_set *
magic_open(int flags)
{
struct magic_set *ms;
+ if (magic_setflags(ms, flags) == -1) {
+ errno = EINVAL;
+ return NULL;
+ }
+
if ((ms = malloc(sizeof(struct magic_set))) == NULL)
return NULL;
ms->o.ptr = ms->o.buf = malloc(ms->o.size = 1024);
free(ms);
return NULL;
}
- ms->flags = flags;
ms->haderr = 0;
ms->mlist = NULL;
return ms;
return ml ? 0 : -1;
}
+private void
+close_and_restore(const struct magic_set *ms, const char *name, int fd,
+ const struct stat *sb)
+{
+ (void) close(fd);
+ if (fd != STDIN_FILENO && (ms->flags & MAGIC_PRESERVE_ATIME) != 0) {
+ /*
+ * Try to restore access, modification times if read it.
+ * This is really *bad* because it will modify the status
+ * time of the file... And of course this will affect
+ * backup programs
+ */
+#ifdef HAVE_UTIMES
+ struct timeval utsbuf[2];
+ utsbuf[0].tv_sec = sb->st_atime;
+ utsbuf[1].tv_sec = sb->st_mtime;
+
+ (void) utimes(name, utsbuf); /* don't care if loses */
+#elif defined(HAVE_UTIME_H) || defined(HAVE_SYS_UTIME_H)
+ struct utimbuf utbuf;
+
+ utbuf.actime = sb->st_atime;
+ utbuf.modtime = sb->st_mtime;
+ (void) utime(name, &utbuf); /* don't care if loses */
+#endif
+ }
+}
+
/*
* find type of named file
*/
*/
if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
file_error(ms, "Cannot read `%s' %s", inname, strerror(errno));
- (void)close(fd);
- return NULL;
+ goto done;
}
if (nbytes == 0) {
if (file_printf(ms, (ms->flags & MAGIC_MIME) ?
"application/x-empty" : "empty") == -1) {
(void)close(fd);
- return NULL;
+ goto done;
}
} else {
buf[nbytes++] = '\0'; /* null-terminate it */
#ifdef __EMX__
switch (file_os2_apptype(ms, inname, buf, nbytes)) {
case -1:
- (void)close(fd);
- return NULL;
+ goto done;
case 0:
break;
default:
return ms->o.buf;
}
#endif
- if (file_buffer(ms, buf, (size_t)nbytes) == -1) {
- (void)close(fd);
- return NULL;
- }
+ if (file_buffer(ms, buf, (size_t)nbytes) == -1)
+ goto done;
#ifdef BUILTIN_ELF
if (nbytes > 5) {
/*
#endif
}
- close(fd);
+ close_and_restore(ms, inname, fd, &sb);
return ms->haderr ? NULL : ms->o.buf;
+done:
+ close_and_restore(ms, inname, fd, &sb);
+ return NULL;
}
return ms->haderr ? ms->o.buf : NULL;
}
-public void
+public int
magic_setflags(struct magic_set *ms, int flags)
{
+#if !defined(HAVE_UTIME) && !defined(HAVE_UTIMES)
+ if (flags & MAGIC_PRESERVE_ATIME)
+ return -1;
+#endif
ms->flags = flags;
+ return 0;
}
#include <sys/types.h>
-#define MAGIC_NONE 0x00 /* No flags */
-#define MAGIC_DEBUG 0x01 /* Turn on debugging */
-#define MAGIC_SYMLINK 0x02 /* Follow symlinks */
-#define MAGIC_COMPRESS 0x04 /* Check inside compressed files */
-#define MAGIC_DEVICES 0x08 /* Look at the contents of devices */
-#define MAGIC_MIME 0x10 /* Return a mime string */
-#define MAGIC_CONTINUE 0x20 /* Return all matches, not just the first */
-#define MAGIC_CHECK 0x40 /* Print warnings to stderr */
+#define MAGIC_NONE 0x00 /* No flags */
+#define MAGIC_DEBUG 0x01 /* Turn on debugging */
+#define MAGIC_SYMLINK 0x02 /* Follow symlinks */
+#define MAGIC_COMPRESS 0x04 /* Check inside compressed files */
+#define MAGIC_DEVICES 0x08 /* Look at the contents of devices */
+#define MAGIC_MIME 0x10 /* Return a mime string */
+#define MAGIC_CONTINUE 0x20 /* Return all matches */
+#define MAGIC_CHECK 0x40 /* Print warnings to stderr */
+#define MAGIC_PRESERVE_ATIME 0x80 /* Restore access time on exit */
#ifdef __cplusplus
const char *magic_buffer(magic_t, const void *, size_t);
const char *magic_error(magic_t);
-void magic_setflags(magic_t, int);
+int magic_setflags(magic_t, int);
int magic_load(magic_t, const char *);
int magic_compile(magic_t, const char *);