$NetBSD: patch-aa,v 1.4 2008/02/22 02:14:53 tnn Exp $ --- watch.c.orig 2008-02-22 03:05:28.000000000 +0100 +++ watch.c @@ -13,7 +13,13 @@ #define VERSION "0.2.0" #include +#if defined(HAVE_NBCOMPAT_H) +#include +#include +#include +#else #include +#endif #include #include #include @@ -142,6 +148,7 @@ main(int argc, char *argv[]) option_differences_cumulative = 0, option_help = 0, option_version = 0; float interval = 2; + struct timespec tsinterval; char *command; int command_length = 0; /* not including final \0 */ @@ -199,6 +206,9 @@ main(int argc, char *argv[]) if (optind >= argc) do_usage(); + tsinterval.tv_sec = interval; + tsinterval.tv_nsec = (interval - tsinterval.tv_sec) * 1000000000L; + command = strdup(argv[optind++]); command_length = strlen(command); for (; optind < argc; optind++) { @@ -246,10 +256,16 @@ main(int argc, char *argv[]) } if (show_title) { +#if defined(__sun) + header = malloc(width + 1); + if (!header) { perror("malloc"); do_exit(2); } + snprintf(header, width + 1, "Every %.1fs: %s", interval, command); +#else // left justify interval and command, // right justify time, clipping all to fit window width asprintf(&header, "Every %.1fs: %.*s", interval, min(width - 1, command_length), command); +#endif mvaddstr(0, 0, header); if (strlen(header) > (size_t) (width - tsl - 1)) mvaddstr(0, width - tsl - 4, "... "); @@ -313,7 +329,7 @@ main(int argc, char *argv[]) first_screen = 0; refresh(); - usleep(interval * 1000000); + nanosleep(&tsinterval, NULL); } endwin();