1 /* expand.c: expand a file with holes into another
3 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>,
4 * D. Jeff Dionne <jeff@lineo.ca>,
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * gerg@snapgear.com -- 9/4/1999 -- hacked to be stand alone program.
17 #include <sys/types.h>
27 expand(char *from, char *to)
31 unsigned int pos, prepos;
32 unsigned int len, prelen, n;
38 if ((fdi = open(from,O_RDONLY)) < 0) {
39 fprintf(stderr,"Can't open compressed file %s\n",from);
43 if ((fdo = open(to,O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
44 fprintf(stderr,"Can't open expanded file %s\n",to);
51 if (!(buf = malloc(2048))) {
52 fprintf(stderr,"can't allocate memory\n");
59 read(fdi,(char *)&len,4);
60 fprintf(stderr, "TOTAL LEN=%x", len);
62 fprintf(stderr, "[%x]\n", len);
66 n = (len > 2048) ? 2048 : len;
70 lseek(fdo, 0, SEEK_SET);
73 while (read(fdi,&pos,4) == 4) {
74 if (read(fdi,&len,4) != 4) break;
79 fprintf(stderr, "POS=%x[%x]:LEN=%x[%x]", prepos, pos, prelen, len);
81 lseek(fdo,pos,SEEK_SET);
82 fprintf(stderr, " --> DATA=%x\n", buf[0]);
93 int main(int argc, char *argv[])
96 printf("usage: expand <from-file> <to-file>\n");
100 printf("expand: from=%s to=%s\n", argv[1], argv[2]);
101 expand(argv[1], argv[2]);