+static FILE *Toutputfile;
+
+void Tshutdown(void) {
+}
+
+static void R_recordtime(void) {
+ int r;
+ struct timeval tv, tvrel;
+
+ Tensurerecordfile();
+ r= gettimeofday(&tv,0); if (r) Tfailed("gettimeofday syscallbegin");
+ tvrel.tv_sec= tv.tv_sec - currenttime.tv_sec;
+ tvrel.tv_usec= tv.tv_usec - currenttime.tv_usec;
+ if (tv.tv_usec < 0) { tvrel.tv_usec += 1000000; tvrel.tv_sec--; }
+ Tvbf("\n +%ld.%06ld",(long)tvrel.tv_sec,(long)tvrel.tv_usec);
+ currenttime= tv;
+}
+
+void Tensurerecordfile(void) {
+ const char *fdstr;
+ int fd, r;
+
+ if (Toutputfile) return;
+
+ Toutputfile= stdout;
+ fdstr= getenv("ADNS_TEST_OUT_FD");
+ if (fdstr) {
+ fd= atoi(fdstr);
+ Toutputfile= fdopen(fd,"a"); if (!Toutputfile) Tfailed("fdopen ADNS_TEST_OUT_FD");
+ }
+
+ r= gettimeofday(¤ttime,0); if (r) Tfailed("gettimeofday syscallbegin");
+ if (fprintf(Toutputfile," start %ld.%06ld\n",
+ (long)currenttime.tv_sec,(long)currenttime.tv_usec) == EOF) Toutputerr();
+}