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

  1. /***
  2. *getpid.c - get current process id
  3. *
  4. *       Copyright (c) 1989-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       Defines _getpid() - get current process id
  8. *
  9. *******************************************************************************/
  10.  
  11. #ifndef _MAC
  12.  
  13. #include <cruntime.h>
  14. #include <oscalls.h>
  15.  
  16. /***
  17. *int _getpid() - get current process id
  18. *
  19. *Purpose:
  20. *       Returns the current process id for the calling process.
  21. *
  22. *Entry:
  23. *       None.
  24. *
  25. *Exit:
  26. *       Returns the current process id.
  27. *
  28. *Uses:
  29. *
  30. *Exceptions:
  31. *
  32. *******************************************************************************/
  33.  
  34. int __cdecl _getpid (
  35.         void
  36.         )
  37. {
  38.         return GetCurrentProcessId();
  39. }
  40.  
  41. #else  /* _MAC */
  42.  
  43.  
  44. #include <cruntime.h>
  45. #include <internal.h>
  46. #include <stdio.h>
  47. #include <io.h>
  48. #include <errno.h>
  49. #include <stddef.h>
  50. #include <macos\errors.h>
  51. #include <macos\processe.h>
  52. #include <macos\gestalte.h>
  53. #include <macos\osutils.h>
  54. #include <macos\traps.h>
  55. #include <macos\toolutil.h>
  56. #include <macos\memory.h>
  57.  
  58. /***
  59. *int _getpid() - get current process id
  60. *
  61. *Purpose:
  62. *       Returns the current process id for the calling process.
  63. *
  64. *Entry:
  65. *       None.
  66. *
  67. *Exit:
  68. *       Returns the current process id.
  69. *
  70. *Uses:
  71. *
  72. *Exceptions:
  73. *
  74. *******************************************************************************/
  75. extern time_t _GetApplicationStartTime();
  76.  
  77. int __cdecl _getpid (
  78.         void
  79.         )
  80. {
  81.         ProcessSerialNumber psn;
  82.         REG3 unsigned number;
  83.  
  84.  
  85.         if (__TrapFromGestalt(gestaltOSAttr, gestaltLaunchControl))
  86.         {
  87.             GetCurrentProcess(&psn);
  88.             number = (unsigned) psn.lowLongOfPSN;
  89.         }
  90.         else
  91.         {
  92.             number = (unsigned)_GetApplicationStartTime();
  93.         }
  94.         return number;
  95.  
  96. }
  97.  
  98. #endif  /* _MAC */
  99.