diff --git a/blah/blah.go b/blah/blah.go index 4270119..8f5c92d 100644 --- a/blah/blah.go +++ b/blah/blah.go @@ -3,7 +3,7 @@ package main import ( "fmt" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) func main() { diff --git a/context.go b/context.go index 65542cb..42e312a 100644 --- a/context.go +++ b/context.go @@ -11,7 +11,7 @@ import ( "path/filepath" "strings" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) // Context handles the interactions with libsass. Context diff --git a/context_test.go b/context_test.go index cf21942..9f6ff33 100644 --- a/context_test.go +++ b/context_test.go @@ -6,7 +6,7 @@ import ( "os" "testing" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) func TestContextFile(t *testing.T) { diff --git a/encoding.go b/encoding.go index e1c8010..bb036bf 100644 --- a/encoding.go +++ b/encoding.go @@ -8,7 +8,7 @@ import ( "strconv" "strings" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) var ( diff --git a/encoding_test.go b/encoding_test.go index c8a7fe5..193de6c 100644 --- a/encoding_test.go +++ b/encoding_test.go @@ -6,7 +6,7 @@ import ( "reflect" "testing" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) type unsupportedStruct struct { diff --git a/examples/basic/main.go b/examples/basic/main.go index 167674c..098e18b 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -4,7 +4,7 @@ import ( "log" "os" - libsass "github.com/wellington/go-libsass" + libsass "github.com/tom-un/go-libsass" ) func main() { diff --git a/examples/customfunc/main.go b/examples/customfunc/main.go index 9ff16a3..c21bc87 100644 --- a/examples/customfunc/main.go +++ b/examples/customfunc/main.go @@ -8,7 +8,7 @@ import ( "log" "os" - "github.com/wellington/go-libsass" + "github.com/tom-un/go-libsass" ) // cryptotext is of type libsass.SassFunc. As libsass compiles the diff --git a/examples/custompreamble/main.go b/examples/custompreamble/main.go index bf496c9..7b8e655 100644 --- a/examples/custompreamble/main.go +++ b/examples/custompreamble/main.go @@ -6,7 +6,7 @@ import ( "log" "os" - "github.com/wellington/go-libsass" + "github.com/tom-un/go-libsass" ) func main() { diff --git a/examples/options/main.go b/examples/options/main.go index f4ecb7b..723706e 100644 --- a/examples/options/main.go +++ b/examples/options/main.go @@ -4,7 +4,7 @@ import ( "log" "os" - libsass "github.com/wellington/go-libsass" + libsass "github.com/tom-un/go-libsass" ) func main() { diff --git a/export.go b/export.go index eb68422..bb75653 100644 --- a/export.go +++ b/export.go @@ -1,6 +1,6 @@ package libsass -import "github.com/wellington/go-libsass/libs" +import "github.com/tom-un/go-libsass/libs" // Error takes a Go error and returns a libsass Error func Error(err error) SassValue { diff --git a/func.go b/func.go index b4e972f..712ca78 100644 --- a/func.go +++ b/func.go @@ -6,7 +6,7 @@ import ( "fmt" "sync" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) var ghMu sync.RWMutex diff --git a/func_test.go b/func_test.go index e95efcb..2f43083 100644 --- a/func_test.go +++ b/func_test.go @@ -7,7 +7,7 @@ import ( "testing" "time" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) func TestFunc_simpletypes(t *testing.T) { diff --git a/go.mod b/go.mod index 2f009dd..33cc29c 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/wellington/go-libsass +module github.com/tom-un/go-libsass go 1.18 diff --git a/header.go b/header.go index ebb75fc..2c1d064 100644 --- a/header.go +++ b/header.go @@ -4,7 +4,7 @@ import ( "strconv" "sync" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) var globalHeaders []string diff --git a/importer.go b/importer.go index 4c7abdb..af0c112 100644 --- a/importer.go +++ b/importer.go @@ -6,7 +6,7 @@ import ( "sync" "time" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) var ( diff --git a/libsass-build/file.cpp b/libsass-build/file.cpp index 32d4a7c..c461bad 100644 --- a/libsass-build/file.cpp +++ b/libsass-build/file.cpp @@ -22,6 +22,7 @@ #include "utf8_string.hpp" #include "sass_functions.hpp" #include "sass2scss.h" +#include #ifdef _WIN32 # include @@ -429,22 +430,44 @@ namespace Sass { CloseHandle(hFile); // just convert from unsigned char* char* contents = (char*) pBuffer; - #else + #elif __APPLE__ + // TODO: waiting for https://github.com/sass/libsass/pull/3183 to be merged. + // On OSX `fopen` can fail with "too many open files" but succeeds using `open`. struct stat st; if (stat(path.c_str(), &st) == -1 || S_ISDIR(st.st_mode)) return 0; - std::ifstream file(path.c_str(), std::ios::in | std::ios::binary | std::ios::ate); + int file = open(path.c_str(), O_RDONLY); char* contents = 0; - if (file.is_open()) { - size_t size = file.tellg(); - // allocate an extra byte for the null char - // and another one for edge-cases in lexer + if (file != -1) { + size_t size = st.st_size; contents = (char*) malloc((size+2)*sizeof(char)); - file.seekg(0, std::ios::beg); - file.read(contents, size); + read(file, contents, size); contents[size+0] = '\0'; contents[size+1] = '\0'; - file.close(); + close(file); + } + #else + // Read the file using `` instead of `` for better portability. + // The `` header initializes `` and this buggy in GCC4/5 with static linking. + // See: + // https://www.spinics.net/lists/gcchelp/msg46851.html + // https://github.com/sass/sassc-ruby/issues/128 + struct stat st; + if (stat(path.c_str(), &st) == -1 || S_ISDIR(st.st_mode)) return 0; + FILE* fd = std::fopen(path.c_str(), "rb"); + if (fd == nullptr) return nullptr; + const std::size_t size = st.st_size; + char* contents = static_cast(malloc(st.st_size + 2 * sizeof(char))); + if (std::fread(static_cast(contents), 1, size, fd) != size) { + free(contents); + std::fclose(fd); + return nullptr; + } + if (std::fclose(fd) != 0) { + free(contents); + return nullptr; } + contents[size] = '\0'; + contents[size + 1] = '\0'; #endif std::string extension; if (path.length() > 5) { diff --git a/toscss.go b/toscss.go index 94fb1d4..4e730aa 100644 --- a/toscss.go +++ b/toscss.go @@ -3,7 +3,7 @@ package libsass import ( "io" - "github.com/wellington/go-libsass/libs" + "github.com/tom-un/go-libsass/libs" ) // ToScss converts Sass to Scss with libsass sass2scss.h diff --git a/version.go b/version.go index ea49c9d..30a0923 100644 --- a/version.go +++ b/version.go @@ -1,6 +1,6 @@ package libsass -import "github.com/wellington/go-libsass/libs" +import "github.com/tom-un/go-libsass/libs" // Version reports libsass version information func Version() string {