tldm-universe/Ardent/UV/gcidir/gci_malloc.c

96 lines
2.4 KiB
C
Raw Normal View History

2024-09-09 21:51:08 +00:00
/******************************************************************************
*
* GCI example .c file - mallocing space
*
* Module %M% Version %I% Date %H%
*
* (c) Copyright 1998 Ardent Software Inc. - All Rights Reserved
* This is unpublished proprietary source code of Ardent Software Inc.
* The copyright notice above does not evidence any actual or intended
* publication of such source code.
*
*******************************************************************************
*
* Maintenence log - insert most recent change descriptions at top
*
* Date.... GTAR# WHO Description.........................................
* 10/14/98 23801 SAP Change copyrights.
* 05/23/90 6933 DTW move include stuff
* 02/19/90 -- DTW New file
*
******************************************************************************/
#include <gci.h>
#define BUFSIZE 256
char ray[BUFSIZE];
/*
* Concatenate two strings together as a third string.
* malloc() the space for the third string.
* As if that weren't enough, copy the second argument into
* a buffer in reverse order.
* arguments: str1 char* first string to concatenate
* str2 char** second string to concatenate
* (and reverse)
* str3 char** resulting string from concatentation
* return: integer length of new string
* See the GCI manual for more information.
*/
int
gci_c4(str1, str2, str3)
char *str1;
char **str2;
char **str3;
{
int len = 0,
rc = 0;
char *ptr,
*ptr3;
/* malloc enough space for the concatenated string */
rc = len = strlen(str1) + strlen(*str2);
*str3 = malloc(len + 1);
/*
* set pointers to the string to be copied and the newly
* malloc'd space
*/
ptr = str1;
ptr3 = *str3;
/* copy string 1 into the malloc'd space pointed at by string 3 */
while (*ptr != 0)
*ptr3++ = *ptr++;
/* copy string 2 into the malloc'd space pointed at by string 3 */
ptr = *str2;
while (*ptr != 0)
*ptr3++ = *ptr++;
/* add a null terminator */
*ptr3++ = 0;
/*
* reverse string 2
*/
/* initialize pointers */
len = strlen(*str2);
ptr3 = *str2;
ptr = &ray[0];
/* null terminator for backwards string */
ray[len] = 0;
/* the first shall be last and the last shall be first */
len--;
while (len >= 0) {
*ptr++ = *(ptr3 + len);
len--;
}
*str2 = ray;
return(rc);
}