diff files.c @ 24:daa801fe719e

fix some bugs
author David A. Holland
date Mon, 20 Dec 2010 04:30:02 -0500
parents f6177d3ed5c2
children 8a955e3dda2c
line wrap: on
line diff
--- a/files.c	Mon Dec 20 04:21:51 2010 -0500
+++ b/files.c	Mon Dec 20 04:30:02 2010 -0500
@@ -307,12 +307,21 @@
 
 	assert(place != NULL);
 
-	fd = file_tryopen(name);
-	if (fd < 0) {
-		warn("%s", name);
-		die();
+	if (name == NULL) {
+		fd = STDIN_FILENO;
+		pf = place_addfile(place, "<standard-input>", false);
+	} else {
+		fd = file_tryopen(name);
+		if (fd < 0) {
+			warn("%s", name);
+			die();
+		}
+		pf = place_addfile(place, name, false);
 	}
-	pf = place_addfile(place, name, false);
+
 	file_read(pf, fd, name);
-	close(fd);
+
+	if (name != NULL) {
+		close(fd);
+	}
 }