cmdline (merge-intel): compilation under baremetal environment
[libcmdline.git] / src / lib / cmdline_socket.c
index 2e201f6..bba3847 100644 (file)
 #include <inttypes.h>
 #include <fcntl.h>
 
+#ifndef CMDLINE_NO_SOCKET
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <sys/socket.h>
 #include <sys/un.h>
+#endif
 
 #include "cmdline_parse.h"
 #include "cmdline_rdline.h"
@@ -78,6 +80,7 @@
 
 /**********************/
 
+#ifndef CMDLINE_NO_SOCKET
 int
 cmdline_tcpv4_listen(in_addr_t addr, uint16_t port)
 {
@@ -189,10 +192,22 @@ end:
 }
 
 struct cmdline *
-cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
+cmdline_accept(cmdline_parse_ctx_t *ctx, const char *prompt, int s)
 {
-       return (cmdline_new(ctx, prompt, 0, 1));
+       int s2;
+       struct sockaddr sin;
+       socklen_t sinlen;
+
+       sinlen = sizeof(struct sockaddr);
+
+       if ((s2 = accept(s, &sin, &sinlen)) < 0) {
+               dprintf("accept() failed\n");
+               return NULL;
+       }
+
+       return (cmdline_new(ctx, prompt, s2, s2));
 }
+#endif
 
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
@@ -207,19 +222,7 @@ cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 }
 
 struct cmdline *
-cmdline_accept(cmdline_parse_ctx_t *ctx, const char *prompt, int s)
+cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
 {
-       int s2;
-       struct sockaddr sin;
-       socklen_t sinlen;
-
-       sinlen = sizeof(struct sockaddr);
-
-       if ((s2 = accept(s, &sin, &sinlen)) < 0) {
-               dprintf("accept() failed\n");
-               return NULL;
-       }
-
-       return (cmdline_new(ctx, prompt, s2, s2));
+       return (cmdline_new(ctx, prompt, 0, 1));
 }
-