[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
03/15: build: syscalls: Add mkdtemp!
From: |
David Thompson |
Subject: |
03/15: build: syscalls: Add mkdtemp! |
Date: |
Sun, 05 Jul 2015 19:31:42 +0000 |
davexunit pushed a commit to branch wip-container
in repository guix.
commit 0a8a58273bba50a075c59b913bf19e42c77657af
Author: David Thompson <address@hidden>
Date: Wed Jun 24 20:50:34 2015 -0400
build: syscalls: Add mkdtemp!
* guix/build/syscalls.scm (mkdtemp!): New procedure.
* tests/syscalls.scm: Test it.
---
guix/build/syscalls.scm | 15 +++++++++++++++
tests/syscalls.scm | 9 +++++++++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index 6d31510..a464040 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -45,6 +45,7 @@
swapon
swapoff
processes
+ mkdtemp!
IFF_UP
IFF_BROADCAST
@@ -265,6 +266,20 @@ user-land process."
(scandir "/proc"))
<))
+(define mkdtemp!
+ (let* ((ptr (dynamic-func "mkdtemp" (dynamic-link)))
+ (proc (pointer->procedure '* ptr '(*))))
+ (lambda (tmpl)
+ "Create a new unique directory in the file system using the template
+string TMPL and return its file name. TMPL must end with 'XXXXXX'."
+ (let ((result (proc (string->pointer tmpl)))
+ (err (errno)))
+ (when (null-pointer? result)
+ (throw 'system-error "mkdtemp!" "~S: ~A"
+ (list tmpl (strerror err))
+ (list err)))
+ (pointer->string result)))))
+
;;;
;;; Packed structures.
diff --git a/tests/syscalls.scm b/tests/syscalls.scm
index 706f3df..049ca93 100644
--- a/tests/syscalls.scm
+++ b/tests/syscalls.scm
@@ -1,5 +1,6 @@
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2014, 2015 Ludovic Courtès <address@hidden>
+;;; Copyright © 2015 David Thompson <address@hidden>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -67,6 +68,14 @@
(lambda args
(memv (system-error-errno args) (list EPERM EINVAL ENOENT)))))
+(test-assert "mkdtemp!"
+ (let* ((tmp (or (getenv "TMPDIR") "/tmp"))
+ (dir (mkdtemp! (string-append tmp "/guix-test-XXXXXX"))))
+ (and (file-exists? dir)
+ (begin
+ (rmdir dir)
+ #t))))
+
(test-assert "all-network-interfaces"
(match (all-network-interfaces)
(((? string? names) ..1)
- branch wip-container created (now 28723ea), David Thompson, 2015/07/05
- 01/15: build: syscalls: Add additional mount flags., David Thompson, 2015/07/05
- 02/15: build: syscalls: Add unmount flags., David Thompson, 2015/07/05
- 03/15: build: syscalls: Add mkdtemp!,
David Thompson <=
- 04/15: utils: Add call-with-temporary-directory., David Thompson, 2015/07/05
- 05/15: build: syscalls: Add clone syscall wrapper., David Thompson, 2015/07/05
- 06/15: build: syscalls: Add setns syscall wrapper., David Thompson, 2015/07/05
- 07/15: build: syscalls: Add pivot-root., David Thompson, 2015/07/05
- 09/15: gnu: system: Move <file-system-mapping> into (gnu system file-systems)., David Thompson, 2015/07/05
- 10/15: gnu: system: Move file-system->spec to (gnu system file-systems)., David Thompson, 2015/07/05
- 12/15: gnu: system: Add Linux container file systems., David Thompson, 2015/07/05
- 11/15: gnu: system: Add Linux container module., David Thompson, 2015/07/05
- 13/15: scripts: system: Add 'container' action., David Thompson, 2015/07/05
- 08/15: gnu: build: Add Linux container module., David Thompson, 2015/07/05