~ubuntu-branches/ubuntu/precise/xfdesktop4/precise

« back to all changes in this revision

Viewing changes to common/xfdesktop-common.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-07 21:40:36 UTC
  • mfrom: (1.1.30 upstream)
  • Revision ID: james.westby@ubuntu.com-20101207214036-vtrnsza407lfs4i3
Tags: 4.7.4-0ubuntu1
Upload to natty (pkg-xfce svn r4625), no Ubuntu changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include <stdio.h>
26
26
 
 
27
#ifdef HAVE_FCNTL_H
 
28
#include <fcntl.h>
 
29
#endif
 
30
 
27
31
#ifdef HAVE_STRING_H
28
32
#include <string.h>
29
33
#endif
42
46
 
43
47
#include <glib.h>
44
48
#include <gdk/gdkx.h>
 
49
#include <gtk/gtk.h>
 
50
 
45
51
#include <libxfce4util/libxfce4util.h>
46
 
#include <libxfcegui4/dialogs.h>
47
52
 
48
53
#include "xfdesktop-common.h"
49
54
 
 
55
#ifndef O_BINARY
 
56
#define O_BINARY  0
 
57
#endif
 
58
 
50
59
gboolean
51
60
xfdesktop_backdrop_list_is_valid(const gchar *path)
52
61
{
258
267
xfdesktop_image_file_is_valid(const gchar *filename)
259
268
{
260
269
    GdkPixbufLoader *loader;
261
 
    FILE *fp;
 
270
    int fd;
262
271
    gboolean size_read = FALSE;
263
272
    guchar buf[4096];
264
 
    gint len;
 
273
    gsize len;
265
274
 
266
275
    g_return_val_if_fail(filename, FALSE);
267
276
    
268
 
    fp = fopen(filename, "rb");
269
 
    if(!fp)
 
277
    fd = open(filename, O_RDONLY|O_BINARY);
 
278
    if(fd < 0)
270
279
        return FALSE;
271
280
    
272
281
    loader = gdk_pixbuf_loader_new();
273
282
    g_signal_connect(G_OBJECT(loader), "size-prepared",
274
283
            G_CALLBACK(pixbuf_loader_size_cb), &size_read);
275
284
    
276
 
    while(!feof(fp) && !ferror(fp)) {
277
 
        if((len=fread(buf, 1, sizeof(buf), fp)) > 0) {
 
285
    do {
 
286
        len = read(fd, buf, sizeof(buf));
 
287
        if(len > 0) {
278
288
            if(!gdk_pixbuf_loader_write(loader, buf, len, NULL))
279
289
                break;
280
290
            if(size_read)
281
291
                break;
282
292
        }
283
 
    }
 
293
    } while(len > 0);
284
294
    
285
 
    fclose(fp);
 
295
    close(fd);
286
296
    gdk_pixbuf_loader_close(loader, NULL);
287
297
    g_object_unref(G_OBJECT(loader));
288
298