/*
* Copyright (c) Christos Zoulas 2003.
* All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#include "patchlevel.h"
#ifndef lint
-FILE_RCSID("@(#)$File: magic.c,v 1.52 2008/07/03 15:53:10 christos Exp $")
+FILE_RCSID("@(#)$File: magic.c,v 1.53 2008/07/16 18:00:57 christos Exp $")
#endif /* lint */
-#ifndef PIPE_BUF
+#ifndef PIPE_BUF
/* Get the PIPE_BUF from pathconf */
#ifdef _PC_PIPE_BUF
#define PIPE_BUF pathconf(".", _PC_PIPE_BUF)
private void free_mlist(struct mlist *);
private void close_and_restore(const struct magic_set *, const char *, int,
const struct stat *);
-private int info_from_stat(struct magic_set *, mode_t);
+private int unreadable_info(struct magic_set *, mode_t, const char *);
#ifndef COMPILE_ONLY
private const char *file_or_fd(struct magic_set *, const char *, int);
#endif
if ((ms->c.li = CAST(struct level_info *, malloc(len))) == NULL)
goto free;
-
+
ms->haderr = 0;
ms->error = -1;
ms->mlist = NULL;
}
private int
-info_from_stat(struct magic_set *ms, mode_t md)
+unreadable_info(struct magic_set *ms, mode_t md, const char *file)
{
/* We cannot open it, but we were able to stat it. */
- if (md & 0222)
+ if (access(file, W_OK) == 0)
if (file_printf(ms, "writable, ") == -1)
return -1;
- if (md & 0111)
+ if (access(file, X_OK) == 0)
if (file_printf(ms, "executable, ") == -1)
return -1;
if (S_ISREG(md))
(void)strcat(strcpy(tmp, inname), ".exe");
if ((fd = open(tmp, flags)) < 0) {
#endif
- if (info_from_stat(ms, sb.st_mode) == -1)
+ if (unreadable_info(ms, sb.st_mode,
+#ifdef __CYGWIN
+ tmp
+#else
+ inname
+#endif
+ ) == -1)
goto done;
rv = 0;
goto done;
if (nbytes == 0) {
/* We can not read it, but we were able to stat it. */
- if (info_from_stat(ms, sb.st_mode) == -1)
+ if (unreadable_info(ms, sb.st_mode, inname) == -1)
goto done;
rv = 0;
goto done;
return NULL;
/*
* The main work is done here!
- * We have the file name and/or the data buffer to be identified.
+ * We have the file name and/or the data buffer to be identified.
*/
if (file_buffer(ms, -1, NULL, buf, nb) == -1) {
return NULL;