This is probably a stupid question, but it seems that there is no /dev/zero equivalent available under windows.
I.e. I want to create a file full of null bytes.
Under Linux:
dd if=/dev/zero of=/tmp/foo bs=1M count=1
works, but how do I (or can I even) do the same thing under windows with the dd for gnuwin32?
I think cygwin emulates things like /dev/zero and /dev/null under that environment, but I don't have cygwin installed in all places and was hoping the gnuwin32 tools could help me out.
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not aware of a gnuwin32 tool that will fill a file with a particular byte value, but here's one that will. I wrote it for the MSVC 6.0 environment; it should port to other compiler environments with minimal work. The part that might give trouble is the "setmode" call; you'll need this to prevent NL to CRLF translation, and to avoid misinterpretation of CTRL-Z.
Enjoy,
Robert Bassett
/ bytegen: repeat a specified byte /
include <stdio.h>
include <fcntl.h>
unsigned interp (char s)
{
if (s == '\')
switch (++s) {
case 'x': case 'X':
return (unsigned char) strtoul (++s, NULL, 16);
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return (unsigned char) strtoul (s, NULL, 0);
case '\':
return '\';
case 'a':
return '\a';
case 'b':
return '\b';
case 'f':
return '\f';
case 'n':
return '\n';
case 'r':
return '\r';
case 't':
return '\t';
case 'v':
return '\v';
}
return (unsigned char) s;
}
int main (int argc, char **argv)
{
unsigned byte, rept;
This is probably a stupid question, but it seems that there is no /dev/zero equivalent available under windows.
I.e. I want to create a file full of null bytes.
Under Linux:
dd if=/dev/zero of=/tmp/foo bs=1M count=1
works, but how do I (or can I even) do the same thing under windows with the dd for gnuwin32?
I think cygwin emulates things like /dev/zero and /dev/null under that environment, but I don't have cygwin installed in all places and was hoping the gnuwin32 tools could help me out.
Thanks.
I'm not aware of a gnuwin32 tool that will fill a file with a particular byte value, but here's one that will. I wrote it for the MSVC 6.0 environment; it should port to other compiler environments with minimal work. The part that might give trouble is the "setmode" call; you'll need this to prevent NL to CRLF translation, and to avoid misinterpretation of CTRL-Z.
Enjoy,
Robert Bassett
/ bytegen: repeat a specified byte /
include <stdio.h>
include <fcntl.h>
unsigned interp (char s)
{
if (s == '\')
switch (++s) {
case 'x': case 'X':
return (unsigned char) strtoul (++s, NULL, 16);
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
return (unsigned char) strtoul (s, NULL, 0);
case '\':
return '\';
case 'a':
return '\a';
case 'b':
return '\b';
case 'f':
return '\f';
case 'n':
return '\n';
case 'r':
return '\r';
case 't':
return '\t';
case 'v':
return '\v';
}
return (unsigned char) s;
}
int main (int argc, char **argv)
{
unsigned byte, rept;
}