MCPcopy Create free account
hub / github.com/acl-dev/acl / tpl_load

Function tpl_load

app/wizard/tpllib.cpp:467–502  ·  view source on GitHub ↗

Load template file */

Source from the content-addressed store, hash-verified

465
466/* Load template file */
467int 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 */
505int tpl_from_string(tpl_t *tpl, const char *buffer, int len)

Callers 1

open_tplMethod · 0.70

Calls 3

tpl_constructFunction · 0.70
tpl_releaseFunction · 0.70
tpl_initFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…