| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- /*******************************************************************************
- * Copyright (c) 2019, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
- /** @file
- * @brief Implements functions to operate on CIP string types
- *
- * Some functions to create CIP string types from C strings or data buffers.
- */
- #include "cipstring.h"
- #include <stdlib.h>
- #include <string.h>
- #include "opener_api.h"
- CipString *SetCipStringByData
- (
- CipString *p_cip_string,
- size_t str_len,
- const EipUint8 *p_data
- )
- {
- CipString *p_result = p_cip_string;
- if (NULL != p_cip_string->string) {
- CipFree(p_cip_string->string);
- p_cip_string->string = NULL;
- p_cip_string->length = 0;
- }
- if (str_len) {
- /* Allocate & clear +1 bytes for the trailing '\0' character. */
- p_cip_string->string = CipCalloc(str_len+1, sizeof (EipUint8));
- if (NULL == p_cip_string->string) {
- p_result = NULL;
- }
- else {
- p_cip_string->length = str_len;
- memcpy(p_cip_string->string, p_data, str_len);
- }
- }
- return p_result;
- }
- CipString *SetCipStringByCstr
- (
- CipString *p_cip_string,
- const char *p_string
- )
- {
- return SetCipStringByData(p_cip_string, strlen(p_string),
- (const EipByte *)p_string);
- }
- CipShortString *SetCipShortStringByData
- (
- CipShortString *p_cip_string,
- size_t str_len,
- const EipUint8 *p_data
- )
- {
- CipShortString *p_result = p_cip_string;
- if (NULL != p_cip_string->string) {
- CipFree(p_cip_string->string);
- p_cip_string->string = NULL;
- p_cip_string->length = 0;
- }
- if (str_len) {
- /* Allocate & clear +1 bytes for the trailing '\0' character. */
- p_cip_string->string = CipCalloc(str_len+1, sizeof (EipUint8));
- if (NULL == p_cip_string->string) {
- p_result = NULL;
- }
- else {
- p_cip_string->length = str_len;
- memcpy(p_cip_string->string, p_data, str_len);
- }
- }
- return p_result;
- }
- CipShortString *SetCipShortStringByCstr
- (
- CipShortString *p_cip_string,
- const char *p_string
- )
- {
- return SetCipShortStringByData(p_cip_string, strlen(p_string),
- (const EipByte *)p_string);
- }
|