Пример #1
0
static void writeEntryToDisk(FileWriteEntry* pEntry)
{
    size_t                     bytesWritten;
    FILE*                      pFile;
    
    pFile = fopen(pEntry->filename, "wb");
    if (!pFile)
        __throw(fileException);
    
    bytesWritten = fwrite(&pEntry->savFileHeader, 1, pEntry->headerLength, pFile);
    bytesWritten += fwrite(pEntry->pBase, 1, pEntry->contentLength, pFile);
    fclose(pFile);
    if (bytesWritten != pEntry->contentLength + pEntry->headerLength)
        __throw(fileException);
}
Пример #2
0
static void initializeBaseFileWriteEntry(BinaryBuffer*   pThis, 
                                         FileWriteEntry* pEntry, 
                                         const char*     pDirectoryName,
                                         SizedString*    pFilename,
                                         const char*     pFilenameSuffix)
{
    static const char pathSeparator = PATH_SEPARATOR;
    size_t filenameLength = SizedString_strlen(pFilename);
    size_t directoryLength = pDirectoryName ? strlen(pDirectoryName) : 0;
    size_t slashSpace = !pDirectoryName ? 0 : (pDirectoryName[directoryLength-1] == PATH_SEPARATOR ? 0 : 1);
    size_t suffixLength = pFilenameSuffix ? strlen(pFilenameSuffix) : 0;
    size_t fullLength = directoryLength + slashSpace + filenameLength + suffixLength;
    
    if (fullLength > sizeof(pEntry->filename)-1)
        __throw(invalidArgumentException);

    memcpy(pEntry->filename, pDirectoryName, directoryLength);
    memcpy(pEntry->filename + directoryLength, &pathSeparator, slashSpace);
    memcpy(pEntry->filename + directoryLength + slashSpace, pFilename->pString, filenameLength);
    memcpy(pEntry->filename + directoryLength + slashSpace + filenameLength, pFilenameSuffix, suffixLength);
    pEntry->filename[fullLength] = '\0';
    pEntry->baseAddress = pThis->baseAddress;
    pEntry->pBase = pThis->pBase;
    pEntry->contentLength = pThis->pCurrent - pThis->pBase;
}
Пример #3
0
__throws void Console_WriteStdOut(int character)
{
    if (g_writeStdOutException)
        __throw(g_writeStdOutException);
    if (g_pWriteStdOutCurr < g_pWriteStdOutEnd)
        *g_pWriteStdOutCurr++ = (char)character;
}
Пример #4
0
 void rethrowBufferOverrunException()
 {
     __try
         throwBufferOverrunException();
     __catch
         __rethrow;
     __throw(invalidArgumentException);
 }
Пример #5
0
void Platform_Init(Token* pParameterTokens)
{
    g_initCount++;
    Token_Copy(&g_initTokenCopy, pParameterTokens);
    
    if (g_initException)
        __throw(g_initException);
}
Пример #6
0
__throws int Console_ReadStdIn(void)
{
    if (g_readStdInException)
        __throw(g_readStdInException);
    if (g_pReadStdInCurr < g_pReadStdInEnd)
        return (int)*(g_pReadStdInCurr++);
    else
        return 0;
}
Пример #7
0
void Console_WriteStdOut(int character)
{
    ssize_t result = -1;
    char    c = (char)character;

    result = write(STDOUT_FILENO, &c, sizeof(c));
    if (result == -1)
        __throw(fileException);
}
Пример #8
0
int Console_ReadStdIn()
{
    ssize_t result = -1;
    char    c = 0;

    result = read(STDIN_FILENO, &c, sizeof(c));
    if (result == -1)
        __throw(fileException);
    return c;
}
Пример #9
0
void Console_WriteStdOut(int character)
{
    char   c = (char)character;
    DWORD  bytesWritten = 0;
    BOOL   result = FALSE;
    
    initStdIo();
    result = WriteFile(g_stdOut, &c, sizeof(c), &bytesWritten, NULL);
    if (!result || bytesWritten != sizeof(c))
        __throw(fileException);
}
Пример #10
0
__throws unsigned char* BinaryBuffer_Realloc(BinaryBuffer* pThis, unsigned char* pToRealloc, size_t bytesToAllocate)
{
    if (!pToRealloc)
        return BinaryBuffer_Alloc(pThis, bytesToAllocate);
    
    if(pToRealloc != pThis->pLastAlloc)
        __throw(invalidArgumentException);
        
    pThis->pCurrent = pThis->pLastAlloc;
    return BinaryBuffer_Alloc(pThis, bytesToAllocate);
}
Пример #11
0
__throws char* SizedString_strdup(const SizedString* pStringToCopy)
{
    char* pCopiedString;
    
    pCopiedString = malloc(pStringToCopy->stringLength + 1);
    if (!pCopiedString)
        __throw(outOfMemoryException);
    memcpy(pCopiedString, pStringToCopy->pString, pStringToCopy->stringLength);
    pCopiedString[pStringToCopy->stringLength] = '\0';
    
    return pCopiedString;
}
Пример #12
0
int Console_HasStdInDataToRead()
{
    int            result = -1;
    struct timeval zeroTimeout = {0, 0};
    fd_set         readSet;

    FD_ZERO(&readSet);
    FD_SET(STDIN_FILENO, &readSet);
    result = select(STDIN_FILENO + 1, &readSet, NULL, NULL, &zeroTimeout);
    if (result == -1)
        __throw(fileException);
    return result;
}
Пример #13
0
__throws unsigned char* BinaryBuffer_Alloc(BinaryBuffer* pThis, size_t bytesToAllocate)
{
    size_t         bytesLeft = pThis->pEnd - pThis->pCurrent;
    unsigned char* pAlloc = pThis->pCurrent;
    
    if (bytesLeft < bytesToAllocate || shouldInjectFailureOnThisAllocation(pThis))
        __throw(outOfMemoryException);

    pThis->pCurrent += bytesToAllocate;
    pThis->pLastAlloc = pAlloc;
    
    return pAlloc;
}
Пример #14
0
int Console_ReadStdIn()
{
    char   c = 0;
    DWORD  bytesRead = 0;
    BOOL   result = FALSE;

    initStdIo();

    result = ReadFile(g_stdIn, &c, sizeof(c), &bytesRead, NULL);
    if (!result || bytesRead != sizeof(c))
        __throw(fileException);

    return c;
}
Пример #15
0
__throws BinaryBuffer* BinaryBuffer_Create(size_t bufferSize)
{
    BinaryBuffer* pThis = allocateAndZero(sizeof(*pThis));
    pThis->pBuffer = malloc(bufferSize);
    if (!pThis->pBuffer)
    {
        BinaryBuffer_Free(pThis);
        __throw(outOfMemoryException);
    }
    pThis->pCurrent = pThis->pBuffer;
    pThis->pBase = pThis->pBuffer;
    pThis->pEnd = pThis->pCurrent + bufferSize;
    
    return pThis;
}
Пример #16
0
__throws void BinaryBuffer_ProcessWriteFileQueue(BinaryBuffer* pThis)
{
    FileWriteEntry* pEntry = pThis->pFileWriteHead;
    int             exceptionThrown = noException;
    
    while (pEntry)
    {
        __try
            writeEntryToDisk(pEntry);
        __catch
            exceptionThrown = getExceptionCode();
        pEntry = pEntry->pNext;
    }
    
    if (exceptionThrown != noException)
        __throw(exceptionThrown);
}
Пример #17
0
static void readQueryTransferReadArguments(Buffer* pBuffer, AnnexOffsetLength* pAnnexOffsetLength)
{
    static const char   readCommand[] = "read";

    memset(pAnnexOffsetLength, 0, sizeof(*pAnnexOffsetLength));
    if (!Buffer_IsNextCharEqualTo(pBuffer, ':') ||
        !Buffer_MatchesString(pBuffer, readCommand, sizeof(readCommand)-1) ||
        !Buffer_IsNextCharEqualTo(pBuffer, ':') )
    {
        __throw(invalidArgumentException);
    }
    
    __try
    {
        __throwing_func( pAnnexOffsetLength->pAnnex = readQueryTransferAnnexArgument(pBuffer) );
        __throwing_func( readQueryTransferOffsetLengthArguments(pBuffer, pAnnexOffsetLength) );
    }
    __catch
    {
        __rethrow;
    }
}
Пример #18
0
 void throwInvalidArgumentException()
 {
     __throw(invalidArgumentException);
 }
Пример #19
0
 void throwBufferOverrunException()
 {
     __throw(bufferOverrunException);
 }
Пример #20
0
__throws int  Console_HasStdInDataToRead(void)
{
    if (g_hasStdInDataToReadException)
        __throw(g_hasStdInDataToReadException);
    return g_hasStdInDataToReadReturn;
}
Пример #21
0
static void validateAnnexIs(const char* pAnnex, const char* pExpected)
{
    if (pAnnex == NULL || 0 != strcmp(pAnnex, pExpected))
        __throw(invalidArgumentException);
}
Пример #22
0
static void validateAnnexIsNull(const char* pAnnex)
{
    if (pAnnex)
        __throw(invalidArgumentException);
}