GRASS 8 Programmer's Manual
8.5.0(2026)-8d6ceba290
Toggle main menu visibility
Loading...
Searching...
No Matches
segment/seek.c
Go to the documentation of this file.
1
/**
2
* \file lib/segment/seek.c
3
*
4
* \brief Segment seek routines.
5
*
6
* This program is free software under the GNU General Public License
7
* (>=v2). Read the file COPYING that comes with GRASS for details.
8
*
9
* \author GRASS Development Team
10
*
11
* \date 2005-2009
12
*/
13
14
#include <stdio.h>
15
#include <sys/types.h>
16
#include <unistd.h>
17
#include <string.h>
18
#include <errno.h>
19
#include <grass/gis.h>
20
#include "local_proto.h"
21
22
/**
23
* \brief Internal use only
24
*
25
* Seek into a segment.
26
*
27
* \param[in,out] SEG segment
28
* \param[in] n
29
* \param[in] index
30
* \return 0 on success
31
* \return -1 if unable to seek
32
*/
33
34
#define SEG_SEEK_FAST(SEG, n, index) \
35
((((off_t)(n)) << (SEG)->sizebits) + (index) + (SEG)->offset)
36
37
#define SEG_SEEK_SLOW(SEG, n, index) \
38
((off_t)(n) * (SEG)->size + (index) + (SEG)->offset)
39
40
int
seg_seek_fast
(
const
SEGMENT *SEG,
int
n,
int
index)
41
{
42
if
(lseek((SEG)->fd,
SEG_SEEK_FAST
(SEG, n, index), SEEK_SET) == -1) {
43
G_fatal_error
(
"Segment seek: %s"
, strerror(errno));
44
}
45
46
return
0;
47
}
48
49
int
seg_seek_slow
(
const
SEGMENT *SEG,
int
n,
int
index)
50
{
51
if
(lseek((SEG)->fd,
SEG_SEEK_SLOW
(SEG, n, index), SEEK_SET) == -1) {
52
G_fatal_error
(
"Segment seek: %s"
, strerror(errno));
53
}
54
55
return
0;
56
}
57
58
int
seg_seek
(
const
SEGMENT *SEG,
int
n,
int
index)
59
{
60
return
SEG->seek(SEG, n, index);
61
}
G_fatal_error
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition
gis/error.c:159
seg_seek
int seg_seek(const SEGMENT *SEG, int n, int index)
Definition
segment/seek.c:58
seg_seek_fast
int seg_seek_fast(const SEGMENT *SEG, int n, int index)
Definition
segment/seek.c:40
seg_seek_slow
int seg_seek_slow(const SEGMENT *SEG, int n, int index)
Definition
segment/seek.c:49
SEG_SEEK_FAST
#define SEG_SEEK_FAST(SEG, n, index)
Internal use only.
Definition
segment/seek.c:34
SEG_SEEK_SLOW
#define SEG_SEEK_SLOW(SEG, n, index)
Definition
segment/seek.c:37
segment
seek.c
Generated on
for GRASS 8 Programmer's Manual by
1.17.0