ubase/libutil/tty.c

40 lines
711 B
C
Raw Normal View History

2013-08-14 10:38:43 -04:00
/* See LICENSE file for copyright and license details. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
2014-06-30 14:03:41 -04:00
2013-08-14 10:38:43 -04:00
#include "../util.h"
void
devtotty(int dev, int *tty_maj, int *tty_min)
{
*tty_maj = (dev >> 8) & 0xfff;
*tty_min = (dev & 0xff) | ((dev >> 12) & 0xfff00);
}
char *
ttytostr(int tty_maj, int tty_min)
{
const char *pts = "pts/";
2013-09-06 05:29:00 -04:00
const char *tty = "tty";
2013-08-14 10:38:43 -04:00
char *ttystr;
size_t len;
/* Up to 10k ttys */
len = strlen(pts) + 4 + 1;
ttystr = emalloc(len);
2013-08-14 10:38:43 -04:00
switch (tty_maj) {
case 136:
snprintf(ttystr, len, "%s%d", pts, tty_min);
break;
case 4:
snprintf(ttystr, len, "%s%d", tty, tty_min);
break;
2013-08-14 10:38:43 -04:00
default:
ttystr[0] = '?';
ttystr[1] = '\0';
break;
}
return ttystr;
}