aboutsummaryrefslogtreecommitdiff
path: root/lib/libk/stdio.h
blob: 5ef68f1e9aa656a206de327d9c360f965a8ea3aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#pragma once

#include <stdarg.h>

///@defgroup libk libk
///@{
///@defgroup stdio stdio
///@{

#ifdef __cplusplus
/**
 * An object type used for streams
 */
struct kIoDevice {
  /** Function that prints a character to the stream */
  virtual void putc(char) = 0;
  /** Function that prints a string to the stream */
  virtual int puts(const char *, int) = 0;
  /** Flush write buffers */
  virtual void flush() = 0;
};
typedef kIoDevice FILE;
#else
typedef void FILE;
#endif

/** A FILE value corresponding to stdin, the keyboard buffer */
extern FILE *stdin;
/** A FILE value corresponding to stdout, the display */
extern FILE *stdout;
/** A FILE value corresponding to stderr, the uart */
extern FILE *stderr;

#ifdef __cplusplus
extern "C" {
#endif
/**
 * Write the formatted string to stdout
 * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal)
 * @return number of bytes written
 */
int printf(const char *restrict format, ...);

/**
 * Write the formatted string to stream; see printf
 */
int fprintf(FILE *restrict stream, const char *restrict format, ...);

/**
 * Write the formatted string to stream; see printf
 */
int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap);
#ifdef __cplusplus
}
#endif

///@}
///@}