libc/pthread: Return EINVAL when input parameter incorrect at pthread_once

https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_once.html

If an implementation detects that the value specified by the once_control
argument to pthread_once() does not refer to a pthread_once_t object
initialized by PTHREAD_ONCE_INIT, it is recommended that the function
should fail and report an [EINVAL] error.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
This commit is contained in:
zhangyuan21
2023-05-05 00:51:07 +08:00
committed by Xiang Xiao
parent ff6ba02378
commit 962dfaf651
+5 -2
View File
@@ -25,6 +25,7 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include <stdbool.h> #include <stdbool.h>
#include <pthread.h> #include <pthread.h>
#include <sched.h> #include <sched.h>
@@ -65,8 +66,10 @@ int pthread_once(FAR pthread_once_t *once_control,
{ {
/* Sanity checks */ /* Sanity checks */
DEBUGASSERT(once_control != NULL); if (once_control == NULL || init_routine == NULL)
DEBUGASSERT(init_routine != NULL); {
return EINVAL;
}
/* Prohibit pre-emption while we test and set the once_control. */ /* Prohibit pre-emption while we test and set the once_control. */