shithub: neatpost

Download patch

ref: a11fb8c888ac092c545f11f38c3da431ffc7a783
parent: f2bd9dc3bbe0453855d163df286e5a5d93f6ec18
author: Ali Gholami Rudi <ali@rudi.ir>
date: Sat Sep 7 19:02:43 EDT 2013

post: exit if output device cannot be opened

--- a/dev.c
+++ b/dev.c
@@ -50,6 +50,8 @@
 	strcpy(dev_dev, dev);
 	sprintf(path, "%s/dev%s/DESC", dir, dev);
 	desc = fopen(path, "r");
+	if (!desc)
+		return 1;
 	while (fscanf(desc, "%s", tok) == 1) {
 		if (tok[0] == '#') {
 			skipline(desc);
--- a/post.c
+++ b/post.c
@@ -7,6 +7,7 @@
  */
 #include <ctype.h>
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include "post.h"
 
@@ -228,7 +229,10 @@
 		outmnt(pos);
 		break;
 	case 'i':
-		dev_open(devpath, devname);
+		if (dev_open(devpath, devname)) {
+			fprintf(stderr, "neatpost: cannot open device %s\n", devname);
+			exit(1);
+		}
 		ps_header();
 		break;
 	case 'T':
@@ -309,7 +313,7 @@
 		nexteol();
 		break;
 	default:
-		fprintf(stderr, "unknown command: %c\n", c);
+		fprintf(stderr, "neatpost: unknown command %c\n", c);
 	}
 }