Splash Site Admin
Зарегистрирован: 09.11.2007 Сообщения: 228
|
Добавлено: Ср Май 07, 2008 6:59 pm Заголовок сообщения: [temporary] |
|
|
[pre]
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <string.h>
void
die (char *str) {
perror (str);
exit (1);
}
u_int8_t buf[65536];
main (int argc, char **argv) {
int fi = open (argv[1], O_RDONLY);
int fo;
char oname[256];
int16_t rec_type;
u_int16_t rec_len;
if (fi < 0) die ("open input");
if (lseek (fi, 8, SEEK_SET) != die ("lseek");
while (read (fi, &rec_type, sizeof rec_type) == sizeof rec_type && rec_type > 0) {
if (read (fi, &rec_len, sizeof rec_len) != sizeof rec_len) die ("read rec_len");
if (read (fi, buf, rec_len) != rec_len) die ("read rec");
sprintf (oname, "%s.%04x", argv[1], rec_type);
fo = open (oname, O_WRONLY | O_CREAT | O_APPEND, 0644);
if (fo < 0) die ("open output");
if (write (fo, buf, rec_len) != rec_len) die ("write rec");
close (fo);
}
}
[/pre] |
|