1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus-ui-console - osal_files_unix.c *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2009 Richard Goedeken *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 /* This implements all kinds of system-dependent file handling
29 #include <sys/types.h>
30 #include <dirent.h> // for opendir(), readdir(), closedir()
33 #include "m64p_types.h"
34 #include "osal_preproc.h"
35 #include "osal_files.h"
37 /* definitions for system directories to search when looking for mupen64plus plugins */
38 #if defined(PLUGINDIR)
39 const int osal_libsearchdirs = 4;
40 const char *osal_libsearchpath[4] = { PLUGINDIR, "/usr/local/lib/mupen64plus", "/usr/lib/mupen64plus", "./" };
42 const int osal_libsearchdirs = 3;
43 const char *osal_libsearchpath[3] = { "/usr/local/lib/mupen64plus", "/usr/lib/mupen64plus", "./" };
46 osal_lib_search *osal_library_search(const char *searchpath)
48 osal_lib_search *head = NULL, *curr = NULL;
53 const char* suffix = ".dylib";
55 const char* suffix = ".so";
58 dir = opendir(searchpath);
62 /* look for any shared libraries in this folder */
63 while ((entry = readdir(dir)) != NULL)
65 osal_lib_search *newlib = NULL;
66 if (strcmp(entry->d_name + strlen(entry->d_name) - strlen(suffix), suffix) != 0)
68 /* this is a .so file, so add it to the list */
69 newlib = malloc(sizeof(osal_lib_search));
72 DebugMessage(M64MSG_ERROR, "Memory allocation error in osal_library_search()!");
73 osal_free_lib_list(head);
86 /* set up the filepath and filename members */
87 strncpy(curr->filepath, searchpath, PATH_MAX-2);
88 curr->filepath[PATH_MAX-2] = 0;
89 if (curr->filepath[strlen(curr->filepath)-1] != '/')
90 strcat(curr->filepath, "/");
91 int pathlen = strlen(curr->filepath);
92 curr->filename = curr->filepath + pathlen;
93 strncat(curr->filepath, entry->d_name, PATH_MAX - pathlen - 1);
94 curr->filepath[PATH_MAX-1] = 0;
95 /* set plugin_type and next pointer */
96 curr->plugin_type = 0;
104 void osal_free_lib_list(osal_lib_search *head)
108 osal_lib_search *next = head->next;