Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
289613a5
Commit
289613a5
authored
Oct 31, 2003
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make sure GetTempFileName never returns 0 on success.
parent
b107b928
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
57 deletions
+46
-57
file.c
files/file.c
+46
-57
No files found.
files/file.c
View file @
289613a5
...
...
@@ -1064,17 +1064,44 @@ BOOL WINAPI GetFileTime( HANDLE hFile, FILETIME *lpCreationTime,
/***********************************************************************
*
FILE_GetTempFileName : utility for GetTempFileName
*
GetTempFileNameA (KERNEL32.@)
*/
static
UINT
FILE_GetTempFileName
(
LPCWSTR
path
,
LPCWSTR
prefix
,
UINT
unique
,
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
)
{
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,9 +1109,6 @@ 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
);
...
...
@@ -1094,16 +1118,21 @@ static UINT FILE_GetTempFileName( LPCWSTR path, LPCWSTR prefix, UINT unique,
for
(
i
=
3
;
(
i
>
0
)
&&
(
*
prefix
);
i
--
)
*
p
++
=
*
prefix
++
;
sprintf
(
buf
,
"%04x.tmp"
,
num
);
MultiByteToWideChar
(
CP_ACP
,
0
,
buf
,
-
1
,
p
,
20
);
/* Now try to create it */
unique
&=
0xffff
;
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
,
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 */
...
...
@@ -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
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment