Blame io/test-stat2.c

Packit 6c4009
/* Test consistence of results of stat and stat64.
Packit 6c4009
   Copyright (C) 2000-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
   Contributed by Ulrich Drepper <drepper@redhat.com>, 2000.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#include <errno.h>
Packit 6c4009
#include <stdint.h>
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <sys/stat.h>
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
main (int argc, char *argv[])
Packit 6c4009
{
Packit 6c4009
  int i;
Packit 6c4009
  int result = 0;
Packit 6c4009
Packit 6c4009
  for (i = 1; i < argc; ++i)
Packit 6c4009
    {
Packit 6c4009
      struct stat st;
Packit 6c4009
      struct stat64 st64;
Packit 6c4009
      int same;
Packit 6c4009
Packit 6c4009
      if (stat (argv[i], &st) != 0)
Packit 6c4009
	{
Packit 6c4009
	  if (errno != EOVERFLOW)
Packit 6c4009
	    {
Packit 6c4009
	      /* Something is wrong.  */
Packit 6c4009
	      printf ("stat(\"%s\",....) failed: %m", argv[i]);
Packit 6c4009
	      result = 1;
Packit 6c4009
	    }
Packit 6c4009
	  continue;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      if (stat64 (argv[i], &st64) != 0)
Packit 6c4009
	{
Packit 6c4009
	  if (errno != ENOSYS)
Packit 6c4009
	    {
Packit 6c4009
	      /* Something is wrong.  */
Packit 6c4009
	      printf ("stat64(\"%s\",....) failed: %m", argv[i]);
Packit 6c4009
	      result = 1;
Packit 6c4009
	    }
Packit 6c4009
	  continue;
Packit 6c4009
	}
Packit 6c4009
Packit 6c4009
      printf ("\nName: %s\n", argv[i]);
Packit 6c4009
Packit 6c4009
#define TEST(name) \
Packit 6c4009
      same = st.name == st64.name;					      \
Packit 6c4009
      printf (#name ": %jd vs %jd  %s\n",				      \
Packit 6c4009
	      (intmax_t) st.name, (intmax_t) st64.name,			      \
Packit 6c4009
	      same ? "OK" : "FAIL");					      \
Packit 6c4009
      result |= ! same
Packit 6c4009
Packit 6c4009
      TEST (st_dev);
Packit 6c4009
      TEST (st_ino);
Packit 6c4009
      TEST (st_mode);
Packit 6c4009
      TEST (st_nlink);
Packit 6c4009
      TEST (st_uid);
Packit 6c4009
      TEST (st_gid);
Packit 6c4009
#ifdef _STATBUF_ST_RDEV
Packit 6c4009
      TEST (st_rdev);
Packit 6c4009
#endif
Packit 6c4009
#ifdef _STATBUF_ST_BLKSIZE
Packit 6c4009
      TEST (st_blksize);
Packit 6c4009
#endif
Packit 6c4009
      TEST (st_blocks);
Packit 6c4009
      TEST (st_atime);
Packit 6c4009
      TEST (st_mtime);
Packit 6c4009
      TEST (st_ctime);
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return result;
Packit 6c4009
}