mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-12 05:59:10 +00:00
Improve isystem includes and magic numbers
This commit is contained in:
parent
1e5bd4d23e
commit
228fb7428b
143 changed files with 1183 additions and 266 deletions
|
@ -151,6 +151,7 @@ int posix_fadvise(int, uint64_t, uint64_t, int);
|
|||
int posix_madvise(void *, uint64_t, int);
|
||||
int prctl();
|
||||
int raise(int);
|
||||
int reboot(int);
|
||||
int readlink(const char *, char *, size_t);
|
||||
int remove(const char *);
|
||||
int rename(const char *, const char *);
|
||||
|
|
|
@ -41,10 +41,11 @@ LIBC_CALLS_A_DIRECTDEPS = \
|
|||
LIBC_INTRIN \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_NT_ADVAPI32 \
|
||||
LIBC_NT_IPHLPAPI \
|
||||
LIBC_NT_KERNEL32 \
|
||||
LIBC_NT_NTDLL \
|
||||
LIBC_NT_POWERPROF \
|
||||
LIBC_NT_WS2_32 \
|
||||
LIBC_NT_IPHLPAPI \
|
||||
LIBC_STR \
|
||||
LIBC_STUBS \
|
||||
LIBC_SYSV_CALLS \
|
||||
|
|
28
libc/calls/ftok.c
Normal file
28
libc/calls/ftok.c
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*-*- 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 2021 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/calls.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
#include "libc/calls/weirdtypes.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
int ftok(const char *path, int id) {
|
||||
struct stat st;
|
||||
if (stat(path, &st) == -1) return -1;
|
||||
return (uint32_t)id << 24 | (st.st_dev & 0xff) << 16 | (st.st_ino & 0xffff);
|
||||
}
|
20
libc/calls/ipc.h
Normal file
20
libc/calls/ipc.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_IPC_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_IPC_H_
|
||||
|
||||
#define IPC_PRIVATE 0
|
||||
#define IPC_RMID 0
|
||||
#define IPC_SET 1
|
||||
#define IPC_STAT 2
|
||||
#define IPC_INFO 3
|
||||
#define IPC_CREAT 01000
|
||||
#define IPC_EXCL 02000
|
||||
#define IPC_NOWAIT 04000
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int ftok(const char *, int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_IPC_H_ */
|
100
libc/calls/mount.c
Normal file
100
libc/calls/mount.c
Normal file
|
@ -0,0 +1,100 @@
|
|||
/*-*- 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 2021 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/mount.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
int32_t sys_mount_linux(const char *source, const char *target,
|
||||
const char *filesystemtype, uint64_t mountflags,
|
||||
const void *data) asm("sys_mount");
|
||||
int32_t sys_mount_bsd(const char *type, const char *dir, int32_t flags,
|
||||
void *data) asm("sys_mount");
|
||||
|
||||
/**
|
||||
* Mounts file system.
|
||||
*
|
||||
* The following flags may be specified:
|
||||
*
|
||||
* - `MS_RDONLY` (mount read-only)
|
||||
* - `MS_NOSUID` (don't honor S_ISUID bit)
|
||||
* - `MS_NODEV` (disallow special files)
|
||||
* - `MS_NOEXEC` (disallow program execution)
|
||||
* - `MS_SYNCHRONOUS` (writes are synced at once)
|
||||
* - `MS_NOATIME` (do not update access times)
|
||||
* - `MS_REMOUNT` (tune existing mounting)
|
||||
*
|
||||
* The following flags may also be used, but could be set to zero at
|
||||
* runtime if the underlying kernel doesn't support them.
|
||||
*
|
||||
* - `MNT_ASYNC` (xnu, freebsd, openbsd, netbsd)
|
||||
* - `MNT_RELOAD` (xnu, freebsd, openbsd, netbsd)
|
||||
* - `MS_STRICTATIME` (linux, xnu)
|
||||
* - `MS_RELATIME` (linux, netbsd)
|
||||
* - `MNT_SNAPSHOT` (xnu, freebsd)
|
||||
* - `MS_MANDLOCK` (linux)
|
||||
* - `MS_DIRSYNC` (linux)
|
||||
* - `MS_NODIRATIME` (linux)
|
||||
* - `MS_BIND` (linux)
|
||||
* - `MS_MOVE` (linux)
|
||||
* - `MS_REC` (linux)
|
||||
* - `MS_SILENT` (linux)
|
||||
* - `MS_POSIXACL` (linux)
|
||||
* - `MS_UNBINDABLE` (linux)
|
||||
* - `MS_PRIVATE` (linux)
|
||||
* - `MS_SLAVE` (linux)
|
||||
* - `MS_SHARED` (linux)
|
||||
* - `MS_KERNMOUNT` (linux)
|
||||
* - `MS_I_VERSION` (linux)
|
||||
* - `MS_LAZYTIME` (linux)
|
||||
* - `MS_ACTIVE` (linux)
|
||||
* - `MS_NOUSER` (linux)
|
||||
* - `MS_RMT`_MASK (linux)
|
||||
* - `MNT_SUIDDIR` (freebsd)
|
||||
* - `MNT_NOCLUSTERR` (freebsd)
|
||||
* - `MNT_NOCLUSTERW` (freebsd)
|
||||
*
|
||||
* Some example values for the `type` parameter:
|
||||
*
|
||||
* - `"nfs"`
|
||||
* - `"vfat"`
|
||||
* - `"tmpfs"`
|
||||
* - `"iso8601"`
|
||||
*
|
||||
*/
|
||||
int mount(const char *source, const char *target, const char *type,
|
||||
unsigned long flags, const void *data) {
|
||||
if (!IsWindows()) {
|
||||
if (!IsBsd()) {
|
||||
return sys_mount_linux(source, target, type, flags, data);
|
||||
} else {
|
||||
if (!strcmp(type, "iso9660")) type = "cd9660";
|
||||
if (!strcmp(type, "vfat")) {
|
||||
if (IsOpenbsd() || IsNetbsd()) {
|
||||
type = "msdos";
|
||||
} else {
|
||||
type = "msdosfs";
|
||||
}
|
||||
}
|
||||
return sys_mount_bsd(type, target, flags, data);
|
||||
}
|
||||
} else {
|
||||
return enosys();
|
||||
}
|
||||
}
|
17
libc/calls/mount.h
Normal file
17
libc/calls/mount.h
Normal file
|
@ -0,0 +1,17 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_MOUNT_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int mount(const char *, const char *, const char *, unsigned long,
|
||||
const void *);
|
||||
int unmount(const char *, int);
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
int umount(const char *);
|
||||
int umount2(const char *, int);
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_MOUNT_H_ */
|
93
libc/calls/reboot.c
Normal file
93
libc/calls/reboot.c
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*-*- 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 2021 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/calls.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/struct/framebuffervirtualscreeninfo.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nt/system.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
#define kNtShutdownForceOthers 1
|
||||
#define kNtShutdownForceSelf 2
|
||||
#define kNtShutdownGraceOverride 0x20
|
||||
#define kNtShutdownHybrid 0x200
|
||||
|
||||
int32_t sys_reboot_linux(int32_t, int32_t, int32_t) asm("sys_reboot");
|
||||
int32_t sys_reboot_bsd(int32_t, const char *) asm("sys_reboot");
|
||||
|
||||
/**
|
||||
* Reboots system.
|
||||
*
|
||||
* The `howto` argument may be one of the following:
|
||||
*
|
||||
* - `RB_AUTOBOOT`
|
||||
* - `RB_POWER_OFF`
|
||||
* - `RB_HALT_SYSTEM`
|
||||
* - `RB_SW_SUSPEND` (linux and windows only)
|
||||
* - `RB_KEXEC` (linux only)
|
||||
* - `RB_ENABLE_CAD` (linux only)
|
||||
* - `RB_DISABLE_CAD` (linux only)
|
||||
*
|
||||
* There's an implicit `sync()` operation before the reboot happens.
|
||||
* This can be prevented by or'ing `howto` with `RB_NOSYNC`. Setting
|
||||
* this option will also prevent apps on Windows from having time to
|
||||
* close themselves.
|
||||
*/
|
||||
int reboot(int howto) {
|
||||
bool ok, immediately;
|
||||
if (howto != -1) {
|
||||
if (!(howto & 0x20000000)) {
|
||||
sync();
|
||||
immediately = false;
|
||||
} else {
|
||||
howto &= ~0x20000000;
|
||||
immediately = true;
|
||||
}
|
||||
if (!IsWindows()) {
|
||||
if (IsLinux()) {
|
||||
return sys_reboot_linux(0xFEE1DEAD, 0x28121969, howto);
|
||||
} else {
|
||||
return sys_reboot_bsd(howto, 0);
|
||||
}
|
||||
} else {
|
||||
if (howto == 0xD000FCE2u) {
|
||||
ok = !!SetSuspendState(0, 0, 0);
|
||||
} else {
|
||||
howto |= kNtShutdownForceOthers;
|
||||
howto |= kNtShutdownForceSelf;
|
||||
if (NtGetVersion() >= 8) {
|
||||
howto |= kNtShutdownHybrid;
|
||||
}
|
||||
if (immediately) {
|
||||
ok = !!InitiateShutdown(0, 0, 0, howto | kNtShutdownGraceOverride, 0);
|
||||
} else {
|
||||
ok = !!InitiateShutdown(0, 0, 20, howto, 0);
|
||||
}
|
||||
}
|
||||
if (ok) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return einval();
|
||||
}
|
||||
}
|
33
libc/calls/ttydefaults.h
Normal file
33
libc/calls/ttydefaults.h
Normal file
|
@ -0,0 +1,33 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_
|
||||
#define COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_
|
||||
#include "libc/sysv/consts/baud.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
|
||||
#define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY)
|
||||
#define TTYDEF_OFLAG (OPOST | ONLCR | XTABS)
|
||||
#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE | ECHOKE | ECHOCTL)
|
||||
#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
|
||||
#define TTYDEF_SPEED (B9600)
|
||||
|
||||
#define CTRL(x) ((x) ^ 0100)
|
||||
#define CEOF CTRL('D')
|
||||
#define CERASE CTRL('?')
|
||||
#define CINTR CTRL('C')
|
||||
#define CKILL CTRL('U')
|
||||
#define CQUIT CTRL('\\')
|
||||
#define CSUSP CTRL('Z')
|
||||
#define CDSUSP CTRL('Y')
|
||||
#define CSTART CTRL('Q')
|
||||
#define CSTOP CTRL('S')
|
||||
#define CLNEXT CTRL('V')
|
||||
#define CDISCARD CTRL('O')
|
||||
#define CWERASE CTRL('W')
|
||||
#define CREPRINT CTRL('R')
|
||||
#define CEOT CEOF
|
||||
#define CBRK CEOL
|
||||
#define CRPRNT CREPRINT
|
||||
#define CFLUSH CDISCARD
|
||||
#define CMIN 1
|
||||
#define CTIME 0
|
||||
|
||||
#endif /* COSMOPOLITAN_LIBC_CALLS_TTYDEFAULTS_H_ */
|
41
libc/calls/unmount.c
Normal file
41
libc/calls/unmount.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-*- 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 2021 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/mount.h"
|
||||
|
||||
int sys_unmount(const char *, int);
|
||||
|
||||
/**
|
||||
* Unmounts file system.
|
||||
*
|
||||
* The following flags may be specified:
|
||||
*
|
||||
* - `MNT_FORCE`
|
||||
*
|
||||
* The following flags may also be used, but could be set to zero at
|
||||
* runtime if the underlying kernel doesn't support them.
|
||||
*
|
||||
* - `MNT_DETACH`
|
||||
* - `MNT_EXPIRE`
|
||||
* - `UMOUNT_NOFOLLOW`
|
||||
* - `MNT_BYFSID`
|
||||
*
|
||||
*/
|
||||
int unmount(const char *target, int flags) {
|
||||
return sys_unmount(target, flags);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue