Use strchr instead of strstr with specially constructed string255 struct (not tested)
authorunc0rr
Wed, 12 Feb 2014 23:46:24 +0400 (2014-02-12)
changeset 10134 81d733899e06
parent 10133 d73412fbf3b4
child 10135 8fd3e38bd4f2
Use strchr instead of strstr with specially constructed string255 struct (not tested)
project_files/hwc/rtl/system.c
--- a/project_files/hwc/rtl/system.c	Wed Feb 12 23:40:35 2014 +0400
+++ b/project_files/hwc/rtl/system.c	Wed Feb 12 23:46:24 2014 +0400
@@ -143,11 +143,22 @@
 }
 
 Integer __attribute__((overloadable)) fpcrtl_pos(Char c, string255 str) {
-    string255 t;
-    t.len = 1;
-    t.str[0] = c;
-    t.str[1] = 0;
-    return fpcrtl_pos(t, str);
+
+    unsigned char* p;
+
+    if (str.len == 0) {
+        return 0;
+    }
+
+    FIX_STRING(str);
+
+    p = strchr(str.str, c);
+
+    if (p == NULL) {
+        return 0;
+    }
+
+    return p - (unsigned char*)&str.s;
 }
 
 Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, string255 str) {
@@ -175,11 +186,20 @@
 }
 
 Integer __attribute__((overloadable)) fpcrtl_pos(Char c, astring str) {
-    string255 t;
-    t.len = 1;
-    t.str[0] = c;
-    t.str[1] = 0;
-    return fpcrtl_pos(t, str);
+    unsigned char* p;
+
+    if (str.len == 0) {
+        return 0;
+    }
+
+    p = strchr(str.s + 1, c);
+
+    if (p == NULL) {
+        return 0;
+    }
+
+    return p - (unsigned char*)&str.s;
+
 }
 
 Integer __attribute__((overloadable)) fpcrtl_pos(string255 substr, astring str) {