MCPcopy Create free account
hub / github.com/anjo76/angelscript / ReadInt

Method ReadInt

sdk/add_on/scriptfile/scriptfile.cpp:430–469  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

428}
429
430asINT64 CScriptFile::ReadInt(asUINT bytes)
431{
432 if( file == 0 )
433 return 0;
434
435 if( bytes > 8 ) bytes = 8;
436 if( bytes == 0 ) return 0;
437
438 unsigned char buf[8];
439 size_t r = fread(buf, bytes, 1, file);
440 if( r == 0 ) return 0;
441
442 asINT64 val = 0;
443 if( mostSignificantByteFirst )
444 {
445 unsigned int n = 0;
446 for( ; n < bytes; n++ )
447 val |= asQWORD(buf[n]) << ((bytes-n-1)*8);
448
449 // Check the most significant byte to determine if the rest
450 // of the qword must be filled to give a negative value
451 if( buf[0] & 0x80 )
452 for( ; n < 8; n++ )
453 val |= asQWORD(0xFF) << (n*8);
454 }
455 else
456 {
457 unsigned int n = 0;
458 for( ; n < bytes; n++ )
459 val |= asQWORD(buf[n]) << (n*8);
460
461 // Check the most significant byte to determine if the rest
462 // of the qword must be filled to give a negative value
463 if( buf[bytes-1] & 0x80 )
464 for( ; n < 8; n++ )
465 val |= asQWORD(0xFF) << (n*8);
466 }
467
468 return val;
469}
470
471asQWORD CScriptFile::ReadUInt(asUINT bytes)
472{

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected