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