GRASS 8 Programmer's Manual 8.5.0RC1(2026)-3334b87d9c
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 */
29off_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 */
50void 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}
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition gis/error.c:159
off_t G_ftell(FILE *fp)
Get the current file position of the stream.
Definition gis/seek.c:29
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)