wdm 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,40 +1,40 @@
1
- #ifndef WDM_RB_MONITOR_H
2
- #define WDM_RB_MONITOR_H
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif // __cplusplus
7
-
8
- // ---------------------------------------------------------
9
- // Constants
10
- // ---------------------------------------------------------
11
-
12
- #define WDM_MONITOR_FLAGS_DEFAULT \
13
- FILE_NOTIFY_CHANGE_FILE_NAME \
14
- | FILE_NOTIFY_CHANGE_DIR_NAME \
15
- | FILE_NOTIFY_CHANGE_LAST_WRITE
16
-
17
- // ----------------------------------------------------------
18
- // Global variables
19
- // ----------------------------------------------------------
20
-
21
- extern VALUE cWDM_Monitor;
22
-
23
- extern VALUE eWDM_UnknownFlagError;
24
- extern VALUE eWDM_MonitorRunningError;
25
- extern VALUE eWDM_InvalidDirectoryError;
26
- extern VALUE eWDM_UnwatchableDirectoryError;
27
-
28
- // ---------------------------------------------------------
29
- // Prototypes
30
- // ---------------------------------------------------------
31
-
32
- void wdm_rb_monitor_init();
33
-
34
- // ---------------------------------------------------------
35
-
36
- #ifdef __cplusplus
37
- }
38
- #endif // __cplusplus
39
-
1
+ #ifndef WDM_RB_MONITOR_H
2
+ #define WDM_RB_MONITOR_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif // __cplusplus
7
+
8
+ // ---------------------------------------------------------
9
+ // Constants
10
+ // ---------------------------------------------------------
11
+
12
+ #define WDM_MONITOR_FLAGS_DEFAULT \
13
+ FILE_NOTIFY_CHANGE_FILE_NAME \
14
+ | FILE_NOTIFY_CHANGE_DIR_NAME \
15
+ | FILE_NOTIFY_CHANGE_LAST_WRITE
16
+
17
+ // ----------------------------------------------------------
18
+ // Global variables
19
+ // ----------------------------------------------------------
20
+
21
+ extern VALUE cWDM_Monitor;
22
+
23
+ extern VALUE eWDM_UnknownFlagError;
24
+ extern VALUE eWDM_MonitorRunningError;
25
+ extern VALUE eWDM_InvalidDirectoryError;
26
+ extern VALUE eWDM_UnwatchableDirectoryError;
27
+
28
+ // ---------------------------------------------------------
29
+ // Prototypes
30
+ // ---------------------------------------------------------
31
+
32
+ void wdm_rb_monitor_init();
33
+
34
+ // ---------------------------------------------------------
35
+
36
+ #ifdef __cplusplus
37
+ }
38
+ #endif // __cplusplus
39
+
40
40
  #endif // WDM_RB_MONITOR_H
@@ -1,77 +1,77 @@
1
- #include "wdm.h"
2
-
3
- #include "memory.h"
4
- #include "utils.h"
5
-
6
- // ---------------------------------------------------------
7
- // Paths functions
8
- // ---------------------------------------------------------
9
-
10
- LPWSTR
11
- wdm_utils_convert_back_to_forward_slashes(LPWSTR path, DWORD path_len)
12
- {
13
- UINT i;
14
-
15
- for(i = 0; i < (path_len - 1); ++i) { // path_len-1 because we don't need to check the NULL-char!
16
- if ( path[i] == L'\\' ) path[i] = L'/';
17
- }
18
-
19
- return path;
20
- }
21
-
22
- LPWSTR
23
- wdm_utils_full_pathname(const LPWSTR path)
24
- {
25
- WCHAR maxed_path[WDM_MAX_WCHAR_LONG_PATH];
26
- LPWSTR full_path;
27
- size_t full_path_len;
28
- BOOL is_directory;
29
-
30
- if ( GetFullPathNameW(path, WDM_MAX_WCHAR_LONG_PATH, maxed_path, NULL) == 0 ) {
31
- return 0;
32
- }
33
-
34
- is_directory = wdm_utils_unicode_is_directory(maxed_path);
35
-
36
- full_path_len = wcslen(maxed_path);
37
- full_path = WDM_ALLOC_N(WCHAR, full_path_len + (is_directory ? 2 : 1)); // When it's a directory, add extra 1 for the (\) at the end
38
-
39
- wcscpy(full_path, maxed_path);
40
-
41
- if ( is_directory ) wcscat(full_path, L"\\");
42
-
43
- return full_path;
44
- }
45
-
46
- BOOL
47
- wdm_utils_unicode_is_directory(const LPWSTR path)
48
- {
49
- WCHAR unicode_path[WDM_MAX_WCHAR_LONG_PATH];
50
-
51
- wcscpy(unicode_path, L"\\\\?\\");
52
-
53
- if ( wdm_utils_is_unc_path(path) ) {
54
- wcscat(unicode_path, L"UNC\\");
55
- wcscat(unicode_path, path + 2); // +2 to skip the begin of a UNC path
56
- }
57
- else {
58
- wcscat(unicode_path, path);
59
- }
60
-
61
- return wdm_utils_is_directory(unicode_path);
62
- }
63
-
64
- BOOL
65
- wdm_utils_is_directory(const LPWSTR path)
66
- {
67
- DWORD dwAttrib = GetFileAttributesW(path);
68
-
69
- return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
70
- (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
71
- }
72
-
73
- BOOL
74
- wdm_utils_is_unc_path(const LPWSTR path)
75
- {
76
- return path[0] == path[1] && path[0] == L'\\';
1
+ #include "wdm.h"
2
+
3
+ #include "memory.h"
4
+ #include "utils.h"
5
+
6
+ // ---------------------------------------------------------
7
+ // Paths functions
8
+ // ---------------------------------------------------------
9
+
10
+ LPWSTR
11
+ wdm_utils_convert_back_to_forward_slashes(LPWSTR path, DWORD path_len)
12
+ {
13
+ UINT i;
14
+
15
+ for(i = 0; i < (path_len - 1); ++i) { // path_len-1 because we don't need to check the NULL-char!
16
+ if ( path[i] == L'\\' ) path[i] = L'/';
17
+ }
18
+
19
+ return path;
20
+ }
21
+
22
+ LPWSTR
23
+ wdm_utils_full_pathname(const LPWSTR path)
24
+ {
25
+ WCHAR maxed_path[WDM_MAX_WCHAR_LONG_PATH];
26
+ LPWSTR full_path;
27
+ size_t full_path_len;
28
+ BOOL is_directory;
29
+
30
+ if ( GetFullPathNameW(path, WDM_MAX_WCHAR_LONG_PATH, maxed_path, NULL) == 0 ) {
31
+ return 0;
32
+ }
33
+
34
+ is_directory = wdm_utils_unicode_is_directory(maxed_path);
35
+
36
+ full_path_len = wcslen(maxed_path);
37
+ full_path = WDM_ALLOC_N(WCHAR, full_path_len + (is_directory ? 2 : 1)); // When it's a directory, add extra 1 for the (\) at the end
38
+
39
+ wcscpy(full_path, maxed_path);
40
+
41
+ if ( is_directory ) wcscat(full_path, L"\\");
42
+
43
+ return full_path;
44
+ }
45
+
46
+ BOOL
47
+ wdm_utils_unicode_is_directory(const LPWSTR path)
48
+ {
49
+ WCHAR unicode_path[WDM_MAX_WCHAR_LONG_PATH];
50
+
51
+ wcscpy(unicode_path, L"\\\\?\\");
52
+
53
+ if ( wdm_utils_is_unc_path(path) ) {
54
+ wcscat(unicode_path, L"UNC\\");
55
+ wcscat(unicode_path, path + 2); // +2 to skip the begin of a UNC path
56
+ }
57
+ else {
58
+ wcscat(unicode_path, path);
59
+ }
60
+
61
+ return wdm_utils_is_directory(unicode_path);
62
+ }
63
+
64
+ BOOL
65
+ wdm_utils_is_directory(const LPWSTR path)
66
+ {
67
+ DWORD dwAttrib = GetFileAttributesW(path);
68
+
69
+ return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
70
+ (dwAttrib & FILE_ATTRIBUTE_DIRECTORY));
71
+ }
72
+
73
+ BOOL
74
+ wdm_utils_is_unc_path(const LPWSTR path)
75
+ {
76
+ return path[0] == path[1] && path[0] == L'\\';
77
77
  }
@@ -1,26 +1,26 @@
1
- #include <Windows.h>
2
-
3
- #ifndef WDM_UTILS_H
4
- #define WDM_UTILS_H
5
-
6
- #ifdef __cplusplus
7
- extern "C" {
8
- #endif // __cplusplus
9
-
10
- // ---------------------------------------------------------
11
- // Prototypes
12
- // ---------------------------------------------------------
13
-
14
- LPWSTR wdm_utils_convert_back_to_forward_slashes(LPWSTR, DWORD);
15
- LPWSTR wdm_utils_full_pathname(const LPWSTR path);
16
- BOOL wdm_utils_is_unc_path(const LPWSTR);
17
- BOOL wdm_utils_is_directory(const LPWSTR);
18
- BOOL wdm_utils_unicode_is_directory(const LPWSTR);
19
-
20
- // ---------------------------------------------------------
21
-
22
- #ifdef __cplusplus
23
- }
24
- #endif // __cplusplus
25
-
1
+ #include <Windows.h>
2
+
3
+ #ifndef WDM_UTILS_H
4
+ #define WDM_UTILS_H
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif // __cplusplus
9
+
10
+ // ---------------------------------------------------------
11
+ // Prototypes
12
+ // ---------------------------------------------------------
13
+
14
+ LPWSTR wdm_utils_convert_back_to_forward_slashes(LPWSTR, DWORD);
15
+ LPWSTR wdm_utils_full_pathname(const LPWSTR path);
16
+ BOOL wdm_utils_is_unc_path(const LPWSTR);
17
+ BOOL wdm_utils_is_directory(const LPWSTR);
18
+ BOOL wdm_utils_unicode_is_directory(const LPWSTR);
19
+
20
+ // ---------------------------------------------------------
21
+
22
+ #ifdef __cplusplus
23
+ }
24
+ #endif // __cplusplus
25
+
26
26
  #endif // WDM_UTILS_H
@@ -1,47 +1,47 @@
1
- #include "wdm.h"
2
-
3
- #include "entry.h"
4
- #include "queue.h"
5
- #include "monitor.h"
6
-
7
- #include "rb_monitor.h"
8
- #include "rb_change.h"
9
-
10
- // ----------------------------------------------------------
11
- // Global variables
12
- // ----------------------------------------------------------
13
-
14
- VALUE mWDM;
15
-
16
- VALUE eWDM_Error;
17
- VALUE eWDM_MonitorRunningError;
18
- VALUE eWDM_InvalidDirectoryError;
19
- VALUE eWDM_UnwatchableDirectoryError;
20
-
21
- ID wdm_rb_sym_call;
22
- ID wdm_rb_sym_at_file;
23
- ID wdm_rb_sym_at_type;
24
- ID wdm_rb_sym_added;
25
- ID wdm_rb_sym_modified;
26
- ID wdm_rb_sym_removed;
27
- ID wdm_rb_sym_renamed_old_file;
28
- ID wdm_rb_sym_renamed_new_file;
29
-
30
- rb_encoding *wdm_rb_enc_utf8;
31
-
32
- // ----------------------------------------------------------
33
-
34
- void
35
- Init_wdm_ext()
36
- {
37
- WDM_DEBUG("Registering WDM with Ruby!");
38
-
39
- wdm_rb_enc_utf8 = rb_utf8_encoding();
40
-
41
- mWDM = rb_define_module("WDM");
42
-
43
- eWDM_Error = rb_define_class_under(mWDM, "Error", rb_eStandardError);
44
-
45
- wdm_rb_monitor_init();
46
- wdm_rb_change_init();
1
+ #include "wdm.h"
2
+
3
+ #include "entry.h"
4
+ #include "queue.h"
5
+ #include "monitor.h"
6
+
7
+ #include "rb_monitor.h"
8
+ #include "rb_change.h"
9
+
10
+ // ----------------------------------------------------------
11
+ // Global variables
12
+ // ----------------------------------------------------------
13
+
14
+ VALUE mWDM;
15
+
16
+ VALUE eWDM_Error;
17
+ VALUE eWDM_MonitorRunningError;
18
+ VALUE eWDM_InvalidDirectoryError;
19
+ VALUE eWDM_UnwatchableDirectoryError;
20
+
21
+ ID wdm_rb_sym_call;
22
+ ID wdm_rb_sym_at_file;
23
+ ID wdm_rb_sym_at_type;
24
+ ID wdm_rb_sym_added;
25
+ ID wdm_rb_sym_modified;
26
+ ID wdm_rb_sym_removed;
27
+ ID wdm_rb_sym_renamed_old_file;
28
+ ID wdm_rb_sym_renamed_new_file;
29
+
30
+ rb_encoding *wdm_rb_enc_utf8;
31
+
32
+ // ----------------------------------------------------------
33
+
34
+ void
35
+ Init_wdm_ext()
36
+ {
37
+ WDM_DEBUG("Registering WDM with Ruby!");
38
+
39
+ wdm_rb_enc_utf8 = rb_utf8_encoding();
40
+
41
+ mWDM = rb_define_module("WDM");
42
+
43
+ eWDM_Error = rb_define_class_under(mWDM, "Error", rb_eStandardError);
44
+
45
+ wdm_rb_monitor_init();
46
+ wdm_rb_change_init();
47
47
  }
@@ -1,72 +1,82 @@
1
- #include <stdio.h>
2
-
3
- #define WINVER 0x0500 // Support Windows 2000 and later,
4
- #define _WIN32_WINNT 0x0500 // this is needed for 'GetLongPathNameW'
5
-
6
- #ifndef VC_EXTRALEAN
7
- #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
8
- #endif
9
-
10
- #include <Windows.h>
11
-
12
- #include <ruby.h>
13
- #include <ruby/encoding.h>
14
-
15
- #ifndef WDM_H
16
- #define WDM_H
17
-
18
- #ifdef __cplusplus
19
- extern "C" {
20
- #endif // __cplusplus
21
-
22
- // ---------------------------------------------------------
23
- // Constants
24
- // ---------------------------------------------------------
25
-
26
- #define WDM_DEBUG_ENABLED FALSE
27
-
28
- #define WDM_BUFFER_SIZE 16384 // 2^14 or 16Kb
29
-
30
- // The maximum WCHAR's for buffers used in functions that have
31
- // a unicode variant and require to prepend "\\?\" to the path
32
- #define WDM_MAX_WCHAR_LONG_PATH 32767
33
-
34
- // ---------------------------------------------------------
35
- // Macros
36
- // ---------------------------------------------------------
37
-
38
- #if WDM_DEBUG_ENABLED == TRUE
39
- #define WDM_DEBUG(str, ...) \
40
- fprintf(stderr, "[DEBUG] (%s@%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__)
41
-
42
- #define WDM_WDEBUG(str, ...) \
43
- fwprintf(stderr, L"[DEBUG] (%S@%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__)
44
-
45
- #else
46
- #define WDM_DEBUG(str, ...)
47
- #define WDM_WDEBUG(str, ...)
48
- #endif
49
-
50
- // ----------------------------------------------------------
51
- // Extern global variables
52
- // ----------------------------------------------------------
53
-
54
- extern VALUE mWDM;
55
-
56
- extern VALUE eWDM_Error;
57
-
58
- extern rb_encoding *wdm_rb_enc_utf8;
59
-
60
- // ---------------------------------------------------------
61
- // Prototypes
62
- // ---------------------------------------------------------
63
-
64
- void Init_wdm_ext();
65
-
66
- // ---------------------------------------------------------
67
-
68
- #ifdef __cplusplus
69
- }
70
- #endif // __cplusplus
71
-
1
+ #include <stdio.h>
2
+
3
+ // Support Windows 2000 and later,
4
+ // this is needed for 'GetLongPathNameW' (both of the following defines)
5
+ #ifndef WINVER
6
+ #define WINVER 0x0500
7
+ #endif
8
+ #ifndef _WIN32_WINNT
9
+ #define _WIN32_WINNT 0x0500
10
+ #endif
11
+
12
+ // Exclude rarely-used stuff from Windows headers (both of the following defines)
13
+ #ifndef WIN32_LEAN_AND_MEAN
14
+ #define WIN32_LEAN_AND_MEAN
15
+ #endif
16
+ #ifndef VC_EXTRALEAN
17
+ #define VC_EXTRALEAN
18
+ #endif
19
+
20
+ #include <Windows.h>
21
+
22
+ #include <ruby.h>
23
+ #include <ruby/encoding.h>
24
+
25
+ #ifndef WDM_H
26
+ #define WDM_H
27
+
28
+ #ifdef __cplusplus
29
+ extern "C" {
30
+ #endif // __cplusplus
31
+
32
+ // ---------------------------------------------------------
33
+ // Constants
34
+ // ---------------------------------------------------------
35
+
36
+ #define WDM_DEBUG_ENABLED FALSE
37
+
38
+ #define WDM_BUFFER_SIZE 16384 // 2^14 or 16Kb
39
+
40
+ // The maximum WCHAR's for buffers used in functions that have
41
+ // a unicode variant and require to prepend "\\?\" to the path
42
+ #define WDM_MAX_WCHAR_LONG_PATH 32767
43
+
44
+ // ---------------------------------------------------------
45
+ // Macros
46
+ // ---------------------------------------------------------
47
+
48
+ #if WDM_DEBUG_ENABLED == TRUE
49
+ #define WDM_DEBUG(str, ...) \
50
+ fprintf(stderr, "[DEBUG] (%s@%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__)
51
+
52
+ #define WDM_WDEBUG(str, ...) \
53
+ fwprintf(stderr, L"[DEBUG] (%S@%d): " str "\n", __FILE__, __LINE__, ##__VA_ARGS__)
54
+
55
+ #else
56
+ #define WDM_DEBUG(str, ...)
57
+ #define WDM_WDEBUG(str, ...)
58
+ #endif
59
+
60
+ // ----------------------------------------------------------
61
+ // Extern global variables
62
+ // ----------------------------------------------------------
63
+
64
+ extern VALUE mWDM;
65
+
66
+ extern VALUE eWDM_Error;
67
+
68
+ extern rb_encoding *wdm_rb_enc_utf8;
69
+
70
+ // ---------------------------------------------------------
71
+ // Prototypes
72
+ // ---------------------------------------------------------
73
+
74
+ void Init_wdm_ext();
75
+
76
+ // ---------------------------------------------------------
77
+
78
+ #ifdef __cplusplus
79
+ }
80
+ #endif // __cplusplus
81
+
72
82
  #endif // WDM_H