feat: export Linux Open File Description (OFD) lock constants (sqlite#255)

feat: export Linux Open File Description (OFD) lock constants

Adds support for Linux Open File Description (OFD) locks (F_OFD_GETLK = 36, F_OFD_SETLK = 37, F_OFD_SETLKW = 38) to enable file-descriptor-scoped POSIX locking in downstream packages like modernc.org/sqlite.

  1. Exports F_OFD_GETLK, F_OFD_SETLK, and F_OFD_SETLKW in fcntl/fcntl_linux_amd64.go with C header provenance comments matching ccgo -header output.

  2. Updates genheaders.go to prepend #define _GNU_SOURCE 1 when generating fcntl headers. Because Linux F_OFD_* constants are guarded by #ifdef __USE_GNU in <bits/fcntl-linux.h>, defining _GNU_SOURCE ensures these constants are not stripped during future regenerations.

    Note

    While running ccgo -header with _GNU_SOURCE on <fcntl.h> exposes ~123 additional Linux/GNU extension symbols (such as O_TMPFILE, O_PATH, SPLICE_F_*, FALLOC_FL_*, and F_SEAL_*), we intentionally cherry-picked only the three F_OFD_* constants into fcntl_linux_amd64.go to keep the diff minimal and avoid slurping in unrelated API surface.

  3. Adds internal/overlay/musl/src/fcntl/fcntl.c as a musl overlay to route the new OFD commands through SYS_fcntl with (void *)arg pointer casting and cancellation point handling (syscall_cp).

For reviewer convenience, the exact diff of the overlay against upstream musl's src/fcntl/fcntl.c is:

--- a/src/fcntl/fcntl.c
+++ b/src/fcntl/fcntl.c
@@ -15,1 +15,1 @@
-	if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
+	if (cmd == F_SETLKW || cmd == F_OFD_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg);
@@ -41,2 +41,4 @@
 	case F_SETLK:
 	case F_GETLK:
+	case F_OFD_SETLK:
+	case F_OFD_GETLK:
 	case F_GETOWN_EX:

Related Merge Requests & Issues:

  • Companion Windows build fix needed to compile all targets (make build_all_targets) and test fixtures: !32 (merged)
  • Main SQLite tracking issue: cznic/sqlite#255
Edited by Nathan Herring

Merge request reports

Loading
Loading