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
c562952f
Commit
c562952f
authored
Jan 19, 2022
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: Add a helper function to read the contents of a file.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
49326cb2
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
58 additions
and
79 deletions
+58
-79
tools.h
tools/tools.h
+22
-0
utils.c
tools/winebuild/utils.c
+2
-11
dump.c
tools/winedump/dump.c
+3
-13
winedump.h
tools/winedump/winedump.h
+1
-1
po.c
tools/wmc/po.c
+7
-15
utils.c
tools/wmc/utils.c
+8
-12
po.c
tools/wrc/po.c
+7
-15
utils.c
tools/wrc/utils.c
+8
-12
No files found.
tools/tools.h
View file @
c562952f
...
...
@@ -350,6 +350,28 @@ static inline int make_temp_file( const char *prefix, const char *suffix, char *
}
static
inline
void
*
read_file
(
const
char
*
name
,
size_t
*
size
)
{
struct
stat
st
;
int
res
,
fd
;
void
*
data
;
if
((
fd
=
open
(
name
,
O_RDONLY
|
O_BINARY
))
==
-
1
)
return
NULL
;
fstat
(
fd
,
&
st
);
data
=
xmalloc
(
st
.
st_size
);
res
=
read
(
fd
,
data
,
st
.
st_size
);
if
(
res
==
-
1
)
{
free
(
data
);
data
=
NULL
;
*
size
=
0
;
}
else
*
size
=
res
;
close
(
fd
);
return
data
;
}
static
inline
struct
target
get_default_target
(
void
)
{
struct
target
target
;
...
...
tools/winebuild/utils.c
View file @
c562952f
...
...
@@ -434,18 +434,9 @@ size_t output_buffer_size;
void
init_input_buffer
(
const
char
*
file
)
{
int
fd
;
struct
stat
st
;
unsigned
char
*
buffer
;
if
((
fd
=
open
(
file
,
O_RDONLY
|
O_BINARY
))
==
-
1
)
fatal_perror
(
"Cannot open %s"
,
file
);
if
((
fstat
(
fd
,
&
st
)
==
-
1
))
fatal_perror
(
"Cannot stat %s"
,
file
);
if
(
!
st
.
st_size
)
fatal_error
(
"%s is an empty file
\n
"
,
file
);
input_buffer
=
buffer
=
xmalloc
(
st
.
st_size
);
if
(
read
(
fd
,
buffer
,
st
.
st_size
)
!=
st
.
st_size
)
fatal_error
(
"Cannot read %s
\n
"
,
file
);
close
(
fd
);
if
(
!
(
input_buffer
=
read_file
(
file
,
&
input_buffer_size
)))
fatal_perror
(
"Cannot read %s"
,
file
);
if
(
!
input_buffer_size
)
fatal_error
(
"%s is an empty file
\n
"
,
file
);
input_buffer_filename
=
xstrdup
(
file
);
input_buffer_size
=
st
.
st_size
;
input_buffer_pos
=
0
;
byte_swapped
=
0
;
}
...
...
tools/winedump/dump.c
View file @
c562952f
...
...
@@ -31,7 +31,7 @@
#include "winedump.h"
void
*
dump_base
=
NULL
;
unsigned
long
dump_total_len
=
0
;
size_t
dump_total_len
=
0
;
void
dump_data
(
const
unsigned
char
*
ptr
,
unsigned
int
size
,
const
char
*
prefix
)
{
...
...
@@ -264,23 +264,14 @@ dumpers[] =
BOOL
dump_analysis
(
const
char
*
name
,
file_dumper
fn
,
enum
FileSig
wanted_sig
)
{
int
fd
;
BOOL
ret
=
TRUE
;
struct
stat
s
;
const
struct
dumper
*
dpr
;
setbuf
(
stdout
,
NULL
);
fd
=
open
(
name
,
O_RDONLY
|
O_BINARY
);
if
(
fd
==
-
1
)
fatal
(
"Can't open file"
);
if
(
!
(
dump_base
=
read_file
(
name
,
&
dump_total_len
)))
fatal
(
"Cannot read file"
);
if
(
fstat
(
fd
,
&
s
)
<
0
)
fatal
(
"Can't get size"
);
dump_total_len
=
s
.
st_size
;
dump_base
=
xmalloc
(
dump_total_len
);
if
((
unsigned
long
)
read
(
fd
,
dump_base
,
dump_total_len
)
!=
dump_total_len
)
fatal
(
"Cannot read file"
);
printf
(
"Contents of %s: %ld bytes
\n\n
"
,
name
,
dump_total_len
);
printf
(
"Contents of %s: %zu bytes
\n\n
"
,
name
,
dump_total_len
);
for
(
dpr
=
dumpers
;
dpr
->
kind
!=
SIG_UNKNOWN
;
dpr
++
)
{
...
...
@@ -299,7 +290,6 @@ BOOL dump_analysis(const char *name, file_dumper fn, enum FileSig wanted_sig)
if
(
ret
)
printf
(
"Done dumping %s
\n
"
,
name
);
free
(
dump_base
);
close
(
fd
);
return
ret
;
}
...
...
tools/winedump/winedump.h
View file @
c562952f
...
...
@@ -139,7 +139,7 @@ typedef struct __globals
extern
_globals
globals
;
extern
void
*
dump_base
;
extern
unsigned
long
dump_total_len
;
extern
size_t
dump_total_len
;
/* Names to use for output DLL */
#define OUTPUT_DLL_NAME \
...
...
tools/wmc/po.c
View file @
c562952f
...
...
@@ -542,21 +542,13 @@ static void byteswap( unsigned int *data, unsigned int count )
static
void
load_mo_file
(
const
char
*
name
)
{
struct
stat
st
;
int
res
,
fd
;
fd
=
open
(
name
,
O_RDONLY
|
O_BINARY
);
if
(
fd
==
-
1
)
fatal_perror
(
"Failed to open %s"
,
name
);
fstat
(
fd
,
&
st
);
mo_file
=
xmalloc
(
st
.
st_size
);
res
=
read
(
fd
,
mo_file
,
st
.
st_size
);
if
(
res
==
-
1
)
fatal_perror
(
"Failed to read %s"
,
name
);
else
if
(
res
!=
st
.
st_size
)
error
(
"Failed to read %s
\n
"
,
name
);
close
(
fd
);
size_t
size
;
if
(
!
(
mo_file
=
read_file
(
name
,
&
size
)))
fatal_perror
(
"Failed to read %s"
,
name
);
/* sanity checks */
if
(
s
t
.
st_s
ize
<
sizeof
(
*
mo_file
))
if
(
size
<
sizeof
(
*
mo_file
))
error
(
"%s is not a valid .mo file
\n
"
,
name
);
if
(
mo_file
->
magic
==
0xde120495
)
byteswap
(
&
mo_file
->
revision
,
4
);
...
...
@@ -564,9 +556,9 @@ static void load_mo_file( const char *name )
error
(
"%s is not a valid .mo file
\n
"
,
name
);
if
((
mo_file
->
revision
>>
16
)
>
1
)
error
(
"%s: unsupported file version %x
\n
"
,
name
,
mo_file
->
revision
);
if
(
mo_file
->
msgid_off
>=
s
t
.
st_s
ize
||
mo_file
->
msgstr_off
>=
s
t
.
st_s
ize
||
s
t
.
st_s
ize
<
sizeof
(
*
mo_file
)
+
2
*
8
*
mo_file
->
count
)
if
(
mo_file
->
msgid_off
>=
size
||
mo_file
->
msgstr_off
>=
size
||
size
<
sizeof
(
*
mo_file
)
+
2
*
8
*
mo_file
->
count
)
error
(
"%s: corrupted file
\n
"
,
name
);
if
(
mo_file
->
magic
==
0xde120495
)
...
...
tools/wmc/utils.c
View file @
c562952f
...
...
@@ -356,11 +356,10 @@ static void init_nls_info( struct nls_info *info, unsigned short *ptr )
static
const
struct
nls_info
*
get_nls_info
(
unsigned
int
codepage
)
{
struct
stat
st
;
unsigned
short
*
data
;
char
*
path
;
unsigned
int
i
;
int
fd
;
size_t
size
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
nlsinfo
)
&&
nlsinfo
[
i
].
codepage
;
i
++
)
if
(
nlsinfo
[
i
].
codepage
==
codepage
)
return
&
nlsinfo
[
i
];
...
...
@@ -370,18 +369,15 @@ static const struct nls_info *get_nls_info( unsigned int codepage )
for
(
i
=
0
;
nlsdirs
[
i
];
i
++
)
{
path
=
strmake
(
"%s/c_%03u.nls"
,
nlsdirs
[
i
],
codepage
);
if
((
fd
=
open
(
path
,
O_RDONLY
))
!=
-
1
)
break
;
if
((
data
=
read_file
(
path
,
&
size
)))
{
free
(
path
);
init_nls_info
(
&
nlsinfo
[
i
],
data
);
return
&
nlsinfo
[
i
];
}
free
(
path
);
}
if
(
!
nlsdirs
[
i
])
return
NULL
;
fstat
(
fd
,
&
st
);
data
=
xmalloc
(
st
.
st_size
);
if
(
read
(
fd
,
data
,
st
.
st_size
)
!=
st
.
st_size
)
error
(
"failed to load %s
\n
"
,
path
);
close
(
fd
);
free
(
path
);
init_nls_info
(
&
nlsinfo
[
i
],
data
);
return
&
nlsinfo
[
i
];
return
NULL
;
}
int
is_valid_codepage
(
int
cp
)
...
...
tools/wrc/po.c
View file @
c562952f
...
...
@@ -1102,21 +1102,13 @@ static void byteswap( unsigned int *data, unsigned int count )
static
void
load_mo_file
(
const
char
*
name
)
{
struct
stat
st
;
int
res
,
fd
;
fd
=
open
(
name
,
O_RDONLY
|
O_BINARY
);
if
(
fd
==
-
1
)
fatal_perror
(
"Failed to open %s"
,
name
);
fstat
(
fd
,
&
st
);
mo_file
=
xmalloc
(
st
.
st_size
);
res
=
read
(
fd
,
mo_file
,
st
.
st_size
);
if
(
res
==
-
1
)
fatal_perror
(
"Failed to read %s"
,
name
);
else
if
(
res
!=
st
.
st_size
)
error
(
"Failed to read %s
\n
"
,
name
);
close
(
fd
);
size_t
size
;
if
(
!
(
mo_file
=
read_file
(
name
,
&
size
)))
fatal_perror
(
"Failed to read %s"
,
name
);
/* sanity checks */
if
(
s
t
.
st_s
ize
<
sizeof
(
*
mo_file
))
if
(
size
<
sizeof
(
*
mo_file
))
error
(
"%s is not a valid .mo file
\n
"
,
name
);
if
(
mo_file
->
magic
==
0xde120495
)
byteswap
(
&
mo_file
->
revision
,
4
);
...
...
@@ -1124,9 +1116,9 @@ static void load_mo_file( const char *name )
error
(
"%s is not a valid .mo file
\n
"
,
name
);
if
((
mo_file
->
revision
>>
16
)
>
1
)
error
(
"%s: unsupported file version %x
\n
"
,
name
,
mo_file
->
revision
);
if
(
mo_file
->
msgid_off
>=
s
t
.
st_s
ize
||
mo_file
->
msgstr_off
>=
s
t
.
st_s
ize
||
s
t
.
st_s
ize
<
sizeof
(
*
mo_file
)
+
2
*
8
*
mo_file
->
count
)
if
(
mo_file
->
msgid_off
>=
size
||
mo_file
->
msgstr_off
>=
size
||
size
<
sizeof
(
*
mo_file
)
+
2
*
8
*
mo_file
->
count
)
error
(
"%s: corrupted file
\n
"
,
name
);
if
(
mo_file
->
magic
==
0xde120495
)
...
...
tools/wrc/utils.c
View file @
c562952f
...
...
@@ -237,11 +237,10 @@ static void init_nls_info( struct nls_info *info, unsigned short *ptr )
static
const
struct
nls_info
*
get_nls_info
(
unsigned
int
codepage
)
{
struct
stat
st
;
unsigned
short
*
data
;
char
*
path
;
unsigned
int
i
;
int
fd
;
size_t
size
;
for
(
i
=
0
;
i
<
ARRAY_SIZE
(
nlsinfo
)
&&
nlsinfo
[
i
].
codepage
;
i
++
)
if
(
nlsinfo
[
i
].
codepage
==
codepage
)
return
&
nlsinfo
[
i
];
...
...
@@ -251,18 +250,15 @@ static const struct nls_info *get_nls_info( unsigned int codepage )
for
(
i
=
0
;
nlsdirs
[
i
];
i
++
)
{
path
=
strmake
(
"%s/c_%03u.nls"
,
nlsdirs
[
i
],
codepage
);
if
((
fd
=
open
(
path
,
O_RDONLY
))
!=
-
1
)
break
;
if
((
data
=
read_file
(
path
,
&
size
)))
{
free
(
path
);
init_nls_info
(
&
nlsinfo
[
i
],
data
);
return
&
nlsinfo
[
i
];
}
free
(
path
);
}
if
(
!
nlsdirs
[
i
])
return
NULL
;
fstat
(
fd
,
&
st
);
data
=
xmalloc
(
st
.
st_size
);
if
(
read
(
fd
,
data
,
st
.
st_size
)
!=
st
.
st_size
)
error
(
"failed to load %s
\n
"
,
path
);
close
(
fd
);
free
(
path
);
init_nls_info
(
&
nlsinfo
[
i
],
data
);
return
&
nlsinfo
[
i
];
return
NULL
;
}
int
is_valid_codepage
(
int
cp
)
...
...
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