Created
March 8, 2018 01:00
-
-
Save Mons/2a21b3e7f462100a524e3544972a84ed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local ffi = require 'ffi' | |
ffi.cdef[[ | |
typedef int mode_t; | |
char *strerror(int errnum); | |
int open(const char *pathname, int flags); | |
int open(const char *pathname, int flags, mode_t mode); | |
ssize_t write(int fd, const char *buf, size_t count); | |
]] | |
O_RDONLY = 00000000 | |
O_WRONLY = 00000001 | |
O_RDWR = 00000002 | |
--local fd = ffi.C.open("testfile",0); | |
local fd = ffi.C.open("testfile",O_RDWR); | |
if fd > -1 then | |
print("file opened: ",fd); | |
local r = ffi.C.write(fd,"buffer\n",7); | |
if r > 0 then | |
else | |
print("write failed", ffi.string(ffi.C.strerror(ffi.errno()))); | |
end | |
else | |
print(ffi.string(ffi.C.strerror(ffi.errno()))); | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment