istereo2
view src/respath.c @ 15:7bd4264bf74a
gui done?
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 30 Sep 2015 04:41:21 +0300 |
parents | |
children | 9d53a4938ce8 |
line source
1 /*
2 Stereoscopic tunnel for iOS.
3 Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <unistd.h>
25 #include "respath.h"
26 #include "config.h"
28 #ifdef IPHONE
29 #include <CoreFoundation/CoreFoundation.h>
30 #endif
33 #ifndef IPHONE
34 struct path_node {
35 char *path;
36 struct path_node *next;
37 };
39 static struct path_node *pathlist;
41 void add_resource_path(const char *path)
42 {
43 struct path_node *node = 0;
45 if(!(node = malloc(sizeof *node)) || !(node->path = malloc(strlen(path) + 1))) {
46 free(node);
47 fprintf(stderr, "failed to add path: %s: %s\n", path, strerror(errno));
48 return;
49 }
50 strcpy(node->path, path);
51 node->next = pathlist;
52 pathlist = node;
53 }
55 char *find_resource(const char *fname, char *path, size_t sz)
56 {
57 static char buffer[1024];
58 struct path_node *node;
60 if(!path) {
61 path = buffer;
62 sz = sizeof buffer;
63 }
65 node = pathlist;
66 while(node) {
67 snprintf(path, sz, "%s/%s", node->path, fname);
68 if(access(path, F_OK) != -1) {
69 return path;
70 }
71 node = node->next;
72 }
74 fprintf(stderr, "can't find resource: %s\n", fname);
75 return 0;
76 }
78 #else /* IPHONE */
80 void add_resource_path(const char *path)
81 {
82 }
85 char *find_resource(const char *fname, char *path, size_t sz)
86 {
87 static char buffer[1024];
88 CFBundleRef bundle;
89 CFURLRef url;
90 CFStringRef cfname;
92 cfname = CFStringCreateWithCString(0, fname, kCFStringEncodingASCII);
94 bundle = CFBundleGetMainBundle();
95 if(!(url = CFBundleCopyResourceURL(bundle, cfname, 0, 0))) {
96 return 0;
97 }
99 if(!path) {
100 path = buffer;
101 sz = sizeof buffer;
102 }
104 if(!CFURLGetFileSystemRepresentation(url, 1, (unsigned char*)path, sz)) {
105 return 0;
106 }
107 return path;
108 }
109 #endif