It seems the call to stat was failing. The problem i've encountered now is that the call will always fail unless i'm in the directory in which the delete code is in. The small script in the 1st post is named rm so that all this information is displayed prior to deleting.
The script is currently in /usr/bin so when i call for example "rm /home/dave/test.txt" from /usr/bin i get the correct values. However calling rm test.txt from the /home/dave directory comes up with a file not found.
I don't really know how to fix this so that regardless of where i call my rm script from it will display the proper information. If anyone can suggest anything it'd be greatly appreciated.
I've attached my new code for delete.c incase something is wrong in there.
Code:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
const char delimiters[] = ".";
char *ext;
mystat(argv[1], 0);
return 0;
}
int mystat(char *file, int fd)
{
int err;
struct stat st;
if (file != NULL)
err = stat(file, &st);
else
err = fstat(fd, &st);
if (err < 0)
{
perror(file);
return -1;
}
if (file != NULL)
printf("%s:\n", file);
else
printf("%d:\n", fd);
printf("dev = %d\n", st.st_dev);
printf("ino = %d\n", st.st_ino);
printf("mode = \\0%010lo %s\n", st.st_mode);
printf("nlink = %d\n", st.st_nlink);
printf("uid = %d\n", st.st_uid);
printf("gid = %d\n", st.st_gid);
printf("size = %lld\n", st.st_size);
printf("blksize = %ld\n", st.st_blksize);
return 0;
}