GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-602118adcc
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 (void)
 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

◆ dig__byte_order_out()

int dig__byte_order_out ( void  )

Get byte order.

Returns
ENDIAN_LITTLE
ENDIAN_BIG

Definition at line 1008 of file portable.c.

References dbl_order, ENDIAN_BIG, and ENDIAN_LITTLE.

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

◆ dig__fread_port_C()

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 511 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(), and Vect_open_fidx().

◆ dig__fread_port_D()

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 Cur_Head, Port_info::dbl_quick, dig_fread(), and PORT_DOUBLE.

Referenced by dig_Rd_P_node(), and dig_Rd_Plus_head().

◆ dig__fread_port_F()

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 Cur_Head, dig_fread(), Port_info::flt_quick, and PORT_FLOAT.

Referenced by dig_Rd_P_node().

◆ dig__fread_port_I()

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 345 of file portable.c.

References Cur_Head, dig_fread(), 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(), and Vect_open_fidx().

◆ dig__fread_port_L()

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 262 of file portable.c.

References Cur_Head, dig_fread(), 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().

◆ dig__fread_port_O()

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 Cur_Head, dig_fread(), nat_off_t, and Port_info::off_t_quick.

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

◆ dig__fread_port_P()

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 537 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().

◆ dig__fread_port_S()

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 428 of file portable.c.

References Cur_Head, dig_fread(), nat_shrt, PORT_SHORT, and Port_info::shrt_quick.

◆ dig__fwrite_port_C()

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 886 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(), and Vect_save_fidx().

◆ dig__fwrite_port_D()

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 559 of file portable.c.

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

Referenced by dig_Wr_P_node(), and dig_Wr_Plus_head().

◆ dig__fwrite_port_F()

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 597 of file portable.c.

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

Referenced by dig_Wr_P_node().

◆ dig__fwrite_port_I()

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 Cur_Head, dig_fwrite(), 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().

◆ dig__fwrite_port_L()

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 703 of file portable.c.

References Cur_Head, dig_fwrite(), 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().

◆ dig__fwrite_port_O()

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 Cur_Head, dig_fwrite(), nat_off_t, 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().

◆ dig__fwrite_port_P()

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 868 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().

◆ dig__fwrite_port_S()

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 813 of file portable.c.

References Cur_Head, dig_fwrite(), nat_shrt, PORT_SHORT, and Port_info::shrt_quick.

◆ dig_init_portable()

◆ dig_set_cur_port()

◆ port_init()

void port_init ( void  )

Variable Documentation

◆ Cur_Head

◆ dbl_cnvrt

unsigned char dbl_cnvrt[sizeof(double)]
extern

Definition at line 125 of file port_init.c.

Referenced by dig_init_portable().

◆ dbl_order

int dbl_order
extern

Definition at line 118 of file port_init.c.

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

◆ flt_cnvrt

unsigned char flt_cnvrt[sizeof(float)]
extern

Definition at line 126 of file port_init.c.

Referenced by dig_init_portable().

◆ flt_order

int flt_order
extern

Definition at line 119 of file port_init.c.

Referenced by dig_init_portable().

◆ int_cnvrt

unsigned char int_cnvrt[sizeof(int)]
extern

Definition at line 129 of file port_init.c.

Referenced by dig_init_portable().

◆ int_order

int int_order
extern

Definition at line 122 of file port_init.c.

Referenced by dig_init_portable().

◆ lng_cnvrt

unsigned char lng_cnvrt[sizeof(long)]
extern

Definition at line 128 of file port_init.c.

Referenced by dig_init_portable().

◆ lng_order

int lng_order
extern

Definition at line 121 of file port_init.c.

Referenced by dig_init_portable().

◆ nat_dbl

int nat_dbl
extern

Definition at line 111 of file port_init.c.

Referenced by port_init().

◆ nat_flt

int nat_flt
extern

Definition at line 112 of file port_init.c.

Referenced by port_init().

◆ nat_int

int nat_int
extern

Definition at line 115 of file port_init.c.

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

◆ nat_lng

int nat_lng
extern

Definition at line 114 of file port_init.c.

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

◆ nat_off_t

int nat_off_t
extern

Definition at line 113 of file port_init.c.

Referenced by dig__fread_port_O(), dig__fwrite_port_O(), dig_init_portable(), and port_init().

◆ nat_shrt

int nat_shrt
extern

Definition at line 116 of file port_init.c.

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

◆ off_t_cnvrt

unsigned char off_t_cnvrt[sizeof(off_t)]
extern

Definition at line 127 of file port_init.c.

Referenced by dig_init_portable().

◆ off_t_order

int off_t_order
extern

Definition at line 120 of file port_init.c.

Referenced by dig_init_portable().

◆ shrt_cnvrt

unsigned char shrt_cnvrt[sizeof(short)]
extern

Definition at line 130 of file port_init.c.

Referenced by dig_init_portable().

◆ shrt_order

int shrt_order
extern

Definition at line 123 of file port_init.c.

Referenced by dig_init_portable().