h_cwd.c revision 1.1 1 /* $NetBSD: h_cwd.c,v 1.1 2011/02/19 13:19:52 pooka Exp $ */
2
3 /*-
4 * Copyright (c) 2011 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
17 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
23 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #include <sys/types.h>
31 #include <sys/stat.h>
32
33 #include <err.h>
34 #include <errno.h>
35 #include <string.h>
36 #include <unistd.h>
37
38 int
39 main(void)
40 {
41 char pwd[1024];
42
43 if (chdir("/rump") == -1)
44 err(1, "chdir1");
45 if (getcwd(pwd, sizeof(pwd)) == NULL)
46 err(1, "getcwd1");
47 if (strcmp(pwd, "/rump") != 0)
48 errx(1, "strcmp1");
49
50 if (mkdir("dir", 0777) == -1)
51 err(1, "mkdir2");
52 if (chdir("dir") == -1)
53 err(1, "chdir2");
54 if (getcwd(pwd, sizeof(pwd)) == NULL)
55 err(1, "getcwd2");
56 if (strcmp(pwd, "/rump/dir") != 0)
57 errx(1, "strcmp2");
58
59 if (mkdir("dir", 0777) == -1)
60 err(1, "mkdir3");
61 if (chdir("dir") == -1)
62 err(1, "chdir3");
63 if (getcwd(pwd, sizeof(pwd)) == NULL)
64 err(1, "getcwd3");
65 if (strcmp(pwd, "/rump/dir/dir") != 0)
66 errx(1, "strcmp3");
67
68 if (chdir("..") == -1)
69 err(1, "chdir4");
70 if (getcwd(pwd, sizeof(pwd)) == NULL)
71 err(1, "getcwd4");
72 if (strcmp(pwd, "/rump/dir") != 0)
73 errx(1, "strcmp4");
74
75 if (chdir("../../../../../../..") == -1)
76 err(1, "chdir5");
77 if (getcwd(pwd, sizeof(pwd)) == NULL)
78 err(1, "getcwd5");
79 if (strcmp(pwd, "/rump") != 0)
80 errx(1, "strcmp5");
81
82 if (chdir("/") == -1)
83 err(1, "chdir6");
84 if (getcwd(pwd, sizeof(pwd)) == NULL)
85 err(1, "getcwd6");
86 if (strcmp(pwd, "/") != 0)
87 errx(1, "strcmp6");
88
89 return 0;
90 }
91