gpio_mailbox: extern more write functions
* and move statics funcs from .h file to .c file
Change-Id: I3b4e995c9f816d3243aaa00859a0bd2d2b21f9ec
diff --git a/gpio-mailbox/fileops.c b/gpio-mailbox/fileops.c
index ff198d0..57879e9 100644
--- a/gpio-mailbox/fileops.c
+++ b/gpio-mailbox/fileops.c
@@ -53,7 +53,6 @@
return -1;
}
-
#define WRITE_TO_FILE(filename, oldv, newv, atomic, format) \
if (!oldv || *oldv != newv) { \
char buf[128]; \
@@ -68,20 +67,43 @@
}
-void __write_file_longlong(const char *filename, long long *oldv, long long newv,
- int atomic)
-{
+static void __write_file_longlong(const char *filename, long long *oldv,
+ long long newv, int atomic) {
WRITE_TO_FILE(filename, oldv, newv, atomic, "%lld")
}
-void __write_file_int(const char *filename, int *oldv, int newv, int atomic)
-{
+static void __write_file_int(const char *filename, int *oldv, int newv,
+ int atomic) {
WRITE_TO_FILE(filename, oldv, newv, atomic, "%d")
}
-void __write_file_double(const char *filename, double *oldv, double newv,
- int atomic)
-{
+static void __write_file_double(const char *filename, double *oldv, double newv,
+ int atomic) {
WRITE_TO_FILE(filename, oldv, newv, atomic, "%.2f")
}
+void write_file_longlong_atomic(const char *filename, long long *oldv,
+ long long newv) {
+ __write_file_longlong(filename, oldv, newv, 1);
+}
+
+void write_file_int_atomic(const char *filename, int *oldv, int newv) {
+ __write_file_int(filename, oldv, newv, 1);
+}
+
+void write_file_double_atomic(const char *filename, double *oldv, double newv) {
+ __write_file_double(filename, oldv, newv, 1);
+}
+
+void write_file_longlong(const char *filename, long long *oldv,
+ long long newv) {
+ __write_file_longlong(filename, oldv, newv, 0);
+}
+
+void write_file_int(const char *filename, int *oldv, int newv) {
+ __write_file_int(filename, oldv, newv, 0);
+}
+
+void write_file_double(const char *filename, double *oldv, double newv) {
+ __write_file_double(filename, oldv, newv, 0);
+}
diff --git a/gpio-mailbox/fileops.h b/gpio-mailbox/fileops.h
index 089c275..18153e8 100644
--- a/gpio-mailbox/fileops.h
+++ b/gpio-mailbox/fileops.h
@@ -7,42 +7,17 @@
// Read a file containing a single short integer.
long read_file_long(const char *filename);
-void __write_file_longlong(const char *filename, long long *oldv,
- long long newv, int atomic);
+// write to a file
+int write_file_string(const char *filename, const char *content);
+void write_file_longlong(const char *filename, long long *oldv, long long newv);
+void write_file_int(const char *filename, int *oldv, int newv);
+void write_file_double(const char *filename, double *oldv, double newv);
-void __write_file_int(const char *filename, int *oldv, int newv, int atomic);
-
-void __write_file_double(const char *filename, double *oldv, double newv,
- int atomic);
-
-static void write_file_longlong_atomic(const char *filename, long long *oldv,
- long long newv ) {
- __write_file_longlong(filename, oldv, newv, 1);
-}
-
-static void write_file_int_atomic(const char *filename, int *oldv, int newv) {
- __write_file_int(filename, oldv, newv, 1);
-}
-
-static void write_file_double_atomic(const char *filename, double *oldv,
- double newv) {
- __write_file_double(filename, oldv, newv, 1);
-}
-
-static void write_file_longlong(const char *filename,
- long long *oldv, long long newv ) {
- __write_file_longlong(filename, oldv, newv, 0);
-}
-
-static void write_file_int(const char *filename, int *oldv,
- int newv) {
- __write_file_int(filename, oldv, newv, 0);
-}
-
-static void write_file_double(const char *filename, double *oldv,
- double newv) {
- __write_file_double(filename, oldv, newv, 0);
-}
-
+// write to a tmp file then rename "atomicly"
+int write_file_string_atomic(const char *filename, const char *content);
+void write_file_longlong_atomic(const char *filename, long long *oldv,
+ long long newv);
+void write_file_int_atomic(const char *filename, int *oldv, int newv);
+void write_file_double_atomic(const char *filename, double *oldv, double newv);
#endif /* FILEOPS_H_ */