[libc-commits] [libc] [libc] Implement sleep and usleep for Linux (PR #205922)

Pavel Labath via libc-commits libc-commits at lists.llvm.org
Tue Jul 21 07:30:07 PDT 2026


================
@@ -0,0 +1,43 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Linux implementation of usleep.
+///
+//===----------------------------------------------------------------------===//
+
+#include "src/unistd/usleep.h"
+#include "hdr/errno_macros.h"
+#include "hdr/types/struct_timespec.h"
+#include "src/__support/OSUtil/linux/syscall_wrappers/nanosleep.h"
+#include "src/__support/common.h"
+#include "src/__support/libc_errno.h"
+#include "src/__support/macros/config.h"
+
+namespace LIBC_NAMESPACE_DECL {
+
+LLVM_LIBC_FUNCTION(int, usleep, (useconds_t usec)) {
+  // POSIX.1-2001 specifies that usleep should fail with EINVAL if the
----------------
labath wrote:

It says it *may fail* in that case. Neither glibc nor musl do that, and I'd be surprised if there weren't applications that depend on that. I think we shouldn't do that either. 

https://github.com/llvm/llvm-project/pull/205922


More information about the libc-commits mailing list