
(library (posix errno)
  (export         ;;FROM linux's asm/errno-base.h
		 EPERM ENOENT ESRCH EINTR EIO ENXIO E2BIG ENOEXEC EBADF ECHILD EAGAIN
		 ENOMEM EACCES EFAULT ENOTBLK EBUSY EEXIST EXDEV ENODEV ENOTDIR EISDIR
		 EINVAL ENFILE EMFILE ENOTTY ETXTBSY EFBIG ENOSPC ESPIPE EROFS EMLINK
		 EPIPE EDOM ERANGE
		 
		 ;;FROM linux's asm/errno.h
		 EDEADLK ENAMETOOLONG ENOLCK

		 ENOSYS

		 ENOTEMPTY ELOOP EWOULDBLOCK ENOMSG EIDRM ECHRNG EL2NSYNC EL3HLT EL3RST
		 ELNRNG EUNATCH ENOCSI EL2HLT EBADE EBADR EXFULL ENOANO EBADRQC EBADSLT

		 EDEADLOCK

		 EBFONT ENOSTR ENODATA ETIME ENOSR ENONET ENOPKG EREMOTE ENOLINK EADV
		 ESRMNT ECOMM EPROTO EMULTIHOP EDOTDOT EBADMSG EOVERFLOW ENOTUNIQ
		 EBADFD EREMCHG ELIBACC ELIBBAD ELIBSCN ELIBMAX ELIBEXEC EILSEQ
		 ERESTART ESTRPIPE EUSERS ENOTSOCK EDESTADDRREQ EMSGSIZE EPROTOTYPE
		 ENOPROTOOPT EPROTONOSUPPORT ESOCKTNOSUPPORT EOPNOTSUPP EPFNOSUPPORT
		 EAFNOSUPPORT EADDRINUSE EADDRNOTAVAIL ENETDOWN ENETUNREACH ENETRESET
		 ECONNABORTED ECONNRESET ENOBUFS EISCONN ENOTCONN ESHUTDOWN
		 ETOOMANYREFS ETIMEDOUT ECONNREFUSED EHOSTDOWN EHOSTUNREACH EALREADY
		 EINPROGRESS ESTALE EUCLEAN ENOTNAM ENAVAIL EISNAM EREMOTEIO EDQUOT
		 ENOMEDIUM EMEDIUMTYPE ECANCELED ENOKEY EKEYEXPIRED EKEYREVOKED
		 EKEYREJECTED EOWNERDEAD ENOTRECOVERABLE


		 strerror errno)
  (import (chezscheme)
	  (srfi private include))

  (meta-cond
   [(memq (machine-type) '(a6le ta6le i3le ti3le))
    (include/resolve () "posix/errno-linux.ss")]
   [else
    (error 'posix.sls "unsupported machine-type ~a" (machine-type))])

  (define strerror
    (case-lambda
     [() (strerror (errno))]
     [(n)
      (define strerror* (foreign-procedure "strerror_r" (int u8* size_t) string))
      (define buff (make-bytevector 1024))
      (strerror* n buff 1024)]))

  (define (errno)
    (foreign-ref 'int (foreign-entry "errno") 0))
  )
