~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.surf.contour/dseg_open.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <unistd.h>
2
 
#include <sys/types.h>
3
 
#include <sys/stat.h>
4
 
#include <fcntl.h>
5
 
#include <grass/gis.h>
6
 
#include "seg.h"
7
 
 
8
 
int dseg_open(DSEG * dseg, int srows, int scols, int nsegs_in_memory)
9
 
{
10
 
    char *filename;
11
 
    int errflag;
12
 
    int fd;
13
 
 
14
 
    dseg->filename = NULL;
15
 
    dseg->fd = -1;
16
 
    dseg->name = NULL;
17
 
    dseg->mapset = NULL;
18
 
 
19
 
    filename = G_tempfile();
20
 
    if (-1 == (fd = creat(filename, 0666))) {
21
 
        G_warning("dseg_open(): unable to create segment file");
22
 
        return -2;
23
 
    }
24
 
    if (0 >
25
 
        (errflag =
26
 
         segment_format(fd, G_window_rows(), G_window_cols(), srows, scols,
27
 
                        sizeof(DCELL)))) {
28
 
        close(fd);
29
 
        unlink(filename);
30
 
        if (errflag == -1) {
31
 
            G_warning("dseg_open(): could not write segment file");
32
 
            return -1;
33
 
        }
34
 
        else {
35
 
            G_warning("dseg_open(): illegal configuration parameter(s)");
36
 
            return -3;
37
 
        }
38
 
    }
39
 
    close(fd);
40
 
    if (-1 == (fd = open(filename, 2))) {
41
 
        unlink(filename);
42
 
        G_warning("dseg_open(): unable to re-open segment file");
43
 
        return -4;
44
 
    }
45
 
    if (0 > (errflag = segment_init(&(dseg->seg), fd, nsegs_in_memory))) {
46
 
        close(fd);
47
 
        unlink(filename);
48
 
        if (errflag == -1) {
49
 
            G_warning("cseg_open(): could not read segment file");
50
 
            return -5;
51
 
        }
52
 
        else {
53
 
            G_warning("cseg_open(): out of memory");
54
 
            return -6;
55
 
        }
56
 
    }
57
 
    dseg->filename = filename;
58
 
    dseg->fd = fd;
59
 
    return 0;
60
 
}