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:
@@ -85,6 +85,13 @@ _nm_auto_fclose_impl (FILE **pfd)
|
|||||||
}
|
}
|
||||||
#define nm_auto_fclose nm_auto(_nm_auto_fclose_impl)
|
#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 */
|
/* http://stackoverflow.com/a/11172679 */
|
||||||
|
Reference in New Issue
Block a user