[PATCH:libX11 2/2] Xrm.c: ReadInFile: refactor fstat error handling

Alan Coopersmith alan.coopersmith at oracle.com
Wed Feb 2 10:18:44 PST 2011


We can simplify the fstat failure case now that the GetFileSize macro
has been expanded inline.

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 src/Xrm.c |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/src/Xrm.c b/src/Xrm.c
index 4337534..49fc258 100644
--- a/src/Xrm.c
+++ b/src/Xrm.c
@@ -1595,18 +1595,13 @@ ReadInFile(_Xconst char *filename)
      */
     {
 	struct stat status_buffer;
-	if ( (fstat((fd), &status_buffer)) == -1 )
-	    size = -1;
-	else
+	if ( (fstat((fd), &status_buffer)) == -1 ) {
+	    close (fd);
+	    return (char *)NULL;
+	} else
 	    size = status_buffer.st_size;
     }
 
-    /* There might have been a problem trying to stat a file */
-    if (size == -1) {
-	close (fd);
-	return (char *)NULL;
-    }
-
     if (!(filebuf = Xmalloc(size + 1))) { /* leave room for '\0' */
 	close(fd);
 	return (char *)NULL;
-- 
1.7.3.2



More information about the xorg-devel mailing list