2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: lndir.c /main/2 1996/11/01 10:11:58 drk $ */
24 /* Create shadow link tree (after X11R4 script of the same name)
25 Mark Reinhold (mbr@lcs.mit.edu)/3 January 1990 */
27 /* Copyright 1990, Massachusetts Institute of Technology
29 Permission to use, copy, modify, and distribute this program for any purpose
30 and without fee is hereby granted, provided that this copyright and
31 permission notice appear on all copies and supporting documentation, that
32 the name of MIT not be used in advertising or publicity pertaining to
33 distribution of this program without specific prior permission, and that
34 notice be given in supporting documentation that copying and distribution is
35 by permission of MIT. MIT makes no representations about the suitability of
36 this software for any purpose. It is provided "as is" without expressed or
40 /* From the original /bin/sh script:
42 Used to create a copy of the a directory tree that has links for all
43 non-directories (except those named RCS or SCCS). If you are
44 building the distribution on more than one machine, you should use
47 If your master sources are located in /usr/local/src/X and you would like
48 your link tree to be in /usr/local/src/new-X, do the following:
50 % mkdir /usr/local/src/new-X
51 % cd /usr/local/src/new-X
58 #include <sys/param.h>
85 quit (code, fmt, a1, a2, a3)
88 fprintf (stderr, fmt, a1, a2, a3);
102 msg (fmt, a1, a2, a3)
105 fprintf (stderr, fmt, a1, a2, a3);
110 /* Recursively create symbolic links from the current directory to the "from"
111 directory. Assumes that files described by fs and ts are directories. */
113 dodir (fn, fs, ts, rel)
114 char *fn; /* name of "from" directory, either absolute or
116 struct stat *fs, *ts; /* stats for the "from" directory and cwd */
117 int rel; /* if true, prepend "../" to fn before using */
121 char buf[MAXPATHLEN + 1], *p;
122 char symbuf[MAXPATHLEN + 1];
126 if ((fs->st_dev == ts->st_dev) && (fs->st_ino == ts->st_ino)) {
127 msg ("%s: From and to directories are identical!", fn);
137 if (!(df = opendir (buf))) {
138 msg ("%s: Cannot opendir", buf);
142 p = buf + strlen (buf);
144 n_dirs = fs->st_nlink;
145 while (dp = readdir (df)) {
146 strcpy (p, dp->d_name);
149 if (stat (buf, &sb) < 0) {
154 if (sb.st_mode & S_IFDIR) {
157 if (dp->d_name[0] == '.' &&
158 (dp->d_name[1] == '\0' || (dp->d_name[1] == '.' &&
159 dp->d_name[2] == '\0')))
161 if (!strcmp (dp->d_name, "RCS"))
163 if (!strcmp (dp->d_name, "SCCS"))
166 printf ("%s:\n", buf);
167 if ((stat (dp->d_name, &sc) < 0) && (errno == ENOENT)) {
168 if (mkdir (dp->d_name, 0777) < 0 ||
169 stat (dp->d_name, &sc) < 0) {
174 if (readlink (dp->d_name, symbuf, sizeof(symbuf) - 1) >= 0) {
175 msg ("%s: is a link instead of a directory\n", dp->d_name);
178 if (chdir (dp->d_name) < 0) {
182 dodir (buf, &sb, &sc, (buf[0] != '/'));
183 if (chdir ("..") < 0)
190 if (symlink (buf, dp->d_name) < 0) {
191 int saverrno = errno;
193 symlen = readlink(dp->d_name, symbuf, sizeof(symbuf) - 1);
196 symbuf[symlen] = '\0';
197 if (symlen < 0 || strcmp(symbuf, buf))
215 if (ac > 1 && !strcmp(av[1], "-silent")) {
218 if (ac < silent + 2 || ac > silent + 3)
219 quit (1, "usage: %s [-silent] fromdir [todir]", av[0]);
222 if (ac == silent + 3)
228 if (stat (tn, &ts) < 0)
230 if (!(ts.st_mode & S_IFDIR))
231 quit (2, "%s: Not a directory", tn);
236 if (stat (fn, &fs) < 0)
238 if (!(fs.st_mode & S_IFDIR))
239 quit (2, "%s: Not a directory", fn);
241 exit (dodir (fn, &fs, &ts, 0));