00001 /* 00002 Copyright (C) 2011 Computer Sciences Department, 00003 University of Wisconsin -- Madison 00004 00005 ---------------------------------------------------------------------- 00006 00007 This file is part of Mnemosyne: Lightweight Persistent Memory, 00008 originally developed at the University of Wisconsin -- Madison. 00009 00010 Mnemosyne was originally developed primarily by Haris Volos 00011 with contributions from Andres Jaan Tack. 00012 00013 ---------------------------------------------------------------------- 00014 00015 Mnemosyne is free software; you can redistribute it and/or 00016 modify it under the terms of the GNU General Public License 00017 as published by the Free Software Foundation, version 2 00018 of the License. 00019 00020 Mnemosyne is distributed in the hope that it will be useful, 00021 but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 GNU General Public License for more details. 00024 00025 You should have received a copy of the GNU General Public License 00026 along with this program; if not, write to the Free Software 00027 Foundation, Inc., 51 Franklin Street, Fifth Floor, 00028 Boston, MA 02110-1301, USA. 00029 00030 ### END HEADER ### 00031 */ 00032 00039 #include "files.h" 00040 #include <string.h> 00041 #include <sys/stat.h> 00042 00043 00044 void 00045 mkdir_r(const char *dir, mode_t mode) 00046 { 00047 char tmp[256]; 00048 char *p = NULL; 00049 size_t len; 00050 00051 snprintf(tmp, sizeof(tmp), "%s", dir); 00052 len = strlen(tmp); 00053 if(tmp[len - 1] == '/') { 00054 tmp[len - 1] = 0; 00055 for(p = tmp + 1; *p; p++) 00056 if(*p == '/') { 00057 *p = 0; 00058 mkdir(tmp, mode); 00059 *p = '/'; 00060 } 00061 } 00062 mkdir(tmp, mode); 00063 } 00064 00065 00066 m_result_t 00067 path2file(char *path, char **file) 00068 { 00069 int i; 00070 00071 for (i=strlen(path); i>=0; i--) { 00072 if (path[i] == '/') { 00073 *file = &path[i+1]; 00074 return M_R_SUCCESS; 00075 } 00076 } 00077 return M_R_FAILURE; 00078 }