diff --git a/c/sys/generated_native_llgo_test.go b/c/sys/generated_native_llgo_test.go new file mode 100644 index 00000000..fbe14744 --- /dev/null +++ b/c/sys/generated_native_llgo_test.go @@ -0,0 +1,25 @@ +//go:build llgo && ((darwin && arm64 && !ios) || (linux && (amd64 || arm64) && !android)) + +package sys + +import ( + "testing" + "unsafe" +) + +func TestGeneratedGettimeofday(t *testing.T) { + var timeout Timeval + if result := Select(0, nil, nil, nil, &timeout); result != 0 { + t.Fatalf("select with zero timeout = %d", result) + } + var value Timeval + if unsafe.Sizeof(value) != 16 || unsafe.Alignof(value) != 8 { + t.Fatalf("timeval layout = %d/%d", unsafe.Sizeof(value), unsafe.Alignof(value)) + } + if result := Gettimeofday(&value, nil); result != 0 { + t.Fatalf("gettimeofday = %d", result) + } + if value.Sec <= 0 || value.Usec < 0 || value.Usec >= 1000000 { + t.Fatalf("invalid timeval %v", value) + } +} diff --git a/c/sys/libc_darwin_arm64.go b/c/sys/libc_darwin_arm64.go new file mode 100644 index 00000000..b2ec88f6 --- /dev/null +++ b/c/sys/libc_darwin_arm64.go @@ -0,0 +1,76 @@ +//go:build darwin && arm64 && !ios + +// Code generated by llcppg; DO NOT EDIT. +// Classified from the common libc binding. + +package sys + +import ( + "github.com/goplus/lib/c" + lltime "github.com/goplus/lib/c/time" + "unsafe" +) + +//go:linkname Pselect C.pselect +func Pselect(_llcppg_param1 c.Int, _llcppg_param2 *FdSet, _llcppg_param3 *FdSet, _llcppg_param4 *FdSet, _llcppg_param5 *lltime.Timespec, _llcppg_param6 *c.Uint) c.Int + +// Names of the interval timers, and structure +// defining a timer setting. +const ( + ITIMER_REAL = 0 + ITIMER_VIRTUAL = 1 + ITIMER_PROF = 2 +) + +const ( + // not on dst + DST_NONE = 0 + // USA style dst + DST_USA = 1 + // Australian style dst + DST_AUST = 2 + // Western European dst + DST_WET = 3 + // Middle European dst + DST_MET = 4 + // Eastern European dst + DST_EET = 5 + // Canada + DST_CAN = 6 +) + +// Structure used as a parameter by getitimer(2) and setitimer(2) system +// calls. +type Itimerval struct { + ItInterval Timeval + ItValue Timeval +} + +type Timezone struct { + TzMinuteswest c.Int + TzDsttime c.Int +} + +//go:linkname Adjtime C.adjtime +func Adjtime(_llcppg_param1 *Timeval, _llcppg_param2 *Timeval) c.Int + +//go:linkname Futimes C.futimes +func Futimes(_llcppg_param1 c.Int, _llcppg_param2 *Timeval) c.Int + +//go:linkname Lutimes C.lutimes +func Lutimes(_llcppg_param1 *c.Char, _llcppg_param2 *Timeval) c.Int + +//go:linkname Settimeofday C.settimeofday +func Settimeofday(_llcppg_param1 *Timeval, _llcppg_param2 *Timezone) c.Int + +//go:linkname Getitimer C.getitimer +func Getitimer(_llcppg_param1 c.Int, _llcppg_param2 *Itimerval) c.Int + +//go:linkname Gettimeofday C.gettimeofday +func Gettimeofday(_llcppg_param1 *Timeval, _llcppg_param2 unsafe.Pointer) c.Int + +//go:linkname Setitimer C.setitimer +func Setitimer(_llcppg_param1 c.Int, _llcppg_param2 *Itimerval, _llcppg_param3 *Itimerval) c.Int + +//go:linkname Utimes C.utimes +func Utimes(_llcppg_param1 *c.Char, _llcppg_param2 *Timeval) c.Int diff --git a/c/sys/libc_linux_amd64.go b/c/sys/libc_linux_amd64.go new file mode 100644 index 00000000..1c7afb30 --- /dev/null +++ b/c/sys/libc_linux_amd64.go @@ -0,0 +1,108 @@ +//go:build linux && amd64 && !android + +// Code generated by llcppg; DO NOT EDIT. +// Classified from the common libc binding. + +package sys + +import ( + "github.com/goplus/lib/c" + llsignal "github.com/goplus/lib/c/signal" + lltime "github.com/goplus/lib/c/time" + _ "unsafe" +) + +// Maximum number of file descriptors in `fd_set'. +const FD_SETSIZE = 1024 + +// Same as above only that the TIMEOUT value is given with higher +// resolution and a sigmask which is been set temporarily. This version +// should be used. +// +// This function is a cancellation point and therefore not marked with +// __THROW. +// +//go:linkname Pselect C.pselect +func Pselect(__nfds c.Int, __readfds *FdSet, __writefds *FdSet, __exceptfds *FdSet, __timeout *lltime.Timespec, __sigmask *llsignal.SigsetT) c.Int + +// Structure crudely representing a timezone. +// This is obsolete and should never be used. +type Timezone struct { + TzMinuteswest c.Int + TzDsttime c.Int +} + +// Values for the first argument to `getitimer' and `setitimer'. +type X__ItimerWhich c.Uint + +const ( + // Timers run in real time. + ITIMER_REAL X__ItimerWhich = 0 + // Timers run only when the process is executing. + ITIMER_VIRTUAL X__ItimerWhich = 1 + // Timers run when the process is executing and when + // the system is executing on behalf of the process. + ITIMER_PROF X__ItimerWhich = 2 +) + +// Type of the second argument to `getitimer' and +// the second and third arguments `setitimer'. +type Itimerval struct { + ItInterval Timeval + ItValue Timeval +} + +type X__TimezonePtrT = *Timezone + +// Get the current time of day and timezone information, +// putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled. +// Returns 0 on success, -1 on errors. +// NOTE: This form of timezone information is obsolete. +// Use the functions and variables declared in instead. +// +//go:linkname Gettimeofday C.gettimeofday +func Gettimeofday(__tv *Timeval, __tz X__TimezonePtrT) c.Int + +// Set the current time of day and timezone information. +// This call is restricted to the super-user. +// +//go:linkname Settimeofday C.settimeofday +func Settimeofday(__tv *Timeval, __tz *Timezone) c.Int + +// Adjust the current time of day by the amount in DELTA. +// If OLDDELTA is not NULL, it is filled in with the amount +// of time adjustment remaining to be done from the last `adjtime' call. +// This call is restricted to the super-user. +// +//go:linkname Adjtime C.adjtime +func Adjtime(__delta *Timeval, __olddelta *Timeval) c.Int + +// Set *VALUE to the current setting of timer WHICH. +// Return 0 on success, -1 on errors. +// +//go:linkname Getitimer C.getitimer +func Getitimer(__which c.Int, __value *Itimerval) c.Int + +// Set the timer WHICH to *NEW. If OLD is not NULL, +// set *OLD to the old value of timer WHICH. +// Returns 0 on success, -1 on errors. +// +//go:linkname Setitimer C.setitimer +func Setitimer(__which c.Int, __new *Itimerval, __old *Itimerval) c.Int + +// Change the access time of FILE to TVP[0] and the modification time of +// FILE to TVP[1]. If TVP is a null pointer, use the current time instead. +// Returns 0 on success, -1 on errors. +// +//go:linkname Utimes C.utimes +func Utimes(__file *c.Char, __tvp *Timeval) c.Int + +// Same as `utimes', but does not follow symbolic links. +// +//go:linkname Lutimes C.lutimes +func Lutimes(__file *c.Char, __tvp *Timeval) c.Int + +// Same as `utimes', but takes an open file descriptor instead of a name. +// +//go:linkname Futimes C.futimes +func Futimes(__fd c.Int, __tvp *Timeval) c.Int diff --git a/c/sys/libc_linux_arm64.go b/c/sys/libc_linux_arm64.go new file mode 100644 index 00000000..e7429366 --- /dev/null +++ b/c/sys/libc_linux_arm64.go @@ -0,0 +1,108 @@ +//go:build linux && arm64 && !android + +// Code generated by llcppg; DO NOT EDIT. +// Classified from the common libc binding. + +package sys + +import ( + "github.com/goplus/lib/c" + llsignal "github.com/goplus/lib/c/signal" + lltime "github.com/goplus/lib/c/time" + _ "unsafe" +) + +// Maximum number of file descriptors in `fd_set'. +const FD_SETSIZE = 1024 + +// Same as above only that the TIMEOUT value is given with higher +// resolution and a sigmask which is been set temporarily. This version +// should be used. +// +// This function is a cancellation point and therefore not marked with +// __THROW. +// +//go:linkname Pselect C.pselect +func Pselect(__nfds c.Int, __readfds *FdSet, __writefds *FdSet, __exceptfds *FdSet, __timeout *lltime.Timespec, __sigmask *llsignal.SigsetT) c.Int + +// Structure crudely representing a timezone. +// This is obsolete and should never be used. +type Timezone struct { + TzMinuteswest c.Int + TzDsttime c.Int +} + +// Values for the first argument to `getitimer' and `setitimer'. +type X__ItimerWhich c.Uint + +const ( + // Timers run in real time. + ITIMER_REAL X__ItimerWhich = 0 + // Timers run only when the process is executing. + ITIMER_VIRTUAL X__ItimerWhich = 1 + // Timers run when the process is executing and when + // the system is executing on behalf of the process. + ITIMER_PROF X__ItimerWhich = 2 +) + +// Type of the second argument to `getitimer' and +// the second and third arguments `setitimer'. +type Itimerval struct { + ItInterval Timeval + ItValue Timeval +} + +type X__TimezonePtrT = *Timezone + +// Get the current time of day and timezone information, +// putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled. +// Returns 0 on success, -1 on errors. +// NOTE: This form of timezone information is obsolete. +// Use the functions and variables declared in instead. +// +//go:linkname Gettimeofday C.gettimeofday +func Gettimeofday(__tv *Timeval, __tz X__TimezonePtrT) c.Int + +// Set the current time of day and timezone information. +// This call is restricted to the super-user. +// +//go:linkname Settimeofday C.settimeofday +func Settimeofday(__tv *Timeval, __tz *Timezone) c.Int + +// Adjust the current time of day by the amount in DELTA. +// If OLDDELTA is not NULL, it is filled in with the amount +// of time adjustment remaining to be done from the last `adjtime' call. +// This call is restricted to the super-user. +// +//go:linkname Adjtime C.adjtime +func Adjtime(__delta *Timeval, __olddelta *Timeval) c.Int + +// Set *VALUE to the current setting of timer WHICH. +// Return 0 on success, -1 on errors. +// +//go:linkname Getitimer C.getitimer +func Getitimer(__which c.Int, __value *Itimerval) c.Int + +// Set the timer WHICH to *NEW. If OLD is not NULL, +// set *OLD to the old value of timer WHICH. +// Returns 0 on success, -1 on errors. +// +//go:linkname Setitimer C.setitimer +func Setitimer(__which c.Int, __new *Itimerval, __old *Itimerval) c.Int + +// Change the access time of FILE to TVP[0] and the modification time of +// FILE to TVP[1]. If TVP is a null pointer, use the current time instead. +// Returns 0 on success, -1 on errors. +// +//go:linkname Utimes C.utimes +func Utimes(__file *uint8, __tvp *Timeval) c.Int + +// Same as `utimes', but does not follow symbolic links. +// +//go:linkname Lutimes C.lutimes +func Lutimes(__file *uint8, __tvp *Timeval) c.Int + +// Same as `utimes', but takes an open file descriptor instead of a name. +// +//go:linkname Futimes C.futimes +func Futimes(__fd c.Int, __tvp *Timeval) c.Int diff --git a/c/sys/llcppg.cfg b/c/sys/llcppg.cfg new file mode 100644 index 00000000..75e27be3 --- /dev/null +++ b/c/sys/llcppg.cfg @@ -0,0 +1,3 @@ +{ + "Dir": ".sysroot/include" +} diff --git a/c/sys/llcppg.pub b/c/sys/llcppg.pub new file mode 100644 index 00000000..053009ca --- /dev/null +++ b/c/sys/llcppg.pub @@ -0,0 +1,8 @@ +D github.com/goplus/lib/c/signal +D github.com/goplus/lib/c/time +T __itimer_which X__ItimerWhich +T __timezone_ptr_t X__TimezonePtrT +T fd_set FdSet +T itimerval Itimerval +T timeval Timeval +T timezone Timezone diff --git a/c/sys/select.go b/c/sys/select.go index 9449efc9..34852aea 100644 --- a/c/sys/select.go +++ b/c/sys/select.go @@ -30,7 +30,16 @@ func FD_SET(fd c.Int, fds *FdSet) //go:linkname FD_ISSET C.llgo_FD_ISSET func FD_ISSET(fd c.Int, fds *FdSet) c.Int -//go:linkname Select C.select -func Select(n c.Int, fdsRead, fdsWrite, fdsError *FdSet, timeout *Timeval) c.Int - // ----------------------------------------------------------------------------- + +// Check the first NFDS descriptors each in READFDS (if not NULL) for read +// readiness, in WRITEFDS (if not NULL) for write readiness, and in EXCEPTFDS +// (if not NULL) for exceptional conditions. If TIMEOUT is not NULL, time out +// after waiting the interval specified therein. Returns the number of ready +// descriptors, or -1 for errors. +// +// This function is a cancellation point and therefore not marked with +// __THROW. +// +//go:linkname Select C.select +func Select(__nfds c.Int, __readfds *FdSet, __writefds *FdSet, __exceptfds *FdSet, __timeout *Timeval) c.Int