diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/b-scan/tmp/support | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/b-scan/tmp/support')
| -rw-r--r-- | other/b-scan/tmp/support/Makefile | 20 | ||||
| -rw-r--r-- | other/b-scan/tmp/support/hpuxdl.c | 187 | ||||
| -rw-r--r-- | other/b-scan/tmp/support/snprintf.c | 331 |
3 files changed, 538 insertions, 0 deletions
diff --git a/other/b-scan/tmp/support/Makefile b/other/b-scan/tmp/support/Makefile new file mode 100644 index 0000000..4025e1f --- /dev/null +++ b/other/b-scan/tmp/support/Makefile | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | CC=gcc | ||
| 2 | COPT=-Wall -ggdb -I../include | ||
| 3 | DEFS=#-DDEBUG | ||
| 4 | OBJ=hpuxdl.o snprintf.o | ||
| 5 | |||
| 6 | # HPUX 11.00 | ||
| 7 | # DEFS=-DNEED_SNPRINTF -DHAVE_SHL_LOAD #-DDEBUG | ||
| 8 | |||
| 9 | # HPUX 10.20 | ||
| 10 | # DEFS=-DHP10 -DNEED_SNPRINTF -DHAVE_SHL_LOAD #-DDEBUG | ||
| 11 | |||
| 12 | all: $(OBJ) | ||
| 13 | |||
| 14 | .c.o: | ||
| 15 | $(CC) $(COPT) $(DEFS) -c $< | ||
| 16 | |||
| 17 | clean: | ||
| 18 | rm -f $(OBJ) core *~ | ||
| 19 | |||
| 20 | |||
diff --git a/other/b-scan/tmp/support/hpuxdl.c b/other/b-scan/tmp/support/hpuxdl.c new file mode 100644 index 0000000..accaed9 --- /dev/null +++ b/other/b-scan/tmp/support/hpuxdl.c | |||
| @@ -0,0 +1,187 @@ | |||
| 1 | #ifdef HAVE_SHL_LOAD | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <dl.h> | ||
| 6 | |||
| 7 | /* | ||
| 8 | * This is a minimal implementation of the ELF dlopen, dlclose, dlsym | ||
| 9 | * and dlerror routines based on HP's shl_load, shl_unload and | ||
| 10 | * shl_findsym. */ | ||
| 11 | |||
| 12 | /* | ||
| 13 | * Reference Counting. | ||
| 14 | * | ||
| 15 | * Empirically it looks like the HP routines do not maintain a | ||
| 16 | * reference count, so I maintain one here. | ||
| 17 | */ | ||
| 18 | |||
| 19 | typedef struct lib_entry { | ||
| 20 | shl_t handle; | ||
| 21 | int count; | ||
| 22 | struct lib_entry *next; | ||
| 23 | } *LibEntry; | ||
| 24 | |||
| 25 | #define lib_entry_handle(e) ((e)->handle) | ||
| 26 | #define lib_entry_count(e) ((e)->count) | ||
| 27 | #define lib_entry_next(e) ((e)->next) | ||
| 28 | #define set_lib_entry_handle(e,v) ((e)->handle = (v)) | ||
| 29 | #define set_lib_entry_count(e,v) ((e)->count = (v)) | ||
| 30 | #define set_lib_entry_next(e,v) ((e)->next = (v)) | ||
| 31 | #define increment_lib_entry_count(e) ((e)->count++) | ||
| 32 | #define decrement_lib_entry_count(e) ((e)->count--) | ||
| 33 | |||
| 34 | static LibEntry Entries = NULL; | ||
| 35 | |||
| 36 | static LibEntry find_lib_entry(shl_t handle) | ||
| 37 | { | ||
| 38 | LibEntry entry; | ||
| 39 | |||
| 40 | for (entry = Entries; entry != NULL; entry = lib_entry_next(entry)) | ||
| 41 | if (lib_entry_handle(entry) == handle) | ||
| 42 | return entry; | ||
| 43 | return NULL; | ||
| 44 | } | ||
| 45 | |||
| 46 | static LibEntry new_lib_entry(shl_t handle) | ||
| 47 | { | ||
| 48 | LibEntry entry; | ||
| 49 | |||
| 50 | if ((entry = (LibEntry) malloc(sizeof(struct lib_entry))) != NULL) { | ||
| 51 | set_lib_entry_handle(entry, handle); | ||
| 52 | set_lib_entry_count(entry, 1); | ||
| 53 | set_lib_entry_next(entry, Entries); | ||
| 54 | Entries = entry; | ||
| 55 | } | ||
| 56 | return entry; | ||
| 57 | } | ||
| 58 | |||
| 59 | static void free_lib_entry(LibEntry entry) | ||
| 60 | { | ||
| 61 | if (entry == Entries) | ||
| 62 | Entries = lib_entry_next(entry); | ||
| 63 | else { | ||
| 64 | LibEntry last, next; | ||
| 65 | for (last = Entries, next = lib_entry_next(last); | ||
| 66 | next != NULL; | ||
| 67 | last = next, next = lib_entry_next(last)) { | ||
| 68 | if (entry == next) { | ||
| 69 | set_lib_entry_next(last, lib_entry_next(entry)); | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | } | ||
| 73 | } | ||
| 74 | free(entry); | ||
| 75 | } | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Error Handling. | ||
| 79 | */ | ||
| 80 | |||
| 81 | #define ERRBUFSIZE 1000 | ||
| 82 | |||
| 83 | static char errbuf[ERRBUFSIZE]; | ||
| 84 | static int dlerrno = 0; | ||
| 85 | |||
| 86 | char *dlerror(void) | ||
| 87 | { | ||
| 88 | return dlerrno ? errbuf : NULL; | ||
| 89 | } | ||
| 90 | |||
| 91 | /* | ||
| 92 | * Opening and Closing Liraries. | ||
| 93 | */ | ||
| 94 | |||
| 95 | void *dlopen(const char *fname, int mode) | ||
| 96 | { | ||
| 97 | shl_t handle; | ||
| 98 | LibEntry entry = NULL; | ||
| 99 | |||
| 100 | dlerrno = 0; | ||
| 101 | if (fname == NULL) | ||
| 102 | handle = PROG_HANDLE; | ||
| 103 | else { | ||
| 104 | handle = shl_load(fname, mode, 0L); | ||
| 105 | if (handle != NULL) { | ||
| 106 | if ((entry = find_lib_entry(handle)) == NULL) { | ||
| 107 | if ((entry = new_lib_entry(handle)) == NULL) { | ||
| 108 | shl_unload(handle); | ||
| 109 | handle = NULL; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | else | ||
| 113 | increment_lib_entry_count(entry); | ||
| 114 | } | ||
| 115 | if (handle == NULL) { | ||
| 116 | char *errstr; | ||
| 117 | dlerrno = errno; | ||
| 118 | errstr = strerror(errno); | ||
| 119 | if (errno == NULL) errstr = "???"; | ||
| 120 | sprintf(errbuf, "can't open %s: %s", fname, errstr); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | #ifdef DEBUG | ||
| 124 | printf("opening library %s, handle = %x, count = %d\n", | ||
| 125 | fname, handle, entry ? lib_entry_count(entry) : -1); | ||
| 126 | if (dlerrno) printf("%s\n", dlerror()); | ||
| 127 | #endif | ||
| 128 | return (void *) handle; | ||
| 129 | } | ||
| 130 | |||
| 131 | int dlclose(void *handle) | ||
| 132 | { | ||
| 133 | LibEntry entry; | ||
| 134 | #ifdef DEBUG | ||
| 135 | entry = find_lib_entry(handle); | ||
| 136 | printf("closing library handle = %x, count = %d\n", | ||
| 137 | handle, entry ? lib_entry_count(entry) : -1); | ||
| 138 | #endif | ||
| 139 | |||
| 140 | dlerrno = 0; | ||
| 141 | if ((shl_t) handle == PROG_HANDLE) | ||
| 142 | return 0; /* ignore attempts to close main program */ | ||
| 143 | else { | ||
| 144 | |||
| 145 | if ((entry = find_lib_entry((shl_t) handle)) != NULL) { | ||
| 146 | decrement_lib_entry_count(entry); | ||
| 147 | if (lib_entry_count(entry) > 0) | ||
| 148 | return 0; | ||
| 149 | else { | ||
| 150 | /* unload once reference count reaches zero */ | ||
| 151 | free_lib_entry(entry); | ||
| 152 | if (shl_unload((shl_t) handle) == 0) | ||
| 153 | return 0; | ||
| 154 | } | ||
| 155 | } | ||
| 156 | /* if you get to here, an error has occurred */ | ||
| 157 | dlerrno = 1; | ||
| 158 | sprintf(errbuf, "attempt to close library failed"); | ||
| 159 | #ifdef DEBUG | ||
| 160 | printf("%s\n", dlerror()); | ||
| 161 | #endif | ||
| 162 | return -1; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | |||
| 166 | /* | ||
| 167 | * Symbol Lookup. | ||
| 168 | */ | ||
| 169 | |||
| 170 | void *dlsym(void *handle, const char *name) | ||
| 171 | { | ||
| 172 | void *f; | ||
| 173 | shl_t myhandle; | ||
| 174 | |||
| 175 | dlerrno = 0; | ||
| 176 | myhandle = (handle == NULL) ? PROG_HANDLE : (shl_t) handle; | ||
| 177 | |||
| 178 | if (shl_findsym(&myhandle, name, TYPE_PROCEDURE, &f) != 0) { | ||
| 179 | dlerrno = 1; | ||
| 180 | sprintf(errbuf, "symbol %s not found", name); | ||
| 181 | f = NULL; | ||
| 182 | } | ||
| 183 | |||
| 184 | return(f); | ||
| 185 | } | ||
| 186 | |||
| 187 | #endif | ||
diff --git a/other/b-scan/tmp/support/snprintf.c b/other/b-scan/tmp/support/snprintf.c new file mode 100644 index 0000000..f6a7a40 --- /dev/null +++ b/other/b-scan/tmp/support/snprintf.c | |||
| @@ -0,0 +1,331 @@ | |||
| 1 | #ifdef NEED_SNPRINTF | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | #ifndef __P | ||
| 8 | #define __P(p) p | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #include <stdarg.h> | ||
| 12 | #define VA_LOCAL_DECL va_list ap; | ||
| 13 | #define VA_START(f) va_start(ap, f) | ||
| 14 | #define VA_END va_end(ap) | ||
| 15 | |||
| 16 | #ifdef SOLARIS2 | ||
| 17 | #ifdef _FILE_OFFSET_BITS | ||
| 18 | #define SOLARIS26 | ||
| 19 | #endif | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef SOLARIS26 | ||
| 23 | #define HAS_SNPRINTF | ||
| 24 | #define HAS_VSNPRINTF | ||
| 25 | #endif | ||
| 26 | #ifdef _SCO_DS_ | ||
| 27 | #define HAS_SNPRINTF | ||
| 28 | #endif | ||
| 29 | #ifdef luna2 | ||
| 30 | #define HAS_VSNPRINTF | ||
| 31 | #endif | ||
| 32 | |||
| 33 | /************************************************************** | ||
| 34 | * Original: | ||
| 35 | * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 | ||
| 36 | * A bombproof version of doprnt (dopr) included. | ||
| 37 | * Sigh. This sort of thing is always nasty do deal with. Note that | ||
| 38 | * the version here does not include floating point... | ||
| 39 | * | ||
| 40 | * snprintf() is used instead of sprintf() as it does limit checks | ||
| 41 | * for string length. This covers a nasty loophole. | ||
| 42 | * | ||
| 43 | * The other functions are there to prevent NULL pointers from | ||
| 44 | * causing nast effects. | ||
| 45 | **************************************************************/ | ||
| 46 | |||
| 47 | static void dopr(char *, const char *, va_list); | ||
| 48 | static char *end; | ||
| 49 | |||
| 50 | #ifndef HAS_VSNPRINTF | ||
| 51 | int vsnprintf(char *str, size_t count, const char *fmt, va_list args) | ||
| 52 | { | ||
| 53 | str[0] = 0; | ||
| 54 | end = str + count - 1; | ||
| 55 | dopr(str, fmt, args); | ||
| 56 | if (count > 0) | ||
| 57 | end[0] = 0; | ||
| 58 | return strlen(str); | ||
| 59 | } | ||
| 60 | |||
| 61 | #ifndef HAS_SNPRINTF | ||
| 62 | /* VARARGS3 */ | ||
| 63 | int snprintf(char *str, size_t count, const char *fmt,...) | ||
| 64 | { | ||
| 65 | int len; | ||
| 66 | VA_LOCAL_DECL | ||
| 67 | |||
| 68 | VA_START(fmt); | ||
| 69 | len = vsnprintf(str, count, fmt, ap); | ||
| 70 | VA_END; | ||
| 71 | return len; | ||
| 72 | } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | /* | ||
| 76 | * dopr(): poor man's version of doprintf | ||
| 77 | */ | ||
| 78 | |||
| 79 | static void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth)); | ||
| 80 | static void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad)); | ||
| 81 | static void dostr __P((char *, int)); | ||
| 82 | static char *output; | ||
| 83 | static void dopr_outch __P((int c)); | ||
| 84 | |||
| 85 | static void dopr(char *buffer, const char *format, va_list args) | ||
| 86 | { | ||
| 87 | int ch; | ||
| 88 | long value; | ||
| 89 | int longflag = 0; | ||
| 90 | int pointflag = 0; | ||
| 91 | int maxwidth = 0; | ||
| 92 | char *strvalue; | ||
| 93 | int ljust; | ||
| 94 | int len; | ||
| 95 | int zpad; | ||
| 96 | |||
| 97 | output = buffer; | ||
| 98 | while ((ch = *format++)) { | ||
| 99 | switch (ch) { | ||
| 100 | case '%': | ||
| 101 | ljust = len = zpad = maxwidth = 0; | ||
| 102 | longflag = pointflag = 0; | ||
| 103 | nextch: | ||
| 104 | ch = *format++; | ||
| 105 | switch (ch) { | ||
| 106 | case 0: | ||
| 107 | dostr("**end of format**", 0); | ||
| 108 | return; | ||
| 109 | case '-': | ||
| 110 | ljust = 1; | ||
| 111 | goto nextch; | ||
| 112 | case '0': /* set zero padding if len not set */ | ||
| 113 | if (len == 0 && !pointflag) | ||
| 114 | zpad = '0'; | ||
| 115 | case '1': | ||
| 116 | case '2': | ||
| 117 | case '3': | ||
| 118 | case '4': | ||
| 119 | case '5': | ||
| 120 | case '6': | ||
| 121 | case '7': | ||
| 122 | case '8': | ||
| 123 | case '9': | ||
| 124 | if (pointflag) | ||
| 125 | maxwidth = maxwidth * 10 + ch - '0'; | ||
| 126 | else | ||
| 127 | len = len * 10 + ch - '0'; | ||
| 128 | goto nextch; | ||
| 129 | case '*': | ||
| 130 | if (pointflag) | ||
| 131 | maxwidth = va_arg(args, int); | ||
| 132 | else | ||
| 133 | len = va_arg(args, int); | ||
| 134 | goto nextch; | ||
| 135 | case '.': | ||
| 136 | pointflag = 1; | ||
| 137 | goto nextch; | ||
| 138 | case 'l': | ||
| 139 | longflag = 1; | ||
| 140 | goto nextch; | ||
| 141 | case 'u': | ||
| 142 | case 'U': | ||
| 143 | /*fmtnum(value,base,dosign,ljust,len,zpad) */ | ||
| 144 | if (longflag) { | ||
| 145 | value = va_arg(args, long); | ||
| 146 | } | ||
| 147 | else { | ||
| 148 | value = va_arg(args, int); | ||
| 149 | } | ||
| 150 | fmtnum(value, 10, 0, ljust, len, zpad); | ||
| 151 | break; | ||
| 152 | case 'o': | ||
| 153 | case 'O': | ||
| 154 | /*fmtnum(value,base,dosign,ljust,len,zpad) */ | ||
| 155 | if (longflag) { | ||
| 156 | value = va_arg(args, long); | ||
| 157 | } | ||
| 158 | else { | ||
| 159 | value = va_arg(args, int); | ||
| 160 | } | ||
| 161 | fmtnum(value, 8, 0, ljust, len, zpad); | ||
| 162 | break; | ||
| 163 | case 'd': | ||
| 164 | case 'D': | ||
| 165 | if (longflag) { | ||
| 166 | value = va_arg(args, long); | ||
| 167 | } | ||
| 168 | else { | ||
| 169 | value = va_arg(args, int); | ||
| 170 | } | ||
| 171 | fmtnum(value, 10, 1, ljust, len, zpad); | ||
| 172 | break; | ||
| 173 | case 'x': | ||
| 174 | if (longflag) { | ||
| 175 | value = va_arg(args, long); | ||
| 176 | } | ||
| 177 | else { | ||
| 178 | value = va_arg(args, int); | ||
| 179 | } | ||
| 180 | fmtnum(value, 16, 0, ljust, len, zpad); | ||
| 181 | break; | ||
| 182 | case 'X': | ||
| 183 | if (longflag) { | ||
| 184 | value = va_arg(args, long); | ||
| 185 | } | ||
| 186 | else { | ||
| 187 | value = va_arg(args, int); | ||
| 188 | } | ||
| 189 | fmtnum(value, -16, 0, ljust, len, zpad); | ||
| 190 | break; | ||
| 191 | case 's': | ||
| 192 | strvalue = va_arg(args, char *); | ||
| 193 | if (maxwidth > 0 || !pointflag) { | ||
| 194 | if (pointflag && len > maxwidth) | ||
| 195 | len = maxwidth; /* Adjust padding */ | ||
| 196 | fmtstr(strvalue, ljust, len, zpad, maxwidth); | ||
| 197 | } | ||
| 198 | break; | ||
| 199 | case 'c': | ||
| 200 | ch = va_arg(args, int); | ||
| 201 | dopr_outch(ch); | ||
| 202 | break; | ||
| 203 | case '%': | ||
| 204 | dopr_outch(ch); | ||
| 205 | continue; | ||
| 206 | default: | ||
| 207 | dostr("???????", 0); | ||
| 208 | } | ||
| 209 | break; | ||
| 210 | default: | ||
| 211 | dopr_outch(ch); | ||
| 212 | break; | ||
| 213 | } | ||
| 214 | } | ||
| 215 | *output = 0; | ||
| 216 | } | ||
| 217 | |||
| 218 | static void fmtstr(char *value, int ljust, int len, int zpad, int maxwidth) | ||
| 219 | { | ||
| 220 | int padlen, strlen; /* amount to pad */ | ||
| 221 | |||
| 222 | if (value == 0) { | ||
| 223 | value = "<NULL>"; | ||
| 224 | } | ||
| 225 | for (strlen = 0; value[strlen]; ++strlen); /* strlen */ | ||
| 226 | if (strlen > maxwidth && maxwidth) | ||
| 227 | strlen = maxwidth; | ||
| 228 | padlen = len - strlen; | ||
| 229 | if (padlen < 0) | ||
| 230 | padlen = 0; | ||
| 231 | if (ljust) | ||
| 232 | padlen = -padlen; | ||
| 233 | while (padlen > 0) { | ||
| 234 | dopr_outch(' '); | ||
| 235 | --padlen; | ||
| 236 | } | ||
| 237 | dostr(value, maxwidth); | ||
| 238 | while (padlen < 0) { | ||
| 239 | dopr_outch(' '); | ||
| 240 | ++padlen; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | static void fmtnum(long value, int base, int dosign, int ljust, int len, int zpad) | ||
| 245 | { | ||
| 246 | int signvalue = 0; | ||
| 247 | unsigned long uvalue; | ||
| 248 | char convert[20]; | ||
| 249 | int place = 0; | ||
| 250 | int padlen = 0; /* amount to pad */ | ||
| 251 | int caps = 0; | ||
| 252 | |||
| 253 | /* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n", | ||
| 254 | value, base, dosign, ljust, len, zpad )); */ | ||
| 255 | uvalue = value; | ||
| 256 | if (dosign) { | ||
| 257 | if (value < 0) { | ||
| 258 | signvalue = '-'; | ||
| 259 | uvalue = -value; | ||
| 260 | } | ||
| 261 | } | ||
| 262 | if (base < 0) { | ||
| 263 | caps = 1; | ||
| 264 | base = -base; | ||
| 265 | } | ||
| 266 | do { | ||
| 267 | convert[place++] = | ||
| 268 | (caps ? "0123456789ABCDEF" : "0123456789abcdef") | ||
| 269 | [uvalue % (unsigned) base]; | ||
| 270 | uvalue = (uvalue / (unsigned) base); | ||
| 271 | } while (uvalue); | ||
| 272 | convert[place] = 0; | ||
| 273 | padlen = len - place; | ||
| 274 | if (padlen < 0) | ||
| 275 | padlen = 0; | ||
| 276 | if (ljust) | ||
| 277 | padlen = -padlen; | ||
| 278 | /* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n", | ||
| 279 | convert,place,signvalue,padlen)); */ | ||
| 280 | if (zpad && padlen > 0) { | ||
| 281 | if (signvalue) { | ||
| 282 | dopr_outch(signvalue); | ||
| 283 | --padlen; | ||
| 284 | signvalue = 0; | ||
| 285 | } | ||
| 286 | while (padlen > 0) { | ||
| 287 | dopr_outch(zpad); | ||
| 288 | --padlen; | ||
| 289 | } | ||
| 290 | } | ||
| 291 | while (padlen > 0) { | ||
| 292 | dopr_outch(' '); | ||
| 293 | --padlen; | ||
| 294 | } | ||
| 295 | if (signvalue) | ||
| 296 | dopr_outch(signvalue); | ||
| 297 | while (place > 0) | ||
| 298 | dopr_outch(convert[--place]); | ||
| 299 | while (padlen < 0) { | ||
| 300 | dopr_outch(' '); | ||
| 301 | ++padlen; | ||
| 302 | } | ||
| 303 | } | ||
| 304 | |||
| 305 | static void dostr(char *str, int cut) | ||
| 306 | { | ||
| 307 | if (cut) { | ||
| 308 | while (*str && cut-- > 0) | ||
| 309 | dopr_outch(*str++); | ||
| 310 | } | ||
| 311 | else { | ||
| 312 | while (*str) | ||
| 313 | dopr_outch(*str++); | ||
| 314 | } | ||
| 315 | } | ||
| 316 | |||
| 317 | static void dopr_outch(int c) | ||
| 318 | { | ||
| 319 | #if 0 | ||
| 320 | if (iscntrl(c) && c != '\n' && c != '\t') { | ||
| 321 | c = '@' + (c & 0x1F); | ||
| 322 | if (end == 0 || output < end) | ||
| 323 | *output++ = '^'; | ||
| 324 | } | ||
| 325 | #endif | ||
| 326 | if (end == 0 || output < end) | ||
| 327 | *output++ = c; | ||
| 328 | } | ||
| 329 | |||
| 330 | #endif /* HAVE_VSNPRINTF */ | ||
| 331 | #endif /*n NEED_SNPRINTF */ | ||
