os.Mkdir和syscall.Mkdir在Golang中有什么区别?

huangapple go评论117阅读模式
英文:

os.Mkdir versus syscall.Mkdir, what is the difference in Golang?

问题

os.Mkdirsyscall.Mkdir在Golang中具有相同的API。

syscall.Mkdir:

func Mkdir(path string, mode uint32) (err error)

os.Mkdir:

func Mkdir(name string, perm FileMode) error

它们之间有什么区别?

英文:

os.Mkdir and syscall.Mkdir both have same API in Golang

syscall.Mkdir:

func Mkdir(path string, mode uint32) (err error)

os.Mkdir:

func Mkdir(name string, perm FileMode) error

What is the difference between them?

答案1

得分: 3

第一个是直接的系统调用,依赖于平台,可能更快/可以使用所有平台相关的位(例如Unix/Linux上的粘性位)。

后者是可移植的API,应该在每个平台上都能正常工作,注意第二个参数不再是匿名整数,而是一个受限制的类型。

英文:

The first one is the direct system call, platform dependent, probably faster/you can use all platform dependent bits (like sticky bit on Unix/Linux for instance)

The latter is the portable API which is supposed to work the same on every platform, note that second argument is no longer an anonymous integer but a constrained type.

huangapple
  • 本文由 发表于 2016年8月20日 14:42:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/39051290.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定