scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | README | LICENSE

formember.c (390B)


      1 #include <stdio.h>
      2 
      3 #include <scc/ar.h>
      4 #include <scc/mach.h>
      5 
      6 int
      7 formember(FILE *fp, int (*fn)(FILE *, char *, void *), void *data)
      8 {
      9 	int r;
     10 	long off;
     11 	fpos_t pos;
     12 	char name[SARNAM+1];
     13 
     14 	for (;;) {
     15 		fgetpos(fp, &pos);
     16 
     17 		if ((off = armember(fp, name)) <= 0)
     18 			return off;
     19 		r = (*fn)(fp, name, data);
     20 		if (r <= 0)
     21 			return r;
     22 
     23 		fsetpos(fp, &pos);
     24 		fseek(fp, off, SEEK_CUR);
     25 	}
     26 }