diff --git a/doc/ref/posix.texi b/doc/ref/posix.texi index 08d939b9f..5990322a4 100644 --- a/doc/ref/posix.texi +++ b/doc/ref/posix.texi @@ -1223,6 +1223,11 @@ valid separators. Thus, programs should not assume that separator---e.g., when extracting the components of a file name. @end defvr +@deffn {Scheme Procedure} in-vicinity @var{directory} @var{file} +Concatenate @var{directory} and @var{file}, adding +@code{file-name-separator-string} (by default slash) in between if it is +not already present. This helps create file names. +@end deffn @node User Information @subsection User Information diff --git a/module/ice-9/boot-9.scm b/module/ice-9/boot-9.scm index 04f84215c..aaa998702 100644 --- a/module/ice-9/boot-9.scm +++ b/module/ice-9/boot-9.scm @@ -1,6 +1,6 @@ ;;; -*- mode: scheme; coding: utf-8; -*- -;;;; Copyright (C) 1995-2014, 2016-2024 Free Software Foundation, Inc. +;;;; Copyright (C) 1995-2014, 2016-2025 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -2144,12 +2144,15 @@ non-locally, that exit determines the continuation." (file-name-separator-at-index? 2) (file-name-separator-at-index? 0))))))) -(define (in-vicinity vicinity file) - (let ((tail (let ((len (string-length vicinity))) +(define (in-vicinity directory file) + "Concatenate @var{directory} and @var{file}, adding +@code{file-name-separator-string} (by default slash) in between if it is +not already present. This helps create file names." + (let ((tail (let ((len (string-length directory))) (if (zero? len) #f - (string-ref vicinity (- len 1)))))) - (string-append vicinity + (string-ref directory (- len 1)))))) + (string-append directory (if (or (not tail) (file-name-separator? tail)) "" file-name-separator-string)