Hi Salem,
Here is the code that wrote the binary file.
regards
sue
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#define NAMESIZE 256
#define TIMESIZE 50
typedef char name_type[NAMESIZE + 1];
typedef char time_type[TIMESIZE +1];
//typedef struct
//{
// char in_name[NAMESIZE];
//} file_in;
typedef struct
{
name_type name; /*File or directory name*/
u_short mode; /*protection and file type*/
short user_id; /*User ID of owner*/
short group_id; /*Group ID of owner*/
off_t size; /*file size in bytes*/
time_type time_last_mod; /*modify time as string*/
} file_sig;
main(int argc, char *argv[])
{
struct stat file_info; /* define the stat variable*/
file_sig out_file; /* define the output file variable*/
name_type in_file; /* define the input file variable*/
// initialise the input and output file names
//in_file_name = argv[2];
//out_list_name = argv[3];
// The file pointers
FILE *fp,*fp1; /*The output file*/
//FILE *fp1; /*The input file*/
// open the input and output files
// if (( fp = fopen(argv[2], "r")) == NULL)
// {
// perror(argv[2]);
// exit(1);
// }
// fp1 = fopen(argv[3], "wb");
fp = fopen("/home/spaterniti/wrkshops/filelist", "r");
fp1 = fopen("/home/spaterniti/wrkshops/b1", "wb");
// if (( fp1 = fopen(argv[3], "wb")) == NULL)
// {
// perror(argv[3]);
// exit(1);
// }
// while there are records read the text file
// and collect the stat information for the selected file
// and write a modified stat record to the output file
while (!feof(fp))
{
// printf("%c", &in_file);
fscanf(fp, "%c", &in_file);
stat(in_file, &file_info);
// create the output data fields from the stat'd data
strcpy(out_file.name, in_file);
//printf("%s\n", &in_file);
//printf("%s\n", &out_file.name);
out_file.mode = file_info.st_mode;
out_file.user_id = file_info.st_uid;
out_file.group_id = file_info.st_gid;
out_file.size = file_info.st_size;
strcpy(out_file.time_last_mod, ctime(&file_info.st_mtime));
//stat("/home/spaterniti/wrkshops/ws01.1.c", &file_info);
// read each record from the list file
// and collect and store the stat information
fwrite(&out_file, sizeof(file_sig),1,fp1);
}
// close the files
fclose(fp);
fclose(fp1);
exit(0);
}