summary refs log tree commit diff stats
path: root/lib/posix/posix_utils.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/posix/posix_utils.nim')
-rw-r--r--lib/posix/posix_utils.nim22
1 files changed, 11 insertions, 11 deletions
diff --git a/lib/posix/posix_utils.nim b/lib/posix/posix_utils.nim
index 7e4a2eeda..0c668246f 100644
--- a/lib/posix/posix_utils.nim
+++ b/lib/posix/posix_utils.nim
@@ -11,7 +11,7 @@
 
 # Where possible, contribute OS-independent procs in `os <os.html>`_ instead.
 
-import posix, parsecfg, os
+import std/[posix, parsecfg, os]
 import std/private/since
 
 when defined(nimPreviewSlimSystem):
@@ -34,7 +34,7 @@ proc uname*(): Uname =
 
   var u: Utsname
   if uname(u) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
   result.sysname = charArrayToString u.sysname
   result.nodename = charArrayToString u.nodename
@@ -45,17 +45,17 @@ proc uname*(): Uname =
 proc fsync*(fd: int) =
   ## synchronize a file's buffer cache to the storage device
   if fsync(fd.cint) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc stat*(path: string): Stat =
   ## Returns file status in a `Stat` structure
   if stat(path.cstring, result) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc memoryLock*(a1: pointer, a2: int) =
   ## Locks pages starting from a1 for a1 bytes and prevent them from being swapped.
   if mlock(a1, a2) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc memoryLockAll*(flags: int) =
   ## Locks all memory for the running process to prevent swapping.
@@ -65,23 +65,23 @@ proc memoryLockAll*(flags: int) =
   ##   memoryLockAll(MCL_CURRENT or MCL_FUTURE)
   ##   ```
   if mlockall(flags.cint) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc memoryUnlock*(a1: pointer, a2: int) =
   ## Unlock pages starting from a1 for a1 bytes and allow them to be swapped.
   if munlock(a1, a2) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc memoryUnlockAll*() =
   ## Unlocks all memory for the running process to allow swapping.
   if munlockall() != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc sendSignal*(pid: Pid, signal: int) =
   ## Sends a signal to a running process by calling `kill`.
   ## Raise exception in case of failure e.g. process not running.
   if kill(pid, signal.cint) != 0:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
 
 proc mkstemp*(prefix: string, suffix=""): (string, File) =
   ## Creates a unique temporary file from a prefix string. A six-character string
@@ -103,14 +103,14 @@ proc mkstemp*(prefix: string, suffix=""): (string, File) =
   var f: File
   if open(f, fd, fmReadWrite):
     return ($tmpl, f)
-  raise newException(OSError, $strerror(errno))
+  raiseOSError(OSErrorCode(errno))
 
 proc mkdtemp*(prefix: string): string =
   ## Creates a unique temporary directory from a prefix string. Adds a six chars suffix.
   ## The directory is created with permissions 0700. Returns the directory name.
   var tmpl = cstring(prefix & "XXXXXX")
   if mkdtemp(tmpl) == nil:
-    raise newException(OSError, $strerror(errno))
+    raiseOSError(OSErrorCode(errno))
   return $tmpl
 
 proc osReleaseFile*(): Config {.since: (1, 5).} =