mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
@@ -95,9 +95,9 @@ const StatHasNanoseconds* = defined(linux) or defined(freebsd) or
|
||||
|
||||
# Platform specific stuff
|
||||
|
||||
when defined(linux) and defined(amd64):
|
||||
when (defined(linux) and not defined(android)) and defined(amd64):
|
||||
include posix_linux_amd64
|
||||
elif (defined(macosx) or defined(bsd)) and defined(cpu64):
|
||||
elif (defined(macos) or defined(macosx) or defined(bsd)) and defined(cpu64):
|
||||
include posix_macos_amd64
|
||||
elif defined(nintendoswitch):
|
||||
include posix_nintendoswitch
|
||||
|
||||
@@ -147,7 +147,7 @@ type
|
||||
Id* {.importc: "id_t", header: "<sys/types.h>".} = cuint
|
||||
Ino* {.importc: "ino_t", header: "<sys/types.h>".} = culong
|
||||
Key* {.importc: "key_t", header: "<sys/types.h>".} = cint
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = cint # cuint really!
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = uint32
|
||||
Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = culong
|
||||
Off* {.importc: "off_t", header: "<sys/types.h>".} = clong
|
||||
Pid* {.importc: "pid_t", header: "<sys/types.h>".} = cint
|
||||
|
||||
@@ -140,7 +140,12 @@ type
|
||||
Id* {.importc: "id_t", header: "<sys/types.h>".} = int
|
||||
Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
|
||||
Key* {.importc: "key_t", header: "<sys/types.h>".} = int
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = int16
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = (
|
||||
when defined(openbsd) or defined(netbsd):
|
||||
uint32
|
||||
else:
|
||||
uint16
|
||||
)
|
||||
Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int16
|
||||
Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
|
||||
Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
|
||||
|
||||
@@ -123,7 +123,7 @@ type
|
||||
Id* {.importc: "id_t", header: "<sys/types.h>".} = cuint
|
||||
Ino* {.importc: "ino_t", header: "<sys/types.h>".} = culong
|
||||
Key* {.importc: "key_t", header: "<sys/types.h>".} = cint
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = cint # cuint really!
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = uint16
|
||||
Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = culong
|
||||
Off* {.importc: "off_t", header: "<sys/types.h>".} = clong
|
||||
Pid* {.importc: "pid_t", header: "<sys/types.h>".} = cint
|
||||
|
||||
@@ -149,7 +149,13 @@ type
|
||||
Id* {.importc: "id_t", header: "<sys/types.h>".} = int
|
||||
Ino* {.importc: "ino_t", header: "<sys/types.h>".} = int
|
||||
Key* {.importc: "key_t", header: "<sys/types.h>".} = int
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = cint
|
||||
Mode* {.importc: "mode_t", header: "<sys/types.h>".} = (
|
||||
when defined(android) or defined(macos) or defined(macosx) or
|
||||
(defined(bsd) and not defined(openbsd) and not defined(netbsd)):
|
||||
uint16
|
||||
else:
|
||||
uint32
|
||||
)
|
||||
Nlink* {.importc: "nlink_t", header: "<sys/types.h>".} = int
|
||||
Off* {.importc: "off_t", header: "<sys/types.h>".} = int64
|
||||
Pid* {.importc: "pid_t", header: "<sys/types.h>".} = int32
|
||||
|
||||
@@ -1435,17 +1435,17 @@ proc getFilePermissions*(filename: string): set[FilePermission] {.
|
||||
var a: Stat
|
||||
if stat(filename, a) < 0'i32: raiseOSError(osLastError())
|
||||
result = {}
|
||||
if (a.st_mode and S_IRUSR) != 0'i32: result.incl(fpUserRead)
|
||||
if (a.st_mode and S_IWUSR) != 0'i32: result.incl(fpUserWrite)
|
||||
if (a.st_mode and S_IXUSR) != 0'i32: result.incl(fpUserExec)
|
||||
if (a.st_mode and S_IRUSR.Mode) != 0.Mode: result.incl(fpUserRead)
|
||||
if (a.st_mode and S_IWUSR.Mode) != 0.Mode: result.incl(fpUserWrite)
|
||||
if (a.st_mode and S_IXUSR.Mode) != 0.Mode: result.incl(fpUserExec)
|
||||
|
||||
if (a.st_mode and S_IRGRP) != 0'i32: result.incl(fpGroupRead)
|
||||
if (a.st_mode and S_IWGRP) != 0'i32: result.incl(fpGroupWrite)
|
||||
if (a.st_mode and S_IXGRP) != 0'i32: result.incl(fpGroupExec)
|
||||
if (a.st_mode and S_IRGRP.Mode) != 0.Mode: result.incl(fpGroupRead)
|
||||
if (a.st_mode and S_IWGRP.Mode) != 0.Mode: result.incl(fpGroupWrite)
|
||||
if (a.st_mode and S_IXGRP.Mode) != 0.Mode: result.incl(fpGroupExec)
|
||||
|
||||
if (a.st_mode and S_IROTH) != 0'i32: result.incl(fpOthersRead)
|
||||
if (a.st_mode and S_IWOTH) != 0'i32: result.incl(fpOthersWrite)
|
||||
if (a.st_mode and S_IXOTH) != 0'i32: result.incl(fpOthersExec)
|
||||
if (a.st_mode and S_IROTH.Mode) != 0.Mode: result.incl(fpOthersRead)
|
||||
if (a.st_mode and S_IWOTH.Mode) != 0.Mode: result.incl(fpOthersWrite)
|
||||
if (a.st_mode and S_IXOTH.Mode) != 0.Mode: result.incl(fpOthersExec)
|
||||
else:
|
||||
when useWinUnicode:
|
||||
wrapUnary(res, getFileAttributesW, filename)
|
||||
@@ -1470,18 +1470,18 @@ proc setFilePermissions*(filename: string, permissions: set[FilePermission]) {.
|
||||
## * `getFilePermissions <#getFilePermissions,string>`_
|
||||
## * `FilePermission enum <#FilePermission>`_
|
||||
when defined(posix):
|
||||
var p = 0'i32
|
||||
if fpUserRead in permissions: p = p or S_IRUSR
|
||||
if fpUserWrite in permissions: p = p or S_IWUSR
|
||||
if fpUserExec in permissions: p = p or S_IXUSR
|
||||
var p = 0.Mode
|
||||
if fpUserRead in permissions: p = p or S_IRUSR.Mode
|
||||
if fpUserWrite in permissions: p = p or S_IWUSR.Mode
|
||||
if fpUserExec in permissions: p = p or S_IXUSR.Mode
|
||||
|
||||
if fpGroupRead in permissions: p = p or S_IRGRP
|
||||
if fpGroupWrite in permissions: p = p or S_IWGRP
|
||||
if fpGroupExec in permissions: p = p or S_IXGRP
|
||||
if fpGroupRead in permissions: p = p or S_IRGRP.Mode
|
||||
if fpGroupWrite in permissions: p = p or S_IWGRP.Mode
|
||||
if fpGroupExec in permissions: p = p or S_IXGRP.Mode
|
||||
|
||||
if fpOthersRead in permissions: p = p or S_IROTH
|
||||
if fpOthersWrite in permissions: p = p or S_IWOTH
|
||||
if fpOthersExec in permissions: p = p or S_IXOTH
|
||||
if fpOthersRead in permissions: p = p or S_IROTH.Mode
|
||||
if fpOthersWrite in permissions: p = p or S_IWOTH.Mode
|
||||
if fpOthersExec in permissions: p = p or S_IXOTH.Mode
|
||||
|
||||
if chmod(filename, cast[Mode](p)) != 0: raiseOSError(osLastError())
|
||||
else:
|
||||
@@ -2854,7 +2854,7 @@ template rawToFormalFileInfo(rawInfo, path, formalInfo): untyped =
|
||||
|
||||
else:
|
||||
template checkAndIncludeMode(rawMode, formalMode: untyped) =
|
||||
if (rawInfo.st_mode and rawMode) != 0'i32:
|
||||
if (rawInfo.st_mode and rawMode.Mode) != 0.Mode:
|
||||
formalInfo.permissions.incl(formalMode)
|
||||
formalInfo.id = (rawInfo.st_dev, rawInfo.st_ino)
|
||||
formalInfo.size = rawInfo.st_size
|
||||
|
||||
Reference in New Issue
Block a user