ref: 1775fd4145bc37c5cb629a3aa5d4eaa53329deeb
parent: 8c743e3dc69213504afed3adf59395710a25e8b2
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Fri Aug 23 14:50:43 EDT 2019
[libmach] Move armember() into formember() Armember() is not used out of formember() and it is not going to happen, so it is better to remove this interface.
--- a/include/scc/scc/mach.h
+++ b/include/scc/scc/mach.h
@@ -69,6 +69,7 @@
void *data;
};
+extern int archive(FILE *fp);
extern int formember(FILE *fp,
int (*fn)(FILE *, char *, void *),
void *data);
@@ -77,8 +78,6 @@
extern Obj *objnew(int type);
extern Objsym *objlookup(Obj *obj, char *name, int install);
extern int objpos(Obj *obj, FILE *fp, long pos);
-extern int archive(FILE *fp);
-extern long armember(FILE *fp, char *member);
/* TODO */
--- a/src/libmach/armember.c
+++ /dev/null
@@ -1,46 +1,0 @@
-#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;
-}
--- a/src/libmach/formember.c
+++ b/src/libmach/formember.c
@@ -1,7 +1,49 @@
#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)