G_fatal_error()'s from G_system()

Has anyone tried to capture errors from G_system/G_fatal_error?
The following seems to function appropriately:

#define ERRMASK 65280 /* 256+512+1024+2048+4096+8192+16384+32768 */
if (((status = G_system(buf)) >> 8) & ERRMASK != 0)
{
  sprintf(buf, "s.sweep failed with a status of %d.", status);
  G_fatal_error(buf);
}

"buf" is a grass command that may terminate by a call to G_fatal_error().
I'm shifting the higher 8 bits, which supposedly contains the error,
and then masking off any remnants. i.e., if a prog returns 1 and there's
nothing "funny" in the lower order bits, then return status will be 256.

Does this seem appropriate?

--D