F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
sscanf_scan.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title format.cpp
3 // \author mstarch
4 // \brief cpp file for c-string format function as a implementation using snprintf
5 // ======================================================================
7 #include <Fw/Types/scan.hpp>
8 #include <cstdio>
9 #include <limits>
10 
12  const char* source,
13  FwSizeType maximumSize,
14  const char* formatString,
15  ...) {
16  va_list args;
17  va_start(args, formatString);
18  Fw::ScanStatus status = Fw::stringScan(count, source, maximumSize, formatString, args);
19  va_end(args);
20  return status;
21 }
22 
24  const char* source,
25  FwSizeType maximumSize,
26  const char* formatString,
27  va_list args) {
29  count = 0;
30  // Check format string
31  if (formatString == nullptr) {
33  }
34  // Must allow the compiler to choose the correct type for comparison
35  else if (maximumSize > std::numeric_limits<size_t>::max()) {
36  scanStatus = Fw::ScanStatus::SIZE_OVERFLOW;
37  }
38  // Check for null-termination of the source string bounded by maximumSize
39  else if (StringUtils::string_length(source, maximumSize) >= maximumSize) {
41  } else {
42  const int scannedFields = vsscanf(source, formatString, args);
43  if (scannedFields < 0) {
44  scanStatus = Fw::ScanStatus::OTHER_ERROR;
45  } else {
46  count = static_cast<FwSizeType>(scannedFields);
47  }
48  }
49  return scanStatus;
50 }
An error was returned from an underlying call.
PlatformSizeType FwSizeType
FwSizeType overflowed the range of size_t.
ScanStatus stringScan(FwSizeType &count, const char *source, FwSizeType maximumSize, const char *formatString,...)
scan a c-string
Definition: sscanf_scan.cpp:11
ScanStatus
status of string scan calls
Definition: scan.hpp:18
Format provided invalid format string.
The source string was not null-terminated within the maximum size.
FwSizeType string_length(const CHAR *source, FwSizeType buffer_size)
get the length of the source string
Definition: StringUtils.cpp:24