kernel: Use 'normal' types (i.e., uint8_t instead of __uint8_t).
[dragonfly.git] / bin / cpdup / compat_sun.c
blobfc1a734c5980babb52696d854e93dd5ebc54ddf2
1 /*
2 * Implement some functions which are unknown to Solaris 10.
3 */
5 #include "compat_sun.h"
6 #include <stdlib.h>
8 int
9 vasprintf(char **str, const char *format, va_list ap)
11 char dummy[2];
12 int result;
14 if ((result = vsnprintf(dummy, 2, format, ap)) < 0) {
15 *str = NULL;
16 return (result);
18 if ((*str = malloc(result + 1)) == NULL)
19 return (-1);
20 if ((result = vsnprintf(*str, result + 1, format, ap)) < 0) {
21 free(*str);
22 *str = NULL;
24 return (result);
27 int
28 asprintf(char **str, const char *format, ...)
30 va_list ap;
31 int result;
33 va_start(ap, format);
34 result = vasprintf(str, format, ap);
35 va_end(ap);
36 return (result);
39 #ifndef NOMD5
41 #include <sys/types.h>
42 #include <sys/uio.h>
43 #include <unistd.h>
44 #include <fcntl.h>
46 char *
47 MD5File(const char *filename, char *buf)
49 unsigned char dbuf[8192];
50 MD5_CTX ctx;
51 int fd;
52 int count;
54 if ((fd = open(filename, O_RDONLY)) < 0)
55 return (NULL);
56 MD5Init(&ctx);
57 while ((count = read(fd, dbuf, sizeof(dbuf))) > 0)
58 MD5Update(&ctx, dbuf, count);
59 close(fd);
60 if (count < 0)
61 return (NULL);
62 if (buf == NULL)
63 if ((buf = malloc(33)) == NULL)
64 return NULL;
65 MD5Final(dbuf, &ctx);
66 for (count = 0; count < 16; count++)
67 sprintf(buf + count * 2, "%02x", dbuf[count]);
68 return (buf);
71 #endif /* ifndef NOMD5 */