vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| On Sun, 3 Apr 2005, Han Boetes wrote: > After a discussion on #openbsd on irc.freenode.net a frontend for > realpath(3) was requested. > > I did some creative cutting and pasting and had the code reviewed > on #openbsd > > FreeBSD and Debian also have a binary for this, though my binary > is based on dirname(1). The manpage is based on realpath(3) and > dirname(1). > > I found the ``setlocale(LC_ALL, "");'' in the dirname source, I > wonder if it's really usefull in this case. > > I hope you find it a usefull addition. readlink -f does it already. Note if you are running really -current: due to the introduction of stat(1), the wrong version of readlink might be installed. This will be fixed very soon. -Otto > > > /* $Id: realpath.c,v 1.3 2005/04/03 09:23:25 han Exp $ */ > > /* > * Copyright (c) 2005 Han Boetes <han@mijncomputer.nl> > * > * 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. > */ > > #ifndef lint > static char rcsid[] = "$Id: realpath.c,v 1.3 2005/04/03 09:23:25 han Exp $"; > #endif /* not lint */ > > #include <err.h> > #include <locale.h> > #include <stdio.h> > #include <sys/param.h> > #include <stdlib.h> > > int > main(int argc, char *argv[]) > { > char path[MAXPATHLEN]; > extern char *__progname; > > setlocale(LC_ALL, ""); > > if (argc != 2) { > (void)fprintf(stderr, "Usage: %s pathname\n", __progname); > exit(1); > } > > if ((realpath(argv[1],path)) == NULL) > err(1, NULL); > puts(path); > exit(0); > } > > > > .\" $Id: realpath.1,v 1.1 2005/04/03 09:19:28 han Exp $ > .\" Copyright (c) 2005, Han Boetes <han@mijncomputer.nl> > .\" > .\" Permission to use, copy, modify, and distribute this documentation 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 DOCUMENTATION IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL > .\" WARRANTIES WITH REGARD TO THIS DOCUMENTATION 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 DOCUMENTATION > .\" > .Dd Sun Apr 3, 2005 > .Dt REALPATH 1 > .Os > .Sh NAME > .Nm realpath > .Nd returns the canonicalized absolute pathname > .Sh SYNOPSIS > .Nm realpath > .Ar pathname > .Sh DESCRIPTION > .Nm > resolves all symbolic links, extra > .Dq / > characters and references to > .Pa /./ > and > .Pa /../ > in > .Fa pathname , > and writes the resulting absolute pathname to the standard output. > .Pp > .Nm > will resolve both absolute and relative paths > and return the absolute pathname corresponding to > .Fa pathname . > .Pp > The > .Nm > utility > exits 0 on success or >0 if an error occurred. > .Sh EXAMPLES > The following line sets the shell variable > .Ev FOO > to whatever the real path to the current working directory is: > .Pp > .Dl FOO=`realpath $PWD` > .Sh SEE ALSO > .Xr basename 1 , > .Xr dirname 1 , > .Xr realpath 3 > > > > > # Han |