! * \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 */
| 1364 | * \return 0 if OK; 1 on error |
| 1365 | */ |
| 1366 | l_int32 |
| 1367 | l_binaryWrite(const char *filename, |
| 1368 | const char *operation, |
| 1369 | void *data, |
| 1370 | size_t nbytes) |
| 1371 | { |
| 1372 | char actualOperation[20]; |
| 1373 | FILE *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 | /*! |
no test coverage detected