app: s/sprintf/g_snprintf/ in xcf_save_image()
[gimp.git] / pdb / util.pl
blob69b26f49a3c13d9609f570591831a0a66e73fa38
1 # GIMP - The GNU Image Manipulation Program
2 # Copyright (C) 1998-2003 Manish Singh <yosh@gimp.org>
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
17 package Gimp::CodeGen::util;
19 use File::Basename 'basename';
20 use File::Copy 'cp';
21 use File::Compare 'cmp';
23 $DEBUG_OUTPUT = exists $ENV{PDBGEN_BACKUP} ? $ENV{PDBGEN_BACKUP} : 1;
25 $FILE_EXT = ".tmp.$$";
27 sub write_file {
28 my $file = shift;
29 my $destdir = shift;
31 my $realfile = basename($file);
32 $realfile =~ s/$FILE_EXT$//;
33 $realfile = "$destdir/$realfile";
35 if (-e $realfile) {
36 if (cmp($realfile, $file)) {
37 cp($realfile, "$realfile~") if $DEBUG_OUTPUT;
38 cp($file, $realfile);
39 print "Wrote $realfile\n";
41 else {
42 print "No changes to $realfile\n";
44 unlink $file;
46 else {
47 rename $file, $realfile;
48 print "Wrote $realfile\n";