mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 05:38:11 +00:00
LibC: Fix bug in scanf() family where we'd capture invalid data.
This commit is contained in:
parent
951377e93e
commit
cdb82f6fbb
3 changed files with 54 additions and 50 deletions
|
@ -424,5 +424,41 @@ int remove(const char* pathname)
|
|||
return rmdir(pathname);
|
||||
}
|
||||
|
||||
int scanf(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int count = vfscanf(stdin, fmt, ap);
|
||||
va_end(ap);
|
||||
return count;
|
||||
}
|
||||
|
||||
int fscanf(FILE* stream, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int count = vfscanf(stream, fmt, ap);
|
||||
va_end(ap);
|
||||
return count;
|
||||
}
|
||||
|
||||
int sscanf(const char* buffer, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
int count = vsscanf(buffer, fmt, ap);
|
||||
va_end(ap);
|
||||
return count;
|
||||
}
|
||||
|
||||
int vfscanf(FILE* stream, const char* fmt, va_list ap)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
if (!fgets(buffer, sizeof(buffer) - 1, stream))
|
||||
return -1;
|
||||
return vsscanf(buffer, fmt, ap);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue