Changeset 9c5e3a5 in mainline
- Timestamp:
- 2018-08-01T11:07:26Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c398db2
- Parents:
- b79903b
- git-author:
- Jiri Svoboda <jiri@…> (2018-07-31 18:06:53)
- git-committer:
- Jiri Svoboda <jiri@…> (2018-08-01 11:07:26)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
boot/Makefile.common
rb79903b r9c5e3a5 241 241 $(USPACE_PATH)/lib/label/test-liblabel \ 242 242 $(USPACE_PATH)/lib/posix/test-libposix \ 243 $(USPACE_PATH)/lib/sif/test-libsif \ 243 244 $(USPACE_PATH)/lib/uri/test-liburi \ 244 245 $(USPACE_PATH)/drv/bus/usb/xhci/test-xhci \ -
uspace/app/contacts/contacts.c
rb79903b r9c5e3a5 202 202 free(cname); 203 203 tinput_destroy(tinput); 204 return EOK; 204 205 error: 205 206 if (trans != NULL) -
uspace/lib/sif/src/sif.c
rb79903b r9c5e3a5 68 68 69 69 static errno_t sif_export_node(sif_node_t *, FILE *); 70 static errno_t sif_import_node(sif_node_t *, FILE *, sif_node_t **); 70 71 71 72 /** Create new SIF node. … … 169 170 return ENOMEM; 170 171 171 root = sif_node_new(NULL);172 if (root == NULL) {173 rc = ENOMEM;174 goto error;175 }176 177 root->ntype = str_dup("sif");178 if (root->ntype == NULL) {179 rc = ENOMEM;180 goto error;181 }182 183 172 f = fopen(fname, "r+"); 184 173 if (f == NULL) { … … 186 175 goto error; 187 176 } 177 178 rc = sif_import_node(NULL, f, &root); 179 if (rc != EOK) 180 goto error; 181 182 if (str_cmp(root->ntype, "sif") != 0) { 183 rc = EIO; 184 goto error; 185 } 186 187 sess->root = root; 188 188 189 189 sess->f = f; … … 534 534 } 535 535 536 /** Import string from file. 537 * 538 * Import string from file (the string in the file must be 539 * properly bracketed and escaped). 540 * 541 * @param f File 542 * @param rstr Place to store pointer to newly allocated string 543 * @return EOK on success, EIO on I/O error 544 */ 545 static errno_t sif_import_string(FILE *f, char **rstr) 546 { 547 char *str; 548 size_t str_size; 549 size_t sidx; 550 char c; 551 errno_t rc; 552 553 str_size = 1; 554 sidx = 0; 555 str = malloc(str_size + 1); 556 if (str == NULL) 557 return ENOMEM; 558 559 c = fgetc(f); 560 if (c != '[') { 561 rc = EIO; 562 goto error; 563 } 564 565 while (true) { 566 c = fgetc(f); 567 if (c == EOF) { 568 rc = EIO; 569 goto error; 570 } 571 572 if (c == ']') 573 break; 574 575 if (c == '\\') { 576 c = fgetc(f); 577 if (c == EOF) { 578 rc = EIO; 579 goto error; 580 } 581 } 582 583 if (sidx >= str_size) { 584 str_size *= 2; 585 str = realloc(str, str_size + 1); 586 if (str == NULL) { 587 rc = ENOMEM; 588 goto error; 589 } 590 } 591 592 str[sidx++] = c; 593 } 594 595 str[sidx] = '\0'; 596 *rstr = str; 597 return EOK; 598 error: 599 free(str); 600 return rc; 601 } 602 536 603 /** Export SIF node to file. 537 604 * … … 567 634 } 568 635 636 /** Import SIF node from file. 637 * 638 * @param parent Parent node 639 * @param f File 640 * @param rnode Place to store pointer to imported node 641 * @return EOK on success, EIO on I/O error 642 */ 643 static errno_t sif_import_node(sif_node_t *parent, FILE *f, sif_node_t **rnode) 644 { 645 errno_t rc; 646 sif_node_t *node = NULL; 647 sif_node_t *child; 648 char *ntype; 649 char c; 650 651 node = sif_node_new(parent); 652 if (node == NULL) 653 return ENOMEM; 654 655 rc = sif_import_string(f, &ntype); 656 if (rc != EOK) 657 goto error; 658 659 node->ntype = ntype; 660 661 c = fgetc(f); 662 if (c != '{') { 663 rc = EIO; 664 goto error; 665 } 666 667 c = fgetc(f); 668 if (c == EOF) { 669 rc = EIO; 670 goto error; 671 } 672 673 while (c != '}') { 674 ungetc(c, f); 675 676 rc = sif_import_node(node, f, &child); 677 if (rc != EOK) 678 goto error; 679 680 list_append(&child->lparent, &node->children); 681 682 c = fgetc(f); 683 if (c == EOF) { 684 rc = EIO; 685 goto error; 686 } 687 } 688 689 *rnode = node; 690 return EOK; 691 error: 692 sif_node_delete(node); 693 return rc; 694 } 695 569 696 /** @} 570 697 */
Note:
See TracChangeset
for help on using the changeset viewer.