Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add parsing of Mach-O files.
Landon Fuller committed 11 years ago
commit a3d60831a362661a98b32a95c2a36beb5ad7503c
parent 00551dc
3 files changed +67 -6
modified libpkg/pkg_macho.c
@@ -30,6 +30,9 @@
#include "pkg_config.h"
#endif

+
#include <mach-o/arch.h>
+
#include <libmachista.h>
+

#include <bsd_compat.h>

#include "pkg.h"
@@ -39,28 +42,78 @@
int
pkg_analyse_files(struct pkgdb *db, struct pkg *pkg, const char *stage)
{
-
    // TODO
-
    return (EPKG_FATAL);
+
	macho_handle_t *macho_handle = NULL;
+
	const macho_t *macho = NULL;
+
	struct pkg_file *file = NULL;
+
	char *fpath = NULL;
+
	int ret = EPKG_OK;
+
	int mret;
+

+
	/* Create our mach-o handle */
+
	macho_handle = macho_create_handle();
+
	if (macho_handle == NULL) {
+
			pkg_emit_error("macho_create_handle() failed");
+
			ret = EPKG_FATAL;
+
			goto cleanup;
+
	}
+

+
	/* Evaluate all package files */
+
	while (pkg_files(pkg, &file) == EPKG_OK) {
+
		if (stage != NULL)
+
			free(fpath);
+

+
		if (stage != NULL)
+
			asprintf(&fpath, "%s/%s", stage, file->path);
+
		else
+
			fpath = file->path;
+

+
		if (fpath == NULL) {
+
			pkg_emit_error("pkg_analyse_files(): path allocation failed");
+
			ret = EPKG_FATAL;
+
			goto cleanup;
+
		}
+

+
		if ((mret = macho_parse_file(macho_handle, fpath, &macho)) != MACHO_SUCCESS) {
+
			if (mret != MACHO_EMAGIC && mret != MACHO_ERANGE) {
+
				pkg_emit_error("macho_parse_file() for %s failed: %s", fpath, macho_strerror(mret));
+
				ret = EPKG_FATAL;
+
				goto cleanup;
+
			}
+

+
			/* Not a Mach-O file; no results */
+
			continue;
+
		}		
+
	}
+

+
cleanup:
+
	macho_destroy_handle(macho_handle);
+

+
	if (stage != NULL)
+
		free(fpath);
+

+
	return (ret);
}


int
pkg_arch_to_legacy(const char *arch, char *dest, size_t sz)
{
-
    // TODO
+
	strlcpy(dest, arch, sz);
	return (0);
}

int
pkg_get_myarch_legacy(char *dest, size_t sz)
{
-
    // TODO
-
	return (0);
+
	return pkg_get_myarch(dest, sz);
}

int
pkg_get_myarch(char *dest, size_t sz)
{
-
    // TODO
+
	const NXArchInfo *ai = NXGetLocalArchInfo();
+
	assert(ai != NULL);
+

+
	strlcpy(dest, ai->name, sz);
	return (0);
}
modified src/Makefile.am
@@ -75,6 +75,10 @@ pkg_static_LDADD+= -lelf
endif
endif

+
if HAVE_MACHO_ABI
+
pkg_static_LDADD+=	$(top_builddir)/external/libmachista_static.la
+
endif
+

pkg_static_LDFLAGS=	-all-static
DYNPROG=		pkg
sbin_PROGRAMS=		pkg-static
modified tests/Makefile.am
@@ -23,6 +23,10 @@ GENERIC_LDADD+= -lelf
endif
endif

+
if HAVE_MACHO_ABI
+
GENERIC_LDADD+=	$(top_builddir)/external/libmachista_static.la
+
endif
+

PUBLIC_INCS=	-I$(top_srcdir)/libpkg -DTESTING \
		-I/usr/local/include
PRIVATE_INCS=	$(PUBLIC_INCS) \