X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilcutil%2Fsilctime.h;h=e01e1ae701f92660debb212b10dae7a6195f7b86;hb=e7b6c157b80152bf9fb9266e6bdd93f9fb0db776;hp=a57830f6444a90006491b6866f5e30fa9f1b6097;hpb=89e862e5385cdd697feaec6c008e30b599890e4d;p=silc.git diff --git a/lib/silcutil/silctime.h b/lib/silcutil/silctime.h index a57830f6..e01e1ae7 100644 --- a/lib/silcutil/silctime.h +++ b/lib/silcutil/silctime.h @@ -44,7 +44,7 @@ * SOURCE * ***/ -typedef struct { +typedef struct SilcTimeObject { unsigned int year : 15; /* Year, 0 - 32768 */ unsigned int month : 4; /* Month, 1 - 12 */ unsigned int day : 5; /* Day, 1 - 31 */ @@ -134,6 +134,25 @@ const char *silc_time_string(SilcInt64 time_val_sec); ***/ SilcBool silc_time_value(SilcInt64 time_val_msec, SilcTime ret_time); +/****f* silcutil/SilcTimeAPI/silc_timezone + * + * SYNOPSIS + * + * SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size); + * + * DESCRIPTION + * + * Returns current timezone in Universal time format into the `timezone' + * buffer of size of `timezone_size'. The possible values this function + * returns are: Z (For UTC timezone), +hh (UTC + hours) -hh (UTC - hours), + * +hh:mm (UTC + hours:minutes) or -hh:mm (UTC - hours:minutes). The + * returned values are always offsets to UTC. + * + * Returns FALSE on error, TRUE otherwise. + * + ***/ +SilcBool silc_timezone(char *timezone, SilcUInt32 timezone_size); + /****f* silcutil/SilcTimeAPI/silc_time_universal * * SYNOPSIS @@ -228,17 +247,16 @@ SilcBool silc_time_generalized_string(SilcTime time_val, char *ret_string, * * SYNOPSIS * - * SilcBool silc_compare_timeval(struct time_val *smaller, - * struct time_val *bigger) + * int silc_compare_timeval(struct time_val *t1, struct time_val *t2); * * DESCRIPTION * - * Compare two timeval structures and return TRUE if the first - * time value is smaller than the second time value. + * Compares `t1' and `t2' time structures and returns less than zero, + * zero or more than zero when `t1' is smaller, equal or bigger than + * `t2', respectively. * ***/ -SilcBool silc_compare_timeval(struct timeval *smaller, - struct timeval *bigger); +int silc_compare_timeval(struct timeval *t1, struct timeval *t2); /****f* silcutil/SilcTimeAPI/silc_gettimeofday * @@ -254,4 +272,47 @@ SilcBool silc_compare_timeval(struct timeval *smaller, ***/ int silc_gettimeofday(struct timeval *p); +/****f* silcutil/SilcTimeAPI/silc_usleep + * + * SYNOPSIS + * + * void silc_usleep(unsigned long microseconds); + * + * DESCRIPTION + * + * Delays the execution of process/thread for the specified amount of + * time, which is in microseconds. + * + * NOTES + * + * The delay is only approximate and on some platforms the resolution is + * in fact milliseconds. + * + ***/ +static inline +void silc_usleep(unsigned long microseconds) +{ +#ifdef SILC_UNIX +#ifdef HAVE_NANOSLEEP + struct timespec tv; + tv.tv_sec = 0; + tv.tv_nsec = microseconds * 1000; +#endif /* HAVE_NANOSLEEP */ +#endif /* SILC_UNIX */ + +#ifdef SILC_UNIX +#ifdef HAVE_NANOSLEEP + nanosleep(&tv, NULL); +#else + usleep(microseconds); +#endif /* HAVE_NANOSLEEP */ +#endif /* SILC_UNIX */ +#ifdef SILC_WIN32 + Sleep(microseconds / 1000); +#endif /* SILC_WIN32 */ +#ifdef SILC_SYMBIAN + silc_symbian_usleep(microseconds); +#endif /* SILC_SYMBIAN */ +} + #endif /* SILCTIME_H */