Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 1 | /*[clinic input] |
| 2 | preserve |
| 3 | [clinic start generated code]*/ |
| 4 | |
| 5 | PyDoc_STRVAR(fcntl_fcntl__doc__, |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 6 | "fcntl($module, fd, cmd, arg=0, /)\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 7 | "--\n" |
| 8 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 9 | "Perform the operation `cmd` on file descriptor fd.\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 10 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 11 | "The values used for `cmd` are operating system dependent, and are available\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 12 | "as constants in the fcntl module, using the same names as used in\n" |
| 13 | "the relevant C header files. The argument arg is optional, and\n" |
| 14 | "defaults to 0; it may be an int or a string. If arg is given as a string,\n" |
| 15 | "the return value of fcntl is a string of that length, containing the\n" |
| 16 | "resulting value put in the arg buffer by the operating system. The length\n" |
| 17 | "of the arg string is not allowed to exceed 1024 bytes. If the arg given\n" |
| 18 | "is an integer or if none is specified, the result value is an integer\n" |
| 19 | "corresponding to the return value of the fcntl call in the C code."); |
| 20 | |
| 21 | #define FCNTL_FCNTL_METHODDEF \ |
| 22 | {"fcntl", (PyCFunction)fcntl_fcntl, METH_VARARGS, fcntl_fcntl__doc__}, |
| 23 | |
| 24 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 25 | fcntl_fcntl_impl(PyObject *module, int fd, int code, PyObject *arg); |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 26 | |
| 27 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 28 | fcntl_fcntl(PyObject *module, PyObject *args) |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 29 | { |
| 30 | PyObject *return_value = NULL; |
| 31 | int fd; |
| 32 | int code; |
| 33 | PyObject *arg = NULL; |
| 34 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 35 | if (!PyArg_ParseTuple(args, "O&i|O:fcntl", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 36 | conv_descriptor, &fd, &code, &arg)) { |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 37 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 38 | } |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 39 | return_value = fcntl_fcntl_impl(module, fd, code, arg); |
| 40 | |
| 41 | exit: |
| 42 | return return_value; |
| 43 | } |
| 44 | |
| 45 | PyDoc_STRVAR(fcntl_ioctl__doc__, |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 46 | "ioctl($module, fd, request, arg=0, mutate_flag=True, /)\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 47 | "--\n" |
| 48 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 49 | "Perform the operation `request` on file descriptor `fd`.\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 50 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 51 | "The values used for `request` are operating system dependent, and are available\n" |
| 52 | "as constants in the fcntl or termios library modules, using the same names as\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 53 | "used in the relevant C header files.\n" |
| 54 | "\n" |
| 55 | "The argument `arg` is optional, and defaults to 0; it may be an int or a\n" |
| 56 | "buffer containing character data (most likely a string or an array).\n" |
| 57 | "\n" |
| 58 | "If the argument is a mutable buffer (such as an array) and if the\n" |
| 59 | "mutate_flag argument (which is only allowed in this case) is true then the\n" |
| 60 | "buffer is (in effect) passed to the operating system and changes made by\n" |
| 61 | "the OS will be reflected in the contents of the buffer after the call has\n" |
| 62 | "returned. The return value is the integer returned by the ioctl system\n" |
| 63 | "call.\n" |
| 64 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 65 | "If the argument is a mutable buffer and the mutable_flag argument is false,\n" |
| 66 | "the behavior is as if a string had been passed.\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 67 | "\n" |
| 68 | "If the argument is an immutable buffer (most likely a string) then a copy\n" |
| 69 | "of the buffer is passed to the operating system and the return value is a\n" |
| 70 | "string of the same length containing whatever the operating system put in\n" |
| 71 | "the buffer. The length of the arg buffer in this case is not allowed to\n" |
| 72 | "exceed 1024 bytes.\n" |
| 73 | "\n" |
| 74 | "If the arg given is an integer or if none is specified, the result value is\n" |
| 75 | "an integer corresponding to the return value of the ioctl call in the C\n" |
| 76 | "code."); |
| 77 | |
| 78 | #define FCNTL_IOCTL_METHODDEF \ |
| 79 | {"ioctl", (PyCFunction)fcntl_ioctl, METH_VARARGS, fcntl_ioctl__doc__}, |
| 80 | |
| 81 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 82 | fcntl_ioctl_impl(PyObject *module, int fd, unsigned int code, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 83 | PyObject *ob_arg, int mutate_arg); |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 84 | |
| 85 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 86 | fcntl_ioctl(PyObject *module, PyObject *args) |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 87 | { |
| 88 | PyObject *return_value = NULL; |
| 89 | int fd; |
| 90 | unsigned int code; |
| 91 | PyObject *ob_arg = NULL; |
| 92 | int mutate_arg = 1; |
| 93 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 94 | if (!PyArg_ParseTuple(args, "O&I|Op:ioctl", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 95 | conv_descriptor, &fd, &code, &ob_arg, &mutate_arg)) { |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 96 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 97 | } |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 98 | return_value = fcntl_ioctl_impl(module, fd, code, ob_arg, mutate_arg); |
| 99 | |
| 100 | exit: |
| 101 | return return_value; |
| 102 | } |
| 103 | |
| 104 | PyDoc_STRVAR(fcntl_flock__doc__, |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 105 | "flock($module, fd, operation, /)\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 106 | "--\n" |
| 107 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 108 | "Perform the lock operation `operation` on file descriptor `fd`.\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 109 | "\n" |
| 110 | "See the Unix manual page for flock(2) for details (On some systems, this\n" |
| 111 | "function is emulated using fcntl())."); |
| 112 | |
| 113 | #define FCNTL_FLOCK_METHODDEF \ |
| 114 | {"flock", (PyCFunction)fcntl_flock, METH_VARARGS, fcntl_flock__doc__}, |
| 115 | |
| 116 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 117 | fcntl_flock_impl(PyObject *module, int fd, int code); |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 118 | |
| 119 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 120 | fcntl_flock(PyObject *module, PyObject *args) |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 121 | { |
| 122 | PyObject *return_value = NULL; |
| 123 | int fd; |
| 124 | int code; |
| 125 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 126 | if (!PyArg_ParseTuple(args, "O&i:flock", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 127 | conv_descriptor, &fd, &code)) { |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 128 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 129 | } |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 130 | return_value = fcntl_flock_impl(module, fd, code); |
| 131 | |
| 132 | exit: |
| 133 | return return_value; |
| 134 | } |
| 135 | |
| 136 | PyDoc_STRVAR(fcntl_lockf__doc__, |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 137 | "lockf($module, fd, cmd, len=0, start=0, whence=0, /)\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 138 | "--\n" |
| 139 | "\n" |
| 140 | "A wrapper around the fcntl() locking calls.\n" |
| 141 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 142 | "`fd` is the file descriptor of the file to lock or unlock, and operation is one\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 143 | "of the following values:\n" |
| 144 | "\n" |
| 145 | " LOCK_UN - unlock\n" |
| 146 | " LOCK_SH - acquire a shared lock\n" |
| 147 | " LOCK_EX - acquire an exclusive lock\n" |
| 148 | "\n" |
| 149 | "When operation is LOCK_SH or LOCK_EX, it can also be bitwise ORed with\n" |
| 150 | "LOCK_NB to avoid blocking on lock acquisition. If LOCK_NB is used and the\n" |
Serhiy Storchaka | d6117a4 | 2016-04-14 12:28:01 +0300 | [diff] [blame] | 151 | "lock cannot be acquired, an OSError will be raised and the exception will\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 152 | "have an errno attribute set to EACCES or EAGAIN (depending on the operating\n" |
| 153 | "system -- for portability, check for either value).\n" |
| 154 | "\n" |
Serhiy Storchaka | 17d3a58 | 2015-03-20 20:04:21 +0200 | [diff] [blame] | 155 | "`len` is the number of bytes to lock, with the default meaning to lock to\n" |
| 156 | "EOF. `start` is the byte offset, relative to `whence`, to that the lock\n" |
| 157 | "starts. `whence` is as with fileobj.seek(), specifically:\n" |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 158 | "\n" |
| 159 | " 0 - relative to the start of the file (SEEK_SET)\n" |
| 160 | " 1 - relative to the current buffer position (SEEK_CUR)\n" |
| 161 | " 2 - relative to the end of the file (SEEK_END)"); |
| 162 | |
| 163 | #define FCNTL_LOCKF_METHODDEF \ |
| 164 | {"lockf", (PyCFunction)fcntl_lockf, METH_VARARGS, fcntl_lockf__doc__}, |
| 165 | |
| 166 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 167 | fcntl_lockf_impl(PyObject *module, int fd, int code, PyObject *lenobj, |
Larry Hastings | 89964c4 | 2015-04-14 18:07:59 -0400 | [diff] [blame] | 168 | PyObject *startobj, int whence); |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 169 | |
| 170 | static PyObject * |
Serhiy Storchaka | 1a2b24f | 2016-07-07 17:35:15 +0300 | [diff] [blame] | 171 | fcntl_lockf(PyObject *module, PyObject *args) |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 172 | { |
| 173 | PyObject *return_value = NULL; |
| 174 | int fd; |
| 175 | int code; |
| 176 | PyObject *lenobj = NULL; |
| 177 | PyObject *startobj = NULL; |
| 178 | int whence = 0; |
| 179 | |
Serhiy Storchaka | 247789c | 2015-04-24 00:40:51 +0300 | [diff] [blame] | 180 | if (!PyArg_ParseTuple(args, "O&i|OOi:lockf", |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 181 | conv_descriptor, &fd, &code, &lenobj, &startobj, &whence)) { |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 182 | goto exit; |
Serhiy Storchaka | 5dee655 | 2016-06-09 16:16:06 +0300 | [diff] [blame] | 183 | } |
Brett Cannon | b7299dd | 2014-11-09 20:22:01 -0500 | [diff] [blame] | 184 | return_value = fcntl_lockf_impl(module, fd, code, lenobj, startobj, whence); |
| 185 | |
| 186 | exit: |
| 187 | return return_value; |
| 188 | } |
Serhiy Storchaka | 2954f83 | 2016-07-07 18:20:03 +0300 | [diff] [blame] | 189 | /*[clinic end generated code: output=36cff76a8fb2c9a6 input=a9049054013a1b77]*/ |