I have created a binary file containing selected stat information, and need to read that file, use the "name" field from the file to collect current stat information, and then compare the selected stat information from the input file data to the current data - and display any abnomalies.
I have written the attached - which compiles!! - but i get a segmentation fault when i try to run it.
Can anyone suggest why??
thanks
Sue
vi bilist.c
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define NAMESIZE 256
#define TIMESIZE 50
typedef char name_type[NAMESIZE +1];
typedef char time_type[TIMESIZE +1];
typedef struct
{
name_type name;
u_short mode;
short user_id;
short group_id;
int size;
time_type time_last_mod;
}file_sig;
//main (int argc, char *argv[])
main()
{
struct stat file_info;
file_sig in_file_record;
FILE *fp;
//if (( fp = fopen(argv[2], "rb")) == NULL)
// {
// perror(argv[2]);
// exit(1);
//
// }
fp = fopen("home/spaterniti/wrkshops/b1","rb");
// read the input file
while (!feof(fp))
{
fread(&in_file_record, sizeof(file_sig), 1, fp);
// get the new stat info for the file name just read
// stat(file_sig.name, &file_info);
// compare the fields
if (in_file_record.mode == file_info.st_mode) {
printf("the modes match");
}
//printf("%c\t",in_file_record.name);
//printf("%o\t",in_file_record.mode);
//printf("%d\t",in_file_record.user_id);
//printf("%d\t",in_file_record.group_id);
//printf("%d\t",in_file_record.size);
//printf("%c\n",in_file_record.time_last_mod);
// }
}
fclose(fp);
exit(0);
}



LinkBack URL
About LinkBacks


