diff --git a/programs/regedit/regproc.c b/programs/regedit/regproc.c index f753947ae42..841ab791a7b 100644 --- a/programs/regedit/regproc.c +++ b/programs/regedit/regproc.c @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include #include @@ -987,9 +989,9 @@ static void REGPROC_export_binary(WCHAR **line_buf, DWORD *line_buf_size, DWORD const WCHAR *hex_prefix; const WCHAR hex[] = {'h','e','x',':',0}; WCHAR hex_buf[17]; - const WCHAR concat[] = {'\\','\n',' ',' ',0}; + const WCHAR concat[] = {'\\','\r','\n',' ',' ',0}; DWORD concat_prefix, concat_len; - const WCHAR newline[] = {'\n',0}; + const WCHAR newline[] = {'\r','\n',0}; CHAR* value_multibyte = NULL; if (type == REG_BINARY) { @@ -1098,7 +1100,7 @@ static void export_hkey(FILE *file, HKEY key, DWORD i; BOOL more_data; LONG ret; - WCHAR key_format[] = {'\n','[','%','s',']','\n',0}; + WCHAR key_format[] = {'\r','\n','[','%','s',']','\r','\n',0}; /* get size information and resize the buffers if necessary */ if (RegQueryInfoKeyW(key, NULL, NULL, NULL, NULL, @@ -1168,7 +1170,7 @@ static void export_hkey(FILE *file, HKEY key, REGPROC_export_binary(line_buf, line_buf_size, &line_len, value_type, *val_buf, val_size1, unicode); } else { const WCHAR start[] = {'"',0}; - const WCHAR end[] = {'"','\n',0}; + const WCHAR end[] = {'"','\r','\n',0}; DWORD len; len = lstrlenW(start); @@ -1189,7 +1191,7 @@ static void export_hkey(FILE *file, HKEY key, case REG_DWORD: { - WCHAR format[] = {'d','w','o','r','d',':','%','0','8','x','\n',0}; + WCHAR format[] = {'d','w','o','r','d',':','%','0','8','x','\r','\n',0}; REGPROC_resize_char_buffer(line_buf, line_buf_size, line_len + 15); sprintfW(*line_buf + line_len, format, *((DWORD *)*val_buf)); @@ -1254,19 +1256,20 @@ static void export_hkey(FILE *file, HKEY key, } /****************************************************************************** - * Open file for export. + * Open file in binary mode for export. */ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode) { FILE *file; WCHAR dash = '-'; - if (strncmpW(file_name,&dash,1)==0) + if (strncmpW(file_name,&dash,1)==0) { file=stdout; - else + _setmode(_fileno(file), _O_BINARY); + } else { CHAR* file_nameA = GetMultiByteString(file_name); - file = fopen(file_nameA, "w"); + file = fopen(file_nameA, "wb"); if (!file) { perror(""); fprintf(stderr,"%s: Can't open file \"%s\"\n", getAppName(), file_nameA); @@ -1278,12 +1281,12 @@ static FILE *REGPROC_open_export_file(WCHAR *file_name, BOOL unicode) if(unicode) { const BYTE unicode_seq[] = {0xff,0xfe}; - const WCHAR header[] = {'W','i','n','d','o','w','s',' ','R','e','g','i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s','i','o','n',' ','5','.','0','0','\n'}; + const WCHAR header[] = {'W','i','n','d','o','w','s',' ','R','e','g','i','s','t','r','y',' ','E','d','i','t','o','r',' ','V','e','r','s','i','o','n',' ','5','.','0','0','\r','\n'}; fwrite(unicode_seq, sizeof(BYTE), sizeof(unicode_seq)/sizeof(unicode_seq[0]), file); fwrite(header, sizeof(WCHAR), sizeof(header)/sizeof(header[0]), file); } else { - fputs("REGEDIT4\n", file); + fputs("REGEDIT4\r\n", file); } return file;