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

Function l_binaryWrite

deps/leptonica/src/utils2.c:1366–1399  ·  view source on GitHub ↗

! * \brief l_binaryWrite() * * \param[in] filename output * \param[in] operation "w" for write; "a" for append * \param[in] data binary data to be written * \param[in] nbytes size of data array * \return 0 if OK; 1 on error */

Source from the content-addressed store, hash-verified

1364 * \return 0 if OK; 1 on error
1365 */
1366l_int32
1367l_binaryWrite(const char *filename,
1368 const char *operation,
1369 void *data,
1370 size_t nbytes)
1371{
1372char actualOperation[20];
1373FILE *fp;
1374
1375 PROCNAME("l_binaryWrite");
1376
1377 if (!filename)
1378 return ERROR_INT("filename not defined", procName, 1);
1379 if (!operation)
1380 return ERROR_INT("operation not defined", procName, 1);
1381 if (!data)
1382 return ERROR_INT("data not defined", procName, 1);
1383 if (nbytes <= 0)
1384 return ERROR_INT("nbytes must be > 0", procName, 1);
1385
1386 if (strcmp(operation, "w") && strcmp(operation, "a"))
1387 return ERROR_INT("operation not one of {'w','a'}", procName, 1);
1388
1389 /* The 'b' flag to fopen() is ignored for all POSIX
1390 * conforming systems. However, Windows needs the 'b' flag. */
1391 stringCopy(actualOperation, operation, 2);
1392 strncat(actualOperation, "b", 2);
1393
1394 if ((fp = fopenWriteStream(filename, actualOperation)) == NULL)
1395 return ERROR_INT("stream not opened", procName, 1);
1396 fwrite(data, 1, nbytes, fp);
1397 fclose(fp);
1398 return 0;
1399}
1400
1401
1402/*!

Callers 15

fmorphautogen1Function · 0.85
fmorphautogen2Function · 0.85
fhmtautogen1Function · 0.85
fhmtautogen2Function · 0.85
ccbaWriteSVGFunction · 0.85
strcodeFinalizeFunction · 0.85
pixacompConvertToPdfFunction · 0.85
pixcompWriteFileFunction · 0.85
fileCorruptByDeletionFunction · 0.85
fileCorruptByMutationFunction · 0.85
convertJpegToPSEmbedFunction · 0.85

Calls 2

stringCopyFunction · 0.85
fopenWriteStreamFunction · 0.85

Tested by

no test coverage detected