Hi,

+void ulong2bebytes(u8 *buf, unsigned long x)
+{
+    buf[3] = (u8) (x % 256);
+    x /= 256;
+    buf[2] = (u8) (x % 256);
+    x /= 256;
+    buf[1] = (u8) (x % 256);
+    buf[0] = (u8) (x / 256);
+}


I would prefer

#define ULONG2BEBYTES(p, x)    do {\
    (p)[3] = (x) & 0xff;\
    (p)[2] = ((x) >> 8)  & 0xff;\
    (p)[1] = ((x) >> 16) & 0xff;\
    (p)[0] = ((x) >> 24) & 0xff;\
} while(0)

instead of defining function for this.

Macros might be somewhat more dangerous in this case,
e.g. someone calling ULONG2BEBYTES(buf++, 12345) ,
but it's fine for me to change it into a macro.

as this are ancillary functions they should be better placed in
an internal header file.

Okay, so in internal.h

Cheers,
Stef

_______________________________________________
opensc-devel mailing list
opensc-devel@lists.opensc-project.org
http://www.opensc-project.org/mailman/listinfo/opensc-devel

Reply via email to