diff -Nur unmakeself.orig/files/unmakeself.c unmakeself/files/unmakeself.c --- unmakeself.orig/files/unmakeself.c Sun Jun 12 20:17:05 2005 +++ unmakeself/files/unmakeself.c Mon Nov 6 14:36:53 2006 @@ -43,6 +43,8 @@ #include #include +#define BUFSIZE 4096 + static char *self = NULL; /* program name */ static int extract_flags = ARCHIVE_EXTRACT_TIME; /* bsdtar default */ @@ -70,6 +72,36 @@ printf("Copyright (C) 2005 Jean-Yves Lefort\n"); } +static int +unmakeself_get_offset (const char *filename) +{ + int offset = -1; + int skip = 0; + char buf[BUFSIZE]; + FILE *stream; + + /* Let the script tell us the number of header lines. */ + snprintf(buf, BUFSIZE, + "sh %s --dumpconf | grep OLDSKIP | cut -f2 -d=", filename); + stream = popen(buf, "r"); + skip = atoi(fgets(buf, BUFSIZE, stream)); + pclose(stream); + + /* Scan the header lines to calculate the offset. */ + if (skip) { + int i; + + stream = fopen(filename, "r"); + for (i = 0; i < skip - 1; i++) { + fgets(buf, BUFSIZE, stream); + offset += strlen(buf); + } + fclose(stream); + offset++; + } + return(offset); +} + static void unmakeself_extract (const char *filename, int print_offset) { @@ -93,6 +125,7 @@ * by locating the first non-printable character following a * newline. The archive starts immediately after that newline. */ + /* while (! done && (len = read(fd, buf, sizeof(buf))) > 0) { int i; @@ -109,7 +142,9 @@ break; } } + */ + offset = unmakeself_get_offset(filename); if (offset != -1) /* offset found */ { if (print_offset) /* only print the offset */