Skip to content

Commit 18a620c

Browse files
committed
Make some improvements of little consequence
1 parent 690d3df commit 18a620c

File tree

11 files changed

+92
-14
lines changed

11 files changed

+92
-14
lines changed

build/objdump

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ if [ -n "$OBJDUMP" ]; then
66
fi
77

88
find_objdump() {
9-
if [ -x .cosmocc/3.3.5/bin/$1-linux-cosmo-objdump ]; then
10-
OBJDUMP=.cosmocc/3.3.5/bin/$1-linux-cosmo-objdump
11-
elif [ -x .cosmocc/3.3.5/bin/$1-linux-musl-objdump ]; then
12-
OBJDUMP=.cosmocc/3.3.5/bin/$1-linux-musl-objdump
13-
elif [ -x "$COSMO/.cosmocc/3.3.5/bin/$1-linux-cosmo-objdump" ]; then
14-
OBJDUMP="$COSMO/.cosmocc/3.3.5/bin/$1-linux-cosmo-objdump"
15-
elif [ -x "$COSMO/.cosmocc/3.3.5/bin/$1-linux-musl-objdump" ]; then
16-
OBJDUMP="$COSMO/.cosmocc/3.3.5/bin/$1-linux-musl-objdump"
9+
if [ -x .cosmocc/3.6.0/bin/$1-linux-cosmo-objdump ]; then
10+
OBJDUMP=.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump
11+
elif [ -x .cosmocc/3.6.0/bin/$1-linux-musl-objdump ]; then
12+
OBJDUMP=.cosmocc/3.6.0/bin/$1-linux-musl-objdump
13+
elif [ -x "$COSMO/.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump" ]; then
14+
OBJDUMP="$COSMO/.cosmocc/3.6.0/bin/$1-linux-cosmo-objdump"
15+
elif [ -x "$COSMO/.cosmocc/3.6.0/bin/$1-linux-musl-objdump" ]; then
16+
OBJDUMP="$COSMO/.cosmocc/3.6.0/bin/$1-linux-musl-objdump"
1717
else
1818
echo "error: toolchain not found (try running 'cosmocc --update' or 'make' in the cosmo monorepo)" >&2
1919
exit 1

libc/calls/statfs.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,63 @@
3434
/**
3535
* Returns information about filesystem.
3636
*
37+
* The `struct statfs` returned has the following fields:
38+
*
39+
* - `f_fstypename` holds a NUL-terminated string identifying the file
40+
* system type. On Linux, this will usually be "nfs". On FreeBSD, it
41+
* will usually be "zfs". On OpenBSD and NetBSD, it's usually "ffs".
42+
* On MacOS it's usually "apfs", and on Windows it's usually "NTFS".
43+
*
44+
* - `f_bsize` is the optimal transfer block size. This may be used to
45+
* appropriately chunk your i/o operations. On local file systems it
46+
* will usually be somewhere between 4096 and 131072 bytes. With NFS
47+
* it may be as high as 512kb.
48+
*
49+
* - `f_frsize` is the fragment size of the file system. This could be
50+
* anywhere between 512 and 4096 bytes for local filesystems usually
51+
* although it could go higher. It should less than, or equal to the
52+
* `f_bsize`. This fragment size is what you want to use to multiply
53+
* other fields that count blocks into a byte count.
54+
*
55+
* - `f_bfree` is the number of free blocks in the filesystem. You can
56+
* multiply this number by `f_frsize` to obtain the free byte count.
57+
*
58+
* - `f_bavail` is the number of free blocks in the filesystem you can
59+
* access from userspace. It's less than or equal to `f_bfree` which
60+
* generally has some blocks reserved for root in a pinch. You could
61+
* multiply this by `f_frsize` to convert this number to bytes.
62+
*
63+
* - `f_files` is the total number of file nodes. Not every OS has it.
64+
* On Windows for instance it's currently always `INT64_MAX`. It has
65+
* an unspecified meaning. It should be seen as informative.
66+
*
67+
* - `f_fsid` is an opaque data structure that uniquely identifies the
68+
* filesystem. We're not yet certain how reliable this is across the
69+
* various OSes and filesystem types.
70+
*
71+
* - `f_namelen` is basically the same as `NAME_MAX` which seems to be
72+
* 255 on all the OSes we've evaluated. It's the maximum length when
73+
* it comes to individual components in a filesystem path.
74+
*
75+
* - `f_type` is an OS-specific file system type ID. This is just some
76+
* magic number. No defines are provided by Cosmopolitan Libc for it
77+
*
78+
* - `f_flags` specifies the options used when a filesystem is mounted
79+
* and the numbers vary across OSes. Cosmopolitan Libc polyfills the
80+
* magic numbers somewhat consistently. If `IsWindows()` is set then
81+
* the constants defined by Microsoft (e.g. `FILE_READ_ONLY_VOLUME`)
82+
* should be used. Otherwise on any other UNIX system, the following
83+
* constants are provided. You should check each constant at runtime
84+
* before using them, to determine if they're non-zero, for support.
85+
*
86+
* - `ST_RDONLY` if mounted in read-only mode (works UNIX + Windows)
87+
* - `ST_NOSUID` if setuid binaries are forbidden (all UNIX support)
88+
* - `ST_NODEV` when device file access forbidden (all UNIX support)
89+
* - `ST_NOEXEC` when a file executions forbidden (all UNIX support)
90+
* - `ST_SYNCHRONOUS`, if `O_SYNC` always happens (all UNIX support)
91+
* - `ST_NOATIME` if access timestamps aren't set (all UNIX support)
92+
* - `ST_RELATIME` if relative acces time is used (all UNIX support)
93+
*
3794
* @return 0 on success, or -1 w/ errno
3895
* @raise ECANCELED if thread was cancelled in masked mode
3996
* @raise EINTR if signal was delivered

libc/stdio/flockfile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
1717
│ PERFORMANCE OF THIS SOFTWARE. │
1818
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/assert.h"
1920
#include "libc/stdio/fflush.internal.h"
2021
#include "libc/stdio/internal.h"
2122
#include "libc/stdio/stdio.h"
@@ -26,6 +27,7 @@
2627
* Acquires reentrant lock on stdio object, blocking if needed.
2728
*/
2829
void flockfile(FILE *f) {
30+
unassert(f != NULL);
2931
pthread_mutex_lock(&f->lock);
3032
}
3133

libc/stdio/stdio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int fileno(FILE *) libcesque paramsnonnull() nosideeffect;
4141
int fputc(int, FILE *) libcesque paramsnonnull();
4242
int fputs(const char *, FILE *) libcesque paramsnonnull();
4343
int fputws(const wchar_t *, FILE *) libcesque paramsnonnull();
44-
void flockfile(FILE *) libcesque paramsnonnull();
44+
void flockfile(FILE *) libcesque;
4545
void funlockfile(FILE *) libcesque paramsnonnull();
4646
int ftrylockfile(FILE *) libcesque paramsnonnull();
4747
char *fgets(char *, int, FILE *) libcesque paramsnonnull();

libc/thread/pthread_attr_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* @see pthread_attr_setschedpolicy()
3535
* @see pthread_attr_setinheritsched()
3636
* @see pthread_attr_setscope()
37+
* @see pthread_attr_setsigaltstack_np()
38+
* @see pthread_attr_setsigaltstacksize_np()
3739
*/
3840
errno_t pthread_attr_init(pthread_attr_t *attr) {
3941
*attr = (pthread_attr_t){

libc/thread/pthread_cancel.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ static errno_t _pthread_cancel_everyone(void) {
354354
*/
355355
errno_t pthread_cancel(pthread_t thread) {
356356
struct PosixThread *arg;
357+
unassert(thread);
357358
if ((arg = (struct PosixThread *)thread)) {
358359
return _pthread_cancel_single(arg);
359360
} else {

libc/thread/pthread_detach.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static errno_t pthread_detach_impl(struct PosixThread *pt) {
6262
* @returnserrno
6363
*/
6464
errno_t pthread_detach(pthread_t thread) {
65+
unassert(thread);
6566
struct PosixThread *pt = (struct PosixThread *)thread;
6667
errno_t err = pthread_detach_impl(pt);
6768
STRACE("pthread_detach(%d) → %s", _pthread_tid(pt), DescribeErrno(err));

libc/thread/pthread_getaffinity_np.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
1717
│ PERFORMANCE OF THIS SOFTWARE. │
1818
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/assert.h"
1920
#include "libc/calls/sched-sysv.internal.h"
2021
#include "libc/calls/struct/cpuset.h"
2122
#include "libc/dce.h"
@@ -39,6 +40,8 @@
3940
errno_t pthread_getaffinity_np(pthread_t thread, size_t size,
4041
cpu_set_t *bitset) {
4142
int rc, tid;
43+
unassert(thread);
44+
unassert(bitset);
4245
tid = _pthread_tid((struct PosixThread *)thread);
4346

4447
if (size != sizeof(cpu_set_t)) {

libc/thread/pthread_setaffinity_np.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
1717
│ PERFORMANCE OF THIS SOFTWARE. │
1818
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/assert.h"
1920
#include "libc/calls/sched-sysv.internal.h"
2021
#include "libc/calls/struct/cpuset.h"
2122
#include "libc/calls/syscall_support-nt.internal.h"
@@ -54,6 +55,8 @@ errno_t pthread_setaffinity_np(pthread_t thread, size_t size,
5455
int e, rc, tid;
5556
cpu_set_t bs = {0};
5657
struct PosixThread *pt;
58+
unassert(thread);
59+
unassert(bitset);
5760
e = errno;
5861
if (size < sizeof(cpu_set_t)) {
5962
memcpy(&bs, bitset, size);

libc/thread/pthread_timedjoin_np.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ errno_t pthread_timedjoin_np(pthread_t thread, void **value_ptr,
118118
struct PosixThread *pt;
119119
enum PosixThreadStatus status;
120120
pt = (struct PosixThread *)thread;
121+
unassert(thread);
121122

122123
// "The behavior is undefined if the value specified by the thread
123124
// argument to pthread_join() does not refer to a joinable thread."

0 commit comments

Comments
 (0)