Load words from a dictionary file.
201 i32 retval = stat(path, &inf);
203 throw exception(
"file '%s' does not exist", path);
207 "failed to stat path '%s' (errno %d - %s)",
214 throw exception(
"'%s' is not a regular file", path);
217 throw exception(
"file '%s' is not readable", path);
219 i32 sz = inf.st_size;
228 fd = open(path, O_RDONLY);
230 while (
unlikely(fd < 0 && errno == EINTR) );
234 "failed to open file '%s' (errno %d - %s)",
241 void *mmap_base = mmap(NULL, sz, PROT_READ, MAP_SHARED, fd, 0);
242 if (
unlikely(mmap_base == MAP_FAILED) ) {
245 "failed to memory map file '%s' (errno %d - %s)",
259 offset = cur =
static_cast<i8*
> (mmap_base);
262 while (
likely(bytes-- > 0) )
264 if (
likely(cur != offset) ) {
265 word =
new string(
"%.*s", cur - offset, offset);
268 if (
unlikely(word->length() == 0) )
287 munmap(mmap_base, sz);
292 munmap(mmap_base, sz);
295 #if CSDBG_DBG_LEVEL & CSDBG_DBGL_INFO
298 "file '%s' (%d word%s) loaded on dictionary %s",
301 (cnt != 1) ?
"s" :
"",
char i8
8-bit signed integer
struct stat fileinfo_t
File metadata.
#define likely(expr)
Offer a hint (positive) to the pipeline branch predictor.
static void dbg_warn(const i8 *,...)
Print a warning debug message on the standard error stream.
i8 * m_name
Dictionary name.
static bool is_readable(const fileinfo_t &)
Check if the process has read access to a file.
virtual chain & add(string *)
int i32
32-bit signed integer
static bool is_regular(const fileinfo_t &)
Check if a file is a regular one.
#define unlikely(expr)
Offer a hint (negative) to the pipeline branch predictor.
static void dbg_info(const i8 *,...)
Print an informational debug message on the standard error stream.
#define __D_ASSERT(x)
Assertion macro.