X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=util.h;h=2b0886cc0c98e3d4902e519c2554808417e6a38e;hb=acb140befabd8b0f1a8606470013b420d05b4fb7;hp=9449f121d19c5047e041923df9fba10941125999;hpb=64f72f31685ea1dff12b19b22cfaf7a53ccc079f;p=polyglot.git diff --git a/util.h b/util.h index 9449f12..2b0886c 100644 --- a/util.h +++ b/util.h @@ -6,9 +6,22 @@ // includes -#include +#include + +// defines + +#ifndef EXIT_SUCCES +#define EXIT_SUCCES 0 +#endif + +#ifndef STDIN_FILENO +#define STDIN_FILENO 0 +#endif + +#ifndef STDOUT_FILENO +#define STDOUT_FILENO 1 +#endif -// constants #undef FALSE #define FALSE 0 @@ -48,6 +61,29 @@ # define ASSERT(a) #endif +#ifdef _WIN32 +#define snprintf _snprintf +#endif + +#define FormatBufferSize 4096 + +#define CONSTRUCT_ARG_STRING(format,buf) \ + { \ + va_list arg_list; \ + int written; \ + va_start(arg_list,format); \ + written=vsnprintf(buf, \ + sizeof(buf), \ + format, \ + arg_list); \ + va_end(arg_list); \ + buf[sizeof(buf)]='\0'; \ + if(written>=sizeof(buf) || written<0){ \ + my_fatal("write_buffer overflow: file \"%s\", line %d\n", \ + __FILE__,__LINE__); \ + } \ + } \ + // types typedef signed char sint8; @@ -59,6 +95,8 @@ typedef unsigned short uint16; typedef signed int sint32; typedef unsigned int uint32; +typedef int bool; + #ifdef _MSC_VER typedef signed __int64 sint64; typedef unsigned __int64 uint64; @@ -67,28 +105,15 @@ typedef unsigned int uint32; typedef unsigned long long int uint64; #endif -struct my_timer_t { +typedef struct { double start_real; double elapsed_real; bool running; -}; +} my_timer_t; + // functions -#ifdef _WIN32 - #include - inline void Idle(void) { - Sleep(1); - } - inline void Idle500msecs(void){ - Sleep(500); - } -#else - #include - inline void Idle(void) { - usleep(1000); - } -#endif extern void util_init (); extern void my_random_init (); @@ -120,12 +145,15 @@ extern char * my_strdup (const char string[]); extern void my_string_clear (const char * * variable); extern void my_string_set (const char * * variable, const char string[]); +extern double now_real (); + extern void my_timer_reset (my_timer_t * timer); extern void my_timer_start (my_timer_t * timer); extern void my_timer_stop (my_timer_t * timer); extern double my_timer_elapsed_real (const my_timer_t * timer); +extern char * my_error(); #endif // !defined UTIL_H