VirtualBox

Changeset 900 in kBuild for vendor/gnumake/current/dir.c


Ignore:
Timestamp:
May 23, 2007 3:13:11 AM (18 years ago)
Author:
bird
Message:

Load /home/bird/src/Gnu/make/2007-05-23 into vendor/gnumake/current.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/gnumake/current/dir.c

    r501 r900  
    2424# define NAMLEN(dirent) strlen((dirent)->d_name)
    2525# ifdef VMS
    26 extern char *vmsify PARAMS ((char *name, int type));
     26char *vmsify (char *name, int type);
    2727# endif
    2828#else
     
    6969#endif
    7070
    71 static char *
    72 dosify (char *filename)
     71static const char *
     72dosify (const char *filename)
    7373{
    7474  static char dos_filename[14];
     
    119119
    120120#ifdef HAVE_CASE_INSENSITIVE_FS
    121 static char *
    122 downcase (char *filename)
     121static const char *
     122downcase (const char *filename)
    123123{
    124124  static PATH_VAR (new_filename);
     
    132132
    133133  /* 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    }
    139139
    140140  *df = 0;
     
    217217    dev_t dev;                  /* Device and inode numbers of this dir.  */
    218218#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.  */
    227224    char *path_key;
    228225    int   ctime;
    229226    int   mtime;        /* controls check for stale directory cache */
    230227    int   fs_flags;     /* FS_FAT, FS_NTFS, ... */
    231 #define FS_FAT      0x1
    232 #define FS_NTFS     0x2
    233 #define FS_UNKNOWN  0x4
    234 #else
    235 #ifdef VMS
     228# define FS_FAT      0x1
     229# define FS_NTFS     0x2
     230# define FS_UNKNOWN  0x4
     231#else
     232# ifdef VMS
    236233    ino_t ino[3];
    237 #else
     234# else
    238235    ino_t ino;
    239 #endif
     236# endif
    240237#endif /* WINDOWS32 */
    241238    struct hash_table dirfiles; /* Files in this directory.  */
     
    246243directory_contents_hash_1 (const void *key_0)
    247244{
    248   struct directory_contents const *key = (struct directory_contents const *) key_0;
     245  const struct directory_contents *key = key_0;
    249246  unsigned long hash;
    250247
     
    269266directory_contents_hash_2 (const void *key_0)
    270267{
    271   struct directory_contents const *key = (struct directory_contents const *) key_0;
     268  const struct directory_contents *key = key_0;
    272269  unsigned long hash;
    273270
     
    304301directory_contents_hash_cmp (const void *xv, const void *yv)
    305302{
    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;
    308305  int result;
    309306
     
    341338struct directory
    342339  {
    343     char *name;                 /* Name of the directory.  */
     340    const char *name;                   /* Name of the directory.  */
    344341
    345342    /* The directory's contents.  This data may be shared by several
     
    352349directory_hash_1 (const void *key)
    353350{
    354   return_ISTRING_HASH_1 (((struct directory const *) key)->name);
     351  return_ISTRING_HASH_1 (((const struct directory *) key)->name);
    355352}
    356353
     
    358355directory_hash_2 (const void *key)
    359356{
    360   return_ISTRING_HASH_2 (((struct directory const *) key)->name);
     357  return_ISTRING_HASH_2 (((const struct directory *) key)->name);
    361358}
    362359
     
    364361directory_hash_cmp (const void *x, const void *y)
    365362{
    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);
    368365}
    369366
     
    382379struct dirfile
    383380  {
    384     char *name;                 /* Name of the file.  */
     381    const char *name;           /* Name of the file.  */
    385382    short length;
    386383    short impossible;           /* This file is impossible.  */
     
    402399dirfile_hash_cmp (const void *xv, const void *yv)
    403400{
    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;
    406403  int result = x->length - y->length;
    407404  if (result)
     
    415412
    416413
    417 static int dir_contents_file_exists_p PARAMS ((struct directory_contents *dir, char *filename));
    418 static struct directory *find_directory PARAMS ((char *name));
     414static int dir_contents_file_exists_p (struct directory_contents *dir,
     415                                       const char *filename);
     416static struct directory *find_directory (const char *name);
    419417
    420418/* Find the directory named NAME and return its `struct directory'.  */
    421419
    422420static struct directory *
    423 find_directory (char *name)
    424 {
    425   register char *p;
    426   register struct directory *dir;
    427   register struct directory **dir_slot;
     421find_directory (const char *name)
     422{
     423  const char *p;
     424  struct directory *dir;
     425  struct directory **dir_slot;
    428426  struct directory dir_key;
    429427  int r;
     
    454452
    455453      p = name + strlen (name);
    456       dir = (struct directory *) xmalloc (sizeof (struct directory));
    457       dir->name = savestring (name, p - name);
     454      dir = xmalloc (sizeof (struct directory));
     455      dir->name = strcache_add_len (name, p - name);
    458456      hash_insert_at (&directories, dir, dir_slot);
    459457      /* The directory is not in the name hash table.
     
    553551              ENULLLOOP (dc->dirstream, opendir (name));
    554552              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.  */
    557555                dc->dirfiles.ht_vec = 0;
    558556              else
     
    565563                    /* We have too many directories open already.
    566564                       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);
    568566                }
    569567            }
     
    582580
    583581static int
    584 dir_contents_file_exists_p (struct directory_contents *dir, char *filename)
     582dir_contents_file_exists_p (struct directory_contents *dir,
     583                            const char *filename)
    585584{
    586585  unsigned int hash;
     
    593592
    594593  if (dir == 0 || dir->dirfiles.ht_vec == 0)
    595     {
    596594    /* The directory could not be stat'd or opened.  */
    597       return 0;
    598     }
     595    return 0;
     596
    599597#ifdef __MSDOS__
    600598  filename = dosify (filename);
     
    626624      dirfile_key.name = filename;
    627625      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);
    629627      if (df)
    630         {
    631           return !df->impossible;
    632         }
     628        return !df->impossible;
    633629    }
    634630
     
    651647              rehash = 1;
    652648            }
    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)
    654650            {
    655651              /* reset date stamp to show most recent re-process.  */
     
    663659
    664660          /* make sure directory can still be opened; if not return.  */
    665           dir->dirstream = opendir(dir->path_key);
     661          dir->dirstream = opendir (dir->path_key);
    666662          if (!dir->dirstream)
    667663            return 0;
     
    682678      ENULLLOOP (d, readdir (dir->dirstream));
    683679      if (d == 0)
    684         break;
     680        {
     681          if (errno)
     682            fatal (NILF, "INTERNAL: readdir: %s\n", strerror (errno));
     683          break;
     684        }
    685685
    686686#if defined(VMS) && defined(HAVE_DIRENT_H)
     
    707707#endif
    708708        {
    709           df = (struct dirfile *) xmalloc (sizeof (struct dirfile));
    710           df->name = savestring (d->d_name, len);
     709          df = xmalloc (sizeof (struct dirfile));
     710          df->name = strcache_add_len (d->d_name, len);
    711711          df->length = len;
    712712          df->impossible = 0;
     
    715715      /* Check if the name matches the one we're searching for.  */
    716716      if (filename != 0 && strieq (d->d_name, filename))
    717         {
    718           return 1;
    719         }
     717        return 1;
    720718    }
    721719
     
    736734
    737735int
    738 dir_file_exists_p (char *dirname, char *filename)
     736dir_file_exists_p (const char *dirname, const char *filename)
    739737{
    740738  return dir_contents_file_exists_p (find_directory (dirname)->contents,
     
    746744
    747745int
    748 file_exists_p (char *name)
    749 {
    750   char *dirend;
    751   char *dirname;
    752   char *slash;
     746file_exists_p (const char *name)
     747{
     748  const char *dirend;
     749  const char *dirname;
     750  const char *slash;
    753751
    754752#ifndef NO_ARCHIVES
     
    761759  if (dirend == 0)
    762760    dirend = strrchr (name, ':');
    763   if (dirend == (char *)0)
     761  if (dirend == 0)
    764762    return dir_file_exists_p ("[]", name);
    765763#else /* !VMS */
     
    768766  /* Forward and backslashes might be mixed.  We need the rightmost one.  */
    769767  {
    770     char *bslash = strrchr(name, '\\');
     768    const char *bslash = strrchr(name, '\\');
    771769    if (!dirend || bslash > dirend)
    772770      dirend = bslash;
     
    789787  else
    790788    {
     789      char *p;
    791790#ifdef HAVE_DOS_PATHS
    792791  /* d:/ and d: are *very* different...  */
     
    795794        dirend++;
    796795#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;
    800800    }
    801801  return dir_file_exists_p (dirname, slash + 1);
     
    808808
    809809void
    810 file_impossible (char *filename)
    811 {
    812   char *dirend;
    813   register char *p = filename;
    814   register struct directory *dir;
    815   register struct dirfile *new;
     810file_impossible (const char *filename)
     811{
     812  const char *dirend;
     813  const char *p = filename;
     814  struct directory *dir;
     815  struct dirfile *new;
    816816
    817817#ifdef VMS
     
    827827  /* Forward and backslashes might be mixed.  We need the rightmost one.  */
    828828  {
    829     char *bslash = strrchr(p, '\\');
     829    const char *bslash = strrchr(p, '\\');
    830830    if (!dirend || bslash > dirend)
    831831      dirend = bslash;
     
    844844  else
    845845    {
    846       char *dirname;
    847       char *slash = dirend;
     846      const char *dirname;
     847      const char *slash = dirend;
    848848      if (dirend == p)
    849849        dirname = "/";
    850850      else
    851851        {
     852          char *cp;
    852853#ifdef HAVE_DOS_PATHS
    853854          /* d:/ and d: are *very* different...  */
     
    856857            dirend++;
    857858#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;
    861863        }
    862864      dir = find_directory (dirname);
     
    868870      /* The directory could not be stat'd.  We allocate a contents
    869871         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));
    873874    }
    874875
     
    881882  /* Make a new entry and put it in the table.  */
    882883
    883   new = (struct dirfile *) xmalloc (sizeof (struct dirfile));
    884   new->name = xstrdup (filename);
     884  new = xmalloc (sizeof (struct dirfile));
    885885  new->length = strlen (filename);
     886  new->name = strcache_add_len (filename, new->length);
    886887  new->impossible = 1;
    887888  hash_insert (&dir->contents->dirfiles, new);
     
    892893
    893894int
    894 file_impossible_p (char *filename)
    895 {
    896   char *dirend;
    897   register char *p = filename;
    898   register struct directory_contents *dir;
    899   register struct dirfile *dirfile;
     895file_impossible_p (const char *filename)
     896{
     897  const char *dirend;
     898  const char *p = filename;
     899  struct directory_contents *dir;
     900  struct dirfile *dirfile;
    900901  struct dirfile dirfile_key;
    901902
     
    909910  /* Forward and backslashes might be mixed.  We need the rightmost one.  */
    910911  {
    911     char *bslash = strrchr(filename, '\\');
     912    const char *bslash = strrchr(filename, '\\');
    912913    if (!dirend || bslash > dirend)
    913914      dirend = bslash;
     
    926927  else
    927928    {
    928       char *dirname;
    929       char *slash = dirend;
     929      const char *dirname;
     930      const char *slash = dirend;
    930931      if (dirend == filename)
    931932        dirname = "/";
    932933      else
    933934        {
     935          char *cp;
    934936#ifdef HAVE_DOS_PATHS
    935937          /* d:/ and d: are *very* different...  */
     
    938940            dirend++;
    939941#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;
    943946        }
    944947      dir = find_directory (dirname)->contents;
     
    962965  dirfile_key.name = filename;
    963966  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);
    965968  if (dirfile)
    966969    return dirfile->impossible;
     
    973976   directory hash table that matches DIR.  */
    974977
    975 char *
    976 dir_name (char *dir)
     978const char *
     979dir_name (const char *dir)
    977980{
    978981  return find_directory (dir)->name;
     
    985988print_dir_data_base (void)
    986989{
    987   register unsigned int files;
    988   register unsigned int impossible;
    989   register struct directory **dir_slot;
    990   register struct directory **dir_end;
     990  unsigned int files;
     991  unsigned int impossible;
     992  struct directory **dir_slot;
     993  struct directory **dir_end;
    991994
    992995  puts (_("\n# Directories\n"));
     
    9981001  for ( ; dir_slot < dir_end; dir_slot++)
    9991002    {
    1000       register struct directory *dir = *dir_slot;
     1003      struct directory *dir = *dir_slot;
    10011004      if (! HASH_VACANT (dir))
    10021005        {
     
    10231026          else
    10241027            {
    1025               register unsigned int f = 0;
    1026               register unsigned int im = 0;
    1027               register struct dirfile **files_slot;
    1028               register struct dirfile **files_end;
     1028              unsigned int f = 0;
     1029              unsigned int im = 0;
     1030              struct dirfile **files_slot;
     1031              struct dirfile **files_end;
    10291032
    10301033              files_slot = (struct dirfile **) dir->contents->dirfiles.ht_vec;
     
    10321035              for ( ; files_slot < files_end; files_slot++)
    10331036                {
    1034                   register struct dirfile *df = *files_slot;
     1037                  struct dirfile *df = *files_slot;
    10351038                  if (! HASH_VACANT (df))
    10361039                    {
     
    11031106
    11041107/* Forward declarations.  */
    1105 static __ptr_t open_dirstream PARAMS ((const char *));
    1106 static struct dirent *read_dirstream PARAMS ((__ptr_t));
     1108static __ptr_t open_dirstream (const char *);
     1109static struct dirent *read_dirstream (__ptr_t);
    11071110
    11081111static __ptr_t
     
    11101113{
    11111114  struct dirstream *new;
    1112   struct directory *dir = find_directory ((char *)directory);
     1115  struct directory *dir = find_directory (directory);
    11131116
    11141117  if (dir->contents == 0 || dir->contents->dirfiles.ht_vec == 0)
     
    11201123     in being lazy, since glob will want to see every file anyway.  */
    11211124
    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));
    11251128  new->contents = dir->contents;
    11261129  new->dirfile_slot = (struct dirfile **) new->contents->dirfiles.ht_vec;
     
    11321135read_dirstream (__ptr_t stream)
    11331136{
     1137  static char *buf;
     1138  static unsigned int bufsz;
     1139
    11341140  struct dirstream *const ds = (struct dirstream *) stream;
    11351141  struct directory_contents *dc = ds->contents;
    11361142  struct dirfile **dirfile_end = (struct dirfile **) dc->dirfiles.ht_vec + dc->dirfiles.ht_size;
    1137   static char *buf;
    1138   static unsigned int bufsz;
    11391143
    11401144  while (ds->dirfile_slot < dirfile_end)
    11411145    {
    1142       register struct dirfile *df = *ds->dirfile_slot++;
     1146      struct dirfile *df = *ds->dirfile_slot++;
    11431147      if (! HASH_VACANT (df) && !df->impossible)
    11441148        {
    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.  */
    11471150          struct dirent *d;
    11481151          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)
    11501154            {
    1151               if (buf != 0)
    1152                 free (buf);
    11531155              bufsz *= 2;
    1154               if (sizeof *d - sizeof d->d_name + len > bufsz)
    1155                 bufsz = sizeof *d - sizeof d->d_name + len;
    1156               buf = xmalloc (bufsz);
     1156              if (sz > bufsz)
     1157                bufsz = sz;
     1158              buf = xrealloc (buf, bufsz);
    11571159            }
    11581160          d = (struct dirent *) buf;
     
    11911193#ifndef stat
    11921194# ifndef VMS
    1193 extern int stat PARAMS ((const char *path, struct stat *sbuf));
     1195int stat (const char *path, struct stat *sbuf);
    11941196# endif
    11951197# define local_stat stat
     
    12081210dir_setup_glob (glob_t *gl)
    12091211{
    1210   /* Bogus sunos4 compiler complains (!) about & before functions.  */
    12111212  gl->gl_opendir = open_dirstream;
    12121213  gl->gl_readdir = read_dirstream;
     
    12231224             directory_hash_1, directory_hash_2, directory_hash_cmp);
    12241225  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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette