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 unsigned char uc
= *name
;
163 h
= (h
<< 4) + (isupper (uc
) ? tolower (uc
) : uc
);
175 /* fake stat entry for a directory */
177 vmsstat_dir (name
, st
)
185 dir
= opendir (name
);
189 s
= strchr (name
, ':'); /* find device */
193 st
->st_dev
= (char *)vms_hash (name
);
204 st
->st_ino
[0] = h
& 0xff;
205 st
->st_ino
[1] = h
& 0xff00;
206 st
->st_ino
[2] = h
>> 16;
212 /* Hash table of directories. */
214 #ifndef DIRECTORY_BUCKETS
215 #define DIRECTORY_BUCKETS 199
218 struct directory_contents
220 struct directory_contents
*next
;
222 dev_t dev
; /* Device and inode numbers of this dir. */
225 * Inode means nothing on WINDOWS32. Even file key information is
226 * unreliable because it is random per file open and undefined
227 * for remote filesystems. The most unique attribute I can
228 * come up with is the fully qualified name of the directory. Beware
229 * though, this is also unreliable. I'm open to suggestion on a better
230 * way to emulate inode.
233 int mtime
; /* controls check for stale directory cache */
234 int fs_flags
; /* FS_FAT, FS_NTFS, ... */
237 #define FS_UNKNOWN 0x4
244 #endif /* WINDOWS32 */
245 struct dirfile
**files
; /* Files in this directory. */
246 DIR *dirstream
; /* Stream reading this directory. */
249 /* Table of directory contents hashed by device and inode number. */
250 static struct directory_contents
*directories_contents
[DIRECTORY_BUCKETS
];
254 struct directory
*next
;
256 char *name
; /* Name of the directory. */
258 /* The directory's contents. This data may be shared by several
259 entries in the hash table, which refer to the same directory
260 (identified uniquely by `dev' and `ino') under different names. */
261 struct directory_contents
*contents
;
264 /* Table of directories hashed by name. */
265 static struct directory
*directories
[DIRECTORY_BUCKETS
];
268 /* Never have more than this many directories open at once. */
270 #define MAX_OPEN_DIRECTORIES 10
272 static unsigned int open_directories
= 0;
275 /* Hash table of files in each directory. */
279 struct dirfile
*next
;
280 char *name
; /* Name of the file. */
281 char impossible
; /* This file is impossible. */
284 #ifndef DIRFILE_BUCKETS
285 #define DIRFILE_BUCKETS 107
288 static int dir_contents_file_exists_p
PARAMS ((struct directory_contents
*dir
, char *filename
));
289 static struct directory
*find_directory
PARAMS ((char *name
));
291 /* Find the directory named NAME and return its `struct directory'. */
293 static struct directory
*
294 find_directory (name
)
297 register unsigned int hash
= 0;
299 register struct directory
*dir
;
303 char fs_label
[BUFSIZ
];
304 char fs_type
[BUFSIZ
];
310 if ((*name
== '.') && (*(name
+1) == 0))
313 name
= vmsify (name
,1);
316 for (p
= name
; *p
!= '\0'; ++p
)
318 hash
%= DIRECTORY_BUCKETS
;
320 for (dir
= directories
[hash
]; dir
!= 0; dir
= dir
->next
)
321 if (strieq (dir
->name
, name
))
328 /* The directory was not found. Create a new entry for it. */
330 dir
= (struct directory
*) xmalloc (sizeof (struct directory
));
331 dir
->next
= directories
[hash
];
332 directories
[hash
] = dir
;
333 dir
->name
= savestring (name
, p
- name
);
335 /* The directory is not in the name hash table.
336 Find its device and inode numbers, and look it up by them. */
339 /* Remove any trailing '\'. Windows32 stat fails even on valid
340 directories if they end in '\'. */
346 r
= vmsstat_dir (name
, &st
);
348 r
= stat (name
, &st
);
352 /* Put back the trailing '\'. If we don't, we're permanently
353 truncating the value! */
360 /* Couldn't stat the directory. Mark this by
361 setting the `contents' member to a nil pointer. */
366 /* Search the contents hash table; device and inode are the key. */
368 struct directory_contents
*dc
;
371 w32_path
= w32ify(name
, 1);
372 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ctime
;
375 hash
= (((unsigned int) st
.st_dev
<< 16)
376 | ((unsigned int) st
.st_ino
[0]
377 + (unsigned int) st
.st_ino
[1]
378 + (unsigned int) st
.st_ino
[2]));
380 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ino
;
383 hash
%= DIRECTORY_BUCKETS
;
385 for (dc
= directories_contents
[hash
]; dc
!= 0; dc
= dc
->next
)
387 if (strieq(dc
->path_key
, w32_path
))
389 if (dc
->dev
== st
.st_dev
391 && dc
->ino
[0] == st
.st_ino
[0]
392 && dc
->ino
[1] == st
.st_ino
[1]
393 && dc
->ino
[2] == st
.st_ino
[2]
395 && dc
->ino
== st
.st_ino
398 #endif /* WINDOWS32 */
403 /* Nope; this really is a directory we haven't seen before. */
405 dc
= (struct directory_contents
*)
406 xmalloc (sizeof (struct directory_contents
));
408 /* Enter it in the contents hash table. */
411 dc
->path_key
= xstrdup(w32_path
);
412 dc
->mtime
= st
.st_mtime
;
415 * NTFS is the only WINDOWS32 filesystem that bumps mtime
416 * on a directory when files are added/deleted from
420 if (GetVolumeInformation(w32_path
,
421 fs_label
, sizeof (fs_label
),
423 &fs_flags
, fs_type
, sizeof (fs_type
)) == FALSE
)
424 dc
->fs_flags
= FS_UNKNOWN
;
425 else if (!strcmp(fs_type
, "FAT"))
426 dc
->fs_flags
= FS_FAT
;
427 else if (!strcmp(fs_type
, "NTFS"))
428 dc
->fs_flags
= FS_NTFS
;
430 dc
->fs_flags
= FS_UNKNOWN
;
433 dc
->ino
[0] = st
.st_ino
[0];
434 dc
->ino
[1] = st
.st_ino
[1];
435 dc
->ino
[2] = st
.st_ino
[2];
439 #endif /* WINDOWS32 */
440 dc
->next
= directories_contents
[hash
];
441 directories_contents
[hash
] = dc
;
443 dc
->dirstream
= opendir (name
);
444 if (dc
->dirstream
== 0)
445 /* Couldn't open the directory. Mark this by
446 setting the `files' member to a nil pointer. */
450 /* Allocate an array of buckets for files and zero it. */
451 dc
->files
= (struct dirfile
**)
452 xmalloc (sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
453 bzero ((char *) dc
->files
,
454 sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
456 /* Keep track of how many directories are open. */
458 if (open_directories
== MAX_OPEN_DIRECTORIES
)
459 /* We have too many directories open already.
460 Read the entire directory and then close it. */
461 (void) dir_contents_file_exists_p (dc
, (char *) 0);
465 /* Point the name-hashed entry for DIR at its contents data. */
473 /* Return 1 if the name FILENAME is entered in DIR's hash table.
474 FILENAME must contain no slashes. */
477 dir_contents_file_exists_p (dir
, filename
)
478 register struct directory_contents
*dir
;
479 register char *filename
;
481 register unsigned int hash
;
483 register struct dirfile
*df
;
484 register struct dirent
*d
;
490 if (dir
== 0 || dir
->files
== 0)
492 /* The directory could not be stat'd or opened. */
496 filename
= dosify (filename
);
499 #ifdef HAVE_CASE_INSENSITIVE_FS
500 filename
= downcase (filename
);
504 filename
= vmsify (filename
,0);
510 if (*filename
== '\0')
512 /* Checking if the directory exists. */
516 for (p
= filename
; *p
!= '\0'; ++p
)
518 hash
%= DIRFILE_BUCKETS
;
520 /* Search the list of hashed files. */
522 for (df
= dir
->files
[hash
]; df
!= 0; df
= df
->next
)
524 if (strieq (df
->name
, filename
))
526 return !df
->impossible
;
531 /* The file was not found in the hashed list.
532 Try to read the directory further. */
534 if (dir
->dirstream
== 0)
538 * Check to see if directory has changed since last read. FAT
539 * filesystems force a rehash always as mtime does not change
540 * on directories (ugh!).
543 (dir
->fs_flags
& FS_FAT
||
544 (stat(dir
->path_key
, &st
) == 0 &&
545 st
.st_mtime
> dir
->mtime
))) {
547 /* reset date stamp to show most recent re-process */
548 dir
->mtime
= st
.st_mtime
;
550 /* make sure directory can still be opened */
551 dir
->dirstream
= opendir(dir
->path_key
);
556 return 0; /* couldn't re-read - fail */
559 /* The directory has been all read in. */
563 while ((d
= readdir (dir
->dirstream
)) != 0)
565 /* Enter the file in the hash table. */
566 register unsigned int newhash
= 0;
568 register unsigned int i
;
570 #if defined(VMS) && defined(HAVE_DIRENT_H)
571 /* In VMS we get file versions too, which have to be stripped off */
573 char *p
= strrchr (d
->d_name
, ';');
578 if (!REAL_DIR_ENTRY (d
))
582 for (i
= 0; i
< len
; ++i
)
583 HASHI (newhash
, d
->d_name
[i
]);
584 newhash
%= DIRFILE_BUCKETS
;
587 * If re-reading a directory, check that this file isn't already
591 for (df
= dir
->files
[newhash
]; df
!= 0; df
= df
->next
)
592 if (streq(df
->name
, d
->d_name
))
598 * If re-reading a directory, don't cache files that have
599 * already been discovered.
604 df
= (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
605 df
->next
= dir
->files
[newhash
];
606 dir
->files
[newhash
] = df
;
607 df
->name
= savestring (d
->d_name
, len
);
612 /* Check if the name matches the one we're searching for. */
614 && newhash
== hash
&& strieq (d
->d_name
, filename
))
620 /* If the directory has been completely read in,
621 close the stream and reset the pointer to nil. */
625 closedir (dir
->dirstream
);
631 /* Return 1 if the name FILENAME in directory DIRNAME
632 is entered in the dir hash table.
633 FILENAME must contain no slashes. */
636 dir_file_exists_p (dirname
, filename
)
637 register char *dirname
;
638 register char *filename
;
640 return dir_contents_file_exists_p (find_directory (dirname
)->contents
,
644 /* Return 1 if the file named NAME exists. */
656 return ar_member_date (name
) != (time_t) -1;
660 dirend
= strrchr (name
, ']');
662 dirend
= strrchr (name
, ':');
664 if (dirend
== (char *)1)
665 return dir_file_exists_p ("[]", name
);
667 dirend
= strrchr (name
, '/');
668 #if defined (WINDOWS32) || defined (__MSDOS__)
669 /* Forward and backslashes might be mixed. We need the rightmost one. */
671 char *bslash
= strrchr(name
, '\\');
672 if (!dirend
|| bslash
> dirend
)
674 /* The case of "d:file". */
675 if (!dirend
&& name
[0] && name
[1] == ':')
678 #endif /* WINDOWS32 || __MSDOS__ */
681 return dir_file_exists_p (".", name
);
682 #else /* !VMS && !AMIGA */
683 return dir_file_exists_p ("", name
);
692 #if defined (WINDOWS32) || defined (__MSDOS__)
693 /* d:/ and d: are *very* different... */
694 if (dirend
< name
+ 3 && name
[1] == ':' &&
695 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
698 dirname
= (char *) alloca (dirend
- name
+ 1);
699 bcopy (name
, dirname
, dirend
- name
);
700 dirname
[dirend
- name
] = '\0';
702 return dir_file_exists_p (dirname
, slash
+ 1);
705 /* Mark FILENAME as `impossible' for `file_impossible_p'.
706 This means an attempt has been made to search for FILENAME
707 as an intermediate file, and it has failed. */
710 file_impossible (filename
)
711 register char *filename
;
714 register char *p
= filename
;
715 register unsigned int hash
;
716 register struct directory
*dir
;
717 register struct dirfile
*new;
720 dirend
= strrchr (p
, ']');
722 dirend
= strrchr (p
, ':');
724 if (dirend
== (char *)1)
725 dir
= find_directory ("[]");
727 dirend
= strrchr (p
, '/');
728 # if defined (WINDOWS32) || defined (__MSDOS__)
729 /* Forward and backslashes might be mixed. We need the rightmost one. */
731 char *bslash
= strrchr(p
, '\\');
732 if (!dirend
|| bslash
> dirend
)
734 /* The case of "d:file". */
735 if (!dirend
&& p
[0] && p
[1] == ':')
738 # endif /* WINDOWS32 or __MSDOS__ */
741 dir
= find_directory ("");
742 # else /* !VMS && !AMIGA */
743 dir
= find_directory (".");
749 char *slash
= dirend
;
754 #if defined (WINDOWS32) || defined (__MSDOS__)
755 /* d:/ and d: are *very* different... */
756 if (dirend
< p
+ 3 && p
[1] == ':' &&
757 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
760 dirname
= (char *) alloca (dirend
- p
+ 1);
761 bcopy (p
, dirname
, dirend
- p
);
762 dirname
[dirend
- p
] = '\0';
764 dir
= find_directory (dirname
);
765 filename
= p
= slash
+ 1;
768 for (hash
= 0; *p
!= '\0'; ++p
)
770 hash
%= DIRFILE_BUCKETS
;
772 if (dir
->contents
== 0)
774 /* The directory could not be stat'd. We allocate a contents
775 structure for it, but leave it out of the contents hash table. */
776 dir
->contents
= (struct directory_contents
*)
777 xmalloc (sizeof (struct directory_contents
));
779 dir
->contents
->path_key
= NULL
;
780 dir
->contents
->mtime
= 0;
781 #else /* WINDOWS32 */
783 dir
->contents
->dev
= 0;
784 dir
->contents
->ino
[0] = dir
->contents
->ino
[1] =
785 dir
->contents
->ino
[2] = 0;
787 dir
->contents
->dev
= dir
->contents
->ino
= 0;
789 #endif /* WINDOWS32 */
790 dir
->contents
->files
= 0;
791 dir
->contents
->dirstream
= 0;
794 if (dir
->contents
->files
== 0)
796 /* The directory was not opened; we must allocate the hash buckets. */
797 dir
->contents
->files
= (struct dirfile
**)
798 xmalloc (sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
799 bzero ((char *) dir
->contents
->files
,
800 sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
803 /* Make a new entry and put it in the table. */
805 new = (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
806 new->next
= dir
->contents
->files
[hash
];
807 dir
->contents
->files
[hash
] = new;
808 new->name
= xstrdup (filename
);
812 /* Return nonzero if FILENAME has been marked impossible. */
815 file_impossible_p (filename
)
819 register char *p
= filename
;
820 register unsigned int hash
;
821 register struct directory_contents
*dir
;
822 register struct dirfile
*next
;
825 dirend
= strrchr (filename
, ']');
827 dir
= find_directory ("[]")->contents
;
829 dirend
= strrchr (filename
, '/');
830 #if defined (WINDOWS32) || defined (__MSDOS__)
831 /* Forward and backslashes might be mixed. We need the rightmost one. */
833 char *bslash
= strrchr(filename
, '\\');
834 if (!dirend
|| bslash
> dirend
)
836 /* The case of "d:file". */
837 if (!dirend
&& filename
[0] && filename
[1] == ':')
838 dirend
= filename
+ 1;
840 #endif /* WINDOWS32 || __MSDOS__ */
843 dir
= find_directory ("")->contents
;
844 #else /* !VMS && !AMIGA */
845 dir
= find_directory (".")->contents
;
851 char *slash
= dirend
;
852 if (dirend
== filename
)
856 #if defined (WINDOWS32) || defined (__MSDOS__)
857 /* d:/ and d: are *very* different... */
858 if (dirend
< filename
+ 3 && filename
[1] == ':' &&
859 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
862 dirname
= (char *) alloca (dirend
- filename
+ 1);
863 bcopy (p
, dirname
, dirend
- p
);
864 dirname
[dirend
- p
] = '\0';
866 dir
= find_directory (dirname
)->contents
;
867 p
= filename
= slash
+ 1;
870 if (dir
== 0 || dir
->files
== 0)
871 /* There are no files entered for this directory. */
875 p
= filename
= dosify (p
);
877 #ifdef HAVE_CASE_INSENSITIVE_FS
878 p
= filename
= downcase (p
);
881 p
= filename
= vmsify (p
, 1);
884 for (hash
= 0; *p
!= '\0'; ++p
)
886 hash
%= DIRFILE_BUCKETS
;
888 for (next
= dir
->files
[hash
]; next
!= 0; next
= next
->next
)
889 if (strieq (filename
, next
->name
))
890 return next
->impossible
;
895 /* Return the already allocated name in the
896 directory hash table that matches DIR. */
902 return find_directory (dir
)->name
;
905 /* Print the data base of directories. */
908 print_dir_data_base ()
910 register unsigned int i
, dirs
, files
, impossible
;
911 register struct directory
*dir
;
913 puts (_("\n# Directories\n"));
915 dirs
= files
= impossible
= 0;
916 for (i
= 0; i
< DIRECTORY_BUCKETS
; ++i
)
917 for (dir
= directories
[i
]; dir
!= 0; dir
= dir
->next
)
920 if (dir
->contents
== 0)
921 printf (_("# %s: could not be stat'd.\n"), dir
->name
);
922 else if (dir
->contents
->files
== 0)
924 printf (_("# %s (key %s, mtime %d): could not be opened.\n"),
925 dir
->name
, dir
->contents
->path_key
,dir
->contents
->mtime
);
926 #else /* WINDOWS32 */
928 printf (_("# %s (device %d, inode [%d,%d,%d]): could not be opened.\n"),
929 dir
->name
, dir
->contents
->dev
,
930 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
931 dir
->contents
->ino
[2]);
933 printf (_("# %s (device %ld, inode %ld): could not be opened.\n"),
934 dir
->name
, (long int) dir
->contents
->dev
,
935 (long int) dir
->contents
->ino
);
937 #endif /* WINDOWS32 */
940 register unsigned int f
= 0, im
= 0;
941 register unsigned int j
;
942 register struct dirfile
*df
;
943 for (j
= 0; j
< DIRFILE_BUCKETS
; ++j
)
944 for (df
= dir
->contents
->files
[j
]; df
!= 0; df
= df
->next
)
950 printf (_("# %s (key %s, mtime %d): "),
951 dir
->name
, dir
->contents
->path_key
, dir
->contents
->mtime
);
952 #else /* WINDOWS32 */
954 printf (_("# %s (device %d, inode [%d,%d,%d]): "),
955 dir
->name
, dir
->contents
->dev
,
956 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
957 dir
->contents
->ino
[2]);
959 printf (_("# %s (device %ld, inode %ld): "),
961 (long)dir
->contents
->dev
, (long)dir
->contents
->ino
);
963 #endif /* WINDOWS32 */
965 fputs (_("No"), stdout
);
968 fputs (_(" files, "), stdout
);
970 fputs (_("no"), stdout
);
973 fputs (_(" impossibilities"), stdout
);
974 if (dir
->contents
->dirstream
== 0)
977 puts (_(" so far."));
983 fputs ("\n# ", stdout
);
985 fputs (_("No"), stdout
);
987 printf ("%u", files
);
988 fputs (_(" files, "), stdout
);
990 fputs (_("no"), stdout
);
992 printf ("%u", impossible
);
993 printf (_(" impossibilities in %u directories.\n"), dirs
);
996 /* Hooks for globbing. */
1000 /* Structure describing state of iterating through a directory hash table. */
1004 struct directory_contents
*contents
; /* The directory being read. */
1006 unsigned int bucket
; /* Current hash bucket. */
1007 struct dirfile
*elt
; /* Current elt in bucket. */
1010 /* Forward declarations. */
1011 static __ptr_t open_dirstream
PARAMS ((const char *));
1012 static struct dirent
*read_dirstream
PARAMS ((__ptr_t
));
1015 open_dirstream (directory
)
1016 const char *directory
;
1018 struct dirstream
*new;
1019 struct directory
*dir
= find_directory ((char *)directory
);
1021 if (dir
->contents
== 0 || dir
->contents
->files
== 0)
1022 /* DIR->contents is nil if the directory could not be stat'd.
1023 DIR->contents->files is nil if it could not be opened. */
1026 /* Read all the contents of the directory now. There is no benefit
1027 in being lazy, since glob will want to see every file anyway. */
1029 (void) dir_contents_file_exists_p (dir
->contents
, (char *) 0);
1031 new = (struct dirstream
*) xmalloc (sizeof (struct dirstream
));
1032 new->contents
= dir
->contents
;
1034 new->elt
= new->contents
->files
[0];
1036 return (__ptr_t
) new;
1039 static struct dirent
*
1040 read_dirstream (stream
)
1043 struct dirstream
*const ds
= (struct dirstream
*) stream
;
1044 register struct dirfile
*df
;
1046 static unsigned int bufsz
;
1048 while (ds
->bucket
< DIRFILE_BUCKETS
)
1050 while ((df
= ds
->elt
) != 0)
1053 if (!df
->impossible
)
1055 /* The glob interface wants a `struct dirent',
1058 unsigned int len
= strlen (df
->name
) + 1;
1059 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1064 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1065 bufsz
= sizeof *d
- sizeof d
->d_name
+ len
;
1066 buf
= xmalloc (bufsz
);
1068 d
= (struct dirent
*) buf
;
1070 #ifdef _DIRENT_HAVE_D_NAMLEN
1071 d
->d_namlen
= len
- 1;
1073 #ifdef _DIRENT_HAVE_D_TYPE
1074 d
->d_type
= DT_UNKNOWN
;
1076 memcpy (d
->d_name
, df
->name
, len
);
1080 if (++ds
->bucket
== DIRFILE_BUCKETS
)
1082 ds
->elt
= ds
->contents
->files
[ds
->bucket
];
1096 /* On 64 bit ReliantUNIX (5.44 and above) in LFS mode, stat() is actually a
1097 * macro for stat64(). If stat is a macro, make a local wrapper function to
1104 # define local_stat stat
1106 static int local_stat (path
, buf
)
1110 return stat (path
, buf
);
1118 /* Bogus sunos4 compiler complains (!) about & before functions. */
1119 gl
->gl_opendir
= open_dirstream
;
1120 gl
->gl_readdir
= read_dirstream
;
1121 gl
->gl_closedir
= ansi_free
;
1122 gl
->gl_stat
= local_stat
;
1123 /* We don't bother setting gl_lstat, since glob never calls it.
1124 The slot is only there for compatibility with 4.4 BSD. */