-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmallc.c
147 lines (117 loc) · 2.25 KB
/
smallc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Creating Array
int *getArray(int size)
{
return malloc(sizeof(int) * size);
}
int *getArrayChar(int size)
{
fprintf(stderr, "Run create arr %s \n", "size");
fprintf(stderr, "Run create arr %d \n", size);
return malloc(sizeof(char) * size);
}
// Reading Array
int readPointerOffset(int offset, int *arr)
{
return arr[offset];
}
char readPointerOffsetChar(int offset, char *arr)
{
return arr[offset];
}
// Writing Array
void writeOffset(int offset, int *arr, int val)
{
arr[offset] = val;
}
void writeOffsetChar(int offset, char *arr, char val)
{
arr[offset] = val;
}
// Freeing Array
void freePointer(void *pt)
{
free(pt);
}
void freePointerChar(char *pt)
{
free(pt);
}
// Creating Any Pointers
void *createStruct(int size)
{
// fprintf(stderr, "%s", "Run create Struct\n", 30);
return malloc(size);
}
// Getting Data from Structs
int getIntStruct(unsigned char *ptr, int offset)
{
unsigned char *ptr2 = ptr + offset;
int *ptr3 = (int *)ptr2;
return (*ptr3);
}
char getCharStruct(unsigned char *ptr, int offset)
{
return (ptr[offset]);
}
void *getStructStruct(unsigned char *ptr, int offset)
{
return (void *)(ptr + offset);
}
// Writing to Structs
void writeIntStruct(unsigned char *ptr, int offset, int num)
{
// fprintf(stderr, "Writing %d to offset %d", num, offset, 30);
unsigned char *a = ptr + offset;
a[3] = (num >> 24) & 0xFF;
a[2] = (num >> 16) & 0xFF;
a[1] = (num >> 8) & 0xFF;
a[0] = num & 0xFF;
}
void writeCharStruct(unsigned char *ptr, int offset, char val)
{
// fprintf(stderr, "%s", "string format", 30);
ptr[offset] = val;
}
void writeStructStruct(unsigned char *ptr, int offset, unsigned char *ptr2, int size)
{
memcpy(ptr + offset, ptr2, size);
}
int *getPointer(void)
{
int *a = malloc(sizeof(int));
return a;
}
int readNumber(int *ptr)
{
return *ptr;
}
int testFunc(int (*ptr)(int))
{
return ptr(5);
}
int *writePointer(int *pt, int num)
{
*pt = num;
return pt;
}
int basicRead(int *ptr)
{
return *ptr;
}
int *g = NULL;
int *savePtr(int *ptr)
{
g = ptr;
return ptr;
}
int readGlobal(void)
{
return *g;
}
int *readPointer(void)
{
return g;
}