File: ppsldisc.c

package info (click to toggle)
pps-tools 1.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 136 kB
  • sloc: ansic: 714; makefile: 24; sh: 12
file content (60 lines) | stat: -rw-r--r-- 1,284 bytes parent folder | download | duplicates (2)
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
/*
 * ppsldics.c -- setup PPS line discipline for RS232
 *
 * Copyright (C) 2005-2007   Rodolfo Giometti <giometti@linux.it>
 *
 *   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 of the License, 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.
 */


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <linux/tty.h>

void usage(char *name)
{
	fprintf(stderr, "usage: %s <ttyS>\n", name);

	exit(EXIT_FAILURE);
}

int main(int argc, char *argv[])
{
	int fd;
	int ldisc = N_PPS;
	int ret;

	if (argc < 2)
		usage(argv[0]);

	fd = open(argv[1], O_RDWR);
	if (fd < 0) {
		perror("open");
		exit(EXIT_FAILURE);
	}

	ret = ioctl(fd, TIOCSETD, &ldisc);
	if (ret < 0) {
		perror("ioctl(TIOCSETD)");
		exit(EXIT_FAILURE);
	}

	pause();

	return 0;
}