-
Notifications
You must be signed in to change notification settings - Fork 207
/
Copy pathcfe_sb_util.c
702 lines (563 loc) · 18.6 KB
/
cfe_sb_util.c
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/******************************************************************************
** File: cfe_sb_util.c
**
** Purpose:
** This file contains 'access' macros and functions for reading and
** writing message header fields.
**
** Author: R.McGraw/SSI
**
******************************************************************************/
/*
** Include Files
*/
#include "cfe_sb.h"
#include "ccsds.h"
#include "osapi.h"
#include "cfe_error.h"
#include <string.h>
/******************************************************************************
** Function: CFE_SB_InitMsg()
**
** Purpose:
** Initialize the header fields of a message
**
** Arguments:
** MsgPtr - Pointer to the header of a message.
** MsgId - MsgId to use for the message.
** Length - Length of the message in bytes.
** Clear - Indicates whether to clear the entire message:
** true = fill sequence count and packet data with zeros
** false = leave sequence count and packet data unchanged
** Return:
** (none)
*/
void CFE_SB_InitMsg(void *MsgPtr,
CFE_SB_MsgId_t MsgId,
uint16 Length,
bool Clear )
{
uint16 SeqCount;
CCSDS_PriHdr_t *PktPtr;
PktPtr = (CCSDS_PriHdr_t *) MsgPtr;
/* Save the sequence count in case it must be preserved. */
SeqCount = CCSDS_RD_SEQ(*PktPtr);
/* Zero the entire packet if needed. */
if (Clear)
{ memset(MsgPtr, 0, Length); }
else /* Clear only the primary header. */
{
CCSDS_CLR_PRI_HDR(*PktPtr);
}
/* Set the length fields in the primary header. */
CCSDS_WR_LEN(*PktPtr, Length);
/* Always set the secondary header flag as CFS applications are required use it */
CCSDS_WR_SHDR(*PktPtr, 1);
CFE_SB_SetMsgId(MsgPtr, MsgId);
/* Restore the sequence count if needed. */
if (!Clear)
CCSDS_WR_SEQ(*PktPtr, SeqCount);
else
CCSDS_WR_SEQFLG(*PktPtr, CCSDS_INIT_SEQFLG);
} /* end CFE_SB_InitMsg */
/******************************************************************************
** Function: CFE_SB_MsgHdrSize()
**
** Purpose:
** Get the size of a message header.
**
** Arguments:
** *MsgPtr - Pointer to a SB message
**
** Return:
** Size of Message Header.
*/
uint16 CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
uint16 size;
const CCSDS_PriHdr_t *HdrPtr;
HdrPtr = (const CCSDS_PriHdr_t *) MsgPtr;
/* if secondary hdr is not present... */
/* Since all cFE messages must have a secondary hdr this check is not needed */
if(CCSDS_RD_SHDR(*HdrPtr) == 0){
size = sizeof(CCSDS_PriHdr_t);
}else if(CCSDS_RD_TYPE(*HdrPtr) == CCSDS_CMD){
size = CFE_SB_CMD_HDR_SIZE;
}else{
size = CFE_SB_TLM_HDR_SIZE;
}
return size;
#endif
}/* end CFE_SB_MsgHdrSize */
/******************************************************************************
** Function: CFE_SB_GetUserData()
**
** Purpose:
** Get a pointer to the user data portion of a message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** Pointer to the first byte after the headers
*/
void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
uint8 *BytePtr;
uint16 HdrSize;
BytePtr = (uint8 *)MsgPtr;
HdrSize = CFE_SB_MsgHdrSize(MsgPtr);
return (BytePtr + HdrSize);
#endif
}/* end CFE_SB_GetUserData */
/******************************************************************************
** Function: CFE_SB_GetUserDataLength()
**
** Purpose:
** Get the length of the user data of a message (total size - hdrs).
**
** Assumptions, External Events, and Notes:
** Caller has already initialized the message header
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** Size of the message minus the headers
*/
uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
uint16 TotalMsgSize;
uint16 HdrSize;
TotalMsgSize = CFE_SB_GetTotalMsgLength(MsgPtr);
HdrSize = CFE_SB_MsgHdrSize(MsgPtr);
return (TotalMsgSize - HdrSize);
#endif
}/* end CFE_SB_GetUserDataLength */
/******************************************************************************
** Function: CFE_SB_SetUserDataLength()
**
** Purpose:
** Set the length field in the primary header.
** Given the user data length add the length of the secondary header.
**
** Assumptions, External Events, and Notes:
** Caller has already initialized the message header
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
** DataLength - Length of the user data
**
** Return:
** (none)
*/
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr, uint16 DataLength)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
uint32 TotalMsgSize, HdrSize;
HdrSize = CFE_SB_MsgHdrSize(MsgPtr);
TotalMsgSize = HdrSize + DataLength;
CCSDS_WR_LEN(MsgPtr->Hdr,TotalMsgSize);
#endif
}/* end CFE_SB_SetUserDataLength */
/******************************************************************************
** Function: CFE_SB_GetTotalMsgLength()
**
** Purpose:
** Get the total length of the message which includes the secondary header
** and the user data field.
** Does not include the Primary header.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** Total Length of the message
*/
uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
return CCSDS_RD_LEN(MsgPtr->Hdr);
#endif
}/* end CFE_SB_GetTotalMsgLength */
/******************************************************************************
** Function: CFE_SB_SetTotalMsgLength()
**
** Purpose:
** Set the length field, given the total length of the message.
** Includes both the secondary header and the user data field.
** Does not include the Primary header.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
** TotalLength - Total Length of the message
**
** Return:
** (none)
*/
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
CCSDS_WR_LEN(MsgPtr->Hdr,TotalLength);
#endif
}/* end CFE_SB_SetTotalMsgLength */
/******************************************************************************
** Function: CFE_SB_GetMsgTime()
**
** Purpose:
** Get the time field from a message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** Time field from message or
** Time value of zero for msgs that do not have a Time field in header
*/
CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr)
{
CFE_TIME_SysTime_t TimeFromMsg;
uint32 LocalSecs32 = 0;
uint32 LocalSubs32 = 0;
#ifdef MESSAGE_FORMAT_IS_CCSDS
#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS)
uint16 LocalSubs16;
#endif
CFE_SB_TlmHdr_t *TlmHdrPtr;
/* if msg type is a command or msg has no secondary hdr, time = 0 */
if ((CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_CMD) && (CCSDS_RD_SHDR(MsgPtr->Hdr) != 0)) {
/* copy time data to/from packets to eliminate alignment issues */
TlmHdrPtr = (CFE_SB_TlmHdr_t *)MsgPtr;
#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS)
memcpy(&LocalSecs32, &TlmHdrPtr->Sec.Time[0], 4);
memcpy(&LocalSubs16, &TlmHdrPtr->Sec.Time[4], 2);
/* convert packet data into CFE_TIME_SysTime_t format */
LocalSubs32 = ((uint32) LocalSubs16) << 16;
#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS)
memcpy(&LocalSecs32, &TlmHdrPtr->Sec.Time[0], 4);
memcpy(&LocalSubs32, &TlmHdrPtr->Sec.Time[4], 4);
/* no conversion necessary -- packet format = CFE_TIME_SysTime_t format */
#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20)
memcpy(&LocalSecs32, &TlmHdrPtr->Sec.Time[0], 4);
memcpy(&LocalSubs32, &TlmHdrPtr->Sec.Time[4], 4);
/* convert packet data into CFE_TIME_SysTime_t format */
LocalSubs32 = CFE_TIME_Micro2SubSecs((LocalSubs32 >> 12));
#endif
}
#endif
/* return the packet time converted to CFE_TIME_SysTime_t format */
TimeFromMsg.Seconds = LocalSecs32;
TimeFromMsg.Subseconds = LocalSubs32;
return TimeFromMsg;
}/* end CFE_SB_GetMsgTime */
/******************************************************************************
** Function: CFE_SB_SetMsgTime()
**
** Purpose:
** Set the time field from a message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
** NewTime - Time to write in message
**
** Return:
** CFE_SUCCESS for no errors
** CFE_SB_WRONG_MSG_TYPE if msg does not have a header field for time.
*/
int32 CFE_SB_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, CFE_TIME_SysTime_t NewTime)
{
int32 Result = CFE_SB_WRONG_MSG_TYPE;
#ifdef MESSAGE_FORMAT_IS_CCSDS
CFE_SB_TlmHdr_t *TlmHdrPtr;
/* declare format specific vars */
#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS)
uint16 LocalSubs16;
#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20)
uint32 LocalSubs32;
#endif
/* cannot set time if msg type is a command or msg has no secondary hdr */
if ((CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_CMD) && (CCSDS_RD_SHDR(MsgPtr->Hdr) != 0)) {
/* copy time data to/from packets to eliminate alignment issues */
TlmHdrPtr = (CFE_SB_TlmHdr_t *) MsgPtr;
#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS)
/* convert time from CFE_TIME_SysTime_t format to packet format */
LocalSubs16 = (uint16) (NewTime.Subseconds >> 16);
memcpy(&TlmHdrPtr->Sec.Time[0], &NewTime.Seconds, 4);
memcpy(&TlmHdrPtr->Sec.Time[4], &LocalSubs16, 2);
Result = CFE_SUCCESS;
#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS)
/* no conversion necessary -- packet format = CFE_TIME_SysTime_t format */
memcpy(&TlmHdrPtr->Sec.Time[0], &NewTime.Seconds, 4);
memcpy(&TlmHdrPtr->Sec.Time[4], &NewTime.Subseconds, 4);
Result = CFE_SUCCESS;
#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20)
/* convert time from CFE_TIME_SysTime_t format to packet format */
LocalSubs32 = CFE_TIME_Sub2MicroSecs(NewTime.Subseconds) << 12;
memcpy(&TlmHdrPtr->Sec.Time[0], &NewTime.Seconds, 4);
memcpy(&TlmHdrPtr->Sec.Time[4], &LocalSubs32, 4);
Result = CFE_SUCCESS;
#endif
}
#endif
return Result;
}/* end CFE_SB_SetMsgTime */
/******************************************************************************
** Function: CFE_SB_TimeStampMsg()
**
** Purpose:
** Set the time field to the current time.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** (none)
*/
void CFE_SB_TimeStampMsg(CFE_SB_MsgPtr_t MsgPtr)
{
CFE_SB_SetMsgTime(MsgPtr,CFE_TIME_GetTime());
}/* end CFE_SB_TimeStampMsg */
/******************************************************************************
** Function: CFE_SB_GetCmdCode()
**
** Purpose:
** Get the opcode field of message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** CmdCode from the message (CCSDS Function Code)
*/
uint16 CFE_SB_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
CFE_SB_CmdHdr_t *CmdHdrPtr;
/* if msg type is telemetry or there is no secondary hdr, return 0 */
if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){
return 0;
}/* end if */
/* Cast the input pointer to a Cmd Msg pointer */
CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr;
return CCSDS_RD_FC(CmdHdrPtr->Sec);
#endif
}/* end CFE_SB_GetCmdCode */
/******************************************************************************
** Function: CFE_SB_SetCmdCode()
**
** Purpose:
** Set the opcode field of message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
** CmdCode - Command code for the message (CCSDS Function Code)
**
** Return:
** (none)
*/
int32 CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr,
uint16 CmdCode)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
CFE_SB_CmdHdr_t *CmdHdrPtr;
/* if msg type is telemetry or there is no secondary hdr... */
if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){
return CFE_SB_WRONG_MSG_TYPE;
}/* end if */
/* Cast the input pointer to a Cmd Msg pointer */
CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr;
CCSDS_WR_FC(CmdHdrPtr->Sec,CmdCode);
return CFE_SUCCESS;
#endif
}/* end CFE_SB_SetCmdCode */
/******************************************************************************
** Function: CFE_SB_GetChecksum()
**
** Purpose:
** Get the checksum field of message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
**
*/
uint16 CFE_SB_GetChecksum(CFE_SB_MsgPtr_t MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
CFE_SB_CmdHdr_t *CmdHdrPtr;
/* if msg type is telemetry or there is no secondary hdr... */
if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){
return 0;
}/* end if */
/* cast the input pointer to a Cmd Msg pointer */
CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr;
return CCSDS_RD_CHECKSUM(CmdHdrPtr->Sec);
#endif
}/* end CFE_SB_GetChecksum */
/******************************************************************************
** Function: CFE_SB_GenerateChecksum()
**
** Purpose:
** Calculate and Set the checksum field of message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Note: If any header fields are changed after this call, the checksum will
** no longer be valid.
** Also, the packet length field dictates the number of iterations
** used in the checksum algorithm and therefore must be properly set
** before calling this function.
**
** Return:
** (none)
*/
void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
CCSDS_CommandPacket_t *CmdPktPtr;
/* if msg type is telemetry or there is no secondary hdr... */
if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){
return;
}/* end if */
CmdPktPtr = (CCSDS_CommandPacket_t *)MsgPtr;
CCSDS_LoadCheckSum(CmdPktPtr);
#endif
}/* end CFE_SB_GenerateChecksum */
/******************************************************************************
** Function: CFE_SB_ValidateChecksum()
**
** Purpose:
** Validate the checksum field of message.
**
** Arguments:
** MsgPtr - Pointer to a CFE_SB_Msg_t
**
** Return:
** true if checksum of packet is valid; false if not.
*/
bool CFE_SB_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr)
{
#ifdef MESSAGE_FORMAT_IS_CCSDS
CCSDS_CommandPacket_t *CmdPktPtr;
/* if msg type is telemetry or there is no secondary hdr... */
if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){
return false;
}/* end if */
CmdPktPtr = (CCSDS_CommandPacket_t *)MsgPtr;
return CCSDS_ValidCheckSum (CmdPktPtr);
#endif
}/* end CFE_SB_ValidateChecksum */
/******************************************************************************
** Function: CFE_SB_MessageStringGet()
**
** See function prototype for full description
**
** UNIT TESTING NOTE:
** During unit testing, the "stub" version of this function must
** also copy the string or all functions that depend on this will break.
**
** Therefore this function is essentially duplicated in the UT code
**
*/
int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr, const char *DefaultString, uint32 DestMaxSize, uint32 SourceMaxSize)
{
int32 Result;
/*
* Error in caller if DestMaxSize == 0.
* Cannot terminate the string, since there is no place for the NUL
* In this case, do nothing
*/
if (DestMaxSize == 0)
{
Result = CFE_SB_BAD_ARGUMENT;
}
else
{
Result = 0;
/*
* Check if should use the default, which is if
* the source string has zero length (first char is NUL).
*/
if (DefaultString != NULL && (SourceMaxSize == 0 || *SourceStringPtr == 0))
{
SourceStringPtr = DefaultString;
SourceMaxSize = DestMaxSize;
}
/* Reserve 1 character for the required NUL */
--DestMaxSize;
while (SourceMaxSize > 0 && *SourceStringPtr != 0 && DestMaxSize > 0)
{
*DestStringPtr = *SourceStringPtr;
++DestStringPtr;
++SourceStringPtr;
--SourceMaxSize;
--DestMaxSize;
++Result;
}
/* Put the NUL in the last character */
*DestStringPtr = 0;
}
return Result;
}
/******************************************************************************
** Function: CFE_SB_MessageStringSet()
**
** See function prototype for full description
**
** UNIT TESTING NOTE:
** During unit testing, the "stub" version of this function must
** also copy the string or all functions that depend on this will break.
**
** Therefore this function is essentially duplicated in the UT code
**
*/
int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr, uint32 DestMaxSize, uint32 SourceMaxSize)
{
int32 Result;
Result = 0;
while (SourceMaxSize > 0 && *SourceStringPtr != 0 && DestMaxSize > 0)
{
*DestStringPtr = *SourceStringPtr;
++DestStringPtr;
++SourceStringPtr;
++Result;
--DestMaxSize;
--SourceMaxSize;
}
/*
* Pad the remaining space with NUL chars,
* but this should NOT be included in the final size
*/
while (DestMaxSize > 0)
{
/* Put the NUL in the last character */
*DestStringPtr = 0;
++DestStringPtr;
--DestMaxSize;
}
return Result;
}