[libc] code cleanup for termios.

This commit is contained in:
bernard 2017-10-17 22:24:23 +08:00
parent 41f3d1f9de
commit a437ffbf3e
2 changed files with 27 additions and 27 deletions

View File

@ -7,7 +7,7 @@ src = Glob('*.c') + Glob('*.cpp')
CPPPATH = [cwd] CPPPATH = [cwd]
group = DefineGroup('libc', src, group = DefineGroup('libc', src,
depend = ['RT_USING_LIBC', 'RT_USING_POSIX_TERMIOS'], depend = ['RT_USING_LIBC', 'RT_USING_POSIX', 'RT_USING_POSIX_TERMIOS'],
CPPPATH = CPPPATH) CPPPATH = CPPPATH)
Return('group') Return('group')

View File

@ -32,7 +32,7 @@
int tcgetattr(int fd, struct termios *tio) int tcgetattr(int fd, struct termios *tio)
{ {
/* Get the current serial port settings. */ /* Get the current serial port settings. */
if (ioctl(fd, TCGETA, tio)) if (ioctl(fd, TCGETA, tio))
return -1; return -1;
@ -41,27 +41,27 @@ int tcgetattr(int fd, struct termios *tio)
int tcsetattr(int fd, int act, const struct termios *tio) int tcsetattr(int fd, int act, const struct termios *tio)
{ {
switch (act) switch (act)
{ {
case TCSANOW: case TCSANOW:
/* make the change immediately */ /* make the change immediately */
return (ioctl(fd, TCSETA, (void*)tio)); return (ioctl(fd, TCSETA, (void*)tio));
case TCSADRAIN: case TCSADRAIN:
/* /*
* Don't make the change until all currently written data * Don't make the change until all currently written data
* has been transmitted. * has been transmitted.
*/ */
return (ioctl(fd, TCSETAW, (void*)tio)); return (ioctl(fd, TCSETAW, (void*)tio));
case TCSAFLUSH: case TCSAFLUSH:
/* Don't make the change until all currently written data /* Don't make the change until all currently written data
* has been transmitted, at which point any received but * has been transmitted, at which point any received but
* unread data is also discarded. * unread data is also discarded.
*/ */
return (ioctl(fd, TCSETAF, (void*)tio)); return (ioctl(fd, TCSETAF, (void*)tio));
default: default:
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
} }
/** /**
@ -106,7 +106,7 @@ int cfsetispeed(struct termios *tio, speed_t speed)
int tcsendbreak(int fd, int dur) int tcsendbreak(int fd, int dur)
{ {
/* nonzero duration is implementation-defined, so ignore it */ /* nonzero duration is implementation-defined, so ignore it */
return 0; return 0;
} }
int tcflush(int fd, int queue) int tcflush(int fd, int queue)
@ -124,14 +124,14 @@ int tcflow(int fd, int action)
*/ */
int tcdrain(int fd) int tcdrain(int fd)
{ {
return 0; return 0;
} }
int isatty (int fd) int isatty (int fd)
{ {
struct termios term; struct termios term;
return tcgetattr (fd, &term) == 0; return tcgetattr (fd, &term) == 0;
} }
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)