GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
gis/seek.c
Go to the documentation of this file.
1
/*!
2
* \file lib/gis/seek.c
3
*
4
* \brief GIS Library - file seek routines
5
*
6
* (C) 2009-2010 by the GRASS Development Team
7
*
8
* This program is free software under the GNU General Public License
9
* (>=v2). Read the file COPYING that comes with GRASS for details.
10
*
11
* \author Glynn Clements
12
*/
13
14
#include <stdio.h>
15
#include <errno.h>
16
#include <string.h>
17
#include <sys/types.h>
18
#include <grass/gis.h>
19
#include <grass/glocale.h>
20
21
/*!
22
\brief Get the current file position of the stream.
23
24
\param fp file descriptor
25
26
\return file position
27
\return -1 on failure
28
*/
29
off_t
G_ftell
(FILE *fp)
30
{
31
#ifdef HAVE_FSEEKO
32
return
ftello(fp);
33
#else
34
return
(off_t)ftell(fp);
35
#endif
36
}
37
38
/*!
39
\brief Change the file position of the stream.
40
41
The value of <i>whence</i> must be one of the constants `SEEK_SET',
42
`SEEK_CUR', or `SEEK_END', to indicate whether the <i>offset</i> is
43
relative to the beginning of the file, the current file position, or
44
the end of the file, respectively.
45
46
\param fp file descriptor
47
\param offset offset
48
\param whence
49
*/
50
void
G_fseek(FILE *fp, off_t offset,
int
whence)
51
{
52
#ifdef HAVE_FSEEKO
53
if
(fseeko(fp, offset, whence) != 0) {
54
int
err
= errno;
55
G_fatal_error
(_(
"File read/write operation failed: %s (%d)"
),
56
strerror(
err
),
err
);
57
}
58
#else
59
long
loff = (long)offset;
60
61
if
((off_t)loff != offset)
62
G_fatal_error
(_(
"Seek offset out of range"
));
63
if
(fseek(fp, loff, whence) != 0) {
64
int
err
= errno;
65
G_fatal_error
(_(
"File read/write operation failed: %s (%d)"
),
66
strerror(
err
),
err
);
67
}
68
#endif
69
}
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition
gis/error.c:159
G_ftell
off_t G_ftell(FILE *fp)
Get the current file position of the stream.
Definition
gis/seek.c:29
err
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
Definition
symbol/read.c:216
gis
seek.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0