Windows平台下新的文件才拷贝

Linux下的cp -u能实现只在源文件比目标文件新时才拷贝,但此命令在MinGW下不好使,我通过在网上查方法,写了以下同样功能的脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
clearBinary()
{
	local destDir=$1
	local fileName=$2
	local ext=$3
 
	rm "${destDir}/${fileName}.${ext}" 1>/dev/null 2>&1
 
	for ((j = 1; j <= 20; j++)); do
		if [ -f "${destDir}/${fileName}_$j.${ext}" ] ; then
			rm "${destDir}/${fileName}_$j.${ext}"
		fi
	done
 
	for ((j = 1; j <= 20; j++)); do
		if [ -f "${destDir}/${fileName}.${ext}" ] ; then
			mv "${destDir}/${fileName}.${ext}" "${destDir}/${fileName}_$j.${ext}"
		fi
	done
}
 
copyFile()
{
	local srcDir=$1
	local destDir=$2
	local fileName=$3
	local ext=$4
 
	local srcPath=${srcDir}/${fileName}.${ext}
	local destPath=${destDir}/${fileName}.${ext}
 
	if [ ! -f "${srcPath}" ] ; then
		return
	fi
 
	local timeFrom=`stat -c %Y "${srcPath}"`
	local timeTo=`stat -c %Y "${destPath}"`
	if [ "$timeFrom" = "$timeTo" -a "x$forceReplace" != "xforce" ]; then
		return
	fi
 
	clearBinary "${destDir}" ${fileName} ${ext}
 
	cp "${srcPath}" "${destPath}"
 
	local timeFromStr=`date -d "@$timeFrom" "+%Y-%m-%d %H:%M:%S"`
	touch -m -d "$timeFromStr" "${destPath}"
 
	echo "[${srcPath}]->[${destPath}] copied."
}
 
copyFile /e/source /c/dest hello docx

EuhatGift发布

我写的一个开源的工具库,地址:https://github.com/euhat/EuhatGift
现在包含功能:

  • Boost库里的json文件操作接口非常适合于写业务代码,但该库会把数字写成数字字符串,这是有问题的。再考虑性能及各种语言编码的兼容性,我写了一个cJSON库的c++包装类,接口类似于Boost,名叫CjsonWrapper。
  • Windows的GetPrivateProfileStringA函数要预定义接收值的Buffer大小,这是有缺点的,这会造成我们读取的值可能只读了一半我们却没有办法。我于是重写了ini操作相关的函数库,名叫IniOp,C语言风格,跨平台。

gtk user control自绘控件

ubuntu下gtk库是默认已安装的,开发部署很方便,以下是我写的自绘控件例子:

EuhatChildWnd.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once
 
struct _cairo_surface;
struct _GtkWidget;
 
class EuhatChildWnd
{
public:
	EuhatChildWnd(int width, int height);
	~EuhatChildWnd();
 
	void clear();
	void drawBrush(struct _GtkWidget *widget, double x, double y);
 
	struct _GtkWidget *drawingArea_;
	struct _cairo_surface *surface_;
 
	double xFrom_;
	double yFrom_;
};

Read more

ntoskrnl.ExiAcquireFastMutex HAL.dll

在32位Win7操作系统里,运行引用我们编的动态库的应用程序,报如下错误:

无法定位程序输入点 ntoskrnl.ExiAcquireFastMutex 于动态链接库 HAL.dll 上。

用Dependency Walker查看我们编的动态库,发现引用了ntoskrnl.exe,猜测在旧有的32位win32环境中是不会从dll中去引用别的exe的。只有在64位win32环境中才会存在从dll中去引用ntoskrnl.exe。

32位动态库编译的解决办法:
链接器->输入->附加依赖项去除ucrt.lib和wdm.lib。
链接器->输入->忽略所有默认库设为否。
链接器->高级->入口点清空。

addr2line ??

gcc中加入编译选项

1
g++ -g -Wl,-Map=test.map -no-pie -rdynamic ...

内核设置如下

1
echo 0 > /proc/sys/kernel/randomize_va_space

addr2line

1
addr2line -e ./test -Cif 0x401425

vim+cscope

1
2
apt install vim
apt install cscope

将以下脚本保存为~/.vimrc,注意要用dos2unix转换一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
if has("cscope")
	set csprg=/usr/bin/cscope
	set csto=0
	set cst
	set nocsverb
	" add any database in current directory
	if filereadable("cscope.out")
	    cs add cscope.out
	" else add database pointed to by environment
	elseif $CSCOPE_DB != ""
	    cs add $CSCOPE_DB
	endif
	set csverb
endif
 
nmap <C-[>s :scs find s <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>g :scs find g <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>c :scs find c <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>t :scs find t <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>e :scs find e <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
nmap <C-[>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nmap <C-[>d :scs find d <C-R>=expand("<cword>")<CR><CR>
nmap <C-[>a :scs find a <C-R>=expand("<cword>")<CR><CR>
 
set fileencodings=utf-8,gb2312,gbk,gb18030
set termencoding=utf-8
set fileformats=unix
set cindent

每次源码更新时,在源码根目录执行

1
2
3
#find . -type f | cat > cscope.files
#find . -name "*.c" -o -name "*.cpp" -o -name "*.h" -o -name "*.hpp" > cscope.files
cscope -bqR

编译Android版本的OpenSSL

将android-ndk-r20b和openssl-master解压在同一层目录,在此目录创建脚本bld.sh,内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/bin/sh
 
BASE_DIR=/home/sdb/android/ndk-r20b
 
export ANDROID_NDK_HOME=${BASE_DIR}/android-ndk-r20b
 
PATH=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin:$ANDROID_NDK_HOME/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin:$PATH
 
cd openssl-master/
 
#./Configure --prefix=${BASE_DIR}/openssl-arm32 android-arm -D__ANDROID_API__=29
./Configure --prefix=${BASE_DIR}/openssl-arm32 android-arm -D__ANDROID_API__=16
#./Configure --prefix=${BASE_DIR}/openssl-x86 android-x86 -D__ANDROID_API__=16
 
make
make install

运行bld.sh脚本就会生成OpenSSL库文件。

How to build rtsp stream from a mp4 file to test EuhatRtsp

First, convert mp4 file to h264 file, save script below as convert.bat

1
2
3
ffmpeg.exe -i %1 -s 1920x1080 -b:v 1536K -an output.mp4
ffmpeg -i output.mp4 -codec copy -bsf: h264_mp4toannexb -f h264 output.264
#ffmpeg -i test.264 -vcodec copy -f mp4 test.mp4

drag a mp4 file over convert.bat, after a while, output.264 will be generated. download h264LiveMediaServer.zip, unzip as h264LiveMediaServer.exe, move it to the same directory with output.264, just double click and run h264LiveMediaServer.exe, it will notify you the rtsp url, then input the url in the url edit box on the EuhatRtsp Demo app ui, click begin button, wait several seconds, you will see the video rendering in EuhatRtsp.

Before running h264LiveMediaServer.exe, vc2019 x86 Redistributable must be installed.

Visit H264LiveMediaServer on Github to get the source code.