8000 The very begining · postgrespro/libblobstamper@987cf19 · GitHub
[go: up one dir, main page]

Skip to content

Commit 987cf19

Browse files
The very begining
1 parent f66a1c6 commit 987cf19

File tree

2 files changed

+130
-0
lines changed

2 files changed

+130
-0
lines changed

Makefile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#DEPS = function.h
2+
#LIB_OBJS = function.o
3+
4+
# https://stackoverflow.com/questions/18007326/how-to-change-default-values-of-variables-like-cc-in-makefile
5+
ifeq ($(origin CC),default)
6+
CC = gcc
7+
endif
8+
9+
.PHONY: all
10+
all: test
11+
@echo All done!
12+
13+
14+
test: $(LIB_OBJS) test.o
15+
$(CC) $(LDFLAGS) $^ -o $@ $(LDLIBS)
16+
17+
%.o: %.cpp $(DEPS)
18+
$(CC) $(CFLAGS) $<
19+
20+
.PHONY: clean
21+
clean:
22+
rm -f *.o test
23+
@echo Clean done!

test.c

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#include <string.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
6+
7+
typedef struct wflMemCtx
8+
{
9+
//Nothing for now;
10+
}wflMemCtx ;
11+
12+
13+
wflMemCtx static_ctx;
14+
15+
wflMemCtx *
16+
wflCreateMemCtx()
17+
{
18+
return &static_ctx;
19+
}
20+
21+
22+
void
23+
wflDestroyMemCtx(wflMemCtx * mctx)
24+
{
25+
}
26+
27+
typedef struct wflBlobDsc
28+
{
29+
struct wflMemCtx * mctx;
30+
char * data;
31+
int begin;
32+
int end;
33+
}wflBlobDsc;
34+
35+
36+
void
37+
wflBlobDump(wflBlobDsc* blob)
38+
{
39+
int length = blob->end - blob->begin + 1 ;
40+
char * str = malloc(length +1 ); // second +1 is for \0
41+
// FIXME проверка null
42+
str[0]='\0';
43+
44+
45+
46+
strncat(str, blob->data + blob->begin, length); // second +1 is for \0
47+
48+
printf("%s\n",str);
49+
free(str);
50+
}
51+
52+
void*
53+
wflMalloc( size_t size )
54+
{
55+
/*just that simple for now*/
56+
return malloc( size );
57+
}
58+
59+
60+
wflBlobDsc*
61+
wflShiftN(wflBlobDsc* blob, size_t n)
62+
{
63+
wflBlobDsc* new_blob;
64+
// FIXME null check here;
65+
if (blob->begin + n > blob->end)
66+
return NULL; /*not enough data*/
67+
68+
new_blob = wflMalloc(sizeof(wflBlobDsc));
69+
70+
new_blob->data = blob->data;
71+
new_blob->begin = blob->begin;
72+
new_blob->end = blob->begin + n - 1;
73+
74+
blob->begin += n;
75+
76+
return new_blob;
77+
}
78+
79+
80+
81+
char blob_data[]="aaalkjdhfs89345yu3ifhjew;lkhf4;lt;o34ithp;eriuwtgp;etup568p34tuewritwe;rtgj;ewoty;4w85tyeihwritgzzz";
82+
83+
int main()
84+
{
85+
wflMemCtx * mctx;
86+
wflBlobDsc blob;
87+
wflBlobDsc * b2;
88+
89+
mctx = wflCreateMemCtx();
90+
91+
blob.mctx = mctx;
92+
blob.data = blob_data;
93+
blob.begin = 0;
94+
blob.end = strlen(blob_data)-1;
95+
96+
97+
98+
wflBlobDump(&blob);
99+
printf("-----\n");
100+
b2 = wflShiftN(&blob,9993);
101+
102+
103+
wflBlobDump(&blob);
104+
wflBlobDump(b2);
105+
106+
wflDestroyMemCtx(mctx);
107+
}

0 commit comments

Comments
 (0)
0