mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
win32/file.c: prototype and cosmetic changes
* win32/file.c (home_dir, system_code_page): use prototype, adjust indent, and fix typo. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36907 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a1fa2695e1
commit
f961b80a78
1 changed files with 25 additions and 22 deletions
47
win32/file.c
47
win32/file.c
|
@ -63,14 +63,14 @@ convert_wchar_to_mb(const wchar_t *wstr, char **str, size_t *str_len, UINT code_
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Return user's home directory using environment variables combinations.
|
Return user's home directory using environment variables combinations.
|
||||||
Memory allocated by this function should be manually freeded afterwards.
|
Memory allocated by this function should be manually freed afterwards.
|
||||||
|
|
||||||
Try:
|
Try:
|
||||||
HOME, HOMEDRIVE + HOMEPATH and USERPROFILE environment variables
|
HOME, HOMEDRIVE + HOMEPATH and USERPROFILE environment variables
|
||||||
TODO: Special Folders - Profile and Personal
|
TODO: Special Folders - Profile and Personal
|
||||||
*/
|
*/
|
||||||
static wchar_t *
|
static wchar_t *
|
||||||
home_dir()
|
home_dir(void)
|
||||||
{
|
{
|
||||||
wchar_t *buffer = NULL;
|
wchar_t *buffer = NULL;
|
||||||
size_t buffer_len = 0, len = 0;
|
size_t buffer_len = 0, len = 0;
|
||||||
|
@ -106,22 +106,22 @@ home_dir()
|
||||||
buffer = (wchar_t *)xmalloc(buffer_len * sizeof(wchar_t));
|
buffer = (wchar_t *)xmalloc(buffer_len * sizeof(wchar_t));
|
||||||
|
|
||||||
switch (home_env) {
|
switch (home_env) {
|
||||||
case 1:
|
case 1:
|
||||||
/* HOME */
|
/* HOME */
|
||||||
GetEnvironmentVariableW(L"HOME", buffer, buffer_len);
|
GetEnvironmentVariableW(L"HOME", buffer, buffer_len);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
/* HOMEDRIVE + HOMEPATH */
|
/* HOMEDRIVE + HOMEPATH */
|
||||||
len = GetEnvironmentVariableW(L"HOMEDRIVE", buffer, buffer_len);
|
len = GetEnvironmentVariableW(L"HOMEDRIVE", buffer, buffer_len);
|
||||||
GetEnvironmentVariableW(L"HOMEPATH", buffer + len, buffer_len - len);
|
GetEnvironmentVariableW(L"HOMEPATH", buffer + len, buffer_len - len);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
/* USERPROFILE */
|
/* USERPROFILE */
|
||||||
GetEnvironmentVariableW(L"USERPROFILE", buffer, buffer_len);
|
GetEnvironmentVariableW(L"USERPROFILE", buffer, buffer_len);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (home_env) {
|
if (home_env) {
|
||||||
/* sanitize backslashes with forwardslashes */
|
/* sanitize backslashes with forwardslashes */
|
||||||
|
@ -135,7 +135,8 @@ home_dir()
|
||||||
|
|
||||||
/* Remove trailing invalid ':$DATA' of the path. */
|
/* Remove trailing invalid ':$DATA' of the path. */
|
||||||
static inline size_t
|
static inline size_t
|
||||||
remove_invalid_alternative_data(wchar_t *wfullpath, size_t size) {
|
remove_invalid_alternative_data(wchar_t *wfullpath, size_t size)
|
||||||
|
{
|
||||||
static const wchar_t prime[] = L":$DATA";
|
static const wchar_t prime[] = L":$DATA";
|
||||||
enum { prime_len = (sizeof(prime) / sizeof(wchar_t)) -1 };
|
enum { prime_len = (sizeof(prime) / sizeof(wchar_t)) -1 };
|
||||||
|
|
||||||
|
@ -166,7 +167,8 @@ remove_invalid_alternative_data(wchar_t *wfullpath, size_t size) {
|
||||||
|
|
||||||
/* Return system code page. */
|
/* Return system code page. */
|
||||||
static inline UINT
|
static inline UINT
|
||||||
system_code_page() {
|
system_code_page(void)
|
||||||
|
{
|
||||||
return AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
return AreFileApisANSI() ? CP_ACP : CP_OEMCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -250,7 +252,8 @@ fix_string_encoding(VALUE str, rb_encoding *encoding)
|
||||||
We try to avoid to call FindFirstFileW() since it takes long time.
|
We try to avoid to call FindFirstFileW() since it takes long time.
|
||||||
*/
|
*/
|
||||||
static inline size_t
|
static inline size_t
|
||||||
replace_to_long_name(wchar_t **wfullpath, size_t size, int heap) {
|
replace_to_long_name(wchar_t **wfullpath, size_t size, int heap)
|
||||||
|
{
|
||||||
WIN32_FIND_DATAW find_data;
|
WIN32_FIND_DATAW find_data;
|
||||||
HANDLE find_handle;
|
HANDLE find_handle;
|
||||||
|
|
||||||
|
@ -480,7 +483,7 @@ rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_na
|
||||||
wdir_len = 0;
|
wdir_len = 0;
|
||||||
}
|
}
|
||||||
else if (!ignore_dir && wpath_len >= 1 && IS_DIR_SEPARATOR_P(wpath[0]) &&
|
else if (!ignore_dir && wpath_len >= 1 && IS_DIR_SEPARATOR_P(wpath[0]) &&
|
||||||
!dir_drive && !(wdir_len >= 2 && IS_DIR_UNC_P(wdir))) {
|
!dir_drive && !(wdir_len >= 2 && IS_DIR_UNC_P(wdir))) {
|
||||||
/* ignore dir since path has root slash and dir doesn't have drive or UNC root */
|
/* ignore dir since path has root slash and dir doesn't have drive or UNC root */
|
||||||
ignore_dir = 1;
|
ignore_dir = 1;
|
||||||
wdir_len = 0;
|
wdir_len = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue