10 int read_file(int fd
, char **buffer
, size_t *length
)
12 int result
= -1, bytes
= 0;
17 *buffer
= (char *) malloc(*length
);
21 while (((result
= read(fd
, (*buffer
+ bytes
), chunk
)) != -1) &&
24 tmp
= realloc(*buffer
, *length
+ chunk
);
46 char *find_file_path(char *file_name
)
48 char *path
, *tmp
= NULL
, *pos
;
50 path
= getcwd(NULL
, 0);
52 printf("cannot get working directory!");
54 /* This should run in a subdirectory 'build' */
55 len
= strrchr(path
, '/') - path
;
56 tmp
= malloc(len
+ strlen(file_name
) + 1);
58 pos
= strstr(path
, "build");
65 strncat(tmp
, file_name
, len
+ strlen(file_name
) + 1);
73 int find_load_file(char *path
, char **file_content
)
77 char *file_name
= path
;
80 tmp
= find_file_path(file_name
);
81 fd
= open(tmp
, O_RDONLY
);
83 printf("cannot open XML file: Path = %s.\n",
88 res
= read_file(fd
, file_content
, &len
);
95 int find_load_photo(char *path
, char **file_content
, size_t *length
)
98 char *file_name
= path
;
101 tmp
= find_file_path(file_name
);
102 fd
= open(tmp
, O_RDONLY
);
104 printf("cannot open photo file: Path = %s.\n",
109 res
= read_file(fd
, file_content
, length
);