home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / comms / comprgs / osrc_149.lzh / ommmcopy.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-12-20  |  4.8 KB  |  136 lines

  1. /***************************************************************************/
  2. /***                                                                     ***/
  3. /***               oMMM - The Outbound Matrix Message Masher             ***/
  4. /***                      Copyright 1989 BS Software                     ***/
  5. /***                                                                     ***/
  6. /***                         FILENAME: OMMMCOPY.C                        ***/
  7. /***                                                                     ***/
  8. /***                   Packet/Message read/write functions               ***/
  9. /***                                                                     ***/
  10. /***                 Based on the original oMMM, a portion of            ***/
  11. /***               the Opus Computer-Based Conversation System           ***/
  12. /***                     Copyright 1986, Wynn Wagner III                 ***/
  13. /***                                                                     ***/
  14. /***************************************************************************/
  15. /***                                                                     ***/
  16. /***                    Tabs set at every 4th column                     ***/
  17. /***                                                                     ***/
  18. /***************************************************************************/
  19.  
  20. /*
  21.     Polytron Version Control System Comments:
  22.  
  23.     The revision of this file is *** $Revision:   1.40  $ ***
  24.  
  25.     History of changes from 1.30 release version
  26.  
  27.     $Log:   C:/OMMM/PROJFILE/OMMMCOPY.C_V  $
  28.  * 
  29.  *    Rev 1.40   12 Feb 1989  4:55:50   Marshall Presnell
  30.  * Public Release Version 1.40
  31.  * 
  32.  *    Rev 1.31   31 Jan 1989  0:58:00   Marshall Presnell
  33.  * oMMM 1.35 Beta Release Version
  34.  * 
  35.  *    Rev 1.30   23 Jan 1989 17:54:06   Marshall Presnell
  36.  * Public Source Code Release - Version 1.30
  37.  
  38. */
  39.  
  40. /*--------------------------------------------------------------------------*/
  41. /* Include files                                                            */
  42. /*--------------------------------------------------------------------------*/
  43.  
  44. #include    "ommm.h"
  45. /* #include    <io.h> */
  46. #    include    <string.h>
  47.  
  48. /*--------------------------------------------------------------------------*/
  49. /* Static function declarations                                             */
  50. /*--------------------------------------------------------------------------*/
  51.  
  52.     /*    ... NONE ...    */
  53.  
  54. /*--------------------------------------------------------------------------*/
  55. /* Static variable definitions                                              */
  56. /*--------------------------------------------------------------------------*/
  57.  
  58.     /*    ... NONE ...    */
  59.  
  60. /*--------------------------------------------------------------------------*/
  61. /* External variable declarations                                           */
  62. /*--------------------------------------------------------------------------*/
  63.  
  64. extern int    errno;
  65.  
  66. /****************************************************************************/
  67.  
  68. /*--------------------------------------------------------------------------*/
  69. /* OPEN READ AND CLOSE                                                      */
  70. /*--------------------------------------------------------------------------*/
  71.  
  72.  int
  73. open_read_and_close(char * filename, char * buffer, int bufsize)
  74. {
  75.     FILE *    fp;
  76.  
  77.     if ((fp = fopen(filename,"rb")) == NULL)
  78.         return(-1);
  79.     memset(buffer,0,bufsize);
  80.     fread(buffer,1,(unsigned) bufsize,fp);
  81.     fclose(fp);
  82.     fp = NULL;
  83.     return(0);
  84. }
  85.  
  86. /*--------------------------------------------------------------------------*/
  87. /* COPY MSG                                                                 */
  88. /*--------------------------------------------------------------------------*/
  89.  
  90.  int
  91. copy_msg(FILE * sf, FILE * df, char * buffer, int bufsize)
  92. {
  93.     int        length;
  94.  
  95.     length = fread(buffer,1,(unsigned) bufsize,sf);
  96.  
  97.     while (length == bufsize) {
  98.         if (fwrite(buffer,1,(unsigned) length,df) != length)
  99.             return(-1);
  100.         length = fread(buffer,1,(unsigned) bufsize,sf);
  101.     }
  102.  
  103.     if (fwrite(buffer,1,(unsigned) length,df) != length)
  104.         return(-1);
  105.  
  106.     if (*(buffer + length - 1) != 0)
  107.         fputc('\0',df);
  108.  
  109.     return(0);
  110. }
  111.  
  112. /*--------------------------------------------------------------------------*/
  113. /* COPY OUT                                                                 */
  114. /*--------------------------------------------------------------------------*/
  115.  
  116.  int
  117. copy_out(FILE * sf, FILE * df, char * buffer, int bufsize)
  118. {
  119.     int        length;
  120.  
  121.     length = fread(buffer,1,(unsigned) bufsize,sf);
  122.  
  123.     while (length) {
  124.         if (fwrite(buffer,1,(unsigned) length,df) != length)
  125.             return(-1);
  126.         length = fread(buffer,1,(unsigned) bufsize,sf);
  127.     }
  128.     return(0);
  129. }
  130.  
  131. /*--------------------------------------------------------------------------*/
  132. /*                                END OF FILE                               */
  133. /*--------------------------------------------------------------------------*/
  134.  
  135.  
  136.