diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/GipfelWidget.cxx | 2 | ||||
-rw-r--r-- | src/ImageMetaData.cxx | 34 | ||||
-rw-r--r-- | src/gipfel.cxx | 2 |
3 files changed, 10 insertions, 28 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx index 105cd30..d11d574 100644 --- a/src/GipfelWidget.cxx +++ b/src/GipfelWidget.cxx @@ -156,8 +156,6 @@ GipfelWidget::save_image(char *file) { return 1; } - md = new ImageMetaData(); - md->longitude(get_view_long()); md->latitude(get_view_lat()); md->height(get_view_height()); diff --git a/src/ImageMetaData.cxx b/src/ImageMetaData.cxx index 09acbf9..e69627e 100644 --- a/src/ImageMetaData.cxx +++ b/src/ImageMetaData.cxx @@ -11,6 +11,8 @@ #include <math.h> #include <string.h> #include <fcntl.h> +#include <libgen.h> +#include <sys/param.h> #include <sys/types.h> #include <sys/wait.h> #include <sys/stat.h> @@ -209,12 +211,12 @@ ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) { char * args[32]; FILE *p; pid_t pid; - char buf[1024], tmpname[256]; + char buf[1024], tmpname[MAXPATHLEN]; int status, err = 0; ssize_t n; int tmp_fd; - strncpy(tmpname, "/tmp/gipfelXXXXXX", sizeof(tmpname)); + snprintf(tmpname, sizeof(tmpname), "%s/.gipfelXXXXXX", dirname(out_img)); tmp_fd = mkstemp(tmpname); if (tmp_fd < 0) { perror("mkstemp"); @@ -261,34 +263,16 @@ ImageMetaData::save_image_jpgcom(char *in_img, char *out_img) { err++; } - if (!err) { - int out_fd = open(out_img, O_WRONLY|O_TRUNC|O_CREAT, S_IRUSR|S_IWUSR); + close(tmp_fd); - lseek(tmp_fd, 0, SEEK_SET); - - if (out_fd == -1) { - perror("open"); + if (!err) { + if (rename(tmpname, out_img) != 0) { + perror("rename"); err++; - } else { - while ((n = read(tmp_fd, buf, sizeof(buf)))) { - if (write(out_fd, buf, n) != n) { - perror("write"); - fprintf(stderr, "ERROR: Image %s might be corrupted. " - "A copy is still available at %s\n", out_img, tmpname); - err++; - break; - } - } - - close(out_fd); + unlink(tmpname); } } - close(tmp_fd); - - if (!err) - unlink(tmpname); - return err != 0; } diff --git a/src/gipfel.cxx b/src/gipfel.cxx index b8c2fbe..ce90816 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -71,7 +71,7 @@ confirm_overwrite(const char *f) { struct stat sb; if (stat(f, &sb) == 0) - return fl_choice("The file exists.\n", "Cancel", "Overwrite", NULL); + return fl_choice("%s exists.\n", "Cancel", "Overwrite", NULL, f); else return 1; } |