-int pb_ph_capture_file(const char *fn) {
- int ret, fd;
- CameraFile *file;
- CameraFilePath camera_file_path;
-
- ret = gp_camera_capture(camera, GP_CAPTURE_IMAGE, &camera_file_path, context);
- if (ret != 0) {
- perror_inf();
- perror("Failed to capture image");
- return -1;
- }
-
- fd = open(fn, O_CREAT | O_WRONLY, 0644);
- if (fd == -1) {
- perror_inf();
- perror("Failed to open file");
- return -1;
- }
-
- ret = gp_file_new_from_fd(&file, fd);
- if (ret != 0) {
- perror_inf();
- perror("Failed to create image file");
- return -1;
- }
-
- ret = gp_camera_file_get(camera, camera_file_path.folder, camera_file_path.name, GP_FILE_TYPE_NORMAL,
- file, context);
- if (ret != 0) {
- perror_inf();
- perror("Failed to get image");
- return -1;
- }
+int pb_ph_capture_file(const char *fn)
+{
+ int ret, fd;
+ CameraFile *file;
+ CameraFilePath camera_file_path;
+
+ ret = gp_camera_capture(camera, GP_CAPTURE_IMAGE, &camera_file_path, context);
+ if (ret != GP_OK)
+ return ret;
+
+ fd = open(fn, O_CREAT | O_WRONLY, 0644);
+ if (fd == -1) {
+ ret = GP_ERROR;
+ perror("Failed to open/create file");
+ goto error_delete;
+ }
+
+ ret = gp_file_new_from_fd(&file, fd);
+ if (ret != GP_OK)
+ goto error_fd;
+
+ ret = gp_camera_file_get(camera, camera_file_path.folder,
+ camera_file_path.name, GP_FILE_TYPE_NORMAL, file, context);