mp-utils/src/common.h

44 lines
1.1 KiB
C

#include <iso646.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/stat.h>
/* arrconcat -- function to copy copy_n bytes from arr2 to arr1, starting at startpos (in arr1) */
void arrconcat(char* arr1, char* arr2, unsigned int startpos, unsigned int copy_n)
{
unsigned int i, i2;
for(i = startpos, i2 = 0; i <= copy_n && arr2 != NULL; i++, i2++)
{
arr1[i] = arr2[i2];
}
}
/* arrccat -- function to copy arr2len bytes from arr2 to the arr1len'th position of arr1. returns *newarr, and stores the length */
/* of newarr[] in arr1len (that's why it needs to be a pointer to arr1len and not just a long unsigned integer). */
char *arrccat(char *arr1, char *arr2, size_t *arr1len, size_t arr2len)
{
char *newarr;
unsigned int i, i2;
newarr = malloc(*arr1len+arr2len);
i = i2 = 0;
for(i = 0; i < *arr1len; i++)
{
newarr[i] = arr1[i];
}
for(i2 = 0; i2 < arr2len; i2++, i++)
{
newarr[i] = arr2[i2];
}
*arr1len = *arr1len+arr2len;
return newarr;
}