From: Alison Chaiken <[email protected]>

Signed-off-by: Alison Chaiken <[email protected]>
---
 util-linux/lsi2c.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 util-linux/lsi2c.c

diff --git a/util-linux/lsi2c.c b/util-linux/lsi2c.c
new file mode 100644
index 0000000..d87ff42
--- /dev/null
+++ b/util-linux/lsi2c.c
@@ -0,0 +1,55 @@
+/*
+ * lsi2c implementation for busybox
+ *
+ * Copyright (C) 2013, 2014 Alison Chaiken [email protected],
+ *                          Souf Oued [email protected]
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+//usage:#define lsi2c_trivial_usage NOUSAGE_STR
+//usage:#define lsi2c_full_usage ""
+
+#include "libbb.h"
+
+static int FAST_FUNC fileAction(
+                               const char *instring,
+                               struct stat *statbuf UNUSED_PARAM,
+                               void *userData UNUSED_PARAM,
+                               int depth)
+{
+       const char *sysfs_node, *drivername;
+       char *address;
+
+       sysfs_node = bb_basename(instring);
+
+       if (!isdigit(sysfs_node[0])) {
+               depth++;
+               return depth;
+       }
+
+       drivername = bb_basename(dirname((char *)instring));
+       address = strchr(sysfs_node, '-');
+
+       if (*address++)
+               printf("Controller %c for driver %s at address 0x%s.\n", 
*sysfs_node,
+                  drivername, address);
+
+       return 0;
+}
+
+int lsi2c_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lsi2c_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+       const char *fileName = "/sys/bus/i2c/drivers";
+       int depth = 0;
+
+       recursive_action(fileName,
+                               ACTION_RECURSE,
+                               fileAction,
+                               NULL, /* dirAction */
+                               NULL, /* userData */
+                               depth);
+
+       return EXIT_SUCCESS;
+}
-- 
1.8.5.2

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to