Rename /tests to /ckm to align with tizen branch
[platform/core/test/security-tests.git] / src / common / memory.h
1 #ifndef MEMORY_H
2 #define MEMORY_H
3
4 #include <memory>
5 #include <sys/smack.h>
6 #include <dirent.h>
7 #include <glob.h>
8
9 #define DEFINE_SMARTPTR(func, type, name) \
10     struct deleter_##func { \
11         void operator()(type* p) {\
12             func(p); \
13         } \
14     }; \
15      \
16     typedef std::unique_ptr<type, deleter_##func> name;
17
18 // Custom freeing functions
19
20 void closePtr(int *fd);
21
22 // Defining specializations of unique_ptr
23
24 DEFINE_SMARTPTR(free, char, CStringPtr);
25 DEFINE_SMARTPTR(closePtr, int, FdUniquePtr);
26 DEFINE_SMARTPTR(smack_accesses_free, smack_accesses, SmackAccessesPtr);
27 DEFINE_SMARTPTR(closedir, DIR, DirPtr);
28 DEFINE_SMARTPTR(globfree, glob_t, GlobPtr);
29
30 // Custom typedefs
31
32 typedef FdUniquePtr SockUniquePtr;
33 typedef CStringPtr SmackLabelPtr;
34 typedef CStringPtr CookieUniquePtr;
35
36 #endif // MEMORY_H