llvm-mos-sdk
util.h
Go to the documentation of this file.
1 // Copyright 2022 LLVM-MOS Project
2 // Licensed under the Apache License, Version 2.0 with LLVM Exceptions.
3 // See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
4 // information.
5 
6 // Utilities shared between disparate parts of the libc.
7 
8 #ifndef _UTIL_H
9 #define _UTIL_H
10 
11 #include <stdarg.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 #include <stdio.h>
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
20 // State of a formatted input/output operation.
21 struct Status {
22  signed char base; // base to which the value shall be converted
23  uint16_t flags; // flags and length modifiers
24  size_t n; // print: maximum characters to be written
25  // scan: number matched conversion specifiers
26  size_t i; // number of characters read/written
27  size_t current; // number of characters read in current conversion
28  char *s; // *sprintf(): target buffer
29  // *sscanf(): source string
30  size_t width; // specified field width
31  int prec; // specified field precision
32  FILE *stream; // *fprintf() / *fscanf() stream
33  va_list arg; // argument stack
34 };
35 
36 // Return the digit for a character in the given base or -1 if invalid.
37 signed char __parse_digit(char c, char base);
38 
39 // A simple base-10 only strtoui. Overflows are undefined behavior. If there are
40 // no digits, it returns zero.
41 unsigned __simple_strtoui(const char *__restrict__ nptr,
42  char **__restrict endptr);
43 
44 #ifdef __cplusplus
45 }
46 #endif
47 
48 #endif // _UTIL_H
std::uint16_t
::uint16_t uint16_t
Definition: cstdint:22
Status::i
size_t i
Definition: util.h:26
Status::prec
int prec
Definition: util.h:31
Status::current
size_t current
Definition: util.h:27
FILE
struct _FILE FILE
Definition: stdio.h:20
Status::arg
va_list arg
Definition: util.h:33
stdio.h
Status::base
signed char base
Definition: util.h:22
Status::s
char * s
Definition: util.h:28
Status
Definition: util.h:21
Status::n
size_t n
Definition: util.h:24
Status::width
size_t width
Definition: util.h:30
Status::flags
uint16_t flags
Definition: util.h:23
Status::stream
FILE * stream
Definition: util.h:32
c
byte byte c
Definition: api.h:59