Commit de3f03dbc61058a744168f49389a17e37ddf2f6a

Thomas de Grivel 2020-03-18T11:49:34

read-file

diff --git a/adams.asd b/adams.asd
index d1fb1bd..acafe21 100644
--- a/adams.asd
+++ b/adams.asd
@@ -47,6 +47,7 @@
    (:module "core" :depends-on ("package" "shell")
 	    :components
 	    ((:file "defs")
+             (:file "helpers")
 	     (:file "host"       :depends-on ("defs" "os" "resource-container"
                                               "syntaxes"))
 	     (:file "os")
diff --git a/core/helpers.lisp b/core/helpers.lisp
new file mode 100644
index 0000000..d4f6527
--- /dev/null
+++ b/core/helpers.lisp
@@ -0,0 +1,29 @@
+;;
+;;  adams - system administrator written in Common Lisp
+;;
+;;  Copyright 2020 Thomas de Grivel <thoxdg@gmail.com>
+;;
+;;  Permission to use, copy, modify, and distribute this software for any
+;;  purpose with or without fee is hereby granted, provided that the above
+;;  copyright notice and this permission notice appear in all copies.
+;;
+;;  THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+;;  WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+;;  MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+;;  ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+;;  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+;;  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+;;  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+;;
+
+(in-package :adams)
+
+(defun read-file (path)
+  (with-output-to-string (out)
+    (with-open-file (stream path :element-type 'character)
+      (let ((buf (make-string 4096)))
+        (loop
+           (let ((size (read-sequence buf stream)))
+             (when (zerop size)
+               (return))
+             (write-sequence buf out :end size)))))))
diff --git a/package.lisp b/package.lisp
index 62b67e4..05a307f 100644
--- a/package.lisp
+++ b/package.lisp
@@ -150,6 +150,8 @@
    #:with-uptime<1>
    ;; OpenBSD
    #:openbsd-pkg
+   ;; helpers
+   #:read-file
    ))
 
 (defpackage :adams-user