Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
Arm Trusted Firmware
Commits
ddf04313
"vscode:/vscode.git/clone" did not exist on "027189b294d14a7d313cdbf611982843f921555d"
Commit
ddf04313
authored
Sep 11, 2020
by
Mark Dykes
Committed by
TrustedFirmware Code Review
Sep 11, 2020
Browse files
Merge "libc: Add support for vsnprintf()" into integration
parents
238db174
77648689
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/lib/libc/stdio.h
View file @
ddf04313
...
@@ -22,6 +22,7 @@ int snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4);
...
@@ -22,6 +22,7 @@ int snprintf(char *s, size_t n, const char *fmt, ...) __printflike(3, 4);
#ifdef STDARG_H
#ifdef STDARG_H
int
vprintf
(
const
char
*
fmt
,
va_list
args
);
int
vprintf
(
const
char
*
fmt
,
va_list
args
);
int
vsnprintf
(
char
*
s
,
size_t
n
,
const
char
*
fmt
,
va_list
args
);
#endif
#endif
int
putchar
(
int
c
);
int
putchar
(
int
c
);
...
...
lib/libc/snprintf.c
View file @
ddf04313
...
@@ -77,7 +77,7 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
...
@@ -77,7 +77,7 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
}
}
/*******************************************************************
/*******************************************************************
* Reduced snprintf to be used for Trusted firmware.
* Reduced
v
snprintf to be used for Trusted firmware.
* The following type specifiers are supported:
* The following type specifiers are supported:
*
*
* %x (or %X) - hexadecimal format
* %x (or %X) - hexadecimal format
...
@@ -97,9 +97,8 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
...
@@ -97,9 +97,8 @@ static void unsigned_num_print(char **s, size_t n, size_t *chars_printed,
* buffer was big enough. If it returns a value lower than n, the
* buffer was big enough. If it returns a value lower than n, the
* whole string has been written.
* whole string has been written.
*******************************************************************/
*******************************************************************/
int
snprintf
(
char
*
s
,
size_t
n
,
const
char
*
fmt
,
...
)
int
v
snprintf
(
char
*
s
,
size_t
n
,
const
char
*
fmt
,
va_list
args
)
{
{
va_list
args
;
int
num
;
int
num
;
unsigned
long
long
int
unum
;
unsigned
long
long
int
unum
;
char
*
str
;
char
*
str
;
...
@@ -120,7 +119,6 @@ int snprintf(char *s, size_t n, const char *fmt, ...)
...
@@ -120,7 +119,6 @@ int snprintf(char *s, size_t n, const char *fmt, ...)
n
--
;
n
--
;
}
}
va_start
(
args
,
fmt
);
while
(
*
fmt
!=
'\0'
)
{
while
(
*
fmt
!=
'\0'
)
{
left
=
false
;
left
=
false
;
padc
=
'\0'
;
padc
=
'\0'
;
...
@@ -221,10 +219,42 @@ loop:
...
@@ -221,10 +219,42 @@ loop:
chars_printed
++
;
chars_printed
++
;
}
}
va_end
(
args
);
if
(
n
>
0U
)
{
if
(
n
>
0U
)
*
s
=
'\0'
;
*
s
=
'\0'
;
}
return
(
int
)
chars_printed
;
return
(
int
)
chars_printed
;
}
}
/*******************************************************************
* Reduced snprintf to be used for Trusted firmware.
* The following type specifiers are supported:
*
* %x (or %X) - hexadecimal format
* %d or %i - signed decimal format
* %s - string format
* %u - unsigned decimal format
* %p - pointer format
*
* The following padding specifiers are supported by this print
* %0NN - Left-pad the number with 0s (NN is a decimal number)
* %NN - Left-pad the number or string with spaces (NN is a decimal number)
* %-NN - Right-pad the number or string with spaces (NN is a decimal number)
*
* The function panics on all other formats specifiers.
*
* It returns the number of characters that would be written if the
* buffer was big enough. If it returns a value lower than n, the
* whole string has been written.
*******************************************************************/
int
snprintf
(
char
*
s
,
size_t
n
,
const
char
*
fmt
,
...)
{
int
count
;
va_list
all_args
;
va_start
(
all_args
,
fmt
);
count
=
vsnprintf
(
s
,
n
,
fmt
,
all_args
);
va_end
(
all_args
);
return
count
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment