Deleted Added
full compact
write.c (213643) write.c (222122)
1/*-
2 * Copyright (c) 2007 Kai Wang
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2007 Kai Wang
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/usr.bin/ar/write.c 213643 2010-10-09 05:31:08Z kientzle $");
28__FBSDID("$FreeBSD: head/usr.bin/ar/write.c 222122 2011-05-20 11:29:09Z bcr $");
29
30#include <sys/endian.h>
31#include <sys/mman.h>
32#include <sys/queue.h>
33#include <sys/stat.h>
34#include <archive.h>
35#include <archive_entry.h>
36#include <errno.h>

--- 71 unchanged lines hidden (view full) ---

108{
109
110 write_archive(bsdar, 'A');
111}
112
113/*
114 * Create object from file, return created obj upon success, or NULL
115 * when an error occurs or the member is not newer than existing
29
30#include <sys/endian.h>
31#include <sys/mman.h>
32#include <sys/queue.h>
33#include <sys/stat.h>
34#include <archive.h>
35#include <archive_entry.h>
36#include <errno.h>

--- 71 unchanged lines hidden (view full) ---

108{
109
110 write_archive(bsdar, 'A');
111}
112
113/*
114 * Create object from file, return created obj upon success, or NULL
115 * when an error occurs or the member is not newer than existing
116 * one while -u is specifed.
116 * one while -u is specified.
117 */
118static struct ar_obj *
119create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
120{
121 struct ar_obj *obj;
122 struct stat sb;
123 const char *bname;
124

--- 90 unchanged lines hidden (view full) ---

215static void
216insert_obj(struct bsdar *bsdar, struct ar_obj *obj, struct ar_obj *pos)
217{
218 if (obj == NULL)
219 bsdar_errc(bsdar, EX_SOFTWARE, 0, "try to insert a null obj");
220
221 if (pos == NULL || obj == pos)
222 /*
117 */
118static struct ar_obj *
119create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
120{
121 struct ar_obj *obj;
122 struct stat sb;
123 const char *bname;
124

--- 90 unchanged lines hidden (view full) ---

215static void
216insert_obj(struct bsdar *bsdar, struct ar_obj *obj, struct ar_obj *pos)
217{
218 if (obj == NULL)
219 bsdar_errc(bsdar, EX_SOFTWARE, 0, "try to insert a null obj");
220
221 if (pos == NULL || obj == pos)
222 /*
223 * If the object to move happens to be the posistion obj,
223 * If the object to move happens to be the position obj,
224 * or if there is not a pos obj, move it to tail.
225 */
226 goto tail;
227
228 if (bsdar->options & AR_B) {
229 TAILQ_INSERT_BEFORE(pos, obj, objs);
230 return;
231 }

--- 181 unchanged lines hidden (view full) ---

413 * Mode 'A' adds the contents of another archive to the tail of
414 * current archive. Note that mode 'A' is a special mode for the
415 * ADDLIB command of the ar script mode. Currently there is no
416 * access to this function from the ar command line mode.
417 */
418 if (mode == 'A') {
419 /*
420 * Read objects from the target archive of ADDLIB command.
224 * or if there is not a pos obj, move it to tail.
225 */
226 goto tail;
227
228 if (bsdar->options & AR_B) {
229 TAILQ_INSERT_BEFORE(pos, obj, objs);
230 return;
231 }

--- 181 unchanged lines hidden (view full) ---

413 * Mode 'A' adds the contents of another archive to the tail of
414 * current archive. Note that mode 'A' is a special mode for the
415 * ADDLIB command of the ar script mode. Currently there is no
416 * access to this function from the ar command line mode.
417 */
418 if (mode == 'A') {
419 /*
420 * Read objects from the target archive of ADDLIB command.
421 * If there are members spcified in argv, read those members
421 * If there are members specified in argv, read those members
422 * only, otherwise the entire archive will be read.
423 */
424 read_objs(bsdar, bsdar->addlib, 1);
425 goto write_objs;
426 }
427
428 /*
429 * Try to find the position member specified by user.
430 */
431 if (bsdar->options & AR_A || bsdar->options & AR_B) {
432 TAILQ_FOREACH(obj, &bsdar->v_obj, objs) {
433 if (strcmp(obj->name, bsdar->posarg) == 0) {
434 pos = obj;
435 break;
436 }
437 }
438
439 /*
440 * If can't find `pos' specified by user,
422 * only, otherwise the entire archive will be read.
423 */
424 read_objs(bsdar, bsdar->addlib, 1);
425 goto write_objs;
426 }
427
428 /*
429 * Try to find the position member specified by user.
430 */
431 if (bsdar->options & AR_A || bsdar->options & AR_B) {
432 TAILQ_FOREACH(obj, &bsdar->v_obj, objs) {
433 if (strcmp(obj->name, bsdar->posarg) == 0) {
434 pos = obj;
435 break;
436 }
437 }
438
439 /*
440 * If can't find `pos' specified by user,
441 * sliently insert objects at tail.
441 * silently insert objects at tail.
442 */
443 if (pos == NULL)
444 bsdar->options &= ~(AR_A | AR_B);
445 }
446
447 for (i = 0; i < bsdar->argc; i++) {
448 av = &bsdar->argv[i];
449

--- 244 unchanged lines hidden (view full) ---

694 int elferr, tabndx, len, i;
695
696 if ((e = elf_memory(maddr, size)) == NULL) {
697 bsdar_warnc(bsdar, 0, "elf_memory() failed: %s",
698 elf_errmsg(-1));
699 return;
700 }
701 if (elf_kind(e) != ELF_K_ELF) {
442 */
443 if (pos == NULL)
444 bsdar->options &= ~(AR_A | AR_B);
445 }
446
447 for (i = 0; i < bsdar->argc; i++) {
448 av = &bsdar->argv[i];
449

--- 244 unchanged lines hidden (view full) ---

694 int elferr, tabndx, len, i;
695
696 if ((e = elf_memory(maddr, size)) == NULL) {
697 bsdar_warnc(bsdar, 0, "elf_memory() failed: %s",
698 elf_errmsg(-1));
699 return;
700 }
701 if (elf_kind(e) != ELF_K_ELF) {
702 /* Sliently ignore non-elf member. */
702 /* Silently ignore non-elf member. */
703 elf_end(e);
704 return;
705 }
706 if (elf_getshstrndx(e, &shstrndx) == 0) {
707 bsdar_warnc(bsdar, EX_SOFTWARE, 0, "elf_getshstrndx failed: %s",
708 elf_errmsg(-1));
709 elf_end(e);
710 return;

--- 157 unchanged lines hidden ---
703 elf_end(e);
704 return;
705 }
706 if (elf_getshstrndx(e, &shstrndx) == 0) {
707 bsdar_warnc(bsdar, EX_SOFTWARE, 0, "elf_getshstrndx failed: %s",
708 elf_errmsg(-1));
709 elf_end(e);
710 return;

--- 157 unchanged lines hidden ---