我正在尝试用我的C#程序用Unix风格的换行编写一个文本文件.
由于某种原因,以下代码不起作用:
TextWriter fileTW = ...
fileTW.NewLine = "\n";
fileTW.WriteLine("Hello World!");
Run Code Online (Sandbox Code Playgroud)
这也不是:
TextWriter fileTW = ...
fileTW.Write("Hello World! + \n");
Run Code Online (Sandbox Code Playgroud)
在这两种情况下,'\n'都被'\ r \n'替换,我不想要!我一直用十六进制编辑器验证这一点,它显示每行以0x0D0A结尾.
有任何想法吗?
谢谢!
编辑:
对不起大家,误报!
请允许我解释一下......
我的TextWriter正在写一个MemoryStream,然后使用SharpZLib将其添加到tar存档中.事实证明,通过使用WinZIP提取文本文件,它正在用\ r \n替换\n的每个实例.如果我将相同的tar存档复制到我的Ubuntu机器并在那里提取,只有\n就在那里.奇怪的!
对不起,如果我浪费了任何人的时间!谢谢!
我正在尝试使用OpenSSL/libcrypto编写一个C函数来计算文件的SHA256总和.我在我的基础上亚当拉默的C++示例代码在这里.
这是我的代码:
int main (int argc, char** argv)
{
char calc_hash[65];
calc_sha256("file.txt", calc_hash);
}
int calc_sha256 (char* path, char output[65])
{
FILE* file = fopen(path, "rb");
if(!file) return -1;
char hash[SHA256_DIGEST_LENGTH];
SHA256_CTX sha256;
SHA256_Init(&sha256);
const int bufSize = 32768;
char* buffer = malloc(bufSize);
int bytesRead = 0;
if(!buffer) return -1;
while((bytesRead = fread(buffer, 1, bufSize, file)))
{
SHA256_Update(&sha256, buffer, bytesRead);
}
SHA256_Final(hash, &sha256);
sha256_hash_string(hash, output);
fclose(file);
free(buffer);
return 0;
}
void sha256_hash_string (char hash[SHA256_DIGEST_LENGTH], char outputBuffer[65])
{
int …
Run Code Online (Sandbox Code Playgroud) 我正在使用u-boot开发嵌入式Linux系统.U-boot使用console = bootarg设置ttyS0串口的波特率,但我还想设置ttyS [1-3]的默认波特率(不是9600).
在这个系统中,U-boot将设备树(dts/dtb)传递给内核,但设置那里的波特率似乎不起作用.
需要注意的是,该系统类似于峡谷地板(ppc460ex).
无论如何在u-boot,内核或设备树中是否有更改串口的默认波特率?
c ×1
c# ×1
cryptography ×1
linux-kernel ×1
newline ×1
openssl ×1
powerpc ×1
serial-port ×1
sha256 ×1
textwriter ×1
u-boot ×1