diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-12-16 11:25:33 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-12-16 11:37:08 -0500 |
commit | 023482caa20c0d3b5ab1641f26d8384829b1e43f (patch) | |
tree | 280881b8b674954b9775f69caf6e7ca0fa744313 /src | |
parent | e0d7dc5dfd7bdaa62b6bc18e9c1cce00bbe08577 (diff) | |
download | bfs-023482caa20c0d3b5ab1641f26d8384829b1e43f.tar.xz |
main: Warn if setlocale() fails
This should help users understand why issues like #128 happen.
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 13 |
1 files changed, 12 insertions, 1 deletions
@@ -116,15 +116,26 @@ int main(int argc, char *argv[]) { } // Use the system locale instead of "C" - setlocale(LC_ALL, ""); + int locale_err = 0; + if (!setlocale(LC_ALL, "")) { + locale_err = errno; + } + // Parse the command line struct bfs_ctx *ctx = bfs_parse_cmdline(argc, argv); if (!ctx) { return EXIT_FAILURE; } + // Warn if setlocale() failed, unless there's no expression to evaluate + if (locale_err && ctx->warn && ctx->expr) { + bfs_warning(ctx, "Failed to set locale: %s\n\n", xstrerror(locale_err)); + } + + // Walk the file system tree, evaluating the expression on each file int ret = bfs_eval(ctx); + // Free the parsed command line, and detect any last-minute errors if (bfs_ctx_free(ctx) != 0 && ret == EXIT_SUCCESS) { ret = EXIT_FAILURE; } |