aboutsummaryrefslogtreecommitdiff
path: root/src/lpm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lpm.c')
-rw-r--r--src/lpm.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/lpm.c b/src/lpm.c
index e390512..473e3c0 100644
--- a/src/lpm.c
+++ b/src/lpm.c
@@ -7,6 +7,8 @@
#include <netdb.h>
#include <sys/socket.h>
#include <arpa/inet.h>
+ #include <libgen.h>
+
#define MAX_PATH PATH_MAX
#endif
@@ -232,16 +234,29 @@ static int lpm_mkdir(lua_State *L) {
static int lpm_stat(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
#ifdef _WIN32
- wchar_t fullpath[MAX_PATH];
+ wchar_t full_path[MAX_PATH];
struct _stat s;
LPCWSTR wpath = lua_toutf16(L, path);
int err = _wstat(wpath, &s);
- const char *abs_path = !err && _wfullpath(fullpath, wpath, MAX_PATH) ? lua_toutf8(L, (LPCWSTR)fullpath) : NULL;
+ const char *abs_path = !err && _wfullpath(full_path, wpath, MAX_PATH) ? lua_toutf8(L, (LPCWSTR)fullpath) : NULL;
#else
- char fullpath[MAX_PATH];
+ char full_path[MAX_PATH];
struct stat s;
int err = lstat(path, &s);
- const char *abs_path = !err ? realpath(path, fullpath) : NULL;
+ const char *abs_path = NULL;
+ if (!err) {
+ if (S_ISLNK(s.st_mode)) {
+ char folder_path[MAX_PATH];
+ strcpy(folder_path, path);
+ abs_path = realpath(dirname(folder_path), full_path);
+ if (abs_path) {
+ strcat(full_path, "/");
+ strcpy(folder_path, path);
+ strcat(full_path, basename(folder_path));
+ }
+ } else
+ abs_path = realpath(path, full_path);
+ }
#endif
if (err || !abs_path) {
lua_pushnil(L);