lib: posix: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type. MISRA-C rule 14.4 Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
This commit is contained in:
parent
6a4a86e413
commit
0c4bb833de
3 changed files with 25 additions and 23 deletions
|
@ -57,7 +57,7 @@ mqd_t mq_open(const char *name, int oflags, ...)
|
||||||
char *mq_desc_ptr, *mq_obj_ptr, *mq_buf_ptr, *mq_name_ptr;
|
char *mq_desc_ptr, *mq_obj_ptr, *mq_buf_ptr, *mq_name_ptr;
|
||||||
|
|
||||||
va_start(va, oflags);
|
va_start(va, oflags);
|
||||||
if (oflags & O_CREAT) {
|
if ((oflags & O_CREAT) != 0) {
|
||||||
mode = va_arg(va, mode_t);
|
mode = va_arg(va, mode_t);
|
||||||
attrs = va_arg(va, mq_attr*);
|
attrs = va_arg(va, mq_attr*);
|
||||||
}
|
}
|
||||||
|
@ -68,8 +68,8 @@ mqd_t mq_open(const char *name, int oflags, ...)
|
||||||
max_msgs = attrs->mq_maxmsg;
|
max_msgs = attrs->mq_maxmsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name == NULL || ((oflags & O_CREAT) && (msg_size <= 0 ||
|
if ((name == NULL) || ((oflags & O_CREAT) != 0 && (msg_size <= 0 ||
|
||||||
max_msgs <= 0))) {
|
max_msgs <= 0))) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return (mqd_t)mqd;
|
return (mqd_t)mqd;
|
||||||
}
|
}
|
||||||
|
@ -84,13 +84,14 @@ mqd_t mq_open(const char *name, int oflags, ...)
|
||||||
msg_queue = find_in_list(name);
|
msg_queue = find_in_list(name);
|
||||||
k_sem_give(&mq_sem);
|
k_sem_give(&mq_sem);
|
||||||
|
|
||||||
if ((msg_queue != NULL) && (oflags & O_CREAT) && (oflags & O_EXCL)) {
|
if ((msg_queue != NULL) && (oflags & O_CREAT) != 0 &&
|
||||||
|
(oflags & O_EXCL) != 0) {
|
||||||
/* Message queue has alreadey been opened and O_EXCL is set */
|
/* Message queue has alreadey been opened and O_EXCL is set */
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
return (mqd_t)mqd;
|
return (mqd_t)mqd;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (msg_queue == NULL && !(oflags & O_CREAT)) {
|
if ((msg_queue == NULL) && (oflags & O_CREAT) == 0) {
|
||||||
errno = ENOENT;
|
errno = ENOENT;
|
||||||
return (mqd_t)mqd;
|
return (mqd_t)mqd;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +158,7 @@ mqd_t mq_open(const char *name, int oflags, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
msg_queue_desc->mqueue = msg_queue;
|
msg_queue_desc->mqueue = msg_queue;
|
||||||
msg_queue_desc->flags = (oflags & O_NONBLOCK) ? O_NONBLOCK : 0;
|
msg_queue_desc->flags = (oflags & O_NONBLOCK) != 0 ? O_NONBLOCK : 0;
|
||||||
return (mqd_t)msg_queue_desc;
|
return (mqd_t)msg_queue_desc;
|
||||||
|
|
||||||
free_mq_buffer:
|
free_mq_buffer:
|
||||||
|
@ -374,7 +375,7 @@ static s32_t send_message(mqueue_desc *mqd, const char *msg_ptr, size_t msg_len,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mqd->flags & O_NONBLOCK) {
|
if ((mqd->flags & O_NONBLOCK) != 0) {
|
||||||
timeout = K_NO_WAIT;
|
timeout = K_NO_WAIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,7 +407,7 @@ static s32_t receive_message(mqueue_desc *mqd, char *msg_ptr, size_t msg_len,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mqd->flags & O_NONBLOCK) {
|
if ((mqd->flags & O_NONBLOCK) != 0) {
|
||||||
timeout = K_NO_WAIT;
|
timeout = K_NO_WAIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,7 +86,7 @@ int pthread_attr_setschedparam(pthread_attr_t *attr,
|
||||||
{
|
{
|
||||||
int priority = schedparam->priority;
|
int priority = schedparam->priority;
|
||||||
|
|
||||||
if (!attr || !attr->initialized ||
|
if ((attr == NULL) || (attr->initialized == 0) ||
|
||||||
(is_posix_prio_valid(priority, attr->schedpolicy) == false)) {
|
(is_posix_prio_valid(priority, attr->schedpolicy) == false)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -140,7 +140,8 @@ int pthread_create(pthread_t *newthread, const pthread_attr_t *attr,
|
||||||
* pointer and stack size. So even though POSIX 1003.1 spec accepts
|
* pointer and stack size. So even though POSIX 1003.1 spec accepts
|
||||||
* attrib as NULL but zephyr needs it initialized with valid stack.
|
* attrib as NULL but zephyr needs it initialized with valid stack.
|
||||||
*/
|
*/
|
||||||
if (!attr || !attr->initialized || !attr->stack || !attr->stacksize) {
|
if ((attr == NULL) || (attr->initialized == 0)
|
||||||
|
|| (attr->stack == NULL) || (attr->stacksize == 0)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +217,7 @@ int pthread_cancel(pthread_t pthread)
|
||||||
struct posix_thread *thread = (struct posix_thread *) pthread;
|
struct posix_thread *thread = (struct posix_thread *) pthread;
|
||||||
int cancel_state;
|
int cancel_state;
|
||||||
|
|
||||||
if (thread == NULL || thread->state == PTHREAD_TERMINATED) {
|
if ((thread == NULL) || (thread->state == PTHREAD_TERMINATED)) {
|
||||||
return ESRCH;
|
return ESRCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +300,7 @@ int pthread_getschedparam(pthread_t pthread, int *policy,
|
||||||
struct posix_thread *thread = (struct posix_thread *) pthread;
|
struct posix_thread *thread = (struct posix_thread *) pthread;
|
||||||
u32_t priority;
|
u32_t priority;
|
||||||
|
|
||||||
if (thread == NULL || thread->state == PTHREAD_TERMINATED) {
|
if ((thread == NULL) || (thread->state == PTHREAD_TERMINATED)) {
|
||||||
return ESRCH;
|
return ESRCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -398,7 +399,7 @@ int pthread_join(pthread_t thread, void **status)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pthread->state == PTHREAD_EXITED) {
|
if (pthread->state == PTHREAD_EXITED) {
|
||||||
if (status) {
|
if (status != NULL) {
|
||||||
*status = pthread->retval;
|
*status = pthread->retval;
|
||||||
}
|
}
|
||||||
} else if (pthread->state == PTHREAD_DETACHED) {
|
} else if (pthread->state == PTHREAD_DETACHED) {
|
||||||
|
@ -460,7 +461,7 @@ int pthread_detach(pthread_t thread)
|
||||||
*/
|
*/
|
||||||
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized) {
|
if ((attr == NULL) || (attr->initialized == 0)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -475,7 +476,7 @@ int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate)
|
||||||
*/
|
*/
|
||||||
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized ||
|
if ((attr == NULL) || (attr->initialized == 0) ||
|
||||||
(detachstate != PTHREAD_CREATE_DETACHED &&
|
(detachstate != PTHREAD_CREATE_DETACHED &&
|
||||||
detachstate != PTHREAD_CREATE_JOINABLE)) {
|
detachstate != PTHREAD_CREATE_JOINABLE)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
@ -493,7 +494,7 @@ int pthread_attr_setdetachstate(pthread_attr_t *attr, int detachstate)
|
||||||
*/
|
*/
|
||||||
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
|
int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized) {
|
if ((attr == NULL) || (attr->initialized == 0)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -509,7 +510,7 @@ int pthread_attr_getschedpolicy(const pthread_attr_t *attr, int *policy)
|
||||||
*/
|
*/
|
||||||
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized ||
|
if ((attr == NULL) || (attr->initialized == 0) ||
|
||||||
(policy != SCHED_RR && policy != SCHED_FIFO)) {
|
(policy != SCHED_RR && policy != SCHED_FIFO)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -525,7 +526,7 @@ int pthread_attr_setschedpolicy(pthread_attr_t *attr, int policy)
|
||||||
*/
|
*/
|
||||||
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized) {
|
if ((attr == NULL) || (attr->initialized == 0)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +543,7 @@ int pthread_attr_getstacksize(const pthread_attr_t *attr, size_t *stacksize)
|
||||||
int pthread_attr_getstack(const pthread_attr_t *attr,
|
int pthread_attr_getstack(const pthread_attr_t *attr,
|
||||||
void **stackaddr, size_t *stacksize)
|
void **stackaddr, size_t *stacksize)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized) {
|
if ((attr == NULL) || (attr->initialized == 0)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -559,7 +560,7 @@ int pthread_attr_getstack(const pthread_attr_t *attr,
|
||||||
int pthread_attr_getschedparam(const pthread_attr_t *attr,
|
int pthread_attr_getschedparam(const pthread_attr_t *attr,
|
||||||
struct sched_param *schedparam)
|
struct sched_param *schedparam)
|
||||||
{
|
{
|
||||||
if (!attr || !attr->initialized) {
|
if ((attr == NULL) || (attr->initialized == 0)) {
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,7 +575,7 @@ int pthread_attr_getschedparam(const pthread_attr_t *attr,
|
||||||
*/
|
*/
|
||||||
int pthread_attr_destroy(pthread_attr_t *attr)
|
int pthread_attr_destroy(pthread_attr_t *attr)
|
||||||
{
|
{
|
||||||
if (attr && attr->initialized) {
|
if ((attr != NULL) && (attr->initialized != 0)) {
|
||||||
attr->initialized = false;
|
attr->initialized = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,7 +138,7 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save time to expire and old reload value. */
|
/* Save time to expire and old reload value. */
|
||||||
if (ovalue) {
|
if (ovalue != NULL) {
|
||||||
timer_gettime(timerid, ovalue);
|
timer_gettime(timerid, ovalue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,7 +159,7 @@ int timer_settime(timer_t timerid, int flags, const struct itimerspec *value,
|
||||||
|
|
||||||
/* Calcaulte timer duration */
|
/* Calcaulte timer duration */
|
||||||
duration = _ts_to_ms(&(value->it_value));
|
duration = _ts_to_ms(&(value->it_value));
|
||||||
if (flags & TIMER_ABSTIME) {
|
if ((flags & TIMER_ABSTIME) != 0) {
|
||||||
current = k_timer_remaining_get(&timer->ztimer);
|
current = k_timer_remaining_get(&timer->ztimer);
|
||||||
|
|
||||||
if (current >= duration) {
|
if (current >= duration) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue