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

Tito farmatito at tiscali.it
Thu Oct 26 06:44:16 PDT 2006


On Thursday 26 October 2006 15:03, Luciano Miguel Ferreira Rocha wrote:
> 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;
> }

Yes, you're right, forget to remove that line, that's what I wanted to do:

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 (strncmp(string_array[i], key,  (exact_match)  ? strlen(key) : strlen(string_array[i])) == 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.
> 
> 

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

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

Should be better like this.......

I hope at least 'cause it's still untested.

Ciao,
Tito 


More information about the busybox mailing list