1 /***************************************************************************
2 * Copyright (C) 2007 by Arep *
3 * Support is provided through the forums at *
4 * http://wii.console-tribe.com *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 ***************************************************************************/
22 #ifndef MISC_H_INCLUDED
23 #define MISC_H_INCLUDED
25 /*** Include site configuration ***/
31 /*** Windows stuff ***/
32 #include "win32compat.h"
34 #define _GNU_SOURCE // For strndup()
38 #include <sys/types.h>
42 #define MY_ASSERT(cond) \
44 fprintf (stderr, "*** ASSERTION FAILED at " __FILE__ ":%d: " # cond "\n", __LINE__); \
48 /*** LOGGING STUFF ***/
56 LOG_NOCR = 1 << 15 /* Use in OR to avoid a trailing newline */
59 /* Don't use this function explicitly. Use the macros below. */
60 void _logprintf (int level, char tag[], char format[], ...);
63 #define logprintf(level, ...) _logprintf (level, (char *) __FUNCTION__, __VA_ARGS__)
65 #define debug(...) logprintf(LOG_DEBUG, __VA_ARGS__)
66 #define debug_nocr(...) logprintf(LOG_DEBUG | LOG_NOCR, __VA_ARGS__)
68 #define logprintf(level, ...) _logprintf (level, NULL, __VA_ARGS__)
70 #define debug(...) do {;} while (0);
71 #define debug_nocr(...) do {;} while (0);
74 #if defined (DEBUG) || defined (VERBOSE)
75 #define log(...) logprintf (LOG_NORMAL, __VA_ARGS__)
76 #define warning(...) logprintf (LOG_WARNING, __VA_ARGS__)
77 #define error(...) logprintf (LOG_ERROR, __VA_ARGS__)
85 void hex_and_ascii_print_with_offset(const char *ident, register const u_int8_t *cp,
86 register u_int16_t length, register u_int16_t oset);
87 #define hex_and_ascii_print(ident, cp, length) hex_and_ascii_print_with_offset(ident, cp, length, 0)
90 #define my_strdup(dest, src) \
91 if (!(dest = strdup (src))) { \
92 fprintf (stderr, "strdup() failed\n"); \
96 #define my_strndup(dest, src, c) \
97 if (!(dest = strndup ((const char *) src, c))) { \
98 fprintf (stderr, "strndup() failed\n"); \
102 char *strtrimr (char *s);
111 /*** STUFF FOR PORTABLE LARGE-FILES FSEEK ***/
112 #if defined(_MSC_VER)
113 typedef __int64 my_off_t;
114 #elif defined (HAVE_OFF_T) && SIZEOF_OFF_T >= 8
115 typedef off_t my_off_t;
116 #elif defined (HAVE_FPOS_T) && SIZEOF_FPOS_T >= 8
117 typedef fpos_t my_off_t;
119 typedef u_int64_t my_off_t;
122 int my_fseek (FILE *fp, my_off_t offset, int whence);
123 my_off_t my_ftell (FILE* fp);
127 /*** STUFF FOR DROPPING PRIVILEGES ***/
128 FRIIDUMPLIB_EXPORT void drop_euid ();
129 FRIIDUMPLIB_EXPORT void upgrade_euid ();
133 /*** STUFF FOR BOOLEAN DATA TYPE ***/
134 #ifdef HAVE_STDBOOL_H
135 /* If using a C99 compiler, use the builtin boolean type */
138 typedef enum {false,true} bool;