root/lang/d/portingdemo/libunko/unko.c @ 7585

Revision 7585, 1.0 kB (checked in by itkz, 7 years ago)

yasui omosirosou but kao ga yabai http://www.moe-tokyo.net/

Line 
1
2
3#include <stdlib.h>
4#include <stddef.h>
5
6#include "unko.h"
7
8
9unko_t *create_unko() {
10        unko_t *unko;
11
12        unko = (unko_t*)malloc(sizeof(unko_t));
13        if (unko == NULL) {
14                return NULL;
15        }
16        unko->first = (int*)malloc(sizeof(int));
17        if (unko->first == NULL) {
18                free(unko);
19                return NULL;
20        }
21        *(unko->first) = 0;
22        unko->second = 1;
23        unko->third = 2;
24        unko->fourth = (int*)malloc(sizeof(int));
25        if (unko->fourth == NULL) {
26                free(unko->first);
27                free(unko);
28                return NULL;
29        }
30        *(unko->fourth) = 3;
31
32        return unko;
33}
34
35
36size_t get_offsetof_first(void) { return offsetof(unko_t, first); }
37size_t get_offsetof_second(void) { return offsetof(unko_t, second); }
38size_t get_offsetof_third(void) { return offsetof(unko_t, third); }
39size_t get_offsetof_fourth(void) { return offsetof(unko_t, fourth); }
40
41
42void delete_unko(unko_t *unko) {
43        if (unko->first != NULL) {
44                free(unko->first);
45        }
46        if (unko->fourth != NULL) {
47                free(unko->fourth);
48        }
49        free(unko);
50}
51
52
53long add_long_and_int(long a, int b) {
54        return a + b;
55}
56
Note: See TracBrowser for help on using the browser.