xcf-seek.cpp
1/* The GIMP -- an image manipulation program
2 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3 *
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 2 of the License, or
7 * (at your option) any later version.
8 *
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.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18
19#include "config.h"
20
21#include <stdio.h>
22#include <errno.h>
23
24#include <glib-object.h>
25
26#include "core/core-types.h"
27
28#include "xcf-private.h"
29#include "xcf-seek.h"
30
31#include "gimp-intl.h"
32
33bool
34xcf_seek_pos (XcfInfo *info,
35 TQ_UINT32 pos,
36 GError **error)
37{
38 if (info->cp != pos)
39 {
40 info->cp = pos;
41 if (fseek (info->fp, info->cp, SEEK_SET) == -1)
42 {
43 g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
44 _("Could not seek in XCF file: %s"),
45 g_strerror (errno));
46
47 return false;
48 }
49 }
50
51 return true;
52}
53
54bool
55xcf_seek_end (XcfInfo *info,
56 GError **error)
57{
58 if (fseek (info->fp, 0, SEEK_END) == -1)
59 {
60 g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
61 _("Could not seek in XCF file: %s"),
62 g_strerror (errno));
63
64 return false;
65 }
66
67 info->cp = ftell (info->fp);
68
69 if (fseek (info->fp, 0, SEEK_END) == -1)
70 {
71 g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
72 _("Could not seek in XCF file: %s"),
73 g_strerror (errno));
74
75 return false;
76 }
77
78 return true;
79}