acldllmain.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. * END COPYRIGHT BLOCK **/
  6. #include "acl.h"
  7. #ifdef _WIN32
  8. /* Lifted from Q125688
  9. * How to Port a 16-bit DLL to a Win32 DLL
  10. * on the MSVC 4.0 CD
  11. */
  12. BOOL WINAPI DllMain (HANDLE hModule, DWORD fdwReason, LPVOID lpReserved)
  13. {
  14. WSADATA wsadata;
  15. switch (fdwReason)
  16. {
  17. case DLL_PROCESS_ATTACH:
  18. /* Code from LibMain inserted here. Return TRUE to keep the
  19. DLL loaded or return FALSE to fail loading the DLL.
  20. You may have to modify the code in your original LibMain to
  21. account for the fact that it may be called more than once.
  22. You will get one DLL_PROCESS_ATTACH for each process that
  23. loads the DLL. This is different from LibMain which gets
  24. called only once when the DLL is loaded. The only time this
  25. is critical is when you are using shared data sections.
  26. If you are using shared data sections for statically
  27. allocated data, you will need to be careful to initialize it
  28. only once. Check your code carefully.
  29. Certain one-time initializations may now need to be done for
  30. each process that attaches. You may also not need code from
  31. your original LibMain because the operating system may now
  32. be doing it for you.
  33. */
  34. /*
  35. * 16 bit code calls UnlockData()
  36. * which is mapped to UnlockSegment in windows.h
  37. * in 32 bit world UnlockData is not defined anywhere
  38. * UnlockSegment is mapped to GlobalUnfix in winbase.h
  39. * and the docs for both UnlockSegment and GlobalUnfix say
  40. * ".. function is oboslete. Segments have no meaning
  41. * in the 32-bit environment". So we do nothing here.
  42. */
  43. if( errno = WSAStartup(0x0101, &wsadata ) != 0 )
  44. return FALSE;
  45. break;
  46. case DLL_THREAD_ATTACH:
  47. /* Called each time a thread is created in a process that has
  48. already loaded (attached to) this DLL. Does not get called
  49. for each thread that exists in the process before it loaded
  50. the DLL.
  51. Do thread-specific initialization here.
  52. */
  53. break;
  54. case DLL_THREAD_DETACH:
  55. /* Same as above, but called when a thread in the process
  56. exits.
  57. Do thread-specific cleanup here.
  58. */
  59. break;
  60. case DLL_PROCESS_DETACH:
  61. /* Code from _WEP inserted here. This code may (like the
  62. LibMain) not be necessary. Check to make certain that the
  63. operating system is not doing it for you.
  64. */
  65. WSACleanup();
  66. break;
  67. }
  68. /* The return value is only used for DLL_PROCESS_ATTACH; all other
  69. conditions are ignored. */
  70. return TRUE; // successful DLL_PROCESS_ATTACH
  71. }
  72. #else
  73. int CALLBACK
  74. LibMain( HINSTANCE hinst, WORD wDataSeg, WORD cbHeapSize, LPSTR lpszCmdLine )
  75. {
  76. /*UnlockData( 0 );*/
  77. return( 1 );
  78. }
  79. #endif
  80. #ifdef LDAP_DEBUG
  81. #ifndef _WIN32
  82. #include <stdarg.h>
  83. #include <stdio.h>
  84. void LDAPDebug( int level, char* fmt, ... )
  85. {
  86. static char debugBuf[1024];
  87. if (module_ldap_debug && (*module_ldap_debug & level))
  88. {
  89. va_list ap;
  90. va_start (ap, fmt);
  91. _snprintf (debugBuf, sizeof(debugBuf), fmt, ap);
  92. va_end (ap);
  93. OutputDebugString (debugBuf);
  94. }
  95. }
  96. #endif
  97. #endif
  98. #ifndef _WIN32
  99. /* The 16-bit version of the RTL does not implement perror() */
  100. #include <stdio.h>
  101. void perror( const char *msg )
  102. {
  103. char buf[128];
  104. wsprintf( buf, "%s: error %d\n", msg, WSAGetLastError()) ;
  105. OutputDebugString( buf );
  106. }
  107. #endif