File: bs_capacityleft.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (22 lines) | stat: -rw-r--r-- 419 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "parse.h"

size_t bs_capacityleft(const struct bytestream* bs) {
  if (bs->cur>=bs->max) 	// if EOF or error, return 0
    return 0;
  return bs->max - bs->cur;
}

#ifdef UNITTEST
#include <assert.h>

int main() {
  struct bytestream bs;

  bs.cur=0; bs.max=100;
  assert(bs_capacityleft(&bs) == 100);
  bs.cur=1;
  assert(bs_capacityleft(&bs) == 99);
  bs.max=0;
  assert(bs_capacityleft(&bs) == 0);
}
#endif