From 8d5f2af1495f8fcac4652d3939c859353c45498c Mon Sep 17 00:00:00 2001 From: Natanael Copa Date: Fri, 18 Nov 2011 10:17:33 +0100 Subject: Implement magic_getpath This function is not documented in libmagic(3) but it is available in magic.h --- magic.c | 12 +++++++++++- test.lua | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/magic.c b/magic.c index d138302..bf7e836 100644 --- a/magic.c +++ b/magic.c @@ -168,10 +168,20 @@ static int Pbuffer(lua_State *L) return 1; } +static int Pgetpath(lua_State *L) +{ + // from file.h in 'file' sources + #define FILE_LOAD 0 + const char *magicfile = luaL_optstring(L, 1, NULL); + lua_pushstring(L, magic_getpath(magicfile, FILE_LOAD)); + return 1; + #undef FILE_LOAD +} + static const luaL_reg Pmagic_methods[] = { {"open", Popen}, {"close", Pclose}, - {"getpath", Ptodo}, + {"getpath", Pgetpath}, {"file", Pfile}, {"descriptor", Pdescriptor}, {"buffer", Pbuffer}, diff --git a/test.lua b/test.lua index 7ac6e67..cf41639 100644 --- a/test.lua +++ b/test.lua @@ -25,4 +25,4 @@ print(m:file("Makefile")) m:setflags(magic.NONE) print(m:buffer("#!/bin/bash\n")) - +print(magic.getpath()) -- cgit v1.2.3