read.c (38911b3c2c7dbb9a097b44856472ebbbedde71fc) read.c (d20e9e02db3dde383c3de1ce8cec3a8c35b3eee6)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2007 Kai Wang
5 * Copyright (c) 2007 Tim Kientzle
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD$");
32
33#include <sys/queue.h>
34#include <sys/stat.h>
35#include <archive.h>
36#include <archive_entry.h>
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2007 Kai Wang
5 * Copyright (c) 2007 Tim Kientzle
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD$");
32
33#include <sys/queue.h>
34#include <sys/stat.h>
35#include <archive.h>
36#include <archive_entry.h>
37#include <assert.h>
37#include <errno.h>
38#include <libgen.h>
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42
43#include "ar.h"
44
38#include <errno.h>
39#include <libgen.h>
40#include <stdio.h>
41#include <stdlib.h>
42#include <string.h>
43
44#include "ar.h"
45
45static int read_archive(struct bsdar *bsdar, char mode);
46
47int
48ar_mode_p(struct bsdar *bsdar)
49{
50
51 return (read_archive(bsdar, 'p'));
52}
53
54int
55ar_mode_t(struct bsdar *bsdar)
56{
57
58 return (read_archive(bsdar, 't'));
59}
60
61int
62ar_mode_x(struct bsdar *bsdar)
63{
64
65 return (read_archive(bsdar, 'x'));
66}
67
68/*
69 * Handle read modes: 'x', 't' and 'p'.
70 */
46/*
47 * Handle read modes: 'x', 't' and 'p'.
48 */
71static int
72read_archive(struct bsdar *bsdar, char mode)
49int
50ar_read_archive(struct bsdar *bsdar, int mode)
73{
74 struct archive *a;
75 struct archive_entry *entry;
76 struct stat sb;
77 struct tm *tp;
78 const char *bname;
79 const char *name;
80 mode_t md;
81 size_t size;
82 time_t mtime;
83 uid_t uid;
84 gid_t gid;
85 char **av;
86 char buf[25];
87 char find;
88 int exitcode, flags, r, i;
89
51{
52 struct archive *a;
53 struct archive_entry *entry;
54 struct stat sb;
55 struct tm *tp;
56 const char *bname;
57 const char *name;
58 mode_t md;
59 size_t size;
60 time_t mtime;
61 uid_t uid;
62 gid_t gid;
63 char **av;
64 char buf[25];
65 char find;
66 int exitcode, flags, r, i;
67
68 assert(mode == 'p' || mode == 't' || mode == 'x');
69
90 if ((a = archive_read_new()) == NULL)
70 if ((a = archive_read_new()) == NULL)
91 bsdar_errc(bsdar, EXIT_FAILURE, 0, "archive_read_new failed");
71 bsdar_errc(bsdar, 0, "archive_read_new failed");
92 archive_read_support_format_ar(a);
93 AC(archive_read_open_filename(a, bsdar->filename, DEF_BLKSZ));
94
95 exitcode = EXIT_SUCCESS;
96
97 for (;;) {
98 r = archive_read_next_header(a, &entry);
99 if (r == ARCHIVE_WARN || r == ARCHIVE_RETRY ||

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

117
118 if (bsdar->argc > 0) {
119 find = 0;
120 for(i = 0; i < bsdar->argc; i++) {
121 av = &bsdar->argv[i];
122 if (*av == NULL)
123 continue;
124 if ((bname = basename(*av)) == NULL)
72 archive_read_support_format_ar(a);
73 AC(archive_read_open_filename(a, bsdar->filename, DEF_BLKSZ));
74
75 exitcode = EXIT_SUCCESS;
76
77 for (;;) {
78 r = archive_read_next_header(a, &entry);
79 if (r == ARCHIVE_WARN || r == ARCHIVE_RETRY ||

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

97
98 if (bsdar->argc > 0) {
99 find = 0;
100 for(i = 0; i < bsdar->argc; i++) {
101 av = &bsdar->argv[i];
102 if (*av == NULL)
103 continue;
104 if ((bname = basename(*av)) == NULL)
125 bsdar_errc(bsdar, EXIT_FAILURE, errno,
105 bsdar_errc(bsdar, errno,
126 "basename failed");
127 if (strcmp(bname, name) != 0)
128 continue;
129
130 *av = NULL;
131 find = 1;
132 break;
133 }

--- 93 unchanged lines hidden ---
106 "basename failed");
107 if (strcmp(bname, name) != 0)
108 continue;
109
110 *av = NULL;
111 find = 1;
112 break;
113 }

--- 93 unchanged lines hidden ---