Enlightenment CVS committal

Author  : doursse
Project : e17
Module  : libs/ecore

Dir     : e17/libs/ecore/src/lib/ecore_file


Modified Files:
        Makefile.am ecore_file.c 


Log Message:
port ecore_file to Windows

===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_file/Makefile.am,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -3 -r1.9 -r1.10
--- Makefile.am 5 Sep 2005 08:40:50 -0000       1.9
+++ Makefile.am 9 Sep 2007 10:26:37 -0000       1.10
@@ -5,7 +5,7 @@
 -I$(top_builddir)/src/lib/ecore \
 @CURL_CFLAGS@
 
-libecore_file_la_LDFLAGS = -version-info 1:0:0 \
+libecore_file_la_LDFLAGS = @create_shared_lib@ -version-info 1:0:0 \
 -L$(top_builddir)/src/lib/ecore/.libs
 
 if BUILD_ECORE_FILE
@@ -25,7 +25,7 @@
 
 libecore_file_la_LIBADD = \
 $(top_builddir)/src/lib/ecore/libecore.la \
[EMAIL PROTECTED]@ @CURL_LIBS@
[EMAIL PROTECTED]@ @CURL_LIBS@ @ecore_file_win32_lib@
 
 endif
 
===================================================================
RCS file: /cvs/e/e17/libs/ecore/src/lib/ecore_file/ecore_file.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -3 -r1.68 -r1.69
--- ecore_file.c        10 Aug 2007 16:01:59 -0000      1.68
+++ ecore_file.c        9 Sep 2007 10:26:37 -0000       1.69
@@ -3,19 +3,78 @@
  */
 
 #ifndef _FILE_OFFSET_BITS
-#define _FILE_OFFSET_BITS  64
+# define _FILE_OFFSET_BITS  64
 #endif
 
 #ifdef __linux__
-#include <features.h>
+# include <features.h>
 #endif
 #include <ctype.h>
 #include "ecore_file_private.h"
 #include <errno.h>
 
+#ifdef _WIN32
+# include <windows.h>
+# include <shlobj.h>
+# include <objidl.h>
+#endif /* _WIN32 */
+
 
 static int init = 0;
 
+/* FIXME: Windows has no symbolic link. */
+/*        Nevertheless, it can creates .lnk files */
+#ifdef _WIN32
+static int
+symlink (const char *oldpath, const char *newpath)
+{
+   IShellLink    *pISL;
+   IShellLink   **shell_link;
+   IPersistFile  *pIPF;
+   IPersistFile **persit_file;
+   wchar_t        new_path[MB_CUR_MAX];
+
+   /* Hack to cleanly remove a warning */
+   shell_link = &pISL;
+   if (FAILED(CoInitialize(NULL)))
+     return -1;
+
+   if (FAILED(CoCreateInstance(&CLSID_ShellLink,
+                               NULL,
+                               CLSCTX_INPROC_SERVER,
+                               &IID_IShellLink,
+                               (void **)shell_link)))
+     goto no_instance;
+
+   if (FAILED(pISL->lpVtbl->SetPath(pISL, oldpath)))
+     goto no_setpath;
+
+   /* Hack to cleanly remove a warning */
+   persit_file = &pIPF;
+   if (FAILED(pISL->lpVtbl->QueryInterface(pISL, &IID_IPersistFile, (void 
**)persit_file)))
+     goto no_queryinterface;
+
+   mbstowcs(new_path, newpath, MB_CUR_MAX);
+   if (FAILED(pIPF->lpVtbl->Save(pIPF, new_path, FALSE)))
+     goto no_save;
+
+   pIPF->lpVtbl->Release(pIPF);
+   pISL->lpVtbl->Release(pISL);
+   CoUninitialize();
+
+   return 0;
+
+ no_save:
+   pIPF->lpVtbl->Release(pIPF);
+ no_queryinterface:
+ no_setpath:
+   pISL->lpVtbl->Release(pISL);
+ no_instance:
+   CoUninitialize();
+   return -1;
+}
+#endif /* _WIN32 */
+
 /* externally accessible functions */
 /**
  * Initialize Ecore_File and the services it will use. Call this function
@@ -64,7 +123,7 @@
 /**
  * Get the time of the last modification to the give file
  * @param file The name of the file
- * @return Return the time of the last data modification, if an error should 
+ * @return Return the time of the last data modification, if an error should
  *         occur it will return 0
  */
 EAPI long long
@@ -120,7 +179,9 @@
    return 0;
 }
 
+#ifndef _WIN32
 static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | 
S_IROTH | S_IXOTH;
+#endif /* _WIN32 */
 /**
  * Create a new directory
  * @param  dir The name of the directory to create
@@ -131,7 +192,11 @@
 EAPI int
 ecore_file_mkdir(const char *dir)
 {
+#ifndef _WIN32
    if (mkdir(dir, default_mode) < 0) return 0;
+#else
+   if (mkdir(dir) < 0) return 0;
+#endif /* _WIN32 */
    return 1;
 }
 
@@ -163,7 +228,7 @@
  * Delete a directory and all its contents
  * @param  dir The name of the directory to delete
  * @return 1 on success, 0 on failure
- * 
+ *
  * If dir is a link only the link is removed
  */
 EAPI int
@@ -171,14 +236,21 @@
 {
    DIR                *dirp;
    struct dirent      *dp;
-   char               path[PATH_MAX], buf[PATH_MAX];;
+   char               path[PATH_MAX];
+#ifndef _WIN32
+   char               buf[PATH_MAX];
+#endif /* _WIN32 */
    struct             stat st;
    int                ret;
 
+   /* On Windows, no link */
+#ifndef _WIN32
    if (readlink(dir, buf, sizeof(buf)) > 0)
      {
        return ecore_file_unlink(dir);
      }
+#endif /* _WIN32 */
+
    ret = stat(dir, &st);
    if ((ret == 0) && (S_ISDIR(st.st_mode)))
      {
@@ -258,8 +330,13 @@
    size_t              num;
    int                 ret = 1;
 
+#ifndef _WIN32
    if (!realpath(src, realpath1)) return 0;
    if (realpath(dst, realpath2) && !strcmp(realpath1, realpath2)) return 0;
+#else
+   if (!_fullpath(realpath1, src, _MAX_PATH)) return 0;
+   if (_fullpath(realpath2, dst, _MAX_PATH) && !strcmp(realpath1, realpath2)) 
return 0;
+#endif /* _WIN32 */
 
    f1 = fopen(src, "rb");
    if (!f1) return 0;
@@ -293,7 +370,7 @@
        if (errno == EXDEV)
          {
             struct stat st;
-            
+
             stat(src, &st);
             if (S_ISREG(st.st_mode))
               {
@@ -318,6 +395,7 @@
 ecore_file_symlink(const char *src, const char *dest)
 {
    if (!symlink(src, dest)) return 1;
+
    return 0;
 }
 
@@ -332,7 +410,12 @@
 {
    char  buf[PATH_MAX];
 
+#ifndef _WIN32
    if (!realpath(file, buf)) return strdup("");
+#else
+   if (!_fullpath(buf, file, _MAX_PATH)) return strdup("");
+#endif /* _WIN32 */
+
    return strdup(buf);
 }
 
@@ -423,22 +506,26 @@
 EAPI char *
 ecore_file_readlink(const char *link)
 {
+#ifndef _WIN32
    char                buf[PATH_MAX];
    int                 count;
 
    if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL;
    buf[count] = 0;
    return strdup(buf);
+#else
+   return NULL;
+#endif /* _WIN32 */
 }
 
 /**
- * Get the list of the files and directories in a given directory. The list 
+ * Get the list of the files and directories in a given directory. The list
  * will be sorted with strcoll as compare function. That means that you may
  * want to set the current locale for the category LC_COLLATE with setlocale().
  * For more information see the manual pages of strcoll and setlocale.
  * The list will not contain the directory entries for '.' and '..'.
  * @param  dir The name of the directory to list
- * @return Return an Ecore_List containing all the files in the directory; 
+ * @return Return an Ecore_List containing all the files in the directory;
  *         on failure it returns NULL.
  */
 EAPI Ecore_List *
@@ -464,7 +551,7 @@
          }
      }
    closedir(dirp);
-   
+
    ecore_list_sort(list, ECORE_COMPARE_CB(strcoll), ECORE_SORT_MIN);
 
    ecore_list_first_goto(list);
@@ -631,7 +718,7 @@
    const char *p;
    char *q;
    char buf[PATH_MAX];
-   
+
    p = filename;
    q = buf;
    while (*p)



-------------------------------------------------------------------------
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