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 d2a828f32c64bf4686e995672243f1c8ce77766d..07f9a5de15e8a54b4f7b1c37ddcb0119190fef5b 100644 (file)
@@ -6,6 +6,7 @@
 
 int fstat(int fd, struct stat *st)
 {
+       if (fd<0) return __syscall_ret(-EBADF);
        return fstatat(fd, "", st, AT_EMPTY_PATH);
 }