static int_type str_n_compare_no_case(char_type const* s1, char_type const* s2, size_type cch) { UNIXSTL_ASSERT(NULL != s1); UNIXSTL_ASSERT(NULL != s2); return ::_wcsnicmp(s1, s2, cch); }
static char_type* str_end(char_type const* s) { UNIXSTL_ASSERT(NULL != s); for(; *s != L'\0'; ++s) {} return const_cast<char_type*>(s); }
/// \brief Releases an aquired lock on the semaphore, increasing the /// semaphore's counter by one. void unlock() { UNIXSTL_ASSERT(NULL != m_sem); if(::sem_post(m_sem) < 0) { #ifdef STLSOFT_CF_EXCEPTION_SUPPORT STLSOFT_THROW_X(synchronisation_exception("semaphore release failed", errno)); #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */ } }
static char_type* str_set(char_type* s, size_type n, char_type c) { UNIXSTL_ASSERT(NULL != s || 0u == n); for(; 0u != n; --n, ++s) { *s = c; } return s; }
/// \brief Attempts to lock the semaphore /// /// \return <b>true</b> if the semaphore was aquired, or <b>false</b> if not bool_type try_lock() { UNIXSTL_ASSERT(NULL != m_sem); int res = ::sem_trywait(m_sem); if(0 == res) { return true; } else { if(EAGAIN != res) { #ifdef STLSOFT_CF_EXCEPTION_SUPPORT STLSOFT_THROW_X(synchronisation_exception("semaphore wait failed", errno)); #endif /* STLSOFT_CF_EXCEPTION_SUPPORT */ } } return false; }
us_size_t path_squeeze_impl( C const* path , us_size_t pathLen , C* buffer , us_size_t cchBuffer ) { typedef C char_t; typedef filesystem_traits<C> traits_t; typedef us_size_t size_t; if(NULL == buffer) { cchBuffer = pathLen + 1u; } else if(0 != cchBuffer) { basic_path<char_t> p(path, pathLen); char_t const* file_ptr = p.get_file(); char_t const* path_ptr = p.c_str(); const size_t fileLen = p.size() - (file_ptr - path_ptr); if(cchBuffer > pathLen) { // Room for all traits_t::char_copy(buffer, path_ptr, pathLen); buffer[pathLen] = '\0'; cchBuffer = pathLen + 1u; } else { size_t rootLen; // Need to handle: // // 1. UNC // 2. drive // 3. rooted - begins with \ or / // 4. non-rooted if(p.is_rooted()) { if(p.is_absolute()) { if(traits_t::is_path_UNC(path_ptr)) { // 1. UNC char_t const* p1 = traits_t::str_chr(path_ptr + 2, '\\'); rootLen = 1 + static_cast<size_t>(p1 - path_ptr); } #if defined(_WIN32) || \ defined(_WIN64) else if(isalpha(path_ptr[0]) && ':' == path_ptr[1]) { // 2. drive rootLen = 3; } #endif /* Windows */ else { // 3. rooted - begins with \ or / rootLen = 1; } } else { // 3. rooted - begins with \ or / rootLen = 1; } } else { // 4. non-rooted rootLen = 0; } if(cchBuffer < 5 + 1) { traits_t::char_copy(buffer, file_ptr, cchBuffer - 1); buffer[cchBuffer - 1] = '\0'; if(cchBuffer > fileLen) { cchBuffer = fileLen + 1; } } else if(cchBuffer < fileLen + 1) { // Squeezing just file+ext size_t leftLen = (cchBuffer - 3 - 1) / 2; size_t rightLen = (cchBuffer - 3 - 1) - leftLen; traits_t::char_copy(buffer, file_ptr, leftLen); buffer[leftLen + 0] = '.'; buffer[leftLen + 1] = '.'; buffer[leftLen + 2] = '.'; traits_t::char_copy(buffer + leftLen + 3, file_ptr + (fileLen - rightLen), rightLen); buffer[leftLen + 3 + rightLen] = '\0'; } else if(cchBuffer < rootLen + 3 + 1 + fileLen + 1) { // File (name + ext) only traits_t::char_copy(buffer, file_ptr, fileLen); buffer[fileLen] = '\0'; if(cchBuffer > fileLen) { cchBuffer = fileLen + 1; } } else { UNIXSTL_ASSERT(cchBuffer < pathLen + 1); // Squeezing size_t rightLen = 1 + fileLen; size_t leftLen = (cchBuffer - 3 - 1) - rightLen; traits_t::char_copy(buffer, path_ptr, leftLen); buffer[leftLen + 0] = '.'; buffer[leftLen + 1] = '.'; buffer[leftLen + 2] = '.'; traits_t::char_copy(buffer + leftLen + 3, file_ptr - 1, rightLen); buffer[leftLen + 3 + rightLen] = '\0'; } } } return cchBuffer; }
/// Gets the full path name of the user's home directory static size_type get_home_directory(char_type* buffer, size_type cchBuffer) { UNIXSTL_ASSERT(NULL != buffer || 0 == cchBuffer); return unixstl_C_get_home_directory_w(buffer, cchBuffer); }