usleep in uClibc/uClinux

William Pitcock nenolod at dereferenced.org
Wed Mar 9 03:05:36 UTC 2011


Hi,

On Tue, 8 Mar 2011 15:14:57 +0100
Drasko DRASKOVIC <drasko.draskovic at gmail.com> wrote:

> Hi all,
> in uClibc/include/unistd.h I can see :
> 
> #if defined __USE_BSD || defined __USE_XOPEN_EXTENDED
> /* Set an alarm to go off (generating a SIGALRM signal) in VALUE
>    microseconds.  If INTERVAL is nonzero, when the alarm goes off, the
>    timer is reset to go off every INTERVAL microseconds thereafter.
>    Returns the number of microseconds remaining before the alarm.  */
> extern __useconds_t ualarm (__useconds_t __value, __useconds_t
> __interval) __THROW;
> 
> /* Sleep USECONDS microseconds, or until a signal arrives that is not
> blocked or ignored.
> 
>    This function is a cancellation point and therefore not marked with
>    __THROW.  */
> extern int usleep (__useconds_t __useconds);
> #endif
> 
> So, usleep() is defined only if __USE_BSD.
> 
> 1) Why so ?
> 
> 2) What if I do not use BSD system, but uClinux ?

__USE_BSD means that it's just an API that was present in the BSD4.3
UNIX distribution, but is not formally part of POSIX.  You don't
*really* need __USE_BSD defined, but if you want to define it, you can
do it like this:

    #define __USE_BSD /* usleep() */
    #include <unistd.h>

The idea is that you can disable some API prototypes in order to test
whether or not your code would compile on those systems.  I'm not
personally convinced of the value of this, but that's why they do it
(or at least, this is my understanding).

Regardless, usleep() is supported by uClibc.

William


More information about the uClibc mailing list