summaryrefslogtreecommitdiffstats
path: root/loader
diff options
context:
space:
mode:
authorErik Troan <ewt@redhat.com>2001-01-30 19:12:39 +0000
committerErik Troan <ewt@redhat.com>2001-01-30 19:12:39 +0000
commit2d8704857ed4a0a182b29c7eab696578dcd96a08 (patch)
tree54e50620fcc18749a2e6b3cc1ee776a53e74adff /loader
parentfc52eb64e5cef745015a1cb92c0a7d4bcd251b68 (diff)
downloadanaconda-2d8704857ed4a0a182b29c7eab696578dcd96a08.tar.gz
anaconda-2d8704857ed4a0a182b29c7eab696578dcd96a08.tar.xz
anaconda-2d8704857ed4a0a182b29c7eab696578dcd96a08.zip
added readLine() [merge from 7.0 branch]
Diffstat (limited to 'loader')
-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