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 # define dirent direct
27 # define NAMLEN(dirent) (dirent)->d_namlen
28 # ifdef HAVE_SYS_NDIR_H
29 # include <sys/ndir.h>
31 # ifdef HAVE_SYS_DIR_H
39 # endif /* HAVE_VMSDIR_H */
42 /* In GNU systems, <dirent.h> defines this macro for us. */
45 #define NAMLEN(d) _D_NAMLEN(d)
48 #if (defined (POSIX) || defined (WINDOWS32)) && !defined (__GNU_LIBRARY__)
49 /* Posix does not require that the d_ino field be present, and some
50 systems do not provide it. */
51 #define REAL_DIR_ENTRY(dp) 1
52 #define FAKE_DIR_ENTRY(dp)
54 #define REAL_DIR_ENTRY(dp) (dp->d_ino != 0)
55 #define FAKE_DIR_ENTRY(dp) (dp->d_ino = 1)
62 /* If it's MSDOS that doesn't have _USE_LFN, disable LFN support. */
71 static char dos_filename
[14];
75 if (filename
== 0 || _USE_LFN
)
78 /* FIXME: what about filenames which violate
79 8+3 constraints, like "config.h.in", or ".emacs"? */
80 if (strpbrk (filename
, "\"*+,;<=>?[\\]|") != 0)
85 /* First, transform the name part. */
86 for (i
= 0; *filename
!= '\0' && i
< 8 && *filename
!= '.'; ++i
)
87 *df
++ = tolower (*filename
++);
89 /* Now skip to the next dot. */
90 while (*filename
!= '\0' && *filename
!= '.')
92 if (*filename
!= '\0')
95 for (i
= 0; *filename
!= '\0' && i
< 3 && *filename
!= '.'; ++i
)
96 *df
++ = tolower (*filename
++);
99 /* Look for more dots. */
100 while (*filename
!= '\0' && *filename
!= '.')
102 if (*filename
== '.')
107 #endif /* __MSDOS__ */
110 #include "pathstuff.h"
117 #ifdef HAVE_CASE_INSENSITIVE_FS
123 static char new_filename
[136];
125 static char new_filename
[PATH_MAX
];
135 /* First, transform the name part. */
136 for (i
= 0; *filename
!= '\0'; ++i
)
138 *df
++ = tolower (*filename
);
146 #endif /* HAVE_CASE_INSENSITIVE_FS */
159 h
= (h
<< 4) + *name
++;
170 /* fake stat entry for a directory */
172 vmsstat_dir (name
, st
)
180 dir
= opendir (name
);
184 s
= strchr (name
, ':'); /* find device */
188 st
->st_dev
= (char *)vms_hash (name
);
199 st
->st_ino
[0] = h
& 0xff;
200 st
->st_ino
[1] = h
& 0xff00;
201 st
->st_ino
[2] = h
>> 16;
207 /* Hash table of directories. */
209 #ifndef DIRECTORY_BUCKETS
210 #define DIRECTORY_BUCKETS 199
213 struct directory_contents
215 struct directory_contents
*next
;
217 dev_t dev
; /* Device and inode numbers of this dir. */
220 * Inode means nothing on WINDOWS32. Even file key information is
221 * unreliable because it is random per file open and undefined
222 * for remote filesystems. The most unique attribute I can
223 * come up with is the fully qualified name of the directory. Beware
224 * though, this is also unreliable. I'm open to suggestion on a better
225 * way to emulate inode.
228 int mtime
; /* controls check for stale directory cache */
229 int fs_flags
; /* FS_FAT, FS_NTFS, ... */
232 #define FS_UNKNOWN 0x4
239 #endif /* WINDOWS32 */
240 struct dirfile
**files
; /* Files in this directory. */
241 DIR *dirstream
; /* Stream reading this directory. */
244 /* Table of directory contents hashed by device and inode number. */
245 static struct directory_contents
*directories_contents
[DIRECTORY_BUCKETS
];
249 struct directory
*next
;
251 char *name
; /* Name of the directory. */
253 /* The directory's contents. This data may be shared by several
254 entries in the hash table, which refer to the same directory
255 (identified uniquely by `dev' and `ino') under different names. */
256 struct directory_contents
*contents
;
259 /* Table of directories hashed by name. */
260 static struct directory
*directories
[DIRECTORY_BUCKETS
];
263 /* Never have more than this many directories open at once. */
265 #define MAX_OPEN_DIRECTORIES 10
267 static unsigned int open_directories
= 0;
270 /* Hash table of files in each directory. */
274 struct dirfile
*next
;
275 char *name
; /* Name of the file. */
276 char impossible
; /* This file is impossible. */
279 #ifndef DIRFILE_BUCKETS
280 #define DIRFILE_BUCKETS 107
283 static int dir_contents_file_exists_p
PARAMS ((struct directory_contents
*dir
, char *filename
));
284 static struct directory
*find_directory
PARAMS ((char *name
));
286 /* Find the directory named NAME and return its `struct directory'. */
288 static struct directory
*
289 find_directory (name
)
292 register unsigned int hash
= 0;
294 register struct directory
*dir
;
297 char fs_label
[BUFSIZ
];
298 char fs_type
[BUFSIZ
];
304 if ((*name
== '.') && (*(name
+1) == 0))
307 name
= vmsify (name
,1);
310 for (p
= name
; *p
!= '\0'; ++p
)
312 hash
%= DIRECTORY_BUCKETS
;
314 for (dir
= directories
[hash
]; dir
!= 0; dir
= dir
->next
)
315 if (strieq (dir
->name
, name
))
322 /* The directory was not found. Create a new entry for it. */
324 dir
= (struct directory
*) xmalloc (sizeof (struct directory
));
325 dir
->next
= directories
[hash
];
326 directories
[hash
] = dir
;
327 dir
->name
= savestring (name
, p
- name
);
329 /* The directory is not in the name hash table.
330 Find its device and inode numbers, and look it up by them. */
333 if (vmsstat_dir (name
, &st
) < 0)
337 /* Remove any trailing '\'. Windows32 stat fails even on valid
338 directories if they end in '\'. */
342 if (stat (name
, &st
) < 0)
345 /* Couldn't stat the directory. Mark this by
346 setting the `contents' member to a nil pointer. */
351 /* Search the contents hash table; device and inode are the key. */
353 struct directory_contents
*dc
;
356 w32_path
= w32ify(name
, 1);
357 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ctime
;
360 hash
= ((unsigned int) st
.st_dev
<< 16)
361 | ((unsigned int) st
.st_ino
[0]
362 + (unsigned int) st
.st_ino
[1]
363 + (unsigned int) st
.st_ino
[2]);
365 hash
= ((unsigned int) st
.st_dev
<< 16) | (unsigned int) st
.st_ino
;
368 hash
%= DIRECTORY_BUCKETS
;
370 for (dc
= directories_contents
[hash
]; dc
!= 0; dc
= dc
->next
)
372 if (strieq(dc
->path_key
, w32_path
))
374 if (dc
->dev
== st
.st_dev
376 && dc
->ino
[0] == st
.st_ino
[0]
377 && dc
->ino
[1] == st
.st_ino
[1]
378 && dc
->ino
[2] == st
.st_ino
[2])
380 && dc
->ino
== st
.st_ino
)
382 #endif /* WINDOWS32 */
387 /* Nope; this really is a directory we haven't seen before. */
389 dc
= (struct directory_contents
*)
390 xmalloc (sizeof (struct directory_contents
));
392 /* Enter it in the contents hash table. */
395 dc
->path_key
= xstrdup(w32_path
);
396 dc
->mtime
= st
.st_mtime
;
399 * NTFS is the only WINDOWS32 filesystem that bumps mtime
400 * on a directory when files are added/deleted from
404 if (GetVolumeInformation(w32_path
,
405 fs_label
, sizeof (fs_label
),
407 &fs_flags
, fs_type
, sizeof (fs_type
)) == FALSE
)
408 dc
->fs_flags
= FS_UNKNOWN
;
409 else if (!strcmp(fs_type
, "FAT"))
410 dc
->fs_flags
= FS_FAT
;
411 else if (!strcmp(fs_type
, "NTFS"))
412 dc
->fs_flags
= FS_NTFS
;
414 dc
->fs_flags
= FS_UNKNOWN
;
417 dc
->ino
[0] = st
.st_ino
[0];
418 dc
->ino
[1] = st
.st_ino
[1];
419 dc
->ino
[2] = st
.st_ino
[2];
423 #endif /* WINDOWS32 */
424 dc
->next
= directories_contents
[hash
];
425 directories_contents
[hash
] = dc
;
427 dc
->dirstream
= opendir (name
);
428 if (dc
->dirstream
== 0)
430 /* Couldn't open the directory. Mark this by
431 setting the `files' member to a nil pointer. */
436 /* Allocate an array of buckets for files and zero it. */
437 dc
->files
= (struct dirfile
**)
438 xmalloc (sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
439 bzero ((char *) dc
->files
,
440 sizeof (struct dirfile
*) * DIRFILE_BUCKETS
);
442 /* Keep track of how many directories are open. */
444 if (open_directories
== MAX_OPEN_DIRECTORIES
)
445 /* We have too many directories open already.
446 Read the entire directory and then close it. */
447 (void) dir_contents_file_exists_p (dc
, (char *) 0);
451 /* Point the name-hashed entry for DIR at its contents data. */
459 /* Return 1 if the name FILENAME is entered in DIR's hash table.
460 FILENAME must contain no slashes. */
463 dir_contents_file_exists_p (dir
, filename
)
464 register struct directory_contents
*dir
;
465 register char *filename
;
467 register unsigned int hash
;
469 register struct dirfile
*df
;
470 register struct dirent
*d
;
476 if (dir
== 0 || dir
->files
== 0)
478 /* The directory could not be stat'd or opened. */
482 filename
= dosify (filename
);
485 #ifdef HAVE_CASE_INSENSITIVE_FS
486 filename
= downcase (filename
);
490 filename
= vmsify (filename
,0);
496 if (*filename
== '\0')
498 /* Checking if the directory exists. */
502 for (p
= filename
; *p
!= '\0'; ++p
)
504 hash
%= DIRFILE_BUCKETS
;
506 /* Search the list of hashed files. */
508 for (df
= dir
->files
[hash
]; df
!= 0; df
= df
->next
)
510 if (strieq (df
->name
, filename
))
512 return !df
->impossible
;
517 /* The file was not found in the hashed list.
518 Try to read the directory further. */
520 if (dir
->dirstream
== 0)
524 * Check to see if directory has changed since last read. FAT
525 * filesystems force a rehash always as mtime does not change
526 * on directories (ugh!).
529 (dir
->fs_flags
& FS_FAT
||
530 (stat(dir
->path_key
, &st
) == 0 &&
531 st
.st_mtime
> dir
->mtime
))) {
533 /* reset date stamp to show most recent re-process */
534 dir
->mtime
= st
.st_mtime
;
536 /* make sure directory can still be opened */
537 dir
->dirstream
= opendir(dir
->path_key
);
542 return 0; /* couldn't re-read - fail */
545 /* The directory has been all read in. */
549 while ((d
= readdir (dir
->dirstream
)) != 0)
551 /* Enter the file in the hash table. */
552 register unsigned int newhash
= 0;
554 register unsigned int i
;
556 if (!REAL_DIR_ENTRY (d
))
560 for (i
= 0; i
< len
; ++i
)
561 HASHI (newhash
, d
->d_name
[i
]);
562 newhash
%= DIRFILE_BUCKETS
;
565 * If re-reading a directory, check that this file isn't already
569 for (df
= dir
->files
[newhash
]; df
!= 0; df
= df
->next
)
570 if (streq(df
->name
, d
->d_name
))
576 * If re-reading a directory, don't cache files that have
577 * already been discovered.
582 df
= (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
583 df
->next
= dir
->files
[newhash
];
584 dir
->files
[newhash
] = df
;
585 df
->name
= savestring (d
->d_name
, len
);
590 /* Check if the name matches the one we're searching for. */
592 && newhash
== hash
&& strieq (d
->d_name
, filename
))
598 /* If the directory has been completely read in,
599 close the stream and reset the pointer to nil. */
603 closedir (dir
->dirstream
);
609 /* Return 1 if the name FILENAME in directory DIRNAME
610 is entered in the dir hash table.
611 FILENAME must contain no slashes. */
614 dir_file_exists_p (dirname
, filename
)
615 register char *dirname
;
616 register char *filename
;
618 return dir_contents_file_exists_p (find_directory (dirname
)->contents
,
622 /* Return 1 if the file named NAME exists. */
634 return ar_member_date (name
) != (time_t) -1;
638 dirend
= rindex (name
, ']');
640 if (dirend
== (char *)1)
641 return dir_file_exists_p ("[]", name
);
643 dirend
= rindex (name
, '/');
644 #if defined (WINDOWS32) || defined (__MSDOS__)
645 /* Forward and backslashes might be mixed. We need the rightmost one. */
647 char *bslash
= rindex(name
, '\\');
648 if (!dirend
|| bslash
> dirend
)
650 /* The case of "d:file". */
651 if (!dirend
&& name
[0] && name
[1] == ':')
654 #endif /* WINDOWS32 || __MSDOS__ */
657 return dir_file_exists_p (".", name
);
658 #else /* !VMS && !AMIGA */
659 return dir_file_exists_p ("", name
);
668 #if defined (WINDOWS32) || defined (__MSDOS__)
669 /* d:/ and d: are *very* different... */
670 if (dirend
< name
+ 3 && name
[1] == ':' &&
671 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
674 dirname
= (char *) alloca (dirend
- name
+ 1);
675 bcopy (name
, dirname
, dirend
- name
);
676 dirname
[dirend
- name
] = '\0';
678 return dir_file_exists_p (dirname
, slash
+ 1);
681 /* Mark FILENAME as `impossible' for `file_impossible_p'.
682 This means an attempt has been made to search for FILENAME
683 as an intermediate file, and it has failed. */
686 file_impossible (filename
)
687 register char *filename
;
690 register char *p
= filename
;
691 register unsigned int hash
;
692 register struct directory
*dir
;
693 register struct dirfile
*new;
696 dirend
= rindex (p
, ']');
698 if (dirend
== (char *)1)
699 dir
= find_directory ("[]");
701 dirend
= rindex (p
, '/');
702 #if defined (WINDOWS32) || defined (__MSDOS__)
703 /* Forward and backslashes might be mixed. We need the rightmost one. */
705 char *bslash
= rindex(p
, '\\');
706 if (!dirend
|| bslash
> dirend
)
708 /* The case of "d:file". */
709 if (!dirend
&& p
[0] && p
[1] == ':')
712 #endif /* WINDOWS32 or __MSDOS__ */
715 dir
= find_directory ("");
716 #else /* !VMS && !AMIGA */
717 dir
= find_directory (".");
723 char *slash
= dirend
;
728 #if defined (WINDOWS32) || defined (__MSDOS__)
729 /* d:/ and d: are *very* different... */
730 if (dirend
< p
+ 3 && p
[1] == ':' &&
731 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
734 dirname
= (char *) alloca (dirend
- p
+ 1);
735 bcopy (p
, dirname
, dirend
- p
);
736 dirname
[dirend
- p
] = '\0';
738 dir
= find_directory (dirname
);
739 filename
= p
= slash
+ 1;
742 for (hash
= 0; *p
!= '\0'; ++p
)
744 hash
%= DIRFILE_BUCKETS
;
746 if (dir
->contents
== 0)
748 /* The directory could not be stat'd. We allocate a contents
749 structure for it, but leave it out of the contents hash table. */
750 dir
->contents
= (struct directory_contents
*)
751 xmalloc (sizeof (struct directory_contents
));
753 dir
->contents
->path_key
= NULL
;
754 dir
->contents
->mtime
= 0;
755 #else /* WINDOWS32 */
757 dir
->contents
->dev
= 0;
758 dir
->contents
->ino
[0] = dir
->contents
->ino
[1] =
759 dir
->contents
->ino
[2] = 0;
761 dir
->contents
->dev
= dir
->contents
->ino
= 0;
763 #endif /* WINDOWS32 */
764 dir
->contents
->files
= 0;
765 dir
->contents
->dirstream
= 0;
768 if (dir
->contents
->files
== 0)
770 /* The directory was not opened; we must allocate the hash buckets. */
771 dir
->contents
->files
= (struct dirfile
**)
772 xmalloc (sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
773 bzero ((char *) dir
->contents
->files
,
774 sizeof (struct dirfile
) * DIRFILE_BUCKETS
);
777 /* Make a new entry and put it in the table. */
779 new = (struct dirfile
*) xmalloc (sizeof (struct dirfile
));
780 new->next
= dir
->contents
->files
[hash
];
781 dir
->contents
->files
[hash
] = new;
782 new->name
= xstrdup (filename
);
786 /* Return nonzero if FILENAME has been marked impossible. */
789 file_impossible_p (filename
)
793 register char *p
= filename
;
794 register unsigned int hash
;
795 register struct directory_contents
*dir
;
796 register struct dirfile
*next
;
799 dirend
= rindex (filename
, ']');
801 dir
= find_directory ("[]")->contents
;
803 dirend
= rindex (filename
, '/');
804 #if defined (WINDOWS32) || defined (__MSDOS__)
805 /* Forward and backslashes might be mixed. We need the rightmost one. */
807 char *bslash
= rindex(filename
, '\\');
808 if (!dirend
|| bslash
> dirend
)
810 /* The case of "d:file". */
811 if (!dirend
&& filename
[0] && filename
[1] == ':')
812 dirend
= filename
+ 1;
814 #endif /* WINDOWS32 || __MSDOS__ */
817 dir
= find_directory ("")->contents
;
818 #else /* !VMS && !AMIGA */
819 dir
= find_directory (".")->contents
;
825 char *slash
= dirend
;
826 if (dirend
== filename
)
830 #if defined (WINDOWS32) || defined (__MSDOS__)
831 /* d:/ and d: are *very* different... */
832 if (dirend
< filename
+ 3 && filename
[1] == ':' &&
833 (*dirend
== '/' || *dirend
== '\\' || *dirend
== ':'))
836 dirname
= (char *) alloca (dirend
- filename
+ 1);
837 bcopy (p
, dirname
, dirend
- p
);
838 dirname
[dirend
- p
] = '\0';
840 dir
= find_directory (dirname
)->contents
;
841 p
= filename
= slash
+ 1;
844 if (dir
== 0 || dir
->files
== 0)
845 /* There are no files entered for this directory. */
849 p
= filename
= dosify (p
);
851 #ifdef HAVE_CASE_INSENSITIVE_FS
852 p
= filename
= downcase (p
);
855 p
= filename
= vmsify (p
, 1);
858 for (hash
= 0; *p
!= '\0'; ++p
)
860 hash
%= DIRFILE_BUCKETS
;
862 for (next
= dir
->files
[hash
]; next
!= 0; next
= next
->next
)
863 if (strieq (filename
, next
->name
))
864 return next
->impossible
;
869 /* Return the already allocated name in the
870 directory hash table that matches DIR. */
876 return find_directory (dir
)->name
;
879 /* Print the data base of directories. */
882 print_dir_data_base ()
884 register unsigned int i
, dirs
, files
, impossible
;
885 register struct directory
*dir
;
887 puts ("\n# Directories\n");
889 dirs
= files
= impossible
= 0;
890 for (i
= 0; i
< DIRECTORY_BUCKETS
; ++i
)
891 for (dir
= directories
[i
]; dir
!= 0; dir
= dir
->next
)
894 if (dir
->contents
== 0)
895 printf ("# %s: could not be stat'd.\n", dir
->name
);
896 else if (dir
->contents
->files
== 0)
898 printf ("# %s (key %s, mtime %d): could not be opened.\n",
899 dir
->name
, dir
->contents
->path_key
,dir
->contents
->mtime
);
900 #else /* WINDOWS32 */
902 printf ("# %s (device %d, inode [%d,%d,%d]): could not be opened.\n",
903 dir
->name
, dir
->contents
->dev
,
904 dir
->contents
->ino
[0], dir
->contents
->ino
[1],
905 dir
->contents
->ino
[2]);
907 printf ("# %s (device %ld, inode %ld): could not be opened.\n",
908 dir
->name
, (long int) dir
->contents
->dev
,
909 (long int) dir
->contents
->ino
);
911 #endif /* WINDOWS32 */
914 register unsigned int f
= 0, im
= 0;
915 register unsigned int j
;
916 register struct dirfile
*df
;
917 for (j
= 0; j
< DIRFILE_BUCKETS
; ++j
)
918 for (df
= dir
->contents
->files
[j
]; df
!= 0; df
= df
->next
)
924 printf ("# %s (key %s, mtime %d): ",
925 dir
->name
, dir
->contents
->path_key
, dir
->contents
->mtime
);
926 #else /* WINDOWS32 */
928 printf ("# %s (device %d, inode [%d,%d,%d]): ",
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): ",
935 (long)dir
->contents
->dev
, (long)dir
->contents
->ino
);
937 #endif /* WINDOWS32 */
939 fputs ("No", stdout
);
942 fputs (" files, ", stdout
);
944 fputs ("no", stdout
);
947 fputs (" impossibilities", stdout
);
948 if (dir
->contents
->dirstream
== 0)
957 fputs ("\n# ", stdout
);
959 fputs ("No", stdout
);
961 printf ("%u", files
);
962 fputs (" files, ", stdout
);
964 fputs ("no", stdout
);
966 printf ("%u", impossible
);
967 printf (" impossibilities in %u directories.\n", dirs
);
970 /* Hooks for globbing. */
974 /* Structure describing state of iterating through a directory hash table. */
978 struct directory_contents
*contents
; /* The directory being read. */
980 unsigned int bucket
; /* Current hash bucket. */
981 struct dirfile
*elt
; /* Current elt in bucket. */
984 /* Forward declarations. */
985 static __ptr_t open_dirstream
PARAMS ((const char *));
986 static struct dirent
*read_dirstream
PARAMS ((__ptr_t
));
989 open_dirstream (directory
)
990 const char *directory
;
992 struct dirstream
*new;
993 struct directory
*dir
= find_directory ((char *)directory
);
995 if (dir
->contents
== 0 || dir
->contents
->files
== 0)
996 /* DIR->contents is nil if the directory could not be stat'd.
997 DIR->contents->files is nil if it could not be opened. */
1000 /* Read all the contents of the directory now. There is no benefit
1001 in being lazy, since glob will want to see every file anyway. */
1003 (void) dir_contents_file_exists_p (dir
->contents
, (char *) 0);
1005 new = (struct dirstream
*) xmalloc (sizeof (struct dirstream
));
1006 new->contents
= dir
->contents
;
1008 new->elt
= new->contents
->files
[0];
1010 return (__ptr_t
) new;
1013 static struct dirent
*
1014 read_dirstream (stream
)
1017 struct dirstream
*const ds
= (struct dirstream
*) stream
;
1018 register struct dirfile
*df
;
1020 static unsigned int bufsz
;
1022 while (ds
->bucket
< DIRFILE_BUCKETS
)
1024 while ((df
= ds
->elt
) != 0)
1027 if (!df
->impossible
)
1029 /* The glob interface wants a `struct dirent',
1032 unsigned int len
= strlen (df
->name
) + 1;
1033 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1038 if (sizeof *d
- sizeof d
->d_name
+ len
> bufsz
)
1039 bufsz
= sizeof *d
- sizeof d
->d_name
+ len
;
1040 buf
= xmalloc (bufsz
);
1042 d
= (struct dirent
*) buf
;
1044 #ifdef _DIRENT_HAVE_D_NAMLEN
1045 d
->d_namlen
= len
- 1;
1047 memcpy (d
->d_name
, df
->name
, len
);
1051 if (++ds
->bucket
== DIRFILE_BUCKETS
)
1053 ds
->elt
= ds
->contents
->files
[ds
->bucket
];
1075 /* Bogus sunos4 compiler complains (!) about & before functions. */
1076 gl
->gl_opendir
= open_dirstream
;
1077 gl
->gl_readdir
= read_dirstream
;
1078 gl
->gl_closedir
= ansi_free
;
1080 /* We don't bother setting gl_lstat, since glob never calls it.
1081 The slot is only there for compatibility with 4.4 BSD. */