Ignore:
Timestamp:
Mar 14, 2018, 10:28:10 PM (7 years ago)
Author:
bird
Message:

kmk: Merged in changes from GNU make 4.2.1 (2e55f5e4abdc0e38c1d64be703b446695e70b3b6 / https://git.savannah.gnu.org/git/make.git).

Location:
trunk/src/kmk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk

  • trunk/src/kmk/arscan.c

    r2591 r3140  
    11/* Library function for scanning an archive file.
    2 Copyright (C) 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997,
    3 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
    4 2010 Free Software Foundation, Inc.
     2Copyright (C) 1987-2016 Free Software Foundation, Inc.
    53This file is part of GNU Make.
    64
     
    1715this program.  If not, see <http://www.gnu.org/licenses/>.  */
    1816
    19 #include "make.h"
     17#include "makeint.h"
     18
     19#ifdef TEST
     20/* Hack, the real error() routine eventually pulls in die from main.c */
     21#define error(a, b, c, d)
     22#endif
    2023
    2124#ifdef HAVE_FCNTL_H
     
    2528#endif
    2629
    27 #ifndef NO_ARCHIVES
     30#ifndef NO_ARCHIVES
    2831
    2932#ifdef VMS
     
    3336#include <descrip.h>
    3437#include <ctype.h>
    35 #if __DECC
     38#include <ssdef.h>
     39#include <stsdef.h>
     40#include <rmsdef.h>
     41
     42/* This symbol should be present in lbrdef.h. */
     43#ifndef LBR$_HDRTRUNC
     44#pragma extern_model save
     45#pragma extern_model globalvalue
     46extern unsigned int LBR$_HDRTRUNC;
     47#pragma extern_model restore
     48#endif
     49
    3650#include <unixlib.h>
    3751#include <lbr$routines.h>
    38 #endif
    39 
     52
     53const char *
     54vmsify (const char *name, int type);
     55
     56/* Time conversion from VMS to Unix
     57   Conversion from local time (stored in library) to GMT (needed for gmake)
     58   Note: The tm_gmtoff element is a VMS extension to the ANSI standard. */
     59static time_t
     60vms_time_to_unix(void *vms_time)
     61{
     62  struct tm *tmp;
     63  time_t unix_time;
     64
     65  unix_time = decc$fix_time(vms_time);
     66  tmp = localtime(&unix_time);
     67  unix_time -= tmp->tm_gmtoff;
     68
     69  return unix_time;
     70}
     71
     72
     73/* VMS library routines need static variables for callback */
    4074static void *VMS_lib_idx;
    4175
    42 static char *VMS_saved_memname;
    43 
    44 static time_t VMS_member_date;
     76static const void *VMS_saved_arg;
    4577
    4678static long int (*VMS_function) ();
    4779
     80static long int VMS_function_ret;
     81
     82
     83/* This is a callback procedure for lib$get_index */
    4884static int
    49 VMS_get_member_info (struct dsc$descriptor_s *module, unsigned long *rfa)
     85VMS_get_member_info(struct dsc$descriptor_s *module, unsigned long *rfa)
    5086{
    5187  int status, i;
    52   long int fnval;
    53 
    54   time_t val;
     88  const int truncated = 0; /* Member name may be truncated */
     89  time_t member_date; /* Member date */
     90  char *filename;
     91  unsigned int buffer_length; /* Actual buffer length */
     92
     93  /* Unused constants - Make does not actually use most of these */
     94  const int file_desc = -1; /* archive file descriptor for reading the data */
     95  const int header_position = 0; /* Header position */
     96  const int data_position = 0; /* Data position in file */
     97  const int data_size = 0; /* Data size */
     98  const int uid = 0; /* member gid */
     99  const int gid = 0; /* member gid */
     100  const int mode = 0; /* member protection mode */
     101  /* End of unused constants */
    55102
    56103  static struct dsc$descriptor_s bufdesc =
    57104    { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
    58105
     106  /* Only need the module definition */
    59107  struct mhddef *mhd;
    60   char filename[128];
    61 
    62   bufdesc.dsc$a_pointer = filename;
    63   bufdesc.dsc$w_length = sizeof (filename);
    64 
    65   status = lbr$set_module (&VMS_lib_idx, rfa, &bufdesc,
    66                            &bufdesc.dsc$w_length, 0);
    67   if (! (status & 1))
     108
     109  /* If a previous callback is non-zero, just return that status */
     110  if (VMS_function_ret)
    68111    {
    69       error (NILF, _("lbr$set_module() failed to extract module info, status = %d"),
    70              status);
    71 
    72       lbr$close (&VMS_lib_idx);
    73 
    74       return 0;
     112      return SS$_NORMAL;
    75113    }
    76114
    77   mhd = (struct mhddef *) filename;
    78 
    79 #ifdef __DECC
    80   /* John Fowler <jfowler@nyx.net> writes this is needed in his environment,
    81    * but that decc$fix_time() isn't documented to work this way.  Let me
    82    * know if this causes problems in other VMS environments.
    83    */
    84   {
    85     /* Modified by M. Gehre at 11-JAN-2008 because old formula is wrong:
    86      * val = decc$fix_time (&mhd->mhd$l_datim) + timezone - daylight*3600;
    87      * a) daylight specifies, if the timezone has daylight saving enabled, not
    88      *    if it is active
    89      * b) what we need is the information, if daylight saving was active, if
    90      *    the library module was replaced. This information we get using the
    91      *    localtime function
    92      */
    93 
    94     struct tm *tmp;
    95 
    96     /* Conversion from VMS time to C time */
    97     val = decc$fix_time (&mhd->mhd$l_datim);
    98 
    99     /*
    100      * Conversion from local time (stored in library) to GMT (needed for gmake)
    101      * Note: The tm_gmtoff element is a VMS extension to the ANSI standard.
    102      */
    103     tmp = localtime (&val);
    104     val -= tmp->tm_gmtoff;
    105   }
    106 #endif
    107 
     115  /* lbr_set_module returns more than just the module header. So allocate
     116     a buffer which is big enough: the maximum LBR$C_MAXHDRSIZ. That's at
     117     least bigger than the size of struct mhddef.
     118     If the request is too small, a buffer truncated warning is issued so
     119     it can be reissued with a larger buffer.
     120     We do not care if the buffer is truncated, so that is still a success. */
     121  mhd = xmalloc(LBR$C_MAXHDRSIZ);
     122  bufdesc.dsc$a_pointer = (char *) mhd;
     123  bufdesc.dsc$w_length = LBR$C_MAXHDRSIZ;
     124
     125  status = lbr$set_module(&VMS_lib_idx, rfa, &bufdesc, &buffer_length, 0);
     126
     127  if ((status != LBR$_HDRTRUNC) && !$VMS_STATUS_SUCCESS(status))
     128    {
     129      ON(error, NILF,
     130          _("lbr$set_module() failed to extract module info, status = %d"),
     131          status);
     132
     133      lbr$close(&VMS_lib_idx);
     134
     135      return status;
     136    }
     137
     138#ifdef TEST
     139  /* When testing this code, it is useful to know the length returned */
     140  printf("Input length = %d, actual = %d\n",
     141      bufdesc.dsc$w_length, buffer_length);
     142#endif
     143
     144  /* Conversion from VMS time to C time.
     145     VMS defectlet - mhddef is sub-optimal, for the time, it has a 32 bit
     146     longword, mhd$l_datim, and a 32 bit fill instead of two longwords, or
     147     equivalent. */
     148  member_date = vms_time_to_unix(&mhd->mhd$l_datim);
     149  free(mhd);
     150
     151  /* Here we have a problem.  The module name on VMS does not have
     152     a file type, but the filename pattern in the "VMS_saved_arg"
     153     may have one.
     154     But only the method being called knows how to interpret the
     155     filename pattern.
     156     There are currently two different formats being used.
     157     This means that we need a VMS specific code in those methods
     158     to handle it. */
     159  filename = xmalloc(module->dsc$w_length + 1);
     160
     161  /* TODO: We may need an option to preserve the case of the module
     162     For now force the module name to lower case */
    108163  for (i = 0; i < module->dsc$w_length; i++)
    109     filename[i] = _tolower ((unsigned char)module->dsc$a_pointer[i]);
     164    filename[i] = _tolower((unsigned char )module->dsc$a_pointer[i]);
    110165
    111166  filename[i] = '\0';
    112167
    113   VMS_member_date = (time_t) -1;
    114 
    115   fnval =
    116     (*VMS_function) (-1, filename, 0, 0, 0, 0, val, 0, 0, 0,
    117                      VMS_saved_memname);
    118 
    119   if (fnval)
    120     {
    121       VMS_member_date = fnval;
    122       return 0;
    123     }
    124   else
    125     return 1;
     168  VMS_function_ret = (*VMS_function)(file_desc, filename, truncated,
     169      header_position, data_position, data_size, member_date, uid, gid, mode,
     170      VMS_saved_arg);
     171
     172  free(filename);
     173  return SS$_NORMAL;
    126174}
     175
    127176
    128177/* Takes three arguments ARCHIVE, FUNCTION and ARG.
     
    156205
    157206long int
    158 ar_scan (const char *archive, ar_member_func_t function, const void *arg)
     207ar_scan (const char *archive, ar_member_func_t function, const void *varg)
    159208{
    160   char *p;
     209  char *vms_archive;
    161210
    162211  static struct dsc$descriptor_s libdesc =
    163212    { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL };
    164213
    165   unsigned long func = LBR$C_READ;
    166   unsigned long type = LBR$C_TYP_UNK;
    167   unsigned long index = 1;
    168 
     214  const unsigned long func = LBR$C_READ;
     215  const unsigned long type = LBR$C_TYP_UNK;
     216  const unsigned long index = 1;
     217  unsigned long lib_idx;
    169218  int status;
    170219
    171   status = lbr$ini_control (&VMS_lib_idx, &func, &type, 0);
    172 
    173   if (! (status & 1))
     220  VMS_saved_arg = varg;
     221
     222  /* Null archive string can show up in test and cause an access violation */
     223  if (archive == NULL)
    174224    {
    175       error (NILF, _("lbr$ini_control() failed with status = %d"), status);
     225      /* Null filenames do not exist */
     226      return -1;
     227    }
     228
     229  /* archive path name must be in VMS format */
     230  vms_archive = (char *) vmsify(archive, 0);
     231
     232  status = lbr$ini_control(&VMS_lib_idx, &func, &type, 0);
     233
     234  if (!$VMS_STATUS_SUCCESS(status))
     235    {
     236      ON(error, NILF, _("lbr$ini_control() failed with status = %d"), status);
    176237      return -2;
    177238    }
    178239
    179   /* there is no such descriptor with "const char *dsc$a_pointer" */
    180   libdesc.dsc$a_pointer = (char *)archive;
    181   libdesc.dsc$w_length = strlen (archive);
    182 
    183   status = lbr$open (&VMS_lib_idx, &libdesc, 0, 0, 0, 0, 0);
    184 
    185   if (! (status & 1))
     240  libdesc.dsc$a_pointer = vms_archive;
     241  libdesc.dsc$w_length = strlen(vms_archive);
     242
     243  status = lbr$open(&VMS_lib_idx, &libdesc, 0, NULL, 0, NULL, 0);
     244
     245  if (!$VMS_STATUS_SUCCESS(status))
    186246    {
    187       error (NILF, _("unable to open library `%s' to lookup member `%s'"),
    188              archive, (char *)arg);
    189       return -1;
     247
     248      /* TODO: A library format failure could mean that this is a file
     249         generated by the GNU AR utility and in that case, we need to
     250         take the UNIX codepath.  This will also take a change to the
     251         GNV AR wrapper program. */
     252
     253      switch (status)
     254        {
     255      case RMS$_FNF:
     256        /* Archive does not exist */
     257        return -1;
     258      default:
     259#ifndef TEST
     260        OSN(error, NILF,
     261            _("unable to open library '%s' to lookup member status %d"),
     262            archive, status);
     263#endif
     264        /* For library format errors, specification says to return -2 */
     265        return -2;
     266        }
    190267    }
    191268
    192   VMS_saved_memname = (char *)arg;
    193 
    194   /* For comparison, delete .obj from arg name.  */
    195 
    196   p = strrchr (VMS_saved_memname, '.');
    197   if (p)
    198     *p = '\0';
    199 
    200269  VMS_function = function;
    201270
    202   VMS_member_date = (time_t) -1;
    203   lbr$get_index (&VMS_lib_idx, &index, VMS_get_member_info, 0);
    204 
    205   /* Undo the damage.  */
    206   if (p)
    207     *p = '.';
    208 
    209   lbr$close (&VMS_lib_idx);
    210 
    211   return VMS_member_date > 0 ? VMS_member_date : 0;
     271  /* Clear the return status, as we are supposed to stop calling the
     272     callback function if it becomes non-zero, and this is a static
     273     variable. */
     274  VMS_function_ret = 0;
     275
     276  status = lbr$get_index(&VMS_lib_idx, &index, VMS_get_member_info, NULL, 0);
     277
     278  lbr$close(&VMS_lib_idx);
     279
     280  /* Unless a failure occurred in the lbr$ routines, return the
     281     the status from the 'function' routine. */
     282  if ($VMS_STATUS_SUCCESS(status))
     283    {
     284      return VMS_function_ret;
     285    }
     286
     287  /* This must be something wrong with the library and an error
     288     message should already have been printed. */
     289  return -2;
    212290}
    213291
     
    215293
    216294/* SCO Unix's compiler defines both of these.  */
    217 #ifdef  M_UNIX
    218 #undef  M_XENIX
     295#ifdef  M_UNIX
     296#undef  M_XENIX
    219297#endif
    220298
     
    225303
    226304#if (!defined (PORTAR) || PORTAR == 0) && (!defined (PORT5AR) || PORT5AR == 0)
    227 #undef  PORTAR
     305#undef  PORTAR
    228306#ifdef M_XENIX
    229307/* According to Jim Sievert <jas1@rsvl.unisys.com>, for SCO XENIX defining
     
    254332
    255333#ifndef WINDOWS32
    256 # if !defined(__BEOS__) && !defined(__HAIKU__)
     334# if !defined (__ANDROID__) && !defined (__BEOS__) && !defined (__HAIKU__) /* bird: exclude haiku */
    257335#  include <ar.h>
    258336# else
    259    /* BeOS 5 doesn't have <ar.h> but has archives in the same format
     337   /* These platforms don't have <ar.h> but have archives in the same format
    260338    * as many other Unices.  This was taken from GNU binutils for BeOS.
    261339    */
    262 #  define ARMAG "!<arch>\n"     /* String that begins an archive file.  */
    263 #  define SARMAG 8              /* Size of that string.  */
    264 #  define ARFMAG "`\n"          /* String in ar_fmag at end of each header.  */
     340#  define ARMAG "!<arch>\n"     /* String that begins an archive file.  */
     341#  define SARMAG 8              /* Size of that string.  */
     342#  define ARFMAG "`\n"          /* String in ar_fmag at end of each header.  */
    265343struct ar_hdr
    266344  {
    267     char ar_name[16];           /* Member file name, sometimes / terminated. */
    268     char ar_date[12];           /* File date, decimal seconds since Epoch.  */
    269     char ar_uid[6], ar_gid[6];  /* User and group IDs, in ASCII decimal.  */
    270     char ar_mode[8];            /* File mode, in ASCII octal.  */
    271     char ar_size[10];           /* File size, in ASCII decimal.  */
    272     char ar_fmag[2];            /* Always contains ARFMAG.  */
     345    char ar_name[16];           /* Member file name, sometimes / terminated. */
     346    char ar_date[12];           /* File date, decimal seconds since Epoch.  */
     347    char ar_uid[6], ar_gid[6];  /* User and group IDs, in ASCII decimal.  */
     348    char ar_mode[8];            /* File mode, in ASCII octal.  */
     349    char ar_size[10];           /* File size, in ASCII decimal.  */
     350    char ar_fmag[2];            /* Always contains ARFMAG.  */
    273351  };
    274352# endif
     
    295373
    296374/* Cray's <ar.h> apparently defines this.  */
    297 #ifndef AR_HDR_SIZE
    298 # define   AR_HDR_SIZE  (sizeof (struct ar_hdr))
     375#ifndef AR_HDR_SIZE
     376# define   AR_HDR_SIZE  (sizeof (struct ar_hdr))
    299377#endif
    300378
     
    332410#ifdef AIAMAG
    333411  FL_HDR fl_header;
    334 #ifdef AIAMAGBIG
     412# ifdef AIAMAGBIG
    335413  int big_archive = 0;
    336414  FL_HDR_BIG fl_header_big;
    337 #endif
    338 #else
    339   int long_name = 0;
     415# endif
    340416#endif
    341417  char *namemap = 0;
     
    346422  {
    347423    char buf[SARMAG];
    348     register int nread = read (desc, buf, SARMAG);
     424    int nread;
     425    EINTRLOOP (nread, read (desc, buf, SARMAG));
    349426    if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG))
    350427      {
    351         (void) close (desc);
    352         return -2;
     428        (void) close (desc);
     429        return -2;
    353430      }
    354431  }
     
    356433#ifdef AIAMAG
    357434  {
    358     register int nread = read (desc, &fl_header, FL_HSZ);
    359 
     435    int nread;
     436    EINTRLOOP (nread, read (desc, &fl_header, FL_HSZ));
    360437    if (nread != FL_HSZ)
    361438      {
    362         (void) close (desc);
    363         return -2;
     439        (void) close (desc);
     440        return -2;
    364441      }
    365442#ifdef AIAMAGBIG
     
    368445    if (!memcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG))
    369446      {
    370         big_archive = 1;
    371 
    372         /* seek back to beginning of archive */
    373         if (lseek (desc, 0, 0) < 0)
    374           {
    375             (void) close (desc);
    376             return -2;
    377           }
    378 
    379         /* re-read the header into the "big" structure */
    380         nread = read (desc, &fl_header_big, FL_HSZ_BIG);
    381         if (nread != FL_HSZ_BIG)
    382           {
    383             (void) close (desc);
    384             return -2;
    385           }
     447        off_t o;
     448
     449        big_archive = 1;
     450
     451        /* seek back to beginning of archive */
     452        EINTRLOOP (o, lseek (desc, 0, 0));
     453        if (o < 0)
     454          {
     455            (void) close (desc);
     456            return -2;
     457          }
     458
     459        /* re-read the header into the "big" structure */
     460        EINTRLOOP (nread, read (desc, &fl_header_big, FL_HSZ_BIG));
     461        if (nread != FL_HSZ_BIG)
     462          {
     463            (void) close (desc);
     464            return -2;
     465          }
    386466      }
    387467    else
     
    389469       /* Check to make sure this is a "normal" archive. */
    390470      if (memcmp (fl_header.fl_magic, AIAMAG, SAIAMAG))
    391         {
     471        {
    392472          (void) close (desc);
    393473          return -2;
    394         }
     474        }
    395475  }
    396476#else
     
    401481    unsigned short int buf;
    402482#endif
    403     register int nread = read(desc, &buf, sizeof (buf));
     483    int nread;
     484    EINTRLOOP (nread, read (desc, &buf, sizeof (buf)));
    404485    if (nread != sizeof (buf) || buf != ARMAG)
    405486      {
    406         (void) close (desc);
    407         return -2;
     487        (void) close (desc);
     488        return -2;
    408489      }
    409490  }
     
    423504    if ( big_archive )
    424505      {
    425         sscanf (fl_header_big.fl_fstmoff, "%20ld", &member_offset);
    426         sscanf (fl_header_big.fl_lstmoff, "%20ld", &last_member_offset);
     506        sscanf (fl_header_big.fl_fstmoff, "%20ld", &member_offset);
     507        sscanf (fl_header_big.fl_lstmoff, "%20ld", &last_member_offset);
    427508      }
    428509    else
    429510#endif
    430511      {
    431         sscanf (fl_header.fl_fstmoff, "%12ld", &member_offset);
    432         sscanf (fl_header.fl_lstmoff, "%12ld", &last_member_offset);
     512        sscanf (fl_header.fl_fstmoff, "%12ld", &member_offset);
     513        sscanf (fl_header.fl_lstmoff, "%12ld", &last_member_offset);
    433514      }
    434515
    435516    if (member_offset == 0)
    436517      {
    437         /* Empty archive.  */
    438         close (desc);
    439         return 0;
     518        /* Empty archive.  */
     519        close (desc);
     520        return 0;
    440521      }
    441522#else
    442 #ifndef M_XENIX
     523#ifndef M_XENIX
    443524    register long int member_offset = sizeof (int);
    444 #else   /* Xenix.  */
     525#else   /* Xenix.  */
    445526    register long int member_offset = sizeof (unsigned short int);
    446 #endif  /* Not Xenix.  */
     527#endif  /* Not Xenix.  */
    447528#endif
    448529#endif
     
    450531    while (1)
    451532      {
    452         register int nread;
    453         struct ar_hdr member_header;
     533        register int nread;
     534        struct ar_hdr member_header;
    454535#ifdef AIAMAGBIG
    455         struct ar_hdr_big member_header_big;
     536        struct ar_hdr_big member_header_big;
    456537#endif
    457538#ifdef AIAMAG
    458         char name[256];
    459         int name_len;
    460         long int dateval;
    461         int uidval, gidval;
    462         long int data_offset;
    463 #else
    464         char namebuf[sizeof member_header.ar_name + 1];
    465         char *name;
    466         int is_namemap;         /* Nonzero if this entry maps long names.  */
    467 #endif
    468         long int eltsize;
    469         int eltmode;
    470         long int fnval;
    471 
    472         if (lseek (desc, member_offset, 0) < 0)
    473           {
    474             (void) close (desc);
    475             return -2;
    476           }
     539        char name[256];
     540        int name_len;
     541        long int dateval;
     542        int uidval, gidval;
     543        long int data_offset;
     544#else
     545        char namebuf[sizeof member_header.ar_name + 1];
     546        char *name;
     547        int is_namemap;         /* Nonzero if this entry maps long names.  */
     548        int long_name = 0;
     549#endif
     550        long int eltsize;
     551        unsigned int eltmode;
     552        long int fnval;
     553        off_t o;
     554
     555        EINTRLOOP (o, lseek (desc, member_offset, 0));
     556        if (o < 0)
     557          {
     558            (void) close (desc);
     559            return -2;
     560          }
    477561
    478562#ifdef AIAMAG
     
    480564
    481565#ifdef AIAMAGBIG
    482         if (big_archive)
    483           {
    484             nread = read (desc, &member_header_big,
    485                           AR_MEMHDR_SZ(member_header_big) );
    486 
    487             if (nread != AR_MEMHDR_SZ(member_header_big))
    488               {
    489                 (void) close (desc);
    490                 return -2;
    491               }
    492 
    493             sscanf (member_header_big.ar_namlen, "%4d", &name_len);
    494             nread = read (desc, name, name_len);
    495 
    496             if (nread != name_len)
    497               {
    498                 (void) close (desc);
    499                 return -2;
    500               }
    501 
    502             name[name_len] = 0;
    503 
    504             sscanf (member_header_big.ar_date, "%12ld", &dateval);
    505             sscanf (member_header_big.ar_uid, "%12d", &uidval);
    506             sscanf (member_header_big.ar_gid, "%12d", &gidval);
    507             sscanf (member_header_big.ar_mode, "%12o", &eltmode);
    508             sscanf (member_header_big.ar_size, "%20ld", &eltsize);
    509 
    510             data_offset = (member_offset + AR_MEMHDR_SZ(member_header_big)
    511                            + name_len + 2);
    512           }
    513         else
    514 #endif
    515           {
    516             nread = read (desc, &member_header,
    517                           AR_MEMHDR_SZ(member_header) );
    518 
    519             if (nread != AR_MEMHDR_SZ(member_header))
    520               {
    521                 (void) close (desc);
    522                 return -2;
    523               }
    524 
    525             sscanf (member_header.ar_namlen, "%4d", &name_len);
    526             nread = read (desc, name, name_len);
    527 
    528             if (nread != name_len)
    529               {
    530                 (void) close (desc);
    531                 return -2;
    532               }
    533 
    534             name[name_len] = 0;
    535 
    536             sscanf (member_header.ar_date, "%12ld", &dateval);
    537             sscanf (member_header.ar_uid, "%12d", &uidval);
    538             sscanf (member_header.ar_gid, "%12d", &gidval);
    539             sscanf (member_header.ar_mode, "%12o", &eltmode);
    540             sscanf (member_header.ar_size, "%12ld", &eltsize);
    541 
    542             data_offset = (member_offset + AR_MEMHDR_SZ(member_header)
    543                            + name_len + 2);
    544           }
    545         data_offset += data_offset % 2;
    546 
    547         fnval =
    548           (*function) (desc, name, 0,
    549                        member_offset, data_offset, eltsize,
    550                        dateval, uidval, gidval,
    551                        eltmode, arg);
    552 
    553 #else   /* Not AIAMAG.  */
    554         nread = read (desc, &member_header, AR_HDR_SIZE);
    555         if (nread == 0)
    556           /* No data left means end of file; that is OK.  */
    557           break;
    558 
    559         if (nread != AR_HDR_SIZE
     566        if (big_archive)
     567          {
     568            EINTRLOOP (nread, read (desc, &member_header_big,
     569                                    AR_MEMHDR_SZ(member_header_big)));
     570
     571            if (nread != AR_MEMHDR_SZ(member_header_big))
     572              {
     573                (void) close (desc);
     574                return -2;
     575              }
     576
     577            sscanf (member_header_big.ar_namlen, "%4d", &name_len);
     578            EINTRLOOP (nread, read (desc, name, name_len));
     579
     580            if (nread != name_len)
     581              {
     582                (void) close (desc);
     583                return -2;
     584              }
     585
     586            name[name_len] = 0;
     587
     588            sscanf (member_header_big.ar_date, "%12ld", &dateval);
     589            sscanf (member_header_big.ar_uid, "%12d", &uidval);
     590            sscanf (member_header_big.ar_gid, "%12d", &gidval);
     591            sscanf (member_header_big.ar_mode, "%12o", &eltmode);
     592            sscanf (member_header_big.ar_size, "%20ld", &eltsize);
     593
     594            data_offset = (member_offset + AR_MEMHDR_SZ(member_header_big)
     595                           + name_len + 2);
     596          }
     597        else
     598#endif
     599          {
     600            EINTRLOOP (nread, read (desc, &member_header,
     601                                    AR_MEMHDR_SZ(member_header)));
     602
     603            if (nread != AR_MEMHDR_SZ(member_header))
     604              {
     605                (void) close (desc);
     606                return -2;
     607              }
     608
     609            sscanf (member_header.ar_namlen, "%4d", &name_len);
     610            EINTRLOOP (nread, read (desc, name, name_len));
     611
     612            if (nread != name_len)
     613              {
     614                (void) close (desc);
     615                return -2;
     616              }
     617
     618            name[name_len] = 0;
     619
     620            sscanf (member_header.ar_date, "%12ld", &dateval);
     621            sscanf (member_header.ar_uid, "%12d", &uidval);
     622            sscanf (member_header.ar_gid, "%12d", &gidval);
     623            sscanf (member_header.ar_mode, "%12o", &eltmode);
     624            sscanf (member_header.ar_size, "%12ld", &eltsize);
     625
     626            data_offset = (member_offset + AR_MEMHDR_SZ(member_header)
     627                           + name_len + 2);
     628          }
     629        data_offset += data_offset % 2;
     630
     631        fnval =
     632          (*function) (desc, name, 0,
     633                       member_offset, data_offset, eltsize,
     634                       dateval, uidval, gidval,
     635                       eltmode, arg);
     636
     637#else   /* Not AIAMAG.  */
     638        EINTRLOOP (nread, read (desc, &member_header, AR_HDR_SIZE));
     639        if (nread == 0)
     640          /* No data left means end of file; that is OK.  */
     641          break;
     642
     643        if (nread != AR_HDR_SIZE
    560644#if defined(ARFMAG) || defined(ARFZMAG)
    561             || (
     645            || (
    562646# ifdef ARFMAG
    563647                memcmp (member_header.ar_fmag, ARFMAG, 2)
     
    573657               )
    574658#endif
    575             )
    576           {
    577             (void) close (desc);
    578             return -2;
    579           }
    580 
    581         name = namebuf;
    582         memcpy (name, member_header.ar_name, sizeof member_header.ar_name);
    583         {
    584           register char *p = name + sizeof member_header.ar_name;
    585           do
    586             *p = '\0';
    587           while (p > name && *--p == ' ');
     659            )
     660          {
     661            (void) close (desc);
     662            return -2;
     663          }
     664
     665        name = namebuf;
     666        memcpy (name, member_header.ar_name, sizeof member_header.ar_name);
     667        {
     668          register char *p = name + sizeof member_header.ar_name;
     669          do
     670            *p = '\0';
     671          while (p > name && *--p == ' ');
    588672
    589673#ifndef AIAMAG
    590           /* If the member name is "//" or "ARFILENAMES/" this may be
    591              a list of file name mappings.  The maximum file name
    592              length supported by the standard archive format is 14
    593              characters.  This member will actually always be the
    594              first or second entry in the archive, but we don't check
    595              that.  */
    596           is_namemap = (!strcmp (name, "//")
    597                         || !strcmp (name, "ARFILENAMES/"));
    598 #endif  /* Not AIAMAG. */
    599           /* On some systems, there is a slash after each member name.  */
    600           if (*p == '/')
    601             *p = '\0';
     674          /* If the member name is "//" or "ARFILENAMES/" this may be
     675             a list of file name mappings.  The maximum file name
     676             length supported by the standard archive format is 14
     677             characters.  This member will actually always be the
     678             first or second entry in the archive, but we don't check
     679             that.  */
     680          is_namemap = (!strcmp (name, "//")
     681                        || !strcmp (name, "ARFILENAMES/"));
     682#endif  /* Not AIAMAG. */
     683          /* On some systems, there is a slash after each member name.  */
     684          if (*p == '/')
     685            *p = '\0';
    602686
    603687#ifndef AIAMAG
    604           /* If the member name starts with a space or a slash, this
    605              is an index into the file name mappings (used by GNU ar).
    606              Otherwise if the member name looks like #1/NUMBER the
    607              real member name appears in the element data (used by
    608              4.4BSD).  */
    609           if (! is_namemap
    610               && (name[0] == ' ' || name[0] == '/')
    611               && namemap != 0)
    612             {
    613               name = namemap + atoi (name + 1);
    614               long_name = 1;
    615             }
    616           else if (name[0] == '#'
    617                    && name[1] == '1'
    618                    && name[2] == '/')
    619             {
    620               int namesize = atoi (name + 3);
    621 
    622               name = alloca (namesize + 1);
    623               nread = read (desc, name, namesize);
    624               if (nread != namesize)
    625                 {
    626                   close (desc);
    627                   return -2;
    628                 }
    629               name[namesize] = '\0';
    630 
    631               long_name = 1;
    632             }
     688          /* If the member name starts with a space or a slash, this
     689             is an index into the file name mappings (used by GNU ar).
     690             Otherwise if the member name looks like #1/NUMBER the
     691             real member name appears in the element data (used by
     692             4.4BSD).  */
     693          if (! is_namemap
     694              && (name[0] == ' ' || name[0] == '/')
     695              && namemap != 0)
     696            {
     697              name = namemap + atoi (name + 1);
     698              long_name = 1;
     699            }
     700          else if (name[0] == '#'
     701                   && name[1] == '1'
     702                   && name[2] == '/')
     703            {
     704              int namesize = atoi (name + 3);
     705
     706              name = alloca (namesize + 1);
     707              EINTRLOOP (nread, read (desc, name, namesize));
     708              if (nread != namesize)
     709                {
     710                  close (desc);
     711                  return -2;
     712                }
     713              name[namesize] = '\0';
     714
     715              long_name = 1;
     716            }
    633717#endif /* Not AIAMAG. */
    634         }
    635 
    636 #ifndef M_XENIX
    637         sscanf (TOCHAR (member_header.ar_mode), "%o", &eltmode);
    638         eltsize = atol (TOCHAR (member_header.ar_size));
    639 #else   /* Xenix.  */
    640         eltmode = (unsigned short int) member_header.ar_mode;
    641         eltsize = member_header.ar_size;
    642 #endif  /* Not Xenix.  */
    643 
    644         fnval =
    645           (*function) (desc, name, ! long_name, member_offset,
    646                        member_offset + AR_HDR_SIZE, eltsize,
    647 #ifndef M_XENIX
    648                        atol (TOCHAR (member_header.ar_date)),
    649                        atoi (TOCHAR (member_header.ar_uid)),
    650                        atoi (TOCHAR (member_header.ar_gid)),
    651 #else   /* Xenix.  */
    652                        member_header.ar_date,
    653                        member_header.ar_uid,
    654                        member_header.ar_gid,
    655 #endif  /* Not Xenix.  */
    656                        eltmode, arg);
     718        }
     719
     720#ifndef M_XENIX
     721        sscanf (TOCHAR (member_header.ar_mode), "%o", &eltmode);
     722        eltsize = atol (TOCHAR (member_header.ar_size));
     723#else   /* Xenix.  */
     724        eltmode = (unsigned short int) member_header.ar_mode;
     725        eltsize = member_header.ar_size;
     726#endif  /* Not Xenix.  */
     727
     728        fnval =
     729          (*function) (desc, name, ! long_name, member_offset,
     730                       member_offset + AR_HDR_SIZE, eltsize,
     731#ifndef M_XENIX
     732                       atol (TOCHAR (member_header.ar_date)),
     733                       atoi (TOCHAR (member_header.ar_uid)),
     734                       atoi (TOCHAR (member_header.ar_gid)),
     735#else   /* Xenix.  */
     736                       member_header.ar_date,
     737                       member_header.ar_uid,
     738                       member_header.ar_gid,
     739#endif  /* Not Xenix.  */
     740                       eltmode, arg);
    657741
    658742#endif  /* AIAMAG.  */
    659743
    660         if (fnval)
    661           {
    662             (void) close (desc);
    663             return fnval;
    664           }
     744        if (fnval)
     745          {
     746            (void) close (desc);
     747            return fnval;
     748          }
    665749
    666750#ifdef AIAMAG
    667         if (member_offset == last_member_offset)
    668           /* End of the chain.  */
    669           break;
     751        if (member_offset == last_member_offset)
     752          /* End of the chain.  */
     753          break;
    670754
    671755#ifdef AIAMAGBIG
    672         if (big_archive)
     756        if (big_archive)
    673757         sscanf (member_header_big.ar_nxtmem, "%20ld", &member_offset);
    674         else
    675 #endif
    676           sscanf (member_header.ar_nxtmem, "%12ld", &member_offset);
    677 
    678         if (lseek (desc, member_offset, 0) != member_offset)
    679           {
    680             (void) close (desc);
    681             return -2;
    682           }
    683 #else
    684 
    685         /* If this member maps archive names, we must read it in.  The
    686            name map will always precede any members whose names must
    687            be mapped.  */
    688         if (is_namemap)
    689           {
    690             char *clear;
    691             char *limit;
    692 
    693             namemap = alloca (eltsize);
    694             nread = read (desc, namemap, eltsize);
    695             if (nread != eltsize)
    696               {
    697                 (void) close (desc);
    698                 return -2;
    699               }
    700 
    701             /* The names are separated by newlines.  Some formats have
    702                a trailing slash.  Null terminate the strings for
    703                convenience.  */
    704             limit = namemap + eltsize;
    705             for (clear = namemap; clear < limit; clear++)
    706               {
    707                 if (*clear == '\n')
    708                   {
    709                     *clear = '\0';
    710                     if (clear[-1] == '/')
    711                       clear[-1] = '\0';
    712                   }
    713               }
    714 
    715             is_namemap = 0;
    716           }
    717 
    718         member_offset += AR_HDR_SIZE + eltsize;
    719         if (member_offset % 2 != 0)
    720           member_offset++;
     758        else
     759#endif
     760          sscanf (member_header.ar_nxtmem, "%12ld", &member_offset);
     761
     762        if (lseek (desc, member_offset, 0) != member_offset)
     763          {
     764            (void) close (desc);
     765            return -2;
     766          }
     767#else
     768
     769        /* If this member maps archive names, we must read it in.  The
     770           name map will always precede any members whose names must
     771           be mapped.  */
     772        if (is_namemap)
     773          {
     774            char *clear;
     775            char *limit;
     776
     777            namemap = alloca (eltsize);
     778            EINTRLOOP (nread, read (desc, namemap, eltsize));
     779            if (nread != eltsize)
     780              {
     781                (void) close (desc);
     782                return -2;
     783              }
     784
     785            /* The names are separated by newlines.  Some formats have
     786               a trailing slash.  Null terminate the strings for
     787               convenience.  */
     788            limit = namemap + eltsize;
     789            for (clear = namemap; clear < limit; clear++)
     790              {
     791                if (*clear == '\n')
     792                  {
     793                    *clear = '\0';
     794                    if (clear[-1] == '/')
     795                      clear[-1] = '\0';
     796                  }
     797              }
     798
     799            is_namemap = 0;
     800          }
     801
     802        member_offset += AR_HDR_SIZE + eltsize;
     803        if (member_offset % 2 != 0)
     804          member_offset++;
    721805#endif
    722806      }
     
    751835      struct ar_hdr hdr;
    752836#if !defined (__hpux) && !defined (cray)
    753       return strneq (name, mem, sizeof(hdr.ar_name) - 1);
    754 #else
    755       return strneq (name, mem, sizeof(hdr.ar_name) - 2);
     837      return strneq (name, mem, sizeof (hdr.ar_name) - 1);
     838#else
     839      return strneq (name, mem, sizeof (hdr.ar_name) - 2);
    756840#endif /* !__hpux && !cray */
    757841#endif /* !AIAMAG */
    758842    }
     843
     844  return !strcmp (name, mem);
     845#else
     846  /* VMS members do not have suffixes, but the filenames usually
     847     have.
     848     Do we need to strip VMS disk/directory format paths?
     849
     850     Most VMS compilers etc. by default are case insensitive
     851     but produce uppercase external names, incl. module names.
     852     However the VMS librarian (ar) and the linker by default
     853     are case sensitive: they take what they get, usually
     854     uppercase names. So for the non-default settings of the
     855     compilers etc. there is a need to have a case sensitive
     856     mode. */
     857  {
     858    int len;
     859    len = strlen(mem);
     860    int match;
     861    char *dot;
     862    if ((dot=strrchr(name,'.')))
     863      match = (len == dot - name) && !strncasecmp(name, mem, len);
     864    else
     865      match = !strcasecmp (name, mem);
     866    return match;
     867  }
    759868#endif /* !VMS */
    760 
    761   return !strcmp (name, mem);
    762869}
    763870
     
    767874static long int
    768875ar_member_pos (int desc UNUSED, const char *mem, int truncated,
    769                long int hdrpos, long int datapos UNUSED, long int size UNUSED,
     876               long int hdrpos, long int datapos UNUSED, long int size UNUSED,
    770877               long int date UNUSED, int uid UNUSED, int gid UNUSED,
    771                int mode UNUSED, const void *name)
     878               unsigned int mode UNUSED, const void *name)
    772879{
    773880  if (!ar_name_equal (name, mem, truncated))
     
    789896  int fd;
    790897  struct ar_hdr ar_hdr;
    791   int i;
     898  off_t o;
     899  int r;
    792900  unsigned int ui;
    793901  struct stat statbuf;
     
    798906    return 1;
    799907
    800   fd = open (arname, O_RDWR, 0666);
     908  EINTRLOOP (fd, open (arname, O_RDWR, 0666));
    801909  if (fd < 0)
    802910    return -3;
    803911  /* Read in this member's header */
    804   if (lseek (fd, pos, 0) < 0)
     912  EINTRLOOP (o, lseek (fd, pos, 0));
     913  if (o < 0)
    805914    goto lose;
    806   if (AR_HDR_SIZE != read (fd, &ar_hdr, AR_HDR_SIZE))
     915  EINTRLOOP (r, read (fd, &ar_hdr, AR_HDR_SIZE));
     916  if (r != AR_HDR_SIZE)
    807917    goto lose;
    808918  /* Write back the header, thus touching the archive file.  */
    809   if (lseek (fd, pos, 0) < 0)
     919  EINTRLOOP (o, lseek (fd, pos, 0));
     920  if (o < 0)
    810921    goto lose;
    811   if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE))
     922  EINTRLOOP (r, write (fd, &ar_hdr, AR_HDR_SIZE));
     923  if (r != AR_HDR_SIZE)
    812924    goto lose;
    813925  /* The file's mtime is the time we we want.  */
    814   EINTRLOOP (i, fstat (fd, &statbuf));
    815   if (i < 0)
     926  EINTRLOOP (r, fstat (fd, &statbuf));
     927  if (r < 0)
    816928    goto lose;
    817929#if defined(ARFMAG) || defined(ARFZMAG) || defined(AIAMAG) || defined(WINDOWS32)
     
    819931  for (ui = 0; ui < sizeof ar_hdr.ar_date; ui++)
    820932    ar_hdr.ar_date[ui] = ' ';
    821   sprintf (TOCHAR (ar_hdr.ar_date), "%ld", (long int) statbuf.st_mtime);
     933  sprintf (TOCHAR (ar_hdr.ar_date), "%lu", (long unsigned) statbuf.st_mtime);
    822934#ifdef AIAMAG
    823   ar_hdr.ar_date[strlen(ar_hdr.ar_date)] = ' ';
     935  ar_hdr.ar_date[strlen (ar_hdr.ar_date)] = ' ';
    824936#endif
    825937#else
     
    827939#endif
    828940  /* Write back this member's header */
    829   if (lseek (fd, pos, 0) < 0)
     941  EINTRLOOP (o, lseek (fd, pos, 0));
     942  if (o < 0)
    830943    goto lose;
    831   if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE))
     944  EINTRLOOP (r, write (fd, &ar_hdr, AR_HDR_SIZE));
     945  if (r != AR_HDR_SIZE)
    832946    goto lose;
    833947  close (fd);
     
    835949
    836950 lose:
    837   i = errno;
     951  r = errno;
    838952  close (fd);
    839   errno = i;
     953  errno = r;
    840954  return -3;
    841955}
     
    847961long int
    848962describe_member (int desc, const char *name, int truncated,
    849                  long int hdrpos, long int datapos, long int size,
    850                  long int date, int uid, int gid, int mode, const void *arg)
     963                 long int hdrpos, long int datapos, long int size,
     964                 long int date, int uid, int gid, unsigned int mode,
     965                 const void *arg)
    851966{
    852967  extern char *ctime ();
    853968
    854   printf (_("Member `%s'%s: %ld bytes at %ld (%ld).\n"),
    855           name, truncated ? _(" (name might be truncated)") : "",
    856           size, hdrpos, datapos);
     969  printf (_("Member '%s'%s: %ld bytes at %ld (%ld).\n"),
     970          name, truncated ? _(" (name might be truncated)") : "",
     971          size, hdrpos, datapos);
    857972  printf (_("  Date %s"), ctime (&date));
    858973  printf (_("  uid = %d, gid = %d, mode = 0%o.\n"), uid, gid, mode);
     
    868983}
    869984
    870 #endif  /* TEST.  */
    871 #endif  /* NO_ARCHIVES.  */
     985#endif  /* TEST.  */
     986#endif  /* NO_ARCHIVES.  */
Note: See TracChangeset for help on using the changeset viewer.