Hi, inline some hints for size reduction (untested). Ciao, Tito
From: Alison Chaiken <alison_chai...@mentor.com> Signed-off-by: Alison Chaiken <alison_chai...@mentor.com> --- util-linux/lsi2c.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 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..ea1e3b5 --- /dev/null +++ b/util-linux/lsi2c.c @@ -0,0 +1,84 @@ +/* + * lsi2c implementation for busybox + * + * Copyright (C) 2013 Alison Chaiken ali...@she-devel.com + * + * 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 2456 + +/* 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) { + fprintf(stderr, "Pathname too long to process: %s.\n", instring); + exit(-1); bb_error_msg_and_die or use xasprintf to dynamically allocate the needed memory? + } + 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 fileName[MAXSTRING]; maybe char *filename = "/sys/bus/i2c/drivers"; + char *nextFile = NULL; + DIR *dir; + struct dirent *next; + // strcpy(fileName, "/sys/bus/i2c/drivers"); + dir = opendir(fileName); + if (!dir) { + fprintf(stderr, "Can't open sysfs.\n"); + exit(-1); + } xopendir + 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 */); + } eventually if (ENABLE_FEATURE_CLEAN_UP) { + free(nextFile); + closedir(dir); } + return EXIT_SUCCESS; +} -- 1.7.9.5 _______________________________________________ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox