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

  1. /**
  2. *
  3. * Name        fltemp -- Create a file with a unique name.
  4. *
  5. * Synopsis    ercode = fltemp(ppath,phandle,attrib);
  6. *
  7. *        int  ercode      Returned DOS error code
  8. *        char *ppath      Path to be prepended
  9. *                  to the resulting filename.
  10. *        int  *phandle      Returned DOS file handle
  11. *        int  attrib      file attribute
  12. *
  13. * Description    This function invents a unique filename in the directory
  14. *        specified by *ppath and creates and opens the file.  The
  15. *        file is opened for reading and writing.  The file can be
  16. *        accessed by using the returned handle number.
  17. *
  18. *        The filename is appended to the string pointed to by
  19. *        ppath.    If the string does not end in a backslash ('\\')
  20. *        then a backslash is added before the filename.    The
  21. *        character buffer containing the string should be at
  22. *        least 67 bytes long.
  23. *
  24. *        The file is NOT automatically deleted when the file is
  25. *        closed or the program is terminated.  Use FLDELETE to
  26. *        delete it.
  27. *
  28. *        The file is given the attributes specified by attrib.
  29. *        The possible values are:
  30. *
  31. *          AT_GENERAL ( 0) - General, no attribute
  32. *          AT_RDONLY  ( 1) - Read only (may not be opened for writing)
  33. *          AT_HIDDEN  ( 2) - Hidden file
  34. *          AT_SYSTEM  ( 4) - System file
  35. *          AT_VOLUME  ( 8) - Volume label
  36. *          AT_DIR     (16) - Subdirectory
  37. *          AT_ARCHIVE (32) - Archive flag (file changed since
  38. *                          last backed up)
  39. *
  40. *        File attributes may be combined by adding the attribute
  41. *        codes.    Volume labels and subdirectories cannot be
  42. *        created using FLTEMP.
  43. *
  44. *        The file is opened in "compatibility mode".  See FLOPEN
  45. *        for more information about this.
  46. *
  47. *        An error occurs if the program is not running under DOS
  48. *        version 3.0 or greater.  (Use FLCREATE in that case.)
  49. *
  50. * Returns    ercode          DOS function error code
  51. *        *phandle      File handle of the created file. If an
  52. *                  error is encountered, -1 is returned.
  53. *        *ppath          Path name of the new file.
  54. *
  55. * Version    3.0  (C)Copyright Blaise Computing Inc.  1983, 1984, 1986
  56. *
  57. **/
  58.  
  59. #include <string.h>
  60.  
  61. #include <bfile.h>
  62. #include <bquery.h>
  63.  
  64. int fltemp(ppath,phandle,attrib)
  65. register char *ppath;
  66. int          *phandle,attrib;
  67. {
  68.     DOSREG     dos_reg;
  69.     int      ercode,minor;
  70.     register int length;
  71.     ADS      path_ads;
  72.  
  73.     if (qydosver(&minor) < 3)
  74.     {
  75.     ercode = 1;
  76.     }
  77.     else
  78.     {
  79.     length = (int) strlen(ppath);
  80.     if (ppath[length - 1] != '\\')
  81.     {                  /* Add trailing backslash if    */
  82.         ppath[length++] = '\\';   /* absent.                      */
  83.         ppath[length]   = '\0';
  84.     }
  85.  
  86.     dos_reg.ax = 0x5a00;          /* Function call 0x5a       */
  87.     dos_reg.cx = utbyword(0,attrib);
  88.     utabsptr(ppath,&path_ads);
  89.     dos_reg.ds = path_ads.s;
  90.     dos_reg.dx = path_ads.r;
  91.  
  92.     ercode       = dos(&dos_reg);
  93.     }
  94.     if (ercode == 0)
  95.     *phandle = (int)dos_reg.ax;
  96.     else
  97.     *phandle = -1;
  98.  
  99.     return(ercode);
  100. }
  101.