FreeBASIC
0.91.0
Main Page
Data Structures
Files
File List
Globals
str_assign.c
Go to the documentation of this file.
1
/* string assigning function */
2
3
#include "
fb.h
"
4
5
FBCALL
void
*
fb_StrAssignEx
6
(
7
void
*dst,
8
ssize_t dst_size,
9
void
*src,
10
ssize_t src_size,
11
int
fill_rem,
12
int
is_init
13
)
14
{
15
FBSTRING
*dstr;
16
const
char
*src_ptr;
17
ssize_t src_len;
18
19
FB_STRLOCK
();
20
21
if
( dst ==
NULL
)
22
{
23
if
( src_size == -1 )
24
fb_hStrDelTemp_NoLock
( (
FBSTRING
*)src );
25
26
FB_STRUNLOCK
();
27
28
return
dst;
29
}
30
31
/* src */
32
FB_STRSETUP_FIX
( src, src_size, src_ptr, src_len );
33
34
/* is dst var-len? */
35
if
( dst_size == -1 )
36
{
37
dstr = (
FBSTRING
*)dst;
38
39
/* src NULL? */
40
if
( src_len == 0 )
41
{
42
if
( is_init ==
FB_FALSE
)
43
{
44
fb_StrDelete
( dstr );
45
}
46
else
47
{
48
dstr->
data
=
NULL
;
49
dstr->
len
= 0;
50
dstr->
size
= 0;
51
}
52
}
53
else
54
{
55
/* if src is a temp, just copy the descriptor */
56
if
( (src_size == -1) &&
FB_ISTEMP
(src) )
57
{
58
if
( is_init ==
FB_FALSE
)
59
fb_StrDelete
( dstr );
60
61
dstr->
data
= (
char
*)src_ptr;
62
dstr->
len
= src_len;
63
dstr->
size
= ((
FBSTRING
*)src)->size;
64
65
((
FBSTRING
*)src)->data =
NULL
;
66
((
FBSTRING
*)src)->len = 0;
67
((
FBSTRING
*)src)->size = 0;
68
69
fb_hStrDelTempDesc
( (
FBSTRING
*)src );
70
71
FB_STRUNLOCK
();
72
73
return
dst;
74
}
75
76
/* else, realloc dst if needed and copy src */
77
if
( is_init ==
FB_FALSE
)
78
{
79
if
(
FB_STRSIZE
( dst ) != src_len )
80
fb_hStrRealloc
( dstr, src_len,
FB_FALSE
);
81
}
82
else
83
{
84
fb_hStrAlloc
( dstr, src_len );
85
}
86
87
fb_hStrCopy
( dstr->
data
, src_ptr, src_len );
88
}
89
}
90
/* fixed-len or zstring.. */
91
else
92
{
93
/* src NULL? */
94
if
( src_len == 0 )
95
{
96
*(
char
*)dst =
'\0'
;
97
}
98
else
99
{
100
/* byte ptr? as in C, assume dst is large enough */
101
if
( dst_size == 0 )
102
dst_size = src_len;
103
else
104
{
105
--dst_size;
/* less the null-term */
106
if
( dst_size < src_len )
107
src_len = dst_size;
108
}
109
110
fb_hStrCopy
( (
char
*)dst, src_ptr, src_len );
111
}
112
113
/* fill reminder with null's */
114
if
( fill_rem != 0 )
115
{
116
dst_size -= src_len;
117
if
( dst_size > 0 )
118
memset( &(((
char
*)dst)[src_len]), 0, dst_size );
119
}
120
}
121
122
123
/* delete temp? */
124
if
( src_size == -1 )
125
fb_hStrDelTemp_NoLock
( (
FBSTRING
*)src );
126
127
FB_STRUNLOCK
();
128
129
return
dst;
130
}
131
132
FBCALL
void
*
fb_StrAssign
133
(
134
void
*dst,
135
ssize_t dst_size,
136
void
*src,
137
ssize_t src_size,
138
int
fill_rem
139
)
140
{
141
return
fb_StrAssignEx
( dst, dst_size, src, src_size, fill_rem,
FB_FALSE
);
142
}
143
144
FBCALL
void
*
fb_StrInit
145
(
146
void
*dst,
147
ssize_t dst_size,
148
void
*src,
149
ssize_t src_size,
150
int
fill_rem
151
)
152
{
153
return
fb_StrAssignEx
( dst, dst_size, src, src_size, fill_rem,
FB_TRUE
);
154
}
rtlib
str_assign.c
Generated on Thu Jan 23 2014 19:40:12 for FreeBASIC by
1.8.4