summaryrefslogtreecommitdiffstats
path: root/lib/libelf/libelf_ar.c
diff options
context:
space:
mode:
authorkaiw <kaiw@FreeBSD.org>2010-07-21 12:54:34 +0000
committerkaiw <kaiw@FreeBSD.org>2010-07-21 12:54:34 +0000
commit5bf2cc0b89a4928b867afcdfdf47ca14579ea977 (patch)
tree121269ef59fca824b890aeb96db5f6f0bbf8ecb4 /lib/libelf/libelf_ar.c
parentbc05b1ebb0eae73c00f539ec402e421a51c05ac1 (diff)
downloadFreeBSD-src-5bf2cc0b89a4928b867afcdfdf47ca14579ea977.zip
FreeBSD-src-5bf2cc0b89a4928b867afcdfdf47ca14579ea977.tar.gz
Move helper functions `_libelf_ar_get_{name,number,string}()` and
`_libelf_ar_open()` to a new compilation unit "libelf_ar_util.c" to break the circular dependency between "elf_memory.o" and "libelf_ar.o". Obtained from: elftoolchain MFC after: 1 month
Diffstat (limited to 'lib/libelf/libelf_ar.c')
-rw-r--r--lib/libelf/libelf_ar.c212
1 files changed, 0 insertions, 212 deletions
diff --git a/lib/libelf/libelf_ar.c b/lib/libelf/libelf_ar.c
index 31eea3d..7322617 100644
--- a/lib/libelf/libelf_ar.c
+++ b/lib/libelf/libelf_ar.c
@@ -72,145 +72,6 @@ __FBSDID("$FreeBSD$");
* they must be the very first objects and in that order.
*/
-/*
- * Convert a string bounded by `start' and `start+sz' (exclusive) to a
- * number in the specified base.
- */
-static int
-_libelf_ar_get_number(char *s, size_t sz, int base, size_t *ret)
-{
- int c, v;
- size_t r;
- char *e;
-
- assert(base <= 10);
-
- e = s + sz;
-
- /* skip leading blanks */
- for (;s < e && (c = *s) == ' '; s++)
- ;
-
- r = 0L;
- for (;s < e; s++) {
- if ((c = *s) == ' ')
- break;
- if (c < '0' || c > '9')
- return (0);
- v = c - '0';
- if (v >= base) /* Illegal digit. */
- break;
- r *= base;
- r += v;
- }
-
- *ret = r;
-
- return (1);
-}
-
-/*
- * Retrieve a string from a name field. If `rawname' is set, leave
- * ar(1) control characters in.
- */
-static char *
-_libelf_ar_get_string(const char *buf, size_t bufsize, int rawname)
-{
- const char *q;
- char *r;
- size_t sz;
-
- if (rawname)
- sz = bufsize + 1;
- else {
- /* Skip back over trailing blanks. */
- for (q = buf + bufsize - 1; q >= buf && *q == ' '; --q)
- ;
-
- if (q < buf) {
- /*
- * If the input buffer only had blanks in it,
- * return a zero-length string.
- */
- buf = "";
- sz = 1;
- } else {
- /*
- * Remove the trailing '/' character, but only
- * if the name isn't one of the special names
- * "/" and "//".
- */
- if (q > buf + 1 ||
- (q == (buf + 1) && *buf != '/'))
- q--;
-
- sz = q - buf + 2; /* Space for a trailing NUL. */
- }
- }
-
- if ((r = malloc(sz)) == NULL) {
- LIBELF_SET_ERROR(RESOURCE, 0);
- return (NULL);
- }
-
- (void) strncpy(r, buf, sz);
- r[sz - 1] = '\0';
-
- return (r);
-}
-
-/*
- * Retrieve the full name of the archive member.
- */
-static char *
-_libelf_ar_get_name(char *buf, size_t bufsize, Elf *e)
-{
- char c, *q, *r, *s;
- size_t len;
- size_t offset;
-
- assert(e->e_kind == ELF_K_AR);
-
- if (buf[0] == '/' && (c = buf[1]) >= '0' && c <= '9') {
- /*
- * The value in field ar_name is a decimal offset into
- * the archive string table where the actual name
- * resides.
- */
- if (_libelf_ar_get_number(buf + 1, bufsize - 1, 10,
- &offset) == 0) {
- LIBELF_SET_ERROR(ARCHIVE, 0);
- return (NULL);
- }
-
- if (offset > e->e_u.e_ar.e_rawstrtabsz) {
- LIBELF_SET_ERROR(ARCHIVE, 0);
- return (NULL);
- }
-
- s = q = e->e_u.e_ar.e_rawstrtab + offset;
- r = e->e_u.e_ar.e_rawstrtab + e->e_u.e_ar.e_rawstrtabsz;
-
- for (s = q; s < r && *s != '/'; s++)
- ;
- len = s - q + 1; /* space for the trailing NUL */
-
- if ((s = malloc(len)) == NULL) {
- LIBELF_SET_ERROR(RESOURCE, 0);
- return (NULL);
- }
-
- (void) strncpy(s, q, len);
- s[len - 1] = '\0';
-
- return (s);
- }
-
- /*
- * Normal 'name'
- */
- return (_libelf_ar_get_string(buf, bufsize, 0));
-}
Elf_Arhdr *
@@ -323,79 +184,6 @@ _libelf_ar_open_member(int fd, Elf_Cmd c, Elf *elf)
return (e);
}
-Elf *
-_libelf_ar_open(Elf *e)
-{
- int i;
- char *s, *end;
- size_t sz;
- struct ar_hdr arh;
-
- e->e_kind = ELF_K_AR;
- e->e_u.e_ar.e_nchildren = 0;
- e->e_u.e_ar.e_next = (off_t) -1;
-
- /*
- * Look for special members.
- */
-
- s = e->e_rawfile + SARMAG;
- end = e->e_rawfile + e->e_rawsize;
-
- assert(e->e_rawsize > 0);
-
- /*
- * Look for magic names "/ " and "// " in the first two entries
- * of the archive.
- */
- for (i = 0; i < 2; i++) {
-
- if (s + sizeof(arh) > end) {
- LIBELF_SET_ERROR(ARCHIVE, 0);
- return (NULL);
- }
-
- (void) memcpy(&arh, s, sizeof(arh));
-
- if (arh.ar_fmag[0] != '`' || arh.ar_fmag[1] != '\n') {
- LIBELF_SET_ERROR(ARCHIVE, 0);
- return (NULL);
- }
-
- if (arh.ar_name[0] != '/') /* not a special symbol */
- break;
-
- if (_libelf_ar_get_number(arh.ar_size, sizeof(arh.ar_size), 10, &sz) == 0) {
- LIBELF_SET_ERROR(ARCHIVE, 0);
- return (NULL);
- }
-
- assert(sz > 0);
-
- s += sizeof(arh);
-
- if (arh.ar_name[1] == ' ') { /* "/ " => symbol table */
-
- e->e_u.e_ar.e_rawsymtab = s;
- e->e_u.e_ar.e_rawsymtabsz = sz;
-
- } else if (arh.ar_name[1] == '/' && arh.ar_name[2] == ' ') {
-
- /* "// " => string table for long file names */
- e->e_u.e_ar.e_rawstrtab = s;
- e->e_u.e_ar.e_rawstrtabsz = sz;
- }
-
- sz = LIBELF_ADJUST_AR_SIZE(sz);
-
- s += sz;
- }
-
- e->e_u.e_ar.e_next = (off_t) (s - e->e_rawfile);
-
- return (e);
-}
-
/*
* An ar(1) symbol table has the following layout:
*
OpenPOWER on IntegriCloud