[klibc] [PATCH 2/3] syscalls: Add syscalls needed by arm64
H. Peter Anvin
hpa at zytor.com
Fri Nov 8 11:37:43 PST 2013
On 11/08/2013 09:12 AM, Steve Capper wrote:
> diff --git a/usr/klibc/lstat.c b/usr/klibc/lstat.c
> new file mode 100644
> index 0000000..0282eec
> --- /dev/null
> +++ b/usr/klibc/lstat.c
> @@ -0,0 +1,17 @@
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/syscall.h>
> +
> +#ifndef __NR_lstat
> +
> +int lstat(const char *path, struct stat *buf)
> +{
> + int fd = open(path, O_RDONLY | O_PATH | O_NOFOLLOW);
> + int ret = fstat(fd, buf);
> + close(fd);
> + return ret;
> +}
> +
> +#endif /* __NR_lstat */
[...]
> diff --git a/usr/klibc/stat.c b/usr/klibc/stat.c
> new file mode 100644
> index 0000000..92343f1
> --- /dev/null
> +++ b/usr/klibc/stat.c
> @@ -0,0 +1,17 @@
> +#include <fcntl.h>
> +#include <unistd.h>
> +#include <sys/types.h>
> +#include <sys/stat.h>
> +#include <sys/syscall.h>
> +
> +#ifndef __NR_stat
> +
> +int stat(const char *path, struct stat *buf)
> +{
> + int fd = open(path, O_RDONLY);
> + int ret = fstat(fd, buf);
> + close(fd);
> + return ret;
> +}
> +
> +#endif /* __NR_stat */
No. Just... no. Especially not O_RDONLY without O_PATH.
But do an implementation based on fstatat() instead.
-hpa
More information about the klibc
mailing list