From b1b47b89522b5eef12bce98c19074013babbfbc1 Mon Sep 17 00:00:00 2001 From: kaiw Date: Tue, 11 Mar 2008 18:35:51 +0000 Subject: GNU ar did NOT implment option -q as a synonym of -r as the manual page stated, thus BSD ar(1) option -q, which was implemented based on the GNU ar manual page, turns out to be incompatible with GNU ar -q. This change will make BSD ar(1) -q a *REAL* GNU ar -q: 1. It will update symbol table. (same as unfixed version) 2. It will NOT compare new members spcified in the command line args with existing members, instead, append them directly. Reported by: Johannes 5 Joemann Reported by: Timothy Bourke Tested by: Johannes 5 Joemann Reviewed by: jkoshy Approved by: jkoshy (mentor) --- usr.bin/ar/ar.1 | 4 ++-- usr.bin/ar/ar.c | 3 ++- usr.bin/ar/ar.h | 1 + usr.bin/ar/write.c | 23 ++++++++++++++++++++--- 4 files changed, 25 insertions(+), 6 deletions(-) (limited to 'usr.bin') diff --git a/usr.bin/ar/ar.1 b/usr.bin/ar/ar.1 index ddfe6e7..cb9414e 100644 --- a/usr.bin/ar/ar.1 +++ b/usr.bin/ar/ar.1 @@ -225,9 +225,9 @@ If the archive file does not already exist, a new archive is created. However, to be compatible with GNU .Nm , +option .Fl q -is implemented as a synonym for -.Fl r . +will update the archive's symbol table. .It Fl r Replace (add) the files specified by arguments .Ar files ... diff --git a/usr.bin/ar/ar.c b/usr.bin/ar/ar.c index 2eed151..fdb7957 100644 --- a/usr.bin/ar/ar.c +++ b/usr.bin/ar/ar.c @@ -294,7 +294,7 @@ main(int argc, char **argv) ar_mode_p(bsdar); break; case 'q': - ar_mode_r(bsdar); + ar_mode_q(bsdar); break; case 'r': ar_mode_r(bsdar); @@ -345,6 +345,7 @@ bsdar_usage() (void)fprintf(stderr, "\tar -m [-Tjsvz] archive file ...\n"); (void)fprintf(stderr, "\tar -m [-Tabijsvz] position archive file ...\n"); (void)fprintf(stderr, "\tar -p [-Tv] archive [file ...]\n"); + (void)fprintf(stderr, "\tar -q [-Tcjsvz] archive file ...\n"); (void)fprintf(stderr, "\tar -r [-Tcjsuvz] archive file ...\n"); (void)fprintf(stderr, "\tar -r [-Tabcijsuvz] position archive file ...\n"); (void)fprintf(stderr, "\tar -s [-jz] archive\n"); diff --git a/usr.bin/ar/ar.h b/usr.bin/ar/ar.h index 478b8b9..e76fba0 100644 --- a/usr.bin/ar/ar.h +++ b/usr.bin/ar/ar.h @@ -115,6 +115,7 @@ void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...); void ar_mode_d(struct bsdar *bsdar); void ar_mode_m(struct bsdar *bsdar); void ar_mode_p(struct bsdar *bsdar); +void ar_mode_q(struct bsdar *bsdar); void ar_mode_r(struct bsdar *bsdar); void ar_mode_s(struct bsdar *bsdar); void ar_mode_t(struct bsdar *bsdar); diff --git a/usr.bin/ar/write.c b/usr.bin/ar/write.c index 7977bd2..4e6d0f6 100644 --- a/usr.bin/ar/write.c +++ b/usr.bin/ar/write.c @@ -81,6 +81,13 @@ ar_mode_m(struct bsdar *bsdar) } void +ar_mode_q(struct bsdar *bsdar) +{ + + write_archive(bsdar, 'q'); +} + +void ar_mode_r(struct bsdar *bsdar) { @@ -247,7 +254,7 @@ write_archive(struct bsdar *bsdar, char mode) } /* We do not create archive in mode 'd', 'm' and 's'. */ - if (mode != 'r') { + if (mode != 'r' && mode != 'q') { bsdar_warnc(bsdar, 0, "%s: no such file", bsdar->filename); return; @@ -342,6 +349,14 @@ write_archive(struct bsdar *bsdar, char mode) goto write_objs; /* + * For mode 'q', we don't need to adjust existing members either. + * Also, -a, -b and -i are ignored in this mode. New members are + * always inserted at tail. + */ + if (mode == 'q') + goto new_archive; + + /* * Try to find the position member specified by user. */ if (bsdar->options & AR_A || bsdar->options & AR_B) { @@ -411,11 +426,13 @@ write_archive(struct bsdar *bsdar, char mode) new_archive: /* * When operating in mode 'r', directly add those user specified - * objects which do not exist in current archive. + * objects which do not exist in current archive. When operating + * in mode 'q', all objects specified in command line args are + * appended to the archive, without comparing with existing ones. */ for (i = 0; i < bsdar->argc; i++) { av = &bsdar->argv[i]; - if (*av != NULL && mode == 'r') { + if (*av != NULL && (mode == 'r' || mode == 'q')) { nobj = create_obj_from_file(bsdar, *av, 0); if (nobj != NULL) insert_obj(bsdar, nobj, pos); -- cgit v1.1