[klibc] [PATCH 2/3] syscalls: Add syscalls needed by arm64

Steve Capper steve.capper at linaro.org
Mon Nov 11 06:45:03 PST 2013


On Fri, Nov 08, 2013 at 11:37:43AM -0800, H. Peter Anvin wrote:
> 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
> 
> 

Apologies.

I've redone stat and lstat to call fstatat. Also I have rewritten the
chmod call to use fchmodat.

-- 
Steve


More information about the klibc mailing list