int G_close_cell(int fd) { struct fileinfo *fcb = &G__.fileinfo[fd]; if (fd < 0 || fd >= G__.fileinfo_count || fcb->open_mode <= 0) return -1; if (fcb->open_mode == OPEN_OLD) return close_old(fd); return close_new(fd, 1); }
static int close_new(RASTER3D_Map * map) { char path[GPATH_MAX]; struct Categories cats; struct History hist; Rast3d_remove_color(map->fileName); /* create empty cats file */ Rast_init_cats(NULL, &cats); Rast3d_write_cats(map->fileName, &cats); Rast_free_cats(&cats); /*generate the history file, use the normal G_ functions */ Rast_short_history(map->fileName, "raster3d", &hist); Rast_command_history(&hist); /*Use the G3d function to write the history file, * otherwise the path is wrong */ if (Rast3d_write_history(map->fileName, &hist) < 0) { G_warning(_("Unable to write history for 3D raster map <%s>"), map->fileName); } Rast3d_range_write(map); close(map->data_fd); /* finally move tempfile to data file */ Rast3d_filename(path, RASTER3D_CELL_ELEMENT, map->fileName, map->mapset); #ifdef __MINGW32__ if (CopyFile(map->tempName, path, FALSE) == 0) { #else if (link(map->tempName, path) < 0) { #endif if (rename(map->tempName, path)) { G_warning(_("Unable to move temp raster map <%s> to 3D raster map <%s>"), map->tempName, path); return 0; } } else remove(map->tempName); return 1; } static int close_cell_new(RASTER3D_Map * map) { long ltmp; if (map->useCache) if (!Rast3d_flush_all_tiles(map)) { G_warning(_("Unable to flush all tiles")); return 0; } if (!Rast3d_flush_index(map)) { G_warning(_("Unable to flush index")); return 0; } /* write the header info which was filled with dummy values at the */ /* opening time */ if (lseek(map->data_fd, (long)(map->offset - sizeof(int) - sizeof(long)), SEEK_SET) == -1) { G_warning(_("Unable to position file")); return 0; } if (!Rast3d_write_ints(map->data_fd, map->useXdr, &(map->indexNbytesUsed), 1)) { G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName); return 0; } Rast3d_long_encode(&(map->indexOffset), (unsigned char *)<mp, 1); if (write(map->data_fd, <mp, sizeof(long)) != sizeof(long)) { G_warning(_("Unable to write header for 3D raster map <%s>"), map->fileName); return 0; } if (!close_new(map) != 0) { G_warning(_("Unable to create 3D raster map <%s>"), map->fileName); return 0; } return 1; }