diff --git a/cffi-fcntl-package.lisp b/cffi-fcntl-package.lisp
deleted file mode 100644
index f5e8fb1..0000000
--- a/cffi-fcntl-package.lisp
+++ /dev/null
@@ -1,99 +0,0 @@
-
-(in-package :common-lisp)
-
-(defpackage :cffi-fcntl
- (:nicknames :fcntl)
- (:use
- :cffi
- :cffi-errno
- :common-lisp)
- (:export
- #:c-fcntl
- #:c-fcntl/int
- #:c-fcntl/pointer
- #:fcntl-getfl
- #:fcntl-setfl
- #:+o-rdonly+
- #:+o-wronly+
- #:+o-rdwr+
- #:+o-creat+
- #:+o-excl+
- #:+o-noctty+
- #:+o-trunc+
- #:+o-append+
- #:+o-nonblock+
- #:+o-ndelay+
- #:+o-sync+
- #:+o-sync+
- #:+o-async+
- #:+o-largefile+
- #:+o-directory+
- #:+o-nofollow+
- #:+o-cloexec+
- #:+o-direct+
- #:+o-noatime+
- #:+o-path+
- #:+o-dsync+
- #:+o-tmpfile+
- #:+f-getlk+
- #:+f-setlk+
- #:+f-setlkw+
- #:+f-getlk64+
- #:+f-setlk64+
- #:+f-setlkw64+
- #:+f-dupfd+
- #:+f-getfd+
- #:+f-setfd+
- #:+f-getfl+
- #:+f-setfl+
- #:+f-setown+
- #:+f-getown+
- #:+f-setsig+
- #:+f-getsig+
- #:+f-setown-ex+
- #:+f-getown-ex+
- #:+f-setlease+
- #:+f-getlease+
- #:+f-notify+
- #:+f-setpipe-sz+
- #:+f-getpipe-sz+
- #:+f-dupfd-cloexec+
- #:+f-cloexec+
- #:+f-rdlck+
- #:+f-wrlck+
- #:+f-unlck+
- #:+f-exlck+
- #:+f-shlck+
- #:+lock-sh+
- #:+lock-ex+
- #:+lock-nb+
- #:+lock-un+
- #:+lock-mand+
- #:+lock-read+
- #:+lock-write+
- #:+lock-rw+
- #:+dn-access+
- #:+dn-modify+
- #:+dn-create+
- #:+dn-delete+
- #:+dn-rename+
- #:+dn-attrib+
- #:+dn-multishot+
- #:+posix-fadv-normal+
- #:+posix-fadv-random+
- #:+posix-fadv-sequential+
- #:+posix-fadv-willneed+
- #:+posix-fadv-dontneed+
- #:+posix-fadv-noreuse+
- #:+sync-file-range-wait-before+
- #:+sync-file-range-write+
- #:+sync-file-range-wait-after+
- #:+splice-f-move+
- #:+splice-f-nonblock+
- #:+splice-f-more+
- #:+splice-f-gift+
- #:+falloc-fl-keep-size+
- #:+falloc-fl-punch-hole+
- #:+falloc-fl-collapse-range+
- #:+falloc-fl-zero-range+
- #:+max-handle-sz+))
diff --git a/cffi-fcntl.asd b/cffi-fcntl.asd
index c3cc089..13bba26 100644
--- a/cffi-fcntl.asd
+++ b/cffi-fcntl.asd
@@ -10,6 +10,6 @@
:defsystem-depends-on ("cffi-grovel")
:depends-on ("cffi" "cffi-errno")
:components
- ((:file "cffi-fcntl-package")
- (:cffi-grovel-file "grovel-fcntl" :depends-on ("cffi-fcntl-package"))
+ ((:file "package")
+ (:cffi-grovel-file "grovel-fcntl" :depends-on ("package"))
(:file "cffi-fcntl" :depends-on ("grovel-fcntl"))))
diff --git a/cffi-fcntl.lisp b/cffi-fcntl.lisp
index 2c3001f..419d3ed 100644
--- a/cffi-fcntl.lisp
+++ b/cffi-fcntl.lisp
@@ -19,4 +19,18 @@
(c-fcntl fd +f-getfl+))
(defun fcntl-setfl (fd flags)
- (c-fcntl/int fd +f-getfl+ flags))
+ (c-fcntl/int fd +f-setfl+ flags))
+
+(defcfun ("open" c-open/2) :int
+ (pathname :string)
+ (flags :int))
+
+(defcfun ("open" c-open/3) :int
+ (pathname :string)
+ (flags :int)
+ (mode mode-t))
+
+(defun open (pathname flags &optional mode)
+ (if (= 0 (logand flags +o-creat+))
+ (c-open/2 pathname flags)
+ (c-open/3 pathname flags mode)))
diff --git a/grovel-fcntl.lisp b/grovel-fcntl.lisp
index dfb1610..c2f40de 100644
--- a/grovel-fcntl.lisp
+++ b/grovel-fcntl.lisp
@@ -3,6 +3,42 @@
(include "fcntl.h")
+(ctype mode-t "mode_t")
+(ctype off-t "off_t")
+(ctype off64-t "off64_t")
+(ctype pid-t "pid_t")
+
+(constant (+s-ifmt+ "S_IFMT"))
+(constant (+s-ifdir+ "S_IFDIR"))
+(constant (+s-ifchr+ "S_IFCHR"))
+(constant (+s-ifblk+ "S_IFBLK"))
+(constant (+s-ififo+ "S_IFIFO"))
+(constant (+s-iflnk+ "S_IFLNK"))
+(constant (+s-ifsock+ "S_IFSOCK"))
+(constant (+s-isuid+ "S_ISUID"))
+(constant (+s-isgid+ "S_ISGID"))
+(constant (+s-irusr+ "S_IRUSR"))
+(constant (+s-iwusr+ "S_IWUSR"))
+(constant (+s-ixusr+ "S_IXUSR"))
+(constant (+s-irwxu+ "S_IRWXU"))
+(constant (+s-irgrp+ "S_IRGRP"))
+(constant (+s-iwgrp+ "S_IWGRP"))
+(constant (+s-ixgrp+ "S_IXGRP"))
+(constant (+s-irwxg+ "S_IRWXG"))
+(constant (+s-iroth+ "S_IROTH"))
+(constant (+s-iwoth+ "S_IWOTH"))
+(constant (+s-ixoth+ "S_IXOTH"))
+(constant (+s-irwxo+ "S_IRWXO"))
+
+(constant (+r-ok+ "R_OK"))
+(constant (+w-ok+ "W_OK"))
+(constant (+x-ok+ "X_OK"))
+(constant (+f-ok+ "F_OK"))
+
+(constant (+seek-set+ "SEEK_SET"))
+(constant (+seek-cur+ "SEEK_CUR"))
+(constant (+seek-end+ "SEEK_END"))
+
(constant (+o-rdonly+ "O_RDONLY"))
(constant (+o-wronly+ "O_WRONLY"))
(constant (+o-rdwr+ "O_RDWR"))
diff --git a/package.lisp b/package.lisp
new file mode 100644
index 0000000..6aebee1
--- /dev/null
+++ b/package.lisp
@@ -0,0 +1,101 @@
+
+(in-package :common-lisp)
+
+(defpackage :cffi-fcntl
+ (:nicknames :fcntl)
+ (:use
+ :cffi
+ :cffi-errno
+ :common-lisp)
+ (:shadow
+ #:open)
+ (:export
+ #:c-fcntl
+ #:c-fcntl/int
+ #:c-fcntl/pointer
+ #:fcntl-getfl
+ #:fcntl-setfl
+ #:+o-rdonly+
+ #:+o-wronly+
+ #:+o-rdwr+
+ #:+o-creat+
+ #:+o-excl+
+ #:+o-noctty+
+ #:+o-trunc+
+ #:+o-append+
+ #:+o-nonblock+
+ #:+o-ndelay+
+ #:+o-sync+
+ #:+o-sync+
+ #:+o-async+
+ #:+o-largefile+
+ #:+o-directory+
+ #:+o-nofollow+
+ #:+o-cloexec+
+ #:+o-direct+
+ #:+o-noatime+
+ #:+o-path+
+ #:+o-dsync+
+ #:+o-tmpfile+
+ #:+f-getlk+
+ #:+f-setlk+
+ #:+f-setlkw+
+ #:+f-getlk64+
+ #:+f-setlk64+
+ #:+f-setlkw64+
+ #:+f-dupfd+
+ #:+f-getfd+
+ #:+f-setfd+
+ #:+f-getfl+
+ #:+f-setfl+
+ #:+f-setown+
+ #:+f-getown+
+ #:+f-setsig+
+ #:+f-getsig+
+ #:+f-setown-ex+
+ #:+f-getown-ex+
+ #:+f-setlease+
+ #:+f-getlease+
+ #:+f-notify+
+ #:+f-setpipe-sz+
+ #:+f-getpipe-sz+
+ #:+f-dupfd-cloexec+
+ #:+f-cloexec+
+ #:+f-rdlck+
+ #:+f-wrlck+
+ #:+f-unlck+
+ #:+f-exlck+
+ #:+f-shlck+
+ #:+lock-sh+
+ #:+lock-ex+
+ #:+lock-nb+
+ #:+lock-un+
+ #:+lock-mand+
+ #:+lock-read+
+ #:+lock-write+
+ #:+lock-rw+
+ #:+dn-access+
+ #:+dn-modify+
+ #:+dn-create+
+ #:+dn-delete+
+ #:+dn-rename+
+ #:+dn-attrib+
+ #:+dn-multishot+
+ #:+posix-fadv-normal+
+ #:+posix-fadv-random+
+ #:+posix-fadv-sequential+
+ #:+posix-fadv-willneed+
+ #:+posix-fadv-dontneed+
+ #:+posix-fadv-noreuse+
+ #:+sync-file-range-wait-before+
+ #:+sync-file-range-write+
+ #:+sync-file-range-wait-after+
+ #:+splice-f-move+
+ #:+splice-f-nonblock+
+ #:+splice-f-more+
+ #:+splice-f-gift+
+ #:+falloc-fl-keep-size+
+ #:+falloc-fl-punch-hole+
+ #:+falloc-fl-collapse-range+
+ #:+falloc-fl-zero-range+
+ #:+max-handle-sz+))