diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-11-21 13:49:59 +0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2007-11-21 13:49:59 +0000 |
commit | 06f95dd07ce691a1f12c8ec7fa5ad84858d81cd0 (patch) | |
tree | bca2f5bb29b4a6844eb8f35c04d4e9bda7025128 /src | |
parent | c370755583d7350f4b96136eb0a6a8a7b08551b1 (diff) | |
download | guix-06f95dd07ce691a1f12c8ec7fa5ad84858d81cd0.tar.gz |
* New primop `readFile' to get the contents of a file as a string.
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/primops.cc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 2a96e25a84..bb9190579a 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -622,6 +622,17 @@ static Expr prim_dirOf(EvalState & state, const ATermVector & args) } +/* Return the contents of a file as a string. */ +static Expr prim_readFile(EvalState & state, const ATermVector & args) +{ + PathSet context; + Path path = coerceToPath(state, args[0], context); + if (!context.empty()) + throw EvalError(format("string `%1%' cannot refer to other paths") % path); + return makeStr(readFile(path)); +} + + /************************************************************* * Creating files *************************************************************/ @@ -968,6 +979,7 @@ void EvalState::addPrimOps() addPrimOp("__pathExists", 1, prim_pathExists); addPrimOp("baseNameOf", 1, prim_baseNameOf); addPrimOp("dirOf", 1, prim_dirOf); + addPrimOp("__readFile", 1, prim_readFile); // Creating files addPrimOp("__toXML", 1, prim_toXML); |