<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def longest_dir_prefix(path, prefixes):
 """Given a list of prefixes, return the one that is the longest prefix to the given path. Returns None if there are no matches. """

  longest_match, longest_prefix = 0, None
  for prefix in prefixes:
    if fast_relpath_optional(path, prefix) is not None and len(prefix) > longest_match:
      longest_match, longest_prefix = len(prefix), prefix

  return longest_prefix