changeset 913:7fed25030389

Enable readfile() and add peek() and poke() functions.
author Rob Landley <rob@landley.net>
date Sat, 01 Jun 2013 20:41:35 -0500
parents f4f5132d5ac7
children 91d15ead5602
files lib/lib.c
diffstat 1 files changed, 34 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/lib/lib.c	Tue May 28 00:28:45 2013 -0500
+++ b/lib/lib.c	Sat Jun 01 20:41:35 2013 -0500
@@ -712,9 +712,6 @@
   }
 }
 
-/*
- This might be of use or might not.  Unknown yet...
-
 // Read contents of file as a single freshly allocated nul-terminated string.
 char *readfile(char *name)
 {
@@ -738,9 +735,6 @@
   return buf;
 }
 
-*/
-
-
 // Sleep for this many thousandths of a second
 void msleep(long miliseconds)
 {
@@ -762,6 +756,40 @@
   return rc;
 }
 
+int64_t peek(void *ptr, int size)
+{
+  if (size & 8) {
+    int64_t *p = (int64_t *)ptr;
+    return *p;
+  } else if (size & 4) {
+    int *p = (int *)ptr;
+    return *p;
+  } else if (size & 2) {
+    short *p = (short *)ptr;
+    return *p;
+  } else {
+    char *p = (char *)ptr;
+    return *p;
+  }
+}
+
+void poke(void *ptr, uint64_t val, int size)
+{
+  if (size & 8) {
+    uint64_t *p = (uint64_t *)ptr;
+    *p = val;
+  } else if (size & 4) {
+    int *p = (int *)ptr;
+    *p = val;
+  } else if (size & 2) {
+    short *p = (short *)ptr;
+    *p = val;
+  } else {
+    char *p = (char *)ptr;
+    *p = val;
+  }
+}
+
 // Open a /var/run/NAME.pid file, dying if we can't write it or if it currently
 // exists and is this executable.
 void xpidfile(char *name)