summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2014-02-10 13:14:37 +0100
committerSimon Rettberg2014-02-10 13:14:37 +0100
commite4c69f10c8729812176ef49171e79e9dd8cd983f (patch)
tree2879f95f15d5930d7f828783fddedec4023be20e
parentHooray for UTF-8 (diff)
downloadprintergui-e4c69f10c8729812176ef49171e79e9dd8cd983f.tar.gz
printergui-e4c69f10c8729812176ef49171e79e9dd8cd983f.tar.xz
printergui-e4c69f10c8729812176ef49171e79e9dd8cd983f.zip
Fix reading from stdin. fread sucks.
-rw-r--r--src/pwgui/main.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/pwgui/main.cpp b/src/pwgui/main.cpp
index 6e12eee..fa131b1 100644
--- a/src/pwgui/main.cpp
+++ b/src/pwgui/main.cpp
@@ -98,17 +98,25 @@ int main(int argc, char *argv[])
return CUPS_BACKEND_FAILED;
}
char buffer[BUFLEN];
- size_t bytes, ret;
- while (!feof(stdin)) {
- bytes = fread(buffer, BUFLEN, 1, stdin);
+ int bytes, ret;
+ int total = 0;
+ for (;;) {
+ bytes = read(STDIN_FILENO, buffer, BUFLEN);
if (bytes == 0) break;
+ if (bytes < 0) {
+ fprintf(stderr, "ERROR: Could not read print job from STDIN.\n");
+ remove(tmpfile);
+ return CUPS_BACKEND_FAILED;
+ }
if ((ret = write(fh, buffer, bytes)) != bytes) {
fprintf(stderr, "ERROR: Could not write %d bytes to %s (wrote %d)\n", (int)bytes, tmpfile, (int)ret);
remove(tmpfile);
return CUPS_BACKEND_FAILED;
}
+ total += bytes;
}
close(fh);
+ fprintf(stderr, "ERROR: Read %d bytes from stdin.\n", total);
//
} else {
// File given, check if file exists
@@ -168,7 +176,7 @@ int main(int argc, char *argv[])
status = run_backend(backend, device, argv[1], creds, argv[3], argv[4], argv[5], tmpfile, pass);
} while (status != CUPS_BACKEND_OK);
remove(tmpfile);
- fprintf(stderr, "Job submitted.\n");
+ fprintf(stderr, "ERROR: Job submitted.\n");
return CUPS_BACKEND_OK;
}