Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
C programming 2nd term
Project
Project
Details
Activity
Releases
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
Ильин Владимир Александрович
C programming 2nd term
Commits
d4e18be0
Commit
d4e18be0
authored
May 02, 2024
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Фикс памяти в get_default_filepath
parent
65a62362
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
11 deletions
+10
-11
main.c
avtomat/main.c
+10
-11
No files found.
avtomat/main.c
View file @
d4e18be0
...
...
@@ -8,7 +8,7 @@
void
usage
();
void
die
(
const
char
*
);
char
*
get_default_filepath
(
char
*
);
char
*
get_default_filepath
(
char
*
,
char
*
);
void
download_file
(
char
*
url
,
char
*
filepath
,
CURL
*
curl
);
int
file_exists
(
const
char
*
filename
);
...
...
@@ -26,13 +26,13 @@ main(int argc, char** argv)
char
*
url_file_path
=
NULL
;
char
*
filepaths_file_path
=
NULL
;
char
*
place_holder
=
NULL
;
// for get_default_filepath func
//get args
if
(
argc
==
1
)
usage
();
else
if
(
argc
==
2
){
url
=
argv
[
1
];
filepath
=
get_default_filepath
(
url
);
filepath
=
get_default_filepath
(
url
,
place_holder
);
}
else
{
for
(
int
i
=
1
;
i
<
argc
;
i
++
)
if
(
!
strcmp
(
argv
[
i
],
"-f"
))
...
...
@@ -74,7 +74,6 @@ main(int argc, char** argv)
size_t
url_len
=
0
;
size_t
filepath_len
=
0
;
switch
(
download_type
){
case
URL_ONLY
:
download_file
(
url
,
filepath
,
curl
);
...
...
@@ -91,9 +90,9 @@ main(int argc, char** argv)
if
(
curr_url
[
strlen
(
curr_url
)
-
1
]
==
'\n'
)
curr_url
[
strlen
(
curr_url
)
-
1
]
=
'\0'
;
download_file
(
curr_url
,
get_default_filepath
(
curr_url
),
curl
);
download_file
(
curr_url
,
get_default_filepath
(
curr_url
,
place_holder
),
curl
);
}
free
(
place_holder
);
free
(
curr_url
);
fclose
(
url_file
);
break
;
...
...
@@ -109,7 +108,7 @@ main(int argc, char** argv)
while
(
getline
(
&
curr_url
,
&
filepath_len
,
url_file
)
!=
-
1
){
if
(
getline
(
&
curr_filepath
,
&
url_len
,
filepaths_file
)
==
-
1
)
curr_filepath
=
get_default_filepath
(
curr_url
);
curr_filepath
=
get_default_filepath
(
curr_url
,
place_holder
);
if
(
curr_filepath
[
strlen
(
curr_filepath
)
-
1
]
==
'\n'
)
curr_filepath
[
strlen
(
curr_filepath
)
-
1
]
=
'\0'
;
...
...
@@ -118,10 +117,10 @@ main(int argc, char** argv)
download_file
(
curr_url
,
curr_filepath
,
curl
);
}
free
(
place_holder
);
free
(
curr_url
);
fclose
(
url_file
);
fclose
(
filepaths_file
);
break
;
}
curl_easy_cleanup
(
curl
);
...
...
@@ -159,9 +158,9 @@ download_file(char *url, char *filepath, CURL *curl)
}
char
*
get_default_filepath
(
char
*
url
)
get_default_filepath
(
char
*
url
,
char
*
place_holder
)
{
char
*
url_copy
=
malloc
(
strlen
(
url
)
+
1
);
char
*
url_copy
=
realloc
(
place_holder
,
strlen
(
url
)
+
1
);
if
(
!
url_copy
)
{
die
(
"Malloc failed!"
);
}
...
...
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