]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
2 NonCanonical Interactive Input Function.
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.
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.
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.
16 #include <LibConfig.h>
18 #include <sys/syslimits.h>
19 #include <sys/termios.h>
20 #include <Containers/Fifo.h>
21 #include <Device/IIO.h>
23 /** Perform a noncanonical read of input.
25 @param[in] filp Pointer to a file descriptor structure.
26 @param[in] BufferSize Maximum number of bytes to return.
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
34 struct __filedes
*filp
39 struct termios
*Termio
;
44 wchar_t InChar
; // Intermediate character buffer
47 InChar
= 0; // Initialize so compilers don't complain.
49 Termio
= &This
->Termio
;
51 tioMin
= Termio
->c_cc
[VMIN
];
52 tioTime
= Termio
->c_cc
[VTIME
];
54 if(tioMin
>= MAX_INPUT
) {
57 /* There are four types of processing that may be done, based on
58 the values of tioMin and tioTime.
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.
66 Currently, only type 0 is implemented.
69 if(tioMin
!= 0) InputType
= 2;
70 if(tioTime
!= 0) ++InputType
;
73 if(InBuf
->IsEmpty(InBuf
)) {
74 NumRead
= filp
->f_ops
->fo_read(filp
, &filp
->f_offset
, sizeof(wchar_t), &InChar
);
76 (void) InBuf
->Write(InBuf
, &InChar
, 1); // Buffer the character