Ok I have to write a program that uses the linux stat() function, it is supposed to read in a filename, were from were it will determine access permissions, it will end once the user enter a blank filename i.e '/0' or enter.
Can anyone see any probs, as i am unable to yet test it.
thanks for any help
Code:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <string.h>
#include <sys/stat.h>
#define BUFFER 10
struct stat fileattrib;
char file[BUFFER], *nl;
int main(int argc, char *argv[])
{
// Get file name
printf("Enter Filename....\n");
while (gets(file) != NULL) // Loop getting filename while not null
{
*nl = strchr( buff, '\n' ); //Search out the null entry
if ((buf[0] == '\n') // if a null is a 0 then exit
break;
if ( nl != NULL )
*nl = '\0'; // remove the end of line
if( stat( file, &fileattrib ) != 0 ) {
{
printf("Access Permissions of file: %s\n ",file);
printf("----------------------------\n");
printf( "%d\n", fileattrib.st_mode );
}
else
printf("File Error Message = %s\n", strerror(errno));
printf("Enter Filename....\n"); // for next filename input
}
}