I’m looking for a canned C routine that does what glob(3) does, except without matching the results against filenames, e.g.
input: "x[1-4]y"
output: "x1y", "x2y", "x3y", "x4y"
regardless of whether any files with those names happen to exist. EDIT: This doesn’t need to produce the list all at once; in fact it would be better if it had an iterator-style “give me the next name now” API, as the list could be enormous.
Obviously this cannot support * and ?, but that’s fine; I only need the [a-z] notation. Support for the {foo,bar,baz} notation would be nice too.
Best option is telling me the name of a routine that is already in everybody’s C library that does this. Second best would be a pointer to a chunk of BSD-licensed (or more permissively) code. GPL code would be awkward, but I could live with it.
cURL (the command line tool, not the library) contains code that does this job, which is relatively easy to extract:
They’ll have to be edited to remove some dependencies on the guts of cURL that are not part of the public library interface. The API is a little confusing, so here’s some wrapper code I wrote:
Pass an array of strings to
url_prep, callurl_nexton the result until it returnsNULL. Strings returned fromurl_nextmust be deallocated withfreewhen you’re done with them.