@@ -299,10 +299,10 @@ _DMON_PRIVATE char* dmon__strcpy(char* dst, int dst_sz, const char* src)
299299
300300_DMON_PRIVATE char * dmon__unixpath (char * dst , int size , const char * path )
301301{
302- size_t len = strlen (path );
302+ size_t len = strlen (path ), i ;
303303 len = dmon__min (len , (size_t )size - 1 );
304304
305- for (size_t i = 0 ; i < len ; i ++ ) {
305+ for (i = 0 ; i < len ; i ++ ) {
306306 if (path [i ] != '\\' )
307307 dst [i ] = path [i ];
308308 else
@@ -1247,15 +1247,17 @@ _DMON_PRIVATE void* dmon__cf_realloc(void* ptr, CFIndex newsize, CFOptionFlags h
12471247
12481248_DMON_PRIVATE void dmon__fsevent_process_events (void )
12491249{
1250- for (int i = 0 , c = stb_sb_count (_dmon .events ); i < c ; i ++ ) {
1250+ int i , c ;
1251+ for (i = 0 , c = stb_sb_count (_dmon .events ); i < c ; i ++ ) {
12511252 dmon__fsevent_event * ev = & _dmon .events [i ];
12521253 if (ev -> skip ) {
12531254 continue ;
12541255 }
12551256
12561257 // remove redundant modify events on a single file
12571258 if (ev -> event_flags & kFSEventStreamEventFlagItemModified ) {
1258- for (int j = i + 1 ; j < c ; j ++ ) {
1259+ int j ;
1260+ for (j = i + 1 ; j < c ; j ++ ) {
12591261 dmon__fsevent_event * check_ev = & _dmon .events [j ];
12601262 if ((check_ev -> event_flags & kFSEventStreamEventFlagItemModified ) &&
12611263 strcmp (ev -> filepath , check_ev -> filepath ) == 0 ) {
@@ -1264,7 +1266,8 @@ _DMON_PRIVATE void dmon__fsevent_process_events(void)
12641266 }
12651267 }
12661268 } else if ((ev -> event_flags & kFSEventStreamEventFlagItemRenamed ) && !ev -> move_valid ) {
1267- for (int j = i + 1 ; j < c ; j ++ ) {
1269+ int j ;
1270+ for (j = i + 1 ; j < c ; j ++ ) {
12681271 dmon__fsevent_event * check_ev = & _dmon .events [j ];
12691272 if ((check_ev -> event_flags & kFSEventStreamEventFlagItemRenamed ) &&
12701273 check_ev -> event_id == (ev -> event_id + 1 )) {
@@ -1296,7 +1299,7 @@ _DMON_PRIVATE void dmon__fsevent_process_events(void)
12961299 }
12971300
12981301 // trigger user callbacks
1299- for (int i = 0 , c = stb_sb_count (_dmon .events ); i < c ; i ++ ) {
1302+ for (i = 0 , c = stb_sb_count (_dmon .events ); i < c ; i ++ ) {
13001303 dmon__fsevent_event * ev = & _dmon .events [i ];
13011304 if (ev -> skip ) {
13021305 continue ;
@@ -1314,7 +1317,8 @@ _DMON_PRIVATE void dmon__fsevent_process_events(void)
13141317 watch -> watch_cb (ev -> watch_id , DMON_ACTION_MODIFY , watch -> rootdir_unmod , ev -> filepath , NULL ,
13151318 watch -> user_data );
13161319 } else if (ev -> event_flags & kFSEventStreamEventFlagItemRenamed ) {
1317- for (int j = i + 1 ; j < c ; j ++ ) {
1320+ int j ;
1321+ for (j = i + 1 ; j < c ; j ++ ) {
13181322 dmon__fsevent_event * check_ev = & _dmon .events [j ];
13191323 if (check_ev -> event_flags & kFSEventStreamEventFlagItemRenamed ) {
13201324 watch -> watch_cb (check_ev -> watch_id , DMON_ACTION_MOVE , watch -> rootdir_unmod ,
@@ -1342,6 +1346,7 @@ static void* dmon__thread(void* arg)
13421346 dispatch_semaphore_signal (_dmon .thread_sem );
13431347
13441348 while (!_dmon .quit ) {
1349+ int i ;
13451350 if (_dmon .modify_watches || pthread_mutex_trylock (& _dmon .mutex ) != 0 ) {
13461351 nanosleep (& req , & rem );
13471352 continue ;
@@ -1353,7 +1358,7 @@ static void* dmon__thread(void* arg)
13531358 continue ;
13541359 }
13551360
1356- for (int i = 0 ; i < _dmon .num_watches ; i ++ ) {
1361+ for (i = 0 ; i < _dmon .num_watches ; i ++ ) {
13571362 dmon__watch_state * watch = & _dmon .watches [i ];
13581363 if (!watch -> init ) {
13591364 DMON_ASSERT (watch -> fsev_stream_ref );
@@ -1420,8 +1425,11 @@ DMON_API_IMPL void dmon_deinit(void)
14201425
14211426 dispatch_release (_dmon .thread_sem );
14221427
1423- for (int i = 0 ; i < _dmon .num_watches ; i ++ ) {
1424- dmon__unwatch (& _dmon .watches [i ]);
1428+ {
1429+ int i ;
1430+ for (i = 0 ; i < _dmon .num_watches ; i ++ ) {
1431+ dmon__unwatch (& _dmon .watches [i ]);
1432+ }
14251433 }
14261434
14271435 pthread_mutex_destroy (& _dmon .mutex );
@@ -1448,27 +1456,30 @@ _DMON_PRIVATE void dmon__fsevent_callback(ConstFSEventStreamRef stream_ref, void
14481456 char abs_filepath [DMON_MAX_PATH ];
14491457 char abs_filepath_lower [DMON_MAX_PATH ];
14501458
1451- for (size_t i = 0 ; i < num_events ; i ++ ) {
1452- const char * filepath = ((const char * * )event_paths )[i ];
1453- long flags = (long )event_flags [i ];
1454- uint64_t event_id = (uint64_t )event_ids [i ];
1455- dmon__fsevent_event ev ;
1456- memset (& ev , 0x0 , sizeof (ev ));
1457-
1458- dmon__strcpy (abs_filepath , sizeof (abs_filepath ), filepath );
1459- dmon__unixpath (abs_filepath , sizeof (abs_filepath ), abs_filepath );
1460-
1461- // normalize path, so it would be the same on both MacOS file-system types (case/nocase)
1462- dmon__tolower (abs_filepath_lower , sizeof (abs_filepath ), abs_filepath );
1463- DMON_ASSERT (strstr (abs_filepath_lower , watch -> rootdir ) == abs_filepath_lower );
1464-
1465- // strip the root dir from the begining
1466- dmon__strcpy (ev .filepath , sizeof (ev .filepath ), abs_filepath + strlen (watch -> rootdir ));
1467-
1468- ev .event_flags = flags ;
1469- ev .event_id = event_id ;
1470- ev .watch_id = watch_id ;
1471- stb_sb_push (_dmon .events , ev );
1459+ {
1460+ size_t i ;
1461+ for (i = 0 ; i < num_events ; i ++ ) {
1462+ const char * filepath = ((const char * * ) event_paths )[i ];
1463+ long flags = (long ) event_flags [i ];
1464+ uint64_t event_id = (uint64_t ) event_ids [i ];
1465+ dmon__fsevent_event ev ;
1466+ memset (& ev , 0x0 , sizeof (ev ));
1467+
1468+ dmon__strcpy (abs_filepath , sizeof (abs_filepath ), filepath );
1469+ dmon__unixpath (abs_filepath , sizeof (abs_filepath ), abs_filepath );
1470+
1471+ // normalize path, so it would be the same on both MacOS file-system types (case/nocase)
1472+ dmon__tolower (abs_filepath_lower , sizeof (abs_filepath ), abs_filepath );
1473+ DMON_ASSERT (strstr (abs_filepath_lower , watch -> rootdir ) == abs_filepath_lower );
1474+
1475+ // strip the root dir from the begining
1476+ dmon__strcpy (ev .filepath , sizeof (ev .filepath ), abs_filepath + strlen (watch -> rootdir ));
1477+
1478+ ev .event_flags = flags ;
1479+ ev .event_id = event_id ;
1480+ ev .watch_id = watch_id ;
1481+ stb_sb_push (_dmon .events , ev );
1482+ }
14721483 }
14731484}
14741485
0 commit comments