Back to index

glibc  2.9
Defines | Functions
tst-nanosleep.c File Reference
#include <errno.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include "../test-skeleton.c"

Go to the source code of this file.


#define TEST_FUNCTION   do_test ()


static int do_test (void)

Define Documentation

#define TEST_FUNCTION   do_test ()

Definition at line 57 of file tst-nanosleep.c.

Function Documentation

static int do_test ( void  ) [static]

Definition at line 28 of file tst-nanosleep.c.

  /* Current time.  */
  struct timeval tv1;
  (void) gettimeofday (&tv1, NULL);

  struct timespec ts;
  ts.tv_sec = 1;
  ts.tv_nsec = 0;
  TEMP_FAILURE_RETRY (nanosleep (&ts, &ts));

  /* At least one second must have passed.  */
  struct timeval tv2;
  (void) gettimeofday (&tv2, NULL);

  tv2.tv_sec -= tv1.tv_sec;
  tv2.tv_usec -= tv1.tv_usec;
  if (tv2.tv_usec < 0)

  if (tv2.tv_sec < 1)
      puts ("nanosleep didn't sleep long enough");
      return 1;

  return 0;

Here is the call graph for this function: