Write('\r\n') Write('redbean\r\n') Write('\r\n') Write('

UNIX Directory Stream Demo

\r\n') Write('\r\n') Write('\r\n') Write('\r\n') Write('\r\n') dir = '.' for name, kind, ino, off in assert(unix.opendir(dir)) do Write('\r\n') Write('
name\r\n') Write('type\r\n') Write('ino\r\n') Write('off\r\n') Write('size\r\n') Write('blocks\r\n') Write('mode\r\n') Write('uid\r\n') Write('gid\r\n') Write('dev\r\n') Write('rdev\r\n') Write('nlink\r\n') Write('blksize\r\n') Write('gen\r\n') Write('flags\r\n') Write('birthtim\r\n') Write('mtim\r\n') Write('atim\r\n') Write('ctim\r\n') Write('
') Write(EscapeHtml(name)) if kind == unix.DT_DIR then Write('/') end Write('\r\n') Write('') if kind == unix.DT_REG then Write('DT_REG') elseif kind == unix.DT_DIR then Write('DT_DIR') elseif kind == unix.DT_FIFO then Write('DT_FIFO') elseif kind == unix.DT_CHR then Write('DT_CHR') elseif kind == unix.DT_BLK then Write('DT_BLK') elseif kind == unix.DT_LNK then Write('DT_LNK') elseif kind == unix.DT_SOCK then Write('DT_SOCK') else Write('DT_UNKNOWN') end Write('\r\n') Write('%d\r\n' % {ino}) Write('%d\r\n' % {off}) st,err = unix.stat(dir..'/'..name, unix.AT_SYMLINK_NOFOLLOW) if st then Write('%d\r\n' % {st:size()}) Write('%d\r\n' % {st:blocks()}) Write('%.7o\r\n' % {st:mode()}) Write('%d\r\n' % {st:uid()}) Write('%d\r\n' % {st:gid()}) Write('%d\r\n' % {st:dev()}) Write('%d,%d\r\n' % {unix.major(st:rdev()), unix.minor(st:rdev())}) Write('%d\r\n' % {st:nlink()}) Write('%d\r\n' % {st:blksize()}) Write('%d\r\n' % {st:gen()}) Write('%#x\r\n' % {st:flags()}) function WriteTime(unixsec,nanos) year,mon,mday,hour,min,sec,gmtoffsec = unix.localtime(unixsec) Write('%.4d-%.2d-%.2dT%.2d:%.2d:%.2d.%.9d%+.2d%.2d\r\n' % { year, mon, mday, hour, min, sec, nanos, gmtoffsec / (60 * 60), math.abs(gmtoffsec) % 60}) end WriteTime(st:birthtim()) WriteTime(st:mtim()) WriteTime(st:atim()) WriteTime(st:ctim()) else Write('%s\r\n' % {err}) end end Write('
\r\n')