* Mini dd implementation for busybox
*
*
- * Copyright (C) 2000 by Matt Kraai <kraai@alumni.carnegiemellon.edu>
+ * Copyright (C) 2000,2001 Matt Kraai
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
#include <sys/types.h>
+#include <sys/stat.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
perror_msg_and_die("%s", outfile);
if (seek && trunc) {
- if (ftruncate(ofd, seek * bs) < 0)
- perror_msg_and_die("%s", outfile);
+ if (ftruncate(ofd, seek * bs) < 0) {
+ struct stat st;
+
+ if (fstat (ofd, &st) < 0 || S_ISREG (st.st_mode) ||
+ S_ISDIR (st.st_mode))
+ perror_msg_and_die("%s", outfile);
+ }
}
} else {
ofd = STDOUT_FILENO;
out_part++;
}
+ if (close (ifd) < 0)
+ perror_msg_and_die("%s", infile);
+
+ if (close (ofd) < 0)
+ perror_msg_and_die("%s", outfile);
+
fprintf(stderr, "%ld+%ld records in\n", (long)in_full, (long)in_part);
fprintf(stderr, "%ld+%ld records out\n", (long)out_full, (long)out_part);