2 /* This is a hack. I totally deny writing it. If this code breaks,
3 * you get to keep all the pieces. JRS, 23 feb 99.
13 #include <sys/times.h>
14 #include <sys/resource.h>
21 double nh_getCPUtime ( void )
25 getrusage ( RUSAGE_SELF, &usage );
26 usertime = (double)usage.ru_utime.tv_sec +
27 (double)usage.ru_utime.tv_usec / 1000000.0;
31 double nh_getCPUprec ( void )
33 /* or perhaps CLOCKS_PER_SEC ? */
34 return 1.0 / (double)(CLK_TCK);
37 double nh_getCPUtime ( void )
42 double nh_getCPUprec ( void )
48 int nh_getPID ( void )
51 return (int) getpid();
57 void nh_exitwith ( int code )
62 int nh_system ( char* cmd )
64 return system ( cmd );
67 int nh_iseof ( FILE* f )
72 if (c == EOF) return 1;
77 int nh_filesize ( FILE* f )
82 fstat ( fileno(f), &buf );
96 int nh_stdout ( void )
102 int nh_stderr ( void )
108 int nh_open ( char* fname, int wr )
112 f = fopen ( fname, (wr==0) ? "r": ((wr==1) ? "w" : "a") );
116 void nh_close ( FILE* f )
123 void nh_flush ( FILE* f )
129 void nh_write ( FILE* f, int c )
133 if (f==stderr) { fflush(f); }
134 if (f==stdout) { fflush(f); }
137 int nh_read ( FILE* f )
143 int nh_errno ( void )
150 int nh_malloc ( int n )
156 void nh_free ( int n )
161 void nh_store ( int p, int ch )
163 *(char*)p = (char)ch;
166 int nh_load ( int p )
168 return (int)(*(char*)p);
171 int nh_getenv ( int p )
173 return (int)getenv ( (const char *)p );