| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include <errno.h> |
| #include <grp.h> |
| #include <pwd.h> |
| #include <string.h> |
| #include <time.h> |
| #include <signal.h> |
| #include <spawn.h> |
| #include <stdio.h> |
| #include <sys/times.h> |
| #include <sys/wait.h> |
| #include <unistd.h> |
|
|
| #ifndef weak |
| #define weak __attribute__((__weak__)) |
| #endif |
|
|
| |
| |
| |
|
|
| weak int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options) { |
| errno = ECHILD; |
| return -1; |
| } |
|
|
| |
| |
| |
|
|
| clock_t times(struct tms *buf) { |
| |
| |
| |
| if (buf) { |
| memset(buf, 0, sizeof(*buf)); |
| } |
| return 0; |
| } |
|
|
| struct tm *getdate(const char *string) { |
| |
| |
| |
| return 0; |
| } |
|
|
| weak int stime(const time_t *t) { |
| errno = EPERM; |
| return -1; |
| } |
|
|
| weak int clock_getcpuclockid(pid_t pid, clockid_t *clockid) { |
| if (pid < 0) { |
| return ESRCH; |
| } |
| if (pid != 0 && pid != getpid()) { |
| return ENOSYS; |
| } |
| if (clockid) { |
| *clockid = CLOCK_PROCESS_CPUTIME_ID; |
| } |
| return 0; |
| } |
|
|
| |
| |
| |
|
|
| struct passwd *getpwnam(const char *name) { |
| errno = ENOENT; |
| return 0; |
| } |
|
|
| struct passwd *getpwuid(uid_t uid) { |
| errno = ENOENT; |
| return 0; |
| } |
|
|
| weak int getpwnam_r(const char *name, struct passwd *pwd, |
| char *buf, size_t buflen, struct passwd **result) { |
| return ENOENT; |
| } |
|
|
| weak int getpwuid_r(uid_t uid, struct passwd *pwd, |
| char *buf, size_t buflen, struct passwd **result) { |
| return ENOENT; |
| } |
|
|
| weak void setpwent(void) { |
| } |
|
|
| weak void endpwent(void) { |
| } |
|
|
| struct passwd *getpwent(void) { |
| errno = EIO; |
| return NULL; |
| } |
|
|
| |
| |
| |
|
|
| weak struct group *getgrnam(const char *name) { |
| errno = ENOENT; |
| return 0; |
| } |
|
|
| weak struct group *getgrgid(gid_t gid) { |
| errno = ENOENT; |
| return 0; |
| } |
|
|
| weak int getgrnam_r(const char *name, struct group *grp, |
| char *buf, size_t buflen, struct group **result) { |
| return ENOENT; |
| } |
|
|
| weak int getgrgid_r(gid_t gid, struct group *grp, |
| char *buf, size_t buflen, struct group **result) { |
| return ENOENT; |
| } |
|
|
| weak struct group *getgrent(void) { |
| errno = EIO; |
| return NULL; |
| } |
|
|
| weak void endgrent(void) { |
| } |
|
|
| weak void setgrent(void) { |
| } |
|
|
| |
| |
| |
|
|
| weak int flock(int fd, int operation) { |
| |
| |
| |
| |
| return 0; |
| } |
|
|
| weak int chroot(const char *path) { |
| |
| |
| errno = EACCES; |
| return -1; |
| } |
|
|
| weak int execve(const char *pathname, char *const argv[], |
| char *const envp[]) { |
| |
| |
| |
| |
| errno = ENOEXEC; |
| return -1; |
| } |
|
|
| weak pid_t fork(void) { |
| |
| |
| |
| errno = ENOSYS; |
| return -1; |
| } |
|
|
| weak pid_t vfork(void) { |
| errno = ENOSYS; |
| return -1; |
| } |
|
|
| weak int posix_spawn(pid_t *pid, const char *path, |
| const posix_spawn_file_actions_t *file_actions, |
| const posix_spawnattr_t *attrp, |
| char *const argv[], char *const envp[]) { |
| errno = ENOSYS; |
| return -1; |
| } |
|
|
| |
| |
| |
|
|
| weak FILE *popen(const char *command, const char *type) { |
| errno = ENOSYS; |
| return NULL; |
| } |
|
|
| weak int pclose(FILE *stream) { |
| errno = ENOSYS; |
| return -1; |
| } |
|
|
| weak int setgroups(size_t size, const gid_t *list) { |
| |
| |
| if (size < 1 || size > sysconf(_SC_NGROUPS_MAX)) { |
| errno = EINVAL; |
| return -1; |
| } |
| |
| errno = EPERM; |
| return -1; |
| } |
|
|
| weak int sigaltstack(const stack_t *restrict ss, stack_t *restrict old_ss) { |
| errno = ENOSYS; |
| return -1; |
| } |
|
|
| |
| |
| |
|
|
| #ifndef EMSCRIPTEN_DYNAMIC_LINKING |
| void __dl_seterr(const char*, ...); |
|
|
| weak void *__dlsym(void *restrict p, const char *restrict s, void *restrict ra) { |
| __dl_seterr("dynamic linking not enabled"); |
| return NULL; |
| } |
|
|
| weak void* dlopen(const char* file, int flags) { |
| __dl_seterr("dynamic linking not enabled"); |
| return NULL; |
| } |
| #endif |
|
|
| |
| |
| |
|
|
| #define MIN(x, y) (((x) < (y)) ? (x) : (y)) |
|
|
| weak int getloadavg(double loadavg[], int nelem) { |
| |
| int limit = MIN(nelem, 3); |
| for (int i = 0; i < limit; i++) { |
| loadavg[i] = 0.1; |
| } |
| return limit; |
| } |
|
|