mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 21:18:53 +00:00
add unsigned long long variant to fish_wcsto*
This commit is contained in:
parent
3b50fe8b68
commit
7996e15ad1
2 changed files with 32 additions and 0 deletions
|
@ -625,6 +625,37 @@ long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr, int base) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// An enhanced version of wcstoull().
|
||||||
|
///
|
||||||
|
/// This is needed because BSD and GNU implementations differ in several ways that make it really
|
||||||
|
/// annoying to use them in a portable fashion.
|
||||||
|
///
|
||||||
|
/// The caller doesn't have to zero errno. Sets errno to -1 if the int ends with something other
|
||||||
|
/// than a digit. Leading whitespace is ignored (per the base wcstoll implementation). Trailing
|
||||||
|
/// whitespace is also ignored.
|
||||||
|
unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr, int base) {
|
||||||
|
while (iswspace(*str)) ++str; // skip leading whitespace
|
||||||
|
if (!*str) { // this is because some implementations don't handle this sensibly
|
||||||
|
errno = EINVAL;
|
||||||
|
if (endptr) *endptr = str;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
|
wchar_t *_endptr;
|
||||||
|
unsigned long long result = wcstoull(str, &_endptr, base);
|
||||||
|
while (iswspace(*_endptr)) ++_endptr; // skip trailing whitespace
|
||||||
|
if (!errno && *_endptr) {
|
||||||
|
if (_endptr == str) {
|
||||||
|
errno = EINVAL;
|
||||||
|
} else {
|
||||||
|
errno = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (endptr) *endptr = _endptr;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
file_id_t file_id_t::file_id_from_stat(const struct stat *buf) {
|
file_id_t file_id_t::file_id_from_stat(const struct stat *buf) {
|
||||||
assert(buf != NULL);
|
assert(buf != NULL);
|
||||||
|
|
||||||
|
|
|
@ -120,6 +120,7 @@ int fish_wcswidth(const wcstring &str);
|
||||||
int fish_wcstoi(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
int fish_wcstoi(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
||||||
long fish_wcstol(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
long fish_wcstol(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
||||||
long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
long long fish_wcstoll(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
||||||
|
unsigned long long fish_wcstoull(const wchar_t *str, const wchar_t **endptr = NULL, int base = 10);
|
||||||
|
|
||||||
/// Class for representing a file's inode. We use this to detect and avoid symlink loops, among
|
/// Class for representing a file's inode. We use this to detect and avoid symlink loops, among
|
||||||
/// other things. While an inode / dev pair is sufficient to distinguish co-existing files, Linux
|
/// other things. While an inode / dev pair is sufficient to distinguish co-existing files, Linux
|
||||||
|
|
Loading…
Reference in a new issue