std::error_code platform_error() {
#if defined ( _WIN32 ) 
	return platform_error(GetLastError());
#else
	return platform_error(errno);
#endif
}
Ejemplo n.º 2
0
void platform_getCurrentExecutablePath(char *out, unsigned int maxLen)
{
    char *lastSlash;

    if (_NSGetExecutablePath(out, &maxLen) != 0)
    {
        platform_error("Could not retrieve path of executable -- buffer of %d is too small.\n", maxLen);
        return;
    }

    // Ensure that the string is null terminated.
    out[maxLen] = '\0';

    // The executable path retrieved now has the executable name appended to it, so we need to remove it.
    // The easiest way to do this is to search for the last '/', and just set it to \0
    lastSlash = strrchr(out, '/');

    if (lastSlash)
    {
        // If we have room for it, retain the trailing / and only null-terminate after it
        if ((lastSlash - out) < maxLen - 1)
        {
            lastSlash++;
        }

        // Null terminate the string so that the name of the executable is not included in the path.
        *lastSlash = '\0';
    }
    else
    {
        platform_error("Could not retrieve path of executable -- no directory delimiter found.\n");
    }
}
Ejemplo n.º 3
0
    //////////////////////////////////////////////////////////////////////////////////////////
    //! Path::folder const
    //! Gets the folder portion of the path only
    //!
    //! \return Path - Absolute folder path (including a trailing backslash)
    //////////////////////////////////////////////////////////////////////////////////////////
    Path  folder() const
    {
      Path tmp(*this);

      // Remove filename, add backslash
      if (!WinAPI<encoding>::pathRemoveFileSpec(tmp)
       || !WinAPI<encoding>::pathAddBackslash(tmp))

       throw platform_error(HERE, "Unable to remove path filename");

      // Return copy
      return tmp.c_str();
    }
 void  format(CharArray<ENC,LEN>& txt, const encoding_char_t<ENC>* str, LocaleId locale = LocaleId::Neutral) const
 {
   // Format date according to user settings
   if (!WinAPI<ENC>::getDateFormat(locale, enum_cast(zero<DateFlags>()), base_cast(this), str, txt.buffer(), LEN))
     throw platform_error(HERE, "Unable to format date");
 }
 void  format(CharArray<ENC,LEN>& txt, DateFlags flags, LocaleId locale = LocaleId::Neutral) const
 { 
   // Format date according to user settings
   if (!WinAPI<ENC>::getDateFormat(locale, enum_cast(flags), base_cast(this), nullptr, txt.buffer(), LEN))
     throw platform_error(HERE, "Unable to format date");
 }