Skip to content

Instantly share code, notes, and snippets.

@Mons
Created March 8, 2018 01:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mons/2a21b3e7f462100a524e3544972a84ed to your computer and use it in GitHub Desktop.
Save Mons/2a21b3e7f462100a524e3544972a84ed to your computer and use it in GitHub Desktop.
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