Tree @upstream/2.2.0 (Download .tar.gz)
- build_tools
- doc_src
- etc
- fish.xcodeproj
- osx
- po
- share
- tests
- user_doc
- autoload.cpp
- autoload.h
- builtin.cpp
- builtin.h
- builtin_commandline.cpp
- builtin_complete.cpp
- builtin_jobs.cpp
- builtin_printf.cpp
- builtin_set.cpp
- builtin_set_color.cpp
- builtin_test.cpp
- builtin_ulimit.cpp
- color.cpp
- color.h
- common.cpp
- common.h
- complete.cpp
- complete.h
- config.guess
- config.h.in
- config.sub
- configure
- configure.ac
- CONTRIBUTING.md
- COPYING
- create_wajig_completions.py
- Dockerfile
- Doxyfile
- Doxyfile.help
- Doxyfile.user
- env.cpp
- env.h
- env_universal_common.cpp
- env_universal_common.h
- event.cpp
- event.h
- exec.cpp
- exec.h
- expand.cpp
- expand.h
- fallback.cpp
- fallback.h
- fish.cpp
- fish.pc.in
- fish_indent.cpp
- fish_tests.cpp
- fish_version.cpp
- fish_version.h
- function.cpp
- function.h
- highlight.cpp
- highlight.h
- history.cpp
- history.h
- input.cpp
- input.h
- input_common.cpp
- input_common.h
- install-sh
- intern.cpp
- intern.h
- io.cpp
- io.h
- iothread.cpp
- iothread.h
- key_reader.cpp
- kill.cpp
- kill.h
- lexicon_filter.in
- lru.h
- Makefile.in
- mimedb.cpp
- mimedb.h
- output.cpp
- output.h
- pager.cpp
- pager.h
- parse_constants.h
- parse_execution.cpp
- parse_execution.h
- parse_productions.cpp
- parse_productions.h
- parse_tree.cpp
- parse_tree.h
- parse_util.cpp
- parse_util.h
- parser.cpp
- parser.h
- parser_keywords.cpp
- parser_keywords.h
- path.cpp
- path.h
- postfork.cpp
- postfork.h
- print_help.cpp
- print_help.h
- proc.cpp
- proc.h
- reader.cpp
- reader.h
- README.md
- release_notes.html
- sanity.cpp
- sanity.h
- screen.cpp
- screen.h
- signal.cpp
- signal.h
- tokenizer.cpp
- tokenizer.h
- utf8.cpp
- utf8.h
- util.cpp
- util.h
- version
- wcstringutil.cpp
- wcstringutil.h
- wgetopt.cpp
- wgetopt.h
- wildcard.cpp
- wildcard.h
- wutil.cpp
- wutil.h
- xdgmime.cpp
- xdgmime.h
- xdgmimealias.cpp
- xdgmimealias.h
- xdgmimeglob.cpp
- xdgmimeglob.h
- xdgmimeint.cpp
- xdgmimeint.h
- xdgmimemagic.cpp
- xdgmimemagic.h
- xdgmimeparent.cpp
- xdgmimeparent.h
util.cpp @upstream/2.2.0 — raw · history · blame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 | /** \file util.c Generic utilities library. Contains datastructures such as automatically growing array lists, priority queues, etc. */ #include "config.h" #include <stdio.h> #include <stdlib.h> #include <wchar.h> #include <math.h> #include <sys/time.h> #include <stdarg.h> #include <string.h> #include <ctype.h> #include <wctype.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <errno.h> #include <assert.h> #include "fallback.h" #include "util.h" #include "common.h" #include "wutil.h" /** Minimum allocated size for data structures. Used to avoid excessive memory allocations for lists, hash tables, etc, which are nearly empty. */ #define MIN_SIZE 32 /** Maximum number of characters that can be inserted using a single call to sb_printf. This is needed since vswprintf doesn't tell us what went wrong. We don't know if we ran out of space or something else went wrong. We assume that any error is an out of memory-error and try again until we reach this size. After this size has been reached, it is instead assumed that something was wrong with the format string. */ #define SB_MAX_SIZE (128*1024*1024) int wcsfilecmp(const wchar_t *a, const wchar_t *b) { CHECK(a, 0); CHECK(b, 0); if (*a==0) { if (*b==0) return 0; return -1; } if (*b==0) { return 1; } long secondary_diff=0; if (iswdigit(*a) && iswdigit(*b)) { wchar_t *aend, *bend; long al; long bl; long diff; errno = 0; al = wcstol(a, &aend, 10); bl = wcstol(b, &bend, 10); if (errno) { /* Huuuuuuuuge numbers - fall back to regular string comparison */ return wcscmp(a, b); } diff = al - bl; if (diff) return diff > 0 ? 2 : -2; secondary_diff = (aend-a) - (bend-b); a=aend-1; b=bend-1; } else { int diff = towlower(*a) - towlower(*b); if (diff != 0) return (diff>0)?2:-2; secondary_diff = *a-*b; } int res = wcsfilecmp(a+1, b+1); if (abs(res) < 2) { /* No primary difference in rest of string. Use secondary difference on this element if found. */ if (secondary_diff) { return secondary_diff > 0 ? 1 :-1; } } return res; } long long get_time() { struct timeval time_struct; gettimeofday(&time_struct, 0); return 1000000ll*time_struct.tv_sec+time_struct.tv_usec; } |