File:  [DVB] / dietlibc / lib / strverscmp.c
Revision 1.2: download - view: text, annotated - select for diffs
Sat Apr 11 04:26:28 2015 UTC (9 years, 1 month ago) by leitner
Branches: MAIN
CVS tags: HEAD
remove some dead stores

#define _GNU_SOURCE
#include <string.h>
#include <ctype.h>

int strverscmp(const char* s1, const char* s2)
{
  size_t i,j;
  long long a,b;
  b=0;
  for (i=0; s1[i]==s2[i]; ++i) {
    if (!s1[i]) return 0;	/* perfect match */
  }

  /* if we get here, there is a mismatch */
  /* backtrack over the matching digits */
  if (!isdigit(s1[i]) || !isdigit(s2[i]))
    return s1[i]-s2[i];
  for (j=i; j>0 && isdigit(s1[j-1]); --j) ;
  for (a=0; j<i; ++j) {
    a=a*10+s1[j]-'0';
  }
  b=a;
  while (isdigit(s1[i])) {
    a=a*10+s1[i]-'0';
    ++i;
  }
  while (isdigit(s2[j])) {
    b=b*10+s2[j]-'0';
    ++j;
  }
  return a<b ? -1 : 1;
}

LinuxTV legacy CVS <linuxtv.org/cvs>