💾 Archived View for gemini.conman.org › sourcecode › Lua › GLV-1 › getuserdir.c captured on 2021-12-03 at 14:04:38.

View Raw

More Information

⬅️ Previous capture (2020-11-01)

-=-=-=-=-=-=-

/***************************************************************************


#include <sys/types.h>
#include <pwd.h>

#include <lua.h>
#include <lauxlib.h>

static int getuserdir(lua_State *L)
{
  struct passwd *ent = getpwnam(luaL_checkstring(L,1));
  if (ent != NULL)
    lua_pushstring(L,ent->pw_dir);
  else
    lua_pushnil(L);
  return 1;
}

int luaopen_1_getuserdir(lua_State *L)
{
  lua_pushcfunction(L,getuserdir);
  return 1;
}