This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] clock_settime


This implements the POSIX clock_settime function, on top of settimeofday:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_settime.html
http://www.kernel.org/doc/man-pages/online/pages/man3/clock_gettime.3.html
http://www.kernel.org/doc/man-pages/online/pages/man2/settimeofday.2.html

The fixes to settimeofday are necessary both to match BSD and Linux behaviour,
and to provide the errnos and return status for clock_settime required by POSIX.
I also fixed posix.sgml WRT clock_setres.

Patches for winsup/cygwin and winsup/doc, plus test programs for both
functions, attached.


Yaakov

Attachment: clock_settime.patch
Description: Binary data

#pragma CCOD:script no
#pragma CCOD:options -lrt

#define _BSD_SOURCE
#include <stdio.h>
#include <sys/time.h>
#include <unistd.h>

#define CHANGE 300	/* five minutes */
#define PAUSE 5

int
main (void)
{
  struct timeval tv;
  struct timezone tz;
  int ret;

  gettimeofday (&tv, &tz);

  tv.tv_sec -= CHANGE;
#ifdef TEST_EINVAL
  tv.tv_usec = -1;
#endif
  if ((ret = settimeofday (&tv, &tz)))
    goto end;

  sleep (PAUSE);

  tv.tv_sec += CHANGE + PAUSE;
  ret = settimeofday (&tv, &tz);

end:
  if (ret)
    perror ("settimeofday-test");
  return ret;
}
#pragma CCOD:script no
#pragma CCOD:options -lrt

#define _XOPEN_SOURCE 500
#include <dlfcn.h>
#include <stdio.h>
#include <time.h>
#include <unistd.h>

#define CHANGE 300	/* five minutes */
#define PAUSE 5

int
main (void)
{
  struct timespec tp;
  int ret;
#ifdef __CYGWIN__
  int (*clock_settime) (clockid_t, const struct timespec *);
  clock_settime = dlsym (dlopen ("cygwin1.dll", 0), "clock_settime");
#endif

  clock_gettime (CLOCK_REALTIME, &tp);

  tp.tv_sec -= CHANGE;
  if ((ret = clock_settime (CLOCK_REALTIME, &tp)))
    goto end;

  sleep (PAUSE);

  tp.tv_sec += CHANGE + PAUSE;
  ret = clock_settime (CLOCK_REALTIME, &tp);

end:
  if (ret)
    perror ("clock_settime-test");
  return ret;
}

Attachment: doc-clock_settime.patch
Description: Binary data


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]