@@ -495,56 +495,56 @@ String FileAccess::get_as_utf8_string(bool p_skip_cr) const {
495
495
return s;
496
496
}
497
497
498
- void FileAccess::store_8 (uint8_t p_dest) {
499
- store_buffer (&p_dest, sizeof (uint8_t ));
498
+ bool FileAccess::store_8 (uint8_t p_dest) {
499
+ return store_buffer (&p_dest, sizeof (uint8_t ));
500
500
}
501
501
502
- void FileAccess::store_16 (uint16_t p_dest) {
502
+ bool FileAccess::store_16 (uint16_t p_dest) {
503
503
if (big_endian) {
504
504
p_dest = BSWAP16 (p_dest);
505
505
}
506
506
507
- store_buffer (reinterpret_cast <uint8_t *>(&p_dest), sizeof (uint16_t ));
507
+ return store_buffer (reinterpret_cast <uint8_t *>(&p_dest), sizeof (uint16_t ));
508
508
}
509
509
510
- void FileAccess::store_32 (uint32_t p_dest) {
510
+ bool FileAccess::store_32 (uint32_t p_dest) {
511
511
if (big_endian) {
512
512
p_dest = BSWAP32 (p_dest);
513
513
}
514
514
515
- store_buffer (reinterpret_cast <uint8_t *>(&p_dest), sizeof (uint32_t ));
515
+ return store_buffer (reinterpret_cast <uint8_t *>(&p_dest), sizeof (uint32_t ));
516
516
}
517
517
518
- void FileAccess::store_64 (uint64_t p_dest) {
518
+ bool FileAccess::store_64 (uint64_t p_dest) {
519
519
if (big_endian) {
520
520
p_dest = BSWAP64 (p_dest);
521
521
}
522
522
523
- store_buffer (reinterpret_cast <uint8_t *>(&p_dest), sizeof (uint64_t ));
523
+ return store_buffer (reinterpret_cast <uint8_t *>(&p_dest), sizeof (uint64_t ));
524
524
}
525
525
526
- void FileAccess::store_real (real_t p_real) {
526
+ bool FileAccess::store_real (real_t p_real) {
527
527
if constexpr (sizeof (real_t ) == 4 ) {
528
- store_float (p_real);
528
+ return store_float (p_real);
529
529
} else {
530
- store_double (p_real);
530
+ return store_double (p_real);
531
531
}
532
532
}
533
533
534
- void FileAccess::store_half (float p_dest) {
535
- store_16 (Math::make_half_float (p_dest));
534
+ bool FileAccess::store_half (float p_dest) {
535
+ return store_16 (Math::make_half_float (p_dest));
536
536
}
537
537
538
- void FileAccess::store_float (float p_dest) {
538
+ bool FileAccess::store_float (float p_dest) {
539
539
MarshallFloat m;
540
540
m.f = p_dest;
541
- store_32 (m.i );
541
+ return store_32 (m.i );
542
542
}
543
543
544
- void FileAccess::store_double (double p_dest) {
544
+ bool FileAccess::store_double (double p_dest) {
545
545
MarshallDouble m;
546
546
m.d = p_dest;
547
- store_64 (m.l );
547
+ return store_64 (m.l );
548
548
}
549
549
550
550
uint64_t FileAccess::get_modified_time (const String &p_file) {
@@ -628,19 +628,18 @@ Error FileAccess::set_read_only_attribute(const String &p_file, bool p_ro) {
628
628
return err;
629
629
}
630
630
631
- void FileAccess::store_string (const String &p_string) {
631
+ bool FileAccess::store_string (const String &p_string) {
632
632
if (p_string.length () == 0 ) {
633
- return ;
633
+ return true ;
634
634
}
635
635
636
636
CharString cs = p_string.utf8 ();
637
- store_buffer ((uint8_t *)&cs[0 ], cs.length ());
637
+ return store_buffer ((uint8_t *)&cs[0 ], cs.length ());
638
638
}
639
639
640
- void FileAccess::store_pascal_string (const String &p_string) {
640
+ bool FileAccess::store_pascal_string (const String &p_string) {
641
641
CharString cs = p_string.utf8 ();
642
- store_32 (cs.length ());
643
- store_buffer ((uint8_t *)&cs[0 ], cs.length ());
642
+ return store_32 (cs.length ()) && store_buffer ((uint8_t *)&cs[0 ], cs.length ());
644
643
}
645
644
646
645
String FileAccess::get_pascal_string () {
@@ -655,13 +654,12 @@ String FileAccess::get_pascal_string() {
655
654
return ret;
656
655
}
657
656
658
- void FileAccess::store_line (const String &p_line) {
659
- store_string (p_line);
660
- store_8 (' \n ' );
657
+ bool FileAccess::store_line (const String &p_line) {
658
+ return store_string (p_line) && store_8 (' \n ' );
661
659
}
662
660
663
- void FileAccess::store_csv_line (const Vector<String> &p_values, const String &p_delim) {
664
- ERR_FAIL_COND (p_delim.length () != 1 );
661
+ bool FileAccess::store_csv_line (const Vector<String> &p_values, const String &p_delim) {
662
+ ERR_FAIL_COND_V (p_delim.length () != 1 , false );
665
663
666
664
String line = " " ;
667
665
int size = p_values.size ();
@@ -678,30 +676,43 @@ void FileAccess::store_csv_line(const Vector<String> &p_values, const String &p_
678
676
line += value;
679
677
}
680
678
681
- store_line (line);
679
+ return store_line (line);
682
680
}
683
681
684
- void FileAccess::store_buffer (const Vector<uint8_t > &p_buffer) {
682
+ bool FileAccess::store_buffer (const Vector<uint8_t > &p_buffer) {
685
683
uint64_t len = p_buffer.size ();
684
+ if (len == 0 ) {
685
+ return true ;
686
+ }
687
+
686
688
const uint8_t *r = p_buffer.ptr ();
687
689
688
- store_buffer (r, len);
690
+ return store_buffer (r, len);
691
+ }
692
+
693
+ bool FileAccess::store_buffer (const uint8_t *p_src, uint64_t p_length) {
694
+ ERR_FAIL_COND_V (!p_src && p_length > 0 , false );
695
+ for (uint64_t i = 0 ; i < p_length; i++) {
696
+ if (unlikely (!store_8 (p_src[i]))) {
697
+ return false ;
698
+ }
699
+ }
700
+ return true ;
689
701
}
690
702
691
- void FileAccess::store_var (const Variant &p_var, bool p_full_objects) {
703
+ bool FileAccess::store_var (const Variant &p_var, bool p_full_objects) {
692
704
int len;
693
705
Error err = encode_variant (p_var, nullptr , len, p_full_objects);
694
- ERR_FAIL_COND_MSG (err != OK, " Error when trying to encode Variant." );
706
+ ERR_FAIL_COND_V_MSG (err != OK, false , " Error when trying to encode Variant." );
695
707
696
708
Vector<uint8_t > buff;
697
709
buff.resize (len);
698
710
699
711
uint8_t *w = buff.ptrw ();
700
712
err = encode_variant (p_var, &w[0 ], len, p_full_objects);
701
- ERR_FAIL_COND_MSG (err != OK, " Error when trying to encode Variant." );
713
+ ERR_FAIL_COND_V_MSG (err != OK, false , " Error when trying to encode Variant." );
702
714
703
- store_32 (len);
704
- store_buffer (buff);
715
+ return store_32 (len) && store_buffer (buff);
705
716
}
706
717
707
718
Vector<uint8_t > FileAccess::get_file_as_bytes (const String &p_path, Error *r_error) {
@@ -864,7 +875,7 @@ void FileAccess::_bind_methods() {
864
875
ClassDB::bind_method (D_METHOD (" store_float" , " value" ), &FileAccess::store_float);
865
876
ClassDB::bind_method (D_METHOD (" store_double" , " value" ), &FileAccess::store_double);
866
877
ClassDB::bind_method (D_METHOD (" store_real" , " value" ), &FileAccess::store_real);
867
- ClassDB::bind_method (D_METHOD (" store_buffer" , " buffer" ), (void (FileAccess::*)(const Vector<uint8_t > &)) & FileAccess::store_buffer);
878
+ ClassDB::bind_method (D_METHOD (" store_buffer" , " buffer" ), (bool (FileAccess::*)(const Vector<uint8_t > &)) & FileAccess::store_buffer);
868
879
ClassDB::bind_method (D_METHOD (" store_line" , " line" ), &FileAccess::store_line);
869
880
ClassDB::bind_method (D_METHOD (" store_csv_line" , " values" , " delim" ), &FileAccess::store_csv_line, DEFVAL (" ," ));
870
881
ClassDB::bind_method (D_METHOD (" store_string" , " string" ), &FileAccess::store_string);
0 commit comments