Skip to content

Commit

Permalink
2002-03-27 Dan Lewis <dihlewis@yahoo.co.uk>
Browse files Browse the repository at this point in the history
	* Makefile.am: wrapper no longer built

io-layer/

	* unicode.h, unicode.c: changed to gunichar2
	* io.h, io.c: changed strings to gunichar2*, added
	SetFileAttributes(), GetCurrentDirectory(), SetCurrentDirectory(),
	some fixes to FindFirstFile() and friends.

metadata/

	* icall.c: removed last of PAL calls, added System.Environment
	* file-io.h, file-io.c: MonoIO implementation
	* object.h, object.c: mono_string_to_utf16() now returns gunichar2*

svn path=/trunk/mono/; revision=3377
  • Loading branch information
Dan Lewis committed Mar 27, 2002
1 parent 8ef0756 commit 3b0014f
Show file tree
Hide file tree
Showing 12 changed files with 781 additions and 266 deletions.
4 changes: 2 additions & 2 deletions mono/Makefile.am
@@ -1,9 +1,9 @@
# Currently the jit needs some work before it will build on windows
if PLATFORM_WIN32
SUBDIRS = utils io-layer monoburg metadata cil dis \
arch monograph interpreter wrapper tests
arch monograph interpreter tests
else
SUBDIRS = utils io-layer monoburg metadata cil dis \
arch monograph interpreter jit wrapper tests
arch monograph interpreter jit tests
endif

7 changes: 7 additions & 0 deletions mono/io-layer/ChangeLog
@@ -1,3 +1,10 @@
2002-03-27 Dan Lewis <dihlewis@yahoo.co.uk>

* unicode.h, unicode.c: changed to gunichar2
* io.h, io.c: changed strings to gunichar2*, added
SetFileAttributes(), GetCurrentDirectory(), SetCurrentDirectory(),
some fixes to FindFirstFile() and friends.

2002-03-26 Dick Porter <dick@ximian.com>

* types.h: Implement the large integer struct
Expand Down
151 changes: 127 additions & 24 deletions mono/io-layer/io.c
Expand Up @@ -25,7 +25,7 @@ struct _WapiHandle_file
{
WapiHandle handle;
int fd;
guchar *filename;
gchar *filename;
WapiSecurityAttributes *security_attributes;
guint32 fileaccess;
guint32 sharemode;
Expand Down Expand Up @@ -838,7 +838,7 @@ static mode_t convert_perms(guint32 sharemode)
*
* Return value: the new handle, or %INVALID_HANDLE_VALUE on error.
*/
WapiHandle *CreateFile(const guchar *name, guint32 fileaccess,
WapiHandle *CreateFile(const gunichar2 *name, guint32 fileaccess,
guint32 sharemode, WapiSecurityAttributes *security,
guint32 createmode, guint32 attrs,
WapiHandle *template G_GNUC_UNUSED)
Expand All @@ -847,7 +847,7 @@ WapiHandle *CreateFile(const guchar *name, guint32 fileaccess,
WapiHandle *handle;
int flags=convert_flags(fileaccess, createmode);
mode_t perms=convert_perms(sharemode);
guchar *filename;
gchar *filename;
int ret;

if(name==NULL) {
Expand Down Expand Up @@ -923,9 +923,9 @@ WapiHandle *CreateFile(const guchar *name, guint32 fileaccess,
*
* Return value: %TRUE on success, %FALSE otherwise.
*/
gboolean DeleteFile(const guchar *name)
gboolean DeleteFile(const gunichar2 *name)
{
guchar *filename;
gchar *filename;
int ret;

if(name==NULL) {
Expand Down Expand Up @@ -974,9 +974,9 @@ gboolean DeleteFile(const guchar *name)
*
* Return value: %TRUE on success, %FALSE otherwise.
*/
gboolean MoveFile (const guchar *name, const guchar *dest_name)
gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name)
{
guchar *utf8_name, *utf8_dest_name;
gchar *utf8_name, *utf8_dest_name;
int result;

utf8_name = _wapi_unicode_to_utf8 (name);
Expand Down Expand Up @@ -1030,11 +1030,11 @@ gboolean MoveFile (const guchar *name, const guchar *dest_name)
*
* Return value: %TRUE on success, %FALSE otherwise.
*/
gboolean CopyFile (const guchar *name, const guchar *dest_name, gboolean fail_if_exists)
gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_exists)
{
WapiHandle *src, *dest;
guint32 attrs;
char buffer [2048];
char *buffer;
int remain, n;

attrs = GetFileAttributes (name);
Expand All @@ -1058,6 +1058,8 @@ gboolean CopyFile (const guchar *name, const guchar *dest_name, gboolean fail_if
return FALSE;
}

buffer = g_new (gchar, 2048);

for (;;) {
if (ReadFile (src, buffer,sizeof (buffer), &remain, NULL) == 0) {
_wapi_set_last_error_from_errno ();
Expand Down Expand Up @@ -1089,6 +1091,8 @@ gboolean CopyFile (const guchar *name, const guchar *dest_name, gboolean fail_if
}
}

g_free (buffer);

CloseHandle (dest);
CloseHandle (src);
return TRUE;
Expand Down Expand Up @@ -1597,10 +1601,10 @@ gboolean FileTimeToSystemTime(const WapiFileTime *file_time,
return(TRUE);
}

WapiHandle *FindFirstFile (const guchar *pattern, WapiFindData *find_data)
WapiHandle *FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data)
{
struct _WapiHandle_find *handle;
guchar *utf8_pattern = NULL;
gchar *utf8_pattern = NULL;
int result;

if (pattern == NULL) {
Expand Down Expand Up @@ -1660,10 +1664,14 @@ gboolean FindNextFile (WapiHandle *wapi_handle, WapiFindData *find_data)
{
struct _WapiHandle_find *handle;
struct stat buf;
const char *filename;
const gchar *filename;

gchar *basename;
gunichar2 *utf16_basename;
time_t ctime;
int i;

if (wapi_handle->type != WAPI_HANDLE_FIND) {
if (wapi_handle == INVALID_HANDLE_VALUE || wapi_handle->type != WAPI_HANDLE_FIND) {
SetLastError (ERROR_INVALID_HANDLE);
return FALSE;
}
Expand Down Expand Up @@ -1711,9 +1719,20 @@ gboolean FindNextFile (WapiHandle *wapi_handle, WapiFindData *find_data)
find_data->dwReserved0 = 0;
find_data->dwReserved1 = 0;

g_strlcpy (find_data->cFileName, filename, MAX_PATH);
g_strlcpy (find_data->cAlternateFileName, filename, 14);
basename = g_path_get_basename (filename);
utf16_basename = g_utf8_to_utf16 (basename, MAX_PATH, NULL, NULL, NULL);

i = 0;
while (utf16_basename [i] != 0) { /* copy basename */
find_data->cFileName [i] = utf16_basename [i];
++ i;
}

find_data->cFileName[i] = 0; /* null terminate */
find_data->cAlternateFileName [0] = 0; /* not used */

g_free (basename);
g_free (utf16_basename);
return TRUE;
}

Expand All @@ -1729,7 +1748,7 @@ gboolean FindClose (WapiHandle *wapi_handle)
{
struct _WapiHandle_find *handle;

if (wapi_handle->type != WAPI_HANDLE_FIND) {
if (wapi_handle == INVALID_HANDLE_VALUE || wapi_handle->type != WAPI_HANDLE_FIND) {
SetLastError (ERROR_INVALID_HANDLE);
return FALSE;
}
Expand All @@ -1751,9 +1770,9 @@ gboolean FindClose (WapiHandle *wapi_handle)
*
* Return value: %TRUE on success, %FALSE otherwise.
*/
gboolean CreateDirectory (const guchar *name, WapiSecurityAttributes *security)
gboolean CreateDirectory (const gunichar2 *name, WapiSecurityAttributes *security)
{
guchar *utf8_name;
gchar *utf8_name;
int result;

utf8_name = _wapi_unicode_to_utf8 (name);
Expand Down Expand Up @@ -1793,9 +1812,9 @@ gboolean CreateDirectory (const guchar *name, WapiSecurityAttributes *security)
*
* Return value: %TRUE on success, %FALSE otherwise.
*/
gboolean RemoveDirectory (const guchar *name)
gboolean RemoveDirectory (const gunichar2 *name)
{
guchar *utf8_name;
gchar *utf8_name;
int result;

utf8_name = _wapi_unicode_to_utf8 (name);
Expand Down Expand Up @@ -1825,9 +1844,9 @@ gboolean RemoveDirectory (const guchar *name)
*
* Return value: -1 on failure
*/
guint32 GetFileAttributes (const guchar *name)
guint32 GetFileAttributes (const gunichar2 *name)
{
guchar *utf8_name;
gchar *utf8_name;
struct stat buf;
int result;

Expand Down Expand Up @@ -1862,9 +1881,9 @@ guint32 GetFileAttributes (const guchar *name)
*
* Return value: %TRUE on success, %FALSE on failure
*/
gboolean GetFileAttributesEx (const guchar *name, WapiGetFileExInfoLevels level, gpointer info)
gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels level, gpointer info)
{
guchar *utf8_name;
gchar *utf8_name;
WapiFileAttributesData *data;

struct stat buf;
Expand Down Expand Up @@ -1923,3 +1942,87 @@ gboolean GetFileAttributesEx (const guchar *name, WapiGetFileExInfoLevels level,

return TRUE;
}

/**
* SetFileAttributes
* @name: name of file
* @attrs: attributes to set
*
* Changes the attributes on a named file.
*
* Return value: %TRUE on success, %FALSE on failure.
*/
extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs)
{
/* FIXME: think of something clever to do on unix */

SetLastError (ERROR_INVALID_FUNCTION);
return FALSE;
}

/**
* GetCurrentDirectory
* @length: size of the buffer
* @buffer: pointer to buffer that recieves path
*
* Retrieves the current directory for the current process.
*
* Return value: number of characters in buffer on success, zero on failure
*/
extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer)
{
gchar *path;
gunichar2 *utf16_path, *ptr;
glong count = 0;

path = g_get_current_dir ();
if (path == NULL)
return 0;

/* if buffer too small, return number of characters required.
* this is plain dumb.
*/

count = strlen (path) + 1;
if (count > length)
return count;

utf16_path = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
if (utf16_path == NULL)
return 0;

while (*ptr)
*buffer ++ = *ptr ++;

*buffer = 0;

g_free (utf16_path);
g_free (path);

return count;
}

/**
* SetCurrentDirectory
* @path: path to new directory
*
* Changes the directory path for the current process.
*
* Return value: %TRUE on success, %FALSE on failure.
*/
extern gboolean SetCurrentDirectory (const gunichar2 *path)
{
gchar *utf8_path;
gboolean result;

utf8_path = _wapi_unicode_to_utf8 (path);
if (chdir (utf8_path) != 0) {
_wapi_set_last_error_from_errno ();
result = FALSE;
}
else
result = TRUE;

g_free (utf8_path);
return result;
}
25 changes: 14 additions & 11 deletions mono/io-layer/io.h
Expand Up @@ -120,8 +120,8 @@ typedef struct
guint32 nFileSizeLow;
guint32 dwReserved0;
guint32 dwReserved1;
guchar cFileName [MAX_PATH];
guchar cAlternateFileName [14];
gunichar2 cFileName [MAX_PATH];
gunichar2 cAlternateFileName [14];
} WapiFindData;

typedef struct
Expand All @@ -137,12 +137,12 @@ typedef struct
#define INVALID_SET_FILE_POINTER ((guint32)-1)
#define INVALID_FILE_SIZE ((guint32)0xFFFFFFFF)

extern WapiHandle *CreateFile(const guchar *name, guint32 fileaccess,
extern WapiHandle *CreateFile(const gunichar2 *name, guint32 fileaccess,
guint32 sharemode,
WapiSecurityAttributes *security,
guint32 createmode,
guint32 attrs, WapiHandle *tmplate);
extern gboolean DeleteFile(const guchar *name);
extern gboolean DeleteFile(const gunichar2 *name);
extern WapiHandle *GetStdHandle(WapiStdHandle stdhandle);
extern gboolean ReadFile(WapiHandle *handle, gpointer buffer, guint32 numbytes,
guint32 *bytesread, WapiOverlapped *overlapped);
Expand All @@ -158,14 +158,17 @@ extern guint32 GetFileSize(WapiHandle *handle, guint32 *highsize);
extern gboolean GetFileTime(WapiHandle *handle, WapiFileTime *create_time, WapiFileTime *last_access, WapiFileTime *last_write);
extern gboolean SetFileTime(WapiHandle *handle, const WapiFileTime *create_time, const WapiFileTime *last_access, const WapiFileTime *last_write);
extern gboolean FileTimeToSystemTime(const WapiFileTime *file_time, WapiSystemTime *system_time);
extern WapiHandle *FindFirstFile (const guchar *pattern, WapiFindData *find_data);
extern WapiHandle *FindFirstFile (const gunichar2 *pattern, WapiFindData *find_data);
extern gboolean FindNextFile (WapiHandle *handle, WapiFindData *find_data);
extern gboolean FindClose (WapiHandle *handle);
extern gboolean CreateDirectory (const guchar *name, WapiSecurityAttributes *security);
extern gboolean RemoveDirectory (const guchar *name);
extern gboolean MoveFile (const guchar *name, const guchar *dest_name);
extern gboolean CopyFile (const guchar *name, const guchar *dest_name, gboolean fail_if_exists);
extern guint32 GetFileAttributes (const guchar *name);
extern gboolean GetFileAttributesEx (const guchar *name, WapiGetFileExInfoLevels level, gpointer info);
extern gboolean CreateDirectory (const gunichar2 *name, WapiSecurityAttributes *security);
extern gboolean RemoveDirectory (const gunichar2 *name);
extern gboolean MoveFile (const gunichar2 *name, const gunichar2 *dest_name);
extern gboolean CopyFile (const gunichar2 *name, const gunichar2 *dest_name, gboolean fail_if_exists);
extern guint32 GetFileAttributes (const gunichar2 *name);
extern gboolean GetFileAttributesEx (const gunichar2 *name, WapiGetFileExInfoLevels level, gpointer info);
extern gboolean SetFileAttributes (const gunichar2 *name, guint32 attrs);
extern guint32 GetCurrentDirectory (guint32 length, gunichar2 *buffer);
extern gboolean SetCurrentDirectory (const gunichar2 *path);

#endif /* _WAPI_IO_H_ */
6 changes: 3 additions & 3 deletions mono/io-layer/unicode.c
Expand Up @@ -8,7 +8,7 @@
#include "unicode.h"

/* This is a nasty kludge */
static guint32 unicode_len(const guchar *str)
static guint32 unicode_len(const gunichar2 *str)
{
guint32 len=0;

Expand All @@ -21,15 +21,15 @@ static guint32 unicode_len(const guchar *str)
} while(1);
}

guchar *_wapi_unicode_to_utf8(const guchar *uni)
gchar *_wapi_unicode_to_utf8(const gunichar2 *uni)
{
GError *error = NULL;
gchar *res;
int len;

len = unicode_len(uni);

res = g_utf16_to_utf8 ((gunichar2 *)uni, len, NULL, NULL, &error);
res = g_utf16_to_utf8 (uni, len, NULL, NULL, &error);

g_assert (!error);

Expand Down
2 changes: 1 addition & 1 deletion mono/io-layer/unicode.h
Expand Up @@ -5,6 +5,6 @@

#include <glib.h>

extern guchar *_wapi_unicode_to_utf8(const guchar *uni);
extern gchar *_wapi_unicode_to_utf8 (const gunichar2 *uni);

#endif /* _WAPI_UNICODE_H_ */
5 changes: 5 additions & 0 deletions mono/metadata/ChangeLog
@@ -1,3 +1,8 @@
2002-03-27 Dan Lewis <dihlewis@yahoo.co.uk>

* icall.c: removed last of PAL calls, added System.Environment
* file-io.h, file-io.c: MonoIO implementation
* object.h, object.c: mono_string_to_utf16() now returns gunichar2*

Tue Mar 26 19:56:10 CET 2002 Paolo Molaro <lupus@ximian.com>

Expand Down

0 comments on commit 3b0014f

Please sign in to comment.