Skip to content
8 changes: 7 additions & 1 deletion cthreads.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <string.h> /* strerror(), strlen() */
#endif

#include <time.h>

#include "cthreads.h"

#ifdef _WIN32
Expand Down Expand Up @@ -463,7 +465,11 @@ int cthreads_cond_timedwait(struct cthreads_cond *cond, struct cthreads_mutex *m
}
#endif

size_t cthreads_error_string(int error_code, char *buf, size_t length) {
#if CTHREADS_STATIC_VLA == 1
size_t cthreads_error_string(int error_code, size_t length, char buf[static length]) {
#else
size_t cthreads_error_string(int error_code, size_t length, char *buf) {
#endif
#ifdef CTHREADS_DEBUG
puts("cthreads_error_string");
#endif
Expand Down
17 changes: 14 additions & 3 deletions cthreads.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,17 +446,28 @@ int cthreads_cond_timedwait(struct cthreads_cond *cond, struct cthreads_mutex *m
int cthreads_error_code(void);
#endif

#if ((defined(__GNUC__) || defined(__clang__) || defined(__TINYC__)) && __STDC__ == 1 && __STDC_VERSION__ >= 199901L) \
|| (__STDC__ == 0 && __STDC_VERSION__ >= 201112L)
#define CTHREADS_STATIC_VLA 1
#else
#define CTHREADS_STATIC_VLA 0
#endif

/**
* Obtains the error code and writes at most `length`
* bytes of the associated message to `buf`.
*
* @param error_code Platform-specific error code. (See: `cthreads_error_code()`)
* @param buf Buffer of `length` bytes and target of the error message
* @param error_code Platform-specific error code. @see \ref cthreads_error_code()
* @param length Length of the provided buffer
* @param buf Buffer of at least `length` bytes and target of the error message
*
* @return Number of bytes required to print the message + NULL-terminator
*/
size_t cthreads_error_string(int error_code, char *buf, size_t length);
#if CTHREADS_STATIC_VLA == 1
size_t cthreads_error_string(int error_code, size_t length, char buf[static length]);
#else
size_t cthreads_error_string(int error_code, size_t length, char* buf);
#endif

#ifdef CTHREADS_SEMAPHORE
/**
Expand Down