Beispiel #1
0
uint32_t hsUNIXStream::Read(uint32_t bytes,  void* buffer)
{
    if (!fRef || !bytes)
        return 0;
    int numItems = ::fread(buffer, 1 /*size*/, bytes /*count*/, fRef);
    fBytesRead += numItems;
    fPosition += numItems;
    if ((unsigned)numItems < bytes) {
        if (feof(fRef)) {
            // EOF ocurred
            char str[128];
            sprintf(str, "Hit EOF on UNIX Read, only read %d out of requested %d bytes\n", numItems, bytes);
            hsDebugMessage(str, 0);
        }
        else {
            hsDebugMessage("Error on UNIX Read", ferror(fRef));
        }
    }
    return numItems;
}
Beispiel #2
0
bool formatv(std::wstring & out, const wchar_t * fmt, va_list args)
{
#define kBufSz 2048
    
    wchar_t buf[kBufSz];
    wchar_t * pbuf = buf;
    int len = 0;
    int attempts = 0;
    bool success = false;
    const int kMaxAttempts = 40;
    
    do
    {
        int maxlen = kBufSz*attempts+kBufSz-1;
        len = hsVsnwprintf(pbuf,maxlen,fmt,args);
        attempts++;
        success = (len>=0 && len<maxlen);
        if (!success)
        {
            if (pbuf!=buf)
                delete [] pbuf;
            pbuf = new wchar_t[kBufSz+kBufSz*attempts];
        }
    }
    while (!success && attempts<kMaxAttempts);
    
    if (success)
    {
        pbuf[len] = L'\0';
        out = pbuf;
    }
    
    if (success)
    {
        pbuf[len] = L'\0';
        out = pbuf;
    }
    else
    {
        out = L"";
        if ( attempts==kMaxAttempts )
        {
            hsDebugMessage( "xtl::formatv - Max reallocs occurred while formatting wstring. Result is likely truncated!", 0 );
        }
    }
    
    if (pbuf!=buf)
        delete [] pbuf;
    
    return success;
}
Beispiel #3
0
uint32_t hsUNIXStream::Read(uint32_t bytes,  void* buffer)
{
    if (!fRef || !bytes)
        return 0;
    size_t numItems = ::fread(buffer, 1 /*size*/, bytes /*count*/, fRef);
    fBytesRead += numItems;
    fPosition += numItems;
    if (numItems < bytes)
    {
        if (!feof(fRef))
        {
            hsDebugMessage("Error on UNIX Read", ferror(fRef));
        }
    }
    return numItems;
}
void hsGFontScaler::UnRegister(UInt32 scalerID)
{
    if (gScalerList != nil) {
        Int32	index = gScalerList->Find(FontScalerPair(scalerID, nil));

        if (index >= 0) {
            gScalerList->Get(index).fScaler->UnRef();
            gScalerList->Remove(index);
            if (gScalerList->GetCount() == 0) {
                delete gScalerList;
                gScalerList = nil;
            }
            return;
        }
    }
    hsDebugMessage("can't unregister unknown scalerID", scalerID);
}
Beispiel #5
0
bool plFileSystem::CreateDir(const plFileName &dir, bool checkParents)
{
    plFileName fdir = dir;
    if (fdir.GetFileName().IsEmpty()) {
        hsDebugMessage("WARNING: CreateDir called with useless trailing slash", 0);
        fdir = fdir.StripFileName();
    }

    if (checkParents) {
        plFileName parent = fdir.StripFileName();
        if (parent.IsValid() && !plFileInfo(parent).Exists() && !CreateDir(parent, true))
            return false;
    }

    if (plFileInfo(fdir).Exists())
        return true;

#if HS_BUILD_FOR_WIN32
    return CreateDirectoryW(fdir.AsString().ToWchar(), nullptr);
#else
    return (mkdir(fdir.AsString().c_str(), 0755) == 0);
#endif
}