From: git Date: Sun, 26 Apr 2026 14:37:33 +0000 (-0400) Subject: initial public commit X-Git-Url: https://git.datadissipation.net/?a=commitdiff_plain;h=328826c727daa12ed4aa02c566c8a4e3159a872b;p=baseutils.git initial public commit --- 328826c727daa12ed4aa02c566c8a4e3159a872b diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dbbd613 --- /dev/null +++ b/Makefile @@ -0,0 +1,12 @@ +TARGETS = realpath +SRC = ${TARGETS:=.c} + +all: ${TARGETS} + +${TARGETS}: ${SRC} + ${CC} ${CFLAGS} ${LDFLAGS} $@.c -o $@ + +clean: + rm -f *.[oa] ${TARGETS} + +.PHONY: all ${TARGETS} clean diff --git a/README.md b/README.md new file mode 100644 index 0000000..98eaa38 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Some of the programs not found in GNU coreutils and Busybox alternatives + +Mostly ports from BSD systems diff --git a/realpath.1 b/realpath.1 new file mode 100644 index 0000000..7d08232 --- /dev/null +++ b/realpath.1 @@ -0,0 +1,78 @@ +.\"- +.\" Copyright (c) 1990, 1993 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" From: src/bin/pwd/pwd.1,v 1.11 2000/11/20 11:39:39 ru Exp +.\" +.Dd April 2026 +.Dt REALPATH 1 +.Os +.Sh NAME +.Nm realpath +.Nd return resolved physical path +.Sh SYNOPSIS +.Nm +.Op Fl q +.Op Ar path ... +.Sh DESCRIPTION +The +.Nm +utility uses the +.Xr realpath 3 +function to resolve all symbolic links, extra +.Ql / +characters and references to +.Pa /./ +and +.Pa /../ +in +.Ar path . +If +.Ar path +is absent, the current working directory +.Pq Sq Pa .\& +is assumed. +.Pp +If +.Fl q +is specified, warnings will not be printed when +.Xr realpath 3 +fails. +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +Show the physical path of the +.Pa /dev/log +directory silencing warnings if any: +.Bd -literal -offset indent +$ realpath -q /dev/log +/var/run/log +.Ed +.Sh SEE ALSO +.Xr realpath 3 diff --git a/realpath.c b/realpath.c new file mode 100644 index 0000000..0b800d9 --- /dev/null +++ b/realpath.c @@ -0,0 +1,79 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1991, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + char buf[PATH_MAX]; + char *progname; + char *p; + const char *path; + int ch, qflag, rval; + + qflag = 0; + progname = argv[0]; + while ((ch = getopt(argc, argv, "q")) != -1) { + switch (ch) { + case 'q': + qflag = 1; + break; + case '?': + default: + fprintf(stderr, "usage: %s [-q] [path ...]\n", + progname); + exit(1); + } + } + + argc -= optind; + argv += optind; + path = *argv != NULL ? *argv++ : "."; + rval = 0; + + do { + if ((p = realpath(path, buf)) == NULL) { + if (!qflag) + fprintf(stderr, "%s: %s: %s\n", progname, path, + strerror(errno)); + rval = 1; + } else + (void)printf("%s\n", p); + } while ((path = *argv++) != NULL); + + exit(rval); +}