let's say I have a path like "shaders/vfxapps.ini" or "shaders\\vfxapps.ini" is there a standard way to extract just the directory part or will I need to write my own function for it?
let's say I have a path like "shaders/vfxapps.ini" or "shaders\\vfxapps.ini" is there a standard way to extract just the directory part or will I need to write my own function for it?
Is this in your own OS, or something we might be aware of?
basename(3) - Linux manual page
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
strtok() or write your own function using strtok() to split a more complex path.
Have a look at _splitpath:
_splitpath, _wsplitpath | Microsoft Docs
> _splitpath( path, NULL, path, NULL, NULL );
Yeah, pretty sure that having input and output being the same memory would be UB.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well the docs for dirname says it modifies path anyways, since _splitpath likely just loops through each character 1 by 1 it will probably set 0 before it checks the next character which would naturally result in the string breaking the intended way, perhaps it's even intended to be used that way, if you're on windows I welcome you to do a test run though, I somehow doubt the function changed it's method of execution since it's creation. Anyways I've got gospel to go to so adios for now.
We're talking about splitpath, and the docs say the input is declared const char *.
So yeah, whether it says so or not, overwriting your input with your output is a crap shoot.
Also, I've no interest in testing it.
Because no matter how many times the test 'works', the fact remains that what you propose is a dumb idea.
Enjoy your bug hunting.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
The guy says he's "got gospel to go to", so clearly reality is no impediment.
The whole problem with the world is that fools and fanatics are always so certain of themselves, but wiser people so full of doubts. - Bertrand Russell
You realise God is not only a reality but the reason we all exist right? You could think of God as the perfect quantum computer that has no pyhsical limitations, not a great comparison due to computers being inferior to God but you get the point right?
I never actually tested it, it's just a stop gap measure that in theory will work, I do have printf statements that output it's contents prior to usage so at the very least if it causes issues it will be spotted in the output (of which it would show up early since it's used to construct the relative paths of shader files, if they fail to load there won't be much output to check).
The code compiles and runs on VS2019 and GCC (tdm64-1) 9.2.0 on Windows 8.1.