|
54 | 54 | sim_byte_swap_data - swap data elements inplace in buffer
|
55 | 55 | sim_shmem_open create or attach to a shared memory region
|
56 | 56 | sim_shmem_close close a shared memory region
|
57 |
| -
|
| 57 | + sim_chdir change working directory |
| 58 | + sim_mkdir create a directory |
| 59 | + sim_rmdir remove a directory |
| 60 | + sim_getcwd get the current working directory |
| 61 | + sim_copyfile copy a file |
| 62 | + sim_filepath_parts expand and extract filename/path parts |
| 63 | + sim_dirscan scan for a filename pattern |
| 64 | + sim_get_filelist get a list of files matching a pattern |
| 65 | + sim_free_filelist free a filelist |
| 66 | + sim_print_filelist print the elements of a filelist |
58 | 67 |
|
59 | 68 | sim_fopen and sim_fseek are OS-dependent. The other routines are not.
|
60 | 69 | sim_fsize is always a 32b routine (it is used only with small capacity random
|
@@ -347,6 +356,55 @@ if (NULL == _sim_expand_homedir (path, pathbuf, sizeof (pathbuf)))
|
347 | 356 | return rmdir (pathbuf);
|
348 | 357 | }
|
349 | 358 |
|
| 359 | +static void _sim_filelist_entry (const char *directory, |
| 360 | + const char *filename, |
| 361 | + t_offset FileSize, |
| 362 | + const struct stat *filestat, |
| 363 | + void *context) |
| 364 | +{ |
| 365 | +char **filelist = *(char ***)context; |
| 366 | +char FullPath[PATH_MAX + 1]; |
| 367 | +int listcount = 0; |
| 368 | + |
| 369 | +snprintf (FullPath, sizeof (FullPath), "%s%s", directory, filename); |
| 370 | +if (filelist != NULL) { |
| 371 | + while (filelist[listcount++] != NULL); |
| 372 | + --listcount; |
| 373 | + } |
| 374 | +filelist = (char **)realloc (filelist, (listcount + 2) * sizeof (*filelist)); |
| 375 | +filelist[listcount] = strdup (FullPath); |
| 376 | +filelist[listcount + 1] = NULL; |
| 377 | +*(char ***)context = filelist; |
| 378 | +} |
| 379 | + |
| 380 | +char **sim_get_filelist (const char *filename) |
| 381 | +{ |
| 382 | +char **filelist = NULL; |
| 383 | + |
| 384 | +sim_dir_scan (filename, _sim_filelist_entry, &filelist); |
| 385 | +return filelist; |
| 386 | +} |
| 387 | + |
| 388 | +void sim_free_filelist (char ***pfilelist) |
| 389 | +{ |
| 390 | +char **listp = *pfilelist; |
| 391 | + |
| 392 | +if (listp == NULL) |
| 393 | + return; |
| 394 | +while (*listp != NULL) |
| 395 | + free (*listp++); |
| 396 | +free (*pfilelist); |
| 397 | +*pfilelist = NULL; |
| 398 | +} |
| 399 | + |
| 400 | +void sim_print_filelist (char **filelist) |
| 401 | +{ |
| 402 | +if (filelist == NULL) |
| 403 | + return; |
| 404 | +while (*filelist != NULL) |
| 405 | + sim_printf ("%s\n", *filelist++); |
| 406 | +} |
| 407 | + |
350 | 408 |
|
351 | 409 | /* OS-dependent routines */
|
352 | 410 |
|
@@ -913,7 +971,7 @@ return getcwd (buf, buf_size);
|
913 | 971 | *
|
914 | 972 | * In the above example above %I% can be replaced by other
|
915 | 973 | * environment variables or numeric parameters to a DO command
|
916 |
| - * invokation. |
| 974 | + * invocation. |
917 | 975 | */
|
918 | 976 |
|
919 | 977 | char *sim_filepath_parts (const char *filepath, const char *parts)
|
|
0 commit comments