| 1 | /* $Id: directory.cpp,v 1.7 1999-10-23 12:34:46 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 Directory functions for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 | /*****************************************************************************
|
|---|
| 15 | * Includes *
|
|---|
| 16 | *****************************************************************************/
|
|---|
| 17 |
|
|---|
| 18 | #include <odin.h>
|
|---|
| 19 | #include <odinwrap.h>
|
|---|
| 20 | #include <os2win.h>
|
|---|
| 21 | #include <stdlib.h>
|
|---|
| 22 | #include <unicode.h>
|
|---|
| 23 | #include <heapstring.h>
|
|---|
| 24 | #include <options.h>
|
|---|
| 25 | #include "initterm.h"
|
|---|
| 26 |
|
|---|
| 27 | ODINDEBUGCHANNEL(KERNEL32-DIRECTORY)
|
|---|
| 28 |
|
|---|
| 29 |
|
|---|
| 30 | /*****************************************************************************
|
|---|
| 31 | * Name : GetCurrentDirectoryA
|
|---|
| 32 | * Purpose : query the current directory
|
|---|
| 33 | * Parameters:
|
|---|
| 34 | * Variables :
|
|---|
| 35 | * Result :
|
|---|
| 36 | * Remark :
|
|---|
| 37 | * Status :
|
|---|
| 38 | *
|
|---|
| 39 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 40 | *****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | ODINFUNCTION2(UINT, GetCurrentDirectoryA, UINT, nBufferLength,
|
|---|
| 43 | LPSTR, lpBuffer)
|
|---|
| 44 | {
|
|---|
| 45 | return O32_GetCurrentDirectory(nBufferLength, lpBuffer);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | /*****************************************************************************
|
|---|
| 50 | * Name : GetCurrentDirectoryW
|
|---|
| 51 | * Purpose : query the current directory
|
|---|
| 52 | * Parameters:
|
|---|
| 53 | * Variables :
|
|---|
| 54 | * Result :
|
|---|
| 55 | * Remark :
|
|---|
| 56 | * Status :
|
|---|
| 57 | *
|
|---|
| 58 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 59 | *****************************************************************************/
|
|---|
| 60 |
|
|---|
| 61 | ODINFUNCTION2(UINT, GetCurrentDirectoryW, UINT, nBufferLength,
|
|---|
| 62 | LPWSTR, lpBuffer)
|
|---|
| 63 | {
|
|---|
| 64 | char *asciidir = (char *)malloc(nBufferLength+1);
|
|---|
| 65 | int rc;
|
|---|
| 66 |
|
|---|
| 67 | rc = O32_GetCurrentDirectory(nBufferLength, asciidir);
|
|---|
| 68 | if(rc != 0)
|
|---|
| 69 | AsciiToUnicode(asciidir, lpBuffer);
|
|---|
| 70 | free(asciidir);
|
|---|
| 71 | return(rc);
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 | /*****************************************************************************
|
|---|
| 76 | * Name : SetCurrentDirectoryA
|
|---|
| 77 | * Purpose :
|
|---|
| 78 | * Parameters:
|
|---|
| 79 | * Variables :
|
|---|
| 80 | * Result :
|
|---|
| 81 | * Remark :
|
|---|
| 82 | * Status :
|
|---|
| 83 | *
|
|---|
| 84 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 85 | *****************************************************************************/
|
|---|
| 86 |
|
|---|
| 87 | ODINFUNCTION1(BOOL,SetCurrentDirectoryA,LPCSTR,lpPathName)
|
|---|
| 88 | {
|
|---|
| 89 | return O32_SetCurrentDirectory((LPSTR)lpPathName);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 |
|
|---|
| 93 | /*****************************************************************************
|
|---|
| 94 | * Name : SetCurrentDirectoryW
|
|---|
| 95 | * Purpose :
|
|---|
| 96 | * Parameters:
|
|---|
| 97 | * Variables :
|
|---|
| 98 | * Result :
|
|---|
| 99 | * Remark :
|
|---|
| 100 | * Status :
|
|---|
| 101 | *
|
|---|
| 102 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 103 | *****************************************************************************/
|
|---|
| 104 |
|
|---|
| 105 | ODINFUNCTION1(BOOL,SetCurrentDirectoryW,LPCWSTR,lpPathName)
|
|---|
| 106 | {
|
|---|
| 107 | char *asciipath;
|
|---|
| 108 | BOOL rc;
|
|---|
| 109 |
|
|---|
| 110 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
|---|
| 111 | rc = SetCurrentDirectoryA(asciipath);
|
|---|
| 112 | FreeAsciiString(asciipath);
|
|---|
| 113 | return(rc);
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 |
|
|---|
| 117 | /*****************************************************************************
|
|---|
| 118 | * Name : CreateDirectoryA
|
|---|
| 119 | * Purpose :
|
|---|
| 120 | * Parameters:
|
|---|
| 121 | * Variables :
|
|---|
| 122 | * Result :
|
|---|
| 123 | * Remark :
|
|---|
| 124 | * Status :
|
|---|
| 125 | *
|
|---|
| 126 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 127 | *****************************************************************************/
|
|---|
| 128 |
|
|---|
| 129 | ODINFUNCTION2(BOOL,CreateDirectoryA,LPCSTR, arg1,
|
|---|
| 130 | PSECURITY_ATTRIBUTES,arg2)
|
|---|
| 131 | {
|
|---|
| 132 | return O32_CreateDirectory(arg1, arg2);
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 | /*****************************************************************************
|
|---|
| 137 | * Name : CreateDirectoryW
|
|---|
| 138 | * Purpose :
|
|---|
| 139 | * Parameters:
|
|---|
| 140 | * Variables :
|
|---|
| 141 | * Result :
|
|---|
| 142 | * Remark :
|
|---|
| 143 | * Status :
|
|---|
| 144 | *
|
|---|
| 145 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 146 | *****************************************************************************/
|
|---|
| 147 |
|
|---|
| 148 | ODINFUNCTION2(BOOL,CreateDirectoryW,LPCWSTR, arg1,
|
|---|
| 149 | PSECURITY_ATTRIBUTES,arg2)
|
|---|
| 150 | {
|
|---|
| 151 | BOOL rc;
|
|---|
| 152 | char *astring;
|
|---|
| 153 |
|
|---|
| 154 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
|---|
| 155 | rc = CreateDirectoryA(astring, arg2);
|
|---|
| 156 | FreeAsciiString(astring);
|
|---|
| 157 | return(rc);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | /*****************************************************************************
|
|---|
| 162 | * Name : GetSystemDirectoryA
|
|---|
| 163 | * Purpose :
|
|---|
| 164 | * Parameters:
|
|---|
| 165 | * Variables :
|
|---|
| 166 | * Result :
|
|---|
| 167 | * Remark :
|
|---|
| 168 | * Status :
|
|---|
| 169 | *
|
|---|
| 170 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 171 | *****************************************************************************/
|
|---|
| 172 |
|
|---|
| 173 | ODINFUNCTION2(UINT,GetSystemDirectoryA,LPSTR,lpBuffer,
|
|---|
| 174 | UINT,uSize)
|
|---|
| 175 | {
|
|---|
| 176 | LPSTR lpstrEnv = getenv("WIN32.DIR.SYSTEM"); /* query environment */
|
|---|
| 177 |
|
|---|
| 178 | if (lpstrEnv != NULL)
|
|---|
| 179 | {
|
|---|
| 180 | lstrcpynA(lpBuffer, /* copy environment variable to buffer */
|
|---|
| 181 | lpstrEnv,
|
|---|
| 182 | uSize);
|
|---|
| 183 | return (lstrlenA(lpBuffer)); /* return number of copies bytes */
|
|---|
| 184 | }
|
|---|
| 185 | else
|
|---|
| 186 | {
|
|---|
| 187 | int len;
|
|---|
| 188 |
|
|---|
| 189 | len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"SYSTEM","",lpBuffer,uSize);
|
|---|
| 190 | if (len > 2) {
|
|---|
| 191 | return len;
|
|---|
| 192 | }
|
|---|
| 193 | else {//SvL: Use path of kernel32.dll instead of calling Open32 api (which returns \OS2\SYSTEM)
|
|---|
| 194 | lstrcpynA(lpBuffer, kernel32Path, uSize);
|
|---|
| 195 | return lstrlenA(lpBuffer);
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 | /*****************************************************************************
|
|---|
| 202 | * Name : GetSystemDirectoryW
|
|---|
| 203 | * Purpose :
|
|---|
| 204 | * Parameters:
|
|---|
| 205 | * Variables :
|
|---|
| 206 | * Result :
|
|---|
| 207 | * Remark :
|
|---|
| 208 | * Status :
|
|---|
| 209 | *
|
|---|
| 210 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 211 | *****************************************************************************/
|
|---|
| 212 |
|
|---|
| 213 | ODINFUNCTION2(UINT,GetSystemDirectoryW,LPWSTR,lpBuffer,
|
|---|
| 214 | UINT, uSize)
|
|---|
| 215 | {
|
|---|
| 216 | char *asciibuffer = (char *)malloc(uSize+1);
|
|---|
| 217 | UINT rc;
|
|---|
| 218 |
|
|---|
| 219 | rc = GetSystemDirectoryA(asciibuffer, uSize);
|
|---|
| 220 | if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
|
|---|
| 221 | free(asciibuffer);
|
|---|
| 222 | return(rc);
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 |
|
|---|
| 226 | /*****************************************************************************
|
|---|
| 227 | * Name : GetWindowsDirectoryA
|
|---|
| 228 | * Purpose :
|
|---|
| 229 | * Parameters:
|
|---|
| 230 | * Variables :
|
|---|
| 231 | * Result :
|
|---|
| 232 | * Remark :
|
|---|
| 233 | * Status :
|
|---|
| 234 | *
|
|---|
| 235 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 236 | *****************************************************************************/
|
|---|
| 237 |
|
|---|
| 238 | ODINFUNCTION2(UINT,GetWindowsDirectoryA,LPSTR,lpBuffer,
|
|---|
| 239 | UINT,uSize)
|
|---|
| 240 | {
|
|---|
| 241 | LPSTR lpstrEnv = getenv("WIN32.DIR.WINDOWS"); /* query environment */
|
|---|
| 242 |
|
|---|
| 243 | if (lpstrEnv != NULL)
|
|---|
| 244 | {
|
|---|
| 245 | lstrcpynA(lpBuffer, /* copy environment variable to buffer */
|
|---|
| 246 | lpstrEnv,
|
|---|
| 247 | uSize);
|
|---|
| 248 | return (lstrlenA(lpBuffer)); /* return number of copies bytes */
|
|---|
| 249 | } else
|
|---|
| 250 | {
|
|---|
| 251 | int len;
|
|---|
| 252 |
|
|---|
| 253 | len = PROFILE_GetOdinIniString(ODINDIRECTORIES,"WINDOWS","",lpBuffer,uSize);
|
|---|
| 254 | if (len > 2) return len;
|
|---|
| 255 | else
|
|---|
| 256 |
|
|---|
| 257 | /* if no override by environment is available */
|
|---|
| 258 | return O32_GetWindowsDirectory(lpBuffer,uSize);
|
|---|
| 259 | }
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 |
|
|---|
| 263 | /*****************************************************************************
|
|---|
| 264 | * Name : GetWindowsDirectoryW
|
|---|
| 265 | * Purpose :
|
|---|
| 266 | * Parameters:
|
|---|
| 267 | * Variables :
|
|---|
| 268 | * Result :
|
|---|
| 269 | * Remark :
|
|---|
| 270 | * Status :
|
|---|
| 271 | *
|
|---|
| 272 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 273 | *****************************************************************************/
|
|---|
| 274 |
|
|---|
| 275 | ODINFUNCTION2(UINT,GetWindowsDirectoryW,LPWSTR,lpBuffer,
|
|---|
| 276 | UINT, uSize)
|
|---|
| 277 | {
|
|---|
| 278 | char *asciibuffer = (char *)malloc(uSize+1);
|
|---|
| 279 | UINT rc;
|
|---|
| 280 |
|
|---|
| 281 | rc = GetWindowsDirectoryA(asciibuffer, uSize);
|
|---|
| 282 | AsciiToUnicode(asciibuffer, lpBuffer);
|
|---|
| 283 | free(asciibuffer);
|
|---|
| 284 | return(rc);
|
|---|
| 285 | }
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 | /*****************************************************************************
|
|---|
| 289 | * Name : RemoveDirectoryA
|
|---|
| 290 | * Purpose :
|
|---|
| 291 | * Parameters:
|
|---|
| 292 | * Variables :
|
|---|
| 293 | * Result :
|
|---|
| 294 | * Remark :
|
|---|
| 295 | * Status :
|
|---|
| 296 | *
|
|---|
| 297 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 298 | *****************************************************************************/
|
|---|
| 299 |
|
|---|
| 300 | ODINFUNCTION1(BOOL,RemoveDirectoryA,LPCSTR,arg1)
|
|---|
| 301 | {
|
|---|
| 302 | return O32_RemoveDirectory(arg1);
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 |
|
|---|
| 306 | /*****************************************************************************
|
|---|
| 307 | * Name : RemoveDirectoryW
|
|---|
| 308 | * Purpose :
|
|---|
| 309 | * Parameters:
|
|---|
| 310 | * Variables :
|
|---|
| 311 | * Result :
|
|---|
| 312 | * Remark :
|
|---|
| 313 | * Status :
|
|---|
| 314 | *
|
|---|
| 315 | * Author : Patrick Haller [Wed, 1999/09/28 20:44]
|
|---|
| 316 | *****************************************************************************/
|
|---|
| 317 |
|
|---|
| 318 | ODINFUNCTION1(BOOL,RemoveDirectoryW,LPCWSTR,lpPathName)
|
|---|
| 319 | {
|
|---|
| 320 | char *asciipath;
|
|---|
| 321 | BOOL rc;
|
|---|
| 322 |
|
|---|
| 323 | asciipath = UnicodeToAsciiString((LPWSTR)lpPathName);
|
|---|
| 324 | rc = RemoveDirectoryA(asciipath);
|
|---|
| 325 | FreeAsciiString(asciipath);
|
|---|
| 326 | return(rc);
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|