Changeset 3140 for trunk/src/kmk/arscan.c
- Timestamp:
- Mar 14, 2018, 10:28:10 PM (7 years ago)
- Location:
- trunk/src/kmk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk
-
Property svn:mergeinfo
set to
/vendor/gnumake/current merged eligible
-
Property svn:mergeinfo
set to
-
trunk/src/kmk/arscan.c
r2591 r3140 1 1 /* 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. 2 Copyright (C) 1987-2016 Free Software Foundation, Inc. 5 3 This file is part of GNU Make. 6 4 … … 17 15 this program. If not, see <http://www.gnu.org/licenses/>. */ 18 16 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 20 23 21 24 #ifdef HAVE_FCNTL_H … … 25 28 #endif 26 29 27 #ifndef 30 #ifndef NO_ARCHIVES 28 31 29 32 #ifdef VMS … … 33 36 #include <descrip.h> 34 37 #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 46 extern unsigned int LBR$_HDRTRUNC; 47 #pragma extern_model restore 48 #endif 49 36 50 #include <unixlib.h> 37 51 #include <lbr$routines.h> 38 #endif 39 52 53 const char * 54 vmsify (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. */ 59 static time_t 60 vms_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 */ 40 74 static void *VMS_lib_idx; 41 75 42 static char *VMS_saved_memname; 43 44 static time_t VMS_member_date; 76 static const void *VMS_saved_arg; 45 77 46 78 static long int (*VMS_function) (); 47 79 80 static long int VMS_function_ret; 81 82 83 /* This is a callback procedure for lib$get_index */ 48 84 static int 49 VMS_get_member_info 85 VMS_get_member_info(struct dsc$descriptor_s *module, unsigned long *rfa) 50 86 { 51 87 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 */ 55 102 56 103 static struct dsc$descriptor_s bufdesc = 57 104 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL }; 58 105 106 /* Only need the module definition */ 59 107 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) 68 111 { 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; 75 113 } 76 114 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 */ 108 163 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]); 110 165 111 166 filename[i] = '\0'; 112 167 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; 126 174 } 175 127 176 128 177 /* Takes three arguments ARCHIVE, FUNCTION and ARG. … … 156 205 157 206 long int 158 ar_scan (const char *archive, ar_member_func_t function, const void * arg)207 ar_scan (const char *archive, ar_member_func_t function, const void *varg) 159 208 { 160 char * p;209 char *vms_archive; 161 210 162 211 static struct dsc$descriptor_s libdesc = 163 212 { 0, DSC$K_DTYPE_T, DSC$K_CLASS_S, NULL }; 164 213 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; 169 218 int status; 170 219 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) 174 224 { 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); 176 237 return -2; 177 238 } 178 239 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)) 186 246 { 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 } 190 267 } 191 268 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 200 269 VMS_function = function; 201 270 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; 212 290 } 213 291 … … 215 293 216 294 /* SCO Unix's compiler defines both of these. */ 217 #ifdef 218 #undef 295 #ifdef M_UNIX 296 #undef M_XENIX 219 297 #endif 220 298 … … 225 303 226 304 #if (!defined (PORTAR) || PORTAR == 0) && (!defined (PORT5AR) || PORT5AR == 0) 227 #undef 305 #undef PORTAR 228 306 #ifdef M_XENIX 229 307 /* According to Jim Sievert <jas1@rsvl.unisys.com>, for SCO XENIX defining … … 254 332 255 333 #ifndef WINDOWS32 256 # if !defined (__BEOS__) && !defined(__HAIKU__)334 # if !defined (__ANDROID__) && !defined (__BEOS__) && !defined (__HAIKU__) /* bird: exclude haiku */ 257 335 # include <ar.h> 258 336 # else 259 /* BeOS 5 doesn't have <ar.h> but hasarchives in the same format337 /* These platforms don't have <ar.h> but have archives in the same format 260 338 * as many other Unices. This was taken from GNU binutils for BeOS. 261 339 */ 262 # define ARMAG "!<arch>\n"/* String that begins an archive file. */263 # define SARMAG 8 264 # define ARFMAG "`\n" 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. */ 265 343 struct ar_hdr 266 344 { 267 char ar_name[16]; 268 char ar_date[12]; 269 char ar_uid[6], ar_gid[6]; 270 char ar_mode[8]; 271 char ar_size[10]; 272 char ar_fmag[2]; 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. */ 273 351 }; 274 352 # endif … … 295 373 296 374 /* Cray's <ar.h> apparently defines this. */ 297 #ifndef 298 # define AR_HDR_SIZE 375 #ifndef AR_HDR_SIZE 376 # define AR_HDR_SIZE (sizeof (struct ar_hdr)) 299 377 #endif 300 378 … … 332 410 #ifdef AIAMAG 333 411 FL_HDR fl_header; 334 # ifdef AIAMAGBIG412 # ifdef AIAMAGBIG 335 413 int big_archive = 0; 336 414 FL_HDR_BIG fl_header_big; 337 #endif 338 #else 339 int long_name = 0; 415 # endif 340 416 #endif 341 417 char *namemap = 0; … … 346 422 { 347 423 char buf[SARMAG]; 348 register int nread = read (desc, buf, SARMAG); 424 int nread; 425 EINTRLOOP (nread, read (desc, buf, SARMAG)); 349 426 if (nread != SARMAG || memcmp (buf, ARMAG, SARMAG)) 350 427 { 351 352 428 (void) close (desc); 429 return -2; 353 430 } 354 431 } … … 356 433 #ifdef AIAMAG 357 434 { 358 register int nread = read (desc, &fl_header, FL_HSZ);359 435 int nread; 436 EINTRLOOP (nread, read (desc, &fl_header, FL_HSZ)); 360 437 if (nread != FL_HSZ) 361 438 { 362 363 439 (void) close (desc); 440 return -2; 364 441 } 365 442 #ifdef AIAMAGBIG … … 368 445 if (!memcmp (fl_header.fl_magic, AIAMAGBIG, SAIAMAG)) 369 446 { 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 } 386 466 } 387 467 else … … 389 469 /* Check to make sure this is a "normal" archive. */ 390 470 if (memcmp (fl_header.fl_magic, AIAMAG, SAIAMAG)) 391 471 { 392 472 (void) close (desc); 393 473 return -2; 394 474 } 395 475 } 396 476 #else … … 401 481 unsigned short int buf; 402 482 #endif 403 register int nread = read(desc, &buf, sizeof (buf)); 483 int nread; 484 EINTRLOOP (nread, read (desc, &buf, sizeof (buf))); 404 485 if (nread != sizeof (buf) || buf != ARMAG) 405 486 { 406 407 487 (void) close (desc); 488 return -2; 408 489 } 409 490 } … … 423 504 if ( big_archive ) 424 505 { 425 426 506 sscanf (fl_header_big.fl_fstmoff, "%20ld", &member_offset); 507 sscanf (fl_header_big.fl_lstmoff, "%20ld", &last_member_offset); 427 508 } 428 509 else 429 510 #endif 430 511 { 431 432 512 sscanf (fl_header.fl_fstmoff, "%12ld", &member_offset); 513 sscanf (fl_header.fl_lstmoff, "%12ld", &last_member_offset); 433 514 } 434 515 435 516 if (member_offset == 0) 436 517 { 437 438 439 518 /* Empty archive. */ 519 close (desc); 520 return 0; 440 521 } 441 522 #else 442 #ifndef 523 #ifndef M_XENIX 443 524 register long int member_offset = sizeof (int); 444 #else 525 #else /* Xenix. */ 445 526 register long int member_offset = sizeof (unsigned short int); 446 #endif 527 #endif /* Not Xenix. */ 447 528 #endif 448 529 #endif … … 450 531 while (1) 451 532 { 452 453 533 register int nread; 534 struct ar_hdr member_header; 454 535 #ifdef AIAMAGBIG 455 536 struct ar_hdr_big member_header_big; 456 537 #endif 457 538 #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 } 477 561 478 562 #ifdef AIAMAG … … 480 564 481 565 #ifdef AIAMAGBIG 482 483 484 nread =read (desc, &member_header_big,485 AR_MEMHDR_SZ(member_header_big));486 487 488 489 490 491 492 493 494 nread = read (desc, name, name_len);495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 #endif 515 516 nread =read (desc, &member_header,517 AR_MEMHDR_SZ(member_header));518 519 520 521 522 523 524 525 526 nread = read (desc, name, name_len);527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 #else 554 nread = read (desc, &member_header, AR_HDR_SIZE);555 556 557 558 559 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 560 644 #if defined(ARFMAG) || defined(ARFZMAG) 561 645 || ( 562 646 # ifdef ARFMAG 563 647 memcmp (member_header.ar_fmag, ARFMAG, 2) … … 573 657 ) 574 658 #endif 575 576 577 578 579 580 581 582 583 584 585 586 587 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 == ' '); 588 672 589 673 #ifndef AIAMAG 590 591 592 593 594 595 596 597 598 #endif 599 600 601 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'; 602 686 603 687 #ifndef AIAMAG 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 nread = read (desc, name, namesize);624 625 626 627 628 629 630 631 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 } 633 717 #endif /* Not AIAMAG. */ 634 635 636 #ifndef 637 638 639 #else 640 641 642 #endif 643 644 645 646 647 #ifndef 648 649 650 651 #else 652 653 654 655 #endif 656 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); 657 741 658 742 #endif /* AIAMAG. */ 659 743 660 661 662 663 664 744 if (fnval) 745 { 746 (void) close (desc); 747 return fnval; 748 } 665 749 666 750 #ifdef AIAMAG 667 668 669 751 if (member_offset == last_member_offset) 752 /* End of the chain. */ 753 break; 670 754 671 755 #ifdef AIAMAGBIG 672 756 if (big_archive) 673 757 sscanf (member_header_big.ar_nxtmem, "%20ld", &member_offset); 674 675 #endif 676 677 678 679 680 681 682 683 #else 684 685 686 687 688 689 690 691 692 693 694 nread = read (desc, namemap, eltsize);695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 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++; 721 805 #endif 722 806 } … … 751 835 struct ar_hdr hdr; 752 836 #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); 756 840 #endif /* !__hpux && !cray */ 757 841 #endif /* !AIAMAG */ 758 842 } 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 } 759 868 #endif /* !VMS */ 760 761 return !strcmp (name, mem);762 869 } 763 870 … … 767 874 static long int 768 875 ar_member_pos (int desc UNUSED, const char *mem, int truncated, 769 876 long int hdrpos, long int datapos UNUSED, long int size UNUSED, 770 877 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) 772 879 { 773 880 if (!ar_name_equal (name, mem, truncated)) … … 789 896 int fd; 790 897 struct ar_hdr ar_hdr; 791 int i; 898 off_t o; 899 int r; 792 900 unsigned int ui; 793 901 struct stat statbuf; … … 798 906 return 1; 799 907 800 fd = open (arname, O_RDWR, 0666);908 EINTRLOOP (fd, open (arname, O_RDWR, 0666)); 801 909 if (fd < 0) 802 910 return -3; 803 911 /* Read in this member's header */ 804 if (lseek (fd, pos, 0) < 0) 912 EINTRLOOP (o, lseek (fd, pos, 0)); 913 if (o < 0) 805 914 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) 807 917 goto lose; 808 918 /* 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) 810 921 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) 812 924 goto lose; 813 925 /* 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) 816 928 goto lose; 817 929 #if defined(ARFMAG) || defined(ARFZMAG) || defined(AIAMAG) || defined(WINDOWS32) … … 819 931 for (ui = 0; ui < sizeof ar_hdr.ar_date; ui++) 820 932 ar_hdr.ar_date[ui] = ' '; 821 sprintf (TOCHAR (ar_hdr.ar_date), "%l d", (long int) statbuf.st_mtime);933 sprintf (TOCHAR (ar_hdr.ar_date), "%lu", (long unsigned) statbuf.st_mtime); 822 934 #ifdef AIAMAG 823 ar_hdr.ar_date[strlen (ar_hdr.ar_date)] = ' ';935 ar_hdr.ar_date[strlen (ar_hdr.ar_date)] = ' '; 824 936 #endif 825 937 #else … … 827 939 #endif 828 940 /* Write back this member's header */ 829 if (lseek (fd, pos, 0) < 0) 941 EINTRLOOP (o, lseek (fd, pos, 0)); 942 if (o < 0) 830 943 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) 832 946 goto lose; 833 947 close (fd); … … 835 949 836 950 lose: 837 i= errno;951 r = errno; 838 952 close (fd); 839 errno = i;953 errno = r; 840 954 return -3; 841 955 } … … 847 961 long int 848 962 describe_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) 851 966 { 852 967 extern char *ctime (); 853 968 854 printf (_("Member `%s'%s: %ld bytes at %ld (%ld).\n"),855 856 969 printf (_("Member '%s'%s: %ld bytes at %ld (%ld).\n"), 970 name, truncated ? _(" (name might be truncated)") : "", 971 size, hdrpos, datapos); 857 972 printf (_(" Date %s"), ctime (&date)); 858 973 printf (_(" uid = %d, gid = %d, mode = 0%o.\n"), uid, gid, mode); … … 868 983 } 869 984 870 #endif 871 #endif 985 #endif /* TEST. */ 986 #endif /* NO_ARCHIVES. */
Note:
See TracChangeset
for help on using the changeset viewer.