1 /* 2 general_utilities.h 3 ------------------- 4 A bunch of useful functions that I keep using all the time. 5 6 Copyright (C) 2000 Eu-Jin Goh 7 8 This program is free software; you can redistribute it and/or 9 modify it under the terms of the GNU General Public License 10 as published by the Free Software Foundation; either version 2 11 of the License, or (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program; if not, write to the Free Software 20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 21 USA. 22 */ 23 24 /* necessary header files and defines */ 25 26 #ifndef GENERAL_UTILITIES_H 27 #define GENERAL_UTILITIES_H 28 29 //#define UTL_ERROR_MESSAGE "Error" 30 #define UTL_FAILURE -1 31 #define UTL_SUCCESS 1 32 33 /* ---------- General utility functions --------------- */ 34 35 /* safe wrapper around malloc. Exits on failure */ 36 void *utl_GetMem(const int size); 37 38 /* allocates memory and copies the src up to size amt */ 39 void *utl_memcpy(const void *src, const int size_to_copy); 40 41 /* error handler. calls perror and exits */ 42 void utl_HandleError(char *error_msg); 43 44 /* assumes srand has already been called */ 45 int utl_GenRandomInt(const int low, const int high); 46 47 /* 48 hex encodes and decodes strings 49 Returns length of output buffer. 50 encode returns an even length null terminated string. 51 decode expects an even length null terminated string. 52 memory will be allocated for out if outLen is 0 53 */ 54 int utl_HexEncode(unsigned char *in, int in_len, char **out, int out_len); 55 int utl_HexDecode(char *in, int in_len, unsigned char **out, int out_len); 56 57 void utl_PrintCharAsHex(char x); 58 59 60 #endif 61