On Saturday, January 08, 2011 00:57:14 Garrett Cooper wrote:
> On Jan 7, 2011, at 11:08 AM, Garrett Cooper wrote:
> > On Jan 7, 2011, at 6:36 AM, Cyril Hrubis wrote:
> >> Hi!
> >>
> >>> Ok -- good to note for next time I guess. I fixed all of the
> >>> compilation errors so now people can report runtime issues. There are
> >>> a handful of them.
> >>
> >> I still could not compile the latest git. I've got a bunch of:
> >>
> >> pipe declared with warn_unused_result
> >> write declared with warn_unused_result
> >> read declared with warn_unused_result
> >
> > Now you know why I used void casts in a few spots :). Some are of value,
> > some are fud.
>
> This has me thinking. Given that the patterns are basically the same,
> I'm
> planning on writing some macros to add to include (say, safe_calls.h? I'm
> not sold on the name, but if you have a better one I'm all ears :)..),
> like the following:
>
> #define SAFE_WRITE(fildes, buf, nbyte, cleanup_fn) ({ \
> int __rval = write((fildes), (buf), (nbyte)); \
> if (__rval == -1) \
> tst_brkm(TBROK|TERRNO, (cleanup_fn), "write failed at
> %s:%d", __FILE__, __LINE__); \ __rval; \
> })
safe_write() is an OK name and ive seen people use it before.
note that write() actually returns a ssize_t, and you should compare it to the
requested write length.
#define SAFE_WRITE(fd, buf, cnt, cleanup) \
({ \
ssize_t __cnt = (cnt); \
ssize_t __ret = write((fd), (buf), __cnt); \
if (__ret != __cnt) \
tst_brkm(TBROK|TERRNO, (cleanup_fn), "%s:%s:%i write failed", \
__FILE__, __func__, __LINE__); \
__ret; \
})
> wish I could get the non-gcc inline extension to work (do-while(0)), but
> that seems to be failing me right now :(..:
the only way to return a value via a macro like this is with the gcc extension
({ ... }). if you want to support other compilers, then your only realistic
option is to do a proper external function.
although perhaps that isnt a bad idea ... it'd reinforce the libltp
requirement and avoid tripping up people who dont get all the nuances of
writing safe macros.
-mike
signature.asc
Description: This is a digitally signed message part.
------------------------------------------------------------------------------ Gaining the trust of online customers is vital for the success of any company that requires sensitive data to be transmitted over the Web. Learn how to best implement a security strategy that keeps consumers' information secure and instills the confidence they need to proceed with transactions. http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________ Ltp-list mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/ltp-list
