1 2.. _misc: 3 4Miscellaneous utilities 5======================= 6 7This section contains miscellaneous functions that don't really belong in any 8other section. 9 10 11Data types 12---------- 13 14.. c:type:: uv_buf_t 15 16 Buffer data type. 17 18 .. c:member:: char* uv_buf_t.base 19 20 Pointer to the base of the buffer. 21 22 .. c:member:: size_t uv_buf_t.len 23 24 Total bytes in the buffer. 25 26 .. note:: 27 On Windows this field is ULONG. 28 29.. c:type:: void* (*uv_malloc_func)(size_t size) 30 31 Replacement function for :man:`malloc(3)`. 32 See :c:func:`uv_replace_allocator`. 33 34.. c:type:: void* (*uv_realloc_func)(void* ptr, size_t size) 35 36 Replacement function for :man:`realloc(3)`. 37 See :c:func:`uv_replace_allocator`. 38 39.. c:type:: void* (*uv_calloc_func)(size_t count, size_t size) 40 41 Replacement function for :man:`calloc(3)`. 42 See :c:func:`uv_replace_allocator`. 43 44.. c:type:: void (*uv_free_func)(void* ptr) 45 46 Replacement function for :man:`free(3)`. 47 See :c:func:`uv_replace_allocator`. 48 49.. c:type:: void (*uv_random_cb)(uv_random_t* req, int status, void* buf, size_t buflen) 50 51 Callback passed to :c:func:`uv_random`. `status` is non-zero in case of 52 error. The `buf` pointer is the same pointer that was passed to 53 :c:func:`uv_random`. 54 55.. c:type:: uv_file 56 57 Cross platform representation of a file handle. 58 59.. c:type:: uv_os_sock_t 60 61 Cross platform representation of a socket handle. 62 63.. c:type:: uv_os_fd_t 64 65 Abstract representation of a file descriptor. On Unix systems this is a 66 `typedef` of `int` and on Windows a `HANDLE`. 67 68.. c:type:: uv_pid_t 69 70 Cross platform representation of a `pid_t`. 71 72 .. versionadded:: 1.16.0 73 74.. c:type:: uv_timeval_t 75 76 Data type for storing times. 77 78 :: 79 80 typedef struct { 81 long tv_sec; 82 long tv_usec; 83 } uv_timeval_t; 84 85.. c:type:: uv_timeval64_t 86 87 Alternative data type for storing times. 88 89 :: 90 91 typedef struct { 92 int64_t tv_sec; 93 int32_t tv_usec; 94 } uv_timeval64_t; 95 96.. c:type:: uv_rusage_t 97 98 Data type for resource usage results. 99 100 :: 101 102 typedef struct { 103 uv_timeval_t ru_utime; /* user CPU time used */ 104 uv_timeval_t ru_stime; /* system CPU time used */ 105 uint64_t ru_maxrss; /* maximum resident set size */ 106 uint64_t ru_ixrss; /* integral shared memory size (X) */ 107 uint64_t ru_idrss; /* integral unshared data size (X) */ 108 uint64_t ru_isrss; /* integral unshared stack size (X) */ 109 uint64_t ru_minflt; /* page reclaims (soft page faults) (X) */ 110 uint64_t ru_majflt; /* page faults (hard page faults) */ 111 uint64_t ru_nswap; /* swaps (X) */ 112 uint64_t ru_inblock; /* block input operations */ 113 uint64_t ru_oublock; /* block output operations */ 114 uint64_t ru_msgsnd; /* IPC messages sent (X) */ 115 uint64_t ru_msgrcv; /* IPC messages received (X) */ 116 uint64_t ru_nsignals; /* signals received (X) */ 117 uint64_t ru_nvcsw; /* voluntary context switches (X) */ 118 uint64_t ru_nivcsw; /* involuntary context switches (X) */ 119 } uv_rusage_t; 120 121 Members marked with `(X)` are unsupported on Windows. 122 See :man:`getrusage(2)` for supported fields on Unix 123 124.. c:type:: uv_cpu_info_t 125 126 Data type for CPU information. 127 128 :: 129 130 typedef struct uv_cpu_info_s { 131 char* model; 132 int speed; 133 struct uv_cpu_times_s { 134 uint64_t user; 135 uint64_t nice; 136 uint64_t sys; 137 uint64_t idle; 138 uint64_t irq; 139 } cpu_times; 140 } uv_cpu_info_t; 141 142.. c:type:: uv_interface_address_t 143 144 Data type for interface addresses. 145 146 :: 147 148 typedef struct uv_interface_address_s { 149 char* name; 150 char phys_addr[6]; 151 int is_internal; 152 union { 153 struct sockaddr_in address4; 154 struct sockaddr_in6 address6; 155 } address; 156 union { 157 struct sockaddr_in netmask4; 158 struct sockaddr_in6 netmask6; 159 } netmask; 160 } uv_interface_address_t; 161 162.. c:type:: uv_passwd_t 163 164 Data type for password file information. 165 166 :: 167 168 typedef struct uv_passwd_s { 169 char* username; 170 long uid; 171 long gid; 172 char* shell; 173 char* homedir; 174 } uv_passwd_t; 175 176.. c:type:: uv_utsname_t 177 178 Data type for operating system name and version information. 179 180 :: 181 182 typedef struct uv_utsname_s { 183 char sysname[256]; 184 char release[256]; 185 char version[256]; 186 char machine[256]; 187 } uv_utsname_t; 188 189.. c:type:: uv_env_item_t 190 191 Data type for environment variable storage. 192 193 :: 194 195 typedef struct uv_env_item_s { 196 char* name; 197 char* value; 198 } uv_env_item_t; 199 200.. c:type:: uv_random_t 201 202 Random data request type. 203 204API 205--- 206 207.. c:function:: uv_handle_type uv_guess_handle(uv_file file) 208 209 Used to detect what type of stream should be used with a given file 210 descriptor. Usually this will be used during initialization to guess the 211 type of the stdio streams. 212 213 For :man:`isatty(3)` equivalent functionality use this function and test 214 for ``UV_TTY``. 215 216.. c:function:: int uv_replace_allocator(uv_malloc_func malloc_func, uv_realloc_func realloc_func, uv_calloc_func calloc_func, uv_free_func free_func) 217 218 .. versionadded:: 1.6.0 219 220 Override the use of the standard library's :man:`malloc(3)`, 221 :man:`calloc(3)`, :man:`realloc(3)`, :man:`free(3)`, memory allocation 222 functions. 223 224 This function must be called before any other libuv function is called or 225 after all resources have been freed and thus libuv doesn't reference 226 any allocated memory chunk. 227 228 On success, it returns 0, if any of the function pointers is NULL it 229 returns UV_EINVAL. 230 231 .. warning:: There is no protection against changing the allocator multiple 232 times. If the user changes it they are responsible for making 233 sure the allocator is changed while no memory was allocated with 234 the previous allocator, or that they are compatible. 235 236.. c:function:: uv_buf_t uv_buf_init(char* base, unsigned int len) 237 238 Constructor for :c:type:`uv_buf_t`. 239 240 Due to platform differences the user cannot rely on the ordering of the 241 `base` and `len` members of the uv_buf_t struct. The user is responsible for 242 freeing `base` after the uv_buf_t is done. Return struct passed by value. 243 244.. c:function:: char** uv_setup_args(int argc, char** argv) 245 246 Store the program arguments. Required for getting / setting the process title. 247 Libuv may take ownership of the memory that `argv` points to. This function 248 should be called exactly once, at program start-up. 249 250 Example: 251 252 :: 253 254 argv = uv_setup_args(argc, argv); /* May return a copy of argv. */ 255 256 257.. c:function:: int uv_get_process_title(char* buffer, size_t size) 258 259 Gets the title of the current process. You *must* call `uv_setup_args` 260 before calling this function. If `buffer` is `NULL` or `size` is zero, 261 `UV_EINVAL` is returned. If `size` cannot accommodate the process title and 262 terminating `NULL` character, the function returns `UV_ENOBUFS`. 263 264 .. versionchanged:: 1.18.1 now thread-safe on all supported platforms. 265 266.. c:function:: int uv_set_process_title(const char* title) 267 268 Sets the current process title. You *must* call `uv_setup_args` before 269 calling this function. On platforms with a fixed size buffer for the process 270 title the contents of `title` will be copied to the buffer and truncated if 271 larger than the available space. Other platforms will return `UV_ENOMEM` if 272 they cannot allocate enough space to duplicate the contents of `title`. 273 274 .. versionchanged:: 1.18.1 now thread-safe on all supported platforms. 275 276.. c:function:: int uv_resident_set_memory(size_t* rss) 277 278 Gets the resident set size (RSS) for the current process. 279 280.. c:function:: int uv_uptime(double* uptime) 281 282 Gets the current system uptime. 283 284.. c:function:: int uv_getrusage(uv_rusage_t* rusage) 285 286 Gets the resource usage measures for the current process. 287 288 .. note:: 289 On Windows not all fields are set, the unsupported fields are filled with zeroes. 290 See :c:type:`uv_rusage_t` for more details. 291 292.. c:function:: uv_pid_t uv_os_getpid(void) 293 294 Returns the current process ID. 295 296 .. versionadded:: 1.18.0 297 298.. c:function:: uv_pid_t uv_os_getppid(void) 299 300 Returns the parent process ID. 301 302 .. versionadded:: 1.16.0 303 304.. c:function:: int uv_cpu_info(uv_cpu_info_t** cpu_infos, int* count) 305 306 Gets information about the CPUs on the system. The `cpu_infos` array will 307 have `count` elements and needs to be freed with :c:func:`uv_free_cpu_info`. 308 309.. c:function:: void uv_free_cpu_info(uv_cpu_info_t* cpu_infos, int count) 310 311 Frees the `cpu_infos` array previously allocated with :c:func:`uv_cpu_info`. 312 313.. c:function:: int uv_interface_addresses(uv_interface_address_t** addresses, int* count) 314 315 Gets address information about the network interfaces on the system. An 316 array of `count` elements is allocated and returned in `addresses`. It must 317 be freed by the user, calling :c:func:`uv_free_interface_addresses`. 318 319.. c:function:: void uv_free_interface_addresses(uv_interface_address_t* addresses, int count) 320 321 Free an array of :c:type:`uv_interface_address_t` which was returned by 322 :c:func:`uv_interface_addresses`. 323 324.. c:function:: void uv_loadavg(double avg[3]) 325 326 Gets the load average. See: `<https://en.wikipedia.org/wiki/Load_(computing)>`_ 327 328 .. note:: 329 Returns [0,0,0] on Windows (i.e., it's not implemented). 330 331.. c:function:: int uv_ip4_addr(const char* ip, int port, struct sockaddr_in* addr) 332 333 Convert a string containing an IPv4 addresses to a binary structure. 334 335.. c:function:: int uv_ip6_addr(const char* ip, int port, struct sockaddr_in6* addr) 336 337 Convert a string containing an IPv6 addresses to a binary structure. 338 339.. c:function:: int uv_ip4_name(const struct sockaddr_in* src, char* dst, size_t size) 340 341 Convert a binary structure containing an IPv4 address to a string. 342 343.. c:function:: int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size) 344 345 Convert a binary structure containing an IPv6 address to a string. 346 347.. c:function:: int uv_inet_ntop(int af, const void* src, char* dst, size_t size) 348.. c:function:: int uv_inet_pton(int af, const char* src, void* dst) 349 350 Cross-platform IPv6-capable implementation of :man:`inet_ntop(3)` 351 and :man:`inet_pton(3)`. On success they return 0. In case of error 352 the target `dst` pointer is unmodified. 353 354.. c:macro:: UV_IF_NAMESIZE 355 356 Maximum IPv6 interface identifier name length. Defined as 357 `IFNAMSIZ` on Unix and `IF_NAMESIZE` on Linux and Windows. 358 359 .. versionadded:: 1.16.0 360 361.. c:function:: int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) 362 363 IPv6-capable implementation of :man:`if_indextoname(3)`. When called, 364 `*size` indicates the length of the `buffer`, which is used to store the 365 result. 366 On success, zero is returned, `buffer` contains the interface name, and 367 `*size` represents the string length of the `buffer`, excluding the NUL 368 terminator byte from `*size`. On error, a negative result is 369 returned. If `buffer` is not large enough to hold the result, 370 `UV_ENOBUFS` is returned, and `*size` represents the necessary size in 371 bytes, including the NUL terminator byte into the `*size`. 372 373 On Unix, the returned interface name can be used directly as an 374 interface identifier in scoped IPv6 addresses, e.g. 375 `fe80::abc:def1:2345%en0`. 376 377 On Windows, the returned interface cannot be used as an interface 378 identifier, as Windows uses numerical interface identifiers, e.g. 379 `fe80::abc:def1:2345%5`. 380 381 To get an interface identifier in a cross-platform compatible way, 382 use `uv_if_indextoiid()`. 383 384 Example: 385 386 :: 387 388 char ifname[UV_IF_NAMESIZE]; 389 size_t size = sizeof(ifname); 390 uv_if_indextoname(sin6->sin6_scope_id, ifname, &size); 391 392 .. versionadded:: 1.16.0 393 394.. c:function:: int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) 395 396 Retrieves a network interface identifier suitable for use in an IPv6 scoped 397 address. On Windows, returns the numeric `ifindex` as a string. On all other 398 platforms, `uv_if_indextoname()` is called. The result is written to 399 `buffer`, with `*size` indicating the length of `buffer`. If `buffer` is not 400 large enough to hold the result, then `UV_ENOBUFS` is returned, and `*size` 401 represents the size, including the NUL byte, required to hold the 402 result. 403 404 See `uv_if_indextoname` for further details. 405 406 .. versionadded:: 1.16.0 407 408.. c:function:: int uv_exepath(char* buffer, size_t* size) 409 410 Gets the executable path. 411 412.. c:function:: int uv_cwd(char* buffer, size_t* size) 413 414 Gets the current working directory, and stores it in `buffer`. If the 415 current working directory is too large to fit in `buffer`, this function 416 returns `UV_ENOBUFS`, and sets `size` to the required length, including the 417 null terminator. 418 419 .. versionchanged:: 1.1.0 420 421 On Unix the path no longer ends in a slash. 422 423 .. versionchanged:: 1.9.0 the returned length includes the terminating null 424 byte on `UV_ENOBUFS`, and the buffer is null terminated 425 on success. 426 427 428.. c:function:: int uv_chdir(const char* dir) 429 430 Changes the current working directory. 431 432.. c:function:: int uv_os_homedir(char* buffer, size_t* size) 433 434 Gets the current user's home directory. On Windows, `uv_os_homedir()` first 435 checks the `USERPROFILE` environment variable using 436 `GetEnvironmentVariableW()`. If `USERPROFILE` is not set, 437 `GetUserProfileDirectoryW()` is called. On all other operating systems, 438 `uv_os_homedir()` first checks the `HOME` environment variable using 439 :man:`getenv(3)`. If `HOME` is not set, :man:`getpwuid_r(3)` is called. The 440 user's home directory is stored in `buffer`. When `uv_os_homedir()` is 441 called, `size` indicates the maximum size of `buffer`. On success `size` is set 442 to the string length of `buffer`. On `UV_ENOBUFS` failure `size` is set to the 443 required length for `buffer`, including the null byte. 444 445 .. warning:: 446 `uv_os_homedir()` is not thread safe. 447 448 .. versionadded:: 1.6.0 449 450.. c:function:: int uv_os_tmpdir(char* buffer, size_t* size) 451 452 Gets the temp directory. On Windows, `uv_os_tmpdir()` uses `GetTempPathW()`. 453 On all other operating systems, `uv_os_tmpdir()` uses the first environment 454 variable found in the ordered list `TMPDIR`, `TMP`, `TEMP`, and `TEMPDIR`. 455 If none of these are found, the path `"/tmp"` is used, or, on Android, 456 `"/data/local/tmp"` is used. The temp directory is stored in `buffer`. When 457 `uv_os_tmpdir()` is called, `size` indicates the maximum size of `buffer`. 458 On success `size` is set to the string length of `buffer` (which does not 459 include the terminating null). On `UV_ENOBUFS` failure `size` is set to the 460 required length for `buffer`, including the null byte. 461 462 .. warning:: 463 `uv_os_tmpdir()` is not thread safe. 464 465 .. versionadded:: 1.9.0 466 467.. c:function:: int uv_os_get_passwd(uv_passwd_t* pwd) 468 469 Gets a subset of the password file entry for the current effective uid (not 470 the real uid). The populated data includes the username, euid, gid, shell, 471 and home directory. On non-Windows systems, all data comes from 472 :man:`getpwuid_r(3)`. On Windows, uid and gid are set to -1 and have no 473 meaning, and shell is `NULL`. After successfully calling this function, the 474 memory allocated to `pwd` needs to be freed with 475 :c:func:`uv_os_free_passwd`. 476 477 .. versionadded:: 1.9.0 478 479.. c:function:: void uv_os_free_passwd(uv_passwd_t* pwd) 480 481 Frees the `pwd` memory previously allocated with :c:func:`uv_os_get_passwd`. 482 483 .. versionadded:: 1.9.0 484 485.. c:function:: uint64_t uv_get_free_memory(void) 486 487 Gets memory information (in bytes). 488 489.. c:function:: uint64_t uv_get_total_memory(void) 490 491 Gets memory information (in bytes). 492 493.. c:function:: uint64_t uv_get_constrained_memory(void) 494 495 Gets the amount of memory available to the process (in bytes) based on 496 limits imposed by the OS. If there is no such constraint, or the constraint 497 is unknown, `0` is returned. Note that it is not unusual for this value to 498 be less than or greater than :c:func:`uv_get_total_memory`. 499 500 .. note:: 501 This function currently only returns a non-zero value on Linux, based 502 on cgroups if it is present. 503 504 .. versionadded:: 1.29.0 505 506.. c:function:: uint64_t uv_hrtime(void) 507 508 Returns the current high-resolution real time. This is expressed in 509 nanoseconds. It is relative to an arbitrary time in the past. It is not 510 related to the time of day and therefore not subject to clock drift. The 511 primary use is for measuring performance between intervals. 512 513 .. note:: 514 Not every platform can support nanosecond resolution; however, this value will always 515 be in nanoseconds. 516 517.. c:function:: void uv_print_all_handles(uv_loop_t* loop, FILE* stream) 518 519 Prints all handles associated with the given `loop` to the given `stream`. 520 521 Example: 522 523 :: 524 525 uv_print_all_handles(uv_default_loop(), stderr); 526 /* 527 [--I] signal 0x1a25ea8 528 [-AI] async 0x1a25cf0 529 [R--] idle 0x1a7a8c8 530 */ 531 532 The format is `[flags] handle-type handle-address`. For `flags`: 533 534 - `R` is printed for a handle that is referenced 535 - `A` is printed for a handle that is active 536 - `I` is printed for a handle that is internal 537 538 .. warning:: 539 This function is meant for ad hoc debugging, there is no API/ABI 540 stability guarantees. 541 542 .. versionadded:: 1.8.0 543 544.. c:function:: void uv_print_active_handles(uv_loop_t* loop, FILE* stream) 545 546 This is the same as :c:func:`uv_print_all_handles` except only active handles 547 are printed. 548 549 .. warning:: 550 This function is meant for ad hoc debugging, there is no API/ABI 551 stability guarantees. 552 553 .. versionadded:: 1.8.0 554 555.. c:function:: int uv_os_environ(uv_env_item_t** envitems, int* count) 556 557 Retrieves all environment variables. This function will allocate memory 558 which must be freed by calling :c:func:`uv_os_free_environ`. 559 560 .. warning:: 561 This function is not thread safe. 562 563 .. versionadded:: 1.31.0 564 565.. c:function:: void uv_os_free_environ(uv_env_item_t* envitems, int count); 566 567 Frees the memory allocated for the environment variables by 568 :c:func:`uv_os_environ`. 569 570 .. versionadded:: 1.31.0 571 572.. c:function:: int uv_os_getenv(const char* name, char* buffer, size_t* size) 573 574 Retrieves the environment variable specified by `name`, copies its value 575 into `buffer`, and sets `size` to the string length of the value. When 576 calling this function, `size` must be set to the amount of storage available 577 in `buffer`, including the null terminator. If the environment variable 578 exceeds the storage available in `buffer`, `UV_ENOBUFS` is returned, and 579 `size` is set to the amount of storage required to hold the value. If no 580 matching environment variable exists, `UV_ENOENT` is returned. 581 582 .. warning:: 583 This function is not thread safe. 584 585 .. versionadded:: 1.12.0 586 587.. c:function:: int uv_os_setenv(const char* name, const char* value) 588 589 Creates or updates the environment variable specified by `name` with 590 `value`. 591 592 .. warning:: 593 This function is not thread safe. 594 595 .. versionadded:: 1.12.0 596 597.. c:function:: int uv_os_unsetenv(const char* name) 598 599 Deletes the environment variable specified by `name`. If no such environment 600 variable exists, this function returns successfully. 601 602 .. warning:: 603 This function is not thread safe. 604 605 .. versionadded:: 1.12.0 606 607.. c:function:: int uv_os_gethostname(char* buffer, size_t* size) 608 609 Returns the hostname as a null-terminated string in `buffer`, and sets 610 `size` to the string length of the hostname. When calling this function, 611 `size` must be set to the amount of storage available in `buffer`, including 612 the null terminator. If the hostname exceeds the storage available in 613 `buffer`, `UV_ENOBUFS` is returned, and `size` is set to the amount of 614 storage required to hold the value. 615 616 .. versionadded:: 1.12.0 617 618 .. versionchanged:: 1.26.0 `UV_MAXHOSTNAMESIZE` is available and represents 619 the maximum `buffer` size required to store a 620 hostname and terminating `nul` character. 621 622.. c:function:: int uv_os_getpriority(uv_pid_t pid, int* priority) 623 624 Retrieves the scheduling priority of the process specified by `pid`. The 625 returned value of `priority` is between -20 (high priority) and 19 (low 626 priority). 627 628 .. note:: 629 On Windows, the returned priority will equal one of the `UV_PRIORITY` 630 constants. 631 632 .. versionadded:: 1.23.0 633 634.. c:function:: int uv_os_setpriority(uv_pid_t pid, int priority) 635 636 Sets the scheduling priority of the process specified by `pid`. The 637 `priority` value range is between -20 (high priority) and 19 (low priority). 638 The constants `UV_PRIORITY_LOW`, `UV_PRIORITY_BELOW_NORMAL`, 639 `UV_PRIORITY_NORMAL`, `UV_PRIORITY_ABOVE_NORMAL`, `UV_PRIORITY_HIGH`, and 640 `UV_PRIORITY_HIGHEST` are also provided for convenience. 641 642 .. note:: 643 On Windows, this function utilizes `SetPriorityClass()`. The `priority` 644 argument is mapped to a Windows priority class. When retrieving the 645 process priority, the result will equal one of the `UV_PRIORITY` 646 constants, and not necessarily the exact value of `priority`. 647 648 .. note:: 649 On Windows, setting `PRIORITY_HIGHEST` will only work for elevated user, 650 for others it will be silently reduced to `PRIORITY_HIGH`. 651 652 .. versionadded:: 1.23.0 653 654.. c:function:: int uv_os_uname(uv_utsname_t* buffer) 655 656 Retrieves system information in `buffer`. The populated data includes the 657 operating system name, release, version, and machine. On non-Windows 658 systems, `uv_os_uname()` is a thin wrapper around :man:`uname(2)`. Returns 659 zero on success, and a non-zero error value otherwise. 660 661 .. versionadded:: 1.25.0 662 663.. c:function:: int uv_gettimeofday(uv_timeval64_t* tv) 664 665 Cross-platform implementation of :man:`gettimeofday(2)`. The timezone 666 argument to `gettimeofday()` is not supported, as it is considered obsolete. 667 668 .. versionadded:: 1.28.0 669 670.. c:function:: int uv_random(uv_loop_t* loop, uv_random_t* req, void* buf, size_t buflen, unsigned int flags, uv_random_cb cb) 671 672 Fill `buf` with exactly `buflen` cryptographically strong random bytes 673 acquired from the system CSPRNG. `flags` is reserved for future extension 674 and must currently be 0. 675 676 Short reads are not possible. When less than `buflen` random bytes are 677 available, a non-zero error value is returned or passed to the callback. 678 679 The synchronous version may block indefinitely when not enough entropy 680 is available. The asynchronous version may not ever finish when the system 681 is low on entropy. 682 683 Sources of entropy: 684 685 - Windows: `RtlGenRandom <https://docs.microsoft.com/en-us/windows/desktop/api/ntsecapi/nf-ntsecapi-rtlgenrandom>_`. 686 - Linux, Android: :man:`getrandom(2)` if available, or :man:`urandom(4)` 687 after reading from `/dev/random` once, or the `KERN_RANDOM` 688 :man:`sysctl(2)`. 689 - FreeBSD: `getrandom(2) <https://www.freebsd.org/cgi/man.cgi?query=getrandom&sektion=2>_`, 690 or `/dev/urandom` after reading from `/dev/random` once. 691 - NetBSD: `KERN_ARND` `sysctl(3) <https://netbsd.gw.com/cgi-bin/man-cgi?sysctl+3+NetBSD-current>_` 692 - macOS, OpenBSD: `getentropy(2) <https://man.openbsd.org/getentropy.2>_` 693 if available, or `/dev/urandom` after reading from `/dev/random` once. 694 - AIX: `/dev/random`. 695 - IBM i: `/dev/urandom`. 696 - Other UNIX: `/dev/urandom` after reading from `/dev/random` once. 697 698 :returns: 0 on success, or an error code < 0 on failure. The contents of 699 `buf` is undefined after an error. 700 701 .. note:: 702 When using the synchronous version, both `loop` and `req` parameters 703 are not used and can be set to `NULL`. 704 705 .. versionadded:: 1.33.0 706 707.. c:function:: void uv_sleep(unsigned int msec) 708 709 Causes the calling thread to sleep for `msec` milliseconds. 710 711 .. versionadded:: 1.34.0 712