summaryrefslogtreecommitdiff
path: root/guix/build/syscalls.scm
diff options
context:
space:
mode:
authorJohn Kehayias <john.kehayias@protonmail.com>2023-11-26 11:12:59 -0500
committerJohn Kehayias <john.kehayias@protonmail.com>2023-11-26 11:12:59 -0500
commitd15ffea6f47a40a9d36f3f32935e63f92e90af03 (patch)
tree826b3be17acf0f680e7888b3f7a3eeeaaedded7d /guix/build/syscalls.scm
parent8d2a5a36af4c36dfa08c7ee75d7a06ebb7a8225a (diff)
parent176440c056fdde6da98b11720989b1ed060ec97c (diff)
Merge branch 'master' into mesa-updates
Change-Id: Ide02272218e76dfae6dc9f8748871c8d61704260
Diffstat (limited to 'guix/build/syscalls.scm')
-rw-r--r--guix/build/syscalls.scm26
1 files changed, 16 insertions, 10 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm
index b29b6f78b6..4afe6d2f87 100644
--- a/guix/build/syscalls.scm
+++ b/guix/build/syscalls.scm
@@ -2338,18 +2338,24 @@ always a positive integer."
(terminal-dimension window-size-rows port (const 25)))
(define terminal-string-width
- (let ((mbstowcs (syscall->procedure int "mbstowcs" (list '* '* size_t)))
- (wcswidth (syscall->procedure int "wcswidth" (list '* size_t))))
- (lambda (str)
- "Return the width of a string as it would be printed on the terminal.
+ (let ((mbstowcs (and=> (false-if-exception
+ (dynamic-func "mbstowcs" (dynamic-link)))
+ (cute pointer->procedure int <> (list '* '* size_t))))
+ (wcswidth (and=> (false-if-exception
+ (dynamic-func "wcswidth" (dynamic-link)))
+ (cute pointer->procedure int <> (list '* size_t)))))
+ (if (and mbstowcs wcswidth)
+ (lambda (str)
+ "Return the width of a string as it would be printed on the terminal.
This procedure accounts for characters that have a different width than 1, such
as CJK double-width characters."
- (let ((wchar (make-bytevector (* (+ (string-length str) 1) 4))))
- (mbstowcs (bytevector->pointer wchar)
- (string->pointer str)
- (string-length str))
- (wcswidth (bytevector->pointer wchar)
- (string-length str))))))
+ (let ((wchar (make-bytevector (* (+ (string-length str) 1) 4))))
+ (mbstowcs (bytevector->pointer wchar)
+ (string->pointer str)
+ (string-length str))
+ (wcswidth (bytevector->pointer wchar)
+ (string-length str))))
+ string-length))) ;using a statically-linked Guile
(define openpty
(let ((proc (syscall->procedure int "openpty" '(* * * * *)