Index: IIO.c
===================================================================
--- IIO.c	(revision 14602)
+++ IIO.c	(working copy)
@@ -100,6 +100,11 @@
     @param[in]      N         Number of bytes in buf.
 
     @retval   >=0    Number of bytes sent to the output device.
+
+    NOTE: The updated code below maintains the same logic that originally
+          existed but seemed a bit strange to me.  It won't write anything
+          if the first byte of buf is a zero (z-term), but will write out
+          one zero if encountered anywhere else and then stop writing.
 **/
 static
 ssize_t
@@ -114,93 +119,181 @@
   cFIFO      *OutBuf;
   mbstate_t  *OutState;
   char       *MbcsPtr;
+  ssize_t     TotalNumBytesWritten;
   ssize_t     NumWritten;
   ssize_t     NumProc;
-  size_t      CharLen;
+  ssize_t     NumProcW;
+  ssize_t     CharLen;
   UINTN       MaxColumn;
   UINTN       MaxRow;
   wchar_t     OutChar[2];     // Just in case we run into 4-byte MBCS character
   int         OutMode;
 
-  errno = 0;          // indicate no error as default
-  NumWritten = -1;
+  TotalNumBytesWritten = -1;
 
   /* Determine what the current screen size is. Also validates the output device. */
   OutMode = IIO_GetOutputSize(filp->MyFD, &MaxColumn, &MaxRow);
-
-  This = filp->devdata;
-  if((This != NULL) && (OutMode >= 0)) {
-    if(filp->MyFD == STDERR_FILENO) {
-      OutBuf = This->ErrBuf;
-      OutState  = &This->ErrState;
+  /* Ensure mode was obtained */
+  if(OutMode >= 0) {
+    /* Get cIIO structure for file descriptor */
+    This = filp->devdata;
+    /* Ensure valid file descriptor data */
+    if(This == NULL) {
+      errno = EINVAL;
     }
-    else {
-      OutBuf = This->OutBuf;
-      OutState  = &This->OutState;
-    }
+    else  {
+      // if we get this far we will report based on number actually output
+      TotalNumBytesWritten = 0;
 
-    /*  Set the maximum screen dimensions. */
-    This->MaxColumn = MaxColumn;
-    This->MaxRow    = MaxRow;
-
-    /*  Record where the cursor is at the beginning of the Output operation. */
-    (void)IIO_GetCursorPosition(filp->MyFD, &This->InitialXY.Column, &This->InitialXY.Row);
-    This->CurrentXY.Column  = This->InitialXY.Column;
-    This->CurrentXY.Row     = This->InitialXY.Row;
-
-
-    NumWritten = 0;
-    OutChar[0] = (wchar_t)buf[0];
-    while((OutChar[0] != 0) && (NumWritten < N)) {
-      CharLen = mbrtowc(OutChar, (const char *)&buf[NumWritten], MB_CUR_MAX, OutState);
-      NumProc = IIO_WriteOne(filp, OutBuf, OutChar[0]);
-      if(NumProc > 0) {
-        // Successfully processed and buffered one character
-        NumWritten += CharLen;   // Index of start of next character
+      /* Get the cFIFO object to use */
+      if(filp->MyFD == STDERR_FILENO) {
+        OutBuf = This->ErrBuf;
+        OutState  = &This->ErrState;
       }
-      else if(NumProc == -1) {
-        // Encoding Error
-        (void)mbrtowc(NULL, NULL, 1, OutState);  // Re-Initialize the conversion state
-        errno = EILSEQ;
-        break;
-      }
       else {
-        // Last character was incomplete
-        break;
+        OutBuf = This->OutBuf;
+        OutState  = &This->OutState;
       }
-    }
-    // At this point, the characters to write are in OutBuf
-    // First, linearize the buffer
-    NumWritten = OutBuf->Copy(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);
-    gMD->UString[NumWritten] = 0;   // Ensure that the buffer is terminated
 
-    if(filp->f_iflags & _S_IWTTY) {
-      // Output device expects wide characters, Output what we have
-      NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, gMD->UString);
-    }
-    else {
-      // Output device expects narrow characters, convert to MBCS
-      MbcsPtr = (char *)gMD->UString2;
-      // Determine the needed space
-      NumProc = (ssize_t)EstimateWtoM((const wchar_t *)gMD->UString, UNICODE_STRING_MAX * sizeof(wchar_t), &CharLen);
+      /*  Set the maximum screen dimensions. */
+      This->MaxColumn = MaxColumn;
+      This->MaxRow    = MaxRow;
 
-      // Now translate this into MBCS in Buffer
-      NumWritten = wcstombs(MbcsPtr, (const wchar_t *)gMD->UString, NumProc);
-      MbcsPtr[NumWritten] = 0;   // Ensure the buffer is terminated
+      /*  Record where the cursor is at the beginning of the Output operation. */
+      (void)IIO_GetCursorPosition(filp->MyFD, &This->InitialXY.Column, &This->InitialXY.Row);
+      This->CurrentXY.Column  = This->InitialXY.Column;
+      This->CurrentXY.Row     = This->InitialXY.Row;
 
-      // Send the MBCS buffer to Output
-      NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, MbcsPtr);
+      // get next buffer character - see notes above function definition above.
+      OutChar[0] = (wchar_t)buf[0];
+
+      // continue looping to support writing in chunks to support wrapping backspace
+      while(N>0) {
+        // variable to track the number of bytes converted from buf to wide chars
+        NumProc = 0;  
+        // loop to translate and output chars to a cFIFO buffer
+        while(N>0) {
+          // see notes above function definition above.
+          if (OutChar[0] == 0) {
+            N = 0;
+            break;
+          }
+          // get width of character in bytes
+          CharLen = mbrtowc(OutChar, (const char *)buf, MB_CUR_MAX, OutState);
+          // handle encoding errors
+          if(CharLen < 0) {
+            // encoding error
+            (void)mbrtowc(NULL, NULL, 1, OutState);  // Re-Initialize the conversion state
+            errno = EILSEQ;
+            N = 0;
+            break;
+          }
+
+          // output the wide character to cFIFO buffer (NOTE: also tracks CurrentXY)
+          NumProcW = IIO_WriteOne(filp, OutBuf, OutChar[0]);
+
+          if(NumProcW > 0) {
+            // Successfully processed and buffered one multi-byte character as a wide character
+            NumProc += CharLen;
+            buf += CharLen;
+            N -= CharLen;
+          }
+          else if(NumProcW == -1) {
+            // Encoding Error
+            (void)mbrtowc(NULL, NULL, 1, OutState);  // Re-Initialize the conversion state
+            errno = EILSEQ;
+            N = 0;
+            break;
+          }
+          else {
+            // Last character was incomplete - check if it was backspace due to column 0
+            if(OutChar[0] == CHAR_BACKSPACE && This->CurrentXY.Column == 0) {
+              // ensure any prior output already processed
+              if (NumProc==0) {
+                // handle wrapping 
+                if(This->CurrentXY.Row > 0) {
+                  // change cursor position
+                  This->CurrentXY.Column = (UINT32) This->MaxColumn - 1;
+                  This->CurrentXY.Row--;
+                  IIO_SetCursorPosition(filp, &This->CurrentXY);
+                }
+                // always eat backspace even if no action
+                TotalNumBytesWritten += CharLen;
+                // continue to next char
+                buf += CharLen;
+                N -= CharLen;
+                continue;
+              }
+              // go process what is already buffered
+              break;
+            }
+            // something stopped it so force end of loop to prevent deadlock loop
+            N = 0;
+            break;
+          }
+        }
+        //
+        // At this point, the characters to write are in OutBuf (or at least some may be)
+        //
+
+        // First, linearize the buffer (Create string from cFIFO)
+        NumProcW = OutBuf->Copy(OutBuf, gMD->UString, UNICODE_STRING_MAX-1);
+        gMD->UString[NumProcW] = 0;   // Ensure that the buffer is terminated
+
+        if(filp->f_iflags & _S_IWTTY) {
+          // Output device expects wide characters, Output what we have
+          NumWritten = filp->f_ops->fo_write(filp, NULL, NumProcW, gMD->UString);
+          // check if all wchars written
+          if(NumWritten != NumProcW) {
+            // convert the num written to the number of bytes
+            // note: using NumProc becuase it will no longer be needed
+            NumProc = NumWritten;
+            for(N = 0, NumWritten = 0; N < NumProc; N++) {
+              NumWritten += OneWcToMcLen(gMD->UString[N]);
+            }
+            // error on write so force loops to end
+            N = 0;
+            errno = EIO; // could perhaps also do: errno=EFI2errno(EFIerrno);
+          }
+          else {
+            // convert NumWritten to be bytes from input buf processed
+            NumWritten = NumProc;
+          }
+        }
+        else {
+          // NOTE: this section doesn't do any error checking of unicode to multi-byte
+          // conversion.  Presumably because we converted from a multi-byte string
+          // to begin with.
+
+          // Output device expects narrow characters, convert to MBCS
+          MbcsPtr = (char *)gMD->UString2;
+
+          // Now translate this into MBCS in Buffer
+          NumWritten = wcstombs(MbcsPtr, (const wchar_t *)gMD->UString, UNICODE_STRING_MAX * sizeof(wchar_t));
+          MbcsPtr[NumWritten] = 0;   // Ensure the buffer is terminated
+
+          // Send the MBCS buffer to Output 
+          CharLen = NumWritten;
+          NumWritten = filp->f_ops->fo_write(filp, NULL, NumWritten, MbcsPtr);
+
+          // check for failure on write
+          if(NumWritten != CharLen) {
+            // force loops to end
+            N = 0;
+            errno = EIO; // could perhaps also do: errno=EFI2errno(EFIerrno);
+          }
+        }
+        // Consume the translated characters. We want to ensure that whatever was supposed
+        // to output is removed from the FIFO buffer or it could become stuck and affect
+        // the next attempt to write to same handle.
+        (void)OutBuf->Flush(OutBuf, NumProcW);
+        // count them (in bytes)
+        TotalNumBytesWritten += NumWritten;
+      }
     }
-    // Consume the translated characters
-    (void)OutBuf->Flush(OutBuf, NumWritten);
   }
-  else {
-    if(This == NULL) {
-      errno = EINVAL;
-    }
-    // Otherwise, errno is already set.
-  }
-  return NumWritten;
+
+  return TotalNumBytesWritten;
 }
 
 /** Echo a character to an output device.
Index: IIOwrite.c
===================================================================
--- IIOwrite.c	(revision 14602)
+++ IIOwrite.c	(working copy)
@@ -176,14 +176,18 @@
         CurColumn = ModuloAdd(PrevColumn, AdjColumn, (UINT32)This->MaxColumn);
         if(CurColumn < PrevColumn) {
           // We must have wrapped, so we are on the next Row
-          ++CurRow;
-          if(CurRow >= This->MaxRow) {
-            // The screen has scrolled so need to adjust Initial location.
-            --This->InitialXY.Row;        // Initial row has moved up one
-            CurRow = (UINT32)(This->MaxRow - 1);    // We stay on the bottom row
-          }
+          AdjRow=1;
         }
       }
+      if(AdjRow!= 0) {
+        CurRow += AdjRow;
+        if(CurRow >= This->MaxRow) {
+          // The screen has scrolled so need to adjust Initial location.
+          --This->InitialXY.Row;        // Initial row has moved up one (can go negative)
+          CurRow = (UINT32)(This->MaxRow - 1);    // We stay on the bottom row
+        }
+      }
+
       This->CurrentXY.Column  = CurColumn;
       This->CurrentXY.Row     = CurRow;
     }
