uart: added flush logic before close. 03/151603/1
authorSegwon <segwon.han@samsung.com>
Thu, 21 Sep 2017 08:43:06 +0000 (17:43 +0900)
committerSegwon <segwon.han@samsung.com>
Thu, 21 Sep 2017 08:44:00 +0000 (17:44 +0900)
Signed-off-by: Segwon <segwon.han@samsung.com>
Change-Id: I639ade4199c50518974b7a5f94c2752677d144b5

src/interface/uart.c

index fd15ca5..b18d18d 100644 (file)
@@ -77,13 +77,31 @@ int uart_open(int port, int *file_hndl)
 
 int uart_close(int file_hndl)
 {
+       int status;
+
        _D("file_hndl : %d", file_hndl);
 
-       if (!file_hndl) {
+       if (file_hndl < 0) {
                _E("Invalid NULL parameter");
                return -EINVAL;
        }
-       close(file_hndl);
+
+       status = uart_flush(file_hndl);
+       if (status < 0) {
+               char errmsg[MAX_ERR_LEN];
+               strerror_r(errno, errmsg, MAX_ERR_LEN);
+               _E("Failed to close fd : %d, errmsg : %s", file_hndl, errmsg);
+               return -EIO;
+       }
+
+       status = close(file_hndl);
+       if (status < 0) {
+               char errmsg[MAX_ERR_LEN];
+               strerror_r(errno, errmsg, MAX_ERR_LEN);
+               _E("Failed to close fd : %d, errmsg : %s", file_hndl, errmsg);
+               return -EIO;
+       }
+
        return 0;
 }