%% options copyright owner = Dirk Krause copyright year = 2015-xxxx license = bsd %% header /** @file Dynamic string allocation with application support. CRT on Windows: Optional. */ #ifndef DK4CONF_H_INCLUDED #include "dk4conf.h" #endif #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef DK4APP_H_INCLUDED #include "dk4app.h" #endif #ifdef __cplusplus extern "C" { #endif /** Duplicate string (create copy in dynamically allocated memory). @param src String to copy. @param app Application structure for diagnostics, may be NULL. @return Pointer to new string on success, NULL on error. */ dkChar * dk4str_dup_app(const dkChar *src, dk4_app_t *app); #ifdef __cplusplus } #endif %% module #include "dk4strda.h" #ifndef DK4NUMCO_H_INCLUDED #include "dk4numco.h" #endif #ifndef DK4MEMA_H_INCLUDED #include "dk4mema.h" #endif #ifndef DK4STRD_H_INCLUDED #include "dk4strd.h" #endif #ifndef DK4CONST_H_INCLUDED #include "dk4const.h" #endif $!trace-include dkChar * dk4str_dup_app(const dkChar *src, dk4_app_t *app) { dkChar *back = NULL; size_t sz; if (NULL != src) { sz = dk4str_len(src); if (SIZE_MAX > sz) { sz++; back = dk4mem_new_app(dkChar,sz,app); if (NULL != back) { (void)dk4str_cpy_s(back, sz, src, NULL); #if 0 if (NULL != app) { if (0 != dk4app_log_do(app, DK4_LL_DEBUG)) { if ((NULL != app->msg_debug) && (41 < app->sz_msg_debug)) { dk4app_log_3( app,app->msg_debug,app->sz_msg_debug,DK4_LL_DEBUG,40,41,back ); } } } #endif } } else { dk4app_log_base1(app, DK4_LL_ERROR, 82); } } return back; }