Download log_entry_copy_files.h
//FUNCTION FOR MAKING A BACKUP COPY OF A FILES.
//USED AT START OF PROGRAM RUN TO MAKE BACKUP COPIES.
//
//Brian Smith 2022-04-10

/*Copyright (C) 2022  Brian R. Smith
 * Contact: briansmith2865@gmail.com

**The source code in this file is free software: you can
**redistribute it and/or modify it under the terms of the GNU
**General Public License (GNU GPL) as published by the Free Software
**foundation, either version 3 of the License, or (at your option)
**any later version.  The code is distributed WITHOUT ANY WARRANTY;
**without even the implied warranty of MERCHANTABILITY or FITNESS
**FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
**
**As additional permission under GNU GPL version 3 section 7, you
**may distribute non-source (e.g., minimized or compacted) forms of
**that code without the copy of the GNU GPL normally required by
**section 4, provided you include this license notice and a URL
**through which recipients can access the Corresponding Source.
**
** @licend  The above is the entire license notice
**for the source code in this file.
*/

#include<stdio.h>
#include<stdlib.h>

//Copies src to dest. Returns 0 on success 1 otherwise.
int copy_files(char* dest, char* src) {
	FILE * fp = NULL;

	fp = fopen(src, "rb");
	if(fp == NULL) {
		printf("\033[0;31mIn read_write(): could not open %s for reading.\033[0m\n\n", src);
		return 1;
	}	
	fseek(fp, 0L, SEEK_END);
	size_t num_bytes = ftell(fp);
	char* buff = (char*) malloc(num_bytes);
	fseek(fp, 0, SEEK_SET);
	if(fread(buff, num_bytes, 1, fp) != 1) {
		printf("\033[0;31mIn read_write(): something wrong with reading.\033[0mi\n\n");
		free(buff);
		fclose(fp);
		return 1;
	}
	fclose(fp);

	
	fp = fopen(dest, "wb");
	if(fp == NULL) {
		printf("\033[0;31mIn read_write(): could not open %s for writing.\033[0m\n\n", dest);
		return 1;
	}
	if(fwrite(buff, num_bytes, 1, fp) != 1) {
		printf("\033[0;31mIn read_write(): problem with write.\033[0m\n\n");
		free(buff);
		return 1;
	}
	fclose(fp);
	free(buff);

	return 0;
}
//NOTE: behaves like bash(linx shell) command 'cp src dest'.
//Probably a library func somewhere for this.