1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright (c) 2009, Olivier MATZ <[email protected]>
4  * All rights reserved.
5  */
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <unistd.h>
10 #include <stdlib.h>
11 #include <stdarg.h>
12 #include <inttypes.h>
13 #include <fcntl.h>
14 
15 #include "cmdline.h"
16 #include "cmdline_private.h"
17 #include "cmdline_socket.h"
18 
19 #ifdef RTE_EXEC_ENV_WINDOWS
20 #define open _open
21 #endif
22 
23 struct cmdline *
24 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
25 {
26 	int fd;
27 
28 	/* everything else is checked in cmdline_new() */
29 	if (!path)
30 		return NULL;
31 
32 	fd = open(path, O_RDONLY, 0);
33 	if (fd < 0) {
34 		dprintf("open() failed\n");
35 		return NULL;
36 	}
37 	return cmdline_new(ctx, prompt, fd, -1);
38 }
39 
40 struct cmdline *
41 cmdline_stdin_new(cmdline_parse_ctx_t *ctx, const char *prompt)
42 {
43 	struct cmdline *cl;
44 
45 	cl = cmdline_new(ctx, prompt, 0, 1);
46 
47 	if (cl != NULL)
48 		terminal_adjust(cl);
49 
50 	return cl;
51 }
52 
53 void
54 cmdline_stdin_exit(struct cmdline *cl)
55 {
56 	if (cl == NULL)
57 		return;
58 
59 	terminal_restore(cl);
60 }
61