OpenMAXBellagio  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 
37 #ifdef ANDROID_COMPILATION
38 #define TMP_DATA_DIRECTORY "/data/omx/"
39 #else
40 #define TMP_DATA_DIRECTORY "/tmp/"
41 #endif
42 
47  char *omxregistryfile = NULL;
48  char *buffer;
49 
50  buffer=getenv("OMX_BELLAGIO_REGISTRY");
51  if(buffer!=NULL&&*buffer!='\0') {
52  omxregistryfile = strdup(buffer);
53  return omxregistryfile;
54  }
55 
56  buffer=getenv("XDG_DATA_HOME");
57  if(buffer!=NULL&&*buffer!='\0') {
58  omxregistryfile = malloc(strlen(buffer) + strlen(REGISTRY_FILENAME) + 2);
59  strcpy(omxregistryfile, buffer);
60  strcat(omxregistryfile, "/");
61  strcat(omxregistryfile, REGISTRY_FILENAME);
62  return omxregistryfile;
63  }
64 
65  buffer=getenv("HOME");
66  if(buffer!=NULL&&*buffer!='\0') {
67  omxregistryfile = malloc(strlen(buffer) + strlen(REGISTRY_FILENAME) + 3);
68  strcpy(omxregistryfile, buffer);
69  strcat(omxregistryfile, "/");
70  strcat(omxregistryfile, REGISTRY_FILENAME);
71  } else {
72  omxregistryfile = malloc(strlen(TMP_DATA_DIRECTORY) + strlen(REGISTRY_FILENAME) + 2);
73  strcpy(omxregistryfile, TMP_DATA_DIRECTORY);
74  strcat(omxregistryfile, REGISTRY_FILENAME);
75  }
76  return omxregistryfile;
77 }
78 
79 /* This function return the absolute path of the registry_name file or
80  * directory depending by the environment variable set.
81  * the variables considered in order are:
82  * $XDG_DATA_HOME
83  * $HOME
84  * TMP_DATA_DIRECTORY (/tmp by default on Linux)
85  * The function does not check for file/dir existence
86  */
87 char* loadersRegistryGetFilename(char* registry_name) {
88  char *omxregistryfile = NULL;
89  char *buffer;
90 
91  buffer=getenv("XDG_DATA_HOME");
92  if(buffer!=NULL&&*buffer!='\0') {
93  omxregistryfile = malloc(strlen(buffer) + strlen(registry_name) + 2);
94  strcpy(omxregistryfile, buffer);
95  strcat(omxregistryfile, "/");
96  strcat(omxregistryfile, registry_name);
97  return omxregistryfile;
98  }
99 
100  buffer=getenv("HOME");
101  if(buffer!=NULL&&*buffer!='\0') {
102  omxregistryfile = malloc(strlen(buffer) + strlen(registry_name) + 3);
103  strcpy(omxregistryfile, buffer);
104  strcat(omxregistryfile, "/");
105  strcat(omxregistryfile, registry_name);
106  } else {
107  omxregistryfile = malloc(strlen(TMP_DATA_DIRECTORY) + strlen(registry_name) + 2);
108  strcpy(omxregistryfile, TMP_DATA_DIRECTORY);
109  strcat(omxregistryfile, registry_name);
110  }
111  return omxregistryfile;
112 }
113 
118 int makedir (const char *newdir) {
119  char *buffer;
120  char *p;
121  int err;
122  size_t len;
123 
124  buffer = strdup(newdir);
125  len = strlen(buffer);
126 
127  if (len == 0) {
128  free(buffer);
129  return 1;
130  }
131  if (buffer[len-1] == '/') {
132  buffer[len-1] = '\0';
133  }
134 
135  err = mkdir(buffer, 0755);
136  if (err == 0 || (( err == -1) && (errno == EEXIST))) {
137  free(buffer);
138  return 0;
139  }
140 
141  p = buffer+1;
142  while (1) {
143  char hold;
144 
145  while(*p && *p != '\\' && *p != '/')
146  p++;
147  hold = *p;
148  *p = 0;
149  if ((mkdir(buffer, 0755) == -1) && (errno == ENOENT)) {
150  free(buffer);
151  return 1;
152  }
153  if (hold == 0)
154  break;
155  *p++ = hold;
156  }
157  free(buffer);
158  return 0;
159 
160 }
161 
162 int exists(const char* fname) {
163  FILE *file;
164  if ((file = fopen(fname, "r")))
165  {
166  fclose(file);
167  return 1;
168  }
169  return 0;
170 }
171 
172 #ifdef COMMON_TEST
173 int main (int argc, char*argv[]) {
174  printf (componentsRegistryGetFilename ());
175 }
176 #endif
177 
main
int main(int argc, char *argv[])
execution of registration function
Definition: omxregister.c:410
TMP_DATA_DIRECTORY
#define TMP_DATA_DIRECTORY
Definition: common.c:40
REGISTRY_FILENAME
#define REGISTRY_FILENAME
Definition: common.c:35
exists
int exists(const char *fname)
Definition: common.c:162
err
OMX_ERRORTYPE err
Definition: omxvolcontroltest.c:34
common.h
loadersRegistryGetFilename
char * loadersRegistryGetFilename(char *registry_name)
Definition: common.c:87
config.h
componentsRegistryGetFilename
char * componentsRegistryGetFilename()
Get registry filename This function returns the name of the registry file for the components loaded w...
Definition: common.c:46
makedir
int makedir(const char *newdir)
Definition: common.c:118

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