Klaus Demo nginx / 2afdfdc
fix win32 glob Igor Sysoev 14 years ago
2 changed file(s) with 47 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
326326 ngx_int_t
327327 ngx_open_glob(ngx_glob_t *gl)
328328 {
329 u_char *p;
330 size_t len;
331
329332 gl->dir = FindFirstFile((const char *) gl->pattern, &gl->finddata);
330333
331334 if (gl->dir == INVALID_HANDLE_VALUE) {
332335 return NGX_ERROR;
333336 }
334337
338 for (p = gl->pattern; *p; p++) {
339 if (*p == '/') {
340 gl->last = p + 1 - gl->pattern;
341 }
342 }
343
344 len = ngx_strlen(gl->finddata.cFileName);
345 gl->name.len = gl->last + len;
346
347 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log);
348 if (gl->name.data == NULL) {
349 return NGX_ERROR;
350 }
351
352 ngx_memcpy(gl->name.data, gl->pattern, gl->last);
353 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName,
354 len + 1);
355
335356 gl->ready = 1;
336357
337358 return NGX_OK;
341362 ngx_int_t
342363 ngx_read_glob(ngx_glob_t *gl, ngx_str_t *name)
343364 {
365 size_t len;
344366 ngx_err_t err;
345367
346368 if (gl->ready) {
347 name->len = ngx_strlen(gl->finddata.cFileName);
348 name->data = (u_char *) gl->finddata.cFileName;
369 *name = gl->name;
349370
350371 gl->ready = 0;
351372 return NGX_OK;
352373 }
353374
375 ngx_free(gl->name.data);
376 gl->name.data = NULL;
377
354378 if (FindNextFile(gl->dir, &gl->finddata) != 0) {
355 name->len = ngx_strlen(gl->finddata.cFileName);
356 name->data = (u_char *) gl->finddata.cFileName;
379
380 len = ngx_strlen(gl->finddata.cFileName);
381 gl->name.len = gl->last + len;
382
383 gl->name.data = ngx_alloc(gl->name.len + 1, gl->log);
384 if (gl->name.data == NULL) {
385 return NGX_ERROR;
386 }
387
388 ngx_memcpy(gl->name.data, gl->pattern, gl->last);
389 ngx_cpystrn(gl->name.data + gl->last, (u_char *) gl->finddata.cFileName,
390 len + 1);
391
392 *name = gl->name;
357393
358394 return NGX_OK;
359395 }
374410 void
375411 ngx_close_glob(ngx_glob_t *gl)
376412 {
377 if (FindClose(gl->dir) != 0) {
413 if (gl->name.data) {
414 ngx_free(gl->name.data);
415 }
416
417 if (FindClose(gl->dir) == 0) {
378418 ngx_log_error(NGX_LOG_ALERT, gl->log, ngx_errno,
379419 "FindClose(%s) failed", gl->pattern);
380420 }
184184 WIN32_FIND_DATA finddata;
185185 ngx_int_t ready;
186186 u_char *pattern;
187 ngx_str_t name;
188 size_t last;
187189 ngx_log_t *log;
188190 } ngx_glob_t;
189191