]> Creatis software - gdcm.git/blobdiff - src/gdcmUtil.cxx
BUG: was leading zeroes in numeric components. This is illegal, according to PS 3...
[gdcm.git] / src / gdcmUtil.cxx
index cbaa71b6de46ff00220bba5c3cf7cd53727c3022..3ec5687345cb007d7827a7751323b84a3ef7e485 100644 (file)
@@ -3,8 +3,8 @@
   Program:   gdcm
   Module:    $RCSfile: gdcmUtil.cxx,v $
   Language:  C++
-  Date:      $Date: 2005/01/21 20:02:46 $
-  Version:   $Revision: 1.116 $
+  Date:      $Date: 2005/01/22 01:40:41 $
+  Version:   $Revision: 1.118 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -367,8 +367,6 @@ bool Util::DicomStringEqual(const std::string &s1, const char *s2)
   return s1_even == s2_even;
 }
 
-
-
 /**
  * \brief   tells us if the processor we are working with is BigEndian or not
  */
@@ -678,15 +676,25 @@ std::string Util::GetMACAddress()
    // 3 OS: Win32, SunOS and 'real' POSIX
    // http://groups-beta.google.com/group/comp.unix.solaris/msg/ad36929d783d63be
    // http://bdn.borland.com/article/0,1410,26040,00.html
-   union dual { uint64_t n; unsigned char addr[6];  };
+   unsigned char addr[6];
+   uint64_t n = 0;
  
-   // zero-initialize the whole thing first:
-   dual d = { 0 };
-   int stat = GetMacAddrSys(d.addr);
+   int stat = GetMacAddrSys(addr);
    if (stat == 0)
    {
-      // fill with zero to fit on 15 bytes.
-      return Format("%015llu", d.n);
+      // Horner evaluation
+      for(int i=0; i<6; i++)
+      {
+         n *= 256;
+         n += addr[i];
+      }
+
+      // we fit on 15 bytes maximum < 256^6.
+#if defined(_MSC_VER) || defined(__BORLANDC__)
+      return Format("%I64u", n);
+#else
+      return Format("%llu", n);
+#endif
    }
    else
    {