Rediger

Del via


File handling

Use these routines to create, delete, and manipulate files and to set and check file-access permissions.

The C run-time libraries have a 512 limit for the number of files that can be open at any one time. Attempting to open more than the maximum number of file descriptors or file streams causes program failure. Use _setmaxstdio to change this number.

File-handling routines (file descriptor)

These routines operate on files designated by a file descriptor.

Routine Use
_chsize,_chsize_s Change file size
_filelength, _filelengthi64 Get file length
_fstat, _fstat32, _fstat64, _fstati64, _fstat32i64, _fstat64i32 Get file-status information on descriptor
_get_osfhandle Return operating-system file handle associated with existing C run-time file descriptor
_isatty Check for character device
_locking Lock areas of file
_open_osfhandle Associate C run-time file descriptor with existing operating-system file handle
_setmode Set file-translation mode

File-Handling Routines (Path or Filename)

These routines operate on files specified by a path or filename.

Routine Use
_access, _waccess, _access_s, _waccess_s Check file-permission setting
_chmod, _wchmod Change file-permission setting
_fullpath, _wfullpath Expand a relative path to its absolute path name
_makepath, _wmakepath, _makepath_s, _wmakepath_s Merge path components into single, full path
_mktemp, _wmktemp, _mktemp_s, _wmktemp_s Create unique filename
remove, _wremove Delete file
rename, _wrename Rename file
_splitpath, _wsplitpath, _splitpath_s, _wsplitpath_s Parse path into components
_stat, _stat64, _stati64, _wstat, _wstat64, _wstati64 Get file-status information on named file
_umask, _umask_s Set default permission mask for new files created by program
_unlink, _wunlink Delete file

File-Handling Routines (Open File)

These routines open files.

Routine Use
fopen, _wfopen, fopen_s, _wfopen_s Opens a file and returns a pointer to the open file.
_fsopen, _wfsopen Open a stream with file sharing and returns a pointer to the open file.
_open, _wopen Opens a file and returns a file descriptor to the opened file.
_sopen, _wsopen, _sopen_s, _wsopen_s Open a file with file sharing and returns a file descriptor to the open file.
_pipe Creates a pipe for reading and writing.
freopen, _wfreopen, freopen_s, _wfreopen_s Reassign a file pointer.

These routines provide a way to change the representation of the file between a FILE structure, a file descriptor, and a Win32 file handle.

Routine Use
_fdopen, _wfdopen Associates a stream with a file that was previously opened for low-level I/O and returns a pointer to the open stream.
_fileno Gets the file descriptor associated with a stream.
_get_osfhandle Return operating-system file handle associated with existing C run-time file descriptor
_open_osfhandle Associates C run-time file descriptor with an existing operating-system file handle.

The following Win32 functions also open files and pipes:

See also

Universal C runtime routines by category
Directory control
System calls