From 40df1261b2c161a5e4fddd599d5d77bd0ebec930 Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Fri, 3 May 2019 13:01:24 +0300 Subject: simplify error strings --- openbsd/__init__.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'openbsd') diff --git a/openbsd/__init__.py b/openbsd/__init__.py index 1aab185..e321f61 100644 --- a/openbsd/__init__.py +++ b/openbsd/__init__.py @@ -1,5 +1,6 @@ import sys +import os from cffi import FFI from ._openbsd import lib as _lib @@ -14,7 +15,7 @@ def pledge(promises=None, execpromises=None): ret = _lib.pledge(promises, execpromises) if ret < 0: errno = _ffi.errno - raise OSError(errno, _decode(_ffi.string(_lib.strerror(errno), 256))) + raise OSError(errno, os.strerror(errno)) def unveil(path=None, permissions=None): @@ -23,7 +24,7 @@ def unveil(path=None, permissions=None): ret = _lib.unveil(path, permissions) if ret < 0: errno = _ffi.errno - raise OSError(errno, _decode(_ffi.string(_lib.strerror(errno), 256))) + raise OSError(errno, os.strerror(errno)) if isinstance(b"openbsd", str): @@ -32,9 +33,6 @@ if isinstance(b"openbsd", str): if isinstance(text, unicode): return text.encode("ascii") return text - - def _decode(text): - return text else: # Python 3 def _encode(text): @@ -42,7 +40,4 @@ else: return text.encode("ascii") return text - def _decode(text): - return text.decode("ascii") - -- cgit 1.4.1-2-gfad0 From aefef1875c0d367e720c4b68919210bb34d755bc Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Fri, 3 May 2019 13:07:56 +0300 Subject: removed strerror --- openbsd/__init__.py | 1 - openbsd/openbsd_builder.py | 2 -- 2 files changed, 3 deletions(-) (limited to 'openbsd') diff --git a/openbsd/__init__.py b/openbsd/__init__.py index e321f61..a688661 100644 --- a/openbsd/__init__.py +++ b/openbsd/__init__.py @@ -5,7 +5,6 @@ from cffi import FFI from ._openbsd import lib as _lib __all__ = ["pledge", "unveil"] - _ffi = FFI() diff --git a/openbsd/openbsd_builder.py b/openbsd/openbsd_builder.py index a8720c1..7778796 100644 --- a/openbsd/openbsd_builder.py +++ b/openbsd/openbsd_builder.py @@ -5,13 +5,11 @@ ffibuilder = FFI() ffibuilder.cdef(''' int pledge(const char *promises, const char *execpromises); int unveil(const char *path, const char *permissions); - char *strerror(int errnum); ''') ffibuilder.set_source("openbsd._openbsd", """ #include - #include """) if __name__ == "__main__": -- cgit 1.4.1-2-gfad0 anger.py?h=v1.7.2&id=30a35e6a7b95a06709590dc56afb96ea7ccecb62'>blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52