Formerly arscan.c.~18~

This commit is contained in:
Roland McGrath 1992-06-03 01:07:39 +00:00
parent 1e9a5d4b8e
commit 6b0a5fd941

View file

@ -1,5 +1,5 @@
/* Library function for scanning an archive file. /* Library function for scanning an archive file.
Copyright (C) 1987, 1989, 1991 Free Software Foundation, Inc. Copyright (C) 1987, 1989, 1991, 1992 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -92,6 +92,11 @@ extern void free ();
#define AR_NAMELEN 255 #define AR_NAMELEN 255
#endif #endif
/* Cray's <ar.h> apparently defines this. */
#ifndef AR_HDR_SIZE
#define AR_HDR_SIZE (sizeof (struct ar_hdr))
#endif
#if defined(__GNU_LIBRARY__) || defined(POSIX) || defined(_IBMR2) #if defined(__GNU_LIBRARY__) || defined(POSIX) || defined(_IBMR2)
#include <unistd.h> #include <unistd.h>
#else #else
@ -220,7 +225,7 @@ ar_scan (archive, function, arg)
#ifdef AIAMAG #ifdef AIAMAG
#define AR_MEMHDR \ #define AR_MEMHDR \
(sizeof (member_header) - sizeof (member_header._ar_name)) (AR_HDR_SIZE - sizeof (member_header._ar_name))
nread = read (desc, (char *) &member_header, AR_MEMHDR); nread = read (desc, (char *) &member_header, AR_MEMHDR);
if (nread != AR_MEMHDR) if (nread != AR_MEMHDR)
@ -255,12 +260,12 @@ ar_scan (archive, function, arg)
eltmode, arg); eltmode, arg);
#else #else
nread = read (desc, (char *) &member_header, sizeof (struct ar_hdr)); nread = read (desc, (char *) &member_header, AR_HDR_SIZE);
if (nread == 0) if (nread == 0)
/* No data left means end of file; that is OK. */ /* No data left means end of file; that is OK. */
break; break;
if (nread != sizeof (member_header) if (nread != AR_HDR_SIZE
#ifdef ARFMAG #ifdef ARFMAG
|| bcmp (member_header.ar_fmag, ARFMAG, 2) || bcmp (member_header.ar_fmag, ARFMAG, 2)
#endif #endif
@ -291,7 +296,7 @@ ar_scan (archive, function, arg)
fnval = fnval =
(*function) (desc, name, member_offset, (*function) (desc, name, member_offset,
member_offset + sizeof (member_header), eltsize, member_offset + AR_HDR_SIZE, eltsize,
#ifndef M_XENIX #ifndef M_XENIX
atol (member_header.ar_date), atol (member_header.ar_date),
atoi (member_header.ar_uid), atoi (member_header.ar_uid),
@ -323,7 +328,7 @@ ar_scan (archive, function, arg)
return -2; return -2;
} }
#else #else
member_offset += sizeof (member_header) + eltsize; member_offset += AR_HDR_SIZE + eltsize;
if (member_offset & 1) member_offset++; if (member_offset & 1) member_offset++;
#endif #endif
} }
@ -413,12 +418,12 @@ ar_member_touch (arname, memname)
/* Read in this member's header */ /* Read in this member's header */
if (lseek (fd, pos, 0) < 0) if (lseek (fd, pos, 0) < 0)
goto lose; goto lose;
if (sizeof ar_hdr != read (fd, (char *) &ar_hdr, sizeof ar_hdr)) if (AR_HDR_SIZE != read (fd, (char *) &ar_hdr, AR_HDR_SIZE))
goto lose; goto lose;
/* Write back the header, thus touching the archive file. */ /* Write back the header, thus touching the archive file. */
if (lseek (fd, pos, 0) < 0) if (lseek (fd, pos, 0) < 0)
goto lose; goto lose;
if (sizeof ar_hdr != write (fd, (char *) &ar_hdr, sizeof ar_hdr)) if (AR_HDR_SIZE != write (fd, (char *) &ar_hdr, AR_HDR_SIZE))
goto lose; goto lose;
/* The file's mtime is the time we we want. */ /* The file's mtime is the time we we want. */
fstat (fd, &statbuf); fstat (fd, &statbuf);
@ -436,7 +441,7 @@ ar_member_touch (arname, memname)
/* Write back this member's header */ /* Write back this member's header */
if (lseek (fd, pos, 0) < 0) if (lseek (fd, pos, 0) < 0)
goto lose; goto lose;
if (sizeof ar_hdr != write (fd, (char *) &ar_hdr, sizeof ar_hdr)) if (AR_HDR_SIZE != write (fd, (char *) &ar_hdr, AR_HDR_SIZE))
goto lose; goto lose;
close (fd); close (fd);
return 0; return 0;