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
2a08d6ce
Commit
2a08d6ce
authored
Sep 28, 2021
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: Add helper functions to spawn a command from an strarray.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
97ca9f8a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
23 deletions
+54
-23
tools.h
tools/tools.h
+48
-0
utils.c
tools/winebuild/utils.c
+2
-6
utils.c
tools/winegcc/utils.c
+4
-17
No files found.
tools/tools.h
View file @
2a08d6ce
...
...
@@ -25,6 +25,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <errno.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#if defined(_WIN32) && !defined(__CYGWIN__)
# include <process.h>
#else
# include <sys/wait.h>
# include <unistd.h>
#endif
#if !defined(__GNUC__) && !defined(__attribute__)
#define __attribute__(x)
...
...
@@ -200,5 +212,41 @@ static inline const char *strarray_bsearch( const struct strarray *array, const
return
res
?
*
res
:
NULL
;
}
static
inline
void
strarray_trace
(
struct
strarray
args
)
{
unsigned
int
i
;
for
(
i
=
0
;
i
<
args
.
count
;
i
++
)
{
if
(
strpbrk
(
args
.
str
[
i
],
"
\t\n\r
"
))
printf
(
"
\"
%s
\"
"
,
args
.
str
[
i
]
);
else
printf
(
"%s"
,
args
.
str
[
i
]
);
putchar
(
i
<
args
.
count
-
1
?
' '
:
'\n'
);
}
}
static
inline
int
strarray_spawn
(
struct
strarray
args
)
{
#if defined(_WIN32) && !defined(__CYGWIN__)
strarray_add
(
&
args
,
NULL
);
return
_spawnvp
(
_P_WAIT
,
args
.
str
[
0
],
args
.
str
);
#else
pid_t
pid
,
wret
;
int
status
;
if
(
!
(
pid
=
fork
()))
{
strarray_add
(
&
args
,
NULL
);
execvp
(
args
.
str
[
0
],
(
char
**
)
args
.
str
);
_exit
(
1
);
}
if
(
pid
==
-
1
)
return
-
1
;
while
(
pid
!=
(
wret
=
waitpid
(
pid
,
&
status
,
0
)))
if
(
wret
==
-
1
&&
errno
!=
EINTR
)
break
;
if
(
pid
==
wret
&&
WIFEXITED
(
status
))
return
WEXITSTATUS
(
status
);
return
255
;
/* abnormal exit with an abort or an interrupt */
#endif
}
#endif
/* __WINE_TOOLS_H */
tools/winebuild/utils.c
View file @
2a08d6ce
...
...
@@ -206,17 +206,13 @@ static const char *find_binary( const char *prefix, const char *name )
void
spawn
(
struct
strarray
args
)
{
unsigned
int
i
;
int
status
;
const
char
*
argv0
=
find_binary
(
NULL
,
args
.
str
[
0
]
);
if
(
argv0
)
args
.
str
[
0
]
=
argv0
;
strarray_add
(
&
args
,
NULL
);
if
(
verbose
)
for
(
i
=
0
;
args
.
str
[
i
];
i
++
)
fprintf
(
stderr
,
"%s%c"
,
args
.
str
[
i
],
args
.
str
[
i
+
1
]
?
' '
:
'\n'
);
if
(
verbose
)
strarray_trace
(
args
);
if
((
status
=
_spawnvp
(
_P_WAIT
,
args
.
str
[
0
],
args
.
str
)))
if
((
status
=
strarray_spawn
(
args
)))
{
if
(
status
>
0
)
fatal_error
(
"%s failed with status %u
\n
"
,
args
.
str
[
0
],
status
);
else
fatal_perror
(
"winebuild"
);
...
...
tools/winegcc/utils.c
View file @
2a08d6ce
...
...
@@ -197,27 +197,14 @@ const char *find_binary( struct strarray prefix, const char *name )
int
spawn
(
struct
strarray
prefix
,
struct
strarray
args
,
int
ignore_errors
)
{
unsigned
int
i
;
int
status
;
const
char
**
argv
;
strarray_add
(
&
args
,
NULL
);
argv
=
args
.
str
;
argv
[
0
]
=
find_binary
(
prefix
,
argv
[
0
]
);
if
(
verbose
)
{
for
(
i
=
0
;
argv
[
i
];
i
++
)
{
if
(
strpbrk
(
argv
[
i
],
"
\t\n\r
"
))
printf
(
"
\"
%s
\"
"
,
argv
[
i
]);
else
printf
(
"%s "
,
argv
[
i
]);
}
printf
(
"
\n
"
);
}
args
.
str
[
0
]
=
find_binary
(
prefix
,
args
.
str
[
0
]
);
if
(
verbose
)
strarray_trace
(
args
);
if
((
status
=
_spawnvp
(
_P_WAIT
,
argv
[
0
],
argv
))
&&
!
ignore_errors
)
if
((
status
=
strarray_spawn
(
args
))
&&
!
ignore_errors
)
{
if
(
status
>
0
)
error
(
"%s failed
\n
"
,
arg
v
[
0
]);
if
(
status
>
0
)
error
(
"%s failed
\n
"
,
arg
s
.
str
[
0
]);
else
perror
(
"winegcc"
);
exit
(
3
);
}
...
...
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