// File: /workspace/github_c_makefile_star2_O2/schroeder-lvb[P]sissm/src/ftrack.c
// Function: ftrackResync
int ftrackResync( ftrackObj *fPtr ) 
{
    int  i, errCode = 1;
    char currFileName[256];
    unsigned long fileSize;
    int fileChanged;

    if ( fPtr != NULL ) {
        errCode = 0;

        ftrackGetFilename( fPtr->fpr, currFileName );

        fileChanged = (0 != strcmp( currFileName, fPtr->baselineFileName ));

        if ( !fileChanged ) {
            fileSize = _ftrackGetFileSize( fPtr );
            if ( fileSize < fPtr->lastFileSize ) {
                fileChanged = 1;
                fPtr->lastFileSize = 0;
            }
            else {
                fPtr->lastFileSize = fileSize;
            }
        }

        if ( fileChanged ) {

            // printf("\n**%s**\n", fPtr->baselineFileName );
            // printf("\nclosing:  **%p**\n", fPtr->fpr );
            // fclose( fPtr->fpr );

	    logPrintf(LOG_LEVEL_INFO, "ftrack", "LogFile resynching due to possible file rotation by host");

#ifdef _WIN32
            // close the current file (if valid)
            if ( fPtr->fpr != NULL ) { fclose ( fPtr->fpr ); fPtr->fpr = NULL; };

            // try to open it up to 3x (3 seconds) before declaring fault
            for ( i=0; i<3; i++ ) {
                if (NULL != (fPtr->fpr = _fsopen( fPtr->originalFileName, "r", _SH_DENYNO ))) break;
                sleep( 1 );
            }
            if ( fPtr->fpr == NULL ) errCode = 1;
#else
            // close the current file (if valid)
            if ( fPtr->fpr != -1 ) { close( fPtr->fpr );  fPtr->fpr = -1; };

            // try to open it up to 3x (3 seconds) before declaring fault
            for ( i=0; i<3; i++ ) {
                if ( -1  != (fPtr->fpr = open( fPtr->baselineFileName, O_RDONLY | O_NONBLOCK | O_NDELAY  ))) break;
                sleep( 1 );
            }
            if ( fPtr->fpr == -1 ) errCode = 1;
#endif
            logPrintf(LOG_LEVEL_INFO, "ftrack", "LogFile reopen base name ::%s:: errCode %d", fPtr->baselineFileName, errCode );
        }
    }
    return( errCode );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x100, %rsp            # imm = 0x100
testq %rdi, %rdi
je 0xeba4
movq %rdi, %r14
movl (%rdi), %edi
movq %rsp, %r15
movq %r15, %rsi
callq 0xea5b
leaq 0x404(%r14), %rbx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8220
testl %eax, %eax
jne 0xeb4a
movq %r14, %rdi
callq 0xeac8
cmpq 0x808(%r14), %rax
jae 0xebe3
andq $0x0, 0x808(%r14)
leaq 0xd9aa(%rip), %rsi      # 0x1c4fb
leaq 0xd9aa(%rip), %rdx      # 0x1c502
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x1920b
movl (%r14), %edi
cmpl $-0x1, %edi
je 0xeb73
callq 0x81d0
orl $-0x1, (%r14)
pushq $0x3
popq %r12
pushq $0x1
popq %r15
xorl %ebp, %ebp
subl $0x1, %r12d
jb 0xeba9
movq %rbx, %rdi
movl $0x800, %esi            # imm = 0x800
xorl %eax, %eax
callq 0x8320
movl %eax, (%r14)
cmpl $-0x1, %eax
jne 0xebb3
movl %r15d, %edi
callq 0x83b0
jmp 0xeb7d
pushq $0x1
popq %rbp
jmp 0xebd1
xorl %ebp, %ebp
cmpl $-0x1, (%r14)
sete %bpl
leaq 0xd941(%rip), %rsi      # 0x1c4fb
leaq 0xd97a(%rip), %rdx      # 0x1c53b
pushq $0x2
popq %rdi
movq %rbx, %rcx
movl %ebp, %r8d
xorl %eax, %eax
callq 0x1920b
movl %ebp, %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x808(%r14)
xorl %ebp, %ebp
jmp 0xebd1