Repository navigation
Expand file tree
/
Copy pathbindings.py
More file actions
1103 lines (808 loc) · 24.6 KB
/
Copy pathbindings.py
File metadata and controls
1103 lines (808 loc) · 24.6 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import ctypes
import inspect
import warnings
from types import FunctionType
from typing import (
TYPE_CHECKING,
Any,
Callable,
Dict,
Iterable,
Iterator,
Optional,
Sequence,
Type,
TypeVar,
Union,
)
from _pointers import add_ref
from ._cstd import c_calloc as _calloc
from ._cstd import c_free as _free
from ._cstd import c_malloc as _malloc
from ._cstd import c_raise as ct_raise
from ._cstd import c_realloc as _realloc
from ._cstd import dll, mdll
from ._utils import get_mapped, get_py
from .base_pointers import BaseCPointer, BasePointer
from .c_pointer import TypedCPointer, VoidPointer
from .exceptions import InvalidBindingParameter
from .std_structs import STRUCT_MAP, DivT, Lconv, LDivT, Tm
from .structure import StructPointer
from .util import NULL, Nullable, handle
if TYPE_CHECKING:
from .structure import Struct
T = TypeVar("T")
PointerLike = Nullable[Optional[Union[TypedCPointer[T], VoidPointer]]]
StringLike = Optional[Union[str, bytes, VoidPointer, TypedCPointer[bytes]]]
Format = Union[StringLike, PointerLike]
TypedPtr = Optional[PointerLike[T]]
PyCFuncPtrType = type(ctypes.CFUNCTYPE(None))
__all__ = (
"isalnum",
"isalpha",
"iscntrl",
"isdigit",
"isgraph",
"islower",
"isprint",
"ispunct",
"isspace",
"isupper",
"isxdigit",
"tolower",
"toupper",
"setlocale",
"frexp",
"ldexp",
"modf",
"fclose",
"clearerr",
"feof",
"ferror",
"fflush",
"fgetpos",
"fopen",
"fread",
"freopen",
"fseek",
"fsetpos",
"ftell",
"fwrite",
"remove",
"rename",
"rewind",
"setbuf",
"setvbuf",
"tmpfile",
"tmpnam",
"fprintf",
"printf",
"sprintf",
"fscanf",
"scanf",
"sscanf",
"fgetc",
"fgets",
"fputc",
"fputs",
"getc",
"getchar",
"gets",
"putc",
"putchar",
"puts",
"ungetc",
"perror",
"strtod",
"strtol",
"strtoul",
"abort",
"exit",
"getenv",
"system",
"abs",
"labs",
"rand",
"srand",
"mblen",
"mbstowcs",
"mbtowc",
"wcstombs",
"wctomb",
"memchr",
"memcmp",
"memcpy",
"memmove",
"memset",
"strcat",
"strncat",
"strchr",
"strcmp",
"strncmp",
"strcoll",
"strcpy",
"strncpy",
"strcspn",
"strerror",
"strlen",
"strpbrk",
"strrchr",
"strspn",
"strstr",
"strtok",
"strxfrm",
"asctime",
"clock",
"ctime",
"difftime",
"mktime",
"strftime",
"time",
"div",
"ldiv",
"localeconv",
"c_raise",
"c_malloc",
"c_calloc",
"c_realloc",
"c_free",
"gmtime",
"signal",
"qsort",
"bsearch",
"sizeof",
"PointerLike",
"StringLike",
"Format",
"TypedPtr",
)
def _not_null(data: Optional[T]) -> T:
assert data is not None, f"{data} is None"
return data
StructMap = Dict[Type[ctypes.Structure], Type["Struct"]]
CharLike = Union[StringLike, int]
class _CFuncTransport:
def __init__(
self,
c_func: "ctypes._FuncPointer",
py_func: Callable,
) -> None:
add_ref(c_func)
self._c_func = c_func
self._py_func = py_func
@property
def c_func(self) -> "ctypes._FuncPointer":
return self._c_func
@property
def py_func(self) -> Callable:
return self._py_func
def _decode_type(
res: Any,
struct_map: StructMap,
current: Optional[Type["ctypes._CData"]],
) -> Any:
res_typ = type(res)
if res_typ.__name__.startswith("LP_"):
struct_type = struct_map.get(res_typ._type_) # type: ignore
struct = (
struct_type.from_existing(res.contents) if struct_type else None
) # fmt: off
res = (
TypedCPointer(
ctypes.addressof(res),
res_typ,
ctypes.sizeof(res),
alt=True,
)
if not issubclass(type(res.contents), ctypes.Structure)
else StructPointer(id(struct), struct)
)
# type safety gets mad if i dont use elif here
elif current is ctypes.c_void_p:
res = VoidPointer(res, ctypes.sizeof(ctypes.c_void_p(res)))
elif issubclass(res_typ, ctypes.Structure):
st = struct_map.get(res_typ)
if st:
res = st.from_existing(res)
elif isinstance(res, bytes):
return res.decode()
return res
def _decode_response(
res: Any,
struct_map: StructMap,
fn: "ctypes._NamedFuncPointer",
) -> Any:
return _decode_type(res, struct_map, fn.restype) # type: ignore
def _process_args(
args: Iterable[Any],
argtypes: Sequence[Type["ctypes._CData"]],
name: str,
struct_map: StructMap,
) -> None:
for index, (value, typ) in enumerate(zip(args, argtypes)):
if value is inspect._empty:
continue
if isinstance(value, _CFuncTransport):
py_func = value.py_func
sig = inspect.signature(py_func)
_process_args(
[param.annotation for param in sig.parameters.values()],
value.c_func._argtypes_, # type: ignore
py_func.__name__,
struct_map,
)
continue
is_c_func: bool = isinstance(
typ,
PyCFuncPtrType,
)
n_type = get_py(typ) if not is_c_func else FunctionType
if typ.__name__.startswith("LP_"):
ptr_tp = typ._type_ # type: ignore
if issubclass(ptr_tp, ctypes.Structure): # type: ignore
n_type = StructPointer
struct = struct_map.get(ptr_tp)
if not struct:
warnings.warn(
f"struct {ptr_tp.__name__} not in struct map",
UserWarning,
)
is_type: bool = isinstance(value, type)
if n_type is Any:
continue
if not (isinstance if not is_type else issubclass)(value, n_type):
v_type = type(value) if not is_type else value
if (n_type in {BasePointer, BaseCPointer, StructPointer}) and (
value is None
):
continue
if (n_type is FunctionType) and is_c_func:
continue
if (
typ
in {
ctypes.c_char_p,
ctypes.c_void_p,
}
) and (value is None):
continue
if ((v_type is ctypes.c_char_p) and (n_type is bytes)) or (
issubclass(v_type, BaseCPointer) and (typ is ctypes.c_void_p)
):
continue
raise InvalidBindingParameter(
f"argument {index + 1} of {name} got invalid type: expected {n_type.__name__}, got {v_type.__name__}" # noqa
)
def _validate_args(
args: Iterable[Any],
fn: "ctypes._NamedFuncPointer",
struct_map: StructMap,
) -> None:
if not fn.argtypes:
return
_process_args(args, fn.argtypes, fn.__name__, struct_map)
def _solve_func(
fn: Callable,
ct_fn: "ctypes._FuncPointer",
struct_map: StructMap,
) -> _CFuncTransport:
at = ct_fn._argtypes_ # type: ignore
@ctypes.CFUNCTYPE(ct_fn._restype_, *at) # type: ignore
def wrapper(*args):
callback_args = []
for value, ctype in zip(args, at):
callback_args.append(_decode_type(value, struct_map, ctype))
return fn(*callback_args)
return _CFuncTransport(wrapper, fn)
@handle
def binding_base(
fn: "ctypes._NamedFuncPointer",
*simple_args,
map_extra: Optional[StructMap] = None,
) -> Any:
smap = {**STRUCT_MAP, **(map_extra or {})}
args = [i if i is not NULL else None for i in simple_args]
validator_args = [
arg
if (
(not isinstance(arg, FunctionType))
and (not isinstance(arg, PyCFuncPtrType))
)
else _solve_func(
arg, # type: ignore
typ, # type: ignore
smap,
)
for arg, typ in zip(
args,
fn.argtypes or [None for _ in args], # type: ignore
)
]
_validate_args(
validator_args,
fn,
smap,
)
res = fn(
*[
i
if not isinstance(
i,
_CFuncTransport,
)
else i.c_func
for i in validator_args
]
)
return _decode_response(
res,
smap,
fn,
)
@handle
def make_string(data: StringLike) -> Union[bytes, ctypes.c_char_p]:
if (type(data) not in {VoidPointer, str, bytes, TypedCPointer}) and data:
raise InvalidBindingParameter(
f"expected a string-like object, got {repr(data)}" # noqa
)
if isinstance(data, bytes):
return data
is_typed_ptr: bool = isinstance(data, TypedCPointer)
if isinstance(data, VoidPointer) or isinstance(data, TypedCPointer):
# mypy is forcing me to call this twice
if is_typed_ptr and (data.type is not bytes): # type: ignore
raise InvalidBindingParameter(
f"{data} does not point to bytes",
)
if is_typed_ptr and (not data.alt): # type: ignore
return ctypes.c_char_p.from_address(data.ensure())
return ctypes.c_char_p(data.ensure())
if isinstance(data, str):
return data.encode()
if not data:
data = ctypes.c_char_p(None) # type: ignore
assert isinstance(data, ctypes.c_char_p), f"{data} is not a char*"
return data
def make_format(*args: Format) -> Iterator[Format]:
for i in args:
if isinstance(i, (VoidPointer, str, bytes)):
yield make_string(i) # type: ignore
continue
yield i
def make_char(char: CharLike) -> bytes:
if isinstance(char, int):
return chr(char).encode()
charp = make_string(char)
string = (
charp
if not isinstance(
charp,
ctypes.c_char_p,
)
else _not_null(charp.value)
)
if len(string) != 1:
raise InvalidBindingParameter(
f'"{string.decode()}" should have a length of 1',
)
return string
def isalnum(c: CharLike) -> int:
return binding_base(dll.isalnum, make_char(c))
def isalpha(c: CharLike) -> int:
return binding_base(dll.isalpha, make_char(c))
def iscntrl(c: CharLike) -> int:
return binding_base(dll.iscntrl, make_char(c))
def isdigit(c: CharLike) -> int:
return binding_base(dll.isdigit, make_char(c))
def isgraph(c: CharLike) -> int:
return binding_base(dll.isgraph, make_char(c))
def islower(c: CharLike) -> int:
return binding_base(dll.islower, make_char(c))
def isprint(c: CharLike) -> int:
return binding_base(dll.isprint, make_char(c))
def ispunct(c: CharLike) -> int:
return binding_base(dll.ispunct, make_char(c))
def isspace(c: CharLike) -> int:
return binding_base(dll.isspace, make_char(c))
def isupper(c: CharLike) -> int:
return binding_base(dll.isupper, make_char(c))
def isxdigit(c: CharLike) -> int:
return binding_base(dll.isxdigit, make_char(c))
def tolower(c: CharLike) -> str:
return binding_base(dll.tolower, make_char(c))
def toupper(c: CharLike) -> str:
return binding_base(dll.toupper, make_char(c))
def setlocale(category: int, locale: StringLike) -> str:
return binding_base(dll.setlocale, category, make_string(locale))
def frexp(x: float, exponent: TypedPtr[int]) -> int:
return binding_base(mdll.frexp, x, exponent)
def ldexp(x: float, exponent: int) -> int:
return binding_base(mdll.ldexp, x, exponent)
def modf(x: float, integer: TypedPtr[float]) -> int:
return binding_base(mdll.modf, x, integer)
def fclose(stream: PointerLike) -> int:
return binding_base(dll.fclose, stream)
def clearerr(stream: PointerLike) -> None:
return binding_base(dll.clearerr, stream)
def feof(stream: PointerLike) -> int:
return binding_base(dll.feof, stream)
def ferror(stream: PointerLike) -> int:
return binding_base(dll.ferror, stream)
def fflush(stream: PointerLike) -> int:
return binding_base(dll.fflush, stream)
def fgetpos(stream: PointerLike, pos: PointerLike) -> int:
return binding_base(dll.fgetpos, stream, pos)
def fopen(filename: StringLike, mode: StringLike) -> VoidPointer:
return binding_base(
dll.fopen,
make_string(filename),
make_string(mode),
)
def fread(
ptr: PointerLike,
size: int,
nmemb: int,
stream: PointerLike,
) -> int:
return binding_base(dll.fread, ptr, size, nmemb, stream)
def freopen(
filename: StringLike,
mode: StringLike,
stream: PointerLike,
) -> VoidPointer:
return binding_base(
dll.freopen,
make_string(filename),
make_string(mode),
stream,
)
def fseek(stream: PointerLike, offset: int, whence: int) -> int:
return binding_base(dll.fseek, stream, offset, whence)
def fsetpos(stream: PointerLike, pos: PointerLike) -> int:
return binding_base(dll.fsetpos, stream, pos)
def ftell(stream: PointerLike) -> int:
return binding_base(dll.ftell, stream)
def fwrite(
ptr: PointerLike,
size: int,
nmemb: int,
stream: PointerLike,
) -> int:
return binding_base(dll.fwrite, ptr, size, nmemb, stream)
def remove(filename: StringLike) -> int:
return binding_base(dll.remove, make_string(filename))
def rename(old_filename: StringLike, new_filename: StringLike) -> int:
return binding_base(
dll.rename,
make_string(old_filename),
make_string(new_filename),
)
def rewind(stream: PointerLike) -> None:
return binding_base(dll.rewind, stream)
def setbuf(stream: PointerLike, buffer: StringLike) -> None:
return binding_base(dll.setbuf, stream, make_string(buffer))
def setvbuf(
stream: PointerLike,
buffer: str,
mode: int,
size: int,
) -> int:
return binding_base(
dll.setvbuf,
stream,
make_string(buffer),
mode,
size,
)
def tmpfile() -> VoidPointer:
return binding_base(dll.tmpfile)
def tmpnam(string: str) -> str:
return binding_base(dll.tmpnam, make_string(string))
def fprintf(stream: PointerLike, fmt: StringLike, *args: Format) -> int:
return binding_base(
dll.fprintf,
stream,
make_string(fmt),
*make_format(*args),
)
def printf(fmt: StringLike, *args: Format) -> int:
return binding_base(dll.printf, make_string(fmt), *make_format(*args))
def sprintf(string: StringLike, fmt: StringLike, *args: Format) -> int:
return binding_base(
dll.sprintf,
make_string(string),
make_string(fmt),
*make_format(*args),
)
def fscanf(stream: PointerLike, fmt: StringLike, *args: Format) -> int:
return binding_base(
dll.fscanf,
stream,
make_string(fmt),
*make_format(*args),
)
def scanf(fmt: StringLike, *args: Format) -> int:
return binding_base(dll.scanf, make_string(fmt), *make_format(*args))
def sscanf(string: StringLike, fmt: StringLike, *args: Format) -> int:
return binding_base(
dll.sscanf,
make_string(string),
make_string(fmt),
*make_format(*args),
)
def fgetc(stream: PointerLike) -> int:
return binding_base(dll.fgetc, stream)
def fgets(string: StringLike, n: int, stream: PointerLike) -> str:
return binding_base(
dll.fgets,
make_string(string),
n,
stream,
)
def fputc(char: int, stream: PointerLike) -> int:
return binding_base(dll.fputc, char, stream)
def fputs(string: StringLike, stream: PointerLike) -> int:
return binding_base(dll.fputs, make_string(string), stream)
def getc(stream: PointerLike) -> int:
return binding_base(dll.getc, stream)
def getchar() -> int:
return binding_base(dll.getchar)
def gets(string: StringLike) -> str:
return binding_base(dll.gets, make_string(string))
def putc(char: int, stream: PointerLike) -> int:
return binding_base(dll.putc, char, stream)
def putchar(char: int) -> int:
return binding_base(dll.putchar, char)
def puts(string: StringLike) -> int:
return binding_base(dll.puts, make_string(string))
def ungetc(char: int, stream: PointerLike) -> int:
return binding_base(dll.ungetc, char, stream)
def perror(string: StringLike) -> None:
return binding_base(dll.perror, make_string(string))
def strtod(string: StringLike, endptr: PointerLike) -> int:
return binding_base(dll.strtod, make_string(string), endptr)
def strtol(
string: StringLike,
endptr: PointerLike,
base: int,
) -> int:
return binding_base(
dll.strtol,
make_string(string),
endptr,
base,
)
def strtoul(
string: StringLike,
endptr: PointerLike,
base: int,
) -> int:
return binding_base(
dll.strtoul,
make_string(string),
endptr,
base,
)
def abort() -> None:
return binding_base(dll.abort)
def exit(status: int) -> None:
return binding_base(dll.exit, status)
def getenv(name: StringLike) -> str:
return binding_base(dll.getenv, make_string(name))
def system(string: StringLike) -> int:
return binding_base(dll.system, make_string(string))
def abs(x: int) -> int:
return binding_base(dll.abs, x)
def labs(x: int) -> int:
return binding_base(dll.labs, x)
def rand() -> int:
return binding_base(dll.rand)
def srand(seed: int) -> None:
return binding_base(dll.srand, seed)
def mblen(string: StringLike, n: int) -> int:
return binding_base(
dll.mblen,
make_string(string),
n,
)
def mbstowcs(pwcs: StringLike, string: StringLike, n: int) -> int:
return binding_base(
dll.mbstowcs,
pwcs,
make_string(string),
n,
)
def mbtowc(pwc: StringLike, string: StringLike, n: int) -> int:
return binding_base(
dll.mbtowc,
pwc,
make_string(string),
n,
)
def wcstombs(string: StringLike, pwcs: str, n: int) -> int:
return binding_base(dll.wcstombs, make_string(string), pwcs, n)
def wctomb(string: StringLike, wchar: str) -> int:
return binding_base(dll.wctomb, make_string(string), wchar)
def memchr(string: PointerLike, c: int, n: int) -> VoidPointer:
return binding_base(dll.memchr, string, c, n)
def memcmp(
str1: PointerLike,
str2: PointerLike,
n: int,
) -> int:
return binding_base(dll.memcmp, str1, str2, n)
def memcpy(
dest: PointerLike,
src: PointerLike,
n: int,
) -> VoidPointer:
return binding_base(dll.memcpy, dest, src, n)
def memmove(
dest: PointerLike,
src: PointerLike,
n: int,
) -> VoidPointer:
return binding_base(dll.memmove, dest, src, n)
def memset(string: PointerLike, c: int, n: int) -> VoidPointer:
return binding_base(dll.memset, string, c, n)
def strcat(dest: StringLike, src: StringLike) -> str:
return binding_base(
dll.strcat,
make_string(dest),
make_string(src),
)
def strncat(dest: StringLike, src: StringLike, n: int) -> str:
return binding_base(
dll.strncat,
make_string(dest),
make_string(src),
n,
)
def strchr(string: StringLike, c: int) -> str:
return binding_base(dll.strchr, make_string(string), c)
def strcmp(str1: StringLike, str2: StringLike) -> int:
return binding_base(
dll.strcmp,
make_string(str1),
make_string(str2),
)
def strncmp(str1: StringLike, str2: StringLike, n: int) -> int:
return binding_base(
dll.strncmp,
make_string(str1),
make_string(str2),
n,
)
def strcoll(str1: StringLike, str2: StringLike) -> int:
return binding_base(
dll.strcoll,
make_string(str1),
make_string(str2),
)
def strcpy(dest: StringLike, src: StringLike) -> str:
return binding_base(
dll.strcpy,
make_string(dest),
make_string(src),
)
def strncpy(dest: StringLike, src: StringLike, n: int) -> str:
return binding_base(
dll.strncpy,
make_string(dest),
make_string(src),
n,
)
def strcspn(str1: StringLike, str2: StringLike) -> int:
return binding_base(
dll.strcspn,
make_string(str1),
make_string(str2),
)
def strerror(errnum: int) -> str:
return binding_base(dll.strerror, errnum)
def strlen(string: StringLike) -> int:
return binding_base(dll.strlen, make_string(string))
def strpbrk(str1: StringLike, str2: StringLike) -> str:
return binding_base(
dll.strpbrk,
make_string(str1),
make_string(str2),
)
def strrchr(string: StringLike, c: int) -> str:
return binding_base(dll.strrchr, make_string(string), c)
def strspn(str1: StringLike, str2: StringLike) -> int:
return binding_base(
dll.strspn,
make_string(str1),
make_string(str2),
)
def strstr(haystack: StringLike, needle: StringLike) -> str:
return binding_base(
dll.strstr,
make_string(haystack),
make_string(needle),
)
def strtok(string: StringLike, delim: StringLike) -> str:
return binding_base(
dll.strtok,
make_string(string),
make_string(delim),
)
def strxfrm(dest: StringLike, src: StringLike, n: int) -> int:
return binding_base(
dll.strxfrm,
make_string(dest),
make_string(src),
n,
)
def asctime(timeptr: StructPointer[Tm]) -> str:
return binding_base(dll.asctime, timeptr)
def clock() -> int:
return binding_base(dll.clock)