libc: Change errno to set_errno and get_errno

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2023-10-18 09:17:28 +08:00
committed by Petro Karashchenko
parent f911d3a1c3
commit 7aad7eebff
11 changed files with 29 additions and 28 deletions
+2 -2
View File
@@ -96,8 +96,8 @@ ssize_t aio_return(FAR struct aiocb *aiocbp)
DEBUGASSERT(aiocbp); DEBUGASSERT(aiocbp);
if (aiocbp->aio_result < 0) if (aiocbp->aio_result < 0)
{ {
set_errno((int)-aiocbp->aio_result); set_errno(-aiocbp->aio_result);
return (ssize_t)ERROR; return ERROR;
} }
ret = aiocbp->aio_result; ret = aiocbp->aio_result;
+2 -2
View File
@@ -616,10 +616,10 @@ static ssize_t gdb_hex2bin(FAR void *buf, size_t buf_len,
}; };
out[pos / 2] = strtoul(ch, NULL, 16); /* Decode high nibble */ out[pos / 2] = strtoul(ch, NULL, 16); /* Decode high nibble */
if (out[pos / 2] == 0 && errno) if (out[pos / 2] == 0 && get_errno())
{ {
GDB_ASSERT(); GDB_ASSERT();
return -errno; /* Buffer contained junk. */ return -get_errno(); /* Buffer contained junk. */
} }
} }
+3 -3
View File
@@ -337,7 +337,7 @@ iconv_t iconv_open(FAR const char *to, FAR const char *from)
if ((t = find_charmap(to)) == -1 || (f = find_charmap(from)) == -1 || if ((t = find_charmap(to)) == -1 || (f = find_charmap(from)) == -1 ||
(g_charmaps[t] >= 0330)) (g_charmaps[t] >= 0330))
{ {
errno = EINVAL; set_errno(EINVAL);
return (iconv_t)-1; return (iconv_t)-1;
} }
@@ -354,7 +354,7 @@ iconv_t iconv_open(FAR const char *to, FAR const char *from)
scd = lib_malloc(sizeof(*scd)); scd = lib_malloc(sizeof(*scd));
if (scd == NULL) if (scd == NULL)
{ {
errno = ENOMEM; set_errno(ENOMEM);
return (iconv_t)-1; return (iconv_t)-1;
} }
@@ -1435,7 +1435,7 @@ starved:
err = EINVAL; err = EINVAL;
x = -1; x = -1;
end: end:
errno = err; set_errno(err);
return x; return x;
} }
+1 -1
View File
@@ -52,7 +52,7 @@ do \
void vwarn(FAR const char *fmt, va_list ap) void vwarn(FAR const char *fmt, va_list ap)
{ {
int error = errno; int error = get_errno();
struct va_format vaf; struct va_format vaf;
#ifdef va_copy #ifdef va_copy
+1 -1
View File
@@ -136,7 +136,7 @@ int android_fdsan_close_with_tag(int fd, uint64_t expected_tag)
* If we were expecting to close with a tag, abort on EBADF. * If we were expecting to close with a tag, abort on EBADF.
**************************************************************************/ **************************************************************************/
if (expected_tag && ret == -1 && errno == EBADF) if (expected_tag && ret == -1 && get_errno() == EBADF)
{ {
ferr("double-close of file descriptor %d detected\n", fd); ferr("double-close of file descriptor %d detected\n", fd);
PANIC(); PANIC();
+8 -7
View File
@@ -247,7 +247,8 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat,
if (!type && lstat(buf, &st)) if (!type && lstat(buf, &st))
{ {
if (errno != ENOENT && (errfunc(buf, errno) || (flags & GLOB_ERR))) if (get_errno() != ENOENT &&
(errfunc(buf, get_errno()) || (flags & GLOB_ERR) != 0))
{ {
return GLOB_ABORTED; return GLOB_ABORTED;
} }
@@ -287,7 +288,7 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat,
dir = opendir(pos ? buf : "."); dir = opendir(pos ? buf : ".");
if (!dir) if (!dir)
{ {
if (errfunc(buf, errno) || (flags & GLOB_ERR)) if (errfunc(buf, get_errno()) || (flags & GLOB_ERR) != 0)
{ {
return GLOB_ABORTED; return GLOB_ABORTED;
} }
@@ -295,8 +296,8 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat,
return 0; return 0;
} }
old_errno = errno; old_errno = get_errno();
while (errno = 0, de = readdir(dir)) while (get_errno() = 0, de = readdir(dir))
{ {
size_t l; size_t l;
int fnm_flags; int fnm_flags;
@@ -344,19 +345,19 @@ static int do_glob(FAR char *buf, size_t pos, int type, FAR char *pat,
} }
} }
readerr = errno; readerr = get_errno();
if (p2) if (p2)
{ {
*p2 = saved_sep; *p2 = saved_sep;
} }
closedir(dir); closedir(dir);
if (readerr && (errfunc(buf, errno) || (flags & GLOB_ERR))) if (readerr && (errfunc(buf, get_errno()) || (flags & GLOB_ERR) != 0))
{ {
return GLOB_ABORTED; return GLOB_ABORTED;
} }
errno = old_errno; set_errno(old_errno);
return 0; return 0;
} }
+3 -3
View File
@@ -55,9 +55,9 @@ int remove(FAR const char *path)
* more frequently the necessary action. * more frequently the necessary action.
*/ */
if (unlink(path) != 0 /* If it is indeed a directory... */ if (unlink(path) != 0 && /* If it is indeed a directory... */
&& (errno != EPERM /* ...try to remove it. */ (get_errno() != EPERM || /* ...try to remove it. */
|| rmdir(path) != 0)) rmdir(path) != 0))
{ {
/* Cannot remove the object for whatever reason. */ /* Cannot remove the object for whatever reason. */
+5 -5
View File
@@ -399,11 +399,11 @@ static long_double decfloat(FAR char *ptr, FAR char **endptr)
} }
else if (num_digit + num_decimal > ldbl_max_10_exp) else if (num_digit + num_decimal > ldbl_max_10_exp)
{ {
errno = ERANGE; set_errno(ERANGE);
} }
else if (num_digit + num_decimal < ldbl_min_10_exp) else if (num_digit + num_decimal < ldbl_min_10_exp)
{ {
errno = ERANGE; set_errno(ERANGE);
} }
if (k % 9) if (k % 9)
@@ -561,13 +561,13 @@ static long_double hexfloat(FAR char *ptr,
if (e2 > -emin) if (e2 > -emin)
{ {
errno = ERANGE; set_errno(ERANGE);
return ldbl_max * ldbl_max; return ldbl_max * ldbl_max;
} }
if (e2 < emin - 2 * ldbl_mant_dig) if (e2 < emin - 2 * ldbl_mant_dig)
{ {
errno = ERANGE; set_errno(ERANGE);
return ldbl_min * ldbl_min; return ldbl_min * ldbl_min;
} }
@@ -613,7 +613,7 @@ static long_double hexfloat(FAR char *ptr,
if (!y) if (!y)
{ {
errno = ERANGE; set_errno(ERANGE);
} }
return scalbnx(y, 2., e2); return scalbnx(y, 2., e2);
+1 -1
View File
@@ -2171,7 +2171,7 @@ static FAR struct tm *timesub(FAR const time_t *timep,
} }
else else
{ {
errno = EOVERFLOW; set_errno(EOVERFLOW);
return NULL; return NULL;
} }
+2 -2
View File
@@ -58,7 +58,7 @@ int getentropy(FAR void *buffer, size_t length)
if (length > 256) if (length > 256)
{ {
errno = EIO; set_errno(EIO);
return -1; return -1;
} }
@@ -67,7 +67,7 @@ int getentropy(FAR void *buffer, size_t length)
int ret = getrandom(pos, length, 0); int ret = getrandom(pos, length, 0);
if (ret < 0) if (ret < 0)
{ {
if (errno == EINTR) if (get_errno() == EINTR)
{ {
continue; continue;
} }
+1 -1
View File
@@ -40,7 +40,7 @@ static int uuid_getrandom(FAR void *buf, size_t size, int flags)
ssize_t ret = getrandom(tmp, size, flags); ssize_t ret = getrandom(tmp, size, flags);
if (ret < 0) if (ret < 0)
{ {
if (errno == EINTR) if (get_errno() == EINTR)
{ {
continue; continue;
} }