$NetBSD: patch-ab,v 1.2 2006/10/25 21:37:51 rillig Exp $

--- watch.c.orig	2006-10-25 23:13:48.793523972 +0200
+++ watch.c	2006-10-25 23:25:56.542821832 +0200
@@ -142,6 +142,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 +200,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 +250,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 +323,7 @@ main(int argc, char *argv[])
 
 		first_screen = 0;
 		refresh();
-		usleep(interval * 1000000);
+		nanosleep(&tsinterval, NULL);
 	}
 
 	endwin();
