💾 Archived View for gemini.conman.org › sourcecode › GLV-1 › getuserdir.c captured on 2022-06-04 at 00:04:54.

View Raw

More Information

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

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


#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;
}