%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% header /** @file Write to file using fwrite(), report errors immediately. */ #ifndef STDIO_H_INCLUDED #include #define STDIO_H_INCLUDED 1 #endif #ifndef DK4APP_H_INCLUDED #include "dk4app.h" #define DK4APP_H_INCLUDED 1 #endif #ifdef __cplusplus extern "C" { #endif /** Write to file, report errors immediately. @param filename File name to write to. @param ptr Start address of buffer. @param elsize Size of each element. @param nelem Number of elements. @param fipo File to write to. @param app Application structure for diagnostics, may be NULL. @return 1 on success (all elements written completely), 0 on error. */ int dk4fwrite_app( const dkChar *filename, const void *ptr, size_t elsize, size_t nelem, FILE *fipo, dk4_app_t *app ); #ifdef __cplusplus } #endif %% module #include "dk4fwra.h" #if DK4_HAVE_ERRNO_H #ifndef ERRNO_H_INCLUDED #include #define ERRNO_H_INCLUDED 1 #endif #endif int dk4fwrite_app( const dkChar *filename, const void *ptr, size_t elsize, size_t nelem, FILE *fipo, dk4_app_t *app ) { size_t wrb; int back = 0; int errc; if ((NULL != ptr) && (NULL != fipo) && (0 < elsize) && (0 < nelem)) { errno = 0; wrb = fwrite(ptr, elsize, nelem, fipo); if (wrb == nelem) { back = 1; } else { errc = errno; dk4fd_write_error_msg(app, filename, errc); } } else { $? "! invalid arguments" } return back; }