[Fix] Re: Using UNIX:UNIX-MMAP to read large text files under CMUCL?

Madhu <[email protected]>
Newsgroups gmane.lisp.cmucl.devel,gmane.lisp.cmucl.general
Message-ID <[email protected]>
Try the following definition of unix-mmap (for unix-glibc2.lisp, which
includes linux)

(in-package "UNIX")
(defun unix-mmap (addr length prot flags fd offset)
  (declare (type (or null system-area-pointer) addr)
           (type (unsigned-byte 32) length)
           (type (integer 1 7) prot)
           (type (unsigned-byte 32) flags)
           (type (or null unix-fd) fd)
           (type (signed-byte 32) offset))
  ;; Can't use syscall, because the address that is returned could be
  ;; "negative".  Hence we explicitly check for mmap returning
  ;; MAP_FAILED.
  (let ((result
	 (alien-funcall (extern-alien "mmap" (function system-area-pointer
						       system-area-pointer
						       size-t int int
                                                       int off-t))
			(or addr +null+) length prot flags (or fd -1) offset)))
    (if (<= (sys:SAP-INT result) 0)
	(values nil (unix-errno))
	result)))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.