Fix coding rule violation
[platform/core/system/tizen-platform-config.git] / src / foreign.c
1 /*
2  * Copyright (C) 2013-2014 Intel Corporation.
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  * Authors:
19  *       José Bollo <jose.bollo@open.eurogiciel.org>
20  *       Stéphane Desneux <stephane.desneux@open.eurogiciel.org>
21  *       Jean-Benoit Martin <jean-benoit.martin@open.eurogiciel.org>
22  *
23  */
24 #define _GNU_SOURCE
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdlib.h>
31
32 #include "foreign.h"
33
34 enum fkey foreign(const char *name, size_t length)
35 {
36         if (length == 3) { /* UID */
37                 if (name[1] == 'I' && name[2] == 'D')
38                         switch (name[0]) {
39 #if _FOREIGN_HAS_(UID)
40                         case 'G': /* GID */ return GID;
41 #endif
42 #if _FOREIGN_HAS_(GID)
43                         case 'U': /* UID */ return UID;
44 #endif
45                         default: break;
46                         }
47         } else if (length == 4) {
48                 switch (name[0]) {
49 #if _FOREIGN_HAS_(HOME)
50                 case 'H': /* HOME */
51                         if (name[1] == 'O' && name[2] == 'M' && name[3] == 'E')
52                                 return HOME;
53                         break;
54 #endif
55 #if _FOREIGN_HAS_(EUID)
56                 case 'E': /* EUID */
57                         if (name[1] == 'U' && name[2] == 'I' && name[3] == 'D')
58                                 return EUID;
59                         break;
60 #endif
61 #if _FOREIGN_HAS_(USER)
62                 case 'U': /* USER */
63                         if (name[1] == 'S' && name[2] == 'E' && name[3] == 'R')
64                                 return USER;
65                         break;
66 #endif
67                 default: break;
68                 }
69         } else if (length == 5 && name[0] == 'E') {
70                 switch (name[1]) {
71 #if _FOREIGN_HAS_(EHOME)
72                 case 'H': /* EHOME */
73                         if (name[2] == 'O' && name[3] == 'M' && name[4] == 'E')
74                                 return EHOME;
75                         break;
76 #endif
77 #if _FOREIGN_HAS_(EUSER)
78                 case 'U': /* EUSER */
79                         if (name[2] == 'S' && name[3] == 'E' && name[4] == 'R')
80                                 return EUSER;
81                         break;
82 #endif
83                 default: break;
84                 }
85         }
86         return _FOREIGN_INVALID_;
87 }
88