xref: /freebsd/lib/libpathconv/tests/rel2abs.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 #include <stdio.h>
27*0f7f3352SJulian Elischer #include <stdlib.h>
28*0f7f3352SJulian Elischer #include <unistd.h>
29*0f7f3352SJulian Elischer #include <string.h>
30*0f7f3352SJulian Elischer #include <sys/param.h>
31*0f7f3352SJulian Elischer #include <errno.h>
32*0f7f3352SJulian Elischer #include "../pathconv.h"
33*0f7f3352SJulian Elischer 
34*0f7f3352SJulian Elischer int
main(int argc,char * argv[])35*0f7f3352SJulian Elischer main(int argc, char *argv[])
36*0f7f3352SJulian Elischer {
37*0f7f3352SJulian Elischer 	char result[MAXPATHLEN];
38*0f7f3352SJulian Elischer 	char cwd[MAXPATHLEN];
39*0f7f3352SJulian Elischer 
40*0f7f3352SJulian Elischer 	if (argc < 2) {
41*0f7f3352SJulian Elischer 		fprintf(stderr, "usage: rel2abs path [base]\n");
42*0f7f3352SJulian Elischer 		exit(1);
43*0f7f3352SJulian Elischer 	}
44*0f7f3352SJulian Elischer 	if (argc == 2) {
45*0f7f3352SJulian Elischer 		if (!getcwd(cwd, MAXPATHLEN)) {
46*0f7f3352SJulian Elischer 			fprintf(stderr, "cannot get current directory.\n");
47*0f7f3352SJulian Elischer 			exit(1);
48*0f7f3352SJulian Elischer 		}
49*0f7f3352SJulian Elischer 	} else
50*0f7f3352SJulian Elischer 		strcpy(cwd, argv[2]);
51*0f7f3352SJulian Elischer 
52*0f7f3352SJulian Elischer 	if (rel2abs(argv[1], cwd, result, MAXPATHLEN)) {
53*0f7f3352SJulian Elischer 		printf("%s\n", result);
54*0f7f3352SJulian Elischer 	} else
55*0f7f3352SJulian Elischer 		printf("ERROR\n");
56*0f7f3352SJulian Elischer 	exit(0);
57*0f7f3352SJulian Elischer }
58