creattemp

From RAD Studio
Jump to: navigation, search

Go Up to io.h Index


Header File

io.h

Category

Input/output Routines

Prototype

int creattemp(char *path, int attrib);

Description

Creates a unique file in the directory associated with the path name.

A file created with creattemp is always created in the translation mode specified by the global variable _fmode (O_TEXT or O_BINARY).

path is a path name ending with a backslash (\). A unique file name is selected in the directory given by path. The newly created file name is stored in the path string supplied. path should be long enough to hold the resulting file name. The file is not automatically deleted when the program terminates.

The attrib argument to creattemp can be zero or an OR-combination of any one of the following constants (defined in dos.h):

FA_HIDDEN

Hidden file

FA_RDONLY

Read-only attribute

FA_SYSTEM

System file



Upon successful file creation, the file pointer is set to the beginning of the file. The file is opened for both reading and writing.

Return Value

Upon successful completion, the new file handle, a nonnegative integer, is returned; otherwise, -1 is returned.

In the event of error, the global variable errno is set to one of the following values:

EACCES

Permission denied

EMFILE

Too many open files

ENOENT

Path or file name not found



Example

#include <string.h>
#include <stdio.h>
#include <io.h>
int main(void)
{
   int handle;
   char pathname[128];
   strcpy(pathname, "\\");
   /* create a unique file in the root directory */
   handle = creattemp(pathname, 0);
   printf("%s was the unique file created.\n", pathname);
   close(handle);
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+