Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 1 | /* Declarations for common convenience functions. |
Ulrich Drepper | fdc93e1 | 2009-01-17 11:47:10 -0800 | [diff] [blame] | 2 | Copyright (C) 2006, 2009 Red Hat, Inc. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 3 | This file is part of Red Hat elfutils. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 4 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 5 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License as published by the |
| 7 | Free Software Foundation; version 2 of the License. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 8 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 9 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 10 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | General Public License for more details. |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 13 | |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 14 | You should have received a copy of the GNU General Public License along |
| 15 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
Ulrich Drepper | 1e9ef50 | 2006-04-04 22:29:06 +0000 | [diff] [blame] | 16 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
Ulrich Drepper | 361df7d | 2006-04-04 21:38:57 +0000 | [diff] [blame] | 17 | |
| 18 | In addition, as a special exception, Red Hat, Inc. gives You the |
| 19 | additional right to link the code of Red Hat elfutils with code licensed |
| 20 | under an Open Source Initiative certified open source license |
| 21 | (http://www.opensource.org/licenses/index.php) and to distribute linked |
| 22 | combinations including the two. Non-GPL Code permitted under this |
| 23 | exception must only link to the code of Red Hat elfutils through those |
| 24 | well defined interfaces identified in the file named EXCEPTION found in |
| 25 | the source code files (the "Approved Interfaces"). The files of Non-GPL |
| 26 | Code may instantiate templates or use macros or inline functions from |
| 27 | the Approved Interfaces without causing the resulting work to be covered |
| 28 | by the GNU General Public License. Only Red Hat, Inc. may make changes |
| 29 | or additions to the list of Approved Interfaces. Red Hat's grant of |
| 30 | this exception is conditioned upon your not adding any new exceptions. |
| 31 | If you wish to add a new Approved Interface or exception, please contact |
| 32 | Red Hat. You must obey the GNU General Public License in all respects |
| 33 | for all of the Red Hat elfutils code and other code used in conjunction |
| 34 | with Red Hat elfutils except the Non-GPL Code covered by this exception. |
| 35 | If you modify this file, you may extend this exception to your version |
| 36 | of the file, but you are not obligated to do so. If you do not wish to |
| 37 | provide this exception without modification, you must delete this |
| 38 | exception statement from your version and license this file solely under |
| 39 | the GPL without exception. |
| 40 | |
| 41 | Red Hat elfutils is an included package of the Open Invention Network. |
| 42 | An included package of the Open Invention Network is a package for which |
| 43 | Open Invention Network licensees cross-license their patents. No patent |
| 44 | license is granted, either expressly or impliedly, by designation as an |
| 45 | included package. Should you wish to participate in the Open Invention |
| 46 | Network licensing program, please visit www.openinventionnetwork.com |
| 47 | <http://www.openinventionnetwork.com>. */ |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 48 | |
| 49 | #ifndef LIB_SYSTEM_H |
| 50 | #define LIB_SYSTEM_H 1 |
| 51 | |
| 52 | #include <stddef.h> |
| 53 | #include <stdint.h> |
| 54 | |
| 55 | extern void *xmalloc (size_t) __attribute__ ((__malloc__)); |
| 56 | extern void *xcalloc (size_t, size_t) __attribute__ ((__malloc__)); |
| 57 | extern void *xrealloc (void *, size_t) __attribute__ ((__malloc__)); |
| 58 | |
| 59 | extern char *xstrdup (const char *) __attribute__ ((__malloc__)); |
| 60 | extern char *xstrndup (const char *, size_t) __attribute__ ((__malloc__)); |
| 61 | |
| 62 | |
| 63 | extern uint32_t crc32 (uint32_t crc, unsigned char *buf, size_t len); |
| 64 | extern int crc32_file (int fd, uint32_t *resp); |
| 65 | |
| 66 | /* A special gettext function we use if the strings are too short. */ |
| 67 | #define sgettext(Str) \ |
| 68 | ({ const char *__res = strrchr (gettext (Str), '|'); \ |
| 69 | __res ? __res + 1 : Str; }) |
| 70 | |
| 71 | #define gettext_noop(Str) Str |
| 72 | |
Ulrich Drepper | fbe998a | 2005-08-29 16:27:10 +0000 | [diff] [blame] | 73 | |
| 74 | #define pwrite_retry(fd, buf, len, off) \ |
| 75 | TEMP_FAILURE_RETRY (pwrite (fd, buf, len, off)) |
| 76 | #define write_retry(fd, buf, n) \ |
| 77 | TEMP_FAILURE_RETRY (write (fd, buf, n)) |
| 78 | #define pread_retry(fd, buf, len, off) \ |
| 79 | TEMP_FAILURE_RETRY (pread (fd, buf, len, off)) |
| 80 | |
Ulrich Drepper | fdc93e1 | 2009-01-17 11:47:10 -0800 | [diff] [blame] | 81 | |
| 82 | /* We need define two variables, argp_program_version_hook and |
| 83 | argp_program_bug_address, in all programs. argp.h declares these |
| 84 | variables as non-const (which is correct in general). But we can |
| 85 | do better, it is not going to change. So we want to move them into |
| 86 | the .rodata section. Define macros to do the trick. */ |
| 87 | #define ARGP_PROGRAM_VERSION_HOOK_DEF \ |
| 88 | void (*const apvh) (FILE *, struct argp_state *) \ |
| 89 | __asm ("argp_program_version_hook") |
| 90 | #define ARGP_PROGRAM_BUG_ADDRESS_DEF \ |
| 91 | const char *const apba__ __asm ("argp_program_bug_address") |
| 92 | |
Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame] | 93 | #endif /* system.h */ |