summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwtc%netscape.com <devnull@localhost>2003-04-18 14:02:24 +0000
committerwtc%netscape.com <devnull@localhost>2003-04-18 14:02:24 +0000
commit23ea7dc66f2533de6da09a7a3bb6db748a9f93e0 (patch)
tree0dc6ea4a36bb1105649c72a99b7fee15e0eb188d
parentc000326732a89dfa8d46f5116efb4dec8fdf8579 (diff)
downloadnspr-hg-23ea7dc66f2533de6da09a7a3bb6db748a9f93e0.tar.gz
Bug 104529: on OS/2, when writing to the command-line console, we must
write \r\n to go to a new line. So we need to translate \n to \r\n. The patch is contributed by Julien Pierre.
-rw-r--r--pr/src/io/prstdio.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/pr/src/io/prstdio.c b/pr/src/io/prstdio.c
index 4ae2f267..de4c39de 100644
--- a/pr/src/io/prstdio.c
+++ b/pr/src/io/prstdio.c
@@ -56,7 +56,45 @@ PR_IMPLEMENT(PRUint32) PR_vfprintf(PRFileDesc* fd, const char *fmt, va_list ap)
PRUint32 rv, len;
char* msg = PR_vsmprintf(fmt, ap);
len = strlen(msg);
+#ifdef XP_OS2
+ /*
+ * OS/2 really needs a \r for every \n.
+ * In the future we should try to use scatter-gather instead of a
+ * succession of PR_Write.
+ */
+ if (isatty(PR_FileDesc2NativeHandle(fd))) {
+ PRUint32 last = 0, idx;
+ PRInt32 tmp;
+ rv = 0;
+ for (idx = 0; idx < len+1; idx++) {
+ if ((idx - last > 0) && (('\n' == msg[idx]) || (idx == len))) {
+ tmp = PR_Write(fd, msg + last, idx - last);
+ if (tmp >= 0) {
+ rv += tmp;
+ }
+ last = idx;
+ }
+ /*
+ * if current character is \n, and
+ * previous character isn't \r, and
+ * next character isn't \r
+ */
+ if (('\n' == msg[idx]) &&
+ ((0 == idx) || ('\r' != msg[idx-1])) &&
+ ('\r' != msg[idx+1])) {
+ /* add extra \r */
+ tmp = PR_Write(fd, "\r", 1);
+ if (tmp >= 0) {
+ rv += tmp;
+ }
+ }
+ }
+ } else {
+ rv = PR_Write(fd, msg, len);
+ }
+#else
rv = PR_Write(fd, msg, len);
+#endif
PR_DELETE(msg);
return rv;
}