paul@6 | 1 | #!/usr/bin/env python |
paul@6 | 2 | |
paul@328 | 3 | """ |
paul@328 | 4 | POSIX input/output functions. |
paul@328 | 5 | |
paul@328 | 6 | Copyright (C) 2016 Paul Boddie <paul@boddie.org.uk> |
paul@328 | 7 | |
paul@328 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@328 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@328 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@328 | 11 | version. |
paul@328 | 12 | |
paul@328 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@328 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@328 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@328 | 16 | details. |
paul@328 | 17 | |
paul@328 | 18 | You should have received a copy of the GNU General Public License along with |
paul@328 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@328 | 20 | """ |
paul@328 | 21 | |
paul@328 | 22 | import native |
paul@328 | 23 | |
paul@6 | 24 | def close(fd): pass |
paul@6 | 25 | def closerange(fd_low, fd_high): pass |
paul@6 | 26 | def dup(fd): pass |
paul@6 | 27 | def dup2(old_fd, new_fd): pass |
paul@328 | 28 | def fchdir(fd): pass |
paul@6 | 29 | def fchmod(fd, mode): pass |
paul@6 | 30 | def fchown(fd, uid, gid): pass |
paul@328 | 31 | def fdatasync(fd): pass |
paul@328 | 32 | |
paul@328 | 33 | def fdopen(fd, mode="r"): |
paul@328 | 34 | |
paul@328 | 35 | """ |
paul@328 | 36 | Open a stream for the given file descriptor 'fd', operating in the given |
paul@328 | 37 | 'mode'. |
paul@328 | 38 | """ |
paul@328 | 39 | |
paul@328 | 40 | _check_fd(fd) |
paul@328 | 41 | _check_string(mode) |
paul@328 | 42 | return native._fdopen(fd, mode) |
paul@328 | 43 | |
paul@6 | 44 | def fpathconf(fd, name): pass |
paul@6 | 45 | def fstat(fd): pass |
paul@6 | 46 | def fstatvfs(fd): pass |
paul@328 | 47 | def fsync(fd): pass |
paul@6 | 48 | def ftruncate(fd, length): pass |
paul@6 | 49 | def isatty(fd): pass |
paul@328 | 50 | |
paul@328 | 51 | SEEK_CUR = 1 |
paul@328 | 52 | SEEK_END = 2 |
paul@328 | 53 | SEEK_SET = 0 |
paul@328 | 54 | |
paul@6 | 55 | def lseek(fd, pos, how): pass |
paul@6 | 56 | def open(filename, flag, mode=0777): pass |
paul@6 | 57 | def openpty(): pass |
paul@6 | 58 | def pipe(): pass |
paul@6 | 59 | def putenv(key, value): pass |
paul@328 | 60 | |
paul@328 | 61 | def read(fd, n): |
paul@328 | 62 | |
paul@328 | 63 | """ |
paul@328 | 64 | Read using the low-level file descriptor 'fd' the given number of bytes 'n'. |
paul@328 | 65 | """ |
paul@328 | 66 | |
paul@328 | 67 | _check_fd(fd) |
paul@328 | 68 | _check_int(n) |
paul@328 | 69 | return native._read(fd, n) |
paul@328 | 70 | |
paul@6 | 71 | def times(): pass |
paul@6 | 72 | def ttyname(fd): pass |
paul@6 | 73 | def umask(new_mask): pass |
paul@6 | 74 | def uname(): pass |
paul@6 | 75 | def unsetenv(key): pass |
paul@328 | 76 | |
paul@328 | 77 | def write(fd, s): |
paul@328 | 78 | |
paul@328 | 79 | "Write using the low-level file descriptor 'fd' the given string 's'." |
paul@328 | 80 | |
paul@328 | 81 | _check_fd(fd) |
paul@328 | 82 | _check_string(s) |
paul@328 | 83 | native._write(fd, s) |
paul@6 | 84 | |
paul@6 | 85 | O_APPEND = 1024 |
paul@6 | 86 | O_ASYNC = 8192 |
paul@6 | 87 | O_CREAT = 64 |
paul@6 | 88 | O_DIRECT = 16384 |
paul@6 | 89 | O_DIRECTORY = 65536 |
paul@6 | 90 | O_DSYNC = 4096 |
paul@6 | 91 | O_EXCL = 128 |
paul@6 | 92 | O_LARGEFILE = 32768 |
paul@6 | 93 | O_NDELAY = 2048 |
paul@6 | 94 | O_NOATIME = 262144 |
paul@6 | 95 | O_NOCTTY = 256 |
paul@6 | 96 | O_NOFOLLOW = 131072 |
paul@6 | 97 | O_NONBLOCK = 2048 |
paul@6 | 98 | O_RDONLY = 0 |
paul@6 | 99 | O_RDWR = 2 |
paul@6 | 100 | O_RSYNC = 1052672 |
paul@6 | 101 | O_SYNC = 1052672 |
paul@6 | 102 | O_TRUNC = 512 |
paul@6 | 103 | O_WRONLY = 1 |
paul@6 | 104 | |
paul@328 | 105 | def _check_fd(fd): |
paul@328 | 106 | |
paul@328 | 107 | "Check the given low-level file descriptor 'fd'." |
paul@328 | 108 | |
paul@328 | 109 | if not native._isinstance(fd, int): |
paul@328 | 110 | raise ValueError(fd) |
paul@328 | 111 | |
paul@328 | 112 | def _check_int(i): |
paul@328 | 113 | |
paul@328 | 114 | "Check the given int 'i'." |
paul@328 | 115 | |
paul@328 | 116 | if not native._isinstance(i, int): |
paul@328 | 117 | raise ValueError(i) |
paul@328 | 118 | |
paul@328 | 119 | def _check_string(s): |
paul@328 | 120 | |
paul@328 | 121 | "Check the given string 's'." |
paul@328 | 122 | |
paul@328 | 123 | if not native._isinstance(s, string): |
paul@328 | 124 | raise ValueError(s) |
paul@6 | 125 | |
paul@6 | 126 | # vim: tabstop=4 expandtab shiftwidth=4 |