common.c
int string_update_with_size(char **str, int *flag, char *s, size_t len) {
  if (*str) {
    if ((s) && (len)) {
      if ((len != strlen(*str)) || (strncmp(*str, s, len) != 0)) {
        free(*str);
        //*str = strndup(s, len); // it seems that OpenWrt 12 doesn't have this
        char *p = malloc(len + 1);
        memcpy(p,s,len);
        p[len] = '\0';
        *str = p;
        *flag = 1;
      } else {
        *flag = 0;
      }
    } else {
      // old string is non-NULL, new string is NULL or length 0
      free(*str);
      *str = NULL;
      *flag = 1;
    }
  } else { // old string is NULL
    if ((s) && (len)) {
      //*str = strndup(s, len); // it seems that OpenWrt 12 doesn't have this
      char *p = malloc(len + 1);
      memcpy(p,s,len);
      p[len] = '\0';
      *str = p;
      *flag = 1;
    } else {
      // old string is NULL and new string is NULL or length 0
      *flag = 0; // so no change
    }
  }
  return *flag;
}
// If the strings are different, the str is free'd and replaced by a pointer
// to a newly strdup'd string and the flag is set
// If they are the same, the flag is cleared
If the strings are different, the str is free'd and replaced by a pointer
to a newly strdup'd string and the flag is set
If they are the same, the flag is cleared
If the strings are different the str is free ' d and replaced by a pointer to a newly strdup ' d string and the flag is set If they are the same the flag is cleared
int string_update_with_size(char **str, int *flag, char *s, size_t len) {
  if (*str) {
    if ((s) && (len)) {
      if ((len != strlen(*str)) || (strncmp(*str, s, len) != 0)) {
        free(*str);
        char *p = malloc(len + 1);
        memcpy(p,s,len);
        p[len] = '\0';
        *str = p;
        *flag = 1;
      } else {
        *flag = 0;
      }
    } else {
      free(*str);
      *str = NULL;
      *flag = 1;
    }
  } else { 
    if ((s) && (len)) {
      char *p = malloc(len + 1);
      memcpy(p,s,len);
      p[len] = '\0';
      *str = p;
      *flag = 1;
    } else {
       and new string is NULL or length 0
      *flag = 0; 
    }
  }
  return *flag;
}
int string_update_with_size ( char * * str , int * flag , char * s , size_t len ) { if ( * str ) { if ( ( s ) && ( len ) ) { if ( ( len != strlen ( * str ) ) || ( strncmp ( * str , s , len ) != 0 ) ) { free ( * str ) ; char * p = malloc ( len + 1 ) ; memcpy ( p , s , len ) ; p [ len ] = ' \0 ' ; * str = p ; * flag = 1 ; } else { * flag = 0 ; } } else { free ( * str ) ; * str = NULL ; * flag = 1 ; } } else { if ( ( s ) && ( len ) ) { char * p = malloc ( len + 1 ) ; memcpy ( p , s , len ) ; p [ len ] = ' \0 ' ; * str = p ; * flag = 1 ; } else { * flag = 0 ; } } return * flag ; }
If the strings are different, the str is free'd and replaced by a pointer
to a newly strdup'd string and the flag is set
If they are the same, the flag is cleared
If the strings are different the str is free ' d and replaced by a pointer to a newly strdup ' d string and the flag is set If they are the same the flag is cleared
//*str = strndup(s, len); // it seems that OpenWrt 12 doesn't have this // old string is non-NULL, new string is NULL or length 0 // old string is NULL //*str = strndup(s, len); // it seems that OpenWrt 12 doesn't have this // old string is NULL and new string is NULL or length 0 // so no change