Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
wine
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sebastian Mayr
wine
Commits
289613a5
Commit
289613a5
authored
21 years ago
by
Alexandre Julliard
Browse files
Options
Downloads
Patches
Plain Diff
Make sure GetTempFileName never returns 0 on success.
parent
b107b928
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
files/file.c
+48
-59
48 additions, 59 deletions
files/file.c
with
48 additions
and
59 deletions
files/file.c
+
48
−
59
View file @
289613a5
...
...
@@ -1064,17 +1064,44 @@ BOOL WINAPI GetFileTime( HANDLE hFile, FILETIME *lpCreationTime,
/***********************************************************************
* FILE_GetTempFileName : utility for GetTempFileName
* 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.@)
*/
static
UINT
FILE_
GetTempFileName
(
LPCWSTR
path
,
LPCWSTR
prefix
,
UINT
unique
,
UINT
WINAPI
GetTempFileName
W
(
LPCWSTR
path
,
LPCWSTR
prefix
,
UINT
unique
,
LPWSTR
buffer
)
{
static
UINT
unique_temp
;
static
const
WCHAR
formatW
[]
=
{
'%'
,
'0'
,
'4'
,
'x'
,
'.'
,
't'
,
'm'
,
'p'
,
0
};
DOS_FULL_NAME
full_name
;
int
i
;
LPWSTR
p
;
UINT
num
;
char
buf
[
20
];
if
(
!
path
||
!
prefix
||
!
buffer
)
{
...
...
@@ -1082,29 +1109,31 @@ static UINT FILE_GetTempFileName( LPCWSTR path, LPCWSTR prefix, UINT unique,
return
0
;
}
if
(
!
unique_temp
)
unique_temp
=
time
(
NULL
)
&
0xffff
;
num
=
unique
?
(
unique
&
0xffff
)
:
(
unique_temp
++
&
0xffff
);
strcpyW
(
buffer
,
path
);
p
=
buffer
+
strlenW
(
buffer
);
/* add a \, if there isn't one and path is more than just the drive letter ... */
if
(
!
((
strlenW
(
buffer
)
==
2
)
&&
(
buffer
[
1
]
==
':'
))
&&
((
p
==
buffer
)
||
(
p
[
-
1
]
!=
'\\'
)))
*
p
++
=
'\\'
;
&&
((
p
==
buffer
)
||
(
p
[
-
1
]
!=
'\\'
)))
*
p
++
=
'\\'
;
for
(
i
=
3
;
(
i
>
0
)
&&
(
*
prefix
);
i
--
)
*
p
++
=
*
prefix
++
;
sprintf
(
buf
,
"%04x.tmp"
,
num
);
MultiByteToWideChar
(
CP_ACP
,
0
,
buf
,
-
1
,
p
,
20
);
unique
&=
0xffff
;
/* Now try to create it */
if
(
!
unique
)
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
{
HANDLE
handle
=
CreateFileW
(
buffer
,
GENERIC_WRITE
,
0
,
NULL
,
CREATE_NEW
,
FILE_ATTRIBUTE_NORMAL
,
0
);
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
)
);
...
...
@@ -1114,10 +1143,8 @@ static UINT FILE_GetTempFileName( LPCWSTR path, LPCWSTR prefix, UINT unique,
if
(
GetLastError
()
!=
ERROR_FILE_EXISTS
&&
GetLastError
()
!=
ERROR_SHARING_VIOLATION
)
break
;
/* No need to go on */
num
++
;
sprintf
(
buf
,
"%04x.tmp"
,
num
);
MultiByteToWideChar
(
CP_ACP
,
0
,
buf
,
-
1
,
p
,
20
);
}
while
(
num
!=
(
unique
&
0xffff
));
if
(
!
(
++
unique
&
0xffff
))
unique
=
1
;
}
while
(
unique
!=
num
);
}
/* Get the full path name */
...
...
@@ -1132,45 +1159,7 @@ static UINT FILE_GetTempFileName( LPCWSTR path, LPCWSTR prefix, UINT unique,
debugstr_w
(
buffer
)
);
}
TRACE
(
"returning %s
\n
"
,
debugstr_w
(
buffer
)
);
return
unique
?
unique
:
num
;
}
/***********************************************************************
* 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
)
{
return
FILE_GetTempFileName
(
path
,
prefix
,
unique
,
buffer
);
return
unique
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment