Skip to content

Commit

Permalink
strict null parameter check & support arm archs
Browse files Browse the repository at this point in the history
  • Loading branch information
teras committed Sep 3, 2017
1 parent 30fbaab commit 777dfb5
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions appimagetool.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ extern int _binary_runtime_end;

#define fARCH_i386 0
#define fARCH_x86_64 1
#define fARCH_arm 2
#define fARCH_aarch64 3

static gchar const APPIMAGEIGNORE[] = ".appimageignore";
static char _exclude_file_desc[256];
Expand Down Expand Up @@ -253,26 +255,40 @@ static void replacestr(char *line, const char *search, const char *replace)
}

void guess_arch(const gchar *archfile, char* archs) {
gchar *found_arch;
gchar *carch;
char line[PATH_MAX];
char command[PATH_MAX];
sprintf(command, "/usr/bin/file -L -N -b %s", archfile);
FILE* fp = popen(command, "r");
if (fp == NULL)
die("Failed to run file command");
fgets(line, sizeof (line) - 1, fp);
found_arch = g_strstrip(g_strsplit_set(line, ",", -1)[1]);
replacestr(found_arch, "-", "_");
pclose(fp);
if (g_ascii_strncasecmp("i386", found_arch, 20)==0) {
archs[fARCH_i386] = 1;
if(verbose)
fprintf (stderr,"File used for determining architecture i386: %s\n", archfile);
}
else if (g_ascii_strncasecmp("x86_64", found_arch, 20)==0) {
archs[fARCH_x86_64] = 1;
if(verbose)
fprintf (stderr,"File used for determining architecture x86_64: %s\n", archfile);
fprintf(stderr, "file output: %s", line);
carch = g_strsplit_set(line, ",", -1)[1];
if (carch) {
carch = g_strstrip(carch);
if (carch) {
replacestr(carch, "-", "_");
replacestr(carch, " ", "_");
if (g_ascii_strncasecmp("i386", carch, 20) == 0) {
archs[fARCH_i386] = 1;
if (verbose)
fprintf(stderr, "File used for determining architecture i386: %s\n", archfile);
} else if (g_ascii_strncasecmp("x86_64", carch, 20) == 0) {
archs[fARCH_x86_64] = 1;
if (verbose)
fprintf(stderr, "File used for determining architecture x86_64: %s\n", archfile);
} else if (g_ascii_strncasecmp("arm", carch, 20) == 0) {
archs[fARCH_arm] = 1;
if (verbose)
fprintf(stderr, "File used for determining architecture ARM: %s\n", archfile);
} else if (g_ascii_strncasecmp("arm_aarch64", carch, 20) == 0) {
archs[fARCH_aarch64] = 1;
if (verbose)
fprintf(stderr, "File used for determining architecture ARM aarch64: %s\n", archfile);
}
}
}
}

Expand Down Expand Up @@ -474,7 +490,7 @@ main (int argc, char *argv[])
/* If no $ARCH variable is set check a file */
if (!arch) {
/* We use the next best .so that we can find to determine the architecture */
char archs[2];
char archs[4];
find_arch(source, "*.so.*", archs);
int countArchs = 0;
if (archs[fARCH_i386]) {
Expand All @@ -485,6 +501,14 @@ main (int argc, char *argv[])
arch = "x86_64";
countArchs++;
}
if (archs[fARCH_arm]) {
arch = "ARM";
countArchs++;
}
if (archs[fARCH_aarch64]) {
arch = "ARM aarch64";
countArchs++;
}
if (countArchs!=1) {
if (countArchs<1)
fprintf(stderr, "Unable to guess the architecture of the AppDir source directory \"%s\"\n", remaining_args[0]);
Expand Down

0 comments on commit 777dfb5

Please sign in to comment.