ref: 634d58176f11bc196c40934ca24a633f11315cb5
parent: ff38a740a0e9dca3f1e52789c0d0a9231d610014
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Jan 8 13:26:44 EST 2019
[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.
--- a/src/cmd/Makefile
+++ b/src/cmd/Makefile
@@ -39,8 +39,8 @@
$(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
--- a/src/cmd/ar-posix.c
+++ /dev/null
@@ -1,14 +1,0 @@
-static char sccsid[] = "@(#) ./ar/posix/driver.c";
-
-#include "ar.h"
-
-time_t
-totime(long long t)
-{
- return t;
-}
-
-int
-setattr()
-{
-}
--- a/src/cmd/ar.c
+++ b/src/cmd/ar.c
@@ -8,7 +8,7 @@
#include <string.h>
#include <time.h>
-#include "ar.h"
+#include "sys.h"
#include <scc/ar.h>
#include <scc/arg.h>
@@ -113,7 +113,7 @@
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 @@
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)
--- a/src/cmd/ar.h
+++ /dev/null
@@ -1,5 +1,0 @@
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-extern time_t totime(long long t);
--- 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
--- /dev/null
+++ b/src/cmd/posix.c
@@ -1,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)
+{
+}
--- /dev/null
+++ b/src/cmd/sys.h
@@ -1,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);