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

  1. /**
  2. *
  3. * Name        flcreate -- Create a file (even if it already exists)
  4. *
  5. * Synopsis    ercode = flcreate(pfile,phandle,attrib);
  6. *
  7. *        int  ercode      Returned DOS error code
  8. *        char *pfile      File path name to be opened
  9. *        int  *phandle      Returned DOS file handle
  10. *        int  attrib      file attribute
  11. *
  12. * Description    If the specified file exists, it is truncated to length
  13. *        zero; if it does not exist, it is created.  The file is
  14. *        opened for reading and writing.  The file can be
  15. *        accessed by using the returned handle number.
  16. *
  17. *        The file is given the attributes specified by attrib.
  18. *        The possible values are:
  19. *
  20. *          AT_GENERAL ( 0) - General, no attribute
  21. *          AT_RDONLY  ( 1) - Read only (may not be opened for writing)
  22. *          AT_HIDDEN  ( 2) - Hidden file
  23. *          AT_SYSTEM  ( 4) - System file
  24. *          AT_VOLUME  ( 8) - Volume label
  25. *          AT_DIR     (16) - Subdirectory
  26. *          AT_ARCHIVE (32) - Archive flag (file changed since
  27. *                          last backed up)
  28. *
  29. *        File attributes may be combined by adding the attribute
  30. *        codes.    Volume labels and subdirectories cannot be
  31. *        created using FLCREATE.
  32. *
  33. *        Under DOS 3.0 or greater, the file is opened in
  34. *        "compatibility mode".  See FLOPEN for more information
  35. *        about this.
  36. *
  37. *        Note that an existing read-only file cannot be created
  38. *        (since it cannot be truncated).
  39. *
  40. *        Under DOS 3.0 or greater, use FLNEW to create a file
  41. *        without truncating any pre-existing copy of the file, or
  42. *        FLTEMP to create a file with a unique name.
  43. *
  44. * Returns    ercode          DOS function error code
  45. *        *phandle      File handle of the created file. If an
  46. *                  error is encountered, -1 is returned.
  47. *
  48. * Version    3.0  (C)Copyright Blaise Computing Inc.  1983, 1984, 1986
  49. *
  50. **/
  51.  
  52. #include <bfile.h>
  53.  
  54. int flcreate(pfile,phandle,attrib)
  55. char *pfile;
  56. int  *phandle,attrib;
  57. {
  58.     DOSREG dos_reg;
  59.     int    ercode;
  60.     ADS    file_ads;
  61.  
  62.     dos_reg.ax = 0x3c00;          /* Function call 0x3C          */
  63.     dos_reg.cx = utbyword(0,attrib);
  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 = (int)dos_reg.ax;
  71.     else
  72.        *phandle = -1;
  73.  
  74.     return(ercode);
  75. }
  76.