Source code formating unification
[platform/framework/web/wrt.git] / src / wrt-launchpad-daemon / include / simple_util.h
1 /*
2  * Copyright (c) 2011 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
17 #ifndef __SIMPLE_UTIL__
18 #define __SIMPLE_UTIL__
19
20 #include <unistd.h>
21 #include <ctype.h>
22 #include <dlog.h>
23
24 #ifdef LAUNCHPAD_LOG
25 #undef LOG_TAG
26 #define LOG_TAG "AUL_PAD"
27 #else
28 #undef LOG_TAG
29 #define LOG_TAG "AUL"
30 #endif
31 #ifdef AMD_LOG
32 #undef LOG_TAG
33 #define LOG_TAG "AUL_AMD"
34 #endif
35
36 #define MAX_LOCAL_BUFSZ 128
37 #define MAX_PID_STR_BUFSZ 20
38
39 #define _E(fmt, arg ...) LOGE(fmt,##arg)
40 #define _D(fmt, arg ...) LOGD(fmt,##arg)
41
42 #define retvm_if(expr, val, fmt, arg ...) do { \
43         if (expr) { \
44             _E(fmt,##arg); \
45             _E("(%s) -> %s() return", #expr, __FUNCTION__); \
46             return (val); \
47         } \
48 } while (0)
49
50 #define retv_if(expr, val) do { \
51         if (expr) { \
52             _E("(%s) -> %s() return", #expr, __FUNCTION__); \
53             return (val); \
54         } \
55 } while (0)
56
57 int __proc_iter_cmdline(int (*iterfunc)
58                         (const char *dname, const char *cmdline, void *priv),
59                         void *priv);
60 int __proc_iter_pgid(int pgid, int (*iterfunc)(int pid, void *priv),
61                      void *priv);
62 char *__proc_get_cmdline_bypid(int pid);
63
64 static inline const char *FILENAME(const char *filename)
65 {
66     const char *p;
67     const char *r;
68
69     if (!filename) {
70         return NULL;
71     }
72
73     r = p = filename;
74     while (*p) {
75         if (*p == '/') {
76             r = p + 1;
77         }
78         p++;
79     }
80
81     return r;
82 }
83
84 #endif