Commit 64ba6cf2 authored by Richard Levitte's avatar Richard Levitte
Browse files

From LPlib:

Windows changes that detects if multibyte characters are available and
deals with them properly.

Contributed by Andy Polyakov <appro@fy.chalmers.se>
parent 210a4f78
Loading
Loading
Loading
Loading
+44 −22
Original line number Diff line number Diff line
/* $LP: LPlib/source/LPdir_win.c,v 1.3 2004/07/19 16:34:54 _cvs_levitte Exp $ */
/* $LP: LPlib/source/LPdir_win.c,v 1.4 2004/07/20 21:15:55 _cvs_levitte Exp $ */
/*
 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
 * All rights reserved.
@@ -25,6 +25,7 @@
 * SUCH DAMAGE.
 */
#include <windows.h>
#include <tchar.h>
#ifndef LPDIR_H
#include "LPdir.h"
#endif
@@ -57,12 +58,12 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
	}
      memset(*ctx, '\0', sizeof(LP_DIR_CTX));

#ifdef LP_SYS_WINCE
      if (sizeof(TCHAR) != sizeof(char))
	{
	WCHAR *wdir = NULL;
	size_t index = 0;
	  TCHAR *wdir = NULL;
	  size_t index = 0,len=strlen(direcory);

	wdir = (WCHAR *)malloc((strlen(directory) + 1) * 2);
	  wdir = (TCHAR *)malloc((len + 1) * sizeof(TCHAR));
	  if (wdir == NULL)
	    {
	      errno = ENOMEM;
@@ -70,16 +71,18 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
	      return 0;
	    }

#ifdef LP_MULTIBYTE_AVAILABLE
	  if (!MultiByteToWideChar (CP_THREAD_ACP,0,directory,len,wdir,len+1))
#endif
	    for (index = 0; index < strlen(directory) + 1; index++)
	  wdir[index] = (short)directory[index];
	      wdir[index] = (TCHAR)directory[index];

	  (*ctx)->handle = FindFirstFile(wdir, &(*ctx)->ctx);

	  free(wdir);
	}
#else
      else
	(*ctx)->handle = FindFirstFile(directory, &(*ctx)->ctx);
#endif

      if ((*ctx)->handle == INVALID_HANDLE_VALUE)
	{
@@ -97,8 +100,27 @@ const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
	}
    }

  if (sizeof(TCHAR) != sizeof(char))
    {
      TCHAR *wdir=(*ctx)->ctx.cFileName;
      size_t i,len;

      for (len=0;wdir[len] && len<(sizeof((*ctx)->entry_name)-1);)
	len++;

#ifdef LP_MULTIBYTE_AVAILABLE
      if (!WideCharToMultiByte (CP_THREAD_ACP,0,wdir,len,
				(*ctx)->entry_name,
				sizeof((*ctx)->entry_name)-1,NULL,0))
#endif
	for (i=0;i<len;i++) (*ctx)->entry_name[i] = (char)wdir[i];
    }
  else
    strncpy((*ctx)->entry_name, (*ctx)->ctx.cFileName,
	  sizeof((*ctx)->entry_name));
	    sizeof((*ctx)->entry_name)-1);

  (*ctx)->entry_name[sizeof((*ctx)->entry_name)-1] = '\0';

  return (*ctx)->entry_name;
}

+2 −1
Original line number Diff line number Diff line
/* $LP: LPlib/source/LPdir_win32.c,v 1.1 2004/06/14 10:07:56 _cvs_levitte Exp $ */
/* $LP: LPlib/source/LPdir_win32.c,v 1.2 2004/07/20 21:15:55 _cvs_levitte Exp $ */
/*
 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
 * All rights reserved.
@@ -26,4 +26,5 @@
 */

#define LP_SYS_WIN32
#define LP_MULTIBYTE_AVAILABLE
#include "LPdir_win.c"
+3 −1
Original line number Diff line number Diff line
/* $LP: LPlib/source/LPdir_wince.c,v 1.1 2004/06/14 10:07:56 _cvs_levitte Exp $ */
/* $LP: LPlib/source/LPdir_wince.c,v 1.2 2004/07/20 21:15:55 _cvs_levitte Exp $ */
/*
 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
 * All rights reserved.
@@ -26,4 +26,6 @@
 */

#define LP_SYS_WINCE
/* We might want to define LP_MULTIBYTE_AVAILABLE here.  It's currently
   under investigation what the exact conditions would be */
#include "LPdir_win.c"