GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
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  G_fatal_error(_("Unable to seek: %s"), strerror(errno));
55 #else
56  long loff = (long) offset;
57  if ((off_t) loff != offset)
58  G_fatal_error(_("Seek offset out of range"));
59  if (fseek(fp, loff, whence) != 0)
60  G_fatal_error(_("Unable to seek: %s"), strerror(errno));
61 #endif
62 }
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
off_t G_ftell(FILE *fp)
Get the current file position of the stream.
Definition: gis/seek.c:29
void G_fseek(FILE *fp, off_t offset, int whence)
Change the file position of the stream.
Definition: gis/seek.c:50
#define _(str)
Definition: glocale.h:10