Merge pull request #97 from ddlsmurf/fixes_macosx

Fixes for macosx
This commit is contained in:
Araq
2012-01-22 16:16:42 -08:00
2 changed files with 23 additions and 17 deletions

View File

@@ -151,6 +151,10 @@ else: # UNIX-like operating system
ScriptExt* = ""
DynlibFormat* = "lib$1.so"
when defined(macosx):
var
pathMax {.importc: "PATH_MAX", header: "<stdlib.h>".}: cint
const
ExtSep* = '.'
## The character which separates the base filename from the extension;
@@ -505,6 +509,12 @@ proc expandFilename*(filename: string): string {.rtl, extern: "nos$1".} =
var L = GetFullPathNameA(filename, 3072'i32, result, unused)
if L <= 0'i32 or L >= 3072'i32: OSError()
setLen(result, L)
when defined(macosx):
# On Mac OS X 10.5, realpath does not allocate the buffer on its own
var pathBuffer: cstring = newString(pathMax)
var resultBuffer = realpath(filename, pathBuffer)
if resultBuffer == nil: OSError()
result = $resultBuffer
else:
var res = realpath(filename, nil)
if res == nil: OSError()

View File

@@ -443,6 +443,11 @@ proc connectAsync*(socket: TSocket, name: string, port = TPort(0),
if not success: OSError()
proc timeValFromMilliseconds(timeout = 500): TTimeVal =
if timeout != -1:
var seconds = timeout div 1000
result.tv_sec = seconds
result.tv_usec = (timeout - seconds * 1000) * 1000
#proc recvfrom*(s: TWinSocket, buf: cstring, len, flags: cint,
# fromm: ptr TSockAddr, fromlen: ptr cint): cint
@@ -475,9 +480,7 @@ proc select*(readfds, writefds, exceptfds: var seq[TSocket],
## You can determine whether a socket is ready by checking if it's still
## in one of the TSocket sequences.
var tv: TTimeVal
tv.tv_sec = 0
tv.tv_usec = timeout * 1000
var tv {.noInit.}: TTimeVal = timeValFromMilliseconds(timeout)
var rd, wr, ex: TFdSet
var m = 0
@@ -495,10 +498,8 @@ proc select*(readfds, writefds, exceptfds: var seq[TSocket],
pruneSocketSet(exceptfds, (ex))
proc select*(readfds, writefds: var seq[TSocket],
timeout = 500): int =
var tv: TTimeVal
tv.tv_sec = 0
tv.tv_usec = timeout * 1000
timeout = 500): int =
var tv {.noInit.}: TTimeVal = timeValFromMilliseconds(timeout)
var rd, wr: TFdSet
var m = 0
@@ -514,10 +515,8 @@ proc select*(readfds, writefds: var seq[TSocket],
pruneSocketSet(writefds, (wr))
proc selectWrite*(writefds: var seq[TSocket],
timeout = 500): int =
var tv: TTimeVal
tv.tv_sec = 0
tv.tv_usec = timeout * 1000
timeout = 500): int =
var tv {.noInit.}: TTimeVal = timeValFromMilliseconds(timeout)
var wr: TFdSet
var m = 0
@@ -530,11 +529,8 @@ proc selectWrite*(writefds: var seq[TSocket],
pruneSocketSet(writefds, (wr))
proc select*(readfds: var seq[TSocket], timeout = 500): int =
var tv: TTimeVal
tv.tv_sec = 0
tv.tv_usec = timeout * 1000
proc select*(readfds: var seq[TSocket], timeout = 500): int =
var tv {.noInit.}: TTimeVal = timeValFromMilliseconds(timeout)
var rd: TFdSet
var m = 0
@@ -643,7 +639,7 @@ proc skip*(socket: TSocket) =
proc send*(socket: TSocket, data: pointer, size: int): int =
## sends data to a socket.
when defined(windows):
when defined(windows) or defined(macosx):
result = send(cint(socket), data, size, 0'i32)
else:
result = send(cint(socket), data, size, int32(MSG_NOSIGNAL))