From 7a5e549612412f81d14d4424269121ae4b68d975 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 31 Aug 2013 00:12:03 +0200 Subject: [PATCH] Add getrlimit(3) and setrlimit(3). --- libc/Makefile | 2 ++ libc/include/sys/resource.h | 2 ++ libc/sys/resource/getrlimit.cpp | 33 +++++++++++++++++++++++++++++++++ libc/sys/resource/setrlimit.cpp | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 libc/sys/resource/getrlimit.cpp create mode 100644 libc/sys/resource/setrlimit.cpp diff --git a/libc/Makefile b/libc/Makefile index 7cba2125..ee386fa3 100644 --- a/libc/Makefile +++ b/libc/Makefile @@ -309,8 +309,10 @@ sys/mman/mprotect.o \ sys/mman/munmap.o \ sys/readdirents/readdirents.o \ sys/resource/getpriority.o \ +sys/resource/getrlimit.o \ sys/resource/prlimit.o \ sys/resource/setpriority.o \ +sys/resource/setrlimit.o \ sys/select/select.o \ sys/socket/accept4.o \ sys/socket/accept.o \ diff --git a/libc/include/sys/resource.h b/libc/include/sys/resource.h index d2502187..36b5782b 100644 --- a/libc/include/sys/resource.h +++ b/libc/include/sys/resource.h @@ -34,8 +34,10 @@ __BEGIN_DECLS @include(pid_t.h) int getpriority(int, id_t); +int getrlimit(int, struct rlimit*); int prlimit(pid_t, int, const struct rlimit*, struct rlimit*); int setpriority(int, id_t, int); +int setrlimit(int, const struct rlimit*); __END_DECLS diff --git a/libc/sys/resource/getrlimit.cpp b/libc/sys/resource/getrlimit.cpp new file mode 100644 index 00000000..6dfcf027 --- /dev/null +++ b/libc/sys/resource/getrlimit.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + sys/resource/getrlimit.cpp + Get the resource limits of the current process. + +*******************************************************************************/ + +#include +#include + +#include + +extern "C" int getrlimit(int resource, struct rlimit* limit) +{ + return prlimit(0, resource, NULL, limit); +} diff --git a/libc/sys/resource/setrlimit.cpp b/libc/sys/resource/setrlimit.cpp new file mode 100644 index 00000000..391b8a0b --- /dev/null +++ b/libc/sys/resource/setrlimit.cpp @@ -0,0 +1,33 @@ +/******************************************************************************* + + Copyright(C) Jonas 'Sortie' Termansen 2013. + + This file is part of the Sortix C Library. + + The Sortix C Library is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation, either version 3 of the License, or (at your + option) any later version. + + The Sortix C Library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with the Sortix C Library. If not, see . + + sys/resource/setrlimit.cpp + Set the resource limits of the current process. + +*******************************************************************************/ + +#include +#include + +#include + +extern "C" int setrlimit(int resource, const struct rlimit* limit) +{ + return prlimit(0, resource, limit, NULL); +}