mirror of
https://github.com/carp-lang/Carp.git
synced 2024-09-11 13:37:57 +03:00
A few extra functions for handling files and char pointers.
This commit is contained in:
parent
fc693d9ba8
commit
00105618a4
@ -27,3 +27,6 @@
|
||||
(defmodule CharRef
|
||||
(defn = [a b]
|
||||
(Char.= @a @b)))
|
||||
|
||||
(defmodule PtrChar
|
||||
(register str (Fn [(Ptr Char)] String)))
|
||||
|
@ -1,5 +1,7 @@
|
||||
(system-include "carp_io.h")
|
||||
|
||||
(register-type FILE)
|
||||
|
||||
(defmodule IO
|
||||
(register println (Fn [(Ref String)] ()))
|
||||
(register print (Fn [(Ref String)] ()))
|
||||
@ -7,4 +9,6 @@
|
||||
(register get-char (Fn [] Char) "getchar")
|
||||
(register read-file (Fn [&String] String))
|
||||
(register exit (Fn [Int] a))
|
||||
(register fopen (Fn [String String] (Ptr FILE)) "fopen")
|
||||
(register fwrite (Fn [a Int Int (Ptr FILE)] ()) "fwrite")
|
||||
)
|
||||
|
@ -15,3 +15,14 @@ char Char_from_MINUS_int(int i) {
|
||||
char Char_copy(char *c) {
|
||||
return *c;
|
||||
}
|
||||
|
||||
string PtrChar_str(char *c) {
|
||||
size_t len = strlen(c) + 1;
|
||||
string ptr = CARP_MALLOC(len);
|
||||
|
||||
if (ptr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (string) memcpy(ptr, c, len);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user