/* * _citrus_esdb_open: * open an ESDB file. */ int _citrus_esdb_open(struct _citrus_esdb *db, const char *esname) { struct _region fr; const char *realname, *encfile; char buf1[PATH_MAX], buf2[PATH_MAX], path[PATH_MAX]; int ret; snprintf(path, sizeof(path), "%s/%s", _PATH_ESDB, ESDB_ALIAS); realname = _lookup_alias(path, esname, buf1, sizeof(buf1), _LOOKUP_CASE_IGNORE); snprintf(path, sizeof(path), "%s/%s", _PATH_ESDB, ESDB_DIR); encfile = _lookup_simple(path, realname, buf2, sizeof(buf2), _LOOKUP_CASE_IGNORE); if (encfile == NULL) return (ENOENT); /* open file */ snprintf(path, sizeof(path), "%s/%s", _PATH_ESDB, encfile); ret = _map_file(&fr, path); if (ret) return (ret); ret = conv_esdb(db, &fr); _unmap_file(&fr); return (ret); }
/* * lookup_iconv_entry: * lookup iconv.dir entry in the specified directory. * * line format of iconv.dir file: * key module arg * key : lookup key. * module : iconv module name. * arg : argument for the module (generally, description file name) * */ static __inline int lookup_iconv_entry(const char *curdir, const char *key, char *linebuf, size_t linebufsize, const char **module, const char **variable) { const char *cp, *cq; char *p, path[PATH_MAX]; /* iconv.dir path */ snprintf(path, (size_t)PATH_MAX, ("%s/" _CITRUS_ICONV_DIR), curdir); /* lookup db */ cp = p = _lookup_simple(path, key, linebuf, linebufsize, _LOOKUP_CASE_IGNORE); if (p == NULL) return ENOENT; /* get module name */ *module = p; cq = _bcs_skip_nonws(cp); p[cq-cp] = '\0'; p += cq-cp+1; cq++; /* get variable */ cp = _bcs_skip_ws(cq); *variable = p += cp - cq; cq = _bcs_skip_nonws(cp); p[cq-cp] = '\0'; return 0; }