~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to plug-ins/common/compressor.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 * Copyright (C) 1997 Daniel Risacher, magnus@alum.mit.edu
4
4
 *
59
59
 
60
60
#include "config.h"
61
61
 
62
 
#include <stdlib.h>
63
 
#include <stdio.h>
 
62
#include <string.h>
 
63
#include <errno.h>
 
64
 
64
65
#include <sys/types.h>
 
66
 
65
67
#ifdef HAVE_SYS_PARAM_H
66
68
#include <sys/param.h>
67
69
#endif
 
70
 
68
71
#ifdef HAVE_SYS_WAIT_H
69
72
#include <sys/wait.h>
70
73
#endif
 
74
 
71
75
#include <sys/stat.h>
72
 
#include <string.h>
 
76
 
73
77
#ifdef HAVE_UNISTD_H
74
78
#include <unistd.h>
75
79
#endif
76
 
#include <errno.h>
 
80
 
 
81
#include <glib/gstdio.h>
77
82
 
78
83
#include <libgimp/gimp.h>
79
84
 
157
162
    ".xcfgz",
158
163
    ".gz",
159
164
 
160
 
    "file_gz_load",
 
165
    "file-gz-load",
161
166
    "loads files compressed with gzip",
162
167
    "You need to have gzip installed.",
163
168
    "gzip", "-cfd",
164
169
    "minigzip -d",
165
170
 
166
 
    "file_gz_save",
 
171
    "file-gz-save",
167
172
    "saves files compressed with gzip",
168
173
    "You need to have gzip installed.",
169
174
    "gzip", "-cfn",
178
183
    ".xcfbz2",
179
184
    ".bz2",
180
185
 
181
 
    "file_bz2_load",
 
186
    "file-bz2-load",
182
187
    "loads files compressed with bzip2",
183
188
    "You need to have bzip2 installed.",
184
189
    "bzip2", "-cfd",
185
190
    "bzip2 -cfd",
186
191
 
187
 
    "file_bz2_save",
 
192
    "file-bz2-save",
188
193
    "saves files compressed with bzip2",
189
194
    "You need to have bzip2 installed",
190
195
    "bzip2", "-cf",
192
197
  }
193
198
};
194
199
 
195
 
GimpPlugInInfo PLUG_IN_INFO =
 
200
const GimpPlugInInfo PLUG_IN_INFO =
196
201
{
197
202
  NULL,  /* init_proc  */
198
203
  NULL,  /* quit_proc  */
207
212
static void
208
213
query (void)
209
214
{
210
 
  static GimpParamDef load_args[] =
 
215
  static const GimpParamDef load_args[] =
211
216
  {
212
 
    { GIMP_PDB_INT32,  "run_mode",     "Interactive, non-interactive" },
 
217
    { GIMP_PDB_INT32,  "run-mode",     "Interactive, non-interactive" },
213
218
    { GIMP_PDB_STRING, "filename",     "The name of the file to load" },
214
 
    { GIMP_PDB_STRING, "raw_filename", "The name entered"             }
 
219
    { GIMP_PDB_STRING, "raw-filename", "The name entered"             }
215
220
  };
216
 
  static GimpParamDef load_return_vals[] =
 
221
  static const GimpParamDef load_return_vals[] =
217
222
  {
218
223
    { GIMP_PDB_IMAGE, "image", "Output image" },
219
224
  };
220
225
 
221
 
  static GimpParamDef save_args[] =
 
226
  static const GimpParamDef save_args[] =
222
227
  {
223
 
    { GIMP_PDB_INT32,    "run_mode",     "Interactive, non-interactive" },
224
 
    { GIMP_PDB_IMAGE,    "image",        "Input image" },
225
 
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save" },
226
 
    { GIMP_PDB_STRING,   "filename",     "The name of the file to save the image in" },
227
 
    { GIMP_PDB_STRING,   "raw_filename", "The name of the file to save the image in" }
 
228
    { GIMP_PDB_INT32,    "run-mode",     "Interactive, non-interactive" },
 
229
    { GIMP_PDB_IMAGE,    "image",        "Input image"                  },
 
230
    { GIMP_PDB_DRAWABLE, "drawable",     "Drawable to save"             },
 
231
    { GIMP_PDB_STRING,   "filename",     "The name of the file to "
 
232
                                         "save the image in"            },
 
233
    { GIMP_PDB_STRING,   "raw-filename", "The name entered"             },
228
234
  };
229
235
 
230
236
  gint i;
364
370
 
365
371
  if (! ext)
366
372
    {
367
 
      g_message (_("No sensible extension, saving as compressed XCF."));
 
373
      g_message (_("No sensible file extension, saving as compressed XCF."));
368
374
      ext = ".xcf";
369
375
    }
370
376
 
378
384
                         tmpname,
379
385
                         tmpname) && valid_file (tmpname)))
380
386
    {
381
 
      unlink (tmpname);
 
387
      g_unlink (tmpname);
382
388
      g_free (tmpname);
383
389
      return GIMP_PDB_EXECUTION_ERROR;
384
390
    }
399
405
      {
400
406
        FILE *f;
401
407
 
402
 
        if (!(f = fopen (filename, "w")))
 
408
        if (!(f = g_fopen (filename, "w")))
403
409
          {
404
410
            g_message (_("Could not open '%s' for writing: %s"),
405
411
                       gimp_filename_to_utf8 (filename), g_strerror (errno));
450
456
    STARTUPINFO          startupinfo;
451
457
    PROCESS_INFORMATION  processinfo;
452
458
 
453
 
    in  = fopen (tmpname, "rb");
454
 
    out = fopen (filename, "wb");
 
459
    in  = g_fopen (tmpname, "rb");
 
460
    out = g_fopen (filename, "wb");
 
461
 
 
462
    if (in == NULL)
 
463
      {
 
464
        g_message (_("Could not open '%s' for reading: %s"),
 
465
                   gimp_filename_to_utf8 (tmpname), g_strerror (errno));
 
466
        g_free (tmpname);
 
467
 
 
468
        return GIMP_PDB_EXECUTION_ERROR;
 
469
      }
 
470
 
 
471
    if (out == NULL)
 
472
      {
 
473
        g_message (_("Could not open '%s' for writing: %s"),
 
474
                   gimp_filename_to_utf8 (filename), g_strerror (errno));
 
475
        g_free (tmpname);
 
476
        
 
477
        return GIMP_PDB_EXECUTION_ERROR;
 
478
      }
455
479
 
456
480
    startupinfo.cb          = sizeof (STARTUPINFO);
457
481
    startupinfo.lpReserved  = NULL;
485
509
  }
486
510
#endif /* G_OS_WIN32 */
487
511
 
488
 
  unlink (tmpname);
 
512
  g_unlink (tmpname);
489
513
  g_free (tmpname);
490
514
 
 
515
  /* ask the core to save a thumbnail for compressed XCF files */
 
516
  if (strcmp (ext, ".xcf") == 0)
 
517
    gimp_file_save_thumbnail (image_ID, filename);
 
518
 
491
519
  return GIMP_PDB_SUCCESS;
492
520
}
493
521
 
505
533
 
506
534
  if (! ext)
507
535
    {
508
 
      g_message (_("No sensible extension, attempting to load "
509
 
                   "with file magic."));
 
536
      g_message (_("No sensible file extension, "
 
537
                   "attempting to load with file magic."));
510
538
      ext = ".foo";
511
539
    }
512
540
 
530
558
      {
531
559
        FILE *f;
532
560
 
533
 
        if (! (f = fopen (tmpname, "w")))
 
561
        if (! (f = g_fopen (tmpname, "w")))
534
562
          {
535
563
            g_message (_("Could not open '%s' for writing: %s"),
536
564
                       gimp_filename_to_utf8 (tmpname), g_strerror (errno));
586
614
    STARTUPINFO          startupinfo;
587
615
    PROCESS_INFORMATION  processinfo;
588
616
 
589
 
    in  = fopen (filename, "rb");
590
 
    out = fopen (tmpname, "wb");
 
617
    in  = g_fopen (filename, "rb");
 
618
    out = g_fopen (tmpname, "wb");
 
619
 
 
620
    if (in == NULL)
 
621
      {
 
622
        g_message (_("Could not open '%s' for reading: %s"),
 
623
                   gimp_filename_to_utf8 (filename), g_strerror (errno));
 
624
        g_free (tmpname);
 
625
       
 
626
        *status = GIMP_PDB_EXECUTION_ERROR;
 
627
        return -1;
 
628
      }
 
629
 
 
630
    if (out == NULL)
 
631
      {
 
632
        g_message (_("Could not open '%s' for writing: %s"),
 
633
                   gimp_filename_to_utf8 (tmpname), g_strerror (errno));
 
634
        g_free (tmpname);
 
635
 
 
636
        *status = GIMP_PDB_EXECUTION_ERROR;
 
637
        return -1;
 
638
      }
591
639
 
592
640
    startupinfo.cb          = sizeof (STARTUPINFO);
593
641
    startupinfo.lpReserved  = NULL;
626
674
 
627
675
  image_ID = gimp_file_load (run_mode, tmpname, tmpname);
628
676
 
629
 
  unlink (tmpname);
 
677
  g_unlink (tmpname);
630
678
  g_free (tmpname);
631
679
 
632
680
  if (image_ID != -1)
647
695
{
648
696
  struct stat buf;
649
697
 
650
 
  return stat (filename, &buf) == 0 && buf.st_size > 0;
 
698
  return g_stat (filename, &buf) == 0 && buf.st_size > 0;
651
699
}
652
700
 
653
701
static const gchar *
665
713
 
666
714
  while (TRUE)
667
715
    {
668
 
      if (!ext || ext[1] == '\0' || strchr (ext, '/'))
 
716
      if (!ext || ext[1] == '\0' || strchr (ext, G_DIR_SEPARATOR))
669
717
        {
670
718
          return NULL;
671
719
        }
 
720
 
672
721
      if (0 == g_ascii_strcasecmp (ext, compressor->xcf_extension))
673
722
        {
674
723
          return ".xcf";  /* we've found it */