blob: 1a5176d297ef5dbc5c53659723a57d8574379bff [file] [log] [blame]
diff -Naur a/src/main.c b/src/main.c
--- a/src/main.c 2014-12-03 16:53:29.724125643 -0800
+++ b/src/main.c 2014-12-03 17:47:29.835274590 -0800
@@ -47,7 +47,6 @@
#include <sys/un.h>
#include <sys/mman.h>
#include <sys/wait.h>
-#include <sys/sendfile.h>
#include "mtd.h"
#include "plat_boot_config.h"
@@ -555,33 +554,29 @@
return 0;
}
-static char *tmp_file = ".tmp_kobs_ng";
-static char *padding_1k_in_head(char *file_name)
+static FILE *padding_1k_in_head(FILE *from)
{
- int to, from;
- int ret;
- int sz = getpagesize();
-
- from = open(file_name, O_RDONLY, S_IRUSR | S_IWUSR);
- to = open(tmp_file, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
- if (from < 0 || to < 0) {
+ FILE *to;
+ char buf[BUFSIZ];
+ size_t size;
+
+ to = tmpfile();
+ if (from == NULL || to == NULL) {
fprintf(stderr, "unable to create a temporary file\n");
exit(5);
}
/* Padding 1k in the head. */
- lseek(to, 1024, SEEK_SET);
+ fseek(to, 1024, SEEK_SET);
- do {
- /* copy a page each time. */
- ret = sendfile(to, from, NULL, sz);
- } while (ret > 0);
+ while ((size = fread(buf, 1, BUFSIZ, from)) > 0) {
+ fwrite(buf, 1, size, to);
+ }
- close(to);
- close(from);
+ fclose(from);
/* change to the temporary file. */
- return tmp_file;
+ return to;
}
int init_main(int argc, char **argv)
@@ -670,19 +665,19 @@
* So we have to add the 1k-padding ourselves.
* Note: We only burn the uboot to nand in the kernel 3.5.7.
*/
- if (padding) {
- infile = padding_1k_in_head(infile);
-
- if (flags & F_VERBOSE)
- printf("\t -- We add the 1k-padding to the uboot.\n");
- }
-
infp = fopen(infile, "rb");
if (infp == NULL) {
fprintf(stderr, "Unable to open input file '%s'\n", infile);
usage();
}
+ if (padding) {
+ infp = padding_1k_in_head(infp);
+
+ if (flags & F_VERBOSE)
+ printf("\t -- We add the 1k-padding to the uboot.\n");
+ }
+
keyp = !device_key ? key : NULL;
if (flags & F_VERBOSE)