xref: /PHP-7.1/win32/dllmain.c (revision 03f3b847)
1 /*
2    +----------------------------------------------------------------------+
3    | PHP Version 7                                                        |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1997-2018 The PHP Group                                |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 3.01 of the PHP license,      |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.php.net/license/3_01.txt                                  |
11    | If you did not receive a copy of the PHP license and are unable to   |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@php.net so we can mail you a copy immediately.               |
14    +----------------------------------------------------------------------+
15    | Authors: Anatol Belski <ab@php.net>                                  |
16    +----------------------------------------------------------------------+
17  */
18 
19 #include <config.w32.h>
20 
21 #include <win32/time.h>
22 #include <win32/ioutil.h>
23 #include <php.h>
24 
25 #ifdef HAVE_LIBXML
26 #include <libxml/threads.h>
27 #endif
28 
29 /* TODO this file, or part of it, could be machine generated, to
30 	allow extensions and SAPIs adding their own init stuff.
31 	However expected is that MINIT is enough in most cases.
32 	This file is only useful for some really internal stuff,
33 	eq. initializing something before the DLL even is
34 	available to be called. */
35 
DllMain(HINSTANCE inst,DWORD reason,LPVOID dummy)36 BOOL WINAPI DllMain(HINSTANCE inst, DWORD reason, LPVOID dummy)
37 {
38 	BOOL ret = TRUE;
39 
40 	switch (reason)
41 	{
42 		case DLL_PROCESS_ATTACH:
43 			ret = ret && php_win32_init_gettimeofday();
44 			if (!ret) {
45 				fprintf(stderr, "gettimeofday() initialization failed");
46 				return ret;
47 			}
48 
49 			ret = ret && php_win32_ioutil_init();
50 			if (!ret) {
51 				fprintf(stderr, "ioutil initialization failed");
52 				return ret;
53 			}
54 			break;
55 #if 0 /* prepared */
56 		case DLL_PROCESS_DETACH:
57 			/* pass */
58 			break;
59 
60 		case DLL_THREAD_ATTACH:
61 			/* pass */
62 			break;
63 
64 		case DLL_THREAD_DETACH:
65 			/* pass */
66 			break;
67 #endif
68 	}
69 
70 #ifdef HAVE_LIBXML
71 	/* This imply that only LIBXML_STATIC_FOR_DLL is supported ATM.
72 		If that changes, this place will need some rework.
73 	   TODO Also this should be revisited as no initialization
74 		might be needed for TS build (libxml build with TLS
75 		support. */
76 	ret = ret && xmlDllMain(inst, reason, dummy);
77 #endif
78 
79 	return ret;
80 }
81