-/* $OpenBSD: function.c,v 1.53 2023/03/08 04:43:10 guenther Exp $ */
+/* $OpenBSD: function.c,v 1.54 2023/04/01 05:27:44 tb Exp $ */
/*-
* Copyright (c) 1990, 1993
{
long long value;
char *endchar, *str; /* Pointer to character ending conversion. */
-
+
/* Determine comparison from leading + or -. */
str = vp;
switch (*str) {
plan->flags = F_EQUAL;
break;
}
-
+
/*
* Convert the string with strtoll(). Note, if strtoll() returns
* zero and endchar points to the beginning of the string we know
COMPARE((now - entry->fts_statp->st_atime +
SECSPERDAY - 1) / SECSPERDAY, plan->sec_data);
}
-
+
PLAN *
c_atime(char *arg, char ***ignored, int unused)
{
COMPARE((now - entry->fts_statp->st_ctime +
SECSPERDAY - 1) / SECSPERDAY, plan->sec_data);
}
-
+
PLAN *
c_ctime(char *arg, char ***ignored, int unused)
{
{
return (1);
}
-
+
PLAN *
c_depth(char *ignore, char ***ignored, int unused)
{
return (palloc(N_DELETE, f_delete));
}
-
+
/*
* -empty functions --
*
plan->ep_bxp[plan->ep_narg] = NULL;
/* Don't mix output of command with find output. */
- fflush(stdout);
- fflush(stderr);
+ fflush(stdout);
+ fflush(stderr);
switch (pid = vfork()) {
case -1:
if (rval)
plan->ep_rval = rval;
}
-
+
/*
* c_exec --
* build three parallel arrays, one with pointers to the strings passed
errx(1, "%s: cannot open \".\"", isok ? "-ok" : "-exec");
isoutput = 1;
-
+
new = palloc(N_EXEC, f_exec);
if (isok)
new->flags |= F_NEEDOK;
argv < ap;
++argv, ++cnt) {
c += strlen(*argv) + 1;
- new->e_argv[cnt] = *argv;
- }
+ new->e_argv[cnt] = *argv;
+ }
if (arg_max < 4 * 1024 + c)
errx(1, "-exec: no space left to run child command");
bufsize = arg_max - 4 * 1024 - c;
}
}
new->e_orig[cnt] = NULL;
- }
+ }
new->e_argv[cnt] = NULL;
*argvp = argv + 1;
return (new);
}
-
+
/*
* -execdir utility [arg ... ] ; functions --
*
pid = waitpid(pid, &status, 0);
return (pid != -1 && WIFEXITED(status) && !WEXITSTATUS(status));
}
-
+
/*
* c_execdir --
* build three parallel arrays, one with pointers to the strings passed
ftsoptions &= ~FTS_NOSTAT;
isoutput = 1;
-
+
new = palloc(N_EXECDIR, f_execdir);
for (ap = argv = *argvp;; ++ap) {
new->fl_mask = flags | notflags;
return (new);
}
-
+
/*
* -follow functions --
*
return (palloc(N_FOLLOW, f_always_true));
}
-
+
/*
* -fstype functions --
*
p[0] = '.';
save[1] = p[1];
p[1] = '\0';
-
- } else
+
+ } else
p = NULL;
if (statfs(entry->fts_accpath, &sb))
}
switch (plan->flags) {
case F_MTFLAG:
- return (val & plan->mt_data);
+ return (val & plan->mt_data);
case F_MTTYPE:
return (strncmp(fstype, plan->c_data, MFSNAMELEN) == 0);
default:
abort();
}
}
-
+
PLAN *
c_fstype(char *arg, char ***ignored, int unused)
{
PLAN *new;
-
+
ftsoptions &= ~FTS_NOSTAT;
-
+
new = palloc(N_FSTYPE, f_fstype);
switch (*arg) {
case 'l':
new->c_data = arg;
return (new);
}
-
+
/*
* -group gname functions --
*
{
return (entry->fts_statp->st_gid == plan->g_data);
}
-
+
PLAN *
c_group(char *gname, char ***ignored, int unused)
{
PLAN *new;
gid_t gid;
-
+
ftsoptions &= ~FTS_NOSTAT;
if (gid_from_group(gname, &gid) == -1) {
if (errstr)
errx(1, "-group: %s: no such group", gname);
}
-
+
new = palloc(N_GROUP, f_group);
new->g_data = gid;
return (new);
{
COMPARE(entry->fts_statp->st_ino, plan->i_data);
}
-
+
PLAN *
c_inum(char *arg, char ***ignored, int unused)
{
long long inum;
PLAN *new;
-
+
ftsoptions &= ~FTS_NOSTAT;
-
+
new = palloc(N_INUM, f_inum);
inum = find_parsenum(new, "-inum", arg, NULL);
if (inum != (ino_t)inum)
new->i_data = inum;
return (new);
}
-
+
/*
* -links n functions --
*
{
COMPARE(entry->fts_statp->st_nlink, plan->l_data);
}
-
+
PLAN *
c_links(char *arg, char ***ignored, int unused)
{
PLAN *new;
long long nlink;
-
+
ftsoptions &= ~FTS_NOSTAT;
-
+
new = palloc(N_LINKS, f_links);
nlink = find_parsenum(new, "-links", arg, NULL);
if (nlink != (nlink_t)nlink)
new->l_data = nlink;
return (new);
}
-
+
/*
* -ls functions --
*
printlong(entry->fts_path, entry->fts_accpath, entry->fts_statp);
return (1);
}
-
+
PLAN *
c_ls(char *ignore, char ***ignored, int unused)
{
ftsoptions &= ~FTS_NOSTAT;
isoutput = 1;
-
+
return (palloc(N_LS, f_ls));
}
COMPARE((now - entry->fts_statp->st_mtime + SECSPERDAY - 1) /
SECSPERDAY, plan->sec_data);
}
-
+
PLAN *
c_mtime(char *arg, char ***ignored, int unused)
{
{
return (!fnmatch(plan->c_data, entry->fts_name, 0));
}
-
+
PLAN *
c_name(char *pattern, char ***ignored, int unused)
{
* -iname functions --
*
* Similar to -name, but does case insensitive matching
- *
+ *
*/
int
f_iname(PLAN *plan, FTSENT *entry)
{
return (!fnmatch(plan->c_data, entry->fts_name, FNM_CASEFOLD));
}
-
+
PLAN *
c_iname(char *pattern, char ***ignored, int unused)
{
new->c_data = pattern;
return (new);
}
-
+
/*
* -newer file functions --
*
(entry->fts_statp->st_mtimespec.tv_sec == plan->t_data.tv_sec &&
entry->fts_statp->st_mtimespec.tv_nsec > plan->t_data.tv_nsec));
}
-
+
PLAN *
c_newer(char *filename, char ***ignored, int unused)
{
PLAN *new;
struct stat sb;
-
+
ftsoptions &= ~FTS_NOSTAT;
if (stat(filename, &sb))
memcpy(&new->t_data, &sb.st_mtimespec, sizeof(struct timespec));
return (new);
}
-
+
/*
* -anewer file functions --
*
(entry->fts_statp->st_atimespec.tv_sec == plan->t_data.tv_sec &&
entry->fts_statp->st_atimespec.tv_nsec > plan->t_data.tv_nsec));
}
-
+
PLAN *
c_anewer(char *filename, char ***ignored, int unused)
{
PLAN *new;
struct stat sb;
-
+
ftsoptions &= ~FTS_NOSTAT;
if (stat(filename, &sb))
memcpy(&new->t_data, &sb.st_atimespec, sizeof(struct timespec));
return (new);
}
-
+
/*
* -cnewer file functions --
*
(entry->fts_statp->st_ctimespec.tv_sec == plan->t_data.tv_sec &&
entry->fts_statp->st_ctimespec.tv_nsec > plan->t_data.tv_nsec));
}
-
+
PLAN *
c_cnewer(char *filename, char ***ignored, int unused)
{
PLAN *new;
struct stat sb;
-
+
ftsoptions &= ~FTS_NOSTAT;
if (stat(filename, &sb))
memcpy(&new->t_data, &sb.st_ctimespec, sizeof(struct timespec));
return (new);
}
-
+
/*
* -nogroup functions --
*
{
return (group_from_gid(entry->fts_statp->st_gid, 1) ? 0 : 1);
}
-
+
PLAN *
c_nogroup(char *ignore, char ***ignored, int unused)
{
return (palloc(N_NOGROUP, f_nogroup));
}
-
+
/*
* -nouser functions --
*
{
return (user_from_uid(entry->fts_statp->st_uid, 1) ? 0 : 1);
}
-
+
PLAN *
c_nouser(char *ignore, char ***ignored, int unused)
{
return (palloc(N_NOUSER, f_nouser));
}
-
+
/*
* -path functions --
*
{
return (!fnmatch(plan->c_data, entry->fts_path, 0));
}
-
+
PLAN *
c_path(char *pattern, char ***ignored, int unused)
{
new->c_data = pattern;
return (new);
}
-
+
/*
* -perm functions --
*
return (mode == plan->m_data);
/* NOTREACHED */
}
-
+
PLAN *
c_perm(char *perm, char ***ignored, int unused)
{
free(set);
return (new);
}
-
+
/*
* -print functions --
*
(void)fputc('\0', stdout);
return(1);
}
-
+
PLAN *
c_print(char *ignore, char ***ignored, int unused)
{
return(palloc(N_PRINT0, f_print0));
}
-
+
/*
* -prune functions --
*
err(1, "%s", entry->fts_path);
return (1);
}
-
+
PLAN *
c_prune(char *ignore, char ***ignored, int unused)
{
return (palloc(N_PRUNE, f_prune));
}
-
+
/*
* -size n[c] functions --
*
FIND_SIZE : entry->fts_statp->st_size;
COMPARE(size, plan->o_data);
}
-
+
PLAN *
c_size(char *arg, char ***ignored, int unused)
{
PLAN *new;
char endch;
-
+
ftsoptions &= ~FTS_NOSTAT;
new = palloc(N_SIZE, f_size);
divsize = 0;
return (new);
}
-
+
/*
* -type c functions --
*
{
return ((entry->fts_statp->st_mode & S_IFMT) == plan->m_data);
}
-
+
PLAN *
c_type(char *typestring, char ***ignored, int unused)
{
PLAN *new;
mode_t mask;
-
+
ftsoptions &= ~FTS_NOSTAT;
switch (typestring[0]) {
default:
errx(1, "-type: %s: unknown type", typestring);
}
-
+
new = palloc(N_TYPE, f_type);
new->m_data = mask;
return (new);
}
-
+
/*
* -user uname functions --
*
{
return (entry->fts_statp->st_uid == plan->u_data);
}
-
+
PLAN *
c_user(char *username, char ***ignored, int unused)
{
PLAN *new;
uid_t uid;
-
+
ftsoptions &= ~FTS_NOSTAT;
if (uid_from_user(username, &uid) == -1) {
new->u_data = uid;
return (new);
}
-
+
/*
* -xdev functions --
*
p && (state = (p->eval)(p, entry)); p = p->next);
return (state);
}
-
+
/*
* N_OPENPAREN and N_CLOSEPAREN nodes are temporary place markers. They are
* eliminated during phase 2 of find_formplan() --- the '(' node is converted
{
return (palloc(N_OPENPAREN, (int (*)(PLAN *, FTSENT *))-1));
}
-
+
PLAN *
c_closeparen(char *ignore, char ***ignored, int unused)
{
return (palloc(N_CLOSEPAREN, (int (*)(PLAN *, FTSENT *))-1));
}
-
+
/*
* ! expression functions --
*
p && (state = (p->eval)(p, entry)); p = p->next);
return (!state);
}
-
+
PLAN *
c_not(char *ignore, char ***ignored, int unused)
{
return (palloc(N_NOT, f_not));
}
-
+
/*
* expression -o expression functions --
*
* and if so, clean it up as appropriate.
*
* At the moment, only N_EXEC has state. Two kinds: 1)
- * lists of files to feed to subprocesses 2) State on exit
+ * lists of files to feed to subprocesses 2) State on exit
* status of past subprocesses.
*/
int