curl / Mailing Lists / curl-library / Single Mail

curl-library

curl errors to symbol string functions? was Re: libcurl smtp error list?

From: Richard Gray <rgray_at_plustechnologies.com>
Date: Fri, 29 Jun 2018 15:03:42 -0400

Gisle Vanem wrote:
> ... But if
> you want a full list of 'CURLE_x' and 'CURLOPT_x' values
> a priori or within your program, I've cooked up this
> GNU-makefile that generates such a list:
>   https://gist.github.com/gvanem/4290a4c74ac75983928502303cb4c0c2
>
> Tested on Windows using MinGW and MSVC only. I'd
> be interested to hear if this mk-opt-err-list.mak
> works on non-Windows too.

Frustrated with log/debug output which showed "... errno = 123", I wrote a
script that can scan the operating system include file(s) that contain errno
defines on our various *ix platforms and produce a list of available errno
values in various formats:

- bare list of errno symbols

- c errno table with number & symbol (below)

- c errno table with lookup functions

      const char *errno_sym(int num, const char *unk_rtn)

      int errno_num(const char *sym)

- c errno table with lookup functions and test main().

/* System specific code for hp-ux generated by errnosym.sh */

#include <errno.h>

#define STRINGIFY(s) #s
const struct errno_table_struct
    { int errno_num; char *errno_sym; }
    errno_table[] = {
       { EDOM, STRINGIFY(EDOM) },
       { ERANGE, STRINGIFY(ERANGE) },
       { EPERM, STRINGIFY(EPERM) },
       { ENOENT, STRINGIFY(ENOENT) },
       { ESRCH, STRINGIFY(ESRCH) },
       { EINTR, STRINGIFY(EINTR) },
       { EIO, STRINGIFY(EIO) },
  ...
       { ECONFIG, STRINGIFY(ECONFIG) },
       { ENOREG, STRINGIFY(ENOREG) },
       { ENOUNREG, STRINGIFY(ENOUNREG) },
       { -1, NULL } };

So instead of a log message like

   XYZ037 Frambastat could not be initialized, errno = 226

we can add the symbol

   XYZ037 Frambastat could not be initialized, errno = 226 (EADDRINUSE)

which is more meaningful, particularly given that the higher errno values are
different on different platforms. We could use strerror(), but it's messages
are much longer and sometimes not quite right in the context of an error we get.

Perhaps libcurl could do something like this to support error number to symbol
functions like:

  const char *curl_easy_strerror_sym(CURLcode e) and

  const char *curl_multi_strerror_sym(CURLMcode e)

Rich
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2018-06-29