Load template file */
| 465 | |
| 466 | /* Load template file */ |
| 467 | int tpl_load(tpl_t *tpl, const char *filename) |
| 468 | { |
| 469 | char *buffer; |
| 470 | int len; |
| 471 | FILE *fp = fopen(filename, "rb"); |
| 472 | |
| 473 | if (fp == NULL) |
| 474 | return TPL_OPEN_ERROR; |
| 475 | |
| 476 | /* Find length of file content */ |
| 477 | (void)fseek(fp, 0, SEEK_END); |
| 478 | len = ftell(fp); |
| 479 | (void) rewind(fp); |
| 480 | |
| 481 | /* Allocate buffer for data + 0 byte */ |
| 482 | buffer = (char*)acl_mymalloc(len+1); |
| 483 | |
| 484 | if (fread(buffer, 1, len, fp) < (unsigned)len) |
| 485 | { |
| 486 | (void)fclose(fp); |
| 487 | acl_myfree(buffer); |
| 488 | return TPL_READ_ERROR; |
| 489 | } |
| 490 | (void)fclose(fp); |
| 491 | buffer[len] = 0; |
| 492 | |
| 493 | /* Use data in buffer to construct template */ |
| 494 | len = tpl_construct(tpl, buffer, buffer + len); |
| 495 | if (len != TPL_OK) |
| 496 | { |
| 497 | tpl_release(tpl); |
| 498 | tpl_init(tpl); |
| 499 | } |
| 500 | acl_myfree(buffer); |
| 501 | return len; |
| 502 | } |
| 503 | |
| 504 | /* Load from a string */ |
| 505 | int tpl_from_string(tpl_t *tpl, const char *buffer, int len) |
no test coverage detected
searching dependent graphs…