Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit a967d4c

Browse files
committed
Bundle complete unistd.h for Windows compatibility
1 parent 38b89ed commit a967d4c

File tree

3 files changed

+49
-9
lines changed

3 files changed

+49
-9
lines changed

sass.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
#if defined(_WIN32) || defined(WIN32) || defined(__WINDOWS__)
2-
#define R_OK 4
3-
#define access _access
4-
#else
51
#include <unistd.h>
6-
#endif
72
#include <Python.h>
83
#include "sass_interface.h"
94

setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,21 @@
3232
]
3333

3434
if sys.platform == 'win32':
35-
warnings = ['-Wall']
35+
flags = ['-Wall', '-I"' + os.path.abspath('win32') + '"']
36+
link_flags = []
3637
macros = {'LIBSASS_PYTHON_VERSION': '\\"' + version + '\\"'}
3738
else:
38-
warnings = ['-Wall', '-Wno-parentheses', '-Wno-tautological-compare']
39+
flags = ['-fPIC', '-Wall', '-Wno-parentheses', '-Wno-tautological-compare']
40+
link_flags = ['-fPIC']
3941
macros = {'LIBSASS_PYTHON_VERSION': '"' + version + '"'}
4042

4143
sass_extension = Extension(
4244
'sass',
4345
['sass.c'] + libsass_sources,
4446
define_macros=macros.items(),
4547
depends=libsass_headers,
46-
extra_compile_args=['-c', '-O2', '-fPIC'] + warnings,
47-
extra_link_args=['-fPIC'],
48+
extra_compile_args=['-c', '-O2'] + flags,
49+
extra_link_args=link_flags,
4850
)
4951

5052

win32/unistd.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* http://stackoverflow.com/a/826027/383405 */
2+
#ifndef _UNISTD_H
3+
#define _UNISTD_H 1
4+
5+
/* This file intended to serve as a drop-in replacement for
6+
* unistd.h on Windows
7+
* Please add functionality as neeeded
8+
*/
9+
10+
#include <stdlib.h>
11+
#include <io.h>
12+
#include <getopt.h> /* getopt from: http://www.pwilson.net/sample.html. */
13+
#include <process.h> /* for getpid() and the exec..() family */
14+
15+
#define srandom srand
16+
#define random rand
17+
18+
/* Values for the second argument to access.
19+
These may be OR'd together. */
20+
#define R_OK 4 /* Test for read permission. */
21+
#define W_OK 2 /* Test for write permission. */
22+
//#define X_OK 1 /* execute permission - unsupported in windows*/
23+
#define F_OK 0 /* Test for existence. */
24+
25+
#define access _access
26+
#define ftruncate _chsize
27+
28+
#define ssize_t int
29+
30+
#define STDIN_FILENO 0
31+
#define STDOUT_FILENO 1
32+
#define STDERR_FILENO 2
33+
/* should be in some equivalent to <sys/types.h> */
34+
typedef __int8 int8_t;
35+
typedef __int16 int16_t;
36+
typedef __int32 int32_t;
37+
typedef __int64 int64_t;
38+
typedef unsigned __int8 uint8_t;
39+
typedef unsigned __int16 uint16_t;
40+
typedef unsigned __int32 uint32_t;
41+
typedef unsigned __int64 uint64_t;
42+
43+
#endif /* unistd.h */

0 commit comments

Comments
 (0)