Blame src/internal/treebnf_errinfo_impl.c

02e59c
/**************************************************************/
02e59c
/*  treebnf: a tree oriented bnf library                      */
02e59c
/*  Copyright (C) 2024  SysDeer Technologies, LLC             */
02e59c
/*  Released under GPLv2 and GPLv3; see COPYING.TREEBNF.      */
02e59c
/**************************************************************/
02e59c
02e59c
#include <treebnf/treebnf.h>
02e59c
#include "treebnf_driver_impl.h"
02e59c
#include "treebnf_errinfo_impl.h"
02e59c
#include "treebnf_visibility_impl.h"
02e59c
02e59c
tbnf_hidden int tbnf_record_error(
02e59c
	const struct tbnf_driver_ctx *	dctx,
02e59c
	int				esyscode,
02e59c
	int				elibcode,
02e59c
	const char *			efunction,
02e59c
	int				eline,
02e59c
	unsigned			eflags,
02e59c
	void *				eany)
02e59c
{
02e59c
	struct tbnf_driver_ctx_impl *	ictx;
02e59c
	struct tbnf_error_info *	erri;
02e59c
02e59c
	ictx = tbnf_get_driver_ictx(dctx);
02e59c
02e59c
	if (ictx->errinfp == ictx->erricap)
02e59c
		return -1;
02e59c
02e59c
	*ictx->errinfp = &ictx->erribuf[ictx->errinfp - ictx->erriptr];
02e59c
	erri = *ictx->errinfp;
02e59c
02e59c
	erri->edctx     = dctx;
02e59c
	erri->esyscode  = esyscode;
02e59c
	erri->elibcode  = elibcode;
02e59c
	erri->efunction = efunction;
02e59c
	erri->eline     = eline;
02e59c
	erri->eflags    = eflags;
02e59c
	erri->eany      = (eany && (esyscode == ENOENT)) ? strdup(eany) : eany;
02e59c
02e59c
	ictx->errinfp++;
02e59c
02e59c
	return -1;
02e59c
}