Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/posix/posix.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/posix/posix_linux_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion lib/posix/posix_macos_amd64.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/posix/posix_nintendoswitch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion lib/posix/posix_other.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 20 additions & 20 deletions lib/pure/os.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down