raw
ch1_mpi                 1 /* util.h
ch1_mpi 2 * Modified by No Such Labs. (C) 2015. See README.
ch1_mpi 3 *
ch1_mpi 4 * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10,
ch1_mpi 5 * SHA256(gnupg-1.4.10.tar.gz):
ch1_mpi 6 * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a
ch1_mpi 7 * (C) 1994-2005 Free Software Foundation, Inc.
ch1_mpi 8 *
ch1_mpi 9 * This program is free software: you can redistribute it and/or modify
ch1_mpi 10 * it under the terms of the GNU General Public License as published by
ch1_mpi 11 * the Free Software Foundation, either version 3 of the License, or
ch1_mpi 12 * (at your option) any later version.
ch1_mpi 13 *
ch1_mpi 14 * This program is distributed in the hope that it will be useful,
ch1_mpi 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
ch1_mpi 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ch1_mpi 17 * GNU General Public License for more details.
ch1_mpi 18 *
ch1_mpi 19 * You should have received a copy of the GNU General Public License
ch1_mpi 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
ch1_mpi 21 */
ch1_mpi 22
ch1_mpi 23 #ifndef G10_UTIL_H
ch1_mpi 24 #define G10_UTIL_H
ch1_mpi 25
ch1_mpi 26 #if defined (_WIN32) || defined (__CYGWIN32__)
ch1_mpi 27 #include <stdarg.h>
ch1_mpi 28 #endif
ch1_mpi 29
ch1_mpi 30 #include "types.h"
ch1_mpi 31 #include "types.h"
ch1_mpi 32 #include "mpi.h"
ch1_mpi 33
ch1_mpi 34 #define log_hexdump printf
ch1_mpi 35 #define log_bug printf
ch1_mpi 36 #define log_bug0 printf
ch1_mpi 37 #define log_fatal printf
ch1_mpi 38 #define log_error printf
ch1_mpi 39 #define log_info printf
ch1_mpi 40 #define log_warning printf
ch1_mpi 41 #define log_debug printf
ch1_mpi 42
ch1_mpi 43 #define g10_log_print_prefix printf
ch1_mpi 44
ch1_mpi 45
ch1_mpi 46 #ifndef HAVE_MEMMOVE
ch1_mpi 47 #define memmove(d, s, n) bcopy((s), (d), (n))
ch1_mpi 48 #endif
ch1_mpi 49
ch1_mpi 50
ch1_mpi 51 /**** other missing stuff ****/
ch1_mpi 52 #ifndef HAVE_ATEXIT /* For SunOS */
ch1_mpi 53 #define atexit(a) (on_exit((a),0))
ch1_mpi 54 #endif
ch1_mpi 55
ch1_mpi 56 #ifndef HAVE_RAISE
ch1_mpi 57 #define raise(a) kill(getpid(), (a))
ch1_mpi 58 #endif
ch1_mpi 59
ch1_mpi 60 /******** some macros ************/
ch1_mpi 61 #ifndef STR
ch1_mpi 62 #define STR(v) #v
ch1_mpi 63 #endif
ch1_mpi 64 #define STR2(v) STR(v)
ch1_mpi 65 #define DIM(v) (sizeof(v)/sizeof((v)[0]))
ch1_mpi 66 #define DIMof(type,member) DIM(((type *)0)->member)
ch1_mpi 67
ch1_mpi 68 #define wipememory2(_ptr,_set,_len) do { volatile char *_vptr=(volatile char *)(_ptr); size_t _vlen=(_len); while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } } while(0)
ch1_mpi 69 #define wipememory(_ptr,_len) wipememory2(_ptr,0,_len)
ch1_mpi 70
ch1_mpi 71 /*-- macros to replace ctype ones and avoid locale problems --*/
ch1_mpi 72 #define spacep(p) (*(p) == ' ' || *(p) == '\t')
ch1_mpi 73 #define digitp(p) (*(p) >= '0' && *(p) <= '9')
ch1_mpi 74 #define hexdigitp(a) (digitp (a) \
ch1_mpi 75 || (*(a) >= 'A' && *(a) <= 'F') \
ch1_mpi 76 || (*(a) >= 'a' && *(a) <= 'f'))
ch1_mpi 77 /* the atoi macros assume that the buffer has only valid digits */
ch1_mpi 78 #define atoi_1(p) (*(p) - '0' )
ch1_mpi 79 #define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
ch1_mpi 80 #define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2))
ch1_mpi 81 #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
ch1_mpi 82 *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
ch1_mpi 83 #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
ch1_mpi 84
ch1_mpi 85
ch1_mpi 86 #endif /*G10_UTIL_H*/