diff --git a/include/spho/ctx.h b/include/spho/ctx.h index 746126c..fbc27e5 100644 --- a/include/spho/ctx.h +++ b/include/spho/ctx.h @@ -3,6 +3,9 @@ #include "spho/data.h" +#define SPHO_ERR_BUF_LEN 2048 +#define SPHO_ERR_FILEBUF_LEN 128 + struct spho_ctx { int err; int err_info; @@ -20,6 +23,6 @@ struct spho_ctx { struct spho_ctx *spho_ctx_create(void); void spho_ctx_destroy(struct spho_ctx *); -char *spho_ctx_strerror(struct spho_ctx *); +const char *spho_ctx_strerror(struct spho_ctx *); #endif diff --git a/include/spho/data.h b/include/spho/data.h index 2050387..837f273 100644 --- a/include/spho/data.h +++ b/include/spho/data.h @@ -24,13 +24,13 @@ struct spho_nom_le { SLIST_ENTRY(spho_nom_le) next; }; -struct spho_const_le { +struct spho_cnst_le { struct spho_cnst cnst; - SLIST_ENTRY(spho_const_le) next; + SLIST_ENTRY(spho_cnst_le) next; }; SLIST_HEAD(spho_nom_l, spho_nom_le); -SLIST_HEAD(spho_const_l, spho_const_le); +SLIST_HEAD(spho_const_l, spho_cnst_le); #endif diff --git a/include/spho/err.h b/include/spho/err.h index f92687a..b11db1b 100644 --- a/include/spho/err.h +++ b/include/spho/err.h @@ -16,6 +16,7 @@ ctx->err_info = errno; \ snprintf(ctx->filebuf, sizeof(ctx->filebuf), "%s", \ __FILE__); \ + ctx->filebuf[sizeof(ctx->filebuf) - 1] = '\0'; \ ctx->errline = __LINE__; \ } while (0) diff --git a/include/spho/spho.h b/include/spho/spho.h index 900444f..780e5d7 100644 --- a/include/spho/spho.h +++ b/include/spho/spho.h @@ -7,26 +7,4 @@ #include "spho/data.h" -#define SPHO_ERR_BUF_LEN 2048 -#define SPHO_ERR_FILEBUF_LEN 128 - -struct spho_ctx { - int err; - int err_info; - - struct spho_nom_l noms; - struct spho_const_l cnsts; - -#ifdef SPHO_DEBUG - char filebuf[SPHO_ERR_FILEBUF_LEN]; - int errline; -#else - char errbuf[SPHO_ERR_BUF_LEN]; -#endif -}; - -struct spho_ctx *spho_ctx_create(void); -void spho_ctx_destroy(struct spho_ctx *); -char *spho_ctx_strerror(struct spho_ctx *); - #endif diff --git a/src/run/devcheck.c b/src/run/devcheck.c index e69de29..9a59086 100644 --- a/src/run/devcheck.c +++ b/src/run/devcheck.c @@ -0,0 +1,6 @@ + + +int main(void) +{ + return (0); +} diff --git a/src/spho/ctx.c b/src/spho/ctx.c index 938863f..e1a39c3 100644 --- a/src/spho/ctx.c +++ b/src/spho/ctx.c @@ -1,15 +1,18 @@ +#include #include +#include #include +#include "spho/err.h" #include "spho/ctx.h" static const char *spho_ctx_sys_strerror(struct spho_ctx *); static const char *spho_ctx_intern_strerror(struct spho_ctx *); struct spho_err { - int num; - char *msg; + int err; + const char *msg; }; struct spho_err spho_errmsgs[] = { @@ -43,15 +46,15 @@ spho_ctx_destroy(struct spho_ctx *ctx) SPHO_PRECOND(ctx != NULL); - while (! SLIST_EMPTY(&c->noms)) { - nom = SLIST_FIRST(&c->noms); - SLIST_REMOVE_HEAD(&c->noms, next); + while (! SLIST_EMPTY(&ctx->noms)) { + nom = SLIST_FIRST(&ctx->noms); + SLIST_REMOVE_HEAD(&ctx->noms, next); free(nom); } - while (! SLIST_EMPTY(&c->cnsts)) { - cnst = SLIST_FIRST(&c->cnsts); - SLIST_REMOVE_HEAD(&c->cnsts, next); + while (! SLIST_EMPTY(&ctx->cnsts)) { + cnst = SLIST_FIRST(&ctx->cnsts); + SLIST_REMOVE_HEAD(&ctx->cnsts, next); free(cnst); } } @@ -60,8 +63,8 @@ spho_ctx_destroy(struct spho_ctx *ctx) const char * spho_ctx_strerror(struct spho_ctx *ctx) { - char *msg; int res; + const char *msg; SPHO_PRECOND(ctx != NULL); @@ -81,6 +84,10 @@ spho_ctx_strerror(struct spho_ctx *ctx) static const char * spho_ctx_sys_strerror(struct spho_ctx *ctx) { + int res; + + SPHO_POSTCOND(ctx != NULL); + #ifdef SPHO_DEBUG res = snprintf(ctx->errbuf, sizeof(ctx->errbuf), "%s:%d:spho_syserr:%s (%d)", ctx->filebuf, ctx->errline, @@ -89,8 +96,8 @@ spho_ctx_sys_strerror(struct spho_ctx *ctx) ctx->errbuf[sizeof(ctx->errbuf) - 1] = '\0'; #else res = snprintf(ctx->errbuf, sizeof(ctx->errbuf), - "spho_syserr:%s (%d)", ctx->filebuf, ctx->errline, - strerror(ctx->err_info), ctx->err_info); + "spho_syserr:%s (%d)", strerror(ctx->err_info), + ctx->err_info); if (res >= sizeof(ctx->errbuf)) ctx->errbuf[sizeof(ctx->errbuf) - 1] = '\0'; #endif