On Sunday 02 May 2004 04:13 pm, Stas Bekman wrote: > Really I was looking at some place where I can define my own map of > code/string pairs and still reuse apr_strerror. I suppose the right way to > go is to define a wrapper function: > > char * my_strerror(apr_status_t statcode, char *buf, apr_size_t bufsize) > { > if (statcode < APR_OS_START_USERERR) { > return apr_strerror(statcode, buf, bufsize); > } > else { > /* handle custom errors here */ > } > } > > Is that the right way to go?
I can't speak for the architects of APR but this is what I ended up doing. It doesn't feel like an optimal solution, really. What about people building on your library, what do they do? But it is very similar to other libraries I have used over the years in this respect. My code ended up looking like: /* In my include file... */ #define MY_OS_START_ERROR APR_OS_START_USERERR #define MY_OS_START_USERERR (APR_OS_START_USERERR + 500) /* In the related source file: char *my_strerror (/* ... */) { if (statcode < MY_OS_START_ERROR) { return apr_strerror(/* ... */); } else if (statcode < MY_OS_START_USERERR) { /* custom errors from my library */ } else if (statcode < APR_OS_START_CANONERR) { /* don't know what this is, throw impossible error code string */ } else { return apr_strerror(/* ... */); } } It's been awhile since I wrote this code but I think the idea was to provide a higher-level library than mine with a way to have it's own errors which would start at MY_OS_START_USERERR just like mine started at APR_OS_START_USERERR. mma