Esempio n. 1
0
static int rosedb_import(struct cache *cache, MDB_txn *txn, int argc, char *argv[])
{
	printf("IMPORT %s\n", argv[0]);

	int ret = 0;
	char *line = NULL;
	int lineno = 0;
	size_t line_len = 0;
	FILE *fp = fopen(argv[0], "r");
	if (fp == NULL) {
		return KNOT_ENOENT;
	}

	while (knot_getline(&line, &line_len, fp) != -1) {
		lineno += 1;
		ret = rosedb_import_line(cache, txn, line, argv[0], lineno);
		if (ret != 0) {
			break;
		}
	}

	free(line);
	fclose(fp);

	return ret;
}
Esempio n. 2
0
int tok_process_lines(FILE *fp, lparse_f cb, void *arg)
{
	if (fp == NULL || cb == NULL) {
		DBG_NULL;
		return KNOT_EINVAL;
	}

	int ret = KNOT_EOK;

	/* Parse lines. */
	char *buf = NULL;
	size_t buflen = 0;
	ssize_t rb = 0;
	while ((rb = knot_getline(&buf, &buflen, fp)) != -1) {
		ret = cb(buf, rb, arg);
		if (ret != KNOT_EOK) break;
	}

	free(buf);
	return ret;
}