|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Don't overwrite the output file v2In case the output file specified via -F already exists, it is overwritten
without a hint to the user. The patch changes the behavior so that an output file is never touched if it is already there. History: v1 Initial patch v2 Open file for reading instead of writing diff --git a/main.c b/main.c index 778d687..691cd27 100644 --- a/main.c +++ b/main.c @@ -218,6 +218,21 @@ print_extended_info(void) "\n"); } +/** + * @return 1 if file exits and is writeable, otherwise 0 + */ +static int +file_writeable(const char *filename) +{ + FILE *f = fopen(filename, "r"); + int retval = f != NULL; + + if (f != NULL) + fclose(f); + + return retval; +} + int main(int argc, char *argv[]) { @@ -373,6 +388,12 @@ main(int argc, char *argv[]) if (ofname == NULL) { fatal ("No output file or device name specified.\n"); } + + if (file_writeable(ofname)) + { + fatal ("Output file already exists.\n"); + } + if (ovecs && (!(global_opts.masked_objective & POSNDATAMASK))) { /* simulates the default behaviour of waypoints */ if (doing_nothing) ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
|
|
Re: Don't overwrite the output file v2This just won't work. We have formats that use "imaginary" files (e.g. "usb:") and we have formats that use multiple files where you're just providing an extension such as shape and Ozi. We have devices that'll hang unless you call open with Magic flags. More importantly, it changes a user-visible behavior in an incompatible way. I know I have lots of scripts that rely on -F acting like most other programs that write files and I'm sure I'm not alone.
cc -c -o foo.o foo.c doesn't double guess my intent. I'm totally hip with an "are you sure" in the GUI (and we have one) but I can't get behind it in the command line invocation. RJL: On Thu, Sep 10, 2009 at 6:17 PM, Stefan Bauer <yoltia-maintain@...> wrote: In case the output file specified via -F already exists, it is overwritten ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Gpsbabel-code mailing list http://www.gpsbabel.org Gpsbabel-code@... https://lists.sourceforge.net/lists/listinfo/gpsbabel-code |
| Free embeddable forum powered by Nabble | Forum Help |