From a3384b7461005260d0dd5c8f05df28ee842442de Mon Sep 17 00:00:00 2001 From: Omar Polo Date: Mon, 9 Aug 2021 09:39:20 +0000 Subject: [PATCH] use .get_file() instead of basename(3) On OpenBSD the compiler complains that calling basename(3) would lose const qualifier. basename(3) is defined as char *basename(char *); and can, accorgindly to the POSIX.1, modify the passed string. This uses the .get_file() method. The check is necessary because file_name could be a directory, in which case .get_file() would return an empty string. The .get_base_dir().get_file() idiom is already used. The usage of get_file() and the check were suggested by theraot, thanks! --- platform/linuxbsd/os_linuxbsd.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platform/linuxbsd/os_linuxbsd.cpp b/platform/linuxbsd/os_linuxbsd.cpp index 23e448fbd79..65a9f3b0426 100644 --- a/platform/linuxbsd/os_linuxbsd.cpp +++ b/platform/linuxbsd/os_linuxbsd.cpp @@ -399,7 +399,10 @@ Error OS_LinuxBSD::move_to_trash(const String &p_path) { // The trash can is successfully created, now we check that we don't exceed our file name length limit. // If the file name is too long trim it so we can add the identifying number and ".trashinfo". // Assumes that the file name length limit is 255 characters. - String file_name = basename(p_path.utf8().get_data()); + String file_name = p_path.get_file(); + if (file_name.length() == 0) { + file_name = p_path.get_base_dir().get_file(); + } if (file_name.length() > 240) { file_name = file_name.substr(0, file_name.length() - 15); }