Changeset c7c6afd in mainline for common/stdc/vsnprintf.c
- Timestamp:
- 2025-04-13T23:27:44Z (4 weeks ago)
- Children:
- b6061f8c
- Parents:
- 240b2e4 (diff), f5e1692 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - git-author:
- Wayne Thornton <wmthornton-dev@…> (2025-04-13 23:27:44)
- git-committer:
- GitHub <noreply@…> (2025-04-13 23:27:44)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
common/stdc/vsnprintf.c
r240b2e4 rc7c6afd 1 1 /* 2 2 * Copyright (c) 2006 Josef Cejka 3 * Copyright (c) 2025 Jiří Zárevúcky 3 4 * All rights reserved. 4 5 * … … 27 28 */ 28 29 29 /** @addtogroup kernel_generic30 /** @addtogroup libc 30 31 * @{ 31 32 */ … … 33 34 */ 34 35 35 #ifndef KERN_PRINTF_CORE_H_ 36 #define KERN_PRINTF_CORE_H_ 36 #include <errno.h> 37 #include <macros.h> 38 #include <printf_core.h> 39 #include <stdarg.h> 40 #include <stdio.h> 41 #include <str.h> 37 42 38 #include <stdarg.h> 39 #include <stddef.h> 40 #include <uchar.h> 43 typedef struct { 44 char *dst; /* Destination */ 45 size_t left; 46 } vsnprintf_data_t; 41 47 42 /** Structure for specifying output methods for different printf clones. */ 43 typedef struct { 44 /* String output function, returns number of printed characters or EOF */ 45 int (*str_write)(const char *, size_t, void *); 48 static int vsnprintf_str_write(const char *str, size_t size, void *data) 49 { 50 vsnprintf_data_t *d = data; 51 size_t left = min(size, d->left); 52 if (left > 0) { 53 memcpy(d->dst, str, left); 54 d->dst += left; 55 d->left -= left; 56 } 57 return EOK; 58 } 46 59 47 /* Wide string output function, returns number of printed characters or EOF */ 48 int (*wstr_write)(const char32_t *, size_t, void *); 60 int vsnprintf(char *str, size_t size, const char *fmt, va_list ap) 61 { 62 vsnprintf_data_t data = { 63 .dst = str, 64 .left = size ? size - 1 : 0, 65 }; 49 66 50 /* User data - output stream specification, state, locks, etc. */ 51 void *data; 52 } printf_spec_t; 67 printf_spec_t ps = { 68 vsnprintf_str_write, 69 &data 70 }; 53 71 54 extern int printf_core(const char *fmt, printf_spec_t *ps, va_list ap); 72 int written = printf_core(fmt, &ps, ap); 73 if (written < 0) 74 return written; 55 75 56 #endif 76 /* Write the terminating NUL character. */ 77 if (size > 0) 78 data.dst[0] = 0; 79 80 return written; 81 } 57 82 58 83 /** @}
Note:
See TracChangeset
for help on using the changeset viewer.