mirror of
https://notabug.org/scuti/lib3ddevil1
synced 2024-12-22 21:39:47 +05:30
Moved scope of 'buffer' to main.
This commit is contained in:
parent
37ce23db73
commit
a8c704e428
25
main.c
25
main.c
@ -28,6 +28,9 @@ void disp_pldheader(struct PldHeader *x) {
|
||||
}
|
||||
|
||||
bool read_pldheader(const char *buffer) {
|
||||
if (buffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
int32_t *n = (int32_t*)buffer;
|
||||
struct PldHeader *ph = (struct PldHeader*)malloc(
|
||||
sizeof(struct PldHeader)
|
||||
@ -50,9 +53,8 @@ bool read_pldheader(const char *buffer) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool readpld(const char *fname) {
|
||||
bool readpld(const char *fname, char *buf) {
|
||||
FILE *f = fopen(fname, "rb");
|
||||
char *buffer = NULL;
|
||||
unsigned int size = 0; // number of elements to buffer;
|
||||
unsigned int rcnt = 0; // number of char's read by fread(...)
|
||||
if (f == NULL) {
|
||||
@ -63,31 +65,32 @@ bool readpld(const char *fname) {
|
||||
fseek(f, 0, SEEK_END);
|
||||
size = ftell(f);
|
||||
rewind(f);
|
||||
buffer = (char*)malloc(sizeof(char) * size);
|
||||
if (buffer == NULL) {
|
||||
buf = (char*)malloc(sizeof(char) * size);
|
||||
if (buf == NULL) {
|
||||
perror("Error 2: ");
|
||||
free(buffer);
|
||||
free(buf);
|
||||
return false;
|
||||
}
|
||||
rcnt = fread(buffer, sizeof(char), size, f);
|
||||
rcnt = fread(buf, sizeof(char), size, f);
|
||||
if (rcnt < size) {
|
||||
perror("Error 3: ");
|
||||
free(buffer);
|
||||
free(buf);
|
||||
return false;
|
||||
}
|
||||
read_pldheader(buffer);
|
||||
read_pldheader(buf);
|
||||
fclose(f);
|
||||
free(buffer);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv) {
|
||||
char *filename = argv[1];
|
||||
bool status = readpld(filename);
|
||||
char *filename = argv[1];
|
||||
char *filedata = NULL;
|
||||
bool status = readpld(filename, filedata);
|
||||
if (status) {
|
||||
printf("Read OK");
|
||||
} else {
|
||||
printf("Read not-OK");
|
||||
}
|
||||
free(filedata);
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user