xref: /freebsd/lib/libpathconv/tests/abs2rel.c (revision b3e7694832e81d7a904a10f525f8797b753bf0d3)
1*0f7f3352SJulian Elischer /*
2*0f7f3352SJulian Elischer  * Copyright (c) 1997 Shigio Yamaguchi. All rights reserved.
3*0f7f3352SJulian Elischer  * Copyright (c) 1999 Tama Communications Corporation. All rights reserved.
4*0f7f3352SJulian Elischer  *
5*0f7f3352SJulian Elischer  * Redistribution and use in source and binary forms, with or without
6*0f7f3352SJulian Elischer  * modification, are permitted provided that the following conditions
7*0f7f3352SJulian Elischer  * are met:
8*0f7f3352SJulian Elischer  * 1. Redistributions of source code must retain the above copyright
9*0f7f3352SJulian Elischer  *    notice, this list of conditions and the following disclaimer.
10*0f7f3352SJulian Elischer  * 2. Redistributions in binary form must reproduce the above copyright
11*0f7f3352SJulian Elischer  *    notice, this list of conditions and the following disclaimer in the
12*0f7f3352SJulian Elischer  *    documentation and/or other materials provided with the distribution.
13*0f7f3352SJulian Elischer  *
14*0f7f3352SJulian Elischer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*0f7f3352SJulian Elischer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*0f7f3352SJulian Elischer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*0f7f3352SJulian Elischer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*0f7f3352SJulian Elischer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*0f7f3352SJulian Elischer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*0f7f3352SJulian Elischer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*0f7f3352SJulian Elischer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*0f7f3352SJulian Elischer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*0f7f3352SJulian Elischer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*0f7f3352SJulian Elischer  * SUCH DAMAGE.
25*0f7f3352SJulian Elischer  */
26*0f7f3352SJulian Elischer 
27*0f7f3352SJulian Elischer #include <stdio.h>
28*0f7f3352SJulian Elischer #include <stdlib.h>
29*0f7f3352SJulian Elischer #include <unistd.h>
30*0f7f3352SJulian Elischer #include <string.h>
31*0f7f3352SJulian Elischer #include <sys/param.h>
32*0f7f3352SJulian Elischer #include <errno.h>
33*0f7f3352SJulian Elischer #include "../pathconv.h"
34*0f7f3352SJulian Elischer 
35*0f7f3352SJulian Elischer int
main(int argc,char * argv[])36*0f7f3352SJulian Elischer main(int argc, char *argv[])
37*0f7f3352SJulian Elischer {
38*0f7f3352SJulian Elischer 	char result[MAXPATHLEN];
39*0f7f3352SJulian Elischer 	char cwd[MAXPATHLEN];
40*0f7f3352SJulian Elischer 
41*0f7f3352SJulian Elischer 	if (argc < 2) {
42*0f7f3352SJulian Elischer 		fprintf(stderr, "usage: abs2rel path [base]\n");
43*0f7f3352SJulian Elischer 		exit(1);
44*0f7f3352SJulian Elischer 	}
45*0f7f3352SJulian Elischer 	if (argc == 2) {
46*0f7f3352SJulian Elischer 		if (!getcwd(cwd, MAXPATHLEN)) {
47*0f7f3352SJulian Elischer 			fprintf(stderr, "cannot get current directory.\n");
48*0f7f3352SJulian Elischer 			exit(1);
49*0f7f3352SJulian Elischer 		}
50*0f7f3352SJulian Elischer 	} else
51*0f7f3352SJulian Elischer 		strcpy(cwd, argv[2]);
52*0f7f3352SJulian Elischer 
53*0f7f3352SJulian Elischer 	if (abs2rel(argv[1], cwd, result, MAXPATHLEN)) {
54*0f7f3352SJulian Elischer 		printf("%s\n", result);
55*0f7f3352SJulian Elischer 	} else
56*0f7f3352SJulian Elischer 		printf("ERROR\n");
57*0f7f3352SJulian Elischer 	exit(0);
58*0f7f3352SJulian Elischer }
59