Skip to content

Commit 23b3443

Browse files
authored
fixes the implementation of strncasecmp and strcmp models (#1219)
Also publishes the ascii module, apparently it wasn't included posix. Thanks @dtpeters for reporting this.
1 parent dc8403e commit 23b3443

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

plugins/primus_lisp/lisp/atoi.lisp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@
2222
(defmacro make-converter (type s)
2323
(cast type (read-ascii-word s)))
2424

25-
(defun atoi (s) (make-converter int s))
26-
(defun atol (s) (make-converter long s))
27-
(defun atoll (s) (make-converter long-long s))
25+
(defun atoi (s)
26+
(declare (external "atoi"))
27+
(make-converter int s))
28+
29+
(defun atol (s)
30+
(declare (external "atol"))
31+
(make-converter long s))
32+
33+
(defun atoll (s)
34+
(declare (external "atoll"))
35+
(make-converter long-long s))

plugins/primus_lisp/lisp/posix.lisp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
(require stdio)
33
(require string)
44
(require errno)
5+
(require ascii)

plugins/primus_lisp/lisp/string.lisp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
(require types)
22
(require pointers)
33
(require memory)
4+
(require ascii)
45

56
(defun strlen (p)
67
(declare (external "strlen"))
@@ -140,20 +141,25 @@
140141
(memcmp s1 s2 (min (strlen/with-null s1)
141142
(strlen/with-null s2))))
142143

143-
(defun strncasecmp (p1 p2 n)
144-
(declare (external "strncasecmp"))
144+
(defun memcasecmp (p1 p2 n)
145145
(let ((res 0) (i 0))
146146
(while (and (< i n) (not res))
147147
(set res (compare
148-
(tolower (memory-read p1))
149-
(tolower (memory-read p2))))
148+
(ascii-to-lower (cast int (memory-read p1)))
149+
(ascii-to-lower (cast int (memory-read p2)))))
150150
(incr p1 p2 i))
151151
res))
152152

153-
(defun strcasecmp (p1 p2)
153+
(defun strncasecmp (p1 p2 n)
154154
(declare (external "strncasecmp"))
155-
(strncasecmp p1 p2 (min (strlen p1)
156-
(strlen p2))))
155+
(memcasecmp p1 p2 (min n
156+
(strlen/with-null p1)
157+
(strlen/with-null p2))))
158+
159+
(defun strcasecmp (p1 p2)
160+
(declare (external "strcasecmp"))
161+
(strncasecmp p1 p2 (min (strlen/with-null p1)
162+
(strlen/with-null p2))))
157163

158164

159165
(defmacro find-substring (compare hay needle)

0 commit comments

Comments
 (0)