]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - io/fstat.c
socket: Use may_alias on sockaddr structs (bug 19622)
[thirdparty/glibc.git] / io / fstat.c
index d93d0929ac65d28eb8345079bf9cd4092dc2c29e..b72ccfe7bc9244e9ec4add6be35a6d5ef65e4a9a 100644 (file)
@@ -1,47 +1,32 @@
-/* Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2024 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Library General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
-
-   In addition to the permissions in the GNU Library General Public
-   License, the Free Software Foundation gives you unlimited
-   permission to link the compiled version of this file with other
-   programs, and to distribute those programs without any restriction
-   coming from the use of this file.  (The Library General Public
-   License restrictions do apply in other respects; for example, they
-   cover modification of the file, and distribution when not linked
-   into another program.)
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
 
    The GNU 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
-   Library General Public License for more details.
+   Lesser General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with the GNU C Library; see the file COPYING.LIB.  If not,
-   write to the Free Software Foundation, 59 Temple Place - Suite 330,
-   Boston, MA 02111-1307, USA.  */
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
 
 #include <sys/stat.h>
+#include <errno.h>
 
-/* This definition is only used if inlining fails for this function; see
-   the last page of <sys/stat.h>.  The real work is done by the `x'
-   function which is passed a version number argument.  We arrange in the
-   makefile that when not inlined this function is always statically
-   linked; that way a dynamically-linked executable always encodes the
-   version number corresponding to the data structures it uses, so the `x'
-   functions in the shared library can adapt without needing to recompile
-   all callers.  */
-
-#undef fstat
-#undef __fstat
 int
 __fstat (int fd, struct stat *buf)
 {
-  return __fxstat (_STAT_VER, fd, buf);
+  if (fd < 0)
+    {
+      __set_errno (EBADF);
+      return -1;
+    }
+  return __fstatat (fd, "", buf, AT_EMPTY_PATH);
 }
 
 weak_alias (__fstat, fstat)