Add tests for cynara-creds-gdbus
[platform/core/test/security-tests.git] / src / common / memory.h
1 /*
2  * Copyright (c) 2014-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 #ifndef MEMORY_H
17 #define MEMORY_H
18
19 #include <memory>
20 #include <sys/smack.h>
21 #include <dirent.h>
22 #include <glob.h>
23 #include <glib.h>
24
25 #define DEFINE_SMARTPTR(func, type, name) \
26     struct deleter_##func { \
27         void operator()(type* p) {\
28             func(p); \
29         } \
30     }; \
31      \
32     typedef std::unique_ptr<type, deleter_##func> name;
33
34 // Custom freeing functions
35
36 void closePtr(int *fd);
37
38 // Defining specializations of unique_ptr
39
40 DEFINE_SMARTPTR(free, char, CStringPtr);
41 DEFINE_SMARTPTR(g_free, gchar, GStringPtr);
42 DEFINE_SMARTPTR(closePtr, int, FdUniquePtr);
43 DEFINE_SMARTPTR(smack_accesses_free, smack_accesses, SmackAccessesPtr);
44 DEFINE_SMARTPTR(closedir, DIR, DirPtr);
45 DEFINE_SMARTPTR(globfree, glob_t, GlobPtr);
46
47 // Custom typedefs
48
49 typedef FdUniquePtr SockUniquePtr;
50 typedef CStringPtr SmackLabelPtr;
51 typedef CStringPtr CookieUniquePtr;
52
53 #endif // MEMORY_H