1 /* This file is part of Netwib. Read and honor its license. 2 */ 3 4 /*-------------------------------------------------------------*/ 5 /*-------------------------------------------------------------*/ 6 netwib_priv_glovars_t netwib_priv_glovars; 7 8 9 /*-------------------------------------------------------------*/ 10 /*-------------------------------------------------------------*/ 11 netwib_priv_mutex netwib_priv_glovars_other_mut; 12 13 /*-------------------------------------------------------------*/ netwib_priv_glovars_other_init(void)14static netwib_err netwib_priv_glovars_other_init(void) 15 { 16 netwib_er(netwib_priv_mutex_init(&netwib_priv_glovars_other_mut)); 17 return(NETWIB_ERR_OK); 18 } 19 20 /*-------------------------------------------------------------*/ netwib_priv_glovars_other_close(void)21static netwib_err netwib_priv_glovars_other_close(void) 22 { 23 netwib_er(netwib_priv_mutex_close(&netwib_priv_glovars_other_mut)); 24 return(NETWIB_ERR_OK); 25 } 26 27 /*-------------------------------------------------------------*/ netwib_priv_glovars_other_rdlock(void)28netwib_err netwib_priv_glovars_other_rdlock(void) 29 { 30 return(netwib_priv_mutex_rdlock(&netwib_priv_glovars_other_mut)); 31 } 32 33 /*-------------------------------------------------------------*/ netwib_priv_glovars_other_rdunlock(void)34netwib_err netwib_priv_glovars_other_rdunlock(void) 35 { 36 return(netwib_priv_mutex_rdunlock(&netwib_priv_glovars_other_mut)); 37 } 38 39 /*-------------------------------------------------------------*/ netwib_priv_glovars_other_wrlock(void)40netwib_err netwib_priv_glovars_other_wrlock(void) 41 { 42 return(netwib_priv_mutex_wrlock(&netwib_priv_glovars_other_mut)); 43 } 44 45 /*-------------------------------------------------------------*/ netwib_priv_glovars_other_wrunlock(void)46netwib_err netwib_priv_glovars_other_wrunlock(void) 47 { 48 return(netwib_priv_mutex_wrunlock(&netwib_priv_glovars_other_mut)); 49 } 50 51 /*-------------------------------------------------------------*/ 52 /*-------------------------------------------------------------*/ 53 netwib_priv_mutex netwib_priv_glovars_mut; 54 55 /*-------------------------------------------------------------*/ 56 /* this define is here because I have a script checking if 57 netwib contains MT-unsafe functions. Like this, they are ignored. */ 58 #define netwib_c_localtime localtime 59 60 /*-------------------------------------------------------------*/ 61 netwib_bool netwib_priv_glovars_initialized = NETWIB_FALSE; netwib_priv_glovars_init(void)62netwib_err netwib_priv_glovars_init(void) 63 { 64 struct tm *ptm; 65 time_t tt; 66 67 /* set global parameters */ 68 netwib_er(netwib_buf_init_mallocdefault(&netwib_priv_glovars.errmsg)); 69 netwib_er(netwib_priv_rand_seed(&netwib_priv_glovars.rand_seed)); 70 71 /* debug */ 72 netwib_priv_glovars.debug_ctrlc_pressed = NETWIB_FALSE; 73 74 /* timezone */ 75 tt = time(NULL); 76 ptm = netwib_c_localtime(&tt); 77 netwib_priv_glovars.time_isdst = (ptm->tm_isdst>0)?NETWIB_TRUE:NETWIB_FALSE; 78 #if defined NETWIBDEF_SYSNAME_Unix 79 #if NETWIBDEF_HAVEFIELD_TM_GMTOFF == 1 80 netwib_priv_glovars.time_zoneoffset = ptm->tm_gmtoff; 81 #else 82 netwib_priv_glovars.time_zoneoffset = -timezone; 83 if (netwib_priv_glovars.time_isdst) { 84 netwib_priv_glovars.time_zoneoffset += 3600; 85 } 86 #endif 87 #elif defined NETWIBDEF_SYSNAME_Windows 88 netwib_priv_glovars.time_zoneoffset = -_timezone; 89 if (netwib_priv_glovars.time_isdst) { 90 netwib_priv_glovars.time_zoneoffset += 3600; 91 } 92 #endif 93 94 /* other */ 95 netwib_er(netwib_priv_glovars_other_init()); 96 97 netwib_er(netwib_priv_mutex_init(&netwib_priv_glovars_mut)); 98 99 netwib_er(netwib_priv_conf_init()); 100 101 netwib_priv_glovars_initialized = NETWIB_TRUE; 102 return(NETWIB_ERR_OK); 103 } 104 105 /*-------------------------------------------------------------*/ netwib_priv_glovars_close(void)106netwib_err netwib_priv_glovars_close(void) 107 { 108 netwib_er(netwib_priv_conf_close()); 109 110 netwib_er(netwib_priv_mutex_close(&netwib_priv_glovars_mut)); 111 112 netwib_er(netwib_priv_glovars_other_close()); 113 114 netwib_er(netwib_buf_close(&netwib_priv_glovars.errmsg)); 115 116 return(NETWIB_ERR_OK); 117 } 118 119 /*-------------------------------------------------------------*/ netwib_priv_glovars_rdlock(void)120netwib_err netwib_priv_glovars_rdlock(void) 121 { 122 return(netwib_priv_mutex_rdlock(&netwib_priv_glovars_mut)); 123 } 124 125 /*-------------------------------------------------------------*/ netwib_priv_glovars_rdunlock(void)126netwib_err netwib_priv_glovars_rdunlock(void) 127 { 128 return(netwib_priv_mutex_rdunlock(&netwib_priv_glovars_mut)); 129 } 130 131 /*-------------------------------------------------------------*/ netwib_priv_glovars_wrlock(void)132netwib_err netwib_priv_glovars_wrlock(void) 133 { 134 return(netwib_priv_mutex_wrlock(&netwib_priv_glovars_mut)); 135 } 136 137 /*-------------------------------------------------------------*/ netwib_priv_glovars_wrunlock(void)138netwib_err netwib_priv_glovars_wrunlock(void) 139 { 140 return(netwib_priv_mutex_wrunlock(&netwib_priv_glovars_mut)); 141 } 142 143 /*-------------------------------------------------------------*/ netwib_priv_glovars_canuse(netwib_bool * pyes)144netwib_err netwib_priv_glovars_canuse(netwib_bool *pyes) 145 { 146 netwib_bool yes; 147 148 yes = NETWIB_FALSE; 149 if (netwib_priv_glovars_initialized) { 150 yes = NETWIB_TRUE; 151 } 152 153 if (pyes != NULL) *pyes = yes; 154 return(NETWIB_ERR_OK); 155 } 156