remove system/ansi_c include from os
This commit is contained in:
parent
64b0485207
commit
fe2b39f007
5 changed files with 19 additions and 31 deletions
|
|
@ -26,7 +26,6 @@ elif defined(posix):
|
||||||
else:
|
else:
|
||||||
{.error: "OS module not ported to your operating system!".}
|
{.error: "OS module not ported to your operating system!".}
|
||||||
|
|
||||||
include "system/ansi_c"
|
|
||||||
include ospaths
|
include ospaths
|
||||||
|
|
||||||
when defined(posix):
|
when defined(posix):
|
||||||
|
|
@ -37,6 +36,21 @@ when defined(posix):
|
||||||
var
|
var
|
||||||
pathMax {.importc: "PATH_MAX", header: "<stdlib.h>".}: cint
|
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.} =
|
proc osErrorMsg*(): string {.rtl, extern: "nos$1", deprecated.} =
|
||||||
## Retrieves the operating system's error flag, ``errno``.
|
## Retrieves the operating system's error flag, ``errno``.
|
||||||
## On Windows ``GetLastError`` is checked before ``errno``.
|
## On Windows ``GetLastError`` is checked before ``errno``.
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,6 @@ proc c_memset(p: pointer, value: cint, size: csize): pointer {.
|
||||||
importc: "memset", header: "<string.h>", discardable.}
|
importc: "memset", header: "<string.h>", discardable.}
|
||||||
proc c_strcmp(a, b: cstring): cint {.
|
proc c_strcmp(a, b: cstring): cint {.
|
||||||
importc: "strcmp", header: "<string.h>", noSideEffect.}
|
importc: "strcmp", header: "<string.h>", noSideEffect.}
|
||||||
proc c_strlen(a: cstring): cint {.
|
|
||||||
importc: "strlen", header: "<string.h>", noSideEffect.}
|
|
||||||
|
|
||||||
type
|
type
|
||||||
C_JmpBuf {.importc: "jmp_buf", header: "<setjmp.h>".} = object
|
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 {.
|
proc c_realloc(p: pointer, newsize: csize): pointer {.
|
||||||
importc: "realloc", header: "<stdlib.h>".}
|
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}
|
{.pop}
|
||||||
|
|
|
||||||
|
|
@ -108,8 +108,8 @@ proc fileMatches(c, bp: cstring): bool =
|
||||||
# and the character for the suffix does not exist or
|
# and the character for the suffix does not exist or
|
||||||
# is one of: \ / :
|
# is one of: \ / :
|
||||||
# depending on the OS case does not matter!
|
# depending on the OS case does not matter!
|
||||||
var blen: int = c_strlen(bp)
|
var blen: int = bp.len
|
||||||
var clen: int = c_strlen(c)
|
var clen: int = c.len
|
||||||
if blen > clen: return false
|
if blen > clen: return false
|
||||||
# check for \ / :
|
# check for \ / :
|
||||||
if clen-blen-1 >= 0 and c[clen-blen-1] notin {'\\', '/', ':'}:
|
if clen-blen-1 >= 0 and c[clen-blen-1] notin {'\\', '/', ':'}:
|
||||||
|
|
|
||||||
|
|
@ -255,7 +255,7 @@ proc raiseExceptionAux(e: ref Exception) =
|
||||||
add(buf, "Error: unhandled exception: ")
|
add(buf, "Error: unhandled exception: ")
|
||||||
if not isNil(e.msg): add(buf, e.msg)
|
if not isNil(e.msg): add(buf, e.msg)
|
||||||
add(buf, " [")
|
add(buf, " [")
|
||||||
xadd(buf, e.name, c_strlen(e.name))
|
xadd(buf, e.name, e.name.len)
|
||||||
add(buf, "]\n")
|
add(buf, "]\n")
|
||||||
showErrorMessage(buf)
|
showErrorMessage(buf)
|
||||||
quitOrDebug()
|
quitOrDebug()
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,7 @@ proc toNimStr(str: cstring, len: int): NimString {.compilerProc.} =
|
||||||
copyMem(addr(result.data), str, len + 1)
|
copyMem(addr(result.data), str, len + 1)
|
||||||
|
|
||||||
proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} =
|
proc cstrToNimstr(str: cstring): NimString {.compilerRtl.} =
|
||||||
result = toNimStr(str, c_strlen(str))
|
result = toNimStr(str, str.len)
|
||||||
|
|
||||||
proc copyString(src: NimString): NimString {.compilerRtl.} =
|
proc copyString(src: NimString): NimString {.compilerRtl.} =
|
||||||
if src != nil:
|
if src != nil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue