
31 Mar
2010
31 Mar
'10
11:55 a.m.
On 03/31/2010 07:20 AM, Daniel P. Berrange wrote:
There's a slightly simpler way you can do this using strspn avoiding the regex engine
#define VALID_IFNAME_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"
rc = strspn(ifname, VALID_IFNAME_CHARS) != strlen (value);
That scans the string twice; if ifname is arbitrarily long, this can be inefficient. As a micro-optimization, you could instead check: rc = !ifname[strspn(ifname, VALID_IFNAME_CHARS)]; -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org