MCPcopy Create free account
hub / github.com/creatale/node-dv / sarrayWriteMem

Function sarrayWriteMem

deps/leptonica/src/sarray1.c:1552–1590  ·  view source on GitHub ↗

! * \brief sarrayWriteMem() * * \param[out] pdata data of serialized sarray; ascii * \param[out] psize size of returned data * \param[in] sa * \return 0 if OK, 1 on error * * * Notes: * (1) Serializes a sarray in memory and puts the result in a buffer. * */

Source from the content-addressed store, hash-verified

1550 * </pre>
1551 */
1552l_int32
1553sarrayWriteMem(l_uint8 **pdata,
1554 size_t *psize,
1555 SARRAY *sa)
1556{
1557l_int32 ret;
1558FILE *fp;
1559
1560 PROCNAME("sarrayWriteMem");
1561
1562 if (pdata) *pdata = NULL;
1563 if (psize) *psize = 0;
1564 if (!pdata)
1565 return ERROR_INT("&data not defined", procName, 1);
1566 if (!psize)
1567 return ERROR_INT("&size not defined", procName, 1);
1568 if (!sa)
1569 return ERROR_INT("sa not defined", procName, 1);
1570
1571#if HAVE_FMEMOPEN
1572 if ((fp = open_memstream((char **)pdata, psize)) == NULL)
1573 return ERROR_INT("stream not opened", procName, 1);
1574 ret = sarrayWriteStream(fp, sa);
1575#else
1576 L_INFO("work-around: writing to a temp file\n", procName);
1577 #ifdef _WIN32
1578 if ((fp = fopenWriteWinTempfile()) == NULL)
1579 return ERROR_INT("tmpfile stream not opened", procName, 1);
1580 #else
1581 if ((fp = tmpfile()) == NULL)
1582 return ERROR_INT("tmpfile stream not opened", procName, 1);
1583 #endif /* _WIN32 */
1584 ret = sarrayWriteStream(fp, sa);
1585 rewind(fp);
1586 *pdata = l_binaryReadStream(fp, psize);
1587#endif /* HAVE_FMEMOPEN */
1588 fclose(fp);
1589 return ret;
1590}
1591
1592
1593/*!

Callers

nothing calls this directly

Calls 3

sarrayWriteStreamFunction · 0.85
fopenWriteWinTempfileFunction · 0.85
l_binaryReadStreamFunction · 0.85

Tested by

no test coverage detected