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
da6d0799
Commit
da6d0799
authored
Apr 29, 2024
by
Ильин Владимир Александрович
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Задача на автомат
parent
e4302bd3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
0 deletions
+89
-0
downloader
avtomat/downloader
+0
-0
main.c
avtomat/main.c
+79
-0
makefile
avtomat/makefile
+10
-0
No files found.
avtomat/downloader
0 → 100755
View file @
da6d0799
File added
avtomat/main.c
0 → 100644
View file @
da6d0799
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void
usage
();
char
*
get_default_filepath
(
char
*
);
int
main
(
int
argc
,
char
**
argv
)
{
char
*
filepath
=
NULL
;
char
*
url
=
NULL
;
if
(
argc
==
2
){
url
=
argv
[
1
];
filepath
=
get_default_filepath
(
url
);
//filepath is a pointer inside url
}
else
if
(
argc
==
3
){
url
=
argv
[
1
];
filepath
=
argv
[
2
];
}
else
usage
();
printf
(
"url:%s
\n
filepath:%s
\n
"
,
url
,
filepath
);
CURL
*
curl
=
curl_easy_init
();
CURLcode
res
;
if
(
!
curl
)
{
fprintf
(
stderr
,
"Curl init failled, baling!"
);
exit
(
1
);
}
FILE
*
file
;
file
=
fopen
(
filepath
,
"wb"
);
curl_easy_setopt
(
curl
,
CURLOPT_URL
,
url
);
curl_easy_setopt
(
curl
,
CURLOPT_WRITEDATA
,
file
);
if
(
!
file
){
fprintf
(
stderr
,
"Could not open file!"
);
exit
(
1
);
}
res
=
curl_easy_perform
(
curl
);
if
(
res
!=
CURLE_OK
)
fprintf
(
stderr
,
"curl_easy_perform() failed: %s
\n
"
,
curl_easy_strerror
(
res
));
else
fprintf
(
stdout
,
"curl returned %s; Downloaded %s
\n
"
,
curl_easy_strerror
(
res
),
filepath
);
fclose
(
file
);
curl_easy_cleanup
(
curl
);
return
0
;
}
char
*
get_default_filepath
(
char
*
url
)
{
char
*
filepath
=
strdup
(
url
);
char
*
tmp
=
strtok
(
filepath
,
"/"
);
while
(
tmp
!=
NULL
)
{
filepath
=
tmp
;
tmp
=
strtok
(
NULL
,
"/"
);
}
return
filepath
;
}
void
usage
(){
puts
(
"usage: <url> <file path>(optional, default is ./<filename on url>)"
);
exit
(
0
);
}
avtomat/makefile
0 → 100644
View file @
da6d0799
INCS
=
-lcurl
CFLAGS
=
-fdiagnostics-color
=
always
-Wall
-Wextra
-Wpedantic
-Wformat
-Wshadow
-Wunused
-Wconversion
-Wsign-conversion
${
INCS
}
-O3
-g
CC
=
gcc
all
:
$(CC)
$(CFLAGS)
main.c
-o
downloader
clear
:
rm
downloader
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