#
#
# Nim's Runtime Library
# (c) Copyright 2012 Andreas Rumpf
#
# See the file "copying.txt", included in this
# distribution, for details about the copyright.
#
# Until std_arg!!
# done: ipc, pwd, stat, semaphore, sys/types, sys/utsname, pthread, unistd,
# statvfs, mman, time, wait, signal, nl_types, sched, spawn, select, ucontext,
# net/if, sys/socket, sys/uio, netinet/in, netinet/tcp, netdb
## This is a raw POSIX interface module. It does not not provide any
## convenience: cstrings are used instead of proper Nim strings and
## return codes indicate errors. If you want exceptions
## and a proper Nim-like interface, use the OS module or write a wrapper.
## Coding conventions:
## ALL types are named the same as in the POSIX standard except that they start
## with 'T' or 'P' (if they are pointers) and without the '_t' suffix to be
## consistent with Nim conventions. If an identifier is a Nim keyword
## the \`identifier\` notation is used.
##
## This library relies on the header files of your C compiler. The
## resulting C code will just ``#include `` and *not* define the
## symbols declared here.
# This ensures that we don't accidentally generate #includes for files that
# might not exist on a specific platform! The user will get an error only
# if they actualy try to use the missing declaration
{.deadCodeElim: on.}
# TODO these constants don't seem to be fetched from a header file for unknown
# platforms - where do they come from and why are they here?
when false:
const
C_IRUSR = 0c000400 ## Read by owner.
C_IWUSR = 0c000200 ## Write by owner.
C_IXUSR = 0c000100 ## Execute by owner.
C_IRGRP = 0c000040 ## Read by group.
C_IWGRP = 0c000020 ## Write by group.
C_IXGRP = 0c000010 ## Execute by group.
C_IROTH = 0c000004 ## Read by others.
C_IWOTH = 0c000002 ## Write by others.
C_IXOTH = 0c000001 ## Execute by others.
C_ISUID = 0c004000 ## Set user ID.
C_ISGID = 0c002000 ## Set group ID.
C_ISVTX = 0c001000 ## On directories, restricted deletion flag.
C_ISDIR = 0c040000 ## Directory.
C_ISFIFO = 0c010000 ##FIFO.
C_ISREG = 0c100000 ## Regular file.
C_ISBLK = 0c060000 ## Block special.
C_ISCHR = 0c020000 ## Character special.
C_ISCTG = 0c110000 ## Reserved.
C_ISLNK = 0c120000 ## Symbolic link.
C_ISSOCK = 0c140000 ## Socket.
const
MM_NULLLBL* = nil
MM_NULLSEV* = 0
MM_NULLMC* = 0
MM_NULLTXT* = nil
MM_NULLACT* = nil
MM_NULLTAG* = nil
STDERR_FILENO* = 2 ## File number of stderr;
STDIN_FILENO* = 0 ## File number of stdin;
STDOUT_FILENO* = 1 ## File number of stdout;
DT_UNKNOWN* = 0 ## Unknown file type.
DT_FIFO* = 1 ## Named pipe, or FIFO.
DT_CHR* = 2 ## Character device.
DT_DIR* = 4 ## Directory.
DT_BLK* = 6 ## Block device.
DT_REG* = 8 ## Regular file.
DT_LNK* = 10 ## Symbolic link.
DT_SOCK* = 12 ## UNIX domain socket.
DT_WHT* = 14
# Special types
type Sighandler = proc (a: cint) {.noconv.}
# Platform specific stuff
when defined(linux) and defined(amd64):
include posix_linux_amd64
else:
include posix_other
# There used to be this name in posix.nim a long time ago, not sure why!
{.deprecated: [cSIG_HOLD: SIG_HOLD].}
when not defined(macosx) and not defined(android):
proc st_atime*(s: Stat): Time {.inline.} =
## Second-granularity time of last access
result = s.st_atim.tv_sec
proc st_mtime*(s: Stat): Time {.inline.} =
## Second-granularity time of last data modification.
result = s.st_mtim.tv_sec
discard """
output: '''Hello, console
1 2 3
1 'hi' 1.1'''
"""
# This file tests the JavaScript console
import jsconsole
console.log("Hello, console")
console.log(1, 2, 3)
console.log(1, "hi", 1.1)