PatchworkOS  3984a1d
A non-POSIX operating system.
Loading...
Searching...
No Matches
vscan.c
Go to the documentation of this file.
1#include <stdarg.h>
2#include <stdio.h>
3#include <stdlib.h>
4#include <sys/io.h>
5
6#define _SCAN_GET(ctx) \
7 ({ \
8 fd_t fd = (fd_t)(ctx)->private; \
9 int res = EOF; \
10 char c; \
11 if (read(fd, &c, 1) == 1) \
12 { \
13 res = c; \
14 } \
15 res; \
16 })
17
18#define _SCAN_UNGET(ctx, c) \
19 ({ \
20 fd_t fd = (fd_t)(ctx)->private; \
21 if ((c) != EOF) \
22 { \
23 seek(fd, -1, SEEK_CUR); \
24 } \
25 })
26
27#include "common/scan.h"
28
29uint64_t vscan(fd_t fd, const char* format, va_list args)
30{
31 int result = _scan(format, args, (void*)(uintptr_t)fd);
32 return result < 0 ? ERR : (uint64_t)result;
33}
static char format[MAX_NAME]
Definition screen.c:17
static int _scan(const char *_RESTRICT format, va_list arg, void *private)
Definition scan.h:666
uint64_t vscan(fd_t fd, const char *format, va_list args)
Wrapper for reading from a file descriptor using scan formatting with va_list.
Definition vscan.c:29
#define ERR
Integer error value.
Definition ERR.h:17
__UINT64_TYPE__ fd_t
A file descriptor.
Definition fd_t.h:12
__builtin_va_list va_list
Definition stdarg.h:9
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43