Sign in to follow this  

vsscanf for windows

Recommended Posts

okay windows doesnt have an implementation fo vsscanf. what i want is a method to populate a va_list, but in not sure how all this va_ stuff works. ideally, i could set up the va_list to be the right size, then palm it off to sscanf could some one explain to me if this is possible, and how this va_ stuff works? cheers,

Share this post

Link to post
Share on other sites
va_list (on most systems) is just a pointer to the first argument's location on the stack.
One idea would be to form an new function call by copying the original list to the top of the stack, unfortunately finding out the size of the list is tricky (the only reliable solution would be to parse the format string yourself). A fixed length buffer is probably sufficient however.

An alternative solution would be to first make a of everything between the argument list's base address and the stack's head to a temporary location, and then move form a new stack frame right above the argument list for the sscanf call. And then restore everything afterwards.
Note that this won't work if another thread is accessing any intermidate data on the stack or if someone else is emulating variable argument lists by sending something that isn't on the stack.

It's impossible to write this kind of code in C of course, so you'll have to write a small assembly wrapper to handle things.

So it's not easy, fast or reliable. But not impossible either.
And scanf is generally a poor parsing function to begin so you should probably consider replacing anyway.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this