1*3d87fbbdSJohn Marino /*-
29f7604d7SJohn Marino * Copyright (c) 1991, 1993, 1994
39f7604d7SJohn Marino * The Regents of the University of California. All rights reserved.
49f7604d7SJohn Marino *
59f7604d7SJohn Marino * Redistribution and use in source and binary forms, with or without
69f7604d7SJohn Marino * modification, are permitted provided that the following conditions
79f7604d7SJohn Marino * are met:
89f7604d7SJohn Marino * 1. Redistributions of source code must retain the above copyright
99f7604d7SJohn Marino * notice, this list of conditions and the following disclaimer.
109f7604d7SJohn Marino * 2. Redistributions in binary form must reproduce the above copyright
119f7604d7SJohn Marino * notice, this list of conditions and the following disclaimer in the
129f7604d7SJohn Marino * documentation and/or other materials provided with the distribution.
139f7604d7SJohn Marino * 3. Neither the name of the University nor the names of its contributors
149f7604d7SJohn Marino * may be used to endorse or promote products derived from this software
159f7604d7SJohn Marino * without specific prior written permission.
169f7604d7SJohn Marino *
179f7604d7SJohn Marino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
189f7604d7SJohn Marino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199f7604d7SJohn Marino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
209f7604d7SJohn Marino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
219f7604d7SJohn Marino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
229f7604d7SJohn Marino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
239f7604d7SJohn Marino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
249f7604d7SJohn Marino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
259f7604d7SJohn Marino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
269f7604d7SJohn Marino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
279f7604d7SJohn Marino * SUCH DAMAGE.
289f7604d7SJohn Marino *
29*3d87fbbdSJohn Marino * $FreeBSD: head/bin/realpath/realpath.c 223372 2011-06-21 19:34:57Z ru $
309f7604d7SJohn Marino */
319f7604d7SJohn Marino
32*3d87fbbdSJohn Marino
339f7604d7SJohn Marino #include <sys/param.h>
349f7604d7SJohn Marino
359f7604d7SJohn Marino #include <err.h>
369f7604d7SJohn Marino #include <stdio.h>
379f7604d7SJohn Marino #include <stdlib.h>
389f7604d7SJohn Marino #include <unistd.h>
399f7604d7SJohn Marino
40*3d87fbbdSJohn Marino static void usage(void) __dead2;
419f7604d7SJohn Marino
429f7604d7SJohn Marino int
main(int argc,char * argv[])439f7604d7SJohn Marino main(int argc, char *argv[])
449f7604d7SJohn Marino {
459f7604d7SJohn Marino char buf[PATH_MAX];
46*3d87fbbdSJohn Marino char *p;
47*3d87fbbdSJohn Marino const char *path;
48*3d87fbbdSJohn Marino int ch, qflag, rval;
499f7604d7SJohn Marino
50*3d87fbbdSJohn Marino qflag = 0;
51*3d87fbbdSJohn Marino while ((ch = getopt(argc, argv, "q")) != -1) {
529f7604d7SJohn Marino switch (ch) {
53*3d87fbbdSJohn Marino case 'q':
54*3d87fbbdSJohn Marino qflag = 1;
559f7604d7SJohn Marino break;
569f7604d7SJohn Marino case '?':
579f7604d7SJohn Marino default:
589f7604d7SJohn Marino usage();
599f7604d7SJohn Marino }
60*3d87fbbdSJohn Marino }
619f7604d7SJohn Marino argc -= optind;
629f7604d7SJohn Marino argv += optind;
63*3d87fbbdSJohn Marino path = *argv != NULL ? *argv++ : ".";
64*3d87fbbdSJohn Marino rval = 0;
65*3d87fbbdSJohn Marino do {
66*3d87fbbdSJohn Marino if ((p = realpath(path, buf)) == NULL) {
67*3d87fbbdSJohn Marino if (!qflag)
68*3d87fbbdSJohn Marino warn("%s", path);
69*3d87fbbdSJohn Marino rval = 1;
70*3d87fbbdSJohn Marino } else
71*3d87fbbdSJohn Marino (void)printf("%s\n", p);
72*3d87fbbdSJohn Marino } while ((path = *argv++) != NULL);
73*3d87fbbdSJohn Marino exit(rval);
749f7604d7SJohn Marino }
759f7604d7SJohn Marino
769f7604d7SJohn Marino static void
usage(void)779f7604d7SJohn Marino usage(void)
789f7604d7SJohn Marino {
79*3d87fbbdSJohn Marino
80*3d87fbbdSJohn Marino (void)fprintf(stderr, "usage: realpath [-q] [path ...]\n");
819f7604d7SJohn Marino exit(1);
829f7604d7SJohn Marino }
83