博客启用新域名 blog.xdeng.cn,这里只作为旧的显示。
clock()函数的一个坑
clock_t s = clock();
Sleep(5*1000);
printf("%d\n", clock() - s);
这段代码在Windows上大于或等于5秒,但是在Linux上就小于5秒。
查资料发现 标准的应该是 Returns the processor time consumed by the program. 返回程序消耗的处理器时间。
但在MSDN上 Calculates the wall-clock time used by the calling process. 计算调用进程使用的挂钟时间,
注释写的是 The clock function tells how much wall-clock time has passed since the CRT initialization during process start. Note that this function does not strictly conform to ISO C, which specifies net CPU time as the return value. To obtain CPU times, use the Win32 GetProcessTimes function. To determine the elapsed time in seconds, divide the value returned by the clock function by the macro CLOCKS_PER_SEC.
在Linux上是占用CPU时间,在Windows上是运行时间。所以跨平台的时候就要注意了,不要使用这个函数来做计时。
参考 http://www.51testing.com/html/00/n-3706800.html
OPENSSL AES解密文件遇到的一个小坑
openssl aes解密需要用到 EVP_CIPHER_CTX_new EVP_DecryptInit_ex EVP_DecryptUpdate EVP_DecryptFinal_ex EVP_CIPHER_CTX_free 五个函数。
默认启用了填充,如果不需要需调用EVP_CIPHER_CTX_set_padding设成0禁用。
在解密大文件的时候需要持续调用EVP_DecryptUpdate来解密,我犯了个错误就是inbuf大小和outbuf大小设成一样,出问题查官方文档才知道outbuf大小要比inbuf大。
EVP_DecryptInit_ex(), EVP_DecryptUpdate() and EVP_DecryptFinal_ex() are the corresponding decryption operations. EVP_DecryptFinal() will return an error code if padding is enabled and the final block is not correctly formatted. The parameters and restrictions are identical to the encryption operations except that if padding is enabled the decrypted data buffer out passed to EVP_DecryptUpdate() should have sufficient room for (inl + cipher_block_size) bytes unless the cipher block size is 1 in which case inl bytes is sufficient.
网上的代码不能乱抄啊!看官方文档的重要性。
https://www.openssl.org/docs/man1.0.2/crypto/EVP_DecryptUpdate.html
https://wiki.openssl.org/index.php/EVP_Symmetric_Encryption_and_Decryption
换服务器了
很早之前买的阿里云到期了,当时是搞活动一下子买了5年,一直用到现在没啥问题。
期间的重启都是自己重启的,不然就没断过了。
现在新换了一台最便宜的,只放博客。
CSGO官方5年老兵收藏币
购买要求 CSGO游戏五年
购买地址 https://valvestore.welovefine.com/feature/csgo-collectible-five-year-veteran-coin.html
直邮大概用了一星期左右到手。