Page 238 - ARM 64 Bit Assembly Language
P. 238

226 Chapter 7


               587  } else {
               588    cmp = 1;    // d > 0
               589  }
               590  bigint_free(d);
               591  return cmp;
               592  }
               593
               594  /******************************************************************/
               595  /* Functions for binary input/output                         */
               596  /******************************************************************/
               597
               598  void bigint_write_binary(FILE *f,bigint x) {
               599  if (fwrite(&(x->size), sizeof(x->size), 1, f) != 1) {
               600    perror("Write failed");
               601    exit(4);
               602  }
               603  if (fwrite(x->blks, sizeof(chunk), x->size, f) != x->size) {
               604    perror("Write failed");
               605    exit(4);
               606  }
               607  }
               608
               609  bigint bigint_read_binary(FILE *f) {
               610  bigint r = (bigint) malloc(sizeof(struct bigint_struct));
               611  if (r == NULL) {
               612    perror("bigint_read_binary");
               613    exit(1);
               614  }
               615  if (fread(&(r->size), sizeof(r->size), 1, f) != 1) {
               616    free(r);
               617    return NULL;
               618  }
               619  r->blks = (chunk *) malloc(r->size * sizeof(chunk));
               620  if (r->blks == NULL) {
               621    perror("bigint_read_binary");
               622    exit(2);
               623  }
               624  if (fread(r->blks, sizeof(chunk), r->size, f) != r->size) {
               625    perror("Unable to read from file");
               626    exit(4);
               627  }
               628  return r;
               629  }
               630
               631  /******************************************************************/
               632  /*  Utility functions                                        */
               633  /******************************************************************/
               634
               635  bigint bigint_alloc(int chunks) {
   233   234   235   236   237   238   239   240   241   242   243