Back to index

glibc  2.9
test-stat2.c
Go to the documentation of this file.
00001 /* Test consistence of results of stat and stat64.
00002    Copyright (C) 2000 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #include <errno.h>
00022 #include <stdint.h>
00023 #include <stdio.h>
00024 #include <sys/stat.h>
00025 
00026 int
00027 main (int argc, char *argv[])
00028 {
00029   int i;
00030   int result = 0;
00031 
00032   for (i = 1; i < argc; ++i)
00033     {
00034       struct stat st;
00035       struct stat64 st64;
00036       int same;
00037 
00038       if (stat (argv[i], &st) != 0)
00039        {
00040          if (errno != EOVERFLOW)
00041            {
00042              /* Something is wrong.  */
00043              printf ("stat(\"%s\",....) failed: %m", argv[i]);
00044              result = 1;
00045            }
00046          continue;
00047        }
00048 
00049       if (stat64 (argv[i], &st64) != 0)
00050        {
00051          if (errno != ENOSYS)
00052            {
00053              /* Something is wrong.  */
00054              printf ("stat64(\"%s\",....) failed: %m", argv[i]);
00055              result = 1;
00056            }
00057          continue;
00058        }
00059 
00060       printf ("\nName: %s\n", argv[i]);
00061 
00062 #define TEST(name) \
00063       same = st.name == st64.name;                                   \
00064       printf (#name ": %jd vs %jd  %s\n",                            \
00065              (intmax_t) st.name, (intmax_t) st64.name,                      \
00066              same ? "OK" : "FAIL");                                         \
00067       result |= ! same
00068 
00069       TEST (st_dev);
00070       TEST (st_ino);
00071       TEST (st_mode);
00072       TEST (st_nlink);
00073       TEST (st_uid);
00074       TEST (st_gid);
00075 #ifdef _STATBUF_ST_RDEV
00076       TEST (st_rdev);
00077 #endif
00078 #ifdef _STATBUF_ST_BLKSIZE
00079       TEST (st_blksize);
00080 #endif
00081       TEST (st_blocks);
00082       TEST (st_atime);
00083       TEST (st_mtime);
00084       TEST (st_ctime);
00085     }
00086 
00087   return result;
00088 }