Logo

index : raylib-jai

---

  • summary
  • about
  • tree
  • log
  • branches
<< path: root/public/raylib-jai.git/html/Raylib/raylib/src/external/glfw/src/posix_poll.c blob: b53e36e80b779cfa2244a57e8970a64da9299238 [raw] [clear marker]

        
0//========================================================================
1// GLFW 3.4 POSIX - www.glfw.org
2//------------------------------------------------------------------------
3// Copyright (c) 2022 Camilla Löwy <elmindreda@glfw.org>
4//
5// This software is provided 'as-is', without any express or implied
6// warranty. In no event will the authors be held liable for any damages
7// arising from the use of this software.
8//
9// Permission is granted to anyone to use this software for any purpose,
10// including commercial applications, and to alter it and redistribute it
11// freely, subject to the following restrictions:
12//
13// 1. The origin of this software must not be misrepresented; you must not
14// claim that you wrote the original software. If you use this software
15// in a product, an acknowledgment in the product documentation would
16// be appreciated but is not required.
17//
18// 2. Altered source versions must be plainly marked as such, and must not
19// be misrepresented as being the original software.
20//
21// 3. This notice may not be removed or altered from any source
22// distribution.
23//
24//========================================================================
25
26#define _GNU_SOURCE
27
28#include "internal.h"
29
30#if defined(GLFW_BUILD_POSIX_POLL)
31
32#include <signal.h>
33#include <time.h>
34#include <errno.h>
35
36GLFWbool _glfwPollPOSIX(struct pollfd* fds, nfds_t count, double* timeout)
37{
38 for (;;)
39 {
40 if (timeout)
41 {
42 const uint64_t base = _glfwPlatformGetTimerValue();
43
44#if defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__CYGWIN__)
45 const time_t seconds = (time_t) *timeout;
46 const long nanoseconds = (long) ((*timeout - seconds) * 1e9);
47 const struct timespec ts = { seconds, nanoseconds };
48 const int result = ppoll(fds, count, &ts, NULL);
49#elif defined(__NetBSD__)
50 const time_t seconds = (time_t) *timeout;
51 const long nanoseconds = (long) ((*timeout - seconds) * 1e9);
52 const struct timespec ts = { seconds, nanoseconds };
53 const int result = pollts(fds, count, &ts, NULL);
54#else
55 const int milliseconds = (int) (*timeout * 1e3);
56 const int result = poll(fds, count, milliseconds);
57#endif
58 const int error = errno; // clock_gettime may overwrite our error
59
60 *timeout -= (_glfwPlatformGetTimerValue() - base) /
61 (double) _glfwPlatformGetTimerFrequency();
62
63 if (result > 0)
64 return GLFW_TRUE;
65 else if (result == -1 && error != EINTR && error != EAGAIN)
66 return GLFW_FALSE;
67 else if (*timeout <= 0.0)
68 return GLFW_FALSE;
69 }
70 else
71 {
72 const int result = poll(fds, count, -1);
73 if (result > 0)
74 return GLFW_TRUE;
75 else if (result == -1 && errno != EINTR && errno != EAGAIN)
76 return GLFW_FALSE;
77 }
78 }
79}
80
81#endif // GLFW_BUILD_POSIX_POLL
82
83
Copyright 2026  E766CB298A6D1E64 | Git-Thing heavily inspired by cgit