2021-02-22 00:26:36 +00:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
2023-12-08 03:11:56 +00:00
|
|
|
│ vi: set et ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi │
|
2020-06-15 14:18:57 +00:00
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
2021-02-22 00:26:36 +00:00
|
|
|
│ Copyright 2021 Justine Alexandra Roberts Tunney │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ 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. │
|
2020-06-15 14:18:57 +00:00
|
|
|
│ │
|
2020-12-28 01:18:44 +00:00
|
|
|
│ 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. │
|
2020-06-15 14:18:57 +00:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2022-08-13 20:11:56 +00:00
|
|
|
#include "libc/calls/struct/stat.h"
|
|
|
|
#include "libc/calls/struct/stat.internal.h"
|
2022-05-12 13:43:59 +00:00
|
|
|
#include "libc/dce.h"
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
#include "libc/intrin/kprintf.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2022-10-10 14:36:07 +00:00
|
|
|
#define N 300
|
|
|
|
|
2022-10-16 19:05:08 +00:00
|
|
|
#define append(...) o += ksnprintf(buf + o, N - o, __VA_ARGS__)
|
2022-10-10 14:36:07 +00:00
|
|
|
|
2024-08-25 01:10:22 +00:00
|
|
|
const char *_DescribeStat(char buf[N], int rc, const struct stat *st) {
|
2022-10-16 19:05:08 +00:00
|
|
|
int o = 0;
|
2022-05-12 13:43:59 +00:00
|
|
|
|
Apply clang-format update to repo (#1154)
Commit bc6c183 introduced a bunch of discrepancies between what files
look like in the repo and what clang-format says they should look like.
However, there were already a few discrepancies prior to that. Most of
these discrepancies seemed to be unintentional, but a few of them were
load-bearing (e.g., a #include that violated header ordering needing
something to have been #defined by a 'later' #include.)
I opted to take what I hope is a relatively smooth-brained approach: I
reverted the .clang-format change, ran clang-format on the whole repo,
reapplied the .clang-format change, reran clang-format again, and then
reverted the commit that contained the first run. Thus the full effect
of this PR should only be to apply the changed formatting rules to the
repo, and from skimming the results, this seems to be the case.
My work can be checked by applying the short, manual commits, and then
rerunning the command listed in the autogenerated commits (those whose
messages I have prefixed auto:) and seeing if your results agree.
It might be that the other diffs should be fixed at some point but I'm
leaving that aside for now.
fd '\.c(c|pp)?$' --print0| xargs -0 clang-format -i
2024-04-25 17:38:00 +00:00
|
|
|
if (rc == -1)
|
|
|
|
return "n/a";
|
|
|
|
if (!st)
|
|
|
|
return "NULL";
|
2024-06-22 12:45:49 +00:00
|
|
|
if (kisdangerous(st)) {
|
2022-10-10 14:36:07 +00:00
|
|
|
ksnprintf(buf, N, "%p", st);
|
2022-05-12 13:43:59 +00:00
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2022-10-10 14:36:07 +00:00
|
|
|
append("{.st_%s=%'ld", "size", st->st_size);
|
2022-05-12 13:43:59 +00:00
|
|
|
|
|
|
|
if (st->st_blocks) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_blocks=%'lu/512", st->st_blocks * 512);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_mode) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%#o", "mode", st->st_mode);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_nlink != 1) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%'lu", "nlink", st->st_nlink);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_uid) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%lu", "uid", st->st_uid);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_gid) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%lu", "gid", st->st_gid);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-16 19:05:08 +00:00
|
|
|
if (st->st_dev) {
|
2023-10-14 08:06:00 +00:00
|
|
|
append(", .st_%s=%#lx", "dev", st->st_dev);
|
2022-10-16 19:05:08 +00:00
|
|
|
}
|
|
|
|
|
2022-05-12 13:43:59 +00:00
|
|
|
if (st->st_ino) {
|
2023-10-14 08:06:00 +00:00
|
|
|
append(", .st_%s=%#lx", "ino", st->st_ino);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_gen) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%'lu", "gen", st->st_gen);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_flags) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%lx", "flags", st->st_flags);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (st->st_rdev) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%'lu", "rdev", st->st_rdev);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
2023-07-30 01:44:15 +00:00
|
|
|
if (st->st_blksize != 4096) {
|
2022-10-10 14:36:07 +00:00
|
|
|
append(", .st_%s=%'lu", "blksize", st->st_blksize);
|
2022-05-12 13:43:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-10 14:36:07 +00:00
|
|
|
append("}");
|
2022-05-12 13:43:59 +00:00
|
|
|
|
Introduce --strace flag for system call tracing
This is similar to the --ftrace (c function call trace) flag, except
it's less noisy since it only logs system calls to stderr. Having this
flag is valuable because (1) system call tracing tells us a lot about
the behavior of complex programs and (2) it's usually very hard to get
system call tracing on various operating systems, e.g. strace, ktrace,
dtruss, truss, nttrace, etc. Especially on Apple platforms where even
with the special boot trick, debuggers still aren't guaranteed to work.
make -j8 o//examples
o//examples/hello.com --strace
This is enabled by default in MODE=, MODE=opt, and MODE=dbg. In MODE=dbg
extra information will be printed.
make -j8 MODE=dbg o/dbg/examples
o/dbg/examples/hello.com --strace |& less
This change also changes:
- Rename IsText() → _istext()
- Rename IsUtf8() → _isutf8()
- Fix madvise() on Windows NT
- Fix empty string case of inet_ntop()
- vfork() wrapper now saves and restores errno
- Update xsigaction() to yoink syscall support
2022-03-19 01:07:28 +00:00
|
|
|
return buf;
|
2021-02-24 04:23:19 +00:00
|
|
|
}
|