Changeset 3629 for trunk/tools/common/kFile.cpp
- Timestamp:
- May 29, 2000, 9:45:58 PM (25 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/common/kFile.cpp
r3613 r3629 1 /* $Id: kFile.cpp,v 1. 2 2000-05-27 02:14:20bird Exp $1 /* $Id: kFile.cpp,v 1.3 2000-05-29 19:45:57 bird Exp $ 2 2 * 3 3 * kFile - Simple (for the time being) file class. … … 20 20 *******************************************************************************/ 21 21 #include <os2.h> 22 23 #include <malloc.h> 22 24 #include <string.h> 25 #include <stdarg.h> 26 #include <stdio.h> 23 27 24 28 #include <kFile.h> … … 212 216 213 217 /** 218 * printf - formatted write. 219 * 220 * Lonely '\n's are prefixed with a '\r' to make output conform with 221 * PC line ending. 222 * 223 * @returns Number of bytes written. 224 * @param pszFormat Format string. 225 * @param ... Ellipcis. 226 * @remark Currently limited to 64KB of result data. 227 */ 228 int kFile::printf(const char *pszFormat, ...) throw (int) 229 { 230 long offStart = getPos(); 231 va_list arg; 232 233 /* !QUICK AND DIRTY! */ 234 char * psz, * pszEnd; 235 char * pszBuffer = (char*)malloc(1024*64); //64KB should normally be enough... 236 237 va_start(arg, pszFormat); 238 pszEnd = vsprintf(pszBuffer, pszFormat, arg) + pszBuffer; 239 va_end(arg); 240 241 psz = pszEnd; 242 while (psz > pszBuffer) 243 { 244 if (*psz-- == '\n' && *psz != '\r') 245 { 246 memmove(psz+2, psz+1, pszEnd - psz + 1); 247 psz[1] = '\r'; 248 pszEnd++; 249 } 250 } 251 252 write(pszBuffer, pszEnd - pszBuffer); 253 free(pszBuffer); 254 255 return getPos() - offStart; 256 } 257 258 259 260 261 /** 214 262 * Seek relative to the current position. 215 263 * @returns Success indicator.
Note:
See TracChangeset
for help on using the changeset viewer.