istereo2
diff src/respath.c @ 2:81d35769f546
added the tunnel effect source
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 19 Sep 2015 05:51:51 +0300 |
parents | |
children | 9d53a4938ce8 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/respath.c Sat Sep 19 05:51:51 2015 +0300 1.3 @@ -0,0 +1,109 @@ 1.4 +/* 1.5 +Stereoscopic tunnel for iOS. 1.6 +Copyright (C) 2011 John Tsiombikas <nuclear@member.fsf.org> 1.7 + 1.8 +This program is free software: you can redistribute it and/or modify 1.9 +it under the terms of the GNU General Public License as published by 1.10 +the Free Software Foundation, either version 3 of the License, or 1.11 +(at your option) any later version. 1.12 + 1.13 +This program is distributed in the hope that it will be useful, 1.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of 1.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.16 +GNU General Public License for more details. 1.17 + 1.18 +You should have received a copy of the GNU General Public License 1.19 +along with this program. If not, see <http://www.gnu.org/licenses/>. 1.20 +*/ 1.21 + 1.22 + 1.23 +#include <stdio.h> 1.24 +#include <stdlib.h> 1.25 +#include <string.h> 1.26 +#include <errno.h> 1.27 +#include <unistd.h> 1.28 +#include "respath.h" 1.29 +#include "config.h" 1.30 + 1.31 +#ifdef IPHONE 1.32 +#include <CoreFoundation/CoreFoundation.h> 1.33 +#endif 1.34 + 1.35 + 1.36 +#ifndef IPHONE 1.37 +struct path_node { 1.38 + char *path; 1.39 + struct path_node *next; 1.40 +}; 1.41 + 1.42 +static struct path_node *pathlist; 1.43 + 1.44 +void add_resource_path(const char *path) 1.45 +{ 1.46 + struct path_node *node = 0; 1.47 + 1.48 + if(!(node = malloc(sizeof *node)) || !(node->path = malloc(strlen(path) + 1))) { 1.49 + free(node); 1.50 + fprintf(stderr, "failed to add path: %s: %s\n", path, strerror(errno)); 1.51 + return; 1.52 + } 1.53 + strcpy(node->path, path); 1.54 + node->next = pathlist; 1.55 + pathlist = node; 1.56 +} 1.57 + 1.58 +char *find_resource(const char *fname, char *path, size_t sz) 1.59 +{ 1.60 + static char buffer[1024]; 1.61 + struct path_node *node; 1.62 + 1.63 + if(!path) { 1.64 + path = buffer; 1.65 + sz = sizeof buffer; 1.66 + } 1.67 + 1.68 + node = pathlist; 1.69 + while(node) { 1.70 + snprintf(path, sz, "%s/%s", node->path, fname); 1.71 + if(access(path, F_OK) != -1) { 1.72 + return path; 1.73 + } 1.74 + node = node->next; 1.75 + } 1.76 + 1.77 + fprintf(stderr, "can't find resource: %s\n", fname); 1.78 + return 0; 1.79 +} 1.80 + 1.81 +#else /* IPHONE */ 1.82 + 1.83 +void add_resource_path(const char *path) 1.84 +{ 1.85 +} 1.86 + 1.87 + 1.88 +char *find_resource(const char *fname, char *path, size_t sz) 1.89 +{ 1.90 + static char buffer[1024]; 1.91 + CFBundleRef bundle; 1.92 + CFURLRef url; 1.93 + CFStringRef cfname; 1.94 + 1.95 + cfname = CFStringCreateWithCString(0, fname, kCFStringEncodingASCII); 1.96 + 1.97 + bundle = CFBundleGetMainBundle(); 1.98 + if(!(url = CFBundleCopyResourceURL(bundle, cfname, 0, 0))) { 1.99 + return 0; 1.100 + } 1.101 + 1.102 + if(!path) { 1.103 + path = buffer; 1.104 + sz = sizeof buffer; 1.105 + } 1.106 + 1.107 + if(!CFURLGetFileSystemRepresentation(url, 1, (unsigned char*)path, sz)) { 1.108 + return 0; 1.109 + } 1.110 + return path; 1.111 +} 1.112 +#endif