1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus-core - 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 file contains the definitions for the unix-specific file handling
26 #include <sys/types.h>
34 #include "osal_files.h"
36 /* global functions */
38 int osal_is_directory(const char* name)
50 int osal_mkdirp(const char *dirpath, int mode)
53 int dirpathlen = strlen(dirpath);
54 char *currpath = strdup(dirpath);
56 /* first, break the path into pieces by replacing all of the slashes wil NULL chars */
57 while (strlen(currpath) > 1)
59 char *lastslash = strrchr(currpath, '/');
60 if (lastslash == NULL)
65 /* then re-assemble the path from left to right until we get to a directory that doesn't exist */
66 while (strlen(currpath) < dirpathlen)
68 if (strlen(currpath) > 0 && stat(currpath, &fileinfo) != 0)
70 currpath[strlen(currpath)] = '/';
73 /* then walk up the path chain, creating directories along the way */
76 if (stat(currpath, &fileinfo) != 0)
78 if (mkdir(currpath, mode) != 0)
81 return 1; /* mkdir failed */
84 if (strlen(currpath) == dirpathlen)
87 currpath[strlen(currpath)] = '/';
94 void * osal_search_dir_open(const char *pathname)
97 dir = opendir(pathname);
101 const char *osal_search_dir_read_next(void * dir_handle)
103 DIR *dir = (DIR *) dir_handle;
104 struct dirent *entry;
106 entry = readdir(dir);
109 return entry->d_name;
112 void osal_search_dir_close(void * dir_handle)
114 closedir((DIR *) dir_handle);