svn commit: r225248 - user/gabor/grep/trunk
Gabor Kovesdan
gabor at FreeBSD.org
Mon Aug 29 19:11:46 UTC 2011
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
More information about the svn-src-user
mailing list