summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--loader/misc.c24
-rw-r--r--loader/misc.h1
2 files changed, 23 insertions, 2 deletions
diff --git a/loader/misc.c b/loader/misc.c
index c811e669e..776520a0e 100644
--- a/loader/misc.c
+++ b/loader/misc.c
@@ -9,21 +9,41 @@ int copyFile(char * source, char * dest) {
int infd = -1, outfd = -1;
char buf[4096];
int i;
+ int rc = 0;
outfd = open(dest, O_CREAT | O_RDWR, 0666);
infd = open(source, O_RDONLY);
if (infd < 0) {
logMessage("failed to open %s: %s", source, strerror(errno));
+ return 1;
+ } else if (outfd < 0) {
+ close(infd);
+ logMessage("failed to open %s: %s", dest, strerror(errno));
+ return 1;
}
while ((i = read(infd, buf, sizeof(buf))) > 0) {
- if (write(outfd, buf, i) != i) break;
+ if (write(outfd, buf, i) != i) {
+ rc = 1;
+ break;
+ }
}
close(infd);
close(outfd);
- return 0;
+ return rc;
+}
+
+char * readLine(FILE * f) {
+ char buf[1024];
+
+ fgets(buf, sizeof(buf), f);
+
+ /* chop */
+ buf[strlen(buf) - 1] = '\0';
+
+ return strdup(buf);
}
diff --git a/loader/misc.h b/loader/misc.h
index 2d29534d6..b85f140db 100644
--- a/loader/misc.h
+++ b/loader/misc.h
@@ -2,5 +2,6 @@
#define H_LOADER_MISC_H
int copyFile(char * source, char * dest);
+char * readLine(FILE * f);
#endif