2 * Copyright 2001-2005, Haiku.
3 * Distributed under the terms of the MIT License.
6 * Erik Jaesler (erik@cgsoftware.com)
9 /** Extra messaging utility functions */
12 #include <ByteOrder.h>
14 #include <MessageUtils.h>
19 CalculateChecksum(const uint8
*buffer
, int32 size
)
25 #if defined(__INTEL__)
26 sum
+= B_SWAP_INT32(*(int32
*)buffer
);
28 sum
+= *(int32
*)buffer
;
35 temp
= (temp
<< 8) + *buffer
++;
43 /* entry_ref support functions */
45 entry_ref_flatten(char *buffer
, size_t *size
, const entry_ref
*ref
)
47 if (*size
< sizeof(ref
->device
) + sizeof(ref
->directory
))
48 return B_BUFFER_OVERFLOW
;
50 memcpy((void *)buffer
, (const void *)&ref
->device
, sizeof(ref
->device
));
51 buffer
+= sizeof(ref
->device
);
52 memcpy((void *)buffer
, (const void *)&ref
->directory
, sizeof(ref
->directory
));
53 buffer
+= sizeof (ref
->directory
);
54 *size
-= sizeof(ref
->device
) + sizeof(ref
->directory
);
56 size_t nameLength
= 0;
58 nameLength
= strlen(ref
->name
) + 1;
59 if (*size
< nameLength
)
60 return B_BUFFER_OVERFLOW
;
62 memcpy((void *)buffer
, (const void *)ref
->name
, nameLength
);
65 *size
= sizeof(ref
->device
) + sizeof(ref
->directory
) + nameLength
;
71 entry_ref_unflatten(entry_ref
*ref
, const char *buffer
, size_t size
)
73 if (size
< sizeof(ref
->device
) + sizeof(ref
->directory
)) {
78 memcpy((void *)&ref
->device
, (const void *)buffer
, sizeof(ref
->device
));
79 buffer
+= sizeof (ref
->device
);
80 memcpy((void *)&ref
->directory
, (const void *)buffer
, sizeof(ref
->directory
));
81 buffer
+= sizeof(ref
->directory
);
83 if (ref
->device
!= ~(dev_t
)0 && size
> sizeof(ref
->device
)
84 + sizeof(ref
->directory
)) {
85 ref
->set_name(buffer
);
86 if (ref
->name
== NULL
) {
98 entry_ref_swap(char *buffer
, size_t size
)
100 if (size
< sizeof(dev_t
) + sizeof(ino_t
))
103 dev_t
*dev
= (dev_t
*)buffer
;
104 *dev
= B_SWAP_INT32(*dev
);
105 buffer
+= sizeof(dev_t
);
107 ino_t
*ino
= (ino_t
*)buffer
;
108 *ino
= B_SWAP_INT64(*ino
);
113 } // namespace BPrivate