happy New Year for all,
Le 03/01/2014 06:53, [email protected] a écrit :
From: Alison Chaiken <[email protected]>
Signed-off-by: Alison Chaiken <[email protected]>
---
util-linux/lsi2c.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 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..4cc2191
--- /dev/null
+++ b/util-linux/lsi2c.c
@@ -0,0 +1,83 @@
+/*
+ * lsi2c implementation for busybox
+ *
+ * Copyright (C) 2013 Alison Chaiken [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 <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <dirent.h>
+#include "libbb.h"
+
+#define MAXSTRING 256
+
+/* int FAST_FUNC (*fileAction)(const char *fileName, struct stat *statbuf,
+ void* userData, int depth), */
+static int FAST_FUNC fileAction(
+ const char *instring,
+ struct stat *statbuf UNUSED_PARAM,
+ void *userData UNUSED_PARAM,
+ int depth UNUSED_PARAM)
+{
+ char sysfs_node[MAXSTRING];
+ char savestr[MAXSTRING];
+ char drivername[MAXSTRING];
+ char *dashpos;
+ const char *delim = "-";
+
+ if (strlen(instring) > MAXSTRING)
+ bb_error_msg_and_die("Pathname too long to process: %s.\n",
instring);
+
+ strcpy(drivername, instring);
+
+/* see comments about basename in libbb.h */
+ strcpy(sysfs_node, bb_basename(instring));
+ strcpy(savestr, sysfs_node);
+ dashpos = strtok(savestr, delim);
+ dashpos = strtok(NULL, delim);
+ strcpy(drivername, bb_basename(dirname(drivername)));
+
+ if ((dashpos) && isdigit(*sysfs_node))
+ printf("Controller %c for driver %s at address 0x%s.\n",
*sysfs_node,
+ drivername, dashpos);
+
+ return TRUE;
+}
+
+int lsi2c_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int lsi2c_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
+{
+ char *nextFile = NULL;
+ const char *fileName = "/sys/bus/i2c/drivers";
+ DIR *dir;
+ struct dirent *next;
+
+ dir = xopendir(fileName);
+
Why you are using readdir() and recursive_action()? recursive_action
does it for you.
Can you give an example of "nextfile" ?
+ while ((next = readdir(dir)) != NULL) {
+ nextFile = concat_subpath_file(fileName, next->d_name);
+ if (nextFile == NULL)
+ continue;
+ recursive_action(nextFile,
+ ACTION_RECURSE,
+ fileAction,
+ NULL, /* dirAction */
+ NULL, /* userData */
+ 0 /* depth */);
+ }
+
+ if (ENABLE_FEATURE_CLEAN_UP) {
+ free(nextFile);
you can not free fileName, GCC message:
warning: attempt to free a non-heap object [-Wfree-nonheap-object]
+ free(fileName);
+ closedir(dir);
+ }
+
+ return EXIT_SUCCESS;
+}
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox