GRASS 8 Programmer's Manual 8.6.0dev(2026)-55de52a352
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 * SPDX-FileCopyrightText: 2009-2010 GRASS Development Team
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 *
9 * \author Glynn Clements
10 */
11
12#include <stdio.h>
13#include <errno.h>
14#include <string.h>
15#include <sys/types.h>
16#include <grass/gis.h>
17#include <grass/glocale.h>
18
19/*!
20 \brief Get the current file position of the stream.
21
22 \param fp file descriptor
23
24 \return file position
25 \return -1 on failure
26 */
28{
29#ifdef HAVE_FSEEKO
30 return ftello(fp);
31#else
32 return (off_t)ftell(fp);
33#endif
34}
35
36/*!
37 \brief Change the file position of the stream.
38
39 The value of <i>whence</i> must be one of the constants `SEEK_SET',
40 `SEEK_CUR', or `SEEK_END', to indicate whether the <i>offset</i> is
41 relative to the beginning of the file, the current file position, or
42 the end of the file, respectively.
43
44 \param fp file descriptor
45 \param offset offset
46 \param whence
47 */
48void G_fseek(FILE *fp, off_t offset, int whence)
49{
50#ifdef HAVE_FSEEKO
51 if (fseeko(fp, offset, whence) != 0) {
52 int err = errno;
53 G_fatal_error(_("File read/write operation failed: %s (%d)"),
54 strerror(err), err);
55 }
56#else
57 long loff = (long)offset;
58
59 if ((off_t)loff != offset)
60 G_fatal_error(_("Seek offset out of range"));
61 if (fseek(fp, loff, whence) != 0) {
62 int err = errno;
63 G_fatal_error(_("File read/write operation failed: %s (%d)"),
64 strerror(err), err);
65 }
66#endif
67}
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_fseek(FILE *fp, off_t offset, int whence)
Change the file position of the stream.
Definition gis/seek.c:48
off_t G_ftell(FILE *fp)
Get the current file position of the stream.
Definition gis/seek.c:27
#define _(str)
Definition glocale.h:10
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)