svn commit: r225310 - user/gabor/grep/trunk

Gabor Kovesdan gabor at FreeBSD.org
Thu Sep 1 13:40:42 UTC 2011


Author: gabor
Date: Thu Sep  1 13:40:41 2011
New Revision: 225310
URL: http://svn.freebsd.org/changeset/base/225310

Log:
  - Restore proper err() call on non-existent file and use more concise code
  
  Submitted by:	jh

Modified:
  user/gabor/grep/trunk/grep.c

Modified: user/gabor/grep/trunk/grep.c
==============================================================================
--- user/gabor/grep/trunk/grep.c	Thu Sep  1 13:36:29 2011	(r225309)
+++ user/gabor/grep/trunk/grep.c	Thu Sep  1 13:40:41 2011	(r225310)
@@ -296,14 +296,12 @@ read_patterns(const char *fn)
 	size_t len;
 	int fd;
 
-	if ((fd = open(fn, O_RDONLY)) == -1)
-		return;
-	if ((fstat(fd, &st) == -1) || (S_ISDIR(st.st_mode))) {
+	if ((f = fopen(fn, "r")) == NULL)
+		err(2, "%s", fn);
+	if ((fstat(fileno(f), &st) == -1) || (S_ISDIR(st.st_mode))) {
 		close(fd);
 		return;
 	}
-	if ((f = fdopen(fd, "r")) == NULL)
-		err(2, "%s", fn);
         while ((line = fgetln(f, &len)) != NULL)
 		add_pattern(line, line[0] == '\n' ? 0 : len);
 	if (ferror(f))


More information about the svn-src-user mailing list