tizen 2.0beta
[apps/native/ug-wifi-direct.git] / popup-wifidirect / src / wfd-app-util.c
1 /*
2 *  WiFi-Direct UG
3 *
4 * Copyright 2012  Samsung Electronics Co., Ltd
5
6 * Licensed under the Flora License, Version 1.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9
10 * http://www.tizenopensource.org/license
11
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 */
19
20 /**
21  * This file implements wifi direct application utils functions.
22  *
23  * @file    wfd-app-util.c
24  * @author  Sungsik Jang (sungsik.jang@samsung.com)
25  * @version 0.1
26  */
27
28
29 #include <stdio.h>
30 #include <string.h>
31 #include "wfd-app-util.h"
32
33
34 char *wfd_app_trim_path(const char *filewithpath)
35 {
36 #if 0
37     char *filename = NULL;
38     if ((filename = strrchr(filewithpath, '/')) == NULL)
39         return (char *) filewithpath;
40     else
41         return (filename + 1);
42 #else
43     static char *filename[100];
44     char *strptr = NULL;
45     int start = 0;
46     const char *space = "                                        ";
47     int len = strlen(filewithpath);
48
49     if (len > 20)
50     {
51         strptr = (char *) filewithpath + (len - 20);
52         start = 0;
53     }
54     else if (len < 20)
55     {
56         strptr = (char *) filewithpath;
57         start = 20 - len;
58     }
59     strncpy((char *) filename, space, strlen(space));
60     strncpy((char *) filename + start, strptr, 50);
61
62     return (char *) filename;
63 #endif
64 }
65
66
67 int wfd_app_gettid()
68 {
69 #ifdef __NR_gettid
70     return syscall(__NR_gettid);
71 #else
72     fprintf(stderr,
73             "__NR_gettid is not defined, please include linux/unistd.h ");
74     return -1;
75 #endif
76 }