mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-09-08 11:43:43 +02:00
Reworked the file locking option as a command instead of as a
compile-time option. The behavior can now be controlled from within the program with "locking disable" or "locking enable".
This commit is contained in:
@@ -11,8 +11,6 @@
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
#ifdef FILE_LOCKS
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
@@ -166,5 +164,3 @@ FILE *flock_open(filename, mode, is_locked)
|
||||
done:
|
||||
return f;
|
||||
}
|
||||
|
||||
#endif /* FILE_LOCKS */
|
||||
|
||||
+22
-20
@@ -46,6 +46,8 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
|
||||
static HashTable expansionTable;
|
||||
static bool noTable = TRUE;
|
||||
|
||||
bool FileLocking = TRUE;
|
||||
|
||||
/* Limit on how long a single file name may be: */
|
||||
|
||||
#define MAXSIZE MAXPATHLEN
|
||||
@@ -454,11 +456,10 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||
p2 = file;
|
||||
if (PaExpand(&p2, &p1, MAXSIZE) < 0) return NULL;
|
||||
|
||||
#ifndef FILE_LOCKS
|
||||
return fopen(realName, mode);
|
||||
#else
|
||||
return flock_open(realName, mode, is_locked);
|
||||
#endif
|
||||
if (FileLocking)
|
||||
return flock_open(realName, mode, is_locked);
|
||||
else
|
||||
return fopen(realName, mode);
|
||||
}
|
||||
|
||||
/* If we were already given a full rooted file name,
|
||||
@@ -473,11 +474,11 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||
{
|
||||
(void) strncpy(realName, file, MAXSIZE-1);
|
||||
realName[MAXSIZE-1] = '\0';
|
||||
#ifndef FILE_LOCKS
|
||||
return fopen(realName, mode);
|
||||
#else
|
||||
return flock_open(realName, mode, is_locked);
|
||||
#endif
|
||||
|
||||
if (FileLocking)
|
||||
return flock_open(realName, mode, is_locked);
|
||||
else
|
||||
return fopen(realName, mode);
|
||||
}
|
||||
|
||||
/* Now try going through the path, one entry at a time. */
|
||||
@@ -485,11 +486,12 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||
while (nextName(&path, file, realName, MAXSIZE) != NULL)
|
||||
{
|
||||
if (*realName == 0) continue;
|
||||
#ifndef FILE_LOCKS
|
||||
f = fopen(realName, mode);
|
||||
#else
|
||||
f = flock_open(realName, mode, is_locked);
|
||||
#endif
|
||||
|
||||
if (FileLocking)
|
||||
f = flock_open(realName, mode, is_locked);
|
||||
else
|
||||
f = fopen(realName, mode);
|
||||
|
||||
if (f != NULL) return f;
|
||||
|
||||
// If any error other than "file not found" occurred,
|
||||
@@ -504,11 +506,11 @@ PaLockOpen(file, mode, ext, path, library, pRealName, is_locked)
|
||||
if (library == NULL) return NULL;
|
||||
while (nextName(&library, file, realName, MAXSIZE) != NULL)
|
||||
{
|
||||
#ifndef FILE_LOCKS
|
||||
f = fopen(realName, mode);
|
||||
#else
|
||||
f = flock_open(realName, mode, is_locked);
|
||||
#endif
|
||||
if (FileLocking)
|
||||
f = flock_open(realName, mode, is_locked);
|
||||
else
|
||||
f = fopen(realName, mode);
|
||||
|
||||
if (f != NULL) return f;
|
||||
|
||||
// If any error other than "file not found" occurred,
|
||||
|
||||
@@ -54,9 +54,7 @@ extern bool StrIsNumeric(char *);
|
||||
|
||||
extern int SetNoisyBool(bool *, char *, FILE *);
|
||||
|
||||
#ifdef FILE_LOCKS
|
||||
extern FILE *flock_open();
|
||||
#endif
|
||||
|
||||
/* The following macro takes an integer and returns another integer that
|
||||
* is the same as the first except that all the '1' bits are turned off,
|
||||
|
||||
Reference in New Issue
Block a user