1991-10-18 19:26:24 +00:00
|
|
|
|
/* Directory hashing for GNU Make.
|
1997-08-27 20:30:54 +00:00
|
|
|
|
Copyright (C) 1988,89,91,92,93,94,95,96,97 Free Software Foundation, Inc.
|
1991-10-18 19:26:24 +00:00
|
|
|
|
This file is part of GNU Make.
|
|
|
|
|
|
|
|
|
|
GNU Make is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
|
|
GNU Make is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with GNU Make; see the file COPYING. If not, write to
|
1999-03-05 05:55:11 +00:00
|
|
|
|
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
#include "make.h"
|
|
|
|
|
|
1996-03-01 17:45:37 +00:00
|
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
|
# include <dirent.h>
|
|
|
|
|
# define NAMLEN(dirent) strlen((dirent)->d_name)
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# ifdef VMS
|
|
|
|
|
extern char *vmsify PARAMS ((char *name, int type));
|
|
|
|
|
# endif
|
1996-03-01 17:45:37 +00:00
|
|
|
|
#else
|
|
|
|
|
# define dirent direct
|
|
|
|
|
# define NAMLEN(dirent) (dirent)->d_namlen
|
|
|
|
|
# ifdef HAVE_SYS_NDIR_H
|
|
|
|
|
# include <sys/ndir.h>
|
|
|
|
|
# endif
|
|
|
|
|
# ifdef HAVE_SYS_DIR_H
|
|
|
|
|
# include <sys/dir.h>
|
|
|
|
|
# endif
|
|
|
|
|
# ifdef HAVE_NDIR_H
|
|
|
|
|
# include <ndir.h>
|
|
|
|
|
# endif
|
1996-03-20 14:57:41 +00:00
|
|
|
|
# ifdef HAVE_VMSDIR_H
|
|
|
|
|
# include "vmsdir.h"
|
|
|
|
|
# endif /* HAVE_VMSDIR_H */
|
1996-03-01 17:45:37 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* In GNU systems, <dirent.h> defines this macro for us. */
|
|
|
|
|
#ifdef _D_NAMLEN
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# undef NAMLEN
|
|
|
|
|
# define NAMLEN(d) _D_NAMLEN(d)
|
1996-03-01 17:45:37 +00:00
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#if (defined (POSIX) || defined (VMS) || defined (WINDOWS32)) && !defined (__GNU_LIBRARY__)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* Posix does not require that the d_ino field be present, and some
|
|
|
|
|
systems do not provide it. */
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# define REAL_DIR_ENTRY(dp) 1
|
|
|
|
|
# define FAKE_DIR_ENTRY(dp)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
#else
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
|
|
|
|
|
# define FAKE_DIR_ENTRY(dp) (dp->d_ino = 1)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
#endif /* POSIX */
|
1992-10-09 17:35:07 +00:00
|
|
|
|
|
1994-07-25 23:01:19 +00:00
|
|
|
|
#ifdef __MSDOS__
|
1994-09-26 22:20:56 +00:00
|
|
|
|
#include <ctype.h>
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#include <fcntl.h>
|
|
|
|
|
|
|
|
|
|
/* If it's MSDOS that doesn't have _USE_LFN, disable LFN support. */
|
|
|
|
|
#ifndef _USE_LFN
|
|
|
|
|
#define _USE_LFN 0
|
1996-07-26 00:05:41 +00:00
|
|
|
|
#endif
|
1994-07-25 23:01:19 +00:00
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
dosify (filename)
|
|
|
|
|
char *filename;
|
|
|
|
|
{
|
|
|
|
|
static char dos_filename[14];
|
|
|
|
|
char *df;
|
|
|
|
|
int i;
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (filename == 0 || _USE_LFN)
|
1996-07-26 00:05:41 +00:00
|
|
|
|
return filename;
|
1994-07-25 23:01:19 +00:00
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
/* FIXME: what about filenames which violate
|
|
|
|
|
8+3 constraints, like "config.h.in", or ".emacs"? */
|
1994-07-25 23:01:19 +00:00
|
|
|
|
if (strpbrk (filename, "\"*+,;<=>?[\\]|") != 0)
|
|
|
|
|
return filename;
|
|
|
|
|
|
|
|
|
|
df = dos_filename;
|
|
|
|
|
|
|
|
|
|
/* First, transform the name part. */
|
|
|
|
|
for (i = 0; *filename != '\0' && i < 8 && *filename != '.'; ++i)
|
1999-10-15 07:00:58 +00:00
|
|
|
|
*df++ = tolower ((unsigned char)*filename++);
|
1994-07-25 23:01:19 +00:00
|
|
|
|
|
|
|
|
|
/* Now skip to the next dot. */
|
|
|
|
|
while (*filename != '\0' && *filename != '.')
|
|
|
|
|
++filename;
|
|
|
|
|
if (*filename != '\0')
|
|
|
|
|
{
|
|
|
|
|
*df++ = *filename++;
|
|
|
|
|
for (i = 0; *filename != '\0' && i < 3 && *filename != '.'; ++i)
|
1999-10-15 07:00:58 +00:00
|
|
|
|
*df++ = tolower ((unsigned char)*filename++);
|
1994-07-25 23:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Look for more dots. */
|
|
|
|
|
while (*filename != '\0' && *filename != '.')
|
|
|
|
|
++filename;
|
|
|
|
|
if (*filename == '.')
|
|
|
|
|
return filename;
|
|
|
|
|
*df = 0;
|
|
|
|
|
return dos_filename;
|
|
|
|
|
}
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif /* __MSDOS__ */
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#include "pathstuff.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#ifdef _AMIGA
|
|
|
|
|
#include <ctype.h>
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#endif
|
1996-05-13 18:38:20 +00:00
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#ifdef HAVE_CASE_INSENSITIVE_FS
|
1996-05-13 18:38:20 +00:00
|
|
|
|
static char *
|
1998-07-30 20:54:47 +00:00
|
|
|
|
downcase (filename)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
char *filename;
|
|
|
|
|
{
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#ifdef _AMIGA
|
|
|
|
|
static char new_filename[136];
|
|
|
|
|
#else
|
|
|
|
|
static char new_filename[PATH_MAX];
|
|
|
|
|
#endif
|
1996-05-13 18:38:20 +00:00
|
|
|
|
char *df;
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
if (filename == 0)
|
|
|
|
|
return 0;
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
df = new_filename;
|
1996-05-13 18:38:20 +00:00
|
|
|
|
|
|
|
|
|
/* First, transform the name part. */
|
|
|
|
|
for (i = 0; *filename != '\0'; ++i)
|
|
|
|
|
{
|
1999-10-15 07:00:58 +00:00
|
|
|
|
*df++ = tolower ((unsigned char)*filename);
|
1996-05-13 18:38:20 +00:00
|
|
|
|
++filename;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*df = 0;
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
return new_filename;
|
1996-05-13 18:38:20 +00:00
|
|
|
|
}
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#endif /* HAVE_CASE_INSENSITIVE_FS */
|
1996-05-13 18:38:20 +00:00
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
vms_hash (name)
|
|
|
|
|
char *name;
|
|
|
|
|
{
|
|
|
|
|
int h = 0;
|
|
|
|
|
int g;
|
|
|
|
|
|
|
|
|
|
while (*name)
|
|
|
|
|
{
|
2000-01-22 05:43:03 +00:00
|
|
|
|
h = (h << 4) + (isupper (*name) ? tolower (*name) : *name);
|
|
|
|
|
name++;
|
1996-03-20 14:57:41 +00:00
|
|
|
|
g = h & 0xf0000000;
|
|
|
|
|
if (g)
|
|
|
|
|
{
|
|
|
|
|
h = h ^ (g >> 24);
|
|
|
|
|
h = h ^ g;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return h;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* fake stat entry for a directory */
|
|
|
|
|
static int
|
|
|
|
|
vmsstat_dir (name, st)
|
|
|
|
|
char *name;
|
|
|
|
|
struct stat *st;
|
|
|
|
|
{
|
|
|
|
|
char *s;
|
|
|
|
|
int h;
|
|
|
|
|
DIR *dir;
|
|
|
|
|
|
|
|
|
|
dir = opendir (name);
|
|
|
|
|
if (dir == 0)
|
|
|
|
|
return -1;
|
|
|
|
|
closedir (dir);
|
|
|
|
|
s = strchr (name, ':'); /* find device */
|
|
|
|
|
if (s)
|
|
|
|
|
{
|
|
|
|
|
*s++ = 0;
|
|
|
|
|
st->st_dev = (char *)vms_hash (name);
|
1997-08-27 20:30:54 +00:00
|
|
|
|
h = vms_hash (s);
|
|
|
|
|
*(s-1) = ':';
|
1996-03-20 14:57:41 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
st->st_dev = 0;
|
|
|
|
|
s = name;
|
1997-08-27 20:30:54 +00:00
|
|
|
|
h = vms_hash (s);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
}
|
1997-08-27 20:30:54 +00:00
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
st->st_ino[0] = h & 0xff;
|
|
|
|
|
st->st_ino[1] = h & 0xff00;
|
|
|
|
|
st->st_ino[2] = h >> 16;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
#endif /* VMS */
|
1994-07-25 23:01:19 +00:00
|
|
|
|
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* Hash table of directories. */
|
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
#ifndef DIRECTORY_BUCKETS
|
|
|
|
|
#define DIRECTORY_BUCKETS 199
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct directory_contents
|
1991-10-18 19:26:24 +00:00
|
|
|
|
{
|
1992-10-09 17:35:07 +00:00
|
|
|
|
struct directory_contents *next;
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dev_t dev; /* Device and inode numbers of this dir. */
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
/*
|
1997-04-07 07:21:16 +00:00
|
|
|
|
* Inode means nothing on WINDOWS32. Even file key information is
|
1996-05-22 21:51:45 +00:00
|
|
|
|
* unreliable because it is random per file open and undefined
|
|
|
|
|
* for remote filesystems. The most unique attribute I can
|
|
|
|
|
* come up with is the fully qualified name of the directory. Beware
|
|
|
|
|
* though, this is also unreliable. I'm open to suggestion on a better
|
|
|
|
|
* way to emulate inode.
|
|
|
|
|
*/
|
|
|
|
|
char *path_key;
|
|
|
|
|
int mtime; /* controls check for stale directory cache */
|
1997-04-07 07:21:16 +00:00
|
|
|
|
int fs_flags; /* FS_FAT, FS_NTFS, ... */
|
|
|
|
|
#define FS_FAT 0x1
|
|
|
|
|
#define FS_NTFS 0x2
|
|
|
|
|
#define FS_UNKNOWN 0x4
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#else
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
ino_t ino[3];
|
|
|
|
|
#else
|
|
|
|
|
ino_t ino;
|
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* WINDOWS32 */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
struct dirfile **files; /* Files in this directory. */
|
|
|
|
|
DIR *dirstream; /* Stream reading this directory. */
|
|
|
|
|
};
|
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
/* Table of directory contents hashed by device and inode number. */
|
|
|
|
|
static struct directory_contents *directories_contents[DIRECTORY_BUCKETS];
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
struct directory
|
|
|
|
|
{
|
|
|
|
|
struct directory *next;
|
|
|
|
|
|
|
|
|
|
char *name; /* Name of the directory. */
|
|
|
|
|
|
|
|
|
|
/* The directory's contents. This data may be shared by several
|
|
|
|
|
entries in the hash table, which refer to the same directory
|
|
|
|
|
(identified uniquely by `dev' and `ino') under different names. */
|
|
|
|
|
struct directory_contents *contents;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Table of directories hashed by name. */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
static struct directory *directories[DIRECTORY_BUCKETS];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Never have more than this many directories open at once. */
|
|
|
|
|
|
|
|
|
|
#define MAX_OPEN_DIRECTORIES 10
|
|
|
|
|
|
|
|
|
|
static unsigned int open_directories = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Hash table of files in each directory. */
|
|
|
|
|
|
|
|
|
|
struct dirfile
|
|
|
|
|
{
|
|
|
|
|
struct dirfile *next;
|
|
|
|
|
char *name; /* Name of the file. */
|
|
|
|
|
char impossible; /* This file is impossible. */
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#ifndef DIRFILE_BUCKETS
|
1992-10-09 17:35:07 +00:00
|
|
|
|
#define DIRFILE_BUCKETS 107
|
1991-10-18 19:26:24 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
static int dir_contents_file_exists_p PARAMS ((struct directory_contents *dir, char *filename));
|
|
|
|
|
static struct directory *find_directory PARAMS ((char *name));
|
1992-10-09 17:35:07 +00:00
|
|
|
|
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* Find the directory named NAME and return its `struct directory'. */
|
|
|
|
|
|
|
|
|
|
static struct directory *
|
|
|
|
|
find_directory (name)
|
|
|
|
|
register char *name;
|
|
|
|
|
{
|
|
|
|
|
register unsigned int hash = 0;
|
|
|
|
|
register char *p;
|
|
|
|
|
register struct directory *dir;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
char* w32_path;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
char fs_label[BUFSIZ];
|
|
|
|
|
char fs_type[BUFSIZ];
|
|
|
|
|
long fs_serno;
|
|
|
|
|
long fs_flags;
|
|
|
|
|
long fs_len;
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#endif
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
if ((*name == '.') && (*(name+1) == 0))
|
|
|
|
|
name = "[]";
|
|
|
|
|
else
|
|
|
|
|
name = vmsify (name,1);
|
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
for (p = name; *p != '\0'; ++p)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
HASHI (hash, *p);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
hash %= DIRECTORY_BUCKETS;
|
|
|
|
|
|
|
|
|
|
for (dir = directories[hash]; dir != 0; dir = dir->next)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
if (strieq (dir->name, name))
|
1991-10-18 19:26:24 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (dir == 0)
|
|
|
|
|
{
|
1992-10-09 17:35:07 +00:00
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
|
|
/* The directory was not found. Create a new entry for it. */
|
|
|
|
|
|
1991-10-18 19:26:24 +00:00
|
|
|
|
dir = (struct directory *) xmalloc (sizeof (struct directory));
|
|
|
|
|
dir->next = directories[hash];
|
|
|
|
|
directories[hash] = dir;
|
|
|
|
|
dir->name = savestring (name, p - name);
|
1992-10-09 17:35:07 +00:00
|
|
|
|
|
|
|
|
|
/* The directory is not in the name hash table.
|
|
|
|
|
Find its device and inode numbers, and look it up by them. */
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
if (vmsstat_dir (name, &st) < 0)
|
|
|
|
|
#else
|
1999-07-22 04:20:14 +00:00
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# ifdef WINDOWS32
|
1999-07-22 04:20:14 +00:00
|
|
|
|
/* Remove any trailing '\'. Windows32 stat fails even on valid
|
|
|
|
|
directories if they end in '\'. */
|
|
|
|
|
if (p[-1] == '\\')
|
|
|
|
|
p[-1] = '\0';
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# endif
|
1995-12-12 03:37:15 +00:00
|
|
|
|
if (stat (name, &st) < 0)
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif
|
|
|
|
|
{
|
1992-10-09 17:35:07 +00:00
|
|
|
|
/* Couldn't stat the directory. Mark this by
|
|
|
|
|
setting the `contents' member to a nil pointer. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dir->contents = 0;
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1992-10-09 17:35:07 +00:00
|
|
|
|
/* Search the contents hash table; device and inode are the key. */
|
|
|
|
|
|
|
|
|
|
struct directory_contents *dc;
|
|
|
|
|
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
w32_path = w32ify(name, 1);
|
|
|
|
|
hash = ((unsigned int) st.st_dev << 16) | (unsigned int) st.st_ctime;
|
|
|
|
|
#else
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# ifdef VMS
|
|
|
|
|
hash = (((unsigned int) st.st_dev << 16)
|
|
|
|
|
| ((unsigned int) st.st_ino[0]
|
|
|
|
|
+ (unsigned int) st.st_ino[1]
|
|
|
|
|
+ (unsigned int) st.st_ino[2]));
|
|
|
|
|
# else
|
1992-10-09 17:35:07 +00:00
|
|
|
|
hash = ((unsigned int) st.st_dev << 16) | (unsigned int) st.st_ino;
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# endif
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif
|
1992-10-09 17:35:07 +00:00
|
|
|
|
hash %= DIRECTORY_BUCKETS;
|
|
|
|
|
|
|
|
|
|
for (dc = directories_contents[hash]; dc != 0; dc = dc->next)
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1998-07-30 20:54:47 +00:00
|
|
|
|
if (strieq(dc->path_key, w32_path))
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#else
|
1996-03-20 14:57:41 +00:00
|
|
|
|
if (dc->dev == st.st_dev
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# ifdef VMS
|
1996-03-20 14:57:41 +00:00
|
|
|
|
&& dc->ino[0] == st.st_ino[0]
|
|
|
|
|
&& dc->ino[1] == st.st_ino[1]
|
2000-01-22 05:43:03 +00:00
|
|
|
|
&& dc->ino[2] == st.st_ino[2]
|
|
|
|
|
# else
|
|
|
|
|
&& dc->ino == st.st_ino
|
|
|
|
|
# endif
|
|
|
|
|
)
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* WINDOWS32 */
|
1992-10-09 17:35:07 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
if (dc == 0)
|
|
|
|
|
{
|
|
|
|
|
/* Nope; this really is a directory we haven't seen before. */
|
|
|
|
|
|
|
|
|
|
dc = (struct directory_contents *)
|
|
|
|
|
xmalloc (sizeof (struct directory_contents));
|
|
|
|
|
|
|
|
|
|
/* Enter it in the contents hash table. */
|
|
|
|
|
dc->dev = st.st_dev;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1999-03-05 07:13:12 +00:00
|
|
|
|
dc->path_key = xstrdup(w32_path);
|
1996-05-22 21:51:45 +00:00
|
|
|
|
dc->mtime = st.st_mtime;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* NTFS is the only WINDOWS32 filesystem that bumps mtime
|
|
|
|
|
* on a directory when files are added/deleted from
|
|
|
|
|
* a directory.
|
|
|
|
|
*/
|
|
|
|
|
w32_path[3] = '\0';
|
|
|
|
|
if (GetVolumeInformation(w32_path,
|
|
|
|
|
fs_label, sizeof (fs_label),
|
|
|
|
|
&fs_serno, &fs_len,
|
|
|
|
|
&fs_flags, fs_type, sizeof (fs_type)) == FALSE)
|
|
|
|
|
dc->fs_flags = FS_UNKNOWN;
|
|
|
|
|
else if (!strcmp(fs_type, "FAT"))
|
|
|
|
|
dc->fs_flags = FS_FAT;
|
|
|
|
|
else if (!strcmp(fs_type, "NTFS"))
|
|
|
|
|
dc->fs_flags = FS_NTFS;
|
|
|
|
|
else
|
|
|
|
|
dc->fs_flags = FS_UNKNOWN;
|
1996-05-22 21:51:45 +00:00
|
|
|
|
#else
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# ifdef VMS
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dc->ino[0] = st.st_ino[0];
|
|
|
|
|
dc->ino[1] = st.st_ino[1];
|
|
|
|
|
dc->ino[2] = st.st_ino[2];
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# else
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dc->ino = st.st_ino;
|
2000-01-22 05:43:03 +00:00
|
|
|
|
# endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* WINDOWS32 */
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dc->next = directories_contents[hash];
|
|
|
|
|
directories_contents[hash] = dc;
|
|
|
|
|
|
|
|
|
|
dc->dirstream = opendir (name);
|
|
|
|
|
if (dc->dirstream == 0)
|
2000-01-22 05:43:03 +00:00
|
|
|
|
/* Couldn't open the directory. Mark this by
|
|
|
|
|
setting the `files' member to a nil pointer. */
|
|
|
|
|
dc->files = 0;
|
1992-10-09 17:35:07 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
/* Allocate an array of buckets for files and zero it. */
|
|
|
|
|
dc->files = (struct dirfile **)
|
|
|
|
|
xmalloc (sizeof (struct dirfile *) * DIRFILE_BUCKETS);
|
|
|
|
|
bzero ((char *) dc->files,
|
|
|
|
|
sizeof (struct dirfile *) * DIRFILE_BUCKETS);
|
|
|
|
|
|
|
|
|
|
/* Keep track of how many directories are open. */
|
|
|
|
|
++open_directories;
|
|
|
|
|
if (open_directories == MAX_OPEN_DIRECTORIES)
|
|
|
|
|
/* We have too many directories open already.
|
|
|
|
|
Read the entire directory and then close it. */
|
|
|
|
|
(void) dir_contents_file_exists_p (dc, (char *) 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Point the name-hashed entry for DIR at its contents data. */
|
|
|
|
|
dir->contents = dc;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dir;
|
|
|
|
|
}
|
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
/* Return 1 if the name FILENAME is entered in DIR's hash table.
|
1991-10-18 19:26:24 +00:00
|
|
|
|
FILENAME must contain no slashes. */
|
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
static int
|
|
|
|
|
dir_contents_file_exists_p (dir, filename)
|
|
|
|
|
register struct directory_contents *dir;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
register char *filename;
|
|
|
|
|
{
|
|
|
|
|
register unsigned int hash;
|
|
|
|
|
register char *p;
|
|
|
|
|
register struct dirfile *df;
|
1992-06-25 01:05:20 +00:00
|
|
|
|
register struct dirent *d;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
struct stat st;
|
|
|
|
|
int rehash = 0;
|
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
if (dir == 0 || dir->files == 0)
|
1996-03-20 14:57:41 +00:00
|
|
|
|
{
|
1992-10-09 17:35:07 +00:00
|
|
|
|
/* The directory could not be stat'd or opened. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1994-07-25 23:01:19 +00:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
filename = dosify (filename);
|
|
|
|
|
#endif
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#ifdef HAVE_CASE_INSENSITIVE_FS
|
|
|
|
|
filename = downcase (filename);
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
filename = vmsify (filename,0);
|
|
|
|
|
#endif
|
|
|
|
|
|
1991-10-18 19:26:24 +00:00
|
|
|
|
hash = 0;
|
|
|
|
|
if (filename != 0)
|
|
|
|
|
{
|
|
|
|
|
if (*filename == '\0')
|
1996-03-20 14:57:41 +00:00
|
|
|
|
{
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* Checking if the directory exists. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
for (p = filename; *p != '\0'; ++p)
|
|
|
|
|
HASH (hash, *p);
|
|
|
|
|
hash %= DIRFILE_BUCKETS;
|
|
|
|
|
|
|
|
|
|
/* Search the list of hashed files. */
|
|
|
|
|
|
|
|
|
|
for (df = dir->files[hash]; df != 0; df = df->next)
|
1996-03-20 14:57:41 +00:00
|
|
|
|
{
|
1996-05-13 18:38:20 +00:00
|
|
|
|
if (strieq (df->name, filename))
|
1996-03-20 14:57:41 +00:00
|
|
|
|
{
|
|
|
|
|
return !df->impossible;
|
|
|
|
|
}
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* The file was not found in the hashed list.
|
|
|
|
|
Try to read the directory further. */
|
|
|
|
|
|
|
|
|
|
if (dir->dirstream == 0)
|
1996-03-20 14:57:41 +00:00
|
|
|
|
{
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
|
|
|
|
/*
|
|
|
|
|
* Check to see if directory has changed since last read. FAT
|
|
|
|
|
* filesystems force a rehash always as mtime does not change
|
|
|
|
|
* on directories (ugh!).
|
|
|
|
|
*/
|
1996-05-22 21:51:45 +00:00
|
|
|
|
if (dir->path_key &&
|
1997-04-07 07:21:16 +00:00
|
|
|
|
(dir->fs_flags & FS_FAT ||
|
|
|
|
|
(stat(dir->path_key, &st) == 0 &&
|
|
|
|
|
st.st_mtime > dir->mtime))) {
|
1996-05-22 21:51:45 +00:00
|
|
|
|
|
|
|
|
|
/* reset date stamp to show most recent re-process */
|
|
|
|
|
dir->mtime = st.st_mtime;
|
|
|
|
|
|
|
|
|
|
/* make sure directory can still be opened */
|
|
|
|
|
dir->dirstream = opendir(dir->path_key);
|
|
|
|
|
|
|
|
|
|
if (dir->dirstream)
|
|
|
|
|
rehash = 1;
|
|
|
|
|
else
|
|
|
|
|
return 0; /* couldn't re-read - fail */
|
|
|
|
|
} else
|
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* The directory has been all read in. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
while ((d = readdir (dir->dirstream)) != 0)
|
|
|
|
|
{
|
|
|
|
|
/* Enter the file in the hash table. */
|
|
|
|
|
register unsigned int newhash = 0;
|
1993-06-02 20:56:37 +00:00
|
|
|
|
unsigned int len;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
register unsigned int i;
|
|
|
|
|
|
2000-01-22 05:43:03 +00:00
|
|
|
|
#if defined(VMS) && defined(HAVE_DIRENT_H)
|
|
|
|
|
/* In VMS we get file versions too, which have to be stripped off */
|
|
|
|
|
{
|
|
|
|
|
char *p = strrchr (d->d_name, ';');
|
|
|
|
|
if (p)
|
|
|
|
|
*p = '\0';
|
|
|
|
|
}
|
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (!REAL_DIR_ENTRY (d))
|
|
|
|
|
continue;
|
|
|
|
|
|
1996-03-01 17:45:37 +00:00
|
|
|
|
len = NAMLEN (d);
|
1993-06-02 20:56:37 +00:00
|
|
|
|
for (i = 0; i < len; ++i)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
HASHI (newhash, d->d_name[i]);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
newhash %= DIRFILE_BUCKETS;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
/*
|
|
|
|
|
* If re-reading a directory, check that this file isn't already
|
|
|
|
|
* in the cache.
|
|
|
|
|
*/
|
|
|
|
|
if (rehash) {
|
|
|
|
|
for (df = dir->files[newhash]; df != 0; df = df->next)
|
|
|
|
|
if (streq(df->name, d->d_name))
|
|
|
|
|
break;
|
|
|
|
|
} else
|
|
|
|
|
df = 0;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* If re-reading a directory, don't cache files that have
|
|
|
|
|
* already been discovered.
|
|
|
|
|
*/
|
|
|
|
|
if (!df) {
|
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
df = (struct dirfile *) xmalloc (sizeof (struct dirfile));
|
|
|
|
|
df->next = dir->files[newhash];
|
|
|
|
|
dir->files[newhash] = df;
|
1993-06-02 20:56:37 +00:00
|
|
|
|
df->name = savestring (d->d_name, len);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
df->impossible = 0;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* Check if the name matches the one we're searching for. */
|
|
|
|
|
if (filename != 0
|
1996-05-13 18:38:20 +00:00
|
|
|
|
&& newhash == hash && strieq (d->d_name, filename))
|
1996-03-20 14:57:41 +00:00
|
|
|
|
{
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If the directory has been completely read in,
|
|
|
|
|
close the stream and reset the pointer to nil. */
|
|
|
|
|
if (d == 0)
|
|
|
|
|
{
|
|
|
|
|
--open_directories;
|
|
|
|
|
closedir (dir->dirstream);
|
|
|
|
|
dir->dirstream = 0;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
1992-10-09 17:35:07 +00:00
|
|
|
|
|
|
|
|
|
/* Return 1 if the name FILENAME in directory DIRNAME
|
|
|
|
|
is entered in the dir hash table.
|
|
|
|
|
FILENAME must contain no slashes. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
dir_file_exists_p (dirname, filename)
|
|
|
|
|
register char *dirname;
|
|
|
|
|
register char *filename;
|
|
|
|
|
{
|
|
|
|
|
return dir_contents_file_exists_p (find_directory (dirname)->contents,
|
|
|
|
|
filename);
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
/* Return 1 if the file named NAME exists. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
file_exists_p (name)
|
|
|
|
|
register char *name;
|
|
|
|
|
{
|
|
|
|
|
char *dirend;
|
|
|
|
|
char *dirname;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
char *slash;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
#ifndef NO_ARCHIVES
|
|
|
|
|
if (ar_name (name))
|
|
|
|
|
return ar_member_date (name) != (time_t) -1;
|
|
|
|
|
#endif
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
1999-10-15 07:00:58 +00:00
|
|
|
|
dirend = strrchr (name, ']');
|
2000-01-22 05:43:03 +00:00
|
|
|
|
if (dirend == 0)
|
|
|
|
|
dirend = strrchr (name, ':');
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dirend++;
|
|
|
|
|
if (dirend == (char *)1)
|
|
|
|
|
return dir_file_exists_p ("[]", name);
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#else /* !VMS */
|
1999-10-15 07:00:58 +00:00
|
|
|
|
dirend = strrchr (name, '/');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#if defined (WINDOWS32) || defined (__MSDOS__)
|
|
|
|
|
/* Forward and backslashes might be mixed. We need the rightmost one. */
|
|
|
|
|
{
|
1999-10-15 07:00:58 +00:00
|
|
|
|
char *bslash = strrchr(name, '\\');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (!dirend || bslash > dirend)
|
|
|
|
|
dirend = bslash;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
/* The case of "d:file". */
|
|
|
|
|
if (!dirend && name[0] && name[1] == ':')
|
|
|
|
|
dirend = name + 1;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif /* WINDOWS32 || __MSDOS__ */
|
1996-05-13 18:38:20 +00:00
|
|
|
|
if (dirend == 0)
|
|
|
|
|
#ifndef _AMIGA
|
|
|
|
|
return dir_file_exists_p (".", name);
|
|
|
|
|
#else /* !VMS && !AMIGA */
|
|
|
|
|
return dir_file_exists_p ("", name);
|
|
|
|
|
#endif /* AMIGA */
|
|
|
|
|
#endif /* VMS */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
slash = dirend;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (dirend == name)
|
|
|
|
|
dirname = "/";
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#if defined (WINDOWS32) || defined (__MSDOS__)
|
|
|
|
|
/* d:/ and d: are *very* different... */
|
|
|
|
|
if (dirend < name + 3 && name[1] == ':' &&
|
|
|
|
|
(*dirend == '/' || *dirend == '\\' || *dirend == ':'))
|
|
|
|
|
dirend++;
|
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
dirname = (char *) alloca (dirend - name + 1);
|
|
|
|
|
bcopy (name, dirname, dirend - name);
|
|
|
|
|
dirname[dirend - name] = '\0';
|
|
|
|
|
}
|
1998-07-30 20:54:47 +00:00
|
|
|
|
return dir_file_exists_p (dirname, slash + 1);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Mark FILENAME as `impossible' for `file_impossible_p'.
|
|
|
|
|
This means an attempt has been made to search for FILENAME
|
|
|
|
|
as an intermediate file, and it has failed. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
file_impossible (filename)
|
|
|
|
|
register char *filename;
|
|
|
|
|
{
|
|
|
|
|
char *dirend;
|
|
|
|
|
register char *p = filename;
|
|
|
|
|
register unsigned int hash;
|
|
|
|
|
register struct directory *dir;
|
|
|
|
|
register struct dirfile *new;
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
1999-10-15 07:00:58 +00:00
|
|
|
|
dirend = strrchr (p, ']');
|
2000-01-22 05:43:03 +00:00
|
|
|
|
if (dirend == 0)
|
2000-02-05 07:50:47 +00:00
|
|
|
|
dirend = strrchr (p, ':');
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dirend++;
|
|
|
|
|
if (dirend == (char *)1)
|
|
|
|
|
dir = find_directory ("[]");
|
|
|
|
|
#else
|
1999-10-15 07:00:58 +00:00
|
|
|
|
dirend = strrchr (p, '/');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#if defined (WINDOWS32) || defined (__MSDOS__)
|
|
|
|
|
/* Forward and backslashes might be mixed. We need the rightmost one. */
|
|
|
|
|
{
|
1999-10-15 07:00:58 +00:00
|
|
|
|
char *bslash = strrchr(p, '\\');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (!dirend || bslash > dirend)
|
|
|
|
|
dirend = bslash;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
/* The case of "d:file". */
|
|
|
|
|
if (!dirend && p[0] && p[1] == ':')
|
|
|
|
|
dirend = p + 1;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif /* WINDOWS32 or __MSDOS__ */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (dirend == 0)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#ifdef _AMIGA
|
|
|
|
|
dir = find_directory ("");
|
|
|
|
|
#else /* !VMS && !AMIGA */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
dir = find_directory (".");
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#endif /* AMIGA */
|
|
|
|
|
#endif /* VMS */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1997-04-07 07:21:16 +00:00
|
|
|
|
char *dirname;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
char *slash = dirend;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (dirend == p)
|
|
|
|
|
dirname = "/";
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#if defined (WINDOWS32) || defined (__MSDOS__)
|
|
|
|
|
/* d:/ and d: are *very* different... */
|
|
|
|
|
if (dirend < p + 3 && p[1] == ':' &&
|
|
|
|
|
(*dirend == '/' || *dirend == '\\' || *dirend == ':'))
|
|
|
|
|
dirend++;
|
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
dirname = (char *) alloca (dirend - p + 1);
|
|
|
|
|
bcopy (p, dirname, dirend - p);
|
|
|
|
|
dirname[dirend - p] = '\0';
|
|
|
|
|
}
|
1991-10-18 19:26:24 +00:00
|
|
|
|
dir = find_directory (dirname);
|
1998-07-30 20:54:47 +00:00
|
|
|
|
filename = p = slash + 1;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (hash = 0; *p != '\0'; ++p)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
HASHI (hash, *p);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
hash %= DIRFILE_BUCKETS;
|
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
if (dir->contents == 0)
|
|
|
|
|
{
|
|
|
|
|
/* The directory could not be stat'd. We allocate a contents
|
|
|
|
|
structure for it, but leave it out of the contents hash table. */
|
|
|
|
|
dir->contents = (struct directory_contents *)
|
|
|
|
|
xmalloc (sizeof (struct directory_contents));
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1996-05-22 21:51:45 +00:00
|
|
|
|
dir->contents->path_key = NULL;
|
|
|
|
|
dir->contents->mtime = 0;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#else /* WINDOWS32 */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
dir->contents->dev = 0;
|
|
|
|
|
dir->contents->ino[0] = dir->contents->ino[1] =
|
|
|
|
|
dir->contents->ino[2] = 0;
|
|
|
|
|
#else
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dir->contents->dev = dir->contents->ino = 0;
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* WINDOWS32 */
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dir->contents->files = 0;
|
1992-10-12 18:05:41 +00:00
|
|
|
|
dir->contents->dirstream = 0;
|
1992-10-09 17:35:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dir->contents->files == 0)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
{
|
|
|
|
|
/* The directory was not opened; we must allocate the hash buckets. */
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dir->contents->files = (struct dirfile **)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
xmalloc (sizeof (struct dirfile) * DIRFILE_BUCKETS);
|
1992-10-09 17:35:07 +00:00
|
|
|
|
bzero ((char *) dir->contents->files,
|
|
|
|
|
sizeof (struct dirfile) * DIRFILE_BUCKETS);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Make a new entry and put it in the table. */
|
|
|
|
|
|
|
|
|
|
new = (struct dirfile *) xmalloc (sizeof (struct dirfile));
|
1992-10-09 17:35:07 +00:00
|
|
|
|
new->next = dir->contents->files[hash];
|
|
|
|
|
dir->contents->files[hash] = new;
|
1999-07-21 05:53:23 +00:00
|
|
|
|
new->name = xstrdup (filename);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
new->impossible = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return nonzero if FILENAME has been marked impossible. */
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
file_impossible_p (filename)
|
|
|
|
|
char *filename;
|
|
|
|
|
{
|
|
|
|
|
char *dirend;
|
|
|
|
|
register char *p = filename;
|
|
|
|
|
register unsigned int hash;
|
1992-10-09 17:35:07 +00:00
|
|
|
|
register struct directory_contents *dir;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
register struct dirfile *next;
|
|
|
|
|
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
1999-10-15 07:00:58 +00:00
|
|
|
|
dirend = strrchr (filename, ']');
|
1996-03-20 14:57:41 +00:00
|
|
|
|
if (dirend == 0)
|
|
|
|
|
dir = find_directory ("[]")->contents;
|
|
|
|
|
#else
|
1999-10-15 07:00:58 +00:00
|
|
|
|
dirend = strrchr (filename, '/');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#if defined (WINDOWS32) || defined (__MSDOS__)
|
|
|
|
|
/* Forward and backslashes might be mixed. We need the rightmost one. */
|
|
|
|
|
{
|
1999-10-15 07:00:58 +00:00
|
|
|
|
char *bslash = strrchr(filename, '\\');
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (!dirend || bslash > dirend)
|
|
|
|
|
dirend = bslash;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
/* The case of "d:file". */
|
|
|
|
|
if (!dirend && filename[0] && filename[1] == ':')
|
|
|
|
|
dirend = filename + 1;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
}
|
|
|
|
|
#endif /* WINDOWS32 || __MSDOS__ */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (dirend == 0)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#ifdef _AMIGA
|
|
|
|
|
dir = find_directory ("")->contents;
|
|
|
|
|
#else /* !VMS && !AMIGA */
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dir = find_directory (".")->contents;
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#endif /* AMIGA */
|
|
|
|
|
#endif /* VMS */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
1997-04-07 07:21:16 +00:00
|
|
|
|
char *dirname;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
char *slash = dirend;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
if (dirend == filename)
|
|
|
|
|
dirname = "/";
|
|
|
|
|
else
|
|
|
|
|
{
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#if defined (WINDOWS32) || defined (__MSDOS__)
|
|
|
|
|
/* d:/ and d: are *very* different... */
|
|
|
|
|
if (dirend < filename + 3 && filename[1] == ':' &&
|
|
|
|
|
(*dirend == '/' || *dirend == '\\' || *dirend == ':'))
|
|
|
|
|
dirend++;
|
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
dirname = (char *) alloca (dirend - filename + 1);
|
|
|
|
|
bcopy (p, dirname, dirend - p);
|
|
|
|
|
dirname[dirend - p] = '\0';
|
|
|
|
|
}
|
1992-10-09 17:35:07 +00:00
|
|
|
|
dir = find_directory (dirname)->contents;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
p = filename = slash + 1;
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
1992-10-09 17:35:07 +00:00
|
|
|
|
if (dir == 0 || dir->files == 0)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
/* There are no files entered for this directory. */
|
|
|
|
|
return 0;
|
|
|
|
|
|
1994-07-25 23:01:19 +00:00
|
|
|
|
#ifdef __MSDOS__
|
|
|
|
|
p = filename = dosify (p);
|
|
|
|
|
#endif
|
1998-07-30 20:54:47 +00:00
|
|
|
|
#ifdef HAVE_CASE_INSENSITIVE_FS
|
|
|
|
|
p = filename = downcase (p);
|
1996-05-13 18:38:20 +00:00
|
|
|
|
#endif
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
|
|
|
|
p = filename = vmsify (p, 1);
|
|
|
|
|
#endif
|
1994-07-25 23:01:19 +00:00
|
|
|
|
|
1991-10-18 19:26:24 +00:00
|
|
|
|
for (hash = 0; *p != '\0'; ++p)
|
|
|
|
|
HASH (hash, *p);
|
|
|
|
|
hash %= DIRFILE_BUCKETS;
|
|
|
|
|
|
|
|
|
|
for (next = dir->files[hash]; next != 0; next = next->next)
|
1996-05-13 18:38:20 +00:00
|
|
|
|
if (strieq (filename, next->name))
|
1991-10-18 19:26:24 +00:00
|
|
|
|
return next->impossible;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return the already allocated name in the
|
|
|
|
|
directory hash table that matches DIR. */
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
|
dir_name (dir)
|
|
|
|
|
char *dir;
|
|
|
|
|
{
|
|
|
|
|
return find_directory (dir)->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Print the data base of directories. */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
print_dir_data_base ()
|
|
|
|
|
{
|
|
|
|
|
register unsigned int i, dirs, files, impossible;
|
|
|
|
|
register struct directory *dir;
|
|
|
|
|
|
1999-07-28 06:23:37 +00:00
|
|
|
|
puts (_("\n# Directories\n"));
|
1991-10-18 19:26:24 +00:00
|
|
|
|
|
|
|
|
|
dirs = files = impossible = 0;
|
|
|
|
|
for (i = 0; i < DIRECTORY_BUCKETS; ++i)
|
|
|
|
|
for (dir = directories[i]; dir != 0; dir = dir->next)
|
|
|
|
|
{
|
|
|
|
|
++dirs;
|
1992-10-09 17:35:07 +00:00
|
|
|
|
if (dir->contents == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s: could not be stat'd.\n"), dir->name);
|
1992-10-09 17:35:07 +00:00
|
|
|
|
else if (dir->contents->files == 0)
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s (key %s, mtime %d): could not be opened.\n"),
|
1996-05-22 21:51:45 +00:00
|
|
|
|
dir->name, dir->contents->path_key,dir->contents->mtime);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#else /* WINDOWS32 */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s (device %d, inode [%d,%d,%d]): could not be opened.\n"),
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dir->name, dir->contents->dev,
|
|
|
|
|
dir->contents->ino[0], dir->contents->ino[1],
|
|
|
|
|
dir->contents->ino[2]);
|
|
|
|
|
#else
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s (device %ld, inode %ld): could not be opened.\n"),
|
1996-06-22 19:30:04 +00:00
|
|
|
|
dir->name, (long int) dir->contents->dev,
|
|
|
|
|
(long int) dir->contents->ino);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* WINDOWS32 */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
register unsigned int f = 0, im = 0;
|
|
|
|
|
register unsigned int j;
|
|
|
|
|
register struct dirfile *df;
|
|
|
|
|
for (j = 0; j < DIRFILE_BUCKETS; ++j)
|
1992-10-09 17:35:07 +00:00
|
|
|
|
for (df = dir->contents->files[j]; df != 0; df = df->next)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (df->impossible)
|
|
|
|
|
++im;
|
|
|
|
|
else
|
|
|
|
|
++f;
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#ifdef WINDOWS32
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s (key %s, mtime %d): "),
|
1996-05-22 21:51:45 +00:00
|
|
|
|
dir->name, dir->contents->path_key, dir->contents->mtime);
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#else /* WINDOWS32 */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#ifdef VMS
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s (device %d, inode [%d,%d,%d]): "),
|
1996-03-20 14:57:41 +00:00
|
|
|
|
dir->name, dir->contents->dev,
|
|
|
|
|
dir->contents->ino[0], dir->contents->ino[1],
|
|
|
|
|
dir->contents->ino[2]);
|
|
|
|
|
#else
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_("# %s (device %ld, inode %ld): "),
|
1998-07-30 20:54:47 +00:00
|
|
|
|
dir->name,
|
|
|
|
|
(long)dir->contents->dev, (long)dir->contents->ino);
|
1996-03-20 14:57:41 +00:00
|
|
|
|
#endif
|
1997-04-07 07:21:16 +00:00
|
|
|
|
#endif /* WINDOWS32 */
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (f == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_("No"), stdout);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
printf ("%u", f);
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_(" files, "), stdout);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (im == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_("no"), stdout);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
printf ("%u", im);
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_(" impossibilities"), stdout);
|
1992-10-09 17:35:07 +00:00
|
|
|
|
if (dir->contents->dirstream == 0)
|
1991-10-18 19:26:24 +00:00
|
|
|
|
puts (".");
|
|
|
|
|
else
|
1999-07-28 06:23:37 +00:00
|
|
|
|
puts (_(" so far."));
|
1991-10-18 19:26:24 +00:00
|
|
|
|
files += f;
|
|
|
|
|
impossible += im;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputs ("\n# ", stdout);
|
|
|
|
|
if (files == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_("No"), stdout);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
printf ("%u", files);
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_(" files, "), stdout);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
if (impossible == 0)
|
1999-07-28 06:23:37 +00:00
|
|
|
|
fputs (_("no"), stdout);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
else
|
|
|
|
|
printf ("%u", impossible);
|
1999-07-28 06:23:37 +00:00
|
|
|
|
printf (_(" impossibilities in %u directories.\n"), dirs);
|
1991-10-18 19:26:24 +00:00
|
|
|
|
}
|
1992-10-11 21:25:04 +00:00
|
|
|
|
|
|
|
|
|
/* Hooks for globbing. */
|
|
|
|
|
|
|
|
|
|
#include <glob.h>
|
|
|
|
|
|
|
|
|
|
/* Structure describing state of iterating through a directory hash table. */
|
|
|
|
|
|
|
|
|
|
struct dirstream
|
|
|
|
|
{
|
|
|
|
|
struct directory_contents *contents; /* The directory being read. */
|
|
|
|
|
|
|
|
|
|
unsigned int bucket; /* Current hash bucket. */
|
|
|
|
|
struct dirfile *elt; /* Current elt in bucket. */
|
|
|
|
|
};
|
|
|
|
|
|
1993-01-22 19:46:10 +00:00
|
|
|
|
/* Forward declarations. */
|
1996-03-20 14:57:41 +00:00
|
|
|
|
static __ptr_t open_dirstream PARAMS ((const char *));
|
|
|
|
|
static struct dirent *read_dirstream PARAMS ((__ptr_t));
|
1993-01-22 19:46:10 +00:00
|
|
|
|
|
1992-10-11 21:25:04 +00:00
|
|
|
|
static __ptr_t
|
|
|
|
|
open_dirstream (directory)
|
|
|
|
|
const char *directory;
|
|
|
|
|
{
|
|
|
|
|
struct dirstream *new;
|
1996-03-20 14:57:41 +00:00
|
|
|
|
struct directory *dir = find_directory ((char *)directory);
|
1992-10-11 21:25:04 +00:00
|
|
|
|
|
1992-11-10 20:43:35 +00:00
|
|
|
|
if (dir->contents == 0 || dir->contents->files == 0)
|
|
|
|
|
/* DIR->contents is nil if the directory could not be stat'd.
|
|
|
|
|
DIR->contents->files is nil if it could not be opened. */
|
1992-10-11 21:25:04 +00:00
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
/* Read all the contents of the directory now. There is no benefit
|
|
|
|
|
in being lazy, since glob will want to see every file anyway. */
|
|
|
|
|
|
|
|
|
|
(void) dir_contents_file_exists_p (dir->contents, (char *) 0);
|
|
|
|
|
|
|
|
|
|
new = (struct dirstream *) xmalloc (sizeof (struct dirstream));
|
|
|
|
|
new->contents = dir->contents;
|
|
|
|
|
new->bucket = 0;
|
|
|
|
|
new->elt = new->contents->files[0];
|
|
|
|
|
|
1992-10-15 23:11:04 +00:00
|
|
|
|
return (__ptr_t) new;
|
1992-10-11 21:25:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
1995-12-12 03:37:15 +00:00
|
|
|
|
static struct dirent *
|
1992-10-11 21:25:04 +00:00
|
|
|
|
read_dirstream (stream)
|
|
|
|
|
__ptr_t stream;
|
|
|
|
|
{
|
|
|
|
|
struct dirstream *const ds = (struct dirstream *) stream;
|
|
|
|
|
register struct dirfile *df;
|
1995-12-12 03:37:15 +00:00
|
|
|
|
static char *buf;
|
|
|
|
|
static unsigned int bufsz;
|
1992-10-11 21:25:04 +00:00
|
|
|
|
|
|
|
|
|
while (ds->bucket < DIRFILE_BUCKETS)
|
|
|
|
|
{
|
|
|
|
|
while ((df = ds->elt) != 0)
|
|
|
|
|
{
|
|
|
|
|
ds->elt = df->next;
|
|
|
|
|
if (!df->impossible)
|
1995-12-12 03:37:15 +00:00
|
|
|
|
{
|
|
|
|
|
/* The glob interface wants a `struct dirent',
|
|
|
|
|
so mock one up. */
|
|
|
|
|
struct dirent *d;
|
|
|
|
|
unsigned int len = strlen (df->name) + 1;
|
|
|
|
|
if (sizeof *d - sizeof d->d_name + len > bufsz)
|
|
|
|
|
{
|
|
|
|
|
if (buf != 0)
|
|
|
|
|
free (buf);
|
|
|
|
|
bufsz *= 2;
|
|
|
|
|
if (sizeof *d - sizeof d->d_name + len > bufsz)
|
|
|
|
|
bufsz = sizeof *d - sizeof d->d_name + len;
|
|
|
|
|
buf = xmalloc (bufsz);
|
1995-12-12 05:48:31 +00:00
|
|
|
|
}
|
|
|
|
|
d = (struct dirent *) buf;
|
|
|
|
|
FAKE_DIR_ENTRY (d);
|
1996-03-01 17:45:37 +00:00
|
|
|
|
#ifdef _DIRENT_HAVE_D_NAMLEN
|
1995-12-12 05:48:31 +00:00
|
|
|
|
d->d_namlen = len - 1;
|
2000-02-07 19:54:04 +00:00
|
|
|
|
#endif
|
|
|
|
|
#ifdef _DIRENT_HAVE_D_TYPE
|
|
|
|
|
d->d_type = DT_UNKNOWN;
|
1995-12-12 03:37:15 +00:00
|
|
|
|
#endif
|
1995-12-12 05:48:31 +00:00
|
|
|
|
memcpy (d->d_name, df->name, len);
|
|
|
|
|
return d;
|
1995-12-12 03:37:15 +00:00
|
|
|
|
}
|
1992-10-11 21:25:04 +00:00
|
|
|
|
}
|
1993-05-14 22:41:07 +00:00
|
|
|
|
if (++ds->bucket == DIRFILE_BUCKETS)
|
|
|
|
|
break;
|
|
|
|
|
ds->elt = ds->contents->files[ds->bucket];
|
1992-10-11 21:25:04 +00:00
|
|
|
|
}
|
1992-10-12 18:05:41 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
1992-10-11 21:25:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
1998-07-30 20:54:47 +00:00
|
|
|
|
static void
|
|
|
|
|
ansi_free(p)
|
|
|
|
|
void *p;
|
|
|
|
|
{
|
|
|
|
|
if (p)
|
|
|
|
|
free(p);
|
|
|
|
|
}
|
|
|
|
|
|
2000-02-07 19:54:04 +00:00
|
|
|
|
/* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a
|
|
|
|
|
* macro for stat64(). If stat is a macro, make a local wrapper function to
|
|
|
|
|
* invoke it.
|
|
|
|
|
*/
|
|
|
|
|
#ifndef stat
|
|
|
|
|
# ifndef VMS
|
|
|
|
|
extern int stat ();
|
|
|
|
|
# endif
|
|
|
|
|
# define local_stat stat
|
|
|
|
|
#else
|
|
|
|
|
static int local_stat (path, buf)
|
|
|
|
|
char *path;
|
|
|
|
|
struct stat *buf;
|
|
|
|
|
{
|
|
|
|
|
return stat (path, buf);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
1992-10-11 21:25:04 +00:00
|
|
|
|
void
|
1995-12-12 03:37:15 +00:00
|
|
|
|
dir_setup_glob (gl)
|
|
|
|
|
glob_t *gl;
|
1992-10-11 21:25:04 +00:00
|
|
|
|
{
|
1995-12-14 07:22:03 +00:00
|
|
|
|
/* Bogus sunos4 compiler complains (!) about & before functions. */
|
|
|
|
|
gl->gl_opendir = open_dirstream;
|
|
|
|
|
gl->gl_readdir = read_dirstream;
|
1998-07-30 20:54:47 +00:00
|
|
|
|
gl->gl_closedir = ansi_free;
|
2000-02-07 19:54:04 +00:00
|
|
|
|
gl->gl_stat = local_stat;
|
1995-12-14 07:22:03 +00:00
|
|
|
|
/* We don't bother setting gl_lstat, since glob never calls it.
|
|
|
|
|
The slot is only there for compatibility with 4.4 BSD. */
|
1992-10-11 21:25:04 +00:00
|
|
|
|
}
|