posix: fix return value of write, fixes #189
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 980430c..dcc71a0 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -516,7 +516,7 @@
         if not self.is_open:
             raise portNotOpenError
         d = to_bytes(data)
-        tx_len = len(d)
+        tx_len = length = len(d)
         timeout = Timeout(self._write_timeout)
         while tx_len > 0:
             try:
@@ -555,7 +555,7 @@
                 # still calculate and check timeout
                 if timeout.expired():
                     raise writeTimeoutError
-        return len(d)
+        return length - len(d)
 
     def flush(self):
         """\