Remove NetBSD references from test utility
This commit is contained in:
parent
5188a03964
commit
dca7e0efec
|
|
@ -1,5 +1,5 @@
|
||||||
# $NetBSD: Makefile,v 1.11 2007/06/22 03:24:16 simonb Exp $
|
# Makefile for the test utility
|
||||||
# @(#)Makefile 8.1 (Berkeley) 5/31/93
|
# Derived from 4.4BSD sources
|
||||||
|
|
||||||
PROG= test
|
PROG= test
|
||||||
SRCS= test.c
|
SRCS= test.c
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
# $NetBSD: TEST.csh,v 1.2 1995/03/21 07:03:59 cgd Exp $
|
# Test script for the test utility
|
||||||
# @(#)TEST.csh 5.2 (Berkeley) 4/30/93
|
# @(#)TEST.csh 5.2 (Berkeley) 4/30/93
|
||||||
|
|
||||||
#alias t '/usr/src/bin/test/obj/test \!*; echo $status'
|
#alias t '/usr/src/bin/test/obj/test \!*; echo $status'
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
.\" $NetBSD: test.1,v 1.30 2016/08/12 03:17:41 sevan Exp $
|
.\" Manual page for the test utility
|
||||||
.\"
|
.\"
|
||||||
.\" Copyright (c) 1991, 1993
|
.\" Copyright (c) 1991, 1993
|
||||||
.\" The Regents of the University of California. All rights reserved.
|
.\" The Regents of the University of California. All rights reserved.
|
||||||
|
|
|
||||||
184
bin/test/test.c
184
bin/test/test.c
|
|
@ -1,19 +1,16 @@
|
||||||
/* $NetBSD: test.c,v 1.41 2016/09/05 01:00:07 sevan Exp $ */
|
/* MINIX test utility derived from BSD sources */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* test(1); version 7-like -- author Erik Baalbergen
|
* test(1); version 7-like -- author Erik Baalbergen
|
||||||
* modified by Eric Gisin to be used as built-in.
|
* modified by Eric Gisin to be used as built-in.
|
||||||
* modified by Arnold Robbins to add SVR3 compatibility
|
* modified by Arnold Robbins to add SVR3 compatibility
|
||||||
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
|
* (-x -c -b -p -u -g -k) plus Korn's -L -nt -ot -ef and new -S (socket).
|
||||||
* modified by J.T. Conklin for NetBSD.
|
* modified by J.T. Conklin.
|
||||||
*
|
*
|
||||||
* This program is in the Public Domain.
|
* This program is in the Public Domain.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#ifndef lint
|
|
||||||
__RCSID("$NetBSD: test.c,v 1.41 2016/09/05 01:00:07 sevan Exp $");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
@ -23,11 +20,11 @@ __RCSID("$NetBSD: test.c,v 1.41 2016/09/05 01:00:07 sevan Exp $");
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <stdarg.h>
|
|
||||||
|
|
||||||
/* test(1) accepts the following grammar:
|
/* test(1) accepts the following grammar:
|
||||||
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
oexpr ::= aexpr | aexpr "-o" oexpr ;
|
||||||
|
|
@ -89,13 +86,7 @@ enum token {
|
||||||
OPERAND
|
OPERAND
|
||||||
};
|
};
|
||||||
|
|
||||||
enum token_types {
|
enum token_types { UNOP, BINOP, BUNOP, BBINOP, PAREN };
|
||||||
UNOP,
|
|
||||||
BINOP,
|
|
||||||
BUNOP,
|
|
||||||
BBINOP,
|
|
||||||
PAREN
|
|
||||||
};
|
|
||||||
|
|
||||||
struct t_op {
|
struct t_op {
|
||||||
const char *op_text;
|
const char *op_text;
|
||||||
|
|
@ -103,12 +94,8 @@ struct t_op {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct t_op cop[] = {
|
static const struct t_op cop[] = {
|
||||||
{"!", UNOT, BUNOP},
|
{"!", UNOT, BUNOP}, {"(", LPAREN, PAREN}, {")", RPAREN, PAREN},
|
||||||
{"(", LPAREN, PAREN},
|
{"<", STRLT, BINOP}, {"=", STREQ, BINOP}, {">", STRGT, BINOP},
|
||||||
{")", RPAREN, PAREN},
|
|
||||||
{"<", STRLT, BINOP},
|
|
||||||
{"=", STREQ, BINOP},
|
|
||||||
{">", STRGT, BINOP},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct t_op cop2[] = {
|
static const struct t_op cop2[] = {
|
||||||
|
|
@ -116,40 +103,23 @@ static const struct t_op cop2[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct t_op mop3[] = {
|
static const struct t_op mop3[] = {
|
||||||
{"ef", FILEQ, BINOP},
|
{"ef", FILEQ, BINOP}, {"eq", INTEQ, BINOP}, {"ge", INTGE, BINOP},
|
||||||
{"eq", INTEQ, BINOP},
|
{"gt", INTGT, BINOP}, {"le", INTLE, BINOP}, {"lt", INTLT, BINOP},
|
||||||
{"ge", INTGE, BINOP},
|
{"ne", INTNE, BINOP}, {"nt", FILNT, BINOP}, {"ot", FILOT, BINOP},
|
||||||
{"gt", INTGT, BINOP},
|
|
||||||
{"le", INTLE, BINOP},
|
|
||||||
{"lt", INTLT, BINOP},
|
|
||||||
{"ne", INTNE, BINOP},
|
|
||||||
{"nt", FILNT, BINOP},
|
|
||||||
{"ot", FILOT, BINOP},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct t_op mop2[] = {
|
static const struct t_op mop2[] = {
|
||||||
{"G", FILGID, UNOP},
|
{"G", FILGID, UNOP}, {"L", FILSYM, UNOP},
|
||||||
{"L", FILSYM, UNOP},
|
{"O", FILUID, UNOP}, {"S", FILSOCK, UNOP},
|
||||||
{"O", FILUID, UNOP},
|
{"a", BAND, BBINOP}, {"b", FILBDEV, UNOP},
|
||||||
{"S", FILSOCK,UNOP},
|
{"c", FILCDEV, UNOP}, {"d", FILDIR, UNOP},
|
||||||
{"a", BAND, BBINOP},
|
{"e", FILEXIST, UNOP}, {"f", FILREG, UNOP},
|
||||||
{"b", FILBDEV,UNOP},
|
{"g", FILSGID, UNOP}, {"h", FILSYM, UNOP}, /* for backwards compat */
|
||||||
{"c", FILCDEV,UNOP},
|
{"k", FILSTCK, UNOP}, {"n", STRNZ, UNOP},
|
||||||
{"d", FILDIR, UNOP},
|
{"o", BOR, BBINOP}, {"p", FILFIFO, UNOP},
|
||||||
{"e", FILEXIST,UNOP},
|
{"r", FILRD, UNOP}, {"s", FILGZ, UNOP},
|
||||||
{"f", FILREG, UNOP},
|
{"t", FILTT, UNOP}, {"u", FILSUID, UNOP},
|
||||||
{"g", FILSGID,UNOP},
|
{"w", FILWR, UNOP}, {"x", FILEX, UNOP},
|
||||||
{"h", FILSYM, UNOP}, /* for backwards compat */
|
|
||||||
{"k", FILSTCK,UNOP},
|
|
||||||
{"n", STRNZ, UNOP},
|
|
||||||
{"o", BOR, BBINOP},
|
|
||||||
{"p", FILFIFO,UNOP},
|
|
||||||
{"r", FILRD, UNOP},
|
|
||||||
{"s", FILGZ, UNOP},
|
|
||||||
{"t", FILTT, UNOP},
|
|
||||||
{"u", FILSUID,UNOP},
|
|
||||||
{"w", FILWR, UNOP},
|
|
||||||
{"x", FILEX, UNOP},
|
|
||||||
{"z", STREZ, UNOP},
|
{"z", STREZ, UNOP},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -177,9 +147,7 @@ extern void *ckmalloc(size_t);
|
||||||
#else
|
#else
|
||||||
static void error(const char *, ...) __dead __printflike(1, 2);
|
static void error(const char *, ...) __dead __printflike(1, 2);
|
||||||
|
|
||||||
static void
|
static void error(const char *msg, ...) {
|
||||||
error(const char *msg, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
|
|
@ -189,9 +157,7 @@ error(const char *msg, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *ckmalloc(size_t);
|
static void *ckmalloc(size_t);
|
||||||
static void *
|
static void *ckmalloc(size_t nbytes) {
|
||||||
ckmalloc(size_t nbytes)
|
|
||||||
{
|
|
||||||
void *p = malloc(nbytes);
|
void *p = malloc(nbytes);
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
|
|
@ -203,11 +169,9 @@ ckmalloc(size_t nbytes)
|
||||||
#ifdef SHELL
|
#ifdef SHELL
|
||||||
int testcmd(int, char **);
|
int testcmd(int, char **);
|
||||||
|
|
||||||
int
|
int testcmd(int argc, char **argv)
|
||||||
testcmd(int argc, char **argv)
|
|
||||||
#else
|
#else
|
||||||
int
|
int main(int argc, char *argv[])
|
||||||
main(int argc, char *argv[])
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
@ -238,9 +202,7 @@ main(int argc, char *argv[])
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void syntax(const char *op, const char *msg) {
|
||||||
syntax(const char *op, const char *msg)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (op && *op)
|
if (op && *op)
|
||||||
error("%s: %s", op, msg);
|
error("%s: %s", op, msg);
|
||||||
|
|
@ -248,9 +210,7 @@ syntax(const char *op, const char *msg)
|
||||||
error("%s", msg);
|
error("%s", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int oexpr(enum token n) {
|
||||||
oexpr(enum token n)
|
|
||||||
{
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = aexpr(n);
|
res = aexpr(n);
|
||||||
|
|
@ -262,9 +222,7 @@ oexpr(enum token n)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int aexpr(enum token n) {
|
||||||
aexpr(enum token n)
|
|
||||||
{
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = nexpr(n);
|
res = nexpr(n);
|
||||||
|
|
@ -276,18 +234,14 @@ aexpr(enum token n)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int nexpr(enum token n) {
|
||||||
nexpr(enum token n)
|
|
||||||
{
|
|
||||||
|
|
||||||
if (n == UNOT)
|
if (n == UNOT)
|
||||||
return !nexpr(t_lex(*++t_wp));
|
return !nexpr(t_lex(*++t_wp));
|
||||||
return primary(n);
|
return primary(n);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int primary(enum token n) {
|
||||||
primary(enum token n)
|
|
||||||
{
|
|
||||||
enum token nn;
|
enum token nn;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
|
|
@ -324,14 +278,12 @@ primary(enum token n)
|
||||||
return strlen(*t_wp) > 0;
|
return strlen(*t_wp) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int binop(void) {
|
||||||
binop(void)
|
|
||||||
{
|
|
||||||
const char *opnd1, *opnd2;
|
const char *opnd1, *opnd2;
|
||||||
struct t_op const *op;
|
struct t_op const *op;
|
||||||
|
|
||||||
opnd1 = *t_wp;
|
opnd1 = *t_wp;
|
||||||
(void) t_lex(*++t_wp);
|
(void)t_lex(*++t_wp);
|
||||||
op = t_wp_op;
|
op = t_wp_op;
|
||||||
|
|
||||||
if ((opnd2 = *++t_wp) == NULL)
|
if ((opnd2 = *++t_wp) == NULL)
|
||||||
|
|
@ -432,9 +384,8 @@ binop(void)
|
||||||
* 1003.2-1992) and it was implemented efficiently with stat() instead of
|
* 1003.2-1992) and it was implemented efficiently with stat() instead of
|
||||||
* open().
|
* open().
|
||||||
*
|
*
|
||||||
* This was apparently broken in NetBSD around about 1994/06/30 when the old
|
* Earlier implementations diverged from the 4.4BSD version when
|
||||||
* 4.4BSD implementation was replaced with a (arguably much better coded)
|
* the original code was replaced with one derived from pdksh.
|
||||||
* implementation derived from pdksh.
|
|
||||||
*
|
*
|
||||||
* Note that modern pdksh is yet different again, but still not correct, at
|
* Note that modern pdksh is yet different again, but still not correct, at
|
||||||
* least not w.r.t. 1003.2-1992.
|
* least not w.r.t. 1003.2-1992.
|
||||||
|
|
@ -492,9 +443,7 @@ binop(void)
|
||||||
* (euid==uid&&egid==gid), but uses st_mode for '-x' iff running as root.
|
* (euid==uid&&egid==gid), but uses st_mode for '-x' iff running as root.
|
||||||
* i.e. it does strictly conform to 1003.1-2001 (and presumably 1003.2b).
|
* i.e. it does strictly conform to 1003.1-2001 (and presumably 1003.2b).
|
||||||
*/
|
*/
|
||||||
static int
|
static int test_access(struct stat *sp, mode_t stmode) {
|
||||||
test_access(struct stat *sp, mode_t stmode)
|
|
||||||
{
|
|
||||||
gid_t *groups;
|
gid_t *groups;
|
||||||
register int n;
|
register int n;
|
||||||
uid_t euid;
|
uid_t euid;
|
||||||
|
|
@ -532,9 +481,7 @@ test_access(struct stat *sp, mode_t stmode)
|
||||||
return sp->st_mode & stmode;
|
return sp->st_mode & stmode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int filstat(char *nm, enum token mode) {
|
||||||
filstat(char *nm, enum token mode)
|
|
||||||
{
|
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
|
||||||
if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s))
|
if (mode == FILSYM ? lstat(nm, &s) : stat(nm, &s))
|
||||||
|
|
@ -582,18 +529,14 @@ filstat(char *nm, enum token mode)
|
||||||
|
|
||||||
#define VTOC(x) (const unsigned char *)((const struct t_op *)x)->op_text
|
#define VTOC(x) (const unsigned char *)((const struct t_op *)x)->op_text
|
||||||
|
|
||||||
static int
|
static int compare1(const void *va, const void *vb) {
|
||||||
compare1(const void *va, const void *vb)
|
|
||||||
{
|
|
||||||
const unsigned char *a = va;
|
const unsigned char *a = va;
|
||||||
const unsigned char *b = VTOC(vb);
|
const unsigned char *b = VTOC(vb);
|
||||||
|
|
||||||
return a[0] - b[0];
|
return a[0] - b[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int compare2(const void *va, const void *vb) {
|
||||||
compare2(const void *va, const void *vb)
|
|
||||||
{
|
|
||||||
const unsigned char *a = va;
|
const unsigned char *a = va;
|
||||||
const unsigned char *b = VTOC(vb);
|
const unsigned char *b = VTOC(vb);
|
||||||
int z = a[0] - b[0];
|
int z = a[0] - b[0];
|
||||||
|
|
@ -601,24 +544,19 @@ compare2(const void *va, const void *vb)
|
||||||
return z ? z : (a[1] - b[1]);
|
return z ? z : (a[1] - b[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct t_op const *
|
static struct t_op const *findop(const char *s) {
|
||||||
findop(const char *s)
|
|
||||||
{
|
|
||||||
if (s[0] == '-') {
|
if (s[0] == '-') {
|
||||||
if (s[1] == '\0')
|
if (s[1] == '\0')
|
||||||
return NULL;
|
return NULL;
|
||||||
if (s[2] == '\0')
|
if (s[2] == '\0')
|
||||||
return bsearch(s + 1, mop2, __arraycount(mop2),
|
return bsearch(s + 1, mop2, __arraycount(mop2), sizeof(*mop2), compare1);
|
||||||
sizeof(*mop2), compare1);
|
|
||||||
else if (s[3] != '\0')
|
else if (s[3] != '\0')
|
||||||
return NULL;
|
return NULL;
|
||||||
else
|
else
|
||||||
return bsearch(s + 1, mop3, __arraycount(mop3),
|
return bsearch(s + 1, mop3, __arraycount(mop3), sizeof(*mop3), compare2);
|
||||||
sizeof(*mop3), compare2);
|
|
||||||
} else {
|
} else {
|
||||||
if (s[1] == '\0')
|
if (s[1] == '\0')
|
||||||
return bsearch(s, cop, __arraycount(cop), sizeof(*cop),
|
return bsearch(s, cop, __arraycount(cop), sizeof(*cop), compare1);
|
||||||
compare1);
|
|
||||||
else if (strcmp(s, cop2[0].op_text) == 0)
|
else if (strcmp(s, cop2[0].op_text) == 0)
|
||||||
return cop2;
|
return cop2;
|
||||||
else
|
else
|
||||||
|
|
@ -626,9 +564,7 @@ findop(const char *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum token
|
static enum token t_lex(char *s) {
|
||||||
t_lex(char *s)
|
|
||||||
{
|
|
||||||
struct t_op const *op;
|
struct t_op const *op;
|
||||||
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
|
|
@ -638,7 +574,7 @@ t_lex(char *s)
|
||||||
|
|
||||||
if ((op = findop(s)) != NULL) {
|
if ((op = findop(s)) != NULL) {
|
||||||
if (!((op->op_type == UNOP && isoperand()) ||
|
if (!((op->op_type == UNOP && isoperand()) ||
|
||||||
(op->op_num == LPAREN && *(t_wp+1) == 0))) {
|
(op->op_num == LPAREN && *(t_wp + 1) == 0))) {
|
||||||
t_wp_op = op;
|
t_wp_op = op;
|
||||||
return op->op_num;
|
return op->op_num;
|
||||||
}
|
}
|
||||||
|
|
@ -647,15 +583,13 @@ t_lex(char *s)
|
||||||
return OPERAND;
|
return OPERAND;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int isoperand(void) {
|
||||||
isoperand(void)
|
|
||||||
{
|
|
||||||
struct t_op const *op;
|
struct t_op const *op;
|
||||||
char *s, *t;
|
char *s, *t;
|
||||||
|
|
||||||
if ((s = *(t_wp+1)) == 0)
|
if ((s = *(t_wp + 1)) == 0)
|
||||||
return 1;
|
return 1;
|
||||||
if ((t = *(t_wp+2)) == 0)
|
if ((t = *(t_wp + 2)) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
if ((op = findop(s)) != NULL)
|
if ((op = findop(s)) != NULL)
|
||||||
return op->op_type == BINOP && (t[0] != ')' || t[1] != '\0');
|
return op->op_type == BINOP && (t[0] != ')' || t[1] != '\0');
|
||||||
|
|
@ -663,9 +597,7 @@ isoperand(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* atoi with error detection */
|
/* atoi with error detection */
|
||||||
static long long
|
static long long getn(const char *s) {
|
||||||
getn(const char *s)
|
|
||||||
{
|
|
||||||
char *p;
|
char *p;
|
||||||
long long r;
|
long long r;
|
||||||
|
|
||||||
|
|
@ -685,33 +617,23 @@ getn(const char *s)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int newerf(const char *f1, const char *f2) {
|
||||||
newerf(const char *f1, const char *f2)
|
|
||||||
{
|
|
||||||
struct stat b1, b2;
|
struct stat b1, b2;
|
||||||
|
|
||||||
return (stat(f1, &b1) == 0 &&
|
return (stat(f1, &b1) == 0 && stat(f2, &b2) == 0 &&
|
||||||
stat(f2, &b2) == 0 &&
|
|
||||||
timespeccmp(&b1.st_mtim, &b2.st_mtim, >));
|
timespeccmp(&b1.st_mtim, &b2.st_mtim, >));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int olderf(const char *f1, const char *f2) {
|
||||||
olderf(const char *f1, const char *f2)
|
|
||||||
{
|
|
||||||
struct stat b1, b2;
|
struct stat b1, b2;
|
||||||
|
|
||||||
return (stat(f1, &b1) == 0 &&
|
return (stat(f1, &b1) == 0 && stat(f2, &b2) == 0 &&
|
||||||
stat(f2, &b2) == 0 &&
|
|
||||||
timespeccmp(&b1.st_mtim, &b2.st_mtim, <));
|
timespeccmp(&b1.st_mtim, &b2.st_mtim, <));
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int equalf(const char *f1, const char *f2) {
|
||||||
equalf(const char *f1, const char *f2)
|
|
||||||
{
|
|
||||||
struct stat b1, b2;
|
struct stat b1, b2;
|
||||||
|
|
||||||
return (stat(f1, &b1) == 0 &&
|
return (stat(f1, &b1) == 0 && stat(f2, &b2) == 0 && b1.st_dev == b2.st_dev &&
|
||||||
stat(f2, &b2) == 0 &&
|
|
||||||
b1.st_dev == b2.st_dev &&
|
|
||||||
b1.st_ino == b2.st_ino);
|
b1.st_ino == b2.st_ino);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user