TizenRT Libs&Environment  v2.0 M2
readline.h
Go to the documentation of this file.
1 /****************************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing,
12  * software distributed under the License is distributed on an
13  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
14  * either express or implied. See the License for the specific
15  * language governing permissions and limitations under the License.
16  *
17  ****************************************************************************/
18 /****************************************************************************
19  * apps/include/readline.h
20  *
21  * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
22  * Author: Gregory Nutt <gnutt@nuttx.org>
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  * notice, this list of conditions and the following disclaimer.
30  * 2. Redistributions in binary form must reproduce the above copyright
31  * notice, this list of conditions and the following disclaimer in
32  * the documentation and/or other materials provided with the
33  * distribution.
34  * 3. Neither the name NuttX nor the names of its contributors may be
35  * used to endorse or promote products derived from this software
36  * without specific prior written permission.
37  *
38  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
39  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
40  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
41  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
42  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
45  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
46  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
47  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
48  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49  * POSSIBILITY OF SUCH DAMAGE.
50  *
51  ****************************************************************************/
52 
53 #ifndef __APPS_INCLUDE_READLINE_H
54 #define __APPS_INCLUDE_READLINE_H
55 
56 /****************************************************************************
57  * Included Files
58  ****************************************************************************/
59 
60 #include <tinyara/config.h>
61 #include <stdio.h>
62 
63 /****************************************************************************
64  * Pre-Processor Definitions
65  ****************************************************************************/
66 
67 /****************************************************************************
68  * Public Data
69  ****************************************************************************/
70 
71 #ifdef __cplusplus
72 // *INDENT-OFF*
73 #define EXTERN extern "C"
74 extern "C" {
75 #else
76 #define EXTERN extern
77 // *INDENT-ON*
78 #endif
79 
80 /****************************************************************************
81  * Public Function Prototypes
82  ****************************************************************************/
83 
84 /****************************************************************************
85  * Name: readline
86  *
87  * readline() reads in at most one less than 'buflen' characters from
88  * 'instream' and stores them into the buffer pointed to by 'buf'.
89  * Characters are echoed on 'outstream'. Reading stops after an EOF or a
90  * newline. If a newline is read, it is stored into the buffer. A null
91  * terminator is stored after the last character in the buffer.
92  *
93  * This version of realine assumes that we are reading and writing to
94  * a VT100 console. This will not work well if 'instream' or 'outstream'
95  * corresponds to a raw byte steam.
96  *
97  * This function is inspired by the GNU readline but is an entirely
98  * different creature.
99  *
100  * Input Parameters:
101  * buf - The user allocated buffer to be filled.
102  * buflen - the size of the buffer.
103  * instream - The stream to read characters from
104  * outstream - The stream to each characters to.
105  *
106  * Returned values:
107  * On success, the (positive) number of bytes transferred is returned.
108  * EOF is returned to indicate either an end of file condition or a
109  * failure.
110  *
111  **************************************************************************/
112 
113 #if CONFIG_NFILE_STREAMS > 0
114 ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream);
115 #endif
116 
117 /****************************************************************************
118  * Name: std_readline
119  *
120  * readline() reads in at most one less than 'buflen' characters from
121  * 'stdin' and stores them into the buffer pointed to by 'buf'.
122  * Characters are echoed on 'stdout'. Reading stops after an EOF or a
123  * newline. If a newline is read, it is stored into the buffer. A null
124  * terminator is stored after the last character in the buffer.
125  *
126  * This version of realine assumes that we are reading and writing to
127  * a VT100 console. This will not work well if 'stdin' or 'stdout'
128  * corresponds to a raw byte steam.
129  *
130  * This function is inspired by the GNU readline but is an entirely
131  * different creature.
132  *
133  * Input Parameters:
134  * buf - The user allocated buffer to be filled.
135  * buflen - the size of the buffer.
136  *
137  * Returned values:
138  * On success, the (positive) number of bytes transferred is returned.
139  * EOF is returned to indicate either an end of file condition or a
140  * failure.
141  *
142  **************************************************************************/
143 
144 #if CONFIG_NFILE_STREAMS > 0
145 #define std_readline(b, s) readline(b, s, stdin, stdout)
146 #else
147 ssize_t std_readline(FAR char *buf, int buflen);
148 #endif
149 
150 #undef EXTERN
151 #ifdef __cplusplus
152 // *INDENT-OFF*
153 }
154 // *INDENT-ON*
155 #endif
156 
157 #endif /* __APPS_INCLUDE_READLINE_H */
ssize_t std_readline(FAR char *buf, int buflen)
struct file_struct FILE
Definition: stdio.h:188
Standard Input / Output APIs.