Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Aug 2011 19:11:45 +0000 (UTC)
From:      Gabor Kovesdan <gabor@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r225248 - user/gabor/grep/trunk
Message-ID:  <201108291911.p7TJBjpx009011@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gabor
Date: Mon Aug 29 19:11:45 2011
New Revision: 225248
URL: http://svn.freebsd.org/changeset/base/225248

Log:
  - Merge a static function into the caller since it is not called
    form elsewhere

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

Modified: user/gabor/grep/trunk/file.c
==============================================================================
--- user/gabor/grep/trunk/file.c	Mon Aug 29 16:24:58 2011	(r225247)
+++ user/gabor/grep/trunk/file.c	Mon Aug 29 19:11:45 2011	(r225248)
@@ -186,56 +186,49 @@ error:
 	return (NULL);
 }
 
-static inline struct file *
-grep_file_init(struct file *f)
+/*
+ * Opens a file for processing.
+ */
+struct file *
+grep_open(const char *path)
 {
+	struct file *f;
+
+	f = grep_malloc(sizeof *f);
+	memset(f, 0, sizeof *f);
+	if (path == NULL) {
+		/* Processing stdin implies --line-buffered. */
+		lbflag = true;
+		f->fd = STDIN_FILENO;
+	} else if ((f->fd = open(path, O_RDONLY)) == -1)
+		goto error1;
 
 	if (filebehave == FILE_GZIP &&
 	    (gzbufdesc = gzdopen(f->fd, "r")) == NULL)
-		goto error;
+		goto error2;
 
 	if (filebehave == FILE_BZIP &&
 	    (bzbufdesc = BZ2_bzdopen(f->fd, "r")) == NULL)
-		goto error;
+		goto error2;
 
 	/* Fill read buffer, also catches errors early */
 	if (grep_refill(f) != 0)
-		goto error;
+		goto error2;
 
 	/* Check for binary stuff, if necessary */
 	if (binbehave != BINFILE_TEXT && memchr(bufpos, '\0', bufrem) != NULL)
-		f->binary = true;
+	f->binary = true;
 
 	return (f);
-error:
+
+error2:
 	close(f->fd);
+error1:
 	free(f);
 	return (NULL);
 }
 
 /*
- * Opens a file for processing.
- */
-struct file *
-grep_open(const char *path)
-{
-	struct file *f;
-
-	f = grep_malloc(sizeof *f);
-	memset(f, 0, sizeof *f);
-	if (path == NULL) {
-		/* Processing stdin implies --line-buffered. */
-		lbflag = true;
-		f->fd = STDIN_FILENO;
-	} else if ((f->fd = open(path, O_RDONLY)) == -1) {
-		free(f);
-		return (NULL);
-	}
-
-	return (grep_file_init(f));
-}
-
-/*
  * Closes a file.
  */
 void



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