-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutil.c
More file actions
46 lines (38 loc) · 648 Bytes
/
Copy pathutil.c
File metadata and controls
46 lines (38 loc) · 648 Bytes
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
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <unistd.h>
#include "common.h"
int
xwrite(int fd, char *buf, size_t count)
{
ssize_t ret;
char *ptr = buf;
while (count) {
ret = write(fd, ptr, count);
if (ret == -1)
return -1;
count -= ret;
ptr += ret;
}
return count;
}
ssize_t
get_password(FILE *f, char *buf)
{
int ret;
char *ptr = buf;
while (ptr - buf < PASSWORD_MAX_LEN) {
ret = fgetc(f);
if (ret == EOF) {
if (ptr > buf && *(ptr - 1) == '\n')
return ptr - buf - 1;
else
return ptr - buf;
} else if (ret == '\n') {
return ptr - buf;
}
*(ptr++) = ret;
}
return -2;
}