Sfoglia il codice sorgente

Add G_fseek(), G_ftell()

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@35818 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 16 anni fa
parent
commit
a1fb6123fe
2 ha cambiato i file con 36 aggiunte e 0 eliminazioni
  1. 6 0
      include/gisdefs.h
  2. 30 0
      lib/gis/seek.c

+ 6 - 0
include/gisdefs.h

@@ -44,6 +44,8 @@
 # define G__freea(p) G_free(p)
 #endif
 
+#include <sys/types.h>
+
 /* adj_cellhd.c */
 const char *G_adjust_Cell_head(struct Cell_head *, int, int);
 const char *G_adjust_Cell_head3(struct Cell_head *, int, int, int);
@@ -1050,6 +1052,10 @@ DCELL G_get_raster_sample(
     int, const struct Cell_head *, struct Categories *, double, double, int,
     INTERP_TYPE);
 
+/* seek.c */
+off_t G_ftell(FILE *);
+void G_fseek(FILE *, off_t, int);
+
 /* set_window.c */
 void G_get_set_window(struct Cell_head *);
 int G_set_window(struct Cell_head *);

+ 30 - 0
lib/gis/seek.c

@@ -0,0 +1,30 @@
+
+#include <grass/config.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+off_t G_ftell(FILE *fp)
+{
+#ifdef HAVE_LARGEFILES
+    return ftello(fp);
+#else
+    return (off_t) ftell(fp);
+#endif     
+}
+
+void G_fseek(FILE *fp, off_t offset, int whence)
+{
+#ifdef HAVE_LARGEFILES
+    if (fseeko(fp, offset, whence) != 0)
+	G_fatal_error(_("unable to seek"));
+#else
+    long loff = (long) offset;
+    if ((off_t) loff != offset)
+	G_fatal_error(_("seek offset out of range"));
+    if (fseek(fp, loff, whence) != 0)
+	G_fatal_error(_("unable to seek"));
+#endif     
+}
+