From: Maciej Slodczyk Date: Tue, 3 Dec 2019 15:27:45 +0000 (+0100) Subject: fix file-helper return value on premature EOF X-Git-Tag: accepted/tizen/unified/20200108.131420~15 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=db1efcddd46a10944e3dd9aa062deb133802f6dc;p=platform%2Fcore%2Fsystem%2Fresourced.git fix file-helper return value on premature EOF Change-Id: I022f22746db4a9285f50208fe53ec7c49063cb0d Signed-off-by: Maciej Slodczyk --- diff --git a/src/common/file-helper.c b/src/common/file-helper.c index 15e3eac..e82a88b 100644 --- a/src/common/file-helper.c +++ b/src/common/file-helper.c @@ -46,8 +46,9 @@ int fwrite_str(const char *path, const char *str) ret_value_errno_msg_if(!f, -errno, "Fail to open file %s", path); + errno = 0; ret = fputs(str, f); - ret_value_errno_msg_if(ret == EOF, errno ? -errno : -EIO, + ret_value_errno_msg_if(ret == EOF, -(errno ?: EIO), "Fail to write file"); return RESOURCED_ERROR_NONE; @@ -115,9 +116,10 @@ int fread_nth_int(const char *path, size_t n, int32_t *number) ret_value_errno_msg_if(!f, -errno, "Fail to open %s file.", path); + errno = 0; for (i = 0; i <= n; i++) { ret = fscanf(f, "%d", &t); - ret_value_errno_msg_if(ret == EOF, -errno, + ret_value_errno_msg_if(ret == EOF, -(errno ?: ENOENT), "Fail to read file\n"); } @@ -136,9 +138,10 @@ int fread_nth_uint(const char *path, size_t n, u_int32_t *number) ret_value_errno_msg_if(!f, -errno, "Fail to open %s file.", path); + errno = 0; for (i = 0; i <= n; i++) { ret = fscanf(f, "%u", &t); - ret_value_errno_msg_if(ret == EOF, -errno, + ret_value_errno_msg_if(ret == EOF, -(errno ?: ENOENT), "Fail to read file\n"); } @@ -157,9 +160,10 @@ int fread_nth_ulong(const char *path, size_t n, unsigned long *number) ret_value_errno_msg_if(!f, -errno, "Fail to open %s file.", path); + errno = 0; for (i = 0; i <= n; i++) { ret = fscanf(f, "%lu", &t); - ret_value_errno_msg_if(ret == EOF, -errno, + ret_value_errno_msg_if(ret == EOF, -(errno ?: ENOENT), "Fail to read file\n"); }