Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

c++ - Including <termios.h> and <asm/termios.h> in the same project

What I want to achieve: I want to set custom baud rate values for some tty*-like UART-mapped terminals.

How: The only way I found by far is to use the struct termios2 structure which is located in<asm/termios> header (as mentioned here, first answer).

My solution works very well by far, but now I need to use some functions:

speed_t cfgetispeed(const struct termios *);
int     tcdrain(int);
int     tcflow(int, int);
int     tcflush(int, int);
int     tcgetattr(int, struct termios *);
pid_t   tcgetsid(int);
int     tcsendbreak(int, int);
int     tcsetattr(int, int, struct termios *);

The problem is that in <asm/termios.h> there are no such functions, and I need to include <termios.h> for being able to use them.

Problem: If I include both headers (<asm/termios.h> and <termios.h>) the compiler will scream about functions and structure re-declaration, and he's right.

How can I solve this without using some obscure practice (like wrapping one of headers in a namespace, like mentioned here)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

How can I solve this without using some obscure practice (like wrapping one of headers in a namespace, like mentioned here)?

If you find namespaces obscure, I don't know how you'd call this:

#define termios asmtermios
#include <asm/termios.h>
#undef  termios
#include <termios.h>

Anyway, this too gets you rid of the error: redefinition of 'struct termios'.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...