Skip to content
Snippets Groups Projects
Commit 2307fe88 authored by antux18's avatar antux18
Browse files

T2.c et correction T2.sh.

parent a9e6584b
Branches
No related merge requests found
...@@ -5,13 +5,47 @@ ...@@ -5,13 +5,47 @@
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
int main(int argc, char * argv[]){ int main(int argc, char * argv[]) {
if(argc<3){ if (argc < 3) {
printf("Usage ./T2.o folder_path link_name\n"); printf("Usage ./T2.o folder_path link_name\n");
} }
//TODO -- implement your code here; char* folder_path = argv[1];
char* link = argv[2];
return 0; // Creating folder if it doesn't exist:
mkdir(folder_path, 0777);
if (errno != 0) {
fprintf(stderr, "cannot create directory '%s': ", folder_path);
switch (errno) {
case 13:
fprintf(stderr, "Permission denied.\n");
break;
case 17:
fprintf(stderr, "File exists.\n");
break;
default:
fprintf(stderr, "Unknown error.\n");
}
}
else {
// Creating link if folder creation is successful:
symlink(folder_path, link);
if (errno != 0) {
fprintf(stderr, "cannot create symlink '%s' to '%s': ", link, folder_path);
switch (errno) {
case 13:
fprintf(stderr, "Permission denied.\n");
break;
case 17:
fprintf(stderr, "File exists.\n");
break;
default:
fprintf(stderr, "Unknown error.\n");
}
}
}
return 0;
} }
ex1/T2.o 0 → 100755
File added
...@@ -18,7 +18,3 @@ then ...@@ -18,7 +18,3 @@ then
fi fi
ln -s $folder_path $link ln -s $folder_path $link
if [ $? -eq 1 ]
then
exit
fi
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment