2 * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
14 #include <openssl/crypto.h>
20 static void exnew(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp)
24 assert(argl == sargl);
25 assert(argp == sargp);
28 static int exdup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from,
29 void *from_d, int idx, long argl, void *argp)
32 assert(argl == sargl);
33 assert(argp == sargp);
37 static void exfree(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
38 int idx, long argl, void *argp)
41 assert(argl == sargl);
42 assert(argp == sargp);
45 typedef struct myobj_st {
46 CRYPTO_EX_DATA ex_data;
50 static MYOBJ *MYOBJ_new()
53 MYOBJ *obj = OPENSSL_malloc(sizeof(*obj));
57 st = CRYPTO_new_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);
62 static void MYOBJ_sethello(MYOBJ *obj, char *cp)
66 st = CRYPTO_set_ex_data(&obj->ex_data, sidx, cp);
70 static char *MYOBJ_gethello(MYOBJ *obj)
72 return CRYPTO_get_ex_data(&obj->ex_data, sidx);
75 static void MYOBJ_free(MYOBJ *obj)
77 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_APP, obj, &obj->ex_data);
87 p = strdup("hello world");
90 sidx = CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_APP, sargl, sargp,
91 exnew, exdup, exfree);
94 MYOBJ_sethello(t1, p);
95 cp = MYOBJ_gethello(t1);
97 cp = MYOBJ_gethello(t2);