Changeset 2595dab in mainline for uspace/lib/libc/generic/io/vprintf.c
- Timestamp:
- 2009-06-03T19:26:28Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d00ae4c
- Parents:
- ca3ba3a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/io/vprintf.c
rca3ba3a r2595dab 39 39 #include <futex.h> 40 40 #include <async.h> 41 #include < console.h>41 #include <string.h> 42 42 43 43 static atomic_t printf_futex = FUTEX_INITIALIZER; 44 44 45 static int vprintf_str_write(const char *str, size_t size, void *data) 45 static int vprintf_str_write(const char *str, size_t size, void *stream) 46 { 47 size_t wr = fwrite(str, 1, size, (FILE *) stream); 48 return str_nlength(str, wr); 49 } 50 51 static int vprintf_wstr_write(const wchar_t *str, size_t size, void *stream) 46 52 { 47 53 size_t offset = 0; 48 size_t prev; 49 count_t chars = 0; 54 size_t chars = 0; 50 55 51 56 while (offset < size) { 52 prev = offset; 53 str_decode(str, &offset, size); 54 console_write(str + prev, offset - prev); 55 chars++; 56 } 57 58 return chars; 59 } 60 61 static int vprintf_wstr_write(const wchar_t *str, size_t size, void *data) 62 { 63 size_t offset = 0; 64 size_t boff; 65 count_t chars = 0; 66 char buf[4]; 67 68 while (offset < size) { 69 boff = 0; 70 chr_encode(str[chars], buf, &boff, 4); 71 console_write(buf, boff); 57 if (fputc(str[chars], (FILE *) stream) <= 0) 58 break; 59 72 60 chars++; 73 61 offset += sizeof(wchar_t); … … 77 65 } 78 66 79 80 67 /** Print formatted text. 81 * @param fmt format string 82 * @param ap format parameters 68 * 69 * @param stream Output stream 70 * @param fmt Format string 71 * @param ap Format parameters 72 * 83 73 * \see For more details about format string see printf_core. 74 * 84 75 */ 85 int v printf(const char *fmt, va_list ap)76 int vfprintf(FILE *stream, const char *fmt, va_list ap) 86 77 { 87 78 struct printf_spec ps = { 88 79 vprintf_str_write, 89 80 vprintf_wstr_write, 90 NULL81 stream 91 82 }; 83 92 84 /* 93 85 * Prevent other threads to execute printf_core() 94 86 */ 95 87 futex_down(&printf_futex); 88 96 89 /* 97 90 * Prevent other pseudo threads of the same thread … … 99 92 */ 100 93 async_serialize_start(); 94 101 95 int ret = printf_core(fmt, &ps, ap); 96 102 97 async_serialize_end(); 103 98 futex_up(&printf_futex); 99 104 100 return ret; 101 } 102 103 /** Print formatted text to stdout. 104 * 105 * @param file Output stream 106 * @param fmt Format string 107 * @param ap Format parameters 108 * 109 * \see For more details about format string see printf_core. 110 * 111 */ 112 int vprintf(const char *fmt, va_list ap) 113 { 114 return vfprintf(stdout, fmt, ap); 105 115 } 106 116
Note:
See TracChangeset
for help on using the changeset viewer.