** Get the next name in '*path' = 'name1;name2;name3;...', changing ** the ending ';' to '\0' to create a zero-terminated string. Return ** NULL when list ends. */
| 438 | ** NULL when list ends. |
| 439 | */ |
| 440 | static const char *getnextfilename (char **path, char *end) { |
| 441 | char *sep; |
| 442 | char *name = *path; |
| 443 | if (name == end) |
| 444 | return NULL; /* no more names */ |
| 445 | else if (*name == '\0') { /* from previous iteration? */ |
| 446 | *name = *LUA_PATH_SEP; /* restore separator */ |
| 447 | name++; /* skip it */ |
| 448 | } |
| 449 | sep = strchr(name, *LUA_PATH_SEP); /* find next separator */ |
| 450 | if (sep == NULL) /* separator not found? */ |
| 451 | sep = end; /* name goes until the end */ |
| 452 | *sep = '\0'; /* finish file name */ |
| 453 | *path = sep; /* will start next search from here */ |
| 454 | return name; |
| 455 | } |
| 456 | |
| 457 | |
| 458 | /* |