A tiny realpath(3) wrapper to make a porter's life easier.
Feedback kettenis deraadt cheloha sthen
OK cheloha martijn deraadt
./usr/bin/rdist
./usr/bin/rdistd
./usr/bin/readlink
+./usr/bin/realpath
./usr/bin/renice
./usr/bin/reset
./usr/bin/rev
./usr/share/man/man1/rdist.1
./usr/share/man/man1/rdistd.1
./usr/share/man/man1/readlink.1
+./usr/share/man/man1/realpath.1
./usr/share/man/man1/register-plist.1
./usr/share/man/man1/rev.1
./usr/share/man/man1/rlog.1
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $OpenBSD: realpath.3,v 1.25 2019/12/11 20:01:50 bluhm Exp $
+.\" $OpenBSD: realpath.3,v 1.26 2021/10/13 15:04:53 kn Exp $
.\"
-.Dd $Mdocdate: December 11 2019 $
+.Dd $Mdocdate: October 13 2021 $
.Dt REALPATH 3
.Os
.Sh NAME
.El
.Sh SEE ALSO
.Xr readlink 1 ,
+.Xr realpath 1 ,
.Xr getcwd 3
.Sh STANDARDS
The
-# $OpenBSD: Makefile,v 1.164 2021/09/01 19:55:53 job Exp $
+# $OpenBSD: Makefile,v 1.165 2021/10/13 15:04:53 kn Exp $
.include <bsd.own.mk>
nfsstat nice nm nl nohup openssl pagesize passwd paste patch pctr \
pkg-config pkill \
pr printenv printf quota radioctl rcs rdist rdistd \
- readlink renice rev rpcgen rpcinfo rs rsync rup rusers rwall \
+ readlink realpath renice rev rpcgen rpcinfo rs rsync rup rusers rwall \
sdiff script sed sendbug shar showmount signify skey \
skeyaudit skeyinfo skeyinit sndioctl sndiod snmp \
sort spell split ssh stat su systat \
-.\" $OpenBSD: readlink.1,v 1.13 2010/09/03 11:09:29 jmc Exp $
+.\" $OpenBSD: readlink.1,v 1.14 2021/10/13 15:04:53 kn Exp $
.\"
.\" Copyright (c) 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: September 3 2010 $
+.Dd $Mdocdate: October 13 2021 $
.Dt READLINK 1
.Os
.Sh NAME
.Sh EXIT STATUS
.Ex -std readlink
.Sh SEE ALSO
+.Xr realpath 1 ,
.Xr readlink 2 ,
.Xr realpath 3
.Sh HISTORY
--- /dev/null
+# $OpenBSD: Makefile,v 1.1 2021/10/13 15:04:53 kn Exp $
+
+PROG= realpath
+
+.include <bsd.prog.mk>
--- /dev/null
+.\" $OpenBSD: realpath.1,v 1.1 2021/10/13 15:04:53 kn Exp $
+.\"
+.\" Copyright (c) 2021 Klemens Nanni <kn@openbsd.org>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: October 13 2021 $
+.Dt REALPATH 1
+.Os
+.Sh NAME
+.Nm realpath
+.Nd print the canonicalized absolute pathname
+.Sh SYNOPSIS
+.Nm
+.Op Fl q
+.Ar file
+.Sh DESCRIPTION
+The
+.Nm
+utility uses
+.Xr realpath 3
+to resolve all symbolic links, extra
+.Dq /
+characters and references to
+.Pa /./
+and
+.Pa /../
+in
+.Ar file ,
+and prints the absolute pathname on standard output.
+.Pp
+The options are as follows:
+.Bl -tag -width Ds
+.It Fl q
+Do not print errors.
+.El
+.Sh EXIT STATUS
+.Ex -std
+.Sh SEE ALSO
+.Xr readlink 1 ,
+.Xr realpath 3
+.Sh HISTORY
+The
+.Nm
+utility first appeared in
+.Ox 7.1 .
--- /dev/null
+/* $OpenBSD: realpath.c,v 1.1 2021/10/13 15:04:53 kn Exp $ */
+/*
+ * Copyright (c) 2021 Klemens Nanni <kn@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <err.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+void __dead
+usage(void)
+{
+ fprintf(stderr, "usage: %s [-q] file\n", getprogname());
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ int ch, qflag = 0;
+ char *buf;
+
+ if (pledge("stdio rpath", NULL) == -1)
+ err(1, "pledge");
+
+ while ((ch = getopt(argc, argv, "q")) != -1) {
+ switch (ch) {
+ case 'q':
+ qflag = 1;
+ break;
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ if (argc != 1)
+ usage();
+
+ buf = realpath(argv[0], NULL);
+ if (buf == NULL) {
+ if (qflag)
+ return (1);
+ err(1, "%s", argv[0]);
+ }
+
+ printf("%s\n", buf);
+ return (0);
+}