github.com/huandu/go@v0.0.0-20151114150818-04e615e41150/src/os/sys_darwin.go (about)

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package os
     6  
     7  import "syscall"
     8  
     9  // supportsCloseOnExec reports whether the platform supports the
    10  // O_CLOEXEC flag.
    11  var supportsCloseOnExec bool
    12  
    13  func init() {
    14  	// Seems like kern.osreldate is veiled on latest OS X. We use
    15  	// kern.osrelease instead.
    16  	osver, err := syscall.Sysctl("kern.osrelease")
    17  	if err != nil {
    18  		return
    19  	}
    20  	var i int
    21  	for i = range osver {
    22  		if osver[i] != '.' {
    23  			continue
    24  		}
    25  	}
    26  	// The O_CLOEXEC flag was introduced in OS X 10.7 (Darwin
    27  	// 11.0.0). See http://support.apple.com/kb/HT1633.
    28  	if i > 2 || i == 2 && osver[0] >= '1' && osver[1] >= '1' {
    29  		supportsCloseOnExec = true
    30  	}
    31  }