diff options
author | Jose M. Guisado <jguisado@soleta.eu> | 2022-12-15 14:58:22 +0100 |
---|---|---|
committer | Jose M. Guisado <jguisado@soleta.eu> | 2022-12-15 17:46:42 +0100 |
commit | 5ec9ec73c8189023256a6d737600382f9e3d288a (patch) | |
tree | 88fcb4f4421611a71c43259f3cd56cf270eb849c /fdisk.c | |
parent | 975acaf5498223318ed2c61bf896dc982c1801f4 (diff) |
fdisk: add set_PyErr_from_rc
python-libfdisk raises Python exceptions when the libfdisk reports an
error when executing some function. libfdisk returns negative
errno values when reporting some error.
Adds utility function to set PyErr string based on the strerror of
a given errno code. Useful when raising Python exceptions.
Diffstat (limited to 'fdisk.c')
-rw-r--r-- | fdisk.c | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -14,6 +14,25 @@ #include "fdisk.h" +void *set_PyErr_from_rc(int e) +{ + switch (e) { + case ENOMEM: + PyErr_SetString(PyExc_MemoryError, strerror(e)); + break; + case EINVAL: + PyErr_SetString(PyExc_TypeError, strerror(e)); + break; + case ENOSYS: + PyErr_SetString(PyExc_NotImplementedError, strerror(e)); + break; + default: + PyErr_SetString(PyExc_Exception, strerror(e)); + } + + return NULL; +} + PyObject *PyObjectResultStr(const char *s) { PyObject *result; |