• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines  Corp., 2001
4  */
5 
6 /*\
7  * [Description]
8  *
9  * Test whether the inode number are the same for both file descriptors.
10  */
11 
12 #include <unistd.h>
13 #include "tst_test.h"
14 #include "tst_safe_macros.h"
15 
16 static int fd[2] = {-1, -1};
17 static int nfd[2] = {10, 20};
18 
setup(void)19 static void setup(void)
20 {
21 	SAFE_PIPE(fd);
22 }
23 
cleanup(void)24 static void cleanup(void)
25 {
26 	unsigned int i;
27 
28 	for (i = 0; i < ARRAY_SIZE(fd); i++) {
29 		close(fd[i]);
30 		close(nfd[i]);
31 	}
32 }
33 
run(unsigned int i)34 static void run(unsigned int i)
35 {
36 	struct stat oldbuf, newbuf;
37 
38 	TEST(dup2(fd[i], nfd[i]));
39 	if (TST_RET == -1) {
40 		tst_res(TFAIL, "call failed unexpectedly");
41 		return;
42 	}
43 
44 	SAFE_FSTAT(fd[i], &oldbuf);
45 	SAFE_FSTAT(nfd[i], &newbuf);
46 
47 	if (oldbuf.st_ino != newbuf.st_ino)
48 		tst_res(TFAIL,
49 			"original inode(%ld) and duped inode(%ld) do not match",
50 			oldbuf.st_ino, newbuf.st_ino);
51 	else
52 		tst_res(TPASS,
53 			"original inode(%ld) and duped inode(%ld) are the same",
54 			oldbuf.st_ino, newbuf.st_ino);
55 
56 	SAFE_CLOSE(TST_RET);
57 }
58 
59 static struct tst_test test = {
60 	.tcnt = ARRAY_SIZE(fd),
61 	.test = run,
62 	.setup = setup,
63 	.cleanup = cleanup,
64 };
65