Fun 0.41.5
The programming language that makes You have fun
Loading...
Searching...
No Matches
connect.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
27
28/* PCSC connect */
30#ifdef FUN_WITH_PCSC
31 /* Stack: [..., ctx_id, reader_name] -> pops reader_name first, then ctx_id */
32 Value vreader = pop_value(vm);
33 Value vctx = pop_value(vm);
34
35 int ctx_id = (int)vctx.i;
37 char *rname = value_to_string_alloc(&vreader);
38 free_value(vreader);
39
40 pcsc_ctx_entry *e = pcsc_get_ctx(ctx_id);
41 if (!e || !rname) {
42 if (rname) free(rname);
43 push_value(vm, make_int(0));
44 break;
45 }
46
47 int hslot = pcsc_alloc_card_slot();
48 if (!hslot) {
49 free(rname);
50 push_value(vm, make_int(0));
51 break;
52 }
53 pcsc_card_entry *ce = pcsc_get_card(hslot);
54 DWORD dwActive = 0;
55 LONG rv = SCardConnect(e->ctx, rname, SCARD_SHARE_SHARED,
56 SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1,
57 &ce->h, &dwActive);
58 free(rname);
59 if (rv != SCARD_S_SUCCESS) {
60 ce->in_use = 0;
61 push_value(vm, make_int(0));
62 break;
63 }
64 ce->proto = dwActive;
65 push_value(vm, make_int(hslot));
66#else
67 Value vreader = pop_value(vm);
68 free_value(vreader);
69 Value vctx = pop_value(vm);
72#endif
73 break;
74}
@ OP_PCSC_CONNECT
Definition bytecode.h:187
Value vctx
Definition connect.c:69
free_value(vreader)
push_value(vm, make_int(0))
free(vals)
Tagged union representing a Fun value.
Definition value.h:68
char * value_to_string_alloc(const Value *v)
Allocate a printable C string for a Value.
Definition value.c:641
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51