00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifdef USE_PCNFS
00012 #undef USE_PCNFS
00013 #endif
00014
00015 #include "rcs_defs.hh"
00016
00017 #include "sendline.h"
00018 #include "sendn.h"
00019 #include "rcs_prnt.hh"
00020
00021 #include <stdlib.h>
00022 #include <string.h>
00023
00024 #include "dbg_mem.h"
00025
00026
00027 #if defined(MSDOS) && !defined(_Windows)
00028 static char sendline_buffer[0x2000];
00029 static long sendline_buffer_size = 0x2000;
00030 #else
00031 static char *sendline_buffer = NULL;
00032 static long sendline_buffer_size = 0;
00033 #endif
00034
00035 int
00036 sendline (int fd, const char *cptr, int _flags, double _timeout)
00037 {
00038 int length;
00039 length = strlen (cptr);
00040 #if defined(MSDOS) && !defined(_Windows)
00041 if (length + 2 > sendline_buffer_size)
00042 {
00043 rcs_print_error ("Since DOS doesn't seem to handle realloc properly\n");
00044 rcs_print_error
00045 ("sending strings over %d with sendline are prohibited.",
00046 sendline_buffer_size);
00047 return (-1);
00048 }
00049 #else
00050 sendline_buffer_size = length + 18 - (length % 16);
00051 sendline_buffer = realloc (sendline_buffer, sendline_buffer_size);
00052 if (NULL == sendline_buffer)
00053 {
00054 rcs_print_error
00055 ("sendline could not allocate %d bytes for temperary buffer.\n",
00056 sendline_buffer_size);
00057 rcs_print_error ("String to send was: %s", cptr);
00058 return (-1);
00059 }
00060 #endif
00061 strcpy (sendline_buffer, cptr);
00062 strcat (sendline_buffer, "\n");
00063 rcs_print_debug (PRINT_SOCKET_WRITE_SIZE, "sendline %s to %d.\n", cptr, fd);
00064 return sendn (fd, sendline_buffer, length + 1, _flags, _timeout);
00065 }