views:

19

answers:

1

Based on sys/acct.h (V1, not V3) I need to gather some user usage statistics based on a parser that parser the acct file line by line. The parser will run and parse the entire file every N seconds and I need to gather user statistics accumulated since the last run (N seconds back). I'm not sure what will be the most appropriate way to do it based on the info provided by sys/acct.h.

Maybe something like this:

if ((ac_btime + ac_etime) < (current_time - N)) { gather; }

Also comp_t is said to be "floating-point value consisting of a 3-bit, base-8 exponent, and a 13-bit mantissa", but I think u_int16_t is just a unsigned short int. Should I be converting it to long it with the provided formula or not?

A: 

You need to mask out the exponent and shift the mantissa. The file you linked to shows how:

v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3);

You could cast something in this to a larger type to ensure that the compiler uses the size you want, but be careful not to do it to the wrong part or you'll get wrong results. It shouldn't be necessary, anyway, but it wouldn't hurt to try:

v = (c & 0x1fff) << (((c >> 13) & 0x7) * 3L);
nategoose