GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71806
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
portable.c File Reference
#include <sys/types.h>
#include <string.h>
#include <grass/vector.h>
#include <grass/glocale.h>
Include dependency graph for portable.c:

Go to the source code of this file.

Functions

void port_init (void)
 Initialize Port_info structures. More...
 
int dig__fread_port_D (double *buf, size_t cnt, struct gvfile *fp)
 Read doubles from the Portable Vector Format. More...
 
int dig__fread_port_F (float *buf, size_t cnt, struct gvfile *fp)
 Read floats from the Portable Vector Format. More...
 
int dig__fread_port_O (off_t *buf, size_t cnt, struct gvfile *fp, size_t port_off_t_size)
 Read off_ts from the Portable Vector Format. More...
 
int dig__fread_port_L (long *buf, size_t cnt, struct gvfile *fp)
 Read longs from the Portable Vector Format. More...
 
int dig__fread_port_I (int *buf, size_t cnt, struct gvfile *fp)
 Read integers from the Portable Vector Format. More...
 
int dig__fread_port_S (short *buf, size_t cnt, struct gvfile *fp)
 Read shorts from the Portable Vector Format. More...
 
int dig__fread_port_C (char *buf, size_t cnt, struct gvfile *fp)
 Read chars from the Portable Vector Format. More...
 
int dig__fread_port_P (plus_t *buf, size_t cnt, struct gvfile *fp)
 Read plus_t from the Portable Vector Format. More...
 
int dig__fwrite_port_D (const double *buf, size_t cnt, struct gvfile *fp)
 Write doubles to the Portable Vector Format. More...
 
int dig__fwrite_port_F (const float *buf, size_t cnt, struct gvfile *fp)
 Write floats to the Portable Vector Format. More...
 
int dig__fwrite_port_O (const off_t *buf, size_t cnt, struct gvfile *fp, size_t port_off_t_size)
 Write off_ts to the Portable Vector Format. More...
 
int dig__fwrite_port_L (const long *buf, size_t cnt, struct gvfile *fp)
 Write longs to the Portable Vector Format. More...
 
int dig__fwrite_port_I (const int *buf, size_t cnt, struct gvfile *fp)
 Write integers to the Portable Vector Format. More...
 
int dig__fwrite_port_S (const short *buf, size_t cnt, struct gvfile *fp)
 Write shorts to the Portable Vector Format. More...
 
int dig__fwrite_port_P (const plus_t *buf, size_t cnt, struct gvfile *fp)
 Write plus_t to the Portable Vector Format. More...
 
int dig__fwrite_port_C (const char *buf, size_t cnt, struct gvfile *fp)
 Write chars to the Portable Vector Format. More...
 
void dig_init_portable (struct Port_info *port, int byte_order)
 Set Port_info structure to byte order of file. More...
 
int dig_set_cur_port (struct Port_info *port)
 Set current Port_info structure. More...
 
int dig__byte_order_out ()
 Get byte order. More...
 

Variables

int nat_dbl
 
int nat_flt
 
int nat_lng
 
int nat_off_t
 
int nat_int
 
int nat_shrt
 
int dbl_order
 
int flt_order
 
int off_t_order
 
int lng_order
 
int int_order
 
int shrt_order
 
unsigned char dbl_cnvrt [sizeof(double)]
 
unsigned char flt_cnvrt [sizeof(float)]
 
unsigned char off_t_cnvrt [sizeof(off_t)]
 
unsigned char lng_cnvrt [sizeof(long)]
 
unsigned char int_cnvrt [sizeof(int)]
 
unsigned char shrt_cnvrt [sizeof(short)]
 
struct Port_infoCur_Head
 

Function Documentation

int dig__byte_order_out ( )

Get byte order.

Returns
ENDIAN_LITTLE
ENDIAN_BIG

Definition at line 1013 of file portable.c.

References dbl_order, ENDIAN_BIG, and ENDIAN_LITTLE.

Referenced by V1_open_new_nat(), Vect_cidx_save(), Vect_save_fidx(), Vect_save_sidx(), and Vect_save_topo().

int dig__fread_port_C ( char *  buf,
size_t  cnt,
struct gvfile fp 
)

Read chars from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to gvfile structure
Returns
0 error
1 OK

Definition at line 509 of file portable.c.

References dig_fread(), and PORT_CHAR.

Referenced by dig__read_head(), dig_Rd_P_line(), dig_Rd_Plus_head(), dig_Rd_spidx_head(), dig_read_cidx_head(), V1_delete_line_nat(), V1_restore_line_nat(), and Vect_open_fidx().

int dig__fread_port_D ( double *  buf,
size_t  cnt,
struct gvfile fp 
)

Read doubles from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 79 of file portable.c.

References Port_info::dbl_cnvrt, Port_info::dbl_quick, dig_fread(), and PORT_DOUBLE.

Referenced by dig_Rd_P_node(), dig_Rd_Plus_head(), and rtree_search().

int dig__fread_port_F ( float *  buf,
size_t  cnt,
struct gvfile fp 
)

Read floats from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 123 of file portable.c.

References dig_fread(), Port_info::flt_cnvrt, Port_info::flt_quick, and PORT_FLOAT.

Referenced by dig_Rd_P_node().

int dig__fread_port_I ( int buf,
size_t  cnt,
struct gvfile fp 
)

Read integers from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 343 of file portable.c.

References Port_info::byte_order, dig_fread(), ENDIAN_LITTLE, int, Port_info::int_cnvrt, int_order, Port_info::int_quick, nat_int, and PORT_INT.

Referenced by dig__fread_port_P(), dig_Rd_P_line(), dig_Rd_spidx_head(), dig_read_cidx(), dig_read_cidx_head(), rtree_search(), and Vect_open_fidx().

int dig__fread_port_L ( long *  buf,
size_t  cnt,
struct gvfile fp 
)

Read longs from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 260 of file portable.c.

References Port_info::byte_order, dig_fread(), ENDIAN_LITTLE, Port_info::lng_cnvrt, lng_order, Port_info::lng_quick, nat_lng, and PORT_LONG.

Referenced by dig__read_head(), dig_Rd_Plus_head(), dig_Rd_spidx_head(), dig_read_cidx_head(), and Vect_open_fidx().

int dig__fread_port_O ( off_t *  buf,
size_t  cnt,
struct gvfile fp,
size_t  port_off_t_size 
)

Read off_ts from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
port_off_t_sizeoffset
Returns
0 error
1 OK

Definition at line 167 of file portable.c.

References _, Port_info::byte_order, dig_fread(), ENDIAN_LITTLE, G_fatal_error(), nat_off_t, Port_info::off_t_cnvrt, off_t_order, and Port_info::off_t_quick.

Referenced by dig__read_head(), dig_Rd_P_line(), dig_Rd_Plus_head(), dig_Rd_spidx_head(), dig_read_cidx_head(), and rtree_search().

int dig__fread_port_P ( plus_t buf,
size_t  cnt,
struct gvfile fp 
)

Read plus_t from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

plus_t is defined as int so we only retype pointer and use int function.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 535 of file portable.c.

References dig__fread_port_I().

Referenced by dig_Rd_P_area(), dig_Rd_P_isle(), dig_Rd_P_line(), dig_Rd_P_node(), and dig_Rd_Plus_head().

int dig__fread_port_S ( short *  buf,
size_t  cnt,
struct gvfile fp 
)

Read shorts from the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
[out]bufdata buffer
cntnumber of members
fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 426 of file portable.c.

References Port_info::byte_order, dig_fread(), ENDIAN_LITTLE, nat_shrt, PORT_SHORT, Port_info::shrt_cnvrt, shrt_order, and Port_info::shrt_quick.

int dig__fwrite_port_C ( const char *  buf,
size_t  cnt,
struct gvfile fp 
)

Write chars to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 890 of file portable.c.

References dig_fwrite(), and PORT_CHAR.

Referenced by dig__write_head(), dig_Wr_P_line(), dig_Wr_Plus_head(), dig_Wr_spidx_head(), dig_write_cidx_head(), V1_delete_line_nat(), V1_restore_line_nat(), and Vect_save_fidx().

int dig__fwrite_port_D ( const double *  buf,
size_t  cnt,
struct gvfile fp 
)

Write doubles to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 557 of file portable.c.

References Port_info::dbl_cnvrt, Port_info::dbl_quick, dig_fwrite(), and PORT_DOUBLE.

Referenced by dig_Wr_P_node(), and dig_Wr_Plus_head().

int dig__fwrite_port_F ( const float *  buf,
size_t  cnt,
struct gvfile fp 
)

Write floats to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 596 of file portable.c.

References dig_fwrite(), Port_info::flt_cnvrt, Port_info::flt_quick, and PORT_FLOAT.

Referenced by dig_Wr_P_node().

int dig__fwrite_port_I ( const int buf,
size_t  cnt,
struct gvfile fp 
)

Write integers to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 758 of file portable.c.

References dig_fwrite(), ENDIAN_LITTLE, int, Port_info::int_cnvrt, int_order, Port_info::int_quick, nat_int, and PORT_INT.

Referenced by dig__fwrite_port_P(), dig_Wr_P_line(), dig_Wr_spidx_head(), dig_write_cidx(), dig_write_cidx_head(), and Vect_save_fidx().

int dig__fwrite_port_L ( const long *  buf,
size_t  cnt,
struct gvfile fp 
)

Write longs to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 702 of file portable.c.

References dig_fwrite(), ENDIAN_LITTLE, Port_info::lng_cnvrt, lng_order, Port_info::lng_quick, nat_lng, and PORT_LONG.

Referenced by dig__write_head(), dig_Wr_Plus_head(), dig_Wr_spidx_head(), dig_write_cidx_head(), and Vect_save_fidx().

int dig__fwrite_port_O ( const off_t *  buf,
size_t  cnt,
struct gvfile fp,
size_t  port_off_t_size 
)

Write off_ts to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
port_off_t_size
Returns
0 error
1 OK

Definition at line 636 of file portable.c.

References _, dig_fwrite(), ENDIAN_LITTLE, G_fatal_error(), nat_off_t, Port_info::off_t_cnvrt, off_t_order, and Port_info::off_t_quick.

Referenced by dig__write_head(), dig_Wr_P_line(), dig_Wr_Plus_head(), dig_Wr_spidx_head(), and dig_write_cidx_head().

int dig__fwrite_port_P ( const plus_t buf,
size_t  cnt,
struct gvfile fp 
)

Write plus_t to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 871 of file portable.c.

References dig__fwrite_port_I().

Referenced by dig_Wr_P_area(), dig_Wr_P_isle(), dig_Wr_P_line(), dig_Wr_P_node(), and dig_Wr_Plus_head().

int dig__fwrite_port_S ( const short *  buf,
size_t  cnt,
struct gvfile fp 
)

Write shorts to the Portable Vector Format.

These routines must handle any type size conversions between the portable format and the native machine.

Parameters
bufdata buffer
cntnumber of members
[in,out]fppointer to struct gvfile
Returns
0 error
1 OK

Definition at line 814 of file portable.c.

References dig_fwrite(), ENDIAN_LITTLE, nat_shrt, PORT_SHORT, Port_info::shrt_cnvrt, shrt_order, and Port_info::shrt_quick.

Variable Documentation

struct Port_info* Cur_Head

Definition at line 45 of file portable.c.

unsigned char dbl_cnvrt[sizeof(double)]

Definition at line 124 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

int dbl_order

Definition at line 117 of file port_init.c.

Referenced by dig__byte_order_out(), dig_init_portable(), main(), and port_init().

unsigned char flt_cnvrt[sizeof(float)]

Definition at line 125 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

int flt_order

Definition at line 118 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

unsigned char int_cnvrt[sizeof(int)]

Definition at line 128 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

int int_order
unsigned char lng_cnvrt[sizeof(long)]

Definition at line 127 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

int lng_order
int nat_dbl

Definition at line 110 of file port_init.c.

Referenced by main(), and port_init().

int nat_flt

Definition at line 111 of file port_init.c.

Referenced by main(), and port_init().

int nat_int

Definition at line 114 of file port_init.c.

Referenced by dig__fread_port_I(), dig__fwrite_port_I(), main(), and port_init().

int nat_lng

Definition at line 113 of file port_init.c.

Referenced by dig__fread_port_L(), dig__fwrite_port_L(), main(), and port_init().

int nat_off_t
int nat_shrt

Definition at line 115 of file port_init.c.

Referenced by dig__fread_port_S(), dig__fwrite_port_S(), main(), and port_init().

unsigned char off_t_cnvrt[sizeof(off_t)]

Definition at line 126 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

int off_t_order
unsigned char shrt_cnvrt[sizeof(short)]

Definition at line 129 of file port_init.c.

Referenced by dig_init_portable(), main(), and port_init().

int shrt_order