mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-22 21:32:31 +00:00
Initial import
This commit is contained in:
commit
c91b3c5006
14915 changed files with 590219 additions and 0 deletions
73
examples/printargs.c
Normal file
73
examples/printargs.c
Normal file
|
@ -0,0 +1,73 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/bits/progn.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
|
||||
const struct AuxiliaryValue {
|
||||
const char *fmt;
|
||||
long *id;
|
||||
const char *name;
|
||||
const char *description;
|
||||
} kAuxiliaryValues[] = {
|
||||
{"%p", &AT_EXECFD, "AT_EXECFD", "file descriptor of program"},
|
||||
{"%p", &AT_PHDR, "AT_PHDR", "address of elf program headers"},
|
||||
{"%p", &AT_PHENT, "AT_PHENT", "size of program header entry"},
|
||||
{"%p", &AT_PHNUM, "AT_PHNUM", "number of program headers"},
|
||||
{"%p", &AT_PAGESZ, "AT_PAGESZ", "system page size"},
|
||||
{"%p", &AT_BASE, "AT_BASE", "base address of the program interpreter"},
|
||||
{"%p", &AT_ENTRY, "AT_ENTRY", "entry address of executable"},
|
||||
{"%p", &AT_NOTELF, "AT_NOTELF", "set if not an elf"},
|
||||
{"%-12d", &AT_UID, "AT_UID", "real user id of thread"},
|
||||
{"%-12d", &AT_EUID, "AT_EUID", "effective user id of thread"},
|
||||
{"%-12d", &AT_GID, "AT_GID", "real group id of thread"},
|
||||
{"%-12d", &AT_EGID, "AT_EGID", "effective group id of thread"},
|
||||
{"%-12d", &AT_CLKTCK, "AT_CLKTCK", "frequency of times() counts"},
|
||||
{"%p", &AT_OSRELDATE, "AT_OSRELDATE",
|
||||
"freebsd release number, e.g. 1200086"},
|
||||
{"%p", &AT_PLATFORM, "AT_PLATFORM", "string identifying hardware platform"},
|
||||
{"%p", &AT_DCACHEBSIZE, "AT_DCACHEBSIZE", "data cache block size"},
|
||||
{"%p", &AT_ICACHEBSIZE, "AT_ICACHEBSIZE", "instruction cache block size"},
|
||||
{"%p", &AT_UCACHEBSIZE, "AT_UCACHEBSIZE", "unified cache block size"},
|
||||
{"%p", &AT_SECURE, "AT_SECURE", "for set{u,g}id binz & security blankets"},
|
||||
{"%-12s", &AT_BASE_PLATFORM, "AT_BASE_PLATFORM",
|
||||
"string identifying real platform"},
|
||||
{"%p", &AT_RANDOM, "AT_RANDOM", "address of sixteen random bytes"},
|
||||
{"%-12s", &AT_EXECFN, "AT_EXECFN", "pathname used to execute program"},
|
||||
{"%p", &AT_SYSINFO_EHDR, "AT_SYSINFO_EHDR",
|
||||
"linux virtual dso page address"},
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[], char **envp) {
|
||||
printf("\nArguments:\n");
|
||||
for (unsigned i = 0; i < argc; ++i) {
|
||||
printf(" ☼ %s\n", argv[i]);
|
||||
}
|
||||
printf("\nEnvironment:\n");
|
||||
for (char **env = envp; *env; ++env) {
|
||||
printf(" ☼ %s\n", *env);
|
||||
}
|
||||
printf("\nAuxiliary Values:\n");
|
||||
for (unsigned i = 0; i < ARRAYLEN(kAuxiliaryValues); ++i) {
|
||||
long key = *kAuxiliaryValues[i].id;
|
||||
unsigned long val = getauxval(key);
|
||||
char fmt[64];
|
||||
printf(PROGN(stpcpy(stpcpy(stpcpy(fmt, "%16s[%p] = "),
|
||||
kAuxiliaryValues[i].fmt),
|
||||
" # %s\n"),
|
||||
fmt),
|
||||
kAuxiliaryValues[i].name, key, val, kAuxiliaryValues[i].description);
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue