summaryrefslogtreecommitdiff
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
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
-rw-r--r--navit/bookmarks.c18
-rw-r--r--navit/file.c60
-rw-r--r--navit/main.c9
3 files changed, 78 insertions, 9 deletions
diff --git a/navit/bookmarks.c b/navit/bookmarks.c
index 07fff8d89..ae4fcf1ad 100644
--- a/navit/bookmarks.c
+++ b/navit/bookmarks.c
@@ -19,7 +19,10 @@
#include <glib.h>
#include <stdlib.h>
+#include "config.h"
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include "file.h"
#include "debug.h"
#include "projection.h"
@@ -32,6 +35,19 @@
#include "navit.h"
#include "navit_nls.h"
+/* FIXME: Move this to support directory */
+#ifdef _MSC_VER
+#include <windows.h>
+static int ftruncate(int fd, __int64 length)
+{
+ HANDLE fh = (HANDLE)_get_osfhandle(fd);
+ if (!fh || _lseeki64(fd, length, SEEK_SET)) {
+ return -1;
+ }
+ return SetEndOfFile(fh) ? 0 : -1;
+}
+#endif /* _MSC_VER */
+
struct bookmarks {
//data storage
struct map *bookmark;
@@ -648,7 +664,7 @@ bookmarks_append_coord(struct bookmarks *this_, char *file, struct pcoord *c, in
const char *prostr;
if (limit != 0 && (f=fopen(file, "r"))) {
- int offsets[limit];
+ int *offsets=g_alloca(sizeof(int)*limit);
int offset_pos=0;
int offset;
char buffer[4096];
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;
diff --git a/navit/main.c b/navit/main.c
index 5fbf19191..6ecda5c90 100644
--- a/navit/main.c
+++ b/navit/main.c
@@ -20,19 +20,22 @@
#include <locale.h>
#include <stdlib.h>
#include <stdio.h>
-#include <getopt.h>
#include <string.h>
#include <signal.h>
#include <glib.h>
#include <sys/types.h>
+#include "config.h"
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
#ifndef _WIN32
#include <sys/wait.h>
#include <signal.h>
#endif
-#include <unistd.h>
-#include "config.h"
#include "file.h"
#include "debug.h"
#include "main.h"