gpio: add modify gpio function in powerdebug tool.

For power consumption test, we can change gpio direction and value
and check that power consumption is falled or not.
use 'D' key to change gpio direction.
And when gpio direction is "out", use 'V' key to change gpio value.

Signed-off-by: Shaojie Sun <shaojie.sun@linaro.com>
diff --git a/utils.c b/utils.c
index e47c58e..4d4b780 100644
--- a/utils.c
+++ b/utils.c
@@ -53,3 +53,39 @@
         free(rpath);
         return ret;
 }
+
+/*
+ * This functions is a helper to write a specific file content and store
+ * the content inside a variable pointer passed as parameter, the format
+ * parameter gives the variable type to be write to the file.
+ *
+ * @path : directory path containing the file
+ * @name : name of the file to be read
+ * @format : the format of the format
+ * @value : a pointer to a variable to store the content of the file
+ * Returns 0 on success, -1 otherwise
+ */
+int file_write_value(const char *path, const char *name,
+			const char *format, void *value)
+{
+	FILE *file;
+	char *rpath;
+	int ret;
+
+	ret = asprintf(&rpath, "%s/%s", path, name);
+	if (ret < 0)
+		return ret;
+
+	file = fopen(rpath, "w");
+	if (!file) {
+		ret = -1;
+		goto out_free;
+	}
+
+	ret = fprintf(file, format, value) < 0 ? -1 : 0;
+
+	fclose(file);
+out_free:
+	free(rpath);
+	return ret;
+}