From mboxrd@z Thu Jan 1 00:00:00 1970 From: David Thompson Subject: [PATCH 03/15] build: syscalls: Add mkdtemp! Date: Mon, 6 Jul 2015 09:16:32 -0400 Message-ID: <1436188604-2813-3-git-send-email-dthompson2@worcester.edu> References: <1436188604-2813-1-git-send-email-dthompson2@worcester.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:47365) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC6H0-0001JF-LW for guix-devel@gnu.org; Mon, 06 Jul 2015 09:17:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZC6Gu-0006nD-6I for guix-devel@gnu.org; Mon, 06 Jul 2015 09:17:26 -0400 Received: from mail-qk0-f174.google.com ([209.85.220.174]:34678) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZC6Gu-0006ms-34 for guix-devel@gnu.org; Mon, 06 Jul 2015 09:17:20 -0400 Received: by qkeo142 with SMTP id o142so116527357qke.1 for ; Mon, 06 Jul 2015 06:17:19 -0700 (PDT) In-Reply-To: <1436188604-2813-1-git-send-email-dthompson2@worcester.edu> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: guix-devel@gnu.org Cc: David Thompson From: David Thompson * 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(+) 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 +;;; Copyright © 2015 David Thompson ;;; ;;; 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) -- 2.4.3