Replace COSMO define with _COSMO_SOURCE

This change might cause ABI breakages for /opt/cosmos. It's needed to
help us better conform to header declaration practices.
This commit is contained in:
Justine Tunney 2023-08-13 20:31:27 -07:00
parent a033b65a33
commit c776a32f75
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
238 changed files with 858 additions and 1069 deletions

View file

@ -398,8 +398,13 @@ static void Pwrite(const void *data, size_t size, uint64_t offset) {
static void LogElfPhdrs(FILE *f, Elf64_Phdr *p, size_t n) {
size_t i;
fprintf(f, "Type Offset VirtAddr PhysAddr "
"FileSiz MemSiz Flg Align\n");
fprintf(f, "Type "
"Offset "
"VirtAddr "
"PhysAddr "
"FileSiz "
"MemSiz "
"Flg Align\n");
for (i = 0; i < n; ++i) {
fprintf(f,
"%-14s 0x%06lx 0x%016lx 0x%016lx 0x%06lx 0x%06lx %c%c%c 0x%04lx\n",
@ -412,8 +417,13 @@ static void LogElfPhdrs(FILE *f, Elf64_Phdr *p, size_t n) {
static void LogPeSections(FILE *f, struct NtImageSectionHeader *p, size_t n) {
size_t i;
fprintf(f, "Name Offset RelativeVirtAddr PhysAddr "
"FileSiz MemSiz Flg\n");
fprintf(f, "Name "
"Offset "
"RelativeVirtAddr "
"PhysAddr "
"FileSiz "
"MemSiz "
"Flg\n");
for (i = 0; i < n; ++i) {
fprintf(f, "%-14.8s 0x%06lx 0x%016lx 0x%016lx 0x%06lx 0x%06lx %c%c%c\n",
p[i].Name, p[i].PointerToRawData, p[i].VirtualAddress,

View file

@ -351,8 +351,8 @@ int main(int argc, char *argv[]) {
struct stat st;
const char *arg;
if (!(arg = getargs_next(&ga))) break;
if (_endswith(arg, "/")) continue;
if (_endswith(arg, ".pkg")) continue;
if (endswith(arg, "/")) continue;
if (endswith(arg, ".pkg")) continue;
if (stat(arg, &st)) SysDie(arg, "stat");
if (S_ISDIR(st.st_mode)) continue;
if (!st.st_size) Die(arg, "file is empty");

View file

@ -412,16 +412,16 @@ bool IsGccOnlyFlag(const char *s) {
return true;
}
}
if (_startswith(s, "-ffixed-")) return true;
if (_startswith(s, "-fcall-saved")) return true;
if (_startswith(s, "-fcall-used")) return true;
if (_startswith(s, "-fgcse-")) return true;
if (_startswith(s, "-fvect-cost-model=")) return true;
if (_startswith(s, "-fsimd-cost-model=")) return true;
if (_startswith(s, "-fopt-info")) return true;
if (_startswith(s, "-mstringop-strategy=")) return true;
if (_startswith(s, "-mpreferred-stack-boundary=")) return true;
if (_startswith(s, "-Wframe-larger-than=")) return true;
if (startswith(s, "-ffixed-")) return true;
if (startswith(s, "-fcall-saved")) return true;
if (startswith(s, "-fcall-used")) return true;
if (startswith(s, "-fgcse-")) return true;
if (startswith(s, "-fvect-cost-model=")) return true;
if (startswith(s, "-fsimd-cost-model=")) return true;
if (startswith(s, "-fopt-info")) return true;
if (startswith(s, "-mstringop-strategy=")) return true;
if (startswith(s, "-mpreferred-stack-boundary=")) return true;
if (startswith(s, "-Wframe-larger-than=")) return true;
return false;
}
@ -454,7 +454,7 @@ void AddEnv(char *s) {
}
char *StripPrefix(char *s, char *p) {
if (_startswith(s, p)) {
if (startswith(s, p)) {
return s + strlen(p);
} else {
return s;
@ -478,18 +478,18 @@ void AddArg(char *actual) {
appendw(&shortened, ' ');
if ((isar || isbfd || ispkg) &&
(strcmp(args.p[args.n - 1], "-o") &&
(_endswith(s, ".o") || _endswith(s, ".pkg") ||
(_endswith(s, ".a") && !isar)))) {
(endswith(s, ".o") || endswith(s, ".pkg") ||
(endswith(s, ".a") && !isar)))) {
appends(&shortened, basename(s));
} else {
appends(&shortened, s);
}
} else if (/*
* a in ('-', '--') or
* a._startswith('-o') or
* a.startswith('-o') or
* c == 'ld' and a == '-T' or
* c == 'cc' and a._startswith('-O') or
* c == 'cc' and a._startswith('-x') or
* c == 'cc' and a.startswith('-O') or
* c == 'cc' and a.startswith('-x') or
* c == 'cc' and a in ('-c', '-E', '-S')
*/
s[0] == '-' && (!s[1] || s[1] == 'o' || (s[1] == '-' && !s[2]) ||
@ -984,7 +984,7 @@ int main(int argc, char *argv[]) {
/*
* capture flags
*/
if (_startswith(argv[i], "-o")) {
if (startswith(argv[i], "-o")) {
if (!strcmp(argv[i], "-o")) {
outpath = argv[++i];
} else {
@ -1174,27 +1174,27 @@ int main(int argc, char *argv[]) {
if (isgcc && ccversion >= 6) no_sanitize_alignment = true;
} else if (!strcmp(argv[i], "-fno-sanitize=pointer-overflow")) {
if (isgcc && ccversion >= 6) no_sanitize_pointer_overflow = true;
} else if (_startswith(argv[i], "-fsanitize=implicit") &&
} else if (startswith(argv[i], "-fsanitize=implicit") &&
strstr(argv[i], "integer")) {
if (isgcc) AddArg(argv[i]);
} else if (strstr(argv[i], "stack-protector")) {
if (isclang || (isgcc && ccversion >= 6)) {
AddArg(argv[i]);
}
} else if (_startswith(argv[i], "-fvect-cost") ||
_startswith(argv[i], "-mstringop") ||
_startswith(argv[i], "-gz") || strstr(argv[i], "sanitize") ||
_startswith(argv[i], "-fvect-cost") ||
_startswith(argv[i], "-fvect-cost")) {
} else if (startswith(argv[i], "-fvect-cost") ||
startswith(argv[i], "-mstringop") ||
startswith(argv[i], "-gz") || strstr(argv[i], "sanitize") ||
startswith(argv[i], "-fvect-cost") ||
startswith(argv[i], "-fvect-cost")) {
if (isgcc && ccversion >= 6) {
AddArg(argv[i]);
}
} else if (_startswith(argv[i], "-fdiagnostic-color=")) {
} else if (startswith(argv[i], "-fdiagnostic-color=")) {
colorflag = argv[i];
} else if (_startswith(argv[i], "-R") ||
} else if (startswith(argv[i], "-R") ||
!strcmp(argv[i], "-fsave-optimization-record")) {
if (isclang) AddArg(argv[i]);
} else if (isclang && _startswith(argv[i], "--debug-prefix-map")) {
} else if (isclang && startswith(argv[i], "--debug-prefix-map")) {
/* llvm doesn't provide a gas interface so simulate w/ clang */
AddArg(xstrcat("-f", argv[i] + 2));
} else if (isgcc && (!strcmp(argv[i], "-Os") || !strcmp(argv[i], "-O2") ||
@ -1279,7 +1279,7 @@ int main(int argc, char *argv[]) {
* scrub environment for determinism and great justice
*/
for (envp = environ; *envp; ++envp) {
if (_startswith(*envp, "MODE=")) {
if (startswith(*envp, "MODE=")) {
mode = *envp + 5;
}
if (IsSafeEnv(*envp)) {

View file

@ -27,6 +27,7 @@
#include "libc/intrin/kprintf.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/ftw.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
@ -37,7 +38,6 @@
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"
#include "third_party/getopt/getopt.internal.h"
#include "libc/stdio/ftw.h"
#define USAGE \
" SRC... DST\n\
@ -130,7 +130,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag,
strcpy(srcfile, fpath);
src = srcfile + striplen;
strcpy(dstfile, dstdir);
if (!_endswith(dstfile, "/")) {
if (!endswith(dstfile, "/")) {
strcat(dstfile, "/");
}
strcat(dstfile, src);

View file

@ -624,7 +624,7 @@ static bool ParseDllImportSymbol(const char *symbol_name,
size_t n;
char *dll_name;
const char *dolla;
if (!_startswith(symbol_name, "dll$")) return false;
if (!startswith(symbol_name, "dll$")) return false;
symbol_name += 4;
dolla = strchr(symbol_name, '$');
if (!dolla) return false;

View file

@ -54,8 +54,8 @@ int main(int argc, char *argv[]) {
if (!l1 && !l2) {
exit(0);
}
if (l1) _chomp(l1);
if (l2) _chomp(l2);
if (l1) chomp(l1);
if (l2) chomp(l2);
if (!l1 || !l2) {
printf("> %s\n", l1 ? l1 : "EOF");
printf("< %s\n", l2 ? l2 : "EOF");

View file

@ -234,7 +234,7 @@ void Decompress(const char *inpath) {
if (opt_usestdout) {
output = stdout;
outpath = "/dev/stdout";
} else if (_endswith(inpath, ".gz")) {
} else if (endswith(inpath, ".gz")) {
n = strlen(inpath);
if (n - 3 + 1 > PATH_MAX) _Exit(2);
memcpy(pathbuf, inpath, n - 3);

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/macros.internal.h"
@ -24,7 +25,6 @@
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "libc/errno.h"
#include "third_party/getopt/getopt.internal.h"
#define USAGE \
@ -331,7 +331,7 @@ void HandleOperand(const char *op) {
while (*op) {
found = false;
for (i = 0; i < ARRAYLEN(kDescriptors); ++i) {
if (_startswith(op, kDescriptors[i].prefix)) {
if (startswith(op, kDescriptors[i].prefix)) {
found = true;
op += strlen(kDescriptors[i].prefix);
if (succinct_) {

View file

@ -53,7 +53,7 @@ void AppendWide(struct Buffer *b, wint_t wc) {
uint64_t wb;
char buf[8];
i = 0;
wb = _tpenc(wc);
wb = tpenc(wc);
do {
buf[i++] = wb & 0xFF;
wb >>= 8;

View file

@ -115,7 +115,7 @@ char *Demangle(char *p, const char *symbol, size_t n) {
char *r;
size_t sn;
sn = strlen(symbol);
if (_startswith(symbol, "_Z")) {
if (startswith(symbol, "_Z")) {
if ((r = DemangleCxxFilt(p, n, symbol, sn))) return r;
}
return CopySymbol(p, n, symbol, sn);

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/build/lib/javadown.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/build/lib/javadown.h"
#define FILEOVERVIEW "@fileoverview"
@ -122,7 +122,7 @@ static void SplitLines(struct Lines *lines, char *p) {
static bool ConsumeFileOverview(struct Lines *lines) {
int i;
if (lines->n && lines->p[0].n >= strlen(FILEOVERVIEW) &&
_startswith(lines->p[0].p, FILEOVERVIEW)) {
startswith(lines->p[0].p, FILEOVERVIEW)) {
lines->p[0].p += strlen(FILEOVERVIEW);
lines->p[0].n -= strlen(FILEOVERVIEW);
while (lines->p[0].n &&

View file

@ -34,7 +34,7 @@ bool ParseSupportVector(char *str, int *out_bits) {
char *tok, *state;
const char *sep = " ,+:/|";
while ((tok = strtok_r(str, sep, &state))) {
if (_startswithi(tok, "_HOST")) {
if (startswithi(tok, "_host")) {
tok += 5;
}
if (!strcasecmp(tok, "linux")) {

View file

@ -362,7 +362,7 @@ static const char *StripExt(char pathbuf[PATH_MAX + 1], const char *s) {
static bool IsObjectSource(const char *name) {
int i;
for (i = 0; i < ARRAYLEN(kSourceExts); ++i) {
if (_endswith(name, kSourceExts[i])) return true;
if (endswith(name, kSourceExts[i])) return true;
}
return false;
}
@ -399,7 +399,7 @@ static char *Explore(void) {
path = names + sauces[i].name;
if (!IsObjectSource(path)) continue;
Appendw(&makefile, '\n');
if (!_startswith(path, "o/")) {
if (!startswith(path, "o/")) {
Appends(&makefile, buildroot);
}
Appends(&makefile, StripExt(buf, path));

View file

@ -25,6 +25,7 @@
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/mem/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/ftw.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/at.h"
@ -32,7 +33,6 @@
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"
#include "third_party/getopt/getopt.internal.h"
#include "libc/stdio/ftw.h"
#define USAGE \
" SRC... DST\n\
@ -126,7 +126,7 @@ int Visit(const char *fpath, const struct stat *sb, int tflag,
strcpy(srcfile, fpath);
src = srcfile + striplen;
strcpy(dstfile, dstdir);
if (!_endswith(dstfile, "/")) {
if (!endswith(dstfile, "/")) {
strcat(dstfile, "/");
}
strcat(dstfile, src);

View file

@ -97,13 +97,13 @@ void Visit(const char *path) {
char *map;
size_t size;
bool isheader;
if (!_endswith(path, ".h") && !_endswith(path, ".inc")) return;
if (_endswith(path, ".internal.h")) return;
if (_endswith(path, "/internal.h")) return;
if (_endswith(path, ".internal.inc")) return;
if (_endswith(path, "/internal.inc")) return;
if (_startswith(path, "libc/isystem/")) return;
isheader = _endswith(path, ".h");
if (!endswith(path, ".h") && !endswith(path, ".inc")) return;
if (endswith(path, ".internal.h")) return;
if (endswith(path, "/internal.h")) return;
if (endswith(path, ".internal.inc")) return;
if (endswith(path, "/internal.inc")) return;
if (startswith(path, "libc/isystem/")) return;
isheader = endswith(path, ".h");
if (isheader && isinterned(visited, path)) return;
appends(&output, "\n\f\n/*!BEGIN ");
appends(&output, path);

View file

@ -231,7 +231,7 @@ void StartTcpServer(void) {
printf("ready %hu\n", ntohs(g_servaddr.sin_port));
fflush(stdout);
fclose(stdout);
dup2(g_bogusfd, stdout->fd);
dup2(g_bogusfd, fileno(stdout));
}
}
@ -573,8 +573,8 @@ void Daemonize(void) {
if (fork() > 0) _exit(0);
setsid();
if (fork() > 0) _exit(0);
dup2(g_bogusfd, stdin->fd);
if (!g_sendready) dup2(g_bogusfd, stdout->fd);
dup2(g_bogusfd, fileno(stdin));
if (!g_sendready) dup2(g_bogusfd, fileno(stdout));
freopen(kLogFile, "ae", stderr);
if (fstat(fileno(stderr), &st) != -1 && st.st_size > kLogMaxBytes) {
ftruncate(fileno(stderr), 0);

View file

@ -151,7 +151,7 @@ static bool CheckDigests(const char *path, FILE *f) {
unsigned char wantdigest[32], gotdigest[32];
char buf[64 + 2 + PATH_MAX + 1 + 1], *p;
for (line = 0; fgets(buf, sizeof(buf), f); ++line) {
if (!*_chomp(buf)) continue;
if (!*chomp(buf)) continue;
for (p = buf, i = 0; i < 32; ++i) {
if ((a = kHexToInt[*p++ & 255]) == -1) goto InvalidLine;
if ((b = kHexToInt[*p++ & 255]) == -1) goto InvalidLine;

View file

@ -23,11 +23,11 @@
#include "libc/fmt/itoa.h"
#include "libc/fmt/magnumstrs.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/ftw.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/s.h"
#include "libc/x/x.h"
#include "libc/stdio/ftw.h"
const char *prog;
char tmpdir[PATH_MAX];
@ -59,12 +59,12 @@ void Execute(char *argv[]) {
int Visit(const char *fpath, const struct stat *sb, int tflag,
struct FTW *ftwbuf) {
if (tflag == FTW_F && _endswith(fpath, ".gz")) {
if (tflag == FTW_F && endswith(fpath, ".gz")) {
Execute((char *[]){"build/bootstrap/gzip.com", "-d", fpath, 0});
strcpy(binpath, fpath);
binpath[strlen(binpath) - 3] = 0;
chmod(binpath, 0755);
} else if (tflag == FTW_F && _endswith(fpath, ".sym")) {
} else if (tflag == FTW_F && endswith(fpath, ".sym")) {
strcpy(binpath, fpath);
binpath[strlen(binpath) - 4] = 0;
symlink(xslurp(fpath, 0), binpath);

View file

@ -20,6 +20,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/elf/def.h"
#include "libc/errno.h"
#include "libc/fmt/conv.h"
#include "libc/fmt/libgen.h"
#include "libc/limits.h"
@ -40,7 +41,6 @@
#include "libc/zip.internal.h"
#include "third_party/getopt/getopt.internal.h"
#include "tool/build/lib/elfwriter.h"
#include "libc/errno.h"
#include "tool/build/lib/stripcomponents.h"
char *name_;
@ -173,7 +173,7 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
}
if (S_ISDIR(st.st_mode)) {
st.st_size = 0;
if (!_endswith(name, "/")) {
if (!endswith(name, "/")) {
name = gc(xstrcat(name, '/'));
}
}
@ -194,7 +194,7 @@ void PullEndOfCentralDirectoryIntoLinkage(struct ElfWriter *elf) {
void CheckFilenameKosher(const char *path) {
CHECK_LE(kZipCfileHdrMinSize + strlen(path), 65535);
CHECK(!_startswith(path, "/"));
CHECK(!startswith(path, "/"));
CHECK(!strstr(path, ".."));
}