summaryrefslogtreecommitdiffstats
path: root/loader/misc.c
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/misc.c
parentfc52eb64e5cef745015a1cb92c0a7d4bcd251b68 (diff)
downloadanaconda-2d8704857ed4a0a182b29c7eab696578dcd96a08.tar.gz
anaconda-2d8704857ed4a0a182b29c7eab696578dcd96a08.tar.xz
anaconda-2d8704857ed4a0a182b29c7eab696578dcd96a08.zip
added readLine() [merge from 7.0 branch]
Diffstat (limited to 'loader/misc.c')
-rw-r--r--loader/misc.c24
1 files changed, 22 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);
}