Skip to content

Instantly share code, notes, and snippets.

@rdp
Forked from fd00/crystal-on-cygwin.patch
Created November 29, 2016 19:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/812d9f02bef7d870a6ab74ababe2b795 to your computer and use it in GitHub Desktop.
Save rdp/812d9f02bef7d870a6ab74ababe2b795 to your computer and use it in GitHub Desktop.
diff --git a/src/exception.cr b/src/exception.cr
index cd4450c..570e2fd 100644
--- a/src/exception.cr
+++ b/src/exception.cr
@@ -21,7 +21,11 @@ struct CallStack
makecontext_start = makecontext_end = LibDL.dlsym(LibDL::RTLD_DEFAULT, "makecontext")
while true
- ret = LibDL.dladdr(makecontext_end, out info)
+ ifdef cygwin
+ break
+ else
+ ret = LibDL.dladdr(makecontext_end, out info)
+ end
break if ret == 0 || info.sname.nil?
break unless LibC.strcmp(info.sname, "makecontext") == 0
makecontext_end += 1
@@ -69,15 +73,18 @@ struct CallStack
end
protected def self.decode_frame(ip, original_ip = ip)
- if LibDL.dladdr(ip, out info) != 0
- offset = original_ip - info.saddr
+ ifdef cygwin
+ else
+ if LibDL.dladdr(ip, out info) != 0
+ offset = original_ip - info.saddr
- if offset == 0
- return decode_frame(ip - 1, original_ip)
- end
+ if offset == 0
+ return decode_frame(ip - 1, original_ip)
+ end
- unless info.sname.nil?
- {offset, String.new(info.sname)}
+ unless info.sname.nil?
+ {offset, String.new(info.sname)}
+ end
end
end
end
diff --git a/src/file/stat.cr b/src/file/stat.cr
index bddf6b8..9ec959d 100644
--- a/src/file/stat.cr
+++ b/src/file/stat.cr
@@ -62,6 +62,23 @@ lib LibC
__unused5 : UInt64
end
end
+ elsif cygwin
+ struct Stat
+ st_dev : UInt32
+ st_ino : UInt64
+ st_mode : LibC::ModeT
+ st_nlink : UInt16
+ st_uid : UInt32
+ st_gid : UInt32
+ st_rdev : UInt32
+ st_size : Int64
+ st_atimespec : LibC::TimeSpec
+ st_mtimespec : LibC::TimeSpec
+ st_ctimespec : LibC::TimeSpec
+ st_blksize : Int64
+ st_blocks : Int64
+ st_birthtim : LibC::TimeSpec
+ end
end
S_ISVTX = 0o001000
diff --git a/src/io.cr b/src/io.cr
index ae0139e..bbde887 100644
--- a/src/io.cr
+++ b/src/io.cr
@@ -26,6 +26,15 @@ lib LibC
O_TRUNC = 0x0400
O_NONBLOCK = 0x0004
O_CLOEXEC = 0x1000000
+ elsif cygwin
+ O_RDONLY = 0x0000
+ O_WRONLY = 0x0001
+ O_RDWR = 0x0002
+ O_APPEND = 0x0008
+ O_CREAT = 0x0200
+ O_TRUNC = 0x0400
+ O_NONBLOCK = 0x4000
+ O_CLOEXEC = 0x40000
end
S_IRWXU = 0o000700 # RWX mask for owner
diff --git a/src/libc.cr b/src/libc.cr
index bfbe0dd..313fa0e 100644
--- a/src/libc.cr
+++ b/src/libc.cr
@@ -29,6 +29,8 @@ lib LibC
alias ModeT = UInt16
elsif linux
alias ModeT = UInt32
+ elsif cygwin
+ alias ModeT = UInt32
end
ifdef darwin
@@ -57,6 +59,9 @@ lib LibC
ifdef linux
MAP_ANON = 0x0020
end
+ ifdef cygwin
+ MAP_ANON = 0x20
+ end
MAP_FAILED = Pointer(Void).new(SizeT.new(-1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment