return 4;
// }}}
+ case 4: // count watches {{{
+ if (4 > rlen) *rbuf = driver_alloc(4);
+
+ (*rbuf)[0] = (context->nwatches >> (8 * 3)) & 0xff;
+ (*rbuf)[1] = (context->nwatches >> (8 * 2)) & 0xff;
+ (*rbuf)[2] = (context->nwatches >> (8 * 1)) & 0xff;
+ (*rbuf)[3] = (context->nwatches >> (8 * 0)) & 0xff;
+ return 4;
+ // }}}
+
default: // unknown request
return -1;
}
%% public interface
-export([open/0, open/1, close/1]).
--export([add/3, update/3, remove/2, list/1]).
+-export([add/3, update/3, remove/2, list/1, count/1]).
-export([controlling_process/2]).
-export([format_error/1]).
%% @doc List watched paths.
-spec list(handle()) ->
- {ok, [Entry]} | {error, badarg}
+ [Entry]
when Entry :: {file:filename(), [flag()]}.
list(Handle) ->
try port_control(Handle, 3, <<>>) of
+ <<Count:32>> -> receive_listing(Handle, Count, [])
+ catch
+ _:_ -> erlang:error(badarg)
+ end.
+
+%% @doc Count watched paths.
+
+-spec count(handle()) ->
+ non_neg_integer().
+
+count(Handle) ->
+ try port_control(Handle, 4, <<>>) of
<<Count:32>> ->
- Entries = receive_listing(Handle, Count, []),
- {ok, Entries}
+ Count
catch
- _:_ -> {error, badarg}
+ _:_ -> erlang:error(badarg)
end.
%% @doc Workhorse for {@link list/1}.