Revert "ar: diff reduction against ELF Tool Chain"
This reverts commit d20e9e02db
.
It caused port build failures.
Reported by: cy
This commit is contained in:
parent
2eb0e53a6b
commit
c5bf58add0
@ -42,6 +42,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sysexits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "ar.h"
|
#include "ar.h"
|
||||||
@ -249,7 +250,7 @@ arscp_open(char *fname)
|
|||||||
int r;
|
int r;
|
||||||
|
|
||||||
if ((a = archive_read_new()) == NULL)
|
if ((a = archive_read_new()) == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_read_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0, "archive_read_new failed");
|
||||||
archive_read_support_format_ar(a);
|
archive_read_support_format_ar(a);
|
||||||
AC(archive_read_open_filename(a, fname, DEF_BLKSZ));
|
AC(archive_read_open_filename(a, fname, DEF_BLKSZ));
|
||||||
if ((r = archive_read_next_header(a, &entry)))
|
if ((r = archive_read_next_header(a, &entry)))
|
||||||
@ -276,15 +277,15 @@ arscp_create(char *in, char *out)
|
|||||||
/* Delete previously created temporary archive, if any. */
|
/* Delete previously created temporary archive, if any. */
|
||||||
if (tmpac) {
|
if (tmpac) {
|
||||||
if (unlink(tmpac) < 0)
|
if (unlink(tmpac) < 0)
|
||||||
bsdar_errc(bsdar, errno, "unlink failed");
|
bsdar_errc(bsdar, EX_IOERR, errno, "unlink failed");
|
||||||
free(tmpac);
|
free(tmpac);
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpac = strdup(TEMPLATE);
|
tmpac = strdup(TEMPLATE);
|
||||||
if (tmpac == NULL)
|
if (tmpac == NULL)
|
||||||
bsdar_errc(bsdar, errno, "strdup failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
|
||||||
if ((ofd = mkstemp(tmpac)) < 0)
|
if ((ofd = mkstemp(tmpac)) < 0)
|
||||||
bsdar_errc(bsdar, errno, "mkstemp failed");
|
bsdar_errc(bsdar, EX_IOERR, errno, "mkstemp failed");
|
||||||
|
|
||||||
if (in) {
|
if (in) {
|
||||||
/*
|
/*
|
||||||
@ -307,7 +308,8 @@ arscp_create(char *in, char *out)
|
|||||||
* (archive with only global header)
|
* (archive with only global header)
|
||||||
*/
|
*/
|
||||||
if ((a = archive_write_new()) == NULL)
|
if ((a = archive_write_new()) == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_write_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0,
|
||||||
|
"archive_write_new failed");
|
||||||
archive_write_set_format_ar_svr4(a);
|
archive_write_set_format_ar_svr4(a);
|
||||||
AC(archive_write_open_fd(a, ofd));
|
AC(archive_write_open_fd(a, ofd));
|
||||||
AC(archive_write_close(a));
|
AC(archive_write_close(a));
|
||||||
@ -348,7 +350,7 @@ arscp_copy(int ifd, int ofd)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (munmap(p, sb.st_size) < 0)
|
if (munmap(p, sb.st_size) < 0)
|
||||||
bsdar_errc(bsdar, errno, "munmap failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "munmap failed");
|
||||||
if (bytes > 0)
|
if (bytes > 0)
|
||||||
return (1);
|
return (1);
|
||||||
|
|
||||||
@ -367,7 +369,7 @@ arscp_addlib(char *archive, struct list *list)
|
|||||||
return;
|
return;
|
||||||
arscp_mlist2argv(list);
|
arscp_mlist2argv(list);
|
||||||
bsdar->addlib = archive;
|
bsdar->addlib = archive;
|
||||||
ar_write_archive(bsdar, 'A');
|
ar_mode_A(bsdar);
|
||||||
arscp_free_argv();
|
arscp_free_argv();
|
||||||
arscp_free_mlist(list);
|
arscp_free_mlist(list);
|
||||||
}
|
}
|
||||||
@ -380,7 +382,7 @@ arscp_addmod(struct list *list)
|
|||||||
if (!arscp_target_exist())
|
if (!arscp_target_exist())
|
||||||
return;
|
return;
|
||||||
arscp_mlist2argv(list);
|
arscp_mlist2argv(list);
|
||||||
ar_write_archive(bsdar, 'q');
|
ar_mode_q(bsdar);
|
||||||
arscp_free_argv();
|
arscp_free_argv();
|
||||||
arscp_free_mlist(list);
|
arscp_free_mlist(list);
|
||||||
}
|
}
|
||||||
@ -393,7 +395,7 @@ arscp_delete(struct list *list)
|
|||||||
if (!arscp_target_exist())
|
if (!arscp_target_exist())
|
||||||
return;
|
return;
|
||||||
arscp_mlist2argv(list);
|
arscp_mlist2argv(list);
|
||||||
ar_write_archive(bsdar, 'd');
|
ar_mode_d(bsdar);
|
||||||
arscp_free_argv();
|
arscp_free_argv();
|
||||||
arscp_free_mlist(list);
|
arscp_free_mlist(list);
|
||||||
}
|
}
|
||||||
@ -406,7 +408,7 @@ arscp_extract(struct list *list)
|
|||||||
if (!arscp_target_exist())
|
if (!arscp_target_exist())
|
||||||
return;
|
return;
|
||||||
arscp_mlist2argv(list);
|
arscp_mlist2argv(list);
|
||||||
ar_read_archive(bsdar, 'x');
|
ar_mode_x(bsdar);
|
||||||
arscp_free_argv();
|
arscp_free_argv();
|
||||||
arscp_free_mlist(list);
|
arscp_free_mlist(list);
|
||||||
}
|
}
|
||||||
@ -422,7 +424,7 @@ arscp_list(void)
|
|||||||
bsdar->argv = NULL;
|
bsdar->argv = NULL;
|
||||||
/* Always verbose. */
|
/* Always verbose. */
|
||||||
bsdar->options |= AR_V;
|
bsdar->options |= AR_V;
|
||||||
ar_read_archive(bsdar, 't');
|
ar_mode_t(bsdar);
|
||||||
bsdar->options &= ~AR_V;
|
bsdar->options &= ~AR_V;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -437,7 +439,8 @@ arscp_dir(char *archive, struct list *list, char *rlt)
|
|||||||
if (rlt) {
|
if (rlt) {
|
||||||
out = stdout;
|
out = stdout;
|
||||||
if ((stdout = fopen(rlt, "w")) == NULL)
|
if ((stdout = fopen(rlt, "w")) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "fopen %s failed", rlt);
|
bsdar_errc(bsdar, EX_IOERR, errno,
|
||||||
|
"fopen %s failed", rlt);
|
||||||
}
|
}
|
||||||
|
|
||||||
bsdar->filename = archive;
|
bsdar->filename = archive;
|
||||||
@ -449,12 +452,13 @@ arscp_dir(char *archive, struct list *list, char *rlt)
|
|||||||
}
|
}
|
||||||
if (verbose)
|
if (verbose)
|
||||||
bsdar->options |= AR_V;
|
bsdar->options |= AR_V;
|
||||||
ar_read_archive(bsdar, 't');
|
ar_mode_t(bsdar);
|
||||||
bsdar->options &= ~AR_V;
|
bsdar->options &= ~AR_V;
|
||||||
|
|
||||||
if (rlt) {
|
if (rlt) {
|
||||||
if (fclose(stdout) == EOF)
|
if (fclose(stdout) == EOF)
|
||||||
bsdar_errc(bsdar, errno, "fclose %s failed", rlt);
|
bsdar_errc(bsdar, EX_IOERR, errno,
|
||||||
|
"fclose %s failed", rlt);
|
||||||
stdout = out;
|
stdout = out;
|
||||||
free(rlt);
|
free(rlt);
|
||||||
}
|
}
|
||||||
@ -473,7 +477,7 @@ arscp_replace(struct list *list)
|
|||||||
if (!arscp_target_exist())
|
if (!arscp_target_exist())
|
||||||
return;
|
return;
|
||||||
arscp_mlist2argv(list);
|
arscp_mlist2argv(list);
|
||||||
ar_write_archive(bsdar, 'r');
|
ar_mode_r(bsdar);
|
||||||
arscp_free_argv();
|
arscp_free_argv();
|
||||||
arscp_free_mlist(list);
|
arscp_free_mlist(list);
|
||||||
}
|
}
|
||||||
@ -486,7 +490,7 @@ arscp_save(void)
|
|||||||
|
|
||||||
if (target) {
|
if (target) {
|
||||||
if (rename(tmpac, target) < 0)
|
if (rename(tmpac, target) < 0)
|
||||||
bsdar_errc(bsdar, errno, "rename failed");
|
bsdar_errc(bsdar, EX_IOERR, errno, "rename failed");
|
||||||
/*
|
/*
|
||||||
* mkstemp creates temp files with mode 0600, here we
|
* mkstemp creates temp files with mode 0600, here we
|
||||||
* set target archive mode per process umask.
|
* set target archive mode per process umask.
|
||||||
@ -494,7 +498,7 @@ arscp_save(void)
|
|||||||
mask = umask(0);
|
mask = umask(0);
|
||||||
umask(mask);
|
umask(mask);
|
||||||
if (chmod(target, 0666 & ~mask) < 0)
|
if (chmod(target, 0666 & ~mask) < 0)
|
||||||
bsdar_errc(bsdar, errno, "chmod failed");
|
bsdar_errc(bsdar, EX_IOERR, errno, "chmod failed");
|
||||||
free(tmpac);
|
free(tmpac);
|
||||||
free(target);
|
free(target);
|
||||||
tmpac = NULL;
|
tmpac = NULL;
|
||||||
@ -516,7 +520,7 @@ arscp_clear(void)
|
|||||||
if (target) {
|
if (target) {
|
||||||
new_target = strdup(target);
|
new_target = strdup(target);
|
||||||
if (new_target == NULL)
|
if (new_target == NULL)
|
||||||
bsdar_errc(bsdar, errno, "strdup failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
|
||||||
arscp_create(NULL, new_target);
|
arscp_create(NULL, new_target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -533,7 +537,7 @@ arscp_end(int eval)
|
|||||||
free(target);
|
free(target);
|
||||||
if (tmpac) {
|
if (tmpac) {
|
||||||
if (unlink(tmpac) == -1)
|
if (unlink(tmpac) == -1)
|
||||||
bsdar_errc(bsdar, errno, "unlink %s failed",
|
bsdar_errc(bsdar, EX_IOERR, errno, "unlink %s failed",
|
||||||
tmpac);
|
tmpac);
|
||||||
free(tmpac);
|
free(tmpac);
|
||||||
}
|
}
|
||||||
@ -564,7 +568,7 @@ arscp_mlist(struct list *list, char *str)
|
|||||||
|
|
||||||
l = malloc(sizeof(*l));
|
l = malloc(sizeof(*l));
|
||||||
if (l == NULL)
|
if (l == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
l->str = str;
|
l->str = str;
|
||||||
l->next = list;
|
l->next = list;
|
||||||
|
|
||||||
@ -606,12 +610,12 @@ arscp_mlist2argv(struct list *list)
|
|||||||
n = arscp_mlist_len(list);
|
n = arscp_mlist_len(list);
|
||||||
argv = malloc(n * sizeof(*argv));
|
argv = malloc(n * sizeof(*argv));
|
||||||
if (argv == NULL)
|
if (argv == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
|
|
||||||
/* Note that module names are stored in reverse order in mlist. */
|
/* Note that module names are stored in reverse order in mlist. */
|
||||||
for(i = n - 1; i >= 0; i--, list = list->next) {
|
for(i = n - 1; i >= 0; i--, list = list->next) {
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
bsdar_errc(bsdar, errno, "invalid mlist");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "invalid mlist");
|
||||||
argv[i] = list->str;
|
argv[i] = list->str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ main(int argc, char **argv)
|
|||||||
bsdar->options |= AR_D;
|
bsdar->options |= AR_D;
|
||||||
bsdar->options |= AR_S;
|
bsdar->options |= AR_S;
|
||||||
while ((bsdar->filename = *argv++) != NULL)
|
while ((bsdar->filename = *argv++) != NULL)
|
||||||
if (ar_read_archive(bsdar, 's'))
|
if (ar_mode_s(bsdar))
|
||||||
exitcode = EXIT_FAILURE;
|
exitcode = EXIT_FAILURE;
|
||||||
|
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
@ -162,7 +162,8 @@ main(int argc, char **argv)
|
|||||||
if (*argv[1] != '-') {
|
if (*argv[1] != '-') {
|
||||||
len = strlen(argv[1]) + 2;
|
len = strlen(argv[1]) + 2;
|
||||||
if ((p = malloc(len)) == NULL)
|
if ((p = malloc(len)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EXIT_FAILURE, errno,
|
||||||
|
"malloc failed");
|
||||||
*p = '-';
|
*p = '-';
|
||||||
(void)strlcpy(p + 1, argv[1], len - 1);
|
(void)strlcpy(p + 1, argv[1], len - 1);
|
||||||
argv[1] = p;
|
argv[1] = p;
|
||||||
@ -262,20 +263,24 @@ main(int argc, char **argv)
|
|||||||
bsdar_usage();
|
bsdar_usage();
|
||||||
|
|
||||||
if (bsdar->options & AR_A && bsdar->options & AR_B)
|
if (bsdar->options & AR_A && bsdar->options & AR_B)
|
||||||
bsdar_errc(bsdar, 0,
|
bsdar_errc(bsdar, EXIT_FAILURE, 0,
|
||||||
"only one of -a and -[bi] options allowed");
|
"only one of -a and -[bi] options allowed");
|
||||||
|
|
||||||
if (bsdar->options & AR_J && bsdar->options & AR_Z)
|
if (bsdar->options & AR_J && bsdar->options & AR_Z)
|
||||||
bsdar_errc(bsdar, 0, "only one of -j and -z options allowed");
|
bsdar_errc(bsdar, EXIT_FAILURE, 0,
|
||||||
|
"only one of -j and -z options allowed");
|
||||||
|
|
||||||
if (bsdar->options & AR_S && bsdar->options & AR_SS)
|
if (bsdar->options & AR_S && bsdar->options & AR_SS)
|
||||||
bsdar_errc(bsdar, 0, "only one of -s and -S options allowed");
|
bsdar_errc(bsdar, EXIT_FAILURE, 0,
|
||||||
|
"only one of -s and -S options allowed");
|
||||||
|
|
||||||
if (bsdar->options & (AR_A | AR_B)) {
|
if (bsdar->options & (AR_A | AR_B)) {
|
||||||
if (*argv == NULL)
|
if (*argv == NULL)
|
||||||
bsdar_errc(bsdar, 0, "no position operand specified");
|
bsdar_errc(bsdar, EXIT_FAILURE, 0,
|
||||||
|
"no position operand specified");
|
||||||
if ((bsdar->posarg = basename(*argv)) == NULL)
|
if ((bsdar->posarg = basename(*argv)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "basename failed");
|
bsdar_errc(bsdar, EXIT_FAILURE, errno,
|
||||||
|
"basename failed");
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
}
|
}
|
||||||
@ -317,17 +322,32 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
if ((!bsdar->mode || strchr("ptx", bsdar->mode)) &&
|
if ((!bsdar->mode || strchr("ptx", bsdar->mode)) &&
|
||||||
bsdar->options & AR_S) {
|
bsdar->options & AR_S) {
|
||||||
exitcode = ar_write_archive(bsdar, 's');
|
exitcode = ar_mode_s(bsdar);
|
||||||
if (!bsdar->mode)
|
if (!bsdar->mode)
|
||||||
exit(exitcode);
|
exit(exitcode);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch(bsdar->mode) {
|
switch(bsdar->mode) {
|
||||||
case 'd': case 'm': case 'q': case 'r':
|
case 'd':
|
||||||
exitcode = ar_write_archive(bsdar, bsdar->mode);
|
exitcode = ar_mode_d(bsdar);
|
||||||
break;
|
break;
|
||||||
case 'p': case 't': case 'x':
|
case 'm':
|
||||||
exitcode = ar_read_archive(bsdar, bsdar->mode);
|
exitcode = ar_mode_m(bsdar);
|
||||||
|
break;
|
||||||
|
case 'p':
|
||||||
|
exitcode = ar_mode_p(bsdar);
|
||||||
|
break;
|
||||||
|
case 'q':
|
||||||
|
exitcode = ar_mode_q(bsdar);
|
||||||
|
break;
|
||||||
|
case 'r':
|
||||||
|
exitcode = ar_mode_r(bsdar);
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
exitcode = ar_mode_t(bsdar);
|
||||||
|
break;
|
||||||
|
case 'x':
|
||||||
|
exitcode = ar_mode_x(bsdar);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bsdar_usage();
|
bsdar_usage();
|
||||||
@ -350,8 +370,8 @@ set_mode(struct bsdar *bsdar, char opt)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (bsdar->mode != '\0' && bsdar->mode != opt)
|
if (bsdar->mode != '\0' && bsdar->mode != opt)
|
||||||
bsdar_errc(bsdar, 0, "Can't specify both -%c and -%c",
|
bsdar_errc(bsdar, EXIT_FAILURE, 0,
|
||||||
opt, bsdar->mode);
|
"Can't specify both -%c and -%c", opt, bsdar->mode);
|
||||||
bsdar->mode = opt;
|
bsdar->mode = opt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,8 +380,8 @@ only_mode(struct bsdar *bsdar, const char *opt, const char *valid_modes)
|
|||||||
{
|
{
|
||||||
|
|
||||||
if (strchr(valid_modes, bsdar->mode) == NULL)
|
if (strchr(valid_modes, bsdar->mode) == NULL)
|
||||||
bsdar_errc(bsdar, 0, "Option %s is not permitted in mode -%c",
|
bsdar_errc(bsdar, EXIT_FAILURE, 0,
|
||||||
opt, bsdar->mode);
|
"Option %s is not permitted in mode -%c", opt, bsdar->mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
*/
|
*/
|
||||||
#define AC(CALL) do { \
|
#define AC(CALL) do { \
|
||||||
if ((CALL)) \
|
if ((CALL)) \
|
||||||
bsdar_errc(bsdar, archive_errno(a), "%s", \
|
bsdar_errc(bsdar, EXIT_FAILURE, archive_errno(a), "%s", \
|
||||||
archive_error_string(a)); \
|
archive_error_string(a)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
@ -114,8 +114,16 @@ struct bsdar {
|
|||||||
TAILQ_HEAD(, ar_obj) v_obj; /* object(member) list */
|
TAILQ_HEAD(, ar_obj) v_obj; /* object(member) list */
|
||||||
};
|
};
|
||||||
|
|
||||||
void ar_mode_script(struct bsdar *ar);
|
void bsdar_errc(struct bsdar *, int _eval, int _code,
|
||||||
int ar_read_archive(struct bsdar *ar, int mode);
|
const char *fmt, ...) __dead2;
|
||||||
int ar_write_archive(struct bsdar *ar, int mode);
|
|
||||||
void bsdar_errc(struct bsdar *, int _code, const char *fmt, ...) __dead2;
|
|
||||||
void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...);
|
void bsdar_warnc(struct bsdar *, int _code, const char *fmt, ...);
|
||||||
|
int ar_mode_d(struct bsdar *bsdar);
|
||||||
|
int ar_mode_m(struct bsdar *bsdar);
|
||||||
|
int ar_mode_p(struct bsdar *bsdar);
|
||||||
|
int ar_mode_q(struct bsdar *bsdar);
|
||||||
|
int ar_mode_r(struct bsdar *bsdar);
|
||||||
|
int ar_mode_s(struct bsdar *bsdar);
|
||||||
|
int ar_mode_t(struct bsdar *bsdar);
|
||||||
|
int ar_mode_x(struct bsdar *bsdar);
|
||||||
|
int ar_mode_A(struct bsdar *bsdar);
|
||||||
|
void ar_mode_script(struct bsdar *ar);
|
||||||
|
@ -34,7 +34,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -43,11 +42,34 @@ __FBSDID("$FreeBSD$");
|
|||||||
|
|
||||||
#include "ar.h"
|
#include "ar.h"
|
||||||
|
|
||||||
|
static int read_archive(struct bsdar *bsdar, char mode);
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_p(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (read_archive(bsdar, 'p'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_t(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (read_archive(bsdar, 't'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_x(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (read_archive(bsdar, 'x'));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle read modes: 'x', 't' and 'p'.
|
* Handle read modes: 'x', 't' and 'p'.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
ar_read_archive(struct bsdar *bsdar, int mode)
|
read_archive(struct bsdar *bsdar, char mode)
|
||||||
{
|
{
|
||||||
struct archive *a;
|
struct archive *a;
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
@ -65,10 +87,8 @@ ar_read_archive(struct bsdar *bsdar, int mode)
|
|||||||
char find;
|
char find;
|
||||||
int exitcode, flags, r, i;
|
int exitcode, flags, r, i;
|
||||||
|
|
||||||
assert(mode == 'p' || mode == 't' || mode == 'x');
|
|
||||||
|
|
||||||
if ((a = archive_read_new()) == NULL)
|
if ((a = archive_read_new()) == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_read_new failed");
|
bsdar_errc(bsdar, EXIT_FAILURE, 0, "archive_read_new failed");
|
||||||
archive_read_support_format_ar(a);
|
archive_read_support_format_ar(a);
|
||||||
AC(archive_read_open_filename(a, bsdar->filename, DEF_BLKSZ));
|
AC(archive_read_open_filename(a, bsdar->filename, DEF_BLKSZ));
|
||||||
|
|
||||||
@ -102,7 +122,7 @@ ar_read_archive(struct bsdar *bsdar, int mode)
|
|||||||
if (*av == NULL)
|
if (*av == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((bname = basename(*av)) == NULL)
|
if ((bname = basename(*av)) == NULL)
|
||||||
bsdar_errc(bsdar, errno,
|
bsdar_errc(bsdar, EXIT_FAILURE, errno,
|
||||||
"basename failed");
|
"basename failed");
|
||||||
if (strcmp(bname, name) != 0)
|
if (strcmp(bname, name) != 0)
|
||||||
continue;
|
continue;
|
||||||
|
@ -77,12 +77,12 @@ bsdar_verrc(struct bsdar *bsdar, int code, const char *fmt, va_list ap)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
bsdar_errc(struct bsdar *bsdar, int code, const char *fmt, ...)
|
bsdar_errc(struct bsdar *bsdar, int eval, int code, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
bsdar_verrc(bsdar, code, fmt, ap);
|
bsdar_verrc(bsdar, code, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
exit(EXIT_FAILURE);
|
exit(eval);
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,6 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <archive.h>
|
#include <archive.h>
|
||||||
#include <archive_entry.h>
|
#include <archive_entry.h>
|
||||||
#include <assert.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <gelf.h>
|
#include <gelf.h>
|
||||||
@ -43,6 +42,7 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sysexits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "ar.h"
|
#include "ar.h"
|
||||||
@ -67,11 +67,54 @@ static void insert_obj(struct bsdar *bsdar, struct ar_obj *obj,
|
|||||||
static void prefault_buffer(const char *buf, size_t s);
|
static void prefault_buffer(const char *buf, size_t s);
|
||||||
static void read_objs(struct bsdar *bsdar, const char *archive,
|
static void read_objs(struct bsdar *bsdar, const char *archive,
|
||||||
int checkargv);
|
int checkargv);
|
||||||
|
static int write_archive(struct bsdar *bsdar, char mode);
|
||||||
static void write_cleanup(struct bsdar *bsdar);
|
static void write_cleanup(struct bsdar *bsdar);
|
||||||
static void write_data(struct bsdar *bsdar, struct archive *a,
|
static void write_data(struct bsdar *bsdar, struct archive *a,
|
||||||
const void *buf, size_t s);
|
const void *buf, size_t s);
|
||||||
static void write_objs(struct bsdar *bsdar);
|
static void write_objs(struct bsdar *bsdar);
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_d(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (write_archive(bsdar, 'd'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_m(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (write_archive(bsdar, 'm'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_q(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (write_archive(bsdar, 'q'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_r(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (write_archive(bsdar, 'r'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_s(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (write_archive(bsdar, 's'));
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ar_mode_A(struct bsdar *bsdar)
|
||||||
|
{
|
||||||
|
|
||||||
|
return (write_archive(bsdar, 'A'));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create object from file, return created obj upon success, or NULL
|
* Create object from file, return created obj upon success, or NULL
|
||||||
* when an error occurs or the member is not newer than existing
|
* when an error occurs or the member is not newer than existing
|
||||||
@ -90,7 +133,7 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
|
|||||||
|
|
||||||
obj = malloc(sizeof(struct ar_obj));
|
obj = malloc(sizeof(struct ar_obj));
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
if ((obj->fd = open(name, O_RDONLY, 0)) < 0) {
|
if ((obj->fd = open(name, O_RDONLY, 0)) < 0) {
|
||||||
bsdar_warnc(bsdar, errno, "can't open file: %s", name);
|
bsdar_warnc(bsdar, errno, "can't open file: %s", name);
|
||||||
free(obj);
|
free(obj);
|
||||||
@ -99,17 +142,17 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
|
|||||||
|
|
||||||
tmpname = strdup(name);
|
tmpname = strdup(name);
|
||||||
if (tmpname == NULL)
|
if (tmpname == NULL)
|
||||||
bsdar_errc(bsdar, errno, "strdup failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
|
||||||
if ((bname = basename(tmpname)) == NULL)
|
if ((bname = basename(tmpname)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "basename failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "basename failed");
|
||||||
if (bsdar->options & AR_TR && strlen(bname) > _TRUNCATE_LEN) {
|
if (bsdar->options & AR_TR && strlen(bname) > _TRUNCATE_LEN) {
|
||||||
if ((obj->name = malloc(_TRUNCATE_LEN + 1)) == NULL)
|
if ((obj->name = malloc(_TRUNCATE_LEN + 1)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
(void)strncpy(obj->name, bname, _TRUNCATE_LEN);
|
(void)strncpy(obj->name, bname, _TRUNCATE_LEN);
|
||||||
obj->name[_TRUNCATE_LEN] = '\0';
|
obj->name[_TRUNCATE_LEN] = '\0';
|
||||||
} else
|
} else
|
||||||
if ((obj->name = strdup(bname)) == NULL)
|
if ((obj->name = strdup(bname)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "strdup failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
|
||||||
free(tmpname);
|
free(tmpname);
|
||||||
|
|
||||||
if (fstat(obj->fd, &sb) < 0) {
|
if (fstat(obj->fd, &sb) < 0) {
|
||||||
@ -162,14 +205,14 @@ create_obj_from_file(struct bsdar *bsdar, const char *name, time_t mtime)
|
|||||||
goto giveup;
|
goto giveup;
|
||||||
}
|
}
|
||||||
if (close(obj->fd) < 0)
|
if (close(obj->fd) < 0)
|
||||||
bsdar_errc(bsdar, errno, "close failed: %s",
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "close failed: %s",
|
||||||
obj->name);
|
obj->name);
|
||||||
|
|
||||||
return (obj);
|
return (obj);
|
||||||
|
|
||||||
giveup:
|
giveup:
|
||||||
if (close(obj->fd) < 0)
|
if (close(obj->fd) < 0)
|
||||||
bsdar_errc(bsdar, errno, "close failed: %s",
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "close failed: %s",
|
||||||
obj->name);
|
obj->name);
|
||||||
free(obj->name);
|
free(obj->name);
|
||||||
free(obj);
|
free(obj);
|
||||||
@ -199,7 +242,7 @@ static void
|
|||||||
insert_obj(struct bsdar *bsdar, struct ar_obj *obj, struct ar_obj *pos)
|
insert_obj(struct bsdar *bsdar, struct ar_obj *obj, struct ar_obj *pos)
|
||||||
{
|
{
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
bsdar_errc(bsdar, 0, "try to insert a null obj");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0, "try to insert a null obj");
|
||||||
|
|
||||||
if (pos == NULL || obj == pos)
|
if (pos == NULL || obj == pos)
|
||||||
/*
|
/*
|
||||||
@ -242,13 +285,13 @@ read_objs(struct bsdar *bsdar, const char *archive, int checkargv)
|
|||||||
int i, r, find;
|
int i, r, find;
|
||||||
|
|
||||||
if ((a = archive_read_new()) == NULL)
|
if ((a = archive_read_new()) == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_read_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0, "archive_read_new failed");
|
||||||
archive_read_support_format_ar(a);
|
archive_read_support_format_ar(a);
|
||||||
AC(archive_read_open_filename(a, archive, DEF_BLKSZ));
|
AC(archive_read_open_filename(a, archive, DEF_BLKSZ));
|
||||||
for (;;) {
|
for (;;) {
|
||||||
r = archive_read_next_header(a, &entry);
|
r = archive_read_next_header(a, &entry);
|
||||||
if (r == ARCHIVE_FATAL)
|
if (r == ARCHIVE_FATAL)
|
||||||
bsdar_errc(bsdar, archive_errno(a), "%s",
|
bsdar_errc(bsdar, EX_DATAERR, archive_errno(a), "%s",
|
||||||
archive_error_string(a));
|
archive_error_string(a));
|
||||||
if (r == ARCHIVE_EOF)
|
if (r == ARCHIVE_EOF)
|
||||||
break;
|
break;
|
||||||
@ -279,7 +322,7 @@ read_objs(struct bsdar *bsdar, const char *archive, int checkargv)
|
|||||||
if (*av == NULL)
|
if (*av == NULL)
|
||||||
continue;
|
continue;
|
||||||
if ((bname = basename(*av)) == NULL)
|
if ((bname = basename(*av)) == NULL)
|
||||||
bsdar_errc(bsdar, errno,
|
bsdar_errc(bsdar, EX_SOFTWARE, errno,
|
||||||
"basename failed");
|
"basename failed");
|
||||||
if (strcmp(bname, name) != 0)
|
if (strcmp(bname, name) != 0)
|
||||||
continue;
|
continue;
|
||||||
@ -296,7 +339,8 @@ read_objs(struct bsdar *bsdar, const char *archive, int checkargv)
|
|||||||
|
|
||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
if ((buff = malloc(size)) == NULL)
|
if ((buff = malloc(size)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno,
|
||||||
|
"malloc failed");
|
||||||
if (archive_read_data(a, buff, size) != (ssize_t)size) {
|
if (archive_read_data(a, buff, size) != (ssize_t)size) {
|
||||||
bsdar_warnc(bsdar, archive_errno(a), "%s",
|
bsdar_warnc(bsdar, archive_errno(a), "%s",
|
||||||
archive_error_string(a));
|
archive_error_string(a));
|
||||||
@ -308,10 +352,10 @@ read_objs(struct bsdar *bsdar, const char *archive, int checkargv)
|
|||||||
|
|
||||||
obj = malloc(sizeof(struct ar_obj));
|
obj = malloc(sizeof(struct ar_obj));
|
||||||
if (obj == NULL)
|
if (obj == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
obj->maddr = buff;
|
obj->maddr = buff;
|
||||||
if ((obj->name = strdup(name)) == NULL)
|
if ((obj->name = strdup(name)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "strdup failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "strdup failed");
|
||||||
obj->size = size;
|
obj->size = size;
|
||||||
obj->uid = archive_entry_uid(entry);
|
obj->uid = archive_entry_uid(entry);
|
||||||
obj->gid = archive_entry_gid(entry);
|
obj->gid = archive_entry_gid(entry);
|
||||||
@ -334,8 +378,8 @@ read_objs(struct bsdar *bsdar, const char *archive, int checkargv)
|
|||||||
/*
|
/*
|
||||||
* Determine the constitution of resulting archive.
|
* Determine the constitution of resulting archive.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
ar_write_archive(struct bsdar *bsdar, int mode)
|
write_archive(struct bsdar *bsdar, char mode)
|
||||||
{
|
{
|
||||||
struct ar_obj *nobj, *obj, *obj_temp, *pos;
|
struct ar_obj *nobj, *obj, *obj_temp, *pos;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
@ -349,9 +393,6 @@ ar_write_archive(struct bsdar *bsdar, int mode)
|
|||||||
pos = NULL;
|
pos = NULL;
|
||||||
memset(&sb, 0, sizeof(sb));
|
memset(&sb, 0, sizeof(sb));
|
||||||
|
|
||||||
assert(mode == 'A' || mode == 'd' || mode == 'm' || mode == 'q' ||
|
|
||||||
mode == 'r' || mode == 's');
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Test if the specified archive exists, to figure out
|
* Test if the specified archive exists, to figure out
|
||||||
* whether we are creating one here.
|
* whether we are creating one here.
|
||||||
@ -435,7 +476,8 @@ ar_write_archive(struct bsdar *bsdar, int mode)
|
|||||||
|
|
||||||
TAILQ_FOREACH_SAFE(obj, &bsdar->v_obj, objs, obj_temp) {
|
TAILQ_FOREACH_SAFE(obj, &bsdar->v_obj, objs, obj_temp) {
|
||||||
if ((bname = basename(*av)) == NULL)
|
if ((bname = basename(*av)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "basename failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno,
|
||||||
|
"basename failed");
|
||||||
if (bsdar->options & AR_TR) {
|
if (bsdar->options & AR_TR) {
|
||||||
if (strncmp(bname, obj->name, _TRUNCATE_LEN))
|
if (strncmp(bname, obj->name, _TRUNCATE_LEN))
|
||||||
continue;
|
continue;
|
||||||
@ -563,7 +605,7 @@ write_data(struct bsdar *bsdar, struct archive *a, const void *buf, size_t s)
|
|||||||
while (s > 0) {
|
while (s > 0) {
|
||||||
written = archive_write_data(a, buf, s);
|
written = archive_write_data(a, buf, s);
|
||||||
if (written < 0)
|
if (written < 0)
|
||||||
bsdar_errc(bsdar, archive_errno(a), "%s",
|
bsdar_errc(bsdar, EX_SOFTWARE, archive_errno(a), "%s",
|
||||||
archive_error_string(a));
|
archive_error_string(a));
|
||||||
buf = (const char *)buf + written;
|
buf = (const char *)buf + written;
|
||||||
s -= written;
|
s -= written;
|
||||||
@ -587,7 +629,7 @@ write_objs(struct bsdar *bsdar)
|
|||||||
uint32_t nr32;
|
uint32_t nr32;
|
||||||
|
|
||||||
if (elf_version(EV_CURRENT) == EV_NONE)
|
if (elf_version(EV_CURRENT) == EV_NONE)
|
||||||
bsdar_errc(bsdar, 0,
|
bsdar_errc(bsdar, EX_SOFTWARE, 0,
|
||||||
"ELF library initialization failed: %s", elf_errmsg(-1));
|
"ELF library initialization failed: %s", elf_errmsg(-1));
|
||||||
|
|
||||||
bsdar->rela_off = 0;
|
bsdar->rela_off = 0;
|
||||||
@ -653,7 +695,7 @@ write_objs(struct bsdar *bsdar)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((a = archive_write_new()) == NULL)
|
if ((a = archive_write_new()) == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_write_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0, "archive_write_new failed");
|
||||||
|
|
||||||
archive_write_set_format_ar_svr4(a);
|
archive_write_set_format_ar_svr4(a);
|
||||||
|
|
||||||
@ -668,7 +710,8 @@ write_objs(struct bsdar *bsdar)
|
|||||||
bsdar->options & AR_S) {
|
bsdar->options & AR_S) {
|
||||||
entry = archive_entry_new();
|
entry = archive_entry_new();
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_entry_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0,
|
||||||
|
"archive_entry_new failed");
|
||||||
if (w_sz == sizeof(uint64_t))
|
if (w_sz == sizeof(uint64_t))
|
||||||
archive_entry_copy_pathname(entry, "/SYM64/");
|
archive_entry_copy_pathname(entry, "/SYM64/");
|
||||||
else
|
else
|
||||||
@ -694,7 +737,8 @@ write_objs(struct bsdar *bsdar)
|
|||||||
if (bsdar->as != NULL) {
|
if (bsdar->as != NULL) {
|
||||||
entry = archive_entry_new();
|
entry = archive_entry_new();
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_entry_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0,
|
||||||
|
"archive_entry_new failed");
|
||||||
archive_entry_copy_pathname(entry, "//");
|
archive_entry_copy_pathname(entry, "//");
|
||||||
archive_entry_set_size(entry, bsdar->as_sz);
|
archive_entry_set_size(entry, bsdar->as_sz);
|
||||||
AC(archive_write_header(a, entry));
|
AC(archive_write_header(a, entry));
|
||||||
@ -706,7 +750,8 @@ write_objs(struct bsdar *bsdar)
|
|||||||
TAILQ_FOREACH(obj, &bsdar->v_obj, objs) {
|
TAILQ_FOREACH(obj, &bsdar->v_obj, objs) {
|
||||||
entry = archive_entry_new();
|
entry = archive_entry_new();
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
bsdar_errc(bsdar, 0, "archive_entry_new failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, 0,
|
||||||
|
"archive_entry_new failed");
|
||||||
archive_entry_copy_pathname(entry, obj->name);
|
archive_entry_copy_pathname(entry, obj->name);
|
||||||
archive_entry_set_uid(entry, obj->uid);
|
archive_entry_set_uid(entry, obj->uid);
|
||||||
archive_entry_set_gid(entry, obj->gid);
|
archive_entry_set_gid(entry, obj->gid);
|
||||||
@ -848,7 +893,7 @@ add_to_ar_str_table(struct bsdar *bsdar, const char *name)
|
|||||||
bsdar->as_cap = _INIT_AS_CAP;
|
bsdar->as_cap = _INIT_AS_CAP;
|
||||||
bsdar->as_sz = 0;
|
bsdar->as_sz = 0;
|
||||||
if ((bsdar->as = malloc(bsdar->as_cap)) == NULL)
|
if ((bsdar->as = malloc(bsdar->as_cap)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -859,7 +904,7 @@ add_to_ar_str_table(struct bsdar *bsdar, const char *name)
|
|||||||
bsdar->as_cap *= 2;
|
bsdar->as_cap *= 2;
|
||||||
bsdar->as = realloc(bsdar->as, bsdar->as_cap);
|
bsdar->as = realloc(bsdar->as, bsdar->as_cap);
|
||||||
if (bsdar->as == NULL)
|
if (bsdar->as == NULL)
|
||||||
bsdar_errc(bsdar, errno, "realloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "realloc failed");
|
||||||
}
|
}
|
||||||
strncpy(&bsdar->as[bsdar->as_sz], name, strlen(name));
|
strncpy(&bsdar->as[bsdar->as_sz], name, strlen(name));
|
||||||
bsdar->as_sz += strlen(name);
|
bsdar->as_sz += strlen(name);
|
||||||
@ -877,14 +922,14 @@ add_to_ar_sym_table(struct bsdar *bsdar, const char *name)
|
|||||||
if (bsdar->s_so == NULL) {
|
if (bsdar->s_so == NULL) {
|
||||||
if ((bsdar->s_so = malloc(_INIT_SYMOFF_CAP)) ==
|
if ((bsdar->s_so = malloc(_INIT_SYMOFF_CAP)) ==
|
||||||
NULL)
|
NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
bsdar->s_so_cap = _INIT_SYMOFF_CAP;
|
bsdar->s_so_cap = _INIT_SYMOFF_CAP;
|
||||||
bsdar->s_cnt = 0;
|
bsdar->s_cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bsdar->s_sn == NULL) {
|
if (bsdar->s_sn == NULL) {
|
||||||
if ((bsdar->s_sn = malloc(_INIT_SYMNAME_CAP)) == NULL)
|
if ((bsdar->s_sn = malloc(_INIT_SYMNAME_CAP)) == NULL)
|
||||||
bsdar_errc(bsdar, errno, "malloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "malloc failed");
|
||||||
bsdar->s_sn_cap = _INIT_SYMNAME_CAP;
|
bsdar->s_sn_cap = _INIT_SYMNAME_CAP;
|
||||||
bsdar->s_sn_sz = 0;
|
bsdar->s_sn_sz = 0;
|
||||||
}
|
}
|
||||||
@ -893,7 +938,7 @@ add_to_ar_sym_table(struct bsdar *bsdar, const char *name)
|
|||||||
bsdar->s_so_cap *= 2;
|
bsdar->s_so_cap *= 2;
|
||||||
bsdar->s_so = realloc(bsdar->s_so, bsdar->s_so_cap);
|
bsdar->s_so = realloc(bsdar->s_so, bsdar->s_so_cap);
|
||||||
if (bsdar->s_so == NULL)
|
if (bsdar->s_so == NULL)
|
||||||
bsdar_errc(bsdar, errno, "realloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "realloc failed");
|
||||||
}
|
}
|
||||||
bsdar->s_so[bsdar->s_cnt] = bsdar->rela_off;
|
bsdar->s_so[bsdar->s_cnt] = bsdar->rela_off;
|
||||||
if ((uint64_t)bsdar->rela_off > bsdar->s_so_max)
|
if ((uint64_t)bsdar->rela_off > bsdar->s_so_max)
|
||||||
@ -908,7 +953,7 @@ add_to_ar_sym_table(struct bsdar *bsdar, const char *name)
|
|||||||
bsdar->s_sn_cap *= 2;
|
bsdar->s_sn_cap *= 2;
|
||||||
bsdar->s_sn = realloc(bsdar->s_sn, bsdar->s_sn_cap);
|
bsdar->s_sn = realloc(bsdar->s_sn, bsdar->s_sn_cap);
|
||||||
if (bsdar->s_sn == NULL)
|
if (bsdar->s_sn == NULL)
|
||||||
bsdar_errc(bsdar, errno, "realloc failed");
|
bsdar_errc(bsdar, EX_SOFTWARE, errno, "realloc failed");
|
||||||
}
|
}
|
||||||
strncpy(&bsdar->s_sn[bsdar->s_sn_sz], name, strlen(name));
|
strncpy(&bsdar->s_sn[bsdar->s_sn_sz], name, strlen(name));
|
||||||
bsdar->s_sn_sz += strlen(name);
|
bsdar->s_sn_sz += strlen(name);
|
||||||
|
Loading…
Reference in New Issue
Block a user