static void file_close (gpointer handle, gpointer data)
{
struct _WapiHandle_file *file_handle = (struct _WapiHandle_file *)data;
+ int fd = file_handle->fd;
DEBUG("%s: closing file handle %p [%s]", __func__, handle,
file_handle->filename);
if (file_handle->share_info)
_wapi_handle_share_release (file_handle->share_info);
- close (GPOINTER_TO_UINT(handle));
+ close (fd);
}
static WapiFileType file_getfiletype(void)
{
struct _WapiHandle_file *file_handle;
gboolean ok;
- int fd = GPOINTER_TO_UINT(handle);
- int ret;
+ int fd, ret;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
return(FALSE);
}
+ fd = file_handle->fd;
if(bytesread!=NULL) {
*bytesread=0;
}
{
struct _WapiHandle_file *file_handle;
gboolean ok;
- int ret;
+ int ret, fd;
off_t current_pos = 0;
- int fd = GPOINTER_TO_UINT(handle);
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+
+ fd = file_handle->fd;
if(byteswritten!=NULL) {
*byteswritten=0;
{
struct _WapiHandle_file *file_handle;
gboolean ok;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int ret, fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
return(FALSE);
}
+ fd = file_handle->fd;
+
if(!(file_handle->fileaccess & GENERIC_WRITE) &&
!(file_handle->fileaccess & GENERIC_ALL)) {
DEBUG("%s: handle %p doesn't have GENERIC_WRITE access: %u", __func__, handle, file_handle->fileaccess);
struct _WapiHandle_file *file_handle;
gboolean ok;
off_t offset, newpos;
- int whence;
+ int whence, fd;
guint32 ret;
- int fd = GPOINTER_TO_UINT(handle);
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
return(INVALID_SET_FILE_POINTER);
}
+ fd = file_handle->fd;
+
if(!(file_handle->fileaccess & GENERIC_READ) &&
!(file_handle->fileaccess & GENERIC_WRITE) &&
!(file_handle->fileaccess & GENERIC_ALL)) {
gboolean ok;
struct stat statbuf;
off_t size, pos;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int ret, fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = file_handle->fd;
if(!(file_handle->fileaccess & GENERIC_WRITE) &&
!(file_handle->fileaccess & GENERIC_ALL)) {
}
#endif
+/* Native Client has no ftruncate function, even in standalone sel_ldr. */
+#ifndef __native_client__
/* always truncate, because the extend write() adds an extra
* byte to the end of the file
*/
_wapi_set_last_error_from_errno ();
return(FALSE);
}
+#endif
return(TRUE);
}
struct stat statbuf;
guint32 size;
int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(INVALID_FILE_SIZE);
}
+ fd = file_handle->fd;
if(!(file_handle->fileaccess & GENERIC_READ) &&
!(file_handle->fileaccess & GENERIC_WRITE) &&
gboolean ok;
struct stat statbuf;
guint64 create_ticks, access_ticks, write_ticks;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int ret, fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = file_handle->fd;
if(!(file_handle->fileaccess & GENERIC_READ) &&
!(file_handle->fileaccess & GENERIC_ALL)) {
struct utimbuf utbuf;
struct stat statbuf;
guint64 access_ticks, write_ticks;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int ret, fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_FILE,
(gpointer *)&file_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = file_handle->fd;
if(!(file_handle->fileaccess & GENERIC_WRITE) &&
!(file_handle->fileaccess & GENERIC_ALL)) {
static void console_close (gpointer handle, gpointer data)
{
struct _WapiHandle_file *console_handle = (struct _WapiHandle_file *)data;
+ int fd = console_handle->fd;
DEBUG("%s: closing console handle %p", __func__, handle);
g_free (console_handle->filename);
- close (GPOINTER_TO_UINT(handle));
+ close (fd);
}
static WapiFileType console_getfiletype(void)
{
struct _WapiHandle_file *console_handle;
gboolean ok;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
-
+ int ret, fd;
+
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_CONSOLE,
(gpointer *)&console_handle);
if(ok==FALSE) {
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = console_handle->fd;
if(bytesread!=NULL) {
*bytesread=0;
{
struct _WapiHandle_file *console_handle;
gboolean ok;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int ret, fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_CONSOLE,
(gpointer *)&console_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = console_handle->fd;
if(byteswritten!=NULL) {
*byteswritten=0;
return(TRUE);
}
-static void pipe_close (gpointer handle, gpointer data G_GNUC_UNUSED)
+static void pipe_close (gpointer handle, gpointer data)
{
+ struct _WapiHandle_file *pipe_handle = (struct _WapiHandle_file*)data;
+ int fd = pipe_handle->fd;
+
DEBUG("%s: closing pipe handle %p", __func__, handle);
/* No filename with pipe handles */
- close(GPOINTER_TO_UINT(handle));
+ close (fd);
}
static WapiFileType pipe_getfiletype(void)
{
struct _WapiHandle_file *pipe_handle;
gboolean ok;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
-
+ int ret, fd;
+
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_PIPE,
(gpointer *)&pipe_handle);
if(ok==FALSE) {
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = pipe_handle->fd;
if(bytesread!=NULL) {
*bytesread=0;
{
struct _WapiHandle_file *pipe_handle;
gboolean ok;
- int ret;
- int fd = GPOINTER_TO_UINT(handle);
+ int ret, fd;
ok=_wapi_lookup_handle (handle, WAPI_HANDLE_PIPE,
(gpointer *)&pipe_handle);
SetLastError (ERROR_INVALID_HANDLE);
return(FALSE);
}
+ fd = pipe_handle->fd;
if(byteswritten!=NULL) {
*byteswritten=0;
return(INVALID_HANDLE_VALUE);
}
+#ifdef __native_client__
+ /* Workaround: Native Client currently returns the same fake inode
+ * for all files, so do a simple hash on the filename so we don't
+ * use the same share info for each file.
+ */
+ statbuf.st_ino = g_str_hash(filename);
+#endif
if (share_check (&statbuf, sharemode, fileaccess,
&file_handle.share_info, fd) == FALSE) {
//security, sizeof(WapiSecurityAttributes));
}
+ file_handle.fd = fd;
file_handle.fileaccess=fileaccess;
file_handle.sharemode=sharemode;
file_handle.attrs=attrs;
gchar *utf8_src, *utf8_dest;
int src_fd, dest_fd;
struct stat st, dest_st;
+ struct utimbuf dest_time;
gboolean ret = TRUE;
+ int ret_utime;
if(name==NULL) {
DEBUG("%s: name is NULL", __func__);
if (!write_file (src_fd, dest_fd, &st, TRUE))
ret = FALSE;
- g_free (utf8_src);
- g_free (utf8_dest);
close (src_fd);
close (dest_fd);
+
+ dest_time.modtime = st.st_mtime;
+ dest_time.actime = st.st_atime;
+ ret_utime = utime (utf8_dest, &dest_time);
+ if (ret_utime == -1)
+ DEBUG ("%s: file [%s] utime failed: %s", __func__, utf8_dest, strerror(errno));
+
+ g_free (utf8_src);
+ g_free (utf8_dest);
return ret;
}
goto retry;
}
+#ifndef __native_client__
result = _wapi_lstat (filename, &linkbuf);
if (result != 0) {
DEBUG ("%s: lstat failed: %s", __func__, filename);
g_free (filename);
goto retry;
}
+#endif
utf8_filename = mono_utf8_from_external (filename);
if (utf8_filename == NULL) {
else
create_time = buf.st_ctime;
+#ifdef __native_client__
+ find_data->dwFileAttributes = _wapi_stat_to_file_attributes (utf8_filename, &buf, NULL);
+#else
find_data->dwFileAttributes = _wapi_stat_to_file_attributes (utf8_filename, &buf, &linkbuf);
+#endif
_wapi_time_t_to_filetime (create_time, &find_data->ftCreationTime);
_wapi_time_t_to_filetime (buf.st_atime, &find_data->ftLastAccessTime);
return (INVALID_FILE_ATTRIBUTES);
}
+#ifndef __native_client__
result = _wapi_lstat (utf8_name, &linkbuf);
if (result != 0) {
_wapi_set_last_path_error_from_errno (NULL, utf8_name);
g_free (utf8_name);
return (INVALID_FILE_ATTRIBUTES);
}
+#endif
+#ifdef __native_client__
+ ret = _wapi_stat_to_file_attributes (utf8_name, &buf, NULL);
+#else
ret = _wapi_stat_to_file_attributes (utf8_name, &buf, &linkbuf);
+#endif
g_free (utf8_name);
glong count;
gsize bytes;
+#ifdef __native_client__
+ gchar *path = g_get_current_dir ();
+ if (length < strlen(path) + 1 || path == NULL)
+ return 0;
+ memcpy (buffer, path, strlen(path) + 1);
+#else
if (getcwd ((char*)buffer, length) == NULL) {
if (errno == ERANGE) { /*buffer length is not big enough */
gchar *path = g_get_current_dir (); /*FIXME g_get_current_dir doesn't work with broken paths and calling it just to know the path length is silly*/
_wapi_set_last_error_from_errno ();
return 0;
}
+#endif
utf16_path = mono_unicode_from_external ((gchar*)buffer, &bytes);
count = (bytes/2)+1;
/* filedes[0] is open for reading, filedes[1] for writing */
+ pipe_read_handle.fd = filedes [0];
pipe_read_handle.fileaccess = GENERIC_READ;
read_handle = _wapi_handle_new_fd (WAPI_HANDLE_PIPE, filedes[0],
&pipe_read_handle);
return(FALSE);
}
+ pipe_write_handle.fd = filedes [1];
pipe_write_handle.fileaccess = GENERIC_WRITE;
write_handle = _wapi_handle_new_fd (WAPI_HANDLE_PIPE, filedes[1],
&pipe_write_handle);
if (strcmp (*(splitted + 1), utf8_root_path_name) == 0 ||
(strcmp (*(splitted + 1), "/") == 0 && strlen (utf8_root_path_name) == 0)) {
drive_type = _wapi_get_drive_type (*(splitted + 2));
- g_strfreev (splitted);
- break;
+ /* it is possible this path might be mounted again with
+ a known type...keep looking */
+ if (drive_type != DRIVE_UNKNOWN) {
+ g_strfreev (splitted);
+ break;
+ }
}
g_strfreev (splitted);
return (drive_type);
}
-static const gchar*
+static gchar*
get_fstypename (gchar *utfpath)
{
#if defined (PLATFORM_MACOSX) || defined (__linux__)
if (statfs (utfpath, &stat) == -1)
return NULL;
#if PLATFORM_MACOSX
- return stat.f_fstypename;
+ return g_strdup (stat.f_fstypename);
#else
current = &_wapi_drive_types[0];
while (current->drive_type != DRIVE_UNKNOWN) {
if (stat.f_type == current->fstypeid)
- return current->fstype;
+ return g_strdup (current->fstype);
current++;
}
return NULL;
GetVolumeInformation (const gunichar2 *path, gunichar2 *volumename, int volumesize, int *outserial, int *maxcomp, int *fsflags, gunichar2 *fsbuffer, int fsbuffersize)
{
gchar *utfpath;
- const gchar *fstypename;
+ gchar *fstypename;
gboolean status = FALSE;
glong len;
}
if (ret != NULL)
g_free (ret);
+ g_free (fstypename);
}
g_free (utfpath);
return status;