minor corrections by M.Taguchi
[reactos.git] / posix / lib / psxdll / unistd / getcwd.c
1 /* $Id: getcwd.c,v 1.4 2002/10/29 04:45:48 rex Exp $
2 */
3 /*
4 * COPYRIGHT: See COPYING in the top level directory
5 * PROJECT: ReactOS POSIX+ Subsystem
6 * FILE: subsys/psx/lib/psxdll/unistd/getcwd.c
7 * PURPOSE: Get the pathname of the current working directory
8 * PROGRAMMER: KJK::Hyperion <noog@libero.it>
9 * UPDATE HISTORY:
10 * 01/02/2002: Created
11 */
12
13 #include <ddk/ntddk.h>
14 #include <ntdll/rtl.h>
15 #include <unistd.h>
16 #include <stddef.h>
17 #include <wchar.h>
18 #include <psx/errno.h>
19 #include <psx/stdlib.h>
20 #include <psx/pdata.h>
21
22 wchar_t *_Wgetcwd(wchar_t *buf, size_t size)
23 {
24 PUNICODE_STRING pwstrCurDir;
25
26 __PdxAcquirePdataLock();
27
28 pwstrCurDir = __PdxGetCurDir();
29
30 if(size < (pwstrCurDir->Length / sizeof(WCHAR)))
31 {
32 __PdxReleasePdataLock();
33 errno = ERANGE;
34 return (0);
35 }
36 else
37 {
38 wcsncpy(buf, pwstrCurDir->Buffer, pwstrCurDir->Length);
39 __PdxReleasePdataLock();
40 return (buf);
41 }
42 }
43
44 char *getcwd(char *buf, size_t size)
45 {
46 PUNICODE_STRING pwstrCurDir;
47
48 __PdxAcquirePdataLock();
49
50 pwstrCurDir = __PdxGetCurDir();
51
52 if(size < (pwstrCurDir->Length / sizeof(WCHAR)))
53 {
54 __PdxReleasePdataLock();
55 errno = ERANGE;
56 return (0);
57 }
58 else
59 {
60 ANSI_STRING strBuffer;
61 NTSTATUS nErrCode;
62
63 strBuffer.Length = 0;
64 strBuffer.MaximumLength = size;
65 strBuffer.Buffer = buf;
66
67 nErrCode = RtlUnicodeStringToAnsiString
68 (
69 &strBuffer,
70 pwstrCurDir,
71 FALSE
72 );
73
74 __PdxReleasePdataLock();
75
76 if(!NT_SUCCESS(nErrCode))
77 {
78 errno = __status_to_errno(nErrCode);
79 return (0);
80 }
81
82 return (buf);
83 }
84
85 __PdxReleasePdataLock();
86 }
87
88 /* EOF */
89