Update.
[glibc.git] / sysdeps / unix / sysv / linux / sys / sysmacros.h
blobca1e0d40dc1caf9685eee1986af4c87140e113d8
1 /* Definitions of macros to access `dev_t' values.
2 Copyright (C) 1996, 1997, 1999, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #ifndef _SYS_SYSMACROS_H
21 #define _SYS_SYSMACROS_H 1
23 #include <features.h>
25 /* If the compiler does not know long long it is out of luck. We are
26 not going to hack weird hacks to support the dev_t representation
27 they need. */
28 #ifdef __GLIBC_HAVE_LONG_LONG
29 extern unsigned int inline major (unsigned long long int __dev) __THROW;
30 extern unsigned int inline minor (unsigned long long int __dev) __THROW;
31 extern unsigned long long int inline makedev (unsigned int __major,
32 unsigned int __minor) __THROW;
34 # if defined __GNUC__ && __GNUC__ >= 2
35 extern inline unsigned int
36 major (unsigned long long int __dev)
38 return ((__dev >> 8) & 0xfff) | ((unsigned int) (__dev >> 32) & ~0xfff);
41 extern inline unsigned int
42 minor (unsigned long long int __dev)
44 return (__dev & 0xff) | ((unsigned int) (__dev >> 12) & ~0xff);
47 extern inline unsigned long long int
48 makedev (unsigned int __major, unsigned int __minor)
50 return ((__minor & 0xff) | ((__major & 0xfff) << 8)
51 | (((unsigned long long int) (__minor & ~0xff)) << 12)
52 | (((unsigned long long int) (__major & ~0xfff)) << 32));
54 # endif
57 /* Historically the three symbols were macros. In case some programs
58 use #ifdef to check for definition provide some dummy macros. */
59 # define major(dev) major (dev)
60 # define minor(dev) minor (dev)
61 # define makedev(maj, min) makedev (maj, min)
62 #endif
64 #endif /* sys/sysmacros.h */