#include #include #include #include #include #include "krb_common.h" /* ** Extern routine prototypes */ extern sys$parse (); /* ** ** parse_prog_name - Parse a program name from a file specification ** ** Functional Description: ** ** This routine parses a program name from a file specification. If the ** parse is unsuccessful, then the input file spec. is returned. ** ** Usage: ** ** parse_prog_name file_spec, prog_name ** ** Formal parameters: ** ** file_spec - (IN) address of the file specification string ** prog_name - (OUT) address of the pointer to which the newly ** allocated program name will returned. ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** None ** ** Side Effects: ** ** None ** */ void parse_prog_name ( char *file_spec, char **prog_name ) { #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __save #pragma __required_pointer_size 32 char *temp_spec; #pragma __required_pointer_size __restore #endif char esa[NAM$C_MAXRSS], rsa[NAM$C_MAXRSS]; struct FAB fab; struct NAM nam; int status; /* ** Initialize FAB & NAM structures */ fab = cc$rms_fab; nam = cc$rms_nam; #if __INITIAL_POINTER_SIZE == 64 temp_spec = _malloc32 (strlen (file_spec) + 1); strcpy (temp_spec, file_spec); fab.fab$l_fna = temp_spec; fab.fab$b_fns = strlen (temp_spec); #else fab.fab$l_fna = file_spec; fab.fab$b_fns = strlen (file_spec); #endif fab.fab$l_nam = &nam; nam.nam$l_esa = esa; nam.nam$b_ess = sizeof (esa); nam.nam$l_rsa = rsa; nam.nam$b_rss = sizeof (rsa); nam.nam$v_synchk = 1; /* ** Parse the file spec., If the parse fails then we simply ** return the entered file spec., otherwise we extract and ** return the file name. */ status = sys$parse (&fab); if (! (status & 1)) { *prog_name = malloc (strlen (file_spec) + 1); strcpy (*prog_name, file_spec); } else { *prog_name = malloc (nam.nam$b_name + 1); strncpy (*prog_name, nam.nam$l_name, nam.nam$b_name); *(*prog_name + nam.nam$b_name) = '\0'; } /* ** Free the temporary specification */ #if __INITIAL_POINTER_SIZE == 64 free (temp_spec); #endif } /* ** ** net_read - read a data buffer over a given socket ** ** Functional Description: ** ** This routine reads a data buffer over a given socket. If the ** code is compiled on Alpha, then the data is read into a 32 bit ** address to accommodate the socket read. ** ** Usage: ** ** net_read sock, data_buf, data_len ** ** Formal parameters: ** ** sock - (IN) the socket number to be read from. ** data_buf - (OUT) address of the data buffer into which the ** data is to be read. ** data_len - (IN) number of bytes to be read into data buffer. ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** n - The number of characters read into the buffer ** ** Side Effects: ** ** None ** */ int net_read ( int sock, char *data_buf, unsigned int data_len ) { #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __save #pragma __required_pointer_size 32 #endif char *temp_ptr; char *temp_buf; #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __restore #endif int sent_len = 0; #if __INITIAL_POINTER_SIZE == 64 temp_buf = _malloc32 (data_len); #else temp_buf = data_buf; #endif for (temp_ptr = temp_buf; data_len; temp_ptr += sent_len, data_len -= sent_len) { sent_len = recv(sock, temp_ptr, data_len, 0); if (sent_len < 0) { if (errno == EINTR) continue; #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return (sent_len); } else if (sent_len == 0) { #if __INITIAL_POINTER_SIZE == 64 memcpy (data_buf, temp_buf, (int) (temp_ptr - temp_buf)); free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } } #if __INITIAL_POINTER_SIZE == 64 memcpy (data_buf, temp_buf, (int) (temp_ptr - temp_buf)); free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } /* ** ** net_write - write a data buffer over a given socket ** ** Functional Description: ** ** This routine write a data buffer over a given socket. If the ** code is compiled on Alpha, then the data to be written is ** copied to a 32 bit address to accommodate the socket write. ** ** Usage: ** ** net_write sock, data_buf, data_len ** ** Formal parameters: ** ** sock - (IN) the socket number to be written to. ** data_buf - (IN) address of the data buffer from which the ** data is to be written. ** data_len - (IN) number of bytes to be written from data buffer. ** ** Implicit Parameters: ** ** None ** ** Routine Value: ** ** n - The number of characters written from the buffer ** ** Side Effects: ** ** None ** */ int net_write ( int sock, char *data_buf, unsigned int data_len ) { #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __save #pragma __required_pointer_size 32 #endif char *temp_buf; char *temp_ptr; #if __INITIAL_POINTER_SIZE == 64 #pragma __required_pointer_size __restore #endif int sent_len = 0; #if __INITIAL_POINTER_SIZE == 64 temp_buf = _malloc32 (data_len); memcpy (temp_buf, data_buf, data_len); #else temp_buf = data_buf; #endif for (temp_ptr = temp_buf; data_len; temp_ptr += sent_len, data_len -= sent_len) { sent_len = send (sock, temp_ptr, data_len, 0); if (sent_len < 0) { if (errno == EINTR) continue; #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return (sent_len); } else if (sent_len == 0) { #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); } } /* ** Free the temporary buffer */ #if __INITIAL_POINTER_SIZE == 64 free (temp_buf); #endif return ((int) (temp_ptr - temp_buf)); }