# Kept for compatability with KuiklyBase-kotlin
package = platform.posix
headers = alloca.h ar.h assert.h complex.h ctype.h dirent.h dlfcn.h err.h errno.h fcntl.h \
    fenv.h fnmatch.h ftw.h getopt.h grp.h inttypes.h libgen.h limits.h \
    locale.h math.h memory.h netdb.h paths.h poll.h \
    pthread.h pwd.h regex.h resolv.h sched.h search.h semaphore.h setjmp.h signal.h \
    stdatomic.h stdint.h stddef.h stdio.h stdlib.h string.h strings.h syslog.h termios.h \
    time.h ucontext.h unistd.h utime.h utmp.h wchar.h wctype.h \
    net/ethernet.h net/if.h net/if_arp.h net/route.h \
    netinet/icmp6.h netinet/if_ether.h netinet/in.h netinet/in_systm.h \
    netinet/ip.h netinet/ip6.h netinet/ip_icmp.h netinet/tcp.h netinet/udp.h \
    sys/ioctl.h sys/ipc.h sys/mman.h sys/poll.h sys/ptrace.h \
    sys/select.h sys/shm.h sys/stat.h sys/socket.h \
    sys/time.h sys/times.h sys/utsname.h sys/wait.h \

compilerOpts = -D_ANSI_SOURCE -D_POSIX_C_SOURCE=199309 -D_BSD_SOURCE \
               -D_XOPEN_SOURCE=700 -D__need_error_t -D_GNU_SOURCE
linkerOpts = -lresolv -lm -lpthread -lutil -lcrypt -lrt
excludedFunctions = bindresvport6 __p_section __res_nisourserver __res_npquery \
                    ns_sign ns_sign2 ns_sign_tcp ns_sign_tcp2 ns_sign_tcp_init \
		    ns_find_tsig ns_verify ns_verify_tcp ns_verify_tcp_init \
		    __acos __asin __atan __atan2 __cos __sin __tan __cosh __sinh \
		    __tanh __acosh __asinh __atanh __exp __frexp __ldexp __log __log10 \
		    __modf __expm1 __log1p __logb __exp2 __log2 __pow __sqrt __hypot \
		    __cbrt __ceil __fabs __floor __fmod __drem __significand __copysign \
		    __nan __j0 __j1 __jn __y0 __y1 __yn __erf __erfc __lgamma __tgamma \
		    __gamma __lgamma_r __rint __nextafter __remainder __scalbn __ilogb \
		    __scalbln __nearbyint __round __trunc __remquo __lrint __llrint \
		    __lround __llround __fdim __fmax __fmin __fma __scalb __acosf __asinf \
		    __atanf __atan2f __cosf __sinf __tanf __coshf __sinhf __tanhf __acoshf \
		    __asinhf __atanhf __expf __frexpf __ldexpf __logf __log10f __modff \
		    __expm1f __log1pf __logbf __exp2f __log2f __powf __sqrtf __hypotf \
		    __cbrtf __ceilf __fabsf __floorf __fmodf __dremf __significandf \
		    __copysignf __nanf __j0f __j1f __jnf __y0f __y1f __ynf __erff \
		    __erfcf __lgammaf __tgammaf __gammaf __lgammaf_r __rintf __nextafterf \
		    __remainderf __scalbnf __ilogbf __scalblnf __nearbyintf __roundf __truncf \
		    __remquof __lrintf __llrintf __lroundf __llroundf __fdimf __fmaxf __fminf \
		    __fmaf __scalbf _ns_flagdata
---
// cinterop -target linux -def klib/src/platform/linux/posix.def -o platform.posix.klib

// Wrapper to access errno variable.
static int posix_errno() {
    return errno;
}

static void set_posix_errno(int value) {
    errno = value;
}

// Wrapper to access h_errno variable.
static int posix_h_errno() {
    return h_errno;
}

static void set_posix_h_errno(int value) {
    h_errno = value;
}

static short posix_htons(short x) {
    return htons(x);
}

static void posix_FD_ZERO(fd_set *set) {
    FD_ZERO(set);
}

static void posix_FD_SET(int bit, fd_set *set) {
    FD_SET(bit, set);
}

static int posix_FD_ISSET(int bit, fd_set *set) {
    return FD_ISSET(bit, set);
}

static int init_sockets() {
    return 0;
}

static void deinit_sockets() {
}
