morpheus-base

morpheus base system
git clone git://git.2f30.org/morpheus-base
Log | Files | Refs

tty.c (711B)


      1 /* See LICENSE file for copyright and license details. */
      2 #include <stdio.h>
      3 #include <stdlib.h>
      4 #include <string.h>
      5 
      6 #include "../util.h"
      7 
      8 void
      9 devtotty(int dev, int *tty_maj, int *tty_min)
     10 {
     11 	*tty_maj = (dev >> 8) & 0xfff;
     12 	*tty_min = (dev & 0xff) | ((dev >> 12) & 0xfff00);
     13 }
     14 
     15 char *
     16 ttytostr(int tty_maj, int tty_min)
     17 {
     18 	const char *pts = "pts/";
     19 	const char *tty = "tty";
     20 	char *ttystr;
     21 	size_t len;
     22 
     23 	/* Up to 10k ttys */
     24 	len = strlen(pts) + 4 + 1;
     25 	ttystr = emalloc(len);
     26 	switch (tty_maj) {
     27 	case 136:
     28 		snprintf(ttystr, len, "%s%d", pts, tty_min);
     29 		break;
     30 	case 4:
     31 		snprintf(ttystr, len, "%s%d", tty, tty_min);
     32 		break;
     33 	default:
     34 		ttystr[0] = '?';
     35 		ttystr[1] = '\0';
     36 		break;
     37 	}
     38 	return ttystr;
     39 }