expect scp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
auto_scp()
{
	local filepath=$1
	expect -c "
		set timeout 10
 
		spawn scp scp://someone@192.168.12.3:1234//home/someone/$filepath .
 
		expect \"password:\" 
		send \"toodangerous\r\"
 
		interact
	"
}

refer to:
https://blog.csdn.net/f_zyj/article/details/93475830
https://zhuanlan.zhihu.com/p/25164676

strdupa in Windows

my_alloca.h

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef _MY_ALLOCA_H_
#define _MY_ALLOCA_H_
 
#include <malloc.h>
 
__declspec(thread) extern size_t strdupa_len;
__declspec(thread) extern char* strdupa_p;
#define strdupa(_str) \
( \
	strdupa_len = strlen(_str), \
	strdupa_p = (char*)_alloca(strdupa_len + 1), \
	memcpy(strdupa_p, _str, strdupa_len + 1), \
	strdupa_p \
)
 
#endif

my_alloca.c

1
2
3
#include "my_alloca.h"
__declspec(thread) size_t strdupa_len;
__declspec(thread) char* strdupa_p;

example.c

1
2
3
4
5
6
#include "my_alloca.h"
 
int main()
{
	char* p = strdupa("hi");
}

Select Windows SDK version when building using cmake

Read cmake online doc carefully, https://cmake.org/cmake/help/latest/variable/CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION.html

So when we build project which has CMakeLists.txt, we can select Windows SDK version in this way:

  1. In explorer, navigate to like C:\Program Files (x86)\Windows Kits\10\Include.
  2. For cmake always finds the newest version to build our project, we can just rename all sdk versions which is newer than we want. e.g. if we want 10.0.19041.0 to build our project, but 10.0.22581.0 is newer, we rename 10.0.22581.0 to 10.0.0.22581.0, the rule is among tokens split by period signs, the third token number is the key word that cmake sorts them to get the largest as newest.
  3. Start cmake to configure the project, it will find the right sdk version.
  4. After cmake is done in configuration, rename 10.0.0.22581.0 back to 10.0.22581.0.