Example #1
0
inline word_t get_file_length(HANDLE fh)
{
    const word_t cur = ::SetFilePointer(fh, 0, 0, FILE_CURRENT);
    const word_t len = ::SetFilePointer(fh, 0, 0, FILE_END);
    if (cur == INVALID_SET_FILE_POINTER || len == INVALID_SET_FILE_POINTER ||
        ::SetFilePointer(fh, cur, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
        PATL_WIN32_EXCEPTION(SetFilePointer);
    return len;
}
Example #2
0
inline std::string get_temp_file_name(
    const char *prefix = "TMP",
    const char *path = ".")
{
    char buf[MAX_PATH];
    if (!::GetTempFileName(path, prefix, 0, buf))
        PATL_WIN32_EXCEPTION(GetTempFileName);
    return std::string(buf);
}
Example #3
0
inline long long get_long_file_length(const char *fname)
{
    WIN32_FIND_DATA data;
    const HANDLE ffh = ::FindFirstFile(fname, &data);
    if (ffh == INVALID_HANDLE_VALUE)
        PATL_WIN32_EXCEPTION(FindFirstFile);
    ::FindClose(ffh);
    return
        static_cast<long long>(data.nFileSizeLow) |
        (static_cast<long long>(data.nFileSizeHigh) << (8 * sizeof(long)));
}
Example #4
0
inline long long get_long_file_length(HANDLE fh)
{
    LONG cur_h = 0, len_h = 0;
    const DWORD cur = ::SetFilePointer(fh, 0, &cur_h, FILE_CURRENT);
    const DWORD len = ::SetFilePointer(fh, 0, &len_h, FILE_END);
    if (cur == INVALID_SET_FILE_POINTER || len == INVALID_SET_FILE_POINTER ||
        ::SetFilePointer(fh, cur, &cur_h, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
        PATL_WIN32_EXCEPTION(SetFilePointer);
    return
        static_cast<long long>(len) |
        (static_cast<long long>(len_h) << (8 * sizeof(long)));
}
Example #5
0
 buffered_base(const char *fname, bool isWrite)
     : fh_(::CreateFile(
         fname,
         isWrite ? GENERIC_WRITE : GENERIC_READ,
         FILE_SHARE_READ,
         0,
         isWrite ? CREATE_ALWAYS : OPEN_EXISTING,
         FILE_FLAG_SEQUENTIAL_SCAN,
         0))
     , buf_(static_cast<unsigned char*>(::VirtualAlloc(
         0,
         BufferSize,
         MEM_COMMIT,
         PAGE_READWRITE)))
     , end_(buf_)
     , ownHandle_(true)
 {
     if (fh_ == INVALID_HANDLE_VALUE)
         PATL_WIN32_EXCEPTION(CreateFile);
     if (!buf_)
         PATL_WIN32_EXCEPTION(VirtualAlloc);
 }
Example #6
0
inline void move_file(const char *from_path, const char *to_path)
{
    if (!::MoveFileEx(from_path, to_path,
        MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH))
        PATL_WIN32_EXCEPTION(MoveFileEx);
}
Example #7
0
inline void delete_file(const char *fname)
{
    if (!::DeleteFile(fname))
        PATL_WIN32_EXCEPTION(DeleteFile);
}