RAD Studio |  |

_rtl_close

Header File

io.h

Category

Input/output Routines

Prototype

int _rtl_close(int handle);

Description

Closes a file.

Note: This function replaces _close which is obsolete
The _rtl_close function closes the file associated with handle, a file handle obtained from a call to creat, creatnew, creattemp, dup, dup2, open, _rtl_creat, or _rtl_open.

It does not write a Ctrl-Z character at the end of the file. If you want to terminate the file with a Ctrl-Z, you must explicitly output one.

Return Value

On success, _rtl_close returns 0.

On error (if it fails because handle is not the handle of a valid, open file), _rtl_close returns a value of -1 and the global variable errno is set to

EBADF | Bad file number

Example

Copy Code

    #include <string.h>
    #include <stdio.h>
    #include <fcntl.h>
    #include <io.h>
    int main(void)
    {
       int handle;
       char msg[] = "Hello world";
       if ((handle = _rtl_open("TEST.$$$", O_RDWR)) == -1)
       {
          perror("Error:");
          return 1;
       }
       _rtl_write(handle, msg, strlen(msg));
       _rtl_close(handle);
       return 0;
    }

Portability

POSIX | Win32 | ANSI C | ANSI C++
| + |  |

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!