port ecore_file to Windows

SVN revision: 31662
This commit is contained in:
doursse 2007-09-09 10:26:37 +00:00 committed by doursse
parent e45ff14147
commit a22ebcafac
3 changed files with 102 additions and 12 deletions

View File

@ -86,15 +86,18 @@ AC_CHECK_HEADERS(netinet/in.h)
winsock_libs="" winsock_libs=""
create_shared_lib="" create_shared_lib=""
ecore_file_win32_lib=""
case "$host_os" in case "$host_os" in
mingw|mingw32) mingw|mingw32)
winsock_libs="-lwsock32" winsock_libs="-lwsock32"
create_shared_lib="-no-undefined" create_shared_lib="-no-undefined"
ecore_file_win32_lib="-lole32 -luuid"
;; ;;
esac esac
AC_SUBST(winsock_libs) AC_SUBST(winsock_libs)
AC_SUBST(create_shared_lib) AC_SUBST(create_shared_lib)
AC_SUBST(ecore_file_win32_lib)
iconv_cflags="" iconv_cflags=""
iconv_libs="" iconv_libs=""

View File

@ -5,7 +5,7 @@ INCLUDES = \
-I$(top_builddir)/src/lib/ecore \ -I$(top_builddir)/src/lib/ecore \
@CURL_CFLAGS@ @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 -L$(top_builddir)/src/lib/ecore/.libs
if BUILD_ECORE_FILE if BUILD_ECORE_FILE
@ -25,7 +25,7 @@ ecore_file_download.c
libecore_file_la_LIBADD = \ libecore_file_la_LIBADD = \
$(top_builddir)/src/lib/ecore/libecore.la \ $(top_builddir)/src/lib/ecore/libecore.la \
@fam_libs@ @CURL_LIBS@ @fam_libs@ @CURL_LIBS@ @ecore_file_win32_lib@
endif endif

View File

@ -3,19 +3,78 @@
*/ */
#ifndef _FILE_OFFSET_BITS #ifndef _FILE_OFFSET_BITS
#define _FILE_OFFSET_BITS 64 # define _FILE_OFFSET_BITS 64
#endif #endif
#ifdef __linux__ #ifdef __linux__
#include <features.h> # include <features.h>
#endif #endif
#include <ctype.h> #include <ctype.h>
#include "ecore_file_private.h" #include "ecore_file_private.h"
#include <errno.h> #include <errno.h>
#ifdef _WIN32
# include <windows.h>
# include <shlobj.h>
# include <objidl.h>
#endif /* _WIN32 */
static int init = 0; 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 */ /* externally accessible functions */
/** /**
* Initialize Ecore_File and the services it will use. Call this function * Initialize Ecore_File and the services it will use. Call this function
@ -64,7 +123,7 @@ ecore_file_shutdown()
/** /**
* Get the time of the last modification to the give file * Get the time of the last modification to the give file
* @param file The name of the 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 * occur it will return 0
*/ */
EAPI long long EAPI long long
@ -120,7 +179,9 @@ ecore_file_is_dir(const char *file)
return 0; return 0;
} }
#ifndef _WIN32
static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH; 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 * Create a new directory
* @param dir The name of the directory to create * @param dir The name of the directory to create
@ -131,7 +192,11 @@ static mode_t default_mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S
EAPI int EAPI int
ecore_file_mkdir(const char *dir) ecore_file_mkdir(const char *dir)
{ {
#ifndef _WIN32
if (mkdir(dir, default_mode) < 0) return 0; if (mkdir(dir, default_mode) < 0) return 0;
#else
if (mkdir(dir) < 0) return 0;
#endif /* _WIN32 */
return 1; return 1;
} }
@ -163,7 +228,7 @@ ecore_file_unlink(const char *file)
* Delete a directory and all its contents * Delete a directory and all its contents
* @param dir The name of the directory to delete * @param dir The name of the directory to delete
* @return 1 on success, 0 on failure * @return 1 on success, 0 on failure
* *
* If dir is a link only the link is removed * If dir is a link only the link is removed
*/ */
EAPI int EAPI int
@ -171,14 +236,21 @@ ecore_file_recursive_rm(const char *dir)
{ {
DIR *dirp; DIR *dirp;
struct dirent *dp; 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; struct stat st;
int ret; int ret;
/* On Windows, no link */
#ifndef _WIN32
if (readlink(dir, buf, sizeof(buf)) > 0) if (readlink(dir, buf, sizeof(buf)) > 0)
{ {
return ecore_file_unlink(dir); return ecore_file_unlink(dir);
} }
#endif /* _WIN32 */
ret = stat(dir, &st); ret = stat(dir, &st);
if ((ret == 0) && (S_ISDIR(st.st_mode))) if ((ret == 0) && (S_ISDIR(st.st_mode)))
{ {
@ -258,8 +330,13 @@ ecore_file_cp(const char *src, const char *dst)
size_t num; size_t num;
int ret = 1; int ret = 1;
#ifndef _WIN32
if (!realpath(src, realpath1)) return 0; if (!realpath(src, realpath1)) return 0;
if (realpath(dst, realpath2) && !strcmp(realpath1, realpath2)) 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"); f1 = fopen(src, "rb");
if (!f1) return 0; if (!f1) return 0;
@ -293,7 +370,7 @@ ecore_file_mv(const char *src, const char *dst)
if (errno == EXDEV) if (errno == EXDEV)
{ {
struct stat st; struct stat st;
stat(src, &st); stat(src, &st);
if (S_ISREG(st.st_mode)) if (S_ISREG(st.st_mode))
{ {
@ -318,6 +395,7 @@ EAPI int
ecore_file_symlink(const char *src, const char *dest) ecore_file_symlink(const char *src, const char *dest)
{ {
if (!symlink(src, dest)) return 1; if (!symlink(src, dest)) return 1;
return 0; return 0;
} }
@ -332,7 +410,12 @@ ecore_file_realpath(const char *file)
{ {
char buf[PATH_MAX]; char buf[PATH_MAX];
#ifndef _WIN32
if (!realpath(file, buf)) return strdup(""); if (!realpath(file, buf)) return strdup("");
#else
if (!_fullpath(buf, file, _MAX_PATH)) return strdup("");
#endif /* _WIN32 */
return strdup(buf); return strdup(buf);
} }
@ -423,22 +506,26 @@ ecore_file_can_exec(const char *file)
EAPI char * EAPI char *
ecore_file_readlink(const char *link) ecore_file_readlink(const char *link)
{ {
#ifndef _WIN32
char buf[PATH_MAX]; char buf[PATH_MAX];
int count; int count;
if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL; if ((count = readlink(link, buf, sizeof(buf))) < 0) return NULL;
buf[count] = 0; buf[count] = 0;
return strdup(buf); 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 * 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(). * want to set the current locale for the category LC_COLLATE with setlocale().
* For more information see the manual pages of strcoll and setlocale. * For more information see the manual pages of strcoll and setlocale.
* The list will not contain the directory entries for '.' and '..'. * The list will not contain the directory entries for '.' and '..'.
* @param dir The name of the directory to list * @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. * on failure it returns NULL.
*/ */
EAPI Ecore_List * EAPI Ecore_List *
@ -464,7 +551,7 @@ ecore_file_ls(const char *dir)
} }
} }
closedir(dirp); closedir(dirp);
ecore_list_sort(list, ECORE_COMPARE_CB(strcoll), ECORE_SORT_MIN); ecore_list_sort(list, ECORE_COMPARE_CB(strcoll), ECORE_SORT_MIN);
ecore_list_first_goto(list); ecore_list_first_goto(list);
@ -631,7 +718,7 @@ ecore_file_escape_name(const char *filename)
const char *p; const char *p;
char *q; char *q;
char buf[PATH_MAX]; char buf[PATH_MAX];
p = filename; p = filename;
q = buf; q = buf;
while (*p) while (*p)