f72a40
internals: added amgc_dprintf(), a signal-resilient dprintf implementation.
@@ -17,6 +17,7 @@ API_SRCS = \
|
|
17
17
|
src/skin/amgc_skin_default.c \
|
18
18
|
|
19
19
|
INTERNAL_SRCS = \
|
20
|
+
src/internal/$(PACKAGE)_dprintf_impl.c \
|
20
21
|
src/internal/$(PACKAGE)_errinfo_impl.c \
|
21
22
|
|
22
23
|
APP_SRCS = \
|
@@ -4,6 +4,7 @@ API_HEADERS = \
|
|
4
4
|
|
5
5
|
INTERNAL_HEADERS = \
|
6
6
|
$(PROJECT_DIR)/src/internal/argv/argv.h \
|
7
|
+
$(PROJECT_DIR)/src/internal/$(PACKAGE)_dprintf_impl.h \
|
7
8
|
$(PROJECT_DIR)/src/internal/$(PACKAGE)_driver_impl.h \
|
8
9
|
$(PROJECT_DIR)/src/internal/$(PACKAGE)_errinfo_impl.h \
|
9
10
|
|
@@ -0,0 +1,56 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
int amgc_dprintf(int fd, const char * fmt, ...)
|
8
|
+
{
|
9
|
+
int ret;
|
10
|
+
int cnt;
|
11
|
+
int size;
|
12
|
+
va_list ap;
|
13
|
+
char * ch;
|
14
|
+
char * buf;
|
15
|
+
char chbuf[2048];
|
16
|
+
|
17
|
+
va_start(ap,fmt);
|
18
|
+
|
19
|
+
size = sizeof(chbuf);
|
20
|
+
buf = ((cnt = vsnprintf(chbuf,size,fmt,ap)) < size)
|
21
|
+
? chbuf : malloc(cnt + 1);
|
22
|
+
|
23
|
+
va_end(ap);
|
24
|
+
|
25
|
+
if (buf == chbuf) {
|
26
|
+
(void)0;
|
27
|
+
|
28
|
+
} else if (buf) {
|
29
|
+
va_start(ap,fmt);
|
30
|
+
vsprintf(buf,fmt,ap);
|
31
|
+
va_end(ap);
|
32
|
+
|
33
|
+
} else {
|
34
|
+
return -1;
|
35
|
+
}
|
36
|
+
|
37
|
+
ret = 0;
|
38
|
+
ch = buf;
|
39
|
+
|
40
|
+
for (; cnt && ret>=0; ) {
|
41
|
+
ret = write(fd,ch,cnt);
|
42
|
+
|
43
|
+
while ((ret < 0) && (errno == EINTR))
|
44
|
+
ret = write(fd,ch,cnt);
|
45
|
+
|
46
|
+
ch += ret;
|
47
|
+
cnt -= ret;
|
48
|
+
}
|
49
|
+
|
50
|
+
ret = (ret < 0) ? -1 : ch - buf;
|
51
|
+
|
52
|
+
if (buf != chbuf)
|
53
|
+
free(buf);
|
54
|
+
|
55
|
+
return ret;
|
56
|
+
}
|
@@ -0,0 +1,6 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
int amgc_dprintf(int fd, const char * fmt, ...);
|
5
|
+
|
6
|
+
|