Source/KSCrash/Recording/Monitors/KSCrashMonitor_AppState.c
/** Load the persistent state portion of a crash context.
 *
 * @param path The path to the file to read.
 *
 * @return true if the operation was successful.
 */
Load the persistent state portion of a crash context.
@param path The path to the file to read.

@return true if the operation was successful.
Load the persistent state portion of a crash context . @param path The path to the file to read . @return true if the operation was successful .
static bool loadState(const char* const path)
{
    const int fd = open(path, O_RDONLY);
    if(fd < 0)
    {
        return false;
    }
    close(fd);
    char* data;
    int length;
    if(!ksfu_readEntireFile(path, &data, &length, 50000))
    {
        KSLOG_ERROR("%s: Could not load file", path);
        return false;
    }
    KSJSONDecodeCallbacks callbacks;
    callbacks.onBeginArray = onBeginArray;
    callbacks.onBeginObject = onBeginObject;
    callbacks.onBooleanElement = onBooleanElement;
    callbacks.onEndContainer = onEndContainer;
    callbacks.onEndData = onEndData;
    callbacks.onFloatingPointElement = onFloatingPointElement;
    callbacks.onIntegerElement = onIntegerElement;
    callbacks.onNullElement = onNullElement;
    callbacks.onStringElement = onStringElement;
    int errorOffset = 0;
    char stringBuffer[1000];
    const int result = ksjson_decode(data,
                                     (int)length,
                                     stringBuffer,
                                     sizeof(stringBuffer),
                                     &callbacks,
                                     &g_state,
                                     &errorOffset);
    free(data);
    if(result != KSJSON_OK)
    {
        KSLOG_ERROR("%s, offset %d: %s",
                    path, errorOffset, ksjson_stringForError(result));
        return false;
    }
    return true;
}
static bool loadState ( const char * const path ) { const int fd = open ( path , O_RDONLY ) ; if ( fd < 0 ) { return false ; } close ( fd ) ; char * data ; int length ; if ( ! ksfu_readEntireFile ( path , & data , & length , 50000 ) ) { KSLOG_ERROR ( " " , path ) ; return false ; } KSJSONDecodeCallbacks callbacks ; callbacks . onBeginArray = onBeginArray ; callbacks . onBeginObject = onBeginObject ; callbacks . onBooleanElement = onBooleanElement ; callbacks . onEndContainer = onEndContainer ; callbacks . onEndData = onEndData ; callbacks . onFloatingPointElement = onFloatingPointElement ; callbacks . onIntegerElement = onIntegerElement ; callbacks . onNullElement = onNullElement ; callbacks . onStringElement = onStringElement ; int errorOffset = 0 ; char stringBuffer [ 1000 ] ; const int result = ksjson_decode ( data , ( int ) length , stringBuffer , sizeof ( stringBuffer ) , & callbacks , & g_state , & errorOffset ) ; free ( data ) ; if ( result != KSJSON_OK ) { KSLOG_ERROR ( " " , path , errorOffset , ksjson_stringForError ( result ) ) ; return false ; } return true ; }
Load the persistent state portion of a crash context.
Load the persistent state portion of a crash context .
// Stop if the file doesn't exist. // This is expected on the first run of the app.