From: Kevin Day Date: Sat, 10 Apr 2021 15:32:15 +0000 (-0500) Subject: Update: handle POSIX compatibility automatically in f_thread_cancel_state_set(). X-Git-Tag: 0.5.3~63 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=3fa1aa7896bd2ad27745291063254050ef61ca03;p=fll Update: handle POSIX compatibility automatically in f_thread_cancel_state_set(). The POSIX standard does not explicitly define that this parameter can be NULL. To prevent any possible problems, allow NULL but when NULL is received, use a temporary variable in its place. --- diff --git a/level_0/f_thread/c/thread.c b/level_0/f_thread/c/thread.c index d0c410c..3b553cc 100644 --- a/level_0/f_thread/c/thread.c +++ b/level_0/f_thread/c/thread.c @@ -882,7 +882,17 @@ extern "C" { #ifndef _di_f_thread_cancel_state_set_ f_status_t f_thread_cancel_state_set(const int state, int *previous) { - const int error = pthread_setcancelstate(state, previous); + int error = 0; + + // POSIX doesn't allow this to be NULL, so make POSIX happy. + if (previous == 0) { + int ignore = 0; + + error = pthread_setcancelstate(state, &ignore); + } + else { + error = pthread_setcancelstate(state, previous); + } if (error) { if (error == EINVAL) return F_status_set_error(F_parameter); diff --git a/level_0/f_thread/c/thread.h b/level_0/f_thread/c/thread.h index 22ba1f6..65ba7ba 100644 --- a/level_0/f_thread/c/thread.h +++ b/level_0/f_thread/c/thread.h @@ -1183,7 +1183,6 @@ extern "C" { * @param previous * (optional) The previously assigned cancellation state. * Set to NULL to not use. - * (Note: Linux allows this to be optional/NULL but POSIX does not explicitly defined this and there may be portability issues.) * * @return * F_none on success.