describe lposix:
- before:
fcntl, fileno = posix.fcntl, posix.fileno
O_NONBLOCK = posix.O_NONBLOCK
- context with fcntl F_GETFL:
- before:
F_GETFL, F_SETFL = posix.F_GETFL, posix.F_SETFL
fdin = fileno (io.stdin)
flags = fcntl (fdin, F_GETFL)
restore = flags
- after:
fcntl (fdin, F_SETFL, restore)
- it returns flags as a non-negative number:
expect (type (flags)).should_be "number"
expect (flags >= 0).should_be (true)
- it resets O_NONBLOCK bit, if any:
fcntl (fdin, F_SETFL, band (flags, bnot (O_NONBLOCK)))
flags = fcntl (fdin, F_GETFL)
expect (band (flags, O_NONBLOCK)).should_be (0)
- it sets O_NONBLOCK bit:
fcntl (fdin, F_SETFL, bor (flags, O_NONBLOCK))
flags = fcntl (fdin, F_GETFL)
expect (band (flags, O_NONBLOCK)).should_not_be (0)
- it returns nil for negative fd argument:
ret, msg, errno = fcntl (-7, F_GETFL)
expect (ret).should_be (nil)
- it returns nil for unopened fd argument:
ret, msg, errno = fcntl (666, F_GETFL)
expect (ret).should_be (nil)
- it diagnoses incorrect userdata argument:
expect (fcntl ("foobar", F_GETFL)).should_error "int expected"