str(1): updates to use pledge(2)

This commit is contained in:
Emma Tebibyte 2024-08-10 19:00:32 -06:00
parent 18dfd20937
commit 8699d04ccc
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -22,7 +22,11 @@
#include <stdio.h> /* fprintf(3) */ #include <stdio.h> /* fprintf(3) */
#include <stdlib.h> /* size_t, EXIT_FAILURE */ #include <stdlib.h> /* size_t, EXIT_FAILURE */
#include <string.h> /* strcmp(3) */ #include <string.h> /* strcmp(3) */
#include <sysexits.h> /* EX_USAGE */ #include <sysexits.h> /* EX_OSERR, EX_USAGE */
#ifdef __OpenBSD__
# include <unistd.h> /* pledge(2) */
#endif
char *program_name = "str"; char *program_name = "str";
@ -55,8 +59,16 @@ usage(char *argv0) {
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
size_t ctype; // selected from ctypes.h; index of ctype size_t ctype; // selected from ctypes.h; index of ctype
int retval; // initially fail but becomes success on the first valid char int retval; // initially fail but becomes success on the first valid char
program_name = argv[0] == NULL ? program_name : argv[0];
if (argc < 3) { return usage(argv[0] == NULL ? program_name : argv[0]); } #ifdef __OpenBSD__
if (pledge("stdio", NULL) == -1) {
perror(program_name);
return EX_OSERR;
}
#endif
if (argc < 3) { return usage(program_name); }
for ( /* iterate ctypes */ for ( /* iterate ctypes */
ctype = 0; ctype = 0;