#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: apprentice.c,v 1.209 2014/05/13 16:42:17 christos Exp $")
+FILE_RCSID("@(#)$File: apprentice.c,v 1.210 2014/05/14 23:15:42 christos Exp $")
#endif /* lint */
#include "magic.h"
}
entries = (uint32_t)(st.st_size / sizeof(struct magic));
if ((off_t)(entries * sizeof(struct magic)) != st.st_size) {
- file_error(ms, 0, "Size of `%s' %llu is not a multiple of %zu",
+ file_error(ms, 0, "Size of `%s' %" INT64_T_FORMAT "u is not "
+ "a multiple of %" SIZE_T_FORMAT "u",
dbname, (unsigned long long)st.st_size,
sizeof(struct magic));
goto error;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: cdf_time.c,v 1.14 2014/04/17 12:44:01 christos Exp $")
+FILE_RCSID("@(#)$File: cdf_time.c,v 1.15 2014/05/14 23:15:42 christos Exp $")
#endif
#include <time.h>
char *ptr = ctime_r(sec, buf);
if (ptr != NULL)
return buf;
- (void)snprintf(buf, 26, "*Bad* 0x%16.16llx\n", (long long)*sec);
+ (void)snprintf(buf, 26, "*Bad* 0x%16.16" INT64_T_FORMAT "x\n",
+ (long long)*sec);
return buf;
}
*/
/*
* file.h - definitions for file(1) program
- * @(#)$File: file.h,v 1.150 2014/05/05 20:53:10 christos Exp $
+ * @(#)$File: file.h,v 1.151 2014/05/14 23:15:42 christos Exp $
*/
#ifndef __file_h__
#define private static
-#if HAVE_VISIBILITY
+#if HAVE_VISIBILITY && !defined(WIN32)
#define public __attribute__ ((__visibility__("default")))
#ifndef protected
#define protected __attribute__ ((__visibility__("hidden")))
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: fsmagic.c,v 1.72 2014/04/17 12:47:11 christos Exp $")
+FILE_RCSID("@(#)$File: fsmagic.c,v 1.73 2014/05/14 23:15:42 christos Exp $")
#endif /* lint */
#include "magic.h"
#ifdef major /* Might be defined in sys/types.h. */
# define HAVE_MAJOR
#endif
-
+#ifdef WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+#endif
+
#ifndef HAVE_MAJOR
# define major(dev) (((dev) >> 8) & 0xff)
# define minor(dev) ((dev) & 0xff)
#endif
ret = stat(fn, sb); /* don't merge into if; see "ret =" above */
+#ifdef WIN32
+ {
+ HANDLE hFile = CreateFile(fn, 0, FILE_SHARE_DELETE |
+ FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0,
+ NULL);
+ if (hFile != INVALID_HANDLE_VALUE) {
+ /*
+ * Stat failed, but we can still open it - assume it's
+ * a block device, if nothing else.
+ */
+ if (ret) {
+ sb->st_mode = S_IFBLK;
+ ret = 0;
+ }
+ switch (GetFileType(hFile)) {
+ case FILE_TYPE_CHAR:
+ sb->st_mode |= S_IFCHR;
+ sb->st_mode &= ~S_IFREG;
+ break;
+ case FILE_TYPE_PIPE:
+ sb->st_mode |= S_IFIFO;
+ sb->st_mode &= ~S_IFREG;
+ break;
+ }
+ CloseHandle(hFile);
+ }
+ }
+#endif
+
if (ret) {
if (ms->flags & MAGIC_ERROR) {
file_error(ms, errno, "cannot stat `%s'", fn);
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: funcs.c,v 1.71 2014/05/05 20:53:10 christos Exp $")
+FILE_RCSID("@(#)$File: funcs.c,v 1.72 2014/05/14 23:15:42 christos Exp $")
#endif /* lint */
#include "magic.h"
if (file_printf(ms, "%s", code_mime) == -1)
rv = -1;
}
+#if HAVE_FORK
done_encoding:
+#endif
free(u8buf);
if (rv)
return rv;
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.83 2014/05/13 16:44:24 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.84 2014/05/14 23:15:42 christos Exp $")
#endif /* lint */
#include "magic.h"
free(hmagicpath);
return MAGIC;
#else
- char *hmagicp = hmagicpath;
+ char *hmagicp;
char *tmppath = NULL;
+ hmagicpath = NULL;
#define APPENDPATH() \
do { \
goto done;
}
+#ifdef WIN32
+ /* Place stdin in binary mode, so EOF (Ctrl+Z) doesn't stop early. */
+ if (fd == STDIN_FILENO)
+ _setmode(STDIN_FILENO, O_BINARY);
+#endif
+
if (inname == NULL) {
if (fstat(fd, &sb) == 0 && S_ISFIFO(sb.st_mode))
ispipe = 1;
errno = 0;
if ((fd = open(inname, flags)) < 0) {
+#ifdef WIN32
+ /*
+ * Can't stat, can't open. It may have been opened in
+ * fsmagic, so if the user doesn't have read permission,
+ * allow it to say so; otherwise an error was probably
+ * displayed in fsmagic.
+ */
+ if (!okstat && errno == EACCES) {
+ sb.st_mode = S_IFBLK;
+ okstat = 1;
+ }
+#endif
if (okstat &&
unreadable_info(ms, sb.st_mode, inname) == -1)
goto done;
}
} else {
- if ((nbytes = read(fd, (char *)buf, HOWMANY)) == -1) {
- file_error(ms, errno, "cannot read `%s'", inname);
+ /* Windows refuses to read from a big console buffer. */
+ size_t howmany =
+#if defined(WIN32) && HOWMANY > 8 * 1024
+ _isatty(fd) ? 8 * 1024 :
+#endif
+ HOWMANY;
+ if ((nbytes = read(fd, (char *)buf, howmany)) == -1) {
+ if (inname == NULL && fd != STDIN_FILENO)
+ file_error(ms, errno, "cannot read fd %d", fd);
+ else
+ file_error(ms, errno, "cannot read `%s'",
+ inname == NULL ? "/dev/stdin" : inname);
goto done;
}
}
#include "file.h"
#ifndef lint
-FILE_RCSID("@(#)$File: softmagic.c,v 1.187 2014/05/13 16:42:17 christos Exp $")
+FILE_RCSID("@(#)$File: softmagic.c,v 1.188 2014/05/14 23:15:42 christos Exp $")
#endif /* lint */
#include "magic.h"
case -1:
return -1;
case 1:
- (void)snprintf(buf, sizeof(buf), "%llu",
+ (void)snprintf(buf, sizeof(buf), "%" INT64_T_FORMAT "u",
(unsigned long long)v);
if (file_printf(ms, F(ms, m, "%s"), buf) == -1)
return -1;
break;
default:
- if (file_printf(ms, F(ms, m, "%llu"),
+ if (file_printf(ms, F(ms, m, "%" INT64_T_FORMAT "u"),
(unsigned long long) v) == -1)
return -1;
break;