Skip to content

Commit a92ff8f

Browse files
committed
examples/sort_perf: Fix for nixos.
Make the word list specifiable with the WORDLIST environment variable, and fall back to the hard coded /usr/share/dict/words only if that variable is not set. In the flake, we set the variable to a known-good list.
1 parent d27e6be commit a92ff8f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

examples/sort_perf.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,14 @@ static void load_dict()
164164
/* Load dictionary into memory */
165165
size_t dict_cap;
166166
csnip_arr_Init(dict, dict_nbytes, dict_cap, 4096, _);
167-
FILE* fp = fopen("/usr/share/dict/words", "r");
167+
const char* wordlist = getenv("WORDLIST");
168+
if (wordlist == NULL)
169+
wordlist = "/usr/share/dict/words";
170+
FILE* fp = fopen(wordlist, "r");
168171
if (fp == 0) {
169-
fprintf(stderr,
170-
"Cannot open /usr/share/dict/words\n");
171-
abort();
172+
fprintf(stderr, "Error: Cannot open word list \"%s\"\n",
173+
wordlist);
174+
exit(1);
172175
}
173176
const size_t bsz = 4096;
174177
size_t r = 0;

flake.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
];
2323

2424
buildInputs = with pkgs; [ ];
25+
26+
WORDLIST = "${pkgs.scowl}/share/dict/words.txt";
2527
};
2628
};
2729
});

0 commit comments

Comments
 (0)