]> git.proxmox.com Git - mirror_edk2.git/commitdiff
StdLib: Simple code cleanup
authorDaryl McDaniel <daryl.mcdaniel@intel.com>
Thu, 17 Jul 2014 20:54:49 +0000 (20:54 +0000)
committerdarylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 17 Jul 2014 20:54:49 +0000 (20:54 +0000)
StdLib/LibC/Main/Main.c
  Change Print to Debug statements.
  Ensure errno is initialized to 0 before calling main().

StdLib/LibC/StdLib/Malloc.c
  Aesthetic Cleanup: remove unnecessary cast, fix two whitespace alignment problems.

StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c
  Change Include order.

StdLib/Include/paths.h
  Add definition _PATH_LIB for the path to the library directory: /Efi/StdLib/lib.

StdLib/LibC/Stdio/vfwscanf.c
  Align declarations and initializations.
  Initialize the multipurpose pointer, p, to NULL.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Daryl McDaniel <daryl.mcdaniel@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15664 6f19259b-4bc3-4df7-8a09-765794883524

StdLib/Include/paths.h
StdLib/LibC/Main/Main.c
StdLib/LibC/StdLib/Malloc.c
StdLib/LibC/Stdio/vfwscanf.c
StdLib/LibC/Uefi/InteractiveIO/NonCanonRead.c

index 7c968241cbb87fcad19f3f87cbdd6a62c1ff97e6..560bd033aff7d11e27b785747ca862c6789e1494 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-    Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+    Copyright (c) 2012 - 2014, Intel Corporation. All rights reserved.<BR>\r
     This program and the accompanying materials\r
     are licensed and made available under the terms and conditions of the BSD License\r
     which accompanies this distribution.  The full text of the license may be found at\r
@@ -50,6 +50,7 @@
 #define _PATH_STDLIB      "/Efi/StdLib/"\r
 #define _PATH_ETC         _PATH_STDLIB "etc/"\r
 #define _PATH_TMP         _PATH_STDLIB "tmp/"\r
+#define _PATH_LIB         _PATH_STDLIB "lib/"\r
 #define _PATH_BIN         "/Efi/Tools/"\r
 \r
 /* DOS style device paths */\r
index 0c84c160e0b8afbf0f4a9df18a23a04c3a69d702..b203d1520e2b3393cc34167efb0e78c424f4fefd 100644 (file)
@@ -4,7 +4,7 @@
   All of the global data in the gMD structure is initialized to 0, NULL, or\r
   SIG_DFL; as appropriate.\r
 \r
-  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
@@ -81,9 +81,9 @@ ArgvConvert(UINTN Argc, CHAR16 **Argv)
   INTN    nArgvSize;  /* Cumulative size of narrow Argv[i] */\r
 \r
 DEBUG_CODE_BEGIN();\r
-  Print(L"ArgvConvert called with %d arguments.\n", Argc);\r
+  DEBUG((DEBUG_INIT, "ArgvConvert called with %d arguments.\n", Argc));\r
   for(count = 0; count < ((Argc > 5)? 5: Argc); ++count) {\r
-    Print(L"Argument[%d] = \"%s\".\n", count, Argv[count]);\r
+    DEBUG((DEBUG_INIT, "Argument[%d] = \"%s\".\n", count, Argv[count]));\r
   }\r
 DEBUG_CODE_END();\r
 \r
@@ -92,7 +92,7 @@ DEBUG_CODE_END();
   for(count = 0; count < Argc; ++count) {\r
     AVsz = (ssize_t)wcstombs(NULL, Argv[count], ARG_MAX);\r
     if(AVsz < 0) {\r
-      Print(L"ABORTING: Argv[%d] contains an unconvertable character.\n", count);\r
+      DEBUG((DEBUG_ERROR, "ABORTING: Argv[%d] contains an unconvertable character.\n", count));\r
       exit(EXIT_FAILURE);\r
       /* Not Reached */\r
     }\r
@@ -102,7 +102,7 @@ DEBUG_CODE_END();
   /* Reserve space for the converted strings. */\r
   gMD->NCmdLine = (char *)AllocateZeroPool(nArgvSize+1);\r
   if(gMD->NCmdLine == NULL) {\r
-    Print(L"ABORTING: Insufficient memory.\n");\r
+    DEBUG((DEBUG_ERROR, "ABORTING: Insufficient memory.\n"));\r
     exit(EXIT_FAILURE);\r
     /* Not Reached */\r
   }\r
@@ -117,7 +117,7 @@ DEBUG_CODE_END();
     string += AVsz;\r
     nArgvSize -= AVsz;\r
     if(nArgvSize < 0) {\r
-      Print(L"ABORTING: Internal Argv[%d] conversion error.\n", count);\r
+      DEBUG((DEBUG_ERROR, "ABORTING: Internal Argv[%d] conversion error.\n", count));\r
       exit(EXIT_FAILURE);\r
       /* Not Reached */\r
     }\r
@@ -158,6 +158,7 @@ ShellAppMain (
       mfd[i].MyFD = (UINT16)i;\r
     }\r
 \r
+    DEBUG((DEBUG_INIT, "StdLib: Open Standard IO.\n"));\r
     i = open("stdin:", (O_RDONLY | O_TTY_INIT), 0444);\r
     if(i == 0) {\r
       i = open("stdout:", (O_WRONLY | O_TTY_INIT), 0222);\r
@@ -177,6 +178,7 @@ ShellAppMain (
     }\r
     else {\r
       if( setjmp(gMD->MainExit) == 0) {\r
+        errno   = 0;    // Clean up any "scratch" values from startup.\r
         ExitVal = (INTN)main( (int)Argc, gMD->NArgV);\r
         exitCleanup(ExitVal);\r
       }\r
index 44d89eef5dca0e44616ed5c530cba409f665965b..7d9718b266df4ac27083f654776c4479fb5160b3 100644 (file)
@@ -98,7 +98,7 @@ malloc(size_t Size)
 \r
   DEBUG((DEBUG_POOL, "malloc(%d): NodeSz: %d", Size, NodeSize));\r
 \r
-  Status = gBS->AllocatePool( EfiLoaderData, NodeSize, (void **)&Head);\r
+  Status = gBS->AllocatePool( EfiLoaderData, NodeSize, &Head);\r
   if( Status != EFI_SUCCESS) {\r
     RetVal  = NULL;\r
     errno   = ENOMEM;\r
@@ -183,7 +183,7 @@ free(void *Ptr)
       errno = EFAULT;\r
       DEBUG((DEBUG_ERROR, "ERROR free(0x%p): Signature is 0x%8X, expected 0x%8X\n",\r
              Ptr, Head->Signature, CPOOL_HEAD_SIGNATURE));\r
-  }\r
+    }\r
   }\r
   DEBUG((DEBUG_POOL, "free Done\n"));\r
 }\r
@@ -272,8 +272,8 @@ realloc(void *Ptr, size_t ReqSize)
     }\r
   }\r
   else {\r
-      free( Ptr);                           // Reclaim the old region.\r
-    }\r
+    free( Ptr);                           // Reclaim the old region.\r
+  }\r
   DEBUG((DEBUG_POOL, "0x%p = realloc(%p, %d): Head: %p NewSz: %d\n",\r
          RetVal, Ptr, ReqSize, Head, NewSize));\r
 \r
index 7bf3f666903c4d223bf74c6c24ecbfa088ca7e50..ae149c3602f2e4eb0daf1db14c513a5fe5a9bd97 100644 (file)
@@ -1,5 +1,7 @@
-/*-\r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+/** @file\r
+  valist worker function for the wide-character fscanf.\r
+\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials are licensed and made available under\r
   the terms and conditions of the BSD License that accompanies this distribution.\r
   The full text of the license may be found at\r
  * The following are used in integral conversions only:\r
  * SIGNOK, NDIGITS, PFXOK, and NZDIGITS\r
  */\r
-#define SIGNOK    0x40  /* +/- is (still) legal */\r
-#define NDIGITS   0x80  /* no digits detected */\r
-#define PFXOK   0x100 /* 0x prefix is (still) legal */\r
-#define NZDIGITS  0x200 /* no zero digits detected */\r
+#define SIGNOK    0x40    /* +/- is (still) legal */\r
+#define NDIGITS   0x80    /* no digits detected */\r
+#define PFXOK     0x100   /* 0x prefix is (still) legal */\r
+#define NZDIGITS  0x200   /* no zero digits detected */\r
 #define HAVESIGN  0x10000 /* sign detected */\r
 \r
 /*\r
@@ -138,38 +140,40 @@ vfwscanf(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)
 int\r
 __vfwscanf_unlocked(FILE * __restrict fp, const wchar_t * __restrict fmt, va_list ap)\r
 {\r
-  wint_t c;   /* character from format, or conversion */\r
-  size_t width;   /* field width, or 0 */\r
-  wchar_t *p;   /* points into all kinds of strings */\r
-  int n;      /* handy integer */\r
-  int flags;    /* flags as defined above */\r
-  wchar_t *p0;    /* saves original value of p when necessary */\r
-  int nassigned;    /* number of fields assigned */\r
-  int nconversions; /* number of conversions */\r
-  int nread;    /* number of characters consumed from fp */\r
-  int base;   /* base argument to conversion function */\r
-  wchar_t buf[BUF]; /* buffer for numeric conversions */\r
-  const wchar_t *ccls;  /* character class start */\r
-  const wchar_t *ccle;  /* character class end */\r
-  int cclcompl;   /* ccl is complemented? */\r
-  wint_t wi;    /* handy wint_t */\r
-  char *mbp;    /* multibyte string pointer for %c %s %[ */\r
-  size_t nconv;   /* number of bytes in mb. conversion */\r
-  char mbbuf[MB_LEN_MAX]; /* temporary mb. character buffer */\r
-  static const mbstate_t initial = { 0 };\r
-  mbstate_t mbs;\r
-\r
+  wint_t                  c;                            /* character from format, or conversion */\r
+  size_t                  width;                        /* field width, or 0 */\r
+  wchar_t                *p                   = NULL;   /* points into all kinds of strings */\r
+  int                     n;                            /* handy integer */\r
+  int                     flags;                        /* flags as defined above */\r
+  wchar_t                *p0;                           /* saves original value of p when necessary */\r
+  int                     nassigned;                    /* number of fields assigned */\r
+  int                     nconversions;                 /* number of conversions */\r
+  int                     nread;                        /* number of characters consumed from fp */\r
+  int                     base;                         /* base argument to conversion function */\r
+  wchar_t                 buf[BUF];                     /* buffer for numeric conversions */\r
+  const wchar_t          *ccls;                         /* character class start */\r
+  const wchar_t          *ccle;                         /* character class end */\r
+  int                     cclcompl;                     /* ccl is complemented? */\r
+  wint_t                  wi;                           /* handy wint_t */\r
+  char                   *mbp;                          /* multibyte string pointer for %c %s %[ */\r
+  size_t                  nconv;                        /* number of bytes in mb. conversion */\r
+  char                    mbbuf[MB_LEN_MAX];            /* temporary mb. character buffer */\r
+  mbstate_t               mbs;\r
+\r
+  static const mbstate_t  initial             = { 0 };\r
   /* `basefix' is used to avoid `if' tests in the integer scanner */\r
-  static short basefix[17] =\r
+  static short            basefix[17] =\r
     { 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };\r
 \r
-  nassigned = 0;\r
-  nconversions = 0;\r
-  nread = 0;\r
-  ccls = ccle = NULL;\r
-  base = 0;\r
-  cclcompl = 0;\r
-  mbp = NULL;\r
+  nassigned     = 0;\r
+  nconversions  = 0;\r
+  nread         = 0;\r
+  ccls          = NULL;\r
+  ccle          = NULL;\r
+  base          = 0;\r
+  cclcompl      = 0;\r
+  mbp           = NULL;\r
+\r
   for (;;) {\r
     c = *fmt++;\r
     if (c == 0)\r
index 15bf43e2601bab85eed219f208486a4d27dd9c88..bcae9c82399e657a364d002b8374678a7ce7474c 100644 (file)
@@ -4,7 +4,7 @@
   The functions assume that isatty() is TRUE at the time they are called.\r
   If _S_IWTTY is set, the device returns WIDE characters.\r
 \r
-  Copyright (c) 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2012 - 2014, 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
@@ -17,8 +17,8 @@
 \r
 #include  <sys/syslimits.h>\r
 #include  <sys/termios.h>\r
-#include  <Device/IIO.h>\r
 #include  <Containers/Fifo.h>\r
+#include  <Device/IIO.h>\r
 \r
 /** Perform a noncanonical read of input.\r
 \r