Changeset 900 in kBuild for vendor/gnumake/current/dir.c
- Timestamp:
- May 23, 2007 3:13:11 AM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/gnumake/current/dir.c
r501 r900 24 24 # define NAMLEN(dirent) strlen((dirent)->d_name) 25 25 # ifdef VMS 26 extern char *vmsify PARAMS ((char *name, int type));26 char *vmsify (char *name, int type); 27 27 # endif 28 28 #else … … 69 69 #endif 70 70 71 static c har *72 dosify (c har *filename)71 static const char * 72 dosify (const char *filename) 73 73 { 74 74 static char dos_filename[14]; … … 119 119 120 120 #ifdef HAVE_CASE_INSENSITIVE_FS 121 static c har *122 downcase (c har *filename)121 static const char * 122 downcase (const char *filename) 123 123 { 124 124 static PATH_VAR (new_filename); … … 132 132 133 133 /* First, transform the name part. */ 134 for (i = 0; *filename != '\0'; ++i)135 {136 *df++ = tolower ((unsigned char)*filename);137 ++filename;138 }134 while (*filename != '\0') 135 { 136 *df++ = tolower ((unsigned char)*filename); 137 ++filename; 138 } 139 139 140 140 *df = 0; … … 217 217 dev_t dev; /* Device and inode numbers of this dir. */ 218 218 #ifdef WINDOWS32 219 /* 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. 226 */ 219 /* Inode means nothing on WINDOWS32. Even file key information is 220 * unreliable because it is random per file open and undefined for remote 221 * filesystems. The most unique attribute I can come up with is the fully 222 * qualified name of the directory. Beware though, this is also 223 * unreliable. I'm open to suggestion on a better way to emulate inode. */ 227 224 char *path_key; 228 225 int ctime; 229 226 int mtime; /* controls check for stale directory cache */ 230 227 int fs_flags; /* FS_FAT, FS_NTFS, ... */ 231 # define FS_FAT 0x1232 # define FS_NTFS 0x2233 # define FS_UNKNOWN 0x4234 #else 235 # ifdef VMS228 # define FS_FAT 0x1 229 # define FS_NTFS 0x2 230 # define FS_UNKNOWN 0x4 231 #else 232 # ifdef VMS 236 233 ino_t ino[3]; 237 # else234 # else 238 235 ino_t ino; 239 # endif236 # endif 240 237 #endif /* WINDOWS32 */ 241 238 struct hash_table dirfiles; /* Files in this directory. */ … … 246 243 directory_contents_hash_1 (const void *key_0) 247 244 { 248 struct directory_contents const *key = (struct directory_contents const *)key_0;245 const struct directory_contents *key = key_0; 249 246 unsigned long hash; 250 247 … … 269 266 directory_contents_hash_2 (const void *key_0) 270 267 { 271 struct directory_contents const *key = (struct directory_contents const *)key_0;268 const struct directory_contents *key = key_0; 272 269 unsigned long hash; 273 270 … … 304 301 directory_contents_hash_cmp (const void *xv, const void *yv) 305 302 { 306 struct directory_contents const *x = (struct directory_contents const *)xv;307 struct directory_contents const *y = (struct directory_contents const *)yv;303 const struct directory_contents *x = xv; 304 const struct directory_contents *y = yv; 308 305 int result; 309 306 … … 341 338 struct directory 342 339 { 343 c har *name; /* Name of the directory. */340 const char *name; /* Name of the directory. */ 344 341 345 342 /* The directory's contents. This data may be shared by several … … 352 349 directory_hash_1 (const void *key) 353 350 { 354 return_ISTRING_HASH_1 ((( struct directory const*) key)->name);351 return_ISTRING_HASH_1 (((const struct directory *) key)->name); 355 352 } 356 353 … … 358 355 directory_hash_2 (const void *key) 359 356 { 360 return_ISTRING_HASH_2 ((( struct directory const*) key)->name);357 return_ISTRING_HASH_2 (((const struct directory *) key)->name); 361 358 } 362 359 … … 364 361 directory_hash_cmp (const void *x, const void *y) 365 362 { 366 return_ISTRING_COMPARE ((( struct directory const*) x)->name,367 (( struct directory const*) y)->name);363 return_ISTRING_COMPARE (((const struct directory *) x)->name, 364 ((const struct directory *) y)->name); 368 365 } 369 366 … … 382 379 struct dirfile 383 380 { 384 c har *name;/* Name of the file. */381 const char *name; /* Name of the file. */ 385 382 short length; 386 383 short impossible; /* This file is impossible. */ … … 402 399 dirfile_hash_cmp (const void *xv, const void *yv) 403 400 { 404 struct dirfile const *x = ((struct dirfile const *) xv);405 struct dirfile const *y = ((struct dirfile const *) yv);401 const struct dirfile *x = xv; 402 const struct dirfile *y = yv; 406 403 int result = x->length - y->length; 407 404 if (result) … … 415 412 416 413 417 static int dir_contents_file_exists_p PARAMS ((struct directory_contents *dir, char *filename)); 418 static struct directory *find_directory PARAMS ((char *name)); 414 static int dir_contents_file_exists_p (struct directory_contents *dir, 415 const char *filename); 416 static struct directory *find_directory (const char *name); 419 417 420 418 /* Find the directory named NAME and return its `struct directory'. */ 421 419 422 420 static struct directory * 423 find_directory (c har *name)424 { 425 registerchar *p;426 registerstruct directory *dir;427 registerstruct directory **dir_slot;421 find_directory (const char *name) 422 { 423 const char *p; 424 struct directory *dir; 425 struct directory **dir_slot; 428 426 struct directory dir_key; 429 427 int r; … … 454 452 455 453 p = name + strlen (name); 456 dir = (struct directory *)xmalloc (sizeof (struct directory));457 dir->name = s avestring(name, p - name);454 dir = xmalloc (sizeof (struct directory)); 455 dir->name = strcache_add_len (name, p - name); 458 456 hash_insert_at (&directories, dir, dir_slot); 459 457 /* The directory is not in the name hash table. … … 553 551 ENULLLOOP (dc->dirstream, opendir (name)); 554 552 if (dc->dirstream == 0) 555 /* Couldn't open the directory. Mark this by 556 setting the`files' member to a nil pointer. */553 /* Couldn't open the directory. Mark this by setting the 554 `files' member to a nil pointer. */ 557 555 dc->dirfiles.ht_vec = 0; 558 556 else … … 565 563 /* We have too many directories open already. 566 564 Read the entire directory and then close it. */ 567 (void) dir_contents_file_exists_p (dc, (char *)0);565 dir_contents_file_exists_p (dc, 0); 568 566 } 569 567 } … … 582 580 583 581 static int 584 dir_contents_file_exists_p (struct directory_contents *dir, char *filename) 582 dir_contents_file_exists_p (struct directory_contents *dir, 583 const char *filename) 585 584 { 586 585 unsigned int hash; … … 593 592 594 593 if (dir == 0 || dir->dirfiles.ht_vec == 0) 595 {596 594 /* The directory could not be stat'd or opened. */ 597 598 } 595 return 0; 596 599 597 #ifdef __MSDOS__ 600 598 filename = dosify (filename); … … 626 624 dirfile_key.name = filename; 627 625 dirfile_key.length = strlen (filename); 628 df = (struct dirfile *)hash_find_item (&dir->dirfiles, &dirfile_key);626 df = hash_find_item (&dir->dirfiles, &dirfile_key); 629 627 if (df) 630 { 631 return !df->impossible; 632 } 628 return !df->impossible; 633 629 } 634 630 … … 651 647 rehash = 1; 652 648 } 653 else if (stat (dir->path_key, &st) == 0 && st.st_mtime > dir->mtime)649 else if (stat (dir->path_key, &st) == 0 && st.st_mtime > dir->mtime) 654 650 { 655 651 /* reset date stamp to show most recent re-process. */ … … 663 659 664 660 /* make sure directory can still be opened; if not return. */ 665 dir->dirstream = opendir (dir->path_key);661 dir->dirstream = opendir (dir->path_key); 666 662 if (!dir->dirstream) 667 663 return 0; … … 682 678 ENULLLOOP (d, readdir (dir->dirstream)); 683 679 if (d == 0) 684 break; 680 { 681 if (errno) 682 fatal (NILF, "INTERNAL: readdir: %s\n", strerror (errno)); 683 break; 684 } 685 685 686 686 #if defined(VMS) && defined(HAVE_DIRENT_H) … … 707 707 #endif 708 708 { 709 df = (struct dirfile *)xmalloc (sizeof (struct dirfile));710 df->name = s avestring(d->d_name, len);709 df = xmalloc (sizeof (struct dirfile)); 710 df->name = strcache_add_len (d->d_name, len); 711 711 df->length = len; 712 712 df->impossible = 0; … … 715 715 /* Check if the name matches the one we're searching for. */ 716 716 if (filename != 0 && strieq (d->d_name, filename)) 717 { 718 return 1; 719 } 717 return 1; 720 718 } 721 719 … … 736 734 737 735 int 738 dir_file_exists_p (c har *dirname,char *filename)736 dir_file_exists_p (const char *dirname, const char *filename) 739 737 { 740 738 return dir_contents_file_exists_p (find_directory (dirname)->contents, … … 746 744 747 745 int 748 file_exists_p (c har *name)749 { 750 c har *dirend;751 c har *dirname;752 c har *slash;746 file_exists_p (const char *name) 747 { 748 const char *dirend; 749 const char *dirname; 750 const char *slash; 753 751 754 752 #ifndef NO_ARCHIVES … … 761 759 if (dirend == 0) 762 760 dirend = strrchr (name, ':'); 763 if (dirend == (char *)0)761 if (dirend == 0) 764 762 return dir_file_exists_p ("[]", name); 765 763 #else /* !VMS */ … … 768 766 /* Forward and backslashes might be mixed. We need the rightmost one. */ 769 767 { 770 c har *bslash = strrchr(name, '\\');768 const char *bslash = strrchr(name, '\\'); 771 769 if (!dirend || bslash > dirend) 772 770 dirend = bslash; … … 789 787 else 790 788 { 789 char *p; 791 790 #ifdef HAVE_DOS_PATHS 792 791 /* d:/ and d: are *very* different... */ … … 795 794 dirend++; 796 795 #endif 797 dirname = (char *) alloca (dirend - name + 1); 798 bcopy (name, dirname, dirend - name); 799 dirname[dirend - name] = '\0'; 796 p = alloca (dirend - name + 1); 797 memcpy (p, name, dirend - name); 798 p[dirend - name] = '\0'; 799 dirname = p; 800 800 } 801 801 return dir_file_exists_p (dirname, slash + 1); … … 808 808 809 809 void 810 file_impossible (c har *filename)811 { 812 c har *dirend;813 registerchar *p = filename;814 registerstruct directory *dir;815 registerstruct dirfile *new;810 file_impossible (const char *filename) 811 { 812 const char *dirend; 813 const char *p = filename; 814 struct directory *dir; 815 struct dirfile *new; 816 816 817 817 #ifdef VMS … … 827 827 /* Forward and backslashes might be mixed. We need the rightmost one. */ 828 828 { 829 c har *bslash = strrchr(p, '\\');829 const char *bslash = strrchr(p, '\\'); 830 830 if (!dirend || bslash > dirend) 831 831 dirend = bslash; … … 844 844 else 845 845 { 846 c har *dirname;847 c har *slash = dirend;846 const char *dirname; 847 const char *slash = dirend; 848 848 if (dirend == p) 849 849 dirname = "/"; 850 850 else 851 851 { 852 char *cp; 852 853 #ifdef HAVE_DOS_PATHS 853 854 /* d:/ and d: are *very* different... */ … … 856 857 dirend++; 857 858 #endif 858 dirname = (char *) alloca (dirend - p + 1); 859 bcopy (p, dirname, dirend - p); 860 dirname[dirend - p] = '\0'; 859 cp = alloca (dirend - p + 1); 860 memcpy (cp, p, dirend - p); 861 cp[dirend - p] = '\0'; 862 dirname = cp; 861 863 } 862 864 dir = find_directory (dirname); … … 868 870 /* The directory could not be stat'd. We allocate a contents 869 871 structure for it, but leave it out of the contents hash table. */ 870 dir->contents = (struct directory_contents *) 871 xmalloc (sizeof (struct directory_contents)); 872 bzero ((char *) dir->contents, sizeof (struct directory_contents)); 872 dir->contents = xmalloc (sizeof (struct directory_contents)); 873 memset (dir->contents, '\0', sizeof (struct directory_contents)); 873 874 } 874 875 … … 881 882 /* Make a new entry and put it in the table. */ 882 883 883 new = (struct dirfile *) xmalloc (sizeof (struct dirfile)); 884 new->name = xstrdup (filename); 884 new = xmalloc (sizeof (struct dirfile)); 885 885 new->length = strlen (filename); 886 new->name = strcache_add_len (filename, new->length); 886 887 new->impossible = 1; 887 888 hash_insert (&dir->contents->dirfiles, new); … … 892 893 893 894 int 894 file_impossible_p (c har *filename)895 { 896 c har *dirend;897 registerchar *p = filename;898 registerstruct directory_contents *dir;899 registerstruct dirfile *dirfile;895 file_impossible_p (const char *filename) 896 { 897 const char *dirend; 898 const char *p = filename; 899 struct directory_contents *dir; 900 struct dirfile *dirfile; 900 901 struct dirfile dirfile_key; 901 902 … … 909 910 /* Forward and backslashes might be mixed. We need the rightmost one. */ 910 911 { 911 c har *bslash = strrchr(filename, '\\');912 const char *bslash = strrchr(filename, '\\'); 912 913 if (!dirend || bslash > dirend) 913 914 dirend = bslash; … … 926 927 else 927 928 { 928 c har *dirname;929 c har *slash = dirend;929 const char *dirname; 930 const char *slash = dirend; 930 931 if (dirend == filename) 931 932 dirname = "/"; 932 933 else 933 934 { 935 char *cp; 934 936 #ifdef HAVE_DOS_PATHS 935 937 /* d:/ and d: are *very* different... */ … … 938 940 dirend++; 939 941 #endif 940 dirname = (char *) alloca (dirend - filename + 1); 941 bcopy (p, dirname, dirend - p); 942 dirname[dirend - p] = '\0'; 942 cp = alloca (dirend - filename + 1); 943 memcpy (cp, p, dirend - p); 944 cp[dirend - p] = '\0'; 945 dirname = cp; 943 946 } 944 947 dir = find_directory (dirname)->contents; … … 962 965 dirfile_key.name = filename; 963 966 dirfile_key.length = strlen (filename); 964 dirfile = (struct dirfile *)hash_find_item (&dir->dirfiles, &dirfile_key);967 dirfile = hash_find_item (&dir->dirfiles, &dirfile_key); 965 968 if (dirfile) 966 969 return dirfile->impossible; … … 973 976 directory hash table that matches DIR. */ 974 977 975 c har *976 dir_name (c har *dir)978 const char * 979 dir_name (const char *dir) 977 980 { 978 981 return find_directory (dir)->name; … … 985 988 print_dir_data_base (void) 986 989 { 987 registerunsigned int files;988 registerunsigned int impossible;989 registerstruct directory **dir_slot;990 registerstruct directory **dir_end;990 unsigned int files; 991 unsigned int impossible; 992 struct directory **dir_slot; 993 struct directory **dir_end; 991 994 992 995 puts (_("\n# Directories\n")); … … 998 1001 for ( ; dir_slot < dir_end; dir_slot++) 999 1002 { 1000 registerstruct directory *dir = *dir_slot;1003 struct directory *dir = *dir_slot; 1001 1004 if (! HASH_VACANT (dir)) 1002 1005 { … … 1023 1026 else 1024 1027 { 1025 registerunsigned int f = 0;1026 registerunsigned int im = 0;1027 registerstruct dirfile **files_slot;1028 registerstruct dirfile **files_end;1028 unsigned int f = 0; 1029 unsigned int im = 0; 1030 struct dirfile **files_slot; 1031 struct dirfile **files_end; 1029 1032 1030 1033 files_slot = (struct dirfile **) dir->contents->dirfiles.ht_vec; … … 1032 1035 for ( ; files_slot < files_end; files_slot++) 1033 1036 { 1034 registerstruct dirfile *df = *files_slot;1037 struct dirfile *df = *files_slot; 1035 1038 if (! HASH_VACANT (df)) 1036 1039 { … … 1103 1106 1104 1107 /* Forward declarations. */ 1105 static __ptr_t open_dirstream PARAMS ((const char *));1106 static struct dirent *read_dirstream PARAMS ((__ptr_t));1108 static __ptr_t open_dirstream (const char *); 1109 static struct dirent *read_dirstream (__ptr_t); 1107 1110 1108 1111 static __ptr_t … … 1110 1113 { 1111 1114 struct dirstream *new; 1112 struct directory *dir = find_directory ( (char *)directory);1115 struct directory *dir = find_directory (directory); 1113 1116 1114 1117 if (dir->contents == 0 || dir->contents->dirfiles.ht_vec == 0) … … 1120 1123 in being lazy, since glob will want to see every file anyway. */ 1121 1124 1122 (void) dir_contents_file_exists_p (dir->contents, (char *)0);1123 1124 new = (struct dirstream *)xmalloc (sizeof (struct dirstream));1125 dir_contents_file_exists_p (dir->contents, 0); 1126 1127 new = xmalloc (sizeof (struct dirstream)); 1125 1128 new->contents = dir->contents; 1126 1129 new->dirfile_slot = (struct dirfile **) new->contents->dirfiles.ht_vec; … … 1132 1135 read_dirstream (__ptr_t stream) 1133 1136 { 1137 static char *buf; 1138 static unsigned int bufsz; 1139 1134 1140 struct dirstream *const ds = (struct dirstream *) stream; 1135 1141 struct directory_contents *dc = ds->contents; 1136 1142 struct dirfile **dirfile_end = (struct dirfile **) dc->dirfiles.ht_vec + dc->dirfiles.ht_size; 1137 static char *buf;1138 static unsigned int bufsz;1139 1143 1140 1144 while (ds->dirfile_slot < dirfile_end) 1141 1145 { 1142 registerstruct dirfile *df = *ds->dirfile_slot++;1146 struct dirfile *df = *ds->dirfile_slot++; 1143 1147 if (! HASH_VACANT (df) && !df->impossible) 1144 1148 { 1145 /* The glob interface wants a `struct dirent', 1146 so mock one up. */ 1149 /* The glob interface wants a `struct dirent', so mock one up. */ 1147 1150 struct dirent *d; 1148 1151 unsigned int len = df->length + 1; 1149 if (sizeof *d - sizeof d->d_name + len > bufsz) 1152 unsigned int sz = sizeof (*d) - sizeof (d->d_name) + len; 1153 if (sz > bufsz) 1150 1154 { 1151 if (buf != 0)1152 free (buf);1153 1155 bufsz *= 2; 1154 if (s izeof *d - sizeof d->d_name + len> bufsz)1155 bufsz = s izeof *d - sizeof d->d_name + len;1156 buf = x malloc (bufsz);1156 if (sz > bufsz) 1157 bufsz = sz; 1158 buf = xrealloc (buf, bufsz); 1157 1159 } 1158 1160 d = (struct dirent *) buf; … … 1191 1193 #ifndef stat 1192 1194 # ifndef VMS 1193 extern int stat PARAMS ((const char *path, struct stat *sbuf));1195 int stat (const char *path, struct stat *sbuf); 1194 1196 # endif 1195 1197 # define local_stat stat … … 1208 1210 dir_setup_glob (glob_t *gl) 1209 1211 { 1210 /* Bogus sunos4 compiler complains (!) about & before functions. */1211 1212 gl->gl_opendir = open_dirstream; 1212 1213 gl->gl_readdir = read_dirstream; … … 1223 1224 directory_hash_1, directory_hash_2, directory_hash_cmp); 1224 1225 hash_init (&directory_contents, DIRECTORY_BUCKETS, 1225 directory_contents_hash_1, directory_contents_hash_2, directory_contents_hash_cmp); 1226 } 1226 directory_contents_hash_1, directory_contents_hash_2, 1227 directory_contents_hash_cmp); 1228 }
Note:
See TracChangeset
for help on using the changeset viewer.