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

  1. /**
  2. *
  3. * Name        flnew -- Create a file (but not if it already exists)
  4. *
  5. * Synopsis    ercode = flnew(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 does not exist, it is created and
  13. *        opened for reading and writing.  The file can be
  14. *        accessed by using the returned handle number.  An error
  15. *        occurs if the file already exists.
  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_ARCHIVE (32) - Archive flag (file changed since
  25. *                          last backed up)
  26. *
  27. *        File attributes may be combined by adding the attribute
  28. *        codes.    Volume labels or subdirectories cannot be
  29. *        created using FLNEW.
  30. *
  31. *        An error occurs if the program is not running under DOS
  32. *        version 3.0 or greater.  (Use FLCREATE in that case.)
  33. *
  34. *        The file is opened in "compatibility mode".  See FLOPEN
  35. *        for more information about this.
  36. *
  37. * Returns    ercode          DOS function error code
  38. *        *phandle      File handle of the created file. If an
  39. *                  error is encountered, -1 is returned.
  40. *
  41. * Version    3.0  (C)Copyright Blaise Computing Inc.  1983, 1984, 1986
  42. *
  43. **/
  44.  
  45. #include <bfile.h>
  46. #include <bquery.h>
  47.  
  48. int flnew(pfile,phandle,attrib)
  49. char *pfile;
  50. int  *phandle,attrib;
  51. {
  52.     DOSREG dos_reg;
  53.     int    minor,ercode;
  54.     ADS    file_ads;
  55.  
  56.     if (qydosver(&minor) < 3)
  57.     {
  58.     ercode = 1;
  59.     }
  60.     else
  61.     {
  62.     dos_reg.ax = 0x5b00;
  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.     }
  70.  
  71.     if (ercode == 0)
  72.        *phandle = (int)dos_reg.ax;
  73.     else
  74.        *phandle = -1;
  75.  
  76.     return(ercode);
  77. }
  78.