From 40647ce7e91580f305eb008e3a2d253238ecd93d Mon Sep 17 00:00:00 2001
From: Geoffroy Couprie <geo.couprie@gmail.com>
Date: Thu, 4 Sep 2008 14:17:18 +0200
Subject: [PATCH] WinCE: various sys directories and env fixes

---
 modules/access_filter/dump.c      |   11 ++++++++++-
 modules/access_filter/timeshift.c |    4 ++++
 src/config/dirs.c                 |    6 ++++++
 src/config/file.c                 |    5 +++++
 src/extras/libc.c                 |    8 ++++++--
 src/libvlc.c                      |    2 ++
 6 files changed, 33 insertions(+), 3 deletions(-)

diff --git a/modules/access_filter/dump.c b/modules/access_filter/dump.c
index 50ccf9a..57ca580 100644
--- a/modules/access_filter/dump.c
+++ b/modules/access_filter/dump.c
@@ -114,7 +114,12 @@ static int Open (vlc_object_t *obj)
         return VLC_ENOMEM;
     memset (p_sys, 0, sizeof (*p_sys));
 
+# ifndef UNDER_CE
     if ((p_sys->stream = tmpfile ()) == NULL)
+# else
+    char buf[75];
+    if(GetTempFileName("\\Temp\\","vlc",0,buf) || ((p_sys->stream = fopen(buf,"wb+")) ==NULL))
+#endif
     {
         msg_Err (access, "cannot create temporary file: %m");
         free (p_sys);
@@ -285,8 +290,12 @@ static void Trigger (access_t *access)
 
     /* This might cause excessive hard drive work :( */
     FILE *oldstream = p_sys->stream;
+#ifdef UNDER_CE
+    fseek(oldstream, 0L, SEEK_SET);
+    clearerr(oldstream);
+#else
     rewind (oldstream);
-
+#endif
     for (;;)
     {
         char buf[16384];
diff --git a/modules/access_filter/timeshift.c b/modules/access_filter/timeshift.c
index 02fae43..78c15c3 100644
--- a/modules/access_filter/timeshift.c
+++ b/modules/access_filter/timeshift.c
@@ -587,9 +587,13 @@ static char *GetTmpFilePath( access_t *p_access )
 
         if (GetTempPathW (ret + 1, wdir) == 0)
         {
+# ifndef UNDER_CE
             pwdir_free = pwdir = _wgetcwd (NULL, 0);
             if (pwdir == NULL)
                 pwdir = L"C:";
+# else
+            pwdir = L"\\";
+# endif
         }
 
         psz_dir = FromWide (pwdir);
diff --git a/src/config/dirs.c b/src/config/dirs.c
index abeb537..0912539 100644
--- a/src/config/dirs.c
+++ b/src/config/dirs.c
@@ -31,6 +31,10 @@
 # define _WIN32_IE IE5
 # include <w32api.h>
 # include <direct.h>
+#if defined( UNDER_CE)
+# include "vlc_fixups.h"
+# include <shellapi.h>
+#endif
 # include <shlobj.h>
 #else
 # include <unistd.h>
@@ -83,6 +87,8 @@ static const char *GetDir( bool b_appdata, bool b_common_appdata )
     wchar_t wdir[MAX_PATH];
 
 # if defined (UNDER_CE)
+/* Ugly, but with the actual cegcc, I don't have SHGetSpecialFolderPathW*/
+#define SHGetSpecialFolderPathW SHGetSpecialFolderPath
     if( SHGetSpecialFolderPath( NULL, wdir, CSIDL_APPDATA, 1 ) )
 # else
     /* Get the "Application Data" folder for the current user */
diff --git a/src/config/file.c b/src/config/file.c
index 4952fcb..decec37 100644
--- a/src/config/file.c
+++ b/src/config/file.c
@@ -179,7 +179,12 @@ int __config_LoadConfigFile( vlc_object_t *p_this, const char *psz_module_name )
      || memcmp (bom, "\xEF\xBB\xBF", 3))
     {
         convert = FromLocaleDup;
+#if defined( UNDER_CE )
+        fseek(file, 0L, SEEK_SET);
+        clearerr(file);
+#elif
         rewind (file); /* no BOM, rewind */
+#endif
     }
 
     module_t *module = NULL;
diff --git a/src/extras/libc.c b/src/extras/libc.c
index f20b8a3..e628c81 100644
--- a/src/extras/libc.c
+++ b/src/extras/libc.c
@@ -234,7 +234,7 @@ char *vlc_strsep( char **ppsz_string, const char *psz_delimiters )
  * vlc_*dir_wrapper: wrapper under Windows to return the list of drive letters
  * when called with an empty argument or just '\'
  *****************************************************************************/
-#if defined(WIN32) && !defined(UNDER_CE)
+#if defined(WIN32)
 #   include <assert.h>
 
 typedef struct vlc_DIR
@@ -258,7 +258,11 @@ void *vlc_wopendir( const wchar_t *wpath )
         if( !p_dir )
             return NULL;
         p_dir->p_real_dir = NULL;
+# if defined(UNDER_CE)
+        p_dir->i_drives = "\\";
+# elif
         p_dir->i_drives = GetLogicalDrives();
+# endif
         return (void *)p_dir;
     }
 
@@ -330,7 +334,7 @@ void vlc_rewinddir( void *_p_dir )
 /* This one is in the libvlccore exported symbol list */
 int vlc_wclosedir( void *_p_dir )
 {
-#if defined(WIN32) && !defined(UNDER_CE)
+#if defined(WIN32)
     vlc_DIR *p_dir = (vlc_DIR *)_p_dir;
     int i_ret = 0;
 
diff --git a/src/libvlc.c b/src/libvlc.c
index f7e0af8..3fe9d88 100644
--- a/src/libvlc.c
+++ b/src/libvlc.c
@@ -2038,9 +2038,11 @@ static int ConsoleWidth( void )
 #else
     CONSOLE_SCREEN_BUFFER_INFO buf;
 
+#ifndef UNDER_CE
     if (GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &buf))
         i_width = buf.dwSize.X;
 #endif
+#endif
 
     return i_width;
 }
-- 
1.5.4.3

