summaryrefslogtreecommitdiff
path: root/support/dktools/dk4strda.ctr
blob: a23964c2d8ccd1b2bafda1cd3862b395e0ff5c01 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
%%	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;
}