net/cxgbe: fix build with optimization=1
[dpdk.git] / lib / cmdline / cmdline_socket.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
4  * All rights reserved.
5  */
6
7 #include <stdio.h>
8 #include <unistd.h>
9 #include <fcntl.h>
10
11 #include "cmdline.h"
12 #include "cmdline_private.h"
13 #include "cmdline_socket.h"
14
15 struct cmdline *
16 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
17 {
18         int fd;
19
20         /* everything else is checked in cmdline_new() */
21         if (!path)
22                 return NULL;
23
24         fd = open(path, O_RDONLY, 0);
25         if (fd < 0) {
26                 dprintf("open() failed\n");
27                 return NULL;
28         }
29         return cmdline_new(ctx, prompt, fd, -1);
30 }
31
32 struct cmdline *
33 cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
34 {
35         struct cmdline *cl;
36
37         cl = cmdline_new(ctx, prompt, 0, 1);
38
39         if (cl != NULL)
40                 terminal_adjust(cl);
41
42         return cl;
43 }
44
45 void
46 cmdline_stdin_exit(struct cmdline *cl)
47 {
48         if (cl == NULL)
49                 return;
50
51         terminal_restore(cl);
52         cmdline_free(cl);
53 }