Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

missing prototypes warnings when building on windows using msys2 #168

Open
FractalU opened this issue Jun 28, 2023 · 0 comments
Open

missing prototypes warnings when building on windows using msys2 #168

FractalU opened this issue Jun 28, 2023 · 0 comments

Comments

@FractalU
Copy link

FractalU commented Jun 28, 2023

I've manually built luafilesystem on window using msys2, a unix like environment on windows similar to cygwin. From gcc I get the following warnings.

src/lfs.c:171:5: warning: no previous prototype for 'lfs_win32_pusherror' [-Wmissing-prototypes]
  171 | int lfs_win32_pusherror(lua_State * L)
      |
src/lfs.c:184:8: warning: no previous prototype for 'windowsToUnixTime' [-Wmissing-prototypes]
  184 | time_t windowsToUnixTime(FILETIME ft)
      |
src/lfs.c:192:5: warning: no previous prototype for 'lfs_win32_lstat' [-Wmissing-prototypes]
  192 | int lfs_win32_lstat(const char *path, STAT_STRUCT * buffer)
      |

I guess all the functions mentioned in the warnings should be declared as static. Below is the proposed change.

In lfs.c at line 169

#ifdef _WIN32

static int lfs_win32_pusherror(lua_State * L)
{
  int en = GetLastError();
  lua_pushnil(L);
  if (en == ERROR_FILE_EXISTS || en == ERROR_SHARING_VIOLATION)
    lua_pushstring(L, "File exists");
  else
    lua_pushstring(L, strerror(en));
  return 2;
}

#define TICKS_PER_SECOND 10000000
#define EPOCH_DIFFERENCE 11644473600LL
static time_t windowsToUnixTime(FILETIME ft)
{
  ULARGE_INTEGER uli;
  uli.LowPart = ft.dwLowDateTime;
  uli.HighPart = ft.dwHighDateTime;
  return (time_t) (uli.QuadPart / TICKS_PER_SECOND - EPOCH_DIFFERENCE);
}

static int lfs_win32_lstat(const char *path, STAT_STRUCT * buffer)
{
  WIN32_FILE_ATTRIBUTE_DATA win32buffer;
  if (GetFileAttributesEx(path, GetFileExInfoStandard, &win32buffer)) {
    if (!(win32buffer.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)) {
      return STAT_FUNC(path, buffer);
    }
    buffer->st_mode = _S_IFLNK;
    buffer->st_dev = 0;
    buffer->st_ino = 0;
    buffer->st_nlink = 0;
    buffer->st_uid = 0;
    buffer->st_gid = 0;
    buffer->st_rdev = 0;
    buffer->st_atime = windowsToUnixTime(win32buffer.ftLastAccessTime);
    buffer->st_mtime = windowsToUnixTime(win32buffer.ftLastWriteTime);
    buffer->st_ctime = windowsToUnixTime(win32buffer.ftCreationTime);
    buffer->st_size = 0;
    return 0;
  } else {
    return 1;
  }
}

#endif

Declare all these functions as static.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant