Add .PLEDGE/.CPU/.MEMORY/etc. to Landlock Make 1.2

This commit is contained in:
Justine Tunney 2022-08-14 20:16:44 -07:00
parent 6c0bbfac4a
commit 7ab15e0b23
20 changed files with 494 additions and 329 deletions

View file

@ -19,26 +19,26 @@
#include "libc/fmt/itoa.h"
#include "libc/macros.internal.h"
static const struct {
char suffix;
uint64_t size;
} kUnits[] = {
{'e', 1024ULL * 1024 * 1024 * 1024 * 1024 * 1024},
{'p', 1024ULL * 1024 * 1024 * 1024 * 1024},
{'t', 1024ULL * 1024 * 1024 * 1024},
{'g', 1024ULL * 1024 * 1024},
{'m', 1024ULL * 1024},
{'k', 1024ULL},
};
/**
* Represents size of memory readably.
*
* @param p is output buffer
* @param b should be 1024 or 1000
* @return pointer to nul byte
*/
char *FormatMemorySize(char *p, uint64_t x) {
char *FormatMemorySize(char *p, uint64_t x, uint64_t b) {
int i, suffix;
struct {
char suffix;
uint64_t size;
} kUnits[] = {
{'e', b * b * b * b * b * b},
{'p', b * b * b * b * b},
{'t', b * b * b * b},
{'g', b * b * b},
{'m', b * b},
{'k', b},
};
for (suffix = i = 0; i < ARRAYLEN(kUnits); ++i) {
if (x >= kUnits[i].size * 9) {
x = (x + kUnits[i].size / 2) / kUnits[i].size;

View file

@ -21,7 +21,7 @@ char *FormatFlex64(char[hasatleast 24], int64_t, char);
size_t uint64toarray_radix16(uint64_t, char[hasatleast 17]);
size_t uint64toarray_fixed16(uint64_t, char[hasatleast 17], uint8_t);
size_t uint64toarray_radix8(uint64_t, char[hasatleast 24]);
char *FormatMemorySize(char *, uint64_t);
char *FormatMemorySize(char *, uint64_t, uint64_t);
#ifndef __STRICT_ANSI__
size_t int128toarray_radix10(int128_t, char *);