Ticket #9583: boost_interprocess_file_lock_wchar.patch

File boost_interprocess_file_lock_wchar.patch, 3.6 KB (added by jmalo@…, 9 years ago)

Patch for support of wide character filenames in boost::interprocess::file_lock

  • detail/os_file_functions.hpp

     
    124124      (name, (unsigned int)mode, winapi::open_existing, attr, 0);
    125125}
    126126
     127inline file_handle_t open_existing_file
     128(const wchar_t *name, mode_t mode, bool temporary = false)
     129{
     130    unsigned long attr = temporary ? winapi::file_attribute_temporary : 0;
     131    return winapi::create_file
     132        (name, (unsigned int)mode, winapi::open_existing, attr, 0);
     133}
     134
    127135inline bool delete_file(const char *name)
    128136{  return winapi::unlink_file(name);   }
    129137
  • detail/win32_api.hpp

     
    914914extern "C" __declspec(dllimport) void * __stdcall MapViewOfFileEx (void *, unsigned long, unsigned long, unsigned long, std::size_t, void*);
    915915extern "C" __declspec(dllimport) void * __stdcall OpenFileMappingA (unsigned long, int, const char *);
    916916extern "C" __declspec(dllimport) void * __stdcall CreateFileA (const char *, unsigned long, unsigned long, struct interprocess_security_attributes*, unsigned long, unsigned long, void *);
     917extern "C" __declspec(dllimport) void * __stdcall CreateFileW (const wchar_t *, unsigned long, unsigned long, struct interprocess_security_attributes*, unsigned long, unsigned long, void *);
    917918extern "C" __declspec(dllimport) void __stdcall GetSystemInfo (struct system_info *);
    918919extern "C" __declspec(dllimport) int __stdcall FlushViewOfFile (void *, std::size_t);
    919920extern "C" __declspec(dllimport) int __stdcall VirtualUnlock (void *, std::size_t);
     
    11931194   return invalid_handle_value;
    11941195}
    11951196
     1197inline void *create_file(const wchar_t *name, unsigned long access, unsigned long creation_flags, unsigned long attributes, interprocess_security_attributes *psec)
     1198{
     1199    for (unsigned int attempt(0); attempt < error_sharing_violation_tries; ++attempt) {
     1200        void * const handle = CreateFileW(name, access,
     1201            file_share_read | file_share_write | file_share_delete,
     1202            psec, creation_flags, attributes, 0);
     1203        bool const invalid(invalid_handle_value == handle);
     1204        if (!invalid) {
     1205            return handle;
     1206        }
     1207        if (error_sharing_violation != get_last_error()) {
     1208            return handle;
     1209        }
     1210        sleep(error_sharing_violation_sleep_ms);
     1211    }
     1212    return invalid_handle_value;
     1213}
     1214
    11961215inline void get_system_info(system_info *info)
    11971216{  GetSystemInfo(info); }
    11981217
  • sync/file_lock.hpp

     
    5353   //!Opens a file lock. Throws interprocess_exception if the file does not
    5454   //!exist or there are no operating system resources.
    5555   file_lock(const char *name);
     56   file_lock(const wchar_t *name);
    5657
    5758   //!Moves the ownership of "moved"'s file mapping object to *this.
    5859   //!After the call, "moved" does not represent any file mapping object.
     
    211212   }
    212213}
    213214
     215inline file_lock::file_lock(const wchar_t *name)
     216{
     217    m_file_hnd = ipcdetail::open_existing_file(name, read_write);
     218
     219    if (m_file_hnd == ipcdetail::invalid_file()) {
     220        error_info err(system_error_code());
     221        throw interprocess_exception(err);
     222    }
     223}
     224
    214225inline file_lock::~file_lock()
    215226{
    216227   if(m_file_hnd != ipcdetail::invalid_file()){