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

Function acl_vstream_loadfile2

lib_acl/src/stdlib/acl_vstream.c:2541–2594  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2539}
2540
2541char *acl_vstream_loadfile2(const char *path, ssize_t *size)
2542{
2543 ACL_VSTREAM *fp;
2544#ifdef ACL_WINDOWS
2545 int oflags = O_RDONLY | O_BINARY;
2546#else
2547 int oflags = O_RDONLY;
2548#endif
2549#ifdef ACL_ANDROID
2550 int mode = 0644;
2551#else
2552 int mode = S_IREAD;
2553#endif
2554 int ret;
2555 ACL_VSTRING *vbuf;
2556 unsigned char buf[4096];
2557
2558 if (size) {
2559 *size = -1;
2560 }
2561
2562 if (path == NULL || *path == 0) {
2563 acl_msg_error("%s, %s(%d):path invalid",
2564 __FUNCTION__, __FILE__, __LINE__);
2565 return NULL;
2566 }
2567
2568 fp = acl_vstream_fopen(path, oflags, mode, 4096);
2569 if (fp == NULL) {
2570 acl_msg_error("%s, %s(%d): open file(%s) error(%s)",
2571 __FUNCTION__, __FILE__, __LINE__,
2572 path, acl_last_serror());
2573 return NULL;
2574 }
2575
2576 vbuf = acl_vstring_alloc(8192);
2577
2578 while (1) {
2579 ret = acl_vstream_read(fp, buf, sizeof(buf));
2580 if (ret == ACL_VSTREAM_EOF) {
2581 break;
2582 }
2583 acl_vstring_memcat(vbuf, (char *) buf, ret);
2584 }
2585
2586 if (size) {
2587 *size = (ssize_t) LEN(vbuf);
2588 }
2589
2590 acl_vstream_close(fp);
2591 ACL_VSTRING_TERMINATE(vbuf);
2592
2593 return acl_vstring_export(vbuf);
2594}
2595
2596/* acl_vstream_ctl - fine control */
2597

Callers 3

UpdateSvnMethod · 0.85
parse_resultFunction · 0.85
acl_vstream_loadfileFunction · 0.85

Calls 8

acl_msg_errorFunction · 0.85
acl_vstream_fopenFunction · 0.85
acl_last_serrorFunction · 0.85
acl_vstring_allocFunction · 0.85
acl_vstream_readFunction · 0.85
acl_vstring_memcatFunction · 0.85
acl_vstream_closeFunction · 0.85
acl_vstring_exportFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…