Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 11 Apr 1999 22:49:18 GMT
From:      howardjp@wam.umd.edu
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/11092: readlink(1) from OpenBSD
Message-ID:  <199904112249.WAA72940@byzantine.student.umd.edu>

next in thread | raw e-mail | index | archive | help

>Number:         11092
>Category:       bin
>Synopsis:       readlink(1) from OpenBSD
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Apr 11 19:50:01 PDT 1999
>Closed-Date:
>Last-Modified:
>Originator:     James Howard
>Release:        FreeBSD 3.1-RELEASE i386
>Organization:
University of Maryland
>Environment:
	
FreeBSD byzantine.student.umd.edu 3.1-RELEASE FreeBSD 3.1-RELEASE #0: Mon Feb 15 11:08:08 GMT 1999     jkh@usw3.freebsd.org:/usr/src/sys/compile/GENERIC  i386

>Description:

	This is the readlink command from OpenBSD, kind of handy sometimes.

>How-To-Repeat:
>Fix:

	Here is a shar file containing the program, manpage, and makefile,
	all unmodified from the OpenBSD source tree.

# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	Makefile
#	readlink.1
#	readlink.c
#
echo x - Makefile
sed 's/^X//' >Makefile << 'END-of-Makefile'
X#	$OpenBSD: Makefile,v 1.2 1997/08/18 20:30:59 kstailey Exp $
X
XPROG=	readlink
X
X.include <bsd.prog.mk>
END-of-Makefile
echo x - readlink.1
sed 's/^X//' >readlink.1 << 'END-of-readlink.1'
X.\"	$OpenBSD: readlink.1,v 1.4 1998/09/27 16:57:50 aaron Exp $
X.\"
X.\" Copyright (c) 1990, 1993
X.\"	The Regents of the University of California.  All rights reserved.
X.\"
X.\" This code is derived from software contributed to Berkeley by
X.\" the Institute of Electrical and Electronics Engineers, Inc.
X.\"
X.\" Redistribution and use in source and binary forms, with or without
X.\" modification, are permitted provided that the following conditions
X.\" are met:
X.\" 1. Redistributions of source code must retain the above copyright
X.\"    notice, this list of conditions and the following disclaimer.
X.\" 2. Redistributions in binary form must reproduce the above copyright
X.\"    notice, this list of conditions and the following disclaimer in the
X.\"    documentation and/or other materials provided with the distribution.
X.\" 3. All advertising materials mentioning features or use of this software
X.\"    must display the following acknowledgement:
X.\"	This product includes software developed by the University of
X.\"	California, Berkeley and its contributors.
X.\" 4. Neither the name of the University nor the names of its contributors
X.\"    may be used to endorse or promote products derived from this software
X.\"    without specific prior written permission.
X.\"
X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
X.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
X.\" SUCH DAMAGE.
X.\"
X.Dd August 18, 1997
X.Dt READLINK 1
X.Os
X.Sh NAME
X.Nm readlink
X.Nd display target of symbolic link on standard output
X.Sh SYNOPSIS
X.Nm readlink
X.Op Fl fn
X.Ar file
X.Sh DESCRIPTION
XThe
X.Nm readlink
Xutility when invoked with the pathname of a symbolic link as its
Xargument dereferences the symbolic link and prints the name of target
Xon standard output.  If readlink is invoked with an argument other
Xthan the pathname of a symbolic link, it exits with a non-zero exit
Xcode without printing anything.
X.Pp
XThe following options are available:
X.Bl -tag -width flag
X.It Fl f
XCanonicalize by following every symlink in every component of the given
Xpath recursively.
X.It Fl n
XDo not print a trailing newline character.
X.El
X.Pp
XThe
X.Nm readlink
Xutility exits 0 on success or >0 if an error occurred.
X.Sh SEE ALSO
X.Xr readlink 2
X.Sh HISTORY
XThe
X.Nm readlink
Xutility first appeared in
X.Ox 2.1 .
END-of-readlink.1
echo x - readlink.c
sed 's/^X//' >readlink.c << 'END-of-readlink.c'
X/*
X * $OpenBSD: readlink.c,v 1.18 1998/08/24 14:45:33 kstailey Exp $
X *
X * Copyright (c) 1997
X *	Kenneth Stailey (hereinafter referred to as the author)
X *
X * Redistribution and use in source and binary forms, with or without
X * modification, are permitted provided that the following conditions
X * are met:
X * 1. Redistributions of source code must retain the above copyright
X *    notice, this list of conditions and the following disclaimer.
X * 2. Redistributions in binary form must reproduce the above copyright
X *    notice, this list of conditions and the following disclaimer in the
X *    documentation and/or other materials provided with the distribution.
X * 3. The name of the author may not be used to endorse or promote products
X *    derived from this software without specific prior written permission.
X *
X * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
X * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
X * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
X * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
X * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
X * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
X * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
X * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
X * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
X */
X
X#include <limits.h>
X#include <errno.h>
X#include <stdio.h>
X#include <stdlib.h>
X#include <string.h>
X#include <unistd.h>
X
Xint
Xmain(argc, argv)
X	int argc;
X	char **argv;
X{
X	char buf[PATH_MAX];
X	int n, ch, nflag = 0, fflag = 0;
X	extern int optind;
X
X	while ((ch = getopt(argc, argv, "fn")) != -1)
X		switch (ch) {
X		case 'f':
X			fflag = 1;
X			break;
X		case 'n':
X			nflag = 1;
X			break;
X		default:
X			(void)fprintf(stderr,
X			    "usage: readlink [-n] [-f] symlink\n");
X			exit(1);
X		}
X	argc -= optind;
X	argv += optind;
X
X	if (argc != 1) {
X		fprintf(stderr, "usage: readlink [-n] [-f] symlink\n");
X		exit(1);
X	}
X
X	n = strlen(argv[0]);
X	if (n > PATH_MAX - 1) {
X		fprintf(stderr,
X			"readlink: filename longer than PATH_MAX-1 (%d)\n",
X			PATH_MAX - 1);
X		exit(1);
X	}
X
X	if (fflag)
X		realpath(argv[0], buf);
X	else {
X		if ((n = readlink(argv[0], buf, sizeof buf-1)) < 0)
X			exit(1);
X		buf[n] = '\0';
X	}
X
X	printf("%s", buf);
X	if (!nflag)
X		putchar('\n');
X	exit(0);
X}
END-of-readlink.c
exit


>Release-Note:
>Audit-Trail:
>Unformatted:


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199904112249.WAA72940>