Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/v1.x' into v1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Feb 26, 2025
2 parents 366eb28 + feddddb commit 6697062
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 151 deletions.
6 changes: 6 additions & 0 deletions docs/src/fs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,12 @@ API
Equivalent to :man:`utime(2)`, :man:`futimes(3)` and :man:`lutimes(3)` respectively.
Passing `UV_FS_UTIME_NOW` as the atime or mtime sets the timestamp to the
current time.
Passing `UV_FS_UTIME_OMIT` as the atime or mtime leaves the timestamp
untouched.
.. note::
z/OS: `uv_fs_lutime()` is not implemented for z/OS. It can still be called but will return
``UV_ENOSYS``.
Expand Down
3 changes: 3 additions & 0 deletions docs/src/threading.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,17 @@ Threads
.. versionadded:: 1.50.0
.. c:function:: int uv_thread_setpriority(uv_thread_t tid, int priority)
If the function succeeds, the return value is 0.
If the function fails, the return value is less than zero.
Sets the scheduling priority of the thread specified by tid. It requires elevated
privilege to set specific priorities on some platforms.
The priority can be set to the following constants. UV_THREAD_PRIORITY_HIGHEST,
UV_THREAD_PRIORITY_ABOVE_NORMAL, UV_THREAD_PRIORITY_NORMAL,
UV_THREAD_PRIORITY_BELOW_NORMAL, UV_THREAD_PRIORITY_LOWEST.
.. c:function:: int uv_thread_getpriority(uv_thread_t tid, int* priority)
If the function succeeds, the return value is 0.
If the function fails, the return value is less than zero.
Retrieves the scheduling priority of the thread specified by tid. The value in the
Expand Down
9 changes: 7 additions & 2 deletions docs/src/tty.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@ Data types
typedef enum {
/* Initial/normal terminal mode */
UV_TTY_MODE_NORMAL,
/* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
/*
* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled).
* May become equivalent to UV_TTY_MODE_RAW_VT in future libuv versions.
*/
UV_TTY_MODE_RAW,
/* Binary-safe I/O mode for IPC (Unix-only) */
UV_TTY_MODE_IO
UV_TTY_MODE_IO,
/* Raw input mode. On Windows ENABLE_VIRTUAL_TERMINAL_INPUT is also set. */
UV_TTY_MODE_RAW_VT
} uv_tty_mode_t;

.. c:enum:: uv_tty_vtermstate_t
Expand Down
12 changes: 10 additions & 2 deletions include/uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ extern "C" {
#include <stddef.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>

/* Internal type, do not use. */
struct uv__queue {
Expand Down Expand Up @@ -805,10 +806,15 @@ struct uv_tty_s {
typedef enum {
/* Initial/normal terminal mode */
UV_TTY_MODE_NORMAL,
/* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled) */
/*
* Raw input mode (On Windows, ENABLE_WINDOW_INPUT is also enabled).
* May become equivalent to UV_TTY_MODE_RAW_VT in future libuv versions.
*/
UV_TTY_MODE_RAW,
/* Binary-safe I/O mode for IPC (Unix-only) */
UV_TTY_MODE_IO
UV_TTY_MODE_IO,
/* Raw input mode. On Windows ENABLE_VIRTUAL_TERMINAL_INPUT is also set. */
UV_TTY_MODE_RAW_VT
} uv_tty_mode_t;

typedef enum {
Expand Down Expand Up @@ -1585,6 +1591,8 @@ UV_EXTERN int uv_fs_chmod(uv_loop_t* loop,
const char* path,
int mode,
uv_fs_cb cb);
#define UV_FS_UTIME_NOW (INFINITY)
#define UV_FS_UTIME_OMIT (NAN)
UV_EXTERN int uv_fs_utime(uv_loop_t* loop,
uv_fs_t* req,
const char* path,
Expand Down
7 changes: 5 additions & 2 deletions include/uv/win.h
Original file line number Diff line number Diff line change
Expand Up @@ -499,8 +499,11 @@ typedef struct {
union { \
struct { \
/* Used for readable TTY handles */ \
/* TODO: remove me in v2.x. */ \
HANDLE unused_; \
union { \
/* TODO: remove me in v2.x. */ \
HANDLE unused_; \
int mode; \
} mode; \
uv_buf_t read_line_buffer; \
HANDLE read_raw_wait; \
/* Fields used for translating win keystrokes into vt100 characters */ \
Expand Down
2 changes: 2 additions & 0 deletions src/unix/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1078,6 +1078,8 @@ int uv_getrusage_thread(uv_rusage_t* rusage) {

return 0;

#elif defined(RUSAGE_LWP)
return uv__getrusage(RUSAGE_LWP, rusage);
#elif defined(RUSAGE_THREAD)
return uv__getrusage(RUSAGE_THREAD, rusage);
#endif /* defined(__APPLE__) */
Expand Down
99 changes: 43 additions & 56 deletions src/unix/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,23 @@ static ssize_t uv__fs_fdatasync(uv_fs_t* req) {
}


UV_UNUSED(static struct timespec uv__fs_to_timespec(double time)) {
#if defined(__APPLE__) \
|| defined(_AIX71) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
|| defined(__HAIKU__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
|| defined(__sun)
static struct timespec uv__fs_to_timespec(double time) {
struct timespec ts;

if (uv__isinf(time))
return (struct timespec){UTIME_NOW, UTIME_NOW};
if (uv__isnan(time))
return (struct timespec){UTIME_OMIT, UTIME_OMIT};

ts.tv_sec = time;
ts.tv_nsec = (time - ts.tv_sec) * 1e9;

Expand All @@ -221,41 +236,23 @@ UV_UNUSED(static struct timespec uv__fs_to_timespec(double time)) {
}
return ts;
}
#endif

UV_UNUSED(static struct timeval uv__fs_to_timeval(double time)) {
struct timeval tv;
tv.tv_sec = time;
tv.tv_usec = (time - tv.tv_sec) * 1e6;
if (tv.tv_usec < 0) {
tv.tv_usec += 1e6;
tv.tv_sec -= 1;
}
return tv;
}

static ssize_t uv__fs_futime(uv_fs_t* req) {
#if defined(__linux__) \
#if defined(__APPLE__) \
|| defined(_AIX71) \
|| defined(__HAIKU__) \
|| defined(__GNU__)
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
return futimens(req->file, ts);
#elif defined(__APPLE__) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
|| defined(__HAIKU__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
|| defined(__sun)
struct timeval tv[2];
tv[0] = uv__fs_to_timeval(req->atime);
tv[1] = uv__fs_to_timeval(req->mtime);
# if defined(__sun)
return futimesat(req->file, NULL, tv);
# else
return futimes(req->file, tv);
# endif
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
return futimens(req->file, ts);
#elif defined(__MVS__)
attrib_t atr;
memset(&atr, 0, sizeof(atr));
Expand Down Expand Up @@ -1142,25 +1139,20 @@ static ssize_t uv__fs_sendfile(uv_fs_t* req) {


static ssize_t uv__fs_utime(uv_fs_t* req) {
#if defined(__linux__) \
|| defined(_AIX71) \
|| defined(__sun) \
|| defined(__HAIKU__)
#if defined(__APPLE__) \
|| defined(_AIX71) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
|| defined(__HAIKU__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
|| defined(__sun)
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
return utimensat(AT_FDCWD, req->path, ts, 0);
#elif defined(__APPLE__) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__)
struct timeval tv[2];
tv[0] = uv__fs_to_timeval(req->atime);
tv[1] = uv__fs_to_timeval(req->mtime);
return utimes(req->path, tv);
#elif defined(_AIX) \
&& !defined(_AIX71)
#elif defined(_AIX) && !defined(_AIX71)
struct utimbuf buf;
buf.actime = req->atime;
buf.modtime = req->mtime;
Expand All @@ -1181,24 +1173,19 @@ static ssize_t uv__fs_utime(uv_fs_t* req) {


static ssize_t uv__fs_lutime(uv_fs_t* req) {
#if defined(__linux__) || \
defined(_AIX71) || \
defined(__sun) || \
defined(__HAIKU__) || \
defined(__GNU__) || \
defined(__OpenBSD__)
#if defined(__APPLE__) \
|| defined(_AIX71) \
|| defined(__DragonFly__) \
|| defined(__FreeBSD__) \
|| defined(__HAIKU__) \
|| defined(__NetBSD__) \
|| defined(__OpenBSD__) \
|| defined(__linux__) \
|| defined(__sun)
struct timespec ts[2];
ts[0] = uv__fs_to_timespec(req->atime);
ts[1] = uv__fs_to_timespec(req->mtime);
return utimensat(AT_FDCWD, req->path, ts, AT_SYMLINK_NOFOLLOW);
#elif defined(__APPLE__) || \
defined(__DragonFly__) || \
defined(__FreeBSD__) || \
defined(__NetBSD__)
struct timeval tv[2];
tv[0] = uv__fs_to_timeval(req->atime);
tv[1] = uv__fs_to_timeval(req->mtime);
return lutimes(req->path, tv);
#else
errno = ENOSYS;
return -1;
Expand Down
4 changes: 2 additions & 2 deletions src/unix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ int uv_thread_setaffinity(uv_thread_t* tid,
if (cpumask[i])
CPU_SET(i, &cpuset);

#if defined(__ANDROID__)
#if defined(__ANDROID__) || defined(__OHOS__)
if (sched_setaffinity(pthread_gettid_np(*tid), sizeof(cpuset), &cpuset))
r = errno;
else
Expand Down Expand Up @@ -242,7 +242,7 @@ int uv_thread_getaffinity(uv_thread_t* tid,
return UV_EINVAL;

CPU_ZERO(&cpuset);
#if defined(__ANDROID__)
#if defined(__ANDROID__) || defined(__OHOS__)
if (sched_getaffinity(pthread_gettid_np(*tid), sizeof(cpuset), &cpuset))
r = errno;
else
Expand Down
7 changes: 7 additions & 0 deletions src/unix/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
int fd;
int rc;

if (uv__is_raw_tty_mode(mode)) {
/* There is only a single raw TTY mode on UNIX. */
mode = UV_TTY_MODE_RAW;
}

if (tty->mode == (int) mode)
return 0;

Expand Down Expand Up @@ -324,6 +329,8 @@ int uv_tty_set_mode(uv_tty_t* tty, uv_tty_mode_t mode) {
case UV_TTY_MODE_IO:
uv__tty_make_raw(&tmp);
break;
default:
UNREACHABLE();
}

/* Apply changes after draining */
Expand Down
25 changes: 24 additions & 1 deletion src/uv-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>

#include "uv.h"
#include "uv/tree.h"
Expand Down Expand Up @@ -125,7 +126,7 @@ enum {

/* Only used by uv_tty_t handles. */
UV_HANDLE_TTY_READABLE = 0x01000000,
UV_HANDLE_TTY_RAW = 0x02000000,
UV_HANDLE_UNUSED0 = 0x02000000,
UV_HANDLE_TTY_SAVED_POSITION = 0x04000000,
UV_HANDLE_TTY_SAVED_ATTRIBUTES = 0x08000000,

Expand All @@ -140,6 +141,10 @@ enum {
UV_HANDLE_REAP = 0x10000000
};

static inline int uv__is_raw_tty_mode(uv_tty_mode_t m) {
return m == UV_TTY_MODE_RAW || m == UV_TTY_MODE_RAW_VT;
}

int uv__loop_configure(uv_loop_t* loop, uv_loop_option option, va_list ap);

void uv__loop_close(uv_loop_t* loop);
Expand Down Expand Up @@ -448,4 +453,22 @@ struct uv__loop_internal_fields_s {
# define UV_PTHREAD_MAX_NAMELEN_NP 16
#endif

/* Open-coded so downstream users don't have to link libm. */
static inline int uv__isinf(double d) {
uint64_t v;

STATIC_ASSERT(sizeof(v) == sizeof(d));
memcpy(&v, &d, sizeof(v));
return (v << 1 >> 53) == 2047 && !(v << 12);
}

/* Open-coded so downstream users don't have to link libm. */
static inline int uv__isnan(double d) {
uint64_t v;

STATIC_ASSERT(sizeof(v) == sizeof(d));
memcpy(&v, &d, sizeof(v));
return (v << 1 >> 53) == 2047 && !!(v << 12);
}

#endif /* UV_COMMON_H_ */
25 changes: 20 additions & 5 deletions src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2580,14 +2580,29 @@ static void fs__fchmod(uv_fs_t* req) {


INLINE static int fs__utime_handle(HANDLE handle, double atime, double mtime) {
FILETIME filetime_a, filetime_m;
FILETIME filetime_as, *filetime_a = &filetime_as;
FILETIME filetime_ms, *filetime_m = &filetime_ms;
FILETIME now;

TIME_T_TO_FILETIME(atime, &filetime_a);
TIME_T_TO_FILETIME(mtime, &filetime_m);
if (uv__isinf(atime) || uv__isinf(mtime))
GetSystemTimeAsFileTime(&now);

if (!SetFileTime(handle, NULL, &filetime_a, &filetime_m)) {
if (uv__isinf(atime))
filetime_a = &now;
else if (uv__isnan(atime))
filetime_a = NULL;
else
TIME_T_TO_FILETIME(atime, filetime_a);

if (uv__isinf(mtime))
filetime_m = &now;
else if (uv__isnan(mtime))
filetime_m = NULL;
else
TIME_T_TO_FILETIME(mtime, filetime_m);

if (!SetFileTime(handle, NULL, filetime_a, filetime_m))
return -1;
}

return 0;
}
Expand Down
Loading

0 comments on commit 6697062

Please sign in to comment.