Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Sep 2011 13:40:41 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r225310 - user/gabor/grep/trunk
Message-ID:  <201109011340.p81DefWk053617@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201109011340.p81DefWk053617>