! * \brief boxaWriteMem() * * \param[out] pdata data of serialized boxa; ascii * \param[out] psize size of returned data * \param[in] boxa * \return 0 if OK, 1 on error * * * Notes: * (1) Serializes a boxa in memory and puts the result in a buffer. * */
| 2295 | * </pre> |
| 2296 | */ |
| 2297 | l_int32 |
| 2298 | boxaWriteMem(l_uint8 **pdata, |
| 2299 | size_t *psize, |
| 2300 | BOXA *boxa) |
| 2301 | { |
| 2302 | l_int32 ret; |
| 2303 | FILE *fp; |
| 2304 | |
| 2305 | PROCNAME("boxaWriteMem"); |
| 2306 | |
| 2307 | if (pdata) *pdata = NULL; |
| 2308 | if (psize) *psize = 0; |
| 2309 | if (!pdata) |
| 2310 | return ERROR_INT("&data not defined", procName, 1); |
| 2311 | if (!psize) |
| 2312 | return ERROR_INT("&size not defined", procName, 1); |
| 2313 | if (!boxa) |
| 2314 | return ERROR_INT("boxa not defined", procName, 1); |
| 2315 | |
| 2316 | #if HAVE_FMEMOPEN |
| 2317 | if ((fp = open_memstream((char **)pdata, psize)) == NULL) |
| 2318 | return ERROR_INT("stream not opened", procName, 1); |
| 2319 | ret = boxaWriteStream(fp, boxa); |
| 2320 | #else |
| 2321 | L_INFO("work-around: writing to a temp file\n", procName); |
| 2322 | #ifdef _WIN32 |
| 2323 | if ((fp = fopenWriteWinTempfile()) == NULL) |
| 2324 | return ERROR_INT("tmpfile stream not opened", procName, 1); |
| 2325 | #else |
| 2326 | if ((fp = tmpfile()) == NULL) |
| 2327 | return ERROR_INT("tmpfile stream not opened", procName, 1); |
| 2328 | #endif /* _WIN32 */ |
| 2329 | ret = boxaWriteStream(fp, boxa); |
| 2330 | rewind(fp); |
| 2331 | *pdata = l_binaryReadStream(fp, psize); |
| 2332 | #endif /* HAVE_FMEMOPEN */ |
| 2333 | fclose(fp); |
| 2334 | return ret; |
| 2335 | } |
| 2336 | |
| 2337 | |
| 2338 | /*---------------------------------------------------------------------* |
no test coverage detected