]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/C/Split/Split.c
BaseTools:remove the redundant directories for '-f' with absolute path.
[mirror_edk2.git] / BaseTools / Source / C / Split / Split.c
index 5ebda0901bae0c476de5ea6abe27ba260afcf577..44a09681d36a9ebaebe9659faa3a4e66b59fb22c 100644 (file)
@@ -2,7 +2,7 @@
 \r
   Split a file into two pieces at the request offset.\r
 \r
-Copyright (c)  1999-2008 Intel Corporation. All rights reserved\r
+Copyright (c) 1999 - 2015, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials are licensed and made available\r
 under the terms and conditions of the BSD License which accompanies this\r
 distribution.  The full text of the license may be found at\r
@@ -19,6 +19,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 #include <stdlib.h>\r
 #ifdef __GNUC__\r
 #include <unistd.h>\r
+#else\r
+#include <direct.h>\r
 #endif\r
 #include <ctype.h>\r
 #include "ParseInf.h"\r
@@ -55,8 +57,10 @@ Returns:
 \r
 --*/\r
 {\r
-  printf ("%s v%d.%d -Utility to break a file into two pieces at the request offset.\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);\r
-  printf ("Copyright (c) 1999-2007 Intel Corporation. All rights reserved.\n");\r
+  printf ("%s Version %d.%d %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);\r
+  printf ("Copyright (c) 1999-2015 Intel Corporation. All rights reserved.\n");\r
+  printf ("\n  SplitFile creates two Binary files either in the same directory as the current working\n");\r
+  printf ("  directory or in the specified directory.\n");\r
 }\r
 \r
 void\r
@@ -122,14 +126,14 @@ GetSplitValue (
     }\r
   }\r
 \r
-  lastCHAR = (CHAR8)toupper(SplitValueString[len - 1]);\r
+  lastCHAR = (CHAR8)toupper((int)SplitValueString[len - 1]);\r
 \r
   if (lastCHAR != 'K' && lastCHAR != 'M' && lastCHAR != 'G') {\r
     return STATUS_ERROR;\r
   }\r
 \r
   for (;index < len - 1; ++index) {\r
-    if (!isdigit(SplitValueString[index])) {\r
+    if (!isdigit((int)SplitValueString[index])) {\r
       return EFI_ABORTED;\r
     }\r
   }\r
@@ -172,20 +176,25 @@ CreateDir (
 {\r
   CHAR8* temp = *FullFileName;\r
   CHAR8* start = temp;\r
+  CHAR8  tempchar;\r
   UINT64 index = 0;\r
 \r
   for (;index < strlen(temp); ++index) {\r
     if (temp[index] == '\\' || temp[index] == '/') {\r
-      temp[index] = 0;\r
-      if (chdir(start)) {\r
-        if (mkdir(start, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {\r
-          return EFI_ABORTED;\r
+      if (temp[index + 1] != '\0') {\r
+        tempchar = temp[index + 1];\r
+        temp[index + 1] = 0;\r
+        if (chdir(start)) {\r
+          if (mkdir(start, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {\r
+            return EFI_ABORTED;\r
+          }\r
+          chdir(start);\r
         }\r
-        chdir(start);\r
+        start = temp + index + 1;\r
+        temp[index] = '/';\r
+        temp[index + 1] = tempchar;\r
+      }\r
     }\r
-      start = temp + index + 1;\r
-      temp[index] = '/';\r
-  }\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -219,7 +228,7 @@ Returns:
   CHAR8         *OutputDir = NULL;\r
   CHAR8         *OutFileName1 = NULL;\r
   CHAR8         *OutFileName2 = NULL;\r
-  UINT64        SplitValue = -1;\r
+  UINT64        SplitValue = (UINT64) -1;\r
   FILE          *Out1;\r
   FILE          *Out2;\r
   CHAR8         *OutName1 = NULL;\r
@@ -227,7 +236,6 @@ Returns:
   CHAR8         *CurrentDir = NULL;\r
   UINT64        Index;\r
   CHAR8         CharC;\r
-  BOOLEAN       QuietFlag = TRUE;\r
   UINT64        DebugLevel = 0;\r
   UINT64        VerboseLevel = 0;\r
 \r
@@ -305,7 +313,6 @@ Returns:
     }\r
 \r
     if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {\r
-      QuietFlag = TRUE;\r
       argc --;\r
       argv ++;\r
       continue;\r
@@ -348,7 +355,7 @@ Returns:
     return STATUS_ERROR;\r
   }\r
 \r
-  In = fopen (InputFileName, "rb");\r
+  In = fopen (LongFilePath (InputFileName), "rb");\r
   if (In == NULL) {\r
     // ("Unable to open file \"%s\"\n", InputFileName);\r
     Error (InputFileName, 0, 1, "File open failure", NULL);\r
@@ -400,14 +407,14 @@ Returns:
   chdir(CurrentDir);\r
   free(CurrentDir);\r
 \r
-  Out1 = fopen (OutFileName1, "wb");\r
+  Out1 = fopen (LongFilePath (OutFileName1), "wb");\r
   if (Out1 == NULL) {\r
     // ("Unable to open file \"%s\"\n", OutFileName1);\r
     Error (OutFileName1, 0, 1, "File open failure", NULL);\r
     return STATUS_ERROR;\r
   }\r
 \r
-  Out2 = fopen (OutFileName2, "wb");\r
+  Out2 = fopen (LongFilePath (OutFileName2), "wb");\r
   if (Out2 == NULL) {\r
     // ("Unable to open file \"%s\"\n", OutFileName2);\r
     Error (OutFileName2, 0, 1, "File open failure", NULL);\r