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:
@@ -99,6 +99,12 @@ _cdio_memdup (const void *mem, size_t count);
|
|||||||
char *
|
char *
|
||||||
_cdio_strdup_upper (const char str[]);
|
_cdio_strdup_upper (const char str[]);
|
||||||
|
|
||||||
|
/* Duplicate path and make it platform compliant. Typically needed for
|
||||||
|
MinGW/MSYS where a "/c/..." path must be translated to "c:/..." for
|
||||||
|
use with fopen(), etc. Returned string must be freed by the caller. */
|
||||||
|
char *
|
||||||
|
_cdio_strdup_fixpath (const char path[]);
|
||||||
|
|
||||||
void
|
void
|
||||||
_cdio_strfreev(char **strv);
|
_cdio_strfreev(char **strv);
|
||||||
|
|
||||||
|
|||||||
@@ -225,17 +225,27 @@ cdio_stdio_new(const char pathname[])
|
|||||||
cdio_stream_io_functions funcs = { NULL, NULL, NULL, NULL, NULL, NULL };
|
cdio_stream_io_functions funcs = { NULL, NULL, NULL, NULL, NULL, NULL };
|
||||||
_UserData *ud = NULL;
|
_UserData *ud = NULL;
|
||||||
struct CDIO_STAT statbuf;
|
struct CDIO_STAT statbuf;
|
||||||
|
char* pathdup;
|
||||||
|
|
||||||
if (CDIO_STAT (pathname, &statbuf) == -1)
|
if (pathname == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
/* MinGW may require a translated path */
|
||||||
|
pathdup = _cdio_strdup_fixpath(pathname);
|
||||||
|
if (pathdup == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
if (CDIO_STAT (pathdup, &statbuf) == -1)
|
||||||
{
|
{
|
||||||
cdio_warn ("could not retrieve file info for `%s': %s",
|
cdio_warn ("could not retrieve file info for `%s': %s",
|
||||||
pathname, strerror (errno));
|
pathdup, strerror (errno));
|
||||||
|
free(pathdup);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ud = calloc (1, sizeof (_UserData));
|
ud = calloc (1, sizeof (_UserData));
|
||||||
|
|
||||||
ud->pathname = strdup(pathname);
|
ud->pathname = pathdup;
|
||||||
ud->st_size = statbuf.st_size; /* let's hope it doesn't change... */
|
ud->st_size = statbuf.st_size; /* let's hope it doesn't change... */
|
||||||
|
|
||||||
funcs.open = _stdio_open;
|
funcs.open = _stdio_open;
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
|
|||||||
unsigned int i_line=0; /* line number in file of psz_line. */
|
unsigned int i_line=0; /* line number in file of psz_line. */
|
||||||
int i = -1; /* Position in tocent. Same as
|
int i = -1; /* Position in tocent. Same as
|
||||||
cd->gen.i_tracks - 1 */
|
cd->gen.i_tracks - 1 */
|
||||||
char *psz_keyword, *psz_field;
|
char *psz_keyword, *psz_field, *psz_cue_name_dup;
|
||||||
cdio_log_level_t log_level = (NULL == cd) ? CDIO_LOG_INFO : CDIO_LOG_WARN;
|
cdio_log_level_t log_level = (NULL == cd) ? CDIO_LOG_INFO : CDIO_LOG_WARN;
|
||||||
cdtext_field_t cdtext_key;
|
cdtext_field_t cdtext_key;
|
||||||
|
|
||||||
@@ -262,7 +262,12 @@ parse_cuefile (_img_private_t *cd, const char *psz_cue_name)
|
|||||||
if (NULL == psz_cue_name)
|
if (NULL == psz_cue_name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fp = fopen (psz_cue_name, "r");
|
psz_cue_name_dup = _cdio_strdup_fixpath(psz_cue_name);
|
||||||
|
if (NULL == psz_cue_name_dup)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fp = fopen (psz_cue_name_dup, "r");
|
||||||
|
free(psz_cue_name_dup);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
cdio_log(log_level, "error opening %s for reading: %s",
|
cdio_log(log_level, "error opening %s for reading: %s",
|
||||||
psz_cue_name, strerror(errno));
|
psz_cue_name, strerror(errno));
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name)
|
|||||||
unsigned int i_line=0; /* line number in file of psz_line. */
|
unsigned int i_line=0; /* line number in file of psz_line. */
|
||||||
int i = -1; /* Position in tocent. Same as
|
int i = -1; /* Position in tocent. Same as
|
||||||
cd->gen.i_tracks - 1 */
|
cd->gen.i_tracks - 1 */
|
||||||
char *psz_keyword, *psz_field;
|
char *psz_keyword, *psz_field, *psz_cue_name_dup;
|
||||||
cdio_log_level_t log_level = (cd) ? CDIO_LOG_WARN : CDIO_LOG_INFO ;
|
cdio_log_level_t log_level = (cd) ? CDIO_LOG_WARN : CDIO_LOG_INFO ;
|
||||||
cdtext_field_t cdtext_key;
|
cdtext_field_t cdtext_key;
|
||||||
|
|
||||||
@@ -308,7 +308,12 @@ parse_tocfile (_img_private_t *cd, const char *psz_cue_name)
|
|||||||
if (NULL == psz_cue_name)
|
if (NULL == psz_cue_name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
fp = fopen (psz_cue_name, "r");
|
psz_cue_name_dup = _cdio_strdup_fixpath(psz_cue_name);
|
||||||
|
if (NULL == psz_cue_name_dup)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fp = fopen (psz_cue_name_dup, "r");
|
||||||
|
free(psz_cue_name_dup);
|
||||||
if (fp == NULL) {
|
if (fp == NULL) {
|
||||||
cdio_log(log_level, "error opening %s for reading: %s",
|
cdio_log(log_level, "error opening %s for reading: %s",
|
||||||
psz_cue_name, strerror(errno));
|
psz_cue_name, strerror(errno));
|
||||||
|
|||||||
@@ -38,6 +38,8 @@
|
|||||||
#include "inttypes.h"
|
#include "inttypes.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
|
|
||||||
#include "cdio_assert.h"
|
#include "cdio_assert.h"
|
||||||
#include <cdio/types.h>
|
#include <cdio/types.h>
|
||||||
#include <cdio/util.h>
|
#include <cdio/util.h>
|
||||||
@@ -136,6 +138,29 @@ _cdio_strdup_upper (const char str[])
|
|||||||
return new_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
|
uint8_t
|
||||||
cdio_to_bcd8 (uint8_t n)
|
cdio_to_bcd8 (uint8_t n)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user