Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <sys\types.h>
    #include <sys\stat.h>
    #include <io.h>
    int creat( const char *path, int mode );
    int _wcreat( const wchar_t *path, int mode );

Description:
    The creat function creates (and opens) a file at the operating system
    level.  It is equivalent to:


           open( path, O_WRONLY | O_CREAT | O_TRUNC, mode );

    The _wcreat function is identical to creat except that it accepts a wide
    character string argument.

    The name of the file to be created is given by path.  When the file
    exists (it must be writeable), it is truncated to contain no data and
    the preceding mode setting is unchanged.

    When the file does not exist, it is created with access permissions
    given by the mode argument.  The access permissions for the file or
    directory are specified as a combination of bits (defined in the
    <sys\stat.h> header file).

    The following bits define permissions for the owner.

    Permission     Meaning

S_IRWXU
    Read, write, execute/search

S_IRUSR
    Read permission

S_IWUSR
    Write permission

S_IXUSR
    Execute/search permission

    The following bits define permissions for the group.

    Permission     Meaning

S_IRWXG
    Read, write, execute/search

S_IRGRP
    Read permission

S_IWGRP
    Write permission

S_IXGRP
    Execute/search permission

    The following bits define permissions for others.

    Permission     Meaning

S_IRWXO
    Read, write, execute/search

S_IROTH
    Read permission

S_IWOTH
    Write permission

S_IXOTH
    Execute/search permission

    The following bits define miscellaneous permissions used by other
    implementations.

    Permission     Meaning

S_IREAD
    is equivalent to S_IRUSR (read permission)

S_IWRITE
    is equivalent to S_IWUSR (write permission)

S_IEXEC
    is equivalent to S_IXUSR (execute/search permission)

    All files are readable with DOS; however, it is a good idea to set
    S_IREAD when read permission is intended for the file.

Returns:
    If successful, creat returns a handle for the file.  When an error
    occurs while opening the file, -1 is returned, and  errno is set to
    indicate the error.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    Constant     Meaning

EACCES
    Access denied because path specifies a directory or a volume ID, or a
    read-only file.

EMFILE
    No more handles available (too many open files).

ENOENT
    The specified path does not exist or path is an empty string.


Example:
    #include <sys\types.h>
    #include <sys\stat.h>
    #include <io.h>

    void main()
      {
        int handle;

        handle = creat( "file", S_IWRITE | S_IREAD );
        if( handle != -1 ) {

          /* process file */

          close( handle );
        }
      }

Classification:
    creat is POSIX 1003.1, _wcreat is not POSIX

Systems:
     creat - All, Netware

    _wcreat - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

See Also:
    chsize, close, dup, dup2, eof, exec Functions, filelength, fileno,
    fstat, isatty, lseek, open, read, setmode, sopen, stat, tell, write,
    umask

See Also: chsize dup2

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson