home *** CD-ROM | disk | FTP | other *** search
- /*+------------------------------------------------------------------------+
- | ERRNO & _DOSERRNO Dynalink module |
- +------------------------------------------------------------------------+*/
-
- #ifdef __OS2__
-
- #include <os2tc.h>
-
- #if defined(__SINGLE_THREAD__)
- /*** Nothing required here ***/
- #else
- #define MAX_THREADS 64
-
- typedef
- struct errors
- {
- int err_no;
- int doserr_no;
- } ERROR;
-
- static ERROR array[MAX_THREADS] =
- {
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},
- {0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0},{0,0}
- };
-
- static char first_call = 1;
-
- static int far *my_TID;
-
-
- #endif
-
- /*+------------------------------------------------------------------------+
- | Stub DLL initialization routine. |
- +------------------------------------------------------------------------+
- The WORST case memory requirements for this DLL in theory are:
-
- ((64 threads) * (2 words per thread))
-
- Which ammounts to about 256 bytes. This's a small enough chunk that
- its reasonable to just take it "up-front" as a static data item.
- This also prevents any other problems later on if a dynamic
- scheme were used and the dynamic block couldn't be grown.
- So in this case there's no heap requirements. We'll make the heap
- as small as possible.
- The startup code handles zapping the static data to zero at the
- start, so there's no elaborate initialization required either.
- */
-
- #if defined(__SINGLE_THREAD__)
- /*** Nothing required here ***/
- #else
- void initialize(void)
- {
- SEL globalseg, localseg;
-
- DosGetInfoSeg(
- (PSEL) &globalseg,
- (PSEL) &localseg
- );
-
- my_TID = MK_FP(localseg, 6);
- }
- #endif
-
-
- int far * huge __errno(void)
- {
- #if defined(__SINGLE_THREAD__)
- static int val = 0;
- return &val;
- #else
- if (first_call)
- {
- initialize();
- first_call = 0;
- }
-
- return &array[ (*my_TID)-1 ].err_no;
- #endif
- }
-
- int far * huge __doserrno(void)
- {
- #if defined(__SINGLE_THREAD__)
- static int val = 0;
- return &val;
- #else
- if (first_call)
- {
- initialize();
- first_call = 0;
- }
-
- return &array[ (*my_TID)-1 ].doserr_no;
- #endif
- }
-
- #endif