aboutsummaryrefslogtreecommitdiffstats
path: root/nnn.c
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-05-16 07:32:21 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2017-05-16 07:32:21 +0530
commit3243a3082ad807914e8bb0c434e0793cb02a1a5c (patch)
tree5ff056e554d93bf984dbe36163f5e4281e53eaf2 /nnn.c
parente671dcd0926de893b73252d214a9b40cab3a18af (diff)
downloadnnn-3243a3082ad807914e8bb0c434e0793cb02a1a5c.tar.gz
Add check to defer name to number conversion
Diffstat (limited to 'nnn.c')
-rw-r--r--nnn.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/nnn.c b/nnn.c
index 0a01160..122f8c4 100644
--- a/nnn.c
+++ b/nnn.c
@@ -378,15 +378,31 @@ xgetenv(char *name, char *fallback)
* If the absolute numeric values are same, we fallback to alphasort.
*/
static int
-xstricmp(const char *s1, const char *s2)
+xstricmp(char *s1, char *s2)
{
static char *c1, *c2;
- static long long num1, num2;
- num1 = strtoll(s1, &c1, 10);
- num2 = strtoll(s2, &c2, 10);
+ c1 = s1;
+ while (isspace(*c1))
+ c1++;
+ if (*c1 == '-' || *c1 == '+')
+ c1++;
+ while(*c1 >= '0' && *c1 <= '9')
+ c1++;
+
+ c2 = s2;
+ while (isspace(*c2))
+ c2++;
+ if (*c2 == '-' || *c2 == '+')
+ c2++;
+ while(*c2 >= '0' && *c2 <= '9')
+ c2++;
if (*c1 == '\0' && *c2 == '\0') {
+ static long long num1, num2;
+
+ num1 = strtoll(s1, &c1, 10);
+ num2 = strtoll(s2, &c2, 10);
if (num1 != num2) {
if (num1 > num2)
return 1;