Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Michael A. (Mike) Iovine
p1
Commits
2bac0fe7
Commit
2bac0fe7
authored
5 years ago
by
Mike Iovine
Browse files
Options
Download
Email Patches
Plain Diff
Check that suffix of input file ends in '.deflate'
parent
40347982
master
No related merge requests found
Pipeline
#30252
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
inflate.c
+18
-4
inflate.c
with
18 additions
and
4 deletions
+18
-4
inflate.c
View file @
2bac0fe7
...
...
@@ -424,9 +424,24 @@ void read_block(char *buf, FILE *out) {
}
}
void
inflate
(
FILE
*
fp
)
{
void
truncate_suffix
(
char
*
fname
)
{
char
*
dot
=
strrchr
(
fname
,
'.'
);
char
*
suffix
=
".deflate"
;
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
if
(
dot
==
NULL
||
*
(
dot
+
i
)
!=
suffix
[
i
])
{
fprintf
(
stderr
,
"error: must be a .deflate file"
);
exit
(
1
);
}
}
*
dot
=
'\0'
;
}
void
inflate
(
FILE
*
fp
,
char
*
fname
)
{
truncate_suffix
(
fname
);
/* Create output file */
FILE
*
out
=
fopen
(
"test.txt"
,
"wb+"
);
FILE
*
out
=
fopen
(
fname
,
"wb+"
);
/* Read the file into a buffer */
fseek
(
fp
,
0
,
SEEK_END
);
...
...
@@ -441,7 +456,6 @@ void inflate(FILE *fp) {
while
(
_CUR_BIT
<
8
*
size
)
{
read_block
(
buf
,
out
);
break
;
}
fclose
(
out
);
...
...
@@ -463,7 +477,7 @@ int main(int argc, char *argv[]) {
return
1
;
}
inflate
(
fp
);
inflate
(
fp
,
fname
);
fclose
(
fp
);
return
0
;
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help