aboutsummaryrefslogtreecommitdiffstats
path: root/get_stack_limit.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2024-09-22 11:22:38 +0200
committerMattias Andrée <maandree@kth.se>2024-09-22 11:22:38 +0200
commitf02bdf3ceaf245982728722a2c3eced750c511a1 (patch)
tree466996a7eb7ce8d8a349fe3b2334d13df692e5b0 /get_stack_limit.c
parentm whitespace (diff)
downloadlibsimple-f02bdf3ceaf245982728722a2c3eced750c511a1.tar.gz
libsimple-f02bdf3ceaf245982728722a2c3eced750c511a1.tar.bz2
libsimple-f02bdf3ceaf245982728722a2c3eced750c511a1.tar.xz
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'get_stack_limit.c')
-rw-r--r--get_stack_limit.c23
1 files changed, 16 insertions, 7 deletions
diff --git a/get_stack_limit.c b/get_stack_limit.c
index 7005727..cb19f2d 100644
--- a/get_stack_limit.c
+++ b/get_stack_limit.c
@@ -12,7 +12,7 @@ libsimple_get_stack_limit(size_t *restrict soft, size_t *restrict hard)
size_t off = 0;
size_t lineoff, linelen;
- fd = open("/proc/self/limits", O_RDONLY);
+ fd = open("/proc/thread-self/limits", O_RDONLY);
if (fd < 0)
return -1;
@@ -47,15 +47,24 @@ line_found:
close(fd);
line = &line[sizeof("Max stack size ") - 1U];
- while (*line == ' ')
+ while (*line == ' ' || *line == '\t')
+ line++;
+ if (soft) {
+ *soft = SIZE_MAX;
+ if (isdigit(*line))
+ *soft = (size_t)strtoull(line, NULL, 10);
+ }
+
+ while (*line != ' ' && *line != '\t' && *line && *line != '\n')
line++;
- if (soft)
- *soft = (size_t)strtoull(line, NULL, 10);
- while (*line == ' ')
+ while (*line == ' ' || *line == '\t')
line++;
- if (hard)
- *hard = (size_t)strtoull(line, NULL, 10);
+ if (hard) {
+ *hard = SIZE_MAX;
+ if (isdigit(*line))
+ *hard = (size_t)strtoull(line, NULL, 10);
+ }
return 0;
}