summaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/unix/sysv/linux')
-rw-r--r--sysdeps/unix/sysv/linux/fallocate.c5
-rw-r--r--sysdeps/unix/sysv/linux/fallocate64.c5
-rw-r--r--sysdeps/unix/sysv/linux/getsysstats.c40
3 files changed, 46 insertions, 4 deletions
diff --git a/sysdeps/unix/sysv/linux/fallocate.c b/sysdeps/unix/sysv/linux/fallocate.c
index a45b0f831d..116f00046e 100644
--- a/sysdeps/unix/sysv/linux/fallocate.c
+++ b/sysdeps/unix/sysv/linux/fallocate.c
@@ -25,7 +25,12 @@
int
fallocate (int fd, int mode, __off_t offset, __off_t len)
{
+#ifndef __NR_fallocate
return INLINE_SYSCALL (fallocate, 6, fd, mode,
__LONG_LONG_PAIR (offset >> 31, offset),
__LONG_LONG_PAIR (len >> 31, len));
+#else
+ __set_errno (ENOSYS);
+ return -1;
+#endif
}
diff --git a/sysdeps/unix/sysv/linux/fallocate64.c b/sysdeps/unix/sysv/linux/fallocate64.c
index 601a70ba1f..2fbe988910 100644
--- a/sysdeps/unix/sysv/linux/fallocate64.c
+++ b/sysdeps/unix/sysv/linux/fallocate64.c
@@ -25,9 +25,14 @@
int
__fallocate64_l64 (int fd, int mode, __off64_t offset, __off64_t len)
{
+#ifndef __NR_fallocate
return INLINE_SYSCALL (fallocate, 6, fd, mode,
__LONG_LONG_PAIR ((long int) (offset >> 32),
(long int) offset),
__LONG_LONG_PAIR ((long int) (len >> 32),
(long int) len));
+#else
+ __set_errno (ENOSYS);
+ return -1;
+#endif
}
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index 28f52c0463..97e20d249b 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -93,15 +93,42 @@ next_line (int fd, char *const buffer, char **cp, char **re,
return NULL;
*re += n;
+
+ nl = memchr (*cp, '\n', *re - *cp);
+ while (nl == NULL && *re == buffer_end)
+ {
+ /* Truncate too long lines. */
+ *re = buffer + 3 * (buffer_end - buffer) / 4;
+ n = read_not_cancel (fd, *re, buffer_end - *re);
+ if (n < 0)
+ return NULL;
+
+ nl = memchr (*re, '\n', n);
+ **re = '\n';
+ *re += n;
+ }
}
+ else
+ nl = memchr (*cp, '\n', *re - *cp);
res = *cp;
- nl = memchr (*cp, '\n', *re - *cp);
}
if (nl == NULL)
nl = *re - 1;
}
+ else if (nl + 5 >= *re)
+ {
+ memmove (buffer, nl, *re - nl);
+ *re = buffer + (*re - nl);
+ nl = *cp = buffer;
+
+ ssize_t n = read_not_cancel (fd, *re, buffer_end - *re);
+ if (n < 0)
+ return NULL;
+
+ *re += n;
+ }
*cp = nl + 1;
assert (*cp <= *re);
@@ -115,8 +142,9 @@ __get_nprocs ()
{
/* XXX Here will come a test for the new system call. */
- char buffer[8192];
- char *const buffer_end = buffer + sizeof (buffer);
+ const size_t buffer_size = __libc_use_alloca (8192) ? 8192 : 512;
+ char *buffer = alloca (buffer_size);
+ char *buffer_end = buffer + buffer_size;
char *cp = buffer_end;
char *re = buffer_end;
int result = 1;
@@ -134,7 +162,11 @@ __get_nprocs ()
char *l;
while ((l = next_line (fd, buffer, &cp, &re, buffer_end)) != NULL)
- if (strncmp (l, "cpu", 3) == 0 && isdigit (l[3]))
+ /* The current format of /proc/stat has all the cpu* entries
+ at the front. We assume here that stays this way. */
+ if (strncmp (l, "cpu", 3) != 0)
+ break;
+ else if (isdigit (l[3]))
++result;
close_not_cancel_no_status (fd);