mirror of
https://github.com/reactos/reactos.git
synced 2025-04-29 18:48:53 +00:00

* lib/kernel32/debug/break.c: Add @implemented and @unimplemented to APIs. * lib/kernel32/debug/debugger.c: Ditto. * lib/kernel32/debug/output.c: Ditto. * lib/kernel32/except/except.c: Ditto. * lib/kernel32/file/backup.c: Ditto. * lib/kernel32/file/cnotify.c: Ditto. * lib/kernel32/file/copy.c: Ditto. * lib/kernel32/file/create.c: Ditto. * lib/kernel32/file/curdir.c: Ditto. * lib/kernel32/file/delete.c: Ditto. * lib/kernel32/file/deviceio.c: Ditto. * lib/kernel32/file/dir.c: Ditto. * lib/kernel32/file/dosdev.c: Ditto. * lib/kernel32/file/file.c: Ditto. * lib/kernel32/file/find.c: Ditto. * lib/kernel32/file/iocompl.c: Ditto. * lib/kernel32/file/lfile.c: Ditto. * lib/kernel32/file/lock.c: Ditto. * lib/kernel32/file/mailslot.c: Ditto. * lib/kernel32/file/move.c: Ditto. * lib/kernel32/file/npipe.c: Ditto. * lib/kernel32/file/pipe.c: Ditto. * lib/kernel32/file/rw.c: Ditto. * lib/kernel32/file/tape.c: Ditto. * lib/kernel32/file/volume.c: Ditto. * lib/kernel32/mem/global.c: Ditto. * lib/kernel32/mem/heap.c: Ditto. * lib/kernel32/mem/isbad.c: Ditto. * lib/kernel32/mem/local.c: Ditto. * lib/kernel32/mem/procmem.c: Ditto. * lib/kernel32/mem/section.c: Ditto. * lib/kernel32/mem/virtual.c: Ditto. * lib/kernel32/misc/atom.c: Ditto. * lib/kernel32/misc/comm.c: Ditto. * lib/kernel32/misc/computername.c: Ditto. * lib/kernel32/misc/console.c: Ditto. * lib/kernel32/misc/env.c: Ditto. * lib/kernel32/misc/error.c: Ditto. * lib/kernel32/misc/errormsg.c: Ditto. * lib/kernel32/misc/handle.c: Ditto. * lib/kernel32/misc/ldr.c: Ditto. * lib/kernel32/misc/mbchars.c: Ditto. * lib/kernel32/misc/muldiv.c: Ditto. * lib/kernel32/misc/perfcnt.c: Ditto. * lib/kernel32/misc/profile.c: Ditto. * lib/kernel32/misc/res.c: Ditto. * lib/kernel32/misc/stubs.c: Ditto. * lib/kernel32/misc/sysinfo.c: Ditto. * lib/kernel32/misc/time.c: Ditto. * lib/kernel32/misc/toolhelp.c: Ditto. * lib/kernel32/process/cmdline.c: Ditto. * lib/kernel32/process/create.c: Ditto. * lib/kernel32/process/proc.c: Ditto. * lib/kernel32/process/session.c: Ditto. * lib/kernel32/string/lstring.c: Ditto. * lib/kernel32/synch/critical.c: Ditto. * lib/kernel32/synch/event.c: Ditto. * lib/kernel32/synch/intrlck.c: Ditto. * lib/kernel32/synch/mutex.c: Ditto. * lib/kernel32/synch/sem.c: Ditto. * lib/kernel32/synch/timer.c: Ditto. * lib/kernel32/synch/wait.c: Ditto. * lib/kernel32/thread/fiber.c: Ditto. * lib/kernel32/thread/fls.c: Ditto. * lib/kernel32/thread/thread.c: Ditto. * lib/kernel32/thread/tls.c: Ditto. svn path=/trunk/; revision=5045
406 lines
8.3 KiB
C
406 lines
8.3 KiB
C
/* $Id: curdir.c,v 1.36 2003/07/10 18:50:51 chorns Exp $
|
|
*
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
* PROJECT: ReactOS system libraries
|
|
* FILE: lib/kernel32/file/curdir.c
|
|
* PURPOSE: Current directory functions
|
|
* UPDATE HISTORY:
|
|
* Created 30/09/98
|
|
*/
|
|
|
|
|
|
/* INCLUDES ******************************************************************/
|
|
|
|
#include <k32.h>
|
|
|
|
#define NDEBUG
|
|
#include <kernel32/kernel32.h>
|
|
|
|
|
|
/* GLOBAL VARIABLES **********************************************************/
|
|
|
|
UNICODE_STRING SystemDirectory;
|
|
UNICODE_STRING WindowsDirectory;
|
|
|
|
|
|
/* FUNCTIONS *****************************************************************/
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
DWORD
|
|
STDCALL
|
|
GetCurrentDirectoryA (
|
|
DWORD nBufferLength,
|
|
LPSTR lpBuffer
|
|
)
|
|
{
|
|
ANSI_STRING AnsiString;
|
|
UNICODE_STRING UnicodeString;
|
|
|
|
/* initialize ansi string */
|
|
AnsiString.Length = 0;
|
|
AnsiString.MaximumLength = nBufferLength;
|
|
AnsiString.Buffer = lpBuffer;
|
|
|
|
/* allocate buffer for unicode string */
|
|
UnicodeString.Length = 0;
|
|
UnicodeString.MaximumLength = nBufferLength * sizeof(WCHAR);
|
|
UnicodeString.Buffer = RtlAllocateHeap (RtlGetProcessHeap (),
|
|
0,
|
|
UnicodeString.MaximumLength);
|
|
|
|
/* get current directory */
|
|
UnicodeString.Length = RtlGetCurrentDirectory_U (UnicodeString.MaximumLength,
|
|
UnicodeString.Buffer);
|
|
DPRINT("UnicodeString.Buffer %S\n", UnicodeString.Buffer);
|
|
|
|
/* convert unicode string to ansi (or oem) */
|
|
if (bIsFileApiAnsi)
|
|
RtlUnicodeStringToAnsiString (&AnsiString,
|
|
&UnicodeString,
|
|
FALSE);
|
|
else
|
|
RtlUnicodeStringToOemString (&AnsiString,
|
|
&UnicodeString,
|
|
FALSE);
|
|
DPRINT("AnsiString.Buffer %s\n", AnsiString.Buffer);
|
|
|
|
/* free unicode string */
|
|
RtlFreeHeap (RtlGetProcessHeap (),
|
|
0,
|
|
UnicodeString.Buffer);
|
|
|
|
return AnsiString.Length;
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
DWORD
|
|
STDCALL
|
|
GetCurrentDirectoryW (
|
|
DWORD nBufferLength,
|
|
LPWSTR lpBuffer
|
|
)
|
|
{
|
|
ULONG Length;
|
|
|
|
Length = RtlGetCurrentDirectory_U (nBufferLength * sizeof(WCHAR),
|
|
lpBuffer);
|
|
|
|
return (Length / sizeof (WCHAR));
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
WINBOOL
|
|
STDCALL
|
|
SetCurrentDirectoryA (
|
|
LPCSTR lpPathName
|
|
)
|
|
{
|
|
ANSI_STRING AnsiString;
|
|
UNICODE_STRING UnicodeString;
|
|
NTSTATUS Status;
|
|
|
|
RtlInitAnsiString (&AnsiString,
|
|
(LPSTR)lpPathName);
|
|
|
|
/* convert ansi (or oem) to unicode */
|
|
if (bIsFileApiAnsi)
|
|
RtlAnsiStringToUnicodeString (&UnicodeString,
|
|
&AnsiString,
|
|
TRUE);
|
|
else
|
|
RtlOemStringToUnicodeString (&UnicodeString,
|
|
&AnsiString,
|
|
TRUE);
|
|
|
|
Status = RtlSetCurrentDirectory_U (&UnicodeString);
|
|
|
|
RtlFreeUnicodeString (&UnicodeString);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
SetLastErrorByStatus (Status);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
WINBOOL
|
|
STDCALL
|
|
SetCurrentDirectoryW (
|
|
LPCWSTR lpPathName
|
|
)
|
|
{
|
|
UNICODE_STRING UnicodeString;
|
|
NTSTATUS Status;
|
|
|
|
RtlInitUnicodeString (&UnicodeString,
|
|
lpPathName);
|
|
|
|
Status = RtlSetCurrentDirectory_U (&UnicodeString);
|
|
if (!NT_SUCCESS(Status))
|
|
{
|
|
SetLastErrorByStatus (Status);
|
|
return FALSE;
|
|
}
|
|
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
DWORD
|
|
STDCALL
|
|
GetTempPathA (
|
|
DWORD nBufferLength,
|
|
LPSTR lpBuffer
|
|
)
|
|
{
|
|
UNICODE_STRING UnicodeString;
|
|
ANSI_STRING AnsiString;
|
|
|
|
AnsiString.Length = 0;
|
|
AnsiString.MaximumLength = nBufferLength;
|
|
AnsiString.Buffer = lpBuffer;
|
|
|
|
/* initialize allocate unicode string */
|
|
UnicodeString.Length = 0;
|
|
UnicodeString.MaximumLength = nBufferLength * sizeof(WCHAR);
|
|
UnicodeString.Buffer = RtlAllocateHeap (RtlGetProcessHeap(),
|
|
0,
|
|
UnicodeString.MaximumLength);
|
|
|
|
UnicodeString.Length = GetTempPathW (nBufferLength,
|
|
UnicodeString.Buffer) * sizeof(WCHAR);
|
|
|
|
/* convert unicode string to ansi (or oem) */
|
|
if (bIsFileApiAnsi)
|
|
RtlUnicodeStringToAnsiString (&AnsiString,
|
|
&UnicodeString,
|
|
FALSE);
|
|
else
|
|
RtlUnicodeStringToOemString (&AnsiString,
|
|
&UnicodeString,
|
|
FALSE);
|
|
|
|
/* free unicode string buffer */
|
|
RtlFreeHeap (RtlGetProcessHeap (),
|
|
0,
|
|
UnicodeString.Buffer);
|
|
|
|
return AnsiString.Length;
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
DWORD
|
|
STDCALL
|
|
GetTempPathW (
|
|
DWORD nBufferLength,
|
|
LPWSTR lpBuffer
|
|
)
|
|
{
|
|
UNICODE_STRING Name;
|
|
UNICODE_STRING Value;
|
|
NTSTATUS Status;
|
|
|
|
Value.Length = 0;
|
|
Value.MaximumLength = (nBufferLength - 1) * sizeof(WCHAR);
|
|
Value.Buffer = lpBuffer;
|
|
|
|
RtlInitUnicodeStringFromLiteral (&Name,
|
|
L"TMP");
|
|
|
|
Status = RtlQueryEnvironmentVariable_U (NULL,
|
|
&Name,
|
|
&Value);
|
|
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
|
|
{
|
|
RtlInitUnicodeStringFromLiteral (&Name,
|
|
L"TEMP");
|
|
|
|
Status = RtlQueryEnvironmentVariable_U (NULL,
|
|
&Name,
|
|
&Value);
|
|
|
|
if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_TOO_SMALL)
|
|
{
|
|
Value.Length = RtlGetCurrentDirectory_U (Value.MaximumLength,
|
|
Value.Buffer);
|
|
}
|
|
}
|
|
|
|
if (NT_SUCCESS(Status))
|
|
{
|
|
lpBuffer[Value.Length / sizeof(WCHAR)] = L'\\';
|
|
lpBuffer[Value.Length / sizeof(WCHAR) + 1] = 0;
|
|
}
|
|
|
|
return Value.Length / sizeof(WCHAR) + 1;
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
UINT
|
|
STDCALL
|
|
GetSystemDirectoryA (
|
|
LPSTR lpBuffer,
|
|
UINT uSize
|
|
)
|
|
{
|
|
ANSI_STRING String;
|
|
ULONG Length;
|
|
NTSTATUS Status;
|
|
|
|
if (lpBuffer == NULL)
|
|
return 0;
|
|
|
|
Length = RtlUnicodeStringToAnsiSize (&SystemDirectory); //len of ansi str incl. nullchar
|
|
|
|
if (uSize >= Length){
|
|
String.Length = 0;
|
|
String.MaximumLength = uSize;
|
|
String.Buffer = lpBuffer;
|
|
|
|
/* convert unicode string to ansi (or oem) */
|
|
if (bIsFileApiAnsi)
|
|
Status = RtlUnicodeStringToAnsiString (&String,
|
|
&SystemDirectory,
|
|
FALSE);
|
|
else
|
|
Status = RtlUnicodeStringToOemString (&String,
|
|
&SystemDirectory,
|
|
FALSE);
|
|
if (!NT_SUCCESS(Status) )
|
|
return 0;
|
|
|
|
return Length-1; //good: ret chars excl. nullchar
|
|
|
|
}
|
|
|
|
return Length; //bad: ret space needed incl. nullchar
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
UINT
|
|
STDCALL
|
|
GetSystemDirectoryW (
|
|
LPWSTR lpBuffer,
|
|
UINT uSize
|
|
)
|
|
{
|
|
ULONG Length;
|
|
|
|
if (lpBuffer == NULL)
|
|
return 0;
|
|
|
|
Length = SystemDirectory.Length / sizeof (WCHAR);
|
|
if (uSize > Length) {
|
|
memmove (lpBuffer,
|
|
SystemDirectory.Buffer,
|
|
SystemDirectory.Length);
|
|
lpBuffer[Length] = 0;
|
|
|
|
return Length; //good: ret chars excl. nullchar
|
|
}
|
|
|
|
return Length+1; //bad: ret space needed incl. nullchar
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
UINT
|
|
STDCALL
|
|
GetWindowsDirectoryA (
|
|
LPSTR lpBuffer,
|
|
UINT uSize
|
|
)
|
|
{
|
|
ANSI_STRING String;
|
|
ULONG Length;
|
|
NTSTATUS Status;
|
|
|
|
if (lpBuffer == NULL)
|
|
return 0;
|
|
|
|
Length = RtlUnicodeStringToAnsiSize (&WindowsDirectory); //len of ansi str incl. nullchar
|
|
|
|
if (uSize >= Length){
|
|
|
|
String.Length = 0;
|
|
String.MaximumLength = uSize;
|
|
String.Buffer = lpBuffer;
|
|
|
|
/* convert unicode string to ansi (or oem) */
|
|
if (bIsFileApiAnsi)
|
|
Status = RtlUnicodeStringToAnsiString (&String,
|
|
&WindowsDirectory,
|
|
FALSE);
|
|
else
|
|
Status = RtlUnicodeStringToOemString (&String,
|
|
&WindowsDirectory,
|
|
FALSE);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
return 0;
|
|
|
|
return Length-1; //good: ret chars excl. nullchar
|
|
}
|
|
|
|
return Length; //bad: ret space needed incl. nullchar
|
|
}
|
|
|
|
|
|
/*
|
|
* @implemented
|
|
*/
|
|
UINT
|
|
STDCALL
|
|
GetWindowsDirectoryW (
|
|
LPWSTR lpBuffer,
|
|
UINT uSize
|
|
)
|
|
{
|
|
ULONG Length;
|
|
|
|
if (lpBuffer == NULL)
|
|
return 0;
|
|
|
|
Length = WindowsDirectory.Length / sizeof (WCHAR);
|
|
if (uSize > Length)
|
|
{
|
|
memmove (lpBuffer,
|
|
WindowsDirectory.Buffer,
|
|
WindowsDirectory.Length);
|
|
lpBuffer[Length] = 0;
|
|
|
|
return Length; //good: ret chars excl. nullchar
|
|
}
|
|
|
|
return Length+1; //bad: ret space needed incl. nullchar
|
|
}
|
|
|
|
/* EOF */
|