diff options
Diffstat (limited to 'spec.c')
| -rw-r--r-- | spec.c | 47 |
1 files changed, 38 insertions, 9 deletions
@@ -1,4 +1,4 @@ -/* $NetBSD: spec.c,v 1.89 2014/04/24 17:22:41 christos Exp $ */ +/* $NetBSD: spec.c,v 1.92 2024/12/05 17:17:43 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -67,7 +67,7 @@ #if 0 static char sccsid[] = "@(#)spec.c 8.2 (Berkeley) 4/28/95"; #else -__RCSID("$NetBSD: spec.c,v 1.89 2014/04/24 17:22:41 christos Exp $"); +__RCSID("$NetBSD: spec.c,v 1.92 2024/12/05 17:17:43 christos Exp $"); #endif #endif /* not lint */ @@ -224,10 +224,14 @@ noparent: mtree_err("no parent node"); */ if (strcmp(centry->name, ".") == 0 && centry->type == 0) centry->type = F_DIR; - if (strcmp(centry->name, ".") != 0 || - centry->type != F_DIR) + if (strcmp(centry->name, ".") != 0) mtree_err( - "root node must be the directory `.'"); + "root node must be the directory `.'," + " found `%s'", centry->name); + if (centry->type != F_DIR) + mtree_err( + "root node must type %#x != %#x", + F_DIR, centry->type); last = root = centry; root->parent = root; } else if (pathparent != NULL) { @@ -363,7 +367,8 @@ dump_nodes(FILE *fp, const char *dir, NODE *root, int pathlast) appendfield(fp, pathlast, "device=%#jx", (uintmax_t)cur->st_rdev); if (MATCHFLAG(F_NLINK)) - appendfield(fp, pathlast, "nlink=%d", cur->st_nlink); + appendfield(fp, pathlast, "nlink=%ju", + (uintmax_t)cur->st_nlink); if (MATCHFLAG(F_SLINK)) appendfield(fp, pathlast, "link=%s", vispath(cur->slink)); @@ -538,7 +543,8 @@ replacenode(NODE *cur, NODE *new) static void set(char *t, NODE *ip) { - int type, value, len; + int type, value; + size_t len; gid_t gid; uid_t uid; char *kw, *val, *md, *ep; @@ -837,7 +843,7 @@ addchild(NODE *pathparent, NODE *centry) * directories sort after non-directories, but otherwise sort in * strcmp() order. * - * Keep this in sync with dcmp() in create.c. + * Keep this in sync with dcmp() below. */ static int nodecmp(const NODE *a, const NODE *b) @@ -846,7 +852,30 @@ nodecmp(const NODE *a, const NODE *b) if ((a->type & F_DIR) != 0) { if ((b->type & F_DIR) == 0) return 1; - } else if ((b->type & F_DIR) != 0) + } else if ((b->type & F_DIR) != 0) { return -1; + } return strcmp(a->name, b->name); } + +/* + * dcmp -- + * used as a comparison function passed to fts_open() to control + * the order in which fts_read() returns results. We make + * directories sort after non-directories, but otherwise sort in + * strcmp() order. + * + * Keep this in sync with nodecmp() above. + */ +int +dcmp(const FTSENT *FTS_CONST *a, const FTSENT *FTS_CONST *b) +{ + + 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); +} |
