author | viric@llimona |
Sat, 09 Feb 2008 11:56:03 +0100 | |
changeset 196 | bca29e2a1a86 |
parent 165 | 7b914d4003c2 |
child 231 | 558b281b88f5 |
permissions | -rw-r--r-- |
165
7b914d4003c2
Fixing licenses in some files, and updating some documents.
viric@mandarina
parents:
147
diff
changeset
|
1 |
/* |
7b914d4003c2
Fixing licenses in some files, and updating some documents.
viric@mandarina
parents:
147
diff
changeset
|
2 |
Task Spooler - a task queue system for the unix user |
7b914d4003c2
Fixing licenses in some files, and updating some documents.
viric@mandarina
parents:
147
diff
changeset
|
3 |
Copyright (C) 2007 LluĂs Batlle i Rossell |
7b914d4003c2
Fixing licenses in some files, and updating some documents.
viric@mandarina
parents:
147
diff
changeset
|
4 |
|
7b914d4003c2
Fixing licenses in some files, and updating some documents.
viric@mandarina
parents:
147
diff
changeset
|
5 |
Please find the license in the provided COPYING file. |
7b914d4003c2
Fixing licenses in some files, and updating some documents.
viric@mandarina
parents:
147
diff
changeset
|
6 |
*/ |
146 | 7 |
#include <stdlib.h> |
8 |
#include <string.h> |
|
9 |
#include <unistd.h> |
|
10 |
#include <stdio.h> |
|
11 |
#include <stdarg.h> |
|
147 | 12 |
#include <sys/time.h> |
146 | 13 |
#include "main.h" |
14 |
||
15 |
||
16 |
/* maxsize: max buffer size, with '\0' */ |
|
17 |
int fd_nprintf(int fd, int maxsize, const char *fmt, ...) |
|
18 |
{ |
|
19 |
va_list ap; |
|
20 |
char *out; |
|
21 |
int size; |
|
22 |
int rest; |
|
23 |
||
24 |
va_start(ap, fmt); |
|
25 |
||
26 |
out = (char *) malloc(maxsize * sizeof(char)); |
|
27 |
if (out == 0) |
|
28 |
{ |
|
29 |
warning("Not enough memory in fd_nprintf()"); |
|
30 |
return -1; |
|
31 |
} |
|
32 |
||
33 |
size = vsnprintf(out, maxsize, fmt, ap); |
|
34 |
||
147 | 35 |
rest = size; /* We don't want the last null character */ |
146 | 36 |
while (rest > 0) |
37 |
{ |
|
38 |
int res; |
|
39 |
res = write(fd, out, rest); |
|
40 |
if (res == -1) |
|
41 |
{ |
|
42 |
warning("Cannot write more chars in pinfo_dump"); |
|
43 |
break; |
|
44 |
} |
|
45 |
rest -= res; |
|
46 |
} |
|
47 |
||
48 |
free(out); |
|
49 |
||
50 |
return size; |
|
51 |
} |