diff options
Diffstat (limited to 'vapi/posix.vapi')
-rw-r--r-- | vapi/posix.vapi | 250 |
1 files changed, 250 insertions, 0 deletions
diff --git a/vapi/posix.vapi b/vapi/posix.vapi index c6d6c6a8f..916ead5ff 100644 --- a/vapi/posix.vapi +++ b/vapi/posix.vapi @@ -24,6 +24,256 @@ * Nikolay Orliuk <virkony@gmail.com> */ +#if POSIX +[CCode (cname = "bool", cheader_filename = "stdbool.h", default_value = "false")] +[BooleanType] +public struct bool { + public inline unowned string to_string () { + if (this) { + return "true"; + } else { + return "false"; + } + } + + public static inline bool parse (string str) { + if (str == "true") { + return true; + } else { + return false; + } + } +} + +[CCode (cname = "char", default_value = "\'\\0\'")] +[IntegerType (rank = 2, min = 0, max = 127)] +public struct char { + public inline string to_string () { + return "%c".printf (this); + } +} + +[CCode (cname = "unsigned char", default_value = "\'\\0\'")] +[IntegerType (rank = 3, min = 0, max = 255)] +public struct uchar { + public inline string to_string () { + return "%hhu".printf (this); + } +} + +[CCode (cname = "int", default_value = "0")] +[IntegerType (rank = 6)] +public struct int { + public inline string to_string () { + return "%d".printf (this); + } + + [CCode (cname = "atoi", cheader_filename = "stdlib.h")] + public static int parse (string str); +} + +[CCode (cname = "unsigned int", default_value = "0U")] +[IntegerType (rank = 7)] +public struct uint { + public inline string to_string () { + return "%u".printf (this); + } +} + +[CCode (cname = "short", default_value = "0")] +[IntegerType (rank = 4, min = -32768, max = 32767)] +public struct short { + public inline string to_string () { + return "%hi".printf (this); + } +} + +[CCode (cname = "unsigned short", default_value = "0U")] +[IntegerType (rank = 5, min = 0, max = 65535)] +public struct ushort { + public inline string to_string () { + return "%hu".printf (this); + } +} + +[CCode (cname = "long", default_value = "0L")] +[IntegerType (rank = 8)] +public struct long { + public inline string to_string () { + return "%li".printf (this); + } + + [CCode (cname = "atol", cheader_filename = "stdlib.h")] + public static long parse (string str); +} + +[CCode (cname = "unsigned long", default_value = "0UL")] +[IntegerType (rank = 9)] +public struct ulong { + public inline string to_string () { + return "%lu".printf (this); + } +} + +[CCode (cname = "size_t", cheader_filename = "sys/types.h", default_value = "0UL")] +[IntegerType (rank = 9)] +public struct size_t { + public inline string to_string () { + return "%zu".printf (this); + } +} + +[CCode (cname = "ssize_t", cheader_filename = "sys/types.h", default_value = "0L")] +[IntegerType (rank = 8)] +public struct ssize_t { + public inline string to_string () { + return "%zi".printf (this); + } +} + +[CCode (cname = "int8_t", cheader_filename = "stdint.h", default_value = "0")] +[IntegerType (rank = 1, min = -128, max = 127)] +public struct int8 { + [CCode (cname = "PRIi8", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } +} + +[CCode (cname = "uint8_t", cheader_filename = "stdint.h", default_value = "0U")] +[IntegerType (rank = 3, min = 0, max = 255)] +public struct uint8 { + [CCode (cname = "PRIu8", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } +} + +[CCode (cname = "int16_t", cheader_filename = "stdint.h", default_value = "0")] +[IntegerType (rank = 4, min = -32768, max = 32767)] +public struct int16 { + [CCode (cname = "PRIi16", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } +} + +[CCode (cname = "uint16_t", cheader_filename = "stdint.h", default_value = "0U")] +[IntegerType (rank = 5, min = 0, max = 65535)] +public struct uint16 { + [CCode (cname = "PRIu16", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } +} + +[CCode (cname = "int32_t", cheader_filename = "stdint.h", default_value = "0")] +[IntegerType (rank = 6)] +public struct int32 { + [CCode (cname = "PRIi32", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } +} + +[CCode (cname = "uint32_t", cheader_filename = "stdint.h", default_value = "0U")] +[IntegerType (rank = 7)] +public struct uint32 { + [CCode (cname = "PRIu32", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } +} + +[CCode (cname = "int64_t", cheader_filename = "stdint.h", default_value = "0LL")] +[IntegerType (rank = 10)] +public struct int64 { + [CCode (cname = "PRIi64", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } + + [CCode (cname = "strtoll", cheader_filename = "stdlib.h")] + public static int64 parse (string str, out unowned string? end = null, int base = 10); +} + +[CCode (cname = "uint64_t", cheader_filename = "stdint.h", default_value = "0ULL")] +[IntegerType (rank = 11)] +public struct uint64 { + [CCode (cname = "PRIu64", cheader_filename = "inttypes.h")] + public const string FORMAT; + + public inline string to_string () { + return ("%" + FORMAT).printf (this); + } + + [CCode (cname = "strtoull", cheader_filename = "stdlib.h")] + public static uint64 parse (string str, out unowned string? end = null, int base = 10); +} + +[CCode (cname = "float", default_value = "0.0F")] +[FloatingType (rank = 1)] +public struct float { + public inline string to_string () { + return "%.8g".printf (this); + } +} + +[CCode (cname = "double", default_value = "0.0")] +[FloatingType (rank = 2)] +public struct double { + public inline string to_string () { + return "%.17g".printf (this); + } + + [CCode (cname = "strtod", cheader_filename = "stdlib.h")] + public static double parse (string str, out unowned string? end = null); +} + +[CCode (cheader_filename = "time.h")] +[IntegerType (rank = 8)] +public struct time_t { + [CCode (cname = "time")] + public time_t (); +} + +[Compact] +[Immutable] +[CCode (cname = "char", const_cname = "const char", copy_function = "strdup", free_function = "free", cheader_filename = "stdlib.h,string.h")] +public class string { + [PrintfFormat] + public string printf (...); + + public inline unowned string to_string () { + return this; + } + + public int length { + [CCode (cname = "strlen")] + get; + } +} + +[CCode (cname="printf", cheader_filename = "stdio.h")] +[PrintfFormat] +public void print (string format,...); + +#endif + [CCode (cprefix = "", lower_case_cprefix = "")] namespace Posix { [CCode (cheader_filename = "assert.h")] |