TIOCMSET(2const)

✨ TIOCMSET ✨ (that's the page name bestie, from the (2const) section πŸ’…)

okay so like. this one is titled TIOCMSET, and honestly the whole squad is here: TIOCMGET, TIOCMSET, TIOCMBIC, TIOCMBIS, TIOCMIWAIT, TIOCGICOUNT β€” they're all about modem control. yep. modem. control. the little wires in your serial port that talk to each other. it's giving vintage tech but she still ate 🌸


πŸ“š LIBRARY

Standard C library β€” that's libc, linked with -lc. your bestie libc has been carrying this whole thing, no cap 🫢


🌟 SYNOPSIS

#include <asm/termbits.h>  /* Definition of TIOC* constants */
#include <sys/ioctl.h>

int ioctl(int fd, TIOCMGET, int *argp);
int ioctl(int fd, TIOCMSET, const int *argp);
int ioctl(int fd, TIOCMBIC, const int *argp);
int ioctl(int fd, TIOCMBIS, const int *argp);
int ioctl(int fd, TIOCMIWAIT, int arg);
int ioctl(int fd, TIOCGICOUNT, struct serial_icounter_struct *argp);

#include <linux/serial.h>

struct serial_icounter_struct;

like yes, it's ioctl six different ways, they're all serving their own little purpose πŸ’œ


πŸ’– DESCRIPTION

πŸŽ€ TIOCMGET

Grab the status of the modem bits. just. read the vibe check of your modem bits, that's it.

πŸŽ€ TIOCMSET

Set the status of the modem bits. you're the main character now, you decide what the bits are doing.

πŸŽ€ TIOCMBIC

Clear the indicated modem bits. girl, clear it. set those specific bits to off.

πŸŽ€ TIOCMBIS

Set the indicated modem bits. opposite energy, we're turning them ON now ✨


The following bits are the ones these ioctls use β€” memorize them, they're iconic:

  • TIOCM_LE β€” DSR (data set ready/line enable)
  • TIOCM_DTR β€” DTR (data terminal ready)
  • TIOCM_RTS β€” RTS (request to send)
  • TIOCM_ST β€” Secondary TXD (transmit)
  • TIOCM_SR β€” Secondary RXD (receive)
  • TIOCM_CTS β€” CTS (clear to send)
  • TIOCM_CAR β€” DCD (data carrier detect)
  • TIOCM_CD β€” see TIOCM_CAR
  • TIOCM_RNG β€” RNG (ring)
  • TIOCM_RI β€” see TIOCM_RNG
  • TIOCM_DSR β€” DSR (data set ready)

πŸŽ€ TIOCMIWAIT

Wait for any of the 4 modem bits (DCD, RI, DSR, CTS) to change. the way that you just sit there and wait for something to happen… relatable honestly 😭

The bits of interest are specified as a bit mask in arg, by ORing together any of the bit values, TIOCM_RNG, TIOCM_DSR, TIOCM_CD, and TIOCM_CTS. The caller should use TIOCGICOUNT to see which bit has changed. iykyk β€” you don't get told who moved, you just know someone did.

πŸŽ€ TIOCGICOUNT

Get counts of input serial line interrupts (DCD, RI, DSR, CTS). The counts are written to the serial_icounter_struct structure pointed to by argp. receipts, basically. we keep track of everything here πŸ’…

Note: both 1->0 and 0->1 transitions are counted, except for RI, where only 0->1 transitions are counted. bestie RI is different. RI always is. πŸ™ˆ

βœ… RETURN VALUE

On success, 0 is returned. slay. On error, -1 is returned, and errno is set to indicate the error. so like, check errno if things went sideways πŸ’€


🧚 EXAMPLES

Check the condition of DTR on the serial port. that's it, that's the whole mission:

#include <asm/termbits.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>

int
main(void)
{
    int fd, serial;

    fd = open("/dev/ttyS0", O_RDONLY);
    ioctl(fd, TIOCMGET, &serial);
    if (serial & TIOCM_DTR)
        puts("TIOCM_DTR is set");
    else
        puts("TIOCM_DTR is not set");
    close(fd);
}

see how simple? open /dev/ttyS0, ask, check the bit, close. chef's kiss πŸ‘‘


πŸ‘€ SEE ALSO


okay that's the page!! ily, go forth and control those modem bits πŸ’– this little manual page is from Linux man-pages 6.20, dated 2026-02-08 β€” and it's the TIOCMSET(2const) page, so like, tag yourself, I'm TIOCMSET πŸŒˆπŸ’œ
πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: GPL-1.0-or-later
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms