1 /* 2 NETWIB 3 Network library 4 Copyright(c) 1999-2010 Laurent Constantin 5 ----- 6 7 Main server : http://www.laurentconstantin.com/ 8 Backup server : http://laurentconstantin.free.fr/ 9 [my current email address is on the web servers] 10 11 ----- 12 This file is part of Netwib. 13 14 Netwib is free software: you can redistribute it and/or modify 15 it under the terms of the GNU General Public License version 3 16 as published by the Free Software Foundation. 17 18 Netwib is distributed in the hope that it will be useful, 19 but WITHOUT ANY WARRANTY; without even the implied warranty of 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 GNU General Public License for more details (http://www.gnu.org/). 22 23 ------------------------------------------------------------------------ 24 */ 25 26 #include <netwib/inc/maininc.h> 27 28 29 /*-------------------------------------------------------------*/ 30 netwib_bool netwib_priv_netwibwasinitialized = NETWIB_FALSE; netwib_init2(void)31static netwib_err netwib_init2(void) 32 { 33 /* ignore double initialization */ 34 if (netwib_priv_netwibwasinitialized) { 35 return(NETWIB_ERR_OK); 36 } 37 netwib_priv_netwibwasinitialized = NETWIB_TRUE; 38 39 #if NETWIB_DEBUG == 1 40 netwib_er(netwib_debug_glovars_init()); 41 netwib_er(netwib_debug_fdopen_init()); 42 netwib_er(netwib_debug_leak_init()); 43 netwib_er(netwib_debug_memcorrupt_init()); 44 netwib_er(netwib_debug_sighdl_init()); 45 #endif 46 47 netwib_er(netwib_priv_glovars_init()); 48 49 #if defined NETWIBDEF_SYSNAME_Unix 50 #elif defined NETWIBDEF_SYSNAME_Windows 51 netwib_er(netwib_priv_cs_init()); 52 /* init winsock 1.1 */ 53 netwib_er(netwib_priv_winsock_init()); 54 /* load dlls */ 55 netwib_er(netwib_priv_dll_init()); 56 #else 57 #error "Unknown value for NETWIBDEF_SYSNAME" 58 #endif 59 60 return(NETWIB_ERR_OK); 61 } 62 63 /*-------------------------------------------------------------*/ netwib_init(void)64netwib_err netwib_init(void) 65 { 66 netwib_err ret; 67 68 ret = netwib_init2(); 69 if (ret != NETWIB_ERR_OK) { 70 netwib_er(netwib_priv_notify_err(NETWIB_PRIV_NOTIFYTYPE_EMERG, ret)); 71 } 72 73 return(ret); 74 } 75 76 /*-------------------------------------------------------------*/ netwib_close2(void)77static netwib_err netwib_close2(void) 78 { 79 /* ignore double close */ 80 if (!netwib_priv_netwibwasinitialized) { 81 return(NETWIB_ERR_OK); 82 } 83 netwib_priv_netwibwasinitialized = NETWIB_FALSE; 84 85 #if defined NETWIBDEF_SYSNAME_Unix 86 #elif defined NETWIBDEF_SYSNAME_Windows 87 netwib_er(netwib_priv_dll_close()); 88 netwib_er(netwib_priv_winsock_close()); 89 netwib_er(netwib_priv_cs_close()); 90 #else 91 #error "Unknown value for NETWIBDEF_SYSNAME" 92 #endif 93 94 netwib_er(netwib_priv_glovars_close()); 95 96 #if NETWIB_DEBUG == 1 97 netwib_er(netwib_debug_sighdl_close()); 98 netwib_er(netwib_debug_leak_report()); 99 netwib_er(netwib_debug_leak_close()); 100 netwib_er(netwib_debug_memcorrupt_check_all()); 101 netwib_er(netwib_debug_memcorrupt_close()); 102 netwib_er(netwib_debug_fdopen_check()); 103 netwib_er(netwib_debug_glovars_close()); 104 #endif 105 106 return(NETWIB_ERR_OK); 107 } 108 109 /*-------------------------------------------------------------*/ netwib_close(void)110netwib_err netwib_close(void) 111 { 112 netwib_err ret; 113 114 ret = netwib_close2(); 115 if (ret != NETWIB_ERR_OK) { 116 netwib_er(netwib_priv_notify_err(NETWIB_PRIV_NOTIFYTYPE_EMERG, ret)); 117 } 118 119 return(ret); 120 } 121