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