prstdio.c (846B)
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 va_list ap; 15 PRUint32 rv; 16 17 va_start(ap, fmt); 18 rv = PR_vfprintf(fd, fmt, ap); 19 va_end(ap); 20 return rv; 21 } 22 23 PR_IMPLEMENT(PRUint32) 24 PR_vfprintf(PRFileDesc* fd, const char* fmt, va_list ap) { 25 /* XXX this could be better */ 26 PRUint32 rv, len; 27 char* msg = PR_vsmprintf(fmt, ap); 28 if (NULL == msg) { 29 return -1; 30 } 31 len = strlen(msg); 32 rv = PR_Write(fd, msg, len); 33 PR_DELETE(msg); 34 return rv; 35 }