]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
cli: Share a common write_cmd() implementation
authorJouni Malinen <j@w1.fi>
Sat, 6 Aug 2016 09:41:56 +0000 (12:41 +0300)
committerJouni Malinen <j@w1.fi>
Sat, 6 Aug 2016 09:41:56 +0000 (12:41 +0300)
wpa_cli and hostapd_cli had identical copies of this function.

Signed-off-by: Jouni Malinen <j@w1.fi>
hostapd/hostapd_cli.c
src/common/cli.c
src/common/cli.h
wpa_supplicant/wpa_cli.c

index 56f5fe25105d6d1f2e1f52b29cd389df4efdac21..196f512f1c5d69c2495ae3830b1a964244327149 100644 (file)
@@ -187,36 +187,6 @@ static inline int wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd)
 }
 
 
-static int write_cmd(char *buf, size_t buflen, const char *cmd, int argc,
-                    char *argv[])
-{
-       int i, res;
-       char *pos, *end;
-
-       pos = buf;
-       end = buf + buflen;
-
-       res = os_snprintf(pos, end - pos, "%s", cmd);
-       if (os_snprintf_error(end - pos, res))
-               goto fail;
-       pos += res;
-
-       for (i = 0; i < argc; i++) {
-               res = os_snprintf(pos, end - pos, " %s", argv[i]);
-               if (os_snprintf_error(end - pos, res))
-                       goto fail;
-               pos += res;
-       }
-
-       buf[buflen - 1] = '\0';
-       return 0;
-
-fail:
-       printf("Too long command\n");
-       return -1;
-}
-
-
 static int hostapd_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd,
                           int min_args, int argc, char *argv[])
 {
index 6e0018875db4036f8cd57498bc6b418aa9b67de2..64c015916cf759360b168f7f75f984fe12f36704 100644 (file)
@@ -206,3 +206,32 @@ int get_cmd_arg_num(const char *str, int pos)
                arg--;
        return arg;
 }
+
+
+int write_cmd(char *buf, size_t buflen, const char *cmd, int argc, char *argv[])
+{
+       int i, res;
+       char *pos, *end;
+
+       pos = buf;
+       end = buf + buflen;
+
+       res = os_snprintf(pos, end - pos, "%s", cmd);
+       if (os_snprintf_error(end - pos, res))
+               goto fail;
+       pos += res;
+
+       for (i = 0; i < argc; i++) {
+               res = os_snprintf(pos, end - pos, " %s", argv[i]);
+               if (os_snprintf_error(end - pos, res))
+                       goto fail;
+               pos += res;
+       }
+
+       buf[buflen - 1] = '\0';
+       return 0;
+
+fail:
+       printf("Too long command\n");
+       return -1;
+}
index 4caf321c4956a89103b8ef9926e941996b275511..9f9f851134c52894c23e41eceb60560bf508e316 100644 (file)
@@ -38,5 +38,7 @@ int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt,
 char ** cli_txt_list_array(struct dl_list *txt_list);
 
 int get_cmd_arg_num(const char *str, int pos);
+int write_cmd(char *buf, size_t buflen, const char *cmd, int argc,
+             char *argv[]);
 
 #endif /* CLI_H */
index 42be5b6f64d5fc82506019d6240ff0581a902693..28fe76c1f80aaf0894f09d1a578dddbc3e1e8ee1 100644 (file)
@@ -256,36 +256,6 @@ static int wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd)
 }
 
 
-static int write_cmd(char *buf, size_t buflen, const char *cmd, int argc,
-                    char *argv[])
-{
-       int i, res;
-       char *pos, *end;
-
-       pos = buf;
-       end = buf + buflen;
-
-       res = os_snprintf(pos, end - pos, "%s", cmd);
-       if (os_snprintf_error(end - pos, res))
-               goto fail;
-       pos += res;
-
-       for (i = 0; i < argc; i++) {
-               res = os_snprintf(pos, end - pos, " %s", argv[i]);
-               if (os_snprintf_error(end - pos, res))
-                       goto fail;
-               pos += res;
-       }
-
-       buf[buflen - 1] = '\0';
-       return 0;
-
-fail:
-       printf("Too long command\n");
-       return -1;
-}
-
-
 static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args,
                       int argc, char *argv[])
 {