From e4871c205ffa3b3e0ad3853ba8728d8eb85b6ad6 Mon Sep 17 00:00:00 2001 From: yuqing Date: Thu, 22 Dec 2016 15:09:39 +0800 Subject: [PATCH] refine getFileContent log info --- HISTORY | 3 ++- src/shared_func.c | 25 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index 622be89..2f7e9f8 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.33 2016-12-13 +Version 1.33 2016-12-22 * add function hash_get_prime_capacity + * refine getFileContent log info Version 1.32 2016-12-01 * downgrade log level from warning to debug diff --git a/src/shared_func.c b/src/shared_func.c index 763a572..add2ca7 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -960,13 +960,32 @@ int getFileContent(const char *filename, char **buff, int64_t *file_size) { int fd; + errno = 0; if (!isFile(filename)) { *buff = NULL; *file_size = 0; - logError("file: "__FILE__", line: %d, " - "%s is not a regular file", __LINE__, filename); - return EINVAL; + if (errno != 0) + { + if (errno == ENOENT) + { + logError("file: "__FILE__", line: %d, " + "file %s not exist", __LINE__, filename); + } + else + { + logError("file: "__FILE__", line: %d, " + "stat %s fail, errno: %d, error info: %s", + __LINE__, filename, errno, STRERROR(errno)); + } + return errno != 0 ? errno : ENOENT; + } + else + { + logError("file: "__FILE__", line: %d, " + "%s is not a regular file", __LINE__, filename); + return EINVAL; + } } fd = open(filename, O_RDONLY);