Copy the regular files of a flat fixture directory into dst_dir. Returns the * number of files copied, or -1 when one could not be read whole. */
| 3204 | /* Copy the regular files of a flat fixture directory into dst_dir. Returns the |
| 3205 | * number of files copied, or -1 when one could not be read whole. */ |
| 3206 | static int cx_order_copy_fixture(const char *src_dir, const char *dst_dir) { |
| 3207 | cbm_dir_t *d = cbm_opendir(src_dir); |
| 3208 | if (!d) { |
| 3209 | return -1; |
| 3210 | } |
| 3211 | int copied = 0; |
| 3212 | cbm_dirent_t *entry; |
| 3213 | while ((entry = cbm_readdir(d)) != NULL) { |
| 3214 | if (entry->name[0] == '.' || entry->is_dir) { |
| 3215 | continue; |
| 3216 | } |
| 3217 | char src[CBM_SZ_1K]; |
| 3218 | snprintf(src, sizeof(src), "%s/%s", src_dir, entry->name); |
| 3219 | FILE *in = cbm_fopen(src, "rb"); |
| 3220 | if (!in) { |
| 3221 | copied = -1; |
| 3222 | break; |
| 3223 | } |
| 3224 | char buf[CBM_SZ_4K]; |
| 3225 | size_t n = fread(buf, 1, sizeof(buf) - 1, in); |
| 3226 | fclose(in); |
| 3227 | if (n == sizeof(buf) - 1) { |
| 3228 | copied = -1; /* fixture files are tiny; a full buffer means truncation */ |
| 3229 | break; |
| 3230 | } |
| 3231 | buf[n] = '\0'; |
| 3232 | write_temp_file(dst_dir, entry->name, buf); |
| 3233 | copied++; |
| 3234 | } |
| 3235 | cbm_closedir(d); |
| 3236 | return copied; |
| 3237 | } |
| 3238 | |
| 3239 | static int cx_order_cmp_node_qn(const void *pa, const void *pb) { |
| 3240 | const cbm_node_t *a = *(const cbm_node_t *const *)pa; |
no test coverage detected