Link to home
Start Free TrialLog in
Avatar of gazillabyte
gazillabyteFlag for United States of America

asked on

Using the posix fnmatch to compare to an empty string

I have a lot of code that uses the fnmatch C function to match strings against patterns.

From time to time I want to match against empty strings, but the wildcard * relates to one or more characters, not zero characters.

I was sure you could achieve a pattern to match all blank strings with

!(?*)

meaning any string that is not one character or more in length, but this does not match.

What is the "right" way to get a match from:

fnmatch(..., "", 0)

where ... is the pattern?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gazillabyte

ASKER

Cheers.

I had a wrapper around fnmatch which checked the length of the pattern and the string and returned false if they were both empty. It must have seemed like a good idea at the time ;-)