Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
list_readers.c
Go to the documentation of this file.
1/*
2 * This file is part of the Fun programming language.
3 * https://fun-lang.xyz/
4 *
5 * Copyright 2025 Johannes Findeisen <you@hanez.org>
6 * Licensed under the terms of the Apache-2.0 license.
7 * https://opensource.org/license/apache-2-0
8 */
9
18
25
26/* PCSC list_readers */
28#ifdef FUN_WITH_PCSC
29 /* Pop context id; return [] if anything goes wrong */
30 Value vid = pop_value(vm);
31 int id = (int)vid.i;
32 free_value(vid);
33
34 pcsc_ctx_entry *e = pcsc_get_ctx(id);
35 if (!e) {
37 break;
38 }
39
40 DWORD sz = 0;
41 LONG rv = SCardListReaders(e->ctx, NULL, NULL, &sz);
42 if (rv != SCARD_S_SUCCESS || sz == 0) {
44 break;
45 }
46
47 char *msz = (char *)malloc(sz);
48 if (!msz) {
50 break;
51 }
52
53 rv = SCardListReaders(e->ctx, NULL, msz, &sz);
54 if (rv != SCARD_S_SUCCESS) {
55 free(msz);
57 break;
58 }
59
60 Value vals[64];
61 int count = 0;
62 char *p = msz;
63 while (*p && count < (int)(sizeof(vals) / sizeof(vals[0]))) {
64 size_t n = strlen(p);
66 p += n + 1;
67 }
69 for (int i = 0; i < count; ++i)
71 free(msz);
72
73 if (arr.type != VAL_ARRAY) {
75 } else {
76 push_value(vm, arr);
77 }
78#else
79 /* Fallback (no PCSC): consume ctx id and return [] to keep the stack consistent */
80 Value vid = pop_value(vm);
83#endif
84 break;
85}
@ OP_PCSC_LIST_READERS
Definition bytecode.h:186
array_clear & arr
Definition clear.c:38
int n
Definition insert.c:41
push_value(vm, make_array_from_values(NULL, 0))
free_value(vid)
Value * vals
Definition make_array.c:39
free(vals)
int count
Definition parser.c:266
const char * p
Definition read_file.c:37
long sz
Definition read_file.c:50
Tagged union representing a Fun value.
Definition value.h:68
int64_t i
Definition value.h:71
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
Definition value.c:95
Value make_array_from_values(const Value *vals, int count)
Create an array Value by copying items from an input span.
Definition value.c:142
@ VAL_ARRAY
Definition value.h:55