restore property that fstat(AT_FDCWD) fails with EBADF
authorRich Felker <dalias@aerifal.cx>
Thu, 18 Jul 2019 23:41:52 +0000 (19:41 -0400)
committerRich Felker <dalias@aerifal.cx>
Thu, 18 Jul 2019 23:47:46 +0000 (19:47 -0400)
AT_FDCWD is not a valid file descriptor, so POSIX requires fstat to
fail with EBADF. if passed to fstatat, the call would spuriously
succeed and return results for the working directory.

src/stat/fstat.c

index d2a828f..07f9a5d 100644 (file)
@@ -6,6 +6,7 @@
 
 int fstat(int fd, struct stat *st)
 {
 
 int fstat(int fd, struct stat *st)
 {
+       if (fd<0) return __syscall_ret(-EBADF);
        return fstatat(fd, "", st, AT_EMPTY_PATH);
 }
 
        return fstatat(fd, "", st, AT_EMPTY_PATH);
 }