summaryrefslogtreecommitdiff
path: root/support/dktools/dk4strda.ctr
blob: 0454aae96babd55f03853b29f93417668cb5828f (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2015-xxxx
SPDX-License-Identifier:	BSD-3-Clause



%%	header

/**	@file
	Dynamic string allocation with application
	support.

	CRT on Windows: Optional.
*/

#ifndef DK4CONF_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4conf.h"
#else
#include <dktools-4/dk4conf.h>
#endif
#endif

#ifndef DK4TYPES_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4types.h"
#else
#include <dktools-4/dk4types.h>
#endif
#endif

#ifndef DK4APP_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4app.h"
#else
#include <dktools-4/dk4app.h>
#endif
#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 "dk4conf.h"
#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

#if DK4_HAVE_ASSERT_H
#ifndef	ASSERT_H_INCLUDED
#include <assert.h>
#define	ASSERT_H_INCLUDED 1
#endif
#endif


$!trace-include



dkChar *
dk4str_dup_app(const dkChar *src, dk4_app_t *app)
{
  dkChar	*back	= NULL;
  size_t	 sz;
#if	DK4_USE_ASSERT
  assert(NULL != src);
#endif
  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;
}