summaryrefslogtreecommitdiff
path: root/navit/file.c
diff options
context:
space:
mode:
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2011-01-25 14:57:21 +0000
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>2011-01-25 14:57:21 +0000
commitca3b703f7c0954121e9012f8b279b6e45a58b200 (patch)
tree9ffb6b6629b9df03e452cafcd880e644b9273404 /navit/file.c
parentfa090208e4ad4851445315dc5adf2241e23a6908 (diff)
downloadnavit-ca3b703f7c0954121e9012f8b279b6e45a58b200.tar.gz
Fix:Core:MSVC fixes|Thanks chollya
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit@4017 ffa7fe5e-494d-0410-b361-a75ebd5db220
Diffstat (limited to 'navit/file.c')
-rw-r--r--navit/file.c60
1 files changed, 55 insertions, 5 deletions
diff --git a/navit/file.c b/navit/file.c
index e6da9d5bd..8def9ebf5 100644
--- a/navit/file.c
+++ b/navit/file.c
@@ -20,12 +20,18 @@
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE_SOURCE
#define _LARGEFILE64_SOURCE
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
+#ifdef _MSC_VER
+#include <dirent.h>
+#else
+#include <windows.h>
+#endif /* _MSC_VER */
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
-#include <dirent.h>
#include <stdio.h>
#include <stdlib.h>
#include <wordexp.h>
@@ -72,12 +78,20 @@ static GHashTable *file_name_hash;
static struct cache *file_cache;
+#ifdef _MSC_VER
+#pragma pack(push,1)
+#endif /* _MSC_VER */
struct file_cache_id {
long long offset;
int size;
int file_name_id;
int method;
-} __attribute__ ((packed));
+#ifndef _MSC_VER
+}__attribute__ ((packed));
+#else /* _MSC_VER */
+};
+#pragma pack(pop)
+#endif /* _MSC_VER */
#ifdef HAVE_SOCKET
static int
@@ -265,14 +279,14 @@ file_size(struct file *file)
int file_mkdir(char *name, int pflag)
{
- char buffer[strlen(name)+1];
+ char *buffer=g_alloca(sizeof(char)*(strlen(name)+1));
int ret;
char *next;
dbg(1,"enter %s %d\n",name,pflag);
if (!pflag) {
if (file_is_dir(name))
return 0;
-#ifdef HAVE_API_WIN32_BASE
+#if defined HAVE_API_WIN32_BASE || defined _MSC_VER
return mkdir(name);
#else
return mkdir(name, 0777);
@@ -656,12 +670,27 @@ file_unmap(struct file *f)
#endif
}
+#ifndef _MSC_VER
void *
file_opendir(char *dir)
{
return opendir(dir);
}
+#else
+void *
+file_opendir(char *dir)
+{
+ WIN32_FIND_DATAA FindFileData;
+ HANDLE hFind = INVALID_HANDLE_VALUE;
+#undef UNICODE // we need FindFirstFileA() which takes an 8-bit c-string
+ char* fname=g_alloca(sizeof(char)*(strlen(dir)+4));
+ sprintf(fname,"%s\\*",dir);
+ hFind = FindFirstFileA(fname, &FindFileData);
+ return hFind;
+}
+#endif
+#ifndef _MSC_VER
char *
file_readdir(void *hnd)
{
@@ -672,17 +701,38 @@ file_readdir(void *hnd)
return NULL;
return ent->d_name;
}
+#else
+char *
+file_readdir(void *hnd)
+{
+ WIN32_FIND_DATA FindFileData;
+
+ if (FindNextFile(hnd, &FindFileData) ) {
+ return FindFileData.cFileName;
+ } else {
+ return NULL;
+ }
+}
+#endif /* _MSC_VER */
+#ifndef _MSC_VER
void
file_closedir(void *hnd)
{
closedir(hnd);
}
+#else
+void
+file_closedir(void *hnd)
+{
+ FindClose(hnd);
+}
+#endif /* _MSC_VER */
struct file *
file_create_caseinsensitive(char *name, struct attr **options)
{
- char dirname[strlen(name)+1];
+ char *dirname=g_alloca(sizeof(char)*(strlen(name)+1));
char *filename;
char *p;
void *d;