MCPcopy Index your code
hub / github.com/GJDuck/e9patch / vsnprintf

Function vsnprintf

examples/stdlib.c:3909–4110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3907}
3908
3909static int vsnprintf(char *str, size_t size, const char *format, va_list ap)
3910{
3911 size_t idx = 0;
3912 for (; *format != '\0'; format++)
3913 {
3914 if (*format != '%')
3915 {
3916 idx = printf_put_char(str, size, idx, *format);
3917 continue;
3918 }
3919 format++;
3920 unsigned flags = 0x0;
3921 for (; true; format++)
3922 {
3923 switch (*format)
3924 {
3925 case ' ':
3926 flags |= PRINTF_FLAG_SPACE;
3927 continue;
3928 case '+':
3929 flags |= PRINTF_FLAG_PLUS;
3930 continue;
3931 case '-':
3932 if (!(flags & PRINTF_FLAG_ZERO))
3933 flags |= PRINTF_FLAG_RIGHT;
3934 continue;
3935 case '#':
3936 flags |= PRINTF_FLAG_HASH;
3937 continue;
3938 case '0':
3939 flags &= ~PRINTF_FLAG_RIGHT;
3940 flags |= PRINTF_FLAG_ZERO;
3941 continue;
3942 default:
3943 break;
3944 }
3945 break;
3946 }
3947
3948 size_t width = 0;
3949 if (*format == '*')
3950 {
3951 format++;
3952 int tmp = va_arg(ap, int);
3953 if (tmp < 0)
3954 {
3955 flags |= (!(flags & PRINTF_FLAG_ZERO)? PRINTF_FLAG_RIGHT: 0);
3956 width = (size_t)-tmp;
3957 }
3958 else
3959 width = (size_t)tmp;
3960 }
3961 else
3962 {
3963 for (; isdigit(*format); format++)
3964 {
3965 width *= 10;
3966 width += (unsigned)(*format - '0');

Callers 6

debug_implFunction · 0.70
vasprintfFunction · 0.70
snprintfFunction · 0.70
vfprintfFunction · 0.70
vfprintf_unlockedFunction · 0.70
warningMethod · 0.50

Calls 4

printf_put_charFunction · 0.70
isdigitFunction · 0.70
printf_put_numFunction · 0.70
strlenFunction · 0.70

Tested by

no test coverage detected