commands: writef write variable contents to file
PATCH 1/2 commands: writef write variable contents to file
From: Gerd Pauli <[email protected]>
--- commands/Kconfig | 10 ++++++++ commands/Makefile | 1 + commands/writef.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 commands/writef.c
commands/Kconfig +10 -0
@@ -1082,6 +1082,16 @@ config CMD_READF whitespaces are removed, nonvisible characters are stripped. Input is limited to 1024 characters. +config CMD_WRITEF + tristate + prompt "writef" + help + Write variable into file + + Usage: writef VAR FILE + + Writes a line from VARiable into a FILE. + config CMD_SLEEP tristate prompt "sleep"
commands/Makefile +1 -0
@@ -103,6 +103,7 @@ obj-$(CONFIG_CMD_BOOT) += boot.o obj-$(CONFIG_CMD_DEVINFO) += devinfo.o obj-$(CONFIG_CMD_DRVINFO) += drvinfo.o obj-$(CONFIG_CMD_READF) += readf.o +obj-$(CONFIG_CMD_WRITEF) += writef.o obj-$(CONFIG_CMD_MENUTREE) += menutree.o obj-$(CONFIG_CMD_2048) += 2048.o obj-$(CONFIG_CMD_REGULATOR) += regulator.o
commands/writef.c new file +68 -0
68 lines not on this page · raw message
Signature · 7 lines
1.9.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi,
Am 14.09.2017 um 14:29 schrieb [email protected]:
Quoted 1 line
From: Gerd Pauli <[email protected]>
please add comment here how it should be used.
Quoted 13 lines
Signed-off-by Gerd Pauli <[email protected]>--- commands/Kconfig | 10 ++++++++ commands/Makefile | 1 + commands/writef.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 commands/writef.ccommands/Kconfig +0
-0
commands/Kconfig config CMD_READF · line 1087
Quoted 6 lines
commands/Kconfig +3
-0@@ -1082,6 +1082,16 @@ config CMD_READF whitespaces are removed, nonvisible characters are stripped. Input is limited to 1024 characters. +config CMD_WRITEF + tristate + prompt "writef"
please use tabs instead of spaces.
Quoted 53 lines
commands/Kconfig +7
-0+ help + Write variable into file + + Usage: writef VAR FILE + + Writes a line from VARiable into a FILE. + config CMD_SLEEP tristate prompt "sleep"commands/Makefile +1
-0@@ -103,6 +103,7 @@ obj-$(CONFIG_CMD_BOOT) += boot.o obj-$(CONFIG_CMD_DEVINFO) += devinfo.o obj-$(CONFIG_CMD_DRVINFO) += drvinfo.o obj-$(CONFIG_CMD_READF) += readf.o +obj-$(CONFIG_CMD_WRITEF) += writef.o obj-$(CONFIG_CMD_MENUTREE) += menutree.o obj-$(CONFIG_CMD_2048) += 2048.o obj-$(CONFIG_CMD_REGULATOR) += regulator.ocommands/writef.c new file +25
-0@@ -0,0 +1,68 @@ +/* +* writef.c - Write Content of Variable to File +* +* Copyright (c) 2017 Gerd Pauli <[email protected]>, HighConsulting GmbH & Co. KG +* +* See file CREDITS for list of people who contributed to this +* project. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 +* as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +*/ + +#include <common.h> +#include <command.h> +#include <fs.h> +#include <libfile.h> +#include <malloc.h> +#include <linux/stat.h>
commands/writef.c line 35
Quoted 10 lines
commands/writef.c new file +10
-0+#include <linux/ctype.h> +#include <environment.h> + +static int do_writef (int argc,char *argv[]) +{ +const char *val; +char *variable, *filename; +size_t size; +void *buf; +int ret;
same here. tabs, not spaces.
please use linux kernel coding style.
https://www.kernel.org/doc/html/v4.13/process/coding-style.html
you can also use checkpatch.pl script from barebox repository.
for example:./scripts/checkpatch.pl -f commands/writef.c
or./scripts/checkpatch.pl your_patch
the same apply to other two patches as well
Quoted 33 lines
commands/writef.c new file +32
-0+if (argc !=3 ) +return COMMAND_ERROR_USAGE ; + + variable = argv[1 ]; + filename = argv[2 ]; + + val =getenv (variable); +if ( val ==NULL ) +return COMMAND_ERROR ; + + size =strlen (val); + size++; + + buf =xmalloc (size+1 ); +sprintf (buf,"%s\n" ,val); + + ret =write_file (filename, buf, size); +free (buf); +return ret; +} + +BAREBOX_CMD_HELP_START(writef) +BAREBOX_CMD_HELP_TEXT("Write Content of VARiable to FILE") +BAREBOX_CMD_HELP_END + +BAREBOX_CMD_START(writef) + .cmd = do_writef, + BAREBOX_CMD_DESC("write variable into file") + BAREBOX_CMD_OPTS("VAR FILE") + BAREBOX_CMD_GROUP(CMD_GRP_SCRIPT) + BAREBOX_CMD_HELP(cmd_writef_help) +BAREBOX_CMD_END
Signature · 2 lines
Regards, Oleksij
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox