commit cb32179a1bbb69b095b8dc8e117fa7ae1c2692cc
parent 2d6091417bf60846c6332ad737f363a6d55a625c
Author: qorg11 <qorg@vxempire.xyz>
Date: Thu, 6 Aug 2020 15:28:24 +0200
added ernno things
Diffstat:
8 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/src/chmod.c b/src/chmod.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
int
main(int argc, char *argv[])
@@ -11,7 +13,7 @@ main(int argc, char *argv[])
int fd = chmod(argv[i],mode);
if(fd == -1)
{
- fprintf(stderr,"Error setting %i on %s\n",mode,argv[i]);
+ fprintf(stderr,"Error setting %i on %s\n %i = %s",mode,argv[i],errno,strerror(errno));
}
}
diff --git a/src/cp.c b/src/cp.c
@@ -1,6 +1,8 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
int
copy(const char *src, const char *dst)
@@ -10,12 +12,12 @@ copy(const char *src, const char *dst)
if(destination == -1)
{
- printf("Error opening destination file\n");
+ fprintf(stderr,"Error opening destination file: %i = %s\n",errno,strerror(errno));
return 1;
}
if(source == -1)
{
- printf("Error opening source file\n");
+ fprintf(stderr,"Error opening source file: %i = %s\n",errno,strerror(errno));
return 1;
}
int lines;
@@ -29,12 +31,13 @@ copy(const char *src, const char *dst)
int
main(int argc, char *argv[])
{
+ int fd;
if (argc == 1)
{
fprintf(stderr,"usage: cp source destination\n");
return 1;
}
else
- copy(argv[1],argv[2]);
+ fd = copy(argv[1],argv[2]);
}
diff --git a/src/head.c b/src/head.c
@@ -1,12 +1,14 @@
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
int
head(FILE *file, int lines)
{
if(file == NULL)
{
- printf("error opening file\n");
+ fprintf(stderr,"error opening file: %i = %s\n",errno,strerror(errno));
return 1;
}
int a;
diff --git a/src/ln.c b/src/ln.c
@@ -26,7 +26,7 @@ main(int argc, char *argv[])
int symstat = symlink(argv[2],argv[3]);
if(symstat == -1)
{
- fprintf(stderr, "Symlink error!");
+ fprintf(stderr, "Symlink error: %i = %s",errno,strerror(errno));
return 1;
}
break;
diff --git a/src/rm.c b/src/rm.c
@@ -1,5 +1,6 @@
#include <stdio.h>
-
+#include <errno.h>
+#include <string.h>
int
main(int argc, char *argv[])
{
@@ -14,7 +15,7 @@ main(int argc, char *argv[])
int fd = remove(argv[i]);
if(fd == -1)
{
- fprintf(stderr,"Error removing file: %s\n",argv[i]);
+ fprintf(stderr,"Error removing file: %i = %s",errno,strerror(errno));
}
}
diff --git a/src/rmdir.c b/src/rmdir.c
@@ -1,7 +1,7 @@
#include <unistd.h>
#include <stdio.h>
-#include <err.h>
-
+#include <errno.h>
+#include <string.h>
int
main(int argc, char *argv[]) {
int errors = 0;
@@ -10,13 +10,10 @@ main(int argc, char *argv[]) {
int fd = rmdir(argv[i]); /* Is it actually a file descriptor? */
if(fd == -1)
{
- warn("Error removing dir %s\n",argv[i]);
+ fprintf(stderr,"Error removing dir %s: %i = %s\n",argv[i],
+ errno,strerror(errno));
errors++;
}
}
- if(errors>0)
- {
- warn("%i error(s) found\n",errors);
- }
return 0;
}
diff --git a/src/touch.c b/src/touch.c
@@ -2,6 +2,8 @@
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <errno.h>
+#include <string.h>
int
main(int argc, char *argv[])
@@ -16,7 +18,7 @@ main(int argc, char *argv[])
if(fd == -1)
{
- fprintf(stderr,"Error creating file\n");
+ fprintf(stderr,"Error creating file: %i = %s\n",errno,strerror(errno));
return 1;
}
close(fd);
diff --git a/src/unlink.c b/src/unlink.c
@@ -15,7 +15,8 @@ main(int argc, char *argv[])
int fd = unlink(argv[1]);
if(fd == -1)
{
- printf("Error unlinking: %i = %s\n",errno,strerror(errno));
+ fprintf(stderr,"Error unlinking: %i = %s\n",
+ errno,strerror(errno));
}
return 0;