mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-16 17:42:29 +00:00
Do code cleanup use duff device linenoise i/o
This commit is contained in:
parent
6ff46ca373
commit
2f56ebfe78
79 changed files with 1393 additions and 1484 deletions
|
@ -28,31 +28,30 @@
|
|||
#include "libc/sysv/consts/ok.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
static noasan bool IsExePath(const char *s, size_t n) {
|
||||
static bool IsExePath(const char *s, size_t n) {
|
||||
return n >= 4 && (READ32LE(s + n - 4) == READ32LE(".exe") ||
|
||||
READ32LE(s + n - 4) == READ32LE(".EXE"));
|
||||
}
|
||||
|
||||
static noasan bool IsComPath(const char *s, size_t n) {
|
||||
static bool IsComPath(const char *s, size_t n) {
|
||||
return n >= 4 && (READ32LE(s + n - 4) == READ32LE(".com") ||
|
||||
READ32LE(s + n - 4) == READ32LE(".COM"));
|
||||
}
|
||||
|
||||
static noasan bool IsComDbgPath(const char *s, size_t n) {
|
||||
static bool IsComDbgPath(const char *s, size_t n) {
|
||||
return n >= 8 && (READ64LE(s + n - 8) == READ64LE(".com.dbg") ||
|
||||
READ64LE(s + n - 8) == READ64LE(".COM.DBG"));
|
||||
}
|
||||
|
||||
static noasan bool AccessCommand(const char *name,
|
||||
char path[hasatleast PATH_MAX], size_t namelen,
|
||||
int *err, const char *suffix, size_t pathlen) {
|
||||
static bool AccessCommand(const char *name, char path[hasatleast PATH_MAX],
|
||||
size_t namelen, int *err, const char *suffix,
|
||||
size_t pathlen) {
|
||||
size_t suffixlen;
|
||||
suffixlen = strlen(suffix);
|
||||
if (pathlen + 1 + namelen + suffixlen + 1 > PATH_MAX) return false;
|
||||
if (pathlen && (path[pathlen - 1] != '/' && path[pathlen - 1] != '\\')) {
|
||||
path[pathlen] = !IsWindows() ? '/'
|
||||
: memchr(path, '\\', pathlen) ? '\\'
|
||||
: '/';
|
||||
path[pathlen] =
|
||||
!IsWindows() ? '/' : memchr(path, '\\', pathlen) ? '\\' : '/';
|
||||
pathlen++;
|
||||
}
|
||||
memcpy(path + pathlen, name, namelen);
|
||||
|
@ -62,8 +61,8 @@ static noasan bool AccessCommand(const char *name,
|
|||
return false;
|
||||
}
|
||||
|
||||
static noasan bool SearchPath(const char *name, char path[hasatleast PATH_MAX],
|
||||
size_t namelen, int *err, const char *suffix) {
|
||||
static bool SearchPath(const char *name, char path[hasatleast PATH_MAX],
|
||||
size_t namelen, int *err, const char *suffix) {
|
||||
char sep;
|
||||
size_t i;
|
||||
const char *p;
|
||||
|
@ -87,10 +86,9 @@ static noasan bool SearchPath(const char *name, char path[hasatleast PATH_MAX],
|
|||
return false;
|
||||
}
|
||||
|
||||
static noasan bool FindCommand(const char *name,
|
||||
char pathbuf[hasatleast PATH_MAX],
|
||||
size_t namelen, bool priorityonly,
|
||||
const char *suffix, int *err) {
|
||||
static bool FindCommand(const char *name, char pathbuf[hasatleast PATH_MAX],
|
||||
size_t namelen, bool priorityonly, const char *suffix,
|
||||
int *err) {
|
||||
if (priorityonly &&
|
||||
(memchr(name, '/', namelen) || memchr(name, '\\', namelen))) {
|
||||
pathbuf[0] = 0;
|
||||
|
@ -107,15 +105,13 @@ static noasan bool FindCommand(const char *name,
|
|||
SearchPath(name, pathbuf, namelen, err, suffix);
|
||||
}
|
||||
|
||||
static noasan bool FindVerbatim(const char *name,
|
||||
char pathbuf[hasatleast PATH_MAX],
|
||||
size_t namelen, bool priorityonly, int *err) {
|
||||
static bool FindVerbatim(const char *name, char pathbuf[hasatleast PATH_MAX],
|
||||
size_t namelen, bool priorityonly, int *err) {
|
||||
return FindCommand(name, pathbuf, namelen, priorityonly, "", err);
|
||||
}
|
||||
|
||||
static noasan bool FindSuffixed(const char *name,
|
||||
char pathbuf[hasatleast PATH_MAX],
|
||||
size_t namelen, bool priorityonly, int *err) {
|
||||
static bool FindSuffixed(const char *name, char pathbuf[hasatleast PATH_MAX],
|
||||
size_t namelen, bool priorityonly, int *err) {
|
||||
return !IsExePath(name, namelen) && !IsComPath(name, namelen) &&
|
||||
!IsComDbgPath(name, namelen) &&
|
||||
(FindCommand(name, pathbuf, namelen, priorityonly, ".com", err) ||
|
||||
|
@ -131,7 +127,7 @@ static noasan bool FindSuffixed(const char *name,
|
|||
* @asyncsignalsafe
|
||||
* @vforksafe
|
||||
*/
|
||||
noasan char *commandv(const char *name, char pathbuf[hasatleast PATH_MAX]) {
|
||||
char *commandv(const char *name, char pathbuf[hasatleast PATH_MAX]) {
|
||||
int e, f;
|
||||
char *res;
|
||||
size_t namelen;
|
||||
|
|
|
@ -73,7 +73,7 @@ int ioctl_tcgets(int fd, ...) {
|
|||
tio = va_arg(va, struct termios *);
|
||||
va_end(va);
|
||||
if (fd >= 0) {
|
||||
if (!tio) {
|
||||
if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) {
|
||||
rc = efault();
|
||||
} else if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||
rc = enotty();
|
||||
|
|
|
@ -68,7 +68,7 @@ int ioctl_tcsets(int fd, uint64_t request, ...) {
|
|||
va_start(va, request);
|
||||
tio = va_arg(va, const struct termios *);
|
||||
va_end(va);
|
||||
if (!tio) {
|
||||
if (!tio || (IsAsan() && !__asan_is_valid(tio, sizeof(*tio)))) {
|
||||
rc = efault();
|
||||
} else if (fd >= 0) {
|
||||
if (fd < g_fds.n && g_fds.p[fd].kind == kFdZip) {
|
||||
|
|
|
@ -29,7 +29,7 @@ errno_t ptsname_r(int fd, char *buf, size_t size) {
|
|||
if (size) {
|
||||
if (!buf) return einval();
|
||||
if (ioctl(fd, TIOCGPTN, &pty) == -1) return errno;
|
||||
int64toarray_radix10(pty, stpcpy(tb, "/dev/pts/"));
|
||||
FormatInt32(stpcpy(tb, "/dev/pts/"), pty);
|
||||
if (strlen(tb) + 1 >= size) return (errno = ERANGE);
|
||||
stpcpy(buf, tb);
|
||||
/* TODO(jart): OpenBSD OMG */
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
#include "libc/calls/struct/sigaction.h"
|
||||
#include "libc/calls/struct/stat.h"
|
||||
|
||||
#define _KERNTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _POLLTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _KERNTRACE 1 /* not configurable w/ flag yet */
|
||||
#define _POLLTRACE 1 /* not configurable w/ flag yet */
|
||||
#define _DATATRACE 1 /* not configurable w/ flag yet */
|
||||
#define _NTTRACE 0 /* not configurable w/ flag yet */
|
||||
#define _NTTRACE 1 /* not configurable w/ flag yet */
|
||||
|
||||
#define STRACE_PROLOGUE "%rSYS %5P %'18T "
|
||||
|
||||
|
|
|
@ -64,7 +64,7 @@ static int ttyname_linux(int fd, char *buf, size_t size) {
|
|||
struct stat st1, st2;
|
||||
if (!isatty(fd)) return errno;
|
||||
char name[PATH_MAX];
|
||||
int64toarray_radix10(fd, stpcpy(name, "/proc/self/fd/"));
|
||||
FormatInt32(stpcpy(name, "/proc/self/fd/"), fd);
|
||||
ssize_t got;
|
||||
got = readlink(name, buf, size);
|
||||
if (got == -1) return errno;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue