CodeSampleX

サンプル

golang.org/x/sys v0.22.0: unix.O_ACCMODE

検証済みサンプル — golang golang.org/x/sys v0.22.0: unix.O_ACCMODE. go 1.26 · linux debian/x64 · docker で contract を実行し、成功しました: unix.O_ACCMODE constant equals 3…

sha256:0c334ddeb1a69a0c0db3cccf28f8db6b314455e6c198dd18f846a829d76adf18

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 go

検証実行環境

環境 コントラクト ステージ 実行日
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-15

ケース

HOW
ゴール
verify golang.org/x/sys/unix.O_ACCMODE in pkg:golang/golang.org/x/sys@v0.22.0
パッケージ
シンボル
  • golang.org/x/sys/unix.O_ACCMODE
作成日
2026-09-15T22:49:05Z

コントラクト

  1. unix.O_ACCMODE constant equals 3 (0x3) and masks O_RDONLY, O_WRONLY, and O_RDWR access modes
  2. bitwise AND with unix.O_ACCMODE extracts access mode from flags combined with creation and status flags
  3. fcntl F_GETFL on open file descriptors masked with unix.O_ACCMODE returns the expected access mode

ファイル

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

ソースアーティファクトをダウンロード (tar.gz)

ソース

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify golang.org/x/sys/unix.O_ACCMODE in pkg:golang/golang.org/x/sys@v0.22.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/golang.org/x/sys@v0.22.0
Demonstrate these symbols/APIs:
  - golang.org/x/sys/unix.O_ACCMODE

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:0dece87b2a5ab166668e275f75e22dd682a4782fc4868f27da39109b9a010e95","contract":["unix.O_ACCMODE constant equals 3 (0x3) and masks O_RDONLY, O_WRONLY, and O_RDWR access modes","bitwise AND with unix.O_ACCMODE extracts access mode from flags combined with creation and status flags","fcntl F_GETFL on open file descriptors masked with unix.O_ACCMODE returns the expected access mode"],"goal":"verify golang.org/x/sys/unix.O_ACCMODE in pkg:golang/golang.org/x/sys@v0.22.0","kind":"HOW","packages":["pkg:golang/golang.org/x/sys@v0.22.0"],"schemaVersion":1,"symbols":["golang.org/x/sys/unix.O_ACCMODE"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/sys@v0.22.0"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/sys@v0.22.0","symbols":["golang.org/x/sys/unix.O_ACCMODE"],"verifierAdapter":"golang@1"}
go.mod
module example.com/sample

go 1.26.6

require golang.org/x/sys v0.22.0
go.sum
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
main.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

func main() {
	tmpFile, err := os.CreateTemp("", "accmode_demo_*")
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to create temp file: %v\n", err)
		os.Exit(1)
	}
	defer os.Remove(tmpFile.Name())
	defer tmpFile.Close()

	fd, err := unix.Open(tmpFile.Name(), unix.O_RDWR, 0)
	if err != nil {
		fmt.Fprintf(os.Stderr, "failed to open file: %v\n", err)
		os.Exit(1)
	}
	defer unix.Close(fd)

	flags, err := unix.FcntlInt(uintptr(fd), unix.F_GETFL, 0)
	if err != nil {
		fmt.Fprintf(os.Stderr, "fcntl F_GETFL failed: %v\n", err)
		os.Exit(1)
	}

	accessMode := flags & unix.O_ACCMODE
	fmt.Printf("O_ACCMODE mask: 0x%x\n", unix.O_ACCMODE)
	fmt.Printf("File descriptor access mode: %d (O_RDWR = %d)\n", accessMode, unix.O_RDWR)
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify golang.org/x/sys/unix.O_ACCMODE in pkg:golang/golang.org/x/sys@v0.22.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/golang.org/x/sys@v0.22.0"
  ],
  "symbols": [
    "golang.org/x/sys/unix.O_ACCMODE"
  ]
}
test/contract.go
package main

import (
	"fmt"
	"os"

	"golang.org/x/sys/unix"
)

func main() {
	if err := runTests(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract test failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All contract assertions passed.")
}

func runTests() error {
	// 1. unix.O_ACCMODE constant equals 3 (0x3) and masks O_RDONLY, O_WRONLY, and O_RDWR access modes
	if unix.O_ACCMODE != 3 {
		return fmt.Errorf("expected unix.O_ACCMODE to be 3, got %d", unix.O_ACCMODE)
	}
	if (unix.O_RDONLY & unix.O_ACCMODE) != unix.O_RDONLY {
		return fmt.Errorf("expected O_RDONLY & O_ACCMODE to equal O_RDONLY")
	}
	if (unix.O_WRONLY & unix.O_ACCMODE) != unix.O_WRONLY {
		return fmt.Errorf("expected O_WRONLY & O_ACCMODE to equal O_WRONLY")
	}
	if (unix.O_RDWR & unix.O_ACCMODE) != unix.O_RDWR {
		return fmt.Errorf("expected O_RDWR & O_ACCMODE to equal O_RDWR")
	}

	// 2. bitwise AND with unix.O_ACCMODE extracts access mode from flags combined with creation and status flags
	combinedRdwr := unix.O_RDWR | unix.O_APPEND | unix.O_CLOEXEC | unix.O_NONBLOCK
	if (combinedRdwr & unix.O_ACCMODE) != unix.O_RDWR {
		return fmt.Errorf("expected combinedRdwr & O_ACCMODE to be O_RDWR (%d), got %d", unix.O_RDWR, combinedRdwr&unix.O_ACCMODE)
	}

	combinedWronly := unix.O_WRONLY | unix.O_CREAT | unix.O_TRUNC | unix.O_SYNC
	if (combinedWronly & unix.O_ACCMODE) != unix.O_WRONLY {
		return fmt.Errorf("expected combinedWronly & O_ACCMODE to be O_WRONLY (%d), got %d", unix.O_WRONLY, combinedWronly&unix.O_ACCMODE)
	}

	combinedRdonly := unix.O_RDONLY | unix.O_CLOEXEC
	if (combinedRdonly & unix.O_ACCMODE) != unix.O_RDONLY {
		return fmt.Errorf("expected combinedRdonly & O_ACCMODE to be O_RDONLY (%d), got %d", unix.O_RDONLY, combinedRdonly&unix.O_ACCMODE)
	}

	// 3. fcntl F_GETFL on open file descriptors masked with unix.O_ACCMODE returns the expected access mode
	tmpFile, err := os.CreateTemp("", "accmode_contract_*")
	if err != nil {
		return fmt.Errorf("failed to create temp file: %w", err)
	}
	defer os.Remove(tmpFile.Name())
	defer tmpFile.Close()

	// O_RDONLY fd
	roFd, err := unix.Open(tmpFile.Name(), unix.O_RDONLY, 0)
	if err != nil {
		return fmt.Errorf("open O_RDONLY failed: %w", err)
	}
	defer unix.Close(roFd)

	roFlags, err := unix.FcntlInt(uintptr(roFd), unix.F_GETFL, 0)
	if err != nil {
		return fmt.Errorf("fcntl F_GETFL on roFd failed: %w", err)
	}
	if (roFlags & unix.O_ACCMODE) != unix.O_RDONLY {
		return fmt.Errorf("expected (roFlags & unix.O_ACCMODE) to be O_RDONLY (%d), got %d", unix.O_RDONLY, roFlags&unix.O_ACCMODE)
	}

	// O_WRONLY fd
	woFd, err := unix.Open(tmpFile.Name(), unix.O_WRONLY, 0)
	if err != nil {
		return fmt.Errorf("open O_WRONLY failed: %w", err)
	}
	defer unix.Close(woFd)

	woFlags, err := unix.FcntlInt(uintptr(woFd), unix.F_GETFL, 0)
	if err != nil {
		return fmt.Errorf("fcntl F_GETFL on woFd failed: %w", err)
	}
	if (woFlags & unix.O_ACCMODE) != unix.O_WRONLY {
		return fmt.Errorf("expected (woFlags & unix.O_ACCMODE) to be O_WRONLY (%d), got %d", unix.O_WRONLY, woFlags&unix.O_ACCMODE)
	}

	// O_RDWR fd
	rwFd, err := unix.Open(tmpFile.Name(), unix.O_RDWR, 0)
	if err != nil {
		return fmt.Errorf("open O_RDWR failed: %w", err)
	}
	defer unix.Close(rwFd)

	rwFlags, err := unix.FcntlInt(uintptr(rwFd), unix.F_GETFL, 0)
	if err != nil {
		return fmt.Errorf("fcntl F_GETFL on rwFd failed: %w", err)
	}
	if (rwFlags & unix.O_ACCMODE) != unix.O_RDWR {
		return fmt.Errorf("expected (rwFlags & unix.O_ACCMODE) to be O_RDWR (%d), got %d", unix.O_RDWR, rwFlags&unix.O_ACCMODE)
	}

	return nil
}

オリジンシーダー

匿名