Rev 19 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 19 | Rev 23 | ||
---|---|---|---|
Line 71... | Line 71... | ||
71 | #define stat _stat64 |
71 | #define stat _stat64 |
72 | #define getcwd(buf,maxsize) _getcwd ((buf), (maxsize)) |
72 | #define getcwd(buf,maxsize) _getcwd ((buf), (maxsize)) |
73 | #define chdir(pathname) _chdir ((pathname)) |
73 | #define chdir(pathname) _chdir ((pathname)) |
74 | #define putenv(v) _putenv ((v)) |
74 | #define putenv(v) _putenv ((v)) |
75 | #define MAXPATHLEN 1024 |
75 | #define MAXPATHLEN 1024 |
- | 76 | static const char *__static_progname = NULL; |
|
- | 77 | static const char *__getprogname (void) { if (__static_progname == NULL) { const char *sep; __static_progname = __argv[0]; if ((sep = strrchr (__static_progname, '\\')) != NULL) __static_progname = sep + 1; if ((sep = strrchr (__static_progname, '/')) != NULL) __static_progname = sep + 1; } return (__static_progname); } |
|
- | 78 | #define __progname (__getprogname ()) |
|
76 | struct dirent { unsigned char d_namlen; char *d_name; }; // bring struct dirent/opendir() support to Windows |
79 | struct dirent { unsigned char d_namlen; char *d_name; }; // bring struct dirent/opendir() support to Windows |
77 | typedef struct DIR { intptr_t handle; struct __finddata64_t info; struct dirent result; char *pathname; char *search_pattern; } DIR; |
80 | typedef struct DIR { intptr_t handle; struct __finddata64_t info; struct dirent result; char *pathname; char *search_pattern; } DIR; |
78 | static inline DIR *opendir (const char *name) // UNIX-like opendir() implementation for Windows |
81 | static inline DIR *opendir (const char *name) // UNIX-like opendir() implementation for Windows |
79 | { |
82 | { |
80 | DIR *dir; size_t base_length, all_length; const char *suffix; |
83 | DIR *dir; size_t base_length, all_length; const char *suffix; |
Line 122... | Line 125... | ||
122 | #else // !_MSC_VER |
125 | #else // !_MSC_VER |
123 | #define strcpy_s(s1,s1size,s2) strcpy ((s1), (s2)) |
126 | #define strcpy_s(s1,s1size,s2) strcpy ((s1), (s2)) |
124 | #define strcat_s(s1,s1size,s2) strcat ((s1), (s2)) |
127 | #define strcat_s(s1,s1size,s2) strcat ((s1), (s2)) |
125 | #define sprintf_s(s1,s1size,...) sprintf ((s1), __VA_ARGS__) |
128 | #define sprintf_s(s1,s1size,...) sprintf ((s1), __VA_ARGS__) |
126 | #define fopen_s(fp,pathname,mode) *(fp) = fopen ((pathname), (mode)) |
129 | #define fopen_s(fp,pathname,mode) *(fp) = fopen ((pathname), (mode)) |
- | 130 | extern const char *__progname; // exported by libc |
|
127 | #endif // _MSC_VER |
131 | #endif // _MSC_VER |
128 | 132 | ||
129 | 133 | ||
130 | // handy macros that generate a version number in the format "YYYYMMDD" corresponding to the build date. Usage: printf ("version " VERSION_FMT_YYYYMMDD "\n", VERSION_ARG_YYYYMMDD); |
134 | // handy macros that generate a version number in the format "YYYYMMDD" corresponding to the build date. Usage: printf ("version " VERSION_FMT_YYYYMMDD "\n", VERSION_ARG_YYYYMMDD); |
131 | #ifndef VERSION_ARG_YYYYMMDD |
135 | #ifndef VERSION_ARG_YYYYMMDD |
Line 222... | Line 226... | ||
222 | __FILE__) // this *COMPILE-TIME* macro complements the __FILE__ macro defined by the C standard by returning just the filename portion of the full path. Supports filenames up to 32 chars. Expand as necessary. |
226 | __FILE__) // this *COMPILE-TIME* macro complements the __FILE__ macro defined by the C standard by returning just the filename portion of the full path. Supports filenames up to 32 chars. Expand as necessary. |
223 | #endif // !__FILE_NAME__ |
227 | #endif // !__FILE_NAME__ |
224 | 228 | ||
225 | 229 | ||
226 | // logging macros |
230 | // logging macros |
227 | #define LOG(type,lvl,...) do { if ((lvl) <= verbose_level) { fprintf (stderr, " |
231 | #define LOG(type,lvl,...) do { if ((lvl) <= verbose_level) { fprintf (stderr, "%s: %s: ", __progname, (type)); if (verbose_level > 1) fprintf (stderr, "%s:%d:%s(): ", __FILE_NAME__, __LINE__, __func__); fprintf (stderr, __VA_ARGS__); fputc ('\n', stderr); } } while (0) |
228 | #define LOG_ERROR(...) LOG ("error", 0, __VA_ARGS__) |
232 | #define LOG_ERROR(...) LOG ("error", 0, __VA_ARGS__) |
229 | #define LOG_WARNING(...) LOG ("warning", 1, __VA_ARGS__) |
233 | #define LOG_WARNING(...) LOG ("warning", 1, __VA_ARGS__) |
230 | #define LOG_INFO(...) LOG ("info", 2, __VA_ARGS__) |
234 | #define LOG_INFO(...) LOG ("info", 2, __VA_ARGS__) |
231 | #define LOG_DEBUG(...) LOG ("debug", 3, __VA_ARGS__) |
235 | #define LOG_DEBUG(...) LOG ("debug", 3, __VA_ARGS__) |
232 | 236 | ||
233 | // macro to gently exit with an error message |
237 | // macro to gently exit with an error message |
234 | #define DIE_WITH_EXITCODE(exitcode,...) do { LOG_ERROR (__VA_ARGS__); exit ((exitcode)); } while (0) |
238 | #define DIE_WITH_EXITCODE(exitcode,...) do { LOG_ERROR (__VA_ARGS__); exit ((exitcode)); } while (0) |
235 | 239 | ||
236 | // macro to exit less brutally than with abort() if something doesn't go the way we'd like to |
240 | // macro to exit less brutally than with abort() if something doesn't go the way we'd like to |
237 | #define ASSERT(is_it_true,...) do { if (!(is_it_true)) { LOG ("fatal error", 0, "consistency check failed:"); LOG (" |
241 | #define ASSERT(is_it_true,...) do { if (!(is_it_true)) { LOG ("fatal error", 0, "consistency check failed:"); LOG ("failed check", 0, #is_it_true); LOG ("consequence", 0, __VA_ARGS__); exit (1); } } while (0) |
238 | #define ASSERT_WITH_ERRNO(is_it_true) ASSERT ((is_it_true), "%s", strerror (errno)) |
242 | #define ASSERT_WITH_ERRNO(is_it_true) ASSERT ((is_it_true), "%s", strerror (errno)) |
239 | 243 | ||
240 | 244 | ||
241 | #ifdef __cplusplus |
245 | #ifdef __cplusplus |
242 | } |
246 | } |