home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / MISC / LO241SRV.ZIP / TCFUNCS.C < prev    next >
C/C++ Source or Header  |  1992-02-08  |  5KB  |  123 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*                     Turbo C routines for BinkleyTerm                     */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*    For complete  details  of the licensing restrictions, please refer    */
  17. /*    to the License  agreement,  which  is published in its entirety in    */
  18. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.240.    */
  19. /*                                                                          */
  20. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  21. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  22. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  23. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  24. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  25. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  26. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  27. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  28. /*                                                                          */
  29. /*                                                                          */
  30. /* You can contact Bit Bucket Software Co. at any one of the following      */
  31. /* addresses:                                                               */
  32. /*                                                                          */
  33. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:132/491, 1:141/491  */
  34. /* P.O. Box 460398                AlterNet 7:491/0                          */
  35. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  36. /*                                Internet f491.n132.z1.fidonet.org         */
  37. /*                                                                          */
  38. /* Please feel free to contact us at any time to share your comments about  */
  39. /* our software and/or licensing policies.                                  */
  40. /*                                                                          */
  41. /*                                                                          */
  42. /*  This module is derived from an original work by Russell J. Price, who   */
  43. /*  has graciously allowed us to use his code in this work.                 */
  44. /*                                                                          */
  45. /*--------------------------------------------------------------------------*/
  46.  
  47. /*
  48.    This module implements the utime() and _dos_read() functions for Turbo C,
  49.    along with replacements for Turbo's IBM-specific cprintf(), cputs(), and
  50.    putch() functions.
  51.  
  52. */
  53.  
  54. #include <stdio.h>
  55. #include <conio.h>
  56. #include <dos.h>
  57. #include <io.h>
  58. #include <fcntl.h>
  59. #include <time.h>
  60. #include <stdarg.h>
  61. #include <sys\stat.h>
  62.  
  63. #include "tc_utime.h"
  64. #include "defines.h"
  65.  
  66. /* always uses modification time */
  67. int cdecl utime(char *name, struct utimbuf *times)
  68. {
  69.    int handle;
  70.    struct date d;
  71.    struct time t;
  72.    struct ftime ft;
  73.  
  74.    unixtodos(times->modtime, &d, &t);
  75.    ft.ft_tsec = t.ti_sec / 2;
  76.    ft.ft_min = t.ti_min;
  77.    ft.ft_hour = t.ti_hour;
  78.    ft.ft_day = d.da_day;
  79.    ft.ft_month = d.da_mon;
  80.    ft.ft_year = d.da_year - 1980;
  81.    if ((handle = shopen(name, O_RDONLY)) == -1)
  82.       return -1;
  83.  
  84.    setftime(handle, &ft);
  85.    close(handle);
  86.    return 0;
  87. }
  88.  
  89. int _dos_read(int fd, void far *buf, int nbytes, int *bytes_read)
  90. {
  91.     union REGS regs;
  92.     struct SREGS sregs;
  93.  
  94.     regs.h.ah = 0x3f;    /* read file */
  95.     regs.x.bx = fd;
  96.     regs.x.cx = nbytes;
  97.     regs.x.dx = FP_OFF(buf);
  98.     sregs.ds = FP_SEG(buf);
  99.     *bytes_read = intdosx(®s, ®s, &sregs);
  100.     return regs.x.cflag ? -1 : 0;
  101. }
  102.  
  103. int _Cdecl cprintf(const char *format, ...)
  104. {
  105.     va_list arg_ptr;
  106.  
  107.     va_start(arg_ptr, format);
  108.     return vprintf(format, arg_ptr);
  109. }
  110.  
  111. /* dunno why Turbo's <conio.h> declares this as
  112.    int when the manual says it returns nothing */
  113. int _Cdecl cputs (const char *str)
  114. {
  115.     printf("%s", str);
  116.     return 0;
  117. }
  118.  
  119. int _Cdecl putch(int ch)
  120. {
  121.     return putchar(ch);
  122. }
  123.