X-Git-Url: http://git.cascardo.info/?p=cascardo%2Flinux.git;a=blobdiff_plain;f=usr%2Fgen_init_cpio.c;fp=usr%2Fgen_init_cpio.c;h=7f06884ecd41b588d829064a53ac964395b0ae1e;hp=b2b3c2d1cf8bd37849d92b9a1d06131f1cf14f96;hb=0c05384a5a1af2352b8c244cf32f480ba6cbf024;hpb=1542dec1c9109fdcd1c53460f064096f24fc49d2 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c index b2b3c2d1cf8b..7f06884ecd41 100644 --- a/usr/gen_init_cpio.c +++ b/usr/gen_init_cpio.c @@ -104,6 +104,8 @@ static int cpio_mkslink(const char *name, const char *target, char s[256]; time_t mtime = time(NULL); + if (name[0] == '/') + name++; sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" "%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ @@ -152,6 +154,8 @@ static int cpio_mkgeneric(const char *name, unsigned int mode, char s[256]; time_t mtime = time(NULL); + if (name[0] == '/') + name++; sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" "%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ @@ -245,6 +249,8 @@ static int cpio_mknod(const char *name, unsigned int mode, else mode |= S_IFCHR; + if (name[0] == '/') + name++; sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" "%08X%08X%08X%08X%08X%08X%08X", "070701", /* magic */ @@ -303,18 +309,18 @@ static int cpio_mkfile(const char *name, const char *location, mode |= S_IFREG; - retval = stat (location, &buf); - if (retval) { - fprintf (stderr, "File %s could not be located\n", location); - goto error; - } - file = open (location, O_RDONLY); if (file < 0) { fprintf (stderr, "File %s could not be opened for reading\n", location); goto error; } + retval = fstat(file, &buf); + if (retval) { + fprintf(stderr, "File %s could not be stat()'ed\n", location); + goto error; + } + filebuf = malloc(buf.st_size); if (!filebuf) { fprintf (stderr, "out of memory\n"); @@ -332,6 +338,8 @@ static int cpio_mkfile(const char *name, const char *location, /* data goes on last link */ if (i == nlinks) size = buf.st_size; + if (name[0] == '/') + name++; namesize = strlen(name) + 1; sprintf(s,"%s%08X%08X%08lX%08lX%08X%08lX" "%08lX%08X%08X%08X%08X%08X%08X",