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/C++ v10.0 : C library - <b>synopsis:</b> 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 );

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 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.

    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.

    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.

    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.

    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.

    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.


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

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:
    POSIX 1003.1

Systems:
    All

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