home *** CD-ROM | disk | FTP | other *** search
- /**
- *
- * Name fltemp -- Create a file with a unique name.
- *
- * Synopsis ercode = fltemp(ppath,phandle,attrib);
- *
- * int ercode Returned DOS error code
- * char *ppath Path to be prepended
- * to the resulting filename.
- * int *phandle Returned DOS file handle
- * int attrib file attribute
- *
- * Description This function invents a unique filename in the directory
- * specified by *ppath and creates and opens the file. The
- * file is opened for reading and writing. The file can be
- * accessed by using the returned handle number.
- *
- * The filename is appended to the string pointed to by
- * ppath. If the string does not end in a backslash ('\\')
- * then a backslash is added before the filename. The
- * character buffer containing the string should be at
- * least 67 bytes long.
- *
- * The file is NOT automatically deleted when the file is
- * closed or the program is terminated. Use FLDELETE to
- * delete it.
- *
- * The file is given the attributes specified by attrib.
- * The possible values are:
- *
- * AT_GENERAL ( 0) - General, no attribute
- * AT_RDONLY ( 1) - Read only (may not be opened for writing)
- * AT_HIDDEN ( 2) - Hidden file
- * AT_SYSTEM ( 4) - System file
- * AT_VOLUME ( 8) - Volume label
- * AT_DIR (16) - Subdirectory
- * AT_ARCHIVE (32) - Archive flag (file changed since
- * last backed up)
- *
- * File attributes may be combined by adding the attribute
- * codes. Volume labels and subdirectories cannot be
- * created using FLTEMP.
- *
- * The file is opened in "compatibility mode". See FLOPEN
- * for more information about this.
- *
- * An error occurs if the program is not running under DOS
- * version 3.0 or greater. (Use FLCREATE in that case.)
- *
- * Returns ercode DOS function error code
- * *phandle File handle of the created file. If an
- * error is encountered, -1 is returned.
- * *ppath Path name of the new file.
- *
- * Version 3.0 (C)Copyright Blaise Computing Inc. 1983, 1984, 1986
- *
- **/
-
- #include <string.h>
-
- #include <bfile.h>
- #include <bquery.h>
-
- int fltemp(ppath,phandle,attrib)
- register char *ppath;
- int *phandle,attrib;
- {
- DOSREG dos_reg;
- int ercode,minor;
- register int length;
- ADS path_ads;
-
- if (qydosver(&minor) < 3)
- {
- ercode = 1;
- }
- else
- {
- length = (int) strlen(ppath);
- if (ppath[length - 1] != '\\')
- { /* Add trailing backslash if */
- ppath[length++] = '\\'; /* absent. */
- ppath[length] = '\0';
- }
-
- dos_reg.ax = 0x5a00; /* Function call 0x5a */
- dos_reg.cx = utbyword(0,attrib);
- utabsptr(ppath,&path_ads);
- dos_reg.ds = path_ads.s;
- dos_reg.dx = path_ads.r;
-
- ercode = dos(&dos_reg);
- }
- if (ercode == 0)
- *phandle = (int)dos_reg.ax;
- else
- *phandle = -1;
-
- return(ercode);
- }