annotate libserial-posix/openport.c @ 925:85d144f9fe56

rvinterf/lowlevel/format.c: forgot to add #include <ctype.h>
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 23 May 2023 03:21:02 +0000
parents fd7b447b99e3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
248
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements the basic serial port opening operation.
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/file.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/ioctl.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <unistd.h>
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int target_fd;
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 open_serial_port(ttyport)
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *ttyport;
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 target_fd = open(ttyport, O_RDWR|O_NONBLOCK);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (target_fd < 0) {
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 perror(ttyport);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 exit(1);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 }
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 ioctl(target_fd, TIOCEXCL);
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return 0;
cb1ba53a1106 beginning of factored-out libserial
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 }