Fix for getting DBC file base name on Windows.
This changes dbcc_basename to work on Windows as well. I tested on UNIX and Windows with the change and both worked as expected.
Can you change back the formatting to how it was? I am aware the formatting for this function is different from the rest of the file as well, that's because it was taken from another project.
Sorry about that, I think I have the formatting fixed now.
Won't this fail under Linux if there are any files with a backslash in them?
I just tested and you are correct it does fail. The same is true the other way as well. I would guess the use of \ or / in a filename is uncommon. One option might make the behavior a compile time option if building on Windows.
I would have thought the code would work fine on Windows, as both "/" and "" are not allowed in file names. I'm loathe to put more compile time options and macros in this program, but it looks like there is no other choice.
Perhaps something like:
/* at the top of the file */
#ifdef _WIN32
#define WINDOWS (1)
#else
#define WINDOWS (0)
#endif
/* ~~~ code ~~~ */
/* near dbcc_basename */
static int is_path_sep(int ch) {
return WINDOWS ? ch == '\\' /* || ch == '/' ??? */: ch == '/';
}
Sorry for the delay, here is what I came up with. Something about is_path_sep(int ch) is causing a seg fault later in the app and I couldn't track it down.