1999-07-06 19:11:14 +04:00
|
|
|
/* $NetBSD: create.c,v 1.23 1999/07/06 15:11:15 christos Exp $ */
|
1995-03-08 00:12:04 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*-
|
1995-03-07 18:28:32 +03:00
|
|
|
* Copyright (c) 1989, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. 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.
|
|
|
|
*/
|
|
|
|
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1995-03-08 00:12:04 +03:00
|
|
|
#if 0
|
1995-03-07 18:28:32 +03:00
|
|
|
static char sccsid[] = "@(#)create.c 8.1 (Berkeley) 6/6/93";
|
1995-03-08 00:12:04 +03:00
|
|
|
#else
|
1999-07-06 19:11:14 +04:00
|
|
|
__RCSID("$NetBSD: create.c,v 1.23 1999/07/06 15:11:15 christos Exp $");
|
1995-03-08 00:12:04 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
1993-11-02 10:51:06 +03:00
|
|
|
#include <fcntl.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <fts.h>
|
1993-11-02 10:51:06 +03:00
|
|
|
#include <grp.h>
|
1999-07-06 16:59:12 +04:00
|
|
|
#include <md5.h>
|
1993-11-02 10:51:06 +03:00
|
|
|
#include <pwd.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdio.h>
|
1997-10-17 15:46:30 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "mtree.h"
|
1993-11-02 10:51:06 +03:00
|
|
|
#include "extern.h"
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
#define INDENTNAMELEN 15
|
|
|
|
#define MAXLINELEN 80
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
extern int crc_total, ftsoptions;
|
|
|
|
extern int dflag, sflag;
|
1998-10-10 11:50:27 +04:00
|
|
|
extern int keys;
|
1993-11-02 10:51:06 +03:00
|
|
|
extern char fullpath[MAXPATHLEN];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
static gid_t gid;
|
|
|
|
static uid_t uid;
|
|
|
|
static mode_t mode;
|
1998-10-10 11:50:27 +04:00
|
|
|
static u_long flags;
|
1993-11-02 10:51:06 +03:00
|
|
|
|
|
|
|
static int dsort __P((const FTSENT **, const FTSENT **));
|
|
|
|
static void output __P((int *, const char *, ...));
|
1998-10-10 11:50:27 +04:00
|
|
|
static int statd __P((FTS *, FTSENT *, uid_t *, gid_t *, mode_t *,
|
|
|
|
u_long *));
|
1993-11-02 10:51:06 +03:00
|
|
|
static void statf __P((FTSENT *));
|
|
|
|
|
|
|
|
void
|
1993-03-21 12:45:37 +03:00
|
|
|
cwalk()
|
|
|
|
{
|
1997-10-17 15:46:30 +04:00
|
|
|
FTS *t;
|
|
|
|
FTSENT *p;
|
1993-03-21 12:45:37 +03:00
|
|
|
time_t clock;
|
1998-07-06 10:56:06 +04:00
|
|
|
char *argv[2], host[MAXHOSTNAMELEN + 1];
|
1993-11-02 10:51:06 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
(void)time(&clock);
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)gethostname(host, sizeof(host));
|
1998-07-06 10:56:06 +04:00
|
|
|
host[sizeof(host) - 1] = '\0';
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)printf(
|
|
|
|
"#\t user: %s\n#\tmachine: %s\n#\t tree: %s\n#\t date: %s",
|
|
|
|
getlogin(), host, fullpath, ctime(&clock));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
argv[0] = ".";
|
1993-11-02 10:51:06 +03:00
|
|
|
argv[1] = NULL;
|
|
|
|
if ((t = fts_open(argv, ftsoptions, dsort)) == NULL)
|
1998-10-08 06:04:55 +04:00
|
|
|
mtree_err("fts_open: %s", strerror(errno));
|
1997-07-11 11:05:29 +04:00
|
|
|
while ((p = fts_read(t)) != NULL)
|
1993-03-21 12:45:37 +03:00
|
|
|
switch(p->fts_info) {
|
|
|
|
case FTS_D:
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)printf("\n# %s\n", p->fts_path);
|
1998-10-10 11:50:27 +04:00
|
|
|
statd(t, p, &uid, &gid, &mode, &flags);
|
1993-11-02 10:51:06 +03:00
|
|
|
statf(p);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case FTS_DP:
|
1993-11-02 10:51:06 +03:00
|
|
|
if (p->fts_level > 0)
|
|
|
|
(void)printf("# %s\n..\n\n", p->fts_path);
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case FTS_DNR:
|
|
|
|
case FTS_ERR:
|
|
|
|
case FTS_NS:
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)fprintf(stderr,
|
|
|
|
"mtree: %s: %s\n", p->fts_path, strerror(errno));
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
default:
|
1993-11-02 10:51:06 +03:00
|
|
|
if (!dflag)
|
|
|
|
statf(p);
|
|
|
|
break;
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)fts_close(t);
|
|
|
|
if (sflag && keys & F_CKSUM)
|
|
|
|
(void)fprintf(stderr,
|
1997-07-11 11:05:29 +04:00
|
|
|
"mtree: %s checksum: %u\n", fullpath, crc_total);
|
1993-11-02 10:51:06 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
static void
|
|
|
|
statf(p)
|
|
|
|
FTSENT *p;
|
|
|
|
{
|
|
|
|
struct group *gr;
|
|
|
|
struct passwd *pw;
|
1998-10-08 06:04:55 +04:00
|
|
|
u_int32_t len, val;
|
1993-11-02 10:51:06 +03:00
|
|
|
int fd, indent;
|
1999-07-06 16:59:12 +04:00
|
|
|
char md5buf[33], *md5cp;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
if (S_ISDIR(p->fts_statp->st_mode))
|
|
|
|
indent = printf("%s", p->fts_name);
|
|
|
|
else
|
|
|
|
indent = printf(" %s", p->fts_name);
|
|
|
|
|
|
|
|
if (indent > INDENTNAMELEN)
|
|
|
|
indent = MAXLINELEN;
|
|
|
|
else
|
|
|
|
indent += printf("%*s", INDENTNAMELEN - indent, "");
|
|
|
|
|
|
|
|
if (!S_ISREG(p->fts_statp->st_mode))
|
|
|
|
output(&indent, "type=%s", inotype(p->fts_statp->st_mode));
|
1998-08-27 22:03:42 +04:00
|
|
|
if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) {
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_UNAME && (pw = getpwuid(p->fts_statp->st_uid)))
|
|
|
|
output(&indent, "uname=%s", pw->pw_name);
|
|
|
|
else /* if (keys & F_UID) */
|
|
|
|
output(&indent, "uid=%u", p->fts_statp->st_uid);
|
1998-08-27 22:03:42 +04:00
|
|
|
}
|
|
|
|
if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) {
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_GNAME && (gr = getgrgid(p->fts_statp->st_gid)))
|
1993-11-17 14:00:52 +03:00
|
|
|
output(&indent, "gname=%s", gr->gr_name);
|
1993-11-02 10:51:06 +03:00
|
|
|
else /* if (keys & F_GID) */
|
|
|
|
output(&indent, "gid=%u", p->fts_statp->st_gid);
|
1998-08-27 22:03:42 +04:00
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode)
|
|
|
|
output(&indent, "mode=%#o", p->fts_statp->st_mode & MBITS);
|
|
|
|
if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
|
|
|
|
output(&indent, "nlink=%u", p->fts_statp->st_nlink);
|
1996-09-05 13:24:19 +04:00
|
|
|
if (keys & F_SIZE && S_ISREG(p->fts_statp->st_mode))
|
1994-03-27 13:09:49 +04:00
|
|
|
output(&indent, "size=%qd", p->fts_statp->st_size);
|
1998-10-08 06:04:55 +04:00
|
|
|
#ifndef __APPLE__
|
1999-07-06 19:11:14 +04:00
|
|
|
# ifdef BSD4_4
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_TIME)
|
1995-03-07 18:28:32 +03:00
|
|
|
output(&indent, "time=%ld.%ld",
|
1996-02-01 03:04:52 +03:00
|
|
|
p->fts_statp->st_mtimespec.tv_sec,
|
|
|
|
p->fts_statp->st_mtimespec.tv_nsec);
|
1999-07-06 19:11:14 +04:00
|
|
|
# else
|
|
|
|
output(&indent, "time=%ld.%ld",
|
|
|
|
p->fts_statp->st_mtime, 0);
|
|
|
|
# endif
|
1998-10-08 06:04:55 +04:00
|
|
|
#else
|
|
|
|
if (keys & F_TIME)
|
|
|
|
output(&indent, "time=%ld.%ld",
|
|
|
|
p->fts_statp->st_mtimespec.ts_sec,
|
|
|
|
p->fts_statp->st_mtimespec.ts_nsec);
|
|
|
|
#endif
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
|
|
|
|
if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 ||
|
|
|
|
crc(fd, &val, &len))
|
1998-10-08 06:04:55 +04:00
|
|
|
mtree_err("%s: %s", p->fts_accpath, strerror(errno));
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)close(fd);
|
|
|
|
output(&indent, "cksum=%lu", val);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1999-07-06 16:59:12 +04:00
|
|
|
if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) {
|
|
|
|
if ((md5cp = MD5File(p->fts_accpath, md5buf)) == NULL)
|
|
|
|
mtree_err("%s: %s", p->fts_accpath, "MD5File");
|
|
|
|
output(&indent, "md5=%s", md5cp);
|
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_SLINK &&
|
|
|
|
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
|
|
|
|
output(&indent, "link=%s", rlink(p->fts_accpath));
|
1998-10-10 11:50:27 +04:00
|
|
|
if (keys & F_FLAGS && p->fts_statp->st_flags != flags)
|
|
|
|
output(&indent, "flags=%s",
|
|
|
|
flags_to_string(p->fts_statp->st_flags, "none"));
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)putchar('\n');
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1999-02-11 18:32:23 +03:00
|
|
|
/* XXX
|
|
|
|
* FLAGS2INDEX will fail once the user and system settable bits need more
|
|
|
|
* than one byte, respectively.
|
|
|
|
*/
|
|
|
|
#define FLAGS2INDEX(x) (((x >> 8) & 0x0000ff00) | (x & 0x000000ff))
|
|
|
|
|
1998-11-03 18:14:40 +03:00
|
|
|
#define MTREE_MAXGID 5000
|
|
|
|
#define MTREE_MAXUID 5000
|
1999-02-11 18:32:23 +03:00
|
|
|
#define MTREE_MAXMODE (MBITS + 1)
|
|
|
|
#define MTREE_MAXFLAGS (FLAGS2INDEX(CH_MASK) + 1) /* 1808 */
|
1998-11-03 18:14:40 +03:00
|
|
|
#define MTREE_MAXS 16
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
static int
|
1998-10-10 11:50:27 +04:00
|
|
|
statd(t, parent, puid, pgid, pmode, pflags)
|
1993-03-21 12:45:37 +03:00
|
|
|
FTS *t;
|
|
|
|
FTSENT *parent;
|
|
|
|
uid_t *puid;
|
|
|
|
gid_t *pgid;
|
|
|
|
mode_t *pmode;
|
1998-10-10 11:50:27 +04:00
|
|
|
u_long *pflags;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-17 15:46:30 +04:00
|
|
|
FTSENT *p;
|
|
|
|
gid_t sgid;
|
|
|
|
uid_t suid;
|
|
|
|
mode_t smode;
|
1998-10-10 11:50:27 +04:00
|
|
|
u_long sflags;
|
1993-11-02 10:51:06 +03:00
|
|
|
struct group *gr;
|
|
|
|
struct passwd *pw;
|
1993-03-21 12:45:37 +03:00
|
|
|
gid_t savegid;
|
|
|
|
uid_t saveuid;
|
|
|
|
mode_t savemode;
|
1998-10-10 11:50:27 +04:00
|
|
|
u_long saveflags;
|
|
|
|
u_short maxgid, maxuid, maxmode, maxflags;
|
1998-11-03 18:14:40 +03:00
|
|
|
u_short g[MTREE_MAXGID], u[MTREE_MAXUID],
|
|
|
|
m[MTREE_MAXMODE], f[MTREE_MAXFLAGS];
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-17 15:46:30 +04:00
|
|
|
savegid = 0;
|
|
|
|
saveuid = 0;
|
|
|
|
savemode = 0;
|
1998-10-10 11:50:27 +04:00
|
|
|
saveflags = 0;
|
1993-11-02 10:51:06 +03:00
|
|
|
if ((p = fts_children(t, 0)) == NULL) {
|
|
|
|
if (errno)
|
1998-10-08 06:04:55 +04:00
|
|
|
mtree_err("%s: %s", RP(parent), strerror(errno));
|
1993-11-02 10:51:06 +03:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-17 15:46:30 +04:00
|
|
|
memset(g, 0, sizeof(g));
|
|
|
|
memset(u, 0, sizeof(u));
|
|
|
|
memset(m, 0, sizeof(m));
|
1998-10-10 11:50:27 +04:00
|
|
|
memset(f, 0, sizeof(f));
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1998-10-10 11:50:27 +04:00
|
|
|
maxuid = maxgid = maxmode = maxflags = 0;
|
1993-03-21 12:45:37 +03:00
|
|
|
for (; p; p = p->fts_link) {
|
1993-11-02 10:51:06 +03:00
|
|
|
smode = p->fts_statp->st_mode & MBITS;
|
1998-11-03 18:14:40 +03:00
|
|
|
if (smode < MTREE_MAXMODE && ++m[smode] > maxmode) {
|
1993-11-02 10:51:06 +03:00
|
|
|
savemode = smode;
|
|
|
|
maxmode = m[smode];
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
sgid = p->fts_statp->st_gid;
|
1998-11-03 18:14:40 +03:00
|
|
|
if (sgid < MTREE_MAXGID && ++g[sgid] > maxgid) {
|
1993-11-02 10:51:06 +03:00
|
|
|
savegid = sgid;
|
|
|
|
maxgid = g[sgid];
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
suid = p->fts_statp->st_uid;
|
1998-11-03 18:14:40 +03:00
|
|
|
if (suid < MTREE_MAXUID && ++u[suid] > maxuid) {
|
1993-11-02 10:51:06 +03:00
|
|
|
saveuid = suid;
|
|
|
|
maxuid = u[suid];
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-10-10 11:50:27 +04:00
|
|
|
|
1999-02-11 18:32:23 +03:00
|
|
|
sflags = FLAGS2INDEX(p->fts_statp->st_flags);
|
|
|
|
if (sflags < MTREE_MAXFLAGS && ++f[sflags] > maxflags) {
|
|
|
|
saveflags = p->fts_statp->st_flags;
|
|
|
|
maxflags = f[sflags];
|
1998-10-10 11:50:27 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)printf("/set type=file");
|
|
|
|
if (keys & F_GID)
|
1998-12-19 18:38:45 +03:00
|
|
|
(void)printf(" gid=%lu", (u_long)savegid);
|
1998-08-30 07:20:09 +04:00
|
|
|
if (keys & F_GNAME) {
|
1993-11-02 10:51:06 +03:00
|
|
|
if ((gr = getgrgid(savegid)) != NULL)
|
|
|
|
(void)printf(" gname=%s", gr->gr_name);
|
|
|
|
else
|
1998-12-19 18:38:45 +03:00
|
|
|
(void)printf(" gid=%lu", (u_long)savegid);
|
1998-08-30 07:20:09 +04:00
|
|
|
}
|
1998-08-27 22:03:42 +04:00
|
|
|
if (keys & F_UNAME) {
|
1993-11-02 10:51:06 +03:00
|
|
|
if ((pw = getpwuid(saveuid)) != NULL)
|
|
|
|
(void)printf(" uname=%s", pw->pw_name);
|
|
|
|
else
|
1998-12-19 18:38:45 +03:00
|
|
|
(void)printf(" uid=%lu", (u_long)saveuid);
|
1998-08-27 22:03:42 +04:00
|
|
|
}
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_UID)
|
1998-12-19 18:38:45 +03:00
|
|
|
(void)printf(" uid=%lu", (u_long)saveuid);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_MODE)
|
1998-12-19 18:38:45 +03:00
|
|
|
(void)printf(" mode=%#lo", (u_long)savemode);
|
1993-11-02 10:51:06 +03:00
|
|
|
if (keys & F_NLINK)
|
|
|
|
(void)printf(" nlink=1");
|
1999-02-11 18:32:23 +03:00
|
|
|
if (keys & F_FLAGS)
|
1998-10-10 11:50:27 +04:00
|
|
|
(void)printf(" flags=%s",
|
|
|
|
flags_to_string(saveflags, "none"));
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)printf("\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
*puid = saveuid;
|
|
|
|
*pgid = savegid;
|
|
|
|
*pmode = savemode;
|
1998-10-10 11:50:27 +04:00
|
|
|
*pflags = saveflags;
|
1993-11-02 10:51:06 +03:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
static int
|
|
|
|
dsort(a, b)
|
|
|
|
const FTSENT **a, **b;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1993-11-02 10:51:06 +03:00
|
|
|
if (S_ISDIR((*a)->fts_statp->st_mode)) {
|
|
|
|
if (!S_ISDIR((*b)->fts_statp->st_mode))
|
|
|
|
return (1);
|
|
|
|
} else if (S_ISDIR((*b)->fts_statp->st_mode))
|
|
|
|
return (-1);
|
|
|
|
return (strcmp((*a)->fts_name, (*b)->fts_name));
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
#if __STDC__
|
|
|
|
#include <stdarg.h>
|
|
|
|
#else
|
|
|
|
#include <varargs.h>
|
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1993-11-02 10:51:06 +03:00
|
|
|
void
|
|
|
|
#if __STDC__
|
|
|
|
output(int *offset, const char *fmt, ...)
|
|
|
|
#else
|
|
|
|
output(offset, fmt, va_alist)
|
|
|
|
int *offset;
|
|
|
|
char *fmt;
|
|
|
|
va_dcl
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char buf[1024];
|
|
|
|
#if __STDC__
|
|
|
|
va_start(ap, fmt);
|
|
|
|
#else
|
|
|
|
va_start(ap);
|
|
|
|
#endif
|
1995-03-07 18:28:32 +03:00
|
|
|
(void)vsnprintf(buf, sizeof(buf), fmt, ap);
|
1993-11-02 10:51:06 +03:00
|
|
|
va_end(ap);
|
|
|
|
|
1995-03-07 18:28:32 +03:00
|
|
|
if (*offset + strlen(buf) > MAXLINELEN - 3) {
|
1993-11-02 10:51:06 +03:00
|
|
|
(void)printf(" \\\n%*s", INDENTNAMELEN, "");
|
|
|
|
*offset = INDENTNAMELEN;
|
|
|
|
}
|
|
|
|
*offset += printf(" %s", buf) + 1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|