summaryrefslogtreecommitdiffstats
path: root/XUtils.h
Commit message (Collapse)AuthorAgeFilesLines
* Use 'fp' name for local 'FILE*' variables.Explorer0912 days1-1/+1
| | | | | | | | | | | It is inappropriate to use the 'fd' name for 'FILE*' variables. POSIX file descriptiors are of type 'int' and are distinguished from ISO C stream pointers (type 'FILE*'). Rename these variables to 'fp', which is a preferred naming in POSIX. (Note that ISO C preferred the 'stream' name for the variables.) No code changes.
* Avoid fprintf in signal handlersChristian Göttsche2024-04-131-0/+4
| | | | | | | fprintf(3) is not safe to call ins signal handlers due to file buffering and memory allocations. Format messages in signal handlers via snprintf(3) and output them via write(2).
* Introduce String_eq_nullable()Christian Göttsche2024-03-271-0/+10
|
* Update includes based on IWYUBenny Baumann2023-12-261-0/+1
|
* Add includes for config.h as per the discussion in PR #1337Daniel Lange2023-12-261-1/+6
| | | | | | Many thanks to @Explorer09 Kang-Che Sung (宋岡哲). Also add a #error stanza to XUtils.h in case somebody forgets the beautiful mess GNU forces on us.
* Rewrite Meter_humanUnit() to accept floating point valueExplorer092023-11-241-0/+3
| | | | | | | | | | | | | | | | | Since Meter_humanUnit() is often called with floating point values in Meter objects, rewrite the function to let it process `double` type natively, and save floating point to integer casts. The rewritten function: * Allows higher orders of magnitude including 'R' and 'Q', and addresses infinity. (The previous version has a maximum value of (2^64 - 1) representing 16 ZiB.) * Rounds values when they are in intervals (99.9, 100) and (9.99, 10), and displays them with correct precision (number of fraction digits). * Produces assertion error on negative and NaN values (undefined behavior). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Add ATTR_NONNULL to various String_* functionsExplorer092023-10-111-0/+8
| | | | | | | | Note: For xSnprintf function the nonnull attribute is not needed. (The `buf` argument may be NULL as long as `len` is 0, and `fmt` is implied by the "format" attribute.) Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* strchrnul is a GNU libc extension, add a wrapper for other platformsNathan Scott2023-10-101-0/+11
|
* Compare all percentage fields with compareRealNumbers()Explorer092023-08-181-0/+5
| | | | | | | | The SPACESHIP_NUMBER() macro does not work well with floating point values that are possible to be NaNs. Change the compare logic of all percentage fields of Process entries to use compareRealNumbers(). Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Replace isnan() with better comparisons (isgreater(), etc.)Explorer092023-08-181-0/+5
| | | | | | | | | | | | | | | | | | The standard isnan() function is defined to never throw FP exceptions even when the argument is a "signaling" NaN. This makes isnan() more expensive than (x != x) expression unless the compiler flag '-fno-signaling-nans' is given. Introduce functions isNaN(), isNonnegative(), isPositive(), sumPositiveValues() and compareRealNumbers(), and replace isnan() in htop's codebase with the new functions. These functions utilize isgreater() and isgreaterequal() comparisons, which do not throw FP exceptions on "quiet" NaNs, which htop uses extensively. With isnan() removed, there is no need to suppress the warning '-Wno-c11-extensions' in FreeBSD. Remove the code from 'configure.ac'. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Annotate functions with access attributeChristian Göttsche2023-02-181-0/+7
| | | | Supported by GCC since version 10.
* Reformat code baseBenny Baumann2022-10-241-1/+1
| | | | | | | | | | | | | | This includes: - Wrap function implementations - Pointer alignment for function signatures - Pointer alignment for variable declarations - Whitespace after keywords - Whitespace after comma - Whitespace around initializers - Whitespace around operators - Code indentation - Line break for single line statements - Misleading alignment
* Write full bufferChristian Göttsche2022-06-281-0/+2
| | | | Retry writing after a short write.
* Improve String_contains_i to allow for multiple termsDaniel Lange2022-03-251-1/+1
| | | | | | | | | | | This enables: * Multiple filters in the main panel and strace etc. views * Multiple search terms The search terms are separated by "|" and are still fixed strings matched case-insensitive. Added a multi flag at request of BenBE.
* Removed unused String_getToken functionTobias Stoeckmann2022-01-111-2/+0
| | | | | Since String_getToken is not used anymore and currently only supports a 50 char token, simply remove it for now.
* Update license headers to explicitly say GPLv2+Daniel Lange2021-09-221-1/+1
|
* Add xReallocArrayZero() helperChristian Göttsche2021-09-111-0/+2
| | | | | Add helper function to reallocate an dynamic allocated array including zeroing the newly allocated memory.
* XUtils: move implementation of String_contains_i out of header fileChristian Göttsche2021-08-251-4/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The function strcasestr(3) is only available if _GNU_SOURCE is defined. If any file includes <string.h> before declaring _GNU_SOURCE, e.g by including "config.h", compilation fails with the following error: In file included from ColumnsPanel.c:8: In file included from ./ColumnsPanel.h:12: In file included from ./Panel.h:13: In file included from ./CRT.h:16: In file included from ./Settings.h:17: In file included from ./Process.h:15: In file included from ./Object.h:17: ./XUtils.h:42:11: error: implicit declaration of function 'strcasestr' is invalid in C99 [-Werror,-Wimplicit-function-declaration] return strcasestr(s1, s2) != NULL; ^ ./XUtils.h:42:11: note: did you mean 'strcasecmp'? /usr/include/strings.h:116:12: note: 'strcasecmp' declared here extern int strcasecmp (const char *__s1, const char *__s2) ^ Move the implementation to avoid unnecessary includes. Since LTO is quite common and stable performance should not be impacted if used.
* Pointer indication aligned to typenameBenny Baumann2021-07-151-1/+1
|
* Add compiler hints on memory allocating utility functionsChristian Göttsche2021-01-111-11/+11
|
* Add wrapper function for free and strdupChristian Göttsche2021-01-111-0/+1
| | | | Reduces code in callers and helps avoiding memory leaks.
* XUtils: add safe strncpy implementationChristian Göttsche2021-01-111-0/+3
| | | | | The standard strncpy fails to null-terminate the destination in case the source is longer than the passed size.
* XUtils: check for multiplication overflow in allocation sizeChristian Göttsche2021-01-021-0/+4
|
* Use size_t as len type for xSnprintfChristian Göttsche2020-12-061-1/+1
| | | | Like the C snprintf function
* IWYU updateChristian Göttsche2020-12-061-0/+1
|
* Add xReadfile wrapper for reading small to medium size filesChristian Göttsche2020-12-021-0/+4
| | | | | | Inspired by proposed Linux syscall Avoid file descriptor leaks like 4af8c63f
* Spacing around operatorsBenny Baumann2020-11-021-2/+2
|
* XUtils string related updatesChristian Göttsche2020-10-191-7/+16
| | | | | | | | | | - allow count out-parameter of String_split() to be NULL - introduce xStrndup() - do not allow NULL pointers passed to String_eq() it is not used in any code - implement String_startsWith(), String_contains_i() and String_eq() as inline header functions - adjust several conversion issues
* Make all required includes explicitBenny Baumann2020-10-181-3/+4
| | | | Information as seen by IWYU 0.12 + clang 9 on Linux
* Combine XAlloc.[ch] into XUtils.[ch]Benny Baumann2020-10-171-0/+11
|
* Rename StringUtils.[ch] to XUtils.[ch]Benny Baumann2020-10-161-0/+45

© 2014-2024 Faster IT GmbH | imprint | privacy policy