]> git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / LibC / Uefi / InteractiveIO / NonCanonRead.c
1 /** @file
2 NonCanonical Interactive Input Function.
3
4 The functions assume that isatty() is TRUE at the time they are called.
5 If _S_IWTTY is set, the device returns WIDE characters.
6
7 Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>
8 This program and the accompanying materials are licensed and made available
9 under the terms and conditions of the BSD License which accompanies this
10 distribution. The full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php.
12
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 **/
16 #include <LibConfig.h>
17
18 #include <sys/syslimits.h>
19 #include <sys/termios.h>
20 #include <Containers/Fifo.h>
21 #include <Device/IIO.h>
22
23 /** Perform a noncanonical read of input.
24
25 @param[in] filp Pointer to a file descriptor structure.
26 @param[in] BufferSize Maximum number of bytes to return.
27
28 @retval -1 An error has occurred. Reason in errno.
29 @retval -1 No data returned. None was ready.
30 @retval >0 The number of elements returned
31 **/
32 ssize_t
33 IIO_NonCanonRead (
34 struct __filedes *filp
35 )
36 {
37 cIIO *This;
38 cFIFO *InBuf;
39 struct termios *Termio;
40 ssize_t NumRead;
41 cc_t tioMin;
42 cc_t tioTime;
43 UINT32 InputType;
44 wchar_t InChar; // Intermediate character buffer
45
46 NumRead = -1;
47 InChar = 0; // Initialize so compilers don't complain.
48 This = filp->devdata;
49 Termio = &This->Termio;
50 InBuf = This->InBuf;
51 tioMin = Termio->c_cc[VMIN];
52 tioTime = Termio->c_cc[VTIME];
53
54 if(tioMin >= MAX_INPUT) {
55 tioMin = MAX_INPUT;
56 }
57 /* There are four types of processing that may be done, based on
58 the values of tioMin and tioTime.
59 Min Time Type
60 --- ---- ----
61 0 0 0 Return buffer contents or 1 new char
62 0 >0 1 Return 0 or 1 character depending on timeout
63 >0 0 2 Buffer Min chars. Return BufferSize chars.
64 >0 >0 3 Return up to Min chars. Unless the inter-byte timer expires.
65
66 Currently, only type 0 is implemented.
67 */
68 InputType = 0;
69 if(tioMin != 0) InputType = 2;
70 if(tioTime != 0) ++InputType;
71 //switch(InputType) {
72 // case 0:
73 if(InBuf->IsEmpty(InBuf)) {
74 NumRead = filp->f_ops->fo_read(filp, &filp->f_offset, sizeof(wchar_t), &InChar);
75 if(NumRead > 0) {
76 (void) InBuf->Write(InBuf, &InChar, 1); // Buffer the character
77 }
78 }
79 // break;
80 // case 1:
81 // break;
82 // case 2:
83 // break;
84 // case 3:
85 // break;
86 //}
87 return NumRead;
88 }