# This was initially taken from the IWYU repository:
# github.com/include-what-you-use/include-what-you-use/blob/164b8fe7597805ae55f029ecf6580dc46a74c7ed/gcc.libc.imp
# It has useful mappings that are normally enabled by default, but there are
# other default mappings that conflict with our builds. The best solution seems
# to be to disable all defaults, import the defaults from the IWYU
# repo and modify the rules that conflict with our build.
#
# TODO(dundargoc): Check if there is a way to disable specific builtin maps as
# to avoid this file entirely.

# Mappings for GNU libc
# ( cd /usr/include && grep '^ *# *include' {sys/,net/,}* | perl -nle 'm/^([^:]+).*<([^>]+)>/ && print qq@    { include: [ "<$2>", private, "<$1>", public ] },@' | grep bits/ | sort )
# When I saw more than one mapping for these, I typically picked
# what I thought was the "best" one.
[
  { include: [ "<bits/a.out.h>", private, "<a.out.h>", public ] },
  { include: [ "<bits/auxv.h>", private, "<sys/auxv.h>", public ] },
  { include: [ "<bits/byteswap.h>", private, "<byteswap.h>", public ] },
  { include: [ "<bits/cmathcalls.h>", private, "<complex.h>", public ] },
  { include: [ "<bits/confname.h>", private, "<unistd.h>", private ] },
  { include: [ "<bits/dirent.h>", private, "<dirent.h>", public ] },
  { include: [ "<bits/dlfcn.h>", private, "<dlfcn.h>", public ] },
  { include: [ "<bits/elfclass.h>", private, "<link.h>", public ] },
  { include: [ "<bits/endian.h>", private, "<endian.h>", public ] },
  { include: [ "<bits/environments.h>", private, "<unistd.h>", private ] },
  { include: [ "<bits/epoll.h>", private, "<sys/epoll.h>", public ] },
  { include: [ "<bits/errno.h>", private, "<errno.h>", public ] },
  { include: [ "<bits/error.h>", private, "<error.h>", public ] },
  { include: [ "<bits/eventfd.h>", private, "<sys/eventfd.h>", public ] },
  { include: [ "<bits/fcntl.h>", private, "<fcntl.h>", public ] },
  { include: [ "<bits/fcntl2.h>", private, "<fcntl.h>", public ] },
  { include: [ "<bits/fenv.h>", private, "<fenv.h>", public ] },
  { include: [ "<bits/fenvinline.h>", private, "<fenv.h>", public ] },
  { include: [ "<bits/huge_val.h>", private, "<math.h>", public ] },
  { include: [ "<bits/huge_valf.h>", private, "<math.h>", public ] },
  { include: [ "<bits/huge_vall.h>", private, "<math.h>", public ] },
  { include: [ "<bits/hwcap.h>", private, "<sys/auxv.h>", public ] },
  { include: [ "<bits/inf.h>", private, "<math.h>", public ] },
  { include: [ "<bits/inotify.h>", private, "<sys/inotify.h>", public ] },
  { include: [ "<bits/ioctl-types.h>", private, "<sys/ioctl.h>", public ] },
  { include: [ "<bits/ioctls.h>", private, "<sys/ioctl.h>", public ] },
  { include: [ "<bits/ipc.h>", private, "<sys/ipc.h>", public ] },
  { include: [ "<bits/ipctypes.h>", private, "<sys/ipc.h>", public ] },
  { include: [ "<bits/libio-ldbl.h>", private, "<libio.h>", public ] },
  { include: [ "<bits/link.h>", private, "<link.h>", public ] },
  { include: [ "<bits/locale.h>", private, "<locale.h>", public ] },
  { include: [ "<bits/math-finite.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mathcalls.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mathdef.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mathinline.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mman.h>", private, "<sys/mman.h>", public ] },
  { include: [ "<bits/mman-shared.h>", private, "<sys/mman.h>", public ] },
  { include: [ "<bits/monetary-ldbl.h>", private, "<monetary.h>", public ] },
  { include: [ "<bits/mqueue.h>", private, "<mqueue.h>", public ] },
  { include: [ "<bits/mqueue2.h>", private, "<mqueue.h>", public ] },
  { include: [ "<bits/msq.h>", private, "<sys/msg.h>", public ] },
  { include: [ "<bits/nan.h>", private, "<math.h>", public ] },
  { include: [ "<bits/netdb.h>", private, "<netdb.h>", private ] },
  { include: [ "<bits/param.h>", private, "<sys/param.h>", public ] },
  { include: [ "<bits/poll.h>", private, "<sys/poll.h>", private ] },
  { include: [ "<bits/poll2.h>", private, "<sys/poll.h>", private ] },
  { include: [ "<bits/posix1_lim.h>", private, "<limits.h>", public ] },
  { include: [ "<bits/posix2_lim.h>", private, "<limits.h>", public ] },
  { include: [ "<bits/posix_opt.h>", private, "<unistd.h>", private ] },
  { include: [ "<bits/printf-ldbl.h>", private, "<printf.h>", public ] },
  { include: [ "<bits/pthreadtypes.h>", private, "<pthread.h>", private ] },
  { include: [ "<bits/resource.h>", private, "<sys/resource.h>", public ] },
  { include: [ "<bits/sched.h>", private, "<sched.h>", public ] },
  { include: [ "<bits/select.h>", private, "<sys/select.h>", public ] },
  { include: [ "<bits/select2.h>", private, "<sys/select.h>", public ] },
  { include: [ "<bits/sem.h>", private, "<sys/sem.h>", public ] },
  { include: [ "<bits/semaphore.h>", private, "<semaphore.h>", public ] },
  { include: [ "<bits/setjmp.h>", private, "<setjmp.h>", public ] },
  { include: [ "<bits/setjmp2.h>", private, "<setjmp.h>", public ] },
  { include: [ "<bits/shm.h>", private, "<sys/shm.h>", public ] },
  { include: [ "<bits/sigaction.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/sigcontext.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/siginfo.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/signum.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/sigset.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/sigstack.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/sigthread.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/sockaddr.h>", private, "<sys/un.h>", public ] },
  { include: [ "<bits/socket.h>", private, "<sys/socket.h>", private ] },
  { include: [ "<bits/socket2.h>", private, "<sys/socket.h>", private ] },
  { include: [ "<bits/socket_type.h>", private, "<sys/socket.h>", private ] },
  { include: [ "<bits/stab.def>", private, "<stab.h>", public ] },
  { include: [ "<bits/stat.h>", private, "<sys/stat.h>", public ] },
  { include: [ "<bits/statfs.h>", private, "<sys/statfs.h>", public ] },
  { include: [ "<bits/statvfs.h>", private, "<sys/statvfs.h>", public ] },
  { include: [ "<bits/stdio-ldbl.h>", private, "<stdio.h>", public ] },
  { include: [ "<bits/stdio-lock.h>", private, "<libio.h>", public ] },
  { include: [ "<bits/stdio.h>", private, "<stdio.h>", public ] },
  { include: [ "<bits/stdio2.h>", private, "<stdio.h>", public ] },
  { include: [ "<bits/stdio_lim.h>", private, "<stdio.h>", public ] },
  { include: [ "<bits/stdlib-bsearch.h>", private, "<stdlib.h>", public ] },
  { include: [ "<bits/stdlib-float.h>", private, "<stdlib.h>", public ] },
  { include: [ "<bits/stdlib-ldbl.h>", private, "<stdlib.h>", public ] },
  { include: [ "<bits/stdlib.h>", private, "<stdlib.h>", public ] },
  { include: [ "<bits/string.h>", private, "<string.h>", public ] },
  { include: [ "<bits/string2.h>", private, "<string.h>", public ] },
  { include: [ "<bits/string3.h>", private, "<string.h>", public ] },
  { include: [ "<bits/stropts.h>", private, "<stropts.h>", public ] },
  { include: [ "<bits/struct_stat.h>", private, "<sys/stat.h>", public ] },
  { include: [ "<bits/struct_stat.h>", private, "<ftw.h>", public ] },
  { include: [ "<bits/sys_errlist.h>", private, "<stdio.h>", public ] },
  { include: [ "<bits/syscall.h>", private, "<sys/syscall.h>", public ] },
  { include: [ "<bits/sysctl.h>", private, "<sys/sysctl.h>", public ] },
  { include: [ "<bits/syslog-ldbl.h>", private, "<sys/syslog.h>", private ] },
  { include: [ "<bits/syslog-path.h>", private, "<sys/syslog.h>", private ] },
  { include: [ "<bits/syslog.h>", private, "<sys/syslog.h>", private ] },
  { include: [ "<bits/termios.h>", private, "<termios.h>", private ] },
  { include: [ "<bits/termios-c_lflag.h>", private, "<termios.h>", private ] },
  { include: [ "<bits/termios-struct.h>", private, "<termios.h>", private ] },
  { include: [ "<bits/termios-tcflow.h>", private, "<termios.h>", private ] },
  { include: [ "<bits/time.h>", private, "<time.h>", public ] },
  { include: [ "<bits/time.h>", private, "<sys/time.h>", public ] },
  { include: [ "<bits/timerfd.h>", private, "<sys/timerfd.h>", public ] },
  { include: [ "<bits/timex.h>", private, "<sys/timex.h>", public ] },
  { include: [ "<bits/types.h>", private, "<sys/types.h>", public ] },
  { include: [ "<bits/types/siginfo_t.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/types/siginfo_t.h>", private, "<sys/wait.h>", public ] },
  { include: [ "<bits/uio.h>", private, "<sys/uio.h>", public ] },
  { include: [ "<bits/unistd.h>", private, "<unistd.h>", private ] },
  { include: [ "<bits/ustat.h>", private, "<sys/ustat.h>", private ] },
  { include: [ "<bits/utmp.h>", private, "<utmp.h>", public ] },
  { include: [ "<bits/utmpx.h>", private, "<utmpx.h>", public ] },
  { include: [ "<bits/utsname.h>", private, "<sys/utsname.h>", public ] },
  { include: [ "<bits/waitflags.h>", private, "<sys/wait.h>", public ] },
  { include: [ "<bits/waitstatus.h>", private, "<sys/wait.h>", public ] },
  { include: [ "<bits/wchar-ldbl.h>", private, "<wchar.h>", public ] },
  { include: [ "<bits/wchar.h>", private, "<wchar.h>", public ] },
  { include: [ "<bits/wchar2.h>", private, "<wchar.h>", public ] },
  { include: [ "<bits/wordsize.h>", private, "<limits.h>", public ] },
  { include: [ "<bits/xopen_lim.h>", private, "<limits.h>", public ] },
  { include: [ "<bits/xtitypes.h>", private, "<stropts.h>", public ] },
  # Sometimes libc tells you what mapping to do via an '#error':
  # # error "Never use <bits/dlfcn.h> directly; include <dlfcn.h> instead."
  # or
  # # error "Never include <bits/socket_type.h> directly; use <sys/socket.h> instead."
  # ( cd /usr/include && grep -R '^ *# *error "Never use\|include' * | perl -nle 'm/<([^>]+).*directly.*<([^>]+)/ && print qq@    { include: [ "<$1>", private, "<$2>", public ] },@' | sort )
  { include: [ "<bits/a.out.h>", private, "<a.out.h>", public ] },
  { include: [ "<bits/byteswap-16.h>", private, "<byteswap.h>", public ] },
  { include: [ "<bits/byteswap.h>", private, "<byteswap.h>", public ] },
  { include: [ "<bits/cmathcalls.h>", private, "<complex.h>", public ] },
  { include: [ "<bits/confname.h>", private, "<unistd.h>", private ] },
  { include: [ "<bits/dirent.h>", private, "<dirent.h>", public ] },
  { include: [ "<bits/dlfcn.h>", private, "<dlfcn.h>", public ] },
  { include: [ "<bits/elfclass.h>", private, "<link.h>", public ] },
  { include: [ "<bits/endian.h>", private, "<endian.h>", public ] },
  { include: [ "<bits/epoll.h>", private, "<sys/epoll.h>", public ] },
  { include: [ "<bits/eventfd.h>", private, "<sys/eventfd.h>", public ] },
  { include: [ "<bits/fcntl-linux.h>", private, "<fcntl.h>", public ] },
  { include: [ "<bits/fcntl.h>", private, "<fcntl.h>", public ] },
  { include: [ "<bits/fenv.h>", private, "<fenv.h>", public ] },
  { include: [ "<bits/huge_val.h>", private, "<math.h>", public ] },
  { include: [ "<bits/huge_valf.h>", private, "<math.h>", public ] },
  { include: [ "<bits/huge_vall.h>", private, "<math.h>", public ] },
  { include: [ "<bits/in.h>", private, "<netinet/in.h>", private ] },
  { include: [ "<bits/inf.h>", private, "<math.h>", public ] },
  { include: [ "<bits/inotify.h>", private, "<sys/inotify.h>", public ] },
  { include: [ "<bits/ioctl-types.h>", private, "<sys/ioctl.h>", public ] },
  { include: [ "<bits/ioctls.h>", private, "<sys/ioctl.h>", public ] },
  { include: [ "<bits/ipc.h>", private, "<sys/ipc.h>", public ] },
  { include: [ "<bits/ipctypes.h>", private, "<sys/ipc.h>", public ] },
  { include: [ "<bits/locale.h>", private, "<locale.h>", public ] },
  { include: [ "<bits/math-finite.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mathdef.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mathinline.h>", private, "<math.h>", public ] },
  { include: [ "<bits/mman-linux.h>", private, "<sys/mman.h>", public ] },
  { include: [ "<bits/mman.h>", private, "<sys/mman.h>", public ] },
  { include: [ "<bits/mqueue.h>", private, "<mqueue.h>", public ] },
  { include: [ "<bits/msq.h>", private, "<sys/msg.h>", public ] },
  { include: [ "<bits/nan.h>", private, "<math.h>", public ] },
  { include: [ "<bits/param.h>", private, "<sys/param.h>", public ] },
  { include: [ "<bits/poll.h>", private, "<sys/poll.h>", private ] },
  { include: [ "<bits/predefs.h>", private, "<features.h>", public ] },
  { include: [ "<bits/resource.h>", private, "<sys/resource.h>", public ] },
  { include: [ "<bits/select.h>", private, "<sys/select.h>", public ] },
  { include: [ "<bits/semaphore.h>", private, "<semaphore.h>", public ] },
  { include: [ "<bits/sigcontext.h>", private, "<signal.h>", public ] },
  { include: [ "<bits/signalfd.h>", private, "<sys/signalfd.h>", public ] },
  { include: [ "<bits/stdlib-float.h>", private, "<stdlib.h>", public ] },
  { include: [ "<bits/string.h>", private, "<string.h>", public ] },
  { include: [ "<bits/string2.h>", private, "<string.h>", public ] },
  { include: [ "<bits/string3.h>", private, "<string.h>", public ] },
  { include: [ "<bits/timerfd.h>", private, "<sys/timerfd.h>", public ] },
  { include: [ "<bits/typesizes.h>", private, "<sys/types.h>", public ] },
  # Top-level #includes that just forward to another file:
  # $ for i in /usr/include/*; do [ -f $i ] } && [ `wc -l < $i` = 1 ] } && echo $i; done
  # (poll.h, syscall.h, syslog.h, ustat.h, wait.h).
  # For each file, I looked at the list of canonical header files --
  # http://www.opengroup.org/onlinepubs/9699919799/idx/head.html --
  # to decide which of the two files is canonical.  If neither is
  # on the POSIX.1 1998 list, I just choose the top-level one.
  { include: [ "<sys/poll.h>", private, "<poll.h>", public ] },
  { include: [ "<sys/syslog.h>", private, "<syslog.h>", public ] },
  { include: [ "<sys/ustat.h>", private, "<ustat.h>", public ] },
  { include: [ "<wait.h>", private, "<sys/wait.h>", public ] },
  # These are all files in bits/ that delegate to asm/ and linux/ to
  # do all (or lots) of the work.  Note these are private->private.
  # $ for i in /usr/include/bits/*; do for dir in asm linux; do grep -H -e $dir/`basename $i` $i; done; done
  { include: [ "<linux/errno.h>", private, "<bits/errno.h>", private ] },
  { include: [ "<asm/ioctls.h>", private, "<bits/ioctls.h>", private ] },
  { include: [ "<asm/socket.h>", private, "<bits/socket.h>", private ] },
  { include: [ "<linux/socket.h>", private, "<bits/socket.h>", private ] },
  # Some asm files have 32- and 64-bit variants:
  # $ ls /usr/include/asm/*_{32,64}.h
  { include: [ "<asm/posix_types_32.h>", private, "<asm/posix_types.h>", public ] },
  { include: [ "<asm/posix_types_64.h>", private, "<asm/posix_types.h>", public ] },
  { include: [ "<asm/unistd_32.h>", private, "<asm/unistd.h>", private ] },
  { include: [ "<asm/unistd_64.h>", private, "<asm/unistd.h>", private ] },
  # I don't know what grep would have found these.  I found them
  # via user report.
  { include: [ "<asm/errno.h>", private, "<errno.h>", public ] },
  { include: [ "<asm/errno-base.h>", private, "<errno.h>", public ] },
  { include: [ "<asm/ptrace-abi.h>", private, "<asm/ptrace.h>", public ] },
  { include: [ "<asm/unistd.h>", private, "<sys/syscall.h>", public ] },
  { include: [ "<linux/limits.h>", private, "<limits.h>", public ] },   # PATH_MAX
  { include: [ "<linux/prctl.h>", private, "<sys/prctl.h>", public ] },
  { include: [ "<sys/ucontext.h>", private, "<ucontext.h>", public ] },
  # Exports guaranteed by the C standard
  { include: [ "<stdint.h>", public, "<inttypes.h>", public ] },
]

# vim: set ft=toml:
