home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / OS2OMMM.SRC / OMMMCOPY.C < prev    next >
Text File  |  1989-02-12  |  5KB  |  144 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. #ifdef    MSC
  47. #    include    <memory.h>
  48. #endif
  49. #ifdef    TURBO_C
  50. #    include    <mem.h>
  51. #endif
  52. #ifdef    ZTC
  53. #    include    <string.h>
  54. #endif
  55.  
  56. /*--------------------------------------------------------------------------*/
  57. /* Static function declarations                                             */
  58. /*--------------------------------------------------------------------------*/
  59.  
  60.     /*    ... NONE ...    */
  61.  
  62. /*--------------------------------------------------------------------------*/
  63. /* Static variable definitions                                              */
  64. /*--------------------------------------------------------------------------*/
  65.  
  66.     /*    ... NONE ...    */
  67.  
  68. /*--------------------------------------------------------------------------*/
  69. /* External variable declarations                                           */
  70. /*--------------------------------------------------------------------------*/
  71.  
  72. extern int    errno;
  73.  
  74. /****************************************************************************/
  75.  
  76. /*--------------------------------------------------------------------------*/
  77. /* OPEN READ AND CLOSE                                                      */
  78. /*--------------------------------------------------------------------------*/
  79.  
  80.  int
  81. open_read_and_close(char * filename, char * buffer, int bufsize)
  82. {
  83.     FILE *    fp;
  84.  
  85.     if ((fp = fopen(filename,"rb")) == NULL)
  86.         return(-1);
  87.     memset(buffer,0,bufsize);
  88.     fread(buffer,1,(unsigned) bufsize,fp);
  89.     fclose(fp);
  90.     fp = NULL;
  91.     return(0);
  92. }
  93.  
  94. /*--------------------------------------------------------------------------*/
  95. /* COPY MSG                                                                 */
  96. /*--------------------------------------------------------------------------*/
  97.  
  98.  int
  99. copy_msg(FILE * sf, FILE * df, char * buffer, int bufsize)
  100. {
  101.     int        length;
  102.  
  103.     length = fread(buffer,1,(unsigned) bufsize,sf);
  104.  
  105.     while (length == bufsize) {
  106.         if (fwrite(buffer,1,(unsigned) length,df) != length)
  107.             return(-1);
  108.         length = fread(buffer,1,(unsigned) bufsize,sf);
  109.     }
  110.  
  111.     if (fwrite(buffer,1,(unsigned) length,df) != length)
  112.         return(-1);
  113.  
  114.     if (*(buffer + length - 1) != 0)
  115.         fputc('\0',df);
  116.  
  117.     return(0);
  118. }
  119.  
  120. /*--------------------------------------------------------------------------*/
  121. /* COPY OUT                                                                 */
  122. /*--------------------------------------------------------------------------*/
  123.  
  124.  int
  125. copy_out(FILE * sf, FILE * df, char * buffer, int bufsize)
  126. {
  127.     int        length;
  128.  
  129.     length = fread(buffer,1,(unsigned) bufsize,sf);
  130.  
  131.     while (length) {
  132.         if (fwrite(buffer,1,(unsigned) length,df) != length)
  133.             return(-1);
  134.         length = fread(buffer,1,(unsigned) bufsize,sf);
  135.     }
  136.     return(0);
  137. }
  138.  
  139. /*--------------------------------------------------------------------------*/
  140. /*                                END OF FILE                               */
  141. /*--------------------------------------------------------------------------*/
  142.  
  143.  
  144.