/** * stat() a file with encoding support. * * @param path the file path * @param buffer pointer to the buffer to store file properties to * @return 0 on success, -1 on error */ int win_stat(const char* path, struct rsh_stat_struct *buffer) { int i, res = -1; for(i = 0; i < 2; i++) { wchar_t* wpath = c2w(path, i); if(wpath == NULL) continue; res = clib_wstat(wpath, buffer); free(wpath); if(res == 0 || errno != ENOENT) break; } return res; }
/** * Fill file information in the file_t structure. * * @param file the file information * @param use_lstat nonzero if lstat() shall be used * @return 0 on success, -1 on error */ int rsh_file_stat2(file_t* file, int use_lstat) { struct rsh_stat_struct st; int res = -1; #ifdef _WIN32 int i; (void)use_lstat; /* ignore on windows */ if(file->wpath) { free(file->wpath); file->wpath = NULL; } for(i = 0; i < 2; i++) { wchar_t* wpath = c2w(file->path, i); if(wpath == NULL) continue; res = clib_wstat(wpath, &st); if(res == 0 || errno != ENOENT) { file->wpath = wpath; file->size = st.st_size; /* set correct filesize for large files under win32 */ win32_set_filesize64(file->path, &file->size); break; } free(wpath); } #else res = (use_lstat ? lstat(file->path, &st) : rsh_stat(file->path, &st)); file->size = st.st_size; #endif /* _WIN32 */ file->mtime = st.st_mtime; return res; }