Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F131874945
D31496.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
6 KB
Referenced Files
None
Subscribers
None
D31496.diff
View Options
diff --git a/usr.bin/ar/acpyacc.y b/usr.bin/ar/acpyacc.y
--- a/usr.bin/ar/acpyacc.y
+++ b/usr.bin/ar/acpyacc.y
@@ -367,7 +367,7 @@
return;
arscp_mlist2argv(list);
bsdar->addlib = archive;
- ar_mode_A(bsdar);
+ ar_write_archive(bsdar, 'A');
arscp_free_argv();
arscp_free_mlist(list);
}
@@ -380,7 +380,7 @@
if (!arscp_target_exist())
return;
arscp_mlist2argv(list);
- ar_mode_q(bsdar);
+ ar_write_archive(bsdar, 'q');
arscp_free_argv();
arscp_free_mlist(list);
}
@@ -393,7 +393,7 @@
if (!arscp_target_exist())
return;
arscp_mlist2argv(list);
- ar_mode_d(bsdar);
+ ar_write_archive(bsdar, 'd');
arscp_free_argv();
arscp_free_mlist(list);
}
@@ -406,7 +406,7 @@
if (!arscp_target_exist())
return;
arscp_mlist2argv(list);
- ar_mode_x(bsdar);
+ ar_read_archive(bsdar, 'x');
arscp_free_argv();
arscp_free_mlist(list);
}
@@ -422,7 +422,7 @@
bsdar->argv = NULL;
/* Always verbose. */
bsdar->options |= AR_V;
- ar_mode_t(bsdar);
+ ar_read_archive(bsdar, 't');
bsdar->options &= ~AR_V;
}
@@ -449,7 +449,7 @@
}
if (verbose)
bsdar->options |= AR_V;
- ar_mode_t(bsdar);
+ ar_read_archive(bsdar, 't');
bsdar->options &= ~AR_V;
if (rlt) {
@@ -473,7 +473,7 @@
if (!arscp_target_exist())
return;
arscp_mlist2argv(list);
- ar_mode_r(bsdar);
+ ar_write_archive(bsdar, 'r');
arscp_free_argv();
arscp_free_mlist(list);
}
diff --git a/usr.bin/ar/ar.h b/usr.bin/ar/ar.h
--- a/usr.bin/ar/ar.h
+++ b/usr.bin/ar/ar.h
@@ -115,14 +115,8 @@
};
void bsdar_errc(struct bsdar *, int _code, const char *fmt, ...) __dead2;
-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);
+int ar_read_archive(struct bsdar *ar, int mode);
+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, ...);
diff --git a/usr.bin/ar/ar.c b/usr.bin/ar/ar.c
--- a/usr.bin/ar/ar.c
+++ b/usr.bin/ar/ar.c
@@ -151,7 +151,7 @@
bsdar->options |= AR_D;
bsdar->options |= AR_S;
while ((bsdar->filename = *argv++) != NULL)
- if (ar_mode_s(bsdar))
+ if (ar_write_archive(bsdar, 's'))
exitcode = EXIT_FAILURE;
exit(exitcode);
@@ -317,32 +317,17 @@
if ((!bsdar->mode || strchr("ptx", bsdar->mode)) &&
bsdar->options & AR_S) {
- exitcode = ar_mode_s(bsdar);
+ exitcode = ar_write_archive(bsdar, 's');
if (!bsdar->mode)
exit(exitcode);
}
switch(bsdar->mode) {
- case 'd':
- exitcode = ar_mode_d(bsdar);
+ case 'd': case 'm': case 'q': case 'r':
+ exitcode = ar_write_archive(bsdar, bsdar->mode);
break;
- case 'm':
- 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);
+ case 'p': case 't': case 'x':
+ exitcode = ar_read_archive(bsdar, bsdar->mode);
break;
default:
bsdar_usage();
diff --git a/usr.bin/ar/read.c b/usr.bin/ar/read.c
--- a/usr.bin/ar/read.c
+++ b/usr.bin/ar/read.c
@@ -34,6 +34,7 @@
#include <sys/stat.h>
#include <archive.h>
#include <archive_entry.h>
+#include <assert.h>
#include <errno.h>
#include <libgen.h>
#include <stdio.h>
@@ -42,34 +43,11 @@
#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'.
*/
-static int
-read_archive(struct bsdar *bsdar, char mode)
+int
+ar_read_archive(struct bsdar *bsdar, int mode)
{
struct archive *a;
struct archive_entry *entry;
@@ -87,6 +65,8 @@
char find;
int exitcode, flags, r, i;
+ assert(mode == 'p' || mode == 't' || mode == 'x');
+
if ((a = archive_read_new()) == NULL)
bsdar_errc(bsdar, 0, "archive_read_new failed");
archive_read_support_format_ar(a);
diff --git a/usr.bin/ar/write.c b/usr.bin/ar/write.c
--- a/usr.bin/ar/write.c
+++ b/usr.bin/ar/write.c
@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <archive.h>
#include <archive_entry.h>
+#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <gelf.h>
@@ -66,54 +67,11 @@
static void prefault_buffer(const char *buf, size_t s);
static void read_objs(struct bsdar *bsdar, const char *archive,
int checkargv);
-static int write_archive(struct bsdar *bsdar, char mode);
static void write_cleanup(struct bsdar *bsdar);
static void write_data(struct bsdar *bsdar, struct archive *a,
const void *buf, size_t s);
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
* when an error occurs or the member is not newer than existing
@@ -376,8 +334,8 @@
/*
* Determine the constitution of resulting archive.
*/
-static int
-write_archive(struct bsdar *bsdar, char mode)
+int
+ar_write_archive(struct bsdar *bsdar, int mode)
{
struct ar_obj *nobj, *obj, *obj_temp, *pos;
struct stat sb;
@@ -391,6 +349,9 @@
pos = NULL;
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
* whether we are creating one here.
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Oct 12, 9:30 PM (21 h, 46 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
23641798
Default Alt Text
D31496.diff (6 KB)
Attached To
Mode
D31496: ar: diff reduction against ELF Tool Chain
Attached
Detach File
Event Timeline
Log In to Comment