ref: 75e3bd0450527acabecfad8dd1da8f335991805c
parent: d9e5a799f09e39fed6619ece999d9419fbba6880
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Nov 24 10:17:51 EST 2017
[lib/scc] Add rdarhdr() This function reads a ar header from a FILE pointer.
--- a/inc/ar.h
+++ b/inc/ar.h
@@ -18,3 +18,4 @@
extern int wrarhdr(FILE *fp, struct arhdr *hdr);
extern int wrarfile(FILE *fp, struct arhdr *hdr);
+extern int rdarhdr(FILE *fp, struct arhdr *hdr);
--- a/lib/scc/libdep.mk
+++ b/lib/scc/libdep.mk
@@ -12,3 +12,4 @@
$(LIBDIR)/wmyro.o \
$(LIBDIR)/rmyro.o \
$(LIBDIR)/war.o \
+ $(LIBDIR)/rar.o \
--- /dev/null
+++ b/lib/scc/rar.c
@@ -1,0 +1,33 @@
+static char sccsid[] = "@(#) ./lib/scc/rar.c";
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "../../inc/ar.h"
+
+int
+rdarhdr(FILE *fp, struct arhdr *hdr)
+{
+ char buf[ARHDR_SIZ+1];
+ size_t len;
+ int n;
+
+ if (!fgets(buf, sizeof(buf), fp))
+ return EOF;
+ if ((len = strlen(buf)) != ARHDR_SIZ ||
+ buf[len-2] != '`' ||
+ buf[len-1] != '\n') {
+ return EOF;
+ }
+
+ n = sscanf(buf, "%16s-%llu-%u-%u-%o-%llu",
+ &hdr->name,
+ &hdr->time,
+ &hdr->uid, &hdr->gid,
+ &hdr->mode,
+ &hdr->size);
+ if (n != 6)
+ return EOF;
+ return (feof(fp)) ? EOF : 0;
+}