The curses library provides applications with the ability to write
the contents of a window to an external file using scr_dump or
putwin, and read it back using scr_restore or getwin.
The putwin and getwin functions do the work; while scr_dump and
scr_restore conveniently save and restore the whole screen, i.e.,
stdscr.
ncurses6
A longstanding implementation of screen-dump was revised with
ncurses6 to remedy problems with the earlier approach:
· A “magic number” is written to the beginning of the dump file,
allowing applications (such as file(1)) to recognize curses dump
files.
Because ncurses6 uses a new format, that requires a new magic
number was unused by other applications. This 16-bit number was
unused:
0x8888 (octal “\210\210”)
but to be more certain, this 32-bit number was chosen:
0x88888888 (octal “\210\210\210\210”)
This is the pattern submitted to the maintainers of the file
program:
#
# ncurses5 (and before) did not use a magic number,
# making screen dumps "data".
#
# ncurses6 (2015) uses this format, ignoring byte-order
0 string \210\210\210\210ncurses ncurses6 screen image
#
· The screen dumps are written in textual form, so that internal
data sizes are not directly related to the dump-format, and
enabling the library to read dumps from either narrow- or wide-
character- configurations.
The narrow library configuration holds characters and video
attributes in a 32-bit chtype, while the wide-character library
stores this information in the cchar_t structure, which is much
larger than 32-bits.
· It is possible to read a screen dump into a terminal with a
different screen-size, because the library truncates or fills the
screen as necessary.
· The ncurses6 getwin reads the legacy screen dumps from ncurses5.
ncurses5 (legacy)
The screen-dump feature was added to ncurses in June 1995. While
there were fixes and improvements in succeeding years, the basic
scheme was unchanged:
· The WINDOW structure was written in binary form.
· The WINDOW structure refers to lines of data, which were written
as an array of binary data following the WINDOW.
· When getwin restored the window, it would keep track of offsets
into the array of line-data and adjust the WINDOW structure which
was read back into memory.
This is similar to Unix SystemV, but does not write a “magic number”
to identify the file format.

There is no standard format for putwin. This section gives a brief
description of the existing formats.
X/Open Curses
Refer to X/Open Curses, Issue 7 (2009).
X/Open's documentation for enhanced curses says only:
The getwin( ) function reads window-related data stored in the
file by putwin( ). The function then creates and initializes a
new window using that data.
The putwin( ) function writes all data associated with win into
the stdio stream to which filep points, using an unspecifiedformat. This information can be retrieved later using getwin( ).
In the mid-1990s when the X/Open Curses document was written, there
were still systems using older, less capable curses libraries (aside
from the BSD curses library which was not relevant to X/Open because
it did not meet the criteria for base curses). The document
explained the term “enhanced” as follows:
· Shading is used to identify X/Open Enhanced Curses material,
relating to interfaces included to provide enhanced
capabilities for applications originally written to be
compiled on systems based on the UNIX operating system.
Therefore, the features described may not be present on
systems that conform to XPG4 or to earlier XPG releases. The
relevant reference pages may provide additional or more
specific portability warnings about use of the material.
In the foregoing, emphasis was added to unspecified format and to
XPG4 or to earlier XPG releases, for clarity.
Unix SystemV
Unix SystemV curses identified the file format by writing a “magic
number” at the beginning of the dump. The WINDOW data and the lines
of text follow, all in binary form.
The Solaris curses source has these definitions:
/* terminfo magic number */
#define MAGNUM 0432
/* curses screen dump magic number */
#define SVR2_DUMP_MAGIC_NUMBER 0433
#define SVR3_DUMP_MAGIC_NUMBER 0434
That is, the feature was likely introduced in SVr2 (1984), and
improved in SVr3 (1987). The Solaris curses source has no magic
number for SVr4 (1989). Other operating systems (AIX and HPUX) use a
magic number which would correspond to this definition:
/* curses screen dump magic number */
#define SVR4_DUMP_MAGIC_NUMBER 0435
That octal number in bytes is 001, 035. Because most Unix vendors
use big-endian hardware, the magic number is written with the high-
order byte first, e.g.,
01 35
After the magic number, the WINDOW structure and line-data are
written in binary format. While the magic number used by the Unix
systems can be seen using od(1), none of the Unix systems documents
the format used for screen-dumps.
The Unix systems do not use identical formats. While collecting
information for for this manual page, the savescreen test-program
produced dumps of different size (all on 64-bit hardware, on 40x80
screens):
· AIX (51817 bytes)
· HPUX (90093 bytes)
· Solaris 10 (13273 bytes)
· ncurses5 (12888 bytes)
Solaris
As noted above, Solaris curses has no magic number corresponding to
SVr4 curses. This is odd since Solaris was the first operating
system to pass the SVr4 guidelines. Solaris has two versions of
curses:
· The default curses library uses the SVr3 magic number.
· There is an alternate curses library in /usr/xpg4. This uses a
textual format with no magic number.
According to the copyright notice, the xpg4 Solaris curses
library was developed by MKS (Mortice Kern Systems) from 1990 to
1995.
Like ncurses6, there is a file-header with parameters. Unlike
ncurses6, the contents of the window are written piecemeal, with
coordinates and attributes for each chunk of text rather than
writing the whole window from top to bottom.
PDCurses
PDCurses added support for screen dumps in version 2.7 (2005). Like
Unix SystemV and ncurses5, it writes the WINDOW structure in binary,
but begins the file with its three-byte identifier “PDC”, followed by
a one-byte version, e.g.,
“PDC\001”
NetBSD
As of April 2017, NetBSD curses does not support scr_dump and
scr_restore (or scr_init, scr_set), although it has putwin and
getwin.
Like ncurses5, NetBSD putwin does not identify its dumps with a
useful magic number. It writes
· the curses shared library major and minor versions as the first
two bytes (e.g., 7 and 1),
· followed by a binary dump of the WINDOW,
· some data for wide-characters referenced by the WINDOW structure,
and
· finally, lines as done by other implementations.

This page is part of the ncurses (new curses) project. Information
about the project can be found at
⟨https://www.gnu.org/software/ncurses/ncurses.html⟩. If you have a
bug report for this manual page, send it to
bug-ncurses-request@gnu.org. This page was obtained from the
project's upstream Git mirror of the CVS repository
⟨git://ncurses.scripts.mit.edu/ncurses.git⟩ on 2018-10-29. (At that
time, the date of the most recent commit that was found in the repos‐
itory was 2018-06-03.) If you discover any rendering problems in
this HTML version of the page, or you believe there is a better or
more up-to-date source for the page, or you have corrections or
improvements to the information in this COLOPHON (which is not part
of the original manual page), send a mail to man-pages@man7.org
scr_dump(5)