scc

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

commit a90a056decd43416af84311bc5577fa99cd6c217
parent 50d3bd454474cd84404e4cb71b1d4b8a0a67987f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sat, 24 Aug 2019 08:22:44 +0100

Revert "[libmach] Move armember() into formember()"

This reverts commit c176afa115cb4c2cec647e688c75af1757666953.

Diffstat:
Minclude/scc/scc/mach.h | 1+
Asrc/libmach/armember.c | 46++++++++++++++++++++++++++++++++++++++++++++++
Msrc/libmach/formember.c | 42------------------------------------------
3 files changed, 47 insertions(+), 42 deletions(-)

diff --git a/include/scc/scc/mach.h b/include/scc/scc/mach.h @@ -69,6 +69,7 @@ struct obj { }; extern int archive(FILE *fp); +extern long armember(FILE *fp, char *member); extern int formember(FILE *fp, int (*fn)(FILE *, char *, void *), void *data); diff --git a/src/libmach/armember.c b/src/libmach/armember.c @@ -0,0 +1,46 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <scc/ar.h> +#include <scc/mach.h> + +static char * +getfname(struct ar_hdr *hdr, char *dst) +{ + char *p; + int i; + + memcpy(dst, hdr->ar_name, SARNAM); + dst[SARNAM] = '\0'; + + for (i = SARNAM-1; i > 0; i--) { + if (dst[i] != ' ' && dst[i] != '/') + break; + dst[i] = '\0'; + } + return dst; +} + +long +armember(FILE *fp, char *member) +{ + struct ar_hdr hdr; + long siz; + + if (fread(&hdr, sizeof(hdr), 1, fp) != 1) + return (feof(fp)) ? 0 : -1; + + if (strncmp(hdr.ar_fmag, ARFMAG, sizeof(hdr.ar_fmag))) + return -1; + + siz = strtol(hdr.ar_size, NULL, 0); + if (siz & 1) + siz++; + if (siz == 0) + return -1; + + getfname(&hdr, member); + + return sizeof(hdr) + siz; +} diff --git a/src/libmach/formember.c b/src/libmach/formember.c @@ -1,50 +1,8 @@ #include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <scc/ar.h> #include <scc/mach.h> -static char * -getfname(struct ar_hdr *hdr, char *dst) -{ - char *p; - int i; - - memcpy(dst, hdr->ar_name, SARNAM); - dst[SARNAM] = '\0'; - - for (i = SARNAM-1; i > 0; i--) { - if (dst[i] != ' ' && dst[i] != '/') - break; - dst[i] = '\0'; - } - return dst; -} - -static long -armember(FILE *fp, char *member) -{ - struct ar_hdr hdr; - long siz; - - if (fread(&hdr, sizeof(hdr), 1, fp) != 1) - return (feof(fp)) ? 0 : -1; - - if (strncmp(hdr.ar_fmag, ARFMAG, sizeof(hdr.ar_fmag))) - return -1; - - siz = strtol(hdr.ar_size, NULL, 0); - if (siz & 1) - siz++; - if (siz == 0) - return -1; - - getfname(&hdr, member); - - return sizeof(hdr) + siz; -} - int formember(FILE *fp, int (*fn)(FILE *, char *, void *), void *data) {