aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/dev/format.c
blob: 508ec6c27c66d14f0db62bdcf0075418ebe701f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * Specify serial port data line format.
 * $Id$
 * Copyright (c) 1997 by Tycho Softworks.
 * For conditions of distribution and reuse see product license.
 */

#include <dev/tty.h>
#ifndef	TERMIOS_H_MISSING
#include <termios.h>
#endif

int	setformat(stty_t stty, char *format)
{
#ifndef	TERMIOS_H_MISSING
	struct	termios *tios = stty;

	tios->c_cflag &= ~CSIZE;
	if(format[2] == '1')
		tios->c_cflag &= ~CSTOPB;
	else
		tios->c_cflag |= CSTOPB;

	switch(format[0])
	{
	case '5':
		tios->c_cflag |= CS5;
		break;
	case '6':
		tios->c_cflag |= CS6;
		break;
	case '7':
		tios->c_cflag |= CS7;
		break;
	case '8':
		tios->c_cflag |= CS8;
		break;
	}

	switch(format[1])
	{
	case 'n':
	case 'N':
		tios->c_cflag &= ~(PARODD | PARENB);
		break;
	case 'e':
	case 'E':
		tios->c_cflag |= PARENB;
		tios->c_cflag &= ~PARODD;
		break;	
	case 'o':
	case 'O':
		tios->c_cflag |= (PARENB | PARODD);
		break;
	}

#endif
	return 0;
}