File: speed.c

package info (click to toggle)
gambas3 3.13.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 51,876 kB
  • sloc: ansic: 149,522; cpp: 90,749; sh: 18,812; makefile: 1,761; perl: 1,536; xml: 482; cs: 342; python: 299
file content (66 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download
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
65
66
/***************************************************************************

  speed.c

  (c) 2019 BenoƮt Minisini <g4mba5@gmail.com>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2, or (at your option)
  any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  MA 02110-1301, USA.

***************************************************************************/

#define __SPEED_C

#include "config.h"
#include "speed.h"

#if OS_LINUX

#if ARCH_PPC
	#include <asm-generic/ioctls.h>
	#include <asm-generic/termbits.h>
#else
	#include <asm/termios.h>
#endif

int ioctl(int fd, unsigned long request, ...);

int SetCustomSpeed(int fd, int speed)
{
	struct termios2 io;
	
	if (ioctl(fd, TCGETS2, &io))
		return 1;
	
	io.c_cflag &= ~CBAUD;
	io.c_cflag |= BOTHER;
	io.c_ispeed = speed;
	io.c_ospeed = speed;
	
	if (ioctl(fd, TCSETS2, &io))
		return 1;
	
	return 0;
}

#else

int SetCustomSpeed(int fd, int speed)
{
	return 1;
}

#endif