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
2ab5d5b5
Commit
2ab5d5b5
authored
May 02, 2024
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
better die func
parent
d4e18be0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
12 deletions
+15
-12
main.c
avtomat/main.c
+15
-12
No files found.
avtomat/main.c
View file @
2ab5d5b5
...
...
@@ -7,7 +7,7 @@
#include <unistd.h>
void
usage
();
void
die
(
const
char
*
);
void
die
(
const
char
*
format
,
...
);
char
*
get_default_filepath
(
char
*
,
char
*
);
void
download_file
(
char
*
url
,
char
*
filepath
,
CURL
*
curl
);
int
file_exists
(
const
char
*
filename
);
...
...
@@ -27,6 +27,7 @@ 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
();
...
...
@@ -83,7 +84,7 @@ main(int argc, char** argv)
url_file
=
fopen
(
url_file_path
,
"r"
);
if
(
!
url_file
)
die
(
"Could not open given url file
!"
);
die
(
"Could not open given url file
%s!"
,
url_file_path
);
while
(
getline
(
&
curr_url
,
&
url_len
,
url_file
)
!=
-
1
){
...
...
@@ -101,9 +102,9 @@ main(int argc, char** argv)
filepaths_file
=
fopen
(
filepaths_file_path
,
"r"
);
if
(
!
url_file
)
die
(
"Could not open given url file
!"
);
die
(
"Could not open given url file
%s!"
,
url_file_path
);
if
(
!
filepaths_file
)
die
(
"Could not open given filepath
s file!"
);
die
(
"Could not open given filepath
file %s!"
,
filepaths_file_path
);
while
(
getline
(
&
curr_url
,
&
filepath_len
,
url_file
)
!=
-
1
){
...
...
@@ -119,6 +120,7 @@ main(int argc, char** argv)
}
free
(
place_holder
);
free
(
curr_url
);
free
(
curr_filepath
);
fclose
(
url_file
);
fclose
(
filepaths_file
);
break
;
...
...
@@ -126,11 +128,13 @@ main(int argc, char** argv)
curl_easy_cleanup
(
curl
);
return
0
;
}
void
die
(
const
char
*
error
)
{
fprintf
(
stderr
,
"Error: %s
\n
"
,
error
);
die
(
const
char
*
format
,
...)
{
va_list
args
;
va_start
(
args
,
format
);
vfprintf
(
stderr
,
format
,
args
);
va_end
(
args
);
fputc
(
'\n'
,
stderr
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -173,7 +177,6 @@ get_default_filepath(char *url, char *place_holder)
filepath
=
tmp
;
tmp
=
strtok
(
NULL
,
"/"
);
}
// TODO: Move memory allocation and deallocation logic to the caller function for better resource management.
return
filepath
;
}
...
...
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