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