X-Git-Url: http://www.privoxy.org/gitweb/?p=privoxy.git;a=blobdiff_plain;f=miscutil.c;h=cd908ebea5aa9205f701d6206df1bfa5955373cc;hp=fb8938ba35cebfa268c5c4e7399ad5a7ed74a2b5;hb=8577ff004f1b8873d78d4aa55a6a502afe242ca3;hpb=c047f21f14e305dacb22135b2add11b4eca78957 diff --git a/miscutil.c b/miscutil.c index fb8938ba..cd908ebe 100644 --- a/miscutil.c +++ b/miscutil.c @@ -7,7 +7,7 @@ * to deserve their own file but don't really fit in * any other file. * - * Copyright : Written by and Copyright (C) 2001-2016 the + * Copyright : Written by and Copyright (C) 2001-2018 the * Privoxy team. http://www.privoxy.org/ * * Based on the Internet Junkbuster originally written @@ -815,6 +815,45 @@ size_t privoxy_strlcat(char *destination, const char *source, const size_t size) #endif /* ndef HAVE_STRLCAT */ +/********************************************************************* + * + * Function : privoxy_millisleep + * + * Description : Sleep a number of milliseconds + * + * Parameters : + * 1 : delay: Number of milliseconds to sleep + * + * Returns : -1 on error, 0 otherwise + * + *********************************************************************/ +int privoxy_millisleep(unsigned milliseconds) +{ +#ifdef HAVE_NANOSLEEP + struct timespec rqtp = {0}; + struct timespec rmtp = {0}; + + rqtp.tv_sec = milliseconds / 1000; + rqtp.tv_nsec = (milliseconds % 1000) * 1000 * 1000; + + return nanosleep(&rqtp, &rmtp); +#elif defined (_WIN32) + Sleep(milliseconds); + + return 0; +#elif defined(__OS2__) + DosSleep(milliseconds * 10); + + return 0; +#else +#warning Missing privoxy_milisleep() implementation. delay-response{} will not work. + + return -1; +#endif /* def HAVE_NANOSLEEP */ + +} + + #if !defined(HAVE_TIMEGM) && defined(HAVE_TZSET) && defined(HAVE_PUTENV) /********************************************************************* *