[libFuzzer] Implement DirName() for Windows.
authorMarcos Pividori <mpividori@google.com>
Tue, 13 Dec 2016 17:46:32 +0000 (17:46 +0000)
committerMarcos Pividori <mpividori@google.com>
Tue, 13 Dec 2016 17:46:32 +0000 (17:46 +0000)
commit67dfacdd80791984a11d5ce3a4df8dad3043ed8f
tree4d8bc08a9f9b91014f33d3dd5d0d31ae19560f1c
parent64d41473965d0e8d39f0c13fa38966ff0d365d8e
[libFuzzer] Implement DirName() for Windows.

Implement DirName from scratch to avoid dependencies on external libraries.
It's based on MSDN documentation for Naming Files, Paths, and Namespaces.

The algorithm can't simply start from the end and look backwards for the
first separator, because we need to preserve the prefix that represent
the root location. We shouldn't remove anything there. In Windows we
have many different options, like:
 \\Server\Share\ , \ , C: , C:\ , \\?\C:\ , \\?\UNC\Server\Share\
We remove the last separator in the rest of the path, if it exists.

It was implemented to have a similar behaviour to dirname() in linux,
removing trailing separators, returning "." when the path doesn't
contain separators, etc.

Differential Revision: https://reviews.llvm.org/D27579

llvm-svn: 289562
llvm/lib/Fuzzer/FuzzerIOWindows.cpp