Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
55701c66
Commit
55701c66
authored
Sep 29, 2021
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: Add a helper function to create temp files.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
1f0bc618
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
55 additions
and
54 deletions
+55
-54
tools.h
tools/tools.h
+31
-0
parser.l
tools/widl/parser.l
+2
-8
widl.c
tools/widl/widl.c
+2
-7
utils.c
tools/winebuild/utils.c
+6
-18
winegcc.c
tools/winegcc/winegcc.c
+2
-13
genres.c
tools/wrc/genres.c
+1
-0
newstruc.c
tools/wrc/newstruc.c
+1
-0
parser.l
tools/wrc/parser.l
+1
-0
parser.y
tools/wrc/parser.y
+1
-0
po.c
tools/wrc/po.c
+1
-0
ppl.l
tools/wrc/ppl.l
+1
-0
ppy.y
tools/wrc/ppy.y
+1
-0
translation.c
tools/wrc/translation.c
+1
-0
utils.c
tools/wrc/utils.c
+1
-0
wpp.c
tools/wrc/wpp.c
+1
-0
wpp_private.h
tools/wrc/wpp_private.h
+0
-1
wrc.c
tools/wrc/wrc.c
+2
-6
wrc.h
tools/wrc/wrc.h
+0
-1
No files found.
tools/tools.h
View file @
55701c66
...
@@ -26,6 +26,8 @@
...
@@ -26,6 +26,8 @@
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/types.h>
#include <sys/types.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
#ifdef HAVE_UNISTD_H
# include <unistd.h>
# include <unistd.h>
...
@@ -249,4 +251,33 @@ static inline int strarray_spawn( struct strarray args )
...
@@ -249,4 +251,33 @@ static inline int strarray_spawn( struct strarray args )
#endif
#endif
}
}
static
inline
int
make_temp_file
(
const
char
*
prefix
,
const
char
*
suffix
,
char
**
name
)
{
static
unsigned
int
value
;
int
fd
,
count
;
const
char
*
tmpdir
=
NULL
;
if
(
!
prefix
)
prefix
=
"tmp"
;
if
(
!
suffix
)
suffix
=
""
;
value
+=
time
(
NULL
)
+
getpid
();
for
(
count
=
0
;
count
<
0x8000
;
count
++
)
{
if
(
tmpdir
)
*
name
=
strmake
(
"%s/%s-%08x%s"
,
tmpdir
,
prefix
,
value
,
suffix
);
else
*
name
=
strmake
(
"%s-%08x%s"
,
prefix
,
value
,
suffix
);
fd
=
open
(
*
name
,
O_RDWR
|
O_CREAT
|
O_EXCL
,
0600
);
if
(
fd
>=
0
)
return
fd
;
value
+=
7777
;
if
(
errno
==
EACCES
&&
!
tmpdir
&&
!
strchr
(
prefix
,
'/'
))
{
if
(
!
(
tmpdir
=
getenv
(
"TMPDIR"
)))
tmpdir
=
"/tmp"
;
}
free
(
*
name
);
}
fprintf
(
stderr
,
"failed to create temp file for %s%s
\n
"
,
prefix
,
suffix
);
exit
(
1
);
}
#endif
/* __WINE_TOOLS_H */
#endif
/* __WINE_TOOLS_H */
tools/widl/parser.l
View file @
55701c66
...
@@ -564,10 +564,7 @@ int do_import(char *fname)
...
@@ -564,10 +564,7 @@ int do_import(char *fname)
input_name = path;
input_name = path;
line_number = 1;
line_number = 1;
name = xstrdup( "widl.XXXXXX" );
fd = make_temp_file( "widl-pp", NULL, &name );
if((fd = mkstemps( name, 0 )) == -1)
error("Could not generate a temp name from %s\n", name);
temp_name = name;
temp_name = name;
if (!(f = fdopen(fd, "wt")))
if (!(f = fdopen(fd, "wt")))
error("Could not open fd %s for writing\n", name);
error("Could not open fd %s for writing\n", name);
...
@@ -605,10 +602,7 @@ static void switch_to_acf(void)
...
@@ -605,10 +602,7 @@ static void switch_to_acf(void)
acf_name = NULL;
acf_name = NULL;
line_number = 1;
line_number = 1;
name = xstrdup( "widl.XXXXXX" );
fd = make_temp_file( "widl-acf", NULL, &name );
if((fd = mkstemps( name, 0 )) == -1)
error("Could not generate a temp name from %s\n", name);
temp_name = name;
temp_name = name;
if (!(f = fdopen(fd, "wt")))
if (!(f = fdopen(fd, "wt")))
error("Could not open fd %s for writing\n", name);
error("Could not open fd %s for writing\n", name);
...
...
tools/widl/widl.c
View file @
55701c66
...
@@ -967,14 +967,9 @@ int main(int argc,char *argv[])
...
@@ -967,14 +967,9 @@ int main(int argc,char *argv[])
{
{
FILE
*
output
;
FILE
*
output
;
int
fd
;
int
fd
;
char
*
name
=
xmalloc
(
strlen
(
header_name
)
+
8
);
char
*
name
;
strcpy
(
name
,
header_name
);
strcat
(
name
,
".XXXXXX"
);
if
((
fd
=
mkstemps
(
name
,
0
))
==
-
1
)
error
(
"Could not generate a temp name from %s
\n
"
,
name
);
fd
=
make_temp_file
(
header_name
,
NULL
,
&
name
);
temp_name
=
name
;
temp_name
=
name
;
if
(
!
(
output
=
fdopen
(
fd
,
"wt"
)))
if
(
!
(
output
=
fdopen
(
fd
,
"wt"
)))
error
(
"Could not open fd %s for writing
\n
"
,
name
);
error
(
"Could not open fd %s for writing
\n
"
,
name
);
...
...
tools/winebuild/utils.c
View file @
55701c66
...
@@ -441,26 +441,14 @@ char *get_temp_file_name( const char *prefix, const char *suffix )
...
@@ -441,26 +441,14 @@ char *get_temp_file_name( const char *prefix, const char *suffix )
const
char
*
ext
,
*
basename
;
const
char
*
ext
,
*
basename
;
int
fd
;
int
fd
;
if
(
!
prefix
||
!
prefix
[
0
])
prefix
=
"winebuild"
;
if
(
prefix
)
if
(
!
suffix
)
suffix
=
""
;
if
((
basename
=
strrchr
(
prefix
,
'/'
)))
basename
++
;
else
basename
=
prefix
;
if
(
!
(
ext
=
strchr
(
basename
,
'.'
)))
ext
=
prefix
+
strlen
(
prefix
);
name
=
xmalloc
(
sizeof
(
"/tmp/"
)
+
(
ext
-
prefix
)
+
sizeof
(
".XXXXXX"
)
+
strlen
(
suffix
)
);
memcpy
(
name
,
prefix
,
ext
-
prefix
);
strcpy
(
name
+
(
ext
-
prefix
),
".XXXXXX"
);
strcat
(
name
,
suffix
);
if
((
fd
=
mkstemps
(
name
,
strlen
(
suffix
)
))
==
-
1
)
{
{
strcpy
(
name
,
"/tmp/"
);
if
((
basename
=
strrchr
(
prefix
,
'/'
)))
basename
++
;
memcpy
(
name
+
5
,
basename
,
ext
-
basename
);
else
basename
=
prefix
;
strcpy
(
name
+
5
+
(
ext
-
basename
),
".XXXXXX"
);
if
((
ext
=
strchr
(
basename
,
'.'
)))
prefix
=
strmake
(
"%.*s"
,
ext
-
basename
,
basename
);
strcat
(
name
,
suffix
);
else
prefix
=
basename
;
if
((
fd
=
mkstemps
(
name
,
strlen
(
suffix
)
))
==
-
1
)
fatal_error
(
"could not generate a temp file
\n
"
);
}
}
fd
=
make_temp_file
(
prefix
,
suffix
,
&
name
);
close
(
fd
);
close
(
fd
);
strarray_add
(
&
tmp_files
,
name
);
strarray_add
(
&
tmp_files
,
name
);
return
name
;
return
name
;
...
...
tools/winegcc/winegcc.c
View file @
55701c66
...
@@ -297,25 +297,14 @@ static void exit_on_signal( int sig )
...
@@ -297,25 +297,14 @@ static void exit_on_signal( int sig )
static
char
*
get_temp_file
(
const
char
*
prefix
,
const
char
*
suffix
)
static
char
*
get_temp_file
(
const
char
*
prefix
,
const
char
*
suffix
)
{
{
int
fd
;
int
fd
;
char
*
tmp
=
strmake
(
"%s-XXXXXX%s"
,
prefix
,
suffix
)
;
char
*
tmp
;
#ifdef HAVE_SIGPROCMASK
#ifdef HAVE_SIGPROCMASK
sigset_t
old_set
;
sigset_t
old_set
;
/* block signals while manipulating the temp files list */
/* block signals while manipulating the temp files list */
sigprocmask
(
SIG_BLOCK
,
&
signal_mask
,
&
old_set
);
sigprocmask
(
SIG_BLOCK
,
&
signal_mask
,
&
old_set
);
#endif
#endif
fd
=
mkstemps
(
tmp
,
strlen
(
suffix
)
);
fd
=
make_temp_file
(
prefix
,
suffix
,
&
tmp
);
if
(
fd
==
-
1
)
{
/* could not create it in current directory, try in TMPDIR */
const
char
*
tmpdir
;
free
(
tmp
);
if
(
!
(
tmpdir
=
getenv
(
"TMPDIR"
)))
tmpdir
=
"/tmp"
;
tmp
=
strmake
(
"%s/%s-XXXXXX%s"
,
tmpdir
,
prefix
,
suffix
);
fd
=
mkstemps
(
tmp
,
strlen
(
suffix
)
);
if
(
fd
==
-
1
)
error
(
"could not create temp file
\n
"
);
}
close
(
fd
);
close
(
fd
);
strarray_add
(
&
tmp_files
,
tmp
);
strarray_add
(
&
tmp_files
,
tmp
);
#ifdef HAVE_SIGPROCMASK
#ifdef HAVE_SIGPROCMASK
...
...
tools/wrc/genres.c
View file @
55701c66
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "genres.h"
#include "genres.h"
#include "utils.h"
#include "utils.h"
...
...
tools/wrc/newstruc.c
View file @
55701c66
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include <assert.h>
#include <assert.h>
#include <ctype.h>
#include <ctype.h>
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "newstruc.h"
#include "newstruc.h"
#include "utils.h"
#include "utils.h"
...
...
tools/wrc/parser.l
View file @
55701c66
...
@@ -111,6 +111,7 @@ ws [ \f\t\r]
...
@@ -111,6 +111,7 @@ ws [ \f\t\r]
#define YY_NO_UNISTD_H
#define YY_NO_UNISTD_H
#endif
#endif
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "utils.h"
#include "utils.h"
#include "parser.h"
#include "parser.h"
...
...
tools/wrc/parser.y
View file @
55701c66
...
@@ -130,6 +130,7 @@
...
@@ -130,6 +130,7 @@
#include
<ctype
.
h
>
#include
<ctype
.
h
>
#include
<string
.
h
>
#include
<string
.
h
>
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "utils.h"
#include "utils.h"
#include "newstruc.h"
#include "newstruc.h"
...
...
tools/wrc/po.c
View file @
55701c66
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include <gettext-po.h>
#include <gettext-po.h>
#endif
#endif
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "genres.h"
#include "genres.h"
#include "newstruc.h"
#include "newstruc.h"
...
...
tools/wrc/ppl.l
View file @
55701c66
...
@@ -173,6 +173,7 @@ ul [uUlL]|[uUlL][lL]|[lL][uU]|[lL][lL][uU]|[uU][lL][lL]|[lL][uU][lL]
...
@@ -173,6 +173,7 @@ ul [uUlL]|[uUlL][lL]|[lL][uU]|[lL][lL][uU]|[uU][lL][lL]|[lL][uU][lL]
#define YY_NO_UNISTD_H
#define YY_NO_UNISTD_H
#endif
#endif
#include "../tools.h"
#include "utils.h"
#include "utils.h"
#include "wpp_private.h"
#include "wpp_private.h"
#include "ppy.tab.h"
#include "ppy.tab.h"
...
...
tools/wrc/ppy.y
View file @
55701c66
...
@@ -30,6 +30,7 @@
...
@@ -30,6 +30,7 @@
#include <ctype.h>
#include <ctype.h>
#include <string.h>
#include <string.h>
#include "../tools.h"
#include "utils.h"
#include "utils.h"
#include "wpp_private.h"
#include "wpp_private.h"
...
...
tools/wrc/translation.c
View file @
55701c66
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <stdlib.h>
#include <stdlib.h>
#include <assert.h>
#include <assert.h>
#include "../tools.h"
#include "dumpres.h"
#include "dumpres.h"
#include "utils.h"
#include "utils.h"
#include "wrc.h"
#include "wrc.h"
...
...
tools/wrc/utils.c
View file @
55701c66
...
@@ -28,6 +28,7 @@
...
@@ -28,6 +28,7 @@
#include <string.h>
#include <string.h>
#include <ctype.h>
#include <ctype.h>
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "utils.h"
#include "utils.h"
#include "parser.h"
#include "parser.h"
...
...
tools/wrc/wpp.c
View file @
55701c66
...
@@ -34,6 +34,7 @@
...
@@ -34,6 +34,7 @@
# include <unistd.h>
# include <unistd.h>
#endif
#endif
#include "../tools.h"
#include "utils.h"
#include "utils.h"
#include "wpp_private.h"
#include "wpp_private.h"
...
...
tools/wrc/wpp_private.h
View file @
55701c66
...
@@ -22,7 +22,6 @@
...
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <string.h>
#include "../tools.h"
#include "wine/list.h"
#include "wine/list.h"
extern
void
wpp_del_define
(
const
char
*
name
);
extern
void
wpp_del_define
(
const
char
*
name
);
...
...
tools/wrc/wrc.c
View file @
55701c66
...
@@ -35,6 +35,7 @@
...
@@ -35,6 +35,7 @@
# include <getopt.h>
# include <getopt.h>
#endif
#endif
#include "../tools.h"
#include "wrc.h"
#include "wrc.h"
#include "utils.h"
#include "utils.h"
#include "dumpres.h"
#include "dumpres.h"
...
@@ -280,12 +281,7 @@ static int load_file( const char *input_name, const char *output_name )
...
@@ -280,12 +281,7 @@ static int load_file( const char *input_name, const char *output_name )
exit
(
0
);
exit
(
0
);
}
}
if
(
output_name
&&
output_name
[
0
])
name
=
strmake
(
"%s.XXXXXX"
,
output_name
);
fd
=
make_temp_file
(
output_name
,
""
,
&
name
);
else
name
=
xstrdup
(
"wrc.XXXXXX"
);
if
((
fd
=
mkstemps
(
name
,
0
))
==
-
1
)
error
(
"Could not generate a temp name from %s
\n
"
,
name
);
temp_name
=
name
;
temp_name
=
name
;
if
(
!
(
output
=
fdopen
(
fd
,
"wt"
)))
if
(
!
(
output
=
fdopen
(
fd
,
"wt"
)))
error
(
"Could not open fd %s for writing
\n
"
,
name
);
error
(
"Could not open fd %s for writing
\n
"
,
name
);
...
...
tools/wrc/wrc.h
View file @
55701c66
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#ifndef __WRC_WRC_H
#ifndef __WRC_WRC_H
#define __WRC_WRC_H
#define __WRC_WRC_H
#include "../tools.h"
#include "wrctypes.h"
#include "wrctypes.h"
/* From wrc.c */
/* From wrc.c */
...
...
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