Last active
November 8, 2020 03:38
-
-
Save JamesTheAwesomeDude/a1ee5ff451e6cd101fbcede292b2c095 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fcntl | |
def modfl(fd, flags): | |
'''Adds all given positive flags to, and removes all given negative flags from, the given file descriptor''' | |
# e.g.: modfl(f, (+os.O_SYNC, -os.O_NONBLOCK)) | |
# would make f synchronous and blocking | |
#OR-in positive flags; NAND-out negative ones | |
ins = lambda fl, x: (fl | x) if x >= 0 else (fl &~ -x) | |
# 1. Get the current flag field | |
cur = fcntl.fcntl(fd,fcntl.F_GETFL) | |
# 2. Calculate the new flag field | |
new = reduce(ins, flags, cur) | |
# 3. Apply the new flag field | |
return fcntl.fcntl(fd, fcntl.F_SETFL, new) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment