putf.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
  3. *
  4. * Copyright (c) 1990, 1993
  5. * The Regents of the University of California. All rights reserved.
  6. *
  7. * This code is partly derived from software contributed to Berkeley by
  8. * Chris Torek, but heavily rewritten for Nut/OS.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. *
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of the copyright holders nor the names of
  20. * contributors may be used to endorse or promote products derived
  21. * from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  24. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  25. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  26. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  27. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  28. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  29. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  30. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  31. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  32. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  33. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  34. * SUCH DAMAGE.
  35. *
  36. * For additional information see http://www.ethernut.de/
  37. *
  38. */
  39. /*
  40. * $Log$
  41. * Revision 1.18 2009/03/05 22:58:05 freckle
  42. * don't follow __arm__ if __NUT_EMULATION__
  43. *
  44. * Revision 1.17 2009/02/13 14:52:05 haraldkipp
  45. * Include memdebug.h for heap management debugging support.
  46. *
  47. * Revision 1.16 2009/01/17 11:26:38 haraldkipp
  48. * Getting rid of two remaining BSD types in favor of stdint.
  49. * Replaced 'u_int' by 'unsinged int' and 'uptr_t' by 'uintptr_t'.
  50. *
  51. * Revision 1.15 2008/08/11 06:59:40 haraldkipp
  52. * BSD types replaced by stdint types (feature request #1282721).
  53. *
  54. * Revision 1.14 2008/07/08 13:26:58 haraldkipp
  55. * Floating point bug with avr-libc 1.16 fixed (bug #1871390).
  56. *
  57. * Revision 1.13 2008/06/28 07:49:33 haraldkipp
  58. * Added floating point support for stdio running on ARM.
  59. *
  60. * Revision 1.12 2008/04/18 13:22:26 haraldkipp
  61. * Added type casts to fix ICCAVR V7.16 compile errors.
  62. *
  63. * Revision 1.11 2005/04/19 10:21:30 haraldkipp
  64. * Support for size_t modifier added. Thanks to Tom Lynn
  65. *
  66. * Revision 1.10 2004/11/24 15:24:07 haraldkipp
  67. * Floating point configuration works again.
  68. *
  69. * Revision 1.9 2004/08/18 16:30:05 haraldkipp
  70. * Compile error on non-Harvard architecture fixed
  71. *
  72. * Revision 1.8 2004/03/16 16:48:27 haraldkipp
  73. * Added Jan Dubiec's H8/300 port.
  74. *
  75. * Revision 1.7 2003/12/17 14:33:24 drsung
  76. * Another bug fix for putf. Thanks to Dusan Ferbas.
  77. *
  78. * Revision 1.6 2003/12/12 23:14:11 drsung
  79. * Rewritten %P handling for program space strings
  80. *
  81. * Revision 1.5 2003/12/12 20:23:17 drsung
  82. * Fixed %P handling
  83. *
  84. * Revision 1.4 2003/11/26 12:45:20 drsung
  85. * Portability issues ... again
  86. *
  87. * Revision 1.3 2003/11/24 18:21:50 drsung
  88. * Added support for program space strings (%P)
  89. *
  90. * Revision 1.2 2003/08/14 15:21:51 haraldkipp
  91. * Formatted output of unsigned int fixed
  92. *
  93. * Revision 1.1.1.1 2003/05/09 14:40:32 haraldkipp
  94. * Initial using 3.2.1
  95. *
  96. * Revision 1.1 2003/02/04 17:49:08 harald
  97. * *** empty log message ***
  98. *
  99. */
  100. #include <cfg/crt.h>
  101. #include <toolchain.h>
  102. #include <string.h>
  103. #include "nut_io.h"
  104. #include <stdlib.h>
  105. #include <memdebug.h>
  106. /*!
  107. * \addtogroup xgCrtStdio
  108. */
  109. /*@{*/
  110. #ifdef STDIO_FLOATING_POINT
  111. #include <math.h>
  112. #if defined(__arm__)
  113. /*
  114. * Newlib needs _sbrk for floating point conversion. Because newlib
  115. * libraries are linked after Nut/OS libraries, this function is referenced
  116. * too late. So we include a reference here to force _sbrk inclusion.
  117. * This reference should depend on newlib usage, not generally on ARM CPUs,
  118. * but how to find out if we have newlib or not?
  119. */
  120. extern char *_sbrk(size_t nbytes);
  121. char *(*sbrk_force)(size_t) = _sbrk;
  122. #endif
  123. #endif /* STDIO_FLOATING_POINT */
  124. #define BUF 24
  125. #define DEFPREC 6
  126. #define PADSIZE 16
  127. static const char blanks[PADSIZE] PROGMEM = {
  128. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
  129. ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
  130. };
  131. static const char zeroes[PADSIZE] PROGMEM = {
  132. '0', '0', '0', '0', '0', '0', '0', '0',
  133. '0', '0', '0', '0', '0', '0', '0', '0'
  134. };
  135. static const char HEXDIGIT[32] PROGMEM = {
  136. '0', '1', '2', '3', '4', '5', '6', '7',
  137. '8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
  138. '0', '1', '2', '3', '4', '5', '6', '7',
  139. '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'
  140. };
  141. /*
  142. *
  143. */
  144. #ifdef __HARVARD_ARCH__
  145. static void _putpad(int _putb(int fd, PGM_P, size_t), int fd, PGM_P padch, int count)
  146. #else
  147. static void _putpad(int _putb(int fd, const void *, size_t), int fd, const char *padch, int count)
  148. #endif
  149. {
  150. while (count > PADSIZE) {
  151. _putb(fd, padch, PADSIZE);
  152. count -= PADSIZE;
  153. }
  154. if (count > 0)
  155. _putb(fd, padch, count);
  156. }
  157. /*
  158. * Flags used during conversion.
  159. */
  160. #define ALT 0x01 /* alternate form */
  161. #define LADJUST 0x04 /* left adjustment */
  162. #define LONGINT 0x08 /* long integer */
  163. #define ZEROPAD 0x10 /* zero (as opposed to blank) pad */
  164. #define LONGLONG 0x20 /* long long integer*/
  165. #define UNSIGNED 0x40 /* unsigned integer*/
  166. #ifdef STDIO_64_BIT
  167. #define ULTYPE uint64_t
  168. #define LLTYPE long long
  169. uint64_t va_args_ulval(int flags, va_list *ap)
  170. {
  171. uint64_t result;
  172. if (flags & LONGLONG)
  173. result = va_arg(*ap, uint64_t);
  174. else if (flags & LONGINT)
  175. result = (uint64_t)va_arg(*ap, uint32_t);
  176. else if (flags & UNSIGNED)
  177. result = (uint64_t)va_arg(*ap, unsigned int);
  178. else
  179. result = (uint64_t)va_arg(*ap, int);
  180. return result;
  181. }
  182. #else
  183. #define ULTYPE uint32_t
  184. #define LLTYPE long
  185. uint32_t va_args_ulval(int flags, va_list *ap)
  186. {
  187. uint32_t result;
  188. if (flags & LONGINT)
  189. result = va_arg(*ap, uint32_t);
  190. else if (flags & UNSIGNED)
  191. result = (uint32_t)va_arg(*ap, unsigned int);
  192. else
  193. result = (uint32_t)va_arg(*ap, int);
  194. return result;
  195. }
  196. #endif
  197. /*!
  198. * \brief Write formatted data using a given output function.
  199. *
  200. * \param _putb Output function for writing data.
  201. * \param fd Descriptor of a previously opened file, device or
  202. * connected socket.
  203. * \param fmt Format string containing conversion specifications.
  204. * \param ap List of arguments.
  205. *
  206. *
  207. */
  208. int _putf(int _putb(int, const void *, size_t),
  209. #ifdef __HARVARD_ARCH__
  210. int _putb_P (int, PGM_P, size_t),
  211. #endif
  212. int fd, const char *fmt, va_list ap)
  213. {
  214. uint8_t ch; /* character from fmt */
  215. int n; /* handy integer (short term usage) */
  216. char *cp; /* handy char pointer (short term usage) */
  217. uint8_t flags; /* flags as above */
  218. int rc; /* return value accumulator */
  219. int width; /* width from format (%8d), or 0 */
  220. int prec; /* precision from format (%.3d), or -1 */
  221. int dprec; /* a copy of prec if [diouxX], 0 otherwise */
  222. int realsz; /* field size expanded by dprec, sign, etc */
  223. uint8_t sign; /* sign prefix (' ', '+', '-', or \0) */
  224. ULTYPE ulval; /* long integer arguments %[diouxX] */
  225. int size; /* size of converted field or string */
  226. #ifdef __HARVARD_ARCH__
  227. char *xdigs; /* for %P malloc'd string*/
  228. #endif
  229. PGM_P hexdigs; /* digits for [xX] conversion */
  230. char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
  231. #ifdef STDIO_FLOATING_POINT
  232. double _double; /* double precision arguments %[eEfgG] */
  233. #ifdef __IMAGECRAFT__
  234. int iccfmt;
  235. int fps;
  236. extern char *FormatFP_1(int format, float f, unsigned flag, int field_width, int prec);
  237. extern char *ftoa(float f, int *status);
  238. #else /* __IMAGECRAFT__ */
  239. char *dtostre(double f, char *str, uint8_t prec, uint8_t flags);
  240. #if __AVR_LIBC_VERSION__ >= 10600
  241. char *dtostrf(double f, signed char width, unsigned char prec, char *str);
  242. #else /* __AVR_LIBC_VERSION__ */
  243. char *dtostrf(double f, char width, char prec, char *str);
  244. #endif /* __AVR_LIBC_VERSION__ */
  245. #endif /* __IMAGECRAFT__ */
  246. #endif /* STDIO_FLOATING_POINT */
  247. rc = 0;
  248. for (;;) {
  249. /*
  250. * Print format string until next percent sign.
  251. */
  252. for (cp = (char *) fmt; (ch = *fmt) != 0 && ch != '%'; fmt++);
  253. if ((n = fmt - cp) != 0) {
  254. _putb(fd, cp, n);
  255. rc += n;
  256. }
  257. if (ch == 0)
  258. break;
  259. fmt++;
  260. /*
  261. * Process modifiers.
  262. */
  263. flags = 0;
  264. sign = 0;
  265. width = 0;
  266. dprec = 0;
  267. prec = -1;
  268. #if defined(STDIO_FLOATING_POINT) && defined(__IMAGECRAFT__)
  269. iccfmt = 0;
  270. #endif
  271. for (;;) {
  272. ch = *fmt++;
  273. if (ch == ' ') {
  274. if (!sign)
  275. sign = ' ';
  276. } else if (ch == '+')
  277. sign = '+';
  278. else if (ch == '-')
  279. flags |= LADJUST;
  280. else if (ch == '#')
  281. flags |= ALT;
  282. else if (ch == '0')
  283. flags |= ZEROPAD;
  284. else if (ch == 'l') {
  285. if(*fmt == 'l') {
  286. flags |= LONGLONG;
  287. ch = *fmt++;
  288. }
  289. else
  290. flags |= LONGINT;
  291. }
  292. else if (ch == 'z') {
  293. if (sizeof(size_t) > sizeof(int)) {
  294. flags |= LONGINT;
  295. }
  296. }
  297. else if (ch == '*') {
  298. width = va_arg(ap, int);
  299. if (width < 0) {
  300. flags |= LADJUST;
  301. width = -width;
  302. }
  303. } else if (ch == '.') {
  304. if (*fmt == '*') {
  305. fmt++;
  306. prec = va_arg(ap, int);
  307. } else {
  308. prec = 0;
  309. while (*fmt >= '0' && *fmt <= '9')
  310. prec = 10 * prec + (*fmt++ - '0');
  311. }
  312. if (prec < 0)
  313. prec = -1;
  314. } else if (ch >= '1' && ch <= '9') {
  315. width = ch - '0';
  316. while (*fmt >= '0' && *fmt <= '9')
  317. width = 10 * width + (*fmt++ - '0');
  318. } else
  319. break;
  320. }
  321. /*
  322. * Process type field.
  323. */
  324. switch (ch) {
  325. case 'c':
  326. *(cp = buf) = va_arg(ap, int);
  327. size = 1;
  328. sign = 0;
  329. break;
  330. case 'P':
  331. #ifdef __HARVARD_ARCH__
  332. /*
  333. * Thanks to Ralph Mason and Damian Slee, who provided some ideas of
  334. * handling prog_char strings
  335. */
  336. cp = va_arg(ap, char *); /* retrieve pointer */
  337. if (cp == 0) { /* if NULL pointer jump to std %s handling */
  338. ch = 's'; /* manipulate ch, so 'free' is later not called */
  339. goto putf_s;
  340. }
  341. size = strlen_P((PGM_P)cp); /* get length of string */
  342. xdigs = malloc(size + 1); /* allocate buffer to store string */
  343. strcpy_P(xdigs, (PGM_P)cp); /* copy the string to RAM */
  344. cp = xdigs; /* use cp for further processing */
  345. goto putf_s; /* jump to std %s handling */
  346. #endif /* __HARVARD_ARCH__ */
  347. case 's':
  348. cp = va_arg(ap, char *);
  349. #ifdef __HARVARD_ARCH__
  350. putf_s:
  351. #endif /* __HARVARD_ARCH__ */
  352. if (cp == 0)
  353. cp = "(null)";
  354. if (prec >= 0) {
  355. char *p = memchr(cp, 0, (size_t) prec);
  356. if (p) {
  357. size = p - cp;
  358. if (size > prec)
  359. size = prec;
  360. } else
  361. size = prec;
  362. } else
  363. size = strlen(cp);
  364. sign = 0;
  365. break;
  366. case 'u':
  367. sign = 0;
  368. flags |= UNSIGNED;
  369. case 'd':
  370. case 'i':
  371. /* Thanks to Ralph Mason for fixing the u_int bug. */
  372. #ifndef STDIO_64_BIT
  373. if (flags & LONGLONG) {
  374. (void)va_arg(ap, uint64_t);
  375. strcpy_P(buf, PSTR("NA"));
  376. cp = buf;
  377. size = strlen("NA");
  378. break;
  379. }
  380. #endif
  381. ulval = va_args_ulval(flags, &ap);
  382. if (ch != 'u' && ( LLTYPE ) ulval < 0) {
  383. ulval = ( ULTYPE ) (-(( LLTYPE) ulval));
  384. sign = '-';
  385. }
  386. if ((dprec = prec) >= 0)
  387. flags &= ~ZEROPAD;
  388. cp = buf + BUF;
  389. if (ulval || prec) {
  390. if (ulval < 10)
  391. *--cp = (char) ulval + '0';
  392. else
  393. do {
  394. *--cp = (char) (ulval % 10) + '0';
  395. ulval /= 10;
  396. } while (ulval);
  397. }
  398. size = buf + BUF - cp;
  399. break;
  400. case 'o':
  401. #ifndef STDIO_64_BIT
  402. if (flags & LONGLONG) {
  403. (void)va_arg(ap, uint64_t);
  404. strcpy_P(buf, PSTR("NA"));
  405. cp = buf;
  406. size = strlen("NA");
  407. break;
  408. }
  409. #endif
  410. ulval = va_args_ulval(flags, &ap);
  411. sign = 0;
  412. if ((dprec = prec) >= 0)
  413. flags &= ~ZEROPAD;
  414. cp = buf + BUF;
  415. if (ulval || prec) {
  416. do {
  417. *--cp = (char) (ulval & 7) + '0';
  418. ulval >>= 3;
  419. } while (ulval);
  420. if ((flags & ALT) != 0 && *cp != '0')
  421. *--cp = '0';
  422. }
  423. size = buf + BUF - cp;
  424. break;
  425. case 'p':
  426. case 'X':
  427. case 'x':
  428. #ifndef STDIO_64_BIT
  429. if (flags & LONGLONG) {
  430. (void)va_arg(ap, uint64_t);
  431. strcpy_P(buf, PSTR("NA"));
  432. cp = buf;
  433. size = strlen("NA");
  434. break;
  435. }
  436. #endif
  437. if (ch == 'p') {
  438. ulval = (uintptr_t) va_arg(ap, void *);
  439. flags |= ALT;
  440. ch = 'x';
  441. } else
  442. ulval = va_args_ulval(flags, &ap);
  443. sign = 0;
  444. if ((dprec = prec) >= 0)
  445. flags &= ~ZEROPAD;
  446. hexdigs = HEXDIGIT;
  447. if (ch == 'x')
  448. hexdigs += 16;
  449. cp = buf + BUF;
  450. do {
  451. *--cp = PRG_RDB(hexdigs + (ulval & 0x0f));
  452. ulval >>= 4;
  453. } while (ulval);
  454. if (flags & ALT) {
  455. *--cp = ch;
  456. *--cp = '0';
  457. }
  458. size = buf + BUF - cp;
  459. break;
  460. #ifdef STDIO_FLOATING_POINT
  461. #ifdef __IMAGECRAFT__
  462. case 'G':
  463. iccfmt++;
  464. case 'g':
  465. iccfmt++;
  466. case 'E':
  467. iccfmt++;
  468. case 'e':
  469. iccfmt++;
  470. case 'f':
  471. if (prec == -1)
  472. prec = DEFPREC;
  473. _double = va_arg(ap, double);
  474. /* ICCAVR bug, we use a hack */
  475. /* cp = FormatFP_1(iccfmt, _double, 0, 1, prec); */
  476. cp = ftoa(_double, &fps);
  477. #elif defined(__arm__) && !defined(__NUT_EMULATION__)
  478. case 'g':
  479. case 'G':
  480. case 'e':
  481. case 'E':
  482. case 'f':
  483. {
  484. int decpt;
  485. int neg;
  486. char *rve = buf;
  487. char *bp = buf;
  488. if (prec == -1)
  489. prec = DEFPREC;
  490. _double = va_arg(ap, double);
  491. cp = _dtoa_r(_REENT, _double, 3, prec, &decpt, &neg, &rve);
  492. if (neg)
  493. sign = '-';
  494. if (decpt == 9999) {
  495. /* Infinite or invalid. */
  496. strcpy(bp, cp);
  497. } else {
  498. /* Left of decimal dot. */
  499. if (decpt > 0) {
  500. while (*cp && decpt > 0) {
  501. *bp++ = *cp++;
  502. decpt--;
  503. }
  504. while (decpt > 0) {
  505. *bp++ = '0';
  506. decpt--;
  507. }
  508. } else {
  509. *bp++ = '0';
  510. }
  511. *bp++ = '.';
  512. /* Right of decimal dot. */
  513. while (decpt < 0 && prec > 0) {
  514. *bp++ = '0';
  515. decpt++;
  516. prec--;
  517. }
  518. while (*cp && prec > 0) {
  519. *bp++ = *cp++;
  520. prec--;
  521. }
  522. while (prec > 0) {
  523. *bp++ = '0';
  524. prec--;
  525. }
  526. *bp = 0;
  527. }
  528. cp = buf;
  529. }
  530. #else
  531. case 'g':
  532. case 'G':
  533. case 'e':
  534. case 'E':
  535. case 'f':
  536. if (prec == -1)
  537. prec = DEFPREC;
  538. _double = va_arg(ap, double);
  539. if (ch == 'f')
  540. dtostrf(_double, 1, prec, buf);
  541. else
  542. dtostre(_double, buf, prec, 1);
  543. cp = buf;
  544. #endif
  545. #else
  546. case 'g':
  547. case 'G':
  548. case 'e':
  549. case 'E':
  550. case 'f':
  551. (void) va_arg(ap, double);
  552. strcpy_P(buf, PSTR("NA"));
  553. cp = buf;
  554. #endif /* STDIO_FLOATING_POINT */
  555. size = strlen(buf);
  556. break;
  557. default:
  558. if (ch == 0)
  559. return rc;
  560. cp = buf;
  561. *cp = ch;
  562. size = 1;
  563. sign = '\0';
  564. break;
  565. } /* switch */
  566. /*
  567. * Output.
  568. */
  569. realsz = dprec > size ? dprec : size;
  570. if (sign)
  571. realsz++;
  572. #ifdef __HARVARD_ARCH__
  573. if ((flags & (LADJUST | ZEROPAD)) == 0)
  574. _putpad(_putb_P, fd, blanks, width - realsz);
  575. if (sign)
  576. _putb(fd, &sign, 1);
  577. if ((flags & (LADJUST | ZEROPAD)) == ZEROPAD)
  578. _putpad(_putb_P, fd, zeroes, width - realsz);
  579. _putpad(_putb_P, fd, zeroes, dprec - size);
  580. if (size) /* DF 12/16/03 - zero length is "flush" in NutTcpDeviceWrite() */
  581. _putb(fd, cp, size);
  582. if (ch == 'P')
  583. free(cp);
  584. if (flags & LADJUST)
  585. _putpad(_putb_P, fd, blanks, width - realsz);
  586. #else
  587. if ((flags & (LADJUST | ZEROPAD)) == 0)
  588. _putpad(_putb, fd, blanks, width - realsz);
  589. if (sign)
  590. _putb(fd, &sign, 1);
  591. if ((flags & (LADJUST | ZEROPAD)) == ZEROPAD)
  592. _putpad(_putb, fd, zeroes, width - realsz);
  593. _putpad(_putb, fd, zeroes, dprec - size);
  594. if (size) /* DF 12/16/03 - zero length is "flush" in NutTcpDeviceWrite() */
  595. _putb(fd, cp, size);
  596. if (flags & LADJUST)
  597. _putpad(_putb, fd, blanks, width - realsz);
  598. #endif
  599. if (width >= realsz)
  600. rc += width;
  601. else
  602. rc += realsz;
  603. }
  604. return rc;
  605. }
  606. /*@}*/