Commit 643617f2 authored by Alexandre Julliard's avatar Alexandre Julliard

Moved most remaining file functions to dlls/kernel.

Removed files/file.c and include/file.h.
parent cba2fcaf
......@@ -19,7 +19,6 @@ SPEC_SRCS16 = \
C_SRCS = \
$(TOPOBJDIR)/files/directory.c \
$(TOPOBJDIR)/files/file.c \
$(TOPOBJDIR)/files/smb.c \
$(TOPOBJDIR)/misc/options.c \
$(TOPOBJDIR)/misc/registry.c \
......
......@@ -147,40 +147,30 @@ HFILE16 WINAPI OpenFile16( LPCSTR name, OFSTRUCT *ofs, UINT16 mode )
((mode & OF_REOPEN )==OF_REOPEN)?"OF_REOPEN ":""
);
ofs->cBytes = sizeof(OFSTRUCT);
ofs->nErrCode = 0;
if (mode & OF_REOPEN) name = ofs->szPathName;
if (!name) return HFILE_ERROR;
/* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
Are there any cases where getting the path here is wrong?
Uwe Bonnes 1997 Apr 2 */
if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error;
/* OF_PARSE simply fills the structure */
if (mode & OF_PARSE)
{
ofs->fFixedDisk = (GetDriveType16( ofs->szPathName[0]-'A' ) != DRIVE_REMOVABLE);
TRACE("(%s): OF_PARSE, res = '%s'\n", name, ofs->szPathName );
OpenFile( name, ofs, mode );
return 0;
}
/* OF_CREATE is completely different from all other options, so
handle it first */
if (mode & OF_CREATE)
{
DWORD access, sharing;
FILE_ConvertOFMode( mode, &access, &sharing );
if ((handle = CreateFileA( ofs->szPathName, GENERIC_READ | GENERIC_WRITE,
sharing, NULL, CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL, 0 ))== INVALID_HANDLE_VALUE)
goto error;
handle = (HANDLE)OpenFile( name, ofs, mode );
if (handle == (HANDLE)HFILE_ERROR) goto error;
}
else
{
ofs->cBytes = sizeof(OFSTRUCT);
ofs->nErrCode = 0;
if (mode & OF_REOPEN) name = ofs->szPathName;
if (!name) return HFILE_ERROR;
/* the watcom 10.6 IDE relies on a valid path returned in ofs->szPathName
Are there any cases where getting the path here is wrong?
Uwe Bonnes 1997 Apr 2 */
if (!GetFullPathNameA( name, sizeof(ofs->szPathName), ofs->szPathName, NULL )) goto error;
/* If OF_SEARCH is set, ignore the given path */
filename = name;
......
......@@ -36,7 +36,6 @@
#include "wine/winbase16.h"
#include "wine/library.h"
#include "file.h"
#include "miscemu.h"
#include "module.h"
#include "thread.h"
......
......@@ -49,13 +49,14 @@ extern HMODULE kernel32_handle;
/* Size of per-process table of DOS handles */
#define DOS_TABLE_SIZE 256
extern HANDLE dos_handles[DOS_TABLE_SIZE];
void FILE_ConvertOFMode( INT mode, DWORD *access, DWORD *sharing );
extern void PTHREAD_Init(void);
extern BOOL WOWTHUNK_Init(void);
extern VOID SYSLEVEL_CheckNotLevel( INT level );
extern void FILE_SetDosError(void);
extern DWORD INSTR_EmulateInstruction( EXCEPTION_RECORD *rec, CONTEXT86 *context );
extern void INSTR_CallBuiltinHandler( CONTEXT86 *context, BYTE intnum );
......@@ -69,6 +70,8 @@ extern void SELECTOR_FreeBlock( WORD sel );
#define IS_SELECTOR_32BIT(sel) \
(wine_ldt_is_system(sel) || (wine_ldt_copy.flags[LOWORD(sel) >> 3] & WINE_LDT_FLAGS_32BIT))
extern HANDLE VXD_Open( LPCWSTR filename, DWORD access, LPSECURITY_ATTRIBUTES sa );
/* this structure is always located at offset 0 of the DGROUP segment */
#include "pshpack1.h"
typedef struct
......
......@@ -2,7 +2,7 @@
* File handling functions
*
* Copyright 1993 Erik Bos
* Copyright 1996 Alexandre Julliard
* Copyright 1996, 2004 Alexandre Julliard
* Copyright 2003 Eric Pouech
*
* This library is free software; you can redistribute it and/or
......@@ -38,7 +38,6 @@
#include "winternl.h"
#include "kernel_private.h"
#include "file.h"
#include "wine/unicode.h"
#include "wine/debug.h"
......@@ -670,6 +669,91 @@ UINT WINAPI GetTempPathW( UINT count, LPWSTR path )
/***********************************************************************
* GetTempFileNameA (KERNEL32.@)
*/
UINT WINAPI GetTempFileNameA( LPCSTR path, LPCSTR prefix, UINT unique, LPSTR buffer)
{
UNICODE_STRING pathW, prefixW;
WCHAR bufferW[MAX_PATH];
UINT ret;
if ( !path || !prefix || !buffer )
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
RtlCreateUnicodeStringFromAsciiz(&pathW, path);
RtlCreateUnicodeStringFromAsciiz(&prefixW, prefix);
ret = GetTempFileNameW(pathW.Buffer, prefixW.Buffer, unique, bufferW);
if (ret)
WideCharToMultiByte(CP_ACP, 0, bufferW, -1, buffer, MAX_PATH, NULL, NULL);
RtlFreeUnicodeString(&pathW);
RtlFreeUnicodeString(&prefixW);
return ret;
}
/***********************************************************************
* GetTempFileNameW (KERNEL32.@)
*/
UINT WINAPI GetTempFileNameW( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer )
{
static const WCHAR formatW[] = {'%','x','.','t','m','p',0};
int i;
LPWSTR p;
if ( !path || !prefix || !buffer )
{
SetLastError( ERROR_INVALID_PARAMETER );
return 0;
}
strcpyW( buffer, path );
p = buffer + strlenW(buffer);
/* add a \, if there isn't one */
if ((p == buffer) || (p[-1] != '\\')) *p++ = '\\';
for (i = 3; (i > 0) && (*prefix); i--) *p++ = *prefix++;
unique &= 0xffff;
if (unique) sprintfW( p, formatW, unique );
else
{
/* get a "random" unique number and try to create the file */
HANDLE handle;
UINT num = GetTickCount() & 0xffff;
if (!num) num = 1;
unique = num;
do
{
sprintfW( p, formatW, unique );
handle = CreateFileW( buffer, GENERIC_WRITE, 0, NULL,
CREATE_NEW, FILE_ATTRIBUTE_NORMAL, 0 );
if (handle != INVALID_HANDLE_VALUE)
{ /* We created it */
TRACE("created %s\n", debugstr_w(buffer) );
CloseHandle( handle );
break;
}
if (GetLastError() != ERROR_FILE_EXISTS &&
GetLastError() != ERROR_SHARING_VIOLATION)
break; /* No need to go on */
if (!(++unique & 0xffff)) unique = 1;
} while (unique != num);
}
TRACE("returning %s\n", debugstr_w(buffer) );
return unique;
}
/***********************************************************************
* contains_pathW
*
* Check if the file name contains a path; helper for SearchPathW.
......@@ -823,6 +907,138 @@ DWORD WINAPI SearchPathA( LPCSTR path, LPCSTR name, LPCSTR ext,
/**************************************************************************
* CopyFileW (KERNEL32.@)
*/
BOOL WINAPI CopyFileW( LPCWSTR source, LPCWSTR dest, BOOL fail_if_exists )
{
HANDLE h1, h2;
BY_HANDLE_FILE_INFORMATION info;
DWORD count;
BOOL ret = FALSE;
char buffer[2048];
if (!source || !dest)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
TRACE("%s -> %s\n", debugstr_w(source), debugstr_w(dest));
if ((h1 = CreateFileW(source, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, 0)) == INVALID_HANDLE_VALUE)
{
WARN("Unable to open source %s\n", debugstr_w(source));
return FALSE;
}
if (!GetFileInformationByHandle( h1, &info ))
{
WARN("GetFileInformationByHandle returned error for %s\n", debugstr_w(source));
CloseHandle( h1 );
return FALSE;
}
if ((h2 = CreateFileW( dest, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
fail_if_exists ? CREATE_NEW : CREATE_ALWAYS,
info.dwFileAttributes, h1 )) == INVALID_HANDLE_VALUE)
{
WARN("Unable to open dest %s\n", debugstr_w(dest));
CloseHandle( h1 );
return FALSE;
}
while (ReadFile( h1, buffer, sizeof(buffer), &count, NULL ) && count)
{
char *p = buffer;
while (count != 0)
{
DWORD res;
if (!WriteFile( h2, p, count, &res, NULL ) || !res) goto done;
p += res;
count -= res;
}
}
ret = TRUE;
done:
CloseHandle( h1 );
CloseHandle( h2 );
return ret;
}
/**************************************************************************
* CopyFileA (KERNEL32.@)
*/
BOOL WINAPI CopyFileA( LPCSTR source, LPCSTR dest, BOOL fail_if_exists)
{
UNICODE_STRING sourceW, destW;
BOOL ret;
if (!source || !dest)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
RtlCreateUnicodeStringFromAsciiz(&sourceW, source);
RtlCreateUnicodeStringFromAsciiz(&destW, dest);
ret = CopyFileW(sourceW.Buffer, destW.Buffer, fail_if_exists);
RtlFreeUnicodeString(&sourceW);
RtlFreeUnicodeString(&destW);
return ret;
}
/**************************************************************************
* CopyFileExW (KERNEL32.@)
*
* This implementation ignores most of the extra parameters passed-in into
* the "ex" version of the method and calls the CopyFile method.
* It will have to be fixed eventually.
*/
BOOL WINAPI CopyFileExW(LPCWSTR sourceFilename, LPCWSTR destFilename,
LPPROGRESS_ROUTINE progressRoutine, LPVOID appData,
LPBOOL cancelFlagPointer, DWORD copyFlags)
{
/*
* Interpret the only flag that CopyFile can interpret.
*/
return CopyFileW(sourceFilename, destFilename, (copyFlags & COPY_FILE_FAIL_IF_EXISTS) != 0);
}
/**************************************************************************
* CopyFileExA (KERNEL32.@)
*/
BOOL WINAPI CopyFileExA(LPCSTR sourceFilename, LPCSTR destFilename,
LPPROGRESS_ROUTINE progressRoutine, LPVOID appData,
LPBOOL cancelFlagPointer, DWORD copyFlags)
{
UNICODE_STRING sourceW, destW;
BOOL ret;
if (!sourceFilename || !destFilename)
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
RtlCreateUnicodeStringFromAsciiz(&sourceW, sourceFilename);
RtlCreateUnicodeStringFromAsciiz(&destW, destFilename);
ret = CopyFileExW(sourceW.Buffer, destW.Buffer, progressRoutine, appData,
cancelFlagPointer, copyFlags);
RtlFreeUnicodeString(&sourceW);
RtlFreeUnicodeString(&destW);
return ret;
}
/**************************************************************************
* MoveFileExW (KERNEL32.@)
*/
BOOL WINAPI MoveFileExW( LPCWSTR source, LPCWSTR dest, DWORD flag )
......
......@@ -37,7 +37,6 @@
#include "wine/winuser16.h"
#include "ntstatus.h"
#include "thread.h"
#include "file.h"
#include "module.h"
#include "options.h"
#include "kernel_private.h"
......@@ -82,6 +81,7 @@ static const WCHAR comW[] = {'.','c','o','m',0};
static const WCHAR batW[] = {'.','b','a','t',0};
static const WCHAR winevdmW[] = {'w','i','n','e','v','d','m','.','e','x','e',0};
extern int DIR_Init(void);
extern void SHELL_LoadRegistry(void);
extern void VOLUME_CreateDevices(void);
extern void VERSION_Init( const WCHAR *appname );
......
......@@ -32,7 +32,6 @@
#include "winreg.h"
#include "winternl.h"
#include "wine/winbase16.h"
#include "file.h"
#include "wine/unicode.h"
#include "wine/server.h"
#include "wine/library.h"
......
......@@ -37,7 +37,6 @@
#include "winuser.h"
#include "wine/winbase16.h"
#include "file.h"
#include "module.h"
#include "winternl.h"
#include "wine/server.h"
......
......@@ -39,7 +39,6 @@
#include "ntddstor.h"
#include "ntddcdrm.h"
#include "kernel_private.h"
#include "file.h"
#include "wine/library.h"
#include "wine/unicode.h"
#include "wine/debug.h"
......
......@@ -36,7 +36,6 @@
#include "winbase.h"
#include "winreg.h"
#include "winerror.h"
#include "file.h"
#include "kernel_private.h"
#include "wine/library.h"
#include "wine/unicode.h"
......
......@@ -46,12 +46,13 @@
#include "winternl.h"
#include "thread.h"
#include "wine/unicode.h"
#include "file.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(dosfs);
WINE_DECLARE_DEBUG_CHANNEL(file);
#define MAX_PATHNAME_LEN 1024
static WCHAR *DIR_Windows;
static WCHAR *DIR_System;
......
......@@ -111,7 +111,6 @@
#include "winreg.h"
#include "winternl.h"
#include "lmerr.h"
#include "file.h"
#include "smb.h"
#include "wine/server.h"
......
/*
* File handling declarations
*
* Copyright 1996 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __WINE_FILE_H
#define __WINE_FILE_H
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#define MAX_PATHNAME_LEN 1024
/* files/file.c */
extern void FILE_SetDosError(void);
/* files/directory.c */
extern int DIR_Init(void);
/* vxd.c */
extern HANDLE VXD_Open( LPCWSTR filename, DWORD access, LPSECURITY_ATTRIBUTES sa );
#endif /* __WINE_FILE_H */
......@@ -70,7 +70,6 @@
#include "wine/library.h"
#include "wine/server.h"
#include "wine/unicode.h"
#include "file.h"
#include "wine/debug.h"
......@@ -84,6 +83,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(reg);
#define SAVE_LOCAL_REGBRANCH_USER_DEFAULT "userdef.reg"
#define SAVE_LOCAL_REGBRANCH_LOCAL_MACHINE "system.reg"
#define MAX_PATHNAME_LEN 1024
static const WCHAR ClassesRootW[] = {'M','a','c','h','i','n','e','\\',
'S','o','f','t','w','a','r','e','\\',
'C','l','a','s','s','e','s',0};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment