scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 272cfb4582a575c73add5b73055ea98741bee5d9
parent 077526434528bec1791fc554bcbec556a6c21088
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 24 Nov 2017 15:17:51 +0000

[lib/scc] Add rdarhdr()

This function reads a ar header from a FILE pointer.

Diffstat:
inc/ar.h | 1+
lib/scc/libdep.mk | 1+
lib/scc/rar.c | 33+++++++++++++++++++++++++++++++++
3 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/inc/ar.h b/inc/ar.h @@ -18,3 +18,4 @@ struct arhdr { extern int wrarhdr(FILE *fp, struct arhdr *hdr); extern int wrarfile(FILE *fp, struct arhdr *hdr); +extern int rdarhdr(FILE *fp, struct arhdr *hdr); diff --git a/lib/scc/libdep.mk b/lib/scc/libdep.mk @@ -12,3 +12,4 @@ LIB-OBJ = $(LIBDIR)/debug.o \ $(LIBDIR)/wmyro.o \ $(LIBDIR)/rmyro.o \ $(LIBDIR)/war.o \ + $(LIBDIR)/rar.o \ diff --git a/lib/scc/rar.c b/lib/scc/rar.c @@ -0,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; +}