Make improvements

- Polyfill pselect() on Windows
- Add -O NOFILE flag to pledge.com
- Polyfill ppoll() on NetBSD, XNU, and Windows
- Support negative numbers and errno in sizetol()
- Add .RSS, .NOFILE, and .MAXCORE to Landlock Make
- Fix issue with .PLEDGE preventing touching of output files
- Add __watch() function (like ftrace) for logging memory changes
This commit is contained in:
Justine Tunney 2022-08-15 15:18:37 -07:00
parent d3b599a796
commit f0701d2a24
35 changed files with 635 additions and 340 deletions

View file

@ -19,6 +19,7 @@
#include "libc/fmt/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/str/str.h"
#include "libc/sysv/errfuns.h"
static int GetExponent(int c) {
switch (c) {
@ -65,27 +66,41 @@ static int GetExponent(int c) {
* characters after it (e.g. kbit, Mibit, TiB) are ignored. Spaces
* before the integer are ignored, and overflows will be detected.
*
* Negative numbers are permissible, as well as a leading `+` sign. To
* tell the difference between an error return and `-1` you must clear
* `errno` before calling and test whether it changed.
*
* @param s is non-null nul-terminated input string
* @param b is multiplier which should be 1000 or 1024
* @return size greater than or equal 0 or -1 on error
* @error EINVAL if error is due to bad syntax
* @error EOVERFLOW if error is due to overflow
*/
long sizetol(const char *s, long b) {
long x;
int c, e;
int c, e, d;
do {
c = *s++;
} while (c == ' ' || c == '\t');
if (!isdigit(c)) return -1;
d = c == '-' ? -1 : 1;
if (c == '-' || c == '+') c = *s++;
if (!isdigit(c)) {
return einval();
}
x = 0;
do {
if (__builtin_mul_overflow(x, 10, &x) ||
__builtin_add_overflow(x, c - '0', &x)) {
return -1;
__builtin_add_overflow(x, (c - '0') * d, &x)) {
return eoverflow();
}
} while (isdigit((c = *s++)));
if ((e = GetExponent(c)) == -1) return -1;
if ((e = GetExponent(c)) == -1) {
return einval();
}
while (e--) {
if (__builtin_mul_overflow(x, b, &x)) return -1;
if (__builtin_mul_overflow(x, b, &x)) {
return eoverflow();
}
}
return x;
}

View file

@ -16,7 +16,6 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/fmt.h"
#include "libc/nt/runtime.h"
#include "libc/str/str.h"