srfi-98.scm 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. ;;; srfi-98.scm --- An interface to access environment variables
  2. ;; Copyright (C) 2009 Free Software Foundation, Inc.
  3. ;;
  4. ;; This library is free software; you can redistribute it and/or
  5. ;; modify it under the terms of the GNU Lesser General Public
  6. ;; License as published by the Free Software Foundation; either
  7. ;; version 3 of the License, or (at your option) any later version.
  8. ;;
  9. ;; This library is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. ;; Lesser General Public License for more details.
  13. ;;
  14. ;; You should have received a copy of the GNU Lesser General Public
  15. ;; License along with this library; if not, write to the Free Software
  16. ;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. ;;; Author: Julian Graham <julian.graham@aya.yale.edu>
  18. ;;; Date: 2009-05-26
  19. ;;; Commentary:
  20. ;; This is an implementation of SRFI-98 (An interface to access environment
  21. ;; variables).
  22. ;;
  23. ;; This module is fully documented in the Guile Reference Manual.
  24. ;;; Code:
  25. (define-module (srfi srfi-98)
  26. :use-module (srfi srfi-1)
  27. :export (get-environment-variable
  28. get-environment-variables))
  29. (cond-expand-provide (current-module) '(srfi-98))
  30. (define get-environment-variable getenv)
  31. (define (get-environment-variables)
  32. (define (string->alist-entry str)
  33. (let ((pvt (string-index str #\=))
  34. (len (string-length str)))
  35. (and pvt (cons (substring str 0 pvt) (substring str (+ pvt 1) len)))))
  36. (filter-map string->alist-entry (environ)))