├── AUTHORS ├── COPYING ├── NEWS ├── README ├── ChangeLog ├── Makefile.am ├── src ├── Makefile.am ├── pax │ ├── extern.h.gch │ ├── Makefile.am │ ├── getoldopt.c │ ├── pack_dev.h │ ├── ftree.h │ ├── pat_rep.h │ ├── sel_subs.h │ ├── dumptar.c │ ├── options.h │ ├── tty_subs.c │ ├── tar.h │ └── cpio.h ├── xargs │ ├── Makefile.am │ ├── pathnames.h │ └── strnsubst.c ├── sed │ ├── Makefile.am │ ├── extern.h │ ├── misc.c │ └── defs.h ├── find │ ├── Makefile.am │ ├── ls.c │ ├── misc.c │ ├── extern.h │ ├── main.c │ └── find.h ├── patch │ ├── Makefile.am │ ├── pathnames.h │ ├── backupfile.h │ ├── inp.h │ ├── pch.h │ ├── util.h │ ├── mkpath.c │ └── common.h └── libnetbsd │ ├── Makefile.am │ ├── useless.c │ ├── reallocarray.c │ ├── fgetstr.c │ ├── errc.c │ ├── strtoq.c │ ├── ctype_local.h │ ├── getprogname.c │ ├── strtoumax.c │ ├── strlcpy.c │ ├── strtoimax.c │ ├── verrc.c │ ├── fgetln.c │ ├── strtoi.c │ ├── strtou.c │ ├── setprogname.c │ ├── wcio.h │ ├── util.h │ ├── strlcat.c │ ├── reallocarr.c │ ├── fileext.h │ ├── pwcache.h │ ├── raise_default_signal.c │ ├── setlocale_local.h │ ├── strmode.c │ ├── local.h │ ├── _strtoi.h │ ├── stat_flags.c │ ├── efun.c │ └── _strtoul.h ├── README.md ├── configure.ac ├── .gitignore ├── difference ├── xargs.patch ├── patch.patch └── find.patch └── include ├── vis.h ├── tzfile.h ├── bsd.h └── fts.h /AUTHORS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = src 2 | -------------------------------------------------------------------------------- /src/Makefile.am: -------------------------------------------------------------------------------- 1 | SUBDIRS = libnetbsd sed find xargs patch pax 2 | -------------------------------------------------------------------------------- /src/pax/extern.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ataraxialinux/netbsd-tools/HEAD/src/pax/extern.h.gch -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NetBSD tools 2 | 3 | Collection of NetBSD tools for Linux (especially for Ataraxia Linux) 4 | -------------------------------------------------------------------------------- /src/xargs/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | 3 | bin_PROGRAMS = xargs 4 | xargs_SOURCES = xargs.c strnsubst.c 5 | xargs_LDADD = ../libnetbsd/libnetbsd.a 6 | man1_MANS = xargs.1 7 | -------------------------------------------------------------------------------- /src/sed/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | 3 | bin_PROGRAMS = sed 4 | sed_SOURCES = compile.c main.c misc.c process.c 5 | sed_LDADD = ../libnetbsd/libnetbsd.a 6 | man1_MANS = sed.1 7 | -------------------------------------------------------------------------------- /src/find/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | 3 | bin_PROGRAMS = find 4 | find_SOURCES = find.c function.c ls.c main.c misc.c operator.c option.c 5 | find_LDADD = ../libnetbsd/libnetbsd.a 6 | man1_MANS = find.1 7 | -------------------------------------------------------------------------------- /src/patch/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | 3 | bin_PROGRAMS = patch 4 | patch_SOURCES = patch.c pch.c inp.c util.c backupfile.c mkpath.c 5 | patch_LDADD = ../libnetbsd/libnetbsd.a 6 | man1_MANS = patch.1 7 | -------------------------------------------------------------------------------- /src/patch/pathnames.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: pathnames.h,v 1.1 2003/07/29 20:10:17 millert Exp $ 3 | * $DragonFly: src/usr.bin/patch/pathnames.h,v 1.2 2008/08/11 00:04:12 joerg Exp $ 4 | * $NetBSD: pathnames.h,v 1.1 2008/09/19 18:33:34 joerg Exp $ 5 | */ 6 | 7 | /* 8 | * Placed in the public domain by Todd C. Miller 9 | * on July 29, 2003. 10 | */ 11 | 12 | #include 13 | 14 | #define _PATH_ED "/bin/ed" 15 | -------------------------------------------------------------------------------- /src/pax/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include -DSMALL 2 | 3 | bin_PROGRAMS = pax 4 | pax_SOURCES = ar_io.c ar_subs.c buf_subs.c file_subs.c ftree.c gen_subs.c getoldopt.c options.c pat_rep.c pax.c sel_subs.c tables.c tar.c tty_subs.c pack_dev.c cpio.c 5 | pax_LDADD = ../libnetbsd/libnetbsd.a 6 | man1_MANS = pax.1 tar.1 cpio.1 7 | 8 | install-exec-hook: 9 | ln -sf pax $(DESTDIR)$(bindir)/cpio 10 | ln -sf pax $(DESTDIR)$(bindir)/tar 11 | -------------------------------------------------------------------------------- /configure.ac: -------------------------------------------------------------------------------- 1 | AC_PREREQ(2.59) 2 | AC_INIT([netbsd-tools], [9.0], [ataraxialinux@protonmail.com]) 3 | AM_INIT_AUTOMAKE 4 | AM_SANITY_CHECK 5 | m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) 6 | 7 | AC_PROG_MAKE_SET 8 | AC_GNU_SOURCE 9 | AC_STDC_HEADERS 10 | AC_PROG_CC() 11 | AC_PROG_YACC() 12 | AC_PROG_LEX() 13 | AC_PROG_RANLIB() 14 | 15 | AC_CONFIG_FILES([Makefile 16 | src/Makefile 17 | src/libnetbsd/Makefile 18 | src/sed/Makefile 19 | src/find/Makefile 20 | src/xargs/Makefile 21 | src/patch/Makefile 22 | src/pax/Makefile]) 23 | AC_OUTPUT 24 | -------------------------------------------------------------------------------- /src/libnetbsd/Makefile.am: -------------------------------------------------------------------------------- 1 | AM_CPPFLAGS = -I$(top_srcdir)/include 2 | 3 | noinst_LIBRARIES = libnetbsd.a 4 | libnetbsd_a_SOURCES = efun.c \ 5 | errc.c \ 6 | fgetln.c \ 7 | fgetstr.c \ 8 | fts.c \ 9 | getprogname.c \ 10 | parsedate.tab.c \ 11 | pwcache.c \ 12 | setprogname.c \ 13 | reallocarr.c \ 14 | reallocarray.c \ 15 | raise_default_signal.c \ 16 | setmode.c \ 17 | stat_flags.c \ 18 | strlcat.c \ 19 | strlcpy.c \ 20 | strmode.c \ 21 | strtoq.c \ 22 | strtoi.c \ 23 | strtoimax.c \ 24 | strtou.c \ 25 | strtoumax.c \ 26 | useless.c \ 27 | verrc.c \ 28 | vis.c 29 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.slo 2 | *.lo 3 | *.o 4 | *.obj 5 | *.so 6 | *.dylib 7 | *.dll 8 | *.lai 9 | *.la 10 | *.a 11 | *.lib 12 | *.exe 13 | *.out 14 | *.app 15 | *.swp 16 | *.DS_Store 17 | m4/* 18 | aclocal.m4 19 | autom4te.cache/ 20 | compile 21 | config.guess 22 | config.log 23 | config.status 24 | config.sub 25 | configure 26 | depcomp 27 | missing 28 | ltmain.sh 29 | libtool 30 | install-sh 31 | .deps 32 | .libs 33 | Makefile 34 | Makefile.in 35 | src/sed/sed 36 | src/find/find 37 | src/xargs/xargs 38 | src/patch/patch 39 | src/pax/pax 40 | src/xinstall/install 41 | src/sed/Makefile 42 | src/find/Makefile 43 | src/xargs/Makefile 44 | src/patch/Makefile 45 | src/pax/Makefile 46 | src/xinstall/Makefile 47 | ylwrap 48 | -------------------------------------------------------------------------------- /src/libnetbsd/useless.c: -------------------------------------------------------------------------------- 1 | // shit-ton of useless bsd functions 2 | 3 | #include 4 | 5 | void setpassent(i) 6 | int i; 7 | { 8 | } 9 | 10 | void setgroupent(i) 11 | int i; 12 | { 13 | } 14 | 15 | int 16 | netbsd_statvfs(const char *file, struct statvfs *st) 17 | { 18 | return statvfs(file, st); 19 | } 20 | 21 | const char *const sys_signame[] = { 22 | "Signal 0", /* 0 */ 23 | "HUP", /* 1 SIGHUP */ 24 | "INT", /* 2 SIGINT */ 25 | "QUIT", /* 3 SIGQUIT */ 26 | "ILL", /* 4 SIGILL */ 27 | "TRAP", /* 5 SIGTRAP */ 28 | "ABRT", /* 6 SIGABRT */ 29 | "EMT", /* 7 SIGEMT */ 30 | "FPE", /* 8 SIGFPE */ 31 | "KILL", /* 9 SIGKILL */ 32 | "BUS", /* 10 SIGBUS */ 33 | "SEGV", /* 11 SIGSEGV */ 34 | "SYS", /* 12 SIGSYS */ 35 | "PIPE", /* 13 SIGPIPE */ 36 | "ALRM", /* 14 SIGALRM */ 37 | "TERM", /* 15 SIGTERM */ 38 | "URG", /* 16 SIGURG */ 39 | "STOP", /* 17 SIGSTOP */ 40 | "TSTP", /* 18 SIGTSTP */ 41 | "CONT", /* 19 SIGCONT */ 42 | "CHLD", /* 20 SIGCHLD */ 43 | "TTIN", /* 21 SIGTTIN */ 44 | "TTOU", /* 22 SIGTTOU */ 45 | "IO", /* 23 SIGIO */ 46 | "XCPU", /* 24 SIGXCPU */ 47 | "XFSZ", /* 25 SIGXFSZ */ 48 | "VTALRM", /* 26 SIGVTALRM */ 49 | "PROF", /* 27 SIGPROF */ 50 | "WINCH", /* 28 SIGWINCH */ 51 | "INFO", /* 29 SIGINFO */ 52 | "USR1", /* 30 SIGUSR1 */ 53 | "USR2", /* 31 SIGUSR2 */ 54 | }; 55 | -------------------------------------------------------------------------------- /src/patch/backupfile.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: backupfile.h,v 1.6 2003/07/28 18:35:36 otto Exp $ 3 | * $DragonFly: src/usr.bin/patch/backupfile.h,v 1.3 2007/09/29 23:11:10 swildner Exp $ 4 | * $NetBSD: backupfile.h,v 1.6 2008/09/19 18:33:34 joerg Exp $ 5 | */ 6 | 7 | /* 8 | * backupfile.h -- declarations for making Emacs style backup file names 9 | * Copyright (C) 1990 Free Software Foundation, Inc. 10 | * 11 | * This program is free software; you can redistribute it and/or modify it 12 | * without restriction. 13 | * 14 | * This program is distributed in the hope that it will be useful, but WITHOUT 15 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | * FITNESS FOR A PARTICULAR PURPOSE. 17 | * 18 | */ 19 | 20 | /* When to make backup files. */ 21 | enum backup_type { 22 | /* Never make backups. */ 23 | none, 24 | 25 | /* Make simple backups of every file. */ 26 | simple, 27 | 28 | /* 29 | * Make numbered backups of files that already have numbered backups, 30 | * and simple backups of the others. 31 | */ 32 | numbered_existing, 33 | 34 | /* Make numbered backups of every file. */ 35 | numbered 36 | }; 37 | 38 | extern enum backup_type backup_type; 39 | extern const char *simple_backup_suffix; 40 | 41 | char *find_backup_file_name(const char *file); 42 | enum backup_type get_version(const char *version); 43 | -------------------------------------------------------------------------------- /src/libnetbsd/reallocarray.c: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ 2 | /* 3 | * Copyright (c) 2008 Otto Moerbeek 4 | * 5 | * Permission to use, copy, modify, and distribute this software for any 6 | * purpose with or without fee is hereby granted, provided that the above 7 | * copyright notice and this permission notice appear in all copies. 8 | * 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | /* 25 | * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX 26 | * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW 27 | */ 28 | #define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) 29 | 30 | void * 31 | reallocarray(void *optr, size_t nmemb, size_t size) 32 | { 33 | if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && 34 | nmemb > 0 && SIZE_MAX / nmemb < size) { 35 | errno = ENOMEM; 36 | return NULL; 37 | } 38 | return realloc(optr, size * nmemb); 39 | } 40 | DEF_WEAK(reallocarray); 41 | -------------------------------------------------------------------------------- /src/patch/inp.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: inp.h,v 1.8 2003/08/15 08:00:51 otto Exp $ 3 | * $DragonFly: src/usr.bin/patch/inp.h,v 1.1 2004/09/24 18:44:28 joerg Exp $ 4 | * $NetBSD: inp.h,v 1.10 2008/09/19 18:33:34 joerg Exp $ 5 | */ 6 | 7 | /* 8 | * patch - a program to apply diffs to original files 9 | * 10 | * Copyright 1986, Larry Wall 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following condition is met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this condition and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * -C option added in 1998, original code by Marc Espie, based on FreeBSD 30 | * behaviour 31 | */ 32 | 33 | void re_input(void); 34 | void scan_input(const char *); 35 | char *ifetch(LINENUM, int); 36 | -------------------------------------------------------------------------------- /difference/xargs.patch: -------------------------------------------------------------------------------- 1 | diff -ruN ../netbsd/usr.bin/xargs/strnsubst.c src/xargs/strnsubst.c 2 | --- ../netbsd/usr.bin/xargs/strnsubst.c 2020-04-10 23:58:13.645336000 +0900 3 | +++ src/xargs/strnsubst.c 2020-04-11 20:18:12.861021992 +0900 4 | @@ -8,19 +8,12 @@ 5 | * For the man who taught me vi, and who got too old, too young. 6 | */ 7 | 8 | -#include 9 | -#ifndef lint 10 | -#if 0 11 | -__FBSDID("$FreeBSD: src/usr.bin/xargs/strnsubst.c,v 1.8 2005/12/30 23:22:50 jmallett Exp $"); 12 | -#endif 13 | -__RCSID("$NetBSD: strnsubst.c,v 1.1 2007/04/18 15:56:07 christos Exp $"); 14 | -#endif /* not lint */ 15 | - 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | +#include 22 | 23 | void strnsubst(char **, const char *, const char *, size_t); 24 | 25 | diff -ruN ../netbsd/usr.bin/xargs/xargs.c src/xargs/xargs.c 26 | --- ../netbsd/usr.bin/xargs/xargs.c 2020-04-10 23:58:13.645336000 +0900 27 | +++ src/xargs/xargs.c 2020-04-11 20:18:17.432022412 +0900 28 | @@ -34,17 +34,6 @@ 29 | * $xMach: xargs.c,v 1.6 2002/02/23 05:27:47 tim Exp $ 30 | */ 31 | 32 | -#include 33 | -#ifndef lint 34 | -__COPYRIGHT("@(#) Copyright (c) 1990, 1993\ 35 | - The Regents of the University of California. All rights reserved."); 36 | -#if 0 37 | -static char sccsid[] = "@(#)xargs.c 8.1 (Berkeley) 6/6/93"; 38 | -__FBSDID("$FreeBSD: src/usr.bin/xargs/xargs.c,v 1.62 2006/01/01 22:59:54 jmallett Exp $"); 39 | -#endif 40 | -__RCSID("$NetBSD: xargs.c,v 1.20 2010/12/17 11:32:57 plunky Exp $"); 41 | -#endif /* not lint */ 42 | - 43 | #include 44 | #include 45 | 46 | @@ -60,6 +49,7 @@ 47 | #include 48 | #include 49 | #include 50 | +#include 51 | 52 | #include "pathnames.h" 53 | 54 | -------------------------------------------------------------------------------- /src/xargs/pathnames.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. All advertising materials mentioning features or use of this software 14 | * must display the following acknowledgement: 15 | * This product includes software developed by the University of 16 | * California, Berkeley and its contributors. 17 | * 4. Neither the name of the University nor the names of its contributors 18 | * may be used to endorse or promote products derived from this software 19 | * without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 | * SUCH DAMAGE. 32 | * 33 | * @(#)pathnames.h 8.1 (Berkeley) 6/6/93 34 | */ 35 | 36 | #define _PATH_ECHO "/bin/echo" 37 | -------------------------------------------------------------------------------- /src/libnetbsd/fgetstr.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: fgetstr.c,v 1.12 2017/06/08 15:59:45 uwe Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2009 The NetBSD Foundation, Inc. 5 | * 6 | * This code is derived from software contributed to The NetBSD Foundation 7 | * by Roy Marples. 8 | * 9 | * Redistribution and use in source and binary forms, with or without 10 | * modification, are permitted provided that the following conditions 11 | * are met: 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 2. Redistributions in binary form must reproduce the above copyright 15 | * notice, this list of conditions and the following disclaimer in the 16 | * documentation and/or other materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | /* 37 | * Get an input line. 38 | * This now uses getdelim(3) for a code reduction. 39 | * The upside is that strings are now always null-terminated, but relying 40 | * on this is non portable - better to use the POSIX getdelim(3) function. 41 | */ 42 | char * 43 | __fgetstr(FILE *__restrict fp, size_t *__restrict lenp, int sep) 44 | { 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /src/pax/getoldopt.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: getoldopt.c,v 1.23 2012/08/09 11:05:59 christos Exp $ */ 2 | 3 | /* 4 | * Plug-compatible replacement for getopt() for parsing tar-like 5 | * arguments. If the first argument begins with "-", it uses getopt; 6 | * otherwise, it uses the old rules used by tar, dump, and ps. 7 | * 8 | * Written 25 August 1985 by John Gilmore (ihnp4!hoptoad!gnu) and placed 9 | * in the Public Domain for your edification and enjoyment. 10 | */ 11 | 12 | #if HAVE_NBTOOL_CONFIG_H 13 | #include "nbtool_config.h" 14 | #endif 15 | 16 | #if HAVE_NBTOOL_CONFIG_H 17 | #include "compat_getopt.h" 18 | #else 19 | #include 20 | #endif 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "pax.h" 29 | #include "extern.h" 30 | 31 | int 32 | getoldopt(int argc, char **argv, const char *optstring, 33 | struct option *longopts, int *idx) 34 | { 35 | static char *key; /* Points to next keyletter */ 36 | static char use_getopt; /* !=0 if argv[1][0] was '-' */ 37 | char c; 38 | char *place; 39 | 40 | optarg = NULL; 41 | 42 | if (key == NULL) { /* First time */ 43 | if (argc < 2) return -1; 44 | key = argv[1]; 45 | if (*key == '-') 46 | use_getopt++; 47 | else 48 | optind = 2; 49 | } 50 | 51 | c = '\0'; 52 | if (!use_getopt) { 53 | c = *key++; 54 | if (c == '\0') { 55 | key--; 56 | use_getopt = 1; 57 | } 58 | } 59 | if (use_getopt) { 60 | if (longopts != NULL) { 61 | return getopt_long(argc, argv, optstring, 62 | longopts, idx); 63 | } else { 64 | return getopt(argc, argv, optstring); 65 | } 66 | } 67 | 68 | place = strchr(optstring, c); 69 | 70 | if (place == NULL || c == ':') { 71 | fprintf(stderr, "%s: unknown option %c\n", argv[0], c); 72 | return '?'; 73 | } 74 | 75 | place++; 76 | if (*place == ':') { 77 | if (optind < argc) { 78 | optarg = argv[optind]; 79 | optind++; 80 | } else { 81 | fprintf(stderr, "%s: %c argument missing\n", 82 | argv[0], c); 83 | return '?'; 84 | } 85 | } 86 | 87 | return c; 88 | } 89 | -------------------------------------------------------------------------------- /src/libnetbsd/errc.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: errc.c,v 1.3 2014/06/06 11:38:41 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | 40 | #ifdef __weak_alias 41 | __weak_alias(errc, _errc) 42 | #endif 43 | 44 | #if !HAVE_ERR_H || !HAVE_DECL_ERRC 45 | __dead void 46 | errc(int eval, int code, const char *fmt, ...) 47 | { 48 | va_list ap; 49 | 50 | va_start(ap, fmt); 51 | verrc(eval, code, fmt, ap); 52 | va_end(ap); 53 | } 54 | #endif 55 | -------------------------------------------------------------------------------- /src/libnetbsd/strtoq.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strtoq.c,v 1.19 2008/08/20 12:42:26 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2008 Joerg Sonnenberger 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | 37 | #ifndef UQUAD_MAX 38 | #define UQUAD_MAX ((u_quad_t)0-1) /* max value for a uquad_t */ 39 | /* max value for a quad_t */ 40 | #endif 41 | #ifndef QUAD_MAX 42 | #define QUAD_MAX ((quad_t)(UQUAD_MAX >> 1)) 43 | #endif 44 | #ifndef QUAD_MIN 45 | #define QUAD_MIN (-QUAD_MAX-1) /* min value for a quad_t */ 46 | #endif 47 | 48 | #ifndef __GLIBC__ 49 | #define _FUNCNAME strtoq 50 | #define __INT quad_t 51 | #define __INT_MIN QUAD_MIN 52 | #define __INT_MAX QUAD_MAX 53 | 54 | #include "_strtol.h" 55 | #endif 56 | -------------------------------------------------------------------------------- /src/pax/pack_dev.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: pack_dev.h,v 1.8 2013/06/14 16:28:20 tsutsui Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Charles M. Hannum. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef _PACK_DEV_H 33 | #define _PACK_DEV_H 34 | 35 | typedef dev_t pack_t(int, u_long [], const char **); 36 | 37 | pack_t *pack_find(const char *); 38 | pack_t pack_native; 39 | 40 | #define major_netbsd(x) ((int32_t)((((x) & 0x000fff00) >> 8))) 41 | #define minor_netbsd(x) ((int32_t)((((x) & 0xfff00000) >> 12) | \ 42 | (((x) & 0x000000ff) >> 0))) 43 | #define makedev_netbsd(x,y) ((dev_t)((((x) << 8) & 0x000fff00) | \ 44 | (((y) << 12) & 0xfff00000) | \ 45 | (((y) << 0) & 0x000000ff))) 46 | 47 | #endif /* _PACK_DEV_H */ 48 | -------------------------------------------------------------------------------- /src/libnetbsd/ctype_local.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: ctype_local.h,v 1.5 2013/04/13 10:21:20 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2010 Citrus Project, 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | #ifndef _CTYPE_LOCAL_H_ 29 | #define _CTYPE_LOCAL_H_ 30 | 31 | #include 32 | 33 | #define _CTYPE_NUM_CHARS (1 << CHAR_BIT) 34 | #define _CTYPE_CACHE_SIZE (1 << 8) 35 | 36 | #define _COMPAT_U 0x01 37 | #define _COMPAT_L 0x02 38 | #define _COMPAT_N 0x04 39 | #define _COMPAT_S 0x08 40 | #define _COMPAT_P 0x10 41 | #define _COMPAT_C 0x20 42 | #define _COMPAT_X 0x40 43 | #define _COMPAT_B 0x80 44 | 45 | extern const unsigned short _C_ctype_tab_[]; 46 | extern const short _C_toupper_tab_[]; 47 | extern const short _C_tolower_tab_[]; 48 | 49 | #ifdef __BUILD_LEGACY 50 | extern const unsigned char *_ctype_; 51 | extern const unsigned char _C_compat_bsdctype[]; 52 | #endif 53 | 54 | #endif /*_CTYPE_LOCAL_H_*/ 55 | -------------------------------------------------------------------------------- /src/libnetbsd/getprogname.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: getprogname.c,v 1.4 2011/10/06 20:31:41 christos Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2001 Christopher G. Demetriou 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. All advertising materials mentioning features or use of this software 16 | * must display the following acknowledgement: 17 | * This product includes software developed for the 18 | * NetBSD Project. See http://www.NetBSD.org/ for 19 | * information about NetBSD. 20 | * 4. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * <> 35 | */ 36 | 37 | #include 38 | 39 | #ifdef __weak_alias 40 | __weak_alias(getprogname,_getprogname) 41 | #endif 42 | 43 | const char *__progname; 44 | 45 | const char * 46 | getprogname(void) 47 | { 48 | 49 | return (__progname); 50 | } 51 | -------------------------------------------------------------------------------- /src/patch/pch.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: pch.h,v 1.9 2003/10/31 20:20:45 millert Exp $ 3 | * $DragonFly: src/usr.bin/patch/pch.h,v 1.1 2004/09/24 18:44:28 joerg Exp $ 4 | * $NetBSD: pch.h,v 1.10 2008/09/19 18:33:34 joerg Exp $ 5 | */ 6 | 7 | /* 8 | * patch - a program to apply diffs to original files 9 | * 10 | * Copyright 1986, Larry Wall 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following condition is met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this condition and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * -C option added in 1998, original code by Marc Espie, based on FreeBSD 30 | * behaviour 31 | */ 32 | 33 | #define OLD_FILE 0 34 | #define NEW_FILE 1 35 | #define INDEX_FILE 2 36 | #define MAX_FILE 3 37 | 38 | struct file_name { 39 | char *path; 40 | bool exists; 41 | }; 42 | 43 | void re_patch(void); 44 | void open_patch_file(const char *); 45 | void set_hunkmax(void); 46 | bool there_is_another_patch(void); 47 | bool another_hunk(void); 48 | bool pch_swap(void); 49 | char *pfetch(LINENUM); 50 | short pch_line_len(LINENUM); 51 | LINENUM pch_first(void); 52 | LINENUM pch_ptrn_lines(void); 53 | LINENUM pch_newfirst(void); 54 | LINENUM pch_repl_lines(void); 55 | LINENUM pch_end(void); 56 | LINENUM pch_context(void); 57 | LINENUM pch_hunk_beg(void); 58 | char pch_char(LINENUM); 59 | void do_ed_script(void); 60 | -------------------------------------------------------------------------------- /src/patch/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: util.h,v 1.15 2005/06/20 07:14:06 otto Exp $ 3 | * $DragonFly: src/usr.bin/patch/util.h,v 1.2 2007/09/29 23:11:10 swildner Exp $ 4 | * $NetBSD: util.h,v 1.13 2018/06/18 18:33:31 christos Exp $ 5 | */ 6 | 7 | /* 8 | * patch - a program to apply diffs to original files 9 | * 10 | * Copyright 1986, Larry Wall 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following condition is met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this condition and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * -C option added in 1998, original code by Marc Espie, based on FreeBSD 30 | * behaviour 31 | */ 32 | 33 | char *fetchname(const char *, bool *, int); 34 | char *checked_in(char *); 35 | int backup_file(const char *); 36 | int move_file(const char *, const char *); 37 | int copy_file(const char *, const char *); 38 | void say(const char *, ...) __printflike(1, 2); 39 | void fatal(const char *, ...) __printflike(1, 2) __dead; 40 | void pfatal(const char *, ...) __printflike(1, 2) __dead; 41 | void ask(const char *, ...) __printflike(1, 2); 42 | char *savestr(const char *); 43 | void set_signals(int); 44 | void ignore_signals(void); 45 | void makedirs(const char *, bool); 46 | void version(void) __dead; 47 | void my_exit(int) __dead; 48 | void *pch_realloc(void *, size_t, size_t); 49 | 50 | /* in mkpath.c */ 51 | extern int mkpath(char *); 52 | -------------------------------------------------------------------------------- /src/libnetbsd/strtoumax.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strtoumax.c,v 1.6 2013/04/16 21:44:06 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2005 The DragonFly Project. All rights reserved. 5 | * Copyright (c) 2003 Citrus Project, 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #if HAVE_NBTOOL_CONFIG_H 31 | #include "nbtool_config.h" 32 | #endif 33 | 34 | #if defined(_KERNEL) 35 | #include 36 | #include 37 | #elif defined(_STANDALONE) 38 | #include 39 | #include 40 | #include 41 | #else 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #endif 51 | 52 | #define _FUNCNAME strtoumax 53 | #define __UINT uintmax_t 54 | #define __UINT_MAX UINTMAX_MAX 55 | 56 | #include "_strtoul.h" 57 | 58 | #ifdef _LIBC 59 | __weak_alias(strtoumax, _strtoumax) 60 | __weak_alias(strtoumax_l, _strtoumax_l) 61 | #endif 62 | -------------------------------------------------------------------------------- /src/pax/ftree.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: ftree.h,v 1.5 2003/10/13 07:41:22 agc Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)ftree.h 8.1 (Berkeley) 5/31/93 36 | */ 37 | 38 | /* 39 | * Data structure used by the ftree.c routines to store the file args to be 40 | * handed to fts(). It keeps a reference count of which args generated a 41 | * "selected" member 42 | */ 43 | 44 | typedef struct ftree { 45 | char *fname; /* file tree name */ 46 | int refcnt; /* has tree had a selected file? */ 47 | struct ftree *fow; /* pointer to next entry on list */ 48 | } FTREE; 49 | -------------------------------------------------------------------------------- /src/libnetbsd/strlcpy.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strlcpy.c,v 1.3 2007/06/04 18:19:27 christos Exp $ */ 2 | /* $OpenBSD: strlcpy.c,v 1.7 2003/04/12 21:56:39 millert Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1998 Todd C. Miller 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL 12 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 13 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE 14 | * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 16 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #if !defined(_KERNEL) && !defined(_STANDALONE) 21 | #if HAVE_NBTOOL_CONFIG_H 22 | #include "nbtool_config.h" 23 | #endif 24 | 25 | #ifdef _LIBC 26 | #include "namespace.h" 27 | #endif 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef _LIBC 34 | # ifdef __weak_alias 35 | __weak_alias(strlcpy, _strlcpy) 36 | # endif 37 | #endif 38 | #else 39 | #include 40 | #endif /* !_KERNEL && !_STANDALONE */ 41 | 42 | 43 | #if !HAVE_STRLCPY 44 | /* 45 | * Copy src to string dst of size siz. At most siz-1 characters 46 | * will be copied. Always NUL terminates (unless siz == 0). 47 | * Returns strlen(src); if retval >= siz, truncation occurred. 48 | */ 49 | size_t 50 | strlcpy(char *dst, const char *src, size_t siz) 51 | { 52 | char *d = dst; 53 | const char *s = src; 54 | size_t n = siz; 55 | 56 | _DIAGASSERT(dst != NULL); 57 | _DIAGASSERT(src != NULL); 58 | 59 | /* Copy as many bytes as will fit */ 60 | if (n != 0 && --n != 0) { 61 | do { 62 | if ((*d++ = *s++) == 0) 63 | break; 64 | } while (--n != 0); 65 | } 66 | 67 | /* Not enough room in dst, add NUL and traverse rest of src */ 68 | if (n == 0) { 69 | if (siz != 0) 70 | *d = '\0'; /* NUL-terminate dst */ 71 | while (*s++) 72 | ; 73 | } 74 | 75 | return(s - src - 1); /* count does not include NUL */ 76 | } 77 | #endif 78 | -------------------------------------------------------------------------------- /src/libnetbsd/strtoimax.c: -------------------------------------------------------------------------------- 1 | /* $DragonFly: src/lib/libc/stdlib/strtoimax.c,v 1.2 2008/08/19 15:50:24 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2005 The DragonFly Project. All rights reserved. 5 | * Copyright (c) 2003 Citrus Project, 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #if HAVE_NBTOOL_CONFIG_H 31 | #include "nbtool_config.h" 32 | #endif 33 | 34 | #if defined(_KERNEL) 35 | #include 36 | #include 37 | #elif defined(_STANDALONE) 38 | #include 39 | #include 40 | #include 41 | #else 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #endif 51 | 52 | #define _FUNCNAME strtoimax 53 | #define __INT intmax_t 54 | #define __INT_MIN INTMAX_MIN 55 | #define __INT_MAX INTMAX_MAX 56 | 57 | #include "_strtol.h" 58 | 59 | #ifdef _LIBC 60 | __weak_alias(strtoimax, _strtoimax) 61 | __weak_alias(strtoimax_l, _strtoimax_l) 62 | #endif 63 | -------------------------------------------------------------------------------- /src/libnetbsd/verrc.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: verrc.c,v 1.3 2014/06/06 11:38:41 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | #ifdef __weak_alias 44 | __weak_alias(verrc, _verrc) 45 | #endif 46 | 47 | #if !HAVE_ERR_H || !HAVE_DECL_ERRC 48 | __dead void 49 | verrc(int eval, int code, const char *fmt, va_list ap) 50 | { 51 | (void)fprintf(stderr, "%s: ", getprogname()); 52 | if (fmt != NULL) { 53 | (void)vfprintf(stderr, fmt, ap); 54 | (void)fprintf(stderr, ": "); 55 | } 56 | (void)fprintf(stderr, "%s\n", strerror(code)); 57 | exit(eval); 58 | } 59 | #endif 60 | -------------------------------------------------------------------------------- /src/libnetbsd/fgetln.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: fgetln.c,v 1.17 2017/06/08 15:59:45 uwe Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Chris Torek. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the University nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include "reentrant.h" 39 | #include "local.h" 40 | 41 | #ifdef __weak_alias 42 | __weak_alias(fgetln,_fgetln) 43 | #endif 44 | 45 | /* 46 | * Get an input line. 47 | * This now uses getdelim(3) for a code reduction. 48 | * The upside is that strings are now always null-terminated, but relying 49 | * on this is non portable - better to use the POSIX getdelim(3) function. 50 | */ 51 | char * 52 | fgetln(FILE *fp, size_t *lenp) 53 | { 54 | char *p; 55 | 56 | FLOCKFILE(fp); 57 | p = __fgetstr(fp, lenp, '\n'); 58 | FUNLOCKFILE(fp); 59 | return p; 60 | } 61 | -------------------------------------------------------------------------------- /src/libnetbsd/strtoi.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strtoi.c,v 1.3 2019/11/28 12:33:23 roy Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2005 The DragonFly Project. All rights reserved. 5 | * Copyright (c) 2003 Citrus Project, 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * Created by Kamil Rytarowski, based on ID: 30 | * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp 31 | */ 32 | 33 | #if defined(HAVE_NBTOOL_CONFIG_H) && HAVE_NBTOOL_CONFIG_H 34 | #include "nbtool_config.h" 35 | #endif 36 | 37 | #if defined(_KERNEL) 38 | #include 39 | #include 40 | #include 41 | #elif defined(_STANDALONE) 42 | #include 43 | #include 44 | #include 45 | #include 46 | #else 47 | #include 48 | #include 49 | #include 50 | #include 51 | #endif 52 | 53 | #define _FUNCNAME strtoi 54 | #define __TYPE intmax_t 55 | #define __WRAPPED strtoimax 56 | 57 | #include "_strtoi.h" 58 | 59 | #ifdef _LIBC 60 | __weak_alias(strtoi, _strtoi) 61 | __weak_alias(strtoi_l, _strtoi_l) 62 | #endif 63 | -------------------------------------------------------------------------------- /src/pax/pat_rep.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: pat_rep.h,v 1.7 2008/02/24 20:42:46 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)pat_rep.h 8.1 (Berkeley) 5/31/93 36 | */ 37 | 38 | #include 39 | /* 40 | * data structure for storing user supplied replacement strings (-s) 41 | */ 42 | typedef struct replace { 43 | char *nstr; /* the new string we will substitute with */ 44 | regex_t rcmp; /* compiled regular expression used to match */ 45 | int flgs; /* print conversions? global in operation? */ 46 | #define PRNT 0x1 47 | #define GLOB 0x2 48 | #define RENM 0x4 49 | #define SYML 0x8 50 | struct replace *fow; /* pointer to next pattern */ 51 | } REPLACE; 52 | -------------------------------------------------------------------------------- /src/libnetbsd/strtou.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strtou.c,v 1.3 2019/11/28 12:33:23 roy Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2005 The DragonFly Project. All rights reserved. 5 | * Copyright (c) 2003 Citrus Project, 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * Created by Kamil Rytarowski, based on ID: 30 | * NetBSD: src/common/lib/libc/stdlib/strtoul.c,v 1.3 2008/08/20 19:58:34 oster Exp 31 | */ 32 | 33 | #if defined(HAVE_NBTOOL_CONFIG_H) && HAVE_NBTOOL_CONFIG_H 34 | #include "nbtool_config.h" 35 | #endif 36 | 37 | #if defined(_KERNEL) 38 | #include 39 | #include 40 | #include 41 | #elif defined(_STANDALONE) 42 | #include 43 | #include 44 | #include 45 | #include 46 | #else 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #endif 53 | 54 | #define _FUNCNAME strtou 55 | #define __TYPE uintmax_t 56 | #define __WRAPPED strtoumax 57 | 58 | #include "_strtoi.h" 59 | 60 | #ifdef _LIBC 61 | __weak_alias(strtou, _strtou) 62 | __weak_alias(strtou_l, _strtou_l) 63 | #endif 64 | -------------------------------------------------------------------------------- /src/libnetbsd/setprogname.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: setprogname.c,v 1.3 2003/07/26 19:24:44 salo Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2001 Christopher G. Demetriou 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. All advertising materials mentioning features or use of this software 16 | * must display the following acknowledgement: 17 | * This product includes software developed for the 18 | * NetBSD Project. See http://www.NetBSD.org/ for 19 | * information about NetBSD. 20 | * 4. The name of the author may not be used to endorse or promote products 21 | * derived from this software without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | * 34 | * <> 35 | */ 36 | 37 | /* In NetBSD, the program name is set by crt0. It can't be overridden. */ 38 | #undef REALLY_SET_PROGNAME 39 | 40 | #include 41 | #include 42 | 43 | #ifdef REALLY_SET_PROGNAME 44 | #include 45 | 46 | extern const char *__progname; 47 | #endif 48 | 49 | /*ARGSUSED*/ 50 | void 51 | setprogname(const char *progname) 52 | { 53 | 54 | #ifdef REALLY_SET_PROGNAME 55 | __progname = strrchr(progname, '/'); 56 | if (__progname == NULL) 57 | __progname = progname; 58 | else 59 | __progname++; 60 | #endif 61 | } 62 | -------------------------------------------------------------------------------- /src/libnetbsd/wcio.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: wcio.h,v 1.3 2003/01/18 11:30:00 thorpej Exp $ */ 2 | 3 | /*- 4 | * Copyright (c)2001 Citrus Project, 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * $Citrus$ 29 | */ 30 | 31 | #ifndef _WCIO_H_ 32 | #define _WCIO_H_ 33 | 34 | #include /* for mbstate_t and wchar_t */ 35 | 36 | /* minimal requirement of SUSv2 */ 37 | #define WCIO_UNGETWC_BUFSIZE 1 38 | 39 | struct wchar_io_data { 40 | mbstate_t wcio_mbstate_in; 41 | mbstate_t wcio_mbstate_out; 42 | 43 | wchar_t wcio_ungetwc_buf[WCIO_UNGETWC_BUFSIZE]; 44 | size_t wcio_ungetwc_inbuf; 45 | 46 | int wcio_mode; /* orientation */ 47 | }; 48 | 49 | #define _SET_ORIENTATION(fp, mode) \ 50 | do {\ 51 | struct wchar_io_data *_wcio = WCIO_GET(fp);\ 52 | if (_wcio && _wcio->wcio_mode == 0)\ 53 | _wcio->wcio_mode = (mode);\ 54 | } while (/*CONSTCOND*/0) 55 | 56 | /* 57 | * WCIO_FREE should be called by fclose 58 | */ 59 | #define WCIO_GET(fp) (&(_EXT(fp)->_wcio)) 60 | #define WCIO_FREE(fp) \ 61 | do {\ 62 | _EXT(fp)->_wcio.wcio_mode = 0;\ 63 | WCIO_FREEUB(fp);\ 64 | } while (/*CONSTCOND*/0) 65 | #define WCIO_FREEUB(fp) \ 66 | do {\ 67 | _EXT(fp)->_wcio.wcio_ungetwc_inbuf = 0;\ 68 | } while (/*CONSTCOND*/0) 69 | 70 | #endif /*_WCIO_H_*/ 71 | -------------------------------------------------------------------------------- /src/patch/mkpath.c: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: mkpath.c,v 1.2 2005/06/20 07:14:06 otto Exp $ 3 | * $DragonFly: src/usr.bin/patch/mkpath.c,v 1.1 2007/09/29 23:11:10 swildner Exp $ 4 | * $NetBSD: mkpath.c,v 1.1 2008/09/19 18:33:34 joerg Exp $ 5 | */ 6 | 7 | /* 8 | * Copyright (c) 1983, 1992, 1993 9 | * The Regents of the University of California. All rights reserved. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | int mkpath(char *); 44 | 45 | /* Code taken directly from mkdir(1). 46 | 47 | * mkpath -- create directories. 48 | * path - path 49 | */ 50 | int 51 | mkpath(char *path) 52 | { 53 | struct stat sb; 54 | char *slash; 55 | int done = 0; 56 | 57 | slash = path; 58 | 59 | while (!done) { 60 | slash += strspn(slash, "/"); 61 | slash += strcspn(slash, "/"); 62 | 63 | done = (*slash == '\0'); 64 | *slash = '\0'; 65 | 66 | if (stat(path, &sb)) { 67 | if (errno != ENOENT || (mkdir(path, 0777) && 68 | errno != EEXIST)) { 69 | warn("%s", path); 70 | return (-1); 71 | } 72 | } else if (!S_ISDIR(sb.st_mode)) { 73 | warnx("%s: %s", path, strerror(ENOTDIR)); 74 | return (-1); 75 | } 76 | 77 | *slash = '/'; 78 | } 79 | 80 | return (0); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /src/sed/extern.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: extern.h,v 1.20 2015/03/12 12:40:41 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Diomidis Spinellis. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Diomidis Spinellis of Imperial College, University of London. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)extern.h 8.1 (Berkeley) 6/6/93 36 | * $FreeBSD: head/usr.bin/sed/extern.h 170608 2007-06-12 12:05:24Z yar $ 37 | */ 38 | 39 | extern struct s_command *prog; 40 | extern struct s_appends *appends; 41 | extern regmatch_t *match; 42 | extern size_t maxnsub; 43 | extern u_long linenum; 44 | extern size_t appendnum; 45 | extern int aflag, eflag, nflag; 46 | extern const char *fname, *outfname; 47 | extern FILE *infile, *outfile; 48 | extern int rflags; /* regex flags to use */ 49 | 50 | void cfclose(struct s_command *, struct s_command *); 51 | void compile(void); 52 | void cspace(SPACE *, const char *, size_t, enum e_spflag); 53 | char *cu_fgets(char *, int, int *); 54 | int mf_fgets(SPACE *, enum e_spflag); 55 | int lastline(void); 56 | void process(void); 57 | void resetstate(void); 58 | char *strregerror(int, regex_t *); 59 | void *xmalloc(size_t); 60 | void *xrealloc(void *, size_t); 61 | void *xcalloc(size_t, size_t); 62 | -------------------------------------------------------------------------------- /src/libnetbsd/util.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: util.h,v 1.3 2012/11/04 13:08:57 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1995 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #ifndef _COMPAT_UTIL_H_ 33 | #define _COMPAT_UTIL_H_ 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | struct utmp50; 41 | struct utmpx50; 42 | struct passwd50; 43 | struct utmp; 44 | struct utmpx; 45 | struct passwd; 46 | 47 | void login(const struct utmp50 *); 48 | void loginx(const struct utmpx50 *); 49 | 50 | int32_t parsedate(const char *, const int32_t *, const int *); 51 | 52 | void pw_copy(int, int, struct passwd50 *, struct passwd50 *); 53 | int pw_copyx(int, int, struct passwd50 *, struct passwd50 *, 54 | char *, size_t); 55 | void pw_getpwconf(char *, size_t, const struct passwd50 *, 56 | const char *); 57 | 58 | void __login50(const struct utmp *); 59 | void __loginx50(const struct utmpx *); 60 | 61 | time_t __parsedate50(const char *, const time_t *, const int *); 62 | 63 | void __pw_copy50(int, int, struct passwd *, struct passwd *); 64 | int __pw_copyx50(int, int, struct passwd *, struct passwd *, 65 | char *, size_t); 66 | void __pw_getpwconf50(char *, size_t, const struct passwd *, 67 | const char *); 68 | #endif /* !_COMPAT_UTIL_H_ */ 69 | -------------------------------------------------------------------------------- /src/libnetbsd/strlcat.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strlcat.c,v 1.4 2013/01/23 07:57:27 matt Exp $ */ 2 | /* $OpenBSD: strlcat.c,v 1.10 2003/04/12 21:56:39 millert Exp $ */ 3 | 4 | /* 5 | * Copyright (c) 1998 Todd C. Miller 6 | * 7 | * Permission to use, copy, modify, and distribute this software for any 8 | * purpose with or without fee is hereby granted, provided that the above 9 | * copyright notice and this permission notice appear in all copies. 10 | * 11 | * THE SOFTWARE IS PROVIDED "AS IS" AND TODD C. MILLER DISCLAIMS ALL 12 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES 13 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL TODD C. MILLER BE LIABLE 14 | * FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 16 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 17 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 | */ 19 | 20 | #if !defined(_KERNEL) && !defined(_STANDALONE) 21 | #if HAVE_NBTOOL_CONFIG_H 22 | #include "nbtool_config.h" 23 | #endif 24 | 25 | #ifdef _LIBC 26 | #include "namespace.h" 27 | #endif 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | #ifdef _LIBC 34 | # ifdef __weak_alias 35 | __weak_alias(strlcat, _strlcat) 36 | # endif 37 | #endif 38 | 39 | #else 40 | #include 41 | #endif /* !_KERNEL && !_STANDALONE */ 42 | 43 | #if !HAVE_STRLCAT 44 | /* 45 | * Appends src to string dst of size siz (unlike strncat, siz is the 46 | * full size of dst, not space left). At most siz-1 characters 47 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). 48 | * Returns strlen(src) + MIN(siz, strlen(initial dst)). 49 | * If retval >= siz, truncation occurred. 50 | */ 51 | size_t 52 | strlcat(char *dst, const char *src, size_t siz) 53 | { 54 | #if 1 55 | char *d = dst; 56 | const char *s = src; 57 | size_t n = siz; 58 | size_t dlen; 59 | 60 | _DIAGASSERT(dst != NULL); 61 | _DIAGASSERT(src != NULL); 62 | 63 | /* Find the end of dst and adjust bytes left but don't go past end */ 64 | while (n-- != 0 && *d != '\0') 65 | d++; 66 | dlen = d - dst; 67 | n = siz - dlen; 68 | 69 | if (n == 0) 70 | return(dlen + strlen(s)); 71 | while (*s != '\0') { 72 | if (n != 1) { 73 | *d++ = *s; 74 | n--; 75 | } 76 | s++; 77 | } 78 | *d = '\0'; 79 | 80 | return(dlen + (s - src)); /* count does not include NUL */ 81 | #else 82 | _DIAGASSERT(dst != NULL); 83 | _DIAGASSERT(src != NULL); 84 | 85 | /* 86 | * Find length of string in dst (maxing out at siz). 87 | */ 88 | size_t dlen = strnlen(dst, siz); 89 | 90 | /* 91 | * Copy src into any remaining space in dst (truncating if needed). 92 | * Note strlcpy(dst, src, 0) returns strlen(src). 93 | */ 94 | return dlen + strlcpy(dst + dlen, src, siz - dlen); 95 | #endif 96 | } 97 | #endif 98 | -------------------------------------------------------------------------------- /src/pax/sel_subs.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: sel_subs.h,v 1.6 2003/10/13 07:41:22 agc Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)sel_subs.h 8.1 (Berkeley) 5/31/93 36 | */ 37 | 38 | /* 39 | * data structure for storing uid/grp selects (-U, -G non standard options) 40 | */ 41 | 42 | #define USR_TB_SZ 317 /* user selection table size */ 43 | #define GRP_TB_SZ 317 /* user selection table size */ 44 | 45 | typedef struct usrt { 46 | uid_t uid; 47 | struct usrt *fow; /* next uid */ 48 | } USRT; 49 | 50 | typedef struct grpt { 51 | gid_t gid; 52 | struct grpt *fow; /* next gid */ 53 | } GRPT; 54 | 55 | /* 56 | * data structure for storing user supplied time ranges (-T option) 57 | */ 58 | 59 | typedef struct time_rng { 60 | time_t low_time; /* lower inclusive time limit */ 61 | time_t high_time; /* higher inclusive time limit */ 62 | int flgs; /* option flags */ 63 | #define HASLOW 0x01 /* has lower time limit */ 64 | #define HASHIGH 0x02 /* has higher time limit */ 65 | #define CMPMTME 0x04 /* compare file modification time */ 66 | #define CMPCTME 0x08 /* compare inode change time */ 67 | #define CMPBOTH (CMPMTME|CMPCTME) /* compare inode and mod time */ 68 | struct time_rng *fow; /* next pattern */ 69 | } TIME_RNG; 70 | -------------------------------------------------------------------------------- /src/libnetbsd/reallocarr.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: reallocarr.c,v 1.5 2015/08/20 22:27:49 kamil Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2015 Joerg Sonnenberger . 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in 15 | * the documentation and/or other materials provided with the 16 | * distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 21 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 22 | * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 23 | * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, 24 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 25 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 26 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 28 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #endif 35 | 36 | #include 37 | /* Old POSIX has SIZE_MAX in limits.h */ 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #ifdef _LIBC 45 | #ifdef __weak_alias 46 | __weak_alias(reallocarr, _reallocarr) 47 | #endif 48 | #endif 49 | 50 | #define SQRT_SIZE_MAX (((size_t)1) << (sizeof(size_t) * CHAR_BIT / 2)) 51 | 52 | #if !HAVE_REALLOCARR 53 | int 54 | reallocarr(void *ptr, size_t number, size_t size) 55 | { 56 | int saved_errno, result; 57 | void *optr; 58 | void *nptr; 59 | 60 | saved_errno = errno; 61 | memcpy(&optr, ptr, sizeof(ptr)); 62 | if (number == 0 || size == 0) { 63 | free(optr); 64 | nptr = NULL; 65 | memcpy(ptr, &nptr, sizeof(ptr)); 66 | errno = saved_errno; 67 | return 0; 68 | } 69 | 70 | /* 71 | * Try to avoid division here. 72 | * 73 | * It isn't possible to overflow during multiplication if neither 74 | * operand uses any of the most significant half of the bits. 75 | */ 76 | if (__predict_false((number|size) >= SQRT_SIZE_MAX && 77 | number > SIZE_MAX / size)) { 78 | errno = saved_errno; 79 | return EOVERFLOW; 80 | } 81 | 82 | nptr = realloc(optr, number * size); 83 | if (__predict_false(nptr == NULL)) { 84 | result = errno; 85 | } else { 86 | result = 0; 87 | memcpy(ptr, &nptr, sizeof(ptr)); 88 | } 89 | errno = saved_errno; 90 | return result; 91 | } 92 | #endif 93 | -------------------------------------------------------------------------------- /src/libnetbsd/fileext.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: fileext.h,v 1.6 2010/01/11 20:39:29 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c)2001 Citrus Project, 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | * 28 | * $Citrus$ 29 | */ 30 | 31 | /* 32 | * file extension 33 | */ 34 | struct __sfileext { 35 | //struct __sbuf _ub; /* ungetc buffer */ 36 | struct wchar_io_data _wcio; /* wide char i/o status */ 37 | size_t _fgetstr_len; 38 | char *_fgetstr_buf; 39 | #ifdef _REENTRANT 40 | mutex_t _lock; /* Lock for FLOCKFILE/FUNLOCKFILE */ 41 | cond_t _lockcond; /* Condition variable for signalling lock releases */ 42 | thr_t _lockowner; /* The thread currently holding the lock */ 43 | int _lockcount; /* Count of recursive locks */ 44 | int _lockinternal; /* Flag of whether the lock is held inside stdio */ 45 | int _lockcancelstate; /* Stashed cancellation state on internal lock */ 46 | #endif 47 | }; 48 | 49 | #define _EXT(fp) ((struct __sfileext *)(void *)((fp)->_ext._base)) 50 | //#define _UB(fp) _EXT(fp)->_ub 51 | #ifdef _REENTRANT 52 | #define _LOCK(fp) (_EXT(fp)->_lock) 53 | #define _LOCKCOND(fp) (_EXT(fp)->_lockcond) 54 | #define _LOCKOWNER(fp) (_EXT(fp)->_lockowner) 55 | #define _LOCKCOUNT(fp) (_EXT(fp)->_lockcount) 56 | #define _LOCKINTERNAL(fp) (_EXT(fp)->_lockinternal) 57 | #define _LOCKCANCELSTATE(fp) (_EXT(fp)->_lockcancelstate) 58 | #define _FILEEXT_SETUP(f, fext) do { \ 59 | /* LINTED */(f)->_ext._base = (unsigned char *)(fext); \ 60 | (fext)->_fgetstr_len = 0; \ 61 | (fext)->_fgetstr_buf = NULL; \ 62 | mutex_init(&_LOCK(f), NULL); \ 63 | cond_init(&_LOCKCOND(f), 0, NULL); \ 64 | _LOCKOWNER(f) = NULL; \ 65 | _LOCKCOUNT(f) = 0; \ 66 | _LOCKINTERNAL(f) = 0; \ 67 | } while (/* CONSTCOND */ 0) 68 | #else 69 | #define _FILEEXT_SETUP(f, fext) do { \ 70 | /* LINTED */(f)->_ext._base = (unsigned char *)(fext); \ 71 | (fext)->_fgetstr_len = 0; \ 72 | (fext)->_fgetstr_buf = NULL; \ 73 | } while (/* CONSTCOND */ 0) 74 | #endif 75 | -------------------------------------------------------------------------------- /src/xargs/strnsubst.c: -------------------------------------------------------------------------------- 1 | /* $xMach: strnsubst.c,v 1.3 2002/02/23 02:10:24 jmallett Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 2002 J. Mallett. All rights reserved. 5 | * You may do whatever you want with this file as long as 6 | * the above copyright and this notice remain intact, along 7 | * with the following statement: 8 | * For the man who taught me vi, and who got too old, too young. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | void strnsubst(char **, const char *, const char *, size_t); 19 | 20 | /* 21 | * Replaces str with a string consisting of str with match replaced with 22 | * replstr as many times as can be done before the constructed string is 23 | * maxsize bytes large. It does not free the string pointed to by str, it 24 | * is up to the calling program to be sure that the original contents of 25 | * str as well as the new contents are handled in an appropriate manner. 26 | * If replstr is NULL, then that internally is changed to a nil-string, so 27 | * that we can still pretend to do somewhat meaningful substitution. 28 | * No value is returned. 29 | */ 30 | void 31 | strnsubst(char **str, const char *match, const char *replstr, size_t maxsize) 32 | { 33 | char *s1, *s2, *this; 34 | 35 | s1 = *str; 36 | if (s1 == NULL) 37 | return; 38 | /* 39 | * If maxsize is 0 then set it to to the length of s1, because we have 40 | * to duplicate s1. XXX we maybe should double-check whether the match 41 | * appears in s1. If it doesn't, then we also have to set the length 42 | * to the length of s1, to avoid modifying the argument. It may make 43 | * sense to check if maxsize is <= strlen(s1), because in that case we 44 | * want to return the unmodified string, too. 45 | */ 46 | if (maxsize == 0) { 47 | match = NULL; 48 | maxsize = strlen(s1) + 1; 49 | } 50 | s2 = calloc(maxsize, 1); 51 | if (s2 == NULL) 52 | err(1, "calloc"); 53 | 54 | if (replstr == NULL) 55 | replstr = ""; 56 | 57 | if (match == NULL || replstr == NULL || maxsize == strlen(s1)) { 58 | (void)strlcpy(s2, s1, maxsize); 59 | goto done; 60 | } 61 | 62 | for (;;) { 63 | this = strstr(s1, match); 64 | if (this == NULL) 65 | break; 66 | if ((strlen(s2) + strlen(s1) + strlen(replstr) - 67 | strlen(match) + 1) > maxsize) { 68 | (void)strlcat(s2, s1, maxsize); 69 | goto done; 70 | } 71 | (void)strncat(s2, s1, (uintptr_t)this - (uintptr_t)s1); 72 | (void)strcat(s2, replstr); 73 | s1 = this + strlen(match); 74 | } 75 | (void)strcat(s2, s1); 76 | done: 77 | *str = s2; 78 | return; 79 | } 80 | 81 | #ifdef TEST 82 | #include 83 | 84 | int 85 | main(void) 86 | { 87 | char *x, *y, *z, *za; 88 | 89 | x = "{}%$"; 90 | strnsubst(&x, "%$", "{} enpury!", 255); 91 | y = x; 92 | strnsubst(&y, "}{}", "ybir", 255); 93 | z = y; 94 | strnsubst(&z, "{", "v ", 255); 95 | za = z; 96 | strnsubst(&z, NULL, za, 255); 97 | if (strcmp(z, "v ybir enpury!") == 0) 98 | (void)printf("strnsubst() seems to work!\n"); 99 | else 100 | (void)printf("strnsubst() is broken.\n"); 101 | (void)printf("%s\n", z); 102 | free(x); 103 | free(y); 104 | free(z); 105 | free(za); 106 | return 0; 107 | } 108 | #endif 109 | -------------------------------------------------------------------------------- /src/sed/misc.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: misc.c,v 1.15 2014/06/26 02:14:32 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Diomidis Spinellis. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Diomidis Spinellis of Imperial College, University of London. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | */ 35 | 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | #include "defs.h" 46 | #include "extern.h" 47 | 48 | /* 49 | * malloc with result test 50 | */ 51 | void * 52 | xmalloc(size_t size) 53 | { 54 | void *p; 55 | 56 | if ((p = malloc(size)) == NULL) 57 | err(1, "malloc(%zu)", size); 58 | return p; 59 | } 60 | 61 | /* 62 | * realloc with result test 63 | */ 64 | void * 65 | xrealloc(void *p, size_t size) 66 | { 67 | if (p == NULL) /* Compatibility hack. */ 68 | return (xmalloc(size)); 69 | 70 | if ((p = realloc(p, size)) == NULL) 71 | err(1, "realloc(%zu)", size); 72 | return p; 73 | } 74 | 75 | /* 76 | * realloc with result test 77 | */ 78 | void * 79 | xcalloc(size_t c, size_t n) 80 | { 81 | void *p; 82 | 83 | if ((p = calloc(c, n)) == NULL) 84 | err(1, "calloc(%zu, %zu)", c, n); 85 | return p; 86 | } 87 | /* 88 | * Return a string for a regular expression error passed. This is overkill, 89 | * because of the silly semantics of regerror (we can never know the size of 90 | * the buffer). 91 | */ 92 | char * 93 | strregerror(int errcode, regex_t *preg) 94 | { 95 | char buf[1]; 96 | static char *oe; 97 | size_t s; 98 | 99 | if (oe != NULL) 100 | free(oe); 101 | s = regerror(errcode, preg, buf, 0); 102 | oe = xmalloc(s); 103 | (void)regerror(errcode, preg, oe, s); 104 | return (oe); 105 | } 106 | -------------------------------------------------------------------------------- /src/libnetbsd/pwcache.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: pwcache.h,v 1.5 2003/11/10 08:51:51 wiz Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)cache.h 8.1 (Berkeley) 5/31/93 36 | */ 37 | 38 | /* 39 | * Constants and data structures used to implement group and password file 40 | * caches. Traditional passwd/group cache routines perform quite poorly with 41 | * archives. The chances of hitting a valid lookup with an archive is quite a 42 | * bit worse than with files already resident on the file system. These misses 43 | * create a MAJOR performance cost. To address this problem, these routines 44 | * cache both hits and misses. 45 | * 46 | * NOTE: name lengths must be as large as those stored in ANY PROTOCOL and 47 | * as stored in the passwd and group files. CACHE SIZES MUST BE PRIME 48 | */ 49 | #define UNMLEN 32 /* >= user name found in any protocol */ 50 | #define GNMLEN 32 /* >= group name found in any protocol */ 51 | #define UID_SZ 317 /* size of uid to user_name cache */ 52 | #define UNM_SZ 317 /* size of user_name to uid cache */ 53 | #define GID_SZ 251 /* size of gid to group_name cache */ 54 | #define GNM_SZ 251 /* size of group_name to gid cache */ 55 | #define VALID 1 /* entry and name are valid */ 56 | #define INVALID 2 /* entry valid, name NOT valid */ 57 | 58 | /* 59 | * Node structures used in the user, group, uid, and gid caches. 60 | */ 61 | 62 | typedef struct uidc { 63 | int valid; /* is this a valid or a miss entry */ 64 | char name[UNMLEN]; /* uid name */ 65 | uid_t uid; /* cached uid */ 66 | } UIDC; 67 | 68 | typedef struct gidc { 69 | int valid; /* is this a valid or a miss entry */ 70 | char name[GNMLEN]; /* gid name */ 71 | gid_t gid; /* cached gid */ 72 | } GIDC; 73 | -------------------------------------------------------------------------------- /include/vis.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: vis.h,v 1.15 2015/07/20 01:52:27 millert Exp $ */ 2 | /* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */ 3 | 4 | /*- 5 | * Copyright (c) 1990 The Regents of the University of California. 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | * 32 | * @(#)vis.h 5.9 (Berkeley) 4/3/91 33 | */ 34 | 35 | #ifndef _VIS_H_ 36 | #define _VIS_H_ 37 | 38 | /* 39 | * to select alternate encoding format 40 | */ 41 | #define VIS_OCTAL 0x01 /* use octal \ddd format */ 42 | #define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ 43 | 44 | /* 45 | * to alter set of characters encoded (default is to encode all 46 | * non-graphic except space, tab, and newline). 47 | */ 48 | #define VIS_SP 0x04 /* also encode space */ 49 | #define VIS_TAB 0x08 /* also encode tab */ 50 | #define VIS_NL 0x10 /* also encode newline */ 51 | #define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) 52 | #define VIS_SAFE 0x20 /* only encode "unsafe" characters */ 53 | #define VIS_DQ 0x200 /* backslash-escape double quotes */ 54 | #define VIS_ALL 0x400 /* encode all characters */ 55 | 56 | /* 57 | * other 58 | */ 59 | #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ 60 | #define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */ 61 | 62 | /* 63 | * unvis return codes 64 | */ 65 | #define UNVIS_VALID 1 /* character valid */ 66 | #define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */ 67 | #define UNVIS_NOCHAR 3 /* valid sequence, no character produced */ 68 | #define UNVIS_SYNBAD -1 /* unrecognized escape sequence */ 69 | #define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */ 70 | 71 | /* 72 | * unvis flags 73 | */ 74 | #define UNVIS_END 1 /* no more characters */ 75 | 76 | #include 77 | 78 | __BEGIN_DECLS 79 | char *vis(char *, int, int, int); 80 | int strvis(char *, const char *, int); 81 | int stravis(char **, const char *, int); 82 | int strnvis(char *, const char *, size_t, int) 83 | __attribute__ ((__bounded__(__string__,1,3))); 84 | int strvisx(char *, const char *, size_t, int) 85 | __attribute__ ((__bounded__(__string__,1,3))); 86 | int strunvis(char *, const char *); 87 | int unvis(char *, char, int *, int); 88 | ssize_t strnunvis(char *, const char *, size_t) 89 | __attribute__ ((__bounded__(__string__,1,3))); 90 | 91 | __END_DECLS 92 | 93 | #endif /* !_VIS_H_ */ 94 | -------------------------------------------------------------------------------- /src/patch/common.h: -------------------------------------------------------------------------------- 1 | /* 2 | * $OpenBSD: common.h,v 1.26 2006/03/11 19:41:30 otto Exp $ 3 | * $DragonFly: src/usr.bin/patch/common.h,v 1.5 2008/08/10 23:50:12 joerg Exp $ 4 | * $NetBSD: common.h,v 1.21 2015/07/24 18:56:44 christos Exp $ 5 | */ 6 | 7 | /* 8 | * patch - a program to apply diffs to original files 9 | * 10 | * Copyright 1986, Larry Wall 11 | * 12 | * Redistribution and use in source and binary forms, with or without 13 | * modification, are permitted provided that the following condition is met: 14 | * 1. Redistributions of source code must retain the above copyright notice, 15 | * this condition and the following disclaimer. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 21 | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * -C option added in 1998, original code by Marc Espie, based on FreeBSD 30 | * behaviour 31 | */ 32 | 33 | #include 34 | 35 | #include 36 | #include 37 | 38 | #define DEBUGGING 39 | 40 | /* constants */ 41 | 42 | #define MAXHUNKSIZE 100000 /* is this enough lines? */ 43 | #define INITHUNKMAX 125 /* initial dynamic allocation size */ 44 | #define MAXLINELEN 8192 45 | #define BUFFERSIZE 1024 46 | #define LINENUM_MAX LONG_MAX 47 | 48 | #define SCCSPREFIX "s." 49 | #define GET "get -e %s" 50 | #define SCCSDIFF "get -p %s | diff - %s >/dev/null" 51 | 52 | #define RCSSUFFIX ",v" 53 | #define CHECKOUT "/usr/bin/co" 54 | #define RCSDIFF "/usr/bin/rcsdiff" 55 | 56 | #define ORIGEXT ".orig" 57 | #define REJEXT ".rej" 58 | 59 | /* handy definitions */ 60 | 61 | #define strNE(s1,s2) (strcmp(s1, s2)) 62 | #define strEQ(s1,s2) (!strcmp(s1, s2)) 63 | #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) 64 | #define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) 65 | 66 | /* typedefs */ 67 | 68 | typedef long LINENUM; /* must be signed */ 69 | 70 | /* globals */ 71 | 72 | extern mode_t filemode; 73 | 74 | extern char buf[MAXLINELEN];/* general purpose buffer */ 75 | extern size_t buf_len; 76 | 77 | extern bool using_plan_a; /* try to keep everything in memory */ 78 | extern bool out_of_mem; /* ran out of memory in plan a */ 79 | 80 | #define MAXFILEC 2 81 | 82 | extern char *filearg[MAXFILEC]; 83 | extern bool ok_to_create_file; 84 | extern char *outname; 85 | extern char *origprae; 86 | 87 | extern char *TMPOUTNAME; 88 | extern char *TMPINNAME; 89 | extern char *TMPREJNAME; 90 | extern char *TMPPATNAME; 91 | extern bool toutkeep; 92 | extern bool trejkeep; 93 | 94 | #ifdef DEBUGGING 95 | extern int debug; 96 | #endif 97 | 98 | extern bool force; 99 | extern bool batch; 100 | extern bool verbose; 101 | extern bool reverse; 102 | extern bool noreverse; 103 | extern bool skip_rest_of_patch; 104 | extern int strippath; 105 | extern bool canonicalize; 106 | /* TRUE if -C was specified on command line. */ 107 | extern bool check_only; 108 | extern bool warn_on_invalid_line; 109 | extern bool last_line_missing_eol; 110 | 111 | 112 | #define CONTEXT_DIFF 1 113 | #define NORMAL_DIFF 2 114 | #define ED_DIFF 3 115 | #define NEW_CONTEXT_DIFF 4 116 | #define UNI_DIFF 5 117 | 118 | extern int diff_type; 119 | extern char *revision; /* prerequisite revision, if any */ 120 | extern LINENUM input_lines; /* how long is input file in lines */ 121 | 122 | extern int posix; 123 | 124 | -------------------------------------------------------------------------------- /src/pax/dumptar.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: dumptar.c,v 1.3 2016/05/30 17:34:35 dholland Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2004 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Christos Zoulas. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #include "tar.h" 43 | 44 | #define ussum(a) 1 45 | 46 | /* 47 | * Ensure null termination. 48 | */ 49 | static char * 50 | buf(const char *p, size_t s) 51 | { 52 | static char buf[1024]; 53 | 54 | assert(s < sizeof(buf)); 55 | memcpy(buf, p, s); 56 | buf[s] = '\0'; 57 | return buf; 58 | } 59 | 60 | static int 61 | intarg(const char *p, size_t s) 62 | { 63 | char *ep, *b = buf(p, s); 64 | int r = (int)strtol(b, &ep, 8); 65 | return r; 66 | } 67 | 68 | static int 69 | usdump(void *p) 70 | { 71 | HD_USTAR *t = p; 72 | int size = intarg(t->size, sizeof(t->size)); 73 | size = ((size + 511) / 512) * 512 + 512; 74 | 75 | (void)fprintf(stdout, "*****\n"); 76 | #define PR(a) \ 77 | (void)fprintf(stdout, #a "=%s\n", buf(t->a, sizeof(t->a))); 78 | #define IPR(a) \ 79 | (void)fprintf(stdout, #a "=%d\n", intarg(t->a, sizeof(t->a))); 80 | #define OPR(a) \ 81 | (void)fprintf(stdout, #a "=%o\n", intarg(t->a, sizeof(t->a))); 82 | PR(name); 83 | OPR(mode); 84 | IPR(uid); 85 | IPR(gid); 86 | IPR(size); 87 | OPR(mtime); 88 | OPR(chksum); 89 | (void)fprintf(stdout, "typeflag=%c\n", t->typeflag); 90 | PR(linkname); 91 | PR(magic); 92 | PR(version); 93 | PR(uname); 94 | PR(gname); 95 | OPR(devmajor); 96 | OPR(devminor); 97 | PR(prefix); 98 | return size; 99 | } 100 | 101 | int 102 | main(int argc, char *argv[]) 103 | { 104 | int fd; 105 | struct stat st; 106 | char *p, *ep; 107 | 108 | if (argc != 2) { 109 | (void)fprintf(stderr, "Usage: %s \n", getprogname()); 110 | return 1; 111 | } 112 | 113 | if ((fd = open(argv[1], O_RDONLY)) == -1) 114 | err(1, "Cannot open `%s'", argv[1]); 115 | 116 | if (fstat(fd, &st) == -1) 117 | err(1, "Cannot fstat `%s'", argv[1]); 118 | 119 | if ((p = mmap(NULL, (size_t)st.st_size, PROT_READ, 120 | MAP_FILE|MAP_PRIVATE, fd, (off_t)0)) == MAP_FAILED) 121 | err(1, "Cannot mmap `%s'", argv[1]); 122 | (void)close(fd); 123 | 124 | ep = (char *)p + (size_t)st.st_size; 125 | 126 | for (; p < ep + sizeof(HD_USTAR);) { 127 | if (ussum(p)) 128 | p += usdump(p); 129 | } 130 | return 0; 131 | } 132 | -------------------------------------------------------------------------------- /src/libnetbsd/raise_default_signal.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: raise_default_signal.c,v 1.3 2008/04/28 20:23:03 martin Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2007 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Luke Mewburn. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | 42 | #if ! HAVE_RAISE_DEFAULT_SIGNAL 43 | /* 44 | * raise_default_signal sig 45 | * Raise the default signal handler for sig, by 46 | * - block all signals 47 | * - set the signal handler to SIG_DFL 48 | * - raise the signal 49 | * - unblock the signal to deliver it 50 | * 51 | * The original signal mask and signal handler is restored on exit 52 | * (whether successful or not). 53 | * 54 | * Returns 0 on success, or -1 on failure with errno set to 55 | * on of the values for sigemptyset(), sigaddset(), sigprocmask(), 56 | * sigaction(), or raise(). 57 | */ 58 | int 59 | raise_default_signal(int sig) 60 | { 61 | struct sigaction origact, act; 62 | sigset_t origmask, fullmask, mask; 63 | int retval, oerrno; 64 | 65 | retval = -1; 66 | 67 | /* Setup data structures */ 68 | /* XXX memset(3) isn't async-safe according to signal(7) */ 69 | (void)memset(&act, 0, sizeof(act)); 70 | act.sa_handler = SIG_DFL; 71 | act.sa_flags = 0; 72 | if ((sigemptyset(&act.sa_mask) == -1) || 73 | (sigfillset(&fullmask) == -1) || 74 | (sigemptyset(&mask) == -1) || 75 | (sigaddset(&mask, sig) == -1)) 76 | goto restore_none; 77 | 78 | /* Block all signals */ 79 | if (sigprocmask(SIG_BLOCK, &fullmask, &origmask) == -1) 80 | goto restore_none; 81 | /* (use 'goto restore_mask' to restore state) */ 82 | 83 | /* Enable the SIG_DFL handler */ 84 | if (sigaction(sig, &act, &origact) == -1) 85 | goto restore_mask; 86 | /* (use 'goto restore_act' to restore state) */ 87 | 88 | /* Raise the signal, and unblock the signal to deliver it */ 89 | if ((raise(sig) == -1) || 90 | (sigprocmask(SIG_UNBLOCK, &mask, NULL) == -1)) 91 | goto restore_act; 92 | 93 | /* Flag successful raise() */ 94 | retval = 0; 95 | 96 | /* Restore the original handler */ 97 | restore_act: 98 | oerrno = errno; 99 | (void)sigaction(sig, &origact, NULL); 100 | errno = oerrno; 101 | 102 | /* Restore the original mask */ 103 | restore_mask: 104 | oerrno = errno; 105 | (void)sigprocmask(SIG_SETMASK, &origmask, NULL); 106 | errno = oerrno; 107 | 108 | restore_none: 109 | return retval; 110 | } 111 | 112 | #endif /* ! HAVE_RAISE_DEFAULT_SIGNAL */ 113 | -------------------------------------------------------------------------------- /src/find/ls.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: ls.c,v 1.21 2011/08/31 16:24:57 plunky Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1989, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | 49 | #include "find.h" 50 | 51 | /* Derived from the print routines in the ls(1) source code. */ 52 | 53 | static void printlink(char *); 54 | static void printtime(time_t); 55 | 56 | void 57 | printlong(char *name, /* filename to print */ 58 | char *accpath, /* current valid path to filename */ 59 | struct stat *sb) /* stat buffer */ 60 | { 61 | char modep[15]; 62 | 63 | (void)printf("%7lu %6lld ", (u_long)sb->st_ino, 64 | (long long)sb->st_blocks); 65 | (void)strmode(sb->st_mode, modep); 66 | (void)printf("%s %3lu %-*s %-*s ", modep, (unsigned long)sb->st_nlink, 67 | LOGIN_NAME_MAX, user_from_uid(sb->st_uid, 0), LOGIN_NAME_MAX, 68 | group_from_gid(sb->st_gid, 0)); 69 | 70 | if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) 71 | (void)printf("%3llu,%5llu ", 72 | (unsigned long long)major(sb->st_rdev), 73 | (unsigned long long)minor(sb->st_rdev)); 74 | else 75 | (void)printf("%9lld ", (long long)sb->st_size); 76 | printtime(sb->st_mtime); 77 | (void)printf("%s", name); 78 | if (S_ISLNK(sb->st_mode)) 79 | printlink(accpath); 80 | (void)putchar('\n'); 81 | } 82 | 83 | static void 84 | printtime(time_t ftime) 85 | { 86 | int i; 87 | char *longstring; 88 | 89 | longstring = ctime(&ftime); 90 | for (i = 4; i < 11; ++i) 91 | (void)putchar(longstring[i]); 92 | 93 | #define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) 94 | if (ftime + SIXMONTHS > time(NULL)) 95 | for (i = 11; i < 16; ++i) 96 | (void)putchar(longstring[i]); 97 | else { 98 | (void)putchar(' '); 99 | for (i = 20; i < 24; ++i) 100 | (void)putchar(longstring[i]); 101 | } 102 | (void)putchar(' '); 103 | } 104 | 105 | static void 106 | printlink(char *name) 107 | { 108 | int lnklen; 109 | char path[MAXPATHLEN + 1]; 110 | 111 | if ((lnklen = readlink(name, path, sizeof(path) - 1)) == -1) { 112 | warn("%s", name); 113 | return; 114 | } 115 | path[lnklen] = '\0'; 116 | (void)printf(" -> %s", path); 117 | } 118 | -------------------------------------------------------------------------------- /src/libnetbsd/setlocale_local.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: setlocale_local.h,v 1.17 2016/04/29 16:26:48 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c)2008 Citrus Project, 5 | * All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 | * SUCH DAMAGE. 27 | */ 28 | 29 | #ifndef _SETLOCALE_LOCAL_H_ 30 | #define _SETLOCALE_LOCAL_H_ 31 | 32 | #include 33 | #include 34 | 35 | #include "ctype_local.h" 36 | 37 | #define _LC_LAST 6 38 | #define _LOCALENAME_LEN_MAX 33 39 | 40 | #define _C_LOCALE "C" 41 | #define _POSIX_LOCALE "POSIX" 42 | 43 | extern const char *_PathLocale; 44 | #define _LOCALE_ALIAS_NAME "locale.alias" 45 | 46 | #ifndef __GLIBC__ 47 | #if defined(__cplusplus) 48 | #define __BEGIN_EXTERN_C extern "C" { 49 | #define __END_EXTERN_C } 50 | #else 51 | #define __BEGIN_EXTERN_C 52 | #define __END_EXTERN_C 53 | #endif 54 | 55 | #define __BEGIN_DECLS __BEGIN_EXTERN_C 56 | #define __END_DECLS __END_EXTERN_C 57 | #endif 58 | 59 | typedef void *_locale_part_t; 60 | 61 | struct _locale_cache_t { 62 | SLIST_ENTRY(_locale_cache_t) cache_link; 63 | const char *monetary_name; 64 | const char *numeric_name; 65 | struct lconv ldata; 66 | }; 67 | 68 | struct _locale { 69 | const struct _locale_cache_t *cache; 70 | char query[_LOCALENAME_LEN_MAX * (_LC_LAST - 1)]; 71 | const char *part_name[_LC_LAST]; 72 | _locale_part_t part_impl[_LC_LAST]; 73 | }; 74 | 75 | typedef const char *(*_locale_set_t)(const char * __restrict, 76 | struct _locale * __restrict); 77 | 78 | __BEGIN_DECLS 79 | _locale_set_t _find_category(int); 80 | const char *_get_locale_env(const char *); 81 | char *__setlocale(int, const char *); 82 | 83 | const char *_generic_LC_ALL_setlocale( 84 | const char * __restrict, struct _locale * __restrict); 85 | const char *_dummy_LC_COLLATE_setlocale( 86 | const char * __restrict, struct _locale * __restrict); 87 | const char *_citrus_LC_CTYPE_setlocale( 88 | const char * __restrict, struct _locale * __restrict); 89 | const char *_citrus_LC_MONETARY_setlocale( 90 | const char * __restrict, struct _locale * __restrict); 91 | const char *_citrus_LC_NUMERIC_setlocale( 92 | const char * __restrict, struct _locale * __restrict); 93 | const char *_citrus_LC_TIME_setlocale( 94 | const char * __restrict, struct _locale * __restrict); 95 | const char *_citrus_LC_MESSAGES_setlocale( 96 | const char * __restrict, struct _locale * __restrict); 97 | 98 | int _setlocale_cache(locale_t, struct _locale_cache_t *); 99 | __END_DECLS 100 | 101 | #ifdef _LIBC 102 | extern __dso_hidden const struct _locale_cache_t _C_cache; 103 | 104 | static __inline struct _locale * 105 | _current_locale(void) 106 | { 107 | return &_lc_global_locale; 108 | } 109 | #endif 110 | 111 | extern size_t __mb_len_max_runtime; 112 | 113 | #endif /*_SETLOCALE_LOCAL_H_*/ 114 | -------------------------------------------------------------------------------- /difference/patch.patch: -------------------------------------------------------------------------------- 1 | diff -ruN ../../netbsd/usr.bin/patch/backupfile.c patch/backupfile.c 2 | --- ../../netbsd/usr.bin/patch/backupfile.c 2020-04-10 23:58:13.588335999 +0900 3 | +++ patch/backupfile.c 2020-04-12 00:30:03.615410351 +0900 4 | @@ -21,9 +21,6 @@ 5 | * David MacKenzie . Some algorithms adapted from GNU Emacs. 6 | */ 7 | 8 | -#include 9 | -__RCSID("$NetBSD: backupfile.c,v 1.15 2014/04/11 17:30:03 christos Exp $"); 10 | - 11 | #include 12 | #include 13 | #include 14 | @@ -31,6 +28,7 @@ 15 | #include 16 | #include 17 | #include 18 | +#include 19 | 20 | #include "backupfile.h" 21 | 22 | @@ -114,7 +112,7 @@ 23 | file_name_length = strlen(file); 24 | 25 | while ((dp = readdir(dirp)) != NULL) { 26 | - if (dp->d_namlen <= file_name_length) 27 | + if (D_NAMLEN(dp) <= file_name_length) 28 | continue; 29 | 30 | this_version = version_number(file, dp->d_name, file_name_length); 31 | diff -ruN ../../netbsd/usr.bin/patch/inp.c patch/inp.c 32 | --- ../../netbsd/usr.bin/patch/inp.c 2020-04-10 23:58:13.589335999 +0900 33 | +++ patch/inp.c 2020-04-12 00:27:15.297394886 +0900 34 | @@ -30,9 +30,6 @@ 35 | * behaviour 36 | */ 37 | 38 | -#include 39 | -__RCSID("$NetBSD: inp.c,v 1.26 2018/06/18 18:33:31 christos Exp $"); 40 | - 41 | #include 42 | #include 43 | #include 44 | @@ -49,6 +46,7 @@ 45 | #include 46 | #include 47 | #include 48 | +#include 49 | 50 | #include "common.h" 51 | #include "util.h" 52 | diff -ruN ../../netbsd/usr.bin/patch/mkpath.c patch/mkpath.c 53 | --- ../../netbsd/usr.bin/patch/mkpath.c 2020-04-10 23:58:13.589335999 +0900 54 | +++ patch/mkpath.c 2020-04-12 00:26:53.033392840 +0900 55 | @@ -33,14 +33,12 @@ 56 | * SUCH DAMAGE. 57 | */ 58 | 59 | -#include 60 | -__RCSID("$NetBSD: mkpath.c,v 1.1 2008/09/19 18:33:34 joerg Exp $"); 61 | - 62 | #include 63 | #include 64 | #include 65 | #include 66 | #include 67 | +#include 68 | 69 | int mkpath(char *); 70 | 71 | diff -ruN ../../netbsd/usr.bin/patch/patch.c patch/patch.c 72 | --- ../../netbsd/usr.bin/patch/patch.c 2020-04-10 23:58:13.589335999 +0900 73 | +++ patch/patch.c 2020-04-12 00:30:50.910414696 +0900 74 | @@ -30,9 +30,6 @@ 75 | * behaviour 76 | */ 77 | 78 | -#include 79 | -__RCSID("$NetBSD: patch.c,v 1.29 2011/09/06 18:25:14 joerg Exp $"); 80 | - 81 | #include 82 | #include 83 | 84 | @@ -43,6 +40,7 @@ 85 | #include 86 | #include 87 | #include 88 | +#include 89 | 90 | #include "common.h" 91 | #include "util.h" 92 | @@ -489,7 +487,11 @@ 93 | Argv_last = Argv; 94 | if (!Argc) 95 | return; 96 | +#ifdef __GLIBC__ 97 | + optind = 0; 98 | +#else 99 | optreset = optind = 1; 100 | +#endif 101 | while ((ch = getopt_long(Argc, Argv, options, longopts, NULL)) != -1) { 102 | switch (ch) { 103 | case 'b': 104 | diff -ruN ../../netbsd/usr.bin/patch/pch.c patch/pch.c 105 | --- ../../netbsd/usr.bin/patch/pch.c 2020-04-10 23:58:13.590335999 +0900 106 | +++ patch/pch.c 2020-04-12 00:27:00.453393522 +0900 107 | @@ -30,9 +30,6 @@ 108 | * behaviour 109 | */ 110 | 111 | -#include 112 | -__RCSID("$NetBSD: pch.c,v 1.30 2018/06/18 18:33:31 christos Exp $"); 113 | - 114 | #include 115 | #include 116 | 117 | @@ -43,6 +40,7 @@ 118 | #include 119 | #include 120 | #include 121 | +#include 122 | 123 | #include "common.h" 124 | #include "util.h" 125 | diff -ruN ../../netbsd/usr.bin/patch/util.c patch/util.c 126 | --- ../../netbsd/usr.bin/patch/util.c 2020-04-10 23:58:13.590335999 +0900 127 | +++ patch/util.c 2020-04-12 00:27:09.707394372 +0900 128 | @@ -30,9 +30,6 @@ 129 | * behaviour 130 | */ 131 | 132 | -#include 133 | -__RCSID("$NetBSD: util.c,v 1.28 2018/06/18 18:33:31 christos Exp $"); 134 | - 135 | #include 136 | #include 137 | 138 | @@ -46,6 +43,7 @@ 139 | #include 140 | #include 141 | #include 142 | +#include 143 | 144 | #include "common.h" 145 | #include "util.h" 146 | -------------------------------------------------------------------------------- /src/find/misc.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: misc.c,v 1.14 2006/10/11 19:51:10 apb Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Cimarron D. Taylor of the University of California, Berkeley. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the University nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #include "find.h" 47 | 48 | /* 49 | * brace_subst -- 50 | * Replace occurrences of {} in orig with path, and place it in a malloced 51 | * area of memory set in store. 52 | */ 53 | void 54 | brace_subst(char *orig, char **store, char *path, int *len) 55 | { 56 | int nlen, plen, rest; 57 | char ch, *p, *ostore; 58 | 59 | plen = strlen(path); 60 | for (p = *store; (ch = *orig) != '\0'; ++orig) 61 | if (ch == '{' && orig[1] == '}') { 62 | /* Length of string after the {}. */ 63 | rest = strlen(&orig[2]); 64 | 65 | nlen = *len; 66 | while ((p - *store) + plen + rest + 1 > nlen) 67 | nlen *= 2; 68 | 69 | if (nlen > *len) { 70 | ostore = *store; 71 | if ((*store = realloc(ostore, nlen)) == NULL) 72 | err(1, "realloc"); 73 | *len = nlen; 74 | p += *store - ostore; /* Relocate. */ 75 | } 76 | memmove(p, path, plen); 77 | p += plen; 78 | ++orig; 79 | } else 80 | *p++ = ch; 81 | *p = '\0'; 82 | } 83 | 84 | /* 85 | * queryuser -- 86 | * print a message to standard error and then read input from standard 87 | * input. If the input is 'y' then 1 is returned. 88 | */ 89 | int 90 | queryuser(char **argv) 91 | { 92 | int ch, first, nl; 93 | 94 | (void)fprintf(stderr, "\"%s", *argv); 95 | while (*++argv) 96 | (void)fprintf(stderr, " %s", *argv); 97 | (void)fprintf(stderr, "\"? "); 98 | (void)fflush(stderr); 99 | 100 | first = ch = getchar(); 101 | for (nl = 0;;) { 102 | if (ch == '\n') { 103 | nl = 1; 104 | break; 105 | } 106 | if (ch == EOF) 107 | break; 108 | ch = getchar(); 109 | } 110 | 111 | if (!nl) { 112 | (void)fprintf(stderr, "\n"); 113 | (void)fflush(stderr); 114 | } 115 | return (first == 'y'); 116 | } 117 | 118 | /* 119 | * show_path -- 120 | * called on SIGINFO 121 | */ 122 | /* ARGSUSED */ 123 | void 124 | show_path(int sig) 125 | { 126 | extern FTSENT *g_entry; 127 | int errno_bak; 128 | 129 | if (g_entry == NULL) { 130 | /* 131 | * not initialized yet. 132 | * assumption: pointer assignment is atomic. 133 | */ 134 | return; 135 | } 136 | 137 | errno_bak = errno; 138 | write(STDERR_FILENO, "find path: ", 11); 139 | write(STDERR_FILENO, g_entry->fts_path, g_entry->fts_pathlen); 140 | write(STDERR_FILENO, "\n", 1); 141 | errno = errno_bak; 142 | } 143 | -------------------------------------------------------------------------------- /src/find/extern.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: extern.h,v 1.29 2016/06/13 00:04:40 pgoyette Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1991, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * from: @(#)extern.h 8.3 (Berkeley) 4/16/94 32 | */ 33 | 34 | //#include 35 | 36 | void brace_subst(char *, char **, char *, int *); 37 | PLAN *find_create(char ***); 38 | int find_execute(PLAN *, char **); 39 | PLAN *find_formplan(char **); 40 | int find_traverse(PLAN *, int (*)(PLAN *, void *), void *); 41 | int f_expr(PLAN *, FTSENT *); 42 | PLAN *not_squish(PLAN *); 43 | PLAN *or_squish(PLAN *); 44 | PLAN *paren_squish(PLAN *); 45 | int plan_cleanup(PLAN *, void *); 46 | void printlong(char *, char *, struct stat *); 47 | int queryuser(char **); 48 | void show_path(int); 49 | 50 | PLAN *c_amin(char ***, int, char *); 51 | PLAN *c_anewer(char ***, int, char *); 52 | PLAN *c_asince(char ***, int, char *); 53 | PLAN *c_atime(char ***, int, char *); 54 | PLAN *c_cmin(char ***, int, char *); 55 | PLAN *c_cnewer(char ***, int, char *); 56 | PLAN *c_csince(char ***, int, char *); 57 | PLAN *c_ctime(char ***, int, char *); 58 | PLAN *c_delete(char ***, int, char *); 59 | PLAN *c_depth(char ***, int, char *); 60 | PLAN *c_empty(char ***, int, char *); 61 | PLAN *c_exec(char ***, int, char *); 62 | PLAN *c_execdir(char ***, int, char *); 63 | PLAN *c_exit(char ***, int, char *); 64 | PLAN *c_false(char ***, int, char *); 65 | PLAN *c_flags(char ***, int, char *); 66 | PLAN *c_follow(char ***, int, char *); 67 | PLAN *c_fprint(char ***, int, char *); 68 | PLAN *c_fstype(char ***, int, char *); 69 | PLAN *c_group(char ***, int, char *); 70 | PLAN *c_iname(char ***, int, char *); 71 | PLAN *c_inum(char ***, int, char *); 72 | PLAN *c_iregex(char ***, int, char *); 73 | PLAN *c_links(char ***, int, char *); 74 | PLAN *c_ls(char ***, int, char *); 75 | PLAN *c_maxdepth(char ***, int, char *); 76 | PLAN *c_mindepth(char ***, int, char *); 77 | PLAN *c_mmin(char ***, int, char *); 78 | PLAN *c_mtime(char ***, int, char *); 79 | PLAN *c_name(char ***, int, char *); 80 | PLAN *c_newer(char ***, int, char *); 81 | PLAN *c_nogroup(char ***, int, char *); 82 | PLAN *c_nouser(char ***, int, char *); 83 | PLAN *c_path(char ***, int, char *); 84 | PLAN *c_perm(char ***, int, char *); 85 | PLAN *c_print(char ***, int, char *); 86 | PLAN *c_print0(char ***, int, char *); 87 | PLAN *c_printx(char ***, int, char *); 88 | PLAN *c_prune(char ***, int, char *); 89 | PLAN *c_regex(char ***, int, char *); 90 | PLAN *c_since(char ***, int, char *); 91 | PLAN *c_size(char ***, int, char *); 92 | PLAN *c_type(char ***, int, char *); 93 | PLAN *c_user(char ***, int, char *); 94 | PLAN *c_xdev(char ***, int, char *); 95 | PLAN *c_openparen(char ***, int, char *); 96 | PLAN *c_closeparen(char ***, int, char *); 97 | PLAN *c_not(char ***, int, char *); 98 | PLAN *c_or(char ***, int, char *); 99 | PLAN *c_null(char ***, int, char *); 100 | 101 | extern int ftsoptions, isdeprecated, isdepth, isoutput, issort, isxargs, 102 | regcomp_flags; 103 | -------------------------------------------------------------------------------- /src/libnetbsd/strmode.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: strmode.c,v 1.19 2012/06/25 22:32:46 abs Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | 42 | #include 43 | 44 | #if !HAVE_STRMODE 45 | void 46 | strmode(mode_t mode, char *p) 47 | { 48 | 49 | _DIAGASSERT(p != NULL); 50 | 51 | /* print type */ 52 | switch (mode & S_IFMT) { 53 | case S_IFDIR: /* directory */ 54 | *p++ = 'd'; 55 | break; 56 | case S_IFCHR: /* character special */ 57 | *p++ = 'c'; 58 | break; 59 | case S_IFBLK: /* block special */ 60 | *p++ = 'b'; 61 | break; 62 | case S_IFREG: /* regular */ 63 | #ifdef S_ARCH2 64 | if ((mode & S_ARCH2) != 0) { 65 | *p++ = 'A'; 66 | } else if ((mode & S_ARCH1) != 0) { 67 | *p++ = 'a'; 68 | } else { 69 | #endif 70 | *p++ = '-'; 71 | #ifdef S_ARCH2 72 | } 73 | #endif 74 | break; 75 | case S_IFLNK: /* symbolic link */ 76 | *p++ = 'l'; 77 | break; 78 | #ifdef S_IFSOCK 79 | case S_IFSOCK: /* socket */ 80 | *p++ = 's'; 81 | break; 82 | #endif 83 | #ifdef S_IFIFO 84 | case S_IFIFO: /* fifo */ 85 | *p++ = 'p'; 86 | break; 87 | #endif 88 | #ifdef S_IFWHT 89 | case S_IFWHT: /* whiteout */ 90 | *p++ = 'w'; 91 | break; 92 | #endif 93 | #ifdef S_IFDOOR 94 | case S_IFDOOR: /* door */ 95 | *p++ = 'D'; 96 | break; 97 | #endif 98 | default: /* unknown */ 99 | *p++ = '?'; 100 | break; 101 | } 102 | /* usr */ 103 | if (mode & S_IRUSR) 104 | *p++ = 'r'; 105 | else 106 | *p++ = '-'; 107 | if (mode & S_IWUSR) 108 | *p++ = 'w'; 109 | else 110 | *p++ = '-'; 111 | switch (mode & (S_IXUSR | S_ISUID)) { 112 | case 0: 113 | *p++ = '-'; 114 | break; 115 | case S_IXUSR: 116 | *p++ = 'x'; 117 | break; 118 | case S_ISUID: 119 | *p++ = 'S'; 120 | break; 121 | case S_IXUSR | S_ISUID: 122 | *p++ = 's'; 123 | break; 124 | } 125 | /* group */ 126 | if (mode & S_IRGRP) 127 | *p++ = 'r'; 128 | else 129 | *p++ = '-'; 130 | if (mode & S_IWGRP) 131 | *p++ = 'w'; 132 | else 133 | *p++ = '-'; 134 | switch (mode & (S_IXGRP | S_ISGID)) { 135 | case 0: 136 | *p++ = '-'; 137 | break; 138 | case S_IXGRP: 139 | *p++ = 'x'; 140 | break; 141 | case S_ISGID: 142 | *p++ = 'S'; 143 | break; 144 | case S_IXGRP | S_ISGID: 145 | *p++ = 's'; 146 | break; 147 | } 148 | /* other */ 149 | if (mode & S_IROTH) 150 | *p++ = 'r'; 151 | else 152 | *p++ = '-'; 153 | if (mode & S_IWOTH) 154 | *p++ = 'w'; 155 | else 156 | *p++ = '-'; 157 | switch (mode & (S_IXOTH | S_ISVTX)) { 158 | case 0: 159 | *p++ = '-'; 160 | break; 161 | case S_IXOTH: 162 | *p++ = 'x'; 163 | break; 164 | case S_ISVTX: 165 | *p++ = 'T'; 166 | break; 167 | case S_IXOTH | S_ISVTX: 168 | *p++ = 't'; 169 | break; 170 | } 171 | *p++ = ' '; /* will be a '+' if ACL's implemented */ 172 | *p = '\0'; 173 | } 174 | #endif /* !HAVE_STRMODE */ 175 | -------------------------------------------------------------------------------- /src/pax/options.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: options.h,v 1.11 2007/04/23 18:40:22 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)options.h 8.2 (Berkeley) 4/18/94 36 | */ 37 | 38 | /* 39 | * argv[0] names. Used for tar and cpio emulation 40 | */ 41 | 42 | #define NM_TAR "tar" 43 | #define NM_CPIO "cpio" 44 | #define NM_PAX "pax" 45 | 46 | /* special value for -E */ 47 | #define none "none" 48 | 49 | /* 50 | * Constants used to specify the legal sets of flags in pax. For each major 51 | * operation mode of pax, a set of illegal flags is defined. If any one of 52 | * those illegal flags are found set, we scream and exit 53 | */ 54 | 55 | /* 56 | * flags (one for each option). 57 | */ 58 | #define AF 0x000000001ULL 59 | #define BF 0x000000002ULL 60 | #define CF 0x000000004ULL 61 | #define DF 0x000000008ULL 62 | #define FF 0x000000010ULL 63 | #define IF 0x000000020ULL 64 | #define KF 0x000000040ULL 65 | #define LF 0x000000080ULL 66 | #define NF 0x000000100ULL 67 | #define OF 0x000000200ULL 68 | #define PF 0x000000400ULL 69 | #define RF 0x000000800ULL 70 | #define SF 0x000001000ULL 71 | #define TF 0x000002000ULL 72 | #define UF 0x000004000ULL 73 | #define VF 0x000008000ULL 74 | #define WF 0x000010000ULL 75 | #define XF 0x000020000ULL 76 | #define CAF 0x000040000ULL /* nonstandard extension */ 77 | #define CBF 0x000080000ULL /* nonstandard extension */ 78 | #define CDF 0x000100000ULL /* nonstandard extension */ 79 | #define CEF 0x000200000ULL /* nonstandard extension */ 80 | #define CGF 0x000400000ULL /* nonstandard extension */ 81 | #define CHF 0x000800000ULL /* nonstandard extension */ 82 | #define CLF 0x001000000ULL /* nonstandard extension */ 83 | #define CMF 0x002000000ULL /* nonstandard extension */ 84 | #define CPF 0x004000000ULL /* nonstandard extension */ 85 | #define CTF 0x008000000ULL /* nonstandard extension */ 86 | #define CUF 0x010000000ULL /* nonstandard extension */ 87 | #define VSF 0x020000000ULL /* non-standard */ 88 | #define CXF 0x040000000ULL 89 | #define CYF 0x080000000ULL /* nonstandard extension */ 90 | #define CZF 0x100000000ULL /* nonstandard extension */ 91 | 92 | /* 93 | * ascii string indexed by bit position above (alter the above and you must 94 | * alter this string) used to tell the user what flags caused us to complain 95 | */ 96 | #define FLGCH "abcdfiklnoprstuvwxABDEGHLMPTUVXYZ" 97 | 98 | /* 99 | * legal pax operation bit patterns 100 | */ 101 | 102 | #define ISLIST(x) (((x) & (RF|WF)) == 0) 103 | #define ISEXTRACT(x) (((x) & (RF|WF)) == RF) 104 | #define ISARCHIVE(x) (((x) & (AF|RF|WF)) == WF) 105 | #define ISAPPND(x) (((x) & (AF|RF|WF)) == (AF|WF)) 106 | #define ISCOPY(x) (((x) & (RF|WF)) == (RF|WF)) 107 | #define ISWRITE(x) (((x) & (RF|WF)) == WF) 108 | 109 | /* 110 | * Illegal option flag subsets based on pax operation 111 | */ 112 | 113 | #define BDEXTR (AF|BF|LF|TF|WF|XF|CBF|CHF|CLF|CMF|CPF|CXF) 114 | #define BDARCH (CF|KF|LF|NF|PF|RF|CDF|CEF|CYF|CZF) 115 | #define BDCOPY (AF|BF|FF|OF|XF|CAF|CBF|CEF) 116 | #define BDLIST (AF|BF|IF|KF|LF|OF|PF|RF|TF|UF|WF|XF|CBF|CDF|CHF|CLF|CMF|CPF|CXF|CYF|CZF) 117 | -------------------------------------------------------------------------------- /src/libnetbsd/local.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: local.h,v 1.38 2014/06/18 17:47:58 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Chris Torek. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the University nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | * 34 | * @(#)local.h 8.3 (Berkeley) 7/3/94 35 | */ 36 | 37 | #include "wcio.h" 38 | #include "fileext.h" 39 | 40 | #include 41 | #include 42 | #include 43 | 44 | /* 45 | * Information local to this implementation of stdio, 46 | * in particular, macros and private variables. 47 | */ 48 | 49 | extern int __sflush(FILE *); 50 | extern FILE *__sfp(void); 51 | extern void __sfpinit(FILE *); 52 | extern int __srefill(FILE *); 53 | extern ssize_t __sread(void *, void *, size_t); 54 | extern ssize_t __swrite(void *, const void *, size_t); 55 | extern off_t __sseek(void *, off_t, int); 56 | extern int __sclose(void *); 57 | extern void __sinit(void); 58 | extern void _cleanup(void); 59 | extern void (*__cleanup)(void); 60 | extern void __smakebuf(FILE *); 61 | extern int __swhatbuf(FILE *, size_t *, int *); 62 | extern int _fwalk(int (*)(FILE *)); 63 | extern char *_mktemp(char *); 64 | extern int __swsetup(FILE *); 65 | extern int __sflags(const char *, int *); 66 | extern int __svfscanf(FILE * __restrict, const char * __restrict, 67 | va_list) __scanflike(2, 0); 68 | extern int __svfscanf_l(FILE * __restrict, locale_t, 69 | const char * __restrict, va_list) __scanflike(3, 0); 70 | extern int __svfscanf_unlocked_l(FILE * __restrict, locale_t, 71 | const char * __restrict, va_list) __scanflike(3, 0); 72 | extern int __vfprintf_unlocked_l(FILE * __restrict, locale_t, 73 | const char * __restrict, va_list) __printflike(3, 0); 74 | 75 | 76 | extern int __sdidinit; 77 | 78 | extern wint_t __fgetwc_unlock(FILE *); 79 | extern wint_t __fputwc_unlock(wchar_t, FILE *); 80 | 81 | extern ssize_t __getdelim(char **__restrict, size_t *__restrict, int, 82 | FILE *__restrict); 83 | extern char *__fgetstr(FILE * __restrict, size_t * __restrict, int); 84 | extern int __vfwprintf_unlocked_l(FILE *, locale_t, const wchar_t *, va_list); 85 | extern int __vfwscanf_unlocked_l(FILE * __restrict, locale_t, 86 | const wchar_t * __restrict, va_list); 87 | 88 | /* 89 | * Return true iff the given FILE cannot be written now. 90 | */ 91 | #define cantwrite(fp) \ 92 | ((((fp)->_flags & __SWR) == 0 || (fp)->_bf._base == NULL) && \ 93 | __swsetup(fp)) 94 | 95 | /* 96 | * Test whether the given stdio file has an active ungetc buffer; 97 | * release such a buffer, without restoring ordinary unread data. 98 | */ 99 | #define HASUB(fp) (_UB(fp)._base != NULL) 100 | #define FREEUB(fp) { \ 101 | if (_UB(fp)._base != (fp)->_ubuf) \ 102 | free((char *)_UB(fp)._base); \ 103 | _UB(fp)._base = NULL; \ 104 | } 105 | 106 | /* 107 | * test for an fgetln() buffer. 108 | */ 109 | #define FREELB(fp) { \ 110 | free(_EXT(fp)->_fgetstr_buf); \ 111 | _EXT(fp)->_fgetstr_buf = NULL; \ 112 | _EXT(fp)->_fgetstr_len = 0; \ 113 | } 114 | 115 | extern void __flockfile_internal(FILE *, int); 116 | extern void __funlockfile_internal(FILE *, int); 117 | 118 | extern char *__gets(char *); 119 | 120 | /* 121 | * Detect if the current file position fits in a long int. 122 | */ 123 | 124 | static __inline bool 125 | __long_overflow(off_t pos) 126 | { 127 | return (pos < LONG_MIN) || (pos > LONG_MAX); 128 | } 129 | -------------------------------------------------------------------------------- /src/find/main.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: main.c,v 1.31 2013/01/24 17:50:08 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993, 1994 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Cimarron D. Taylor of the University of California, Berkeley. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the University nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | */ 34 | 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include "find.h" 51 | 52 | time_t now; /* time find was run */ 53 | int dotfd; /* starting directory */ 54 | int ftsoptions; /* options for the ftsopen(3) call */ 55 | int isdeprecated; /* using deprecated syntax */ 56 | int isdepth; /* do directories on post-order visit */ 57 | int isoutput; /* user specified output operator */ 58 | int issort; /* sort directory entries */ 59 | int isxargs; /* don't permit xargs delimiting chars */ 60 | int regcomp_flags = REG_BASIC; /* regex compilation flags */ 61 | 62 | __dead static void usage(void); 63 | 64 | int 65 | main(int argc, char *argv[]) 66 | { 67 | char **p, **start; 68 | int ch; 69 | 70 | (void)time(&now); /* initialize the time-of-day */ 71 | (void)setlocale(LC_ALL, ""); 72 | 73 | /* array to hold dir list. at most (argc - 1) elements. */ 74 | p = start = malloc(argc * sizeof (char *)); 75 | if (p == NULL) 76 | err(1, NULL); 77 | 78 | ftsoptions = FTS_NOSTAT | FTS_PHYSICAL; 79 | while ((ch = getopt(argc, argv, "HLPdEf:hsXx")) != -1) 80 | switch (ch) { 81 | case 'H': 82 | ftsoptions &= ~FTS_LOGICAL; 83 | ftsoptions |= FTS_PHYSICAL|FTS_COMFOLLOW; 84 | break; 85 | case 'L': 86 | ftsoptions &= ~(FTS_COMFOLLOW|FTS_PHYSICAL); 87 | ftsoptions |= FTS_LOGICAL; 88 | break; 89 | case 'P': 90 | ftsoptions &= ~(FTS_COMFOLLOW|FTS_LOGICAL); 91 | ftsoptions |= FTS_PHYSICAL; 92 | break; 93 | case 'd': 94 | isdepth = 1; 95 | break; 96 | case 'E': 97 | regcomp_flags = REG_EXTENDED; 98 | break; 99 | case 'f': 100 | *p++ = optarg; 101 | break; 102 | case 'h': 103 | ftsoptions &= ~FTS_PHYSICAL; 104 | ftsoptions |= FTS_LOGICAL; 105 | break; 106 | case 's': 107 | issort = 1; 108 | break; 109 | case 'X': 110 | isxargs = 1; 111 | break; 112 | case 'x': 113 | ftsoptions |= FTS_XDEV; 114 | break; 115 | case '?': 116 | default: 117 | break; 118 | } 119 | 120 | argc -= optind; 121 | argv += optind; 122 | 123 | /* 124 | * Find first option to delimit the file list. The first argument 125 | * that starts with a -, or is a ! or a ( must be interpreted as a 126 | * part of the find expression, according to POSIX .2. 127 | */ 128 | for (; *argv != NULL; *p++ = *argv++) { 129 | if (argv[0][0] == '-') 130 | break; 131 | if ((argv[0][0] == '!' || argv[0][0] == '(') && 132 | argv[0][1] == '\0') 133 | break; 134 | } 135 | 136 | if (p == start) 137 | usage(); 138 | 139 | *p = NULL; 140 | 141 | if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) 142 | err(1, "."); 143 | 144 | exit(find_execute(find_formplan(argv), start)); 145 | } 146 | 147 | static void 148 | usage(void) 149 | { 150 | 151 | (void)fprintf(stderr, "Usage: %s [-H | -L | -P] [-dEhsXx] [-f file] " 152 | "file [file ...] [expression]\n", getprogname()); 153 | exit(1); 154 | } 155 | -------------------------------------------------------------------------------- /src/sed/defs.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: defs.h,v 1.12 2014/06/06 21:56:39 wiz Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Diomidis Spinellis. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Diomidis Spinellis of Imperial College, University of London. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)defs.h 8.1 (Berkeley) 6/6/93 36 | * $FreeBSD: head/usr.bin/sed/defs.h 192732 2009-05-25 06:45:33Z brian $ 37 | */ 38 | 39 | /* 40 | * Types of address specifications 41 | */ 42 | enum e_atype { 43 | AT_RE = 1, /* Line that match RE */ 44 | AT_LINE, /* Specific line */ 45 | AT_RELLINE, /* Relative line */ 46 | AT_LAST /* Last line */ 47 | }; 48 | 49 | /* 50 | * Format of an address 51 | */ 52 | struct s_addr { 53 | enum e_atype type; /* Address type */ 54 | union { 55 | u_long l; /* Line number */ 56 | regex_t *r; /* Regular expression */ 57 | } u; 58 | }; 59 | 60 | /* 61 | * Substitution command 62 | */ 63 | struct s_subst { 64 | int n; /* Occurrence to subst. */ 65 | int p; /* True if p flag */ 66 | int icase; /* True if I flag */ 67 | char *wfile; /* NULL if no wfile */ 68 | int wfd; /* Cached file descriptor */ 69 | regex_t *re; /* Regular expression */ 70 | unsigned int maxbref; /* Largest backreference. */ 71 | u_long linenum; /* Line number. */ 72 | char *new; /* Replacement text */ 73 | }; 74 | 75 | /* 76 | * Translate command. 77 | */ 78 | struct s_tr { 79 | unsigned char bytetab[256]; 80 | struct trmulti { 81 | size_t fromlen; 82 | char from[MB_LEN_MAX]; 83 | size_t tolen; 84 | char to[MB_LEN_MAX]; 85 | } *multis; 86 | size_t nmultis; 87 | }; 88 | 89 | /* 90 | * An internally compiled command. 91 | * Initialy, label references are stored in t, on a second pass they 92 | * are updated to pointers. 93 | */ 94 | struct s_command { 95 | struct s_command *next; /* Pointer to next command */ 96 | struct s_addr *a1, *a2; /* Start and end address */ 97 | u_long startline; /* Start line number or zero */ 98 | char *t; /* Text for : a c i r w */ 99 | union { 100 | struct s_command *c; /* Command(s) for b t { */ 101 | struct s_subst *s; /* Substitute command */ 102 | struct s_tr *y; /* Replace command array */ 103 | int fd; /* File descriptor for w */ 104 | } u; 105 | char code; /* Command code */ 106 | u_int nonsel:1; /* True if ! */ 107 | }; 108 | 109 | /* 110 | * Types of command arguments recognised by the parser 111 | */ 112 | enum e_args { 113 | EMPTY, /* d D g G h H l n N p P q x = \0 */ 114 | TEXT, /* a c i */ 115 | NONSEL, /* ! */ 116 | GROUP, /* { */ 117 | ENDGROUP, /* } */ 118 | COMMENT, /* # */ 119 | BRANCH, /* b t */ 120 | LABEL, /* : */ 121 | RFILE, /* r */ 122 | WFILE, /* w */ 123 | SUBST, /* s */ 124 | TR /* y */ 125 | }; 126 | 127 | /* 128 | * Structure containing things to append before a line is read 129 | */ 130 | struct s_appends { 131 | enum {AP_STRING, AP_FILE} type; 132 | char *s; 133 | size_t len; 134 | }; 135 | 136 | enum e_spflag { 137 | APPEND, /* Append to the contents. */ 138 | REPLACE /* Replace the contents. */ 139 | }; 140 | 141 | /* 142 | * Structure for a space (process, hold, otherwise). 143 | */ 144 | typedef struct { 145 | char *space; /* Current space pointer. */ 146 | size_t len; /* Current length. */ 147 | int deleted; /* If deleted. */ 148 | char *back; /* Backing memory. */ 149 | size_t blen; /* Backing memory length. */ 150 | } SPACE; 151 | -------------------------------------------------------------------------------- /src/libnetbsd/_strtoi.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: _strtoi.h,v 1.2 2015/01/18 17:55:22 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * Original version ID: 32 | * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp 33 | * 34 | * Created by Kamil Rytarowski, based on ID: 35 | * NetBSD: src/common/lib/libc/stdlib/_strtoul.h,v 1.7 2013/05/17 12:55:56 joerg Exp 36 | */ 37 | 38 | /* 39 | * function template for strtoi and strtou 40 | * 41 | * parameters: 42 | * _FUNCNAME : function name 43 | * __TYPE : return and range limits type 44 | * __WRAPPED : wrapped function, strtoimax or strtoumax 45 | */ 46 | 47 | #define _DIAGASSERT assert 48 | 49 | #define __WRAPPED_L_(x) x ## _l 50 | #define __WRAPPED_L__(x) __WRAPPED_L_(x) 51 | #define __WRAPPED_L __WRAPPED_L__(__WRAPPED) 52 | 53 | #if defined(_KERNEL) || defined(_STANDALONE) || \ 54 | defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY) 55 | __TYPE 56 | _FUNCNAME(const char * __restrict nptr, char ** __restrict endptr, int base, 57 | __TYPE lo, __TYPE hi, int * rstatus) 58 | #else 59 | #include 60 | #include "setlocale_local.h" 61 | #define INT_FUNCNAME_(pre, name, post) pre ## name ## post 62 | #define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post) 63 | 64 | static __TYPE 65 | INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char * __restrict nptr, 66 | char ** __restrict endptr, int base, 67 | __TYPE lo, __TYPE hi, int * rstatus, locale_t loc) 68 | #endif 69 | { 70 | #if !defined(_KERNEL) && !defined(_STANDALONE) 71 | int serrno; 72 | #endif 73 | __TYPE im; 74 | char *ep; 75 | int rep; 76 | 77 | _DIAGASSERT(hi >= lo); 78 | 79 | _DIAGASSERT(nptr != NULL); 80 | /* endptr may be NULL */ 81 | 82 | if (endptr == NULL) 83 | endptr = &ep; 84 | 85 | if (rstatus == NULL) 86 | rstatus = &rep; 87 | 88 | #if !defined(_KERNEL) && !defined(_STANDALONE) 89 | serrno = errno; 90 | errno = 0; 91 | #endif 92 | 93 | #if defined(_KERNEL) || defined(_STANDALONE) || \ 94 | defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY) 95 | im = __WRAPPED(nptr, endptr, base); 96 | #else 97 | im = __WRAPPED_L(nptr, endptr, base, loc); 98 | #endif 99 | 100 | #if !defined(_KERNEL) && !defined(_STANDALONE) 101 | *rstatus = errno; 102 | errno = serrno; 103 | #endif 104 | 105 | if (*rstatus == 0) { 106 | /* No digits were found */ 107 | if (nptr == *endptr) 108 | *rstatus = ECANCELED; 109 | /* There are further characters after number */ 110 | else if (**endptr != '\0') 111 | *rstatus = ENOTSUP; 112 | } 113 | 114 | if (im < lo) { 115 | if (*rstatus == 0) 116 | *rstatus = ERANGE; 117 | return lo; 118 | } 119 | if (im > hi) { 120 | if (*rstatus == 0) 121 | *rstatus = ERANGE; 122 | return hi; 123 | } 124 | 125 | return im; 126 | } 127 | 128 | #if !defined(_KERNEL) && !defined(_STANDALONE) && \ 129 | !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY) 130 | __TYPE 131 | _FUNCNAME(const char * __restrict nptr, char ** __restrict endptr, int base, 132 | __TYPE lo, __TYPE hi, int * rstatus) 133 | { 134 | //return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, lo, hi, 135 | //rstatus, _current_locale()); 136 | } 137 | 138 | __TYPE 139 | INT_FUNCNAME(, _FUNCNAME, _l)(const char * __restrict nptr, 140 | char ** __restrict endptr, int base, 141 | __TYPE lo, __TYPE hi, int * rstatus, locale_t loc) 142 | { 143 | return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, lo, hi, 144 | rstatus, loc); 145 | } 146 | #endif 147 | -------------------------------------------------------------------------------- /src/libnetbsd/stat_flags.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: stat_flags.c,v 1.2 2007/01/16 17:34:02 cbiere Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #else 35 | #define HAVE_STRUCT_STAT_ST_FLAGS 1 36 | #endif 37 | 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | 46 | #define SAPPEND(s) do { \ 47 | if (prefix != NULL) \ 48 | (void)strlcat(string, prefix, sizeof(string)); \ 49 | (void)strlcat(string, s, sizeof(string)); \ 50 | prefix = ","; \ 51 | } while (/* CONSTCOND */ 0) 52 | 53 | /* 54 | * flags_to_string -- 55 | * Convert stat flags to a comma-separated string. If no flags 56 | * are set, return the default string. 57 | */ 58 | char * 59 | flags_to_string(u_long flags, const char *def) 60 | { 61 | char string[128]; 62 | const char *prefix; 63 | 64 | string[0] = '\0'; 65 | prefix = NULL; 66 | #if HAVE_STRUCT_STAT_ST_FLAGS 67 | if (flags & UF_APPEND) 68 | SAPPEND("uappnd"); 69 | if (flags & UF_IMMUTABLE) 70 | SAPPEND("uchg"); 71 | if (flags & UF_NODUMP) 72 | SAPPEND("nodump"); 73 | if (flags & UF_OPAQUE) 74 | SAPPEND("opaque"); 75 | if (flags & SF_APPEND) 76 | SAPPEND("sappnd"); 77 | if (flags & SF_ARCHIVED) 78 | SAPPEND("arch"); 79 | if (flags & SF_IMMUTABLE) 80 | SAPPEND("schg"); 81 | #ifdef SF_SNAPSHOT 82 | if (flags & SF_SNAPSHOT) 83 | SAPPEND("snap"); 84 | #endif 85 | #endif 86 | if (prefix != NULL) 87 | return strdup(string); 88 | return strdup(def); 89 | } 90 | 91 | #define TEST(a, b, f) { \ 92 | if (!strcmp(a, b)) { \ 93 | if (clear) { \ 94 | if (clrp) \ 95 | *clrp |= (f); \ 96 | if (setp) \ 97 | *setp &= ~(f); \ 98 | } else { \ 99 | if (setp) \ 100 | *setp |= (f); \ 101 | if (clrp) \ 102 | *clrp &= ~(f); \ 103 | } \ 104 | break; \ 105 | } \ 106 | } 107 | 108 | /* 109 | * string_to_flags -- 110 | * Take string of arguments and return stat flags. Return 0 on 111 | * success, 1 on failure. On failure, stringp is set to point 112 | * to the offending token. 113 | */ 114 | int 115 | string_to_flags(char **stringp, u_long *setp, u_long *clrp) 116 | { 117 | int clear; 118 | char *string, *p; 119 | 120 | if (setp) 121 | *setp = 0; 122 | if (clrp) 123 | *clrp = 0; 124 | 125 | #if HAVE_STRUCT_STAT_ST_FLAGS 126 | string = *stringp; 127 | while ((p = strsep(&string, "\t ,")) != NULL) { 128 | clear = 0; 129 | *stringp = p; 130 | if (*p == '\0') 131 | continue; 132 | if (p[0] == 'n' && p[1] == 'o') { 133 | clear = 1; 134 | p += 2; 135 | } 136 | switch (p[0]) { 137 | case 'a': 138 | TEST(p, "arch", SF_ARCHIVED); 139 | TEST(p, "archived", SF_ARCHIVED); 140 | return (1); 141 | case 'd': 142 | clear = !clear; 143 | TEST(p, "dump", UF_NODUMP); 144 | return (1); 145 | case 'n': 146 | /* 147 | * Support `nonodump'. Note that 148 | * the state of clear is not changed. 149 | */ 150 | TEST(p, "nodump", UF_NODUMP); 151 | return (1); 152 | case 'o': 153 | TEST(p, "opaque", UF_OPAQUE); 154 | return (1); 155 | case 's': 156 | TEST(p, "sappnd", SF_APPEND); 157 | TEST(p, "sappend", SF_APPEND); 158 | TEST(p, "schg", SF_IMMUTABLE); 159 | TEST(p, "schange", SF_IMMUTABLE); 160 | TEST(p, "simmutable", SF_IMMUTABLE); 161 | return (1); 162 | case 'u': 163 | TEST(p, "uappnd", UF_APPEND); 164 | TEST(p, "uappend", UF_APPEND); 165 | TEST(p, "uchg", UF_IMMUTABLE); 166 | TEST(p, "uchange", UF_IMMUTABLE); 167 | TEST(p, "uimmutable", UF_IMMUTABLE); 168 | return (1); 169 | default: 170 | return (1); 171 | } 172 | } 173 | #endif 174 | 175 | return (0); 176 | } 177 | -------------------------------------------------------------------------------- /src/libnetbsd/efun.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: efun.c,v 1.12 2019/10/03 20:29:19 tnn Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 2006 The NetBSD Foundation, Inc. 5 | * All rights reserved. 6 | * 7 | * This code is derived from software contributed to The NetBSD Foundation 8 | * by Christos Zoulas. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 | * POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | #if HAVE_NBTOOL_CONFIG_H 33 | #include "nbtool_config.h" 34 | #endif 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | static void (*efunc)(int, const char *, ...) = err; 46 | 47 | static void __dead 48 | eexit(int e, const char *fmt __unused, ...) 49 | { 50 | exit(e); 51 | } 52 | 53 | void (* 54 | esetfunc(void (*ef)(int, const char *, ...)))(int, const char *, ...) 55 | { 56 | void (*of)(int, const char *, ...) = efunc; 57 | efunc = ef == NULL ? eexit : ef; 58 | return of; 59 | } 60 | 61 | size_t 62 | estrlcpy(char *dst, const char *src, size_t len) 63 | { 64 | size_t rv; 65 | if ((rv = strlcpy(dst, src, len)) >= len) { 66 | errno = ENAMETOOLONG; 67 | (*efunc)(1, 68 | "Cannot copy string; %zu chars needed %zu provided", 69 | rv, len); 70 | } 71 | return rv; 72 | } 73 | 74 | size_t 75 | estrlcat(char *dst, const char *src, size_t len) 76 | { 77 | size_t rv; 78 | if ((rv = strlcat(dst, src, len)) >= len) { 79 | errno = ENAMETOOLONG; 80 | (*efunc)(1, 81 | "Cannot append to string; %zu chars needed %zu provided", 82 | rv, len); 83 | } 84 | return rv; 85 | } 86 | 87 | char * 88 | estrdup(const char *s) 89 | { 90 | char *d = strdup(s); 91 | if (d == NULL) 92 | (*efunc)(1, "Cannot copy string"); 93 | return d; 94 | } 95 | 96 | char * 97 | estrndup(const char *s, size_t len) 98 | { 99 | char *d = strndup(s, len); 100 | if (d == NULL) 101 | (*efunc)(1, "Cannot copy string"); 102 | return d; 103 | } 104 | 105 | void * 106 | emalloc(size_t n) 107 | { 108 | void *p = malloc(n); 109 | if (p == NULL && n != 0) 110 | (*efunc)(1, "Cannot allocate %zu bytes", n); 111 | return p; 112 | } 113 | 114 | void * 115 | ecalloc(size_t n, size_t s) 116 | { 117 | void *p = calloc(n, s); 118 | if (p == NULL && n != 0 && s != 0) 119 | (*efunc)(1, "Cannot allocate %zu blocks of size %zu", n, s); 120 | return p; 121 | } 122 | 123 | void * 124 | erealloc(void *p, size_t n) 125 | { 126 | void *q = realloc(p, n); 127 | if (q == NULL && n != 0) 128 | (*efunc)(1, "Cannot re-allocate %zu bytes", n); 129 | return q; 130 | } 131 | 132 | void 133 | ereallocarr(void *p, size_t n, size_t s) 134 | { 135 | int rv = reallocarr(p, n, s); 136 | if (rv != 0) { 137 | errno = rv; 138 | (*efunc)(1, "Cannot re-allocate %zu * %zu bytes", n, s); 139 | } 140 | } 141 | 142 | FILE * 143 | efopen(const char *p, const char *m) 144 | { 145 | FILE *fp = fopen(p, m); 146 | if (fp == NULL) 147 | (*efunc)(1, "Cannot open `%s'", p); 148 | return fp; 149 | } 150 | 151 | int 152 | easprintf(char ** __restrict ret, const char * __restrict format, ...) 153 | { 154 | int rv; 155 | va_list ap; 156 | va_start(ap, format); 157 | if ((rv = vasprintf(ret, format, ap)) == -1) 158 | (*efunc)(1, "Cannot format string"); 159 | va_end(ap); 160 | return rv; 161 | } 162 | 163 | int 164 | evasprintf(char ** __restrict ret, const char * __restrict format, va_list ap) 165 | { 166 | int rv; 167 | if ((rv = vasprintf(ret, format, ap)) == -1) 168 | (*efunc)(1, "Cannot format string"); 169 | return rv; 170 | } 171 | 172 | intmax_t 173 | estrtoi(const char * nptr, int base, intmax_t lo, intmax_t hi) 174 | { 175 | int e; 176 | intmax_t rv = strtoi(nptr, NULL, base, lo, hi, &e); 177 | if (e != 0) { 178 | errno = e; 179 | (*efunc)(1, 180 | "Cannot convert string value '%s' with base %d to a number in range [%jd .. %jd]", 181 | nptr, base, lo, hi); 182 | } 183 | return rv; 184 | } 185 | 186 | uintmax_t 187 | estrtou(const char * nptr, int base, uintmax_t lo, uintmax_t hi) 188 | { 189 | int e; 190 | uintmax_t rv = strtou(nptr, NULL, base, lo, hi, &e); 191 | if (e != 0) { 192 | errno = e; 193 | (*efunc)(1, 194 | "Cannot convert string value '%s' with base %d to a number in range [%ju .. %ju]", 195 | nptr, base, lo, hi); 196 | } 197 | return rv; 198 | } 199 | -------------------------------------------------------------------------------- /include/tzfile.h: -------------------------------------------------------------------------------- 1 | /* $OpenBSD: tzfile.h,v 1.9 2012/09/13 11:14:20 millert Exp $ */ 2 | 3 | #ifndef TZFILE_H 4 | 5 | #define TZFILE_H 6 | 7 | /* 8 | ** This file is in the public domain, so clarified as of 9 | ** 1996-06-05 by Arthur David Olson. 10 | */ 11 | 12 | /* 13 | ** This header is for use ONLY with the time conversion code. 14 | ** There is no guarantee that it will remain unchanged, 15 | ** or that it will remain at all. 16 | ** Do NOT copy it to any system include directory. 17 | ** Thank you! 18 | */ 19 | 20 | /* 21 | ** Information about time zone files. 22 | */ 23 | 24 | #ifndef TZDIR 25 | #define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ 26 | #endif /* !defined TZDIR */ 27 | 28 | #ifndef TZDEFAULT 29 | #define TZDEFAULT "/etc/localtime" 30 | #endif /* !defined TZDEFAULT */ 31 | 32 | #ifndef TZDEFRULES 33 | #define TZDEFRULES "posixrules" 34 | #endif /* !defined TZDEFRULES */ 35 | 36 | /* 37 | ** Each file begins with. . . 38 | */ 39 | 40 | #define TZ_MAGIC "TZif" 41 | 42 | struct tzhead { 43 | char tzh_magic[4]; /* TZ_MAGIC */ 44 | char tzh_version[1]; /* '\0' or '2' as of 2005 */ 45 | char tzh_reserved[15]; /* reserved--must be zero */ 46 | char tzh_ttisgmtcnt[4]; /* coded number of trans. time flags */ 47 | char tzh_ttisstdcnt[4]; /* coded number of trans. time flags */ 48 | char tzh_leapcnt[4]; /* coded number of leap seconds */ 49 | char tzh_timecnt[4]; /* coded number of transition times */ 50 | char tzh_typecnt[4]; /* coded number of local time types */ 51 | char tzh_charcnt[4]; /* coded number of abbr. chars */ 52 | }; 53 | 54 | /* 55 | ** . . .followed by. . . 56 | ** 57 | ** tzh_timecnt (char [4])s coded transition times a la time(2) 58 | ** tzh_timecnt (unsigned char)s types of local time starting at above 59 | ** tzh_typecnt repetitions of 60 | ** one (char [4]) coded UTC offset in seconds 61 | ** one (unsigned char) used to set tm_isdst 62 | ** one (unsigned char) that's an abbreviation list index 63 | ** tzh_charcnt (char)s '\0'-terminated zone abbreviations 64 | ** tzh_leapcnt repetitions of 65 | ** one (char [4]) coded leap second transition times 66 | ** one (char [4]) total correction after above 67 | ** tzh_ttisstdcnt (char)s indexed by type; if TRUE, transition 68 | ** time is standard time, if FALSE, 69 | ** transition time is wall clock time 70 | ** if absent, transition times are 71 | ** assumed to be wall clock time 72 | ** tzh_ttisgmtcnt (char)s indexed by type; if TRUE, transition 73 | ** time is UTC, if FALSE, 74 | ** transition time is local time 75 | ** if absent, transition times are 76 | ** assumed to be local time 77 | */ 78 | 79 | /* 80 | ** If tzh_version is '2' or greater, the above is followed by a second instance 81 | ** of tzhead and a second instance of the data in which each coded transition 82 | ** time uses 8 rather than 4 chars, 83 | ** then a POSIX-TZ-environment-variable-style string for use in handling 84 | ** instants after the last transition time stored in the file 85 | ** (with nothing between the newlines if there is no POSIX representation for 86 | ** such instants). 87 | */ 88 | 89 | /* 90 | ** In the current implementation, "tzset()" refuses to deal with files that 91 | ** exceed any of the limits below. 92 | */ 93 | 94 | #ifndef TZ_MAX_TIMES 95 | #define TZ_MAX_TIMES 1200 96 | #endif /* !defined TZ_MAX_TIMES */ 97 | 98 | #ifndef TZ_MAX_TYPES 99 | #ifndef NOSOLAR 100 | #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ 101 | #endif /* !defined NOSOLAR */ 102 | #ifdef NOSOLAR 103 | /* 104 | ** Must be at least 14 for Europe/Riga as of Jan 12 1995, 105 | ** as noted by Earl Chew. 106 | */ 107 | #define TZ_MAX_TYPES 20 /* Maximum number of local time types */ 108 | #endif /* !defined NOSOLAR */ 109 | #endif /* !defined TZ_MAX_TYPES */ 110 | 111 | #ifndef TZ_MAX_CHARS 112 | #define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ 113 | /* (limited by what unsigned chars can hold) */ 114 | #endif /* !defined TZ_MAX_CHARS */ 115 | 116 | #ifndef TZ_MAX_LEAPS 117 | #define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ 118 | #endif /* !defined TZ_MAX_LEAPS */ 119 | 120 | #define SECSPERMIN 60 121 | #define MINSPERHOUR 60 122 | #define HOURSPERDAY 24 123 | #define DAYSPERWEEK 7 124 | #define DAYSPERNYEAR 365 125 | #define DAYSPERLYEAR 366 126 | #define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) 127 | #define SECSPERDAY ((long) SECSPERHOUR * HOURSPERDAY) 128 | #define MONSPERYEAR 12 129 | 130 | #define TM_SUNDAY 0 131 | #define TM_MONDAY 1 132 | #define TM_TUESDAY 2 133 | #define TM_WEDNESDAY 3 134 | #define TM_THURSDAY 4 135 | #define TM_FRIDAY 5 136 | #define TM_SATURDAY 6 137 | 138 | #define TM_JANUARY 0 139 | #define TM_FEBRUARY 1 140 | #define TM_MARCH 2 141 | #define TM_APRIL 3 142 | #define TM_MAY 4 143 | #define TM_JUNE 5 144 | #define TM_JULY 6 145 | #define TM_AUGUST 7 146 | #define TM_SEPTEMBER 8 147 | #define TM_OCTOBER 9 148 | #define TM_NOVEMBER 10 149 | #define TM_DECEMBER 11 150 | 151 | #define TM_YEAR_BASE 1900 152 | 153 | #define EPOCH_YEAR 1970 154 | #define EPOCH_WDAY TM_THURSDAY 155 | 156 | #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) 157 | 158 | /* 159 | ** Since everything in isleap is modulo 400 (or a factor of 400), we know that 160 | ** isleap(y) == isleap(y % 400) 161 | ** and so 162 | ** isleap(a + b) == isleap((a + b) % 400) 163 | ** or 164 | ** isleap(a + b) == isleap(a % 400 + b % 400) 165 | ** This is true even if % means modulo rather than Fortran remainder 166 | ** (which is allowed by C89 but not C99). 167 | ** We use this to avoid addition overflow problems. 168 | */ 169 | 170 | #define isleap_sum(a, b) isleap((a) % 400 + (b) % 400) 171 | 172 | #endif /* !defined TZFILE_H */ 173 | -------------------------------------------------------------------------------- /src/pax/tty_subs.c: -------------------------------------------------------------------------------- 1 | /* $NetBSD: tty_subs.c,v 1.19 2007/04/23 18:40:22 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | */ 35 | 36 | #if HAVE_NBTOOL_CONFIG_H 37 | #include "nbtool_config.h" 38 | #endif 39 | 40 | #include 41 | #include 42 | #include 43 | #include 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include "pax.h" 53 | #include "extern.h" 54 | #include 55 | 56 | /* 57 | * routines that deal with I/O to and from the user 58 | */ 59 | 60 | #define DEVTTY "/dev/tty" /* device for interactive i/o */ 61 | static FILE *ttyoutf = NULL; /* output pointing at control tty */ 62 | static FILE *ttyinf = NULL; /* input pointing at control tty */ 63 | 64 | /* 65 | * tty_init() 66 | * Try to open the controlling terminal (if any) for this process. If the 67 | * open fails, future ops that require user input will get an EOF. 68 | */ 69 | 70 | int 71 | tty_init(void) 72 | { 73 | int ttyfd; 74 | 75 | if ((ttyfd = open(DEVTTY, O_RDWR)) >= 0) { 76 | if ((ttyoutf = fdopen(ttyfd, "w")) != NULL) { 77 | if ((ttyinf = fdopen(ttyfd, "r")) != NULL) 78 | return 0; 79 | (void)fclose(ttyoutf); 80 | } 81 | (void)close(ttyfd); 82 | } 83 | 84 | if (iflag) { 85 | tty_warn(1, "Fatal error, cannot open %s", DEVTTY); 86 | return -1; 87 | } 88 | return 0; 89 | } 90 | 91 | /* 92 | * tty_prnt() 93 | * print a message using the specified format to the controlling tty 94 | * if there is no controlling terminal, just return. 95 | */ 96 | 97 | void 98 | tty_prnt(const char *fmt, ...) 99 | { 100 | va_list ap; 101 | if (ttyoutf == NULL) 102 | return; 103 | va_start(ap, fmt); 104 | (void)vfprintf(ttyoutf, fmt, ap); 105 | va_end(ap); 106 | (void)fflush(ttyoutf); 107 | } 108 | 109 | /* 110 | * tty_read() 111 | * read a string from the controlling terminal if it is open into the 112 | * supplied buffer 113 | * Return: 114 | * 0 if data was read, -1 otherwise. 115 | */ 116 | 117 | int 118 | tty_read(char *str, int len) 119 | { 120 | char *pt; 121 | 122 | if ((--len <= 0) || (ttyinf == NULL) || (fgets(str,len,ttyinf) == NULL)) 123 | return -1; 124 | *(str + len) = '\0'; 125 | 126 | /* 127 | * strip off that trailing newline 128 | */ 129 | if ((pt = strchr(str, '\n')) != NULL) 130 | *pt = '\0'; 131 | return 0; 132 | } 133 | 134 | /* 135 | * tty_warn() 136 | * write a warning message to stderr. if "set" the exit value of pax 137 | * will be non-zero. 138 | */ 139 | 140 | void 141 | tty_warn(int set, const char *fmt, ...) 142 | { 143 | va_list ap; 144 | va_start(ap, fmt); 145 | if (set) 146 | exit_val = 1; 147 | /* 148 | * when vflag we better ship out an extra \n to get this message on a 149 | * line by itself 150 | */ 151 | if ((Vflag || vflag) && vfpart) { 152 | (void)fputc('\n', stderr); 153 | vfpart = 0; 154 | } 155 | (void)fprintf(stderr, "%s: ", argv0); 156 | (void)vfprintf(stderr, fmt, ap); 157 | va_end(ap); 158 | (void)fputc('\n', stderr); 159 | } 160 | 161 | /* 162 | * syswarn() 163 | * write a warning message to stderr. if "set" the exit value of pax 164 | * will be non-zero. 165 | */ 166 | 167 | void 168 | syswarn(int set, int errnum, const char *fmt, ...) 169 | { 170 | va_list ap; 171 | va_start(ap, fmt); 172 | if (set) 173 | exit_val = 1; 174 | /* 175 | * when vflag we better ship out an extra \n to get this message on a 176 | * line by itself 177 | */ 178 | if ((Vflag || vflag) && vfpart) { 179 | (void)fputc('\n', stdout); 180 | vfpart = 0; 181 | } 182 | (void)fprintf(stderr, "%s: ", argv0); 183 | (void)vfprintf(stderr, fmt, ap); 184 | va_end(ap); 185 | 186 | /* 187 | * format and print the errno 188 | */ 189 | if (errnum > 0) 190 | (void)fprintf(stderr, " (%s)", strerror(errnum)); 191 | (void)fputc('\n', stderr); 192 | } 193 | -------------------------------------------------------------------------------- /src/find/find.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: find.h,v 1.26 2016/06/13 00:04:40 pgoyette Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * This code is derived from software contributed to Berkeley by 8 | * Cimarron D. Taylor of the University of California, Berkeley. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions 12 | * are met: 13 | * 1. Redistributions of source code must retain the above copyright 14 | * notice, this list of conditions and the following disclaimer. 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 3. Neither the name of the University nor the names of its contributors 19 | * may be used to endorse or promote products derived from this software 20 | * without specific prior written permission. 21 | * 22 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 | * SUCH DAMAGE. 33 | * 34 | * from: @(#)find.h 8.1 (Berkeley) 6/6/93 35 | */ 36 | 37 | #include 38 | #include 39 | 40 | /* node type */ 41 | enum ntype { 42 | N_AND = 1, /* must start > 0 */ 43 | N_AMIN, N_ANEWER, N_ASINCE, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, 44 | N_CSINCE, N_CTIME, N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT, 45 | N_EXPR, N_FALSE, N_FLAGS, N_FOLLOW, N_FPRINT, N_FSTYPE, N_GROUP, 46 | N_INAME, N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH, 47 | N_MMIN, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, 48 | N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRINTX, 49 | N_PRUNE, N_REGEX, N_SINCE, N_SIZE, N_TYPE, N_USER, N_XDEV, N_DELETE 50 | }; 51 | 52 | /* node definition */ 53 | typedef struct _plandata { 54 | struct _plandata *next; /* next node */ 55 | int (*eval)(struct _plandata *, FTSENT *); 56 | /* node evaluation function */ 57 | #define F_EQUAL 1 /* [acm]time inum links size */ 58 | #define F_LESSTHAN 2 59 | #define F_GREATER 3 60 | #define F_NEEDOK 1 /* exec ok */ 61 | #define F_PLUSSET 2 /* -exec ... {} + */ 62 | #define F_MTFLAG 1 /* fstype */ 63 | #define F_MTTYPE 2 64 | #define F_ATLEAST 1 /* perm */ 65 | int flags; /* private flags */ 66 | enum ntype type; /* plan node type */ 67 | union { 68 | u_int32_t _f_data; /* flags */ 69 | gid_t _g_data; /* gid */ 70 | ino_t _i_data; /* inode */ 71 | mode_t _m_data; /* mode mask */ 72 | nlink_t _l_data; /* link count */ 73 | off_t _o_data; /* file size */ 74 | time_t _t_data; /* time value */ 75 | struct timespec _ts_data; /* time value */ 76 | uid_t _u_data; /* uid */ 77 | short _mt_data; /* mount flags */ 78 | struct _plandata *_p_data[2]; /* PLAN trees */ 79 | struct _ex { 80 | char **_e_argv; /* argv array */ 81 | char **_e_orig; /* original strings */ 82 | int *_e_len; /* allocated length */ 83 | char **_ep_bxp; /* ptr to 1st addt'l arg */ 84 | char *_ep_p; /* current buffer pointer */ 85 | char *_ep_bbp; /* begin buffer pointer */ 86 | char *_ep_ebp; /* end buffer pointer */ 87 | int _ep_maxargs; /* max #args */ 88 | int _ep_narg; /* # addt'l args */ 89 | int _ep_rval; /* return value */ 90 | } ex; 91 | char *_a_data[2]; /* array of char pointers */ 92 | char *_c_data; /* char pointer */ 93 | int _exit_val; /* exit value */ 94 | int _max_data; /* tree depth */ 95 | int _min_data; /* tree depth */ 96 | regex_t _regexp_data; /* compiled regexp */ 97 | FILE *_fprint_file; /* file stream for -fprint */ 98 | } p_un; 99 | } PLAN; 100 | #define a_data p_un._a_data 101 | #define c_data p_un._c_data 102 | #define i_data p_un._i_data 103 | #define f_data p_un._f_data 104 | #define g_data p_un._g_data 105 | #define l_data p_un._l_data 106 | #define m_data p_un._m_data 107 | #define mt_data p_un._mt_data 108 | #define o_data p_un._o_data 109 | #define p_data p_un._p_data 110 | #define t_data p_un._t_data 111 | #define ts_data p_un._ts_data 112 | #define u_data p_un._u_data 113 | #define e_argv p_un.ex._e_argv 114 | #define e_orig p_un.ex._e_orig 115 | #define e_len p_un.ex._e_len 116 | #define ep_p p_un.ex._ep_p 117 | #define ep_bbp p_un.ex._ep_bbp 118 | #define ep_ebp p_un.ex._ep_ebp 119 | #define ep_bxp p_un.ex._ep_bxp 120 | #define ep_cnt p_un.ex._ep_cnt 121 | #define ep_maxargs p_un.ex._ep_maxargs 122 | #define ep_nline p_un.ex._ep_nline 123 | #define ep_narg p_un.ex._ep_narg 124 | #define ep_rval p_un.ex._ep_rval 125 | #define exit_val p_un._exit_val 126 | #define max_data p_un._max_data 127 | #define min_data p_un._min_data 128 | #define regexp_data p_un._regexp_data 129 | #define fprint_file p_un._fprint_file 130 | 131 | typedef struct _option { 132 | const char *name; /* option name */ 133 | enum ntype token; /* token type */ 134 | PLAN *(*create)(char ***, int, char *); /* create function */ 135 | int arg; /* function needs arg */ 136 | } OPTION; 137 | 138 | #include "extern.h" 139 | -------------------------------------------------------------------------------- /include/bsd.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define __attribute__(x) 11 | #define __dead __attribute__((__noreturn__)) 12 | #define __pure __attribute__((__const__)) 13 | #define __constfunc __attribute__((__const__)) 14 | #define __unused __attribute__((__unused__)) 15 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 16 | #define _DIAGASSERT assert 17 | #define __predict_true(exp) __builtin_expect((exp) != 0, 1) 18 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) 19 | #define __nothing (/*LINTED*/(void)0) 20 | 21 | #ifndef __GLIBC__ 22 | #if defined(__cplusplus) 23 | #define __BEGIN_EXTERN_C extern "C" { 24 | #define __END_EXTERN_C } 25 | #else 26 | #define __BEGIN_EXTERN_C 27 | #define __END_EXTERN_C 28 | #endif 29 | 30 | #define __BEGIN_DECLS __BEGIN_EXTERN_C 31 | #define __END_DECLS __END_EXTERN_C 32 | #endif 33 | 34 | #if !defined(DEF_WEAK) 35 | #define DEF_WEAK(x) 36 | #endif 37 | 38 | #define __printflike(fmtarg, firstvararg) /* nothing */ 39 | #define __scanflike(fmtarg, firstvararg) /* nothing */ 40 | #define __sysloglike(fmtarg, firstvararg) /* nothing */ 41 | #define __format_arg(fmtarg) /* nothing */ 42 | 43 | #define S_ISTXT S_ISVTX /* sticky bit */ 44 | 45 | #ifndef st_atimespec 46 | #define st_atimespec st_atim 47 | #endif 48 | 49 | #ifndef st_atimensec 50 | #define st_atimensec st_atim.tv_nsec 51 | #endif 52 | 53 | #ifndef st_mtimespec 54 | #define st_mtimespec st_mtim 55 | #endif 56 | 57 | #ifndef st_mtimensec 58 | #define st_mtimensec st_mtim.tv_nsec 59 | #endif 60 | 61 | #ifndef st_ctimespec 62 | #define st_ctimespec st_ctim 63 | #endif 64 | 65 | #ifndef st_ctimensec 66 | #define st_ctimensec st_ctim.tv_nsec 67 | #endif 68 | 69 | /* 70 | * Definitions of flags stored in file flags word. 71 | * 72 | * Super-user and owner changeable flags. 73 | */ 74 | #define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */ 75 | #define UF_NODUMP 0x00000001 /* do not dump file */ 76 | #define UF_IMMUTABLE 0x00000002 /* file may not be changed */ 77 | #define UF_APPEND 0x00000004 /* writes to file may only append */ 78 | #define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */ 79 | /* UF_NOUNLINK 0x00000010 [NOT IMPLEMENTED] */ 80 | /* 81 | * Super-user changeable flags. 82 | */ 83 | #define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */ 84 | #define SF_ARCHIVED 0x00010000 /* file is archived */ 85 | #define SF_IMMUTABLE 0x00020000 /* file may not be changed */ 86 | #define SF_APPEND 0x00040000 /* writes to file may only append */ 87 | /* SF_NOUNLINK 0x00100000 [NOT IMPLEMENTED] */ 88 | #define SF_SNAPSHOT 0x00200000 /* snapshot inode */ 89 | #define SF_LOG 0x00400000 /* WAPBL log file inode */ 90 | #define SF_SNAPINVAL 0x00800000 /* snapshot is invalid */ 91 | 92 | #define SIGINFO 29 93 | #ifndef ALLPERMS 94 | #define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) 95 | #endif 96 | #define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH) 97 | #define MNT_RDONLY 0x00000001 98 | #define MNT_LOCAL 0x00001000 99 | #ifndef FNM_CASEFOLD 100 | #define FNM_CASEFOLD 0x08 101 | #endif 102 | #ifndef ARG_MAX 103 | #define ARG_MAX (256 * 1024) /* max bytes for an exec function */ 104 | #endif 105 | #define REG_BASIC 0000 106 | 107 | #define timespeccmp(tsp, usp, cmp) \ 108 | (((tsp)->tv_sec == (usp)->tv_sec) ? \ 109 | ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ 110 | ((tsp)->tv_sec cmp (usp)->tv_sec)) 111 | 112 | #define __arraycount(a) (sizeof(a) / sizeof(*(a))) 113 | 114 | #if !defined(_DIRENT_HAVE_NAMLEN) 115 | #define D_NAMLEN(x) \ 116 | strnlen((x)->d_name, (x)->d_reclen) 117 | #else 118 | #define D_NAMLEN(x) \ 119 | (x)->d_namlen 120 | #endif 121 | 122 | #define _VFS_NAMELEN 32 123 | #define _VFS_MNAMELEN 1024 124 | 125 | #define _PATH_DEFTAPE "/dev/st0" 126 | 127 | typedef va_list __va_list; 128 | 129 | extern const char *const *sys_signame; 130 | 131 | size_t strlcat(char *, const char *, size_t); 132 | size_t strlcpy(char *, const char *, size_t); 133 | const char *getprogname(void) __constfunc; 134 | void setprogname(const char *); 135 | int wcswidth(const wchar_t *, size_t); 136 | int wcwidth(wchar_t); 137 | time_t parsedate(const char *, const time_t *, const int *); 138 | void *emalloc(size_t); 139 | int string_to_flags(char **, unsigned long *, unsigned long *); 140 | void *setmode(const char *); 141 | mode_t getmode(const void *, mode_t); 142 | void strmode(mode_t, char *); 143 | int gid_from_group(const char *, gid_t *); 144 | const char *group_from_gid(gid_t, int); 145 | int uid_from_user(const char *, uid_t *); 146 | const char *user_from_uid(uid_t, int); 147 | char *fgetln(FILE * __restrict, size_t * __restrict); 148 | int reallocarr(void *, size_t, size_t); 149 | int setpassent(int); 150 | int setgroupent(int); 151 | int raise_default_signal(int); 152 | 153 | #ifndef __GLIBC__ 154 | quad_t strtoq(const char * __restrict, char ** __restrict, int); 155 | #endif 156 | 157 | __dead void errc(int, int, const char *, ...) 158 | __printflike(3, 4) __dead; 159 | __dead void verrc(int, int, const char *, va_list) 160 | __printflike(3, 0) __dead; 161 | intmax_t strtoimax(const char * __restrict, 162 | char ** __restrict, int); 163 | intmax_t strtoimax_l(const char * __restrict, 164 | char ** __restrict, int, locale_t); 165 | intmax_t strtoi(const char * __restrict, char ** __restrict, int, 166 | intmax_t, intmax_t, int *); 167 | uintmax_t strtou(const char * __restrict, char ** __restrict, int, 168 | uintmax_t, uintmax_t, int *); 169 | int vasprintf(char ** __restrict, const char * __restrict, 170 | __va_list) 171 | __printflike(2, 0); 172 | 173 | /* __OpenBSD */ 174 | #ifndef __GLIBC__ 175 | void *reallocarray(void *, size_t, size_t); 176 | #endif 177 | -------------------------------------------------------------------------------- /src/libnetbsd/_strtoul.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: _strtoul.h,v 1.11 2017/07/06 21:08:44 joerg Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1990, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * Original version ID: 32 | * NetBSD: src/lib/libc/locale/_wcstoul.h,v 1.2 2003/08/07 16:43:03 agc Exp 33 | */ 34 | 35 | /* 36 | * function template for strtoul, strtoull and strtoumax. 37 | * 38 | * parameters: 39 | * _FUNCNAME : function name 40 | * __UINT : return type 41 | * __UINT_MAX : upper limit of the return type 42 | */ 43 | 44 | 45 | #define _DIAGASSERT assert 46 | #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 47 | 48 | #if defined(_KERNEL) || defined(_STANDALONE) || \ 49 | defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY) 50 | __UINT 51 | _FUNCNAME(const char *nptr, char **endptr, int base) 52 | #else 53 | #include 54 | #include "setlocale_local.h" 55 | #define INT_FUNCNAME_(pre, name, post) pre ## name ## post 56 | #define INT_FUNCNAME(pre, name, post) INT_FUNCNAME_(pre, name, post) 57 | 58 | static __UINT 59 | INT_FUNCNAME(_int_, _FUNCNAME, _l)(const char *nptr, char **endptr, 60 | int base, locale_t loc) 61 | #endif 62 | { 63 | const char *s; 64 | __UINT acc, cutoff; 65 | unsigned char c; 66 | int i, neg, any, cutlim; 67 | 68 | _DIAGASSERT(nptr != NULL); 69 | /* endptr may be NULL */ 70 | 71 | /* check base value */ 72 | if (base && (base < 2 || base > 36)) { 73 | #if !defined(_KERNEL) && !defined(_STANDALONE) 74 | errno = EINVAL; 75 | if (endptr != NULL) 76 | /* LINTED interface specification */ 77 | *endptr = __UNCONST(nptr); 78 | return 0; 79 | #else 80 | panic("%s: invalid base %d", __func__, base); 81 | #endif 82 | } 83 | 84 | /* 85 | * Skip white space and pick up leading +/- sign if any. 86 | * If base is 0, allow 0x for hex and 0 for octal, else 87 | * assume decimal; if base is already 16, allow 0x. 88 | */ 89 | s = nptr; 90 | #if defined(_KERNEL) || defined(_STANDALONE) || \ 91 | defined(HAVE_NBTOOL_CONFIG_H) || defined(BCS_ONLY) 92 | do { 93 | c = *s++; 94 | } while (isspace(c)); 95 | #else 96 | do { 97 | c = *s++; 98 | } while (isspace_l(c, loc)); 99 | #endif 100 | if (c == '-') { 101 | neg = 1; 102 | c = *s++; 103 | } else { 104 | neg = 0; 105 | if (c == '+') 106 | c = *s++; 107 | } 108 | if ((base == 0 || base == 16) && 109 | c == '0' && (*s == 'x' || *s == 'X') && 110 | ((s[1] >= '0' && s[1] <= '9') || 111 | (s[1] >= 'a' && s[1] <= 'f') || 112 | (s[1] >= 'A' && s[1] <= 'F'))) { 113 | c = s[1]; 114 | s += 2; 115 | base = 16; 116 | #if 0 117 | } else if ((base == 0 || base == 2) && 118 | c == '0' && (*s == 'b' || *s == 'B') && 119 | (s[1] >= '0' && s[1] <= '1')) { 120 | c = s[1]; 121 | s += 2; 122 | base = 2; 123 | #endif 124 | } else if (base == 0) 125 | base = (c == '0' ? 8 : 10); 126 | 127 | /* 128 | * See strtol for comments as to the logic used. 129 | */ 130 | cutoff = ((__UINT)__UINT_MAX / (__UINT)base); 131 | cutlim = (int)((__UINT)__UINT_MAX % (__UINT)base); 132 | for (acc = 0, any = 0;; c = *s++) { 133 | if (c >= '0' && c <= '9') 134 | i = c - '0'; 135 | else if (c >= 'a' && c <= 'z') 136 | i = (c - 'a') + 10; 137 | else if (c >= 'A' && c <= 'Z') 138 | i = (c - 'A') + 10; 139 | else 140 | break; 141 | if (i >= base) 142 | break; 143 | if (any < 0) 144 | continue; 145 | if (acc > cutoff || (acc == cutoff && i > cutlim)) { 146 | acc = __UINT_MAX; 147 | #if !defined(_KERNEL) && !defined(_STANDALONE) 148 | any = -1; 149 | errno = ERANGE; 150 | #else 151 | any = 0; 152 | break; 153 | #endif 154 | } else { 155 | any = 1; 156 | acc *= (__UINT)base; 157 | acc += i; 158 | } 159 | } 160 | if (neg && any > 0) 161 | acc = -acc; 162 | if (endptr != NULL) 163 | /* LINTED interface specification */ 164 | *endptr = __UNCONST(any ? s - 1 : nptr); 165 | return(acc); 166 | } 167 | 168 | #if !defined(_KERNEL) && !defined(_STANDALONE) && \ 169 | !defined(HAVE_NBTOOL_CONFIG_H) && !defined(BCS_ONLY) 170 | __UINT 171 | _FUNCNAME(const char *nptr, char **endptr, int base) 172 | { 173 | //return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, _current_locale()); 174 | } 175 | 176 | __UINT 177 | INT_FUNCNAME(, _FUNCNAME, _l)(const char *nptr, char **endptr, int base, locale_t loc) 178 | { 179 | return INT_FUNCNAME(_int_, _FUNCNAME, _l)(nptr, endptr, base, loc); 180 | } 181 | #endif 182 | -------------------------------------------------------------------------------- /src/pax/tar.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: tar.h,v 1.10 2013/01/24 17:43:44 christos Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)tar.h 8.2 (Berkeley) 4/18/94 36 | */ 37 | 38 | /* 39 | * defines and data structures common to all tar formats 40 | */ 41 | #define CHK_LEN 8 /* length of checksum field */ 42 | #define TNMSZ 100 /* size of name field */ 43 | #ifdef _PAX_ 44 | #define NULLCNT 2 /* number of null blocks in trailer */ 45 | #define CHK_OFFSET 148 /* start of chksum field */ 46 | #define BLNKSUM 256L /* sum of checksum field using ' ' */ 47 | #endif /* _PAX_ */ 48 | 49 | /* 50 | * Values used in typeflag field in all tar formats 51 | * (only REGTYPE, LNKTYPE and SYMTYPE are used in old bsd tar headers) 52 | */ 53 | #define REGTYPE '0' /* Regular File */ 54 | #define AREGTYPE '\0' /* Regular File */ 55 | #define LNKTYPE '1' /* Link */ 56 | #define SYMTYPE '2' /* Symlink */ 57 | #define CHRTYPE '3' /* Character Special File */ 58 | #define BLKTYPE '4' /* Block Special File */ 59 | #define DIRTYPE '5' /* Directory */ 60 | #define FIFOTYPE '6' /* FIFO */ 61 | #define CONTTYPE '7' /* high perf file */ 62 | #define GLOBXTYPE 'g' /* global extended header */ 63 | #define FILEXTYPE 'x' /* file extended header */ 64 | 65 | /* 66 | * GNU tar compatibility; 67 | */ 68 | #define LONGLINKTYPE 'K' /* Long Symlink */ 69 | #define LONGNAMETYPE 'L' /* Long File */ 70 | 71 | /* 72 | * Mode field encoding of the different file types - values in octal 73 | */ 74 | #define TSUID 04000 /* Set UID on execution */ 75 | #define TSGID 02000 /* Set GID on execution */ 76 | #define TSVTX 01000 /* Reserved */ 77 | #define TUREAD 00400 /* Read by owner */ 78 | #define TUWRITE 00200 /* Write by owner */ 79 | #define TUEXEC 00100 /* Execute/Search by owner */ 80 | #define TGREAD 00040 /* Read by group */ 81 | #define TGWRITE 00020 /* Write by group */ 82 | #define TGEXEC 00010 /* Execute/Search by group */ 83 | #define TOREAD 00004 /* Read by other */ 84 | #define TOWRITE 00002 /* Write by other */ 85 | #define TOEXEC 00001 /* Execute/Search by other */ 86 | 87 | #ifdef _PAX_ 88 | /* 89 | * Pad with a bit mask, much faster than doing a mod but only works on powers 90 | * of 2. Macro below is for block of 512 bytes. 91 | */ 92 | #define TAR_PAD(x) ((512 - ((x) & 511)) & 511) 93 | #endif /* _PAX_ */ 94 | 95 | /* 96 | * structure of an old tar header as it appeared in BSD releases 97 | */ 98 | typedef struct { 99 | char name[TNMSZ]; /* name of entry */ 100 | char mode[8]; /* mode */ 101 | char uid[8]; /* uid */ 102 | char gid[8]; /* gid */ 103 | char size[12]; /* size */ 104 | char mtime[12]; /* modification time */ 105 | char chksum[CHK_LEN]; /* checksum */ 106 | char linkflag; /* norm, hard, or sym. */ 107 | char linkname[TNMSZ]; /* linked to name */ 108 | } HD_TAR; 109 | 110 | #ifdef _PAX_ 111 | /* 112 | * -o options for BSD tar to not write directories to the archive 113 | */ 114 | #define TAR_NODIR "nodir" 115 | #define TAR_OPTION "write_opt" 116 | 117 | /* 118 | * default device names 119 | */ 120 | extern char DEV_0[]; 121 | extern char DEV_1[]; 122 | extern char DEV_4[]; 123 | extern char DEV_5[]; 124 | extern char DEV_7[]; 125 | extern char DEV_8[]; 126 | #endif /* _PAX_ */ 127 | 128 | /* 129 | * Data Interchange Format - Extended tar header format - POSIX 1003.1-1990 130 | */ 131 | #define TPFSZ 155 132 | #define TMAGIC "ustar" /* ustar and a null */ 133 | #define TMAGLEN 6 134 | #define TVERSION "00" /* 00 and no null */ 135 | #define TVERSLEN 2 136 | 137 | typedef struct { 138 | char name[TNMSZ]; /* name of entry */ 139 | char mode[8]; /* mode */ 140 | char uid[8]; /* uid */ 141 | char gid[8]; /* gid */ 142 | char size[12]; /* size */ 143 | char mtime[12]; /* modification time */ 144 | char chksum[CHK_LEN]; /* checksum */ 145 | char typeflag; /* type of file. */ 146 | char linkname[TNMSZ]; /* linked to name */ 147 | char magic[TMAGLEN]; /* magic cookie */ 148 | char version[TVERSLEN]; /* version */ 149 | char uname[32]; /* ascii owner name */ 150 | char gname[32]; /* ascii group name */ 151 | char devmajor[8]; /* major device number */ 152 | char devminor[8]; /* minor device number */ 153 | char prefix[TPFSZ]; /* linked to name */ 154 | } HD_USTAR; 155 | -------------------------------------------------------------------------------- /src/pax/cpio.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: cpio.h,v 1.6 2003/10/13 07:41:22 agc Exp $ */ 2 | 3 | /*- 4 | * Copyright (c) 1992 Keith Muller. 5 | * Copyright (c) 1992, 1993 6 | * The Regents of the University of California. All rights reserved. 7 | * 8 | * This code is derived from software contributed to Berkeley by 9 | * Keith Muller of the University of California, San Diego. 10 | * 11 | * Redistribution and use in source and binary forms, with or without 12 | * modification, are permitted provided that the following conditions 13 | * are met: 14 | * 1. Redistributions of source code must retain the above copyright 15 | * notice, this list of conditions and the following disclaimer. 16 | * 2. Redistributions in binary form must reproduce the above copyright 17 | * notice, this list of conditions and the following disclaimer in the 18 | * documentation and/or other materials provided with the distribution. 19 | * 3. Neither the name of the University nor the names of its contributors 20 | * may be used to endorse or promote products derived from this software 21 | * without specific prior written permission. 22 | * 23 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33 | * SUCH DAMAGE. 34 | * 35 | * @(#)cpio.h 8.1 (Berkeley) 5/31/93 36 | */ 37 | 38 | /* 39 | * Defines common to all versions of cpio 40 | */ 41 | #define TRAILER "TRAILER!!!" /* name in last archive record */ 42 | 43 | /* 44 | * Header encoding of the different file types 45 | */ 46 | #define C_ISDIR 040000 /* Directory */ 47 | #define C_ISFIFO 010000 /* FIFO */ 48 | #define C_ISREG 0100000 /* Regular file */ 49 | #define C_ISBLK 060000 /* Block special file */ 50 | #define C_ISCHR 020000 /* Character special file */ 51 | #define C_ISCTG 0110000 /* Reserved for contiguous files */ 52 | #define C_ISLNK 0120000 /* Reserved for symbolic links */ 53 | #define C_ISOCK 0140000 /* Reserved for sockets */ 54 | #define C_IFMT 0170000 /* type of file */ 55 | 56 | /* 57 | * Data Interchange Format - Extended cpio header format - POSIX 1003.1-1990 58 | */ 59 | typedef struct { 60 | char c_magic[6]; /* magic cookie */ 61 | char c_dev[6]; /* device number */ 62 | char c_ino[6]; /* inode number */ 63 | char c_mode[6]; /* file type/access */ 64 | char c_uid[6]; /* owners uid */ 65 | char c_gid[6]; /* owners gid */ 66 | char c_nlink[6]; /* # of links at archive creation */ 67 | char c_rdev[6]; /* block/char major/minor # */ 68 | char c_mtime[11]; /* modification time */ 69 | char c_namesize[6]; /* length of pathname */ 70 | char c_filesize[11]; /* length of file in bytes */ 71 | } HD_CPIO; 72 | 73 | #define MAGIC 070707 /* transportable archive id */ 74 | 75 | #ifdef _PAX_ 76 | #define AMAGIC "070707" /* ascii equivalent string of MAGIC */ 77 | #define CPIO_MASK 0x3ffff /* bits valid in the dev/ino fields */ 78 | /* used for dev/inode remaps */ 79 | #endif /* _PAX_ */ 80 | 81 | /* 82 | * Binary cpio header structure 83 | * 84 | * CAUTION! CAUTION! CAUTION! 85 | * Each field really represents a 16 bit short (NOT ASCII). Described as 86 | * an array of chars in an attempt to improve portability!! 87 | */ 88 | typedef struct { 89 | u_char h_magic[2]; 90 | u_char h_dev[2]; 91 | u_char h_ino[2]; 92 | u_char h_mode[2]; 93 | u_char h_uid[2]; 94 | u_char h_gid[2]; 95 | u_char h_nlink[2]; 96 | u_char h_rdev[2]; 97 | u_char h_mtime_1[2]; 98 | u_char h_mtime_2[2]; 99 | u_char h_namesize[2]; 100 | u_char h_filesize_1[2]; 101 | u_char h_filesize_2[2]; 102 | } HD_BCPIO; 103 | 104 | #ifdef _PAX_ 105 | /* 106 | * extraction and creation macros for binary cpio 107 | */ 108 | #define SHRT_EXT(ch) ((((unsigned)(ch)[0])<<8) | (((unsigned)(ch)[1])&0xff)) 109 | #define RSHRT_EXT(ch) ((((unsigned)(ch)[1])<<8) | (((unsigned)(ch)[0])&0xff)) 110 | #define CHR_WR_0(val) ((char)(((val) >> 24) & 0xff)) 111 | #define CHR_WR_1(val) ((char)(((val) >> 16) & 0xff)) 112 | #define CHR_WR_2(val) ((char)(((val) >> 8) & 0xff)) 113 | #define CHR_WR_3(val) ((char)((val) & 0xff)) 114 | 115 | /* 116 | * binary cpio masks and pads 117 | */ 118 | #define BCPIO_PAD(x) ((2 - ((x) & 1)) & 1) /* pad to next 2 byte word */ 119 | #define BCPIO_MASK 0xffff /* mask for dev/ino fields */ 120 | #endif /* _PAX_ */ 121 | 122 | /* 123 | * System VR4 cpio header structure (with/without file data crc) 124 | */ 125 | typedef struct { 126 | char c_magic[6]; /* magic cookie */ 127 | char c_ino[8]; /* inode number */ 128 | char c_mode[8]; /* file type/access */ 129 | char c_uid[8]; /* owners uid */ 130 | char c_gid[8]; /* owners gid */ 131 | char c_nlink[8]; /* # of links at archive creation */ 132 | char c_mtime[8]; /* modification time */ 133 | char c_filesize[8]; /* length of file in bytes */ 134 | char c_maj[8]; /* block/char major # */ 135 | char c_min[8]; /* block/char minor # */ 136 | char c_rmaj[8]; /* special file major # */ 137 | char c_rmin[8]; /* special file minor # */ 138 | char c_namesize[8]; /* length of pathname */ 139 | char c_chksum[8]; /* 0 OR CRC of bytes of FILE data */ 140 | } HD_VCPIO; 141 | 142 | #define VMAGIC 070701 /* sVr4 new portable archive id */ 143 | #define VCMAGIC 070702 /* sVr4 new portable archive id CRC */ 144 | #ifdef _PAX_ 145 | #define AVMAGIC "070701" /* ascii string of above */ 146 | #define AVCMAGIC "070702" /* ascii string of above */ 147 | #define VCPIO_PAD(x) ((4 - ((x) & 3)) & 3) /* pad to next 4 byte word */ 148 | #define VCPIO_MASK 0xffffffff /* mask for dev/ino fields */ 149 | #endif /* _PAX_ */ 150 | -------------------------------------------------------------------------------- /include/fts.h: -------------------------------------------------------------------------------- 1 | /* $NetBSD: fts.h,v 1.19 2009/08/16 19:33:38 christos Exp $ */ 2 | 3 | /* 4 | * Copyright (c) 1989, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | * 31 | * @(#)fts.h 8.3 (Berkeley) 8/14/94 32 | */ 33 | 34 | #include 35 | #include 36 | 37 | #ifndef _FTS_H_ 38 | #define _FTS_H_ 39 | 40 | #ifndef __fts_stat_t 41 | #define __fts_stat_t struct stat 42 | #endif 43 | #ifndef __fts_nlink_t 44 | #define __fts_nlink_t nlink_t 45 | #endif 46 | #ifndef __fts_ino_t 47 | #define __fts_ino_t ino_t 48 | #endif 49 | #ifndef __fts_length_t 50 | #define __fts_length_t unsigned int 51 | #endif 52 | #ifndef __fts_number_t 53 | #define __fts_number_t int64_t 54 | #endif 55 | #ifndef __fts_dev_t 56 | #define __fts_dev_t dev_t 57 | #endif 58 | #ifndef __fts_level_t 59 | #define __fts_level_t int 60 | #endif 61 | 62 | typedef struct { 63 | struct _ftsent *fts_cur; /* current node */ 64 | struct _ftsent *fts_child; /* linked list of children */ 65 | struct _ftsent **fts_array; /* sort array */ 66 | dev_t fts_dev; /* starting device # */ 67 | char *fts_path; /* path for this descent */ 68 | int fts_rfd; /* fd for root */ 69 | unsigned int fts_pathlen; /* sizeof(path) */ 70 | unsigned int fts_nitems; /* elements in the sort array */ 71 | int (*fts_compar) /* compare function */ 72 | (const struct _ftsent **, const struct _ftsent **); 73 | 74 | #define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ 75 | #define FTS_LOGICAL 0x002 /* logical walk */ 76 | #define FTS_NOCHDIR 0x004 /* don't change directories */ 77 | #define FTS_NOSTAT 0x008 /* don't get stat info */ 78 | #define FTS_PHYSICAL 0x010 /* physical walk */ 79 | #define FTS_SEEDOT 0x020 /* return dot and dot-dot */ 80 | #define FTS_XDEV 0x040 /* don't cross devices */ 81 | #define FTS_WHITEOUT 0x080 /* return whiteout information */ 82 | #define FTS_OPTIONMASK 0x0ff /* valid user option mask */ 83 | 84 | #define FTS_NAMEONLY 0x100 /* (private) child names only */ 85 | #define FTS_STOP 0x200 /* (private) unrecoverable error */ 86 | int fts_options; /* fts_open options, global flags */ 87 | } FTS; 88 | 89 | typedef struct _ftsent { 90 | struct _ftsent *fts_cycle; /* cycle node */ 91 | struct _ftsent *fts_parent; /* parent directory */ 92 | struct _ftsent *fts_link; /* next file in directory */ 93 | __fts_number_t fts_number; /* local numeric value */ 94 | void *fts_pointer; /* local address value */ 95 | char *fts_accpath; /* access path */ 96 | char *fts_path; /* root path */ 97 | int fts_errno; /* errno for this node */ 98 | int fts_symfd; /* fd for symlink */ 99 | __fts_length_t fts_pathlen; /* strlen(fts_path) */ 100 | __fts_length_t fts_namelen; /* strlen(fts_name) */ 101 | 102 | __fts_ino_t fts_ino; /* inode */ 103 | __fts_dev_t fts_dev; /* device */ 104 | __fts_nlink_t fts_nlink; /* link count */ 105 | 106 | #define FTS_ROOTPARENTLEVEL -1 107 | #define FTS_ROOTLEVEL 0 108 | __fts_level_t fts_level; /* depth (-1 to N) */ 109 | 110 | #define FTS_D 1 /* preorder directory */ 111 | #define FTS_DC 2 /* directory that causes cycles */ 112 | #define FTS_DEFAULT 3 /* none of the above */ 113 | #define FTS_DNR 4 /* unreadable directory */ 114 | #define FTS_DOT 5 /* dot or dot-dot */ 115 | #define FTS_DP 6 /* postorder directory */ 116 | #define FTS_ERR 7 /* error; errno is set */ 117 | #define FTS_F 8 /* regular file */ 118 | #define FTS_INIT 9 /* initialized only */ 119 | #define FTS_NS 10 /* stat(2) failed */ 120 | #define FTS_NSOK 11 /* no stat(2) requested */ 121 | #define FTS_SL 12 /* symbolic link */ 122 | #define FTS_SLNONE 13 /* symbolic link without target */ 123 | #define FTS_W 14 /* whiteout object */ 124 | unsigned short fts_info; /* user flags for FTSENT structure */ 125 | 126 | #define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ 127 | #define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ 128 | #define FTS_ISW 0x04 /* this is a whiteout object */ 129 | unsigned short fts_flags; /* private flags for FTSENT structure */ 130 | 131 | #define FTS_AGAIN 1 /* read node again */ 132 | #define FTS_FOLLOW 2 /* follow symbolic link */ 133 | #define FTS_NOINSTR 3 /* no instructions */ 134 | #define FTS_SKIP 4 /* discard node */ 135 | unsigned short fts_instr; /* fts_set() instructions */ 136 | 137 | __fts_stat_t *fts_statp; /* stat(2) information */ 138 | char fts_name[1]; /* file name */ 139 | } FTSENT; 140 | 141 | FTSENT *fts_children(FTS *, int); 142 | int fts_close(FTS *); 143 | FTS *fts_open(char * const *, int, 144 | int (*)(const FTSENT **, const FTSENT **)); 145 | FTSENT *fts_read(FTS *); 146 | int fts_set(FTS *, FTSENT *, int); 147 | 148 | #endif /* !_FTS_H_ */ 149 | -------------------------------------------------------------------------------- /difference/find.patch: -------------------------------------------------------------------------------- 1 | diff -ruN netbsd/usr.bin/find/extern.h find/extern.h 2 | --- netbsd/usr.bin/find/extern.h 2020-04-10 23:58:13.512335998 +0900 3 | +++ find/extern.h 2020-04-12 21:10:18.390139676 +0900 4 | @@ -31,7 +31,7 @@ 5 | * from: @(#)extern.h 8.3 (Berkeley) 4/16/94 6 | */ 7 | 8 | -#include 9 | +//#include 10 | 11 | void brace_subst(char *, char **, char *, int *); 12 | PLAN *find_create(char ***); 13 | diff -ruN netbsd/usr.bin/find/find.c find/find.c 14 | --- netbsd/usr.bin/find/find.c 2020-04-10 23:58:13.512335998 +0900 15 | +++ find/find.c 2020-04-12 21:10:18.390139676 +0900 16 | @@ -32,15 +32,6 @@ 17 | * SUCH DAMAGE. 18 | */ 19 | 20 | -#include 21 | -#ifndef lint 22 | -#if 0 23 | -static char sccsid[] = "from: @(#)find.c 8.5 (Berkeley) 8/5/94"; 24 | -#else 25 | -__RCSID("$NetBSD: find.c,v 1.30 2016/06/13 00:04:40 pgoyette Exp $"); 26 | -#endif 27 | -#endif /* not lint */ 28 | - 29 | #include 30 | #include 31 | 32 | @@ -53,6 +44,7 @@ 33 | #include 34 | #include 35 | #include 36 | +#include 37 | 38 | #include "find.h" 39 | 40 | diff -ruN netbsd/usr.bin/find/function.c find/function.c 41 | --- netbsd/usr.bin/find/function.c 2020-04-10 23:58:13.513335998 +0900 42 | +++ find/function.c 2020-04-12 22:34:27.699239815 +0900 43 | @@ -32,17 +32,9 @@ 44 | * SUCH DAMAGE. 45 | */ 46 | 47 | -#include 48 | -#ifndef lint 49 | -#if 0 50 | -static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; 51 | -#else 52 | -__RCSID("$NetBSD: function.c,v 1.77 2018/09/04 15:16:15 kre Exp $"); 53 | -#endif 54 | -#endif /* not lint */ 55 | - 56 | #include 57 | #include 58 | +#include 59 | #include 60 | #include 61 | 62 | @@ -61,7 +53,7 @@ 63 | #include 64 | #include 65 | #include 66 | -#include 67 | +#include 68 | 69 | #include "find.h" 70 | 71 | @@ -78,6 +70,16 @@ 72 | } \ 73 | } 74 | 75 | +struct netbsd_statvfs { 76 | + struct statvfs buf; 77 | + unsigned long f_flag; 78 | + char f_fstypename[_VFS_NAMELEN]; 79 | +}; 80 | + 81 | +#define statvfs netbsd_statvfs 82 | + 83 | +int statvfs(const char *__restrict, struct statvfs *__restrict); 84 | + 85 | static int64_t find_parsenum(PLAN *, const char *, const char *, char *); 86 | static void run_f_exec(PLAN *); 87 | int f_always_true(PLAN *, FTSENT *); 88 | @@ -469,12 +471,14 @@ 89 | errx(1, "-delete: %s: relative path potentially not safe", 90 | entry->fts_accpath); 91 | 92 | +#if 0 93 | /* Turn off user immutable bits if running as root */ 94 | if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) && 95 | !(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) && 96 | geteuid() == 0) 97 | chflags(entry->fts_accpath, 98 | entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); 99 | +#endif 100 | 101 | /* rmdir directories, unlink everything else */ 102 | if (S_ISDIR(entry->fts_statp->st_mode)) { 103 | @@ -962,7 +966,7 @@ 104 | { 105 | u_int32_t flags; 106 | 107 | - flags = entry->fts_statp->st_flags; 108 | + flags = entry->fts_statp; 109 | if (plan->flags == F_ATLEAST) 110 | return ((plan->f_data | flags) == flags); 111 | else 112 | diff -ruN netbsd/usr.bin/find/ls.c find/ls.c 113 | --- netbsd/usr.bin/find/ls.c 2020-04-10 23:58:13.513335998 +0900 114 | +++ find/ls.c 2020-04-12 21:10:18.390139676 +0900 115 | @@ -29,17 +29,9 @@ 116 | * SUCH DAMAGE. 117 | */ 118 | 119 | -#include 120 | -#ifndef lint 121 | -#if 0 122 | -static char sccsid[] = "from: @(#)ls.c 8.1 (Berkeley) 6/6/93"; 123 | -#else 124 | -__RCSID("$NetBSD: ls.c,v 1.21 2011/08/31 16:24:57 plunky Exp $"); 125 | -#endif 126 | -#endif /* not lint */ 127 | - 128 | #include 129 | #include 130 | +#include 131 | 132 | #include 133 | #include 134 | @@ -52,6 +44,7 @@ 135 | #include 136 | #include 137 | #include 138 | +#include 139 | 140 | #include "find.h" 141 | 142 | diff -ruN netbsd/usr.bin/find/main.c find/main.c 143 | --- netbsd/usr.bin/find/main.c 2020-04-10 23:58:13.513335998 +0900 144 | +++ find/main.c 2020-04-12 21:10:18.391139676 +0900 145 | @@ -32,17 +32,6 @@ 146 | * SUCH DAMAGE. 147 | */ 148 | 149 | -#include 150 | -#ifndef lint 151 | -#if 0 152 | -static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; 153 | -#else 154 | -__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\ 155 | - The Regents of the University of California. All rights reserved."); 156 | -__RCSID("$NetBSD: main.c,v 1.31 2013/01/24 17:50:08 christos Exp $"); 157 | -#endif 158 | -#endif /* not lint */ 159 | - 160 | #include 161 | #include 162 | 163 | @@ -56,6 +45,7 @@ 164 | #include 165 | #include 166 | #include 167 | +#include 168 | 169 | #include "find.h" 170 | 171 | diff -ruN netbsd/usr.bin/find/misc.c find/misc.c 172 | --- netbsd/usr.bin/find/misc.c 2020-04-10 23:58:13.513335998 +0900 173 | +++ find/misc.c 2020-04-12 21:10:18.391139676 +0900 174 | @@ -32,15 +32,6 @@ 175 | * SUCH DAMAGE. 176 | */ 177 | 178 | -#include 179 | -#ifndef lint 180 | -#if 0 181 | -static char sccsid[] = "from: @(#)misc.c 8.2 (Berkeley) 4/1/94"; 182 | -#else 183 | -__RCSID("$NetBSD: misc.c,v 1.14 2006/10/11 19:51:10 apb Exp $"); 184 | -#endif 185 | -#endif /* not lint */ 186 | - 187 | #include 188 | #include 189 | 190 | diff -ruN netbsd/usr.bin/find/operator.c find/operator.c 191 | --- netbsd/usr.bin/find/operator.c 2020-04-10 23:58:13.513335998 +0900 192 | +++ find/operator.c 2020-04-12 21:10:18.391139676 +0900 193 | @@ -32,15 +32,6 @@ 194 | * SUCH DAMAGE. 195 | */ 196 | 197 | -#include 198 | -#ifndef lint 199 | -#if 0 200 | -static char sccsid[] = "from: @(#)operator.c 8.1 (Berkeley) 6/6/93"; 201 | -#else 202 | -__RCSID("$NetBSD: operator.c,v 1.10 2014/10/18 08:33:30 snj Exp $"); 203 | -#endif 204 | -#endif /* not lint */ 205 | - 206 | #include 207 | 208 | #include 209 | diff -ruN netbsd/usr.bin/find/option.c find/option.c 210 | --- netbsd/usr.bin/find/option.c 2020-04-10 23:58:13.513335998 +0900 211 | +++ find/option.c 2020-04-12 21:10:18.391139676 +0900 212 | @@ -32,15 +32,6 @@ 213 | * SUCH DAMAGE. 214 | */ 215 | 216 | -#include 217 | -#ifndef lint 218 | -#if 0 219 | -static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94"; 220 | -#else 221 | -__RCSID("$NetBSD: option.c,v 1.27 2016/06/13 00:04:40 pgoyette Exp $"); 222 | -#endif 223 | -#endif /* not lint */ 224 | - 225 | #include 226 | #include 227 | 228 | --------------------------------------------------------------------------------