2024-08-05 19:15:24 +08:00
|
|
|
#include <dirent.h>
|
2024-08-05 19:09:24 +08:00
|
|
|
#include <fcntl.h>
|
2024-01-29 04:45:14 +08:00
|
|
|
#include <locale.h>
|
2023-10-09 05:22:27 +08:00
|
|
|
#include <paths.h>
|
2023-09-15 17:56:03 +08:00
|
|
|
#include <stdbool.h>
|
2023-04-09 20:33:20 +08:00
|
|
|
#include <stdint.h>
|
2023-10-09 05:22:27 +08:00
|
|
|
#include <stdio.h>
|
2023-03-26 23:23:05 +08:00
|
|
|
#include <stdlib.h>
|
2023-11-26 18:47:30 +08:00
|
|
|
#include <sys/resource.h>
|
2024-08-05 19:09:24 +08:00
|
|
|
#include <sys/stat.h>
|
2024-08-05 19:15:24 +08:00
|
|
|
#include <sys/types.h>
|
2024-08-07 15:54:41 +08:00
|
|
|
#include <time.h>
|
2023-08-20 21:34:01 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#define UNUSED(x) (void)(x)
|
2023-03-26 23:23:05 +08:00
|
|
|
|
|
|
|
size_t C_MB_CUR_MAX() { return MB_CUR_MAX; }
|
2023-04-09 19:54:41 +08:00
|
|
|
|
2023-04-09 20:33:20 +08:00
|
|
|
uint64_t C_ST_LOCAL() {
|
|
|
|
#if defined(ST_LOCAL)
|
|
|
|
return ST_LOCAL;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-08-20 21:34:01 +08:00
|
|
|
// confstr + _CS_PATH is only available on macOS with rust's libc
|
|
|
|
// we could just declare extern "C" confstr directly in Rust
|
|
|
|
// that would panic if it failed to link, which C++ did not
|
|
|
|
// therefore we define a backup, which just returns an error
|
|
|
|
// which for confstr is 0
|
|
|
|
#if defined(_CS_PATH)
|
|
|
|
#else
|
|
|
|
size_t confstr(int name, char* buf, size_t size) {
|
|
|
|
UNUSED(name);
|
|
|
|
UNUSED(buf);
|
|
|
|
UNUSED(size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int C_CS_PATH() {
|
|
|
|
#if defined(_CS_PATH)
|
|
|
|
return _CS_PATH;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-04-09 20:33:20 +08:00
|
|
|
uint64_t C_MNT_LOCAL() {
|
|
|
|
#if defined(MNT_LOCAL)
|
|
|
|
return MNT_LOCAL;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
2023-09-15 17:56:03 +08:00
|
|
|
|
2023-10-09 05:22:27 +08:00
|
|
|
const char* C_PATH_BSHELL() { return _PATH_BSHELL; }
|
|
|
|
|
|
|
|
int C_PC_CASE_SENSITIVE() {
|
|
|
|
#ifdef _PC_CASE_SENSITIVE
|
|
|
|
return _PC_CASE_SENSITIVE;
|
|
|
|
#else
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
FILE* stdout_stream() { return stdout; }
|
|
|
|
|
2023-11-26 18:47:30 +08:00
|
|
|
int C_RLIMIT_CORE() { return RLIMIT_CORE; }
|
|
|
|
int C_RLIMIT_DATA() { return RLIMIT_DATA; }
|
|
|
|
int C_RLIMIT_FSIZE() { return RLIMIT_FSIZE; }
|
|
|
|
int C_RLIMIT_NOFILE() { return RLIMIT_NOFILE; }
|
|
|
|
int C_RLIMIT_STACK() { return RLIMIT_STACK; }
|
|
|
|
int C_RLIMIT_CPU() { return RLIMIT_CPU; }
|
|
|
|
|
|
|
|
int C_RLIMIT_SBSIZE() {
|
|
|
|
#ifdef RLIMIT_SBSIZE
|
|
|
|
return RLIMIT_SBSIZE;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_NICE() {
|
|
|
|
#ifdef RLIMIT_NICE
|
|
|
|
return RLIMIT_NICE;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_SIGPENDING() {
|
|
|
|
#ifdef RLIMIT_SIGPENDING
|
|
|
|
return RLIMIT_SIGPENDING;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_MEMLOCK() {
|
|
|
|
#ifdef RLIMIT_MEMLOCK
|
|
|
|
return RLIMIT_MEMLOCK;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_RSS() {
|
|
|
|
#ifdef RLIMIT_RSS
|
|
|
|
return RLIMIT_RSS;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_MSGQUEUE() {
|
|
|
|
#ifdef RLIMIT_MSGQUEUE
|
|
|
|
return RLIMIT_MSGQUEUE;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_RTPRIO() {
|
|
|
|
#ifdef RLIMIT_RTPRIO
|
|
|
|
return RLIMIT_RTPRIO;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_NPROC() {
|
|
|
|
#ifdef RLIMIT_NPROC
|
|
|
|
return RLIMIT_NPROC;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_AS() {
|
|
|
|
#ifdef RLIMIT_AS
|
|
|
|
return RLIMIT_AS;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_SWAP() {
|
|
|
|
#ifdef RLIMIT_SWAP
|
|
|
|
return RLIMIT_SWAP;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_RTTIME() {
|
|
|
|
#ifdef RLIMIT_RTTIME
|
|
|
|
return RLIMIT_RTTIME;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_KQUEUES() {
|
|
|
|
#ifdef RLIMIT_KQUEUES
|
|
|
|
return RLIMIT_KQUEUES;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_NPTS() {
|
|
|
|
#ifdef RLIMIT_NPTS
|
|
|
|
return RLIMIT_NPTS;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int C_RLIMIT_NTHR() {
|
|
|
|
#ifdef RLIMIT_NTHR
|
|
|
|
return RLIMIT_NTHR;
|
|
|
|
#else
|
|
|
|
return -1;
|
|
|
|
#endif
|
|
|
|
}
|
2024-08-05 19:15:24 +08:00
|
|
|
|
2024-08-07 15:42:35 +08:00
|
|
|
bool C_readdir64(DIR* dirp, const char** d_name, size_t* d_name_len, uint64_t* d_ino,
|
|
|
|
unsigned char* d_type) {
|
|
|
|
struct dirent* dent = readdir(dirp);
|
2024-08-05 19:15:24 +08:00
|
|
|
if (!dent) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*d_name = dent->d_name;
|
|
|
|
*d_name_len = sizeof dent->d_name / sizeof **d_name;
|
|
|
|
#if defined(__BSD__)
|
|
|
|
*d_ino = dent->d_fileno;
|
|
|
|
#else
|
|
|
|
*d_ino = dent->d_ino;
|
|
|
|
#endif
|
|
|
|
*d_type = dent->d_type;
|
|
|
|
return true;
|
|
|
|
}
|
2024-08-05 19:09:24 +08:00
|
|
|
|
2024-08-07 15:42:35 +08:00
|
|
|
bool C_fstatat64(int dirfd, const char* file, int flag, uint64_t* st_dev, uint64_t* st_ino,
|
|
|
|
mode_t* st_mode) {
|
2024-08-05 19:09:24 +08:00
|
|
|
struct stat buf;
|
|
|
|
if (fstatat(dirfd, file, &buf, flag) == -1) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
*st_dev = buf.st_dev;
|
|
|
|
*st_ino = buf.st_ino;
|
|
|
|
*st_mode = buf.st_mode;
|
|
|
|
return true;
|
|
|
|
}
|
2024-08-07 15:54:41 +08:00
|
|
|
|
|
|
|
bool C_localtime64_r(int64_t timep, struct tm* result) {
|
|
|
|
time_t timep_ = timep;
|
|
|
|
return localtime_r(&timep_, result);
|
|
|
|
}
|