int pakfire_b64decode(struct pakfire* pakfire, void** output, size_t* length,
const char* buffer);
+// Copy
+int pakfire_copy(struct pakfire* pakfire, FILE* src, FILE* dst);
+
#endif
#endif /* PAKFIRE_UTIL_H */
PAKFIRE_COPY_OUT,
};
-static int pakfire_copy(struct pakfire* pakfire, const char* src, const char* dst,
+static int __pakfire_copy(struct pakfire* pakfire, const char* src, const char* dst,
enum pakfire_copy_direction direction) {
struct archive* reader = NULL;
struct archive* writer = NULL;
if (r)
return r;
- return pakfire_copy(pakfire, src, path, PAKFIRE_COPY_IN);
+ return __pakfire_copy(pakfire, src, path, PAKFIRE_COPY_IN);
}
PAKFIRE_EXPORT int pakfire_copy_out(struct pakfire* pakfire, const char* src, const char* dst) {
if (r)
return r;
- return pakfire_copy(pakfire, path, dst, PAKFIRE_COPY_OUT);
+ return __pakfire_copy(pakfire, path, dst, PAKFIRE_COPY_OUT);
}
PAKFIRE_EXPORT const char* pakfire_get_arch(struct pakfire* pakfire) {
return r;
}
+
+// Copy
+
+int pakfire_copy(struct pakfire* pakfire, FILE* src, FILE* dst) {
+ char buffer[BUFFER_SIZE];
+ size_t bytes_read;
+ size_t bytes_written;
+
+ while (!feof(src)) {
+ // Read some data into the buffer
+ bytes_read = fread(buffer, 1, sizeof(buffer), src);
+
+ // Check for any errors
+ if (ferror(src)) {
+ ERROR(pakfire, "Could not read data: %m\n");
+ return 1;
+ }
+
+ // Write the data
+ bytes_written = fwrite(buffer, 1, bytes_read, dst);
+ if (bytes_written < bytes_read) {
+ ERROR(pakfire, "Could not write data: %m\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}