(root)/
strace-6.5/
tests-m32/
xutimes.c
       1  /*
       2   * Check decoding of utimes/osf_utimes syscall.
       3   *
       4   * Copyright (c) 2015-2021 Dmitry V. Levin <ldv@strace.io>
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #ifndef TEST_SYSCALL_NR
      11  # error TEST_SYSCALL_NR must be defined
      12  #endif
      13  
      14  #ifndef TEST_SYSCALL_STR
      15  # error TEST_SYSCALL_STR must be defined
      16  #endif
      17  
      18  #ifndef TEST_STRUCT
      19  # error TEST_STRUCT must be defined
      20  #endif
      21  
      22  #include <stdint.h>
      23  #include <stdio.h>
      24  #include <sys/time.h>
      25  #include <unistd.h>
      26  
      27  static void
      28  print_tv(const TEST_STRUCT *const tv)
      29  {
      30  	printf("{tv_sec=%lld, tv_usec=%llu}",
      31  	       (long long) tv->tv_sec,
      32  	       zero_extend_signed_to_ull(tv->tv_usec));
      33  	print_time_t_usec(tv->tv_sec,
      34  			  zero_extend_signed_to_ull(tv->tv_usec), 1);
      35  }
      36  
      37  static const char *errstr;
      38  
      39  static long
      40  k_utimes(const kernel_ulong_t pathname, const kernel_ulong_t times)
      41  {
      42  	long rc = syscall(TEST_SYSCALL_NR, pathname, times);
      43  	errstr = sprintrc(rc);
      44  	return rc;
      45  }
      46  
      47  int
      48  main(void)
      49  {
      50  	static const char proto_fname[] = TEST_SYSCALL_STR "_sample";
      51  	static const char qname[] = "\"" TEST_SYSCALL_STR "_sample\"";
      52  
      53  	char *const fname = tail_memdup(proto_fname, sizeof(proto_fname));
      54  	const kernel_ulong_t kfname = (uintptr_t) fname;
      55  	TEST_STRUCT *const tv = tail_alloc(sizeof(*tv) * 2);
      56  
      57  	/* pathname */
      58  	k_utimes(0, 0);
      59  	printf("%s(NULL, NULL) = %s\n", TEST_SYSCALL_STR, errstr);
      60  
      61  	k_utimes(kfname + sizeof(proto_fname) - 1, 0);
      62  	printf("%s(\"\", NULL) = %s\n", TEST_SYSCALL_STR, errstr);
      63  
      64  	k_utimes(kfname, 0);
      65  	printf("%s(%s, NULL) = %s\n", TEST_SYSCALL_STR, qname, errstr);
      66  
      67  	fname[sizeof(proto_fname) - 1] = '+';
      68  	k_utimes(kfname, 0);
      69  	fname[sizeof(proto_fname) - 1] = '\0';
      70  	printf("%s(%p, NULL) = %s\n", TEST_SYSCALL_STR, fname, errstr);
      71  
      72  	if (F8ILL_KULONG_SUPPORTED) {
      73  		k_utimes(f8ill_ptr_to_kulong(fname), 0);
      74  		printf("%s(%#jx, NULL) = %s\n", TEST_SYSCALL_STR,
      75  		       (uintmax_t) f8ill_ptr_to_kulong(fname), errstr);
      76  	}
      77  
      78  	/* times */
      79  	k_utimes(kfname, (uintptr_t) (tv + 1));
      80  	printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
      81  	       qname, tv + 1, errstr);
      82  
      83  	k_utimes(kfname, (uintptr_t) (tv + 2));
      84  	printf("%s(%s, %p) = %s\n", TEST_SYSCALL_STR,
      85  	       qname, tv + 2, errstr);
      86  
      87  	tv[0].tv_sec = 0xdeadbeefU;
      88  	tv[0].tv_usec = 0xfacefeedU;
      89  	tv[1].tv_sec = (time_t) 0xcafef00ddeadbeefLL;
      90  	tv[1].tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
      91  
      92  	k_utimes(kfname, (uintptr_t) tv);
      93  	printf("%s(%s, [", TEST_SYSCALL_STR, qname);
      94  	print_tv(&tv[0]);
      95  	printf(", ");
      96  	print_tv(&tv[1]);
      97  	printf("]) = %s\n", errstr);
      98  
      99  	tv[0].tv_sec = 1492358607;
     100  	tv[0].tv_usec = 1000000;
     101  	tv[1].tv_sec = 1492356078;
     102  	tv[1].tv_usec = 1000001;
     103  
     104  	k_utimes(kfname, (uintptr_t) tv);
     105  	printf("%s(%s, [", TEST_SYSCALL_STR, qname);
     106  	print_tv(&tv[0]);
     107  	printf(", ");
     108  	print_tv(&tv[1]);
     109  	printf("]) = %s\n", errstr);
     110  
     111  	tv[0].tv_usec = 345678;
     112  	tv[1].tv_usec = 456789;
     113  
     114  	k_utimes(kfname, (uintptr_t) tv);
     115  	printf("%s(%s, [", TEST_SYSCALL_STR, qname);
     116  	print_tv(&tv[0]);
     117  	printf(", ");
     118  	print_tv(&tv[1]);
     119  	printf("]) = %s\n", errstr);
     120  
     121  	if (F8ILL_KULONG_SUPPORTED) {
     122  		k_utimes(kfname, f8ill_ptr_to_kulong(tv));
     123  		printf("%s(%s, %#jx) = %s\n", TEST_SYSCALL_STR,
     124  		       qname, (uintmax_t) f8ill_ptr_to_kulong(tv), errstr);
     125  	}
     126  
     127  	puts("+++ exited with 0 +++");
     128  	return 0;
     129  }