OLD | NEW |
1 /* | 1 /* |
2 Samba Unix SMB/CIFS implementation. | 2 Samba Unix SMB/CIFS implementation. |
3 | 3 |
4 Samba trivial allocation library - new interface | 4 Samba trivial allocation library - new interface |
5 | 5 |
6 NOTE: Please read talloc_guide.txt for full documentation | 6 NOTE: Please read talloc_guide.txt for full documentation |
7 | 7 |
8 Copyright (C) Andrew Tridgell 2004 | 8 Copyright (C) Andrew Tridgell 2004 |
9 Copyright (C) Stefan Metzmacher 2006 | 9 Copyright (C) Stefan Metzmacher 2006 |
10 | 10 |
(...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1715 #else | 1715 #else |
1716 #define va_copy(dest, src) (dest) = (src) | 1716 #define va_copy(dest, src) (dest) = (src) |
1717 #endif | 1717 #endif |
1718 #endif | 1718 #endif |
1719 | 1719 |
1720 char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) | 1720 char *talloc_vasprintf(const void *t, const char *fmt, va_list ap) |
1721 { | 1721 { |
1722 int len; | 1722 int len; |
1723 char *ret; | 1723 char *ret; |
1724 va_list ap2; | 1724 va_list ap2; |
1725 char c; | |
1726 | 1725 |
1727 /* this call looks strange, but it makes it work on older solaris boxes
*/ | |
1728 va_copy(ap2, ap); | 1726 va_copy(ap2, ap); |
1729 » len = vsnprintf(&c, 1, fmt, ap2); | 1727 » len = vsnprintf(NULL, 0, fmt, ap2); |
1730 va_end(ap2); | 1728 va_end(ap2); |
1731 if (unlikely(len < 0)) { | 1729 if (unlikely(len < 0)) { |
1732 return NULL; | 1730 return NULL; |
1733 } | 1731 } |
1734 | 1732 |
1735 ret = (char *)__talloc(t, len+1); | 1733 ret = (char *)__talloc(t, len+1); |
1736 if (unlikely(!ret)) return NULL; | 1734 if (unlikely(!ret)) return NULL; |
1737 | 1735 |
1738 va_copy(ap2, ap); | 1736 va_copy(ap2, ap); |
1739 vsnprintf(ret, len+1, fmt, ap2); | 1737 vsnprintf(ret, len+1, fmt, ap2); |
(...skipping 26 matching lines...) Expand all Loading... |
1766 static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen, | 1764 static INLINE char *__talloc_vaslenprintf_append(char *s, size_t slen, |
1767 const char *fmt, va_list ap) | 1765 const char *fmt, va_list ap) |
1768 { | 1766 { |
1769 /* ssize_t isn't present on Windows. */ | 1767 /* ssize_t isn't present on Windows. */ |
1770 #ifndef _MSC_VER | 1768 #ifndef _MSC_VER |
1771 ssize_t alen; | 1769 ssize_t alen; |
1772 #else | 1770 #else |
1773 size_t alen; | 1771 size_t alen; |
1774 #endif | 1772 #endif |
1775 va_list ap2; | 1773 va_list ap2; |
1776 char c; | |
1777 | 1774 |
1778 va_copy(ap2, ap); | 1775 va_copy(ap2, ap); |
1779 » alen = vsnprintf(&c, 1, fmt, ap2); | 1776 » alen = vsnprintf(NULL, 0, fmt, ap2); |
1780 va_end(ap2); | 1777 va_end(ap2); |
1781 | 1778 |
1782 if (alen <= 0) { | 1779 if (alen <= 0) { |
1783 /* Either the vsnprintf failed or the format resulted in | 1780 /* Either the vsnprintf failed or the format resulted in |
1784 * no characters being formatted. In the former case, we | 1781 * no characters being formatted. In the former case, we |
1785 * ought to return NULL, in the latter we ought to return | 1782 * ought to return NULL, in the latter we ought to return |
1786 * the original string. Most current callers of this | 1783 * the original string. Most current callers of this |
1787 * function expect it to never return NULL. | 1784 * function expect it to never return NULL. |
1788 */ | 1785 */ |
1789 return s; | 1786 return s; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2013 tc = talloc_chunk_from_ptr(context); | 2010 tc = talloc_chunk_from_ptr(context); |
2014 while (tc) { | 2011 while (tc) { |
2015 if (TC_PTR_FROM_CHUNK(tc) == ptr) return 1; | 2012 if (TC_PTR_FROM_CHUNK(tc) == ptr) return 1; |
2016 while (tc && tc->prev) tc = tc->prev; | 2013 while (tc && tc->prev) tc = tc->prev; |
2017 if (tc) { | 2014 if (tc) { |
2018 tc = tc->parent; | 2015 tc = tc->parent; |
2019 } | 2016 } |
2020 } | 2017 } |
2021 return 0; | 2018 return 0; |
2022 } | 2019 } |
OLD | NEW |