home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / crt / src / mterrno.c < prev    next >
C/C++ Source or Header  |  1998-06-17  |  2KB  |  73 lines

  1. /***
  2. *mterrno.c - provide function versions of errno & _doserrno for LIBC.LIB
  3. *
  4. *       Copyright (c) 1994-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Sometimes users want to compile code (such as for use in a library)
  8. *       for both single-thread and multi-thread applications.  Currently the
  9. *       one major stumbling block to doing this is the fact that errno &
  10. *       _doserrno are defined in different ways in LIBC.LIB and LIBCMT.LIB.
  11. *       Code that should otherwise be usable with both LIBC.LIB and LIBCMT.LIB
  12. *       but which accesses errno and/or _doserrno is not usable with both.
  13. *       By providing the function versions of errno & _doserrno in LIBC.LIB,
  14. *       users can compile their code for both LIBCMT.LIB and LIBC.LIB.
  15. *       Note that this does not magically make single-thread code safe in a
  16. *       multi-threaded environment, it merely makes it easier to use the
  17. *       same code with LIBC.LIB and LIBCMT.LIB.
  18. *
  19. *******************************************************************************/
  20.  
  21. #ifndef _MT
  22.  
  23. /* Get the definitions of the function versions of errno/_doserrno */
  24.  
  25. #define _MT
  26. #include <stdlib.h>
  27. #undef _MT
  28.  
  29. /* undo the macros that convert the variable names to function calls */
  30.  
  31. #undef errno
  32. #undef _doserrno
  33.  
  34. /* declare the variables - must match the definitions in <STDLIB.H> */
  35.  
  36. extern int errno;                       /* XENIX style error number */
  37. extern unsigned long _doserrno;         /* OS system error value */
  38.  
  39.  
  40. /***
  41. *int * _errno()                 - return pointer to thread's errno
  42. *unsigned long * __doserrno()   - return pointer to thread's _doserrno
  43. *
  44. *Purpose:
  45. *       _errno() returns a pointer to the global variable errno
  46. *       __doserrno returns a pointer to the global variable _doserrno
  47. *
  48. *Entry:
  49. *       None.
  50. *
  51. *Exit:
  52. *       See above.
  53. *
  54. *Exceptions:
  55. *
  56. *******************************************************************************/
  57.  
  58. int * __cdecl _errno(
  59.         void
  60.         )
  61. {
  62.         return & errno;
  63. }
  64.  
  65. unsigned long * __cdecl __doserrno(
  66.         void
  67.         )
  68. {
  69.         return & _doserrno;
  70. }
  71.  
  72. #endif  /* _MT */
  73.