1  /* Get file status.  Linux version.
       2     Copyright (C) 2020-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #include <sys/stat.h>
      20  #include <kernel_stat.h>
      21  #include <sysdep.h>
      22  
      23  #if !XSTAT_IS_XSTAT64
      24  int
      25  __fstatat (int fd, const char *file, struct stat *buf, int flag)
      26  {
      27    struct __stat64_t64 st64;
      28    int r = __fstatat64_time64 (fd, file, &st64, flag);
      29    if (r == 0)
      30      {
      31        if (! in_ino_t_range (st64.st_ino)
      32  	  || ! in_off_t_range (st64.st_size)
      33  	  || ! in_blkcnt_t_range (st64.st_blocks)
      34  	  || ! in_time_t_range (st64.st_atim.tv_sec)
      35  	  || ! in_time_t_range (st64.st_mtim.tv_sec)
      36  	  || ! in_time_t_range (st64.st_ctim.tv_sec))
      37  	return INLINE_SYSCALL_ERROR_RETURN_VALUE (EOVERFLOW);
      38  
      39        /* Clear internal pad and reserved fields.  */
      40        memset (buf, 0, sizeof (*buf));
      41  
      42        buf->st_dev = st64.st_dev;
      43        buf->st_ino = st64.st_ino;
      44        buf->st_mode = st64.st_mode;
      45        buf->st_nlink = st64.st_nlink;
      46        buf->st_uid = st64.st_uid;
      47        buf->st_gid = st64.st_gid;
      48        buf->st_rdev = st64.st_rdev;
      49        buf->st_size = st64.st_size;
      50        buf->st_blksize = st64.st_blksize;
      51        buf->st_blocks  = st64.st_blocks;
      52        buf->st_atim = valid_timespec64_to_timespec (st64.st_atim);
      53        buf->st_mtim = valid_timespec64_to_timespec (st64.st_mtim);
      54        buf->st_ctim = valid_timespec64_to_timespec (st64.st_ctim);
      55      }
      56    return r;
      57  }
      58  
      59  weak_alias (__fstatat, fstatat)
      60  #endif