Enlightenment CVS committal

Author  : doursse
Project : e17
Module  : libs/embryo

Dir     : e17/libs/embryo/src/bin


Modified Files:
        embryo_cc_prefix.c embryo_cc_sc1.c 


Log Message:
update win32 port : use fulpath instead of a function, use correct temp dir 
value and correct open function according to the compiler

===================================================================
RCS file: /cvs/e/e17/libs/embryo/src/bin/embryo_cc_prefix.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -3 -r1.5 -r1.6
--- embryo_cc_prefix.c  10 Feb 2007 17:23:05 -0000      1.5
+++ embryo_cc_prefix.c  25 Nov 2007 11:38:49 -0000      1.6
@@ -17,22 +17,24 @@
 #include <ctype.h>
 #include <time.h>
 #include <dirent.h>
-#ifdef WIN32
-#include <windows.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <errno.h>
+#ifdef _WIN32
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
+# undef WIN32_LEAN_AND_MEAN
+# include <stdlib.h>
+# include <stdio.h>
+# include <errno.h>
 #else
-#include <dlfcn.h>     /* dlopen,dlclose,etc */
-#include <pwd.h>
-#include <grp.h>
-#include <glob.h>
-#endif /* WIN32 */
+# include <dlfcn.h>    /* dlopen,dlclose,etc */
+# include <pwd.h>
+# include <grp.h>
+# include <glob.h>
+#endif /* _WIN32 */
 
 #include "embryo_cc_prefix.h"
 
 /* FIXME: that hack is a temporary one. That code will be in MinGW soon */
-#ifdef WIN32
+#ifdef _WIN32
 
 #define RTLD_LAZY 1 /* lazy function call binding */
 #define RTLD_NOW 2 /* immediate function call binding */
@@ -98,130 +100,9 @@
   }
 }
 
-char *realpath(const char *path, char resolved_path[PATH_MAX])
-{
-  char *return_path = 0;
-
-  if (path) //Else EINVAL
-  {
-    if (resolved_path)
-    {
-      return_path = resolved_path;
-    }
-    else
-    {
-      //Non standard extension that glibc uses
-      return_path = malloc(PATH_MAX);
-    }
-
-    if (return_path) //Else EINVAL
-    {
-      //This is a Win32 API function similar to what realpath() is supposed to 
do
-      size_t size = GetFullPathNameA(path, PATH_MAX, return_path, 0);
-
-      //GetFullPathNameA() returns a size larger than buffer if buffer is too 
small
-      if (size > PATH_MAX)
-      {
-        if (return_path != resolved_path) //Malloc'd buffer - Unstandard 
extension retry
-        {
-          size_t new_size;
-
-          free(return_path);
-          return_path = malloc(size);
-
-          if (return_path)
-          {
-            new_size = GetFullPathNameA(path, size, return_path, 0); //Try 
again
-
-            if (new_size > size) //If it's still too large, we have a problem, 
don't try again
-            {
-              free(return_path);
-              return_path = 0;
-              errno = ENAMETOOLONG;
-            }
-            else
-            {
-              size = new_size;
-            }
-          }
-          else
-          {
-            //I wasn't sure what to return here, but the standard does say to 
return EINVAL
-            //if resolved_path is null, and in this case we couldn't malloc 
large enough buffer
-            errno = EINVAL;
-          }  
-        }
-        else //resolved_path buffer isn't big enough
-        {
-          return_path = 0;
-          errno = ENAMETOOLONG;
-        }
-      }
-
-      //GetFullPathNameA() returns 0 if some path resolve problem occured
-      if (!size) 
-      {
-        if (return_path != resolved_path) //Malloc'd buffer
-        {
-          free(return_path);
-        }
-
-        return_path = 0;
-
-        //Convert MS errors into standard errors
-        switch (GetLastError())
-        {
-          case ERROR_FILE_NOT_FOUND:
-            errno = ENOENT;
-            break;
-
-          case ERROR_PATH_NOT_FOUND: case ERROR_INVALID_DRIVE:
-            errno = ENOTDIR;
-            break;
-
-          case ERROR_ACCESS_DENIED:
-            errno = EACCES;
-            break;
-
-          default: //Unknown Error
-            errno = EIO;
-            break;
-        }
-      }
-
-      //If we get to here with a valid return_path, we're still doing good
-      if (return_path)
-      {
-        struct stat stat_buffer;
-
-        //Make sure path exists, stat() returns 0 on success
-        if (stat(return_path, &stat_buffer)) 
-        {
-          if (return_path != resolved_path)
-          {
-            free(return_path);
-          }
-
-          return_path = 0;
-          //stat() will set the correct errno for us
-        }
-        //else we succeeded!
-      }
-    }
-    else
-    {
-      errno = EINVAL;
-    }
-  }
-  else
-  {
-    errno = EINVAL;
-  }
-
-  return return_path;
-}
+#define realpath(file_name, resolved_name) _fullpath((resolved_name), 
(file_name), PATH_MAX)
 
-#endif /* WIN32 */
+#endif /* _WIN32 */
 
 /* local subsystem functions */
 static int _e_prefix_share_hunt(void);
===================================================================
RCS file: /cvs/e/e17/libs/embryo/src/bin/embryo_cc_sc1.c,v
retrieving revision 1.33
retrieving revision 1.34
diff -u -3 -r1.33 -r1.34
--- embryo_cc_sc1.c     10 Feb 2007 17:23:05 -0000      1.33
+++ embryo_cc_sc1.c     25 Nov 2007 11:38:49 -0000      1.34
@@ -21,7 +21,7 @@
  *  must not be misrepresented as being the original software.
  *  3.  This notice may not be removed or altered from any source
  *  distribution.  
- *  Version: $Id: embryo_cc_sc1.c,v 1.33 2007/02/10 17:23:05 raster Exp $
+ *  Version: $Id: embryo_cc_sc1.c,v 1.34 2007/11/25 11:38:49 doursse Exp $
  */
 
 #ifdef HAVE_CONFIG_H
@@ -36,11 +36,12 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#ifdef WIN32
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#endif /* WIN32 */
+#ifdef _WIN32
+# include <fcntl.h>
+# include <io.h>
+# include <share.h>
+# include <sys/stat.h>
+#endif /* _WIN32 */
 
 #include "embryo_cc_osdefs.h"
 #include "embryo_cc_sc.h"
@@ -291,7 +292,7 @@
    void               *inpfmark;
    char                lcl_ctrlchar;
    int                 lcl_packstr, lcl_needsemicolon, lcl_tabsize;
-   char *tmpdir;
+   char               *tmpdir;
 
    /* set global variables to their initial value */
    binf = NULL;
@@ -316,20 +317,31 @@
    setopt(argc, argv, inpfname, binfname, incfname, reportname);
 
    /* open the output file */
+
+#ifndef _WIN32
    tmpdir = getenv("TMPDIR");
    if (!tmpdir) tmpdir = "/tmp";
 
    snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
-#ifndef WIN32
    fd_out = mkstemp(outfname);
 #else
-   if (mktemp (outfname))
-     do
-       fd_out = open (outfname, O_CREAT | O_EXCL, S_IREAD | S_IWRITE);
-     while (!(fd_out == -1 && errno == EEXIST) && mktemp (outfname));
-   else
-     fd_out = -1;
-#endif /* WIN32 */
+   tmpdir = getenv("TMP");
+   if (!tmpdir) tmpdir = getenv("TEMP");
+   if (!tmpdir) tmpdir = getenv("USERPROFILE");
+   if (!tmpdir) tmpdir = getenv("WINDIR");
+   if (!tmpdir) error(101, "embryo_cc.asm-tmp-XXXXXX (unable to get a valid 
temp path)");
+
+   snprintf(outfname, _MAX_PATH, "%s/embryo_cc.asm-tmp-XXXXXX", tmpdir);
+# ifdef __MINGW32__
+   if (!mktemp(outfname))
+     error(101, outfname);
+   fd_out = _sopen(outfname, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, 
_S_IREAD | _S_IWRITE);
+# else
+   if (_mktemp_s(outfname, _MAX_PATH))
+     error(101, outfname);
+   _sopen_s(&fd_out, outfname, _O_RDWR | _O_BINARY | _O_CREAT, _SH_DENYNO, 
_S_IREAD | _S_IWRITE);
+# endif /* __MINGW32__ */
+#endif /* _WIN32 */
    if (fd_out < 0)
      error(101, outfname);
 



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
enlightenment-cvs mailing list
enlightenment-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs

Reply via email to