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