X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Finterpreter%2FnHandle.c;h=ecc5f8f3bfc0386f47b29cdcecd9286c9fd04e31;hb=040b364027e72aead0c91c585572182add60a3dd;hp=1e601b9f3e88e39fa9b3655705b24896bdcada05;hpb=8931116063aaf06ed2759e2b2ca2e554cfa7124f;p=ghc-hetmet.git diff --git a/ghc/interpreter/nHandle.c b/ghc/interpreter/nHandle.c index 1e601b9..ecc5f8f 100644 --- a/ghc/interpreter/nHandle.c +++ b/ghc/interpreter/nHandle.c @@ -7,6 +7,85 @@ #include #include #include +#include +#include +#ifndef _WIN32 +#include +#include +#include +#include +#endif +#include + +#ifndef _WIN32 +double nh_getCPUtime ( void ) +{ + double usertime; + struct rusage usage; + getrusage ( RUSAGE_SELF, &usage ); + usertime = (double)usage.ru_utime.tv_sec + + (double)usage.ru_utime.tv_usec / 1000000.0; + return usertime; +} + +double nh_getCPUprec ( void ) +{ + /* or perhaps CLOCKS_PER_SEC ? */ + return 1.0 / (double)(CLK_TCK); +} +#else +double nh_getCPUtime ( void ) +{ + return 1; +} + +double nh_getCPUprec ( void ) +{ + return 1; +} +#endif + +int nh_getPID ( void ) +{ +#ifndef _WIN32 + return (int) getpid(); +#else + return (int) 0; +#endif +} + +void nh_exitwith ( int code ) +{ + exit(code); +} + +int nh_system ( char* cmd ) +{ + return system ( cmd ); +} + +int nh_iseof ( FILE* f ) +{ + int c; + errno = 0; + c = fgetc ( f ); + if (c == EOF) return 1; + ungetc ( c, f ); + return 0; +} + +int nh_filesize ( FILE* f ) +{ +#ifndef _WIN32 + struct stat buf; + errno = 0; + fstat ( fileno(f), &buf ); + return buf.st_size; +#else + errno = EPERM; + return 0; +#endif +} int nh_stdin ( void ) { @@ -20,6 +99,12 @@ int nh_stdout ( void ) return (int)stdout; } +int nh_stderr ( void ) +{ + errno = 0; + return (int)stderr; +} + int nh_open ( char* fname, int wr ) { FILE* f; @@ -35,11 +120,18 @@ void nh_close ( FILE* f ) fclose ( f ); } +void nh_flush ( FILE* f ) +{ + errno = 0; + fflush ( f ); +} + void nh_write ( FILE* f, int c ) { errno = 0; fputc(c,f); - fflush(f); + if (f==stderr) { fflush(f); } + if (f==stdout) { fflush(f); } } int nh_read ( FILE* f ) @@ -50,13 +142,14 @@ int nh_read ( FILE* f ) int nh_errno ( void ) { - return errno; + int t = errno; + errno = 0; + return t; } int nh_malloc ( int n ) { char* p = malloc(n); - assert(p); return (int)p; } @@ -65,7 +158,18 @@ void nh_free ( int n ) free ( (char*)n ); } -void nh_assign ( int p, int offset, int ch ) +void nh_store ( int p, int ch ) { - ((char*)p)[offset] = (char)ch; + *(char*)p = (char)ch; } + +int nh_load ( int p ) +{ + return (int)(*(char*)p); +} + +int nh_getenv ( int p ) +{ + return (int)getenv ( (const char *)p ); +} +