1 // 2 // Copyright (c) 2017 The Khronos Group Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 #if defined(__MINGW32__) 17 18 #include "mingw_compat.h" 19 #include <stdio.h> 20 #include <string.h> 21 22 // This function is unavailable on various mingw compilers, 23 // especially 64 bit so implementing it here 24 const char *basename_dot = "."; basename(char * path)25char *basename(char *path) 26 { 27 char *p = path, *b = NULL; 28 int len = strlen(path); 29 30 if (path == NULL) 31 { 32 return (char *)basename_dot; 33 } 34 35 // Not absolute path on windows 36 if (path[1] != ':') 37 { 38 return path; 39 } 40 41 // Trim trailing path seperators 42 if (path[len - 1] == '\\' || path[len - 1] == '/') 43 { 44 len--; 45 path[len] = '\0'; 46 } 47 48 while (len) 49 { 50 while ((*p != '\\' || *p != '/') && len) 51 { 52 p++; 53 len--; 54 } 55 p++; 56 b = p; 57 } 58 59 return b; 60 } 61 62 #endif