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
Hide 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 @@
...
@@ -7,7 +7,7 @@
#include <unistd.h>
#include <unistd.h>
void
usage
();
void
usage
();
void
die
(
const
char
*
);
void
die
(
const
char
*
format
,
...
);
char
*
get_default_filepath
(
char
*
,
char
*
);
char
*
get_default_filepath
(
char
*
,
char
*
);
void
download_file
(
char
*
url
,
char
*
filepath
,
CURL
*
curl
);
void
download_file
(
char
*
url
,
char
*
filepath
,
CURL
*
curl
);
int
file_exists
(
const
char
*
filename
);
int
file_exists
(
const
char
*
filename
);
...
@@ -27,6 +27,7 @@ main(int argc, char** argv)
...
@@ -27,6 +27,7 @@ main(int argc, char** argv)
char
*
url_file_path
=
NULL
;
char
*
url_file_path
=
NULL
;
char
*
filepaths_file_path
=
NULL
;
char
*
filepaths_file_path
=
NULL
;
char
*
place_holder
=
NULL
;
// for get_default_filepath func
char
*
place_holder
=
NULL
;
// for get_default_filepath func
//get args
//get args
if
(
argc
==
1
)
if
(
argc
==
1
)
usage
();
usage
();
...
@@ -83,9 +84,9 @@ main(int argc, char** argv)
...
@@ -83,9 +84,9 @@ main(int argc, char** argv)
url_file
=
fopen
(
url_file_path
,
"r"
);
url_file
=
fopen
(
url_file_path
,
"r"
);
if
(
!
url_file
)
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
){
while
(
getline
(
&
curr_url
,
&
url_len
,
url_file
)
!=
-
1
){
if
(
curr_url
[
strlen
(
curr_url
)
-
1
]
==
'\n'
)
if
(
curr_url
[
strlen
(
curr_url
)
-
1
]
==
'\n'
)
curr_url
[
strlen
(
curr_url
)
-
1
]
=
'\0'
;
curr_url
[
strlen
(
curr_url
)
-
1
]
=
'\0'
;
...
@@ -101,9 +102,9 @@ main(int argc, char** argv)
...
@@ -101,9 +102,9 @@ main(int argc, char** argv)
filepaths_file
=
fopen
(
filepaths_file_path
,
"r"
);
filepaths_file
=
fopen
(
filepaths_file_path
,
"r"
);
if
(
!
url_file
)
if
(
!
url_file
)
die
(
"Could not open given url file
!"
);
die
(
"Could not open given url file
%s!"
,
url_file_path
);
if
(
!
filepaths_file
)
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
){
while
(
getline
(
&
curr_url
,
&
filepath_len
,
url_file
)
!=
-
1
){
...
@@ -119,6 +120,7 @@ main(int argc, char** argv)
...
@@ -119,6 +120,7 @@ main(int argc, char** argv)
}
}
free
(
place_holder
);
free
(
place_holder
);
free
(
curr_url
);
free
(
curr_url
);
free
(
curr_filepath
);
fclose
(
url_file
);
fclose
(
url_file
);
fclose
(
filepaths_file
);
fclose
(
filepaths_file
);
break
;
break
;
...
@@ -126,12 +128,14 @@ main(int argc, char** argv)
...
@@ -126,12 +128,14 @@ main(int argc, char** argv)
curl_easy_cleanup
(
curl
);
curl_easy_cleanup
(
curl
);
return
0
;
return
0
;
}
}
void
void
die
(
const
char
*
format
,
...)
{
die
(
const
char
*
error
)
va_list
args
;
{
va_start
(
args
,
format
);
fprintf
(
stderr
,
"Error: %s
\n
"
,
error
);
vfprintf
(
stderr
,
format
,
args
);
exit
(
EXIT_FAILURE
);
va_end
(
args
);
fputc
(
'\n'
,
stderr
);
exit
(
EXIT_FAILURE
);
}
}
void
void
...
@@ -173,7 +177,6 @@ get_default_filepath(char *url, char *place_holder)
...
@@ -173,7 +177,6 @@ get_default_filepath(char *url, char *place_holder)
filepath
=
tmp
;
filepath
=
tmp
;
tmp
=
strtok
(
NULL
,
"/"
);
tmp
=
strtok
(
NULL
,
"/"
);
}
}
// TODO: Move memory allocation and deallocation logic to the caller function for better resource management.
return
filepath
;
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