I am making a protocol and need to turn my files into buffer. For that I made a library. Most works, but in the data_file () function, when I load text files, I get a good result, but when I load binary files, it does not work. Detail: When I am in the fread loop and I give print in the characters, it shows normal. But when I try to retrieve the buffer as a string, there is no problem.
(I thought the problem) copied from text files to 1gb + video files
file-of.h header file
#ifndef FILE_OF_H
#define FILE_OF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <type-of/include/type.h>
#include <assert.h>
#include <sys/stat.h>
#include <unistd.h>
#if (defined(WIN32) || defined(WINDOWS_XP))
#define MAX_FNAME (_MAX_PATH + _MAX_FNAME)
#else // if not win32
#define MAX_FNAME MAX_PATH
#endif // WIN32
#define READING 1
#define ALLOCATED 2
typedef struct FileTag FILE_OF;
typedef struct stat _STAT;
struct FileTag {
B8U name[MAX_FNAME];
BIT status;
STREAM * mem;
_STAT * of;
STATUS (*update)(FILE_OF * file, B8U * name);
STATUS(*stat_get)(FILE_OF * file);
STATUS(*is_reading)(FILE_OF * file);
STATUS(*read)(FILE_OF * file);
void(*reading)(FILE_OF * file);
STATUS(*write)(FILE_OF * file);
void(*writing)(FILE_OF * file);
void (*show)(FILE_OF * file);
void (*show_str)(FILE_OF * file);
STREAM * (*stream_push)(void * stream, B32U size);
STATUS(*stream_next)(STREAM ** stream, STREAM * next);
STATUS (*stream_join)(FILE_OF * file,STREAM * piece);
void * (*stream_split)(STREAM * stream,B32U begin,B32U end);
void (*stream_pop)(STREAM ** stream);
void (*pop)(FILE_OF * file);
};
extern FILE_OF * file_push();
extern FILE_OF file_std();
extern _STAT file_stat_std();
extern _STAT * file_stat_push();
extern STATUS file_upd(FILE_OF * file, B8U * name);
extern STATUS file_stat_get(FILE_OF * file);
extern void file_show(FILE_OF * file);
extern STATUS file_is_reading(FILE_OF * file);
extern STATUS file_read(FILE_OF * file);
extern void file_reading(FILE_OF * file);
extern STATUS file_write(FILE_OF * file);
extern void file_writing(FILE_OF * file);
extern void file_show_str(FILE_OF * file);
extern STREAM * file_stream_push(void * stream, B32U size);
extern void file_stream_set(STREAM * stream, void * set);
extern STATUS file_stream_next(STREAM ** stream, STREAM * next);
extern STATUS file_stream_join(FILE_OF * file,STREAM * piece);
extern void * file_stream_split(STREAM * stream, B32U begin, B32U end);
extern void file_stream_pop(STREAM ** stream);
extern void file_pop(FILE_OF * file);
extern void debug_set(STATUS state);
#ifdef __cplusplus
}
#endif
#endif
this is the source code:
#include <file-of/include/file.h>
STATUS debug = Off;
void debug_set(STATUS state) {
debug = state;
}
void file_function(FILE_OF * file) {
assert(file != NULL);
file->stream_push = file_stream_push;
file->stream_next = file_stream_next;
file->stream_join = file_stream_join;
file->stream_split = file_stream_split;
file->stream_pop = file_stream_pop;
file->update = file_upd;
file->stat_get = file_stat_get;
file->is_reading = file_is_reading;
file->read = file_read;
file->reading = file_reading;
file->write = file_write;
file->writing = file_writing;
file->show = file_show;
file->show_str = file_show_str;
file->pop = file_pop;
}
void file_stat_zero(_STAT * of) {
if (of) {
of->st_atime = 0;
of->st_ctime = 0;
of->st_dev = 0;
of->st_gid = 0;
of->st_ino = 0;
of->st_mode = 0;
of->st_mtime = 0;
of->st_nlink = 0;
of->st_rdev = 0;
of->st_size = 0;
of->st_uid = 0;
}
}
_STAT file_stat_std() {
_STAT to;
file_stat_zero(&to);
return (to);
}
_STAT * file_stat_push() {
_STAT * stat = malloc(sizeof (_STAT));
file_stat_zero(stat);
return (stat);
}
void file_zero(FILE_OF * file) {
assert(file != NULL);
memcpy(file->name, "none#include <file-of/include/file.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
STATUS file_join(FILE_OF * file, B32U max) {
if (!file && !file->of)return (Off);
FILE_OF part_local = file_std(), * part = &part_local;
B32U i = 0;
while (i < max) {
sprintf(part->name, "temp[%u]", i + 1);
if(!part->is_reading(part))part->reading(file);
if(part->update(part, part->name)){
//part->show_str(part);
if(file->stream_join(file,part->mem)){
printf("%s join the party\n",part->name);
}
part->stream_pop(&part->mem);
}
i++;
}
part->pop(part);
return (On);
}
STATUS file_ex() {
STATUS allocated = Off;
FILE_OF * file, local = file_std();
if (allocated == Off) {
file = &local;
}
//debug_set(On);
if (file_join(file, 2)) {
file->writing(file);
file->update(file, "file.c");
file->write(file);
}
file->pop(file);
}
void info_ex() {
STATUS allocated = Off;
FILE_OF * file, local;
if (allocated) {
file = file_push();
} else {
local = file_std();
file = &local;
}
B8 * name = "main.c";
if (file->update(file, name)) {
file->show_str(file);
B8U * piece = (B8U*)file->stream_split(file->mem,20,25);
printf("[%s]\n",piece);
free(piece);
file->writing(file); // allow the file to be writen
if (file->update(file, "example.c")) {
if (file->write(file)) {
printf("wrote\n");
}
}
}
file->pop(file);
}
", 5);
bit_on(&file->status, READING);
file->mem = NULL;
file->of = file_stat_push();
file_function(file);
}
FILE_OF * file_push() {
FILE_OF * file = malloc(sizeof (FILE_OF));
file_zero(file);
bit_on(&file->status, ALLOCATED);
return (file);
}
FILE_OF file_std() {
FILE_OF file;
file_zero(&file);
bit_off(&file.status, ALLOCATED);
return (file);
}
STATUS file_is_reading(FILE_OF * file) {
if (file) {
if (bit_is_on(file->status, READING))return (On);
}
return (Off);
}
STATUS file_stat_get(FILE_OF * file) {
assert(file != NULL);
if (file->of && stat(file->name, file->of) == 0 && file->of->st_size)return (On);
return (Off);
}
STATUS file_upd(FILE_OF * file, B8U * name) {
assert(file != NULL && name != NULL);
if (!equals(file->name, name)) {
B32U n_len = strlen(name);
B32U n_up = (n_len < MAX_FNAME) ? n_len : MAX_FNAME;
memcpy(file->name, name, n_up);
file->name[n_up] = 0;
}
if (file->is_reading(file)) {
if (!file->of || !file->stat_get(file))return (Off);
if (!file->mem)
if (!file->stream_next(&file->mem, file->stream_push(NULL, file->of->st_size)))return (Off);
if (file->mem && !file->read(file))
return (Off);
}
return (On);
}
STATUS file_read(FILE_OF * file) {
assert(file || file->of);
if (!bit_is_on(file->status, READING) || !file->mem)return (Off);
FILE * pointer = fopen(file->name, "rb");
if (!pointer) {
if (debug)printf("file %s does not exist\n", file->name);
return (Off);
}
if (debug)printf("Trying to read %s\n", file->name);
STATUS read = Off;
B32U pos = 0;
STREAM * mem = file->mem;
while (mem) {
fseek(pointer, (pos) ? pos - 1 : 0, SEEK_SET);
fread(file->mem->data, sizeof (B8U), file->mem->size, pointer);
//printf("%s",B8UC(file->mem->data) );
pos += mem->size;
NEXT(mem);
if (!read)read = On;
}
if (debug && !read)printf("file[%s] could not be loaded\n\n", file->name);
fclose(pointer);
return (On);
}
void file_reading(FILE_OF * file) {
if (file)
bit_on(&file->status, READING);
}
STATUS file_write(FILE_OF * file) {
assert(file != NULL);
if (!file->mem || !file->mem->size || bit_is_on(file->status, READING))return (Off);
FILE * pointer = fopen(file->name, "wb");
if (!pointer) {
if (debug)printf("file %s does not exist\n", file->name);
return (Off);
}
STATUS rec = Off;
B32U pos = 0;
STREAM * mem = file->mem;
while (mem) {
fseek(pointer, (pos) ? pos - 1 : 0, SEEK_SET);
fwrite(mem->data, sizeof (B8U), mem->size, pointer);
pos += mem->size;
NEXT(mem);
if (!rec)rec = On;
}
if (rec)fputc(0, pointer);
fclose(pointer);
return (On);
}
void file_writing(FILE_OF * file) {
if (file)
bit_off(&file->status, READING);
}
STREAM * file_stream_push(void * stream, B32U size) {
STREAM * set = malloc(sizeof (STREAM));
set->size = size;
set->data = NULL;
if (set->size) {
set->data = calloc(set->size + 1, sizeof (B8));
if (stream)memmove(set->data, stream, size);
}
set->next = NULL;
return (set);
}
void file_stream_set(STREAM * stream, void * set) {
assert(stream != NULL);
stream->data = set;
}
STATUS file_stream_next(STREAM ** stream, STREAM * next) {
if (!next)return (Off);
if (*stream != NULL) {
STREAM * update = *stream;
while (update->next != NULL) {
NEXT(update);
}
update->next = next;
return (On);
}
*stream = next;
return (On);
}
STATUS file_stream_join(FILE_OF * file,STREAM * piece){
if(!file || !file->of || !piece){
if(debug)printf("something is not allocated\n");
return(Off);
}
if(file->stream_next(&file->mem,file->stream_push(piece->data,piece->size))){
file->of->st_size += piece->size;
return(On);
}
return(Off);
}
void * file_stream_split(STREAM * stream, B32U begin, B32U end) {
if (stream) {
B32U size = (begin > 0) ? end - begin : end;
if (size <= stream->size) {
void * data = calloc(size+1,sizeof(B8U));
memcpy(data, &((B8U*)stream->data)[begin], size);
B8UC(data)[size] = 0;
return (data);
}
}
return (NULL);
}
void file_stream_pop(STREAM ** stream) {
if (*stream) {
if ((*stream)->data) {
free((*stream)->data);
(*stream)->data = NULL;
}
free(stream);
*stream = NULL;
}
}
void file_show(FILE_OF * file) {
if (file && file->mem && file->name) {
printf("Information for [%s] mode [%s]\n", file->name, (file->reading) ? "read" : "write");
printf("---------------------------\n");
printf("File Size: \t\t%ld bytes\n", file->of->st_size);
printf("Number of Links: \t%hd\n", file->of->st_nlink);
printf("File inode: \t\t%hu\n", file->of->st_ino);
printf("File Permissions: \t");
printf((S_ISDIR(file->of->st_mode)) ? "d" : "-");
printf((file->of->st_mode & S_IRUSR) ? "r" : "-");
printf((file->of->st_mode & S_IWUSR) ? "w" : "-");
printf((file->of->st_mode & S_IXUSR) ? "x" : "-");
printf((file->of->st_mode & S_IRGRP) ? "r" : "-");
printf((file->of->st_mode & S_IWGRP) ? "w" : "-");
printf((file->of->st_mode & S_IXGRP) ? "x" : "-");
printf((file->of->st_mode & S_IROTH) ? "r" : "-");
printf((file->of->st_mode & S_IWOTH) ? "w" : "-");
printf((file->of->st_mode & S_IXOTH) ? "x" : "-");
if (file->mem)printf("\ndata[filled]");
printf("\n\n");
//printf("The file %s a symbolic link\n", (S_ISLNK(file->of->st_mode)) ? "is" : "is not");
}
}
void file_show_str(FILE_OF * file) {
if (file && file->mem && file->mem->data) {
printf("%s", B8UC(file->mem->data));
}
}
void file_pop(FILE_OF * file) {
assert(file != NULL);
if (file->of) {
if (debug)printf("poping stat\n");
free(file->of);
file->of = NULL;
}
if (file->mem) {
if (debug)printf("poping file memory\n");
STREAM * stream = file->mem;
while (stream->next) {
STREAM * next = stream->next;
file->stream_pop(&stream);
stream = next;
}
if (debug && file->mem) {
free(file->mem);
file->mem = NULL;
}
}
if (bit_is_on(file->status, ALLOCATED)) {
if (debug)printf("poping file file\n");
free(file);
file = NULL;
}
}
This is a test file:
#include <file-info/include/file-info.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
STATUS file_ex();
int main() {
file_ex();
return (EXIT_SUCCESS);
}
and finally the main code:
#ifndef TYPE_OF_H
#define TYPE_OF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#define PIXEL_PER_KM 3779575.17575
#define PIXEL_PER_MT (PIXEL_PER_KM / 1000)
#define PIXEL_PER_CM (PIXEL_PER_MT / 100)
#define MICROSECOND_PER_HOUR 3600000000
#define BIT_ON(var,bit) ((var)=((var) | (bit)))
#define BIT_OFF(var,bit) ((var)=((var) & (~bit)))
#define BIT_IS_ON(var,bit) (var & bit)
#define PAIR(position,value) ((value)=((position) << (1)))
#define NEXT(a)( (a) = (a)->next )
#define PREVIEW(a)( (a) = (a)->preview )
typedef char B8;
typedef unsigned char B8U;
typedef short B16;
typedef unsigned short B16U;
typedef int B32;
typedef unsigned int B32U;
typedef long long int B64;
typedef unsigned long long int B64U;
typedef float BP32;
typedef double BP64;
typedef struct Bit8Tag BIT;
typedef struct BufferStreamTag STREAM;
struct BufferStreamTag{
void * data;
B32U size;
STREAM * next;
};
typedef enum {
Off, On
} STATUS;
typedef enum {
B8_T, B8U_T, B16_T, B16U_T, B32_T, B64_T, B64U_T, B32U_T, BP32_T, BP64_T
} TYPE;
#if (defined(WIN32) || defined(WINDOWS_XP))
#define is_win()(On)
#else // if not WIN32
#define is_win()(Off)
#endif // WIN32
#define B8C(a)((B8*)a)
#define B8UC(a)((B8U*)a)
#define B16C(a)((B16*)a)
#define B32C(a)((B32*)a)
#define B64C(a)((B64*)a)
#define BP32C(a)((BP32*)a)
#define BP64C(a)((BP64*)a)
#define area(a,b) ((a)*(b))
#define radian(x,y)(atan2(y,x))
#define angle(a)( (a * (180 / M_PI)) + 180)
#define CAST(a,type)((type*)a)
#if defined WIN32
#define ARIAL_PATH "C:/Windows/Fonts/arial.ttf#ifndef FILE_OF_H
#define FILE_OF_H
#ifdef __cplusplus
extern "C" {
#endif
#include <type-of/include/type.h>
#include <assert.h>
#include <sys/stat.h>
#include <unistd.h>
#if (defined(WIN32) || defined(WINDOWS_XP))
#define MAX_FNAME (_MAX_PATH + _MAX_FNAME)
#else // if not win32
#define MAX_FNAME MAX_PATH
#endif // WIN32
#define READING 1
#define ALLOCATED 2
typedef struct FileTag FILE_OF;
typedef struct stat _STAT;
struct FileTag {
B8U name[MAX_FNAME];
BIT status;
STREAM * mem;
_STAT * of;
STATUS (*update)(FILE_OF * file, B8U * name);
STATUS(*stat_get)(FILE_OF * file);
STATUS(*is_reading)(FILE_OF * file);
STATUS(*read)(FILE_OF * file);
void(*reading)(FILE_OF * file);
STATUS(*write)(FILE_OF * file);
void(*writing)(FILE_OF * file);
void (*show)(FILE_OF * file);
void (*show_str)(FILE_OF * file);
STREAM * (*stream_push)(void * stream, B32U size);
STATUS(*stream_next)(STREAM ** stream, STREAM * next);
STATUS (*stream_join)(FILE_OF * file,STREAM * piece);
void * (*stream_split)(STREAM * stream,B32U begin,B32U end);
void (*stream_pop)(STREAM ** stream);
void (*pop)(FILE_OF * file);
};
extern FILE_OF * file_push();
extern FILE_OF file_std();
extern _STAT file_stat_std();
extern _STAT * file_stat_push();
extern STATUS file_upd(FILE_OF * file, B8U * name);
extern STATUS file_stat_get(FILE_OF * file);
extern void file_show(FILE_OF * file);
extern STATUS file_is_reading(FILE_OF * file);
extern STATUS file_read(FILE_OF * file);
extern void file_reading(FILE_OF * file);
extern STATUS file_write(FILE_OF * file);
extern void file_writing(FILE_OF * file);
extern void file_show_str(FILE_OF * file);
extern STREAM * file_stream_push(void * stream, B32U size);
extern void file_stream_set(STREAM * stream, void * set);
extern STATUS file_stream_next(STREAM ** stream, STREAM * next);
extern STATUS file_stream_join(FILE_OF * file,STREAM * piece);
extern void * file_stream_split(STREAM * stream, B32U begin, B32U end);
extern void file_stream_pop(STREAM ** stream);
extern void file_pop(FILE_OF * file);
extern void debug_set(STATUS state);
#ifdef __cplusplus
}
#endif
#endif
"
#else
#define ARIAL_PATH "home/media/TheGreat/#include <file-of/include/file.h>
STATUS debug = Off;
void debug_set(STATUS state) {
debug = state;
}
void file_function(FILE_OF * file) {
assert(file != NULL);
file->stream_push = file_stream_push;
file->stream_next = file_stream_next;
file->stream_join = file_stream_join;
file->stream_split = file_stream_split;
file->stream_pop = file_stream_pop;
file->update = file_upd;
file->stat_get = file_stat_get;
file->is_reading = file_is_reading;
file->read = file_read;
file->reading = file_reading;
file->write = file_write;
file->writing = file_writing;
file->show = file_show;
file->show_str = file_show_str;
file->pop = file_pop;
}
void file_stat_zero(_STAT * of) {
if (of) {
of->st_atime = 0;
of->st_ctime = 0;
of->st_dev = 0;
of->st_gid = 0;
of->st_ino = 0;
of->st_mode = 0;
of->st_mtime = 0;
of->st_nlink = 0;
of->st_rdev = 0;
of->st_size = 0;
of->st_uid = 0;
}
}
_STAT file_stat_std() {
_STAT to;
file_stat_zero(&to);
return (to);
}
_STAT * file_stat_push() {
_STAT * stat = malloc(sizeof (_STAT));
file_stat_zero(stat);
return (stat);
}
void file_zero(FILE_OF * file) {
assert(file != NULL);
memcpy(file->name, "none#include <file-of/include/file.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
STATUS file_join(FILE_OF * file, B32U max) {
if (!file && !file->of)return (Off);
FILE_OF part_local = file_std(), * part = &part_local;
B32U i = 0;
while (i < max) {
sprintf(part->name, "temp[%u]", i + 1);
if(!part->is_reading(part))part->reading(file);
if(part->update(part, part->name)){
//part->show_str(part);
if(file->stream_join(file,part->mem)){
printf("%s join the party\n",part->name);
}
part->stream_pop(&part->mem);
}
i++;
}
part->pop(part);
return (On);
}
STATUS file_ex() {
STATUS allocated = Off;
FILE_OF * file, local = file_std();
if (allocated == Off) {
file = &local;
}
//debug_set(On);
if (file_join(file, 2)) {
file->writing(file);
file->update(file, "file.c");
file->write(file);
}
file->pop(file);
}
void info_ex() {
STATUS allocated = Off;
FILE_OF * file, local;
if (allocated) {
file = file_push();
} else {
local = file_std();
file = &local;
}
B8 * name = "main.c";
if (file->update(file, name)) {
file->show_str(file);
B8U * piece = (B8U*)file->stream_split(file->mem,20,25);
printf("[%s]\n",piece);
free(piece);
file->writing(file); // allow the file to be writen
if (file->update(file, "example.c")) {
if (file->write(file)) {
printf("wrote\n");
}
}
}
file->pop(file);
}
", 5);
bit_on(&file->status, READING);
file->mem = NULL;
file->of = file_stat_push();
file_function(file);
}
FILE_OF * file_push() {
FILE_OF * file = malloc(sizeof (FILE_OF));
file_zero(file);
bit_on(&file->status, ALLOCATED);
return (file);
}
FILE_OF file_std() {
FILE_OF file;
file_zero(&file);
bit_off(&file.status, ALLOCATED);
return (file);
}
STATUS file_is_reading(FILE_OF * file) {
if (file) {
if (bit_is_on(file->status, READING))return (On);
}
return (Off);
}
STATUS file_stat_get(FILE_OF * file) {
assert(file != NULL);
if (file->of && stat(file->name, file->of) == 0 && file->of->st_size)return (On);
return (Off);
}
STATUS file_upd(FILE_OF * file, B8U * name) {
assert(file != NULL && name != NULL);
if (!equals(file->name, name)) {
B32U n_len = strlen(name);
B32U n_up = (n_len < MAX_FNAME) ? n_len : MAX_FNAME;
memcpy(file->name, name, n_up);
file->name[n_up] = 0;
}
if (file->is_reading(file)) {
if (!file->of || !file->stat_get(file))return (Off);
if (!file->mem)
if (!file->stream_next(&file->mem, file->stream_push(NULL, file->of->st_size)))return (Off);
if (file->mem && !file->read(file))
return (Off);
}
return (On);
}
STATUS file_read(FILE_OF * file) {
assert(file || file->of);
if (!bit_is_on(file->status, READING) || !file->mem)return (Off);
FILE * pointer = fopen(file->name, "rb");
if (!pointer) {
if (debug)printf("file %s does not exist\n", file->name);
return (Off);
}
if (debug)printf("Trying to read %s\n", file->name);
STATUS read = Off;
B32U pos = 0;
STREAM * mem = file->mem;
while (mem) {
fseek(pointer, (pos) ? pos - 1 : 0, SEEK_SET);
fread(file->mem->data, sizeof (B8U), file->mem->size, pointer);
//printf("%s",B8UC(file->mem->data) );
pos += mem->size;
NEXT(mem);
if (!read)read = On;
}
if (debug && !read)printf("file[%s] could not be loaded\n\n", file->name);
fclose(pointer);
return (On);
}
void file_reading(FILE_OF * file) {
if (file)
bit_on(&file->status, READING);
}
STATUS file_write(FILE_OF * file) {
assert(file != NULL);
if (!file->mem || !file->mem->size || bit_is_on(file->status, READING))return (Off);
FILE * pointer = fopen(file->name, "wb");
if (!pointer) {
if (debug)printf("file %s does not exist\n", file->name);
return (Off);
}
STATUS rec = Off;
B32U pos = 0;
STREAM * mem = file->mem;
while (mem) {
fseek(pointer, (pos) ? pos - 1 : 0, SEEK_SET);
fwrite(mem->data, sizeof (B8U), mem->size, pointer);
pos += mem->size;
NEXT(mem);
if (!rec)rec = On;
}
if (rec)fputc(0, pointer);
fclose(pointer);
return (On);
}
void file_writing(FILE_OF * file) {
if (file)
bit_off(&file->status, READING);
}
STREAM * file_stream_push(void * stream, B32U size) {
STREAM * set = malloc(sizeof (STREAM));
set->size = size;
set->data = NULL;
if (set->size) {
set->data = calloc(set->size + 1, sizeof (B8));
if (stream)memmove(set->data, stream, size);
}
set->next = NULL;
return (set);
}
void file_stream_set(STREAM * stream, void * set) {
assert(stream != NULL);
stream->data = set;
}
STATUS file_stream_next(STREAM ** stream, STREAM * next) {
if (!next)return (Off);
if (*stream != NULL) {
STREAM * update = *stream;
while (update->next != NULL) {
NEXT(update);
}
update->next = next;
return (On);
}
*stream = next;
return (On);
}
STATUS file_stream_join(FILE_OF * file,STREAM * piece){
if(!file || !file->of || !piece){
if(debug)printf("something is not allocated\n");
return(Off);
}
if(file->stream_next(&file->mem,file->stream_push(piece->data,piece->size))){
file->of->st_size += piece->size;
return(On);
}
return(Off);
}
void * file_stream_split(STREAM * stream, B32U begin, B32U end) {
if (stream) {
B32U size = (begin > 0) ? end - begin : end;
if (size <= stream->size) {
void * data = calloc(size+1,sizeof(B8U));
memcpy(data, &((B8U*)stream->data)[begin], size);
B8UC(data)[size] = 0;
return (data);
}
}
return (NULL);
}
void file_stream_pop(STREAM ** stream) {
if (*stream) {
if ((*stream)->data) {
free((*stream)->data);
(*stream)->data = NULL;
}
free(stream);
*stream = NULL;
}
}
void file_show(FILE_OF * file) {
if (file && file->mem && file->name) {
printf("Information for [%s] mode [%s]\n", file->name, (file->reading) ? "read" : "write");
printf("---------------------------\n");
printf("File Size: \t\t%ld bytes\n", file->of->st_size);
printf("Number of Links: \t%hd\n", file->of->st_nlink);
printf("File inode: \t\t%hu\n", file->of->st_ino);
printf("File Permissions: \t");
printf((S_ISDIR(file->of->st_mode)) ? "d" : "-");
printf((file->of->st_mode & S_IRUSR) ? "r" : "-");
printf((file->of->st_mode & S_IWUSR) ? "w" : "-");
printf((file->of->st_mode & S_IXUSR) ? "x" : "-");
printf((file->of->st_mode & S_IRGRP) ? "r" : "-");
printf((file->of->st_mode & S_IWGRP) ? "w" : "-");
printf((file->of->st_mode & S_IXGRP) ? "x" : "-");
printf((file->of->st_mode & S_IROTH) ? "r" : "-");
printf((file->of->st_mode & S_IWOTH) ? "w" : "-");
printf((file->of->st_mode & S_IXOTH) ? "x" : "-");
if (file->mem)printf("\ndata[filled]");
printf("\n\n");
//printf("The file %s a symbolic link\n", (S_ISLNK(file->of->st_mode)) ? "is" : "is not");
}
}
void file_show_str(FILE_OF * file) {
if (file && file->mem && file->mem->data) {
printf("%s", B8UC(file->mem->data));
}
}
void file_pop(FILE_OF * file) {
assert(file != NULL);
if (file->of) {
if (debug)printf("poping stat\n");
free(file->of);
file->of = NULL;
}
if (file->mem) {
if (debug)printf("poping file memory\n");
STREAM * stream = file->mem;
while (stream->next) {
STREAM * next = stream->next;
file->stream_pop(&stream);
stream = next;
}
if (debug && file->mem) {
free(file->mem);
file->mem = NULL;
}
}
if (bit_is_on(file->status, ALLOCATED)) {
if (debug)printf("poping file file\n");
free(file);
file = NULL;
}
}
"
#endif
#define EXIT 27
struct Bit8Tag {
unsigned b16 : 16;
};
extern void bit_on(BIT * value, int bit);
extern void bit_off(BIT * value, int bit);
extern STATUS bit_is_on(BIT value, int bit);
extern B32U strsub(B8 * data, B8 * key);
extern void take_set(B32U value);
extern B32U take_out();
extern B32U take(B8 * data);
extern void look(void * data);
extern STATUS equals(void * first, void * second);
extern void data_file_fill(void * data, B32U size, FILE * file);
extern void clear();
#ifdef __cplusplus
}
#endif
#endif // TYPE_OF_H
Here are the types:
#include <file-info/include/file-info.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
STATUS file_ex();
int main() {
file_ex();
return (EXIT_SUCCESS);
}