Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/tr/tr.c
Show All 38 Lines | |||||
#ifndef lint | #ifndef lint | ||||
static const char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; | static const char sccsid[] = "@(#)tr.c 8.2 (Berkeley) 5/4/95"; | ||||
#endif | #endif | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/capsicum.h> | #include <sys/capsicum.h> | ||||
#include <capsicum_helpers.h> | |||||
#include <ctype.h> | #include <ctype.h> | ||||
#include <err.h> | #include <err.h> | ||||
#include <errno.h> | |||||
#include <limits.h> | #include <limits.h> | ||||
#include <locale.h> | #include <locale.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <termios.h> | |||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <wchar.h> | #include <wchar.h> | ||||
#include <wctype.h> | #include <wctype.h> | ||||
#include "cmap.h" | #include "cmap.h" | ||||
#include "cset.h" | #include "cset.h" | ||||
#include "extern.h" | #include "extern.h" | ||||
static STR s1 = { STRING1, NORMAL, 0, OOBCH, 0, { 0, OOBCH }, NULL, NULL }; | static STR s1 = { STRING1, NORMAL, 0, OOBCH, 0, { 0, OOBCH }, NULL, NULL }; | ||||
static STR s2 = { STRING2, NORMAL, 0, OOBCH, 0, { 0, OOBCH }, NULL, NULL }; | static STR s2 = { STRING2, NORMAL, 0, OOBCH, 0, { 0, OOBCH }, NULL, NULL }; | ||||
static struct cset *setup(char *, STR *, int, int); | static struct cset *setup(char *, STR *, int, int); | ||||
static void usage(void); | static void usage(void); | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
static int carray[NCHARS_SB]; | static int carray[NCHARS_SB]; | ||||
cap_rights_t rights; | |||||
unsigned long cmd; | |||||
struct cmap *map; | struct cmap *map; | ||||
struct cset *delete, *squeeze; | struct cset *delete, *squeeze; | ||||
int n, *p; | int n, *p; | ||||
int Cflag, cflag, dflag, sflag, isstring2; | int Cflag, cflag, dflag, sflag, isstring2; | ||||
wint_t ch, cnt, lastch; | wint_t ch, cnt, lastch; | ||||
(void)setlocale(LC_ALL, ""); | (void)setlocale(LC_ALL, ""); | ||||
cap_rights_init(&rights, CAP_FSTAT, CAP_IOCTL, CAP_READ); | if (caph_limit_stdio() == -1) | ||||
if (cap_rights_limit(STDIN_FILENO, &rights) < 0 && errno != ENOSYS) | err(1, "unable to limit stdio"); | ||||
err(1, "unable to limit rights for stdin"); | |||||
cap_rights_init(&rights, CAP_FSTAT, CAP_IOCTL, CAP_WRITE); | |||||
if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit rights for stdout"); | |||||
if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit rights for stderr"); | |||||
/* Required for isatty(3). */ | |||||
cmd = TIOCGETA; | |||||
if (cap_ioctls_limit(STDIN_FILENO, &cmd, 1) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit ioctls for stdin"); | |||||
if (cap_ioctls_limit(STDOUT_FILENO, &cmd, 1) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit ioctls for stdout"); | |||||
if (cap_ioctls_limit(STDERR_FILENO, &cmd, 1) < 0 && errno != ENOSYS) | |||||
err(1, "unable to limit ioctls for stderr"); | |||||
if (cap_enter() < 0 && errno != ENOSYS) | if (cap_enter() < 0 && errno != ENOSYS) | ||||
err(1, "unable to enter capability mode"); | err(1, "unable to enter capability mode"); | ||||
Cflag = cflag = dflag = sflag = 0; | Cflag = cflag = dflag = sflag = 0; | ||||
while ((ch = getopt(argc, argv, "Ccdsu")) != -1) | while ((ch = getopt(argc, argv, "Ccdsu")) != -1) | ||||
switch((char)ch) { | switch((char)ch) { | ||||
case 'C': | case 'C': | ||||
▲ Show 20 Lines • Show All 291 Lines • Show Last 20 Lines |