Clang format os_fuchsia.c

Change-Id: Id40541bdff20b471f4c5754df953dcc3bb9efc7c
diff --git a/src/utils/os_fuchsia.c b/src/utils/os_fuchsia.c
index a690736..0bed525 100644
--- a/src/utils/os_fuchsia.c
+++ b/src/utils/os_fuchsia.c
@@ -12,17 +12,17 @@
 
 #include "includes.h"
 
-#include <time.h>
 #include <sys/wait.h>
+#include <time.h>
 
-#include "os.h"
 #include "common.h"
+#include "os.h"
 
 #ifdef WPA_TRACE
 
-#include "wpa_debug.h"
-#include "trace.h"
 #include "list.h"
+#include "trace.h"
+#include "wpa_debug.h"
 
 static struct dl_list alloc_list = DL_LIST_HEAD_INIT(alloc_list);
 
@@ -38,18 +38,12 @@
 
 #endif /* WPA_TRACE */
 
-
-void os_sleep(os_time_t sec, os_time_t usec)
-{
-  if (sec)
-    sleep(sec);
-  if (usec)
-    usleep(usec);
+void os_sleep(os_time_t sec, os_time_t usec) {
+  if (sec) sleep(sec);
+  if (usec) usleep(usec);
 }
 
-
-int os_get_time(struct os_time *t)
-{
+int os_get_time(struct os_time *t) {
   int res;
   struct timeval tv;
   res = gettimeofday(&tv, NULL);
@@ -58,9 +52,7 @@
   return res;
 }
 
-
-int os_get_reltime(struct os_reltime *t)
-{
+int os_get_reltime(struct os_reltime *t) {
 #if defined(CLOCK_BOOTTIME)
   static clockid_t clock_id = CLOCK_BOOTTIME;
 #elif defined(CLOCK_MONOTONIC)
@@ -80,32 +72,29 @@
     }
     switch (clock_id) {
 #ifdef CLOCK_BOOTTIME
-    case CLOCK_BOOTTIME:
-      clock_id = CLOCK_MONOTONIC;
-      break;
+      case CLOCK_BOOTTIME:
+        clock_id = CLOCK_MONOTONIC;
+        break;
 #endif
 #ifdef CLOCK_MONOTONIC
-    case CLOCK_MONOTONIC:
-      clock_id = CLOCK_REALTIME;
-      break;
+      case CLOCK_MONOTONIC:
+        clock_id = CLOCK_REALTIME;
+        break;
 #endif
-    case CLOCK_REALTIME:
-      return -1;
+      case CLOCK_REALTIME:
+        return -1;
     }
   }
 }
 
-
 int os_mktime(int year, int month, int day, int hour, int min, int sec,
-        os_time_t *t)
-{
+              os_time_t *t) {
   struct tm tm, *tm1;
   time_t t_local, t1, t2;
   os_time_t tz_offset;
 
   if (year < 1970 || month < 1 || month > 12 || day < 1 || day > 31 ||
-      hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 ||
-      sec > 60)
+      hour < 0 || hour > 23 || min < 0 || min > 59 || sec < 0 || sec > 60)
     return -1;
 
   memset(&tm, 0, sizeof(tm));
@@ -131,19 +120,16 @@
   } else
     tz_offset = 0;
 
-  *t = (os_time_t) t_local - tz_offset;
+  *t = (os_time_t)t_local - tz_offset;
   return 0;
 }
 
-
-int os_gmtime(os_time_t t, struct os_tm *tm)
-{
+int os_gmtime(os_time_t t, struct os_tm *tm) {
   struct tm *tm2;
   time_t t2 = t;
 
   tm2 = gmtime(&t2);
-  if (tm2 == NULL)
-    return -1;
+  if (tm2 == NULL) return -1;
   tm->sec = tm2->tm_sec;
   tm->min = tm2->tm_min;
   tm->hour = tm2->tm_hour;
@@ -155,26 +141,18 @@
 
 #define os_daemon daemon
 
-int os_daemonize(const char *pid_file)
-{
+int os_daemonize(const char *pid_file) {
   /* Not supported */
   return -1;
 }
 
+void os_daemonize_terminate(const char *pid_file) { /* Not supported */ }
 
-void os_daemonize_terminate(const char *pid_file)
-{
-  /* Not supported */
-}
-
-
-int os_get_random(unsigned char *buf, size_t len)
-{
+int os_get_random(unsigned char *buf, size_t len) {
   FILE *f;
   size_t rc;
 
-  if (TEST_FAIL())
-    return -1;
+  if (TEST_FAIL()) return -1;
 
   /* TODO(alangardner): implement using random for now */
   f = fopen("/dev/urandom", "rb");
@@ -189,38 +167,27 @@
   return rc != len ? -1 : 0;
 }
 
+unsigned long os_random(void) { return random(); }
 
-unsigned long os_random(void)
-{
-  return random();
-}
-
-
-char * os_rel2abs_path(const char *rel_path)
-{
+char *os_rel2abs_path(const char *rel_path) {
   char *buf = NULL, *cwd, *ret;
   size_t len = 128, cwd_len, rel_len, ret_len;
   int last_errno;
 
-  if (!rel_path)
-    return NULL;
+  if (!rel_path) return NULL;
 
-  if (rel_path[0] == '/')
-    return os_strdup(rel_path);
+  if (rel_path[0] == '/') return os_strdup(rel_path);
 
   for (;;) {
     buf = os_malloc(len);
-    if (buf == NULL)
-      return NULL;
+    if (buf == NULL) return NULL;
     cwd = getcwd(buf, len);
     if (cwd == NULL) {
       last_errno = errno;
       os_free(buf);
-      if (last_errno != ERANGE)
-        return NULL;
+      if (last_errno != ERANGE) return NULL;
       len *= 2;
-      if (len > 2000)
-        return NULL;
+      if (len > 2000) return NULL;
     } else {
       buf[len - 1] = '\0';
       break;
@@ -241,58 +208,42 @@
   return ret;
 }
 
+int os_program_init(void) { return 0; }
 
-int os_program_init(void)
-{
-  return 0;
-}
-
-
-void os_program_deinit(void)
-{
+void os_program_deinit(void) {
 #ifdef WPA_TRACE
   struct os_alloc_trace *a;
   unsigned long total = 0;
   dl_list_for_each(a, &alloc_list, struct os_alloc_trace, list) {
     total += a->len;
     if (a->magic != ALLOC_MAGIC) {
-      wpa_printf(MSG_INFO, "MEMLEAK[%p]: invalid magic 0x%x "
-           "len %lu",
-           a, a->magic, (unsigned long) a->len);
+      wpa_printf(MSG_INFO,
+                 "MEMLEAK[%p]: invalid magic 0x%x "
+                 "len %lu",
+                 a, a->magic, (unsigned long)a->len);
       continue;
     }
-    wpa_printf(MSG_INFO, "MEMLEAK[%p]: len %lu",
-         a, (unsigned long) a->len);
+    wpa_printf(MSG_INFO, "MEMLEAK[%p]: len %lu", a, (unsigned long)a->len);
     wpa_trace_dump("memleak", a);
   }
   if (total)
-    wpa_printf(MSG_INFO, "MEMLEAK: total %lu bytes",
-         (unsigned long) total);
+    wpa_printf(MSG_INFO, "MEMLEAK: total %lu bytes", (unsigned long)total);
 #endif /* WPA_TRACE */
 }
 
-
-int os_setenv(const char *name, const char *value, int overwrite)
-{
+int os_setenv(const char *name, const char *value, int overwrite) {
   return setenv(name, value, overwrite);
 }
 
+int os_unsetenv(const char *name) { return unsetenv(name); }
 
-int os_unsetenv(const char *name)
-{
-  return unsetenv(name);
-}
-
-
-char * os_readfile(const char *name, size_t *len)
-{
+char *os_readfile(const char *name, size_t *len) {
   FILE *f;
   char *buf;
   long pos;
 
   f = fopen(name, "rb");
-  if (f == NULL)
-    return NULL;
+  if (f == NULL) return NULL;
 
   if (fseek(f, 0, SEEK_END) < 0 || (pos = ftell(f)) < 0) {
     fclose(f);
@@ -321,19 +272,14 @@
   return buf;
 }
 
-
-int os_file_exists(const char *fname)
-{
+int os_file_exists(const char *fname) {
   FILE *f = fopen(fname, "rb");
-  if (f == NULL)
-    return 0;
+  if (f == NULL) return 0;
   fclose(f);
   return 1;
 }
 
-
-int os_fdatasync(FILE *stream)
-{
+int os_fdatasync(FILE *stream) {
   if (!fflush(stream)) {
     return fdatasync(fileno(stream));
   }
@@ -341,67 +287,48 @@
   return -1;
 }
 
-
 #ifndef WPA_TRACE
-void * os_zalloc(size_t size)
-{
-  return calloc(1, size);
-}
+void *os_zalloc(size_t size) { return calloc(1, size); }
 #endif /* WPA_TRACE */
 
-
-size_t os_strlcpy(char *dest, const char *src, size_t siz)
-{
+size_t os_strlcpy(char *dest, const char *src, size_t siz) {
   return strlcpy(dest, src, siz);
 }
 
-
-int os_memcmp_const(const void *a, const void *b, size_t len)
-{
+int os_memcmp_const(const void *a, const void *b, size_t len) {
   const u8 *aa = a;
   const u8 *bb = b;
   size_t i;
   u8 res;
 
-  for (res = 0, i = 0; i < len; i++)
-    res |= aa[i] ^ bb[i];
+  for (res = 0, i = 0; i < len; i++) res |= aa[i] ^ bb[i];
 
   return res;
 }
 
-
 #ifdef WPA_TRACE
 
 #if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
-char wpa_trace_fail_func[256] = { 0 };
+char wpa_trace_fail_func[256] = {0};
 unsigned int wpa_trace_fail_after;
 
-static int testing_fail_alloc(void)
-{
+static int testing_fail_alloc(void) {
   const char *func[WPA_TRACE_LEN];
   size_t i, res, len;
   char *pos, *next;
   int match;
 
-  if (!wpa_trace_fail_after)
-    return 0;
+  if (!wpa_trace_fail_after) return 0;
 
   res = wpa_trace_calling_func(func, WPA_TRACE_LEN);
   i = 0;
-  if (i < res && os_strcmp(func[i], __func__) == 0)
-    i++;
-  if (i < res && os_strcmp(func[i], "os_malloc") == 0)
-    i++;
-  if (i < res && os_strcmp(func[i], "os_zalloc") == 0)
-    i++;
-  if (i < res && os_strcmp(func[i], "os_calloc") == 0)
-    i++;
-  if (i < res && os_strcmp(func[i], "os_realloc") == 0)
-    i++;
-  if (i < res && os_strcmp(func[i], "os_realloc_array") == 0)
-    i++;
-  if (i < res && os_strcmp(func[i], "os_strdup") == 0)
-    i++;
+  if (i < res && os_strcmp(func[i], __func__) == 0) i++;
+  if (i < res && os_strcmp(func[i], "os_malloc") == 0) i++;
+  if (i < res && os_strcmp(func[i], "os_zalloc") == 0) i++;
+  if (i < res && os_strcmp(func[i], "os_calloc") == 0) i++;
+  if (i < res && os_strcmp(func[i], "os_realloc") == 0) i++;
+  if (i < res && os_strcmp(func[i], "os_realloc_array") == 0) i++;
+  if (i < res && os_strcmp(func[i], "os_strdup") == 0) i++;
 
   pos = wpa_trace_fail_func;
 
@@ -440,40 +367,33 @@
     pos = next + 1;
     i++;
   }
-  if (!match)
-    return 0;
+  if (!match) return 0;
 
   wpa_trace_fail_after--;
   if (wpa_trace_fail_after == 0) {
-    wpa_printf(MSG_INFO, "TESTING: fail allocation at %s",
-         wpa_trace_fail_func);
+    wpa_printf(MSG_INFO, "TESTING: fail allocation at %s", wpa_trace_fail_func);
     for (i = 0; i < res; i++)
-      wpa_printf(MSG_INFO, "backtrace[%d] = %s",
-           (int) i, func[i]);
+      wpa_printf(MSG_INFO, "backtrace[%d] = %s", (int)i, func[i]);
     return 1;
   }
 
   return 0;
 }
 
-
-char wpa_trace_test_fail_func[256] = { 0 };
+char wpa_trace_test_fail_func[256] = {0};
 unsigned int wpa_trace_test_fail_after;
 
-int testing_test_fail(void)
-{
+int testing_test_fail(void) {
   const char *func[WPA_TRACE_LEN];
   size_t i, res, len;
   char *pos, *next;
   int match;
 
-  if (!wpa_trace_test_fail_after)
-    return 0;
+  if (!wpa_trace_test_fail_after) return 0;
 
   res = wpa_trace_calling_func(func, WPA_TRACE_LEN);
   i = 0;
-  if (i < res && os_strcmp(func[i], __func__) == 0)
-    i++;
+  if (i < res && os_strcmp(func[i], __func__) == 0) i++;
 
   pos = wpa_trace_test_fail_func;
 
@@ -512,16 +432,13 @@
     pos = next + 1;
     i++;
   }
-  if (!match)
-    return 0;
+  if (!match) return 0;
 
   wpa_trace_test_fail_after--;
   if (wpa_trace_test_fail_after == 0) {
-    wpa_printf(MSG_INFO, "TESTING: fail at %s",
-         wpa_trace_test_fail_func);
+    wpa_printf(MSG_INFO, "TESTING: fail at %s", wpa_trace_test_fail_func);
     for (i = 0; i < res; i++)
-      wpa_printf(MSG_INFO, "backtrace[%d] = %s",
-           (int) i, func[i]);
+      wpa_printf(MSG_INFO, "backtrace[%d] = %s", (int)i, func[i]);
     return 1;
   }
 
@@ -530,22 +447,16 @@
 
 #else
 
-static inline int testing_fail_alloc(void)
-{
-  return 0;
-}
+static inline int testing_fail_alloc(void) { return 0; }
 #endif
 
-void * os_malloc(size_t size)
-{
+void *os_malloc(size_t size) {
   struct os_alloc_trace *a;
 
-  if (testing_fail_alloc())
-    return NULL;
+  if (testing_fail_alloc()) return NULL;
 
   a = malloc(sizeof(*a) + size);
-  if (a == NULL)
-    return NULL;
+  if (a == NULL) return NULL;
   a->magic = ALLOC_MAGIC;
   dl_list_add(&alloc_list, &a->list);
   a->len = size;
@@ -553,47 +464,37 @@
   return a + 1;
 }
 
-
-void * os_realloc(void *ptr, size_t size)
-{
+void *os_realloc(void *ptr, size_t size) {
   struct os_alloc_trace *a;
   size_t copy_len;
   void *n;
 
-  if (ptr == NULL)
-    return os_malloc(size);
+  if (ptr == NULL) return os_malloc(size);
 
-  a = (struct os_alloc_trace *) ptr - 1;
+  a = (struct os_alloc_trace *)ptr - 1;
   if (a->magic != ALLOC_MAGIC) {
-    wpa_printf(MSG_INFO, "REALLOC[%p]: invalid magic 0x%x%s",
-         a, a->magic,
-         a->magic == FREED_MAGIC ? " (already freed)" : "");
+    wpa_printf(MSG_INFO, "REALLOC[%p]: invalid magic 0x%x%s", a, a->magic,
+               a->magic == FREED_MAGIC ? " (already freed)" : "");
     wpa_trace_show("Invalid os_realloc() call");
     abort();
   }
   n = os_malloc(size);
-  if (n == NULL)
-    return NULL;
+  if (n == NULL) return NULL;
   copy_len = a->len;
-  if (copy_len > size)
-    copy_len = size;
+  if (copy_len > size) copy_len = size;
   os_memcpy(n, a + 1, copy_len);
   os_free(ptr);
   return n;
 }
 
-
-void os_free(void *ptr)
-{
+void os_free(void *ptr) {
   struct os_alloc_trace *a;
 
-  if (ptr == NULL)
-    return;
-  a = (struct os_alloc_trace *) ptr - 1;
+  if (ptr == NULL) return;
+  a = (struct os_alloc_trace *)ptr - 1;
   if (a->magic != ALLOC_MAGIC) {
-    wpa_printf(MSG_INFO, "FREE[%p]: invalid magic 0x%x%s",
-         a, a->magic,
-         a->magic == FREED_MAGIC ? " (already freed)" : "");
+    wpa_printf(MSG_INFO, "FREE[%p]: invalid magic 0x%x%s", a, a->magic,
+               a->magic == FREED_MAGIC ? " (already freed)" : "");
     wpa_trace_show("Invalid os_free() call");
     abort();
   }
@@ -604,24 +505,18 @@
   free(a);
 }
 
-
-void * os_zalloc(size_t size)
-{
+void *os_zalloc(size_t size) {
   void *ptr = os_malloc(size);
-  if (ptr)
-    os_memset(ptr, 0, size);
+  if (ptr) os_memset(ptr, 0, size);
   return ptr;
 }
 
-
-char * os_strdup(const char *s)
-{
+char *os_strdup(const char *s) {
   size_t len;
   char *d;
   len = os_strlen(s);
   d = os_malloc(len + 1);
-  if (d == NULL)
-    return NULL;
+  if (d == NULL) return NULL;
   os_memcpy(d, s, len);
   d[len] = '\0';
   return d;
@@ -629,9 +524,7 @@
 
 #endif /* WPA_TRACE */
 
-
-int os_exec(const char *program, const char *arg, int wait_completion)
-{
+int os_exec(const char *program, const char *arg, int wait_completion) {
   /* TODO(alangardner): Implement using launchpad */
   pid_t pid;
   int pid_status;
@@ -657,14 +550,11 @@
     i = 1;
     pos = _arg;
     while (i < MAX_ARG && pos && *pos) {
-      while (*pos == ' ')
-        pos++;
-      if (*pos == '\0')
-        break;
+      while (*pos == ' ') pos++;
+      if (*pos == '\0') break;
       argv[i++] = pos;
       pos = os_strchr(pos, ' ');
-      if (pos)
-        *pos++ = '\0';
+      if (pos) *pos++ = '\0';
     }
     argv[i] = NULL;
 
@@ -683,4 +573,3 @@
 
   return 0;
 }
-