|
Lines 131-137
struct glob_lim {
Link Here
|
| 131 |
size_t glim_readdir; |
131 |
size_t glim_readdir; |
| 132 |
}; |
132 |
}; |
| 133 |
|
133 |
|
|
|
134 |
struct glob_path_stat { |
| 135 |
char *gps_path; |
| 136 |
struct stat *gps_stat; |
| 137 |
}; |
| 138 |
|
| 134 |
static int compare(const void *, const void *); |
139 |
static int compare(const void *, const void *); |
|
|
140 |
static int compare_gps(const void *, const void *); |
| 135 |
static int g_Ctoc(const Char *, char *, u_int); |
141 |
static int g_Ctoc(const Char *, char *, u_int); |
| 136 |
static int g_lstat(Char *, struct stat *, glob_t *); |
142 |
static int g_lstat(Char *, struct stat *, glob_t *); |
| 137 |
static DIR *g_opendir(Char *, glob_t *); |
143 |
static DIR *g_opendir(Char *, glob_t *); |
|
Lines 538-546
glob0(const Char *pattern, glob_t *pglob
Link Here
|
| 538 |
else |
544 |
else |
| 539 |
return(GLOB_NOMATCH); |
545 |
return(GLOB_NOMATCH); |
| 540 |
} |
546 |
} |
| 541 |
if (!(pglob->gl_flags & GLOB_NOSORT)) |
547 |
if (!(pglob->gl_flags & GLOB_NOSORT)) { |
| 542 |
qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, |
548 |
if ((pglob->gl_flags & GLOB_KEEPSTAT)) { |
| 543 |
pglob->gl_pathc - oldpathc, sizeof(char *), compare); |
549 |
/* Keep the paths and stat info synced during sort */ |
|
|
550 |
struct glob_path_stat *path_stat; |
| 551 |
int i; |
| 552 |
int n = pglob->gl_pathc - oldpathc; |
| 553 |
int o = pglob->gl_offs + oldpathc; |
| 554 |
|
| 555 |
if ((path_stat = calloc(n, sizeof(*path_stat))) == NULL) |
| 556 |
return 0; /* return unsorted on alloc failure */ |
| 557 |
for (i = 0; i < n; i++) { |
| 558 |
path_stat[i].gps_path = pglob->gl_pathv[o + i]; |
| 559 |
path_stat[i].gps_stat = pglob->gl_statv[o + i]; |
| 560 |
} |
| 561 |
qsort(path_stat, n, sizeof(*path_stat), compare_gps); |
| 562 |
for (i = 0; i < n; i++) { |
| 563 |
pglob->gl_pathv[o + i] = path_stat[i].gps_path; |
| 564 |
pglob->gl_statv[o + i] = path_stat[i].gps_stat; |
| 565 |
} |
| 566 |
free(path_stat); |
| 567 |
} else { |
| 568 |
qsort(pglob->gl_pathv + pglob->gl_offs + oldpathc, |
| 569 |
pglob->gl_pathc - oldpathc, sizeof(char *), |
| 570 |
compare); |
| 571 |
} |
| 572 |
} |
| 544 |
return(0); |
573 |
return(0); |
| 545 |
} |
574 |
} |
| 546 |
|
575 |
|
|
Lines 548-553
static int
Link Here
|
| 548 |
compare(const void *p, const void *q) |
577 |
compare(const void *p, const void *q) |
| 549 |
{ |
578 |
{ |
| 550 |
return(strcmp(*(char **)p, *(char **)q)); |
579 |
return(strcmp(*(char **)p, *(char **)q)); |
|
|
580 |
} |
| 581 |
|
| 582 |
static int |
| 583 |
compare_gps(const void *_p, const void *_q) |
| 584 |
{ |
| 585 |
const struct glob_path_stat *p = (const struct glob_path_stat *)_p; |
| 586 |
const struct glob_path_stat *q = (const struct glob_path_stat *)_q; |
| 587 |
|
| 588 |
return(strcmp(p->gps_path, q->gps_path)); |
| 551 |
} |
589 |
} |
| 552 |
|
590 |
|
| 553 |
static int |
591 |
static int |