mirror of
https://github.com/linux-msm/cdba.git
synced 2026-02-25 13:11:56 -08:00
tty: split tty_open to a separate file
Split the function tty_open() to a separate file. Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
This commit is contained in:
@@ -26,34 +26,6 @@ static const char *username;
|
||||
|
||||
struct device *selected_device;
|
||||
|
||||
int tty_open(const char *tty, struct termios *old)
|
||||
{
|
||||
struct termios tios;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
fd = open(tty, O_RDWR | O_NOCTTY | O_EXCL);
|
||||
if (fd < 0)
|
||||
err(1, "unable to open \"%s\"", tty);
|
||||
|
||||
ret = tcgetattr(fd, old);
|
||||
if (ret < 0)
|
||||
err(1, "unable to retrieve \"%s\" tios", tty);
|
||||
|
||||
memset(&tios, 0, sizeof(tios));
|
||||
tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
|
||||
tios.c_iflag = IGNPAR;
|
||||
tios.c_oflag = 0;
|
||||
|
||||
tcflush(fd, TCIFLUSH);
|
||||
|
||||
ret = tcsetattr(fd, TCSANOW, &tios);
|
||||
if (ret < 0)
|
||||
err(1, "unable to update \"%s\" tios", tty);
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
static void fastboot_opened(struct fastboot *fb, void *data)
|
||||
{
|
||||
const uint8_t one = 1;
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#include "cdba.h"
|
||||
|
||||
int tty_open(const char *tty, struct termios *old);
|
||||
|
||||
void cdba_send_buf(int type, size_t len, const void *buf);
|
||||
#define cdba_send(type) cdba_send_buf(type, 0, NULL)
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "cdba-server.h"
|
||||
#include "device.h"
|
||||
#include "tty.h"
|
||||
#include "watch.h"
|
||||
|
||||
struct console {
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cdba-server.h"
|
||||
#include "device.h"
|
||||
#include "tty.h"
|
||||
|
||||
struct alpaca {
|
||||
int alpaca_fd;
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cdba-server.h"
|
||||
#include "device.h"
|
||||
#include "status.h"
|
||||
#include "tty.h"
|
||||
#include "watch.h"
|
||||
|
||||
struct cdb_assist {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#include "cdba-server.h"
|
||||
#include "device.h"
|
||||
#include "status.h"
|
||||
#include "tty.h"
|
||||
#include "watch.h"
|
||||
|
||||
enum qcomlt_parse_state {
|
||||
|
||||
@@ -89,7 +89,8 @@ server_srcs = ['cdba-server.c',
|
||||
'ppps.c',
|
||||
'status.c',
|
||||
'status-cmd.c',
|
||||
'watch.c']
|
||||
'watch.c',
|
||||
'tty.c']
|
||||
|
||||
build_server = true
|
||||
foreach d: server_deps
|
||||
|
||||
42
tty.c
Normal file
42
tty.c
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2018, Linaro Ltd.
|
||||
* All rights reserved.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "tty.h"
|
||||
|
||||
int tty_open(const char *tty, struct termios *old)
|
||||
{
|
||||
struct termios tios;
|
||||
int ret;
|
||||
int fd;
|
||||
|
||||
fd = open(tty, O_RDWR | O_NOCTTY | O_EXCL);
|
||||
if (fd < 0)
|
||||
err(1, "unable to open \"%s\"", tty);
|
||||
|
||||
ret = tcgetattr(fd, old);
|
||||
if (ret < 0)
|
||||
err(1, "unable to retrieve \"%s\" tios", tty);
|
||||
|
||||
memset(&tios, 0, sizeof(tios));
|
||||
tios.c_cflag = B115200 | CS8 | CLOCAL | CREAD;
|
||||
tios.c_iflag = IGNPAR;
|
||||
tios.c_oflag = 0;
|
||||
|
||||
tcflush(fd, TCIFLUSH);
|
||||
|
||||
ret = tcsetattr(fd, TCSANOW, &tios);
|
||||
if (ret < 0)
|
||||
err(1, "unable to update \"%s\" tios", tty);
|
||||
|
||||
return fd;
|
||||
}
|
||||
Reference in New Issue
Block a user