vsprintf.c (3fa04ecd72780da31ba8b329e148179bc24a9c7d) vsprintf.c (ef0658f3de484bf9b173639cd47544584e01efa5)
1/*
2 * linux/lib/vsprintf.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
8/*

--- 394 unchanged lines hidden (view full) ---

403 FORMAT_TYPE_UINT,
404 FORMAT_TYPE_INT,
405 FORMAT_TYPE_NRCHARS,
406 FORMAT_TYPE_SIZE_T,
407 FORMAT_TYPE_PTRDIFF
408};
409
410struct printf_spec {
1/*
2 * linux/lib/vsprintf.c
3 *
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
6
7/* vsprintf.c -- Lars Wirzenius & Linus Torvalds. */
8/*

--- 394 unchanged lines hidden (view full) ---

403 FORMAT_TYPE_UINT,
404 FORMAT_TYPE_INT,
405 FORMAT_TYPE_NRCHARS,
406 FORMAT_TYPE_SIZE_T,
407 FORMAT_TYPE_PTRDIFF
408};
409
410struct printf_spec {
411 enum format_type type;
412 int flags; /* flags to number() */
413 int field_width; /* width of output field */
414 int base;
415 int precision; /* # of digits/chars */
416 int qualifier;
411 u16 type;
412 s16 field_width; /* width of output field */
413 u8 flags; /* flags to number() */
414 u8 base;
415 s8 precision; /* # of digits/chars */
416 u8 qualifier;
417};
418
419static char *number(char *buf, char *end, unsigned long long num,
420 struct printf_spec spec)
421{
422 /* we are called with base 8, 10 or 16, only, thus don't need "G..." */
423 static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
424

--- 903 unchanged lines hidden (view full) ---

1328
1329 case FORMAT_TYPE_INVALID:
1330 if (str < end)
1331 *str = '%';
1332 ++str;
1333 break;
1334
1335 case FORMAT_TYPE_NRCHARS: {
417};
418
419static char *number(char *buf, char *end, unsigned long long num,
420 struct printf_spec spec)
421{
422 /* we are called with base 8, 10 or 16, only, thus don't need "G..." */
423 static const char digits[16] = "0123456789ABCDEF"; /* "GHIJKLMNOPQRSTUVWXYZ"; */
424

--- 903 unchanged lines hidden (view full) ---

1328
1329 case FORMAT_TYPE_INVALID:
1330 if (str < end)
1331 *str = '%';
1332 ++str;
1333 break;
1334
1335 case FORMAT_TYPE_NRCHARS: {
1336 int qualifier = spec.qualifier;
1336 u8 qualifier = spec.qualifier;
1337
1338 if (qualifier == 'l') {
1339 long *ip = va_arg(args, long *);
1340 *ip = (str - buf);
1341 } else if (TOLOWER(qualifier) == 'z') {
1342 size_t *ip = va_arg(args, size_t *);
1343 *ip = (str - buf);
1344 } else {

--- 269 unchanged lines hidden (view full) ---

1614 save_arg(void *);
1615 /* skip all alphanumeric pointer suffixes */
1616 while (isalnum(*fmt))
1617 fmt++;
1618 break;
1619
1620 case FORMAT_TYPE_NRCHARS: {
1621 /* skip %n 's argument */
1337
1338 if (qualifier == 'l') {
1339 long *ip = va_arg(args, long *);
1340 *ip = (str - buf);
1341 } else if (TOLOWER(qualifier) == 'z') {
1342 size_t *ip = va_arg(args, size_t *);
1343 *ip = (str - buf);
1344 } else {

--- 269 unchanged lines hidden (view full) ---

1614 save_arg(void *);
1615 /* skip all alphanumeric pointer suffixes */
1616 while (isalnum(*fmt))
1617 fmt++;
1618 break;
1619
1620 case FORMAT_TYPE_NRCHARS: {
1621 /* skip %n 's argument */
1622 int qualifier = spec.qualifier;
1622 u8 qualifier = spec.qualifier;
1623 void *skip_arg;
1624 if (qualifier == 'l')
1625 skip_arg = va_arg(args, long *);
1626 else if (TOLOWER(qualifier) == 'z')
1627 skip_arg = va_arg(args, size_t *);
1628 else
1629 skip_arg = va_arg(args, int *);
1630 break;

--- 249 unchanged lines hidden (view full) ---

1880 * @args: arguments
1881 */
1882int vsscanf(const char *buf, const char *fmt, va_list args)
1883{
1884 const char *str = buf;
1885 char *next;
1886 char digit;
1887 int num = 0;
1623 void *skip_arg;
1624 if (qualifier == 'l')
1625 skip_arg = va_arg(args, long *);
1626 else if (TOLOWER(qualifier) == 'z')
1627 skip_arg = va_arg(args, size_t *);
1628 else
1629 skip_arg = va_arg(args, int *);
1630 break;

--- 249 unchanged lines hidden (view full) ---

1880 * @args: arguments
1881 */
1882int vsscanf(const char *buf, const char *fmt, va_list args)
1883{
1884 const char *str = buf;
1885 char *next;
1886 char digit;
1887 int num = 0;
1888 int qualifier, base, field_width;
1888 u8 qualifier;
1889 u8 base;
1890 s16 field_width;
1889 bool is_sign;
1890
1891 while (*fmt && *str) {
1892 /* skip any white space in format */
1893 /* white space in format matchs any amount of
1894 * white space, including none, in the input.
1895 */
1896 if (isspace(*fmt)) {

--- 61 unchanged lines hidden (view full) ---

1958 } while (--field_width > 0 && *str);
1959 num++;
1960 }
1961 continue;
1962 case 's':
1963 {
1964 char *s = (char *)va_arg(args, char *);
1965 if (field_width == -1)
1891 bool is_sign;
1892
1893 while (*fmt && *str) {
1894 /* skip any white space in format */
1895 /* white space in format matchs any amount of
1896 * white space, including none, in the input.
1897 */
1898 if (isspace(*fmt)) {

--- 61 unchanged lines hidden (view full) ---

1960 } while (--field_width > 0 && *str);
1961 num++;
1962 }
1963 continue;
1964 case 's':
1965 {
1966 char *s = (char *)va_arg(args, char *);
1967 if (field_width == -1)
1966 field_width = INT_MAX;
1968 field_width = SHORT_MAX;
1967 /* first, skip leading white space in buffer */
1968 str = skip_spaces(str);
1969
1970 /* now copy until next white space */
1971 while (*str && !isspace(*str) && field_width--)
1972 *s++ = *str++;
1973 *s = '\0';
1974 num++;

--- 141 unchanged lines hidden ---
1969 /* first, skip leading white space in buffer */
1970 str = skip_spaces(str);
1971
1972 /* now copy until next white space */
1973 while (*str && !isspace(*str) && field_width--)
1974 *s++ = *str++;
1975 *s = '\0';
1976 num++;

--- 141 unchanged lines hidden ---