diff options
Diffstat (limited to 'other/ssharp/openbsd-compat')
70 files changed, 6794 insertions, 0 deletions
diff --git a/other/ssharp/openbsd-compat/CVS/Entries b/other/ssharp/openbsd-compat/CVS/Entries new file mode 100644 index 0000000..1b578be --- /dev/null +++ b/other/ssharp/openbsd-compat/CVS/Entries | |||
| @@ -0,0 +1,67 @@ | |||
| 1 | /Makefile.in/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 2 | /base64.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 3 | /base64.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 4 | /bindresvport.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 5 | /bindresvport.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 6 | /bsd-arc4random.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 7 | /bsd-arc4random.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 8 | /bsd-cygwin_util.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 9 | /bsd-cygwin_util.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 10 | /bsd-misc.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 11 | /bsd-misc.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 12 | /bsd-nextstep.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 13 | /bsd-nextstep.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 14 | /bsd-snprintf.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 15 | /bsd-snprintf.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 16 | /bsd-waitpid.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 17 | /bsd-waitpid.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 18 | /daemon.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 19 | /daemon.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 20 | /fake-gai-errnos.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 21 | /fake-getaddrinfo.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 22 | /fake-getaddrinfo.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 23 | /fake-getnameinfo.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 24 | /fake-getnameinfo.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 25 | /fake-queue.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 26 | /fake-regex.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 27 | /fake-socket.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 28 | /getcwd.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 29 | /getcwd.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 30 | /getgrouplist.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 31 | /getgrouplist.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 32 | /getusershell.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 33 | /getusershell.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 34 | /glob.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 35 | /glob.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 36 | /inet_aton.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 37 | /inet_aton.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 38 | /inet_ntoa.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 39 | /inet_ntoa.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 40 | /inet_ntop.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 41 | /inet_ntop.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 42 | /mktemp.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 43 | /mktemp.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 44 | /openbsd-compat.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 45 | /realpath.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 46 | /realpath.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 47 | /rresvport.c/1.3/Wed Sep 26 16:03:10 2001//Trel-0-51 | ||
| 48 | /rresvport.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 49 | /setenv.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 50 | /setenv.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 51 | /setproctitle.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 52 | /setproctitle.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 53 | /sigact.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 54 | /sigact.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 55 | /strlcat.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 56 | /strlcat.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 57 | /strlcpy.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 58 | /strlcpy.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 59 | /strmode.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 60 | /strmode.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 61 | /strsep.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 62 | /strsep.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 63 | /strtok.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 64 | /strtok.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 65 | /vis.c/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 66 | /vis.h/1.1.1.1/Wed Sep 19 14:44:59 2001//Trel-0-51 | ||
| 67 | D | ||
diff --git a/other/ssharp/openbsd-compat/CVS/Repository b/other/ssharp/openbsd-compat/CVS/Repository new file mode 100644 index 0000000..e73c637 --- /dev/null +++ b/other/ssharp/openbsd-compat/CVS/Repository | |||
| @@ -0,0 +1 @@ | |||
| ssharp/openbsd-compat | |||
diff --git a/other/ssharp/openbsd-compat/CVS/Root b/other/ssharp/openbsd-compat/CVS/Root new file mode 100644 index 0000000..3811072 --- /dev/null +++ b/other/ssharp/openbsd-compat/CVS/Root | |||
| @@ -0,0 +1 @@ | |||
| /cvs | |||
diff --git a/other/ssharp/openbsd-compat/CVS/Tag b/other/ssharp/openbsd-compat/CVS/Tag new file mode 100644 index 0000000..00329bf --- /dev/null +++ b/other/ssharp/openbsd-compat/CVS/Tag | |||
| @@ -0,0 +1 @@ | |||
| Nrel-0-51 | |||
diff --git a/other/ssharp/openbsd-compat/Makefile.in b/other/ssharp/openbsd-compat/Makefile.in new file mode 100644 index 0000000..0e99d8e --- /dev/null +++ b/other/ssharp/openbsd-compat/Makefile.in | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | # $Id: Makefile.in,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ | ||
| 2 | |||
| 3 | sysconfdir=@sysconfdir@ | ||
| 4 | piddir=@piddir@ | ||
| 5 | srcdir=@srcdir@ | ||
| 6 | top_srcdir=@top_srcdir@ | ||
| 7 | |||
| 8 | VPATH=@srcdir@ | ||
| 9 | CC=@CC@ | ||
| 10 | LD=@LD@ | ||
| 11 | CFLAGS=@CFLAGS@ | ||
| 12 | CPPFLAGS=-I. -I.. -I$(srcdir) -I$(srcdir)/.. @CPPFLAGS@ @DEFS@ | ||
| 13 | LIBS=@LIBS@ | ||
| 14 | AR=@AR@ | ||
| 15 | RANLIB=@RANLIB@ | ||
| 16 | INSTALL=@INSTALL@ | ||
| 17 | LDFLAGS=-L. @LDFLAGS@ | ||
| 18 | |||
| 19 | OPENBSD=base64.o bindresvport.o daemon.o getcwd.o getgrouplist.o getusershell.o glob.o inet_aton.o inet_ntoa.o inet_ntop.o mktemp.o realpath.o rresvport.o setenv.o setproctitle.o sigact.o strlcat.o strlcpy.o strmode.o strsep.o strtok.o vis.o | ||
| 20 | |||
| 21 | COMPAT=bsd-arc4random.o bsd-cygwin_util.o bsd-misc.o bsd-nextstep.o bsd-snprintf.o bsd-waitpid.o fake-getaddrinfo.o fake-getnameinfo.o | ||
| 22 | |||
| 23 | .c.o: | ||
| 24 | $(CC) $(CFLAGS) $(CPPFLAGS) -c $< | ||
| 25 | |||
| 26 | all: libopenbsd-compat.a | ||
| 27 | |||
| 28 | $(COMPAT): ../config.h | ||
| 29 | $(OPENBSD): ../config.h | ||
| 30 | |||
| 31 | libopenbsd-compat.a: $(COMPAT) $(OPENBSD) | ||
| 32 | $(AR) rv $@ $(COMPAT) $(OPENBSD) | ||
| 33 | $(RANLIB) $@ | ||
| 34 | |||
| 35 | clean: | ||
| 36 | rm -f *.o *.a core | ||
| 37 | |||
| 38 | distclean: clean | ||
| 39 | rm -f Makefile *~ | ||
diff --git a/other/ssharp/openbsd-compat/base64.c b/other/ssharp/openbsd-compat/base64.c new file mode 100644 index 0000000..d12b993 --- /dev/null +++ b/other/ssharp/openbsd-compat/base64.c | |||
| @@ -0,0 +1,316 @@ | |||
| 1 | /* $OpenBSD: base64.c,v 1.3 1997/11/08 20:46:55 deraadt Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1996 by Internet Software Consortium. | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this software for any | ||
| 7 | * purpose with or without fee is hereby granted, provided that the above | ||
| 8 | * copyright notice and this permission notice appear in all copies. | ||
| 9 | * | ||
| 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
| 11 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
| 12 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
| 13 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
| 14 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
| 15 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
| 16 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
| 17 | * SOFTWARE. | ||
| 18 | */ | ||
| 19 | |||
| 20 | /* | ||
| 21 | * Portions Copyright (c) 1995 by International Business Machines, Inc. | ||
| 22 | * | ||
| 23 | * International Business Machines, Inc. (hereinafter called IBM) grants | ||
| 24 | * permission under its copyrights to use, copy, modify, and distribute this | ||
| 25 | * Software with or without fee, provided that the above copyright notice and | ||
| 26 | * all paragraphs of this notice appear in all copies, and that the name of IBM | ||
| 27 | * not be used in connection with the marketing of any product incorporating | ||
| 28 | * the Software or modifications thereof, without specific, written prior | ||
| 29 | * permission. | ||
| 30 | * | ||
| 31 | * To the extent it has a right to do so, IBM grants an immunity from suit | ||
| 32 | * under its patents, if any, for the use, sale or manufacture of products to | ||
| 33 | * the extent that such products are used for performing Domain Name System | ||
| 34 | * dynamic updates in TCP/IP networks by means of the Software. No immunity is | ||
| 35 | * granted for any product per se or for any other function of any product. | ||
| 36 | * | ||
| 37 | * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, | ||
| 38 | * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
| 39 | * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, | ||
| 40 | * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING | ||
| 41 | * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN | ||
| 42 | * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. | ||
| 43 | */ | ||
| 44 | |||
| 45 | #include "config.h" | ||
| 46 | |||
| 47 | #if !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) | ||
| 48 | |||
| 49 | #include <sys/types.h> | ||
| 50 | #include <sys/param.h> | ||
| 51 | #include <sys/socket.h> | ||
| 52 | #include <netinet/in.h> | ||
| 53 | #include <arpa/inet.h> | ||
| 54 | |||
| 55 | #include <ctype.h> | ||
| 56 | #include <stdio.h> | ||
| 57 | |||
| 58 | #include <stdlib.h> | ||
| 59 | #include <string.h> | ||
| 60 | |||
| 61 | #include "base64.h" | ||
| 62 | |||
| 63 | #define Assert(Cond) if (!(Cond)) abort() | ||
| 64 | |||
| 65 | static const char Base64[] = | ||
| 66 | "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
| 67 | static const char Pad64 = '='; | ||
| 68 | |||
| 69 | /* (From RFC1521 and draft-ietf-dnssec-secext-03.txt) | ||
| 70 | The following encoding technique is taken from RFC 1521 by Borenstein | ||
| 71 | and Freed. It is reproduced here in a slightly edited form for | ||
| 72 | convenience. | ||
| 73 | |||
| 74 | A 65-character subset of US-ASCII is used, enabling 6 bits to be | ||
| 75 | represented per printable character. (The extra 65th character, "=", | ||
| 76 | is used to signify a special processing function.) | ||
| 77 | |||
| 78 | The encoding process represents 24-bit groups of input bits as output | ||
| 79 | strings of 4 encoded characters. Proceeding from left to right, a | ||
| 80 | 24-bit input group is formed by concatenating 3 8-bit input groups. | ||
| 81 | These 24 bits are then treated as 4 concatenated 6-bit groups, each | ||
| 82 | of which is translated into a single digit in the base64 alphabet. | ||
| 83 | |||
| 84 | Each 6-bit group is used as an index into an array of 64 printable | ||
| 85 | characters. The character referenced by the index is placed in the | ||
| 86 | output string. | ||
| 87 | |||
| 88 | Table 1: The Base64 Alphabet | ||
| 89 | |||
| 90 | Value Encoding Value Encoding Value Encoding Value Encoding | ||
| 91 | 0 A 17 R 34 i 51 z | ||
| 92 | 1 B 18 S 35 j 52 0 | ||
| 93 | 2 C 19 T 36 k 53 1 | ||
| 94 | 3 D 20 U 37 l 54 2 | ||
| 95 | 4 E 21 V 38 m 55 3 | ||
| 96 | 5 F 22 W 39 n 56 4 | ||
| 97 | 6 G 23 X 40 o 57 5 | ||
| 98 | 7 H 24 Y 41 p 58 6 | ||
| 99 | 8 I 25 Z 42 q 59 7 | ||
| 100 | 9 J 26 a 43 r 60 8 | ||
| 101 | 10 K 27 b 44 s 61 9 | ||
| 102 | 11 L 28 c 45 t 62 + | ||
| 103 | 12 M 29 d 46 u 63 / | ||
| 104 | 13 N 30 e 47 v | ||
| 105 | 14 O 31 f 48 w (pad) = | ||
| 106 | 15 P 32 g 49 x | ||
| 107 | 16 Q 33 h 50 y | ||
| 108 | |||
| 109 | Special processing is performed if fewer than 24 bits are available | ||
| 110 | at the end of the data being encoded. A full encoding quantum is | ||
| 111 | always completed at the end of a quantity. When fewer than 24 input | ||
| 112 | bits are available in an input group, zero bits are added (on the | ||
| 113 | right) to form an integral number of 6-bit groups. Padding at the | ||
| 114 | end of the data is performed using the '=' character. | ||
| 115 | |||
| 116 | Since all base64 input is an integral number of octets, only the | ||
| 117 | ------------------------------------------------- | ||
| 118 | following cases can arise: | ||
| 119 | |||
| 120 | (1) the final quantum of encoding input is an integral | ||
| 121 | multiple of 24 bits; here, the final unit of encoded | ||
| 122 | output will be an integral multiple of 4 characters | ||
| 123 | with no "=" padding, | ||
| 124 | (2) the final quantum of encoding input is exactly 8 bits; | ||
| 125 | here, the final unit of encoded output will be two | ||
| 126 | characters followed by two "=" padding characters, or | ||
| 127 | (3) the final quantum of encoding input is exactly 16 bits; | ||
| 128 | here, the final unit of encoded output will be three | ||
| 129 | characters followed by one "=" padding character. | ||
| 130 | */ | ||
| 131 | |||
| 132 | int | ||
| 133 | b64_ntop(u_char const *src, size_t srclength, char *target, size_t targsize) | ||
| 134 | { | ||
| 135 | size_t datalength = 0; | ||
| 136 | u_char input[3]; | ||
| 137 | u_char output[4]; | ||
| 138 | int i; | ||
| 139 | |||
| 140 | while (2 < srclength) { | ||
| 141 | input[0] = *src++; | ||
| 142 | input[1] = *src++; | ||
| 143 | input[2] = *src++; | ||
| 144 | srclength -= 3; | ||
| 145 | |||
| 146 | output[0] = input[0] >> 2; | ||
| 147 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | ||
| 148 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | ||
| 149 | output[3] = input[2] & 0x3f; | ||
| 150 | Assert(output[0] < 64); | ||
| 151 | Assert(output[1] < 64); | ||
| 152 | Assert(output[2] < 64); | ||
| 153 | Assert(output[3] < 64); | ||
| 154 | |||
| 155 | if (datalength + 4 > targsize) | ||
| 156 | return (-1); | ||
| 157 | target[datalength++] = Base64[output[0]]; | ||
| 158 | target[datalength++] = Base64[output[1]]; | ||
| 159 | target[datalength++] = Base64[output[2]]; | ||
| 160 | target[datalength++] = Base64[output[3]]; | ||
| 161 | } | ||
| 162 | |||
| 163 | /* Now we worry about padding. */ | ||
| 164 | if (0 != srclength) { | ||
| 165 | /* Get what's left. */ | ||
| 166 | input[0] = input[1] = input[2] = '\0'; | ||
| 167 | for (i = 0; i < srclength; i++) | ||
| 168 | input[i] = *src++; | ||
| 169 | |||
| 170 | output[0] = input[0] >> 2; | ||
| 171 | output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4); | ||
| 172 | output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6); | ||
| 173 | Assert(output[0] < 64); | ||
| 174 | Assert(output[1] < 64); | ||
| 175 | Assert(output[2] < 64); | ||
| 176 | |||
| 177 | if (datalength + 4 > targsize) | ||
| 178 | return (-1); | ||
| 179 | target[datalength++] = Base64[output[0]]; | ||
| 180 | target[datalength++] = Base64[output[1]]; | ||
| 181 | if (srclength == 1) | ||
| 182 | target[datalength++] = Pad64; | ||
| 183 | else | ||
| 184 | target[datalength++] = Base64[output[2]]; | ||
| 185 | target[datalength++] = Pad64; | ||
| 186 | } | ||
| 187 | if (datalength >= targsize) | ||
| 188 | return (-1); | ||
| 189 | target[datalength] = '\0'; /* Returned value doesn't count \0. */ | ||
| 190 | return (datalength); | ||
| 191 | } | ||
| 192 | |||
| 193 | /* skips all whitespace anywhere. | ||
| 194 | converts characters, four at a time, starting at (or after) | ||
| 195 | src from base - 64 numbers into three 8 bit bytes in the target area. | ||
| 196 | it returns the number of data bytes stored at the target, or -1 on error. | ||
| 197 | */ | ||
| 198 | |||
| 199 | int | ||
| 200 | b64_pton(char const *src, u_char *target, size_t targsize) | ||
| 201 | { | ||
| 202 | int tarindex, state, ch; | ||
| 203 | char *pos; | ||
| 204 | |||
| 205 | state = 0; | ||
| 206 | tarindex = 0; | ||
| 207 | |||
| 208 | while ((ch = *src++) != '\0') { | ||
| 209 | if (isspace(ch)) /* Skip whitespace anywhere. */ | ||
| 210 | continue; | ||
| 211 | |||
| 212 | if (ch == Pad64) | ||
| 213 | break; | ||
| 214 | |||
| 215 | pos = strchr(Base64, ch); | ||
| 216 | if (pos == 0) /* A non-base64 character. */ | ||
| 217 | return (-1); | ||
| 218 | |||
| 219 | switch (state) { | ||
| 220 | case 0: | ||
| 221 | if (target) { | ||
| 222 | if (tarindex >= targsize) | ||
| 223 | return (-1); | ||
| 224 | target[tarindex] = (pos - Base64) << 2; | ||
| 225 | } | ||
| 226 | state = 1; | ||
| 227 | break; | ||
| 228 | case 1: | ||
| 229 | if (target) { | ||
| 230 | if (tarindex + 1 >= targsize) | ||
| 231 | return (-1); | ||
| 232 | target[tarindex] |= (pos - Base64) >> 4; | ||
| 233 | target[tarindex+1] = ((pos - Base64) & 0x0f) | ||
| 234 | << 4 ; | ||
| 235 | } | ||
| 236 | tarindex++; | ||
| 237 | state = 2; | ||
| 238 | break; | ||
| 239 | case 2: | ||
| 240 | if (target) { | ||
| 241 | if (tarindex + 1 >= targsize) | ||
| 242 | return (-1); | ||
| 243 | target[tarindex] |= (pos - Base64) >> 2; | ||
| 244 | target[tarindex+1] = ((pos - Base64) & 0x03) | ||
| 245 | << 6; | ||
| 246 | } | ||
| 247 | tarindex++; | ||
| 248 | state = 3; | ||
| 249 | break; | ||
| 250 | case 3: | ||
| 251 | if (target) { | ||
| 252 | if (tarindex >= targsize) | ||
| 253 | return (-1); | ||
| 254 | target[tarindex] |= (pos - Base64); | ||
| 255 | } | ||
| 256 | tarindex++; | ||
| 257 | state = 0; | ||
| 258 | break; | ||
| 259 | } | ||
| 260 | } | ||
| 261 | |||
| 262 | /* | ||
| 263 | * We are done decoding Base-64 chars. Let's see if we ended | ||
| 264 | * on a byte boundary, and/or with erroneous trailing characters. | ||
| 265 | */ | ||
| 266 | |||
| 267 | if (ch == Pad64) { /* We got a pad char. */ | ||
| 268 | ch = *src++; /* Skip it, get next. */ | ||
| 269 | switch (state) { | ||
| 270 | case 0: /* Invalid = in first position */ | ||
| 271 | case 1: /* Invalid = in second position */ | ||
| 272 | return (-1); | ||
| 273 | |||
| 274 | case 2: /* Valid, means one byte of info */ | ||
| 275 | /* Skip any number of spaces. */ | ||
| 276 | for (; ch != '\0'; ch = *src++) | ||
| 277 | if (!isspace(ch)) | ||
| 278 | break; | ||
| 279 | /* Make sure there is another trailing = sign. */ | ||
| 280 | if (ch != Pad64) | ||
| 281 | return (-1); | ||
| 282 | ch = *src++; /* Skip the = */ | ||
| 283 | /* Fall through to "single trailing =" case. */ | ||
| 284 | /* FALLTHROUGH */ | ||
| 285 | |||
| 286 | case 3: /* Valid, means two bytes of info */ | ||
| 287 | /* | ||
| 288 | * We know this char is an =. Is there anything but | ||
| 289 | * whitespace after it? | ||
| 290 | */ | ||
| 291 | for (; ch != '\0'; ch = *src++) | ||
| 292 | if (!isspace(ch)) | ||
| 293 | return (-1); | ||
| 294 | |||
| 295 | /* | ||
| 296 | * Now make sure for cases 2 and 3 that the "extra" | ||
| 297 | * bits that slopped past the last full byte were | ||
| 298 | * zeros. If we don't check them, they become a | ||
| 299 | * subliminal channel. | ||
| 300 | */ | ||
| 301 | if (target && target[tarindex] != 0) | ||
| 302 | return (-1); | ||
| 303 | } | ||
| 304 | } else { | ||
| 305 | /* | ||
| 306 | * We ended by seeing the end of the string. Make sure we | ||
| 307 | * have no partial bytes lying around. | ||
| 308 | */ | ||
| 309 | if (state != 0) | ||
| 310 | return (-1); | ||
| 311 | } | ||
| 312 | |||
| 313 | return (tarindex); | ||
| 314 | } | ||
| 315 | |||
| 316 | #endif /* !defined(HAVE_B64_NTOP) && !defined(HAVE___B64_NTOP) */ | ||
diff --git a/other/ssharp/openbsd-compat/base64.h b/other/ssharp/openbsd-compat/base64.h new file mode 100644 index 0000000..b4d1238 --- /dev/null +++ b/other/ssharp/openbsd-compat/base64.h | |||
| @@ -0,0 +1,18 @@ | |||
| 1 | /* $Id: base64.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_BASE64_H | ||
| 4 | #define _BSD_BASE64_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE___B64_NTOP | ||
| 9 | # ifndef HAVE_B64_NTOP | ||
| 10 | int b64_ntop(u_char const *src, size_t srclength, char *target, | ||
| 11 | size_t targsize); | ||
| 12 | int b64_pton(char const *src, u_char *target, size_t targsize); | ||
| 13 | # endif /* !HAVE_B64_NTOP */ | ||
| 14 | # define __b64_ntop b64_ntop | ||
| 15 | # define __b64_pton b64_pton | ||
| 16 | #endif /* HAVE___B64_NTOP */ | ||
| 17 | |||
| 18 | #endif /* _BSD_BINRESVPORT_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bindresvport.c b/other/ssharp/openbsd-compat/bindresvport.c new file mode 100644 index 0000000..332bcb0 --- /dev/null +++ b/other/ssharp/openbsd-compat/bindresvport.c | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | /* This file has be modified from the original OpenBSD source */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Sun RPC is a product of Sun Microsystems, Inc. and is provided for | ||
| 5 | * unrestricted use provided that this legend is included on all tape | ||
| 6 | * media and as a part of the software program in whole or part. Users | ||
| 7 | * may copy or modify Sun RPC without charge, but are not authorized | ||
| 8 | * to license or distribute it to anyone else except as part of a product or | ||
| 9 | * program developed by the user. | ||
| 10 | * | ||
| 11 | * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE | ||
| 12 | * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR | ||
| 13 | * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. | ||
| 14 | * | ||
| 15 | * Sun RPC is provided with no support and without any obligation on the | ||
| 16 | * part of Sun Microsystems, Inc. to assist in its use, correction, | ||
| 17 | * modification or enhancement. | ||
| 18 | * | ||
| 19 | * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE | ||
| 20 | * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC | ||
| 21 | * OR ANY PART THEREOF. | ||
| 22 | * | ||
| 23 | * In no event will Sun Microsystems, Inc. be liable for any lost revenue | ||
| 24 | * or profits or other special, indirect and consequential damages, even if | ||
| 25 | * Sun has been advised of the possibility of such damages. | ||
| 26 | * | ||
| 27 | * Sun Microsystems, Inc. | ||
| 28 | * 2550 Garcia Avenue | ||
| 29 | * Mountain View, California 94043 | ||
| 30 | */ | ||
| 31 | |||
| 32 | #include "config.h" | ||
| 33 | |||
| 34 | #ifndef HAVE_BINDRESVPORT_SA | ||
| 35 | |||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 37 | static char *rcsid = "$OpenBSD: bindresvport.c,v 1.13 2000/01/26 03:43:21 deraadt Exp $"; | ||
| 38 | #endif /* LIBC_SCCS and not lint */ | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Copyright (c) 1987 by Sun Microsystems, Inc. | ||
| 42 | * | ||
| 43 | * Portions Copyright(C) 1996, Jason Downs. All rights reserved. | ||
| 44 | */ | ||
| 45 | |||
| 46 | #include "includes.h" | ||
| 47 | |||
| 48 | #define STARTPORT 600 | ||
| 49 | #define ENDPORT (IPPORT_RESERVED - 1) | ||
| 50 | #define NPORTS (ENDPORT - STARTPORT + 1) | ||
| 51 | |||
| 52 | /* | ||
| 53 | * Bind a socket to a privileged IP port | ||
| 54 | */ | ||
| 55 | int | ||
| 56 | bindresvport_sa(sd, sa) | ||
| 57 | int sd; | ||
| 58 | struct sockaddr *sa; | ||
| 59 | { | ||
| 60 | int error, af; | ||
| 61 | struct sockaddr_storage myaddr; | ||
| 62 | struct sockaddr_in *sin; | ||
| 63 | struct sockaddr_in6 *sin6; | ||
| 64 | u_int16_t *portp; | ||
| 65 | u_int16_t port; | ||
| 66 | socklen_t salen; | ||
| 67 | int i; | ||
| 68 | |||
| 69 | if (sa == NULL) { | ||
| 70 | memset(&myaddr, 0, sizeof(myaddr)); | ||
| 71 | sa = (struct sockaddr *)&myaddr; | ||
| 72 | |||
| 73 | if (getsockname(sd, sa, &salen) == -1) | ||
| 74 | return -1; /* errno is correctly set */ | ||
| 75 | |||
| 76 | af = sa->sa_family; | ||
| 77 | memset(&myaddr, 0, salen); | ||
| 78 | } else | ||
| 79 | af = sa->sa_family; | ||
| 80 | |||
| 81 | if (af == AF_INET) { | ||
| 82 | sin = (struct sockaddr_in *)sa; | ||
| 83 | salen = sizeof(struct sockaddr_in); | ||
| 84 | portp = &sin->sin_port; | ||
| 85 | } else if (af == AF_INET6) { | ||
| 86 | sin6 = (struct sockaddr_in6 *)sa; | ||
| 87 | salen = sizeof(struct sockaddr_in6); | ||
| 88 | portp = &sin6->sin6_port; | ||
| 89 | } else { | ||
| 90 | errno = EPFNOSUPPORT; | ||
| 91 | return (-1); | ||
| 92 | } | ||
| 93 | sa->sa_family = af; | ||
| 94 | |||
| 95 | port = ntohs(*portp); | ||
| 96 | if (port == 0) | ||
| 97 | port = (arc4random() % NPORTS) + STARTPORT; | ||
| 98 | |||
| 99 | /* Avoid warning */ | ||
| 100 | error = -1; | ||
| 101 | |||
| 102 | for(i = 0; i < NPORTS; i++) { | ||
| 103 | *portp = htons(port); | ||
| 104 | |||
| 105 | error = bind(sd, sa, salen); | ||
| 106 | |||
| 107 | /* Terminate on success */ | ||
| 108 | if (error == 0) | ||
| 109 | break; | ||
| 110 | |||
| 111 | /* Terminate on errors, except "address already in use" */ | ||
| 112 | if ((error < 0) && !((errno == EADDRINUSE) || (errno == EINVAL))) | ||
| 113 | break; | ||
| 114 | |||
| 115 | port++; | ||
| 116 | if (port > ENDPORT) | ||
| 117 | port = STARTPORT; | ||
| 118 | } | ||
| 119 | |||
| 120 | return (error); | ||
| 121 | } | ||
| 122 | |||
| 123 | #endif /* HAVE_BINDRESVPORT_SA */ | ||
diff --git a/other/ssharp/openbsd-compat/bindresvport.h b/other/ssharp/openbsd-compat/bindresvport.h new file mode 100644 index 0000000..9214fab --- /dev/null +++ b/other/ssharp/openbsd-compat/bindresvport.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: bindresvport.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_BINDRESVPORT_H | ||
| 4 | #define _BSD_BINDRESVPORT_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_BINDRESVPORT_SA | ||
| 9 | int bindresvport_sa(int sd, struct sockaddr *sa); | ||
| 10 | #endif /* !HAVE_BINDRESVPORT_SA */ | ||
| 11 | |||
| 12 | #endif /* _BSD_BINDRESVPORT_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-arc4random.c b/other/ssharp/openbsd-compat/bsd-arc4random.c new file mode 100644 index 0000000..2a6744c --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-arc4random.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer in the | ||
| 11 | * documentation and/or other materials provided with the distribution. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "includes.h" | ||
| 26 | #include "log.h" | ||
| 27 | |||
| 28 | RCSID("$Id: bsd-arc4random.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 29 | |||
| 30 | #ifndef HAVE_ARC4RANDOM | ||
| 31 | |||
| 32 | #include <openssl/rand.h> | ||
| 33 | #include <openssl/rc4.h> | ||
| 34 | #include <openssl/err.h> | ||
| 35 | |||
| 36 | /* Size of key to use */ | ||
| 37 | #define SEED_SIZE 20 | ||
| 38 | |||
| 39 | /* Number of bytes to reseed after */ | ||
| 40 | #define REKEY_BYTES (1 << 24) | ||
| 41 | |||
| 42 | static int rc4_ready = 0; | ||
| 43 | static RC4_KEY rc4; | ||
| 44 | |||
| 45 | unsigned int arc4random(void) | ||
| 46 | { | ||
| 47 | unsigned int r = 0; | ||
| 48 | static int first_time = 1; | ||
| 49 | |||
| 50 | if (rc4_ready <= 0) { | ||
| 51 | if (!first_time) | ||
| 52 | seed_rng(); | ||
| 53 | first_time = 0; | ||
| 54 | arc4random_stir(); | ||
| 55 | } | ||
| 56 | |||
| 57 | RC4(&rc4, sizeof(r), (unsigned char *)&r, (unsigned char *)&r); | ||
| 58 | |||
| 59 | rc4_ready -= sizeof(r); | ||
| 60 | |||
| 61 | return(r); | ||
| 62 | } | ||
| 63 | |||
| 64 | void arc4random_stir(void) | ||
| 65 | { | ||
| 66 | unsigned char rand_buf[SEED_SIZE]; | ||
| 67 | |||
| 68 | memset(&rc4, 0, sizeof(rc4)); | ||
| 69 | if (!RAND_bytes(rand_buf, sizeof(rand_buf))) | ||
| 70 | fatal("Couldn't obtain random bytes (error %ld)", | ||
| 71 | ERR_get_error()); | ||
| 72 | RC4_set_key(&rc4, sizeof(rand_buf), rand_buf); | ||
| 73 | memset(rand_buf, 0, sizeof(rand_buf)); | ||
| 74 | |||
| 75 | rc4_ready = REKEY_BYTES; | ||
| 76 | } | ||
| 77 | #endif /* !HAVE_ARC4RANDOM */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-arc4random.h b/other/ssharp/openbsd-compat/bsd-arc4random.h new file mode 100644 index 0000000..3986202 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-arc4random.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer in the | ||
| 11 | * documentation and/or other materials provided with the distribution. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | /* $Id: bsd-arc4random.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 26 | |||
| 27 | #ifndef _BSD_ARC4RANDOM_H | ||
| 28 | #define _BSD_ARC4RANDOM_H | ||
| 29 | |||
| 30 | #include "config.h" | ||
| 31 | |||
| 32 | #ifndef HAVE_ARC4RANDOM | ||
| 33 | unsigned int arc4random(void); | ||
| 34 | void arc4random_stir(void); | ||
| 35 | #endif /* !HAVE_ARC4RANDOM */ | ||
| 36 | |||
| 37 | #endif /* _BSD_ARC4RANDOM_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-cygwin_util.c b/other/ssharp/openbsd-compat/bsd-cygwin_util.c new file mode 100644 index 0000000..e610454 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-cygwin_util.c | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * cygwin_util.c | ||
| 4 | * | ||
| 5 | * Author: Corinna Vinschen <vinschen@cygnus.com> | ||
| 6 | * | ||
| 7 | * Copyright (c) 2000 Corinna Vinschen <vinschen@cygnus.com>, Duisburg, Germany | ||
| 8 | * All rights reserved | ||
| 9 | * | ||
| 10 | * Created: Sat Sep 02 12:17:00 2000 cv | ||
| 11 | * | ||
| 12 | * This file contains functions for forcing opened file descriptors to | ||
| 13 | * binary mode on Windows systems. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "includes.h" | ||
| 17 | |||
| 18 | RCSID("$Id: bsd-cygwin_util.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 19 | |||
| 20 | #ifdef HAVE_CYGWIN | ||
| 21 | |||
| 22 | #include <fcntl.h> | ||
| 23 | #include <stdlib.h> | ||
| 24 | #include <sys/vfs.h> | ||
| 25 | #include <windows.h> | ||
| 26 | #define is_winnt (GetVersion() < 0x80000000) | ||
| 27 | |||
| 28 | #if defined(open) && open == binary_open | ||
| 29 | # undef open | ||
| 30 | #endif | ||
| 31 | #if defined(pipe) && open == binary_pipe | ||
| 32 | # undef pipe | ||
| 33 | #endif | ||
| 34 | |||
| 35 | int binary_open(const char *filename, int flags, ...) | ||
| 36 | { | ||
| 37 | va_list ap; | ||
| 38 | mode_t mode; | ||
| 39 | |||
| 40 | va_start(ap, flags); | ||
| 41 | mode = va_arg(ap, mode_t); | ||
| 42 | va_end(ap); | ||
| 43 | return open(filename, flags | O_BINARY, mode); | ||
| 44 | } | ||
| 45 | |||
| 46 | int binary_pipe(int fd[2]) | ||
| 47 | { | ||
| 48 | int ret = pipe(fd); | ||
| 49 | |||
| 50 | if (!ret) { | ||
| 51 | setmode (fd[0], O_BINARY); | ||
| 52 | setmode (fd[1], O_BINARY); | ||
| 53 | } | ||
| 54 | return ret; | ||
| 55 | } | ||
| 56 | |||
| 57 | int check_nt_auth(int pwd_authenticated, uid_t uid) | ||
| 58 | { | ||
| 59 | /* | ||
| 60 | * The only authentication which is able to change the user | ||
| 61 | * context on NT systems is the password authentication. So | ||
| 62 | * we deny all requsts for changing the user context if another | ||
| 63 | * authentication method is used. | ||
| 64 | * This may change in future when a special openssh | ||
| 65 | * subauthentication package is available. | ||
| 66 | */ | ||
| 67 | if (is_winnt && !pwd_authenticated && geteuid() != uid) | ||
| 68 | return 0; | ||
| 69 | |||
| 70 | return 1; | ||
| 71 | } | ||
| 72 | |||
| 73 | int check_ntsec(const char *filename) | ||
| 74 | { | ||
| 75 | char *cygwin; | ||
| 76 | int allow_ntea = 0; | ||
| 77 | int allow_ntsec = 0; | ||
| 78 | struct statfs fsstat; | ||
| 79 | |||
| 80 | /* Windows 95/98/ME don't support file system security at all. */ | ||
| 81 | if (!is_winnt) | ||
| 82 | return 0; | ||
| 83 | |||
| 84 | /* Evaluate current CYGWIN settings. */ | ||
| 85 | if ((cygwin = getenv("CYGWIN")) != NULL) { | ||
| 86 | if (strstr(cygwin, "ntea") && !strstr(cygwin, "nontea")) | ||
| 87 | allow_ntea = 1; | ||
| 88 | if (strstr(cygwin, "ntsec") && !strstr(cygwin, "nontsec")) | ||
| 89 | allow_ntsec = 1; | ||
| 90 | } | ||
| 91 | |||
| 92 | /* | ||
| 93 | * `ntea' is an emulation of POSIX attributes. It doesn't support | ||
| 94 | * real file level security as ntsec on NTFS file systems does | ||
| 95 | * but it supports FAT filesystems. `ntea' is minimum requirement | ||
| 96 | * for security checks. | ||
| 97 | */ | ||
| 98 | if (allow_ntea) | ||
| 99 | return 1; | ||
| 100 | |||
| 101 | /* | ||
| 102 | * Retrieve file system flags. In Cygwin, file system flags are | ||
| 103 | * copied to f_type which has no meaning in Win32 itself. | ||
| 104 | */ | ||
| 105 | if (statfs(filename, &fsstat)) | ||
| 106 | return 1; | ||
| 107 | |||
| 108 | /* | ||
| 109 | * Only file systems supporting ACLs are able to set permissions. | ||
| 110 | * `ntsec' is the setting in Cygwin which switches using of NTFS | ||
| 111 | * ACLs to support POSIX permissions on files. | ||
| 112 | */ | ||
| 113 | if (fsstat.f_type & FS_PERSISTENT_ACLS) | ||
| 114 | return allow_ntsec; | ||
| 115 | |||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | #endif /* HAVE_CYGWIN */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-cygwin_util.h b/other/ssharp/openbsd-compat/bsd-cygwin_util.h new file mode 100644 index 0000000..b5357e8 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-cygwin_util.h | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* | ||
| 2 | * | ||
| 3 | * cygwin_util.c | ||
| 4 | * | ||
| 5 | * Author: Corinna Vinschen <vinschen@cygnus.com> | ||
| 6 | * | ||
| 7 | * Copyright (c) 2000 Corinna Vinschen <vinschen@cygnus.com>, Duisburg, Germany | ||
| 8 | * All rights reserved | ||
| 9 | * | ||
| 10 | * Created: Sat Sep 02 12:17:00 2000 cv | ||
| 11 | * | ||
| 12 | * This file contains functions for forcing opened file descriptors to | ||
| 13 | * binary mode on Windows systems. | ||
| 14 | */ | ||
| 15 | |||
| 16 | /* $Id: bsd-cygwin_util.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 17 | |||
| 18 | #ifndef _BSD_CYGWIN_UTIL_H | ||
| 19 | #define _BSD_CYGWIN_UTIL_H | ||
| 20 | |||
| 21 | #ifdef HAVE_CYGWIN | ||
| 22 | |||
| 23 | #include <io.h> | ||
| 24 | |||
| 25 | int binary_open(const char *filename, int flags, ...); | ||
| 26 | int binary_pipe(int fd[2]); | ||
| 27 | int check_nt_auth(int pwd_authenticated, uid_t uid); | ||
| 28 | int check_ntsec(const char *filename); | ||
| 29 | |||
| 30 | #define open binary_open | ||
| 31 | #define pipe binary_pipe | ||
| 32 | |||
| 33 | #endif /* HAVE_CYGWIN */ | ||
| 34 | |||
| 35 | #endif /* _BSD_CYGWIN_UTIL_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-misc.c b/other/ssharp/openbsd-compat/bsd-misc.c new file mode 100644 index 0000000..832af65 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-misc.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer in the | ||
| 11 | * documentation and/or other materials provided with the distribution. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "includes.h" | ||
| 26 | #include "xmalloc.h" | ||
| 27 | #include "ssh.h" | ||
| 28 | |||
| 29 | RCSID("$Id: bsd-misc.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 30 | |||
| 31 | char *get_progname(char *argv0) | ||
| 32 | { | ||
| 33 | #ifdef HAVE___PROGNAME | ||
| 34 | extern char *__progname; | ||
| 35 | |||
| 36 | return __progname; | ||
| 37 | #else | ||
| 38 | char *p; | ||
| 39 | |||
| 40 | if (argv0 == NULL) | ||
| 41 | return "unknown"; /* XXX */ | ||
| 42 | p = strrchr(argv0, '/'); | ||
| 43 | if (p == NULL) | ||
| 44 | p = argv0; | ||
| 45 | else | ||
| 46 | p++; | ||
| 47 | return p; | ||
| 48 | #endif | ||
| 49 | } | ||
| 50 | |||
| 51 | #ifndef HAVE_SETLOGIN | ||
| 52 | int setlogin(const char *name) | ||
| 53 | { | ||
| 54 | return(0); | ||
| 55 | } | ||
| 56 | #endif /* !HAVE_SETLOGIN */ | ||
| 57 | |||
| 58 | #ifndef HAVE_INNETGR | ||
| 59 | int innetgr(const char *netgroup, const char *host, | ||
| 60 | const char *user, const char *domain) | ||
| 61 | { | ||
| 62 | return(0); | ||
| 63 | } | ||
| 64 | #endif /* HAVE_INNETGR */ | ||
| 65 | |||
| 66 | #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) | ||
| 67 | int seteuid(uid_t euid) | ||
| 68 | { | ||
| 69 | return(setreuid(-1,euid)); | ||
| 70 | } | ||
| 71 | #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ | ||
| 72 | |||
| 73 | #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) | ||
| 74 | int setegid(uid_t egid) | ||
| 75 | { | ||
| 76 | return(setresgid(-1,egid,-1)); | ||
| 77 | } | ||
| 78 | #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ | ||
| 79 | |||
| 80 | #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR) | ||
| 81 | const char *strerror(int e) | ||
| 82 | { | ||
| 83 | extern int sys_nerr; | ||
| 84 | extern char *sys_errlist[]; | ||
| 85 | |||
| 86 | if ((e >= 0) && (e < sys_nerr)) | ||
| 87 | return(sys_errlist[e]); | ||
| 88 | else | ||
| 89 | return("unlisted error"); | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #ifndef HAVE_UTIMES | ||
| 94 | int utimes(char *filename, struct timeval *tvp) | ||
| 95 | { | ||
| 96 | struct utimbuf ub; | ||
| 97 | |||
| 98 | ub.actime = tvp->tv_sec; | ||
| 99 | ub.modtime = tvp->tv_usec; | ||
| 100 | |||
| 101 | return(utime(filename, &ub)); | ||
| 102 | } | ||
| 103 | #endif | ||
diff --git a/other/ssharp/openbsd-compat/bsd-misc.h b/other/ssharp/openbsd-compat/bsd-misc.h new file mode 100644 index 0000000..01f8a6a --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-misc.h | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1999-2000 Damien Miller. All rights reserved. | ||
| 3 | * | ||
| 4 | * Redistribution and use in source and binary forms, with or without | ||
| 5 | * modification, are permitted provided that the following conditions | ||
| 6 | * are met: | ||
| 7 | * 1. Redistributions of source code must retain the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer. | ||
| 9 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer in the | ||
| 11 | * documentation and/or other materials provided with the distribution. | ||
| 12 | * | ||
| 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 14 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 15 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 16 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 17 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 18 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 19 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 20 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 21 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 22 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | /* $Id: bsd-misc.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 26 | |||
| 27 | #ifndef _BSD_MISC_H | ||
| 28 | #define _BSD_MISC_H | ||
| 29 | |||
| 30 | #include "config.h" | ||
| 31 | |||
| 32 | char *get_progname(char *argv0); | ||
| 33 | |||
| 34 | #ifndef HAVE_SETSID | ||
| 35 | #define setsid() setpgrp(0, getpid()) | ||
| 36 | #endif /* !HAVE_SETSID */ | ||
| 37 | |||
| 38 | #ifndef HAVE_SETENV | ||
| 39 | int setenv(const char *name, const char *value, int overwrite); | ||
| 40 | #endif /* !HAVE_SETENV */ | ||
| 41 | |||
| 42 | #ifndef HAVE_SETLOGIN | ||
| 43 | int setlogin(const char *name); | ||
| 44 | #endif /* !HAVE_SETLOGIN */ | ||
| 45 | |||
| 46 | #ifndef HAVE_INNETGR | ||
| 47 | int innetgr(const char *netgroup, const char *host, | ||
| 48 | const char *user, const char *domain); | ||
| 49 | #endif /* HAVE_INNETGR */ | ||
| 50 | |||
| 51 | #if !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) | ||
| 52 | int seteuid(uid_t euid); | ||
| 53 | #endif /* !defined(HAVE_SETEUID) && defined(HAVE_SETREUID) */ | ||
| 54 | |||
| 55 | #if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) | ||
| 56 | int setegid(uid_t egid); | ||
| 57 | #endif /* !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */ | ||
| 58 | |||
| 59 | #if !defined(HAVE_STRERROR) && defined(HAVE_SYS_ERRLIST) && defined(HAVE_SYS_NERR) | ||
| 60 | const char *strerror(int e); | ||
| 61 | #endif | ||
| 62 | |||
| 63 | |||
| 64 | #ifndef HAVE_UTIMES | ||
| 65 | #ifndef HAVE_STRUCT_TIMEVAL | ||
| 66 | struct timeval { | ||
| 67 | long tv_sec; | ||
| 68 | long tv_usec; | ||
| 69 | } | ||
| 70 | #endif /* HAVE_STRUCT_TIMEVAL */ | ||
| 71 | |||
| 72 | int utimes(char *filename, struct timeval *tvp); | ||
| 73 | #endif /* HAVE_UTIMES */ | ||
| 74 | |||
| 75 | |||
| 76 | #endif /* _BSD_MISC_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-nextstep.c b/other/ssharp/openbsd-compat/bsd-nextstep.c new file mode 100644 index 0000000..2239709 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-nextstep.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* | ||
| 2 | * Redistribution and use in source and binary forms, with or without | ||
| 3 | * modification, are permitted provided that the following conditions | ||
| 4 | * are met: | ||
| 5 | * 1. Redistributions of source code must retain the above copyright | ||
| 6 | * notice, this list of conditions and the following disclaimer. | ||
| 7 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer in the | ||
| 9 | * documentation and/or other materials provided with the distribution. | ||
| 10 | * | ||
| 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 13 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 14 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 15 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 16 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 17 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 18 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 19 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 20 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "includes.h" | ||
| 24 | |||
| 25 | RCSID("$Id: bsd-nextstep.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 26 | |||
| 27 | #ifdef HAVE_NEXT | ||
| 28 | #include <errno.h> | ||
| 29 | #include <sys/wait.h> | ||
| 30 | #include "bsd-nextstep.h" | ||
| 31 | |||
| 32 | pid_t | ||
| 33 | posix_wait(int *status) | ||
| 34 | { | ||
| 35 | union wait statusp; | ||
| 36 | pid_t wait_pid; | ||
| 37 | |||
| 38 | #undef wait /* Use NeXT's wait() function */ | ||
| 39 | wait_pid = wait(&statusp); | ||
| 40 | if (status) | ||
| 41 | *status = (int) statusp.w_status; | ||
| 42 | |||
| 43 | return wait_pid; | ||
| 44 | } | ||
| 45 | |||
| 46 | int | ||
| 47 | tcgetattr(int fd, struct termios *t) | ||
| 48 | { | ||
| 49 | return (ioctl(fd, TIOCGETA, t)); | ||
| 50 | } | ||
| 51 | |||
| 52 | int | ||
| 53 | tcsetattr(int fd, int opt, const struct termios *t) | ||
| 54 | { | ||
| 55 | struct termios localterm; | ||
| 56 | |||
| 57 | if (opt & TCSASOFT) { | ||
| 58 | localterm = *t; | ||
| 59 | localterm.c_cflag |= CIGNORE; | ||
| 60 | t = &localterm; | ||
| 61 | } | ||
| 62 | switch (opt & ~TCSASOFT) { | ||
| 63 | case TCSANOW: | ||
| 64 | return (ioctl(fd, TIOCSETA, t)); | ||
| 65 | case TCSADRAIN: | ||
| 66 | return (ioctl(fd, TIOCSETAW, t)); | ||
| 67 | case TCSAFLUSH: | ||
| 68 | return (ioctl(fd, TIOCSETAF, t)); | ||
| 69 | default: | ||
| 70 | errno = EINVAL; | ||
| 71 | return (-1); | ||
| 72 | } | ||
| 73 | } | ||
| 74 | |||
| 75 | int tcsetpgrp(int fd, pid_t pgrp) | ||
| 76 | { | ||
| 77 | return (ioctl(fd, TIOCSPGRP, &pgrp)); | ||
| 78 | } | ||
| 79 | |||
| 80 | speed_t cfgetospeed(const struct termios *t) | ||
| 81 | { | ||
| 82 | return (t->c_ospeed); | ||
| 83 | } | ||
| 84 | |||
| 85 | speed_t cfgetispeed(const struct termios *t) | ||
| 86 | { | ||
| 87 | return (t->c_ispeed); | ||
| 88 | } | ||
| 89 | |||
| 90 | int | ||
| 91 | cfsetospeed(struct termios *t,int speed) | ||
| 92 | { | ||
| 93 | t->c_ospeed = speed; | ||
| 94 | return (0); | ||
| 95 | } | ||
| 96 | |||
| 97 | int | ||
| 98 | cfsetispeed(struct termios *t, int speed) | ||
| 99 | { | ||
| 100 | t->c_ispeed = speed; | ||
| 101 | return (0); | ||
| 102 | } | ||
| 103 | #endif /* HAVE_NEXT */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-nextstep.h b/other/ssharp/openbsd-compat/bsd-nextstep.h new file mode 100644 index 0000000..48de0f1 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-nextstep.h | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | /* | ||
| 2 | * Redistribution and use in source and binary forms, with or without | ||
| 3 | * modification, are permitted provided that the following conditions | ||
| 4 | * are met: | ||
| 5 | * 1. Redistributions of source code must retain the above copyright | ||
| 6 | * notice, this list of conditions and the following disclaimer. | ||
| 7 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer in the | ||
| 9 | * documentation and/or other materials provided with the distribution. | ||
| 10 | * | ||
| 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 13 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 14 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 15 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 16 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 17 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 18 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 19 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 20 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | |||
| 24 | /* $Id: bsd-nextstep.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 25 | |||
| 26 | #ifndef _NEXT_POSIX_H | ||
| 27 | #define _NEXT_POSIX_H | ||
| 28 | |||
| 29 | #ifdef HAVE_NEXT | ||
| 30 | #include <sys/dir.h> | ||
| 31 | |||
| 32 | /* NGROUPS_MAX is behind -lposix. Use the BSD version which is NGROUPS */ | ||
| 33 | #undef NGROUPS_MAX | ||
| 34 | #define NGROUPS_MAX NGROUPS | ||
| 35 | |||
| 36 | /* NeXT's readdir() is BSD (struct direct) not POSIX (struct dirent) */ | ||
| 37 | #define dirent direct | ||
| 38 | |||
| 39 | /* Swap out NeXT's BSD wait() for a more POSIX complient one */ | ||
| 40 | pid_t posix_wait(int *status); | ||
| 41 | #define wait(a) posix_wait(a) | ||
| 42 | |||
| 43 | /* #ifdef wrapped functions that need defining for clean compiling */ | ||
| 44 | pid_t getppid(void); | ||
| 45 | void vhangup(void); | ||
| 46 | int innetgr(const char *netgroup, const char *host, const char *user, | ||
| 47 | const char *domain); | ||
| 48 | |||
| 49 | /* TERMCAP */ | ||
| 50 | int tcgetattr(int fd, struct termios *t); | ||
| 51 | int tcsetattr(int fd, int opt, const struct termios *t); | ||
| 52 | int tcsetpgrp(int fd, pid_t pgrp); | ||
| 53 | speed_t cfgetospeed(const struct termios *t); | ||
| 54 | speed_t cfgetispeed(const struct termios *t); | ||
| 55 | int cfsetospeed(struct termios *t, int speed); | ||
| 56 | int cfsetispeed(struct termios *t, int speed); | ||
| 57 | #endif /* HAVE_NEXT */ | ||
| 58 | #endif /* _NEXT_POSIX_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-snprintf.c b/other/ssharp/openbsd-compat/bsd-snprintf.c new file mode 100644 index 0000000..14d12fc --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-snprintf.c | |||
| @@ -0,0 +1,744 @@ | |||
| 1 | /************************************************************** | ||
| 2 | * Original: | ||
| 3 | * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 | ||
| 4 | * A bombproof version of doprnt (dopr) included. | ||
| 5 | * Sigh. This sort of thing is always nasty do deal with. Note that | ||
| 6 | * the version here does not include floating point... | ||
| 7 | * | ||
| 8 | * snprintf() is used instead of sprintf() as it does limit checks | ||
| 9 | * for string length. This covers a nasty loophole. | ||
| 10 | * | ||
| 11 | * The other functions are there to prevent NULL pointers from | ||
| 12 | * causing nast effects. | ||
| 13 | * | ||
| 14 | * More Recently: | ||
| 15 | * Brandon Long <blong@fiction.net> 9/15/96 for mutt 0.43 | ||
| 16 | * This was ugly. It is still ugly. I opted out of floating point | ||
| 17 | * numbers, but the formatter understands just about everything | ||
| 18 | * from the normal C string format, at least as far as I can tell from | ||
| 19 | * the Solaris 2.5 printf(3S) man page. | ||
| 20 | * | ||
| 21 | * Brandon Long <blong@fiction.net> 10/22/97 for mutt 0.87.1 | ||
| 22 | * Ok, added some minimal floating point support, which means this | ||
| 23 | * probably requires libm on most operating systems. Don't yet | ||
| 24 | * support the exponent (e,E) and sigfig (g,G). Also, fmtint() | ||
| 25 | * was pretty badly broken, it just wasn't being exercised in ways | ||
| 26 | * which showed it, so that's been fixed. Also, formated the code | ||
| 27 | * to mutt conventions, and removed dead code left over from the | ||
| 28 | * original. Also, there is now a builtin-test, just compile with: | ||
| 29 | * gcc -DTEST_SNPRINTF -o snprintf snprintf.c -lm | ||
| 30 | * and run snprintf for results. | ||
| 31 | * | ||
| 32 | * Thomas Roessler <roessler@guug.de> 01/27/98 for mutt 0.89i | ||
| 33 | * The PGP code was using unsigned hexadecimal formats. | ||
| 34 | * Unfortunately, unsigned formats simply didn't work. | ||
| 35 | * | ||
| 36 | * Michael Elkins <me@cs.hmc.edu> 03/05/98 for mutt 0.90.8 | ||
| 37 | * The original code assumed that both snprintf() and vsnprintf() were | ||
| 38 | * missing. Some systems only have snprintf() but not vsnprintf(), so | ||
| 39 | * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. | ||
| 40 | * | ||
| 41 | * Ben Lindstrom <mouring@eviladmin.org> 09/27/00 for OpenSSH | ||
| 42 | * Welcome to the world of %lld and %qd support. With other | ||
| 43 | * long long support. This is needed for sftp-server to work | ||
| 44 | * right. | ||
| 45 | * | ||
| 46 | * Ben Lindstrom <mouring@eviladmin.org> 02/12/01 for OpenSSH | ||
| 47 | * Removed all hint of VARARGS stuff and banished it to the void, | ||
| 48 | * and did a bit of KNF style work to make things a bit more | ||
| 49 | * acceptable. Consider stealing from mutt or enlightenment. | ||
| 50 | **************************************************************/ | ||
| 51 | |||
| 52 | #include "includes.h" | ||
| 53 | |||
| 54 | RCSID("$Id: bsd-snprintf.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 55 | |||
| 56 | #if defined(BROKEN_SNPRINTF) /* For those with broken snprintf() */ | ||
| 57 | # undef HAVE_SNPRINTF | ||
| 58 | # undef HAVE_VSNPRINTF | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) | ||
| 62 | |||
| 63 | static void | ||
| 64 | dopr(char *buffer, size_t maxlen, const char *format, va_list args); | ||
| 65 | |||
| 66 | static void | ||
| 67 | fmtstr(char *buffer, size_t *currlen, size_t maxlen, char *value, int flags, | ||
| 68 | int min, int max); | ||
| 69 | |||
| 70 | static void | ||
| 71 | fmtint(char *buffer, size_t *currlen, size_t maxlen, long value, int base, | ||
| 72 | int min, int max, int flags); | ||
| 73 | |||
| 74 | static void | ||
| 75 | fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, | ||
| 76 | int min, int max, int flags); | ||
| 77 | |||
| 78 | static void | ||
| 79 | dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c); | ||
| 80 | |||
| 81 | /* | ||
| 82 | * dopr(): poor man's version of doprintf | ||
| 83 | */ | ||
| 84 | |||
| 85 | /* format read states */ | ||
| 86 | #define DP_S_DEFAULT 0 | ||
| 87 | #define DP_S_FLAGS 1 | ||
| 88 | #define DP_S_MIN 2 | ||
| 89 | #define DP_S_DOT 3 | ||
| 90 | #define DP_S_MAX 4 | ||
| 91 | #define DP_S_MOD 5 | ||
| 92 | #define DP_S_CONV 6 | ||
| 93 | #define DP_S_DONE 7 | ||
| 94 | |||
| 95 | /* format flags - Bits */ | ||
| 96 | #define DP_F_MINUS (1 << 0) | ||
| 97 | #define DP_F_PLUS (1 << 1) | ||
| 98 | #define DP_F_SPACE (1 << 2) | ||
| 99 | #define DP_F_NUM (1 << 3) | ||
| 100 | #define DP_F_ZERO (1 << 4) | ||
| 101 | #define DP_F_UP (1 << 5) | ||
| 102 | #define DP_F_UNSIGNED (1 << 6) | ||
| 103 | |||
| 104 | /* Conversion Flags */ | ||
| 105 | #define DP_C_SHORT 1 | ||
| 106 | #define DP_C_LONG 2 | ||
| 107 | #define DP_C_LDOUBLE 3 | ||
| 108 | #define DP_C_LONG_LONG 4 | ||
| 109 | |||
| 110 | #define char_to_int(p) (p - '0') | ||
| 111 | #define abs_val(p) (p < 0 ? -p : p) | ||
| 112 | |||
| 113 | |||
| 114 | static void | ||
| 115 | dopr(char *buffer, size_t maxlen, const char *format, va_list args) | ||
| 116 | { | ||
| 117 | char *strvalue; | ||
| 118 | char ch; | ||
| 119 | long value; | ||
| 120 | long double fvalue; | ||
| 121 | int min = 0; | ||
| 122 | int max = -1; | ||
| 123 | int state = DP_S_DEFAULT; | ||
| 124 | int flags = 0; | ||
| 125 | int cflags = 0; | ||
| 126 | size_t currlen = 0; | ||
| 127 | |||
| 128 | ch = *format++; | ||
| 129 | |||
| 130 | while (state != DP_S_DONE) { | ||
| 131 | if ((ch == '\0') || (currlen >= maxlen)) | ||
| 132 | state = DP_S_DONE; | ||
| 133 | |||
| 134 | switch(state) { | ||
| 135 | case DP_S_DEFAULT: | ||
| 136 | if (ch == '%') | ||
| 137 | state = DP_S_FLAGS; | ||
| 138 | else | ||
| 139 | dopr_outch(buffer, &currlen, maxlen, ch); | ||
| 140 | ch = *format++; | ||
| 141 | break; | ||
| 142 | case DP_S_FLAGS: | ||
| 143 | switch (ch) { | ||
| 144 | case '-': | ||
| 145 | flags |= DP_F_MINUS; | ||
| 146 | ch = *format++; | ||
| 147 | break; | ||
| 148 | case '+': | ||
| 149 | flags |= DP_F_PLUS; | ||
| 150 | ch = *format++; | ||
| 151 | break; | ||
| 152 | case ' ': | ||
| 153 | flags |= DP_F_SPACE; | ||
| 154 | ch = *format++; | ||
| 155 | break; | ||
| 156 | case '#': | ||
| 157 | flags |= DP_F_NUM; | ||
| 158 | ch = *format++; | ||
| 159 | break; | ||
| 160 | case '0': | ||
| 161 | flags |= DP_F_ZERO; | ||
| 162 | ch = *format++; | ||
| 163 | break; | ||
| 164 | default: | ||
| 165 | state = DP_S_MIN; | ||
| 166 | break; | ||
| 167 | } | ||
| 168 | break; | ||
| 169 | case DP_S_MIN: | ||
| 170 | if (isdigit((unsigned char)ch)) { | ||
| 171 | min = 10*min + char_to_int (ch); | ||
| 172 | ch = *format++; | ||
| 173 | } else if (ch == '*') { | ||
| 174 | min = va_arg (args, int); | ||
| 175 | ch = *format++; | ||
| 176 | state = DP_S_DOT; | ||
| 177 | } else | ||
| 178 | state = DP_S_DOT; | ||
| 179 | break; | ||
| 180 | case DP_S_DOT: | ||
| 181 | if (ch == '.') { | ||
| 182 | state = DP_S_MAX; | ||
| 183 | ch = *format++; | ||
| 184 | } else | ||
| 185 | state = DP_S_MOD; | ||
| 186 | break; | ||
| 187 | case DP_S_MAX: | ||
| 188 | if (isdigit((unsigned char)ch)) { | ||
| 189 | if (max < 0) | ||
| 190 | max = 0; | ||
| 191 | max = 10*max + char_to_int(ch); | ||
| 192 | ch = *format++; | ||
| 193 | } else if (ch == '*') { | ||
| 194 | max = va_arg (args, int); | ||
| 195 | ch = *format++; | ||
| 196 | state = DP_S_MOD; | ||
| 197 | } else | ||
| 198 | state = DP_S_MOD; | ||
| 199 | break; | ||
| 200 | case DP_S_MOD: | ||
| 201 | switch (ch) { | ||
| 202 | case 'h': | ||
| 203 | cflags = DP_C_SHORT; | ||
| 204 | ch = *format++; | ||
| 205 | break; | ||
| 206 | case 'l': | ||
| 207 | cflags = DP_C_LONG; | ||
| 208 | ch = *format++; | ||
| 209 | if (ch == 'l') { | ||
| 210 | cflags = DP_C_LONG_LONG; | ||
| 211 | ch = *format++; | ||
| 212 | } | ||
| 213 | break; | ||
| 214 | case 'q': | ||
| 215 | cflags = DP_C_LONG_LONG; | ||
| 216 | ch = *format++; | ||
| 217 | break; | ||
| 218 | case 'L': | ||
| 219 | cflags = DP_C_LDOUBLE; | ||
| 220 | ch = *format++; | ||
| 221 | break; | ||
| 222 | default: | ||
| 223 | break; | ||
| 224 | } | ||
| 225 | state = DP_S_CONV; | ||
| 226 | break; | ||
| 227 | case DP_S_CONV: | ||
| 228 | switch (ch) { | ||
| 229 | case 'd': | ||
| 230 | case 'i': | ||
| 231 | if (cflags == DP_C_SHORT) | ||
| 232 | value = va_arg(args, int); | ||
| 233 | else if (cflags == DP_C_LONG) | ||
| 234 | value = va_arg(args, long int); | ||
| 235 | else if (cflags == DP_C_LONG_LONG) | ||
| 236 | value = va_arg (args, long long); | ||
| 237 | else | ||
| 238 | value = va_arg (args, int); | ||
| 239 | fmtint(buffer, &currlen, maxlen, value, 10, min, max, flags); | ||
| 240 | break; | ||
| 241 | case 'o': | ||
| 242 | flags |= DP_F_UNSIGNED; | ||
| 243 | if (cflags == DP_C_SHORT) | ||
| 244 | value = va_arg(args, unsigned int); | ||
| 245 | else if (cflags == DP_C_LONG) | ||
| 246 | value = va_arg(args, unsigned long int); | ||
| 247 | else if (cflags == DP_C_LONG_LONG) | ||
| 248 | value = va_arg(args, unsigned long long); | ||
| 249 | else | ||
| 250 | value = va_arg(args, unsigned int); | ||
| 251 | fmtint(buffer, &currlen, maxlen, value, 8, min, max, flags); | ||
| 252 | break; | ||
| 253 | case 'u': | ||
| 254 | flags |= DP_F_UNSIGNED; | ||
| 255 | if (cflags == DP_C_SHORT) | ||
| 256 | value = va_arg(args, unsigned int); | ||
| 257 | else if (cflags == DP_C_LONG) | ||
| 258 | value = va_arg(args, unsigned long int); | ||
| 259 | else if (cflags == DP_C_LONG_LONG) | ||
| 260 | value = va_arg(args, unsigned long long); | ||
| 261 | else | ||
| 262 | value = va_arg(args, unsigned int); | ||
| 263 | fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); | ||
| 264 | break; | ||
| 265 | case 'X': | ||
| 266 | flags |= DP_F_UP; | ||
| 267 | case 'x': | ||
| 268 | flags |= DP_F_UNSIGNED; | ||
| 269 | if (cflags == DP_C_SHORT) | ||
| 270 | value = va_arg(args, unsigned int); | ||
| 271 | else if (cflags == DP_C_LONG) | ||
| 272 | value = va_arg(args, unsigned long int); | ||
| 273 | else if (cflags == DP_C_LONG_LONG) | ||
| 274 | value = va_arg(args, unsigned long long); | ||
| 275 | else | ||
| 276 | value = va_arg(args, unsigned int); | ||
| 277 | fmtint(buffer, &currlen, maxlen, value, 16, min, max, flags); | ||
| 278 | break; | ||
| 279 | case 'f': | ||
| 280 | if (cflags == DP_C_LDOUBLE) | ||
| 281 | fvalue = va_arg(args, long double); | ||
| 282 | else | ||
| 283 | fvalue = va_arg(args, double); | ||
| 284 | /* um, floating point? */ | ||
| 285 | fmtfp(buffer, &currlen, maxlen, fvalue, min, max, flags); | ||
| 286 | break; | ||
| 287 | case 'E': | ||
| 288 | flags |= DP_F_UP; | ||
| 289 | case 'e': | ||
| 290 | if (cflags == DP_C_LDOUBLE) | ||
| 291 | fvalue = va_arg(args, long double); | ||
| 292 | else | ||
| 293 | fvalue = va_arg(args, double); | ||
| 294 | break; | ||
| 295 | case 'G': | ||
| 296 | flags |= DP_F_UP; | ||
| 297 | case 'g': | ||
| 298 | if (cflags == DP_C_LDOUBLE) | ||
| 299 | fvalue = va_arg(args, long double); | ||
| 300 | else | ||
| 301 | fvalue = va_arg(args, double); | ||
| 302 | break; | ||
| 303 | case 'c': | ||
| 304 | dopr_outch(buffer, &currlen, maxlen, va_arg(args, int)); | ||
| 305 | break; | ||
| 306 | case 's': | ||
| 307 | strvalue = va_arg(args, char *); | ||
| 308 | if (max < 0) | ||
| 309 | max = maxlen; /* ie, no max */ | ||
| 310 | fmtstr(buffer, &currlen, maxlen, strvalue, flags, min, max); | ||
| 311 | break; | ||
| 312 | case 'p': | ||
| 313 | strvalue = va_arg(args, void *); | ||
| 314 | fmtint(buffer, &currlen, maxlen, (long) strvalue, 16, min, max, flags); | ||
| 315 | break; | ||
| 316 | case 'n': | ||
| 317 | if (cflags == DP_C_SHORT) { | ||
| 318 | short int *num; | ||
| 319 | num = va_arg(args, short int *); | ||
| 320 | *num = currlen; | ||
| 321 | } else if (cflags == DP_C_LONG) { | ||
| 322 | long int *num; | ||
| 323 | num = va_arg(args, long int *); | ||
| 324 | *num = currlen; | ||
| 325 | } else if (cflags == DP_C_LONG_LONG) { | ||
| 326 | long long *num; | ||
| 327 | num = va_arg(args, long long *); | ||
| 328 | *num = currlen; | ||
| 329 | } else { | ||
| 330 | int *num; | ||
| 331 | num = va_arg(args, int *); | ||
| 332 | *num = currlen; | ||
| 333 | } | ||
| 334 | break; | ||
| 335 | case '%': | ||
| 336 | dopr_outch(buffer, &currlen, maxlen, ch); | ||
| 337 | break; | ||
| 338 | case 'w': /* not supported yet, treat as next char */ | ||
| 339 | ch = *format++; | ||
| 340 | break; | ||
| 341 | default: /* Unknown, skip */ | ||
| 342 | break; | ||
| 343 | } | ||
| 344 | ch = *format++; | ||
| 345 | state = DP_S_DEFAULT; | ||
| 346 | flags = cflags = min = 0; | ||
| 347 | max = -1; | ||
| 348 | break; | ||
| 349 | case DP_S_DONE: | ||
| 350 | break; | ||
| 351 | default: /* hmm? */ | ||
| 352 | break; /* some picky compilers need this */ | ||
| 353 | } | ||
| 354 | } | ||
| 355 | if (currlen < maxlen - 1) | ||
| 356 | buffer[currlen] = '\0'; | ||
| 357 | else | ||
| 358 | buffer[maxlen - 1] = '\0'; | ||
| 359 | } | ||
| 360 | |||
| 361 | static void | ||
| 362 | fmtstr(char *buffer, size_t *currlen, size_t maxlen, | ||
| 363 | char *value, int flags, int min, int max) | ||
| 364 | { | ||
| 365 | int padlen, strln; /* amount to pad */ | ||
| 366 | int cnt = 0; | ||
| 367 | |||
| 368 | if (value == 0) | ||
| 369 | value = "<NULL>"; | ||
| 370 | |||
| 371 | for (strln = 0; value[strln]; ++strln); /* strlen */ | ||
| 372 | padlen = min - strln; | ||
| 373 | if (padlen < 0) | ||
| 374 | padlen = 0; | ||
| 375 | if (flags & DP_F_MINUS) | ||
| 376 | padlen = -padlen; /* Left Justify */ | ||
| 377 | |||
| 378 | while ((padlen > 0) && (cnt < max)) { | ||
| 379 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
| 380 | --padlen; | ||
| 381 | ++cnt; | ||
| 382 | } | ||
| 383 | while (*value && (cnt < max)) { | ||
| 384 | dopr_outch(buffer, currlen, maxlen, *value++); | ||
| 385 | ++cnt; | ||
| 386 | } | ||
| 387 | while ((padlen < 0) && (cnt < max)) { | ||
| 388 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
| 389 | ++padlen; | ||
| 390 | ++cnt; | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | /* Have to handle DP_F_NUM (ie 0x and 0 alternates) */ | ||
| 395 | |||
| 396 | static void | ||
| 397 | fmtint(char *buffer, size_t *currlen, size_t maxlen, | ||
| 398 | long value, int base, int min, int max, int flags) | ||
| 399 | { | ||
| 400 | unsigned long uvalue; | ||
| 401 | char convert[20]; | ||
| 402 | int signvalue = 0; | ||
| 403 | int place = 0; | ||
| 404 | int spadlen = 0; /* amount to space pad */ | ||
| 405 | int zpadlen = 0; /* amount to zero pad */ | ||
| 406 | int caps = 0; | ||
| 407 | |||
| 408 | if (max < 0) | ||
| 409 | max = 0; | ||
| 410 | |||
| 411 | uvalue = value; | ||
| 412 | |||
| 413 | if (!(flags & DP_F_UNSIGNED)) { | ||
| 414 | if (value < 0) { | ||
| 415 | signvalue = '-'; | ||
| 416 | uvalue = -value; | ||
| 417 | } else if (flags & DP_F_PLUS) /* Do a sign (+/i) */ | ||
| 418 | signvalue = '+'; | ||
| 419 | else if (flags & DP_F_SPACE) | ||
| 420 | signvalue = ' '; | ||
| 421 | } | ||
| 422 | |||
| 423 | if (flags & DP_F_UP) | ||
| 424 | caps = 1; /* Should characters be upper case? */ | ||
| 425 | |||
| 426 | do { | ||
| 427 | convert[place++] = | ||
| 428 | (caps? "0123456789ABCDEF":"0123456789abcdef") | ||
| 429 | [uvalue % (unsigned)base]; | ||
| 430 | uvalue = (uvalue / (unsigned)base ); | ||
| 431 | } while (uvalue && (place < 20)); | ||
| 432 | if (place == 20) | ||
| 433 | place--; | ||
| 434 | convert[place] = 0; | ||
| 435 | |||
| 436 | zpadlen = max - place; | ||
| 437 | spadlen = min - MAX (max, place) - (signvalue ? 1 : 0); | ||
| 438 | if (zpadlen < 0) | ||
| 439 | zpadlen = 0; | ||
| 440 | if (spadlen < 0) | ||
| 441 | spadlen = 0; | ||
| 442 | if (flags & DP_F_ZERO) { | ||
| 443 | zpadlen = MAX(zpadlen, spadlen); | ||
| 444 | spadlen = 0; | ||
| 445 | } | ||
| 446 | if (flags & DP_F_MINUS) | ||
| 447 | spadlen = -spadlen; /* Left Justifty */ | ||
| 448 | |||
| 449 | |||
| 450 | /* Spaces */ | ||
| 451 | while (spadlen > 0) { | ||
| 452 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
| 453 | --spadlen; | ||
| 454 | } | ||
| 455 | |||
| 456 | /* Sign */ | ||
| 457 | if (signvalue) | ||
| 458 | dopr_outch(buffer, currlen, maxlen, signvalue); | ||
| 459 | |||
| 460 | /* Zeros */ | ||
| 461 | if (zpadlen > 0) { | ||
| 462 | while (zpadlen > 0) { | ||
| 463 | dopr_outch(buffer, currlen, maxlen, '0'); | ||
| 464 | --zpadlen; | ||
| 465 | } | ||
| 466 | } | ||
| 467 | |||
| 468 | /* Digits */ | ||
| 469 | while (place > 0) | ||
| 470 | dopr_outch(buffer, currlen, maxlen, convert[--place]); | ||
| 471 | |||
| 472 | /* Left Justified spaces */ | ||
| 473 | while (spadlen < 0) { | ||
| 474 | dopr_outch (buffer, currlen, maxlen, ' '); | ||
| 475 | ++spadlen; | ||
| 476 | } | ||
| 477 | } | ||
| 478 | |||
| 479 | static long double | ||
| 480 | pow10(int exp) | ||
| 481 | { | ||
| 482 | long double result = 1; | ||
| 483 | |||
| 484 | while (exp) { | ||
| 485 | result *= 10; | ||
| 486 | exp--; | ||
| 487 | } | ||
| 488 | |||
| 489 | return result; | ||
| 490 | } | ||
| 491 | |||
| 492 | static long | ||
| 493 | round(long double value) | ||
| 494 | { | ||
| 495 | long intpart = value; | ||
| 496 | |||
| 497 | value -= intpart; | ||
| 498 | if (value >= 0.5) | ||
| 499 | intpart++; | ||
| 500 | |||
| 501 | return intpart; | ||
| 502 | } | ||
| 503 | |||
| 504 | static void | ||
| 505 | fmtfp(char *buffer, size_t *currlen, size_t maxlen, long double fvalue, | ||
| 506 | int min, int max, int flags) | ||
| 507 | { | ||
| 508 | char iconvert[20]; | ||
| 509 | char fconvert[20]; | ||
| 510 | int signvalue = 0; | ||
| 511 | int iplace = 0; | ||
| 512 | int fplace = 0; | ||
| 513 | int padlen = 0; /* amount to pad */ | ||
| 514 | int zpadlen = 0; | ||
| 515 | int caps = 0; | ||
| 516 | long intpart; | ||
| 517 | long fracpart; | ||
| 518 | long double ufvalue; | ||
| 519 | |||
| 520 | /* | ||
| 521 | * AIX manpage says the default is 0, but Solaris says the default | ||
| 522 | * is 6, and sprintf on AIX defaults to 6 | ||
| 523 | */ | ||
| 524 | if (max < 0) | ||
| 525 | max = 6; | ||
| 526 | |||
| 527 | ufvalue = abs_val(fvalue); | ||
| 528 | |||
| 529 | if (fvalue < 0) | ||
| 530 | signvalue = '-'; | ||
| 531 | else if (flags & DP_F_PLUS) /* Do a sign (+/i) */ | ||
| 532 | signvalue = '+'; | ||
| 533 | else if (flags & DP_F_SPACE) | ||
| 534 | signvalue = ' '; | ||
| 535 | |||
| 536 | intpart = ufvalue; | ||
| 537 | |||
| 538 | /* | ||
| 539 | * Sorry, we only support 9 digits past the decimal because of our | ||
| 540 | * conversion method | ||
| 541 | */ | ||
| 542 | if (max > 9) | ||
| 543 | max = 9; | ||
| 544 | |||
| 545 | /* We "cheat" by converting the fractional part to integer by | ||
| 546 | * multiplying by a factor of 10 | ||
| 547 | */ | ||
| 548 | fracpart = round((pow10 (max)) * (ufvalue - intpart)); | ||
| 549 | |||
| 550 | if (fracpart >= pow10 (max)) { | ||
| 551 | intpart++; | ||
| 552 | fracpart -= pow10 (max); | ||
| 553 | } | ||
| 554 | |||
| 555 | /* Convert integer part */ | ||
| 556 | do { | ||
| 557 | iconvert[iplace++] = | ||
| 558 | (caps? "0123456789ABCDEF":"0123456789abcdef")[intpart % 10]; | ||
| 559 | intpart = (intpart / 10); | ||
| 560 | } while(intpart && (iplace < 20)); | ||
| 561 | if (iplace == 20) | ||
| 562 | iplace--; | ||
| 563 | iconvert[iplace] = 0; | ||
| 564 | |||
| 565 | /* Convert fractional part */ | ||
| 566 | do { | ||
| 567 | fconvert[fplace++] = | ||
| 568 | (caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10]; | ||
| 569 | fracpart = (fracpart / 10); | ||
| 570 | } while(fracpart && (fplace < 20)); | ||
| 571 | if (fplace == 20) | ||
| 572 | fplace--; | ||
| 573 | fconvert[fplace] = 0; | ||
| 574 | |||
| 575 | /* -1 for decimal point, another -1 if we are printing a sign */ | ||
| 576 | padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); | ||
| 577 | zpadlen = max - fplace; | ||
| 578 | if (zpadlen < 0) | ||
| 579 | zpadlen = 0; | ||
| 580 | if (padlen < 0) | ||
| 581 | padlen = 0; | ||
| 582 | if (flags & DP_F_MINUS) | ||
| 583 | padlen = -padlen; /* Left Justifty */ | ||
| 584 | |||
| 585 | if ((flags & DP_F_ZERO) && (padlen > 0)) { | ||
| 586 | if (signvalue) { | ||
| 587 | dopr_outch(buffer, currlen, maxlen, signvalue); | ||
| 588 | --padlen; | ||
| 589 | signvalue = 0; | ||
| 590 | } | ||
| 591 | while (padlen > 0) { | ||
| 592 | dopr_outch(buffer, currlen, maxlen, '0'); | ||
| 593 | --padlen; | ||
| 594 | } | ||
| 595 | } | ||
| 596 | while (padlen > 0) { | ||
| 597 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
| 598 | --padlen; | ||
| 599 | } | ||
| 600 | if (signvalue) | ||
| 601 | dopr_outch(buffer, currlen, maxlen, signvalue); | ||
| 602 | |||
| 603 | while (iplace > 0) | ||
| 604 | dopr_outch(buffer, currlen, maxlen, iconvert[--iplace]); | ||
| 605 | |||
| 606 | /* | ||
| 607 | * Decimal point. This should probably use locale to find the correct | ||
| 608 | * char to print out. | ||
| 609 | */ | ||
| 610 | dopr_outch(buffer, currlen, maxlen, '.'); | ||
| 611 | |||
| 612 | while (fplace > 0) | ||
| 613 | dopr_outch(buffer, currlen, maxlen, fconvert[--fplace]); | ||
| 614 | |||
| 615 | while (zpadlen > 0) { | ||
| 616 | dopr_outch(buffer, currlen, maxlen, '0'); | ||
| 617 | --zpadlen; | ||
| 618 | } | ||
| 619 | |||
| 620 | while (padlen < 0) { | ||
| 621 | dopr_outch(buffer, currlen, maxlen, ' '); | ||
| 622 | ++padlen; | ||
| 623 | } | ||
| 624 | } | ||
| 625 | |||
| 626 | static void | ||
| 627 | dopr_outch(char *buffer, size_t *currlen, size_t maxlen, char c) | ||
| 628 | { | ||
| 629 | if (*currlen < maxlen) | ||
| 630 | buffer[(*currlen)++] = c; | ||
| 631 | } | ||
| 632 | #endif /* !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF) */ | ||
| 633 | |||
| 634 | #ifndef HAVE_VSNPRINTF | ||
| 635 | int | ||
| 636 | vsnprintf(char *str, size_t count, const char *fmt, va_list args) | ||
| 637 | { | ||
| 638 | str[0] = 0; | ||
| 639 | dopr(str, count, fmt, args); | ||
| 640 | |||
| 641 | return(strlen(str)); | ||
| 642 | } | ||
| 643 | #endif /* !HAVE_VSNPRINTF */ | ||
| 644 | |||
| 645 | #ifndef HAVE_SNPRINTF | ||
| 646 | int | ||
| 647 | snprintf(char *str,size_t count,const char *fmt,...) | ||
| 648 | { | ||
| 649 | va_list ap; | ||
| 650 | |||
| 651 | va_start(ap, fmt); | ||
| 652 | (void) vsnprintf(str, count, fmt, ap); | ||
| 653 | va_end(ap); | ||
| 654 | |||
| 655 | return(strlen(str)); | ||
| 656 | } | ||
| 657 | |||
| 658 | #ifdef TEST_SNPRINTF | ||
| 659 | int | ||
| 660 | main(void) | ||
| 661 | { | ||
| 662 | #define LONG_STRING 1024 | ||
| 663 | char buf1[LONG_STRING]; | ||
| 664 | char buf2[LONG_STRING]; | ||
| 665 | char *fp_fmt[] = { | ||
| 666 | "%-1.5f", | ||
| 667 | "%1.5f", | ||
| 668 | "%123.9f", | ||
| 669 | "%10.5f", | ||
| 670 | "% 10.5f", | ||
| 671 | "%+22.9f", | ||
| 672 | "%+4.9f", | ||
| 673 | "%01.3f", | ||
| 674 | "%4f", | ||
| 675 | "%3.1f", | ||
| 676 | "%3.2f", | ||
| 677 | NULL | ||
| 678 | }; | ||
| 679 | double fp_nums[] = { | ||
| 680 | -1.5, | ||
| 681 | 134.21, | ||
| 682 | 91340.2, | ||
| 683 | 341.1234, | ||
| 684 | 0203.9, | ||
| 685 | 0.96, | ||
| 686 | 0.996, | ||
| 687 | 0.9996, | ||
| 688 | 1.996, | ||
| 689 | 4.136, | ||
| 690 | 0 | ||
| 691 | }; | ||
| 692 | char *int_fmt[] = { | ||
| 693 | "%-1.5d", | ||
| 694 | "%1.5d", | ||
| 695 | "%123.9d", | ||
| 696 | "%5.5d", | ||
| 697 | "%10.5d", | ||
| 698 | "% 10.5d", | ||
| 699 | "%+22.33d", | ||
| 700 | "%01.3d", | ||
| 701 | "%4d", | ||
| 702 | "%lld", | ||
| 703 | "%qd", | ||
| 704 | NULL | ||
| 705 | }; | ||
| 706 | long long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 }; | ||
| 707 | int x, y; | ||
| 708 | int fail = 0; | ||
| 709 | int num = 0; | ||
| 710 | |||
| 711 | printf("Testing snprintf format codes against system sprintf...\n"); | ||
| 712 | |||
| 713 | for (x = 0; fp_fmt[x] != NULL ; x++) { | ||
| 714 | for (y = 0; fp_nums[y] != 0 ; y++) { | ||
| 715 | snprintf(buf1, sizeof (buf1), fp_fmt[x], fp_nums[y]); | ||
| 716 | sprintf (buf2, fp_fmt[x], fp_nums[y]); | ||
| 717 | if (strcmp (buf1, buf2)) { | ||
| 718 | printf("snprintf doesn't match Format: %s\n\t" | ||
| 719 | "snprintf = %s\n\tsprintf = %s\n", | ||
| 720 | fp_fmt[x], buf1, buf2); | ||
| 721 | fail++; | ||
| 722 | } | ||
| 723 | num++; | ||
| 724 | } | ||
| 725 | } | ||
| 726 | for (x = 0; int_fmt[x] != NULL ; x++) { | ||
| 727 | for (y = 0; int_nums[y] != 0 ; y++) { | ||
| 728 | snprintf(buf1, sizeof (buf1), int_fmt[x], int_nums[y]); | ||
| 729 | sprintf(buf2, int_fmt[x], int_nums[y]); | ||
| 730 | if (strcmp (buf1, buf2)) { | ||
| 731 | printf("snprintf doesn't match Format: %s\n\t" | ||
| 732 | "snprintf = %s\n\tsprintf = %s\n", | ||
| 733 | int_fmt[x], buf1, buf2); | ||
| 734 | fail++; | ||
| 735 | } | ||
| 736 | num++; | ||
| 737 | } | ||
| 738 | } | ||
| 739 | printf("%d tests failed out of %d.\n", fail, num); | ||
| 740 | return(0); | ||
| 741 | } | ||
| 742 | #endif /* SNPRINTF_TEST */ | ||
| 743 | |||
| 744 | #endif /* !HAVE_SNPRINTF */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-snprintf.h b/other/ssharp/openbsd-compat/bsd-snprintf.h new file mode 100644 index 0000000..c9cd4f9 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-snprintf.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | /* $Id: bsd-snprintf.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_SNPRINTF_H | ||
| 4 | #define _BSD_SNPRINTF_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #include <sys/types.h> /* For size_t */ | ||
| 9 | |||
| 10 | #ifndef HAVE_SNPRINTF | ||
| 11 | int snprintf(char *str, size_t count, const char *fmt, ...); | ||
| 12 | #endif /* !HAVE_SNPRINTF */ | ||
| 13 | |||
| 14 | #ifndef HAVE_VSNPRINTF | ||
| 15 | int vsnprintf(char *str, size_t count, const char *fmt, va_list args); | ||
| 16 | #endif /* !HAVE_SNPRINTF */ | ||
| 17 | |||
| 18 | |||
| 19 | #endif /* _BSD_SNPRINTF_H */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-waitpid.c b/other/ssharp/openbsd-compat/bsd-waitpid.c new file mode 100644 index 0000000..9c62ece --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-waitpid.c | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* | ||
| 2 | * Redistribution and use in source and binary forms, with or without | ||
| 3 | * modification, are permitted provided that the following conditions | ||
| 4 | * are met: | ||
| 5 | * 1. Redistributions of source code must retain the above copyright | ||
| 6 | * notice, this list of conditions and the following disclaimer. | ||
| 7 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer in the | ||
| 9 | * documentation and/or other materials provided with the distribution. | ||
| 10 | * | ||
| 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 13 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 14 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 15 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 16 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 17 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 18 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 19 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 20 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "includes.h" | ||
| 24 | |||
| 25 | RCSID("$Id: bsd-waitpid.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 26 | |||
| 27 | #ifndef HAVE_WAITPID | ||
| 28 | #include <errno.h> | ||
| 29 | #include <sys/wait.h> | ||
| 30 | #include "bsd-waitpid.h" | ||
| 31 | |||
| 32 | pid_t | ||
| 33 | waitpid(int pid, int *stat_loc, int options) | ||
| 34 | { | ||
| 35 | union wait statusp; | ||
| 36 | pid_t wait_pid; | ||
| 37 | |||
| 38 | if (pid <= 0) { | ||
| 39 | if (pid != -1) { | ||
| 40 | errno = EINVAL; | ||
| 41 | return -1; | ||
| 42 | } | ||
| 43 | pid = 0; /* wait4() wants pid=0 for indiscriminate wait. */ | ||
| 44 | } | ||
| 45 | wait_pid = wait4(pid, &statusp, options, NULL); | ||
| 46 | if (stat_loc) | ||
| 47 | *stat_loc = (int) statusp.w_status; | ||
| 48 | |||
| 49 | return wait_pid; | ||
| 50 | } | ||
| 51 | |||
| 52 | #endif /* !HAVE_WAITPID */ | ||
diff --git a/other/ssharp/openbsd-compat/bsd-waitpid.h b/other/ssharp/openbsd-compat/bsd-waitpid.h new file mode 100644 index 0000000..3f2a884 --- /dev/null +++ b/other/ssharp/openbsd-compat/bsd-waitpid.h | |||
| @@ -0,0 +1,49 @@ | |||
| 1 | /* | ||
| 2 | * Redistribution and use in source and binary forms, with or without | ||
| 3 | * modification, are permitted provided that the following conditions | ||
| 4 | * are met: | ||
| 5 | * 1. Redistributions of source code must retain the above copyright | ||
| 6 | * notice, this list of conditions and the following disclaimer. | ||
| 7 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 8 | * notice, this list of conditions and the following disclaimer in the | ||
| 9 | * documentation and/or other materials provided with the distribution. | ||
| 10 | * | ||
| 11 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 12 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 13 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 14 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 15 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 16 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 17 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 18 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 19 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 20 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 21 | * | ||
| 22 | */ | ||
| 23 | |||
| 24 | /* $Id: bsd-waitpid.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 25 | |||
| 26 | #ifndef _BSD_WAITPID_H | ||
| 27 | #define _BSD_WAITPID_H | ||
| 28 | |||
| 29 | #ifndef HAVE_WAITPID | ||
| 30 | /* Clean out any potental issues */ | ||
| 31 | #undef WIFEXITED | ||
| 32 | #undef WIFSTOPPED | ||
| 33 | #undef WIFSIGNALED | ||
| 34 | |||
| 35 | /* Define required functions to mimic a POSIX look and feel */ | ||
| 36 | #define _W_INT(w) (*(int*)&(w)) /* convert union wait to int */ | ||
| 37 | #define WIFEXITED(w) (!((_W_INT(w)) & 0377)) | ||
| 38 | #define WIFSTOPPED(w) ((_W_INT(w)) & 0100) | ||
| 39 | #define WIFSIGNALED(w) (!WIFEXITED(w) && !WIFSTOPPED(w)) | ||
| 40 | #define WEXITSTATUS(w) (int)(WIFEXITED(w) ? ((_W_INT(w) >> 8) & 0377) : -1) | ||
| 41 | #define WTERMSIG(w) (int)(WIFSIGNALED(w) ? (_W_INT(w) & 0177) : -1) | ||
| 42 | #define WCOREFLAG 0x80 | ||
| 43 | #define WCOREDUMP(w) ((_W_INT(w)) & WCOREFLAG) | ||
| 44 | |||
| 45 | /* Prototype */ | ||
| 46 | pid_t waitpid(int pid, int *stat_loc, int options); | ||
| 47 | |||
| 48 | #endif /* !HAVE_WAITPID */ | ||
| 49 | #endif /* _BSD_WAITPID_H */ | ||
diff --git a/other/ssharp/openbsd-compat/daemon.c b/other/ssharp/openbsd-compat/daemon.c new file mode 100644 index 0000000..f704a90 --- /dev/null +++ b/other/ssharp/openbsd-compat/daemon.c | |||
| @@ -0,0 +1,81 @@ | |||
| 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 | |||
| 34 | #include "includes.h" | ||
| 35 | |||
| 36 | #ifndef HAVE_DAEMON | ||
| 37 | |||
| 38 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 39 | static char rcsid[] = "$OpenBSD: daemon.c,v 1.2 1996/08/19 08:22:13 tholo Exp $"; | ||
| 40 | #endif /* LIBC_SCCS and not lint */ | ||
| 41 | |||
| 42 | int | ||
| 43 | daemon(nochdir, noclose) | ||
| 44 | int nochdir, noclose; | ||
| 45 | { | ||
| 46 | int fd; | ||
| 47 | |||
| 48 | switch (fork()) { | ||
| 49 | case -1: | ||
| 50 | return (-1); | ||
| 51 | case 0: | ||
| 52 | break; | ||
| 53 | default: | ||
| 54 | #ifdef HAVE_CYGWIN | ||
| 55 | /* | ||
| 56 | * This sleep avoids a race condition which kills the | ||
| 57 | * child process if parent is started by a NT/W2K service. | ||
| 58 | */ | ||
| 59 | sleep(1); | ||
| 60 | #endif | ||
| 61 | _exit(0); | ||
| 62 | } | ||
| 63 | |||
| 64 | if (setsid() == -1) | ||
| 65 | return (-1); | ||
| 66 | |||
| 67 | if (!nochdir) | ||
| 68 | (void)chdir("/"); | ||
| 69 | |||
| 70 | if (!noclose && (fd = open(_PATH_DEVNULL, O_RDWR, 0)) != -1) { | ||
| 71 | (void)dup2(fd, STDIN_FILENO); | ||
| 72 | (void)dup2(fd, STDOUT_FILENO); | ||
| 73 | (void)dup2(fd, STDERR_FILENO); | ||
| 74 | if (fd > 2) | ||
| 75 | (void)close (fd); | ||
| 76 | } | ||
| 77 | return (0); | ||
| 78 | } | ||
| 79 | |||
| 80 | #endif /* !HAVE_DAEMON */ | ||
| 81 | |||
diff --git a/other/ssharp/openbsd-compat/daemon.h b/other/ssharp/openbsd-compat/daemon.h new file mode 100644 index 0000000..bfab99c --- /dev/null +++ b/other/ssharp/openbsd-compat/daemon.h | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | /* $Id: daemon.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_DAEMON_H | ||
| 4 | #define _BSD_DAEMON_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | #ifndef HAVE_DAEMON | ||
| 8 | int daemon(int nochdir, int noclose); | ||
| 9 | #endif /* !HAVE_DAEMON */ | ||
| 10 | |||
| 11 | #endif /* _BSD_DAEMON_H */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-gai-errnos.h b/other/ssharp/openbsd-compat/fake-gai-errnos.h new file mode 100644 index 0000000..0787bdc --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-gai-errnos.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | /* | ||
| 2 | * fake library for ssh | ||
| 3 | * | ||
| 4 | * This file is included in getaddrinfo.c and getnameinfo.c. | ||
| 5 | * See getaddrinfo.c and getnameinfo.c. | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* $Id: fake-gai-errnos.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 9 | |||
| 10 | /* for old netdb.h */ | ||
| 11 | #ifndef EAI_NODATA | ||
| 12 | #define EAI_NODATA 1 | ||
| 13 | #define EAI_MEMORY 2 | ||
| 14 | #endif | ||
diff --git a/other/ssharp/openbsd-compat/fake-getaddrinfo.c b/other/ssharp/openbsd-compat/fake-getaddrinfo.c new file mode 100644 index 0000000..c5af9ce --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-getaddrinfo.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* | ||
| 2 | * fake library for ssh | ||
| 3 | * | ||
| 4 | * This file includes getaddrinfo(), freeaddrinfo() and gai_strerror(). | ||
| 5 | * These funtions are defined in rfc2133. | ||
| 6 | * | ||
| 7 | * But these functions are not implemented correctly. The minimum subset | ||
| 8 | * is implemented for ssh use only. For exapmle, this routine assumes | ||
| 9 | * that ai_family is AF_INET. Don't use it for another purpose. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include "includes.h" | ||
| 13 | #include "ssh.h" | ||
| 14 | |||
| 15 | RCSID("$Id: fake-getaddrinfo.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 16 | |||
| 17 | #ifndef HAVE_GAI_STRERROR | ||
| 18 | char *gai_strerror(int ecode) | ||
| 19 | { | ||
| 20 | switch (ecode) { | ||
| 21 | case EAI_NODATA: | ||
| 22 | return "no address associated with hostname."; | ||
| 23 | case EAI_MEMORY: | ||
| 24 | return "memory allocation failure."; | ||
| 25 | default: | ||
| 26 | return "unknown error."; | ||
| 27 | } | ||
| 28 | } | ||
| 29 | #endif /* !HAVE_GAI_STRERROR */ | ||
| 30 | |||
| 31 | #ifndef HAVE_FREEADDRINFO | ||
| 32 | void freeaddrinfo(struct addrinfo *ai) | ||
| 33 | { | ||
| 34 | struct addrinfo *next; | ||
| 35 | |||
| 36 | do { | ||
| 37 | next = ai->ai_next; | ||
| 38 | free(ai); | ||
| 39 | } while (NULL != (ai = next)); | ||
| 40 | } | ||
| 41 | #endif /* !HAVE_FREEADDRINFO */ | ||
| 42 | |||
| 43 | #ifndef HAVE_GETADDRINFO | ||
| 44 | static struct addrinfo *malloc_ai(int port, u_long addr) | ||
| 45 | { | ||
| 46 | struct addrinfo *ai; | ||
| 47 | |||
| 48 | ai = malloc(sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); | ||
| 49 | if (ai == NULL) | ||
| 50 | return(NULL); | ||
| 51 | |||
| 52 | memset(ai, 0, sizeof(struct addrinfo) + sizeof(struct sockaddr_in)); | ||
| 53 | |||
| 54 | ai->ai_addr = (struct sockaddr *)(ai + 1); | ||
| 55 | /* XXX -- ssh doesn't use sa_len */ | ||
| 56 | ai->ai_addrlen = sizeof(struct sockaddr_in); | ||
| 57 | ai->ai_addr->sa_family = ai->ai_family = AF_INET; | ||
| 58 | |||
| 59 | ((struct sockaddr_in *)(ai)->ai_addr)->sin_port = port; | ||
| 60 | ((struct sockaddr_in *)(ai)->ai_addr)->sin_addr.s_addr = addr; | ||
| 61 | |||
| 62 | return(ai); | ||
| 63 | } | ||
| 64 | |||
| 65 | int getaddrinfo(const char *hostname, const char *servname, | ||
| 66 | const struct addrinfo *hints, struct addrinfo **res) | ||
| 67 | { | ||
| 68 | struct addrinfo *cur, *prev = NULL; | ||
| 69 | struct hostent *hp; | ||
| 70 | struct in_addr in; | ||
| 71 | int i, port; | ||
| 72 | |||
| 73 | if (servname) | ||
| 74 | port = htons(atoi(servname)); | ||
| 75 | else | ||
| 76 | port = 0; | ||
| 77 | |||
| 78 | if (hints && hints->ai_flags & AI_PASSIVE) { | ||
| 79 | if (NULL != (*res = malloc_ai(port, htonl(0x00000000)))) | ||
| 80 | return 0; | ||
| 81 | else | ||
| 82 | return EAI_MEMORY; | ||
| 83 | } | ||
| 84 | |||
| 85 | if (!hostname) { | ||
| 86 | if (NULL != (*res = malloc_ai(port, htonl(0x7f000001)))) | ||
| 87 | return 0; | ||
| 88 | else | ||
| 89 | return EAI_MEMORY; | ||
| 90 | } | ||
| 91 | |||
| 92 | if (inet_aton(hostname, &in)) { | ||
| 93 | if (NULL != (*res = malloc_ai(port, in.s_addr))) | ||
| 94 | return 0; | ||
| 95 | else | ||
| 96 | return EAI_MEMORY; | ||
| 97 | } | ||
| 98 | |||
| 99 | hp = gethostbyname(hostname); | ||
| 100 | if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) { | ||
| 101 | for (i = 0; hp->h_addr_list[i]; i++) { | ||
| 102 | cur = malloc_ai(port, ((struct in_addr *)hp->h_addr_list[i])->s_addr); | ||
| 103 | if (cur == NULL) { | ||
| 104 | if (*res) | ||
| 105 | freeaddrinfo(*res); | ||
| 106 | return EAI_MEMORY; | ||
| 107 | } | ||
| 108 | |||
| 109 | if (prev) | ||
| 110 | prev->ai_next = cur; | ||
| 111 | else | ||
| 112 | *res = cur; | ||
| 113 | |||
| 114 | prev = cur; | ||
| 115 | } | ||
| 116 | return 0; | ||
| 117 | } | ||
| 118 | |||
| 119 | return EAI_NODATA; | ||
| 120 | } | ||
| 121 | #endif /* !HAVE_GETADDRINFO */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-getaddrinfo.h b/other/ssharp/openbsd-compat/fake-getaddrinfo.h new file mode 100644 index 0000000..dbc398e --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-getaddrinfo.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | /* $Id: fake-getaddrinfo.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _FAKE_GETADDRINFO_H | ||
| 4 | #define _FAKE_GETADDRINFO_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #include "fake-gai-errnos.h" | ||
| 9 | |||
| 10 | #ifndef AI_PASSIVE | ||
| 11 | # define AI_PASSIVE 1 | ||
| 12 | # define AI_CANONNAME 2 | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #ifndef NI_NUMERICHOST | ||
| 16 | # define NI_NUMERICHOST 2 | ||
| 17 | # define NI_NAMEREQD 4 | ||
| 18 | # define NI_NUMERICSERV 8 | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #ifndef HAVE_STRUCT_ADDRINFO | ||
| 22 | struct addrinfo { | ||
| 23 | int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ | ||
| 24 | int ai_family; /* PF_xxx */ | ||
| 25 | int ai_socktype; /* SOCK_xxx */ | ||
| 26 | int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ | ||
| 27 | size_t ai_addrlen; /* length of ai_addr */ | ||
| 28 | char *ai_canonname; /* canonical name for hostname */ | ||
| 29 | struct sockaddr *ai_addr; /* binary address */ | ||
| 30 | struct addrinfo *ai_next; /* next structure in linked list */ | ||
| 31 | }; | ||
| 32 | #endif /* !HAVE_STRUCT_ADDRINFO */ | ||
| 33 | |||
| 34 | #ifndef HAVE_GETADDRINFO | ||
| 35 | int getaddrinfo(const char *hostname, const char *servname, | ||
| 36 | const struct addrinfo *hints, struct addrinfo **res); | ||
| 37 | #endif /* !HAVE_GETADDRINFO */ | ||
| 38 | |||
| 39 | #ifndef HAVE_GAI_STRERROR | ||
| 40 | char *gai_strerror(int ecode); | ||
| 41 | #endif /* !HAVE_GAI_STRERROR */ | ||
| 42 | |||
| 43 | #ifndef HAVE_FREEADDRINFO | ||
| 44 | void freeaddrinfo(struct addrinfo *ai); | ||
| 45 | #endif /* !HAVE_FREEADDRINFO */ | ||
| 46 | |||
| 47 | #endif /* _FAKE_GETADDRINFO_H */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-getnameinfo.c b/other/ssharp/openbsd-compat/fake-getnameinfo.c new file mode 100644 index 0000000..172b58d --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-getnameinfo.c | |||
| @@ -0,0 +1,55 @@ | |||
| 1 | /* | ||
| 2 | * fake library for ssh | ||
| 3 | * | ||
| 4 | * This file includes getnameinfo(). | ||
| 5 | * These funtions are defined in rfc2133. | ||
| 6 | * | ||
| 7 | * But these functions are not implemented correctly. The minimum subset | ||
| 8 | * is implemented for ssh use only. For exapmle, this routine assumes | ||
| 9 | * that ai_family is AF_INET. Don't use it for another purpose. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include "includes.h" | ||
| 13 | #include "ssh.h" | ||
| 14 | |||
| 15 | RCSID("$Id: fake-getnameinfo.c,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $"); | ||
| 16 | |||
| 17 | #ifndef HAVE_GETNAMEINFO | ||
| 18 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, | ||
| 19 | size_t hostlen, char *serv, size_t servlen, int flags) | ||
| 20 | { | ||
| 21 | struct sockaddr_in *sin = (struct sockaddr_in *)sa; | ||
| 22 | struct hostent *hp; | ||
| 23 | char tmpserv[16]; | ||
| 24 | |||
| 25 | if (serv) { | ||
| 26 | snprintf(tmpserv, sizeof(tmpserv), "%d", ntohs(sin->sin_port)); | ||
| 27 | if (strlen(tmpserv) >= servlen) | ||
| 28 | return EAI_MEMORY; | ||
| 29 | else | ||
| 30 | strcpy(serv, tmpserv); | ||
| 31 | } | ||
| 32 | |||
| 33 | if (host) { | ||
| 34 | if (flags & NI_NUMERICHOST) { | ||
| 35 | if (strlen(inet_ntoa(sin->sin_addr)) >= hostlen) | ||
| 36 | return EAI_MEMORY; | ||
| 37 | |||
| 38 | strcpy(host, inet_ntoa(sin->sin_addr)); | ||
| 39 | return 0; | ||
| 40 | } else { | ||
| 41 | hp = gethostbyaddr((char *)&sin->sin_addr, | ||
| 42 | sizeof(struct in_addr), AF_INET); | ||
| 43 | if (hp == NULL) | ||
| 44 | return EAI_NODATA; | ||
| 45 | |||
| 46 | if (strlen(hp->h_name) >= hostlen) | ||
| 47 | return EAI_MEMORY; | ||
| 48 | |||
| 49 | strcpy(host, hp->h_name); | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | #endif /* !HAVE_GETNAMEINFO */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-getnameinfo.h b/other/ssharp/openbsd-compat/fake-getnameinfo.h new file mode 100644 index 0000000..8177cae --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-getnameinfo.h | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | /* $Id: fake-getnameinfo.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _FAKE_GETNAMEINFO_H | ||
| 4 | #define _FAKE_GETNAMEINFO_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_GETNAMEINFO | ||
| 9 | int getnameinfo(const struct sockaddr *sa, size_t salen, char *host, | ||
| 10 | size_t hostlen, char *serv, size_t servlen, int flags); | ||
| 11 | #endif /* !HAVE_GETNAMEINFO */ | ||
| 12 | |||
| 13 | #ifndef NI_MAXSERV | ||
| 14 | # define NI_MAXSERV 32 | ||
| 15 | #endif /* !NI_MAXSERV */ | ||
| 16 | #ifndef NI_MAXHOST | ||
| 17 | # define NI_MAXHOST 1025 | ||
| 18 | #endif /* !NI_MAXHOST */ | ||
| 19 | |||
| 20 | #endif /* _FAKE_GETNAMEINFO_H */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-queue.h b/other/ssharp/openbsd-compat/fake-queue.h new file mode 100644 index 0000000..269af41 --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-queue.h | |||
| @@ -0,0 +1,490 @@ | |||
| 1 | /* $OpenBSD: queue.h,v 1.16 2000/09/07 19:47:59 art Exp $ */ | ||
| 2 | /* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1991, 1993 | ||
| 6 | * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by the University of | ||
| 19 | * California, Berkeley and its contributors. | ||
| 20 | * 4. Neither the name of the University nor the names of its contributors | ||
| 21 | * may be used to endorse or promote products derived from this software | ||
| 22 | * without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 34 | * SUCH DAMAGE. | ||
| 35 | * | ||
| 36 | * @(#)queue.h 8.5 (Berkeley) 8/20/94 | ||
| 37 | */ | ||
| 38 | |||
| 39 | #ifndef _SYS_QUEUE_H_ | ||
| 40 | #define _SYS_QUEUE_H_ | ||
| 41 | |||
| 42 | /* | ||
| 43 | * This file defines five types of data structures: singly-linked lists, | ||
| 44 | * lists, simple queues, tail queues, and circular queues. | ||
| 45 | * | ||
| 46 | * | ||
| 47 | * A singly-linked list is headed by a single forward pointer. The elements | ||
| 48 | * are singly linked for minimum space and pointer manipulation overhead at | ||
| 49 | * the expense of O(n) removal for arbitrary elements. New elements can be | ||
| 50 | * added to the list after an existing element or at the head of the list. | ||
| 51 | * Elements being removed from the head of the list should use the explicit | ||
| 52 | * macro for this purpose for optimum efficiency. A singly-linked list may | ||
| 53 | * only be traversed in the forward direction. Singly-linked lists are ideal | ||
| 54 | * for applications with large datasets and few or no removals or for | ||
| 55 | * implementing a LIFO queue. | ||
| 56 | * | ||
| 57 | * A list is headed by a single forward pointer (or an array of forward | ||
| 58 | * pointers for a hash table header). The elements are doubly linked | ||
| 59 | * so that an arbitrary element can be removed without a need to | ||
| 60 | * traverse the list. New elements can be added to the list before | ||
| 61 | * or after an existing element or at the head of the list. A list | ||
| 62 | * may only be traversed in the forward direction. | ||
| 63 | * | ||
| 64 | * A simple queue is headed by a pair of pointers, one the head of the | ||
| 65 | * list and the other to the tail of the list. The elements are singly | ||
| 66 | * linked to save space, so elements can only be removed from the | ||
| 67 | * head of the list. New elements can be added to the list before or after | ||
| 68 | * an existing element, at the head of the list, or at the end of the | ||
| 69 | * list. A simple queue may only be traversed in the forward direction. | ||
| 70 | * | ||
| 71 | * A tail queue is headed by a pair of pointers, one to the head of the | ||
| 72 | * list and the other to the tail of the list. The elements are doubly | ||
| 73 | * linked so that an arbitrary element can be removed without a need to | ||
| 74 | * traverse the list. New elements can be added to the list before or | ||
| 75 | * after an existing element, at the head of the list, or at the end of | ||
| 76 | * the list. A tail queue may be traversed in either direction. | ||
| 77 | * | ||
| 78 | * A circle queue is headed by a pair of pointers, one to the head of the | ||
| 79 | * list and the other to the tail of the list. The elements are doubly | ||
| 80 | * linked so that an arbitrary element can be removed without a need to | ||
| 81 | * traverse the list. New elements can be added to the list before or after | ||
| 82 | * an existing element, at the head of the list, or at the end of the list. | ||
| 83 | * A circle queue may be traversed in either direction, but has a more | ||
| 84 | * complex end of list detection. | ||
| 85 | * | ||
| 86 | * For details on the use of these macros, see the queue(3) manual page. | ||
| 87 | */ | ||
| 88 | |||
| 89 | /* | ||
| 90 | * Singly-linked List definitions. | ||
| 91 | */ | ||
| 92 | #define SLIST_HEAD(name, type) \ | ||
| 93 | struct name { \ | ||
| 94 | struct type *slh_first; /* first element */ \ | ||
| 95 | } | ||
| 96 | |||
| 97 | #define SLIST_HEAD_INITIALIZER(head) \ | ||
| 98 | { NULL } | ||
| 99 | |||
| 100 | #define SLIST_ENTRY(type) \ | ||
| 101 | struct { \ | ||
| 102 | struct type *sle_next; /* next element */ \ | ||
| 103 | } | ||
| 104 | |||
| 105 | /* | ||
| 106 | * Singly-linked List access methods. | ||
| 107 | */ | ||
| 108 | #define SLIST_FIRST(head) ((head)->slh_first) | ||
| 109 | #define SLIST_END(head) NULL | ||
| 110 | #define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) | ||
| 111 | #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) | ||
| 112 | |||
| 113 | #define SLIST_FOREACH(var, head, field) \ | ||
| 114 | for((var) = SLIST_FIRST(head); \ | ||
| 115 | (var) != SLIST_END(head); \ | ||
| 116 | (var) = SLIST_NEXT(var, field)) | ||
| 117 | |||
| 118 | /* | ||
| 119 | * Singly-linked List functions. | ||
| 120 | */ | ||
| 121 | #define SLIST_INIT(head) { \ | ||
| 122 | SLIST_FIRST(head) = SLIST_END(head); \ | ||
| 123 | } | ||
| 124 | |||
| 125 | #define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ | ||
| 126 | (elm)->field.sle_next = (slistelm)->field.sle_next; \ | ||
| 127 | (slistelm)->field.sle_next = (elm); \ | ||
| 128 | } while (0) | ||
| 129 | |||
| 130 | #define SLIST_INSERT_HEAD(head, elm, field) do { \ | ||
| 131 | (elm)->field.sle_next = (head)->slh_first; \ | ||
| 132 | (head)->slh_first = (elm); \ | ||
| 133 | } while (0) | ||
| 134 | |||
| 135 | #define SLIST_REMOVE_HEAD(head, field) do { \ | ||
| 136 | (head)->slh_first = (head)->slh_first->field.sle_next; \ | ||
| 137 | } while (0) | ||
| 138 | |||
| 139 | /* | ||
| 140 | * List definitions. | ||
| 141 | */ | ||
| 142 | #define LIST_HEAD(name, type) \ | ||
| 143 | struct name { \ | ||
| 144 | struct type *lh_first; /* first element */ \ | ||
| 145 | } | ||
| 146 | |||
| 147 | #define LIST_HEAD_INITIALIZER(head) \ | ||
| 148 | { NULL } | ||
| 149 | |||
| 150 | #define LIST_ENTRY(type) \ | ||
| 151 | struct { \ | ||
| 152 | struct type *le_next; /* next element */ \ | ||
| 153 | struct type **le_prev; /* address of previous next element */ \ | ||
| 154 | } | ||
| 155 | |||
| 156 | /* | ||
| 157 | * List access methods | ||
| 158 | */ | ||
| 159 | #define LIST_FIRST(head) ((head)->lh_first) | ||
| 160 | #define LIST_END(head) NULL | ||
| 161 | #define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) | ||
| 162 | #define LIST_NEXT(elm, field) ((elm)->field.le_next) | ||
| 163 | |||
| 164 | #define LIST_FOREACH(var, head, field) \ | ||
| 165 | for((var) = LIST_FIRST(head); \ | ||
| 166 | (var)!= LIST_END(head); \ | ||
| 167 | (var) = LIST_NEXT(var, field)) | ||
| 168 | |||
| 169 | /* | ||
| 170 | * List functions. | ||
| 171 | */ | ||
| 172 | #define LIST_INIT(head) do { \ | ||
| 173 | LIST_FIRST(head) = LIST_END(head); \ | ||
| 174 | } while (0) | ||
| 175 | |||
| 176 | #define LIST_INSERT_AFTER(listelm, elm, field) do { \ | ||
| 177 | if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ | ||
| 178 | (listelm)->field.le_next->field.le_prev = \ | ||
| 179 | &(elm)->field.le_next; \ | ||
| 180 | (listelm)->field.le_next = (elm); \ | ||
| 181 | (elm)->field.le_prev = &(listelm)->field.le_next; \ | ||
| 182 | } while (0) | ||
| 183 | |||
| 184 | #define LIST_INSERT_BEFORE(listelm, elm, field) do { \ | ||
| 185 | (elm)->field.le_prev = (listelm)->field.le_prev; \ | ||
| 186 | (elm)->field.le_next = (listelm); \ | ||
| 187 | *(listelm)->field.le_prev = (elm); \ | ||
| 188 | (listelm)->field.le_prev = &(elm)->field.le_next; \ | ||
| 189 | } while (0) | ||
| 190 | |||
| 191 | #define LIST_INSERT_HEAD(head, elm, field) do { \ | ||
| 192 | if (((elm)->field.le_next = (head)->lh_first) != NULL) \ | ||
| 193 | (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ | ||
| 194 | (head)->lh_first = (elm); \ | ||
| 195 | (elm)->field.le_prev = &(head)->lh_first; \ | ||
| 196 | } while (0) | ||
| 197 | |||
| 198 | #define LIST_REMOVE(elm, field) do { \ | ||
| 199 | if ((elm)->field.le_next != NULL) \ | ||
| 200 | (elm)->field.le_next->field.le_prev = \ | ||
| 201 | (elm)->field.le_prev; \ | ||
| 202 | *(elm)->field.le_prev = (elm)->field.le_next; \ | ||
| 203 | } while (0) | ||
| 204 | |||
| 205 | #define LIST_REPLACE(elm, elm2, field) do { \ | ||
| 206 | if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ | ||
| 207 | (elm2)->field.le_next->field.le_prev = \ | ||
| 208 | &(elm2)->field.le_next; \ | ||
| 209 | (elm2)->field.le_prev = (elm)->field.le_prev; \ | ||
| 210 | *(elm2)->field.le_prev = (elm2); \ | ||
| 211 | } while (0) | ||
| 212 | |||
| 213 | /* | ||
| 214 | * Simple queue definitions. | ||
| 215 | */ | ||
| 216 | #define SIMPLEQ_HEAD(name, type) \ | ||
| 217 | struct name { \ | ||
| 218 | struct type *sqh_first; /* first element */ \ | ||
| 219 | struct type **sqh_last; /* addr of last next element */ \ | ||
| 220 | } | ||
| 221 | |||
| 222 | #define SIMPLEQ_HEAD_INITIALIZER(head) \ | ||
| 223 | { NULL, &(head).sqh_first } | ||
| 224 | |||
| 225 | #define SIMPLEQ_ENTRY(type) \ | ||
| 226 | struct { \ | ||
| 227 | struct type *sqe_next; /* next element */ \ | ||
| 228 | } | ||
| 229 | |||
| 230 | /* | ||
| 231 | * Simple queue access methods. | ||
| 232 | */ | ||
| 233 | #define SIMPLEQ_FIRST(head) ((head)->sqh_first) | ||
| 234 | #define SIMPLEQ_END(head) NULL | ||
| 235 | #define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head)) | ||
| 236 | #define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next) | ||
| 237 | |||
| 238 | #define SIMPLEQ_FOREACH(var, head, field) \ | ||
| 239 | for((var) = SIMPLEQ_FIRST(head); \ | ||
| 240 | (var) != SIMPLEQ_END(head); \ | ||
| 241 | (var) = SIMPLEQ_NEXT(var, field)) | ||
| 242 | |||
| 243 | /* | ||
| 244 | * Simple queue functions. | ||
| 245 | */ | ||
| 246 | #define SIMPLEQ_INIT(head) do { \ | ||
| 247 | (head)->sqh_first = NULL; \ | ||
| 248 | (head)->sqh_last = &(head)->sqh_first; \ | ||
| 249 | } while (0) | ||
| 250 | |||
| 251 | #define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \ | ||
| 252 | if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ | ||
| 253 | (head)->sqh_last = &(elm)->field.sqe_next; \ | ||
| 254 | (head)->sqh_first = (elm); \ | ||
| 255 | } while (0) | ||
| 256 | |||
| 257 | #define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \ | ||
| 258 | (elm)->field.sqe_next = NULL; \ | ||
| 259 | *(head)->sqh_last = (elm); \ | ||
| 260 | (head)->sqh_last = &(elm)->field.sqe_next; \ | ||
| 261 | } while (0) | ||
| 262 | |||
| 263 | #define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ | ||
| 264 | if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ | ||
| 265 | (head)->sqh_last = &(elm)->field.sqe_next; \ | ||
| 266 | (listelm)->field.sqe_next = (elm); \ | ||
| 267 | } while (0) | ||
| 268 | |||
| 269 | #define SIMPLEQ_REMOVE_HEAD(head, elm, field) do { \ | ||
| 270 | if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \ | ||
| 271 | (head)->sqh_last = &(head)->sqh_first; \ | ||
| 272 | } while (0) | ||
| 273 | |||
| 274 | /* | ||
| 275 | * Tail queue definitions. | ||
| 276 | */ | ||
| 277 | #define TAILQ_HEAD(name, type) \ | ||
| 278 | struct name { \ | ||
| 279 | struct type *tqh_first; /* first element */ \ | ||
| 280 | struct type **tqh_last; /* addr of last next element */ \ | ||
| 281 | } | ||
| 282 | |||
| 283 | #define TAILQ_HEAD_INITIALIZER(head) \ | ||
| 284 | { NULL, &(head).tqh_first } | ||
| 285 | |||
| 286 | #define TAILQ_ENTRY(type) \ | ||
| 287 | struct { \ | ||
| 288 | struct type *tqe_next; /* next element */ \ | ||
| 289 | struct type **tqe_prev; /* address of previous next element */ \ | ||
| 290 | } | ||
| 291 | |||
| 292 | /* | ||
| 293 | * tail queue access methods | ||
| 294 | */ | ||
| 295 | #define TAILQ_FIRST(head) ((head)->tqh_first) | ||
| 296 | #define TAILQ_END(head) NULL | ||
| 297 | #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) | ||
| 298 | #define TAILQ_LAST(head, headname) \ | ||
| 299 | (*(((struct headname *)((head)->tqh_last))->tqh_last)) | ||
| 300 | /* XXX */ | ||
| 301 | #define TAILQ_PREV(elm, headname, field) \ | ||
| 302 | (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) | ||
| 303 | #define TAILQ_EMPTY(head) \ | ||
| 304 | (TAILQ_FIRST(head) == TAILQ_END(head)) | ||
| 305 | |||
| 306 | #define TAILQ_FOREACH(var, head, field) \ | ||
| 307 | for((var) = TAILQ_FIRST(head); \ | ||
| 308 | (var) != TAILQ_END(head); \ | ||
| 309 | (var) = TAILQ_NEXT(var, field)) | ||
| 310 | |||
| 311 | #define TAILQ_FOREACH_REVERSE(var, head, field, headname) \ | ||
| 312 | for((var) = TAILQ_LAST(head, headname); \ | ||
| 313 | (var) != TAILQ_END(head); \ | ||
| 314 | (var) = TAILQ_PREV(var, headname, field)) | ||
| 315 | |||
| 316 | /* | ||
| 317 | * Tail queue functions. | ||
| 318 | */ | ||
| 319 | #define TAILQ_INIT(head) do { \ | ||
| 320 | (head)->tqh_first = NULL; \ | ||
| 321 | (head)->tqh_last = &(head)->tqh_first; \ | ||
| 322 | } while (0) | ||
| 323 | |||
| 324 | #define TAILQ_INSERT_HEAD(head, elm, field) do { \ | ||
| 325 | if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ | ||
| 326 | (head)->tqh_first->field.tqe_prev = \ | ||
| 327 | &(elm)->field.tqe_next; \ | ||
| 328 | else \ | ||
| 329 | (head)->tqh_last = &(elm)->field.tqe_next; \ | ||
| 330 | (head)->tqh_first = (elm); \ | ||
| 331 | (elm)->field.tqe_prev = &(head)->tqh_first; \ | ||
| 332 | } while (0) | ||
| 333 | |||
| 334 | #define TAILQ_INSERT_TAIL(head, elm, field) do { \ | ||
| 335 | (elm)->field.tqe_next = NULL; \ | ||
| 336 | (elm)->field.tqe_prev = (head)->tqh_last; \ | ||
| 337 | *(head)->tqh_last = (elm); \ | ||
| 338 | (head)->tqh_last = &(elm)->field.tqe_next; \ | ||
| 339 | } while (0) | ||
| 340 | |||
| 341 | #define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ | ||
| 342 | if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ | ||
| 343 | (elm)->field.tqe_next->field.tqe_prev = \ | ||
| 344 | &(elm)->field.tqe_next; \ | ||
| 345 | else \ | ||
| 346 | (head)->tqh_last = &(elm)->field.tqe_next; \ | ||
| 347 | (listelm)->field.tqe_next = (elm); \ | ||
| 348 | (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ | ||
| 349 | } while (0) | ||
| 350 | |||
| 351 | #define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ | ||
| 352 | (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ | ||
| 353 | (elm)->field.tqe_next = (listelm); \ | ||
| 354 | *(listelm)->field.tqe_prev = (elm); \ | ||
| 355 | (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ | ||
| 356 | } while (0) | ||
| 357 | |||
| 358 | #define TAILQ_REMOVE(head, elm, field) do { \ | ||
| 359 | if (((elm)->field.tqe_next) != NULL) \ | ||
| 360 | (elm)->field.tqe_next->field.tqe_prev = \ | ||
| 361 | (elm)->field.tqe_prev; \ | ||
| 362 | else \ | ||
| 363 | (head)->tqh_last = (elm)->field.tqe_prev; \ | ||
| 364 | *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ | ||
| 365 | } while (0) | ||
| 366 | |||
| 367 | #define TAILQ_REPLACE(head, elm, elm2, field) do { \ | ||
| 368 | if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ | ||
| 369 | (elm2)->field.tqe_next->field.tqe_prev = \ | ||
| 370 | &(elm2)->field.tqe_next; \ | ||
| 371 | else \ | ||
| 372 | (head)->tqh_last = &(elm2)->field.tqe_next; \ | ||
| 373 | (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ | ||
| 374 | *(elm2)->field.tqe_prev = (elm2); \ | ||
| 375 | } while (0) | ||
| 376 | |||
| 377 | /* | ||
| 378 | * Circular queue definitions. | ||
| 379 | */ | ||
| 380 | #define CIRCLEQ_HEAD(name, type) \ | ||
| 381 | struct name { \ | ||
| 382 | struct type *cqh_first; /* first element */ \ | ||
| 383 | struct type *cqh_last; /* last element */ \ | ||
| 384 | } | ||
| 385 | |||
| 386 | #define CIRCLEQ_HEAD_INITIALIZER(head) \ | ||
| 387 | { CIRCLEQ_END(&head), CIRCLEQ_END(&head) } | ||
| 388 | |||
| 389 | #define CIRCLEQ_ENTRY(type) \ | ||
| 390 | struct { \ | ||
| 391 | struct type *cqe_next; /* next element */ \ | ||
| 392 | struct type *cqe_prev; /* previous element */ \ | ||
| 393 | } | ||
| 394 | |||
| 395 | /* | ||
| 396 | * Circular queue access methods | ||
| 397 | */ | ||
| 398 | #define CIRCLEQ_FIRST(head) ((head)->cqh_first) | ||
| 399 | #define CIRCLEQ_LAST(head) ((head)->cqh_last) | ||
| 400 | #define CIRCLEQ_END(head) ((void *)(head)) | ||
| 401 | #define CIRCLEQ_NEXT(elm, field) ((elm)->field.cqe_next) | ||
| 402 | #define CIRCLEQ_PREV(elm, field) ((elm)->field.cqe_prev) | ||
| 403 | #define CIRCLEQ_EMPTY(head) \ | ||
| 404 | (CIRCLEQ_FIRST(head) == CIRCLEQ_END(head)) | ||
| 405 | |||
| 406 | #define CIRCLEQ_FOREACH(var, head, field) \ | ||
| 407 | for((var) = CIRCLEQ_FIRST(head); \ | ||
| 408 | (var) != CIRCLEQ_END(head); \ | ||
| 409 | (var) = CIRCLEQ_NEXT(var, field)) | ||
| 410 | |||
| 411 | #define CIRCLEQ_FOREACH_REVERSE(var, head, field) \ | ||
| 412 | for((var) = CIRCLEQ_LAST(head); \ | ||
| 413 | (var) != CIRCLEQ_END(head); \ | ||
| 414 | (var) = CIRCLEQ_PREV(var, field)) | ||
| 415 | |||
| 416 | /* | ||
| 417 | * Circular queue functions. | ||
| 418 | */ | ||
| 419 | #define CIRCLEQ_INIT(head) do { \ | ||
| 420 | (head)->cqh_first = CIRCLEQ_END(head); \ | ||
| 421 | (head)->cqh_last = CIRCLEQ_END(head); \ | ||
| 422 | } while (0) | ||
| 423 | |||
| 424 | #define CIRCLEQ_INSERT_AFTER(head, listelm, elm, field) do { \ | ||
| 425 | (elm)->field.cqe_next = (listelm)->field.cqe_next; \ | ||
| 426 | (elm)->field.cqe_prev = (listelm); \ | ||
| 427 | if ((listelm)->field.cqe_next == CIRCLEQ_END(head)) \ | ||
| 428 | (head)->cqh_last = (elm); \ | ||
| 429 | else \ | ||
| 430 | (listelm)->field.cqe_next->field.cqe_prev = (elm); \ | ||
| 431 | (listelm)->field.cqe_next = (elm); \ | ||
| 432 | } while (0) | ||
| 433 | |||
| 434 | #define CIRCLEQ_INSERT_BEFORE(head, listelm, elm, field) do { \ | ||
| 435 | (elm)->field.cqe_next = (listelm); \ | ||
| 436 | (elm)->field.cqe_prev = (listelm)->field.cqe_prev; \ | ||
| 437 | if ((listelm)->field.cqe_prev == CIRCLEQ_END(head)) \ | ||
| 438 | (head)->cqh_first = (elm); \ | ||
| 439 | else \ | ||
| 440 | (listelm)->field.cqe_prev->field.cqe_next = (elm); \ | ||
| 441 | (listelm)->field.cqe_prev = (elm); \ | ||
| 442 | } while (0) | ||
| 443 | |||
| 444 | #define CIRCLEQ_INSERT_HEAD(head, elm, field) do { \ | ||
| 445 | (elm)->field.cqe_next = (head)->cqh_first; \ | ||
| 446 | (elm)->field.cqe_prev = CIRCLEQ_END(head); \ | ||
| 447 | if ((head)->cqh_last == CIRCLEQ_END(head)) \ | ||
| 448 | (head)->cqh_last = (elm); \ | ||
| 449 | else \ | ||
| 450 | (head)->cqh_first->field.cqe_prev = (elm); \ | ||
| 451 | (head)->cqh_first = (elm); \ | ||
| 452 | } while (0) | ||
| 453 | |||
| 454 | #define CIRCLEQ_INSERT_TAIL(head, elm, field) do { \ | ||
| 455 | (elm)->field.cqe_next = CIRCLEQ_END(head); \ | ||
| 456 | (elm)->field.cqe_prev = (head)->cqh_last; \ | ||
| 457 | if ((head)->cqh_first == CIRCLEQ_END(head)) \ | ||
| 458 | (head)->cqh_first = (elm); \ | ||
| 459 | else \ | ||
| 460 | (head)->cqh_last->field.cqe_next = (elm); \ | ||
| 461 | (head)->cqh_last = (elm); \ | ||
| 462 | } while (0) | ||
| 463 | |||
| 464 | #define CIRCLEQ_REMOVE(head, elm, field) do { \ | ||
| 465 | if ((elm)->field.cqe_next == CIRCLEQ_END(head)) \ | ||
| 466 | (head)->cqh_last = (elm)->field.cqe_prev; \ | ||
| 467 | else \ | ||
| 468 | (elm)->field.cqe_next->field.cqe_prev = \ | ||
| 469 | (elm)->field.cqe_prev; \ | ||
| 470 | if ((elm)->field.cqe_prev == CIRCLEQ_END(head)) \ | ||
| 471 | (head)->cqh_first = (elm)->field.cqe_next; \ | ||
| 472 | else \ | ||
| 473 | (elm)->field.cqe_prev->field.cqe_next = \ | ||
| 474 | (elm)->field.cqe_next; \ | ||
| 475 | } while (0) | ||
| 476 | |||
| 477 | #define CIRCLEQ_REPLACE(head, elm, elm2, field) do { \ | ||
| 478 | if (((elm2)->field.cqe_next = (elm)->field.cqe_next) == \ | ||
| 479 | CIRCLEQ_END(head)) \ | ||
| 480 | (head).cqh_last = (elm2); \ | ||
| 481 | else \ | ||
| 482 | (elm2)->field.cqe_next->field.cqe_prev = (elm2); \ | ||
| 483 | if (((elm2)->field.cqe_prev = (elm)->field.cqe_prev) == \ | ||
| 484 | CIRCLEQ_END(head)) \ | ||
| 485 | (head).cqh_first = (elm2); \ | ||
| 486 | else \ | ||
| 487 | (elm2)->field.cqe_prev->field.cqe_next = (elm2); \ | ||
| 488 | } while (0) | ||
| 489 | |||
| 490 | #endif /* !_SYS_QUEUE_H_ */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-regex.h b/other/ssharp/openbsd-compat/fake-regex.h new file mode 100644 index 0000000..8f7f6ed --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-regex.h | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* $OpenBSD: regex.h,v 1.3 1997/09/21 10:45:48 niklas Exp $ */ | ||
| 2 | /* $NetBSD: regex.h,v 1.4.6.1 1996/06/10 18:57:07 explorer Exp $ */ | ||
| 3 | |||
| 4 | /*- | ||
| 5 | * Copyright (c) 1992 Henry Spencer. | ||
| 6 | * Copyright (c) 1992, 1993 | ||
| 7 | * The Regents of the University of California. All rights reserved. | ||
| 8 | * | ||
| 9 | * This code is derived from software contributed to Berkeley by | ||
| 10 | * Henry Spencer of the University of Toronto. | ||
| 11 | * | ||
| 12 | * Redistribution and use in source and binary forms, with or without | ||
| 13 | * modification, are permitted provided that the following conditions | ||
| 14 | * are met: | ||
| 15 | * 1. Redistributions of source code must retain the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer. | ||
| 17 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 18 | * notice, this list of conditions and the following disclaimer in the | ||
| 19 | * documentation and/or other materials provided with the distribution. | ||
| 20 | * 3. All advertising materials mentioning features or use of this software | ||
| 21 | * must display the following acknowledgement: | ||
| 22 | * This product includes software developed by the University of | ||
| 23 | * California, Berkeley and its contributors. | ||
| 24 | * 4. Neither the name of the University nor the names of its contributors | ||
| 25 | * may be used to endorse or promote products derived from this software | ||
| 26 | * without specific prior written permission. | ||
| 27 | * | ||
| 28 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 29 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 30 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 31 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 32 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 33 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 34 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 35 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 36 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 37 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 38 | * SUCH DAMAGE. | ||
| 39 | * | ||
| 40 | * @(#)regex.h 8.1 (Berkeley) 6/2/93 | ||
| 41 | */ | ||
| 42 | |||
| 43 | #ifndef _REGEX_H_ | ||
| 44 | #define _REGEX_H_ | ||
| 45 | |||
| 46 | #include <sys/types.h> | ||
| 47 | |||
| 48 | /* types */ | ||
| 49 | typedef off_t regoff_t; | ||
| 50 | |||
| 51 | typedef struct { | ||
| 52 | int re_magic; | ||
| 53 | size_t re_nsub; /* number of parenthesized subexpressions */ | ||
| 54 | const char *re_endp; /* end pointer for REG_PEND */ | ||
| 55 | struct re_guts *re_g; /* none of your business :-) */ | ||
| 56 | } regex_t; | ||
| 57 | |||
| 58 | typedef struct { | ||
| 59 | regoff_t rm_so; /* start of match */ | ||
| 60 | regoff_t rm_eo; /* end of match */ | ||
| 61 | } regmatch_t; | ||
| 62 | |||
| 63 | /* regcomp() flags */ | ||
| 64 | #define REG_BASIC 0000 | ||
| 65 | #define REG_EXTENDED 0001 | ||
| 66 | #define REG_ICASE 0002 | ||
| 67 | #define REG_NOSUB 0004 | ||
| 68 | #define REG_NEWLINE 0010 | ||
| 69 | #define REG_NOSPEC 0020 | ||
| 70 | #define REG_PEND 0040 | ||
| 71 | #define REG_DUMP 0200 | ||
| 72 | |||
| 73 | /* regerror() flags */ | ||
| 74 | #define REG_NOMATCH 1 | ||
| 75 | #define REG_BADPAT 2 | ||
| 76 | #define REG_ECOLLATE 3 | ||
| 77 | #define REG_ECTYPE 4 | ||
| 78 | #define REG_EESCAPE 5 | ||
| 79 | #define REG_ESUBREG 6 | ||
| 80 | #define REG_EBRACK 7 | ||
| 81 | #define REG_EPAREN 8 | ||
| 82 | #define REG_EBRACE 9 | ||
| 83 | #define REG_BADBR 10 | ||
| 84 | #define REG_ERANGE 11 | ||
| 85 | #define REG_ESPACE 12 | ||
| 86 | #define REG_BADRPT 13 | ||
| 87 | #define REG_EMPTY 14 | ||
| 88 | #define REG_ASSERT 15 | ||
| 89 | #define REG_INVARG 16 | ||
| 90 | #define REG_ATOI 255 /* convert name to number (!) */ | ||
| 91 | #define REG_ITOA 0400 /* convert number to name (!) */ | ||
| 92 | |||
| 93 | /* regexec() flags */ | ||
| 94 | #define REG_NOTBOL 00001 | ||
| 95 | #define REG_NOTEOL 00002 | ||
| 96 | #define REG_STARTEND 00004 | ||
| 97 | #define REG_TRACE 00400 /* tracing of execution */ | ||
| 98 | #define REG_LARGE 01000 /* force large representation */ | ||
| 99 | #define REG_BACKR 02000 /* force use of backref code */ | ||
| 100 | |||
| 101 | int regcomp(regex_t*, const char*, int); | ||
| 102 | size_t regerror(int, const regex_t*, char*, size_t); | ||
| 103 | int regexec(const regex_t*, const char*, size_t, regmatch_t[], int); | ||
| 104 | void regfree(regex_t*); | ||
| 105 | |||
| 106 | #endif /* !_REGEX_H_ */ | ||
diff --git a/other/ssharp/openbsd-compat/fake-socket.h b/other/ssharp/openbsd-compat/fake-socket.h new file mode 100644 index 0000000..b11a974 --- /dev/null +++ b/other/ssharp/openbsd-compat/fake-socket.h | |||
| @@ -0,0 +1,47 @@ | |||
| 1 | /* $Id: fake-socket.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _FAKE_SOCKET_H | ||
| 4 | #define _FAKE_SOCKET_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | #include "sys/types.h" | ||
| 8 | |||
| 9 | #ifndef HAVE_STRUCT_SOCKADDR_STORAGE | ||
| 10 | # define _SS_MAXSIZE 128 /* Implementation specific max size */ | ||
| 11 | # define _SS_PADSIZE (_SS_MAXSIZE - sizeof (struct sockaddr)) | ||
| 12 | |||
| 13 | struct sockaddr_storage { | ||
| 14 | struct sockaddr ss_sa; | ||
| 15 | char __ss_pad2[_SS_PADSIZE]; | ||
| 16 | }; | ||
| 17 | # define ss_family ss_sa.sa_family | ||
| 18 | #endif /* !HAVE_STRUCT_SOCKADDR_STORAGE */ | ||
| 19 | |||
| 20 | #ifndef IN6_IS_ADDR_LOOPBACK | ||
| 21 | # define IN6_IS_ADDR_LOOPBACK(a) \ | ||
| 22 | (((u_int32_t *) (a))[0] == 0 && ((u_int32_t *) (a))[1] == 0 && \ | ||
| 23 | ((u_int32_t *) (a))[2] == 0 && ((u_int32_t *) (a))[3] == htonl (1)) | ||
| 24 | #endif /* !IN6_IS_ADDR_LOOPBACK */ | ||
| 25 | |||
| 26 | #ifndef HAVE_STRUCT_IN6_ADDR | ||
| 27 | struct in6_addr { | ||
| 28 | u_int8_t s6_addr[16]; | ||
| 29 | }; | ||
| 30 | #endif /* !HAVE_STRUCT_IN6_ADDR */ | ||
| 31 | |||
| 32 | #ifndef HAVE_STRUCT_SOCKADDR_IN6 | ||
| 33 | struct sockaddr_in6 { | ||
| 34 | unsigned short sin6_family; | ||
| 35 | u_int16_t sin6_port; | ||
| 36 | u_int32_t sin6_flowinfo; | ||
| 37 | struct in6_addr sin6_addr; | ||
| 38 | }; | ||
| 39 | #endif /* !HAVE_STRUCT_SOCKADDR_IN6 */ | ||
| 40 | |||
| 41 | #ifndef AF_INET6 | ||
| 42 | /* Define it to something that should never appear */ | ||
| 43 | #define AF_INET6 AF_MAX | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #endif /* !_FAKE_SOCKET_H */ | ||
| 47 | |||
diff --git a/other/ssharp/openbsd-compat/getcwd.c b/other/ssharp/openbsd-compat/getcwd.c new file mode 100644 index 0000000..de3bacc --- /dev/null +++ b/other/ssharp/openbsd-compat/getcwd.c | |||
| @@ -0,0 +1,237 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1989, 1991, 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 | * | ||
| 14 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 24 | * SUCH DAMAGE. | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include "config.h" | ||
| 28 | |||
| 29 | #if !defined(HAVE_GETCWD) | ||
| 30 | |||
| 31 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 32 | static char rcsid[] = "$OpenBSD: getcwd.c,v 1.6 2000/07/19 15:25:13 deraadt Exp $"; | ||
| 33 | #endif /* LIBC_SCCS and not lint */ | ||
| 34 | |||
| 35 | #include <sys/param.h> | ||
| 36 | #include <sys/stat.h> | ||
| 37 | #include <errno.h> | ||
| 38 | #include <dirent.h> | ||
| 39 | #include <sys/dir.h> | ||
| 40 | #include <stdio.h> | ||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | #include "includes.h" | ||
| 44 | |||
| 45 | #define ISDOT(dp) \ | ||
| 46 | (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ | ||
| 47 | (dp->d_name[1] == '.' && dp->d_name[2] == '\0'))) | ||
| 48 | |||
| 49 | char * | ||
| 50 | getcwd(char *pt,size_t size) | ||
| 51 | { | ||
| 52 | register struct dirent *dp; | ||
| 53 | register DIR *dir = NULL; | ||
| 54 | register dev_t dev; | ||
| 55 | register ino_t ino; | ||
| 56 | register int first; | ||
| 57 | register char *bpt, *bup; | ||
| 58 | struct stat s; | ||
| 59 | dev_t root_dev; | ||
| 60 | ino_t root_ino; | ||
| 61 | size_t ptsize, upsize; | ||
| 62 | int save_errno; | ||
| 63 | char *ept, *eup, *up; | ||
| 64 | |||
| 65 | /* | ||
| 66 | * If no buffer specified by the user, allocate one as necessary. | ||
| 67 | * If a buffer is specified, the size has to be non-zero. The path | ||
| 68 | * is built from the end of the buffer backwards. | ||
| 69 | */ | ||
| 70 | if (pt) { | ||
| 71 | ptsize = 0; | ||
| 72 | if (!size) { | ||
| 73 | errno = EINVAL; | ||
| 74 | return (NULL); | ||
| 75 | } | ||
| 76 | ept = pt + size; | ||
| 77 | } else { | ||
| 78 | if ((pt = malloc(ptsize = 1024 - 4)) == NULL) | ||
| 79 | return (NULL); | ||
| 80 | ept = pt + ptsize; | ||
| 81 | } | ||
| 82 | bpt = ept - 1; | ||
| 83 | *bpt = '\0'; | ||
| 84 | |||
| 85 | /* | ||
| 86 | * Allocate bytes (1024 - malloc space) for the string of "../"'s. | ||
| 87 | * Should always be enough (it's 340 levels). If it's not, allocate | ||
| 88 | * as necessary. Special * case the first stat, it's ".", not "..". | ||
| 89 | */ | ||
| 90 | if ((up = malloc(upsize = 1024 - 4)) == NULL) | ||
| 91 | goto err; | ||
| 92 | eup = up + MAXPATHLEN; | ||
| 93 | bup = up; | ||
| 94 | up[0] = '.'; | ||
| 95 | up[1] = '\0'; | ||
| 96 | |||
| 97 | /* Save root values, so know when to stop. */ | ||
| 98 | if (stat("/", &s)) | ||
| 99 | goto err; | ||
| 100 | root_dev = s.st_dev; | ||
| 101 | root_ino = s.st_ino; | ||
| 102 | |||
| 103 | errno = 0; /* XXX readdir has no error return. */ | ||
| 104 | |||
| 105 | for (first = 1;; first = 0) { | ||
| 106 | /* Stat the current level. */ | ||
| 107 | if (lstat(up, &s)) | ||
| 108 | goto err; | ||
| 109 | |||
| 110 | /* Save current node values. */ | ||
| 111 | ino = s.st_ino; | ||
| 112 | dev = s.st_dev; | ||
| 113 | |||
| 114 | /* Check for reaching root. */ | ||
| 115 | if (root_dev == dev && root_ino == ino) { | ||
| 116 | *--bpt = '/'; | ||
| 117 | /* | ||
| 118 | * It's unclear that it's a requirement to copy the | ||
| 119 | * path to the beginning of the buffer, but it's always | ||
| 120 | * been that way and stuff would probably break. | ||
| 121 | */ | ||
| 122 | memmove(pt, bpt, ept - bpt); | ||
| 123 | free(up); | ||
| 124 | return (pt); | ||
| 125 | } | ||
| 126 | |||
| 127 | /* | ||
| 128 | * Build pointer to the parent directory, allocating memory | ||
| 129 | * as necessary. Max length is 3 for "../", the largest | ||
| 130 | * possible component name, plus a trailing NULL. | ||
| 131 | */ | ||
| 132 | if (bup + 3 + MAXNAMLEN + 1 >= eup) { | ||
| 133 | char *nup; | ||
| 134 | |||
| 135 | if ((nup = realloc(up, upsize *= 2)) == NULL) | ||
| 136 | goto err; | ||
| 137 | up = nup; | ||
| 138 | bup = up; | ||
| 139 | eup = up + upsize; | ||
| 140 | } | ||
| 141 | *bup++ = '.'; | ||
| 142 | *bup++ = '.'; | ||
| 143 | *bup = '\0'; | ||
| 144 | |||
| 145 | /* Open and stat parent directory. | ||
| 146 | * RACE?? - replaced fstat(dirfd(dir), &s) w/ lstat(up,&s) | ||
| 147 | */ | ||
| 148 | if (!(dir = opendir(up)) || lstat(up,&s)) | ||
| 149 | goto err; | ||
| 150 | |||
| 151 | /* Add trailing slash for next directory. */ | ||
| 152 | *bup++ = '/'; | ||
| 153 | |||
| 154 | /* | ||
| 155 | * If it's a mount point, have to stat each element because | ||
| 156 | * the inode number in the directory is for the entry in the | ||
| 157 | * parent directory, not the inode number of the mounted file. | ||
| 158 | */ | ||
| 159 | save_errno = 0; | ||
| 160 | if (s.st_dev == dev) { | ||
| 161 | for (;;) { | ||
| 162 | if (!(dp = readdir(dir))) | ||
| 163 | goto notfound; | ||
| 164 | if (dp->d_fileno == ino) | ||
| 165 | break; | ||
| 166 | } | ||
| 167 | } else | ||
| 168 | for (;;) { | ||
| 169 | if (!(dp = readdir(dir))) | ||
| 170 | goto notfound; | ||
| 171 | if (ISDOT(dp)) | ||
| 172 | continue; | ||
| 173 | memmove(bup, dp->d_name, dp->d_namlen + 1); | ||
| 174 | |||
| 175 | /* Save the first error for later. */ | ||
| 176 | if (lstat(up, &s)) { | ||
| 177 | if (!save_errno) | ||
| 178 | save_errno = errno; | ||
| 179 | errno = 0; | ||
| 180 | continue; | ||
| 181 | } | ||
| 182 | if (s.st_dev == dev && s.st_ino == ino) | ||
| 183 | break; | ||
| 184 | } | ||
| 185 | |||
| 186 | /* | ||
| 187 | * Check for length of the current name, preceding slash, | ||
| 188 | * leading slash. | ||
| 189 | */ | ||
| 190 | if (bpt - pt < dp->d_namlen + (first ? 1 : 2)) { | ||
| 191 | size_t len, off; | ||
| 192 | char *npt; | ||
| 193 | |||
| 194 | if (!ptsize) { | ||
| 195 | errno = ERANGE; | ||
| 196 | goto err; | ||
| 197 | } | ||
| 198 | off = bpt - pt; | ||
| 199 | len = ept - bpt; | ||
| 200 | if ((npt = realloc(pt, ptsize *= 2)) == NULL) | ||
| 201 | goto err; | ||
| 202 | pt = npt; | ||
| 203 | bpt = pt + off; | ||
| 204 | ept = pt + ptsize; | ||
| 205 | memmove(ept - len, bpt, len); | ||
| 206 | bpt = ept - len; | ||
| 207 | } | ||
| 208 | if (!first) | ||
| 209 | *--bpt = '/'; | ||
| 210 | bpt -= dp->d_namlen; | ||
| 211 | memmove(bpt, dp->d_name, dp->d_namlen); | ||
| 212 | (void)closedir(dir); | ||
| 213 | |||
| 214 | /* Truncate any file name. */ | ||
| 215 | *bup = '\0'; | ||
| 216 | } | ||
| 217 | |||
| 218 | notfound: | ||
| 219 | /* | ||
| 220 | * If readdir set errno, use it, not any saved error; otherwise, | ||
| 221 | * didn't find the current directory in its parent directory, set | ||
| 222 | * errno to ENOENT. | ||
| 223 | */ | ||
| 224 | if (!errno) | ||
| 225 | errno = save_errno ? save_errno : ENOENT; | ||
| 226 | /* FALLTHROUGH */ | ||
| 227 | err: | ||
| 228 | if (ptsize) | ||
| 229 | free(pt); | ||
| 230 | if (up) | ||
| 231 | free(up); | ||
| 232 | if (dir) | ||
| 233 | (void)closedir(dir); | ||
| 234 | return (NULL); | ||
| 235 | } | ||
| 236 | |||
| 237 | #endif /* !defined(HAVE_GETCWD) */ | ||
diff --git a/other/ssharp/openbsd-compat/getcwd.h b/other/ssharp/openbsd-compat/getcwd.h new file mode 100644 index 0000000..abead5b --- /dev/null +++ b/other/ssharp/openbsd-compat/getcwd.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: getcwd.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_GETCWD_H | ||
| 4 | #define _BSD_GETCWD_H | ||
| 5 | #include "config.h" | ||
| 6 | |||
| 7 | #if !defined(HAVE_GETCWD) | ||
| 8 | |||
| 9 | char *getcwd(char *pt, size_t size); | ||
| 10 | |||
| 11 | #endif /* !defined(HAVE_GETCWD) */ | ||
| 12 | #endif /* _BSD_GETCWD_H */ | ||
diff --git a/other/ssharp/openbsd-compat/getgrouplist.c b/other/ssharp/openbsd-compat/getgrouplist.c new file mode 100644 index 0000000..f7a27c3 --- /dev/null +++ b/other/ssharp/openbsd-compat/getgrouplist.c | |||
| @@ -0,0 +1,103 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1991, 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 | |||
| 34 | #include "includes.h" | ||
| 35 | |||
| 36 | #ifndef HAVE_GETGROUPLIST | ||
| 37 | |||
| 38 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 39 | static char rcsid[] = "$OpenBSD: getgrouplist.c,v 1.7 1997/08/19 19:13:27 deraadt Exp $"; | ||
| 40 | #endif /* LIBC_SCCS and not lint */ | ||
| 41 | |||
| 42 | /* | ||
| 43 | * get credential | ||
| 44 | */ | ||
| 45 | #include <sys/types.h> | ||
| 46 | #include <string.h> | ||
| 47 | #include <grp.h> | ||
| 48 | |||
| 49 | int | ||
| 50 | getgrouplist(uname, agroup, groups, grpcnt) | ||
| 51 | const char *uname; | ||
| 52 | gid_t agroup; | ||
| 53 | register gid_t *groups; | ||
| 54 | int *grpcnt; | ||
| 55 | { | ||
| 56 | register struct group *grp; | ||
| 57 | register int i, ngroups; | ||
| 58 | int ret, maxgroups; | ||
| 59 | int bail; | ||
| 60 | |||
| 61 | ret = 0; | ||
| 62 | ngroups = 0; | ||
| 63 | maxgroups = *grpcnt; | ||
| 64 | |||
| 65 | /* | ||
| 66 | * install primary group | ||
| 67 | */ | ||
| 68 | if (ngroups >= maxgroups) { | ||
| 69 | *grpcnt = ngroups; | ||
| 70 | return (-1); | ||
| 71 | } | ||
| 72 | groups[ngroups++] = agroup; | ||
| 73 | |||
| 74 | /* | ||
| 75 | * Scan the group file to find additional groups. | ||
| 76 | */ | ||
| 77 | setgrent(); | ||
| 78 | while ((grp = getgrent())) { | ||
| 79 | if (grp->gr_gid == agroup) | ||
| 80 | continue; | ||
| 81 | for (bail = 0, i = 0; bail == 0 && i < ngroups; i++) | ||
| 82 | if (groups[i] == grp->gr_gid) | ||
| 83 | bail = 1; | ||
| 84 | if (bail) | ||
| 85 | continue; | ||
| 86 | for (i = 0; grp->gr_mem[i]; i++) { | ||
| 87 | if (!strcmp(grp->gr_mem[i], uname)) { | ||
| 88 | if (ngroups >= maxgroups) { | ||
| 89 | ret = -1; | ||
| 90 | goto out; | ||
| 91 | } | ||
| 92 | groups[ngroups++] = grp->gr_gid; | ||
| 93 | break; | ||
| 94 | } | ||
| 95 | } | ||
| 96 | } | ||
| 97 | out: | ||
| 98 | endgrent(); | ||
| 99 | *grpcnt = ngroups; | ||
| 100 | return (ret); | ||
| 101 | } | ||
| 102 | |||
| 103 | #endif /* HAVE_GETGROUPLIST */ | ||
diff --git a/other/ssharp/openbsd-compat/getgrouplist.h b/other/ssharp/openbsd-compat/getgrouplist.h new file mode 100644 index 0000000..8f8e0fc --- /dev/null +++ b/other/ssharp/openbsd-compat/getgrouplist.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* $Id: getgrouplist.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_GETGROUPLIST_H | ||
| 4 | #define _BSD_GETGROUPLIST_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_GETGROUPLIST | ||
| 9 | |||
| 10 | #include <grp.h> | ||
| 11 | |||
| 12 | int getgrouplist(const char *, gid_t, gid_t *, int *); | ||
| 13 | |||
| 14 | #endif | ||
| 15 | |||
| 16 | #endif | ||
diff --git a/other/ssharp/openbsd-compat/getusershell.c b/other/ssharp/openbsd-compat/getusershell.c new file mode 100644 index 0000000..b334ba2 --- /dev/null +++ b/other/ssharp/openbsd-compat/getusershell.c | |||
| @@ -0,0 +1,138 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1985, 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 | |||
| 34 | #include "includes.h" | ||
| 35 | #include "getusershell.h" | ||
| 36 | |||
| 37 | #ifndef HAVE_GETUSERSHELL | ||
| 38 | |||
| 39 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 40 | static char rcsid[] = "$OpenBSD: getusershell.c,v 1.2 1996/08/19 08:24:15 tholo Exp $"; | ||
| 41 | #endif /* LIBC_SCCS and not lint */ | ||
| 42 | |||
| 43 | #include <sys/file.h> | ||
| 44 | #include <ctype.h> | ||
| 45 | |||
| 46 | /* | ||
| 47 | * Local shells should NOT be added here. They should be added in | ||
| 48 | * /etc/shells. | ||
| 49 | */ | ||
| 50 | |||
| 51 | static char *okshells[] = { _PATH_BSHELL, _PATH_CSHELL, NULL }; | ||
| 52 | static char **curshell, **shells, *strings; | ||
| 53 | static char **initshells __P((void)); | ||
| 54 | |||
| 55 | /* | ||
| 56 | * Get a list of shells from _PATH_SHELLS, if it exists. | ||
| 57 | */ | ||
| 58 | char * | ||
| 59 | getusershell() | ||
| 60 | { | ||
| 61 | char *ret; | ||
| 62 | |||
| 63 | if (curshell == NULL) | ||
| 64 | curshell = initshells(); | ||
| 65 | ret = *curshell; | ||
| 66 | if (ret != NULL) | ||
| 67 | curshell++; | ||
| 68 | return (ret); | ||
| 69 | } | ||
| 70 | |||
| 71 | void | ||
| 72 | endusershell() | ||
| 73 | { | ||
| 74 | |||
| 75 | if (shells != NULL) | ||
| 76 | free(shells); | ||
| 77 | shells = NULL; | ||
| 78 | if (strings != NULL) | ||
| 79 | free(strings); | ||
| 80 | strings = NULL; | ||
| 81 | curshell = NULL; | ||
| 82 | } | ||
| 83 | |||
| 84 | void | ||
| 85 | setusershell() | ||
| 86 | { | ||
| 87 | |||
| 88 | curshell = initshells(); | ||
| 89 | } | ||
| 90 | |||
| 91 | static char ** | ||
| 92 | initshells() | ||
| 93 | { | ||
| 94 | register char **sp, *cp; | ||
| 95 | register FILE *fp; | ||
| 96 | struct stat statb; | ||
| 97 | |||
| 98 | if (shells != NULL) | ||
| 99 | free(shells); | ||
| 100 | shells = NULL; | ||
| 101 | if (strings != NULL) | ||
| 102 | free(strings); | ||
| 103 | strings = NULL; | ||
| 104 | if ((fp = fopen(_PATH_SHELLS, "r")) == NULL) | ||
| 105 | return (okshells); | ||
| 106 | if (fstat(fileno(fp), &statb) == -1) { | ||
| 107 | (void)fclose(fp); | ||
| 108 | return (okshells); | ||
| 109 | } | ||
| 110 | if ((strings = malloc((u_int)statb.st_size)) == NULL) { | ||
| 111 | (void)fclose(fp); | ||
| 112 | return (okshells); | ||
| 113 | } | ||
| 114 | shells = calloc((unsigned)statb.st_size / 3, sizeof (char *)); | ||
| 115 | if (shells == NULL) { | ||
| 116 | (void)fclose(fp); | ||
| 117 | free(strings); | ||
| 118 | strings = NULL; | ||
| 119 | return (okshells); | ||
| 120 | } | ||
| 121 | sp = shells; | ||
| 122 | cp = strings; | ||
| 123 | while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { | ||
| 124 | while (*cp != '#' && *cp != '/' && *cp != '\0') | ||
| 125 | cp++; | ||
| 126 | if (*cp == '#' || *cp == '\0') | ||
| 127 | continue; | ||
| 128 | *sp++ = cp; | ||
| 129 | while (!isspace(*cp) && *cp != '#' && *cp != '\0') | ||
| 130 | cp++; | ||
| 131 | *cp++ = '\0'; | ||
| 132 | } | ||
| 133 | *sp = NULL; | ||
| 134 | (void)fclose(fp); | ||
| 135 | return (shells); | ||
| 136 | } | ||
| 137 | |||
| 138 | #endif /* HAVE_GETUSERSHELL */ | ||
diff --git a/other/ssharp/openbsd-compat/getusershell.h b/other/ssharp/openbsd-compat/getusershell.h new file mode 100644 index 0000000..cb4e62c --- /dev/null +++ b/other/ssharp/openbsd-compat/getusershell.h | |||
| @@ -0,0 +1,16 @@ | |||
| 1 | /* $Id: getusershell.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _GETUSERSHELL_H | ||
| 4 | #define _GETUSERSHELL_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_GETUSERSHELL | ||
| 9 | |||
| 10 | char *getusershell(void); | ||
| 11 | void setusershell(void); | ||
| 12 | void endusershell(void); | ||
| 13 | |||
| 14 | #endif /* HAVE_GETUSERSHELL */ | ||
| 15 | |||
| 16 | #endif /* _GETUSERSHELL_H */ | ||
diff --git a/other/ssharp/openbsd-compat/glob.c b/other/ssharp/openbsd-compat/glob.c new file mode 100644 index 0000000..4f70149 --- /dev/null +++ b/other/ssharp/openbsd-compat/glob.c | |||
| @@ -0,0 +1,915 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1989, 1993 | ||
| 3 | * The Regents of the University of California. All rights reserved. | ||
| 4 | * | ||
| 5 | * This code is derived from software contributed to Berkeley by | ||
| 6 | * Guido van Rossum. | ||
| 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. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by the University of | ||
| 19 | * California, Berkeley and its contributors. | ||
| 20 | * 4. Neither the name of the University nor the names of its contributors | ||
| 21 | * may be used to endorse or promote products derived from this software | ||
| 22 | * without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 34 | * SUCH DAMAGE. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include "includes.h" | ||
| 38 | #include <ctype.h> | ||
| 39 | |||
| 40 | long | ||
| 41 | get_arg_max() | ||
| 42 | { | ||
| 43 | #ifdef ARG_MAX | ||
| 44 | return(ARG_MAX); | ||
| 45 | #elif defined(HAVE_SYSCONF) && defined(_SC_ARG_MAX) | ||
| 46 | return(sysconf(_SC_ARG_MAX)); | ||
| 47 | #else | ||
| 48 | return(256); /* XXX: arbitrary */ | ||
| 49 | #endif | ||
| 50 | } | ||
| 51 | |||
| 52 | #if !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | ||
| 53 | !defined(GLOB_HAS_GL_MATCHC) | ||
| 54 | |||
| 55 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 56 | #if 0 | ||
| 57 | static char sccsid[] = "@(#)glob.c 8.3 (Berkeley) 10/13/93"; | ||
| 58 | #else | ||
| 59 | static char rcsid[] = "$OpenBSD: glob.c,v 1.16 2001/04/05 18:36:12 deraadt Exp $"; | ||
| 60 | #endif | ||
| 61 | #endif /* LIBC_SCCS and not lint */ | ||
| 62 | |||
| 63 | /* | ||
| 64 | * glob(3) -- a superset of the one defined in POSIX 1003.2. | ||
| 65 | * | ||
| 66 | * The [!...] convention to negate a range is supported (SysV, Posix, ksh). | ||
| 67 | * | ||
| 68 | * Optional extra services, controlled by flags not defined by POSIX: | ||
| 69 | * | ||
| 70 | * GLOB_QUOTE: | ||
| 71 | * Escaping convention: \ inhibits any special meaning the following | ||
| 72 | * character might have (except \ at end of string is retained). | ||
| 73 | * GLOB_MAGCHAR: | ||
| 74 | * Set in gl_flags if pattern contained a globbing character. | ||
| 75 | * GLOB_NOMAGIC: | ||
| 76 | * Same as GLOB_NOCHECK, but it will only append pattern if it did | ||
| 77 | * not contain any magic characters. [Used in csh style globbing] | ||
| 78 | * GLOB_ALTDIRFUNC: | ||
| 79 | * Use alternately specified directory access functions. | ||
| 80 | * GLOB_TILDE: | ||
| 81 | * expand ~user/foo to the /home/dir/of/user/foo | ||
| 82 | * GLOB_BRACE: | ||
| 83 | * expand {1,2}{a,b} to 1a 1b 2a 2b | ||
| 84 | * gl_matchc: | ||
| 85 | * Number of matches in the current invocation of glob. | ||
| 86 | */ | ||
| 87 | |||
| 88 | |||
| 89 | #define DOLLAR '$' | ||
| 90 | #define DOT '.' | ||
| 91 | #define EOS '\0' | ||
| 92 | #define LBRACKET '[' | ||
| 93 | #define NOT '!' | ||
| 94 | #define QUESTION '?' | ||
| 95 | #define QUOTE '\\' | ||
| 96 | #define RANGE '-' | ||
| 97 | #define RBRACKET ']' | ||
| 98 | #define SEP '/' | ||
| 99 | #define STAR '*' | ||
| 100 | #define TILDE '~' | ||
| 101 | #define UNDERSCORE '_' | ||
| 102 | #define LBRACE '{' | ||
| 103 | #define RBRACE '}' | ||
| 104 | #define SLASH '/' | ||
| 105 | #define COMMA ',' | ||
| 106 | |||
| 107 | #ifndef DEBUG | ||
| 108 | |||
| 109 | #define M_QUOTE 0x8000 | ||
| 110 | #define M_PROTECT 0x4000 | ||
| 111 | #define M_MASK 0xffff | ||
| 112 | #define M_ASCII 0x00ff | ||
| 113 | |||
| 114 | typedef u_short Char; | ||
| 115 | |||
| 116 | #else | ||
| 117 | |||
| 118 | #define M_QUOTE 0x80 | ||
| 119 | #define M_PROTECT 0x40 | ||
| 120 | #define M_MASK 0xff | ||
| 121 | #define M_ASCII 0x7f | ||
| 122 | |||
| 123 | typedef char Char; | ||
| 124 | |||
| 125 | #endif | ||
| 126 | |||
| 127 | |||
| 128 | #define CHAR(c) ((Char)((c)&M_ASCII)) | ||
| 129 | #define META(c) ((Char)((c)|M_QUOTE)) | ||
| 130 | #define M_ALL META('*') | ||
| 131 | #define M_END META(']') | ||
| 132 | #define M_NOT META('!') | ||
| 133 | #define M_ONE META('?') | ||
| 134 | #define M_RNG META('-') | ||
| 135 | #define M_SET META('[') | ||
| 136 | #define ismeta(c) (((c)&M_QUOTE) != 0) | ||
| 137 | |||
| 138 | |||
| 139 | static int compare __P((const void *, const void *)); | ||
| 140 | static int g_Ctoc __P((const Char *, char *, u_int)); | ||
| 141 | static int g_lstat __P((Char *, struct stat *, glob_t *)); | ||
| 142 | static DIR *g_opendir __P((Char *, glob_t *)); | ||
| 143 | static Char *g_strchr __P((Char *, int)); | ||
| 144 | static int g_stat __P((Char *, struct stat *, glob_t *)); | ||
| 145 | static int glob0 __P((const Char *, glob_t *)); | ||
| 146 | static int glob1 __P((Char *, Char *, glob_t *, size_t *)); | ||
| 147 | static int glob2 __P((Char *, Char *, Char *, Char *, Char *, Char *, | ||
| 148 | glob_t *, size_t *)); | ||
| 149 | static int glob3 __P((Char *, Char *, Char *, Char *, Char *, Char *, | ||
| 150 | Char *, Char *, glob_t *, size_t *)); | ||
| 151 | static int globextend __P((const Char *, glob_t *, size_t *)); | ||
| 152 | static const Char * | ||
| 153 | globtilde __P((const Char *, Char *, size_t, glob_t *)); | ||
| 154 | static int globexp1 __P((const Char *, glob_t *)); | ||
| 155 | static int globexp2 __P((const Char *, const Char *, glob_t *, int *)); | ||
| 156 | static int match __P((Char *, Char *, Char *)); | ||
| 157 | #ifdef DEBUG | ||
| 158 | static void qprintf __P((const char *, Char *)); | ||
| 159 | #endif | ||
| 160 | |||
| 161 | int | ||
| 162 | glob(pattern, flags, errfunc, pglob) | ||
| 163 | const char *pattern; | ||
| 164 | int flags, (*errfunc) __P((const char *, int)); | ||
| 165 | glob_t *pglob; | ||
| 166 | { | ||
| 167 | const u_char *patnext; | ||
| 168 | int c; | ||
| 169 | Char *bufnext, *bufend, patbuf[MAXPATHLEN]; | ||
| 170 | |||
| 171 | patnext = (u_char *) pattern; | ||
| 172 | if (!(flags & GLOB_APPEND)) { | ||
| 173 | pglob->gl_pathc = 0; | ||
| 174 | pglob->gl_pathv = NULL; | ||
| 175 | if (!(flags & GLOB_DOOFFS)) | ||
| 176 | pglob->gl_offs = 0; | ||
| 177 | } | ||
| 178 | pglob->gl_flags = flags & ~GLOB_MAGCHAR; | ||
| 179 | pglob->gl_errfunc = errfunc; | ||
| 180 | pglob->gl_matchc = 0; | ||
| 181 | |||
| 182 | bufnext = patbuf; | ||
| 183 | bufend = bufnext + MAXPATHLEN - 1; | ||
| 184 | if (flags & GLOB_NOESCAPE) | ||
| 185 | while (bufnext < bufend && (c = *patnext++) != EOS) | ||
| 186 | *bufnext++ = c; | ||
| 187 | else { | ||
| 188 | /* Protect the quoted characters. */ | ||
| 189 | while (bufnext < bufend && (c = *patnext++) != EOS) | ||
| 190 | if (c == QUOTE) { | ||
| 191 | if ((c = *patnext++) == EOS) { | ||
| 192 | c = QUOTE; | ||
| 193 | --patnext; | ||
| 194 | } | ||
| 195 | *bufnext++ = c | M_PROTECT; | ||
| 196 | } else | ||
| 197 | *bufnext++ = c; | ||
| 198 | } | ||
| 199 | *bufnext = EOS; | ||
| 200 | |||
| 201 | if (flags & GLOB_BRACE) | ||
| 202 | return globexp1(patbuf, pglob); | ||
| 203 | else | ||
| 204 | return glob0(patbuf, pglob); | ||
| 205 | } | ||
| 206 | |||
| 207 | /* | ||
| 208 | * Expand recursively a glob {} pattern. When there is no more expansion | ||
| 209 | * invoke the standard globbing routine to glob the rest of the magic | ||
| 210 | * characters | ||
| 211 | */ | ||
| 212 | static int | ||
| 213 | globexp1(pattern, pglob) | ||
| 214 | const Char *pattern; | ||
| 215 | glob_t *pglob; | ||
| 216 | { | ||
| 217 | const Char* ptr = pattern; | ||
| 218 | int rv; | ||
| 219 | |||
| 220 | /* Protect a single {}, for find(1), like csh */ | ||
| 221 | if (pattern[0] == LBRACE && pattern[1] == RBRACE && pattern[2] == EOS) | ||
| 222 | return glob0(pattern, pglob); | ||
| 223 | |||
| 224 | while ((ptr = (const Char *) g_strchr((Char *) ptr, LBRACE)) != NULL) | ||
| 225 | if (!globexp2(ptr, pattern, pglob, &rv)) | ||
| 226 | return rv; | ||
| 227 | |||
| 228 | return glob0(pattern, pglob); | ||
| 229 | } | ||
| 230 | |||
| 231 | |||
| 232 | /* | ||
| 233 | * Recursive brace globbing helper. Tries to expand a single brace. | ||
| 234 | * If it succeeds then it invokes globexp1 with the new pattern. | ||
| 235 | * If it fails then it tries to glob the rest of the pattern and returns. | ||
| 236 | */ | ||
| 237 | static int | ||
| 238 | globexp2(ptr, pattern, pglob, rv) | ||
| 239 | const Char *ptr, *pattern; | ||
| 240 | glob_t *pglob; | ||
| 241 | int *rv; | ||
| 242 | { | ||
| 243 | int i; | ||
| 244 | Char *lm, *ls; | ||
| 245 | const Char *pe, *pm, *pl; | ||
| 246 | Char patbuf[MAXPATHLEN]; | ||
| 247 | |||
| 248 | /* copy part up to the brace */ | ||
| 249 | for (lm = patbuf, pm = pattern; pm != ptr; *lm++ = *pm++) | ||
| 250 | ; | ||
| 251 | *lm = EOS; | ||
| 252 | ls = lm; | ||
| 253 | |||
| 254 | /* Find the balanced brace */ | ||
| 255 | for (i = 0, pe = ++ptr; *pe; pe++) | ||
| 256 | if (*pe == LBRACKET) { | ||
| 257 | /* Ignore everything between [] */ | ||
| 258 | for (pm = pe++; *pe != RBRACKET && *pe != EOS; pe++) | ||
| 259 | ; | ||
| 260 | if (*pe == EOS) { | ||
| 261 | /* | ||
| 262 | * We could not find a matching RBRACKET. | ||
| 263 | * Ignore and just look for RBRACE | ||
| 264 | */ | ||
| 265 | pe = pm; | ||
| 266 | } | ||
| 267 | } else if (*pe == LBRACE) | ||
| 268 | i++; | ||
| 269 | else if (*pe == RBRACE) { | ||
| 270 | if (i == 0) | ||
| 271 | break; | ||
| 272 | i--; | ||
| 273 | } | ||
| 274 | |||
| 275 | /* Non matching braces; just glob the pattern */ | ||
| 276 | if (i != 0 || *pe == EOS) { | ||
| 277 | *rv = glob0(patbuf, pglob); | ||
| 278 | return 0; | ||
| 279 | } | ||
| 280 | |||
| 281 | for (i = 0, pl = pm = ptr; pm <= pe; pm++) { | ||
| 282 | switch (*pm) { | ||
| 283 | case LBRACKET: | ||
| 284 | /* Ignore everything between [] */ | ||
| 285 | for (pl = pm++; *pm != RBRACKET && *pm != EOS; pm++) | ||
| 286 | ; | ||
| 287 | if (*pm == EOS) { | ||
| 288 | /* | ||
| 289 | * We could not find a matching RBRACKET. | ||
| 290 | * Ignore and just look for RBRACE | ||
| 291 | */ | ||
| 292 | pm = pl; | ||
| 293 | } | ||
| 294 | break; | ||
| 295 | |||
| 296 | case LBRACE: | ||
| 297 | i++; | ||
| 298 | break; | ||
| 299 | |||
| 300 | case RBRACE: | ||
| 301 | if (i) { | ||
| 302 | i--; | ||
| 303 | break; | ||
| 304 | } | ||
| 305 | /* FALLTHROUGH */ | ||
| 306 | case COMMA: | ||
| 307 | if (i && *pm == COMMA) | ||
| 308 | break; | ||
| 309 | else { | ||
| 310 | /* Append the current string */ | ||
| 311 | for (lm = ls; (pl < pm); *lm++ = *pl++) | ||
| 312 | ; | ||
| 313 | |||
| 314 | /* | ||
| 315 | * Append the rest of the pattern after the | ||
| 316 | * closing brace | ||
| 317 | */ | ||
| 318 | for (pl = pe + 1; (*lm++ = *pl++) != EOS; ) | ||
| 319 | ; | ||
| 320 | |||
| 321 | /* Expand the current pattern */ | ||
| 322 | #ifdef DEBUG | ||
| 323 | qprintf("globexp2:", patbuf); | ||
| 324 | #endif | ||
| 325 | *rv = globexp1(patbuf, pglob); | ||
| 326 | |||
| 327 | /* move after the comma, to the next string */ | ||
| 328 | pl = pm + 1; | ||
| 329 | } | ||
| 330 | break; | ||
| 331 | |||
| 332 | default: | ||
| 333 | break; | ||
| 334 | } | ||
| 335 | } | ||
| 336 | *rv = 0; | ||
| 337 | return 0; | ||
| 338 | } | ||
| 339 | |||
| 340 | |||
| 341 | |||
| 342 | /* | ||
| 343 | * expand tilde from the passwd file. | ||
| 344 | */ | ||
| 345 | static const Char * | ||
| 346 | globtilde(pattern, patbuf, patbuf_len, pglob) | ||
| 347 | const Char *pattern; | ||
| 348 | Char *patbuf; | ||
| 349 | size_t patbuf_len; | ||
| 350 | glob_t *pglob; | ||
| 351 | { | ||
| 352 | struct passwd *pwd; | ||
| 353 | char *h; | ||
| 354 | const Char *p; | ||
| 355 | Char *b, *eb; | ||
| 356 | |||
| 357 | if (*pattern != TILDE || !(pglob->gl_flags & GLOB_TILDE)) | ||
| 358 | return pattern; | ||
| 359 | |||
| 360 | /* Copy up to the end of the string or / */ | ||
| 361 | eb = &patbuf[patbuf_len - 1]; | ||
| 362 | for (p = pattern + 1, h = (char *) patbuf; | ||
| 363 | h < (char *)eb && *p && *p != SLASH; *h++ = *p++) | ||
| 364 | ; | ||
| 365 | |||
| 366 | *h = EOS; | ||
| 367 | |||
| 368 | #if 0 | ||
| 369 | if (h == (char *)eb) | ||
| 370 | return what; | ||
| 371 | #endif | ||
| 372 | |||
| 373 | if (((char *) patbuf)[0] == EOS) { | ||
| 374 | /* | ||
| 375 | * handle a plain ~ or ~/ by expanding $HOME | ||
| 376 | * first and then trying the password file | ||
| 377 | */ | ||
| 378 | #if 0 | ||
| 379 | if (issetugid() != 0 || (h = getenv("HOME")) == NULL) { | ||
| 380 | #endif | ||
| 381 | if ((getuid() != geteuid()) || (h = getenv("HOME")) == NULL) { | ||
| 382 | if ((pwd = getpwuid(getuid())) == NULL) | ||
| 383 | return pattern; | ||
| 384 | else | ||
| 385 | h = pwd->pw_dir; | ||
| 386 | } | ||
| 387 | } else { | ||
| 388 | /* | ||
| 389 | * Expand a ~user | ||
| 390 | */ | ||
| 391 | if ((pwd = getpwnam((char*) patbuf)) == NULL) | ||
| 392 | return pattern; | ||
| 393 | else | ||
| 394 | h = pwd->pw_dir; | ||
| 395 | } | ||
| 396 | |||
| 397 | /* Copy the home directory */ | ||
| 398 | for (b = patbuf; b < eb && *h; *b++ = *h++) | ||
| 399 | ; | ||
| 400 | |||
| 401 | /* Append the rest of the pattern */ | ||
| 402 | while (b < eb && (*b++ = *p++) != EOS) | ||
| 403 | ; | ||
| 404 | *b = EOS; | ||
| 405 | |||
| 406 | return patbuf; | ||
| 407 | } | ||
| 408 | |||
| 409 | |||
| 410 | /* | ||
| 411 | * The main glob() routine: compiles the pattern (optionally processing | ||
| 412 | * quotes), calls glob1() to do the real pattern matching, and finally | ||
| 413 | * sorts the list (unless unsorted operation is requested). Returns 0 | ||
| 414 | * if things went well, nonzero if errors occurred. It is not an error | ||
| 415 | * to find no matches. | ||
| 416 | */ | ||
| 417 | static int | ||
| 418 | glob0(pattern, pglob) | ||
| 419 | const Char *pattern; | ||
| 420 | glob_t *pglob; | ||
| 421 | { | ||
| 422 | const Char *qpatnext; | ||
| 423 | int c, err, oldpathc; | ||
| 424 | Char *bufnext, patbuf[MAXPATHLEN]; | ||
| 425 | size_t limit = 0; | ||
| 426 | |||
| 427 | qpatnext = globtilde(pattern, patbuf, MAXPATHLEN, pglob); | ||
| 428 | oldpathc = pglob->gl_pathc; | ||
| 429 | bufnext = patbuf; | ||
| 430 | |||
| 431 | /* We don't need to check for buffer overflow any more. */ | ||
| 432 | while ((c = *qpatnext++) != EOS) { | ||
| 433 | switch (c) { | ||
| 434 | case LBRACKET: | ||
| 435 | c = *qpatnext; | ||
| 436 | if (c == NOT) | ||
| 437 | ++qpatnext; | ||
| 438 | if (*qpatnext == EOS || | ||
| 439 | g_strchr((Char *) qpatnext+1, RBRACKET) == NULL) { | ||
| 440 | *bufnext++ = LBRACKET; | ||
| 441 | if (c == NOT) | ||
| 442 | --qpatnext; | ||
| 443 | break; | ||
| 444 | } | ||
| 445 | *bufnext++ = M_SET; | ||
| 446 | if (c == NOT) | ||
| 447 | *bufnext++ = M_NOT; | ||
| 448 | c = *qpatnext++; | ||
| 449 | do { | ||
| 450 | *bufnext++ = CHAR(c); | ||
| 451 | if (*qpatnext == RANGE && | ||
| 452 | (c = qpatnext[1]) != RBRACKET) { | ||
| 453 | *bufnext++ = M_RNG; | ||
| 454 | *bufnext++ = CHAR(c); | ||
| 455 | qpatnext += 2; | ||
| 456 | } | ||
| 457 | } while ((c = *qpatnext++) != RBRACKET); | ||
| 458 | pglob->gl_flags |= GLOB_MAGCHAR; | ||
| 459 | *bufnext++ = M_END; | ||
| 460 | break; | ||
| 461 | case QUESTION: | ||
| 462 | pglob->gl_flags |= GLOB_MAGCHAR; | ||
| 463 | *bufnext++ = M_ONE; | ||
| 464 | break; | ||
| 465 | case STAR: | ||
| 466 | pglob->gl_flags |= GLOB_MAGCHAR; | ||
| 467 | /* collapse adjacent stars to one, | ||
| 468 | * to avoid exponential behavior | ||
| 469 | */ | ||
| 470 | if (bufnext == patbuf || bufnext[-1] != M_ALL) | ||
| 471 | *bufnext++ = M_ALL; | ||
| 472 | break; | ||
| 473 | default: | ||
| 474 | *bufnext++ = CHAR(c); | ||
| 475 | break; | ||
| 476 | } | ||
| 477 | } | ||
| 478 | *bufnext = EOS; | ||
| 479 | #ifdef DEBUG | ||
| 480 | qprintf("glob0:", patbuf); | ||
| 481 | #endif | ||
| 482 | |||
| 483 | if ((err = glob1(patbuf, patbuf+MAXPATHLEN-1, pglob, &limit)) != 0) | ||
| 484 | return(err); | ||
| 485 | |||
| 486 | /* | ||
| 487 | * If there was no match we are going to append the pattern | ||
| 488 | * if GLOB_NOCHECK was specified or if GLOB_NOMAGIC was specified | ||
| 489 | * and the pattern did not contain any magic characters | ||
| 490 | * GLOB_NOMAGIC is there just for compatibility with csh. | ||
| 491 | */ | ||
| 492 | if (pglob->gl_pathc == oldpathc) { | ||
| 493 | if ((pglob->gl_flags & GLOB_NOCHECK) || | ||
| 494 | ((pglob->gl_flags & GLOB_NOMAGIC) && | ||
| 495 | !(pglob->gl_flags & GLOB_MAGCHAR))) | ||
| 496 | return(globextend(pattern, pglob, &limit)); | ||
| 497 | else | ||
| 498 | return(GLOB_NOMATCH); | ||
| 499 | } | ||
| 500 | if (!(pglob->gl_flags & GLOB_NOSORT)) | ||
| 501 | qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, | ||
| 502 | pglob->gl_pathc - oldpathc, sizeof(char *), compare); | ||
| 503 | return(0); | ||
| 504 | } | ||
| 505 | |||
| 506 | static int | ||
| 507 | compare(p, q) | ||
| 508 | const void *p, *q; | ||
| 509 | { | ||
| 510 | return(strcmp(*(char **)p, *(char **)q)); | ||
| 511 | } | ||
| 512 | |||
| 513 | static int | ||
| 514 | glob1(pattern, pattern_last, pglob, limitp) | ||
| 515 | Char *pattern, *pattern_last; | ||
| 516 | glob_t *pglob; | ||
| 517 | size_t *limitp; | ||
| 518 | { | ||
| 519 | Char pathbuf[MAXPATHLEN]; | ||
| 520 | |||
| 521 | /* A null pathname is invalid -- POSIX 1003.1 sect. 2.4. */ | ||
| 522 | if (*pattern == EOS) | ||
| 523 | return(0); | ||
| 524 | return(glob2(pathbuf, pathbuf+MAXPATHLEN-1, | ||
| 525 | pathbuf, pathbuf+MAXPATHLEN-1, | ||
| 526 | pattern, pattern_last, pglob, limitp)); | ||
| 527 | } | ||
| 528 | |||
| 529 | /* | ||
| 530 | * The functions glob2 and glob3 are mutually recursive; there is one level | ||
| 531 | * of recursion for each segment in the pattern that contains one or more | ||
| 532 | * meta characters. | ||
| 533 | */ | ||
| 534 | static int | ||
| 535 | glob2(pathbuf, pathbuf_last, pathend, pathend_last, pattern, | ||
| 536 | pattern_last, pglob, limitp) | ||
| 537 | Char *pathbuf, *pathbuf_last, *pathend, *pathend_last; | ||
| 538 | Char *pattern, *pattern_last; | ||
| 539 | glob_t *pglob; | ||
| 540 | size_t *limitp; | ||
| 541 | { | ||
| 542 | struct stat sb; | ||
| 543 | Char *p, *q; | ||
| 544 | int anymeta; | ||
| 545 | |||
| 546 | /* | ||
| 547 | * Loop over pattern segments until end of pattern or until | ||
| 548 | * segment with meta character found. | ||
| 549 | */ | ||
| 550 | for (anymeta = 0;;) { | ||
| 551 | if (*pattern == EOS) { /* End of pattern? */ | ||
| 552 | *pathend = EOS; | ||
| 553 | if (g_lstat(pathbuf, &sb, pglob)) | ||
| 554 | return(0); | ||
| 555 | |||
| 556 | if (((pglob->gl_flags & GLOB_MARK) && | ||
| 557 | pathend[-1] != SEP) && (S_ISDIR(sb.st_mode) || | ||
| 558 | (S_ISLNK(sb.st_mode) && | ||
| 559 | (g_stat(pathbuf, &sb, pglob) == 0) && | ||
| 560 | S_ISDIR(sb.st_mode)))) { | ||
| 561 | if (pathend+1 > pathend_last) | ||
| 562 | return (1); | ||
| 563 | *pathend++ = SEP; | ||
| 564 | *pathend = EOS; | ||
| 565 | } | ||
| 566 | ++pglob->gl_matchc; | ||
| 567 | return(globextend(pathbuf, pglob, limitp)); | ||
| 568 | } | ||
| 569 | |||
| 570 | /* Find end of next segment, copy tentatively to pathend. */ | ||
| 571 | q = pathend; | ||
| 572 | p = pattern; | ||
| 573 | while (*p != EOS && *p != SEP) { | ||
| 574 | if (ismeta(*p)) | ||
| 575 | anymeta = 1; | ||
| 576 | if (q+1 > pathend_last) | ||
| 577 | return (1); | ||
| 578 | *q++ = *p++; | ||
| 579 | } | ||
| 580 | |||
| 581 | if (!anymeta) { /* No expansion, do next segment. */ | ||
| 582 | pathend = q; | ||
| 583 | pattern = p; | ||
| 584 | while (*pattern == SEP) { | ||
| 585 | if (pathend+1 > pathend_last) | ||
| 586 | return (1); | ||
| 587 | *pathend++ = *pattern++; | ||
| 588 | } | ||
| 589 | } else | ||
| 590 | /* Need expansion, recurse. */ | ||
| 591 | return(glob3(pathbuf, pathbuf_last, pathend, | ||
| 592 | pathend_last, pattern, pattern_last, | ||
| 593 | p, pattern_last, pglob, limitp)); | ||
| 594 | } | ||
| 595 | /* NOTREACHED */ | ||
| 596 | } | ||
| 597 | |||
| 598 | static int | ||
| 599 | glob3(pathbuf, pathbuf_last, pathend, pathend_last, pattern, pattern_last, | ||
| 600 | restpattern, restpattern_last, pglob, limitp) | ||
| 601 | Char *pathbuf, *pathbuf_last, *pathend, *pathend_last; | ||
| 602 | Char *pattern, *pattern_last, *restpattern, *restpattern_last; | ||
| 603 | glob_t *pglob; | ||
| 604 | size_t *limitp; | ||
| 605 | { | ||
| 606 | register struct dirent *dp; | ||
| 607 | DIR *dirp; | ||
| 608 | int err; | ||
| 609 | char buf[MAXPATHLEN]; | ||
| 610 | |||
| 611 | /* | ||
| 612 | * The readdirfunc declaration can't be prototyped, because it is | ||
| 613 | * assigned, below, to two functions which are prototyped in glob.h | ||
| 614 | * and dirent.h as taking pointers to differently typed opaque | ||
| 615 | * structures. | ||
| 616 | */ | ||
| 617 | struct dirent *(*readdirfunc)(); | ||
| 618 | |||
| 619 | if (pathend > pathend_last) | ||
| 620 | return (1); | ||
| 621 | *pathend = EOS; | ||
| 622 | errno = 0; | ||
| 623 | |||
| 624 | if ((dirp = g_opendir(pathbuf, pglob)) == NULL) { | ||
| 625 | /* TODO: don't call for ENOENT or ENOTDIR? */ | ||
| 626 | if (pglob->gl_errfunc) { | ||
| 627 | if (g_Ctoc(pathbuf, buf, sizeof(buf))) | ||
| 628 | return(GLOB_ABORTED); | ||
| 629 | if (pglob->gl_errfunc(buf, errno) || | ||
| 630 | pglob->gl_flags & GLOB_ERR) | ||
| 631 | return(GLOB_ABORTED); | ||
| 632 | } | ||
| 633 | return(0); | ||
| 634 | } | ||
| 635 | |||
| 636 | err = 0; | ||
| 637 | |||
| 638 | /* Search directory for matching names. */ | ||
| 639 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | ||
| 640 | readdirfunc = pglob->gl_readdir; | ||
| 641 | else | ||
| 642 | readdirfunc = readdir; | ||
| 643 | while ((dp = (*readdirfunc)(dirp))) { | ||
| 644 | register u_char *sc; | ||
| 645 | register Char *dc; | ||
| 646 | |||
| 647 | /* Initial DOT must be matched literally. */ | ||
| 648 | if (dp->d_name[0] == DOT && *pattern != DOT) | ||
| 649 | continue; | ||
| 650 | dc = pathend; | ||
| 651 | sc = (u_char *) dp->d_name; | ||
| 652 | while (dc < pathend_last && (*dc++ = *sc++) != EOS) | ||
| 653 | ; | ||
| 654 | if (dc >= pathend_last) { | ||
| 655 | *dc = EOS; | ||
| 656 | err = 1; | ||
| 657 | break; | ||
| 658 | } | ||
| 659 | |||
| 660 | if (!match(pathend, pattern, restpattern)) { | ||
| 661 | *pathend = EOS; | ||
| 662 | continue; | ||
| 663 | } | ||
| 664 | err = glob2(pathbuf, pathbuf_last, --dc, pathend_last, | ||
| 665 | restpattern, restpattern_last, pglob, limitp); | ||
| 666 | if (err) | ||
| 667 | break; | ||
| 668 | } | ||
| 669 | |||
| 670 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | ||
| 671 | (*pglob->gl_closedir)(dirp); | ||
| 672 | else | ||
| 673 | closedir(dirp); | ||
| 674 | return(err); | ||
| 675 | } | ||
| 676 | |||
| 677 | |||
| 678 | /* | ||
| 679 | * Extend the gl_pathv member of a glob_t structure to accomodate a new item, | ||
| 680 | * add the new item, and update gl_pathc. | ||
| 681 | * | ||
| 682 | * This assumes the BSD realloc, which only copies the block when its size | ||
| 683 | * crosses a power-of-two boundary; for v7 realloc, this would cause quadratic | ||
| 684 | * behavior. | ||
| 685 | * | ||
| 686 | * Return 0 if new item added, error code if memory couldn't be allocated. | ||
| 687 | * | ||
| 688 | * Invariant of the glob_t structure: | ||
| 689 | * Either gl_pathc is zero and gl_pathv is NULL; or gl_pathc > 0 and | ||
| 690 | * gl_pathv points to (gl_offs + gl_pathc + 1) items. | ||
| 691 | */ | ||
| 692 | static int | ||
| 693 | globextend(path, pglob, limitp) | ||
| 694 | const Char *path; | ||
| 695 | glob_t *pglob; | ||
| 696 | size_t *limitp; | ||
| 697 | { | ||
| 698 | register char **pathv; | ||
| 699 | register int i; | ||
| 700 | u_int newsize, len; | ||
| 701 | char *copy; | ||
| 702 | const Char *p; | ||
| 703 | |||
| 704 | newsize = sizeof(*pathv) * (2 + pglob->gl_pathc + pglob->gl_offs); | ||
| 705 | pathv = pglob->gl_pathv ? realloc((char *)pglob->gl_pathv, newsize) : | ||
| 706 | malloc(newsize); | ||
| 707 | if (pathv == NULL) { | ||
| 708 | if (pglob->gl_pathv) { | ||
| 709 | free(pglob->gl_pathv); | ||
| 710 | pglob->gl_pathv = NULL; | ||
| 711 | } | ||
| 712 | return(GLOB_NOSPACE); | ||
| 713 | } | ||
| 714 | |||
| 715 | if (pglob->gl_pathv == NULL && pglob->gl_offs > 0) { | ||
| 716 | /* first time around -- clear initial gl_offs items */ | ||
| 717 | pathv += pglob->gl_offs; | ||
| 718 | for (i = pglob->gl_offs; --i >= 0; ) | ||
| 719 | *--pathv = NULL; | ||
| 720 | } | ||
| 721 | pglob->gl_pathv = pathv; | ||
| 722 | |||
| 723 | for (p = path; *p++;) | ||
| 724 | ; | ||
| 725 | len = (size_t)(p - path); | ||
| 726 | *limitp += len; | ||
| 727 | if ((copy = malloc(len)) != NULL) { | ||
| 728 | if (g_Ctoc(path, copy, len)) { | ||
| 729 | free(copy); | ||
| 730 | return(GLOB_NOSPACE); | ||
| 731 | } | ||
| 732 | pathv[pglob->gl_offs + pglob->gl_pathc++] = copy; | ||
| 733 | } | ||
| 734 | pathv[pglob->gl_offs + pglob->gl_pathc] = NULL; | ||
| 735 | |||
| 736 | if ((pglob->gl_flags & GLOB_LIMIT) && | ||
| 737 | newsize + *limitp >= (u_int) get_arg_max()) { | ||
| 738 | errno = 0; | ||
| 739 | return(GLOB_NOSPACE); | ||
| 740 | } | ||
| 741 | |||
| 742 | return(copy == NULL ? GLOB_NOSPACE : 0); | ||
| 743 | } | ||
| 744 | |||
| 745 | |||
| 746 | /* | ||
| 747 | * pattern matching function for filenames. Each occurrence of the * | ||
| 748 | * pattern causes a recursion level. | ||
| 749 | */ | ||
| 750 | static int | ||
| 751 | match(name, pat, patend) | ||
| 752 | register Char *name, *pat, *patend; | ||
| 753 | { | ||
| 754 | int ok, negate_range; | ||
| 755 | Char c, k; | ||
| 756 | |||
| 757 | while (pat < patend) { | ||
| 758 | c = *pat++; | ||
| 759 | switch (c & M_MASK) { | ||
| 760 | case M_ALL: | ||
| 761 | if (pat == patend) | ||
| 762 | return(1); | ||
| 763 | do | ||
| 764 | if (match(name, pat, patend)) | ||
| 765 | return(1); | ||
| 766 | while (*name++ != EOS) | ||
| 767 | ; | ||
| 768 | return(0); | ||
| 769 | case M_ONE: | ||
| 770 | if (*name++ == EOS) | ||
| 771 | return(0); | ||
| 772 | break; | ||
| 773 | case M_SET: | ||
| 774 | ok = 0; | ||
| 775 | if ((k = *name++) == EOS) | ||
| 776 | return(0); | ||
| 777 | if ((negate_range = ((*pat & M_MASK) == M_NOT)) != EOS) | ||
| 778 | ++pat; | ||
| 779 | while (((c = *pat++) & M_MASK) != M_END) | ||
| 780 | if ((*pat & M_MASK) == M_RNG) { | ||
| 781 | if (c <= k && k <= pat[1]) | ||
| 782 | ok = 1; | ||
| 783 | pat += 2; | ||
| 784 | } else if (c == k) | ||
| 785 | ok = 1; | ||
| 786 | if (ok == negate_range) | ||
| 787 | return(0); | ||
| 788 | break; | ||
| 789 | default: | ||
| 790 | if (*name++ != c) | ||
| 791 | return(0); | ||
| 792 | break; | ||
| 793 | } | ||
| 794 | } | ||
| 795 | return(*name == EOS); | ||
| 796 | } | ||
| 797 | |||
| 798 | /* Free allocated data belonging to a glob_t structure. */ | ||
| 799 | void | ||
| 800 | globfree(pglob) | ||
| 801 | glob_t *pglob; | ||
| 802 | { | ||
| 803 | register int i; | ||
| 804 | register char **pp; | ||
| 805 | |||
| 806 | if (pglob->gl_pathv != NULL) { | ||
| 807 | pp = pglob->gl_pathv + pglob->gl_offs; | ||
| 808 | for (i = pglob->gl_pathc; i--; ++pp) | ||
| 809 | if (*pp) | ||
| 810 | free(*pp); | ||
| 811 | free(pglob->gl_pathv); | ||
| 812 | pglob->gl_pathv = NULL; | ||
| 813 | } | ||
| 814 | } | ||
| 815 | |||
| 816 | static DIR * | ||
| 817 | g_opendir(str, pglob) | ||
| 818 | register Char *str; | ||
| 819 | glob_t *pglob; | ||
| 820 | { | ||
| 821 | char buf[MAXPATHLEN]; | ||
| 822 | |||
| 823 | if (!*str) | ||
| 824 | strcpy(buf, "."); | ||
| 825 | else { | ||
| 826 | if (g_Ctoc(str, buf, sizeof(buf))) | ||
| 827 | return(NULL); | ||
| 828 | } | ||
| 829 | |||
| 830 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | ||
| 831 | return((*pglob->gl_opendir)(buf)); | ||
| 832 | |||
| 833 | return(opendir(buf)); | ||
| 834 | } | ||
| 835 | |||
| 836 | static int | ||
| 837 | g_lstat(fn, sb, pglob) | ||
| 838 | register Char *fn; | ||
| 839 | struct stat *sb; | ||
| 840 | glob_t *pglob; | ||
| 841 | { | ||
| 842 | char buf[MAXPATHLEN]; | ||
| 843 | |||
| 844 | if (g_Ctoc(fn, buf, sizeof(buf))) | ||
| 845 | return(-1); | ||
| 846 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | ||
| 847 | return((*pglob->gl_lstat)(buf, sb)); | ||
| 848 | return(lstat(buf, sb)); | ||
| 849 | } | ||
| 850 | |||
| 851 | static int | ||
| 852 | g_stat(fn, sb, pglob) | ||
| 853 | register Char *fn; | ||
| 854 | struct stat *sb; | ||
| 855 | glob_t *pglob; | ||
| 856 | { | ||
| 857 | char buf[MAXPATHLEN]; | ||
| 858 | |||
| 859 | if (g_Ctoc(fn, buf, sizeof(buf))) | ||
| 860 | return(-1); | ||
| 861 | if (pglob->gl_flags & GLOB_ALTDIRFUNC) | ||
| 862 | return((*pglob->gl_stat)(buf, sb)); | ||
| 863 | return(stat(buf, sb)); | ||
| 864 | } | ||
| 865 | |||
| 866 | static Char * | ||
| 867 | g_strchr(str, ch) | ||
| 868 | Char *str; | ||
| 869 | int ch; | ||
| 870 | { | ||
| 871 | do { | ||
| 872 | if (*str == ch) | ||
| 873 | return (str); | ||
| 874 | } while (*str++); | ||
| 875 | return (NULL); | ||
| 876 | } | ||
| 877 | |||
| 878 | static int | ||
| 879 | g_Ctoc(str, buf, len) | ||
| 880 | register const Char *str; | ||
| 881 | char *buf; | ||
| 882 | u_int len; | ||
| 883 | { | ||
| 884 | |||
| 885 | while (len--) { | ||
| 886 | if ((*buf++ = *str++) == EOS) | ||
| 887 | return (0); | ||
| 888 | } | ||
| 889 | return (1); | ||
| 890 | } | ||
| 891 | |||
| 892 | #ifdef DEBUG | ||
| 893 | static void | ||
| 894 | qprintf(str, s) | ||
| 895 | const char *str; | ||
| 896 | register Char *s; | ||
| 897 | { | ||
| 898 | register Char *p; | ||
| 899 | |||
| 900 | (void)printf("%s:\n", str); | ||
| 901 | for (p = s; *p; p++) | ||
| 902 | (void)printf("%c", CHAR(*p)); | ||
| 903 | (void)printf("\n"); | ||
| 904 | for (p = s; *p; p++) | ||
| 905 | (void)printf("%c", *p & M_PROTECT ? '"' : ' '); | ||
| 906 | (void)printf("\n"); | ||
| 907 | for (p = s; *p; p++) | ||
| 908 | (void)printf("%c", ismeta(*p) ? '_' : ' '); | ||
| 909 | (void)printf("\n"); | ||
| 910 | } | ||
| 911 | #endif | ||
| 912 | |||
| 913 | #endif /* !defined(HAVE_GLOB) || !defined(GLOB_HAS_ALTDIRFUNC) || | ||
| 914 | !defined(GLOB_HAS_GL_MATCHC) */ | ||
| 915 | |||
diff --git a/other/ssharp/openbsd-compat/glob.h b/other/ssharp/openbsd-compat/glob.h new file mode 100644 index 0000000..b4c8f7a --- /dev/null +++ b/other/ssharp/openbsd-compat/glob.h | |||
| @@ -0,0 +1,101 @@ | |||
| 1 | /* $OpenBSD: glob.h,v 1.5 2001/03/18 17:18:58 deraadt Exp $ */ | ||
| 2 | /* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1989, 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 | * Guido van Rossum. | ||
| 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. All advertising materials mentioning features or use of this software | ||
| 20 | * must display the following acknowledgement: | ||
| 21 | * This product includes software developed by the University of | ||
| 22 | * California, Berkeley and its contributors. | ||
| 23 | * 4. Neither the name of the University nor the names of its contributors | ||
| 24 | * may be used to endorse or promote products derived from this software | ||
| 25 | * without specific prior written permission. | ||
| 26 | * | ||
| 27 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 33 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 34 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 35 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 36 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 37 | * SUCH DAMAGE. | ||
| 38 | * | ||
| 39 | * @(#)glob.h 8.1 (Berkeley) 6/2/93 | ||
| 40 | */ | ||
| 41 | |||
| 42 | #if !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || \ | ||
| 43 | !defined(GLOB_HAS_GL_MATCHC) | ||
| 44 | |||
| 45 | #ifndef _GLOB_H_ | ||
| 46 | #define _GLOB_H_ | ||
| 47 | |||
| 48 | struct stat; | ||
| 49 | typedef struct { | ||
| 50 | int gl_pathc; /* Count of total paths so far. */ | ||
| 51 | int gl_matchc; /* Count of paths matching pattern. */ | ||
| 52 | int gl_offs; /* Reserved at beginning of gl_pathv. */ | ||
| 53 | int gl_flags; /* Copy of flags parameter to glob. */ | ||
| 54 | char **gl_pathv; /* List of paths matching pattern. */ | ||
| 55 | /* Copy of errfunc parameter to glob. */ | ||
| 56 | int (*gl_errfunc) __P((const char *, int)); | ||
| 57 | |||
| 58 | /* | ||
| 59 | * Alternate filesystem access methods for glob; replacement | ||
| 60 | * versions of closedir(3), readdir(3), opendir(3), stat(2) | ||
| 61 | * and lstat(2). | ||
| 62 | */ | ||
| 63 | void (*gl_closedir) __P((void *)); | ||
| 64 | struct dirent *(*gl_readdir) __P((void *)); | ||
| 65 | void *(*gl_opendir) __P((const char *)); | ||
| 66 | int (*gl_lstat) __P((const char *, struct stat *)); | ||
| 67 | int (*gl_stat) __P((const char *, struct stat *)); | ||
| 68 | } glob_t; | ||
| 69 | |||
| 70 | /* Flags */ | ||
| 71 | #define GLOB_APPEND 0x0001 /* Append to output from previous call. */ | ||
| 72 | #define GLOB_DOOFFS 0x0002 /* Use gl_offs. */ | ||
| 73 | #define GLOB_ERR 0x0004 /* Return on error. */ | ||
| 74 | #define GLOB_MARK 0x0008 /* Append / to matching directories. */ | ||
| 75 | #define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */ | ||
| 76 | #define GLOB_NOSORT 0x0020 /* Don't sort. */ | ||
| 77 | |||
| 78 | #define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */ | ||
| 79 | #define GLOB_BRACE 0x0080 /* Expand braces ala csh. */ | ||
| 80 | #define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */ | ||
| 81 | #define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */ | ||
| 82 | #define GLOB_QUOTE 0x0400 /* Quote special chars with \. */ | ||
| 83 | #define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */ | ||
| 84 | #define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */ | ||
| 85 | #define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */ | ||
| 86 | |||
| 87 | /* Error values returned by glob(3) */ | ||
| 88 | #define GLOB_NOSPACE (-1) /* Malloc call failed. */ | ||
| 89 | #define GLOB_ABORTED (-2) /* Unignored error. */ | ||
| 90 | #define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */ | ||
| 91 | #define GLOB_NOSYS (-4) /* Function not supported. */ | ||
| 92 | #define GLOB_ABEND GLOB_ABORTED | ||
| 93 | |||
| 94 | int glob __P((const char *, int, int (*)(const char *, int), glob_t *)); | ||
| 95 | void globfree __P((glob_t *)); | ||
| 96 | |||
| 97 | #endif /* !_GLOB_H_ */ | ||
| 98 | |||
| 99 | #endif /* !defined(HAVE_GLOB_H) || !defined(GLOB_HAS_ALTDIRFUNC) || | ||
| 100 | !defined(GLOB_HAS_GL_MATCHC */ | ||
| 101 | |||
diff --git a/other/ssharp/openbsd-compat/inet_aton.c b/other/ssharp/openbsd-compat/inet_aton.c new file mode 100644 index 0000000..18e31e7 --- /dev/null +++ b/other/ssharp/openbsd-compat/inet_aton.c | |||
| @@ -0,0 +1,193 @@ | |||
| 1 | /* $OpenBSD: inet_addr.c,v 1.6 1999/05/03 22:31:14 yanick Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * ++Copyright++ 1983, 1990, 1993 | ||
| 5 | * - | ||
| 6 | * Copyright (c) 1983, 1990, 1993 | ||
| 7 | * The Regents of the University of California. All rights reserved. | ||
| 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 | * 3. All advertising materials mentioning features or use of this software | ||
| 18 | * must display the following acknowledgement: | ||
| 19 | * This product includes software developed by the University of | ||
| 20 | * California, Berkeley and its contributors. | ||
| 21 | * 4. Neither the name of the University nor the names of its contributors | ||
| 22 | * may be used to endorse or promote products derived from this software | ||
| 23 | * without specific prior written permission. | ||
| 24 | * | ||
| 25 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 26 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 27 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 28 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 29 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 30 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 31 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 32 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 33 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 34 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 35 | * SUCH DAMAGE. | ||
| 36 | * - | ||
| 37 | * Portions Copyright (c) 1993 by Digital Equipment Corporation. | ||
| 38 | * | ||
| 39 | * Permission to use, copy, modify, and distribute this software for any | ||
| 40 | * purpose with or without fee is hereby granted, provided that the above | ||
| 41 | * copyright notice and this permission notice appear in all copies, and that | ||
| 42 | * the name of Digital Equipment Corporation not be used in advertising or | ||
| 43 | * publicity pertaining to distribution of the document or software without | ||
| 44 | * specific, written prior permission. | ||
| 45 | * | ||
| 46 | * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL | ||
| 47 | * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES | ||
| 48 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT | ||
| 49 | * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
| 50 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
| 51 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
| 52 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
| 53 | * SOFTWARE. | ||
| 54 | * - | ||
| 55 | * --Copyright-- | ||
| 56 | */ | ||
| 57 | |||
| 58 | #include "config.h" | ||
| 59 | |||
| 60 | #if !defined(HAVE_INET_ATON) | ||
| 61 | |||
| 62 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 63 | #if 0 | ||
| 64 | static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; | ||
| 65 | static char rcsid[] = "$From: inet_addr.c,v 8.5 1996/08/05 08:31:35 vixie Exp $"; | ||
| 66 | #else | ||
| 67 | static char rcsid[] = "$OpenBSD: inet_addr.c,v 1.6 1999/05/03 22:31:14 yanick Exp $"; | ||
| 68 | #endif | ||
| 69 | #endif /* LIBC_SCCS and not lint */ | ||
| 70 | |||
| 71 | #include <sys/types.h> | ||
| 72 | #include <sys/param.h> | ||
| 73 | #include <netinet/in.h> | ||
| 74 | #include <arpa/inet.h> | ||
| 75 | #include <ctype.h> | ||
| 76 | |||
| 77 | #if 0 | ||
| 78 | /* | ||
| 79 | * Ascii internet address interpretation routine. | ||
| 80 | * The value returned is in network order. | ||
| 81 | */ | ||
| 82 | in_addr_t | ||
| 83 | inet_addr(cp) | ||
| 84 | register const char *cp; | ||
| 85 | { | ||
| 86 | struct in_addr val; | ||
| 87 | |||
| 88 | if (inet_aton(cp, &val)) | ||
| 89 | return (val.s_addr); | ||
| 90 | return (INADDR_NONE); | ||
| 91 | } | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* | ||
| 95 | * Check whether "cp" is a valid ascii representation | ||
| 96 | * of an Internet address and convert to a binary address. | ||
| 97 | * Returns 1 if the address is valid, 0 if not. | ||
| 98 | * This replaces inet_addr, the return value from which | ||
| 99 | * cannot distinguish between failure and a local broadcast address. | ||
| 100 | */ | ||
| 101 | int | ||
| 102 | inet_aton(const char *cp, struct in_addr *addr) | ||
| 103 | { | ||
| 104 | register u_int32_t val; | ||
| 105 | register int base, n; | ||
| 106 | register char c; | ||
| 107 | unsigned int parts[4]; | ||
| 108 | register unsigned int *pp = parts; | ||
| 109 | |||
| 110 | c = *cp; | ||
| 111 | for (;;) { | ||
| 112 | /* | ||
| 113 | * Collect number up to ``.''. | ||
| 114 | * Values are specified as for C: | ||
| 115 | * 0x=hex, 0=octal, isdigit=decimal. | ||
| 116 | */ | ||
| 117 | if (!isdigit(c)) | ||
| 118 | return (0); | ||
| 119 | val = 0; base = 10; | ||
| 120 | if (c == '0') { | ||
| 121 | c = *++cp; | ||
| 122 | if (c == 'x' || c == 'X') | ||
| 123 | base = 16, c = *++cp; | ||
| 124 | else | ||
| 125 | base = 8; | ||
| 126 | } | ||
| 127 | for (;;) { | ||
| 128 | if (isascii(c) && isdigit(c)) { | ||
| 129 | val = (val * base) + (c - '0'); | ||
| 130 | c = *++cp; | ||
| 131 | } else if (base == 16 && isascii(c) && isxdigit(c)) { | ||
| 132 | val = (val << 4) | | ||
| 133 | (c + 10 - (islower(c) ? 'a' : 'A')); | ||
| 134 | c = *++cp; | ||
| 135 | } else | ||
| 136 | break; | ||
| 137 | } | ||
| 138 | if (c == '.') { | ||
| 139 | /* | ||
| 140 | * Internet format: | ||
| 141 | * a.b.c.d | ||
| 142 | * a.b.c (with c treated as 16 bits) | ||
| 143 | * a.b (with b treated as 24 bits) | ||
| 144 | */ | ||
| 145 | if (pp >= parts + 3) | ||
| 146 | return (0); | ||
| 147 | *pp++ = val; | ||
| 148 | c = *++cp; | ||
| 149 | } else | ||
| 150 | break; | ||
| 151 | } | ||
| 152 | /* | ||
| 153 | * Check for trailing characters. | ||
| 154 | */ | ||
| 155 | if (c != '\0' && (!isascii(c) || !isspace(c))) | ||
| 156 | return (0); | ||
| 157 | /* | ||
| 158 | * Concoct the address according to | ||
| 159 | * the number of parts specified. | ||
| 160 | */ | ||
| 161 | n = pp - parts + 1; | ||
| 162 | switch (n) { | ||
| 163 | |||
| 164 | case 0: | ||
| 165 | return (0); /* initial nondigit */ | ||
| 166 | |||
| 167 | case 1: /* a -- 32 bits */ | ||
| 168 | break; | ||
| 169 | |||
| 170 | case 2: /* a.b -- 8.24 bits */ | ||
| 171 | if ((val > 0xffffff) || (parts[0] > 0xff)) | ||
| 172 | return (0); | ||
| 173 | val |= parts[0] << 24; | ||
| 174 | break; | ||
| 175 | |||
| 176 | case 3: /* a.b.c -- 8.8.16 bits */ | ||
| 177 | if ((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff)) | ||
| 178 | return (0); | ||
| 179 | val |= (parts[0] << 24) | (parts[1] << 16); | ||
| 180 | break; | ||
| 181 | |||
| 182 | case 4: /* a.b.c.d -- 8.8.8.8 bits */ | ||
| 183 | if ((val > 0xff) || (parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) | ||
| 184 | return (0); | ||
| 185 | val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); | ||
| 186 | break; | ||
| 187 | } | ||
| 188 | if (addr) | ||
| 189 | addr->s_addr = htonl(val); | ||
| 190 | return (1); | ||
| 191 | } | ||
| 192 | |||
| 193 | #endif /* !defined(HAVE_INET_ATON) */ | ||
diff --git a/other/ssharp/openbsd-compat/inet_aton.h b/other/ssharp/openbsd-compat/inet_aton.h new file mode 100644 index 0000000..bbdefd7 --- /dev/null +++ b/other/ssharp/openbsd-compat/inet_aton.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: inet_aton.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_INET_ATON_H | ||
| 4 | #define _BSD_INET_ATON_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_INET_ATON | ||
| 9 | int inet_aton(const char *cp, struct in_addr *addr); | ||
| 10 | #endif /* HAVE_INET_ATON */ | ||
| 11 | |||
| 12 | #endif /* _BSD_INET_ATON_H */ | ||
diff --git a/other/ssharp/openbsd-compat/inet_ntoa.c b/other/ssharp/openbsd-compat/inet_ntoa.c new file mode 100644 index 0000000..8a8b3c8 --- /dev/null +++ b/other/ssharp/openbsd-compat/inet_ntoa.c | |||
| @@ -0,0 +1,64 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1983, 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 | |||
| 34 | #include "config.h" | ||
| 35 | |||
| 36 | #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) | ||
| 37 | |||
| 38 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 39 | static char rcsid[] = "$OpenBSD: inet_ntoa.c,v 1.2 1996/08/19 08:29:16 tholo Exp $"; | ||
| 40 | #endif /* LIBC_SCCS and not lint */ | ||
| 41 | |||
| 42 | /* | ||
| 43 | * Convert network-format internet address | ||
| 44 | * to base 256 d.d.d.d representation. | ||
| 45 | */ | ||
| 46 | #include <sys/types.h> | ||
| 47 | #include <netinet/in.h> | ||
| 48 | #include <arpa/inet.h> | ||
| 49 | #include <stdio.h> | ||
| 50 | #include "inet_ntoa.h" | ||
| 51 | |||
| 52 | char *inet_ntoa(struct in_addr in) | ||
| 53 | { | ||
| 54 | static char b[18]; | ||
| 55 | register char *p; | ||
| 56 | |||
| 57 | p = (char *)∈ | ||
| 58 | #define UC(b) (((int)b)&0xff) | ||
| 59 | (void)snprintf(b, sizeof(b), | ||
| 60 | "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); | ||
| 61 | return (b); | ||
| 62 | } | ||
| 63 | |||
| 64 | #endif /* defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) */ | ||
diff --git a/other/ssharp/openbsd-compat/inet_ntoa.h b/other/ssharp/openbsd-compat/inet_ntoa.h new file mode 100644 index 0000000..c719774 --- /dev/null +++ b/other/ssharp/openbsd-compat/inet_ntoa.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: inet_ntoa.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_INET_NTOA_H | ||
| 4 | #define _BSD_INET_NTOA_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #if defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) | ||
| 9 | char *inet_ntoa(struct in_addr in); | ||
| 10 | #endif /* defined(BROKEN_INET_NTOA) || !defined(HAVE_INET_NTOA) */ | ||
| 11 | |||
| 12 | #endif /* _BSD_INET_NTOA_H */ | ||
diff --git a/other/ssharp/openbsd-compat/inet_ntop.c b/other/ssharp/openbsd-compat/inet_ntop.c new file mode 100644 index 0000000..bf3d97a --- /dev/null +++ b/other/ssharp/openbsd-compat/inet_ntop.c | |||
| @@ -0,0 +1,211 @@ | |||
| 1 | /* $OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $ */ | ||
| 2 | |||
| 3 | /* Copyright (c) 1996 by Internet Software Consortium. | ||
| 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS | ||
| 10 | * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | ||
| 11 | * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE | ||
| 12 | * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL | ||
| 13 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR | ||
| 14 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS | ||
| 15 | * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | ||
| 16 | * SOFTWARE. | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include "config.h" | ||
| 20 | |||
| 21 | #ifndef HAVE_INET_NTOP | ||
| 22 | |||
| 23 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 24 | #if 0 | ||
| 25 | static char rcsid[] = "$From: inet_ntop.c,v 8.7 1996/08/05 08:41:18 vixie Exp $"; | ||
| 26 | #else | ||
| 27 | static char rcsid[] = "$OpenBSD: inet_ntop.c,v 1.1 1997/03/13 19:07:32 downsj Exp $"; | ||
| 28 | #endif | ||
| 29 | #endif /* LIBC_SCCS and not lint */ | ||
| 30 | |||
| 31 | #include <sys/param.h> | ||
| 32 | #include <sys/types.h> | ||
| 33 | #include <sys/socket.h> | ||
| 34 | #include "openbsd-compat/fake-socket.h" | ||
| 35 | #include <netinet/in.h> | ||
| 36 | #include <arpa/inet.h> | ||
| 37 | #ifndef HAVE_CYGWIN | ||
| 38 | #include <arpa/nameser.h> | ||
| 39 | #endif | ||
| 40 | #include <string.h> | ||
| 41 | #include <errno.h> | ||
| 42 | #include <stdio.h> | ||
| 43 | |||
| 44 | #ifndef IN6ADDRSZ | ||
| 45 | #define IN6ADDRSZ 16 /* IPv6 T_AAAA */ | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #ifndef INT16SZ | ||
| 49 | #define INT16SZ 2 /* for systems without 16-bit ints */ | ||
| 50 | #endif | ||
| 51 | |||
| 52 | /* | ||
| 53 | * WARNING: Don't even consider trying to compile this on a system where | ||
| 54 | * sizeof(int) < 4. sizeof(int) > 4 is fine; all the world's not a VAX. | ||
| 55 | */ | ||
| 56 | |||
| 57 | static const char *inet_ntop4 __P((const u_char *src, char *dst, size_t size)); | ||
| 58 | static const char *inet_ntop6 __P((const u_char *src, char *dst, size_t size)); | ||
| 59 | |||
| 60 | /* char * | ||
| 61 | * inet_ntop(af, src, dst, size) | ||
| 62 | * convert a network format address to presentation format. | ||
| 63 | * return: | ||
| 64 | * pointer to presentation format address (`dst'), or NULL (see errno). | ||
| 65 | * author: | ||
| 66 | * Paul Vixie, 1996. | ||
| 67 | */ | ||
| 68 | const char * | ||
| 69 | inet_ntop(af, src, dst, size) | ||
| 70 | int af; | ||
| 71 | const void *src; | ||
| 72 | char *dst; | ||
| 73 | size_t size; | ||
| 74 | { | ||
| 75 | switch (af) { | ||
| 76 | case AF_INET: | ||
| 77 | return (inet_ntop4(src, dst, size)); | ||
| 78 | case AF_INET6: | ||
| 79 | return (inet_ntop6(src, dst, size)); | ||
| 80 | default: | ||
| 81 | errno = EAFNOSUPPORT; | ||
| 82 | return (NULL); | ||
| 83 | } | ||
| 84 | /* NOTREACHED */ | ||
| 85 | } | ||
| 86 | |||
| 87 | /* const char * | ||
| 88 | * inet_ntop4(src, dst, size) | ||
| 89 | * format an IPv4 address, more or less like inet_ntoa() | ||
| 90 | * return: | ||
| 91 | * `dst' (as a const) | ||
| 92 | * notes: | ||
| 93 | * (1) uses no statics | ||
| 94 | * (2) takes a u_char* not an in_addr as input | ||
| 95 | * author: | ||
| 96 | * Paul Vixie, 1996. | ||
| 97 | */ | ||
| 98 | static const char * | ||
| 99 | inet_ntop4(src, dst, size) | ||
| 100 | const u_char *src; | ||
| 101 | char *dst; | ||
| 102 | size_t size; | ||
| 103 | { | ||
| 104 | static const char fmt[] = "%u.%u.%u.%u"; | ||
| 105 | char tmp[sizeof "255.255.255.255"]; | ||
| 106 | |||
| 107 | if (sprintf(tmp, fmt, src[0], src[1], src[2], src[3]) > size) { | ||
| 108 | errno = ENOSPC; | ||
| 109 | return (NULL); | ||
| 110 | } | ||
| 111 | strcpy(dst, tmp); | ||
| 112 | return (dst); | ||
| 113 | } | ||
| 114 | |||
| 115 | /* const char * | ||
| 116 | * inet_ntop6(src, dst, size) | ||
| 117 | * convert IPv6 binary address into presentation (printable) format | ||
| 118 | * author: | ||
| 119 | * Paul Vixie, 1996. | ||
| 120 | */ | ||
| 121 | static const char * | ||
| 122 | inet_ntop6(src, dst, size) | ||
| 123 | const u_char *src; | ||
| 124 | char *dst; | ||
| 125 | size_t size; | ||
| 126 | { | ||
| 127 | /* | ||
| 128 | * Note that int32_t and int16_t need only be "at least" large enough | ||
| 129 | * to contain a value of the specified size. On some systems, like | ||
| 130 | * Crays, there is no such thing as an integer variable with 16 bits. | ||
| 131 | * Keep this in mind if you think this function should have been coded | ||
| 132 | * to use pointer overlays. All the world's not a VAX. | ||
| 133 | */ | ||
| 134 | char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp; | ||
| 135 | struct { int base, len; } best, cur; | ||
| 136 | u_int words[IN6ADDRSZ / INT16SZ]; | ||
| 137 | int i; | ||
| 138 | |||
| 139 | /* | ||
| 140 | * Preprocess: | ||
| 141 | * Copy the input (bytewise) array into a wordwise array. | ||
| 142 | * Find the longest run of 0x00's in src[] for :: shorthanding. | ||
| 143 | */ | ||
| 144 | memset(words, '\0', sizeof words); | ||
| 145 | for (i = 0; i < IN6ADDRSZ; i++) | ||
| 146 | words[i / 2] |= (src[i] << ((1 - (i % 2)) << 3)); | ||
| 147 | best.base = -1; | ||
| 148 | cur.base = -1; | ||
| 149 | for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { | ||
| 150 | if (words[i] == 0) { | ||
| 151 | if (cur.base == -1) | ||
| 152 | cur.base = i, cur.len = 1; | ||
| 153 | else | ||
| 154 | cur.len++; | ||
| 155 | } else { | ||
| 156 | if (cur.base != -1) { | ||
| 157 | if (best.base == -1 || cur.len > best.len) | ||
| 158 | best = cur; | ||
| 159 | cur.base = -1; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | } | ||
| 163 | if (cur.base != -1) { | ||
| 164 | if (best.base == -1 || cur.len > best.len) | ||
| 165 | best = cur; | ||
| 166 | } | ||
| 167 | if (best.base != -1 && best.len < 2) | ||
| 168 | best.base = -1; | ||
| 169 | |||
| 170 | /* | ||
| 171 | * Format the result. | ||
| 172 | */ | ||
| 173 | tp = tmp; | ||
| 174 | for (i = 0; i < (IN6ADDRSZ / INT16SZ); i++) { | ||
| 175 | /* Are we inside the best run of 0x00's? */ | ||
| 176 | if (best.base != -1 && i >= best.base && | ||
| 177 | i < (best.base + best.len)) { | ||
| 178 | if (i == best.base) | ||
| 179 | *tp++ = ':'; | ||
| 180 | continue; | ||
| 181 | } | ||
| 182 | /* Are we following an initial run of 0x00s or any real hex? */ | ||
| 183 | if (i != 0) | ||
| 184 | *tp++ = ':'; | ||
| 185 | /* Is this address an encapsulated IPv4? */ | ||
| 186 | if (i == 6 && best.base == 0 && | ||
| 187 | (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { | ||
| 188 | if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp))) | ||
| 189 | return (NULL); | ||
| 190 | tp += strlen(tp); | ||
| 191 | break; | ||
| 192 | } | ||
| 193 | tp += sprintf(tp, "%x", words[i]); | ||
| 194 | } | ||
| 195 | /* Was it a trailing run of 0x00's? */ | ||
| 196 | if (best.base != -1 && (best.base + best.len) == (IN6ADDRSZ / INT16SZ)) | ||
| 197 | *tp++ = ':'; | ||
| 198 | *tp++ = '\0'; | ||
| 199 | |||
| 200 | /* | ||
| 201 | * Check for overflow, copy, and we're done. | ||
| 202 | */ | ||
| 203 | if ((size_t)(tp - tmp) > size) { | ||
| 204 | errno = ENOSPC; | ||
| 205 | return (NULL); | ||
| 206 | } | ||
| 207 | strcpy(dst, tmp); | ||
| 208 | return (dst); | ||
| 209 | } | ||
| 210 | |||
| 211 | #endif /* !HAVE_INET_NTOP */ | ||
diff --git a/other/ssharp/openbsd-compat/inet_ntop.h b/other/ssharp/openbsd-compat/inet_ntop.h new file mode 100644 index 0000000..62f2ecd --- /dev/null +++ b/other/ssharp/openbsd-compat/inet_ntop.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | /* $Id: inet_ntop.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_RRESVPORT_H | ||
| 4 | #define _BSD_RRESVPORT_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_INET_NTOP | ||
| 9 | const char * | ||
| 10 | inet_ntop(int af, const void *src, char *dst, size_t size); | ||
| 11 | #endif /* !HAVE_INET_NTOP */ | ||
| 12 | |||
| 13 | #endif /* _BSD_RRESVPORT_H */ | ||
diff --git a/other/ssharp/openbsd-compat/mktemp.c b/other/ssharp/openbsd-compat/mktemp.c new file mode 100644 index 0000000..9ed1bc8 --- /dev/null +++ b/other/ssharp/openbsd-compat/mktemp.c | |||
| @@ -0,0 +1,183 @@ | |||
| 1 | /* THIS FILE HAS BEEN MODIFIED FROM THE ORIGINAL OPENBSD SOURCE */ | ||
| 2 | /* Changes: Removed mktemp */ | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Copyright (c) 1987, 1993 | ||
| 6 | * The Regents of the University of California. 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. All advertising materials mentioning features or use of this software | ||
| 17 | * must display the following acknowledgement: | ||
| 18 | * This product includes software developed by the University of | ||
| 19 | * California, Berkeley and its contributors. | ||
| 20 | * 4. Neither the name of the University nor the names of its contributors | ||
| 21 | * may be used to endorse or promote products derived from this software | ||
| 22 | * without specific prior written permission. | ||
| 23 | * | ||
| 24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 34 | * SUCH DAMAGE. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include "includes.h" | ||
| 38 | |||
| 39 | #ifndef HAVE_MKDTEMP | ||
| 40 | |||
| 41 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 42 | static char rcsid[] = "$OpenBSD: mktemp.c,v 1.13 1998/06/30 23:03:13 deraadt Exp $"; | ||
| 43 | #endif /* LIBC_SCCS and not lint */ | ||
| 44 | |||
| 45 | #ifdef HAVE_CYGWIN | ||
| 46 | #define open binary_open | ||
| 47 | extern int binary_open(); | ||
| 48 | #endif | ||
| 49 | |||
| 50 | static int _gettemp(char *, int *, int, int); | ||
| 51 | |||
| 52 | int | ||
| 53 | mkstemps(path, slen) | ||
| 54 | char *path; | ||
| 55 | int slen; | ||
| 56 | { | ||
| 57 | int fd; | ||
| 58 | |||
| 59 | return (_gettemp(path, &fd, 0, slen) ? fd : -1); | ||
| 60 | } | ||
| 61 | |||
| 62 | int | ||
| 63 | mkstemp(path) | ||
| 64 | char *path; | ||
| 65 | { | ||
| 66 | int fd; | ||
| 67 | |||
| 68 | return (_gettemp(path, &fd, 0, 0) ? fd : -1); | ||
| 69 | } | ||
| 70 | |||
| 71 | char * | ||
| 72 | mkdtemp(path) | ||
| 73 | char *path; | ||
| 74 | { | ||
| 75 | return(_gettemp(path, (int *)NULL, 1, 0) ? path : (char *)NULL); | ||
| 76 | } | ||
| 77 | |||
| 78 | static int | ||
| 79 | _gettemp(path, doopen, domkdir, slen) | ||
| 80 | char *path; | ||
| 81 | register int *doopen; | ||
| 82 | int domkdir; | ||
| 83 | int slen; | ||
| 84 | { | ||
| 85 | register char *start, *trv, *suffp; | ||
| 86 | struct stat sbuf; | ||
| 87 | int pid, rval; | ||
| 88 | |||
| 89 | if (doopen && domkdir) { | ||
| 90 | errno = EINVAL; | ||
| 91 | return(0); | ||
| 92 | } | ||
| 93 | |||
| 94 | for (trv = path; *trv; ++trv) | ||
| 95 | ; | ||
| 96 | trv -= slen; | ||
| 97 | suffp = trv; | ||
| 98 | --trv; | ||
| 99 | if (trv < path) { | ||
| 100 | errno = EINVAL; | ||
| 101 | return (0); | ||
| 102 | } | ||
| 103 | pid = getpid(); | ||
| 104 | while (*trv == 'X' && pid != 0) { | ||
| 105 | *trv-- = (pid % 10) + '0'; | ||
| 106 | pid /= 10; | ||
| 107 | } | ||
| 108 | while (*trv == 'X') { | ||
| 109 | char c; | ||
| 110 | |||
| 111 | pid = (arc4random() & 0xffff) % (26+26); | ||
| 112 | if (pid < 26) | ||
| 113 | c = pid + 'A'; | ||
| 114 | else | ||
| 115 | c = (pid - 26) + 'a'; | ||
| 116 | *trv-- = c; | ||
| 117 | } | ||
| 118 | start = trv + 1; | ||
| 119 | |||
| 120 | /* | ||
| 121 | * check the target directory; if you have six X's and it | ||
| 122 | * doesn't exist this runs for a *very* long time. | ||
| 123 | */ | ||
| 124 | if (doopen || domkdir) { | ||
| 125 | for (;; --trv) { | ||
| 126 | if (trv <= path) | ||
| 127 | break; | ||
| 128 | if (*trv == '/') { | ||
| 129 | *trv = '\0'; | ||
| 130 | rval = stat(path, &sbuf); | ||
| 131 | *trv = '/'; | ||
| 132 | if (rval != 0) | ||
| 133 | return(0); | ||
| 134 | if (!S_ISDIR(sbuf.st_mode)) { | ||
| 135 | errno = ENOTDIR; | ||
| 136 | return(0); | ||
| 137 | } | ||
| 138 | break; | ||
| 139 | } | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | for (;;) { | ||
| 144 | if (doopen) { | ||
| 145 | if ((*doopen = | ||
| 146 | open(path, O_CREAT|O_EXCL|O_RDWR, 0600)) >= 0) | ||
| 147 | return(1); | ||
| 148 | if (errno != EEXIST) | ||
| 149 | return(0); | ||
| 150 | } else if (domkdir) { | ||
| 151 | if (mkdir(path, 0700) == 0) | ||
| 152 | return(1); | ||
| 153 | if (errno != EEXIST) | ||
| 154 | return(0); | ||
| 155 | } else if (lstat(path, &sbuf)) | ||
| 156 | return(errno == ENOENT ? 1 : 0); | ||
| 157 | |||
| 158 | /* tricky little algorithm for backward compatibility */ | ||
| 159 | for (trv = start;;) { | ||
| 160 | if (!*trv) | ||
| 161 | return (0); | ||
| 162 | if (*trv == 'Z') { | ||
| 163 | if (trv == suffp) | ||
| 164 | return (0); | ||
| 165 | *trv++ = 'a'; | ||
| 166 | } else { | ||
| 167 | if (isdigit(*trv)) | ||
| 168 | *trv = 'a'; | ||
| 169 | else if (*trv == 'z') /* inc from z to A */ | ||
| 170 | *trv = 'A'; | ||
| 171 | else { | ||
| 172 | if (trv == suffp) | ||
| 173 | return (0); | ||
| 174 | ++*trv; | ||
| 175 | } | ||
| 176 | break; | ||
| 177 | } | ||
| 178 | } | ||
| 179 | } | ||
| 180 | /*NOTREACHED*/ | ||
| 181 | } | ||
| 182 | |||
| 183 | #endif /* !HAVE_MKDTEMP */ | ||
diff --git a/other/ssharp/openbsd-compat/mktemp.h b/other/ssharp/openbsd-compat/mktemp.h new file mode 100644 index 0000000..776692d --- /dev/null +++ b/other/ssharp/openbsd-compat/mktemp.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | /* $Id: mktemp.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_MKTEMP_H | ||
| 4 | #define _BSD_MKTEMP_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | #ifndef HAVE_MKDTEMP | ||
| 8 | int mkstemps(char *path, int slen); | ||
| 9 | int mkstemp(char *path); | ||
| 10 | char *mkdtemp(char *path); | ||
| 11 | #endif /* !HAVE_MKDTEMP */ | ||
| 12 | |||
| 13 | #endif /* _BSD_MKTEMP_H */ | ||
diff --git a/other/ssharp/openbsd-compat/openbsd-compat.h b/other/ssharp/openbsd-compat/openbsd-compat.h new file mode 100644 index 0000000..0105fa7 --- /dev/null +++ b/other/ssharp/openbsd-compat/openbsd-compat.h | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | /* $Id: openbsd-compat.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _OPENBSD_H | ||
| 4 | #define _OPENBSD_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | /* OpenBSD function replacements */ | ||
| 9 | #include "bindresvport.h" | ||
| 10 | #include "getcwd.h" | ||
| 11 | #include "realpath.h" | ||
| 12 | #include "rresvport.h" | ||
| 13 | #include "strlcpy.h" | ||
| 14 | #include "strlcat.h" | ||
| 15 | #include "strmode.h" | ||
| 16 | #include "mktemp.h" | ||
| 17 | #include "daemon.h" | ||
| 18 | #include "base64.h" | ||
| 19 | #include "sigact.h" | ||
| 20 | #include "inet_aton.h" | ||
| 21 | #include "inet_ntoa.h" | ||
| 22 | #include "inet_ntop.h" | ||
| 23 | #include "strsep.h" | ||
| 24 | #include "strtok.h" | ||
| 25 | #include "vis.h" | ||
| 26 | #include "setproctitle.h" | ||
| 27 | #include "getgrouplist.h" | ||
| 28 | #include "glob.h" | ||
| 29 | #include "getusershell.h" | ||
| 30 | |||
| 31 | /* Home grown routines */ | ||
| 32 | #include "bsd-arc4random.h" | ||
| 33 | #include "bsd-misc.h" | ||
| 34 | #include "bsd-snprintf.h" | ||
| 35 | #include "bsd-waitpid.h" | ||
| 36 | |||
| 37 | /* rfc2553 socket API replacements */ | ||
| 38 | #include "fake-getaddrinfo.h" | ||
| 39 | #include "fake-getnameinfo.h" | ||
| 40 | #include "fake-socket.h" | ||
| 41 | |||
| 42 | #endif /* _OPENBSD_H */ | ||
diff --git a/other/ssharp/openbsd-compat/realpath.c b/other/ssharp/openbsd-compat/realpath.c new file mode 100644 index 0000000..fbe2a9c --- /dev/null +++ b/other/ssharp/openbsd-compat/realpath.c | |||
| @@ -0,0 +1,163 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1994 | ||
| 3 | * The Regents of the University of California. All rights reserved. | ||
| 4 | * | ||
| 5 | * This code is derived from software contributed to Berkeley by | ||
| 6 | * Jan-Simon Pendry. | ||
| 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 REGENTS 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 REGENTS 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 | #include "includes.h" | ||
| 31 | |||
| 32 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) | ||
| 33 | |||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 35 | static char *rcsid = "$OpenBSD: realpath..c,v 1.4 1998/05/18 09:55:19 deraadt Exp $"; | ||
| 36 | #endif /* LIBC_SCCS and not lint */ | ||
| 37 | |||
| 38 | #include <sys/param.h> | ||
| 39 | #include <sys/stat.h> | ||
| 40 | |||
| 41 | #include <errno.h> | ||
| 42 | #include <fcntl.h> | ||
| 43 | #include <stdlib.h> | ||
| 44 | #include <string.h> | ||
| 45 | #include <unistd.h> | ||
| 46 | |||
| 47 | /* | ||
| 48 | * MAXSYMLINKS | ||
| 49 | */ | ||
| 50 | #ifndef MAXSYMLINKS | ||
| 51 | #define MAXSYMLINKS 5 | ||
| 52 | #endif | ||
| 53 | |||
| 54 | /* | ||
| 55 | * char *realpath(const char *path, char resolved_path[MAXPATHLEN]); | ||
| 56 | * | ||
| 57 | * Find the real name of path, by removing all ".", ".." and symlink | ||
| 58 | * components. Returns (resolved) on success, or (NULL) on failure, | ||
| 59 | * in which case the path which caused trouble is left in (resolved). | ||
| 60 | */ | ||
| 61 | char * | ||
| 62 | realpath(const char *path, char *resolved) | ||
| 63 | { | ||
| 64 | struct stat sb; | ||
| 65 | int fd, n, rootd, serrno = 0; | ||
| 66 | char *p, *q, wbuf[MAXPATHLEN], start[MAXPATHLEN]; | ||
| 67 | int symlinks = 0; | ||
| 68 | |||
| 69 | /* Save the starting point. */ | ||
| 70 | getcwd(start,MAXPATHLEN); | ||
| 71 | if ((fd = open(".", O_RDONLY)) < 0) { | ||
| 72 | (void)strcpy(resolved, "."); | ||
| 73 | return (NULL); | ||
| 74 | } | ||
| 75 | close(fd); | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Find the dirname and basename from the path to be resolved. | ||
| 79 | * Change directory to the dirname component. | ||
| 80 | * lstat the basename part. | ||
| 81 | * if it is a symlink, read in the value and loop. | ||
| 82 | * if it is a directory, then change to that directory. | ||
| 83 | * get the current directory name and append the basename. | ||
| 84 | */ | ||
| 85 | (void)strncpy(resolved, path, MAXPATHLEN - 1); | ||
| 86 | resolved[MAXPATHLEN - 1] = '\0'; | ||
| 87 | loop: | ||
| 88 | q = strrchr(resolved, '/'); | ||
| 89 | if (q != NULL) { | ||
| 90 | p = q + 1; | ||
| 91 | if (q == resolved) | ||
| 92 | q = "/"; | ||
| 93 | else { | ||
| 94 | do { | ||
| 95 | --q; | ||
| 96 | } while (q > resolved && *q == '/'); | ||
| 97 | q[1] = '\0'; | ||
| 98 | q = resolved; | ||
| 99 | } | ||
| 100 | if (chdir(q) < 0) | ||
| 101 | goto err1; | ||
| 102 | } else | ||
| 103 | p = resolved; | ||
| 104 | |||
| 105 | /* Deal with the last component. */ | ||
| 106 | if (lstat(p, &sb) == 0) { | ||
| 107 | if (S_ISLNK(sb.st_mode)) { | ||
| 108 | if (++symlinks > MAXSYMLINKS) { | ||
| 109 | serrno = ELOOP; | ||
| 110 | goto err1; | ||
| 111 | } | ||
| 112 | n = readlink(p, resolved, MAXPATHLEN-1); | ||
| 113 | if (n < 0) | ||
| 114 | goto err1; | ||
| 115 | resolved[n] = '\0'; | ||
| 116 | goto loop; | ||
| 117 | } | ||
| 118 | if (S_ISDIR(sb.st_mode)) { | ||
| 119 | if (chdir(p) < 0) | ||
| 120 | goto err1; | ||
| 121 | p = ""; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | |||
| 125 | /* | ||
| 126 | * Save the last component name and get the full pathname of | ||
| 127 | * the current directory. | ||
| 128 | */ | ||
| 129 | (void)strcpy(wbuf, p); | ||
| 130 | if (getcwd(resolved, MAXPATHLEN) == 0) | ||
| 131 | goto err1; | ||
| 132 | |||
| 133 | /* | ||
| 134 | * Join the two strings together, ensuring that the right thing | ||
| 135 | * happens if the last component is empty, or the dirname is root. | ||
| 136 | */ | ||
| 137 | if (resolved[0] == '/' && resolved[1] == '\0') | ||
| 138 | rootd = 1; | ||
| 139 | else | ||
| 140 | rootd = 0; | ||
| 141 | |||
| 142 | if (*wbuf) { | ||
| 143 | if (strlen(resolved) + strlen(wbuf) + rootd + 1 > MAXPATHLEN) { | ||
| 144 | serrno = ENAMETOOLONG; | ||
| 145 | goto err1; | ||
| 146 | } | ||
| 147 | if (rootd == 0) | ||
| 148 | (void)strcat(resolved, "/"); | ||
| 149 | (void)strcat(resolved, wbuf); | ||
| 150 | } | ||
| 151 | |||
| 152 | /* Go back to where we came from. */ | ||
| 153 | if (chdir(start) < 0) { | ||
| 154 | serrno = errno; | ||
| 155 | goto err2; | ||
| 156 | } | ||
| 157 | return (resolved); | ||
| 158 | |||
| 159 | err1: chdir(start); | ||
| 160 | err2: errno = serrno; | ||
| 161 | return (NULL); | ||
| 162 | } | ||
| 163 | #endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */ | ||
diff --git a/other/ssharp/openbsd-compat/realpath.h b/other/ssharp/openbsd-compat/realpath.h new file mode 100644 index 0000000..3617160 --- /dev/null +++ b/other/ssharp/openbsd-compat/realpath.h | |||
| @@ -0,0 +1,13 @@ | |||
| 1 | /* $Id: realpath.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_REALPATH_H | ||
| 4 | #define _BSD_REALPATH_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #if !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) | ||
| 9 | |||
| 10 | char *realpath(const char *path, char *resolved); | ||
| 11 | |||
| 12 | #endif /* !defined(HAVE_REALPATH) || defined(BROKEN_REALPATH) */ | ||
| 13 | #endif /* _BSD_REALPATH_H */ | ||
diff --git a/other/ssharp/openbsd-compat/rresvport.c b/other/ssharp/openbsd-compat/rresvport.c new file mode 100644 index 0000000..636bf36 --- /dev/null +++ b/other/ssharp/openbsd-compat/rresvport.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1995, 1996, 1998 Theo de Raadt. All rights reserved. | ||
| 3 | * Copyright (c) 1983, 1993, 1994 | ||
| 4 | * The Regents of the University of California. All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * 3. All advertising materials mentioning features or use of this software | ||
| 15 | * must display the following acknowledgement: | ||
| 16 | * This product includes software developed by the University of | ||
| 17 | * California, Berkeley and its contributors. | ||
| 18 | * This product includes software developed by Theo de Raadt. | ||
| 19 | * 4. 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 "config.h" | ||
| 37 | |||
| 38 | |||
| 39 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 40 | static char *rcsid = "$OpenBSD: rresvport.c,v 1.5 2000/01/26 03:43:20 deraadt Exp $"; | ||
| 41 | #endif /* LIBC_SCCS and not lint */ | ||
| 42 | |||
| 43 | #include "includes.h" | ||
| 44 | |||
| 45 | |||
| 46 | int | ||
| 47 | my_rresvport_af(int *alport, sa_family_t af) | ||
| 48 | { | ||
| 49 | struct sockaddr_storage ss; | ||
| 50 | struct sockaddr *sa; | ||
| 51 | u_int16_t *portp; | ||
| 52 | int s, one = 1, len = sizeof(int), i = 0; | ||
| 53 | socklen_t salen; | ||
| 54 | |||
| 55 | |||
| 56 | memset(&ss, '\0', sizeof ss); | ||
| 57 | sa = (struct sockaddr *)&ss; | ||
| 58 | |||
| 59 | switch (af) { | ||
| 60 | case AF_INET: | ||
| 61 | salen = sizeof(struct sockaddr_in); | ||
| 62 | portp = &((struct sockaddr_in *)sa)->sin_port; | ||
| 63 | break; | ||
| 64 | case AF_INET6: | ||
| 65 | salen = sizeof(struct sockaddr_in6); | ||
| 66 | portp = &((struct sockaddr_in6 *)sa)->sin6_port; | ||
| 67 | break; | ||
| 68 | default: | ||
| 69 | errno = EPFNOSUPPORT; | ||
| 70 | return (-1); | ||
| 71 | } | ||
| 72 | sa->sa_family = af; | ||
| 73 | |||
| 74 | s = socket(af, SOCK_STREAM, 0); | ||
| 75 | if (s < 0) | ||
| 76 | return (-1); | ||
| 77 | |||
| 78 | //setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, len); | ||
| 79 | for (*portp = htons(*alport);; *portp = htons(*alport+i)) { | ||
| 80 | ++i; | ||
| 81 | if (bind(s, sa, salen) == 0) | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | |||
| 85 | return (s); | ||
| 86 | } | ||
| 87 | |||
diff --git a/other/ssharp/openbsd-compat/rresvport.h b/other/ssharp/openbsd-compat/rresvport.h new file mode 100644 index 0000000..40a19f1 --- /dev/null +++ b/other/ssharp/openbsd-compat/rresvport.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: rresvport.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_RRESVPORT_H | ||
| 4 | #define _BSD_RRESVPORT_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_RRESVPORT_AF | ||
| 9 | int rresvport_af(int *alport, sa_family_t af); | ||
| 10 | #endif /* !HAVE_RRESVPORT_AF */ | ||
| 11 | |||
| 12 | #endif /* _BSD_RRESVPORT_H */ | ||
diff --git a/other/ssharp/openbsd-compat/setenv.c b/other/ssharp/openbsd-compat/setenv.c new file mode 100644 index 0000000..ac9670b --- /dev/null +++ b/other/ssharp/openbsd-compat/setenv.c | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1987 Regents of the University of California. | ||
| 3 | * 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 | |||
| 34 | #include "config.h" | ||
| 35 | #ifndef HAVE_SETENV | ||
| 36 | |||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 38 | static char *rcsid = "$OpenBSD: setenv.c,v 1.3 1998/02/02 22:44:53 millert Exp $"; | ||
| 39 | #endif /* LIBC_SCCS and not lint */ | ||
| 40 | |||
| 41 | #include <stdlib.h> | ||
| 42 | #include <string.h> | ||
| 43 | |||
| 44 | /* | ||
| 45 | * __findenv -- | ||
| 46 | * Returns pointer to value associated with name, if any, else NULL. | ||
| 47 | * Sets offset to be the offset of the name/value combination in the | ||
| 48 | * environmental array, for use by setenv(3) and unsetenv(3). | ||
| 49 | * Explicitly removes '=' in argument name. | ||
| 50 | * | ||
| 51 | * This routine *should* be a static; don't use it. | ||
| 52 | */ | ||
| 53 | char * | ||
| 54 | __findenv(name, offset) | ||
| 55 | register const char *name; | ||
| 56 | int *offset; | ||
| 57 | { | ||
| 58 | extern char **environ; | ||
| 59 | register int len, i; | ||
| 60 | register const char *np; | ||
| 61 | register char **p, *cp; | ||
| 62 | |||
| 63 | if (name == NULL || environ == NULL) | ||
| 64 | return (NULL); | ||
| 65 | for (np = name; *np && *np != '='; ++np) | ||
| 66 | ; | ||
| 67 | len = np - name; | ||
| 68 | for (p = environ; (cp = *p) != NULL; ++p) { | ||
| 69 | for (np = name, i = len; i && *cp; i--) | ||
| 70 | if (*cp++ != *np++) | ||
| 71 | break; | ||
| 72 | if (i == 0 && *cp++ == '=') { | ||
| 73 | *offset = p - environ; | ||
| 74 | return (cp); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | return (NULL); | ||
| 78 | } | ||
| 79 | |||
| 80 | /* | ||
| 81 | * setenv -- | ||
| 82 | * Set the value of the environmental variable "name" to be | ||
| 83 | * "value". If rewrite is set, replace any current value. | ||
| 84 | */ | ||
| 85 | int | ||
| 86 | setenv(name, value, rewrite) | ||
| 87 | register const char *name; | ||
| 88 | register const char *value; | ||
| 89 | int rewrite; | ||
| 90 | { | ||
| 91 | extern char **environ; | ||
| 92 | static int alloced; /* if allocated space before */ | ||
| 93 | register char *C; | ||
| 94 | int l_value, offset; | ||
| 95 | char *__findenv(); | ||
| 96 | |||
| 97 | if (*value == '=') /* no `=' in value */ | ||
| 98 | ++value; | ||
| 99 | l_value = strlen(value); | ||
| 100 | if ((C = __findenv(name, &offset))) { /* find if already exists */ | ||
| 101 | if (!rewrite) | ||
| 102 | return (0); | ||
| 103 | if (strlen(C) >= l_value) { /* old larger; copy over */ | ||
| 104 | while ((*C++ = *value++)); | ||
| 105 | return (0); | ||
| 106 | } | ||
| 107 | } else { /* create new slot */ | ||
| 108 | register int cnt; | ||
| 109 | register char **P; | ||
| 110 | |||
| 111 | for (P = environ, cnt = 0; *P; ++P, ++cnt); | ||
| 112 | if (alloced) { /* just increase size */ | ||
| 113 | P = (char **)realloc((void *)environ, | ||
| 114 | (size_t)(sizeof(char *) * (cnt + 2))); | ||
| 115 | if (!P) | ||
| 116 | return (-1); | ||
| 117 | environ = P; | ||
| 118 | } | ||
| 119 | else { /* get new space */ | ||
| 120 | alloced = 1; /* copy old entries into it */ | ||
| 121 | P = (char **)malloc((size_t)(sizeof(char *) * | ||
| 122 | (cnt + 2))); | ||
| 123 | if (!P) | ||
| 124 | return (-1); | ||
| 125 | memmove(P, environ, cnt * sizeof(char *)); | ||
| 126 | environ = P; | ||
| 127 | } | ||
| 128 | environ[cnt + 1] = NULL; | ||
| 129 | offset = cnt; | ||
| 130 | } | ||
| 131 | for (C = (char *)name; *C && *C != '='; ++C); /* no `=' in name */ | ||
| 132 | if (!(environ[offset] = /* name + `=' + value */ | ||
| 133 | malloc((size_t)((int)(C - name) + l_value + 2)))) | ||
| 134 | return (-1); | ||
| 135 | for (C = environ[offset]; (*C = *name++) && *C != '='; ++C) | ||
| 136 | ; | ||
| 137 | for (*C++ = '='; (*C++ = *value++); ) | ||
| 138 | ; | ||
| 139 | return (0); | ||
| 140 | } | ||
| 141 | |||
| 142 | /* | ||
| 143 | * unsetenv(name) -- | ||
| 144 | * Delete environmental variable "name". | ||
| 145 | */ | ||
| 146 | void | ||
| 147 | unsetenv(name) | ||
| 148 | const char *name; | ||
| 149 | { | ||
| 150 | extern char **environ; | ||
| 151 | register char **P; | ||
| 152 | int offset; | ||
| 153 | char *__findenv(); | ||
| 154 | |||
| 155 | while (__findenv(name, &offset)) /* if set multiple times */ | ||
| 156 | for (P = &environ[offset];; ++P) | ||
| 157 | if (!(*P = *(P + 1))) | ||
| 158 | break; | ||
| 159 | } | ||
| 160 | |||
| 161 | #endif /* HAVE_SETENV */ | ||
diff --git a/other/ssharp/openbsd-compat/setenv.h b/other/ssharp/openbsd-compat/setenv.h new file mode 100644 index 0000000..9670bc9 --- /dev/null +++ b/other/ssharp/openbsd-compat/setenv.h | |||
| @@ -0,0 +1,14 @@ | |||
| 1 | /* $Id: setenv.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_SETENV_H | ||
| 4 | #define _BSD_SETENV_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_SETENV | ||
| 9 | |||
| 10 | int setenv(register const char *name, register const char *value, int rewrite); | ||
| 11 | |||
| 12 | #endif /* !HAVE_SETENV */ | ||
| 13 | |||
| 14 | #endif /* _BSD_SETENV_H */ | ||
diff --git a/other/ssharp/openbsd-compat/setproctitle.c b/other/ssharp/openbsd-compat/setproctitle.c new file mode 100644 index 0000000..38eca9a --- /dev/null +++ b/other/ssharp/openbsd-compat/setproctitle.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* | ||
| 2 | * Modified for OpenSSH by Kevin Steves | ||
| 3 | * October 2000 | ||
| 4 | */ | ||
| 5 | |||
| 6 | /* | ||
| 7 | * Copyright (c) 1994, 1995 Christopher G. Demetriou | ||
| 8 | * All rights reserved. | ||
| 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. All advertising materials mentioning features or use of this software | ||
| 19 | * must display the following acknowledgement: | ||
| 20 | * This product includes software developed by Christopher G. Demetriou | ||
| 21 | * for the NetBSD Project. | ||
| 22 | * 4. The name of the author may not be used to endorse or promote products | ||
| 23 | * derived from this software without specific prior written permission | ||
| 24 | * | ||
| 25 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 26 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 27 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 28 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 29 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 30 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 31 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 32 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 33 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 34 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 38 | static char rcsid[] = "$OpenBSD: setproctitle.c,v 1.7 1999/02/25 22:10:12 art Exp $"; | ||
| 39 | #endif /* LIBC_SCCS and not lint */ | ||
| 40 | |||
| 41 | #include "includes.h" | ||
| 42 | |||
| 43 | #ifndef HAVE_SETPROCTITLE | ||
| 44 | |||
| 45 | #define SPT_NONE 0 | ||
| 46 | #define SPT_PSTAT 1 | ||
| 47 | |||
| 48 | #ifndef SPT_TYPE | ||
| 49 | #define SPT_TYPE SPT_NONE | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #if SPT_TYPE == SPT_PSTAT | ||
| 53 | #include <sys/param.h> | ||
| 54 | #include <sys/pstat.h> | ||
| 55 | #endif /* SPT_TYPE == SPT_PSTAT */ | ||
| 56 | |||
| 57 | #define MAX_PROCTITLE 2048 | ||
| 58 | |||
| 59 | extern char *__progname; | ||
| 60 | |||
| 61 | /* | ||
| 62 | * Set Process Title (SPT) defines. Modeled after sendmail's | ||
| 63 | * SPT type definition strategy. | ||
| 64 | * | ||
| 65 | * SPT_TYPE: | ||
| 66 | * | ||
| 67 | * SPT_NONE: Don't set the process title. Default. | ||
| 68 | * SPT_PSTAT: Use pstat(PSTAT_SETCMD). HP-UX specific. | ||
| 69 | */ | ||
| 70 | |||
| 71 | void | ||
| 72 | setproctitle(const char *fmt, ...) | ||
| 73 | { | ||
| 74 | #if SPT_TYPE != SPT_NONE | ||
| 75 | va_list ap; | ||
| 76 | |||
| 77 | char buf[MAX_PROCTITLE]; | ||
| 78 | size_t used; | ||
| 79 | |||
| 80 | #if SPT_TYPE == SPT_PSTAT | ||
| 81 | union pstun pst; | ||
| 82 | #endif /* SPT_TYPE == SPT_PSTAT */ | ||
| 83 | |||
| 84 | va_start(ap, fmt); | ||
| 85 | if (fmt != NULL) { | ||
| 86 | used = snprintf(buf, MAX_PROCTITLE, "%s: ", __progname); | ||
| 87 | if (used >= MAX_PROCTITLE) | ||
| 88 | used = MAX_PROCTITLE - 1; | ||
| 89 | (void)vsnprintf(buf + used, MAX_PROCTITLE - used, fmt, ap); | ||
| 90 | } else | ||
| 91 | (void)snprintf(buf, MAX_PROCTITLE, "%s", __progname); | ||
| 92 | va_end(ap); | ||
| 93 | used = strlen(buf); | ||
| 94 | |||
| 95 | #if SPT_TYPE == SPT_PSTAT | ||
| 96 | pst.pst_command = buf; | ||
| 97 | pstat(PSTAT_SETCMD, pst, used, 0, 0); | ||
| 98 | #endif /* SPT_TYPE == SPT_PSTAT */ | ||
| 99 | |||
| 100 | #endif /* SPT_TYPE != SPT_NONE */ | ||
| 101 | } | ||
| 102 | #endif /* HAVE_SETPROCTITLE */ | ||
diff --git a/other/ssharp/openbsd-compat/setproctitle.h b/other/ssharp/openbsd-compat/setproctitle.h new file mode 100644 index 0000000..8300997 --- /dev/null +++ b/other/ssharp/openbsd-compat/setproctitle.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: setproctitle.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_SETPROCTITLE_H | ||
| 4 | #define _BSD_SETPROCTITLE_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_SETPROCTITLE | ||
| 9 | void setproctitle(const char *fmt, ...); | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #endif /* _BSD_SETPROCTITLE_H */ | ||
diff --git a/other/ssharp/openbsd-compat/sigact.c b/other/ssharp/openbsd-compat/sigact.c new file mode 100644 index 0000000..390fbd0 --- /dev/null +++ b/other/ssharp/openbsd-compat/sigact.c | |||
| @@ -0,0 +1,102 @@ | |||
| 1 | /* $OpenBSD: sigaction.c,v 1.3 1999/06/27 08:14:21 millert Exp $ */ | ||
| 2 | |||
| 3 | /**************************************************************************** | ||
| 4 | * Copyright (c) 1998 Free Software Foundation, Inc. * | ||
| 5 | * * | ||
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a * | ||
| 7 | * copy of this software and associated documentation files (the * | ||
| 8 | * "Software"), to deal in the Software without restriction, including * | ||
| 9 | * without limitation the rights to use, copy, modify, merge, publish, * | ||
| 10 | * distribute, distribute with modifications, sublicense, and/or sell * | ||
| 11 | * copies of the Software, and to permit persons to whom the Software is * | ||
| 12 | * furnished to do so, subject to the following conditions: * | ||
| 13 | * * | ||
| 14 | * The above copyright notice and this permission notice shall be included * | ||
| 15 | * in all copies or substantial portions of the Software. * | ||
| 16 | * * | ||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * | ||
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * | ||
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * | ||
| 20 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * | ||
| 21 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * | ||
| 22 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * | ||
| 23 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * | ||
| 24 | * * | ||
| 25 | * Except as contained in this notice, the name(s) of the above copyright * | ||
| 26 | * holders shall not be used in advertising or otherwise to promote the * | ||
| 27 | * sale, use or other dealings in this Software without prior written * | ||
| 28 | * authorization. * | ||
| 29 | ****************************************************************************/ | ||
| 30 | |||
| 31 | /**************************************************************************** | ||
| 32 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * | ||
| 33 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * | ||
| 34 | ****************************************************************************/ | ||
| 35 | |||
| 36 | #include <signal.h> | ||
| 37 | #include "config.h" | ||
| 38 | #include "sigact.h" | ||
| 39 | |||
| 40 | /* This file provides sigaction() emulation using sigvec() */ | ||
| 41 | /* Use only if this is non POSIX system */ | ||
| 42 | |||
| 43 | #if !HAVE_SIGACTION && HAVE_SIGVEC | ||
| 44 | |||
| 45 | int | ||
| 46 | sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact) | ||
| 47 | { | ||
| 48 | return sigvec(sig, &(sigact->sv), &(osigact->sv)); | ||
| 49 | } | ||
| 50 | |||
| 51 | int | ||
| 52 | sigemptyset (sigset_t * mask) | ||
| 53 | { | ||
| 54 | *mask = 0; | ||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | |||
| 58 | int | ||
| 59 | sigprocmask (int mode, sigset_t * mask, sigset_t * omask) | ||
| 60 | { | ||
| 61 | sigset_t current = sigsetmask(0); | ||
| 62 | |||
| 63 | if (omask) *omask = current; | ||
| 64 | |||
| 65 | if (mode==SIG_BLOCK) | ||
| 66 | current |= *mask; | ||
| 67 | else if (mode==SIG_UNBLOCK) | ||
| 68 | current &= ~*mask; | ||
| 69 | else if (mode==SIG_SETMASK) | ||
| 70 | current = *mask; | ||
| 71 | |||
| 72 | sigsetmask(current); | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | int | ||
| 77 | sigsuspend (sigset_t * mask) | ||
| 78 | { | ||
| 79 | return sigpause(*mask); | ||
| 80 | } | ||
| 81 | |||
| 82 | int | ||
| 83 | sigdelset (sigset_t * mask, int sig) | ||
| 84 | { | ||
| 85 | *mask &= ~sigmask(sig); | ||
| 86 | return 0; | ||
| 87 | } | ||
| 88 | |||
| 89 | int | ||
| 90 | sigaddset (sigset_t * mask, int sig) | ||
| 91 | { | ||
| 92 | *mask |= sigmask(sig); | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | int | ||
| 97 | sigismember (sigset_t * mask, int sig) | ||
| 98 | { | ||
| 99 | return (*mask & sigmask(sig)) != 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | #endif | ||
diff --git a/other/ssharp/openbsd-compat/sigact.h b/other/ssharp/openbsd-compat/sigact.h new file mode 100644 index 0000000..b37c1f8 --- /dev/null +++ b/other/ssharp/openbsd-compat/sigact.h | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /* $OpenBSD: SigAction.h,v 1.2 1999/06/27 08:15:19 millert Exp $ */ | ||
| 2 | |||
| 3 | /**************************************************************************** | ||
| 4 | * Copyright (c) 1998 Free Software Foundation, Inc. * | ||
| 5 | * * | ||
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a * | ||
| 7 | * copy of this software and associated documentation files (the * | ||
| 8 | * "Software"), to deal in the Software without restriction, including * | ||
| 9 | * without limitation the rights to use, copy, modify, merge, publish, * | ||
| 10 | * distribute, distribute with modifications, sublicense, and/or sell * | ||
| 11 | * copies of the Software, and to permit persons to whom the Software is * | ||
| 12 | * furnished to do so, subject to the following conditions: * | ||
| 13 | * * | ||
| 14 | * The above copyright notice and this permission notice shall be included * | ||
| 15 | * in all copies or substantial portions of the Software. * | ||
| 16 | * * | ||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * | ||
| 18 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * | ||
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * | ||
| 20 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * | ||
| 21 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * | ||
| 22 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * | ||
| 23 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * | ||
| 24 | * * | ||
| 25 | * Except as contained in this notice, the name(s) of the above copyright * | ||
| 26 | * holders shall not be used in advertising or otherwise to promote the * | ||
| 27 | * sale, use or other dealings in this Software without prior written * | ||
| 28 | * authorization. * | ||
| 29 | ****************************************************************************/ | ||
| 30 | |||
| 31 | /**************************************************************************** | ||
| 32 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * | ||
| 33 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * | ||
| 34 | ****************************************************************************/ | ||
| 35 | |||
| 36 | /* | ||
| 37 | * $From: SigAction.h,v 1.5 1999/06/19 23:00:54 tom Exp $ | ||
| 38 | * | ||
| 39 | * This file exists to handle non-POSIX systems which don't have <unistd.h>, | ||
| 40 | * and usually no sigaction() nor <termios.h> | ||
| 41 | */ | ||
| 42 | |||
| 43 | #ifndef _SIGACTION_H | ||
| 44 | #define _SIGACTION_H | ||
| 45 | |||
| 46 | #if !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC) | ||
| 47 | |||
| 48 | #undef SIG_BLOCK | ||
| 49 | #define SIG_BLOCK 00 | ||
| 50 | |||
| 51 | #undef SIG_UNBLOCK | ||
| 52 | #define SIG_UNBLOCK 01 | ||
| 53 | |||
| 54 | #undef SIG_SETMASK | ||
| 55 | #define SIG_SETMASK 02 | ||
| 56 | |||
| 57 | /* | ||
| 58 | * <bsd/signal.h> is in the Linux 1.2.8 + gcc 2.7.0 configuration, | ||
| 59 | * and is useful for testing this header file. | ||
| 60 | */ | ||
| 61 | #if HAVE_BSD_SIGNAL_H | ||
| 62 | # include <bsd/signal.h> | ||
| 63 | #endif | ||
| 64 | |||
| 65 | struct sigaction | ||
| 66 | { | ||
| 67 | struct sigvec sv; | ||
| 68 | }; | ||
| 69 | |||
| 70 | typedef unsigned long sigset_t; | ||
| 71 | |||
| 72 | #undef sa_mask | ||
| 73 | #define sa_mask sv.sv_mask | ||
| 74 | #undef sa_handler | ||
| 75 | #define sa_handler sv.sv_handler | ||
| 76 | #undef sa_flags | ||
| 77 | #define sa_flags sv.sv_flags | ||
| 78 | |||
| 79 | int sigaction(int sig, struct sigaction *sigact, struct sigaction *osigact); | ||
| 80 | int sigprocmask (int how, sigset_t *mask, sigset_t *omask); | ||
| 81 | int sigemptyset (sigset_t *mask); | ||
| 82 | int sigsuspend (sigset_t *mask); | ||
| 83 | int sigdelset (sigset_t *mask, int sig); | ||
| 84 | int sigaddset (sigset_t *mask, int sig); | ||
| 85 | |||
| 86 | #endif /* !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC) */ | ||
| 87 | |||
| 88 | #endif /* !defined(_SIGACTION_H) */ | ||
diff --git a/other/ssharp/openbsd-compat/strlcat.c b/other/ssharp/openbsd-compat/strlcat.c new file mode 100644 index 0000000..7631d96 --- /dev/null +++ b/other/ssharp/openbsd-compat/strlcat.c | |||
| @@ -0,0 +1,77 @@ | |||
| 1 | /* $OpenBSD: strlcat.c,v 1.5 2001/01/13 16:17:24 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 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. The name of the author may not be used to endorse or promote products | ||
| 16 | * derived from this software without specific prior written permission. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include "config.h" | ||
| 31 | #ifndef HAVE_STRLCAT | ||
| 32 | |||
| 33 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 34 | static char *rcsid = "$OpenBSD: strlcat.c,v 1.5 2001/01/13 16:17:24 millert Exp $"; | ||
| 35 | #endif /* LIBC_SCCS and not lint */ | ||
| 36 | |||
| 37 | #include <sys/types.h> | ||
| 38 | #include <string.h> | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Appends src to string dst of size siz (unlike strncat, siz is the | ||
| 42 | * full size of dst, not space left). At most siz-1 characters | ||
| 43 | * will be copied. Always NUL terminates (unless siz <= strlen(dst)). | ||
| 44 | * Returns strlen(initial dst) + strlen(src); if retval >= siz, | ||
| 45 | * truncation occurred. | ||
| 46 | */ | ||
| 47 | size_t strlcat(dst, src, siz) | ||
| 48 | char *dst; | ||
| 49 | const char *src; | ||
| 50 | size_t siz; | ||
| 51 | { | ||
| 52 | register char *d = dst; | ||
| 53 | register const char *s = src; | ||
| 54 | register size_t n = siz; | ||
| 55 | size_t dlen; | ||
| 56 | |||
| 57 | /* Find the end of dst and adjust bytes left but don't go past end */ | ||
| 58 | while (n-- != 0 && *d != '\0') | ||
| 59 | d++; | ||
| 60 | dlen = d - dst; | ||
| 61 | n = siz - dlen; | ||
| 62 | |||
| 63 | if (n == 0) | ||
| 64 | return(dlen + strlen(s)); | ||
| 65 | while (*s != '\0') { | ||
| 66 | if (n != 1) { | ||
| 67 | *d++ = *s; | ||
| 68 | n--; | ||
| 69 | } | ||
| 70 | s++; | ||
| 71 | } | ||
| 72 | *d = '\0'; | ||
| 73 | |||
| 74 | return(dlen + (s - src)); /* count does not include NUL */ | ||
| 75 | } | ||
| 76 | |||
| 77 | #endif /* !HAVE_STRLCAT */ | ||
diff --git a/other/ssharp/openbsd-compat/strlcat.h b/other/ssharp/openbsd-compat/strlcat.h new file mode 100644 index 0000000..a903618 --- /dev/null +++ b/other/ssharp/openbsd-compat/strlcat.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: strlcat.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_STRLCAT_H | ||
| 4 | #define _BSD_STRLCAT_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | #ifndef HAVE_STRLCAT | ||
| 8 | #include <sys/types.h> | ||
| 9 | size_t strlcat(char *dst, const char *src, size_t siz); | ||
| 10 | #endif /* !HAVE_STRLCAT */ | ||
| 11 | |||
| 12 | #endif /* _BSD_STRLCAT_H */ | ||
diff --git a/other/ssharp/openbsd-compat/strlcpy.c b/other/ssharp/openbsd-compat/strlcpy.c new file mode 100644 index 0000000..276c25c --- /dev/null +++ b/other/ssharp/openbsd-compat/strlcpy.c | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | /* $OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> | ||
| 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. The name of the author may not be used to endorse or promote products | ||
| 16 | * derived from this software without specific prior written permission. | ||
| 17 | * | ||
| 18 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, | ||
| 19 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY | ||
| 20 | * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL | ||
| 21 | * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | ||
| 24 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | ||
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | ||
| 26 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
| 27 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | */ | ||
| 29 | |||
| 30 | #include "config.h" | ||
| 31 | #ifndef HAVE_STRLCPY | ||
| 32 | |||
| 33 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 34 | static char *rcsid = "$OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp $"; | ||
| 35 | #endif /* LIBC_SCCS and not lint */ | ||
| 36 | |||
| 37 | #include <sys/types.h> | ||
| 38 | #include <string.h> | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Copy src to string dst of size siz. At most siz-1 characters | ||
| 42 | * will be copied. Always NUL terminates (unless siz == 0). | ||
| 43 | * Returns strlen(src); if retval >= siz, truncation occurred. | ||
| 44 | */ | ||
| 45 | size_t strlcpy(dst, src, siz) | ||
| 46 | char *dst; | ||
| 47 | const char *src; | ||
| 48 | size_t siz; | ||
| 49 | { | ||
| 50 | register char *d = dst; | ||
| 51 | register const char *s = src; | ||
| 52 | register size_t n = siz; | ||
| 53 | |||
| 54 | /* Copy as many bytes as will fit */ | ||
| 55 | if (n != 0 && --n != 0) { | ||
| 56 | do { | ||
| 57 | if ((*d++ = *s++) == 0) | ||
| 58 | break; | ||
| 59 | } while (--n != 0); | ||
| 60 | } | ||
| 61 | |||
| 62 | /* Not enough room in dst, add NUL and traverse rest of src */ | ||
| 63 | if (n == 0) { | ||
| 64 | if (siz != 0) | ||
| 65 | *d = '\0'; /* NUL-terminate dst */ | ||
| 66 | while (*s++) | ||
| 67 | ; | ||
| 68 | } | ||
| 69 | |||
| 70 | return(s - src - 1); /* count does not include NUL */ | ||
| 71 | } | ||
| 72 | |||
| 73 | #endif /* !HAVE_STRLCPY */ | ||
diff --git a/other/ssharp/openbsd-compat/strlcpy.h b/other/ssharp/openbsd-compat/strlcpy.h new file mode 100644 index 0000000..9c7c21b --- /dev/null +++ b/other/ssharp/openbsd-compat/strlcpy.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: strlcpy.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_STRLCPY_H | ||
| 4 | #define _BSD_STRLCPY_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | #ifndef HAVE_STRLCPY | ||
| 8 | #include <sys/types.h> | ||
| 9 | size_t strlcpy(char *dst, const char *src, size_t siz); | ||
| 10 | #endif /* !HAVE_STRLCPY */ | ||
| 11 | |||
| 12 | #endif /* _BSD_STRLCPY_H */ | ||
diff --git a/other/ssharp/openbsd-compat/strmode.c b/other/ssharp/openbsd-compat/strmode.c new file mode 100644 index 0000000..67e0e4d --- /dev/null +++ b/other/ssharp/openbsd-compat/strmode.c | |||
| @@ -0,0 +1,158 @@ | |||
| 1 | /*- | ||
| 2 | * Copyright (c) 1990 The Regents of the University of California. | ||
| 3 | * 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 | |||
| 34 | #include "includes.h" | ||
| 35 | #ifndef HAVE_STRMODE | ||
| 36 | |||
| 37 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 38 | static char *rcsid = "$OpenBSD: strmode.c,v 1.3 1997/06/13 13:57:20 deraadt Exp $"; | ||
| 39 | #endif /* LIBC_SCCS and not lint */ | ||
| 40 | |||
| 41 | #include <sys/types.h> | ||
| 42 | #include <sys/stat.h> | ||
| 43 | #include <string.h> | ||
| 44 | |||
| 45 | void | ||
| 46 | strmode(mode, p) | ||
| 47 | register mode_t mode; | ||
| 48 | register char *p; | ||
| 49 | { | ||
| 50 | /* print type */ | ||
| 51 | switch (mode & S_IFMT) { | ||
| 52 | case S_IFDIR: /* directory */ | ||
| 53 | *p++ = 'd'; | ||
| 54 | break; | ||
| 55 | case S_IFCHR: /* character special */ | ||
| 56 | *p++ = 'c'; | ||
| 57 | break; | ||
| 58 | case S_IFBLK: /* block special */ | ||
| 59 | *p++ = 'b'; | ||
| 60 | break; | ||
| 61 | case S_IFREG: /* regular */ | ||
| 62 | *p++ = '-'; | ||
| 63 | break; | ||
| 64 | case S_IFLNK: /* symbolic link */ | ||
| 65 | *p++ = 'l'; | ||
| 66 | break; | ||
| 67 | #ifdef S_IFSOCK | ||
| 68 | case S_IFSOCK: /* socket */ | ||
| 69 | *p++ = 's'; | ||
| 70 | break; | ||
| 71 | #endif | ||
| 72 | #ifdef S_IFIFO | ||
| 73 | case S_IFIFO: /* fifo */ | ||
| 74 | *p++ = 'p'; | ||
| 75 | break; | ||
| 76 | #endif | ||
| 77 | #ifdef S_IFWHT | ||
| 78 | case S_IFWHT: /* whiteout */ | ||
| 79 | *p++ = 'w'; | ||
| 80 | break; | ||
| 81 | #endif | ||
| 82 | default: /* unknown */ | ||
| 83 | *p++ = '?'; | ||
| 84 | break; | ||
| 85 | } | ||
| 86 | /* usr */ | ||
| 87 | if (mode & S_IRUSR) | ||
| 88 | *p++ = 'r'; | ||
| 89 | else | ||
| 90 | *p++ = '-'; | ||
| 91 | if (mode & S_IWUSR) | ||
| 92 | *p++ = 'w'; | ||
| 93 | else | ||
| 94 | *p++ = '-'; | ||
| 95 | switch (mode & (S_IXUSR | S_ISUID)) { | ||
| 96 | case 0: | ||
| 97 | *p++ = '-'; | ||
| 98 | break; | ||
| 99 | case S_IXUSR: | ||
| 100 | *p++ = 'x'; | ||
| 101 | break; | ||
| 102 | case S_ISUID: | ||
| 103 | *p++ = 'S'; | ||
| 104 | break; | ||
| 105 | case S_IXUSR | S_ISUID: | ||
| 106 | *p++ = 's'; | ||
| 107 | break; | ||
| 108 | } | ||
| 109 | /* group */ | ||
| 110 | if (mode & S_IRGRP) | ||
| 111 | *p++ = 'r'; | ||
| 112 | else | ||
| 113 | *p++ = '-'; | ||
| 114 | if (mode & S_IWGRP) | ||
| 115 | *p++ = 'w'; | ||
| 116 | else | ||
| 117 | *p++ = '-'; | ||
| 118 | switch (mode & (S_IXGRP | S_ISGID)) { | ||
| 119 | case 0: | ||
| 120 | *p++ = '-'; | ||
| 121 | break; | ||
| 122 | case S_IXGRP: | ||
| 123 | *p++ = 'x'; | ||
| 124 | break; | ||
| 125 | case S_ISGID: | ||
| 126 | *p++ = 'S'; | ||
| 127 | break; | ||
| 128 | case S_IXGRP | S_ISGID: | ||
| 129 | *p++ = 's'; | ||
| 130 | break; | ||
| 131 | } | ||
| 132 | /* other */ | ||
| 133 | if (mode & S_IROTH) | ||
| 134 | *p++ = 'r'; | ||
| 135 | else | ||
| 136 | *p++ = '-'; | ||
| 137 | if (mode & S_IWOTH) | ||
| 138 | *p++ = 'w'; | ||
| 139 | else | ||
| 140 | *p++ = '-'; | ||
| 141 | switch (mode & (S_IXOTH | S_ISVTX)) { | ||
| 142 | case 0: | ||
| 143 | *p++ = '-'; | ||
| 144 | break; | ||
| 145 | case S_IXOTH: | ||
| 146 | *p++ = 'x'; | ||
| 147 | break; | ||
| 148 | case S_ISVTX: | ||
| 149 | *p++ = 'T'; | ||
| 150 | break; | ||
| 151 | case S_IXOTH | S_ISVTX: | ||
| 152 | *p++ = 't'; | ||
| 153 | break; | ||
| 154 | } | ||
| 155 | *p++ = ' '; /* will be a '+' if ACL's implemented */ | ||
| 156 | *p = '\0'; | ||
| 157 | } | ||
| 158 | #endif | ||
diff --git a/other/ssharp/openbsd-compat/strmode.h b/other/ssharp/openbsd-compat/strmode.h new file mode 100644 index 0000000..c1f5623 --- /dev/null +++ b/other/ssharp/openbsd-compat/strmode.h | |||
| @@ -0,0 +1,7 @@ | |||
| 1 | /* $Id: strmode.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef HAVE_STRMODE | ||
| 4 | |||
| 5 | void strmode( register mode_t mode, register char *p); | ||
| 6 | |||
| 7 | #endif | ||
diff --git a/other/ssharp/openbsd-compat/strsep.c b/other/ssharp/openbsd-compat/strsep.c new file mode 100644 index 0000000..c03649c --- /dev/null +++ b/other/ssharp/openbsd-compat/strsep.c | |||
| @@ -0,0 +1,89 @@ | |||
| 1 | /* $OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert 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. All advertising materials mentioning features or use of this software | ||
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed by the University of | ||
| 18 | * California, Berkeley and its contributors. | ||
| 19 | * 4. 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 "config.h" | ||
| 37 | |||
| 38 | #if !defined(HAVE_STRSEP) | ||
| 39 | |||
| 40 | #include <string.h> | ||
| 41 | #include <stdio.h> | ||
| 42 | |||
| 43 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 44 | #if 0 | ||
| 45 | static char sccsid[] = "@(#)strsep.c 8.1 (Berkeley) 6/4/93"; | ||
| 46 | #else | ||
| 47 | static char *rcsid = "$OpenBSD: strsep.c,v 1.3 1997/08/20 04:28:14 millert Exp $"; | ||
| 48 | #endif | ||
| 49 | #endif /* LIBC_SCCS and not lint */ | ||
| 50 | |||
| 51 | /* | ||
| 52 | * Get next token from string *stringp, where tokens are possibly-empty | ||
| 53 | * strings separated by characters from delim. | ||
| 54 | * | ||
| 55 | * Writes NULs into the string at *stringp to end tokens. | ||
| 56 | * delim need not remain constant from call to call. | ||
| 57 | * On return, *stringp points past the last NUL written (if there might | ||
| 58 | * be further tokens), or is NULL (if there are definitely no more tokens). | ||
| 59 | * | ||
| 60 | * If *stringp is NULL, strsep returns NULL. | ||
| 61 | */ | ||
| 62 | char * | ||
| 63 | strsep(char **stringp, const char *delim) | ||
| 64 | { | ||
| 65 | register char *s; | ||
| 66 | register const char *spanp; | ||
| 67 | register int c, sc; | ||
| 68 | char *tok; | ||
| 69 | |||
| 70 | if ((s = *stringp) == NULL) | ||
| 71 | return (NULL); | ||
| 72 | for (tok = s;;) { | ||
| 73 | c = *s++; | ||
| 74 | spanp = delim; | ||
| 75 | do { | ||
| 76 | if ((sc = *spanp++) == c) { | ||
| 77 | if (c == 0) | ||
| 78 | s = NULL; | ||
| 79 | else | ||
| 80 | s[-1] = 0; | ||
| 81 | *stringp = s; | ||
| 82 | return (tok); | ||
| 83 | } | ||
| 84 | } while (sc != 0); | ||
| 85 | } | ||
| 86 | /* NOTREACHED */ | ||
| 87 | } | ||
| 88 | |||
| 89 | #endif /* !defined(HAVE_STRSEP) */ | ||
diff --git a/other/ssharp/openbsd-compat/strsep.h b/other/ssharp/openbsd-compat/strsep.h new file mode 100644 index 0000000..b57ec7b --- /dev/null +++ b/other/ssharp/openbsd-compat/strsep.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: strsep.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_STRSEP_H | ||
| 4 | #define _BSD_STRSEP_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_STRSEP | ||
| 9 | char *strsep(char **stringp, const char *delim); | ||
| 10 | #endif /* HAVE_STRSEP */ | ||
| 11 | |||
| 12 | #endif /* _BSD_STRSEP_H */ | ||
diff --git a/other/ssharp/openbsd-compat/strtok.c b/other/ssharp/openbsd-compat/strtok.c new file mode 100644 index 0000000..6ce6f9a --- /dev/null +++ b/other/ssharp/openbsd-compat/strtok.c | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1988 Regents of the University of California. | ||
| 3 | * 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 | |||
| 34 | #include "config.h" | ||
| 35 | |||
| 36 | #ifndef HAVE_STRTOK_R | ||
| 37 | |||
| 38 | #include "strtok.h" | ||
| 39 | |||
| 40 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 41 | static char *rcsid = "$OpenBSD: strtok.c,v 1.3 1999/11/09 11:19:46 art Exp $"; | ||
| 42 | #endif /* LIBC_SCCS and not lint */ | ||
| 43 | |||
| 44 | #include <string.h> | ||
| 45 | |||
| 46 | char *strtok_r(char *s, const char *delim, char **last) | ||
| 47 | { | ||
| 48 | register char *spanp; | ||
| 49 | register int c, sc; | ||
| 50 | char *tok; | ||
| 51 | |||
| 52 | if (s == NULL && (s = *last) == NULL) | ||
| 53 | return (NULL); | ||
| 54 | |||
| 55 | /* | ||
| 56 | * Skip (span) leading delimiters (s += strspn(s, delim), sort of). | ||
| 57 | */ | ||
| 58 | cont: | ||
| 59 | c = *s++; | ||
| 60 | for (spanp = (char *)delim; (sc = *spanp++) != 0;) { | ||
| 61 | if (c == sc) | ||
| 62 | goto cont; | ||
| 63 | } | ||
| 64 | |||
| 65 | if (c == 0) { /* no non-delimiter characters */ | ||
| 66 | *last = NULL; | ||
| 67 | return (NULL); | ||
| 68 | } | ||
| 69 | tok = s - 1; | ||
| 70 | |||
| 71 | /* | ||
| 72 | * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). | ||
| 73 | * Note that delim must have one NUL; we stop if we see that, too. | ||
| 74 | */ | ||
| 75 | for (;;) { | ||
| 76 | c = *s++; | ||
| 77 | spanp = (char *)delim; | ||
| 78 | do { | ||
| 79 | if ((sc = *spanp++) == c) { | ||
| 80 | if (c == 0) | ||
| 81 | s = NULL; | ||
| 82 | else | ||
| 83 | s[-1] = 0; | ||
| 84 | *last = s; | ||
| 85 | return (tok); | ||
| 86 | } | ||
| 87 | } while (sc != 0); | ||
| 88 | } | ||
| 89 | /* NOTREACHED */ | ||
| 90 | } | ||
| 91 | |||
| 92 | #endif /* !HAVE_STRTOK_R */ | ||
diff --git a/other/ssharp/openbsd-compat/strtok.h b/other/ssharp/openbsd-compat/strtok.h new file mode 100644 index 0000000..57d8b21 --- /dev/null +++ b/other/ssharp/openbsd-compat/strtok.h | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | /* $Id: strtok.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_STRTOK_H | ||
| 4 | #define _BSD_STRTOK_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_STRTOK_R | ||
| 9 | char *strtok_r(char *s, const char *delim, char **last); | ||
| 10 | #endif /* HAVE_STRTOK_R */ | ||
| 11 | |||
| 12 | #endif /* _BSD_STRTOK_H */ | ||
diff --git a/other/ssharp/openbsd-compat/vis.c b/other/ssharp/openbsd-compat/vis.c new file mode 100644 index 0000000..7eb2d6c --- /dev/null +++ b/other/ssharp/openbsd-compat/vis.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /*- | ||
| 2 | * Copyright (c) 1989, 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 | |||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 35 | static char rcsid[] = "$OpenBSD: vis.c,v 1.6 2000/11/21 00:47:28 millert Exp $"; | ||
| 36 | #endif /* LIBC_SCCS and not lint */ | ||
| 37 | |||
| 38 | #include "includes.h" | ||
| 39 | |||
| 40 | #ifndef HAVE_VIS | ||
| 41 | |||
| 42 | #define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7') | ||
| 43 | #define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \ | ||
| 44 | isgraph((u_char)(c))) || \ | ||
| 45 | ((flag & VIS_SP) == 0 && (c) == ' ') || \ | ||
| 46 | ((flag & VIS_TAB) == 0 && (c) == '\t') || \ | ||
| 47 | ((flag & VIS_NL) == 0 && (c) == '\n') || \ | ||
| 48 | ((flag & VIS_SAFE) && \ | ||
| 49 | ((c) == '\b' || (c) == '\007' || (c) == '\r'))) | ||
| 50 | |||
| 51 | /* | ||
| 52 | * vis - visually encode characters | ||
| 53 | */ | ||
| 54 | char *vis(char *dst, int c, int flag, int nextc) | ||
| 55 | { | ||
| 56 | if (isvisible(c)) { | ||
| 57 | *dst++ = c; | ||
| 58 | if (c == '\\' && (flag & VIS_NOSLASH) == 0) | ||
| 59 | *dst++ = '\\'; | ||
| 60 | *dst = '\0'; | ||
| 61 | return (dst); | ||
| 62 | } | ||
| 63 | |||
| 64 | if (flag & VIS_CSTYLE) { | ||
| 65 | switch(c) { | ||
| 66 | case '\n': | ||
| 67 | *dst++ = '\\'; | ||
| 68 | *dst++ = 'n'; | ||
| 69 | goto done; | ||
| 70 | case '\r': | ||
| 71 | *dst++ = '\\'; | ||
| 72 | *dst++ = 'r'; | ||
| 73 | goto done; | ||
| 74 | case '\b': | ||
| 75 | *dst++ = '\\'; | ||
| 76 | *dst++ = 'b'; | ||
| 77 | goto done; | ||
| 78 | #ifdef __STDC__ | ||
| 79 | case '\a': | ||
| 80 | #else | ||
| 81 | case '\007': | ||
| 82 | #endif | ||
| 83 | *dst++ = '\\'; | ||
| 84 | *dst++ = 'a'; | ||
| 85 | goto done; | ||
| 86 | case '\v': | ||
| 87 | *dst++ = '\\'; | ||
| 88 | *dst++ = 'v'; | ||
| 89 | goto done; | ||
| 90 | case '\t': | ||
| 91 | *dst++ = '\\'; | ||
| 92 | *dst++ = 't'; | ||
| 93 | goto done; | ||
| 94 | case '\f': | ||
| 95 | *dst++ = '\\'; | ||
| 96 | *dst++ = 'f'; | ||
| 97 | goto done; | ||
| 98 | case ' ': | ||
| 99 | *dst++ = '\\'; | ||
| 100 | *dst++ = 's'; | ||
| 101 | goto done; | ||
| 102 | case '\0': | ||
| 103 | *dst++ = '\\'; | ||
| 104 | *dst++ = '0'; | ||
| 105 | if (isoctal(nextc)) { | ||
| 106 | *dst++ = '0'; | ||
| 107 | *dst++ = '0'; | ||
| 108 | } | ||
| 109 | goto done; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) { | ||
| 113 | *dst++ = '\\'; | ||
| 114 | *dst++ = ((u_char)c >> 6 & 07) + '0'; | ||
| 115 | *dst++ = ((u_char)c >> 3 & 07) + '0'; | ||
| 116 | *dst++ = ((u_char)c & 07) + '0'; | ||
| 117 | goto done; | ||
| 118 | } | ||
| 119 | if ((flag & VIS_NOSLASH) == 0) | ||
| 120 | *dst++ = '\\'; | ||
| 121 | if (c & 0200) { | ||
| 122 | c &= 0177; | ||
| 123 | *dst++ = 'M'; | ||
| 124 | } | ||
| 125 | if (iscntrl(c)) { | ||
| 126 | *dst++ = '^'; | ||
| 127 | if (c == 0177) | ||
| 128 | *dst++ = '?'; | ||
| 129 | else | ||
| 130 | *dst++ = c + '@'; | ||
| 131 | } else { | ||
| 132 | *dst++ = '-'; | ||
| 133 | *dst++ = c; | ||
| 134 | } | ||
| 135 | done: | ||
| 136 | *dst = '\0'; | ||
| 137 | return (dst); | ||
| 138 | } | ||
| 139 | #endif /* HAVE_VIS */ | ||
diff --git a/other/ssharp/openbsd-compat/vis.h b/other/ssharp/openbsd-compat/vis.h new file mode 100644 index 0000000..5d5503f --- /dev/null +++ b/other/ssharp/openbsd-compat/vis.h | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* $Id: vis.h,v 1.1.1.1 2001/09/19 14:44:59 stealth Exp $ */ | ||
| 2 | |||
| 3 | #ifndef _BSD_VIS_H | ||
| 4 | #define _BSD_VIS_H | ||
| 5 | |||
| 6 | #include "config.h" | ||
| 7 | |||
| 8 | #ifndef HAVE_VIS | ||
| 9 | |||
| 10 | /* | ||
| 11 | * to select alternate encoding format | ||
| 12 | */ | ||
| 13 | #define VIS_OCTAL 0x01 /* use octal \ddd format */ | ||
| 14 | #define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */ | ||
| 15 | |||
| 16 | /* | ||
| 17 | * to alter set of characters encoded (default is to encode all | ||
| 18 | * non-graphic except space, tab, and newline). | ||
| 19 | */ | ||
| 20 | #define VIS_SP 0x04 /* also encode space */ | ||
| 21 | #define VIS_TAB 0x08 /* also encode tab */ | ||
| 22 | #define VIS_NL 0x10 /* also encode newline */ | ||
| 23 | #define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL) | ||
| 24 | #define VIS_SAFE 0x20 /* only encode "unsafe" characters */ | ||
| 25 | |||
| 26 | /* | ||
| 27 | * other | ||
| 28 | */ | ||
| 29 | #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ | ||
| 30 | |||
| 31 | char *vis (char *, int, int, int); | ||
| 32 | #endif /* HAVE_VIS */ | ||
| 33 | |||
| 34 | #endif /* _BSD_VIS_H */ | ||
