Next: , Previous: , Up: Basic Editing   [Contents][Index]


3.15 Saving Buffers in Files

Another useful command when working with buffer IO spaces (and in general, with any IO space) is save. Let’s say we want to save a copy of the header of an ELF file in another file. We could do it the pokeish way:

$ poke foo.o
[…]
(poke) save :from 0#B :size 64#B :file "header.dat"

The command above saves the first 64 bytes in the current IO space (which is backed by the file foo.o) into a new file header.dat in the current working directory.

Let’s now consider again the scenario where we are using a memory IO space as a scratch area. It is late in the night and we are tired, so we would like to save the contents of the scratch buffer to a file, so we can continue our work tomorrow. This is how we would do that:

(poke) .info ios
  Id	Type	Mode	Bias		Size		Name
* #1	MEMORY		0x00000000#B	0x00001000#B    *scratch*
  #0	FILE	rw	0x00000000#B	0x000f4241#B    ./foo.o
(poke) save :from 0#B :size iosize (1) :file "scratch.dat"

Here we used the built-in function iosize, that given an IO space identifier returns its size.