From 9811c41921752ff7a98f5845c6c6f19d0959859b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Grubbstr=C3=B6m=20=28Grubba=29?= <grubba@grubba.org> Date: Fri, 28 Feb 2020 11:34:57 +0100 Subject: [PATCH] I/O: Make termios code dependent on presence of tcgetattr(). Preparation for supporting some termios operations on NT. Preparation for #10013. --- src/modules/_Stdio/configure.in | 2 +- src/modules/_Stdio/file.c | 2 ++ src/modules/_Stdio/file_functions.h | 2 ++ src/modules/_Stdio/termios.c | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/_Stdio/configure.in b/src/modules/_Stdio/configure.in index f440e9ff78..a805cb2e9a 100644 --- a/src/modules/_Stdio/configure.in +++ b/src/modules/_Stdio/configure.in @@ -67,7 +67,7 @@ AC_CHECK_LIB(util, openpty) AC_HAVE_FUNCS(readdir_r statvfs statfs ustat lseek64 lstat fsync \ grantpt unlockpt ptsname posix_openpt socketpair writev sendfile munmap \ - openpty \ + openpty tcgetattr \ madvise poll setsockopt getprotobyname inet_ntoa \ inet_ntop execve listxattr flistxattr getxattr fgetxattr setxattr fsetxattr \ fdopendir pathconf fpathconf dirfd fstatat openat unlinkat kqueue access) diff --git a/src/modules/_Stdio/file.c b/src/modules/_Stdio/file.c index d62093f374..20408a48b1 100644 --- a/src/modules/_Stdio/file.c +++ b/src/modules/_Stdio/file.c @@ -6157,6 +6157,7 @@ void check_static_file_data(struct callback *UNUSED(a), void *UNUSED(b), #if defined(HAVE_TERMIOS_H) || defined(HAVE_SYS_TERMIOS_H) void file_tcgetattr(INT32 args); +#ifdef HAVE_TCGETATTR void file_tcsetattr(INT32 args); void file_tcsendbreak(INT32 args); void file_tcflush(INT32 args); @@ -6164,6 +6165,7 @@ void file_tcdrain(INT32 args); /* void file_tcflow(INT32 args); */ /* void file_tcgetpgrp(INT32 args); */ /* void file_tcsetpgrp(INT32 args); */ +#endif #ifdef TIOCSWINSZ void file_tcsetsize(INT32 args); #endif diff --git a/src/modules/_Stdio/file_functions.h b/src/modules/_Stdio/file_functions.h index ce3393aba8..67040f189d 100644 --- a/src/modules/_Stdio/file_functions.h +++ b/src/modules/_Stdio/file_functions.h @@ -170,6 +170,7 @@ FILE_FUNC("grantpt",file_grantpt, tFunc(tNone,tStr)) #if defined(HAVE_TERMIOS_H) || defined(HAVE_SYS_TERMIOS_H) /* function(void:mapping) */ FILE_FUNC("tcgetattr",file_tcgetattr, tFunc(tNone,tMapping)) +#ifdef HAVE_TCGETATTR /* function(mapping, void|string: int(0..1)) */ FILE_FUNC("tcsetattr", file_tcsetattr, tFunc(tMapping tOr(tVoid, tStr), tInt01)) /* function(int: int(0..1)) */ @@ -180,6 +181,7 @@ FILE_FUNC("tcdrain", file_tcdrain, tFunc(tNone, tInt01)) /* FILE_FUNC("tcflow",file_tcflow,"function(string:int)"); */ /* FILE_FUNC("tcgetpgrp",file_tcgetpgrp,"function(void:int)"); */ /* FILE_FUNC("tcsetpgrp",file_tcsetpgrp,"function(int:int)"); */ +#endif #ifdef TIOCSWINSZ FILE_FUNC("tcsetsize", file_tcsetsize, tFunc(tIntPos tIntPos, tInt01)) #endif diff --git a/src/modules/_Stdio/termios.c b/src/modules/_Stdio/termios.c index 8e890729d3..1e243ca44e 100644 --- a/src/modules/_Stdio/termios.c +++ b/src/modules/_Stdio/termios.c @@ -126,6 +126,7 @@ #define FD (THIS->box.fd) #define ERRNO (THIS->my_errno) +#ifdef HAVE_TCGETATTR static int termios_bauds( int speed ) { switch (speed) @@ -158,6 +159,8 @@ static const struct { #undef c_oflag #undef c_lflag +#endif /* HAVE_TCGETATTR */ + void file_tcgetattr(INT32 args) { struct termios ti; @@ -168,6 +171,7 @@ void file_tcgetattr(INT32 args) pop_n_elems(args); +#ifdef HAVE_TCGETATTR if (tcgetattr(FD,&ti)) /* error */ { ERRNO=errno; @@ -216,6 +220,8 @@ void file_tcgetattr(INT32 args) n++; #endif +#endif /* HAVE_TCGETATTR */ + #ifdef TIOCGWINSZ { struct winsize winsize; @@ -235,6 +241,7 @@ void file_tcgetattr(INT32 args) } +#ifdef HAVE_TCGETATTR static int termios_speed( int speed ) { switch (speed) @@ -467,6 +474,8 @@ void file_tcsendbreak(INT32 args) push_int(!tcsendbreak(FD, len)); } +#endif /* HAVE_TCGETATTR */ + #ifdef TIOCSWINSZ /*! @decl int(0..1) tcsetsize(int rows, int cols) *! -- GitLab