home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / ERRNO.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.5 KB  |  107 lines

  1. /*+------------------------------------------------------------------------+
  2.   |                 ERRNO & _DOSERRNO Dynalink module                      |
  3.   +------------------------------------------------------------------------+*/
  4.  
  5. #ifdef  __OS2__
  6.  
  7. #include <os2tc.h>
  8.  
  9. #if defined(__SINGLE_THREAD__)
  10.     /*** Nothing required here ***/
  11. #else
  12. #define    MAX_THREADS    64
  13.  
  14. typedef
  15.     struct errors
  16.         {
  17.         int    err_no;
  18.         int    doserr_no;
  19.         } ERROR;
  20.  
  21. static ERROR array[MAX_THREADS] =
  22.         {
  23.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  24.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  25.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  26.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  27.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  28.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  29.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
  30.         {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}
  31.         };
  32.  
  33. static char first_call = 1;
  34.  
  35. static int far *my_TID;
  36.  
  37.  
  38. #endif
  39.  
  40. /*+------------------------------------------------------------------------+
  41.   |            Stub DLL initialization routine.                   |
  42.   +------------------------------------------------------------------------+
  43.     The WORST case memory requirements for this DLL in theory are:
  44.  
  45.     ((64 threads) * (2 words per thread))
  46.     
  47.     Which ammounts to about 256 bytes.  This's a small enough chunk that
  48.     its reasonable to just take it "up-front" as a static data item.
  49.     This also prevents any other problems later on if a dynamic
  50.     scheme were used and the dynamic block couldn't be grown.
  51.     So in this case there's no heap requirements. We'll make the heap
  52.     as small as possible.
  53.     The startup code handles zapping the static data to zero at the
  54.     start, so there's no elaborate initialization required either.
  55. */
  56.  
  57. #if defined(__SINGLE_THREAD__)
  58.     /*** Nothing required here ***/
  59. #else
  60. void initialize(void)
  61. {
  62.     SEL globalseg, localseg;
  63.  
  64.     DosGetInfoSeg(
  65.         (PSEL) &globalseg,
  66.         (PSEL) &localseg
  67.         );
  68.  
  69.     my_TID = MK_FP(localseg, 6);
  70. }
  71. #endif
  72.  
  73.  
  74. int far * huge __errno(void)
  75. {
  76. #if defined(__SINGLE_THREAD__)
  77.     static    int    val = 0;
  78.     return    &val;
  79. #else
  80.     if (first_call)
  81.         {
  82.         initialize();
  83.         first_call = 0;
  84.         }
  85.  
  86.     return    &array[ (*my_TID)-1 ].err_no;
  87. #endif
  88. }
  89.  
  90. int far * huge __doserrno(void)
  91. {
  92. #if defined(__SINGLE_THREAD__)
  93.     static    int    val = 0;
  94.     return    &val;
  95. #else
  96.     if (first_call)
  97.         {
  98.         initialize();
  99.         first_call = 0;
  100.         }
  101.  
  102.     return    &array[ (*my_TID)-1 ].doserr_no;
  103. #endif
  104. }
  105.  
  106. #endif
  107.