scc

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

war.c (688B)


      1 static char sccsid[] = "@(#) ./lib/scc/war.c";
      2 
      3 #include <assert.h>
      4 #include <stdio.h>
      5 
      6 #include "../../inc/ar.h"
      7 
      8 int
      9 wrarhdr(FILE *fp, struct arhdr *hdr)
     10 {
     11 	int len;
     12 
     13 	len = fprintf(fp,
     14 	              "%-16s%-12llu%-6u%-6u%-8o%-10llu`\n",
     15 	              hdr->name,
     16 	              hdr->time,
     17 	              hdr->uid, hdr->gid,
     18 	              hdr->mode,
     19 	              hdr->size);
     20 	assert(len== ARHDR_SIZ);
     21 
     22 	return (feof(fp)) ? EOF : len;
     23 }
     24 
     25 int
     26 wrarfile(FILE *fo, struct arhdr *hdr)
     27 {
     28 	FILE *fi;
     29 	int c;
     30 
     31 	if ((fi = fopen(hdr->name, "rb")) == NULL)
     32 		return -1;
     33 	while ((c = getc(fi)) != EOF)
     34 		putc(c, fo);
     35 	if (hdr->size & 1)
     36 		putc('\n', fo);
     37 	return (fclose(fi) == EOF) ? -1 : 0;
     38 }