1 /* Directory hashing for GNU Make.
2 Copyright (C) 1988,89,91,92,93,94,95,96,97 Free Software Foundation, Inc.
3 This file is part of GNU Make.
5 GNU Make is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 GNU Make is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNU Make; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
24 # define NAMLEN(dirent) strlen((dirent)->d_name)
26 extern char *vmsify
PARAMS ((char *name
, int type
));
29 # define dirent direct
30 # define NAMLEN(dirent) (dirent)->d_namlen
31 # ifdef HAVE_SYS_NDIR_H
32 # include <sys/ndir.h>
34 # ifdef HAVE_SYS_DIR_H
42 # endif /* HAVE_VMSDIR_H */
45 /* In GNU systems, <dirent.h> defines this macro for us. */
48 # define NAMLEN(d) _D_NAMLEN(d)
51 #if (defined (POSIX) || defined (VMS) || defined (WINDOWS32)) && !defined (__GNU_LIBRARY__)
52 /* Posix does not require that the d_ino field be present, and some
53 systems do not provide it. */
54 # define REAL_DIR_ENTRY(dp) 1
55 # define FAKE_DIR_ENTRY(dp)
57 # define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
58 # define FAKE_DIR_ENTRY(dp) (dp->d_ino = 1)
65 /* If it's MSDOS that doesn't have _USE_LFN, disable LFN support. */
74 static char dos_filename
[14];
78 if (filename
== 0 || _USE_LFN
)
81 /* FIXME: what about filenames which violate
82 8+3 constraints, like "config.h.in", or ".emacs"? */
83 if (strpbrk (filename
, "\"*+,;<=>?[\\]|") != 0)
88 /* First, transform the name part. */
89 for (i
= 0; *filename
!= '\0' && i
< 8 && *filename
!= '.'; ++i
)
90 *df
++ = tolower ((unsigned char)*filename
++);
92 /* Now skip to the next dot. */
93 while (*filename
!= '\0' && *filename
!= '.')
95 if (*filename
!= '\0')
98 for (i
= 0; *filename
!= '\0' && i
< 3 && *filename
!= '.'; ++i
)
99 *df
++ = tolower ((unsigned char)*filename
++);
102 /* Look for more dots. */
103 while (*filename
!= '\0' && *filename
!= '.')
105 if (*filename
== '.')
110 #endif /* __MSDOS__ */
113 #include "pathstuff.h"
120 #ifdef HAVE_CASE_INSENSITIVE_FS
126 static char new_filename
[136];
128 static char new_filename
[PATH_MAX
];
138 /* First, transform the name part. */
139 for (i
= 0; *filename
!= '\0'; ++i
)
141 *df
++ = tolower ((unsigned char)*filename
);
149 #endif /* HAVE_CASE_INSENSITIVE_FS */
162 h
= (h
<< 4) + (isupper (*name
) ? tolower (*name
) : *name
);
174 /* fake stat entry for a directory */
176 vmsstat_dir (name
, st
)
184 dir
= opendir (name
);
188 s
= strchr (name
, ':'); /* find device */
192 st
->st_dev
= (char *)vms_hash (name
);
203 st
->st_ino
[0] = h
& 0xff;
204 st
->st_ino
[1] = h
& 0xff00;
205 st
->st_ino
[2] = h
>> 16;
211 /* Hash table of directories. */
213 #ifndef DIRECTORY_BUCKETS
214 #define DIRECTORY_BUCKETS 199
217 struct directory_contents
219 struct directory_contents
*next
;
221 dev_t dev
; /* Device and inode numbers of this dir. */
224 * Inode means nothing on WINDOWS32. Even file key information is
225 * unreliable because it is random per file open and undefined
226 * for remote filesystems. The most unique attribute I can
227 * come up with is the fully qualified name of the directory. Beware
228 * though, this is also unreliable. I'm open to suggestion on a better
229 * way to emulate inode.
232 int mtime
; /* controls check for stale directory cache */
233 int fs_flags
; /* FS_FAT, FS_NTFS, ... */
236 #define FS_UNKNOWN 0x4
243 #endif /* WINDOWS32 */
244 struct dirfile
**files
; /* Files in this directory. */
245 DIR *dirstream
; /* Stream reading this directory. */
248 /* Table of directory contents hashed by device and inode number. */
249 static struct directory_contents
*directories_contents
[DIRECTORY_BUCKETS
];
253 struct directory
*next
;
255 char *name
; /* Name of the directory. */
257 /* The directory's contents. This data may be shared by several
258 entries in the hash table, which refer to the same directory
259 (identified uniquely by `dev' and `ino') under different names. */
260 struct directory_contents
*contents
;
263 /* Table of directories hashed by name. */
264 static struct directory
*directories
[DIRECTORY_BUCKETS
];
267 /* Never have more than this many directories open at once. */
269 #define MAX_OPEN_DIRECTORIES 10
271 static unsigned int open_directories
= 0;
274 /* Hash table of files in each directory. */
278 struct dirfile
*next
;
279 char *name
; /* Name of the file. */
280 char impossible
; /* This file is impossible. */
283 #ifndef DIRFILE_BUCKETS
284 #define DIRFILE_BUCKETS 107
287 static int dir_contents_file_exists_p
PARAMS ((struct directory_contents
*dir
, char *filename
));
288 static struct directory
*find_directory
PARAMS ((char *name
));
290 /* Find the directory named NAME and return its `struct directory'. */
292 static struct directory
*
293 find_directory (name
)
296 register unsigned int hash
= 0;
298 register struct directory
*dir
;
302 char fs_label
[BUFSIZ
];
303 char fs_type
[BUFSIZ
];
309 if ((*name
== '.') && (*(name
+1) == 0))
312 name
= vmsify (name
,1);
315 for (p
= name
; *p
!= '\0'; ++p
)
317 hash
%= DIRECTORY_BUCKETS
;
319 for (dir
= directories
[hash
]; dir
!= 0; dir
= dir
->next
)
320 if (strieq (dir
->name
, name
))
327 /* The directory was not found. Create a new entry for it. */
329 dir
= (struct directory
*) xmalloc (sizeof (struct directory
));
330 dir
->next
= directories
[hash
];
331 directories
[hash
] = dir
;
332 dir
->name
= savestring (name
, p
- name
);
334 /* The directory is not in the name hash table.
335 Find its device and inode numbers, and look it up by them. */
338 /* Remove any trailing '\'. Windows32 stat fails even on valid
339 directories if they end in '\'. */
345 r
= vmsstat_dir (name
, &st
);
347 r
= stat (name
, &st
);
351 /* Put back the trailing '\'. If we don't, we're permanently
352 truncating the value! */
359 /* Couldn't stat the directory. Mark this by
360 setting the `contents' member to a nil pointer. */
365 /* Search the contents hash table; device and inode are the key. */
367 struct directory_contents
*dc
;
370 w32_path
= w32ify(name
, 1);
371 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ctime
;
374 hash
= (((unsigned int) st
.st_dev
<< 16)
375 | ((unsigned int) st
.st_ino
[0]
376 + (unsigned int) st
.st_ino
[1]
377 + (unsigned int) st
.st_ino
[2]));
379 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ino
;
382 hash
%= DIRECTORY_BUCKETS
;
384 for (dc
= directories_contents
[hash
]; dc
!= 0; dc
= dc
->next
)
386 if (strieq(dc
->path_key
, w32_path
))
388 if (dc
->dev
== st
.st_dev
390 && dc
->ino
[0] == st
.st_ino
[0]
391 && dc
->ino
[1] == st
.st_ino
[1]
392 && dc
->ino
[2] == st
.st_ino
[2]
394 && dc
->ino
== st
.st_ino
397 #endif /* WINDOWS32 */
402 /* Nope; this really is a directory we haven't seen before. */
404 dc
= (struct directory_contents
*)
405 xmalloc (sizeof (struct directory_contents
));
407 /* Enter it in the contents hash table. */
410 dc
->path_key
= xstrdup(w32_path
);
411 dc
->mtime
= st
.st_mtime
;
414 * NTFS is the only WINDOWS32 filesystem that bumps mtime
415 * on a directory when files are added/deleted from
419 if (GetVolumeInformation(w32_path
,
420 fs_label
, sizeof (fs_label
),
422 &fs_flags
, fs_type
, sizeof (fs_type
)) == FALSE
)
423 dc
->fs_flags
= FS_UNKNOWN
;
424 else if (!strcmp(fs_type
, "FAT"))
425 dc
->fs_flags
= FS_FAT
;
426 else if (!strcmp(fs_type
, "NTFS"))
427 dc
->fs_flags
= FS_NTFS
;
429 dc
->fs_flags
= FS_UNKNOWN
;
432 dc
->ino
[0] = st
.st_ino
[0];
433 dc
->ino
[1] = st
.st_ino
[1];
434 dc
->ino
[2] = st
.st_ino
[2];
438 #endif /* WINDOWS32 */
439 dc
->next
= directories_contents
[hash
];
440 directories_contents
[hash
] = dc
;
442 dc
->dirstream
= opendir (name
);
443 if (dc
->dirstream
== 0)
444 /* Couldn't open the directory. Mark this by
445 setting the `files' member to a nil pointer. */
449 /* Allocate an array of buckets for files and zero it. */
450 dc
->files
= (struct dirfile
**)
451 xmalloc (sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
452 bzero ((char *) dc
->files
,
453 sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
455 /* Keep track of how many directories are open. */
457 if (open_directories
== MAX_OPEN_DIRECTORIES
)
458 /* We have too many directories open already.
459 Read the entire directory and then close it. */
460 (void) dir_contents_file_exists_p (dc
, (char *) 0);
464 /* Point the name-hashed entry for DIR at its contents data. */
472 /* Return 1 if the name FILENAME is entered in DIR's hash table.
473 FILENAME must contain no slashes. */
476 dir_contents_file_exists_p (dir
, filename
)
477 register struct directory_contents
*dir
;
478 register char *filename
;
480 register unsigned int hash
;
482 register struct dirfile
*df
;
483 register struct dirent
*d
;
489 if (dir
== 0 || dir
->files
== 0)
491 /* The directory could not be stat'd or opened. */
495 filename
= dosify (filename
);
498 #ifdef HAVE_CASE_INSENSITIVE_FS
499 filename
= downcase (filename
);
503 filename
= vmsify (filename
,0);
509 if (*filename
== '\0')
511 /* Checking if the directory exists. */
515 for (p
= filename
; *p
!= '\0'; ++p
)
517 hash
%= DIRFILE_BUCKETS
;
519 /* Search the list of hashed files. */
521 for (df
= dir
->files
[hash
]; df
!= 0; df
= df
->next
)
523 if (strieq (df
->name
, filename
))
525 return !df
->impossible
;
530 /* The file was not found in the hashed list.
531 Try to read the directory further. */
533 if (dir
->dirstream
== 0)
537 * Check to see if directory has changed since last read. FAT
538 * filesystems force a rehash always as mtime does not change
539 * on directories (ugh!).
542 (dir
->fs_flags
& FS_FAT
||
543 (stat(dir
->path_key
, &st
) == 0 &&
544 st
.st_mtime
> dir
->mtime
))) {
546 /* reset date stamp to show most recent re-process */
547 dir
->mtime
= st
.st_mtime
;
549 /* make sure directory can still be opened */
550 dir
->dirstream
= opendir(dir
->path_key
);
555 return 0; /* couldn't re-read - fail */
558 /* The directory has been all read in. */
562 while ((d
= readdir (dir
->dirstream
)) != 0)
564 /* Enter the file in the hash table. */
565 register unsigned int newhash
= 0;
567 register unsigned int i
;
569 #if defined(VMS) && defined(HAVE_DIRENT_H)
570 /* In VMS we get file versions too, which have to be stripped off */
572 char *p
= strrchr (d
->d_name
, ';');
577 if (!REAL_DIR_ENTRY (d
))
581 for (i
= 0; i
< len
; ++i
)
582 HASHI (newhash
, d
->d_name
[i
]);
583 newhash
%= DIRFILE_BUCKETS
;
586 * If re-reading a directory, check that this file isn't already
590 for (df
= dir
->files
[newhash
]; df
!= 0; df
= df
->next
)
591 if (streq(df
->name
, d
->d_name
))
597 * If re-reading a directory, don't cache files that have
598 * already been discovered.
603 df
= (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
604 df
->next
= dir
->files
[newhash
];
605 dir
->files
[newhash
] = df
;
606 df
->name
= savestring (d
->d_name
, len
);
611 /* Check if the name matches the one we're searching for. */
613 && newhash
== hash
&& strieq (d
->d_name
, filename
))
619 /* If the directory has been completely read in,
620 close the stream and reset the pointer to nil. */
624 closedir (dir
->dirstream
);
630 /* Return 1 if the name FILENAME in directory DIRNAME
631 is entered in the dir hash table.
632 FILENAME must contain no slashes. */
635 dir_file_exists_p (dirname
, filename
)
636 register char *dirname
;
637 register char *filename
;
639 return dir_contents_file_exists_p (find_directory (dirname
)->contents
,
643 /* Return 1 if the file named NAME exists. */
655 return ar_member_date (name
) != (time_t) -1;
659 dirend
= strrchr (name
, ']');
661 dirend
= strrchr (name
, ':');
663 if (dirend
== (char *)1)
664 return dir_file_exists_p ("[]", name
);
666 dirend
= strrchr (name
, '/');
667 #if defined (WINDOWS32) || defined (__MSDOS__)
668 /* Forward and backslashes might be mixed. We need the rightmost one. */
670 char *bslash
= strrchr(name
, '\\');
671 if (!dirend
|| bslash
> dirend
)
673 /* The case of "d:file". */
674 if (!dirend
&& name
[0] && name
[1] == ':')
677 #endif /* WINDOWS32 || __MSDOS__ */
680 return dir_file_exists_p (".", name
);
681 #else /* !VMS && !AMIGA */
682 return dir_file_exists_p ("", name
);
691 #if defined (WINDOWS32) || defined (__MSDOS__)
692 /* d:/ and d: are *very* different... */
693 if (dirend
< name
+ 3 && name
[1] == ':' &&
694 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
697 dirname
= (char *) alloca (dirend
- name
+ 1);
698 bcopy (name
, dirname
, dirend
- name
);
699 dirname
[dirend
- name
] = '\0';
701 return dir_file_exists_p (dirname
, slash
+ 1);
704 /* Mark FILENAME as `impossible' for `file_impossible_p'.
705 This means an attempt has been made to search for FILENAME
706 as an intermediate file, and it has failed. */
709 file_impossible (filename
)
710 register char *filename
;
713 register char *p
= filename
;
714 register unsigned int hash
;
715 register struct directory
*dir
;
716 register struct dirfile
*new;
719 dirend
= strrchr (p
, ']');
721 dirend
= strrchr (p
, ':');
723 if (dirend
== (char *)1)
724 dir
= find_directory ("[]");
726 dirend
= strrchr (p
, '/');
727 #if defined (WINDOWS32) || defined (__MSDOS__)
728 /* Forward and backslashes might be mixed. We need the rightmost one. */
730 char *bslash
= strrchr(p
, '\\');
731 if (!dirend
|| bslash
> dirend
)
733 /* The case of "d:file". */
734 if (!dirend
&& p
[0] && p
[1] == ':')
737 #endif /* WINDOWS32 or __MSDOS__ */
740 dir
= find_directory ("");
741 #else /* !VMS && !AMIGA */
742 dir
= find_directory (".");
748 char *slash
= dirend
;
753 #if defined (WINDOWS32) || defined (__MSDOS__)
754 /* d:/ and d: are *very* different... */
755 if (dirend
< p
+ 3 && p
[1] == ':' &&
756 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
759 dirname
= (char *) alloca (dirend
- p
+ 1);
760 bcopy (p
, dirname
, dirend
- p
);
761 dirname
[dirend
- p
] = '\0';
763 dir
= find_directory (dirname
);
764 filename
= p
= slash
+ 1;
767 for (hash
= 0; *p
!= '\0'; ++p
)
769 hash
%= DIRFILE_BUCKETS
;
771 if (dir
->contents
== 0)
773 /* The directory could not be stat'd. We allocate a contents
774 structure for it, but leave it out of the contents hash table. */
775 dir
->contents
= (struct directory_contents
*)
776 xmalloc (sizeof (struct directory_contents
));
778 dir
->contents
->path_key
= NULL
;
779 dir
->contents
->mtime
= 0;
780 #else /* WINDOWS32 */
782 dir
->contents
->dev
= 0;
783 dir
->contents
->ino
[0] = dir
->contents
->ino
[1] =
784 dir
->contents
->ino
[2] = 0;
786 dir
->contents
->dev
= dir
->contents
->ino
= 0;
788 #endif /* WINDOWS32 */
789 dir
->contents
->files
= 0;
790 dir
->contents
->dirstream
= 0;
793 if (dir
->contents
->files
== 0)
795 /* The directory was not opened; we must allocate the hash buckets. */
796 dir
->contents
->files
= (struct dirfile
**)
797 xmalloc (sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
798 bzero ((char *) dir
->contents
->files
,
799 sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
802 /* Make a new entry and put it in the table. */
804 new = (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
805 new->next
= dir
->contents
->files
[hash
];
806 dir
->contents
->files
[hash
] = new;
807 new->name
= xstrdup (filename
);
811 /* Return nonzero if FILENAME has been marked impossible. */
814 file_impossible_p (filename
)
818 register char *p
= filename
;
819 register unsigned int hash
;
820 register struct directory_contents
*dir
;
821 register struct dirfile
*next
;
824 dirend
= strrchr (filename
, ']');
826 dir
= find_directory ("[]")->contents
;
828 dirend
= strrchr (filename
, '/');
829 #if defined (WINDOWS32) || defined (__MSDOS__)
830 /* Forward and backslashes might be mixed. We need the rightmost one. */
832 char *bslash
= strrchr(filename
, '\\');
833 if (!dirend
|| bslash
> dirend
)
835 /* The case of "d:file". */
836 if (!dirend
&& filename
[0] && filename
[1] == ':')
837 dirend
= filename
+ 1;
839 #endif /* WINDOWS32 || __MSDOS__ */
842 dir
= find_directory ("")->contents
;
843 #else /* !VMS && !AMIGA */
844 dir
= find_directory (".")->contents
;
850 char *slash
= dirend
;
851 if (dirend
== filename
)
855 #if defined (WINDOWS32) || defined (__MSDOS__)
856 /* d:/ and d: are *very* different... */
857 if (dirend
< filename
+ 3 && filename
[1] == ':' &&
858 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
861 dirname
= (char *) alloca (dirend
- filename
+ 1);
862 bcopy (p
, dirname
, dirend
- p
);
863 dirname
[dirend
- p
] = '\0';
865 dir
= find_directory (dirname
)->contents
;
866 p
= filename
= slash
+ 1;
869 if (dir
== 0 || dir
->files
== 0)
870 /* There are no files entered for this directory. */
874 p
= filename
= dosify (p
);
876 #ifdef HAVE_CASE_INSENSITIVE_FS
877 p
= filename
= downcase (p
);
880 p
= filename
= vmsify (p
, 1);
883 for (hash
= 0; *p
!= '\0'; ++p
)
885 hash
%= DIRFILE_BUCKETS
;
887 for (next
= dir
->files
[hash
]; next
!= 0; next
= next
->next
)
888 if (strieq (filename
, next
->name
))
889 return next
->impossible
;
894 /* Return the already allocated name in the
895 directory hash table that matches DIR. */
901 return find_directory (dir
)->name
;
904 /* Print the data base of directories. */
907 print_dir_data_base ()
909 register unsigned int i
, dirs
, files
, impossible
;
910 register struct directory
*dir
;
912 puts (_("\n# Directories\n"));
914 dirs
= files
= impossible
= 0;
915 for (i
= 0; i
< DIRECTORY_BUCKETS
; ++i
)
916 for (dir
= directories
[i
]; dir
!= 0; dir
= dir
->next
)
919 if (dir
->contents
== 0)
920 printf (_("# %s: could not be stat'd.\n"), dir
->name
);
921 else if (dir
->contents
->files
== 0)
923 printf (_("# %s (key %s, mtime %d): could not be opened.\n"),
924 dir
->name
, dir
->contents
->path_key
,dir
->contents
->mtime
);
925 #else /* WINDOWS32 */
927 printf (_("# %s (device %d, inode [%d,%d,%d]): could not be opened.\n"),
928 dir
->name
, dir
->contents
->dev
,
929 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
930 dir
->contents
->ino
[2]);
932 printf (_("# %s (device %ld, inode %ld): could not be opened.\n"),
933 dir
->name
, (long int) dir
->contents
->dev
,
934 (long int) dir
->contents
->ino
);
936 #endif /* WINDOWS32 */
939 register unsigned int f
= 0, im
= 0;
940 register unsigned int j
;
941 register struct dirfile
*df
;
942 for (j
= 0; j
< DIRFILE_BUCKETS
; ++j
)
943 for (df
= dir
->contents
->files
[j
]; df
!= 0; df
= df
->next
)
949 printf (_("# %s (key %s, mtime %d): "),
950 dir
->name
, dir
->contents
->path_key
, dir
->contents
->mtime
);
951 #else /* WINDOWS32 */
953 printf (_("# %s (device %d, inode [%d,%d,%d]): "),
954 dir
->name
, dir
->contents
->dev
,
955 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
956 dir
->contents
->ino
[2]);
958 printf (_("# %s (device %ld, inode %ld): "),
960 (long)dir
->contents
->dev
, (long)dir
->contents
->ino
);
962 #endif /* WINDOWS32 */
964 fputs (_("No"), stdout
);
967 fputs (_(" files, "), stdout
);
969 fputs (_("no"), stdout
);
972 fputs (_(" impossibilities"), stdout
);
973 if (dir
->contents
->dirstream
== 0)
976 puts (_(" so far."));
982 fputs ("\n# ", stdout
);
984 fputs (_("No"), stdout
);
986 printf ("%u", files
);
987 fputs (_(" files, "), stdout
);
989 fputs (_("no"), stdout
);
991 printf ("%u", impossible
);
992 printf (_(" impossibilities in %u directories.\n"), dirs
);
995 /* Hooks for globbing. */
999 /* Structure describing state of iterating through a directory hash table. */
1003 struct directory_contents
*contents
; /* The directory being read. */
1005 unsigned int bucket
; /* Current hash bucket. */
1006 struct dirfile
*elt
; /* Current elt in bucket. */
1009 /* Forward declarations. */
1010 static __ptr_t open_dirstream
PARAMS ((const char *));
1011 static struct dirent
*read_dirstream
PARAMS ((__ptr_t
));
1014 open_dirstream (directory
)
1015 const char *directory
;
1017 struct dirstream
*new;
1018 struct directory
*dir
= find_directory ((char *)directory
);
1020 if (dir
->contents
== 0 || dir
->contents
->files
== 0)
1021 /* DIR->contents is nil if the directory could not be stat'd.
1022 DIR->contents->files is nil if it could not be opened. */
1025 /* Read all the contents of the directory now. There is no benefit
1026 in being lazy, since glob will want to see every file anyway. */
1028 (void) dir_contents_file_exists_p (dir
->contents
, (char *) 0);
1030 new = (struct dirstream
*) xmalloc (sizeof (struct dirstream
));
1031 new->contents
= dir
->contents
;
1033 new->elt
= new->contents
->files
[0];
1035 return (__ptr_t
) new;
1038 static struct dirent
*
1039 read_dirstream (stream
)
1042 struct dirstream
*const ds
= (struct dirstream
*) stream
;
1043 register struct dirfile
*df
;
1045 static unsigned int bufsz
;
1047 while (ds
->bucket
< DIRFILE_BUCKETS
)
1049 while ((df
= ds
->elt
) != 0)
1052 if (!df
->impossible
)
1054 /* The glob interface wants a `struct dirent',
1057 unsigned int len
= strlen (df
->name
) + 1;
1058 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1063 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1064 bufsz
= sizeof *d
- sizeof d
->d_name
+ len
;
1065 buf
= xmalloc (bufsz
);
1067 d
= (struct dirent
*) buf
;
1069 #ifdef _DIRENT_HAVE_D_NAMLEN
1070 d
->d_namlen
= len
- 1;
1072 #ifdef _DIRENT_HAVE_D_TYPE
1073 d
->d_type
= DT_UNKNOWN
;
1075 memcpy (d
->d_name
, df
->name
, len
);
1079 if (++ds
->bucket
== DIRFILE_BUCKETS
)
1081 ds
->elt
= ds
->contents
->files
[ds
->bucket
];
1095 /* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a
1096 * macro for stat64(). If stat is a macro, make a local wrapper function to
1103 # define local_stat stat
1105 static int local_stat (path
, buf
)
1109 return stat (path
, buf
);
1117 /* Bogus sunos4 compiler complains (!) about & before functions. */
1118 gl
->gl_opendir
= open_dirstream
;
1119 gl
->gl_readdir
= read_dirstream
;
1120 gl
->gl_closedir
= ansi_free
;
1121 gl
->gl_stat
= local_stat
;
1122 /* We don't bother setting gl_lstat, since glob never calls it.
1123 The slot is only there for compatibility with 4.4 BSD. */