diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-07-24 13:30:58 +0200 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-07-24 13:30:58 +0200 |
commit | 5431a58e86d3f2579c1edf1dc8d7074de73ac694 (patch) | |
tree | f33798b55f473cbb7337a84e669b3c07053671d9 /src | |
parent | 9ac6ff53b105925400a773a5088c9d0ec5b095a4 (diff) | |
download | emacs-5431a58e86d3f2579c1edf1dc8d7074de73ac694.tar.gz emacs-5431a58e86d3f2579c1edf1dc8d7074de73ac694.tar.bz2 emacs-5431a58e86d3f2579c1edf1dc8d7074de73ac694.zip |
Add new function `directory-append'
* doc/lispref/files.texi (Directory Names): Document it, and
remove the concat-based file concatenation description.
* lisp/emacs-lisp/shortdoc.el (file-name): Add. And add more
expand-file-name examples.
* src/fileio.c (Fdirectory_append): New function.
Diffstat (limited to 'src')
-rw-r--r-- | src/fileio.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/fileio.c b/src/fileio.c index 04c9d7d4af3..277da48315e 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -749,6 +749,51 @@ For that reason, you should normally use `make-temp-file' instead. */) empty_unibyte_string, Qnil); } +DEFUN ("directory-append", Fdirectory_append, Sdirectory_append, 2, 2, 0, + doc: /* Return FILE (a string) appended to DIRECTORY (a string). +DIRECTORY may or may not end with a slash -- the return value from +this function will be the same. */) + (Lisp_Object directory, Lisp_Object file) +{ + USE_SAFE_ALLOCA; + char *p; + + CHECK_STRING (file); + CHECK_STRING (directory); + + if (SCHARS (file) == 0) + xsignal1 (Qfile_error, build_string ("Empty file name")); + + if (SCHARS (directory) == 0) + return file; + + /* Make the strings the same multibytedness. */ + if (STRING_MULTIBYTE (file) != STRING_MULTIBYTE (directory)) + { + if (STRING_MULTIBYTE (file)) + directory = make_multibyte_string (SSDATA (directory), + SCHARS (directory), + SCHARS (directory)); + else + file = make_multibyte_string (SSDATA (file), + SCHARS (file), + SCHARS (file)); + } + + /* Allocate enough extra space in case we need to put a slash in + there. */ + p = SAFE_ALLOCA (SBYTES (file) + SBYTES (directory) + 2); + ptrdiff_t offset = SBYTES (directory); + memcpy (p, SSDATA (directory), offset); + if (! IS_DIRECTORY_SEP (p[offset - 1])) + p[offset++] = DIRECTORY_SEP; + memcpy (p + offset, SSDATA (file), SBYTES (file)); + p[offset + SBYTES (file)] = 0; + Lisp_Object result = build_string (p); + SAFE_FREE (); + return result; +} + /* NAME must be a string. */ static bool file_name_absolute_no_tilde_p (Lisp_Object name) @@ -6488,6 +6533,7 @@ This includes interactive calls to `delete-file' and defsubr (&Sdirectory_file_name); defsubr (&Smake_temp_file_internal); defsubr (&Smake_temp_name); + defsubr (&Sdirectory_append); defsubr (&Sexpand_file_name); defsubr (&Ssubstitute_in_file_name); defsubr (&Scopy_file); |