Back to index

glibc  2.9
xstatconv.c
Go to the documentation of this file.
00001 /* Convert between `struct stat' format, and `struct stat64' format.
00002    Copyright (C) 2000,01,02 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <errno.h>
00021 #include <sys/stat.h>
00022 
00023 static inline int
00024 xstat64_conv (struct stat *buf, const struct stat64 *buf64)
00025 {
00026   if (sizeof *buf == sizeof *buf64
00027       && sizeof buf->st_ino == sizeof buf64->st_ino
00028       && sizeof buf->st_size == sizeof buf64->st_size
00029       && sizeof buf->st_blocks == sizeof buf64->st_blocks)
00030     {
00031       *buf = *(struct stat *) buf64;
00032       return 0;
00033     }
00034 
00035   buf->st_fstype = buf64->st_fstype;
00036   buf->st_fsid = buf64->st_fsid;
00037   buf->st_ino = buf64->st_ino;
00038   buf->st_gen = buf64->st_gen;
00039   buf->st_rdev = buf64->st_rdev;
00040   buf->st_mode = buf64->st_mode;
00041   buf->st_nlink = buf64->st_nlink;
00042   buf->st_uid = buf64->st_uid;
00043   buf->st_gid = buf64->st_gid;
00044   buf->st_size = buf64->st_size;
00045   buf->st_atime = buf64->st_atime;
00046   buf->st_atime_usec = buf64->st_atime_usec;
00047   buf->st_mtime = buf64->st_mtime;
00048   buf->st_mtime_usec = buf64->st_mtime_usec;
00049   buf->st_ctime = buf64->st_ctime;
00050   buf->st_ctime_usec = buf64->st_ctime_usec;
00051   buf->st_blksize = buf64->st_blksize;
00052   buf->st_blocks = buf64->st_blocks;
00053   buf->st_author = buf64->st_author;
00054   buf->st_flags = buf64->st_flags;
00055 
00056   if ((sizeof buf->st_ino != sizeof buf64->st_ino
00057        && buf->st_ino != buf64->st_ino)
00058       || (sizeof buf->st_size != sizeof buf64->st_size
00059          && buf->st_size != buf64->st_size)
00060       || (sizeof buf->st_blocks != sizeof buf64->st_blocks
00061          && buf->st_blocks != buf64->st_blocks))
00062     {
00063       __set_errno (EOVERFLOW);
00064       return -1;
00065     }
00066 
00067   return 0;
00068 }