sysmacros.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Definitions of macros to access `dev_t' values.
  2. Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Library General Public License as
  6. published by the Free Software Foundation; either version 2 of the
  7. License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Library General Public License for more details.
  12. You should have received a copy of the GNU Library General Public
  13. License along with the GNU C Library; see the file COPYING.LIB. If not,
  14. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA. */
  16. #ifndef _SYS_SYSMACROS_H
  17. #define _SYS_SYSMACROS_H 1
  18. /* For compatibility we provide alternative names.
  19. The problem here is that compilers other than GCC probably don't
  20. have the `long long' type and so `dev_t' is actually an array. */
  21. #if defined __GNUC__ && __GNUC__ >= 2
  22. # define major(dev) ((int)(((dev) >> 8) & 0xff))
  23. # define minor(dev) ((int)((dev) & 0xff))
  24. # define makedev(major, minor) ((((unsigned int) (major)) << 8) \
  25. | ((unsigned int) (minor)))
  26. #else
  27. /* We need to know the word order here. This assumes that the word order
  28. is consistent with the byte order. */
  29. # include <endian.h>
  30. # if __BYTE_ORDER == __BIG_ENDIAN
  31. # define major(dev) (((dev).__val[1] >> 8) & 0xff)
  32. # define minor(dev) ((dev).__val[1] & 0xff)
  33. # define makedev(major, minor) { 0, ((((unsigned int) (major)) << 8) \
  34. | ((unsigned int) (minor))) }
  35. # else
  36. # define major(dev) (((dev).__val[0] >> 8) & 0xff)
  37. # define minor(dev) ((dev).__val[0] & 0xff)
  38. # define makedev(major, minor) { ((((unsigned int) (major)) << 8) \
  39. | ((unsigned int) (minor))), 0 }
  40. # endif
  41. #endif
  42. #endif /* sys/sysmacros.h */