Hi!
> > What should be done in this case is to create an equivalent to the
> > SAFE_FILE_PRINTF() function that is not calling the tst_brkm() and
> 
> 
> well, if create a new safe function/macro to replace use the SAFE_FILE_PRINTF
> but not calling tst_brkm(), that's will be break the safe rule.  
> if create a unsafe function/macro, I dont know where is to place the 
> new function and how to rename. 
> 
> Additional, i found so much testcases use safe macro in there cleanup(), 
> that's 
> really a hard work if maintain all.

The ideal solution would be to create a base functions file_scanf() and
file_printf() that would look like safe_file_scanf() and
safe_file_printf() but without the file, lineno and cleanup parameters.

These would return non-zero return value on failure and then we can base the
safe_file_scanf() on the top of these functions.

I.e. safe_file_scanf() would call file_scanf() and call tst_brkm() if
file_scanf() has reported a failure. Then we can use file_scanf() in test
cleanup. But as these functions use variable number of arguments this needs one
more indirection with functions that takes va_list.

int file_vscanf(const char *file, const char *fmt, va_list va)
{
        // do here what safe_file_scanf() does but return with error
        // instead of tst_brkm()
}

int file_scanf(const char *file, const char *fmt, ...)
{
        va_list va;

        va_start(va, fmt);
        ret = file_vscanf(file, fmt, va);
        va_end(va);

        return ret;
}

void safe_file_scanf(const char *file, const int lineno,
                     void (*cleanup_fn) (void),
                     const char *path, const char *fmt, ...)
{
        // call file_vscanf() here and switch on it's exit value
        // i.e. one for failed to open file
        //      one for EOF
        //      one for unexpected number of conversion
        //      and exit cleanly on zero
}

-- 
Cyril Hrubis
chru...@suse.cz

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to