Home Contents | # rawio.dup | Rawio | Core4 Lua Event System

## SYNOPSIS

1. new_handle = old_handle:dup()
2. new_handle = rawio.dup(fd)

## DESCRIPTION

Creates a copy of a file handle. The new file handle refers to the same file as the old handle, but is completely independent otherwise. The first form takes an existing rawio file handle, while the second takes an already open file descriptor.

## RETURN VALUE

On success, a rawio handle is returned. On error, three values are returned: nil, a string describing the error (The result of the C library call strerror() on the errno code) and the errno number from the standard C library.

## NOTES

Useful pre-existing file descriptors are 0 (Standard input), 1 (Standard output), 2 (Standard error output).

## EXAMPLE

Creates a duplicate of standard output, writes its file descriptor and closes the duplicate. Note that the normal standard output keeps working after the close, as the original file handle is not affected.
> > >
handle = rawio.dup(1) handle:write(string.format("fd=%d\n", handle:fd())) handle:close()
4

## SEE ALSO

rawio.attach, rawio:blocking, rawio:canReadLine, rawio:clearError, rawio:close, rawio:connect, rawio:detach, rawio:lastError, rawio:line, rawio:lines, rawio.access, rawio.open, rawio:read, rawio:copy, rawio.stat, rawio.statfs, rawio:writet, rawio:write