Changeset d8de5d3 in mainline
- Timestamp:
- 2011-05-23T13:31:54Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 540cb1b, 773f188
- Parents:
- 207533f
- Location:
- uspace/lib/c
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/assert.c
r207533f rd8de5d3 39 39 #include <stdint.h> 40 40 41 #define MSG_START "Assertion failed (" 42 #define MSG_FILE ") in file \"" 43 #define MSG_LINE "\", line " 44 #define MSG_END ".\n" 45 46 static atomic_t failed_asserts; 41 static atomic_t failed_asserts = {0}; 47 42 48 43 void assert_abort(const char *cond, const char *file, unsigned int line) 49 44 { 50 char lstr[11];51 char *pd = &lstr[10];52 uint32_t ln = (uint32_t) line;53 54 /*55 * Convert ln to a zero-terminated string.56 */57 *pd-- = 0;58 for (; ln; ln /= 10)59 *pd-- = '0' + ln % 10;60 pd++;61 62 45 /* 63 46 * Send the message safely to klog. Nested asserts should not occur. 64 47 */ 65 klog_write(MSG_START, str_size(MSG_START)); 66 klog_write(cond, str_size(cond)); 67 klog_write(MSG_FILE, str_size(MSG_FILE)); 68 klog_write(file, str_size(file)); 69 klog_write(MSG_LINE, str_size(MSG_LINE)); 70 klog_write(pd, str_size(pd)); 71 klog_write(MSG_END, str_size(MSG_END)); 72 48 klog_printf("Assertion failed (%s) in file \"%s\", line %u.\n", 49 cond, file, line); 50 73 51 /* 74 52 * Check if this is a nested or parallel assert. … … 82 60 * assertions. 83 61 */ 84 printf( MSG_START "%s" MSG_FILE "%s" MSG_LINE "%u" MSG_END,62 printf("Assertion failed (%s) in file \"%s\", line %u.\n", 85 63 cond, file, line); 86 64 stacktrace_print(); 87 65 88 66 abort(); 89 67 } -
uspace/lib/c/generic/io/klog.c
r207533f rd8de5d3 38 38 #include <sys/types.h> 39 39 #include <unistd.h> 40 #include <errno.h> 40 41 #include <io/klog.h> 42 #include <io/printf_core.h> 41 43 42 44 size_t klog_write(const void *buf, size_t size) … … 55 57 } 56 58 59 /** Print formatted text to klog. 60 * 61 * @param fmt Format string 62 * 63 * \see For more details about format string see printf_core. 64 * 65 */ 66 int klog_printf(const char *fmt, ...) 67 { 68 va_list args; 69 va_start(args, fmt); 70 71 int ret = klog_vprintf(fmt, args); 72 73 va_end(args); 74 75 return ret; 76 } 77 78 static int klog_vprintf_str_write(const char *str, size_t size, void *data) 79 { 80 size_t wr = klog_write(str, size); 81 return str_nlength(str, wr); 82 } 83 84 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data) 85 { 86 size_t offset = 0; 87 size_t chars = 0; 88 89 while (offset < size) { 90 char buf[STR_BOUNDS(1)]; 91 size_t sz = 0; 92 93 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK) 94 klog_write(buf, sz); 95 96 chars++; 97 offset += sizeof(wchar_t); 98 } 99 100 return chars; 101 } 102 103 /** Print formatted text to klog. 104 * 105 * @param fmt Format string 106 * @param ap Format parameters 107 * 108 * \see For more details about format string see printf_core. 109 * 110 */ 111 int klog_vprintf(const char *fmt, va_list ap) 112 { 113 printf_spec_t ps = { 114 klog_vprintf_str_write, 115 klog_vprintf_wstr_write, 116 NULL 117 }; 118 119 return printf_core(fmt, &ps, ap); 120 } 121 57 122 /** @} 58 123 */ -
uspace/lib/c/generic/io/vprintf.c
r207533f rd8de5d3 96 96 /** Print formatted text to stdout. 97 97 * 98 * @param file Output stream 99 * @param fmt Format string 100 * @param ap Format parameters 98 * @param fmt Format string 99 * @param ap Format parameters 101 100 * 102 101 * \see For more details about format string see printf_core. -
uspace/lib/c/include/assert.h
r207533f rd8de5d3 64 64 __attribute__((noreturn)); 65 65 66 67 66 #endif 68 67 -
uspace/lib/c/include/io/klog.h
r207533f rd8de5d3 37 37 38 38 #include <sys/types.h> 39 #include <stdarg.h> 39 40 40 41 extern size_t klog_write(const void *, size_t); 41 42 extern void klog_update(void); 43 extern int klog_printf(const char *, ...); 44 extern int klog_vprintf(const char *, va_list); 42 45 43 46 #endif
Note:
See TracChangeset
for help on using the changeset viewer.