summaryrefslogtreecommitdiffstats
path: root/libc-top-half/musl/src/legacy
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 13:54:38 +0000
commit8c1ab65c0f548d20b7f177bdb736daaf603340e1 (patch)
treedf55b7e75bf43f2bf500845b105afe3ac3a5157e /libc-top-half/musl/src/legacy
parentInitial commit. (diff)
downloadwasi-libc-b0f726bfa464c79fdf040fa7daed6094ddbffb4c.tar.xz
wasi-libc-b0f726bfa464c79fdf040fa7daed6094ddbffb4c.zip
Adding upstream version 0.0~git20221206.8b7148f.upstream/0.0_git20221206.8b7148f
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libc-top-half/musl/src/legacy')
-rw-r--r--libc-top-half/musl/src/legacy/cuserid.c22
-rw-r--r--libc-top-half/musl/src/legacy/daemon.c33
-rw-r--r--libc-top-half/musl/src/legacy/err.c67
-rw-r--r--libc-top-half/musl/src/legacy/euidaccess.c10
-rw-r--r--libc-top-half/musl/src/legacy/ftw.c11
-rw-r--r--libc-top-half/musl/src/legacy/futimes.c14
-rw-r--r--libc-top-half/musl/src/legacy/getdtablesize.c11
-rw-r--r--libc-top-half/musl/src/legacy/getloadavg.c14
-rw-r--r--libc-top-half/musl/src/legacy/getpagesize.c8
-rw-r--r--libc-top-half/musl/src/legacy/getpass.c40
-rw-r--r--libc-top-half/musl/src/legacy/getusershell.c32
-rw-r--r--libc-top-half/musl/src/legacy/isastream.c7
-rw-r--r--libc-top-half/musl/src/legacy/lutimes.c16
-rw-r--r--libc-top-half/musl/src/legacy/ulimit.c19
-rw-r--r--libc-top-half/musl/src/legacy/utmpx.c52
-rw-r--r--libc-top-half/musl/src/legacy/valloc.c8
16 files changed, 364 insertions, 0 deletions
diff --git a/libc-top-half/musl/src/legacy/cuserid.c b/libc-top-half/musl/src/legacy/cuserid.c
new file mode 100644
index 0000000..dcaf73d
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/cuserid.c
@@ -0,0 +1,22 @@
+#define _GNU_SOURCE
+#include <pwd.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+
+char *cuserid(char *buf)
+{
+ static char usridbuf[L_cuserid];
+ struct passwd pw, *ppw;
+ long pwb[256];
+ if (buf) *buf = 0;
+ getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
+ if (!ppw)
+ return buf;
+ size_t len = strnlen(pw.pw_name, L_cuserid);
+ if (len == L_cuserid)
+ return buf;
+ if (!buf) buf = usridbuf;
+ memcpy(buf, pw.pw_name, len+1);
+ return buf;
+}
diff --git a/libc-top-half/musl/src/legacy/daemon.c b/libc-top-half/musl/src/legacy/daemon.c
new file mode 100644
index 0000000..1568b1d
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/daemon.c
@@ -0,0 +1,33 @@
+#define _GNU_SOURCE
+#include <fcntl.h>
+#include <unistd.h>
+
+int daemon(int nochdir, int noclose)
+{
+ if (!nochdir && chdir("/"))
+ return -1;
+ if (!noclose) {
+ int fd, failed = 0;
+ if ((fd = open("/dev/null", O_RDWR)) < 0) return -1;
+ if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0)
+ failed++;
+ if (fd > 2) close(fd);
+ if (failed) return -1;
+ }
+
+ switch(fork()) {
+ case 0: break;
+ case -1: return -1;
+ default: _exit(0);
+ }
+
+ if (setsid() < 0) return -1;
+
+ switch(fork()) {
+ case 0: break;
+ case -1: return -1;
+ default: _exit(0);
+ }
+
+ return 0;
+}
diff --git a/libc-top-half/musl/src/legacy/err.c b/libc-top-half/musl/src/legacy/err.c
new file mode 100644
index 0000000..0d6ab52
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/err.c
@@ -0,0 +1,67 @@
+#include <err.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <stdlib.h>
+
+extern char *__progname;
+
+void vwarn(const char *fmt, va_list ap)
+{
+ fprintf (stderr, "%s: ", __progname);
+ if (fmt) {
+ vfprintf(stderr, fmt, ap);
+ fputs (": ", stderr);
+ }
+ perror(0);
+}
+
+void vwarnx(const char *fmt, va_list ap)
+{
+ fprintf (stderr, "%s: ", __progname);
+ if (fmt) vfprintf(stderr, fmt, ap);
+ putc('\n', stderr);
+}
+
+_Noreturn void verr(int status, const char *fmt, va_list ap)
+{
+ vwarn(fmt, ap);
+ exit(status);
+}
+
+_Noreturn void verrx(int status, const char *fmt, va_list ap)
+{
+ vwarnx(fmt, ap);
+ exit(status);
+}
+
+void warn(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarn(fmt, ap);
+ va_end(ap);
+}
+
+void warnx(const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ vwarnx(fmt, ap);
+ va_end(ap);
+}
+
+_Noreturn void err(int status, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verr(status, fmt, ap);
+ va_end(ap);
+}
+
+_Noreturn void errx(int status, const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ verrx(status, fmt, ap);
+ va_end(ap);
+}
diff --git a/libc-top-half/musl/src/legacy/euidaccess.c b/libc-top-half/musl/src/legacy/euidaccess.c
new file mode 100644
index 0000000..6e1f398
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/euidaccess.c
@@ -0,0 +1,10 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <fcntl.h>
+
+int euidaccess(const char *filename, int amode)
+{
+ return faccessat(AT_FDCWD, filename, amode, AT_EACCESS);
+}
+
+weak_alias(euidaccess, eaccess);
diff --git a/libc-top-half/musl/src/legacy/ftw.c b/libc-top-half/musl/src/legacy/ftw.c
new file mode 100644
index 0000000..506bd29
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/ftw.c
@@ -0,0 +1,11 @@
+#include <ftw.h>
+
+int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit)
+{
+ /* The following cast assumes that calling a function with one
+ * argument more than it needs behaves as expected. This is
+ * actually undefined, but works on all real-world machines. */
+ return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS);
+}
+
+weak_alias(ftw, ftw64);
diff --git a/libc-top-half/musl/src/legacy/futimes.c b/libc-top-half/musl/src/legacy/futimes.c
new file mode 100644
index 0000000..1c19eb1
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/futimes.c
@@ -0,0 +1,14 @@
+#define _GNU_SOURCE
+#include <sys/stat.h>
+#include <sys/time.h>
+
+int futimes(int fd, const struct timeval tv[2])
+{
+ struct timespec times[2];
+ if (!tv) return futimens(fd, 0);
+ times[0].tv_sec = tv[0].tv_sec;
+ times[0].tv_nsec = tv[0].tv_usec * 1000;
+ times[1].tv_sec = tv[1].tv_sec;
+ times[1].tv_nsec = tv[1].tv_usec * 1000;
+ return futimens(fd, times);
+}
diff --git a/libc-top-half/musl/src/legacy/getdtablesize.c b/libc-top-half/musl/src/legacy/getdtablesize.c
new file mode 100644
index 0000000..b30c193
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/getdtablesize.c
@@ -0,0 +1,11 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <limits.h>
+#include <sys/resource.h>
+
+int getdtablesize(void)
+{
+ struct rlimit rl;
+ getrlimit(RLIMIT_NOFILE, &rl);
+ return rl.rlim_cur < INT_MAX ? rl.rlim_cur : INT_MAX;
+}
diff --git a/libc-top-half/musl/src/legacy/getloadavg.c b/libc-top-half/musl/src/legacy/getloadavg.c
new file mode 100644
index 0000000..ff06de0
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/getloadavg.c
@@ -0,0 +1,14 @@
+#define _GNU_SOURCE
+#include <stdlib.h>
+#include <sys/sysinfo.h>
+
+int getloadavg(double *a, int n)
+{
+ struct sysinfo si;
+ if (n <= 0) return n ? -1 : 0;
+ sysinfo(&si);
+ if (n > 3) n = 3;
+ for (int i=0; i<n; i++)
+ a[i] = 1.0/(1<<SI_LOAD_SHIFT) * si.loads[i];
+ return n;
+}
diff --git a/libc-top-half/musl/src/legacy/getpagesize.c b/libc-top-half/musl/src/legacy/getpagesize.c
new file mode 100644
index 0000000..0fc29ff
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/getpagesize.c
@@ -0,0 +1,8 @@
+#define _GNU_SOURCE
+#include <unistd.h>
+#include "libc.h"
+
+int getpagesize(void)
+{
+ return PAGE_SIZE;
+}
diff --git a/libc-top-half/musl/src/legacy/getpass.c b/libc-top-half/musl/src/legacy/getpass.c
new file mode 100644
index 0000000..d51286c
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/getpass.c
@@ -0,0 +1,40 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <termios.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+
+char *getpass(const char *prompt)
+{
+ int fd;
+ struct termios s, t;
+ ssize_t l;
+ static char password[128];
+
+ if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0) return 0;
+
+ tcgetattr(fd, &t);
+ s = t;
+ t.c_lflag &= ~(ECHO|ISIG);
+ t.c_lflag |= ICANON;
+ t.c_iflag &= ~(INLCR|IGNCR);
+ t.c_iflag |= ICRNL;
+ tcsetattr(fd, TCSAFLUSH, &t);
+ tcdrain(fd);
+
+ dprintf(fd, "%s", prompt);
+
+ l = read(fd, password, sizeof password);
+ if (l >= 0) {
+ if (l > 0 && password[l-1] == '\n' || l==sizeof password) l--;
+ password[l] = 0;
+ }
+
+ tcsetattr(fd, TCSAFLUSH, &s);
+
+ dprintf(fd, "\n");
+ close(fd);
+
+ return l<0 ? 0 : password;
+}
diff --git a/libc-top-half/musl/src/legacy/getusershell.c b/libc-top-half/musl/src/legacy/getusershell.c
new file mode 100644
index 0000000..5fecdec
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/getusershell.c
@@ -0,0 +1,32 @@
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+
+static const char defshells[] = "/bin/sh\n/bin/csh\n";
+
+static char *line;
+static size_t linesize;
+static FILE *f;
+
+void endusershell(void)
+{
+ if (f) fclose(f);
+ f = 0;
+}
+
+void setusershell(void)
+{
+ if (!f) f = fopen("/etc/shells", "rbe");
+ if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb");
+}
+
+char *getusershell(void)
+{
+ ssize_t l;
+ if (!f) setusershell();
+ if (!f) return 0;
+ l = getline(&line, &linesize, f);
+ if (l <= 0) return 0;
+ if (line[l-1]=='\n') line[l-1]=0;
+ return line;
+}
diff --git a/libc-top-half/musl/src/legacy/isastream.c b/libc-top-half/musl/src/legacy/isastream.c
new file mode 100644
index 0000000..4dafdb0
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/isastream.c
@@ -0,0 +1,7 @@
+#include <stropts.h>
+#include <fcntl.h>
+
+int isastream(int fd)
+{
+ return fcntl(fd, F_GETFD) < 0 ? -1 : 0;
+}
diff --git a/libc-top-half/musl/src/legacy/lutimes.c b/libc-top-half/musl/src/legacy/lutimes.c
new file mode 100644
index 0000000..dd46592
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/lutimes.c
@@ -0,0 +1,16 @@
+#define _GNU_SOURCE
+#include <sys/stat.h>
+#include <sys/time.h>
+#include <fcntl.h>
+
+int lutimes(const char *filename, const struct timeval tv[2])
+{
+ struct timespec times[2];
+ if (tv) {
+ times[0].tv_sec = tv[0].tv_sec;
+ times[0].tv_nsec = tv[0].tv_usec * 1000;
+ times[1].tv_sec = tv[1].tv_sec;
+ times[1].tv_nsec = tv[1].tv_usec * 1000;
+ }
+ return utimensat(AT_FDCWD, filename, tv ? times : 0, AT_SYMLINK_NOFOLLOW);
+}
diff --git a/libc-top-half/musl/src/legacy/ulimit.c b/libc-top-half/musl/src/legacy/ulimit.c
new file mode 100644
index 0000000..1f59e8e
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/ulimit.c
@@ -0,0 +1,19 @@
+#include <sys/resource.h>
+#include <ulimit.h>
+#include <stdarg.h>
+
+long ulimit(int cmd, ...)
+{
+ struct rlimit rl;
+ getrlimit(RLIMIT_FSIZE, &rl);
+ if (cmd == UL_SETFSIZE) {
+ long val;
+ va_list ap;
+ va_start(ap, cmd);
+ val = va_arg(ap, long);
+ va_end(ap);
+ rl.rlim_cur = 512ULL * val;
+ if (setrlimit(RLIMIT_FSIZE, &rl)) return -1;
+ }
+ return rl.rlim_cur / 512;
+}
diff --git a/libc-top-half/musl/src/legacy/utmpx.c b/libc-top-half/musl/src/legacy/utmpx.c
new file mode 100644
index 0000000..7aa65da
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/utmpx.c
@@ -0,0 +1,52 @@
+#define _GNU_SOURCE
+#include <utmpx.h>
+#include <stddef.h>
+#include <errno.h>
+
+void endutxent(void)
+{
+}
+
+void setutxent(void)
+{
+}
+
+struct utmpx *getutxent(void)
+{
+ return NULL;
+}
+
+struct utmpx *getutxid(const struct utmpx *ut)
+{
+ return NULL;
+}
+
+struct utmpx *getutxline(const struct utmpx *ut)
+{
+ return NULL;
+}
+
+struct utmpx *pututxline(const struct utmpx *ut)
+{
+ return NULL;
+}
+
+void updwtmpx(const char *f, const struct utmpx *u)
+{
+}
+
+static int __utmpxname(const char *f)
+{
+ errno = ENOTSUP;
+ return -1;
+}
+
+weak_alias(endutxent, endutent);
+weak_alias(setutxent, setutent);
+weak_alias(getutxent, getutent);
+weak_alias(getutxid, getutid);
+weak_alias(getutxline, getutline);
+weak_alias(pututxline, pututline);
+weak_alias(updwtmpx, updwtmp);
+weak_alias(__utmpxname, utmpname);
+weak_alias(__utmpxname, utmpxname);
diff --git a/libc-top-half/musl/src/legacy/valloc.c b/libc-top-half/musl/src/legacy/valloc.c
new file mode 100644
index 0000000..5af2256
--- /dev/null
+++ b/libc-top-half/musl/src/legacy/valloc.c
@@ -0,0 +1,8 @@
+#define _BSD_SOURCE
+#include <stdlib.h>
+#include "libc.h"
+
+void *valloc(size_t size)
+{
+ return memalign(PAGE_SIZE, size);
+}