Adding the challenge 0303

This commit is contained in:
2026-07-31 20:30:42 +02:00
parent 185ba1878e
commit 8a50f55782
15 changed files with 966 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
//go:build unix
package db0303
import (
"os"
"path"
"syscall"
)
// open or create a file and fsync the directory
func createFileSync(file string) (*os.File, error) {
fp, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0o644)
if err != nil {
return nil, err
}
if err = syncDir(path.Base(file)); err != nil {
_ = fp.Close()
return nil, err
}
return fp, err
}
func syncDir(file string) error {
flags := os.O_RDONLY | syscall.O_DIRECTORY
dirfd, err := syscall.Open(path.Dir(file), flags, 0o644)
if err != nil {
return err
}
defer syscall.Close(dirfd)
return syscall.Fsync(dirfd)
}
// QzBQWVJJOUhU https://trialofcode.org/