diff options
-rw-r--r-- | lib/pure/os.nim | 16 | ||||
-rw-r--r-- | lib/system/ansi_c.nim | 26 | ||||
-rw-r--r-- | lib/system/debugger.nim | 4 | ||||
-rw-r--r-- | lib/system/excpt.nim | 2 | ||||
-rw-r--r-- | lib/system/sysstr.nim | 2 |
5 files changed, 19 insertions, 31 deletions
diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 2b8dca497..86dd903e7 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -26,7 +26,6 @@ elif defined(posix): else: {.error: "OS module not ported to your operating system!".} -include "system/ansi_c" include ospaths when defined(posix): @@ -37,6 +36,21 @@ when defined(posix): var pathMax {.importc: "PATH_MAX", header: "<stdlib.h>".}: cint +proc c_remove(filename: cstring): cint {. + importc: "remove", header: "<stdio.h>".} +proc c_rename(oldname, newname: cstring): cint {. + importc: "rename", header: "<stdio.h>".} +proc c_system(cmd: cstring): cint {. + importc: "system", header: "<stdlib.h>".} +proc c_strerror(errnum: cint): cstring {. + importc: "strerror", header: "<string.h>".} +proc c_strlen(a: cstring): cint {. + importc: "strlen", header: "<string.h>", noSideEffect.} +proc c_getenv(env: cstring): cstring {. + importc: "getenv", header: "<stdlib.h>".} +proc c_putenv(env: cstring): cint {. + importc: "putenv", header: "<stdlib.h>".} + proc osErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} = ## Retrieves the operating system's error flag, ``errno``. ## On Windows ``GetLastError`` is checked before ``errno``. diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim index 089563f22..ff4d32713 100644 --- a/lib/system/ansi_c.nim +++ b/lib/system/ansi_c.nim @@ -25,8 +25,6 @@ proc c_memset(p: pointer, value: cint, size: csize): pointer {. importc: "memset", header: "<string.h>", discardable.} proc c_strcmp(a, b: cstring): cint {. importc: "strcmp", header: "<string.h>", noSideEffect.} -proc c_strlen(a: cstring): cint {. - importc: "strlen", header: "<string.h>", noSideEffect.} type C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>".} = object @@ -112,28 +110,4 @@ proc c_free(p: pointer) {. proc c_realloc(p: pointer, newsize: csize): pointer {. importc: "realloc", header: "<stdlib.h>".} -when hostOS != "standalone": - when not declared(errno): - when defined(NimrodVM): - var vmErrnoWrapper {.importc.}: ptr cint - template errno: expr = - bind vmErrnoWrapper - vmErrnoWrapper[] - else: - var errno {.importc, header: "<errno.h>".}: cint ## error variable -proc c_strerror(errnum: cint): cstring {. - importc: "strerror", header: "<string.h>".} - -proc c_remove(filename: cstring): cint {. - importc: "remove", header: "<stdio.h>".} -proc c_rename(oldname, newname: cstring): cint {. - importc: "rename", header: "<stdio.h>".} - -proc c_system(cmd: cstring): cint {. - importc: "system", header: "<stdlib.h>".} -proc c_getenv(env: cstring): cstring {. - importc: "getenv", header: "<stdlib.h>".} -proc c_putenv(env: cstring): cint {. - importc: "putenv", header: "<stdlib.h>".} - {.pop} diff --git a/lib/system/debugger.nim b/lib/system/debugger.nim index b18c61755..55f14e982 100644 --- a/lib/system/debugger.nim +++ b/lib/system/debugger.nim @@ -108,8 +108,8 @@ proc fileMatches(c, bp: cstring): bool = # and the character for the suffix does not exist or # is one of: \ / : # depending on the OS case does not matter! - var blen: int = c_strlen(bp) - var clen: int = c_strlen(c) + var blen: int = bp.len + var clen: int = c.len if blen > clen: return false # check for \ / : if clen-blen-1 >= 0 and c[clen-blen-1] notin {'\\', '/', ':'}: diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index 948f87410..526e27c83 100644 --- a/lib/system/excpt.nim +++ b/lib/system/excpt.nim @@ -255,7 +255,7 @@ proc raiseExceptionAux(e: ref Exception) = add(buf, "Error: unhandled exception: ") if not isNil(e.msg): add(buf, e.msg) add(buf, " [") - xadd(buf, e.name, c_strlen(e.name)) + xadd(buf, e.name, e.name.len) add(buf, "]\n") showErrorMessage(buf) quitOrDebug() diff --git a/lib/system/sysstr.nim b/lib/system/sysstr.nim index e67a3e56a..569470aa2 100644 --- a/lib/system/sysstr.nim +++ b/lib/system/sysstr.nim @@ -85,7 +85,7 @@ proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} = copyMem(addr(result.data), str, len + 1) proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} = - result = toNimStr(str, c_strlen(str)) + result = toNimStr(str, str.len) proc copyString(src: NimString): NimString {.compilerRtl.} = if src != nil: |