OSDN Git Service

I was library can be compiled 20140223
[zither/ds-zither.git] / libms / count_memcpy2.c
1 // count_memcpy2.c
2 // masashi shimakura 20140223
3
4 #include<stdio.h>
5 #include<string.h>
6 #include<stdlib.h>
7 #include "libms.h"
8
9 /* ----------- COUNT MEMCPY2 ------------- */
10 char * count_memcpy2(char * out, char * data, int start, int plus)
11 {
12 int stop, max, count, co;
13 char * swap;
14 max = (int)strlen(data);
15
16 if(start < 0 || plus < 0 || max < 0){
17    out[0] = (char)0x00;
18    return(out);
19    }
20
21 stop = start + plus;
22
23 if(max < stop){
24    out[0] = (char)0x00;
25    return(out);
26    }
27
28 swap = (char *)calloc(plus + 5, sizeof(char));
29
30 co = 0;
31 for(count = start; count <= stop; count ++){
32    swap[co] = data[count];
33    co++;
34    }
35
36 swap[co] = (char)0x00;
37
38 out = safe_memcpy(out, swap, BUF_MAX);
39
40 free(swap);
41
42 return(out);
43 }
44
45
46