View | Details | Raw Unified | Return to bug 105214
Collapse All | Expand All

(-)unmakeself/files/unmakeself.c (+35 lines)
Lines 43-48 Link Here
43
#include <getopt.h>
43
#include <getopt.h>
44
#include <archive.h>
44
#include <archive.h>
45
45
46
#define BUFSIZE 4096
47
46
static char *self = NULL;				/* program name */
48
static char *self = NULL;				/* program name */
47
static int extract_flags = ARCHIVE_EXTRACT_TIME;	/* bsdtar default */
49
static int extract_flags = ARCHIVE_EXTRACT_TIME;	/* bsdtar default */
48
50
Lines 70-75 Link Here
70
  printf("Copyright (C) 2005 Jean-Yves Lefort\n");
72
  printf("Copyright (C) 2005 Jean-Yves Lefort\n");
71
}
73
}
72
74
75
static int
76
unmakeself_get_offset (const char *filename)
77
{
78
  int offset = -1;
79
  int skip = 0;
80
  char buf[BUFSIZE];
81
  FILE *stream;
82
83
  /* Let the script tell us the number of header lines. */
84
  snprintf(buf, BUFSIZE,
85
	   "sh %s --dumpconf | grep OLDSKIP | cut -f2 -d=", filename);
86
  stream = popen(buf, "r");
87
  skip = atoi(fgets(buf, BUFSIZE, stream));
88
  pclose(stream);
89
90
  /* Scan the header lines to calculate the offset. */
91
  if (skip) {
92
    int i;
93
    
94
    stream = fopen(filename, "r");
95
    for (i = 0; i < skip - 1; i++) {
96
      fgets(buf, BUFSIZE, stream);
97
      offset += strlen(buf);
98
    }
99
    fclose(stream);
100
    offset++;
101
  }
102
  return(offset);
103
}
104
73
static void
105
static void
74
unmakeself_extract (const char *filename, int print_offset)
106
unmakeself_extract (const char *filename, int print_offset)
75
{
107
{
Lines 93-98 Link Here
93
   * by locating the first non-printable character following a
125
   * by locating the first non-printable character following a
94
   * newline. The archive starts immediately after that newline.
126
   * newline. The archive starts immediately after that newline.
95
   */
127
   */
128
  /*
96
  while (! done && (len = read(fd, buf, sizeof(buf))) > 0)
129
  while (! done && (len = read(fd, buf, sizeof(buf))) > 0)
97
    {
130
    {
98
      int i;
131
      int i;
Lines 109-115 Link Here
109
	    break;
142
	    break;
110
	  }
143
	  }
111
    }
144
    }
145
  */
112
146
147
  offset = unmakeself_get_offset(filename);
113
  if (offset != -1)		/* offset found */
148
  if (offset != -1)		/* offset found */
114
    {
149
    {
115
      if (print_offset)		/* only print the offset */
150
      if (print_offset)		/* only print the offset */

Return to bug 105214