Carl Worth | 5070a20 | 2010-05-12 12:45:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include <talloc.h> |
| 25 | |
| 26 | void * |
| 27 | xtalloc_named_const (const void *context, size_t size, const char *name) |
| 28 | { |
| 29 | void *ret; |
| 30 | |
| 31 | ret = talloc_named_const (context, size, name); |
| 32 | if (ret == NULL) { |
| 33 | fprintf (stderr, "Out of memory.\n"); |
| 34 | exit (1); |
| 35 | } |
| 36 | |
| 37 | return ret; |
| 38 | } |
| 39 | |
| 40 | char * |
| 41 | xtalloc_strdup (const void *t, const char *p) |
| 42 | { |
| 43 | char *ret; |
| 44 | |
| 45 | ret = talloc_strdup (t, p); |
| 46 | if (ret == NULL) { |
| 47 | fprintf (stderr, "Out of memory.\n"); |
| 48 | exit (1); |
| 49 | } |
| 50 | |
| 51 | return ret; |
| 52 | } |
Carl Worth | a807fb7 | 2010-05-18 22:10:04 -0700 | [diff] [blame] | 53 | |
| 54 | char * |
| 55 | xtalloc_strndup (const void *t, const char *p, size_t n) |
| 56 | { |
| 57 | char *ret; |
| 58 | |
| 59 | ret = talloc_strndup (t, p, n); |
| 60 | if (ret == NULL) { |
| 61 | fprintf (stderr, "Out of memory.\n"); |
| 62 | exit (1); |
| 63 | } |
| 64 | |
| 65 | return ret; |
| 66 | } |
Carl Worth | b894583 | 2010-05-20 15:02:03 -0700 | [diff] [blame] | 67 | |
| 68 | char * |
| 69 | xtalloc_asprintf (const void *t, const char *fmt, ...) |
| 70 | { |
| 71 | va_list ap; |
| 72 | char *ret; |
| 73 | |
| 74 | va_start(ap, fmt); |
| 75 | |
| 76 | ret = talloc_vasprintf(t, fmt, ap); |
| 77 | if (ret == NULL) { |
| 78 | fprintf (stderr, "Out of memory.\n"); |
| 79 | exit (1); |
| 80 | } |
| 81 | |
| 82 | va_end(ap); |
| 83 | return ret; |
| 84 | } |
Carl Worth | 9bb796f | 2010-05-25 14:40:47 -0700 | [diff] [blame] | 85 | |
| 86 | void * |
| 87 | _xtalloc_reference_loc (const void *context, |
| 88 | const void *ptr, const char *location) |
| 89 | { |
| 90 | void *ret; |
| 91 | |
| 92 | ret = _talloc_reference_loc (context, ptr, location); |
| 93 | if (ret == NULL) { |
| 94 | fprintf (stderr, "Out of memory.\n"); |
| 95 | exit (1); |
| 96 | } |
| 97 | |
| 98 | return ret; |
| 99 | } |