aboutsummaryrefslogtreecommitdiff
path: root/lib/stdio.h
blob: f7c18464ed96735ee2568c9311ea51d75acb8e72 (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
#pragma once

#include <stdarg.h>

/** An object type used for streams */
typedef struct kIoDevice {
  int id;
  /** Functions that prints a character to the stream */
  void (*putc)(const struct kIoDevice *, char);
  /** Function that prints a string to the stream */
  int (*puts)(const struct kIoDevice *, const char *, int);
  /** Flush all buffers */
  void (*flush)(const struct kIoDevice *);
} FILE;

/** 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;

/**
 * Write the formatted string to stdout
 *
 * Supports ``%s`` (string), ``%d`` (decimal), ``%u`` (unsigned), ``%x`` (hexadecimal)
 */
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);