Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for getting DBC file base name on Windows. #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

blackboxembedded
Copy link

This changes dbcc_basename to work on Windows as well. I tested on UNIX and Windows with the change and both worked as expected.

@howerj
Copy link
Owner

howerj commented Aug 18, 2024

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.

@blackboxembedded
Copy link
Author

Sorry about that, I think I have the formatting fixed now.

@howerj
Copy link
Owner

howerj commented Aug 18, 2024

Won't this fail under Linux if there are any files with a backslash in them?

@blackboxembedded
Copy link
Author

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.

@howerj
Copy link
Owner

howerj commented Aug 18, 2024

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 == '/';
}

@blackboxembedded
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants