【问题标题】:How to get CRTSCTS defined in termios.h?如何获取在 termios.h 中定义的 CRTSCTS?
【发布时间】:2020-05-22 14:11:49
【问题描述】:

我的机器在#ifdef __USE_MISC 中有CRTSCTS #defined,这会阻止我编译的C 程序使用它。

/usr/include/x86_64-linux-gnu/bits/termios.h:

...       
#define  B4000000 0010017
#define __MAX_BAUD B4000000
#ifdef __USE_MISC
# define CIBAUD   002003600000      /* input baud rate (not used) */
# define CMSPAR   010000000000      /* mark or space (stick) parity */
# define CRTSCTS  020000000000      /* flow control */
#endif

/* c_lflag bits */
#define ISIG    0000001
#define ICANON  0000002
...

如何在不将值 020000000000 侵入我的程序的情况下访问 CRTSCTS?

我已经#include <termios.h> 和许多其他标题。

我也在用:

#define __USE_POSIX199309
#define _POSIX_C_SOURCE 199309L
#include <time.h>    /* nanosleep needs lines above */

【问题讨论】:

  • #define __USE_POSIX199309 来自man feature_test_macros: These macros have names prefixed by two underscores (e.g., __USE_MISC). Programs should never define these macros directly
  • KamilCuk 是对的 - 你想用__USE_POSIX199309 完成什么?
  • 使用 __USE_POSIX199309 和类似的将没有效果。它们在“features.h”中未定义,然后构建。该过程会尝试确定您的平台并选择合适的定义。

标签: c ubuntu-18.04 termios flow-control


【解决方案1】:

__USE_MISC 宏是一个内部定义,虽然我想您可以自己定义它,但最好找到启用它的正确功能测试宏。

在我的 CentOS 7 系统上,/usr/include/features.h 有各种类型的宏,而且似乎__USE_MISC 是由_BSD_SOURCE_SVID_SOURCE 启用的;目前尚不清楚哪一个与您将需要的其他东西兼容。

... // features.h
#if defined _BSD_SOURCE || defined _SVID_SOURCE
# define __USE_MISC     1
#endif

在程序顶部尝试#define _BSD_SOURCE - 在所有包含之前 - 看看效果如何。

参考:http://man7.org/linux/man-pages/man7/feature_test_macros.7.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-01-12
    • 2014-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-30
    • 2012-06-18
    • 1970-01-01
    相关资源
    最近更新 更多