time_t ar_member_date (const char *name) { char *arname; char *memname; long int val; ar_parse_name (name, &arname, &memname); /* Make sure we know the modtime of the archive itself because we are likely to be called just before commands to remake a member are run, and they will change the archive itself. But we must be careful not to enter_file the archive itself if it does not exist, because pattern_search assumes that files found in the data base exist or can be made. */ { struct file *arfile; arfile = lookup_file (arname); if (arfile == 0 && file_exists_p (arname)) arfile = enter_file (strcache_add (arname)); if (arfile != 0) (void) f_mtime (arfile, 0); } val = ar_scan (arname, ar_member_date_1, memname); free (arname); return (val <= 0 ? (time_t) -1 : (time_t) val); }
int ar_member_touch (const char *arname, const char *memname) { long int pos = ar_scan (arname, ar_member_pos, memname); int fd; struct ar_hdr ar_hdr; int i; unsigned int ui; struct stat statbuf; if (pos < 0) return (int) pos; if (!pos) return 1; fd = open (arname, O_RDWR, 0666); if (fd < 0) return -3; /* Read in this member's header */ if (lseek (fd, pos, 0) < 0) goto lose; if (AR_HDR_SIZE != read (fd, &ar_hdr, AR_HDR_SIZE)) goto lose; /* Write back the header, thus touching the archive file. */ if (lseek (fd, pos, 0) < 0) goto lose; if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE)) goto lose; /* The file's mtime is the time we we want. */ EINTRLOOP (i, fstat (fd, &statbuf)); if (i < 0) goto lose; #if defined(ARFMAG) || defined(ARFZMAG) || defined(AIAMAG) || defined(WINDOWS32) /* Advance member's time to that time */ for (ui = 0; ui < sizeof ar_hdr.ar_date; ui++) ar_hdr.ar_date[ui] = ' '; sprintf (TOCHAR (ar_hdr.ar_date), "%ld", (long int) statbuf.st_mtime); #ifdef AIAMAG ar_hdr.ar_date[strlen (ar_hdr.ar_date)] = ' '; #endif #else ar_hdr.ar_date = statbuf.st_mtime; #endif /* Write back this member's header */ if (lseek (fd, pos, 0) < 0) goto lose; if (AR_HDR_SIZE != write (fd, &ar_hdr, AR_HDR_SIZE)) goto lose; close (fd); return 0; lose: i = errno; close (fd); errno = i; return -3; }
/* Fortran character scan function */ int AR_scan(AR_DATA *result, const AR_TYPE *resulttype, const char* str1, const AR_DATA *str1len, const AR_TYPE *str1lentype, const char* str2, const AR_DATA *str2len, const AR_TYPE *str2lentype, const AR_DATA *backward, const AR_TYPE *backwardtype) { int status; long len1 = str1len->ar_internal_data_item1; long len2 = str2len->ar_internal_data_item1; long back; if (AR_CLASS(*resulttype) != AR_CLASS_INT || AR_INT_SIZE(*resulttype) != AR_Int_8_S && AR_INT_SIZE(*resulttype) != AR_Int_16_S && AR_INT_SIZE(*resulttype) != AR_Int_32_S && AR_INT_SIZE(*resulttype) != AR_Int_64_S || *resulttype != *str1lentype || *resulttype != *str2lentype || (backward != NULL && *backwardtype != AR_Logical)) status = AR_STAT_INVALID_TYPE; else if(len1 < 0 || len2 < 0) status = AR_STAT_UNDEFINED; else { if(backward == NULL || (AR_status(backward, backwardtype)&AR_STAT_ZERO)) back = 0; else back = 1; status = ar_scan((ar_data*)result, resulttype, str1, len1, str2, len2, back); } if (IS_ERROR_STATUS(status)) ar_set_invalid_result((ar_data*)result, resulttype); return status; }
int main (int argc, char **argv) { ar_scan (argv[1], describe_member, NULL); return 0; }