Simpler BE reading. - vtv-tools - virtual terminal video tools
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) Tags
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 7e4457182ef8ffcd6bb0ee7c35eebd55ac429cd1
 (DIR) parent e8dadc39466370c2295e5e7b176d77e823403fa6
 (HTM) Author: Troels Henriksen <athas@sigkill.dk>
       Date:   Mon, 14 Aug 2023 20:32:37 +0200
       
       Simpler BE reading.
       
       Diffstat:
         M src/vtv-from-ff.c                   |      28 +++++++++++-----------------
       
       1 file changed, 11 insertions(+), 17 deletions(-)
       ---
 (DIR) diff --git a/src/vtv-from-ff.c b/src/vtv-from-ff.c
       @@ -25,29 +25,23 @@ void bg_rgb(FILE *f, uint8_t r, uint8_t g, uint8_t b) {
        }
        
        int read_be_uint16(FILE *f, uint16_t *x) {
       -  uint8_t b;
       +  uint8_t word[2];
        
       -  *x = 0;
       -  if (fread(&b, 1, 1, f) != 1) { return 1; }
       -  *x += (uint16_t)b << 8;
       -  if (fread(&b, 1, 1, f) != 1) { return 1; }
       -  *x += b;
       +  if (fread(&word, 1, 2, f) != 2) {
       +    return 1;
       +  }
       +  *x = (word[1] << 8) + word[0];
        
          return 0;
        }
        
        int read_be_uint32(FILE *f, uint32_t *x) {
       -  uint8_t b;
       -
       -  *x = 0;
       -  if (fread(&b, 1, 1, f) != 1) { return 1; }
       -  *x += (uint32_t)b << 24;
       -  if (fread(&b, 1, 1, f) != 1) { return 1; }
       -  *x += (uint32_t)b << 16;
       -  if (fread(&b, 1, 1, f) != 1) { return 1; }
       -  *x += (uint32_t)b << 8;
       -  if (fread(&b, 1, 1, f) != 1) { return 1; }
       -  *x += b;
       +  uint8_t word[4];
       +
       +  if (fread(&word, 1, 4, f) != 4) {
       +    return 1;
       +  }
       +  *x = (word[0] << 24) + (word[1] << 16) + (word[2] << 8) + word[3];
        
          return 0;
        }