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
;
301 char fs_label
[BUFSIZ
];
302 char fs_type
[BUFSIZ
];
308 if ((*name
== '.') && (*(name
+1) == 0))
311 name
= vmsify (name
,1);
314 for (p
= name
; *p
!= '\0'; ++p
)
316 hash
%= DIRECTORY_BUCKETS
;
318 for (dir
= directories
[hash
]; dir
!= 0; dir
= dir
->next
)
319 if (strieq (dir
->name
, name
))
326 /* The directory was not found. Create a new entry for it. */
328 dir
= (struct directory
*) xmalloc (sizeof (struct directory
));
329 dir
->next
= directories
[hash
];
330 directories
[hash
] = dir
;
331 dir
->name
= savestring (name
, p
- name
);
333 /* The directory is not in the name hash table.
334 Find its device and inode numbers, and look it up by them. */
337 if (vmsstat_dir (name
, &st
) < 0)
341 /* Remove any trailing '\'. Windows32 stat fails even on valid
342 directories if they end in '\'. */
346 if (stat (name
, &st
) < 0)
349 /* Couldn't stat the directory. Mark this by
350 setting the `contents' member to a nil pointer. */
355 /* Search the contents hash table; device and inode are the key. */
357 struct directory_contents
*dc
;
360 w32_path
= w32ify(name
, 1);
361 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ctime
;
364 hash
= (((unsigned int) st
.st_dev
<< 16)
365 | ((unsigned int) st
.st_ino
[0]
366 + (unsigned int) st
.st_ino
[1]
367 + (unsigned int) st
.st_ino
[2]));
369 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ino
;
372 hash
%= DIRECTORY_BUCKETS
;
374 for (dc
= directories_contents
[hash
]; dc
!= 0; dc
= dc
->next
)
376 if (strieq(dc
->path_key
, w32_path
))
378 if (dc
->dev
== st
.st_dev
380 && dc
->ino
[0] == st
.st_ino
[0]
381 && dc
->ino
[1] == st
.st_ino
[1]
382 && dc
->ino
[2] == st
.st_ino
[2]
384 && dc
->ino
== st
.st_ino
387 #endif /* WINDOWS32 */
392 /* Nope; this really is a directory we haven't seen before. */
394 dc
= (struct directory_contents
*)
395 xmalloc (sizeof (struct directory_contents
));
397 /* Enter it in the contents hash table. */
400 dc
->path_key
= xstrdup(w32_path
);
401 dc
->mtime
= st
.st_mtime
;
404 * NTFS is the only WINDOWS32 filesystem that bumps mtime
405 * on a directory when files are added/deleted from
409 if (GetVolumeInformation(w32_path
,
410 fs_label
, sizeof (fs_label
),
412 &fs_flags
, fs_type
, sizeof (fs_type
)) == FALSE
)
413 dc
->fs_flags
= FS_UNKNOWN
;
414 else if (!strcmp(fs_type
, "FAT"))
415 dc
->fs_flags
= FS_FAT
;
416 else if (!strcmp(fs_type
, "NTFS"))
417 dc
->fs_flags
= FS_NTFS
;
419 dc
->fs_flags
= FS_UNKNOWN
;
422 dc
->ino
[0] = st
.st_ino
[0];
423 dc
->ino
[1] = st
.st_ino
[1];
424 dc
->ino
[2] = st
.st_ino
[2];
428 #endif /* WINDOWS32 */
429 dc
->next
= directories_contents
[hash
];
430 directories_contents
[hash
] = dc
;
432 dc
->dirstream
= opendir (name
);
433 if (dc
->dirstream
== 0)
434 /* Couldn't open the directory. Mark this by
435 setting the `files' member to a nil pointer. */
439 /* Allocate an array of buckets for files and zero it. */
440 dc
->files
= (struct dirfile
**)
441 xmalloc (sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
442 bzero ((char *) dc
->files
,
443 sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
445 /* Keep track of how many directories are open. */
447 if (open_directories
== MAX_OPEN_DIRECTORIES
)
448 /* We have too many directories open already.
449 Read the entire directory and then close it. */
450 (void) dir_contents_file_exists_p (dc
, (char *) 0);
454 /* Point the name-hashed entry for DIR at its contents data. */
462 /* Return 1 if the name FILENAME is entered in DIR's hash table.
463 FILENAME must contain no slashes. */
466 dir_contents_file_exists_p (dir
, filename
)
467 register struct directory_contents
*dir
;
468 register char *filename
;
470 register unsigned int hash
;
472 register struct dirfile
*df
;
473 register struct dirent
*d
;
479 if (dir
== 0 || dir
->files
== 0)
481 /* The directory could not be stat'd or opened. */
485 filename
= dosify (filename
);
488 #ifdef HAVE_CASE_INSENSITIVE_FS
489 filename
= downcase (filename
);
493 filename
= vmsify (filename
,0);
499 if (*filename
== '\0')
501 /* Checking if the directory exists. */
505 for (p
= filename
; *p
!= '\0'; ++p
)
507 hash
%= DIRFILE_BUCKETS
;
509 /* Search the list of hashed files. */
511 for (df
= dir
->files
[hash
]; df
!= 0; df
= df
->next
)
513 if (strieq (df
->name
, filename
))
515 return !df
->impossible
;
520 /* The file was not found in the hashed list.
521 Try to read the directory further. */
523 if (dir
->dirstream
== 0)
527 * Check to see if directory has changed since last read. FAT
528 * filesystems force a rehash always as mtime does not change
529 * on directories (ugh!).
532 (dir
->fs_flags
& FS_FAT
||
533 (stat(dir
->path_key
, &st
) == 0 &&
534 st
.st_mtime
> dir
->mtime
))) {
536 /* reset date stamp to show most recent re-process */
537 dir
->mtime
= st
.st_mtime
;
539 /* make sure directory can still be opened */
540 dir
->dirstream
= opendir(dir
->path_key
);
545 return 0; /* couldn't re-read - fail */
548 /* The directory has been all read in. */
552 while ((d
= readdir (dir
->dirstream
)) != 0)
554 /* Enter the file in the hash table. */
555 register unsigned int newhash
= 0;
557 register unsigned int i
;
559 #if defined(VMS) && defined(HAVE_DIRENT_H)
560 /* In VMS we get file versions too, which have to be stripped off */
562 char *p
= strrchr (d
->d_name
, ';');
567 if (!REAL_DIR_ENTRY (d
))
571 for (i
= 0; i
< len
; ++i
)
572 HASHI (newhash
, d
->d_name
[i
]);
573 newhash
%= DIRFILE_BUCKETS
;
576 * If re-reading a directory, check that this file isn't already
580 for (df
= dir
->files
[newhash
]; df
!= 0; df
= df
->next
)
581 if (streq(df
->name
, d
->d_name
))
587 * If re-reading a directory, don't cache files that have
588 * already been discovered.
593 df
= (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
594 df
->next
= dir
->files
[newhash
];
595 dir
->files
[newhash
] = df
;
596 df
->name
= savestring (d
->d_name
, len
);
601 /* Check if the name matches the one we're searching for. */
603 && newhash
== hash
&& strieq (d
->d_name
, filename
))
609 /* If the directory has been completely read in,
610 close the stream and reset the pointer to nil. */
614 closedir (dir
->dirstream
);
620 /* Return 1 if the name FILENAME in directory DIRNAME
621 is entered in the dir hash table.
622 FILENAME must contain no slashes. */
625 dir_file_exists_p (dirname
, filename
)
626 register char *dirname
;
627 register char *filename
;
629 return dir_contents_file_exists_p (find_directory (dirname
)->contents
,
633 /* Return 1 if the file named NAME exists. */
645 return ar_member_date (name
) != (time_t) -1;
649 dirend
= strrchr (name
, ']');
651 dirend
= strrchr (name
, ':');
653 if (dirend
== (char *)1)
654 return dir_file_exists_p ("[]", name
);
656 dirend
= strrchr (name
, '/');
657 #if defined (WINDOWS32) || defined (__MSDOS__)
658 /* Forward and backslashes might be mixed. We need the rightmost one. */
660 char *bslash
= strrchr(name
, '\\');
661 if (!dirend
|| bslash
> dirend
)
663 /* The case of "d:file". */
664 if (!dirend
&& name
[0] && name
[1] == ':')
667 #endif /* WINDOWS32 || __MSDOS__ */
670 return dir_file_exists_p (".", name
);
671 #else /* !VMS && !AMIGA */
672 return dir_file_exists_p ("", name
);
681 #if defined (WINDOWS32) || defined (__MSDOS__)
682 /* d:/ and d: are *very* different... */
683 if (dirend
< name
+ 3 && name
[1] == ':' &&
684 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
687 dirname
= (char *) alloca (dirend
- name
+ 1);
688 bcopy (name
, dirname
, dirend
- name
);
689 dirname
[dirend
- name
] = '\0';
691 return dir_file_exists_p (dirname
, slash
+ 1);
694 /* Mark FILENAME as `impossible' for `file_impossible_p'.
695 This means an attempt has been made to search for FILENAME
696 as an intermediate file, and it has failed. */
699 file_impossible (filename
)
700 register char *filename
;
703 register char *p
= filename
;
704 register unsigned int hash
;
705 register struct directory
*dir
;
706 register struct dirfile
*new;
709 dirend
= strrchr (p
, ']');
711 dirend
= strrchr (p
, ':');
713 if (dirend
== (char *)1)
714 dir
= find_directory ("[]");
716 dirend
= strrchr (p
, '/');
717 #if defined (WINDOWS32) || defined (__MSDOS__)
718 /* Forward and backslashes might be mixed. We need the rightmost one. */
720 char *bslash
= strrchr(p
, '\\');
721 if (!dirend
|| bslash
> dirend
)
723 /* The case of "d:file". */
724 if (!dirend
&& p
[0] && p
[1] == ':')
727 #endif /* WINDOWS32 or __MSDOS__ */
730 dir
= find_directory ("");
731 #else /* !VMS && !AMIGA */
732 dir
= find_directory (".");
738 char *slash
= dirend
;
743 #if defined (WINDOWS32) || defined (__MSDOS__)
744 /* d:/ and d: are *very* different... */
745 if (dirend
< p
+ 3 && p
[1] == ':' &&
746 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
749 dirname
= (char *) alloca (dirend
- p
+ 1);
750 bcopy (p
, dirname
, dirend
- p
);
751 dirname
[dirend
- p
] = '\0';
753 dir
= find_directory (dirname
);
754 filename
= p
= slash
+ 1;
757 for (hash
= 0; *p
!= '\0'; ++p
)
759 hash
%= DIRFILE_BUCKETS
;
761 if (dir
->contents
== 0)
763 /* The directory could not be stat'd. We allocate a contents
764 structure for it, but leave it out of the contents hash table. */
765 dir
->contents
= (struct directory_contents
*)
766 xmalloc (sizeof (struct directory_contents
));
768 dir
->contents
->path_key
= NULL
;
769 dir
->contents
->mtime
= 0;
770 #else /* WINDOWS32 */
772 dir
->contents
->dev
= 0;
773 dir
->contents
->ino
[0] = dir
->contents
->ino
[1] =
774 dir
->contents
->ino
[2] = 0;
776 dir
->contents
->dev
= dir
->contents
->ino
= 0;
778 #endif /* WINDOWS32 */
779 dir
->contents
->files
= 0;
780 dir
->contents
->dirstream
= 0;
783 if (dir
->contents
->files
== 0)
785 /* The directory was not opened; we must allocate the hash buckets. */
786 dir
->contents
->files
= (struct dirfile
**)
787 xmalloc (sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
788 bzero ((char *) dir
->contents
->files
,
789 sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
792 /* Make a new entry and put it in the table. */
794 new = (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
795 new->next
= dir
->contents
->files
[hash
];
796 dir
->contents
->files
[hash
] = new;
797 new->name
= xstrdup (filename
);
801 /* Return nonzero if FILENAME has been marked impossible. */
804 file_impossible_p (filename
)
808 register char *p
= filename
;
809 register unsigned int hash
;
810 register struct directory_contents
*dir
;
811 register struct dirfile
*next
;
814 dirend
= strrchr (filename
, ']');
816 dir
= find_directory ("[]")->contents
;
818 dirend
= strrchr (filename
, '/');
819 #if defined (WINDOWS32) || defined (__MSDOS__)
820 /* Forward and backslashes might be mixed. We need the rightmost one. */
822 char *bslash
= strrchr(filename
, '\\');
823 if (!dirend
|| bslash
> dirend
)
825 /* The case of "d:file". */
826 if (!dirend
&& filename
[0] && filename
[1] == ':')
827 dirend
= filename
+ 1;
829 #endif /* WINDOWS32 || __MSDOS__ */
832 dir
= find_directory ("")->contents
;
833 #else /* !VMS && !AMIGA */
834 dir
= find_directory (".")->contents
;
840 char *slash
= dirend
;
841 if (dirend
== filename
)
845 #if defined (WINDOWS32) || defined (__MSDOS__)
846 /* d:/ and d: are *very* different... */
847 if (dirend
< filename
+ 3 && filename
[1] == ':' &&
848 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
851 dirname
= (char *) alloca (dirend
- filename
+ 1);
852 bcopy (p
, dirname
, dirend
- p
);
853 dirname
[dirend
- p
] = '\0';
855 dir
= find_directory (dirname
)->contents
;
856 p
= filename
= slash
+ 1;
859 if (dir
== 0 || dir
->files
== 0)
860 /* There are no files entered for this directory. */
864 p
= filename
= dosify (p
);
866 #ifdef HAVE_CASE_INSENSITIVE_FS
867 p
= filename
= downcase (p
);
870 p
= filename
= vmsify (p
, 1);
873 for (hash
= 0; *p
!= '\0'; ++p
)
875 hash
%= DIRFILE_BUCKETS
;
877 for (next
= dir
->files
[hash
]; next
!= 0; next
= next
->next
)
878 if (strieq (filename
, next
->name
))
879 return next
->impossible
;
884 /* Return the already allocated name in the
885 directory hash table that matches DIR. */
891 return find_directory (dir
)->name
;
894 /* Print the data base of directories. */
897 print_dir_data_base ()
899 register unsigned int i
, dirs
, files
, impossible
;
900 register struct directory
*dir
;
902 puts (_("\n# Directories\n"));
904 dirs
= files
= impossible
= 0;
905 for (i
= 0; i
< DIRECTORY_BUCKETS
; ++i
)
906 for (dir
= directories
[i
]; dir
!= 0; dir
= dir
->next
)
909 if (dir
->contents
== 0)
910 printf (_("# %s: could not be stat'd.\n"), dir
->name
);
911 else if (dir
->contents
->files
== 0)
913 printf (_("# %s (key %s, mtime %d): could not be opened.\n"),
914 dir
->name
, dir
->contents
->path_key
,dir
->contents
->mtime
);
915 #else /* WINDOWS32 */
917 printf (_("# %s (device %d, inode [%d,%d,%d]): could not be opened.\n"),
918 dir
->name
, dir
->contents
->dev
,
919 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
920 dir
->contents
->ino
[2]);
922 printf (_("# %s (device %ld, inode %ld): could not be opened.\n"),
923 dir
->name
, (long int) dir
->contents
->dev
,
924 (long int) dir
->contents
->ino
);
926 #endif /* WINDOWS32 */
929 register unsigned int f
= 0, im
= 0;
930 register unsigned int j
;
931 register struct dirfile
*df
;
932 for (j
= 0; j
< DIRFILE_BUCKETS
; ++j
)
933 for (df
= dir
->contents
->files
[j
]; df
!= 0; df
= df
->next
)
939 printf (_("# %s (key %s, mtime %d): "),
940 dir
->name
, dir
->contents
->path_key
, dir
->contents
->mtime
);
941 #else /* WINDOWS32 */
943 printf (_("# %s (device %d, inode [%d,%d,%d]): "),
944 dir
->name
, dir
->contents
->dev
,
945 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
946 dir
->contents
->ino
[2]);
948 printf (_("# %s (device %ld, inode %ld): "),
950 (long)dir
->contents
->dev
, (long)dir
->contents
->ino
);
952 #endif /* WINDOWS32 */
954 fputs (_("No"), stdout
);
957 fputs (_(" files, "), stdout
);
959 fputs (_("no"), stdout
);
962 fputs (_(" impossibilities"), stdout
);
963 if (dir
->contents
->dirstream
== 0)
966 puts (_(" so far."));
972 fputs ("\n# ", stdout
);
974 fputs (_("No"), stdout
);
976 printf ("%u", files
);
977 fputs (_(" files, "), stdout
);
979 fputs (_("no"), stdout
);
981 printf ("%u", impossible
);
982 printf (_(" impossibilities in %u directories.\n"), dirs
);
985 /* Hooks for globbing. */
989 /* Structure describing state of iterating through a directory hash table. */
993 struct directory_contents
*contents
; /* The directory being read. */
995 unsigned int bucket
; /* Current hash bucket. */
996 struct dirfile
*elt
; /* Current elt in bucket. */
999 /* Forward declarations. */
1000 static __ptr_t open_dirstream
PARAMS ((const char *));
1001 static struct dirent
*read_dirstream
PARAMS ((__ptr_t
));
1004 open_dirstream (directory
)
1005 const char *directory
;
1007 struct dirstream
*new;
1008 struct directory
*dir
= find_directory ((char *)directory
);
1010 if (dir
->contents
== 0 || dir
->contents
->files
== 0)
1011 /* DIR->contents is nil if the directory could not be stat'd.
1012 DIR->contents->files is nil if it could not be opened. */
1015 /* Read all the contents of the directory now. There is no benefit
1016 in being lazy, since glob will want to see every file anyway. */
1018 (void) dir_contents_file_exists_p (dir
->contents
, (char *) 0);
1020 new = (struct dirstream
*) xmalloc (sizeof (struct dirstream
));
1021 new->contents
= dir
->contents
;
1023 new->elt
= new->contents
->files
[0];
1025 return (__ptr_t
) new;
1028 static struct dirent
*
1029 read_dirstream (stream
)
1032 struct dirstream
*const ds
= (struct dirstream
*) stream
;
1033 register struct dirfile
*df
;
1035 static unsigned int bufsz
;
1037 while (ds
->bucket
< DIRFILE_BUCKETS
)
1039 while ((df
= ds
->elt
) != 0)
1042 if (!df
->impossible
)
1044 /* The glob interface wants a `struct dirent',
1047 unsigned int len
= strlen (df
->name
) + 1;
1048 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1053 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1054 bufsz
= sizeof *d
- sizeof d
->d_name
+ len
;
1055 buf
= xmalloc (bufsz
);
1057 d
= (struct dirent
*) buf
;
1059 #ifdef _DIRENT_HAVE_D_NAMLEN
1060 d
->d_namlen
= len
- 1;
1062 #ifdef _DIRENT_HAVE_D_TYPE
1063 d
->d_type
= DT_UNKNOWN
;
1065 memcpy (d
->d_name
, df
->name
, len
);
1069 if (++ds
->bucket
== DIRFILE_BUCKETS
)
1071 ds
->elt
= ds
->contents
->files
[ds
->bucket
];
1085 /* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a
1086 * macro for stat64(). If stat is a macro, make a local wrapper function to
1093 # define local_stat stat
1095 static int local_stat (path
, buf
)
1099 return stat (path
, buf
);
1107 /* Bogus sunos4 compiler complains (!) about & before functions. */
1108 gl
->gl_opendir
= open_dirstream
;
1109 gl
->gl_readdir
= read_dirstream
;
1110 gl
->gl_closedir
= ansi_free
;
1111 gl
->gl_stat
= local_stat
;
1112 /* We don't bother setting gl_lstat, since glob never calls it.
1113 The slot is only there for compatibility with 4.4 BSD. */