[PATCH 05/11] Simplify Error() - don't allocate temporary copy of error string

Alan Coopersmith alan.coopersmith at oracle.com
Mon Nov 29 20:57:42 PST 2010


Doesn't seem to be any reason to just not pass the error string
as another argument directly to LogVWrite()

Signed-off-by: Alan Coopersmith <alan.coopersmith at oracle.com>
---
 include/os.h |    2 +-
 os/log.c     |   19 ++++++-------------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/include/os.h b/include/os.h
index e882a0c..566514d 100644
--- a/include/os.h
+++ b/include/os.h
@@ -526,7 +526,7 @@ extern _X_EXPORT void FatalError(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2) _X
 
 extern _X_EXPORT void VErrorF(const char *f, va_list args);
 extern _X_EXPORT void ErrorF(const char *f, ...) _X_ATTRIBUTE_PRINTF(1,2);
-extern _X_EXPORT void Error(char *str);
+extern _X_EXPORT void Error(const char *str);
 extern _X_EXPORT void LogPrintMarkers(void);
 
 extern _X_EXPORT void xorg_backtrace(void);
diff --git a/os/log.c b/os/log.c
index d77708e..fdcf91c 100644
--- a/os/log.c
+++ b/os/log.c
@@ -571,21 +571,14 @@ ErrorF(const char * f, ...)
 /* A perror() workalike. */
 
 void
-Error(char *str)
+Error(const char *str)
 {
-    char *err = NULL;
-    int saveErrno = errno;
-
-    if (str) {
-	err = malloc(strlen(strerror(saveErrno)) + strlen(str) + 2 + 1);
-	if (!err)
-	    return;
-	sprintf(err, "%s: ", str);
-	strcat(err, strerror(saveErrno));
+    const char *err = strerror(errno);
+
+    if (str)
+	LogWrite(-1, "%s: %s", str, err);
+    else
 	LogWrite(-1, "%s", err);
-	free(err);
-    } else
-	LogWrite(-1, "%s", strerror(saveErrno));
 }
 
 void
-- 
1.7.3.2



More information about the xorg-devel mailing list