home *** CD-ROM | disk | FTP | other *** search
/ Oracle Video Server 3.0.3.1 / OVS_3031_NT.iso / win32 / sqlnet / net23 / client / util.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-17  |  3.0 KB  |  161 lines

  1. /*
  2.   $Header: /netrcs/RCS/oracle/network/tns/tnsapi/RCS/util.c,v 1.4 1995/09/13 06:57:30 yzheng Exp $
  3. */
  4.  
  5. /*
  6.  * Error handling and reporting routines
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <varargs.h>
  11. #ifndef WIN32
  12. #include <sys/time.h>
  13. #else
  14. #include <time.h>
  15. #endif
  16.  
  17. #ifdef WIN32
  18. static time_t time_start, time_stop; /* for real time */
  19. #else
  20. static struct timeval time_start, time_stop; /* for real time */
  21. #endif
  22. static double start, stop, seconds;
  23.  
  24. char *sys_err_str();
  25.  
  26. /*
  27.  * Fatal error. Print a message, dump core
  28.  */
  29.  
  30. err_dump(va_alist)
  31. va_dcl
  32. {
  33.   va_list args;
  34.   char *fmt;
  35.  
  36.   va_start(args);
  37.   fmt = va_arg(args, char *);
  38.   vfprintf(stderr, fmt, args);
  39.   va_end(args);
  40.  
  41.   fprintf(stderr, "%s \n", sys_err_str());
  42.  
  43.   fflush(stdout);  /* abort does not flush stdio buffers */
  44.   fflush(stderr);
  45.   abort();      /* dump core and terminate */
  46.   exit(1);      /* should not get here */
  47. }
  48.  
  49.  
  50. /*
  51.  * Fatal error related to a system call. Print a message and terminate.
  52.  */
  53. err_sys(va_alist)
  54. va_dcl
  55. {
  56.   va_list args;
  57.   char *fmt;
  58.  
  59.   va_start(args);
  60.   fmt = va_arg(args, char *);
  61.   vfprintf(stderr, fmt, args);
  62.   va_end(args);
  63.  
  64.   fprintf(stderr, "%s \n", sys_err_str());
  65.  
  66.   exit(1);
  67. }
  68.  
  69. /*
  70.  * Print a message and return to caller
  71.  */
  72. void err_ret(va_alist)
  73. va_dcl
  74. {
  75.   va_list args;
  76.   char *fmt;
  77.  
  78.   va_start(args);
  79.   fmt = va_arg(args, char *);
  80.   vfprintf(stderr, fmt, args);
  81.   va_end(args);
  82.  
  83.   fprintf(stderr, "%s \n", sys_err_str());
  84.  
  85.   fflush(stdout);
  86.   fflush(stderr);
  87.   return;
  88. }
  89.  
  90. /*
  91.  * return a string containing some additional operating-system dependent
  92.  * information. 
  93.  */
  94. #ifndef WIN32
  95. extern int errno;     /* UNIX errno number */
  96. extern int sys_nerr;  /* # of error message strings in sys table */
  97. extern char *sys_errlist[]; /* the system error message table */
  98. #endif
  99. char * sys_err_str()
  100. {
  101.   static char msgstr[1024];
  102. #ifndef WIN32  
  103.   if (errno != 0)
  104.   {
  105.     if (errno > 0 && errno < sys_nerr)
  106.       sprintf(msgstr, "(%s)", sys_errlist[errno]);
  107.     else
  108.       sprintf(msgstr, "(errno = %d)", errno);
  109.   }
  110.   else
  111.   {
  112.     msgstr[0] = '\0';
  113.   }
  114. #endif
  115.   return(msgstr);
  116. }
  117.  
  118. /*
  119.  * start the time,
  120.  * save some info for the stop timer to use 
  121.  */
  122. void t_start()
  123. {
  124. #ifdef WIN32
  125.   time_start = time(NULL) ;
  126. #else
  127.   if (gettimeofday(&time_start, (struct timezone *)0) < 0)
  128.     err_sys("t_start: gettimeofday() error");
  129. #endif
  130. }
  131.  
  132. /* 
  133.  * stop the timeer and save appropiate info
  134.  */
  135. void t_stop()
  136. {
  137. #ifdef WIN32
  138.   time_stop = time(NULL) ;
  139. #else
  140.   if (gettimeofday(&time_stop, (struct timezone *)0) < 0)
  141.     err_sys("t_stop: gettimeofday() error");
  142. #endif
  143. }
  144.  
  145. /*
  146.  * return the real elapsed time in seconds
  147.  */
  148. double t_getrtime()
  149. {
  150. #ifdef WIN32
  151.   seconds = (double)(time_stop - time_start)  ;
  152. #else
  153.   start = ((double)time_start.tv_sec)* 1000000.0 + time_start.tv_usec;
  154.   stop =  ((double)time_stop.tv_sec) * 1000000.0 + time_stop.tv_usec;
  155.   seconds = (stop - start) / 1000000.0;
  156. #endif
  157.   return (seconds);
  158. }
  159.  
  160.    
  161.