[BusyBox 0001076]: "ip addr del" does not work

Luciano Miguel Ferreira Rocha strange at nsk.no-ip.org
Thu Oct 26 06:03:10 PDT 2006


On Thu, Oct 26, 2006 at 01:53:02PM +0200, Tito wrote:
> Hi, what about this?
> 
> static int compare_string_array_internal(const char * const string_array[],
>  	const char *key, unsigned exact_match)
>  {
>          int i;
>  
>          for (i = 0; string_array[i] != 0; i++) {
>  		if (exact_match) {
>  			if (strncmp(string_array[i], key,  (exact_match)  ? strlen(key) : strlen(string_array[i])) == 0)
>  				return i;
>          }
>          return -i;
>  }

That's wrong. Unless exact_match is specified, no strcmp would be
called.

Also, exact_match = 1 means a search *not* for an exact_match?

This sould be better, and calls strlen only once:
 static int compare_string_array_internal(const char * const string_array[],
  	const char *key, unsigned fuzzy_match)
{
	int i;
	int kl = strlen(key);
  
	for (i = 0; string_array[i] != 0; i++) {
		if (strncmp(string_array[i], key, kl) == 0 &&
			(fuzzy_match || string_array[i][kl] == '\0'))
			return i;
	}
	return -i;
}

> int compare_string_array(const char * const string_array[])
> {
> 		return compare_string_array_internal(string_array, key, 0);
> }
> 
> int compare_substring_array(const char * const string_array[])
> {
> 		return compare_string_array_internal(string_array, key, 1);
> }

These two are missing the argument for the key.


-- 
lfr
0/0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://busybox.net/lists/busybox/attachments/20061026/d6dd28f5/attachment.pgp 


More information about the busybox mailing list