mirror of
https://git.FreeBSD.org/src.git
synced 2024-10-18 02:19:39 +00:00
Switch over to using the new fflagstostr and strtofflags library calls.
This commit is contained in:
parent
0a266c86a2
commit
141d77b8cb
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=61749
@ -5,7 +5,6 @@ NOSHARED?=yes
|
||||
|
||||
PROG= chflags
|
||||
CFLAGS+=-Wall
|
||||
.PATH: ${.CURDIR}/../../lib/libc/gen
|
||||
SRCS= chflags.c setflags.c
|
||||
SRCS= chflags.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -56,8 +56,6 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int setflags __P((char **, u_long *, u_long *));
|
||||
|
||||
void usage __P((void));
|
||||
|
||||
int
|
||||
@ -123,7 +121,7 @@ main(argc, argv)
|
||||
set = val;
|
||||
oct = 1;
|
||||
} else {
|
||||
if (setflags(&flags, &set, &clear))
|
||||
if (strtofflags(&flags, &set, &clear))
|
||||
errx(1, "invalid flag: %s", flags);
|
||||
clear = ~clear;
|
||||
oct = 0;
|
||||
|
@ -3,8 +3,7 @@
|
||||
|
||||
|
||||
PROG= ls
|
||||
SRCS= cmp.c setflags.c ls.c print.c util.c
|
||||
.PATH: ${.CURDIR}/../../lib/libc/gen
|
||||
SRCS= cmp.c ls.c print.c util.c
|
||||
|
||||
.if !defined(RELEASE_BUILD_FIXIT)
|
||||
CFLAGS+= -DCOLORLS
|
||||
|
@ -43,7 +43,6 @@ int revnamecmp __P((const FTSENT *, const FTSENT *));
|
||||
int statcmp __P((const FTSENT *, const FTSENT *));
|
||||
int revstatcmp __P((const FTSENT *, const FTSENT *));
|
||||
|
||||
char *flags_to_string __P((u_long, char *));
|
||||
void prcopy __P((char *, char *, int));
|
||||
void printcol __P((DISPLAY *));
|
||||
void printlong __P((DISPLAY *));
|
||||
|
11
bin/ls/ls.c
11
bin/ls/ls.c
@ -78,8 +78,6 @@ static const char rcsid[] =
|
||||
*/
|
||||
#define STRBUF_SIZEOF(t) (1 + CHAR_BIT * sizeof(t) / 3 + 1)
|
||||
|
||||
char *getflags __P((u_long, char *));
|
||||
|
||||
static void display __P((FTSENT *, FTSENT *));
|
||||
static u_quad_t makenines __P((u_long));
|
||||
static int mastercmp __P((const FTSENT **, const FTSENT **));
|
||||
@ -605,7 +603,13 @@ display(p, list)
|
||||
if ((glen = strlen(group)) > maxgroup)
|
||||
maxgroup = glen;
|
||||
if (f_flags) {
|
||||
flags = getflags(sp->st_flags, "-");
|
||||
flags = fflagstostr(sp->st_flags);
|
||||
if (flags != NULL && *flags == '\0') {
|
||||
free(flags);
|
||||
flags = strdup("-");
|
||||
}
|
||||
if (flags == NULL)
|
||||
err(1, NULL);
|
||||
if ((flen = strlen(flags)) > maxflags)
|
||||
maxflags = flen;
|
||||
} else
|
||||
@ -627,6 +631,7 @@ display(p, list)
|
||||
if (f_flags) {
|
||||
np->flags = &np->data[ulen + glen + 2];
|
||||
(void)strcpy(np->flags, flags);
|
||||
free(flags);
|
||||
}
|
||||
cur->fts_pointer = np;
|
||||
}
|
||||
|
@ -2,10 +2,9 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= rm
|
||||
SRCS= rm.c setflags.c
|
||||
SRCS= rm.c
|
||||
|
||||
LINKS= ${BINDIR}/rm ${BINDIR}/unlink
|
||||
MLINKS= rm.1 unlink.1
|
||||
.PATH: ${.CURDIR}/../../lib/libc/gen
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
14
bin/rm/rm.c
14
bin/rm/rm.c
@ -60,8 +60,6 @@ static const char rcsid[] =
|
||||
#include <sysexits.h>
|
||||
#include <unistd.h>
|
||||
|
||||
char *getflags __P((u_long, char *));
|
||||
|
||||
int dflag, eval, fflag, iflag, Pflag, vflag, Wflag, stdin_ok;
|
||||
uid_t uid;
|
||||
|
||||
@ -423,7 +421,7 @@ check(path, name, sp)
|
||||
struct stat *sp;
|
||||
{
|
||||
int ch, first;
|
||||
char modep[15], flagsp[128];
|
||||
char modep[15], *flagsp;
|
||||
|
||||
/* Check -i first. */
|
||||
if (iflag)
|
||||
@ -441,15 +439,15 @@ check(path, name, sp)
|
||||
(!(sp->st_flags & (UF_APPEND|UF_IMMUTABLE)) || !uid)))
|
||||
return (1);
|
||||
strmode(sp->st_mode, modep);
|
||||
strcpy(flagsp, getflags(sp->st_flags, NULL));
|
||||
if (*flagsp)
|
||||
strcat(flagsp, " ");
|
||||
(void)fprintf(stderr, "override %s%s%s/%s %sfor %s? ",
|
||||
if ((flagsp = fflagstostr(sp->st_flags)) == NULL)
|
||||
err(1, NULL);
|
||||
(void)fprintf(stderr, "override %s%s%s/%s %s%sfor %s? ",
|
||||
modep + 1, modep[9] == ' ' ? "" : " ",
|
||||
user_from_uid(sp->st_uid, 0),
|
||||
group_from_gid(sp->st_gid, 0),
|
||||
*flagsp ? flagsp : "",
|
||||
*flagsp ? flagsp : "", *flagsp ? " " : "",
|
||||
path);
|
||||
free(flagsp);
|
||||
}
|
||||
(void)fflush(stderr);
|
||||
|
||||
|
@ -14,8 +14,8 @@ LDADD= -lskey -lmd -lcrypt -lutil
|
||||
DPADD= ${LIBSKEY} ${LIBMD} ${LIBCRYPT} ${LIBUTIL}
|
||||
|
||||
LSDIR= ../../bin/ls
|
||||
.PATH: ${.CURDIR}/${LSDIR} ${.CURDIR}/../../lib/libc/gen
|
||||
SRCS+= ls.c cmp.c print.c setflags.c util.c
|
||||
.PATH: ${.CURDIR}/${LSDIR}
|
||||
SRCS+= ls.c cmp.c print.c util.c
|
||||
CFLAGS+=-Dmain=ls_main -I${.CURDIR}/${LSDIR}
|
||||
|
||||
.if defined(NOPAM)
|
||||
|
@ -5,7 +5,6 @@ NOSHARED?=yes
|
||||
|
||||
PROG= chflags
|
||||
CFLAGS+=-Wall
|
||||
.PATH: ${.CURDIR}/../../lib/libc/gen
|
||||
SRCS= chflags.c setflags.c
|
||||
SRCS= chflags.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -56,8 +56,6 @@ static const char rcsid[] =
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int setflags __P((char **, u_long *, u_long *));
|
||||
|
||||
void usage __P((void));
|
||||
|
||||
int
|
||||
@ -123,7 +121,7 @@ main(argc, argv)
|
||||
set = val;
|
||||
oct = 1;
|
||||
} else {
|
||||
if (setflags(&flags, &set, &clear))
|
||||
if (strtofflags(&flags, &set, &clear))
|
||||
errx(1, "invalid flag: %s", flags);
|
||||
clear = ~clear;
|
||||
oct = 0;
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
CFLAGS+= -Wall
|
||||
PROG= find
|
||||
SRCS= find.c function.c ls.c main.c misc.c operator.c option.c setflags.c
|
||||
.PATH: ${.CURDIR}/../../lib/libc/gen
|
||||
SRCS= find.c function.c ls.c main.c misc.c operator.c option.c
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
|
@ -75,8 +75,6 @@ static const char rcsid[] =
|
||||
} \
|
||||
}
|
||||
|
||||
u_long setflags __P((char **, u_long *, u_long *));
|
||||
|
||||
static PLAN *palloc __P((enum ntype, int (*) __P((PLAN *, FTSENT *))));
|
||||
|
||||
/*
|
||||
@ -1060,7 +1058,7 @@ c_flags(flags_str)
|
||||
new->flags = F_ATLEAST;
|
||||
flags_str++;
|
||||
}
|
||||
if (setflags(&flags_str, &flags, ¬flags) == 1)
|
||||
if (strtofflags(&flags_str, &flags, ¬flags) == 1)
|
||||
errx(1, "-flags: %s: illegal flags string", flags_str);
|
||||
|
||||
new->fl_flags = flags;
|
||||
|
@ -2,8 +2,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= xinstall
|
||||
SRCS= setflags.c xinstall.c
|
||||
.PATH: ${.CURDIR}/../../lib/libc/gen
|
||||
SRCS= xinstall.c
|
||||
MAN1= install.1
|
||||
|
||||
install: maninstall
|
||||
|
@ -151,7 +151,7 @@ main(argc, argv)
|
||||
break;
|
||||
case 'f':
|
||||
flags = optarg;
|
||||
if (setflags(&flags, &fset, NULL))
|
||||
if (strtofflags(&flags, &fset, NULL))
|
||||
errx(EX_USAGE, "%s: invalid flag", flags);
|
||||
iflags |= SETFLAGS;
|
||||
break;
|
||||
|
@ -2,10 +2,9 @@
|
||||
# $FreeBSD$
|
||||
|
||||
PROG= mtree
|
||||
SRCS= compare.c crc.c create.c excludes.c misc.c mtree.c spec.c verify.c \
|
||||
setflags.c
|
||||
SRCS= compare.c crc.c create.c excludes.c misc.c mtree.c spec.c verify.c
|
||||
MAN8= mtree.8
|
||||
.PATH: ${.CURDIR}/../../usr.bin/cksum ${.CURDIR}/../../lib/libc/gen
|
||||
.PATH: ${.CURDIR}/../../usr.bin/cksum
|
||||
|
||||
.if !defined(WORLD)
|
||||
DPADD+= ${LIBMD}
|
||||
|
@ -88,6 +88,7 @@ compare(name, s, p)
|
||||
u_long len, val;
|
||||
int fd, label;
|
||||
char *cp, *tab = "";
|
||||
char *fflags;
|
||||
|
||||
label = 0;
|
||||
switch(s->type) {
|
||||
@ -224,10 +225,14 @@ typeerr: LABEL;
|
||||
*/
|
||||
if ((s->flags & F_FLAGS) && s->st_flags != p->fts_statp->st_flags) {
|
||||
LABEL;
|
||||
(void)printf("%sflags (\"%s\" is not ", tab,
|
||||
getflags(s->st_flags, "none"));
|
||||
(void)printf("\"%s\"",
|
||||
getflags(p->fts_statp->st_flags, "none"));
|
||||
fflags = flags_to_string(s->st_flags);
|
||||
(void)printf("%sflags (\"%s\" is not ", tab, fflags);
|
||||
free(fflags);
|
||||
|
||||
fflags = flags_to_string(p->fts_statp->st_flags);
|
||||
(void)printf("\"%s\"", fflags);
|
||||
free(fflags);
|
||||
|
||||
if (uflag)
|
||||
if (chflags(p->fts_accpath, s->st_flags))
|
||||
(void)printf(", not modified: %s)\n",
|
||||
|
@ -153,6 +153,7 @@ statf(indent, p)
|
||||
struct passwd *pw;
|
||||
u_long len, val;
|
||||
int fd, offset;
|
||||
char *fflags;
|
||||
char *escaped_name;
|
||||
|
||||
escaped_name = calloc(1, p->fts_namelen * 4 + 1);
|
||||
@ -256,9 +257,11 @@ statf(indent, p)
|
||||
if (keys & F_SLINK &&
|
||||
(p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
|
||||
output(indent, &offset, "link=%s", rlink(p->fts_accpath));
|
||||
if (keys & F_FLAGS && p->fts_statp->st_flags != flags)
|
||||
output(indent, &offset, "flags=%s",
|
||||
getflags(p->fts_statp->st_flags, "none"));
|
||||
if (keys & F_FLAGS && p->fts_statp->st_flags != flags) {
|
||||
fflags = flags_to_string(p->fts_statp->st_flags);
|
||||
output(indent, &offset, "flags=%s", fflags);
|
||||
free(fflags);
|
||||
}
|
||||
(void)putchar('\n');
|
||||
}
|
||||
|
||||
@ -290,6 +293,7 @@ statd(t, parent, puid, pgid, pmode, pflags)
|
||||
u_long saveflags = 0;
|
||||
u_short maxgid, maxuid, maxmode, maxflags;
|
||||
u_short g[MAXGID], u[MAXUID], m[MAXMODE], f[MAXFLAGS];
|
||||
char *fflags;
|
||||
static int first = 1;
|
||||
|
||||
if ((p = fts_children(t, 0)) == NULL) {
|
||||
@ -374,9 +378,11 @@ statd(t, parent, puid, pgid, pmode, pflags)
|
||||
(void)printf(" mode=%#o", savemode);
|
||||
if (keys & F_NLINK)
|
||||
(void)printf(" nlink=1");
|
||||
if (keys & F_FLAGS && saveflags)
|
||||
(void)printf(" flags=%s",
|
||||
getflags(saveflags, "none"));
|
||||
if (keys & F_FLAGS && saveflags) {
|
||||
fflags = flags_to_string(saveflags);
|
||||
(void)printf(" flags=%s", fflags);
|
||||
free(fflags);
|
||||
}
|
||||
(void)printf("\n");
|
||||
*puid = saveuid;
|
||||
*pgid = savegid;
|
||||
|
@ -37,8 +37,7 @@
|
||||
int compare __P((char *, NODE *, FTSENT *));
|
||||
int crc __P((int, u_long *, u_long *));
|
||||
void cwalk __P((void));
|
||||
char *flags_to_string __P((u_long, char *));
|
||||
int string_to_flags __P((char **, u_long *, u_long *));
|
||||
char *flags_to_string __P((u_long));
|
||||
|
||||
char *inotype __P((u_int));
|
||||
u_int parsekey __P((char *, int *));
|
||||
|
@ -44,6 +44,7 @@ static const char rcsid[] =
|
||||
#include <err.h>
|
||||
#include <fts.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include "mtree.h"
|
||||
#include "extern.h"
|
||||
|
||||
@ -109,3 +110,20 @@ keycompare(a, b)
|
||||
{
|
||||
return (strcmp(((KEY *)a)->name, ((KEY *)b)->name));
|
||||
}
|
||||
|
||||
char *
|
||||
flags_to_string(fflags)
|
||||
u_long fflags;
|
||||
{
|
||||
char *string;
|
||||
|
||||
string = fflagstostr(fflags);
|
||||
if (string != NULL && *string == '\0') {
|
||||
free(string);
|
||||
string = strdup("none");
|
||||
}
|
||||
if (string == NULL)
|
||||
err(1, NULL);
|
||||
|
||||
return string;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ set(t, ip)
|
||||
case F_FLAGS:
|
||||
if (strcmp("none", val) == 0)
|
||||
ip->st_flags = 0;
|
||||
else if (setflags(&val, &ip->st_flags, NULL) != 0)
|
||||
else if (strtofflags(&val, &ip->st_flags, NULL) != 0)
|
||||
errx(1, "line %d: invalid flag %s",lineno, val);
|
||||
break;
|
||||
case F_GID:
|
||||
|
Loading…
Reference in New Issue
Block a user