scc

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

rar.c (619B)


      1 static char sccsid[] = "@(#) ./lib/scc/rar.c";
      2 
      3 #include <assert.h>
      4 #include <stdio.h>
      5 #include <string.h>
      6 
      7 #include "../../inc/ar.h"
      8 
      9 int
     10 rdarhdr(FILE *fp, struct arhdr *hdr)
     11 {
     12 	char buf[ARHDR_SIZ+1];
     13 	size_t len;
     14 	int n;
     15 
     16 	if (!fgets(buf, sizeof(buf), fp))
     17 		return EOF;
     18 	if ((len = strlen(buf)) != ARHDR_SIZ ||
     19 	    buf[len-2] != '`' ||
     20 	    buf[len-1] != '\n') {
     21 		return EOF;
     22 	}
     23 
     24 	n = sscanf(buf, "%16s-%llu-%u-%u-%o-%llu",
     25 	           &hdr->name,
     26 	           &hdr->time,
     27 	           &hdr->uid, &hdr->gid,
     28 	           &hdr->mode,
     29 	           &hdr->size);
     30 	if (n != 6)
     31 		return EOF;
     32 	return (feof(fp)) ? EOF : 0;
     33 }