nginx - How to use ffi.C.lstat? -
i want file's basic infomation lstat function in ngx_lua programme. init.lua's content fallow:
local ffi = require "ffi" local ffi_c = ffi.c local ffi_new = ffi.new ffi.cdef[[ typedef long long time_t; typedef struct timespec { time_t tv_sec; long tv_nsec; ...; }; typedef struct stat { struct timespec st_mtim; ...; }; int lstat(const char *path, struct stat *buf); ]] buf = ffi_new("struct stat *") function checkfile (filename, buf) ffi_c.lstat(filename, buf) end when start nginx, there errors happen. content fallow:
- 2014/04/25 15:00:39 [error] 26396#0: lua entry thread aborted: runtime error: /home/nginx/conf/cop/init.lua:42: /usr/local/lib/libluajit-5.1.so.2: undefined symbol: lstat stack traceback: coroutine 0: [c]: in function '__index' /home/nginx/conf/cop/init.lua:42: in function 'checkfile' /home/nginx/conf/cop/check1.lua:37: in function , context: ngx.timer
buf = ffi_new("struct stat *") creates new pointer struct stat object; doesn't allocate actual struct stat instance. want ffi_new("struct stat") instead.
before attempting ffi, sure familiar c's memory model, because using luajit's ffi writing in c. won't protect dereferencing null, etc.
also, buf global, don't want. sure make local.
Comments
Post a Comment