Fun 0.41.5
The programming language that makes you have fun!
Loading...
Searching...
No Matches
establish.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
10/**
11 * @file establish.c
12 * @brief Implements the OP_PCSC_ESTABLISH opcode (conditional build).
13 *
14 * Creates a new PC/SC context using SCardEstablishContext(SCARD_SCOPE_SYSTEM)
15 * and registers it in the internal PCSC context registry when FUN_WITH_PCSC
16 * is enabled. Returns the allocated context id on success, or 0 on failure.
17 * When PCSC support is disabled at build time, this opcode returns 0.
18 *
19 * OP_PCSC_ESTABLISH: () -> int
20 *
21 * - Returns: context id (>0) on success; 0 on error or when disabled.
22 */
23
24/* PCSC establish */
26#ifdef FUN_WITH_PCSC
27 int slot = pcsc_alloc_ctx_slot();
28 if (!slot) {
29 push_value(vm, make_int(0));
30 break;
31 }
33 if (!e) {
34 push_value(vm, make_int(0));
35 break;
36 }
37 LONG rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &e->ctx);
38 if (rv != SCARD_S_SUCCESS) {
39 e->in_use = 0;
40 push_value(vm, make_int(0));
41 break;
42 }
43 push_value(vm, make_int(slot));
44#else
45 push_value(vm, make_int(0));
46#endif
47 break;
48}
@ OP_PCSC_ESTABLISH
Definition bytecode.h:184
LONG rv
Definition connect.c:53
pcsc_ctx_entry * e
Definition connect.c:38
push_value(vm, make_int(slot))
static int pcsc_alloc_ctx_slot(void)
Allocate a free context slot in the PC/SC registry.
Definition pcsc.c:54
static pcsc_ctx_entry * pcsc_get_ctx(int id)
Lookup a context slot by id.
Definition pcsc.c:88
Definition pcsc.c:35
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Definition value.c:51