-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.c
76 lines (66 loc) · 1.2 KB
/
tools.c
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <getch.h>
#include <unistd.h>
#include "tools.h"
// 从键盘获取指定长度的字符串
char* get_str(char* str,size_t hope_len)
{
if(NULL == str || 0 == hope_len) return NULL;
size_t index = 0;
while(index < hope_len-1)
{
int key_val = getch();
if(10 == key_val) break;
if(127 == key_val)
{
if(index)
{
index--;
printf("\b \b");
}
continue;
}
str[index++] = key_val;
printf("%c",key_val);
}
str[index] = '\0';
printf("\n");
stdin->_IO_read_ptr = stdin->_IO_read_end;
return str;
}
// 输入指定长度密码
char* get_pass(char* str,size_t hope_len,bool is_show)
{
if(NULL == str || 0 == hope_len) return NULL;
size_t index = 0;
while(index < hope_len-1)
{
int key_val = getch();
if(10 == key_val) break;
if(127 == key_val)
{
if(index)
{
index--;
printf("\b \b");
}
continue;
}
str[index++] = key_val;
if(is_show) printf("%c",key_val);
else printf("*");
}
str[index] = '\0';
printf("\n");
stdin->_IO_read_ptr = stdin->_IO_read_end;
return str;
}
// 文件数据读写
void file_oi(int ofd,int ifd)
{
char buf[4096] = {};
int ret = 0;
while((ret = read(ofd,buf,sizeof(buf))))
{
write(ifd,buf,ret);
}
}