Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: nspr/pr/src/io/prstdio.c

Issue 2078763002: Delete bundled copy of NSS and replace with README. (Closed) Base URL: https://chromium.googlesource.com/chromium/deps/nss@master
Patch Set: Delete bundled copy of NSS and replace with README. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « nspr/pr/src/io/prsocket.c ('k') | nspr/pr/src/linking/prlink.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "primpl.h"
7
8 #include <string.h>
9
10 /*
11 ** fprintf to a PRFileDesc
12 */
13 PR_IMPLEMENT(PRUint32) PR_fprintf(PRFileDesc* fd, const char *fmt, ...)
14 {
15 va_list ap;
16 PRUint32 rv;
17
18 va_start(ap, fmt);
19 rv = PR_vfprintf(fd, fmt, ap);
20 va_end(ap);
21 return rv;
22 }
23
24 PR_IMPLEMENT(PRUint32) PR_vfprintf(PRFileDesc* fd, const char *fmt, va_list ap)
25 {
26 /* XXX this could be better */
27 PRUint32 rv, len;
28 char* msg = PR_vsmprintf(fmt, ap);
29 if (NULL == msg) {
30 return -1;
31 }
32 len = strlen(msg);
33 #ifdef XP_OS2
34 /*
35 * OS/2 really needs a \r for every \n.
36 * In the future we should try to use scatter-gather instead of a
37 * succession of PR_Write.
38 */
39 if (isatty(PR_FileDesc2NativeHandle(fd))) {
40 PRUint32 last = 0, idx;
41 PRInt32 tmp;
42 rv = 0;
43 for (idx = 0; idx < len+1; idx++) {
44 if ((idx - last > 0) && (('\n' == msg[idx]) || (idx == len))) {
45 tmp = PR_Write(fd, msg + last, idx - last);
46 if (tmp >= 0) {
47 rv += tmp;
48 }
49 last = idx;
50 }
51 /*
52 * if current character is \n, and
53 * previous character isn't \r, and
54 * next character isn't \r
55 */
56 if (('\n' == msg[idx]) &&
57 ((0 == idx) || ('\r' != msg[idx-1])) &&
58 ('\r' != msg[idx+1])) {
59 /* add extra \r */
60 tmp = PR_Write(fd, "\r", 1);
61 if (tmp >= 0) {
62 rv += tmp;
63 }
64 }
65 }
66 } else {
67 rv = PR_Write(fd, msg, len);
68 }
69 #else
70 rv = PR_Write(fd, msg, len);
71 #endif
72 PR_DELETE(msg);
73 return rv;
74 }
OLDNEW
« no previous file with comments | « nspr/pr/src/io/prsocket.c ('k') | nspr/pr/src/linking/prlink.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698