rb-fsevent 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,6 @@
1
+ {<img src="https://codeclimate.com/badge.png" />}[https://codeclimate.com/github/thibaudgg/rb-fsevent]
2
+
3
+
1
4
  = rb-fsevent
2
5
 
3
6
  Very simple & usable Mac OSX FSEvents API
Binary file
File without changes
@@ -65,13 +65,13 @@ static inline TStringIRep* TSICTStringCreateWithDataOfTypeAndFormat(CFDataRef da
65
65
  if (format == kTSITStringFormatDefault) {
66
66
  format = TSICTStringGetDefaultFormat();
67
67
  }
68
-
68
+
69
69
  TStringIRep* rep = calloc(1, sizeof(TStringIRep));
70
70
  rep->data = CFDataCreateCopy(kCFAllocatorDefault, data);
71
71
  rep->type = type;
72
72
  rep->format = format;
73
73
  rep->length = calloc(10, sizeof(char));
74
-
74
+
75
75
  CFIndex len = CFDataGetLength(rep->data);
76
76
  if (snprintf(rep->length, 10, "%lu", len)) {
77
77
  return rep;
@@ -86,10 +86,10 @@ static inline CFDataRef TSICTStringCreateDataFromIntermediateRepresentation(TStr
86
86
  CFIndex len = CFDataGetLength(rep->data);
87
87
  CFMutableDataRef buffer = CFDataCreateMutableCopy(kCFAllocatorDefault, (len + 12), rep->data);
88
88
  UInt8* bufferBytes = CFDataGetMutableBytePtr(buffer);
89
-
89
+
90
90
  size_t prefixLength = strlen(rep->length) + 1;
91
91
  CFDataReplaceBytes(buffer, BeginningRange, (const UInt8*)rep->length, (CFIndex)prefixLength);
92
-
92
+
93
93
  if (rep->format == kTSITStringFormatTNetstring) {
94
94
  const UInt8 ftag = (UInt8)TNetstringTypes[rep->type];
95
95
  CFDataAppendBytes(buffer, &ftag, 1);
@@ -98,10 +98,10 @@ static inline CFDataRef TSICTStringCreateDataFromIntermediateRepresentation(TStr
98
98
  const UInt8 ftag = (UInt8)OTNetstringTypes[rep->type];
99
99
  bufferBytes[(prefixLength - 1)] = ftag;
100
100
  }
101
-
101
+
102
102
  CFDataRef dataRep = CFDataCreateCopy(kCFAllocatorDefault, buffer);
103
103
  CFRelease(buffer);
104
-
104
+
105
105
  return dataRep;
106
106
  }
107
107
 
@@ -116,21 +116,21 @@ static inline CFStringRef TSICTStringCreateStringFromIntermediateRepresentation(
116
116
  static inline CFDataRef TSICTStringCreateDataWithDataOfTypeAndFormat(CFDataRef data, TSITStringTag type, TSITStringFormat format)
117
117
  {
118
118
  CFRetain(data);
119
-
119
+
120
120
  if (format == kTSITStringFormatDefault) {
121
121
  format = TSICTStringGetDefaultFormat();
122
122
  }
123
-
123
+
124
124
  TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, type, format);
125
125
  if (rep == NULL) {
126
126
  return NULL;
127
127
  }
128
-
128
+
129
129
  CFDataRef result = TSICTStringCreateDataFromIntermediateRepresentation(rep);
130
-
130
+
131
131
  TSICTStringDestroy(rep);
132
132
  CFRelease(data);
133
-
133
+
134
134
  return result;
135
135
  }
136
136
 
@@ -139,15 +139,15 @@ static inline void TSICTStringAppendObjectToMutableDataWithFormat(CFTypeRef obje
139
139
  if (object == NULL) {
140
140
  object = kCFNull;
141
141
  }
142
-
142
+
143
143
  CFRetain(object);
144
-
144
+
145
145
  TStringIRep* objRep = TSICTStringCreateWithObjectAndFormat(object, format);
146
146
  CFDataRef objData = TSICTStringCreateDataFromIntermediateRepresentation(objRep);
147
147
  CFDataAppendBytes(buffer, (CFDataGetBytePtr(objData)), CFDataGetLength(objData));
148
148
  CFRelease(objData);
149
149
  TSICTStringDestroy(objRep);
150
-
150
+
151
151
  CFRelease(object);
152
152
  }
153
153
 
@@ -156,7 +156,7 @@ static void ArrayBufferAppendCallback(const void* item, void* context)
156
156
  TStringCollectionCallbackContext* cx = (TStringCollectionCallbackContext*)context;
157
157
  CFMutableDataRef buffer = cx->buffer;
158
158
  TSITStringFormat format = cx->format;
159
-
159
+
160
160
  TSICTStringAppendObjectToMutableDataWithFormat(item, buffer, format);
161
161
  }
162
162
 
@@ -165,7 +165,7 @@ static void DictionaryBufferAppendCallback(const void* key, const void* value, v
165
165
  TStringCollectionCallbackContext* cx = (TStringCollectionCallbackContext*)context;
166
166
  CFMutableDataRef buffer = cx->buffer;
167
167
  TSITStringFormat format = cx->format;
168
-
168
+
169
169
  TSICTStringAppendObjectToMutableDataWithFormat(key, buffer, format);
170
170
  TSICTStringAppendObjectToMutableDataWithFormat(value, buffer, format);
171
171
  }
@@ -181,15 +181,15 @@ CFDataRef TSICTStringCreateRenderedDataFromObjectWithFormat(CFTypeRef object, TS
181
181
  if (object == NULL) {
182
182
  object = kCFNull;
183
183
  }
184
-
184
+
185
185
  CFRetain(object);
186
-
186
+
187
187
  TStringIRep* rep = TSICTStringCreateWithObjectAndFormat(object, format);
188
188
  CFDataRef data = TSICTStringCreateDataFromIntermediateRepresentation(rep);
189
-
189
+
190
190
  TSICTStringDestroy(rep);
191
191
  CFRelease(object);
192
-
192
+
193
193
  return data;
194
194
  }
195
195
 
@@ -203,15 +203,15 @@ CFStringRef TSICTStringCreateRenderedStringFromObjectWithFormat(CFTypeRef object
203
203
  if (object == NULL) {
204
204
  object = kCFNull;
205
205
  }
206
-
206
+
207
207
  CFRetain(object);
208
-
208
+
209
209
  TStringIRep* rep = TSICTStringCreateWithObjectAndFormat(object, format);
210
210
  CFStringRef string = TSICTStringCreateStringFromIntermediateRepresentation(rep);
211
-
211
+
212
212
  TSICTStringDestroy(rep);
213
213
  CFRelease(object);
214
-
214
+
215
215
  return string;
216
216
  }
217
217
 
@@ -222,10 +222,10 @@ TStringIRep* TSICTStringCreateWithObjectAndFormat(CFTypeRef object, TSITStringFo
222
222
  return TSICTStringCreateNullWithFormat(format);
223
223
  }
224
224
  CFRetain(object);
225
-
225
+
226
226
  CFTypeID cfType = CFGetTypeID(object);
227
227
  TStringIRep* rep = NULL;
228
-
228
+
229
229
  if (cfType == kCFDataTypeID) {
230
230
  rep = TSICTStringCreateWithDataOfTypeAndFormat(object, kTSITStringTagString, format);
231
231
  } else if (cfType == kCFStringTypeID) {
@@ -247,7 +247,7 @@ TStringIRep* TSICTStringCreateWithObjectAndFormat(CFTypeRef object, TSITStringFo
247
247
  } else {
248
248
  rep = TSICTStringCreateInvalidWithFormat(format);
249
249
  }
250
-
250
+
251
251
  CFRelease(object);
252
252
  return rep;
253
253
  }
@@ -268,7 +268,7 @@ TStringIRep* TSICTStringCreateWithNumberAndFormat(CFNumberRef number, TSITString
268
268
  TSITStringTag tag = kTSITStringTagNumber;
269
269
  CFDataRef data;
270
270
  CFNumberType numType = CFNumberGetType(number);
271
-
271
+
272
272
  switch(numType) {
273
273
  case kCFNumberCharType:
274
274
  {
@@ -291,7 +291,7 @@ TStringIRep* TSICTStringCreateWithNumberAndFormat(CFNumberRef number, TSITString
291
291
  break;
292
292
  }
293
293
  }
294
-
294
+
295
295
  if (tag == kTSITStringTagBool) {
296
296
  bool value;
297
297
  CFNumberGetValue(number, kCFNumberIntType, &value);
@@ -304,17 +304,17 @@ TStringIRep* TSICTStringCreateWithNumberAndFormat(CFNumberRef number, TSITString
304
304
  char buf[32];
305
305
  char *p, *e;
306
306
  double value;
307
-
307
+
308
308
  CFNumberGetValue(number, numType, &value);
309
309
  sprintf(buf, "%#.15g", value);
310
-
310
+
311
311
  e = buf + strlen(buf);
312
312
  p = e;
313
313
  while (p[-1]=='0' && ('0' <= p[-2] && p[-2] <= '9')) {
314
314
  p--;
315
315
  }
316
316
  memmove(p, e, strlen(e)+1);
317
-
317
+
318
318
  data = CFDataCreate(kCFAllocatorDefault, (UInt8*)buf, (CFIndex)strlen(buf));
319
319
  } else {
320
320
  char buf[32];
@@ -323,7 +323,7 @@ TStringIRep* TSICTStringCreateWithNumberAndFormat(CFNumberRef number, TSITString
323
323
  sprintf(buf, "%lli", value);
324
324
  data = CFDataCreate(kCFAllocatorDefault, (UInt8*)buf, (CFIndex)strlen(buf));
325
325
  }
326
-
326
+
327
327
  TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(data, tag, format);
328
328
  CFRelease(data);
329
329
  CFRelease(number);
@@ -365,13 +365,13 @@ TStringIRep* TSICTStringCreateInvalidWithFormat(TSITStringFormat format)
365
365
  TStringIRep* TSICTStringCreateWithArrayAndFormat(CFArrayRef array, TSITStringFormat format)
366
366
  {
367
367
  CFRetain(array);
368
-
368
+
369
369
  CFMutableDataRef buffer = CFDataCreateMutable(kCFAllocatorDefault, 0);
370
-
370
+
371
371
  CFRange all = CFRangeMake(0, CFArrayGetCount(array));
372
372
  TStringCollectionCallbackContext cx = {buffer, format};
373
373
  CFArrayApplyFunction(array, all, ArrayBufferAppendCallback, &cx);
374
-
374
+
375
375
  TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(buffer, kTSITStringTagList, format);
376
376
  CFRelease(buffer);
377
377
  CFRelease(array);
@@ -381,12 +381,12 @@ TStringIRep* TSICTStringCreateWithArrayAndFormat(CFArrayRef array, TSITStringFor
381
381
  TStringIRep* TSICTStringCreateWithDictionaryAndFormat(CFDictionaryRef dictionary, TSITStringFormat format)
382
382
  {
383
383
  CFRetain(dictionary);
384
-
384
+
385
385
  CFMutableDataRef buffer = CFDataCreateMutable(kCFAllocatorDefault, 0);
386
-
386
+
387
387
  TStringCollectionCallbackContext cx = {buffer, format};
388
388
  CFDictionaryApplyFunction(dictionary, DictionaryBufferAppendCallback, &cx);
389
-
389
+
390
390
  TStringIRep* rep = TSICTStringCreateWithDataOfTypeAndFormat(buffer, kTSITStringTagDict, format);
391
391
  CFRelease(buffer);
392
392
  CFRelease(dictionary);
@@ -134,13 +134,11 @@ int cli_parser (int argc, const char** argv, struct cli_info* args_info)
134
134
  case 'V': // version
135
135
  cli_print_version();
136
136
  exit(EXIT_SUCCESS);
137
- break;
138
137
  case 'h': // help
139
138
  case '?': // invalid option
140
139
  case ':': // missing argument
141
140
  cli_print_help();
142
141
  exit((c == 'h') ? EXIT_SUCCESS : EXIT_FAILURE);
143
- break;
144
142
  }
145
143
  }
146
144
 
@@ -1,6 +1,8 @@
1
1
  #ifndef CLI_H
2
2
  #define CLI_H
3
3
 
4
+ #include "common.h"
5
+
4
6
  #ifndef CLI_NAME
5
7
  #define CLI_NAME "fsevent_watch"
6
8
  #endif /* CLI_NAME */
@@ -10,12 +12,9 @@
10
12
  #endif /* PROJECT_VERSION */
11
13
 
12
14
  #ifndef CLI_VERSION
13
- #define _str(s) #s
14
- #define _xstr(s) _str(s)
15
15
  #define CLI_VERSION _xstr(PROJECT_VERSION)
16
16
  #endif /* CLI_VERSION */
17
17
 
18
- #include "common.h"
19
18
 
20
19
  struct cli_info {
21
20
  UInt64 since_when_arg;
@@ -9,21 +9,9 @@
9
9
  #include <CoreServices/CoreServices.h>
10
10
  #include <unistd.h>
11
11
  #include "compat.h"
12
+ #include "defines.h"
12
13
  #include "TSICTString.h"
13
14
 
14
- #define COMPILED_AT __DATE__ " " __TIME__
15
-
16
- #define FLAG_CHECK(flags, flag) ((flags) & (flag))
17
-
18
- #define FPRINTF_FLAG_CHECK(flags, flag, msg, fd) \
19
- do { \
20
- if (FLAG_CHECK(flags, flag)) { \
21
- fprintf(fd, "%s", msg "\n"); } } \
22
- while (0)
23
-
24
- #define FLAG_CHECK_STDERR(flags, flag, msg) \
25
- FPRINTF_FLAG_CHECK(flags, flag, msg, stderr)
26
-
27
15
  enum FSEventWatchOutputFormat {
28
16
  kFSEventWatchOutputFormatClassic,
29
17
  kFSEventWatchOutputFormatNIW,
@@ -0,0 +1,40 @@
1
+ #ifndef fsevent_watch_defines_h
2
+ #define fsevent_watch_defines_h
3
+
4
+ #define _str(s) #s
5
+ #define _xstr(s) _str(s)
6
+
7
+ #define COMPILED_AT __DATE__ " " __TIME__
8
+
9
+ #if defined (__clang__)
10
+ #define COMPILER "clang " __clang_version__
11
+ #elif defined (__GNUC__)
12
+ #define COMPILER "gcc " __VERSION__
13
+ #else
14
+ #define COMPILER "unknown"
15
+ #endif
16
+
17
+ #if defined(__ppc__)
18
+ #define TARGET_CPU "ppc"
19
+ #elif defined(__ppc64__)
20
+ #define TARGET_CPU "ppc64"
21
+ #elif defined(__i386__)
22
+ #define TARGET_CPU "i386"
23
+ #elif defined(__x86_64__)
24
+ #define TARGET_CPU "x86_64"
25
+ #else
26
+ #define TARGET_CPU "unknown"
27
+ #endif
28
+
29
+ #define FLAG_CHECK(flags, flag) ((flags) & (flag))
30
+
31
+ #define FPRINTF_FLAG_CHECK(flags, flag, msg, fd) \
32
+ do { \
33
+ if (FLAG_CHECK(flags, flag)) { \
34
+ fprintf(fd, "%s", msg "\n"); } } \
35
+ while (0)
36
+
37
+ #define FLAG_CHECK_STDERR(flags, flag, msg) \
38
+ FPRINTF_FLAG_CHECK(flags, flag, msg, stderr)
39
+
40
+ #endif /* fsevent_watch_defines_h */
@@ -47,48 +47,48 @@ static void append_path(const char* path)
47
47
  #endif
48
48
 
49
49
  #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
50
-
50
+
51
51
  #ifdef DEBUG
52
52
  fprintf(stderr, "compiled against 10.6+, using CFURLCreateFileReferenceURL\n");
53
53
  #endif
54
-
54
+
55
55
  CFURLRef url = CFURLCreateFromFileSystemRepresentation(NULL, (const UInt8*)path, (CFIndex)strlen(path), false);
56
56
  CFURLRef placeholder = CFURLCopyAbsoluteURL(url);
57
57
  CFRelease(url);
58
-
58
+
59
59
  CFMutableArrayRef imaginary = NULL;
60
-
60
+
61
61
  // if we don't have an existing url, spin until we get to a parent that
62
62
  // does exist, saving any imaginary components for appending back later
63
63
  while(!CFURLResourceIsReachable(placeholder, NULL)) {
64
64
  #ifdef DEBUG
65
65
  fprintf(stderr, "path does not exist\n");
66
66
  #endif
67
-
67
+
68
68
  CFStringRef child;
69
-
69
+
70
70
  if (imaginary == NULL) {
71
71
  imaginary = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks);
72
72
  }
73
-
73
+
74
74
  child = CFURLCopyLastPathComponent(placeholder);
75
75
  CFArrayInsertValueAtIndex(imaginary, 0, child);
76
76
  CFRelease(child);
77
-
77
+
78
78
  url = CFURLCreateCopyDeletingLastPathComponent(NULL, placeholder);
79
79
  CFRelease(placeholder);
80
80
  placeholder = url;
81
-
81
+
82
82
  #ifdef DEBUG
83
83
  fprintf(stderr, "parent: ");
84
84
  CFShow(placeholder);
85
85
  #endif
86
86
  }
87
-
87
+
88
88
  #ifdef DEBUG
89
89
  fprintf(stderr, "path exists\n");
90
90
  #endif
91
-
91
+
92
92
  // realpath() doesn't always return the correct case for a path, so this
93
93
  // is a funky workaround that converts a path into a (volId/inodeId) pair
94
94
  // and asks what the path should be for that. since it looks at the actual
@@ -98,12 +98,12 @@ static void append_path(const char* path)
98
98
  CFRelease(placeholder);
99
99
  placeholder = CFURLCreateFilePathURL(NULL, url, NULL);
100
100
  CFRelease(url);
101
-
101
+
102
102
  #ifdef DEBUG
103
103
  fprintf(stderr, "path resolved to: ");
104
104
  CFShow(placeholder);
105
105
  #endif
106
-
106
+
107
107
  // if we stripped off any imaginary path components, append them back on
108
108
  if (imaginary != NULL) {
109
109
  CFIndex count = CFArrayGetCount(imaginary);
@@ -119,30 +119,30 @@ static void append_path(const char* path)
119
119
  }
120
120
  CFRelease(imaginary);
121
121
  }
122
-
122
+
123
123
  #ifdef DEBUG
124
124
  fprintf(stderr, "result: ");
125
125
  CFShow(placeholder);
126
126
  #endif
127
-
127
+
128
128
  CFStringRef cfPath = CFURLCopyFileSystemPath(placeholder, kCFURLPOSIXPathStyle);
129
129
  CFArrayAppendValue(config.paths, cfPath);
130
130
  CFRelease(cfPath);
131
131
  CFRelease(placeholder);
132
-
132
+
133
133
  #else
134
-
134
+
135
135
  #ifdef DEBUG
136
136
  fprintf(stderr, "compiled against 10.5, using realpath()\n");
137
137
  #endif
138
-
138
+
139
139
  char fullPath[PATH_MAX + 1];
140
-
140
+
141
141
  if (realpath(path, fullPath) == NULL) {
142
142
  #ifdef DEBUG
143
143
  fprintf(stderr, " realpath not directly resolvable from path\n");
144
144
  #endif
145
-
145
+
146
146
  if (path[0] != '/') {
147
147
  #ifdef DEBUG
148
148
  fprintf(stderr, " passed path is not absolute\n");
@@ -162,18 +162,18 @@ static void append_path(const char* path)
162
162
  strlcpy(fullPath, path, sizeof(fullPath));
163
163
  }
164
164
  }
165
-
165
+
166
166
  #ifdef DEBUG
167
167
  fprintf(stderr, " resolved path to: %s\n", fullPath);
168
168
  fprintf(stderr, "\n");
169
169
  #endif
170
-
170
+
171
171
  CFStringRef pathRef = CFStringCreateWithCString(kCFAllocatorDefault,
172
172
  fullPath,
173
173
  kCFStringEncodingUTF8);
174
174
  CFArrayAppendValue(config.paths, pathRef);
175
175
  CFRelease(pathRef);
176
-
176
+
177
177
  #endif
178
178
  }
179
179
 
@@ -249,7 +249,7 @@ static inline void parse_cli_settings(int argc, const char* argv[])
249
249
  fprintf(stderr, "config.latency %f\n", config.latency);
250
250
 
251
251
  // STFU clang
252
- #if __LP64__
252
+ #if defined(__LP64__)
253
253
  fprintf(stderr, "config.flags %#.8x\n", config.flags);
254
254
  #else
255
255
  fprintf(stderr, "config.flags %#.8lx\n", config.flags);
@@ -382,7 +382,7 @@ static void callback(__attribute__((unused)) FSEventStreamRef streamRef,
382
382
  fprintf(stderr, " event ID: %llu\n", eventIds[i]);
383
383
 
384
384
  // STFU clang
385
- #if __LP64__
385
+ #if defined(__LP64__)
386
386
  fprintf(stderr, " event flags: %#.8x\n", eventFlags[i]);
387
387
  #else
388
388
  fprintf(stderr, " event flags: %#.8lx\n", eventFlags[i]);