commit 634d58176f11bc196c40934ca24a633f11315cb5
parent ff38a740a0e9dca3f1e52789c0d0a9231d610014
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 8 Jan 2019 18:26:44 +0000
[ar] Increase the portability
ar.h was including directly system headers. This was done
with the idea of chaging the include path to get different
headers, but since the number of needed functions is small
is better to use a few wrappers and avoid the inclusion
trick.
Diffstat:
7 files changed, 62 insertions(+), 31 deletions(-)
diff --git a/src/cmd/Makefile b/src/cmd/Makefile
@@ -39,8 +39,8 @@ $(BINDIR)/objcopy: objcopy.o
$(BINDIR)/addr2line: addr2line.o
$(CC) $(SCC_LDFLAGS) addr2line.o -lmach -o $@
-$(BINDIR)/ar: ar.o ar-$(DRIVER).o
- $(CC) $(SCC_LDFLAGS) ar.o ar-$(DRIVER).o -o $@
+$(BINDIR)/ar: ar.o $(DRIVER).o
+ $(CC) $(SCC_LDFLAGS) ar.o $(DRIVER).o -o $@
dep: inc-dep
diff --git a/src/cmd/ar-posix.c b/src/cmd/ar-posix.c
@@ -1,14 +0,0 @@
-static char sccsid[] = "@(#) ./ar/posix/driver.c";
-
-#include "ar.h"
-
-time_t
-totime(long long t)
-{
- return t;
-}
-
-int
-setattr()
-{
-}
diff --git a/src/cmd/ar.c b/src/cmd/ar.c
@@ -8,7 +8,7 @@ static char sccsid[] = "@(#) ./ar/main.c";
#include <string.h>
#include <time.h>
-#include "ar.h"
+#include "sys.h"
#include <scc/ar.h>
#include <scc/arg.h>
@@ -113,7 +113,7 @@ archive(char *fname, FILE *to, char letter)
size_t n;
FILE *from;
char mtime[13];
- struct stat st;
+ struct fprop prop;
if (vflag)
printf("%c - %s\n", letter, fname);
@@ -121,17 +121,17 @@ archive(char *fname, FILE *to, char letter)
fprintf(stderr, "ar:%s: too long name\n", fname);
if ((from = fopen(fname, "rb")) == NULL)
error("opening member '%s':%s\n", fname, errstr());
- if (stat(fname, &st) < 0)
+ if (getstat(fname, &prop) < 0)
error("error getting '%s' attributes", fname);
- strftime(mtime, sizeof(mtime), "%s", gmtime(&st.st_mtime));
+ strftime(mtime, sizeof(mtime), "%s", gmtime(&prop.time));
fprintf(to,
"%-16.16s%-12s%-6u%-6u%-8o%-10llu`\n",
fname,
mtime,
- st.st_uid,
- st.st_gid,
- st.st_mode,
- (unsigned long long) st.st_size);
+ prop.uid,
+ prop.gid,
+ prop.mode,
+ (unsigned long long) prop.size);
for (n = 0; (c = getc(from)) != EOF; n++)
putc(c, to);
if (n & 1)
diff --git a/src/cmd/ar.h b/src/cmd/ar.h
@@ -1,5 +0,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-extern time_t totime(long long t);
diff --git a/src/cmd/deps.mk b/src/cmd/deps.mk
@@ -1,10 +1,16 @@
#deps
-ar-posix.o: ar.h
+addr2line.o: $(INCDIR)/scc/scc/arg.h
+addr2line.o: $(INCDIR)/scc/scc/mach.h
ar.o: $(INCDIR)/scc/scc/ar.h
ar.o: $(INCDIR)/scc/scc/arg.h
-ar.o: ar.h
+ar.o: sys.h
nm.o: $(INCDIR)/scc/scc/arg.h
nm.o: $(INCDIR)/scc/scc/mach.h
+objdump.o: $(INCDIR)/scc/scc/arg.h
+objdump.o: $(INCDIR)/scc/scc/mach.h
+posix.o: sys.h
+ranlib.o: $(INCDIR)/scc/scc/arg.h
+ranlib.o: $(INCDIR)/scc/scc/mach.h
size.o: $(INCDIR)/scc/scc/arg.h
size.o: $(INCDIR)/scc/scc/mach.h
strip.o: $(INCDIR)/scc/scc/arg.h
diff --git a/src/cmd/posix.c b/src/cmd/posix.c
@@ -0,0 +1,33 @@
+static char sccsid[] = "@(#) ./ar/posix/driver.c";
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+#include "sys.h"
+
+time_t
+totime(long long t)
+{
+ return t;
+}
+
+int
+getstat(char *fname, struct fprop *prop)
+{
+ struct stat st;
+
+ if (stat(fname, &st) < 0)
+ return -1;
+ prop->uid = st.st_uid;
+ prop->gid = st.st_gid;
+ prop->mode = st.st_mode;
+ prop->time = st.st_mtime;
+
+ return 0;
+}
+
+int
+setstat(char *fname, struct fprop *prop)
+{
+}
diff --git a/src/cmd/sys.h b/src/cmd/sys.h
@@ -0,0 +1,11 @@
+struct fprop {
+ unsigned uid;
+ unsigned gid;
+ unsigned mode;
+ long size;
+ time_t time;
+};
+
+extern time_t totime(long long t);
+extern int getstat(char *fname, struct fprop *prop);
+extern int setstat(char *fname, struct fprop *prop);