home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / BTMTSRC3.ZIP / TCFUNCS.C < prev    next >
C/C++ Source or Header  |  1990-05-14  |  5KB  |  120 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 "tc_utime.h"
  62.  
  63. /* always uses modification time */
  64. int cdecl utime(char *name, struct utimbuf *times)
  65. {
  66.     int handle;
  67.     struct date d;
  68.     struct time t;
  69.     struct ftime ft;
  70.  
  71.     unixtodos(times->modtime, &d, &t);
  72.     ft.ft_tsec = t.ti_sec / 2;
  73.     ft.ft_min = t.ti_min;
  74.     ft.ft_hour = t.ti_hour;
  75.     ft.ft_day = d.da_day;
  76.     ft.ft_month = d.da_mon;
  77.    ft.ft_year = d.da_year - 1980;
  78.     if((handle = open(name, O_RDONLY)) == -1)
  79.         return -1;
  80.  
  81.     setftime(handle, &ft);
  82.     close(handle);
  83.     return 0;
  84. }
  85.  
  86. int _dos_read(int fd, void far *buf, int nbytes, int *bytes_read)
  87. {
  88.     union REGS regs;
  89.     struct SREGS sregs;
  90.  
  91.     regs.h.ah = 0x3f;    /* read file */
  92.     regs.x.bx = fd;
  93.     regs.x.cx = nbytes;
  94.     regs.x.dx = FP_OFF(buf);
  95.     sregs.ds = FP_SEG(buf);
  96.     *bytes_read = intdosx(®s, ®s, &sregs);
  97.     return regs.x.cflag ? -1 : 0;
  98. }
  99.  
  100. int _Cdecl cprintf(const char *format, ...)
  101. {
  102.     va_list arg_ptr;
  103.  
  104.     va_start(arg_ptr, format);
  105.     return vprintf(format, arg_ptr);
  106. }
  107.  
  108. /* dunno why Turbo's <conio.h> declares this as
  109.    int when the manual says it returns nothing */
  110. int _Cdecl cputs (const char *str)
  111. {
  112.     printf("%s", str);
  113.     return 0;
  114. }
  115.  
  116. int _Cdecl putch(int ch)
  117. {
  118.     return putchar(ch);
  119. }
  120.