Changeset 134 for trunk/src/samhain.c
- Timestamp:
- Oct 26, 2007, 12:20:10 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/samhain.c
r133 r134 138 138 #endif 139 139 140 #ifdef HAVE_PTHREAD 141 typedef struct gt { 142 size_t g_count; 143 char * g_glob; 144 }; 145 146 pthread_key_t g_key; 147 148 int sh_g_thread() 149 { 150 struct gt * ptr = malloc(sizeof(struct gt)); 151 if (!gt) 152 return -1; 153 ptr->g_count = 0; 154 ptr->g_glob = calloc(1, SH_MAX_GLOBS * (GLOB_LEN+1)); 155 if (!(ptr->g_glob)) 156 return -1; 157 return pthread_setspecific(g_key, ptr); 158 } 159 160 void sh_g_destroy(void * data) 161 { 162 struct gt * ptr = (struct gt *) data; 163 free(ptr->g_glob); 164 free(ptr); 165 return; 166 } 167 168 static void sh_g_init() 169 { 170 if (0 != pthread_key_create(&g_key, sh_g_destroy)) 171 { 172 perror("1"); 173 exit(EXIT_FAILURE); 174 } 175 176 if (0 != sh_g_thread()) 177 { 178 perror("1"); 179 exit(EXIT_FAILURE); 180 } 181 return; 182 } 183 #define SH_G_INIT sh_g_init() 184 #else 185 #define SH_G_INIT ((void)0) 186 #endif 187 140 188 char * globber(const char * str) 141 189 { … … 143 191 size_t j; 144 192 145 static size_t items = 0; 193 #ifdef HAVE_PTHREAD 194 struct gt * ptr = pthread_getspecific(g_key); 195 size_t count = ptr->g_count; 196 char * glob = ptr->g_glob; 197 #else 146 198 static size_t count = 0; 147 199 static char glob[SH_MAX_GLOBS * (GLOB_LEN+1)]; 200 # 148 201 149 202 if (str == NULL) … … 152 205 j = strlen(str); 153 206 154 ++items;155 156 207 ASSERT((j <= GLOB_LEN), _("j <= GLOB_LEN")) 157 208 … … 164 215 { 165 216 count = 0; 166 items = 0;167 217 } 168 218 … … 177 227 178 228 i = count; 229 #ifdef HAVE_PTHREAD 230 ptr->count = count + j + 1; 231 #else 179 232 count = count + j + 1; 233 #endif 180 234 return &glob[i]; 181 235 } … … 1144 1198 char * my_argv[32]; 1145 1199 #endif 1200 1201 SH_G_INIT; /* Must precede any use of _() */ 1146 1202 1147 1203 SL_ENTER(_("main"));
Note:
See TracChangeset
for help on using the changeset viewer.