1 /* dracut-install.c -- install files and executables
3 Copyright (C) 2012 Harald Hoyer
4 Copyright (C) 2012 Red Hat, Inc. All rights reserved.
6 This program is free software: you can redistribute it and/or modify
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program; If not, see <http://www.gnu.org/licenses/>.
20 #define PROGRAM_VERSION_STRING "1"
32 #define CPIO_END "TRAILER!!!"
33 #define CPIO_ENDLEN (sizeof(CPIO_END)-1)
35 static char buf
[CPIO_ENDLEN
* 2 + 1];
37 int main(int argc
, char **argv
)
43 fprintf(stderr
, "Usage: %s <file>\n", argv
[0]);
47 f
= fopen(argv
[1], "r");
50 fprintf(stderr
, "Cannot open file '%s'\n", argv
[1]);
54 s
= fread(buf
, 6, 1, f
);
56 fprintf(stderr
, "Read error from file '%s'\n", argv
[1]);
60 fseek(f
, 0, SEEK_SET
);
62 /* check, if this is a cpio archive */
63 if (buf
[0] == '0' && buf
[1] == '7' && buf
[2] == '0' && buf
[3] == '7' && buf
[4] == '0' && buf
[5] == '1') {
66 /* Search for CPIO_END */
69 fseek(f
, pos
, SEEK_SET
);
70 buf
[sizeof(buf
) - 1] = 0;
71 s
= fread(buf
, CPIO_ENDLEN
, 2, f
);
75 h
= strstr(buf
, CPIO_END
);
77 pos
= (h
- buf
) + pos
+ CPIO_ENDLEN
;
78 fseek(f
, pos
, SEEK_SET
);
85 /* CPIO_END not found, just cat the whole file */
86 fseek(f
, 0, SEEK_SET
);
92 buf
[sizeof(buf
) - 1] = 0;
93 s
= fread(buf
, 1, sizeof(buf
) - 1, f
);
97 for (i
= 0; (i
< s
) && (buf
[i
] == 0); i
++) ;
101 fseek(f
, pos
, SEEK_SET
);
109 /* cat out the rest */
111 s
= fread(buf
, 1, sizeof(buf
), f
);
115 s
= fwrite(buf
, 1, s
, stdout
);