aboutsummaryrefslogtreecommitdiff
path: root/lib/lib.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2013-06-01 20:41:35 -0500
committerRob Landley <rob@landley.net>2013-06-01 20:41:35 -0500
commit6b28341dfc933ccd631a4d1e0b5d055c39e96e8d (patch)
tree1fdc9bd3f5db1e81f80d9726bd4a82dc536074e1 /lib/lib.c
parente8d186a510b929d84fefaccf8822fc0e6d3c1b0d (diff)
downloadtoybox-6b28341dfc933ccd631a4d1e0b5d055c39e96e8d.tar.gz
Enable readfile() and add peek() and poke() functions.
Diffstat (limited to 'lib/lib.c')
-rw-r--r--lib/lib.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 813677dd..7b0cf1a1 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -712,9 +712,6 @@ char *xreadlink(char *name)
}
}
-/*
- 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 @@ char *xreadfile(char *name)
return buf;
}
-*/
-
-
// Sleep for this many thousandths of a second
void msleep(long miliseconds)
{
@@ -762,6 +756,40 @@ int xioctl(int fd, int request, void *data)
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)