mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Add Cosmopolitan to uname()
This commit is contained in:
parent
ed316491ca
commit
3ffc17c50e
9 changed files with 56 additions and 14 deletions
|
@ -6,6 +6,7 @@
|
|||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int sigwait(const sigset_t *, int *);
|
||||
int sigtimedwait(const sigset_t *, siginfo_t *, const struct timespec *);
|
||||
int sigwaitinfo(const sigset_t *, siginfo_t *);
|
||||
|
||||
|
|
26
libc/calls/sigwait.c
Normal file
26
libc/calls/sigwait.c
Normal file
|
@ -0,0 +1,26 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2023 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/sigtimedwait.h"
|
||||
|
||||
int sigwait(const sigset_t *mask, int *sig) {
|
||||
siginfo_t si;
|
||||
if (sigtimedwait(mask, &si, 0) < 0) return -1;
|
||||
*sig = si.si_signo;
|
||||
return 0;
|
||||
}
|
|
@ -145,12 +145,12 @@ int uname(struct utsname *uts) {
|
|||
} else if (IsLinux()) {
|
||||
struct utsname_linux linux;
|
||||
if (!(rc = sys_uname_linux(&linux))) {
|
||||
stpcpy(uts->sysname, linux.sysname);
|
||||
stpcpy(uts->nodename, linux.nodename);
|
||||
stpcpy(uts->release, linux.release);
|
||||
stpcpy(uts->version, linux.version);
|
||||
stpcpy(uts->machine, linux.machine);
|
||||
stpcpy(uts->domainname, linux.domainname);
|
||||
strlcpy(uts->sysname, linux.sysname, SYS_NMLN);
|
||||
strlcpy(uts->nodename, linux.nodename, SYS_NMLN);
|
||||
strlcpy(uts->release, linux.release, SYS_NMLN);
|
||||
strlcpy(uts->version, linux.version, SYS_NMLN);
|
||||
strlcpy(uts->machine, linux.machine, SYS_NMLN);
|
||||
strlcpy(uts->domainname, linux.domainname, SYS_NMLN);
|
||||
if (!strcmp(uts->domainname, "(none)")) {
|
||||
uts->domainname[0] = 0;
|
||||
}
|
||||
|
@ -166,7 +166,6 @@ int uname(struct utsname *uts) {
|
|||
} else if (IsWindows()) {
|
||||
stpcpy(uts->sysname, "Windows");
|
||||
stpcpy(uts->machine, "x86_64");
|
||||
GetNtVersion(stpcpy(uts->version, "Windows "));
|
||||
GetNtVersion(uts->release);
|
||||
GetNtName(uts->nodename, kNtComputerNamePhysicalDnsHostname);
|
||||
GetNtName(uts->domainname, kNtComputerNamePhysicalDnsDomain);
|
||||
|
@ -174,6 +173,18 @@ int uname(struct utsname *uts) {
|
|||
} else {
|
||||
rc = enosys();
|
||||
}
|
||||
if (!rc) {
|
||||
char buf[SYS_NMLN];
|
||||
stpcpy(buf, "Cosmopolitan 3.0-alpha");
|
||||
if (*MODE) {
|
||||
strlcat(buf, " MODE=" MODE, SYS_NMLN);
|
||||
}
|
||||
if (*uts->version) {
|
||||
strlcat(buf, "; ", SYS_NMLN);
|
||||
strlcat(buf, uts->version, SYS_NMLN);
|
||||
}
|
||||
strlcpy(uts->version, buf, SYS_NMLN);
|
||||
}
|
||||
STRACE("uname([{%#s, %#s, %#s, %#s, %#s, %#s}]) → %d% m",
|
||||
Str(rc, uts->sysname), Str(rc, uts->nodename), Str(rc, uts->release),
|
||||
Str(rc, uts->version), Str(rc, uts->machine), Str(rc, uts->domainname),
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bsr.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
@ -60,7 +59,6 @@ int __cxa_atexit(void *fp, void *arg, void *pred) {
|
|||
}
|
||||
}
|
||||
i = _bsr(~b->mask);
|
||||
unassert(i < ARRAYLEN(b->p));
|
||||
b->mask |= 1u << i;
|
||||
b->p[i].fp = fp;
|
||||
b->p[i].arg = arg;
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/intrin/bsf.h"
|
||||
#include "libc/intrin/cxaatexit.internal.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
|
@ -60,7 +59,6 @@ StartOverLocked:
|
|||
if (!pred) {
|
||||
b2 = b->next;
|
||||
if (b2) {
|
||||
unassert(b != &__cxa_blocks.root);
|
||||
if (_weaken(free)) {
|
||||
_weaken(free)(b);
|
||||
}
|
||||
|
|
|
@ -17,14 +17,12 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/atomic.h"
|
||||
#include "libc/intrin/strace.internal.h"
|
||||
#include "libc/intrin/weaken.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "libc/thread/tls.h"
|
||||
#include "third_party/nsync/mu.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef _WCHAR_H
|
||||
#define _WCHAR_H
|
||||
#include "libc/fmt/conv.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/str/unicode.h"
|
||||
|
|
9
third_party/musl/grp.c
vendored
9
third_party/musl/grp.c
vendored
|
@ -25,11 +25,13 @@
|
|||
│ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │
|
||||
│ │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/calls/calls.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/limits.h"
|
||||
#include "libc/thread/thread.h"
|
||||
#include "third_party/musl/passwd.h"
|
||||
|
||||
|
@ -246,3 +248,10 @@ struct group *getgrnam(const char *name) {
|
|||
&g_getgrent->mem, &nmem, &res);
|
||||
return res;
|
||||
}
|
||||
|
||||
int initgroups(const char *user, gid_t gid) {
|
||||
gid_t groups[NGROUPS_MAX];
|
||||
int count = NGROUPS_MAX;
|
||||
if (getgrouplist(user, gid, groups, &count) < 0) return -1;
|
||||
return setgroups(count, groups);
|
||||
}
|
||||
|
|
2
third_party/musl/passwd.h
vendored
2
third_party/musl/passwd.h
vendored
|
@ -43,7 +43,7 @@ void setgrent(void);
|
|||
struct group *fgetgrent(struct FILE *);
|
||||
int putgrent(const struct group *, struct FILE *);
|
||||
int getgrouplist(const char *, gid_t, gid_t *, int *);
|
||||
int initgroups(const char *, int32_t);
|
||||
int initgroups(const char *, gid_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
Loading…
Reference in a new issue