From owner-svn-src-user@FreeBSD.ORG Mon Aug 29 19:11:46 2011 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EDEC71065672; Mon, 29 Aug 2011 19:11:45 +0000 (UTC) (envelope-from gabor@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id DEB0B8FC08; Mon, 29 Aug 2011 19:11:45 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7TJBjs3009013; Mon, 29 Aug 2011 19:11:45 GMT (envelope-from gabor@svn.freebsd.org) Received: (from gabor@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7TJBjpx009011; Mon, 29 Aug 2011 19:11:45 GMT (envelope-from gabor@svn.freebsd.org) Message-Id: <201108291911.p7TJBjpx009011@svn.freebsd.org> From: Gabor Kovesdan Date: Mon, 29 Aug 2011 19:11:45 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225248 - user/gabor/grep/trunk X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Aug 2011 19:11:46 -0000 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