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.
12 #include <sys/times.h>
13 #include <sys/resource.h>
18 double nh_getCPUtime ( void )
22 getrusage ( RUSAGE_SELF, &usage );
23 usertime = (double)usage.ru_utime.tv_sec +
24 (double)usage.ru_utime.tv_usec / 1000000.0;
28 double nh_getCPUprec ( void )
30 /* or perhaps CLOCKS_PER_SEC ? */
31 return 1.0 / (double)(CLK_TCK);
34 int nh_getPID ( void )
36 return (int) getpid();
39 void nh_exitwith ( int code )
44 int nh_system ( char* cmd )
46 return system ( cmd );
49 int nh_iseof ( FILE* f )
54 if (c == EOF) return 1;
59 int nh_filesize ( FILE* f )
63 fstat ( fileno(f), &buf );
73 int nh_stdout ( void )
79 int nh_stderr ( void )
85 int nh_open ( char* fname, int wr )
89 f = fopen ( fname, (wr==0) ? "r": ((wr==1) ? "w" : "a") );
93 void nh_close ( FILE* f )
100 void nh_flush ( FILE* f )
106 void nh_write ( FILE* f, int c )
110 if (f==stderr) { fflush(f); }
111 if (f==stdout) { fflush(f); }
114 int nh_read ( FILE* f )
120 int nh_errno ( void )
127 int nh_malloc ( int n )
133 void nh_free ( int n )
138 void nh_store ( int p, int ch )
140 *(char*)p = (char)ch;
143 int nh_load ( int p )
145 return (int)(*(char*)p);
148 int nh_getenv ( int p )
150 return (int)getenv ( (const char *)p );
157 int nh_init_args ( int argc, char *argv[] )
168 int nh_argvb ( int argno, int offset )
170 return prog_argv[argno][offset];