From c2458e4e0e8e90638b755221af3f1d652b2facf1 Mon Sep 17 00:00:00 2001
From: Ian Chamberlain <ian.h.chamberlain@gmail.com>
Date: Mon, 11 Apr 2022 22:49:21 -0400
Subject: [PATCH] Add pthread_condattr functions

Best I can tell, there is no way to control the clock behavior of
condvars using libctru - so, simply fail if the user tries to set
anything other than CLOCK_REALTIME.
---
 src/condvar.rs | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/src/condvar.rs b/src/condvar.rs
index 92769c0..acf8b02 100644
--- a/src/condvar.rs
+++ b/src/condvar.rs
@@ -82,3 +82,38 @@ pub unsafe extern "C" fn pthread_cond_timedwait(
 pub unsafe extern "C" fn pthread_cond_destroy(_cond: *mut libc::pthread_cond_t) -> libc::c_int {
     0
 }
+
+#[no_mangle]
+pub extern "C" fn pthread_condattr_init(_attr: *const libc::pthread_condattr_t) -> libc::c_int {
+    0
+}
+
+#[no_mangle]
+pub extern "C" fn pthread_condattr_destroy(_attr: *const libc::pthread_condattr_t) -> libc::c_int {
+    0
+}
+
+#[no_mangle]
+pub extern "C" fn pthread_condattr_getclock(
+    _attr: *const libc::pthread_condattr_t,
+    clock_id: *mut libc::clockid_t,
+) -> libc::c_int {
+    unsafe {
+        *clock_id = libc::CLOCK_REALTIME;
+    }
+
+    0
+}
+
+#[no_mangle]
+pub extern "C" fn pthread_condattr_setclock(
+    _attr: *mut libc::pthread_condattr_t,
+    clock_id: libc::clockid_t,
+) -> libc::c_int {
+    // only one clock is supported, so all other options are considered an error
+    if clock_id == libc::CLOCK_REALTIME {
+        0
+    } else {
+        libc::EINVAL
+    }
+}