home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c005 / 4.ddi / C / FLOPEN.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-08-05  |  2.1 KB  |  76 lines

  1. /**
  2. *
  3. * Name        flopen -- Open a file
  4. *
  5. * Synopsis    ercode = flopen(pfile,phandle,mode);
  6. *
  7. *        int  ercode      Returned DOS error code
  8. *        char *pfile      File path name
  9. *        int  *phandle      File handle associated with the file
  10. *        int  mode      Mode value:  includes access rights,
  11. *                  sharing mode, and inheritance flag.
  12. *
  13. * Description    This function opens a file with the specified file path
  14. *        name and returns a file handle with which the file may
  15. *        be accessed.
  16. *
  17. *        The file is opened as specified in mode.  This mode
  18. *        value is a combination of the access code, the sharing
  19. *        mode, and the inheritance flag.  The values for the
  20. *        access code are as follows:
  21. *
  22. *            RDONLY  (0) - Open for reading only
  23. *            WRTONLY (1) - Open for writing only
  24. *            RDWRT   (2) - Open for reading and writing.
  25. *
  26. *        The values for the sharing mode limit the ways in which
  27. *        the file may be opened by other processes:
  28. *
  29. *            COMPATIBILITY ( 0) - DOS 2.x style
  30. *            DENY_RW      (16) - Exclusive
  31. *            DENY_WRITE      (32) - Cannot be opened for writing
  32. *            DENY_READ      (48) - Cannot be opened for reading
  33. *            DENY_NONE      (64) - No restrictions
  34. *
  35. *        The values for the inheritance flag are as follows:
  36. *
  37. *            INHERIT    (  0) - DOS 2.x style (file handle is
  38. *                       inherited by child programs)
  39. *            NO_INHERIT (128) - File handle is private to this
  40. *                       program.
  41. *
  42. *        Note that DOS 2.x requires the COMPATIBILITY and INHERIT
  43. *        attributes.
  44. *
  45. * Returns    ercode          DOS function error code
  46. *        *phandle      Associated file handle. If an error is
  47. *                  encountered, -1 is returned.
  48. *
  49. * Version    3.0  (C)Copyright Blaise Computing Inc.  1983, 1984, 1986
  50. *
  51. **/
  52.  
  53. #include <bfile.h>
  54.  
  55. int flopen(pfile,phandle,access)
  56. char *pfile;
  57. int  *phandle,access;
  58. {
  59.     DOSREG dos_reg;
  60.     int    ercode;
  61.     ADS    file_ads;
  62.  
  63.     dos_reg.ax = utbyword(0x3d,access);
  64.     utabsptr(pfile,&file_ads);
  65.     dos_reg.ds = file_ads.s;
  66.     dos_reg.dx = file_ads.r;
  67.  
  68.     ercode     = dos(&dos_reg);
  69.     if (ercode == 0)
  70.        *phandle = dos_reg.ax;
  71.     else
  72.        *phandle = -1;
  73.  
  74.     return(ercode);
  75. }
  76.