static int luv_os_homedir(lua_State* L) { size_t size = 2*PATH_MAX; char homedir[2*PATH_MAX]; int ret = uv_os_homedir(homedir, &size); if (ret < 0) return luv_error(L, ret); lua_pushlstring(L, homedir, size); return 1; }
// Remember to free strings returned by this. static char *getUserHomeDirectory(caerModuleData moduleData) { size_t homeDirLength = PATH_MAX; // Allocate memory for home directory path. char *homeDir = malloc(homeDirLength); if (homeDir == NULL) { caerModuleLog(moduleData, CAER_LOG_ERROR, "Failed to allocate memory for home directory string."); return (NULL); } // Discover home directory path, use libuv for cross-platform support. int retVal = uv_os_homedir(homeDir, &homeDirLength); if (retVal < 0) { caerModuleLog(moduleData, CAER_LOG_ERROR, "uv_os_homedir failed, error %d (%s).", retVal, uv_err_name(retVal)); return (NULL); } return (homeDir); }