GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r72999
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 <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 */
27 off_t G_ftell(FILE *fp)
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 */
48 void G_fseek(FILE *fp, off_t offset, int whence)
49 {
50 #ifdef HAVE_FSEEKO
51  if (fseeko(fp, offset, whence) != 0)
52  G_fatal_error(_("Unable to seek"));
53 #else
54  long loff = (long) offset;
55  if ((off_t) loff != offset)
56  G_fatal_error(_("Seek offset out of range"));
57  if (fseek(fp, loff, whence) != 0)
58  G_fatal_error(_("Unable to seek"));
59 #endif
60 }
off_t G_ftell(FILE *fp)
Get the current file position of the stream.
Definition: gis/seek.c:27
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:160
void G_fseek(FILE *fp, off_t offset, int whence)
Change the file position of the stream.
Definition: gis/seek.c:48
#define _(str)
Definition: glocale.h:13