Skip to content
Snippets Groups Projects
port.c 1016 B
Newer Older
Alexandre Julliard's avatar
Alexandre Julliard committed
/*
 * Misc. functions for systems that don't have them
 *
 * Copyright 1996 Alexandre Julliard
 */

#include "config.h"
Alexandre Julliard's avatar
Alexandre Julliard committed
#include <sys/types.h>
Alexandre Julliard's avatar
Alexandre Julliard committed
#include <sys/time.h>

#ifndef HAVE_USLEEP
unsigned int usleep (unsigned int useconds)
{
    struct timeval delay;

    delay.tv_sec = 0;
    delay.tv_usec = useconds;

Alexandre Julliard's avatar
Alexandre Julliard committed
    select( 0, 0, 0, 0, &delay );
Alexandre Julliard's avatar
Alexandre Julliard committed
    return 0;
}
#endif /* HAVE_USLEEP */

Alexandre Julliard's avatar
Alexandre Julliard committed
#ifndef HAVE_MEMMOVE
void *memmove( void *dst, const void *src, unsigned int len )
{
    /* Use memcpy if not overlapping */
    if (((char *)dst + len <= (char *)src) ||
        ((char *)src + len <= (char *)dst))
    {
        memcpy( dst, src, len );
    }
    /* Otherwise do it the hard way (FIXME: could do better than this) */
    else if (dst < src)
    {
        while (len--) *((char *)dst)++ = *((char *)src)++;
    }
    else
    {
        dst = (char *)dst + len - 1;
        src = (char *)src + len - 1;
        while (len--) *((char *)dst)-- = *((char *)src)--;
    }
    return dst;
}
#endif  /* HAVE_MEMMOVE */