Refine the -o option when -Lmakefile & -Landroidbp

The commands below
$>mkdir tmp
$>hidl-gen -o tmp -Landroidbp \
	-randroid.hardware:hardware/interfaces \
	-randroid.hidl:system/libhidl/transport \
	android.hardware.tests.libhwbinder@1.0

geneates files to a ./tmphardware directory instead of ./tmp/hardware.
Refine this and generate files under the specified directory.
Test: Pixel phone
Bug: 65036223
Change-Id: Ibf620414acc95367d259994ee140099180a3fa54
diff --git a/main.cpp b/main.cpp
index 647ea3a..a936cab 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1430,8 +1430,7 @@
             }
 
             if (outputFormat->mOutputMode == OutputHandler::NEEDS_DIR) {
-                const size_t len = outputPath.size();
-                if (outputPath[len - 1] != '/') {
+                if (outputPath.back() != '/') {
                     outputPath += "/";
                 }
             }
@@ -1442,6 +1441,9 @@
             if (outputPath.empty()) {
                 outputPath = rootPath;
             }
+            if (outputPath.back() != '/') {
+                outputPath += "/";
+            }
 
             break;
         }