shared: add NM_AUTO_PROTECT_ERRNO

Similar to systemd's PROTECT_ERRNO. The difference it, that it doesn't
treat the auto-variable as internal, so it is allowed to use it. E.g.

    if (!(fd = open (...)) {
        NM_AUTO_PROTECT_ERRNO (errno_saved);
        printf ("error: %s", g_strerror (errno_saved));
        return FALSE;
    }
This commit is contained in:
Thomas Haller 2016-12-11 22:35:44 +01:00
parent 215c50922d
commit 99e1e4d6a1

View file

@ -85,6 +85,13 @@ _nm_auto_fclose_impl (FILE **pfd)
}
#define nm_auto_fclose nm_auto(_nm_auto_fclose_impl)
static inline void
_nm_auto_protect_errno (int *p_saved_errno)
{
errno = *p_saved_errno;
}
#define NM_AUTO_PROTECT_ERRNO(errsv_saved) nm_auto(_nm_auto_protect_errno) _nm_unused const int errsv_saved = (errno)
/*****************************************************************************/
/* http://stackoverflow.com/a/11172679 */