• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  *  AUTHOR		: William Roske
5  *  CO-PILOT		: Dave Fenner
6  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
7  */
8 
9 /*\
10  * [Description]
11  *
12  * Tests that link(2) succeeds.
13  */
14 
15 #include <unistd.h>
16 #include <sys/stat.h>
17 #include "tst_test.h"
18 
19 #define OLDPATH "oldpath"
20 #define NEWPATH "newpath"
21 
verify_link(void)22 static void verify_link(void)
23 {
24 	struct stat fbuf, lbuf;
25 
26 	TST_EXP_PASS(link(OLDPATH, NEWPATH));
27 
28 	if (!TST_PASS)
29 		return;
30 
31 	SAFE_STAT(OLDPATH, &fbuf);
32 	SAFE_STAT(NEWPATH, &lbuf);
33 
34 	if (fbuf.st_nlink > 1 && fbuf.st_nlink == lbuf.st_nlink) {
35 		tst_res(TPASS, "link("OLDPATH","NEWPATH") "
36                                  "returned 0 and stat link counts match");
37 	} else {
38 		tst_res(TFAIL, "link("OLDPATH","NEWPATH") returned 0"
39                                  " but stat link counts do not match %d %d",
40                                  (int)fbuf.st_nlink, (int)lbuf.st_nlink);
41 	}
42 
43 	SAFE_UNLINK(NEWPATH);
44 }
45 
setup(void)46 static void setup(void)
47 {
48 	SAFE_TOUCH(OLDPATH, 0700, NULL);
49 }
50 
51 static struct tst_test test = {
52 	.test_all = verify_link,
53 	.setup = setup,
54 	.needs_tmpdir = 1,
55 };
56