anchor.diff:  %%    [file:out-of-range] is raised if $offset is negative, or if it exceeds 
   %%       the current file size.
   %%    [file:io-error] is raised if any other error occurs.
  -write_binary(Ctx,File,Value) ->
  -   write_binary(Ctx,File,Value,?intv(0)).
  -
  -write_binary(_, File, ?bin(Value), Offset) when is_binary(File),
  -                                                is_integer(Offset) ->
  +write_binary(_, File, ?bin(Value)) when is_binary(File) ->
  +   % truncate the file if possible when no offset
      case file:open(File, [write,binary]) of
  -      {ok,Fd} ->
  -         case file:position(Fd, Offset) of
  -            {ok,_} ->
  -               case catch io:put_chars(Fd, Value) of
  -                  ok ->
  -                     _ = file:close(Fd),
  -                     [];
  -                  _ ->
  -                     _ = file:close(Fd),
  -                     err_io_error(File)
  -               end;
  -            {error,einval} ->
  -               err_out_of_range(Offset)
  +      {ok, Fd} ->
  +         try
  +            ok = file:write(Fd, Value),
  +            []
  +         catch
  +            _:_ ->
  +               err_io_error(File)
  +         after
  +             file:close(Fd)
            end;
         {error,eisdir} ->
            err_is_dir(File);
  
positive.code:       true ->
           try
              NDir = maybe_add_dir_sep(filename:nativename(Dir)),
              %?dbg("NDir",NDir),
              if Recursive ->
                    L = do_rec_list(Dir),
                    %?dbg("L",L),
                    [binary:replace(filename:nativename(Li), NDir, <<>>) || Li <- L];
                 true ->
                    [binary:replace(maybe_add_dir_sep(filename:nativename(Li)), NDir, <<>>) || 
                     Li <- file_wildcard(Pattern, Dir)]
              end
           catch
              _:_ ->
  
negative.code:                 name = ?Q(<<"unknown-encoding">>)
                  },
     exit(E).
  err_out_of_range(Offset) ->
     E = #xqError{description = <<"The specified offset or length (",
                                (integer_to_binary(Offset))/binary,
                                ") is negative, or the chosen values"
                                " would exceed the file bounds">>,
                  name = ?Q(<<"out-of-range">>)
  