Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions c/os/_libc_darwin_arm64.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Code generated by llcppg; classified from the common libc binding.
#include <arpa/inet.h>
#include <assert.h>
#include <ctype.h>
#include <dirent.h>
#include <dlfcn.h>
#include <errno.h>
#include <fcntl.h>
#include <fnmatch.h>
#include <glob.h>
#include <grp.h>
#include <inttypes.h>
#include <libgen.h>
#include <limits.h>
#include <locale.h>
#include <net/if.h>
#include <netdb.h>
#include <netinet/in.h>
#include <poll.h>
#include <pthread.h>
#include <pwd.h>
#include <sched.h>
#include <semaphore.h>
#include <setjmp.h>
#include <signal.h>
#include <spawn.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/file.h>
#include <sys/mman.h>
#include <sys/resource.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <sys/utsname.h>
#include <sys/wait.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include <utime.h>
#include <mach/mach_types.h>

int _llcppg___darwin_check_fd_set(int _a, const void *_b) {
return __darwin_check_fd_set(_a, _b);
}

int _llcppg___darwin_fd_isset(int _fd, const struct fd_set *_p) {
return __darwin_fd_isset(_fd, _p);
}
3 changes: 0 additions & 3 deletions c/os/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,3 @@ type DIR struct {

//go:linkname Opendir C.opendir
func Opendir(name *c.Char) *DIR

//go:linkname Closedir C.closedir
func Closedir(dir *DIR) c.Int
8 changes: 8 additions & 0 deletions c/os/dirent_unix64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build (darwin && arm64 && !ios) || (linux && amd64 && !android)

package os

import "github.com/goplus/lib/c/syscall"

// Dirent shares the representation already used by Readdir.
type Dirent = syscall.Dirent
2 changes: 1 addition & 1 deletion c/os/flags_default.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:build !windows
//go:build !windows && !(linux && (amd64 || arm64) && !android)

/*
* Copyright (c) 2026 The XGo Authors (xgo.dev). All rights reserved.
Expand Down
6 changes: 0 additions & 6 deletions c/os/functions_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ func Getcwd(buffer c.Pointer, size uintptr) *c.Char
//go:linkname Open C.open
func Open(path *c.Char, flags c.Int, __llgo_va_list ...any) c.Int

//go:linkname Fcntl C.fcntl
func Fcntl(a c.Int, b c.Int, __llgo_va_list ...any) c.Int

//go:linkname Close C.close
func Close(fd c.Int) c.Int

//go:linkname Read C.read
func Read(fd c.Int, buf c.Pointer, count uintptr) int

Expand Down
30 changes: 30 additions & 0 deletions c/os/generated_native_darwin_arm64_llgo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build llgo && darwin && arm64 && !ios

package os

import (
"testing"
"unsafe"
)

func TestGeneratedMachMessageHeaderLayout(t *testing.T) {
var header MachMsgHeaderT
if unsafe.Sizeof(header) != 24 || unsafe.Alignof(header) != 4 {
t.Fatalf("mach_msg_header_t = %d/%d, want 24/4", unsafe.Sizeof(header), unsafe.Alignof(header))
}
}
func TestGeneratedUUIDOutputBuffer(t *testing.T) {
var value UuidT
for i := range value {
value[i] = 0xa5
}
UuidClear(&value[0])
for i, b := range value {
if b != 0 {
t.Fatalf("uuid_clear left byte %d = %d", i, b)
}
}
if result := UuidIsNull(&value[0]); result == 0 {
t.Fatal("cleared uuid is not nil")
}
}
42 changes: 42 additions & 0 deletions c/os/generated_native_llgo_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//go:build llgo && ((darwin && arm64 && !ios) || (linux && (amd64 || arm64) && !android))

package os

import (
"github.com/goplus/lib/c"
"testing"
"unsafe"
)

func TestGeneratedPipeIO(t *testing.T) {
var pair [2]c.Int
if result := NativePipe(&pair[0]); result != 0 {
t.Fatalf("pipe = %d", result)
}
defer func() {
for _, fd := range pair {
if result := Close(fd); result != 0 {
t.Errorf("close = %d", result)
}
}
}()
input := [6]byte{0, 1, 127, 128, 254, 255}
var output [6]byte
for offset := 0; offset < len(input); {
n := NativeWrite(pair[1], unsafe.Pointer(&input[offset]), c.SizeT(len(input)-offset))
if n <= 0 {
t.Fatalf("write = %d", n)
}
offset += int(n)
}
for offset := 0; offset < len(output); {
n := NativeRead(pair[0], unsafe.Pointer(&output[offset]), c.SizeT(len(output)-offset))
if n <= 0 {
t.Fatalf("read = %d", n)
}
offset += int(n)
}
if output != input {
t.Fatalf("pipe data = %v, want %v", output, input)
}
}
38 changes: 38 additions & 0 deletions c/os/legacy_functions_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build !windows && !((darwin && arm64 && !ios) || (linux && (amd64 || arm64) && !android))

package os

import (
"github.com/goplus/lib/c"
_ "unsafe"
)

//go:linkname Closedir C.closedir
func Closedir(dir *DIR) c.Int

//go:linkname Close C.close
func Close(fd c.Int) c.Int

//go:linkname Fchdir C.fchdir
func Fchdir(dirfd c.Int) c.Int

//go:linkname Dup C.dup
func Dup(fd c.Int) c.Int

//go:linkname Dup2 C.dup2
func Dup2(oldfd c.Int, newfd c.Int) c.Int

//go:linkname Fsync C.fsync
func Fsync(fd c.Int) c.Int

//go:linkname Isatty C.isatty
func Isatty(fd c.Int) c.Int

// In Mach, all system calls take normal arguments and always return an
// error code (zero for success).
//
//go:linkname Syscall C.syscall
func Syscall(sysno c.Long, __llgo_va_list ...any) c.Long

//go:linkname Fcntl C.fcntl
func Fcntl(a c.Int, b c.Int, __llgo_va_list ...any) c.Int
Loading
Loading