本文整理汇总了C++中PyErr_SetFromErrno函数的典型用法代码示例。如果您正苦于以下问题:C++ PyErr_SetFromErrno函数的具体用法?C++ PyErr_SetFromErrno怎么用?C++ PyErr_SetFromErrno使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PyErr_SetFromErrno函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: psutil_disk_partitions
/*
* Return disk mounted partitions as a list of tuples including device,
* mount point and filesystem type.
*/
static PyObject *
psutil_disk_partitions(PyObject *self, PyObject *args)
{
FILE *file;
struct mnttab mt;
PyObject *py_retlist = PyList_New(0);
PyObject *py_tuple = NULL;
if (py_retlist == NULL)
return NULL;
file = fopen(MNTTAB, "rb");
if (file == NULL) {
PyErr_SetFromErrno(PyExc_OSError);
goto error;
}
while (getmntent(file, &mt) == 0) {
py_tuple = Py_BuildValue(
"(ssss)",
mt.mnt_special, // device
mt.mnt_mountp, // mount point
mt.mnt_fstype, // fs type
mt.mnt_mntopts); // options
if (py_tuple == NULL)
goto error;
if (PyList_Append(py_retlist, py_tuple))
goto error;
Py_DECREF(py_tuple);
}
fclose(file);
return py_retlist;
error:
Py_XDECREF(py_tuple);
Py_DECREF(py_retlist);
if (file != NULL)
fclose(file);
return NULL;
}
示例2: dbm_ass_sub
static int
dbm_ass_sub(dbmobject *dp, PyObject *v, PyObject *w)
{
datum krec, drec;
if (!PyArg_Parse(v, "s#", &krec.dptr, &krec.dsize) ) {
PyErr_SetString(PyExc_TypeError,
"gdbm mappings have string indices only");
return -1;
}
if (dp->di_dbm == NULL) {
PyErr_SetString(DbmError,
"GDBM object has already been closed");
return -1;
}
dp->di_size = -1;
if (w == NULL) {
if (gdbm_delete(dp->di_dbm, krec) < 0) {
PyErr_SetString(PyExc_KeyError,
PyString_AS_STRING((PyStringObject *)v));
return -1;
}
}
else {
if (!PyArg_Parse(w, "s#", &drec.dptr, &drec.dsize)) {
PyErr_SetString(PyExc_TypeError,
"gdbm mappings have string elements only");
return -1;
}
errno = 0;
if (gdbm_store(dp->di_dbm, krec, drec, GDBM_REPLACE) < 0) {
if (errno != 0)
PyErr_SetFromErrno(DbmError);
else
PyErr_SetString(DbmError,
gdbm_strerror(gdbm_errno));
return -1;
}
}
return 0;
}
示例3: psutil_proc_exe
/*
* Return process pathname executable.
* Thanks to Robert N. M. Watson:
* http://fxr.googlebit.com/source/usr.bin/procstat/procstat_bin.c?v=8-CURRENT
*/
PyObject *
psutil_proc_exe(PyObject *self, PyObject *args) {
long pid;
char pathname[PATH_MAX];
int error;
int mib[4];
int ret;
size_t size;
const char *encoding_errs;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = pid;
size = sizeof(pathname);
error = sysctl(mib, 4, pathname, &size, NULL, 0);
if (error == -1) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
if (size == 0 || strlen(pathname) == 0) {
ret = psutil_pid_exists(pid);
if (ret == -1)
return NULL;
else if (ret == 0)
return NoSuchProcess();
else
strcpy(pathname, "");
}
#if PY_MAJOR_VERSION >= 3
return PyUnicode_DecodeFSDefault(pathname);
#else
return Py_BuildValue("s", pathname);
#endif
}
示例4: psutil_net_if_mtu
/*
* Return NIC MTU. References:
* http://www.i-scream.org/libstatgrab/
*/
static PyObject *
psutil_net_if_mtu(PyObject *self, PyObject *args) {
char *nic_name;
int sock = 0;
int ret;
#ifdef PSUTIL_SUNOS10
struct lifreq lifr;
#else
struct ifreq ifr;
#endif
if (! PyArg_ParseTuple(args, "s", &nic_name))
return NULL;
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock == -1)
goto error;
#ifdef PSUTIL_SUNOS10
strncpy(lifr.lifr_name, nic_name, sizeof(lifr.lifr_name));
ret = ioctl(sock, SIOCGIFMTU, &lifr);
#else
strncpy(ifr.ifr_name, nic_name, sizeof(ifr.ifr_name));
ret = ioctl(sock, SIOCGIFMTU, &ifr);
#endif
if (ret == -1)
goto error;
close(sock);
#ifdef PSUTIL_SUNOS10
return Py_BuildValue("i", lifr.lifr_mtu);
#else
return Py_BuildValue("i", ifr.ifr_mtu);
#endif
error:
if (sock != 0)
close(sock);
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
示例5: PyFile_AsFile
static PyObject *bits_disk_write(PyObject *self, PyObject *args)
{
PyObject *pyfile;
grub_file_t file;
grub_disk_addr_t sector;
const char *data;
unsigned offset;
int length;
if (!PyArg_ParseTuple(args, "O!KIs#:disk_write", &PyFile_Type, &pyfile, §or, &offset, &data, &length))
return NULL;
file = PyFile_AsFile(pyfile);
if (!file->device->disk)
return PyErr_Format(PyExc_RuntimeError, "Can't get disk device from non-disk-backed file");
if (grub_disk_write(file->device->disk, sector, offset, length, data) != GRUB_ERR_NONE)
return PyErr_SetFromErrno(PyExc_IOError);
return Py_BuildValue("");
}
示例6: pytalloc_get_ptr
static PyObject *py_socket_write(pytalloc_Object *self, PyObject *args)
{
char *buffer;
int len;
int *sock;
int status;
if (!PyArg_ParseTuple(args, "s#:write", &buffer, &len)) {
return NULL;
}
sock = pytalloc_get_ptr(self);
status = swrap_send(*sock, buffer, len, 0);
if (status < 0) {
PyErr_SetFromErrno(py_socket_error);
return NULL;
}
Py_RETURN_NONE;
}
示例7: method_sendfile
static PyObject *
method_sendfile(PyObject *self, PyObject *args)
{
int out_fd, in_fd;
off_t offset;
size_t count;
ssize_t sts;
if (!PyArg_ParseTuple(args, "iiLk", &out_fd, &in_fd, &offset, &count))
return NULL;
Py_BEGIN_ALLOW_THREADS;
sts = sendfile(out_fd, in_fd, (off_t *) &offset, (ssize_t) count);
Py_END_ALLOW_THREADS;
if (sts == -1) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
} else {
return Py_BuildValue("Lk", offset, sts);
}
}
示例8: psutil_proc_cwd
PyObject *
psutil_proc_cwd(PyObject *self, PyObject *args) {
// Reference:
// http://anoncvs.spacehopper.org/openbsd-src/tree/bin/ps/print.c#n179
long pid;
struct kinfo_proc kp;
char path[MAXPATHLEN];
size_t pathlen = sizeof path;
if (! PyArg_ParseTuple(args, "l", &pid))
return NULL;
if (psutil_kinfo_proc(pid, &kp) == -1)
return NULL;
int name[] = { CTL_KERN, KERN_PROC_CWD, pid };
if (sysctl(name, 3, path, &pathlen, NULL, 0) != 0) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return Py_BuildValue("s", path);
}
示例9: time_clock_settime
static PyObject *
time_clock_settime(PyObject *self, PyObject *args)
{
int clk_id;
PyObject *obj;
struct timespec tp;
int ret;
if (!PyArg_ParseTuple(args, "iO:clock_settime", &clk_id, &obj))
return NULL;
if (_PyTime_ObjectToTimespec(obj, &tp.tv_sec, &tp.tv_nsec) == -1)
return NULL;
ret = clock_settime((clockid_t)clk_id, &tp);
if (ret != 0) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
Py_RETURN_NONE;
}
示例10: get_system_cpu_times
/*
* Return a Python tuple representing user, kernel and idle CPU times
*/
static PyObject*
get_system_cpu_times(PyObject* self, PyObject* args)
{
long cpu_time[CPUSTATES];
size_t size;
size = sizeof(cpu_time);
if (sysctlbyname("kern.cp_time", &cpu_time, &size, NULL, 0) == -1) {
PyErr_SetFromErrno(0);
return NULL;
}
return Py_BuildValue("(ddddd)",
(double)cpu_time[CP_USER] / CLOCKS_PER_SEC,
(double)cpu_time[CP_NICE] / CLOCKS_PER_SEC,
(double)cpu_time[CP_SYS] / CLOCKS_PER_SEC,
(double)cpu_time[CP_IDLE] / CLOCKS_PER_SEC,
(double)cpu_time[CP_INTR] / CLOCKS_PER_SEC
);
}
示例11: SMBus_read_block_data
static PyObject *
SMBus_read_block_data(SMBus *self, PyObject *args)
{
int addr, cmd;
union i2c_smbus_data data;
if (!PyArg_ParseTuple(args, "ii:read_block_data", &addr, &cmd))
return NULL;
SMBus_SET_ADDR(self, addr);
/* save a bit of code by calling the access function directly */
if (i2c_smbus_access(self->fd, I2C_SMBUS_READ, (__u8)cmd,
I2C_SMBUS_BLOCK_DATA, &data)) {
PyErr_SetFromErrno(PyExc_IOError);
return NULL;
}
/* first byte of the block contains (remaining) data length */
return SMBus_buf_to_list(&data.block[1], data.block[0]);
}
示例12: read_init_file
static PyObject *
read_init_file(EditLineObject *self, PyObject *args)
{
PyObject *filename_obj = Py_None, *filename_bytes;
if (!PyArg_ParseTuple(args, "|O:read_init_file", &filename_obj))
return NULL;
if (filename_obj == Py_None)
return NULL;
if (!PyUnicode_FSConverter(filename_obj, &filename_bytes))
return NULL;
errno = el_source(self->el, PyBytes_AsString(filename_bytes));
Py_DECREF(filename_bytes);
if (errno)
return PyErr_SetFromErrno(PyExc_IOError);
Py_RETURN_NONE;
}
示例13: oss_write
static PyObject *
oss_write(oss_audio_t *self, PyObject *args)
{
char *cp;
int rv, size;
if (!PyArg_ParseTuple(args, "s#:write", &cp, &size)) {
return NULL;
}
Py_BEGIN_ALLOW_THREADS
rv = write(self->fd, cp, size);
Py_END_ALLOW_THREADS
if (rv == -1) {
return PyErr_SetFromErrno(PyExc_IOError);
} else {
self->ocount += rv;
}
return PyInt_FromLong(rv);
}
示例14: time_gmtime
static PyObject *
time_gmtime(PyObject *self, PyObject *args)
{
time_t when;
struct tm buf, *local;
if (!parse_time_t_args(args, "|O:gmtime", &when))
return NULL;
errno = 0;
local = gmtime(&when);
if (local == NULL) {
#ifdef EINVAL
if (errno == 0)
errno = EINVAL;
#endif
return PyErr_SetFromErrno(PyExc_OSError);
}
buf = *local;
return tmtotuple(&buf);
}
示例15: m_timerfd_create
static PyObject * m_timerfd_create(PyObject *self, PyObject *args, PyObject *kwargs)
{
char *kw[] = {"clockid", "flags", NULL};
long clockid = 0, flags = 0;
int t_res;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ll", kw, &clockid, &flags))
return NULL;
if (clockid == 0) {
clockid = CLOCK_MONOTONIC;
}
t_res = timerfd_create(clockid, flags);
if (t_res < 1) {
return PyErr_SetFromErrno(PyExc_IOError);
/* PyErr_SetString(ErrorObject, "timerfd_create system call faild."); */
/* return NULL; */
}
return (PyObject *)PyLong_FromLong(t_res);
}//m_timerfd_create()