os: use stringslite.TrimSuffix

This commit is contained in:
apocelipes 2024-05-04 18:11:06 +08:00
parent 20130cc36a
commit 4b6ffd043b

View file

@ -8,6 +8,7 @@ package os
import (
"errors"
"internal/stringslite"
"runtime"
)
@ -25,13 +26,5 @@ func executable() (string, error) {
// When the executable has been deleted then Readlink returns a
// path appended with " (deleted)".
return stringsTrimSuffix(path, " (deleted)"), err
}
// stringsTrimSuffix is the same as strings.TrimSuffix.
func stringsTrimSuffix(s, suffix string) string {
if len(s) >= len(suffix) && s[len(s)-len(suffix):] == suffix {
return s[:len(s)-len(suffix)]
}
return s
return stringslite.TrimSuffix(path, " (deleted)"), err
}