(root)/
strace-6.5/
tests/
getcwd.c
       1  /*
       2   * Check decoding of getcwd syscall.
       3   *
       4   * Copyright (c) 2016-2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  
      13  #include <limits.h>
      14  #include <stdio.h>
      15  #include <unistd.h>
      16  
      17  int
      18  main(void)
      19  {
      20  	long res;
      21  	char cur_dir[PATH_MAX + 1];
      22  	static const size_t bogus_size = (size_t) 0xbadc0deddeadfaceULL;
      23  
      24  	res = syscall(__NR_getcwd, cur_dir, sizeof(cur_dir));
      25  
      26  	if (res <= 0)
      27  		perror_msg_and_fail("getcwd");
      28  
      29  	printf("getcwd(");
      30  	print_quoted_string(cur_dir);
      31  	printf(", %zu) = %ld\n", sizeof(cur_dir), res);
      32  
      33  	res = syscall(__NR_getcwd, cur_dir, 0);
      34  	printf("getcwd(%p, 0) = %s\n", cur_dir, sprintrc(res));
      35  
      36  	res = syscall(__NR_getcwd, NULL, bogus_size);
      37  	printf("getcwd(NULL, %zu) = %s\n", bogus_size, sprintrc(res));
      38  
      39  	res = syscall(__NR_getcwd, (void *) -1L, sizeof(cur_dir));
      40  	printf("getcwd(%p, %zu) = %s\n",
      41  	       (void *) -1L, sizeof(cur_dir), sprintrc(res));
      42  
      43  	puts("+++ exited with 0 +++");
      44  
      45  	return 0;
      46  }