summaryrefslogtreecommitdiff
path: root/rtemstoolkit/rld-buffer.h
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2017-08-16 18:09:59 +1000
committerChris Johns <chrisj@rtems.org>2017-08-16 18:18:35 +1000
commit78bbe4c1a31dc62c3a9bee919645c0aa8781709b (patch)
tree51caba18f81dd97459d45c00ba5bdb3d468e112c /rtemstoolkit/rld-buffer.h
parent0ea1c27f792a486badddb24c6ab219e4af0d91c3 (diff)
linkers/exe-info Support ARM static constructors.
Note, ARM destructors are registered at runtime and currently not easly found. Update libiberty to get a newer demangler. Closes #3102.
Diffstat (limited to 'rtemstoolkit/rld-buffer.h')
-rw-r--r--rtemstoolkit/rld-buffer.h49
1 files changed, 40 insertions, 9 deletions
diff --git a/rtemstoolkit/rld-buffer.h b/rtemstoolkit/rld-buffer.h
index ea94a9a..08df4ba 100644
--- a/rtemstoolkit/rld-buffer.h
+++ b/rtemstoolkit/rld-buffer.h
@@ -59,6 +59,13 @@ namespace rld
*/
~buffer ();
+ /*
+ * Return true if the byte order is little-endian.
+ */
+ bool little_endian () const {
+ return le;
+ }
+
/**
* Clear the buffer reseting the level to zero.
*/
@@ -148,11 +155,23 @@ namespace rld
{
uint8_t bytes[sizeof (T)];
T v = value;
- int b = sizeof (T) - 1;
- while (b >= 0)
+ if (buf.little_endian ())
{
- bytes[b--] = (uint8_t) v;
- v >>= 8;
+ size_t b = sizeof (T);
+ while (b != 0)
+ {
+ bytes[--b] = (uint8_t) v;
+ v >>= 8;
+ }
+ }
+ else
+ {
+ size_t b = 0;
+ while (b < sizeof (T))
+ {
+ bytes[b++] = (uint8_t) v;
+ v >>= 8;
+ }
}
buf.write (bytes, sizeof (T));
}
@@ -164,13 +183,25 @@ namespace rld
void read (buffer& buf, T& value)
{
uint8_t bytes[sizeof (T)];
- int b = sizeof (T) - 1;
- buf.read (bytes, sizeof(T));
+ buf.read (bytes, sizeof (T));
value = 0;
- while (b >= 0)
+ if (buf.little_endian ())
+ {
+ size_t b = sizeof (T);
+ while (b != 0)
+ {
+ value <<= 8;
+ value |= (T) bytes[--b];
+ }
+ }
+ else
{
- value <<= 8;
- value |= (T) bytes[b--];
+ size_t b = 0;
+ while (b < sizeof (T))
+ {
+ value <<= 8;
+ value |= (T) bytes[b++];
+ }
}
}