common.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* common.h - Common functions
  2. Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. On Debian systems, the complete text of the GNU General Public License
  14. can be found in /usr/share/common-licenses/GPL-3 file.
  15. */
  16. #include <asm/types.h>
  17. #ifndef _COMMON_H
  18. #define _COMMON_H
  19. void die(char *msg, ...) __attribute((noreturn));
  20. /* Displays a prinf-style message and terminates the program. */
  21. void pdie(char *msg, ...) __attribute((noreturn));
  22. /* Like die, but appends an error message according to the state of errno. */
  23. void *alloc(int size);
  24. /* mallocs SIZE bytes and returns a pointer to the data. Terminates the program
  25. if malloc fails. */
  26. void *qalloc(void **root, int size);
  27. /* Like alloc, but registers the data area in a list described by ROOT. */
  28. void qfree(void **root);
  29. /* Deallocates all qalloc'ed data areas described by ROOT. */
  30. int min(int a, int b);
  31. /* Returns the smaller integer value of a and b. */
  32. char get_key(char *valid, char *prompt);
  33. /* Displays PROMPT and waits for user input. Only characters in VALID are
  34. accepted. Terminates the program on EOF. Returns the character. */
  35. #endif