Add _cdio_strdup_fixpath for absolute paths handling in MinGW

* MinGW may provide absolute paths in the form /c/directory/...
  to native calls that require instead c:/directory
This commit is contained in:
Pete Batard
2012-03-05 15:32:35 +00:00
parent 35aa0c7dec
commit e6b00d7dcf
5 changed files with 61 additions and 10 deletions

View File

@@ -38,6 +38,8 @@
#include "inttypes.h"
#endif
#include <ctype.h>
#include "cdio_assert.h"
#include <cdio/types.h>
#include <cdio/util.h>
@@ -136,6 +138,29 @@ _cdio_strdup_upper (const char str[])
return new_str;
}
/* Convert MinGW/MSYS paths that start in "/c/..." to "c:/..."
so that they can be used with fopen(), stat(), etc. */
char *
_cdio_strdup_fixpath (const char path[])
{
char *new_path = NULL;
if (path)
{
new_path = strdup (path);
#if defined(_WIN32)
if (new_path && (strlen (new_path) >= 3) && (new_path[0] == '/') &&
(new_path[2] == '/') && (isalpha (new_path[1])))
{
new_path[0] = new_path[1];
new_path[1] = ':';
}
#endif
}
return new_path;
}
uint8_t
cdio_to_bcd8 (uint8_t n)
{