OpenMAX Bellagio 0.9.3
common.c
Go to the documentation of this file.
1
26#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <errno.h>
30#include <sys/stat.h>
31
32#include "config.h"
33#include "common.h"
34
35#define REGISTRY_FILENAME ".omxregister"
36#define REGISTRY_DIR "/var/lib/libomxil-bellagio0/"
37
38#ifdef ANDROID_COMPILATION
39#define TMP_DATA_DIRECTORY "/data/omx/"
40#else
41#define TMP_DATA_DIRECTORY "/tmp/"
42#endif
43
49}
50
51char* componentsRegistryGetFilenameCheck(int check_exists) {
52 char *omxregistryfile = NULL;
53 char *buffer;
54 struct stat sb;
55
56 buffer=getenv("OMX_BELLAGIO_REGISTRY");
57 if(buffer!=NULL&&*buffer!='\0') {
58 omxregistryfile = strdup(buffer);
59 if (!check_exists||stat(omxregistryfile, &sb) == 0) {
60 return omxregistryfile;
61 } else {
62 if (omxregistryfile) {
63 free(omxregistryfile);
64 omxregistryfile=NULL;
65 }
66 }
67 return NULL;
68 }
69
70 buffer=getenv("XDG_DATA_HOME");
71 if(buffer!=NULL&&*buffer!='\0') {
72 omxregistryfile = malloc(strlen(buffer) + strlen(REGISTRY_FILENAME) + 2);
73 strcpy(omxregistryfile, buffer);
74 strcat(omxregistryfile, "/");
75 strcat(omxregistryfile, REGISTRY_FILENAME);
76 if (!check_exists||stat(omxregistryfile, &sb) == 0) {
77 return omxregistryfile;
78 } else {
79 if (omxregistryfile) {
80 free(omxregistryfile);
81 omxregistryfile=NULL;
82 }
83 }
84 }
85
86 buffer=getenv("HOME");
87 if(buffer!=NULL&&*buffer!='\0') {
88 omxregistryfile = malloc(strlen(buffer) + strlen(REGISTRY_FILENAME) + 3);
89 strcpy(omxregistryfile, buffer);
90 strcat(omxregistryfile, "/");
91 strcat(omxregistryfile, REGISTRY_FILENAME);
92 } else {
93 omxregistryfile = malloc(strlen(TMP_DATA_DIRECTORY) + strlen(REGISTRY_FILENAME) + 2);
94 strcpy(omxregistryfile, TMP_DATA_DIRECTORY);
95 strcat(omxregistryfile, REGISTRY_FILENAME);
96 }
97 if (!check_exists||stat(omxregistryfile, &sb) == 0) {
98 return omxregistryfile;
99 } else {
100 if (omxregistryfile) {
101 free(omxregistryfile);
102 omxregistryfile=NULL;
103 }
104 }
105 omxregistryfile = malloc(strlen(REGISTRY_DIR) + strlen("registry") + 2);
106 strcpy(omxregistryfile, REGISTRY_DIR);
107 strcat(omxregistryfile, "registry");
108 return omxregistryfile;
109}
110
111/* This function return the absolute path of the registry_name file or
112 * directory depending by the environment variable set.
113 * the variables considered in order are:
114 * $XDG_DATA_HOME
115 * $HOME
116 * TMP_DATA_DIRECTORY (/tmp by default on Linux)
117 * The function does not check for file/dir existence
118 */
119char* loadersRegistryGetFilename(char* registry_name) {
120 char *omxregistryfile = NULL;
121 char *buffer;
122
123 buffer=getenv("XDG_DATA_HOME");
124 if(buffer!=NULL&&*buffer!='\0') {
125 omxregistryfile = malloc(strlen(buffer) + strlen(registry_name) + 2);
126 strcpy(omxregistryfile, buffer);
127 strcat(omxregistryfile, "/");
128 strcat(omxregistryfile, registry_name);
129 return omxregistryfile;
130 }
131
132 buffer=getenv("HOME");
133 if(buffer!=NULL&&*buffer!='\0') {
134 omxregistryfile = malloc(strlen(buffer) + strlen(registry_name) + 3);
135 strcpy(omxregistryfile, buffer);
136 strcat(omxregistryfile, "/");
137 strcat(omxregistryfile, registry_name);
138 } else {
139 omxregistryfile = malloc(strlen(TMP_DATA_DIRECTORY) + strlen(registry_name) + 2);
140 strcpy(omxregistryfile, TMP_DATA_DIRECTORY);
141 strcat(omxregistryfile, registry_name);
142 }
143 return omxregistryfile;
144}
145
150int makedir (const char *newdir) {
151 char *buffer;
152 char *p;
153 int err;
154 size_t len;
155
156 buffer = strdup(newdir);
157 len = strlen(buffer);
158
159 if (len == 0) {
160 free(buffer);
161 return 1;
162 }
163 if (buffer[len-1] == '/') {
164 buffer[len-1] = '\0';
165 }
166
167 err = mkdir(buffer, 0755);
168 if (err == 0 || (( err == -1) && (errno == EEXIST))) {
169 free(buffer);
170 return 0;
171 }
172
173 p = buffer+1;
174 while (1) {
175 char hold;
176
177 while(*p && *p != '\\' && *p != '/')
178 p++;
179 hold = *p;
180 *p = 0;
181 if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT)) {
182 free(buffer);
183 return 1;
184 }
185 if (hold == 0)
186 break;
187 *p++ = hold;
188 }
189 free(buffer);
190 return 0;
191
192}
193
194int exists(const char* fname) {
195 FILE *file;
196 if ((file = fopen(fname, "r")))
197 {
198 fclose(file);
199 return 1;
200 }
201 return 0;
202}
203
204#ifdef COMMON_TEST
205int main (int argc, char*argv[]) {
207}
208#endif
209
#define REGISTRY_FILENAME
Definition: common.c:35
#define TMP_DATA_DIRECTORY
Definition: common.c:41
char * componentsRegistryGetFilename(void)
Get registry filename This function returns the name of the registry file for the components loaded w...
Definition: common.c:47
char * componentsRegistryGetFilenameCheck(int check_exists)
Definition: common.c:51
int exists(const char *fname)
Definition: common.c:194
#define REGISTRY_DIR
Definition: common.c:36
char * loadersRegistryGetFilename(char *registry_name)
Definition: common.c:119
int makedir(const char *newdir)
Definition: common.c:150
int main(int argc, char *argv[])
execution of registration function
Definition: omxregister.c:403
OMX_ERRORTYPE err

Generated for OpenMAX Bellagio rel. 0.9.3 by  doxygen 1.5.1
SourceForge.net Logo