This is the mail archive of the
cygwin-patches
mailing list for the Cygwin project.
Fixes for cfget[io]speed
- From: "Yaakov (Cygwin/X)" <yselkowitz at users dot sourceforge dot net>
- To: cygwin-patches <cygwin-patches at cygwin dot com>
- Date: Tue, 11 Jan 2011 03:36:15 -0600
- Subject: Fixes for cfget[io]speed
I discovered some compliance issues with cfget[io]speed:
* POSIX requires these to be declared (at least) as functions[1];
* POSIX requires their argument to be const[1];
* the macros are not safe for C++ code.
The following patch fixes these issues, providing that constifying the
arguments doesn't change the ABI.
Yaakov
[1]
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/termios.h.html
2011-01-11 Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
* termios.cc (cfgetospeed, cfgetispeed): Constify argument per POSIX.
* include/sys/termios.h (cfgetospeed, cfgetispeed): Declare functions.
Move macros after declarations and make conditional on !__cplusplus.
Index: termios.cc
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/termios.cc,v
retrieving revision 1.35
diff -u -r1.35 termios.cc
--- termios.cc 2 Aug 2009 21:38:40 -0000 1.35
+++ termios.cc 11 Jan 2011 09:07:38 -0000
@@ -232,14 +232,14 @@
/* cfgetospeed: POSIX96 7.1.3.1 */
extern "C" speed_t
-cfgetospeed (struct termios *tp)
+cfgetospeed (const struct termios *tp)
{
return __tonew_termios (tp)->c_ospeed;
}
/* cfgetispeed: POSIX96 7.1.3.1 */
extern "C" speed_t
-cfgetispeed (struct termios *tp)
+cfgetispeed (const struct termios *tp)
{
return __tonew_termios (tp)->c_ispeed;
}
Index: include/sys/termios.h
===================================================================
RCS file: /cvs/src/src/winsup/cygwin/include/sys/termios.h,v
retrieving revision 1.18
diff -u -r1.18 termios.h
--- include/sys/termios.h 23 Oct 2010 18:07:08 -0000 1.18
+++ include/sys/termios.h 11 Jan 2011 09:07:39 -0000
@@ -317,9 +317,6 @@
#define termio termios
-#define cfgetospeed(tp) ((tp)->c_ospeed)
-#define cfgetispeed(tp) ((tp)->c_ispeed)
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -331,6 +328,8 @@
int tcflush (int, int);
int tcflow (int, int);
void cfmakeraw (struct termios *);
+speed_t cfgetispeed(const struct termios *);
+speed_t cfgetospeed(const struct termios *);
int cfsetispeed (struct termios *, speed_t);
int cfsetospeed (struct termios *, speed_t);
@@ -338,6 +337,11 @@
}
#endif
+#ifndef __cplusplus
+#define cfgetispeed(tp) ((tp)->c_ispeed)
+#define cfgetospeed(tp) ((tp)->c_ospeed)
+#endif
+
/* Extra stuff to make porting stuff easier. */
struct winsize
{