diff options
Diffstat (limited to 'src/pj_ctx.c')
| -rw-r--r-- | src/pj_ctx.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/pj_ctx.c b/src/pj_ctx.c index 32a3d690..7ba85e78 100644 --- a/src/pj_ctx.c +++ b/src/pj_ctx.c @@ -27,6 +27,7 @@ #include <projects.h> #include <string.h> +#include <errno.h> static projCtx_t default_context; static volatile int default_context_initialized = 0; @@ -40,6 +41,8 @@ projCtx pj_get_ctx( projPJ pj ) { if (0==pj) return pj_get_default_ctx (); + if (0==pj->ctx) + return pj_get_default_ctx (); return pj->ctx; } @@ -130,14 +133,20 @@ int pj_ctx_get_errno( projCtx ctx ) /* pj_ctx_set_errno() */ /* */ /* Also sets the global errno. */ +/* Since pj_errno makes sense in single threaded cases only, */ +/* we set it only when called on the default context. */ /************************************************************************/ void pj_ctx_set_errno( projCtx ctx, int new_errno ) { ctx->last_errno = new_errno; - if( new_errno != 0 ) - pj_errno = new_errno; + if (ctx!=pj_get_default_ctx()) + return; + if( new_errno == 0 ) + return; + pj_errno = new_errno; + errno = new_errno; } /************************************************************************/ |
