dietlibc-0.33~cvs20120325/.cvsignore010064400000000000000000000004131173363226000136770ustar00t elftrunc mapfile t1 load compile bin-alpha bin-arm bin-i386 bin-mips bin-ppc bin-sparc bin-mipsel bin-parisc bin-s390 bin-sparc64 pic-alpha pic-arm pic-i386 pic-mips pic-ppc pic-sparc pic-mipsel pic-parisc pic-s390 pic-sparc64 bin-ia64 bin-x86_64 pic-x86_64 cycles dietlibc-0.33~cvs20120325/AUTHOR010064400000000000000000000001601173363226000126230ustar00Felix von Leitner Please see the file THANKS for additional authors and contributors. dietlibc-0.33~cvs20120325/BUGS010064400000000000000000000006011173363226000123610ustar00Please report bugs to felix-dietlibc@fefe.de or to the mailing list at dietlibc@fefe.de You need to be subscribed to be able to post to the mailing list. If you want to report a bug, but do not want to be named or need any detail to stay confidential, please email me directly and make sure you mention this. My PGP key is available as http://www.fefe.de/felix@fefe.de.asc dietlibc-0.33~cvs20120325/CAVEAT010064400000000000000000000001601173363226000125640ustar00 Beware! Much of this code is untested! Someday, we will have a test suite and everything will be just fine. dietlibc-0.33~cvs20120325/CHANGES010064400000000000000000002002551173363226000127000ustar000.33: first stab at getting TLS to work in actual threads use fs: to find current thread on x86_64 add fallocate, posix_fallocate work around Ubuntu who added -fstack-protector to their gcc, which added stack protector code to the function from the dietlibc startup code that sets up the registers and segments used by the stack protector mechanism. fix sys/personality.h (Mathias Krause) update sys/ptrace.h (Nikola Vladov) fix fork+pthread closing fd 0 (Tim München) finally add stdout tty detection and turn off linewise buffering if !tty enlarge dev_t to 32-bit on i386, arm, sparc, s390 (Pascal Terjan) update sys/stat.h to include nsec and enlarge dev_t add WANT_VALGRIND_SUPPORT in dietfeatures.h. When #defined, the startup code will check if the program is running under valgrind, and if it is, the SIMD optimized string routines will switch back to a slower version that does not generate valgrind false positives. add WANT_LLMNR in dietfeatures.h. Now you can do "ping windowsbox" and it works if that box runs win7 and trusts the LAN; the down side is that LLMNR does not like the .local prefix, so DNS does zeroconf lookup for unqualified names now, too. add WANT_GNU_STARTUP_BLOAT in dietfeatures.h to support program_invocation_short_name and program_invocation_name add INT*_MIN, INT*_MAX, UINT*_MAX, etc to stdint.h remove const from stdsignal prototype to agree with standard only count %[] conversions in *scanf if they matched at least one char (Indan Zupancic) make sure __sc_nr_cpus does not dump core if /proc/cpuinfo is larger than 2048 bytes (Bela Lubkin) use vsyscall for time on x86_64 instead of wrapping gettimeofday (Nikola Vladov) CPU affinity support (Indan Zupancic) lots of ARM fixes (Enrico Scholz) make sure strftime does not write more than max bytes when writing \0 (Tobias S. Josefowitz) change gettimeofday vsyscall to use the vdso add WANT_HOSTS_GIVEUP_EARLY in dietfeatures.h various build fixes, add sys/atomic.h and the __CAS function redo nice with get/setpriority as glibc does (Thierry Vignaud) add fdopendir add openat and friends srand(0) made rand() return a series of 0 instead of random data (https://banu.com/blog/42/openbsd-bug-in-the-random-function/) 0.32: add mbsinit, mbrlen, mbtowc, wctomb, mbrtowc, wcrtomb, wcwidth add btowc, wctype, iswctype add some wide char routines add statvfs, fstatvfs add some amd64 asm string routines add some constants for inotify several fixes from Enrico Scholz (printf, string routines on big endian) add some more syscalls some minor cleanups shrink some string functions (Kris Katterjohn) prepare x86_64 for syscall numbers > 255 fix unaligned memcpy if WANT_SMALL_STRING_ROUTINES is not defined (Enrico Scholz) fix utmp, add utmpx support (R.L. Horn) fix the dynamic library for the ARM architecture (Gernot Tenchio) get ARM port to work with EABI (Tristan Newby) fix of scanf with negative floats (Andre Oliveira) use vsyscall to do time(2) on x86-64 implement back references in basic regexes make regex faster (coalesce n CHAR matches to one STRING match) stdio speedup use randomness passed in ELF auxvec instead of /dev/urandom in startup (strace looks cleaner now) use ELF auxvec to implement getpagesize support thread local storage (w00t!!!!) don't crash in getaddrinfo if hints is NULL (Gernot Tenchio) add -D_REENTRANT for -pthread in diet don't segfault in setlocale if locale is NULL (Nikola Vladov) implement _SC_PHYS_PAGES in sysconf() add some gcc attributes and restrict keywords to string.h 0.31: getopt_long and getopt_long_only now refuse ambiguous abbreviations fix printf %u/%x on 64-bit platforms fix fd leak in if_nameindex (Florian Westphal) fix printf %g (well, get closer) fix sparc64 longjmp (Rene Rebe) add dn_skipname add pthread prototypes that are needed to compile libgcc when compiling a cross compiler gcc fix ftw64 fixes for some corner cases from Ilja van Sprundel: - tempnam - strsignal - strftime - sunrpc code faster qsort support %j in printf (Gernot Tenchio) do omit the frame pointer on x86_64 fix pthread_cond_timedwait (Gernot Tenchio) fix getcwd, ftw, ftw64, dirname (Ilja van Sprundel) Some fd leaks in error conditions. fix stackguard to be .quad instead of .long (cause subtle memory corruption, which in most cases caused DNS lookups to fail on 64-bit platforms) fix dynamic build do the magic required for -fstack-protector in gcc 4.1.1 to actually work (which includes setting up thread local storage), so far on i386 and amd64 add ctime_r (for c-icap, Gernot Tenchio) fix strptime return value (Gernot Tenchio) fix R_386_32, R_ARM_ABS32, R_X86_64_64 in libdl (Gernot Tenchio) Olaf: Added DT_GNU_HASH symbol resolver. fix security bug in librpc. You know, librpc, that stinking Sun code full of problems? Just adding that code was a bad mistake, I think. I tried auditing it, but I nearly got a brain tumor when I opened those files. Thanks to Ilja van Sprundel for finding this bug (with Google codesearch, no less! :-) ) accept mDNS packets with set recursion desired bit add const to cfgetispeed and cfgetospeed arguments fix off-by-one in getdelim (reported by Ilja van Sprundel) prevent integer overflows in printf (return -1, like Solaris) fix putenv (Nikola Vladov) use time_t in struct stat for the time values support LLMNR in dnsd (no idea if it works, apparently only Vista supports it) fix ftell (Jens Laas) fix getaddrinfo (return more than just the first IP) (Gernot Tenchio) make sure to declare __dietlibc__ during compilation of the lib itself, so we can have more portable code in the libc code behind #ifndef __dietlibc__ (see ftw64 for an example) fix off-by-one in iconv add missing brackets in dn_skipname strptime also fills in tm_wday and tm_yday (Gernot Tenchio) x86-64 getpriority has bias 20 (Rene Rebe) fix typo in fstatfs64 (Gernot Tenchio) fix infinite loop in getaddrinfo (Nikola Vladov) don't include sys/stat.h in stdio.h and unistd.h (Gernot Tenchio) work around gcc optimizing away our int overflow check in printf some work on printf fix some compiler warnings support long device major and minor add WANT_FREE_OVERWRITE in dietfeatures.h (see comment there) 0.30: put exception handling frames in read-only section on AMD64 and S/390 make sys/stat.h ILP64 compatible (both Markus Oberhumer) whoops, strptime was completely broken, and noone noticed :-) fix DNS resolver to only use shorter timeout for .local queries remove throw() statements for functions taking function pointer arguments (qsort, besearch, ftw) fix embarassing bug in pclose (Juergen Sawinski, Ren? Rebe) when asking for an IPv6 address and there is an IPv4 address in /etc/hosts but not an IPv6 address, return NO_DATA without querying DNS. This is how glibc does it, and it means you can use e.g. elinks to browse http://localhost/ without being connected to the internet / a DNS server. make libcrypt/crypt.c to work when compiled with gcc 4 provide toascii and ustat (Reynir Stefansson) change size of struct sigaction.sa_flags from long to int on alpha. beginnings of wide char string routines fix regex match bug ("@(a|b)" would also match "x@z") ARM big-endian support (Paul Clifford) support %s in strftime, so date in embutils does :-) fix two strptime bugs (Gernot Tenchio) add strnlen and clearenv (for udev) #define IOV_MAX in limits.h behind _XOPEN_SOURCE (for opennntpd) tzfile fix (Nikola Vladov) lots of fixes from Markus FX Oberhumer: * better signal handling error detection * setjmp.S on i386 * getenv on i386 * sys/stat.h -malign-double fix * update fcntl.h for MIPS to 2.6.13 version * jmp_buf is 40*8 instead of 58*8 on ppc64. * This patch fixes the section of the TOC entries on ppc64 * libstdc++ updates for gcc 4 * remove cstddef and cwchar (no longer needed) * int -> ssize_t for read and write * sigjmp.c: __mask_was_saved was not set in all cases! * another round of ILP64 cleanups add ngettext, dngettext (for glib) add strdupa and strndupa (for directfb) add extended attribute, thread, and misc syscalls Olaf: fixed my libdl code to run with gcc-4.0.x support optstring starting with '-' extension in getopt_long (Jens L??s) make sure ftw returns in the directory it was called from Olaf: fixing a bug in timegm (an off by ONE array access)... tzfile fix for recent gcc make resolv.conf more glibcish so openssh 4.3p1 compiles add linux/* glue to make openssh compile with tun/tap support fix putenv (Ren? Rebe, Thomas Ogrisegg) limit search/domain entries in /etc/resolv.conf (Gernot Tenchio) fix unlockpt (Gernot Tenchio) Olaf: fixing putenv for the situation that environ is NULL (situation after a clearenv) HP-PA fixes (Micah Anderson, Herbert Poetzl) syscall() for ppc/64 make __kernel_size_t more like the real thing (Rene Rebe) fix __exec_shell (execv and execvp) (Gernot Tenchio) fix mmap and provide mmap64 on S/390 (Bastian Blank) fix telldir, seekdir (Gernot Tenchio) also add -lc after -lgcc for gcc 4.1 on arm (Enrico Scholz) update SSP (ProPolice) support (with help from Eduardo Tongson) fix buffer underflow in strncpy if n==0 and WANT_FULL_POSIX_COMPAT is defined (it's normally not) (Ilja van Sprundel) reading from stdin used to flush stdout. Now it only does that if stdin is a tty. sparc64 fixes for ioctls, includes and sigaction (Rene Rebe) 0.29: oops, fix LD_RUN_PATH unsetting (Enrico Scholz) Markus Oberhumer sent the following diffs: dl_iterate_phdr for libgcc_eh proper endian.h recognition for __s390x__ rem and sdiv for sparc fix stupid dns decoding bug (Gernot Tenchio) #ifdef powerpc -> #ifdef __powerpc__ (Enrico Scholz) struct siginfo was wrong for 64-bit platforms Lots of fixes and patches from Markus Oberhumer. libstdc++ compatibility ilp64 compatibility make diet libc compile with -Werror on 13 platforms provide time() using gettimeofday for s390x remove waitpid warnings on ia64, s390/x provide C++ exception handling support ppc64 now compiles again typo in libcompat/syscall.S for WANT_THREAD_SAFE (Bj?rn D?bel) syscall.h update for all architectures remove two ppc64 warnings fix s/390 syscalls > 255 add "diet -L gcc" option to print the lib path remove new gcc4 signedness warnings add link.h (probably only useful to compile an ia64 cross-gcc) understand -m32 on x86_64 as meaning i386 now that gcc 4 is out, finally switch -malign-functions to -falign-functions in diet MADV_* for hppa and ia64 (Enrico Scholz) add _PATH_TMP to paths.h support syscall on sparc and x86_64 (Herbert Poetzl) change alignment code in gethostbyname_r (Herbert Poetzl) avoid bus errors in DNS code implement gettimeofday vsyscall for x86_64 replace unfinished plug&play DNS hack with zeroconf, rename dietfeatures.h option to WANT_PLUGPLAY_DNS. A small dns daemon can be found in contrib/dnsd.c hack ugly non-thread-safe kludge to communicate proper scope_id to getaddrinfo fix bug regarding regular expressions like "(a|)b" work around gcc 4 bug make sure diet always leaves -V in front of the gcc command line sparc64 fixes (Martin) fix warnings in socketcall functions 0.28: add tcgetsid (Yuri Kozlov) add _udivdi3, _divdi3, _umoddi3, _moddi3 for MIPS These are in libgcc, but libgcc is compiled PIC and we compile the diet libc non-pic, and that is not compatible on MIPS so ld complains. setlocale now accepts setting the locale to "C". several fixes from Gwenole Beauchesne, AMD64 and otherwise. fix memory leak in regfree (thanks, Valgrind!). add support for gcc ProPolice and stack gap (see README.security). add ftw64 (yuck!) #include in syscalls.s/environ.S to make sure environ is actually large enough (Enrico Scholz) add waitpid wrapper around wait4 for arm-linux (Avinash Bhatia) make res_mkquery reject invalid domains (label>64, name>255) (Nikola Vladov) make res_query return TRY_AGAIN instead of NO_DATA if no answer was received (Nikola Vladov) fix PT_READ_U in sys/trace.h (John K. Hohm) Olaf: added mmap64 wrapper (arm,mips,sparc,...) work around new kernel rt signal semantics (need to set restorer function) Olaf: - libdl + gcc 3.4 resulted in a SIGSEGV because local names were dynamically resolved.... - Also fixed a bug in the symbol resolver - fixing the mmap64 stuff & arm/dyn_syscalls had no mmap2 (Gerrit Pape) tzfile parser fix (John K. Hohm) ppc64 fixes (Gwenole Beauchesne) add sigisemptyset, sigandset and sigorset (John K. Hohm) minor additions to make gdb 6.3 happy (John K. Hohm) ld.so support for gdb (John K. Hohm) implement nice(2) via setpriority() if there is no nice syscall support libm.so (John K. Hohm) hack rpc/xdr.h to work with gcc 4 (Andreas Jochens via Gerrit Pape) make dyn didn't work for !WANT_FULL_RESOLV_CONF (Sampo Kellomaki) #undef __i686 in i386/PIC.h (George Sawinski) fix timegm bug (found by Nikola Vladov) add sys/swap.h (George Sawinski) Olaf: dynamic x86_64 support (libdl relocator and dyn_syscalls) 0.27: change DNS routines to look for ip6.arpa instead of ip6.int WANT_FREAD_OPTIMIZATION was broken on sockets (Johannes Stezenbach) Olaf: - added fix for getgrouplist (Nikola Vladov) - fix the fd leak on error path (Denis Vlasenko) - the regparm attribute in typedefinition generats error with gcc-2.95 on non-x86 arch... (reported: Johannes Stezenbach) PowerPC build fix (Gerrit Pape) Olaf: added missing settimeofday add netinet/ether.h and netinet/if_ether.h add linux/fd.h add pivot_root, delete_module and init_module prototypes to unistd.h (protected by _LINUX_SOURCE) add some BSD legacy declarations to dirent.h (Bryan Henderson) add strtoull and strtoll as aliases to strtoull and strtoll use _FILE_OFFSET_BITS consistently (Indan Zupancic) add support for $DIETHOME in diet, to override the compiled-in path (George) 0.26: iconv UTF-8 fix (Kuba Winnicki) Olaf: - add 'getgrouplist' - fix type of 'unsetenv' - add missing realtime syscalls 'clock_*' 'timer_*' and types ARGH! gcc 3.4 breaks regparm attributes on i386! grep portability fixes (Gunnar Ritter) add empty libcrypt.a to help compile code from others (Gunnar Ritter) add make uninstall fix pread64, pwrite64 Olaf: MIPS has a special case for the pread/pwrite syscall ... Use -isystem instead of -I for our system includes (Paul Jarc) Add MNT_DETACH to sys/mount.h add pselect fix for tzfile (Felix J. Ogris) add res_close to close the DNS UDP sockets remove ia64/waitpid.S; it was broken and there is a working C version (Gerrit Pape) 0.25: fix sprintf head -1 -> head -n 1 handle negative precision and -0 (Jens L??s) susv3 renamed IFNAMSIZ to IF_NAMESIZE make diet accept "gcc-3.3.2" and "diet -v -Os gcc" (Yuri Kozlov) make libcompat syscall position independent (Peter S. Mazinger) fix missing pthread stdio external (Gernot Tenchio) Port parts of glibc test suite (Florian Westphal) Now we need more manpower to fix the bugs it uncovers ;-) add linux/if_ether.h and net/ethernet.h for sniffers faster string routines and a small fix for alloc (Thomas Ogrisegg) remove C++ comments from header files add ftrylockfile C99 fixes and a new printf test from Enrico Scholz epoll_event needs to be packed on x86_64 (pointed out by Indan Zupancic) work around make dependency problem breaking mipsel by creating kludge mipsel/syscalls.h (Samium Gromoff) Fix i386 unified syscall -EMEDIUMTYPE handling (Juergen Sawinski via Clifford Wolf) vsnprintf: fix output when output does not fit (Enrico Scholz) new dirname with test suite entry (Yuri Kozlov) fnmatch: add [:charclass:], fix negation (Michael J. Pomraning) make calloc a weak symbol (Martin Pohlack) make NULL C++ friendly (Martin Pohlack) new realpath (Thomas Ogrisegg) fix stupid glibcism in sys/epoll.h add pause for Alpha (Kurt Garloff) ptrace fix (Dallachiesa Michele) ptread.h cleanups (Martin Pohlack) fix execvp and execlp (Youn?s) fix time() for sparc64 0.24: work around incompatible Linux select() modifying the timeout in librpc (Patch was sent from Mike Waychison from Sun) the overflow checking in strtou?ll? was broken in some cases. Unfortunately, correct overflow checking enlarged the routine by 20%. (reported by Manuel Novoa III) two stdio bug fixes (also reported by Manuel Novoa III) remove several warnings (Johannes Stezenbach) Olaf: fixing tmpfile (missing parameter) and __dtostr (gcc 2.95) Olaf: add the pthread-semaphore support. implemented experimental plug-and-play IPv6 DNS (see dietfeatures.h, see http://www.fefe.de/ipv6pnpdns.html) typo in parisc setjmp.S (Michael Mueller) Olaf: fixing the pthread_join function add IPv6 link-local%eth0 support to getaddrinfo Olaf: added missing syscalls (cap{g,s}et) and addmntent Add s390x and ppc64 support (Marian Jancar, SuSE) Marian also contributed %m support to printf, and fixes for many bugs Olaf: - fixing strtok_r (rewrite) - making the %m support NON DEFAULT as it is NOT SUSv3 or SUSv2 - make the HUGE_VAL/HUGE_VALF macros arch (endian) independend - changeing __dtostr so that it returns "inf" for an inf-value not "nan" - fixing the strrchr bug (reported by Gernot Tenchio) - fixing the strtoul/strtoull bug (reported by Gernot Tenchio) - adding the patch to printf (Gernot Tenchio) - fixing snprintf (Gernot Tenchio) - fixing memccpy,memcmp,strncmp (reported by Gernot Tenchio) - fixing strtoXXX (Gernot Tenchio, patch modified) - fixing the *scanf return behavior (reported by Enrico Scholz) add printf test change sys_siglist to char** (removes linker warning) fix getnameinfo (Arnaldo Carvalho de Melo) add ar.h (for GNU make) replace qsort with new quicksort with three-way partitioning parisc start.S fix (Gerrit Pape) check fflush return code (Manuel Novoa III) add el-cheapo strptime and more BSD legacy crap to get more of e2fsutils, dump and util-linux compiled 0.23: update sys/soundcard.h various x86_64 fixes (Gwenole Beauchesne) fix assert for 64-bit platforms (Gwenole Beauchesne) remove many warning from test suite (Gwenole Beauchesne) hopefully fix resolver (again, Gwenole) fix floorl typo (Norbert Wolff) add more BSD brokenness to time.h forward poll.h to sys/poll.h make DNS socket close-on-exec (Felix J. Ogris) add cuserid to libcompat (Andreas Krennmair) add ctermid and ftok to libcompat (those are _really_ ugly) copy some RPC bugfix cruft from glibc warning: I don't use rpc or xdr, I don't actually understand or have a way to test this. Maybe I should remove this cruft from the diet libc...? make declaration of writev and readv match susv3 add finite (Andreas Krennmair) move flock+constants to unistd.h (the Linux man page is wrong on this) fix assert (Andreas Krennmair) add modf, libm fixes (Andreas Krennmair) rename __pure__ to __pure (Laurent Bercot) utmp x86_64 biarch support (Gwenole Beauchesne) add fgetpwent (Alvaro Gomes Sobral Barcellos) add vsyscall support for linux 2.5 on recent CPUs add a few new 2.5 syscalls, adapt to renamed epoll syscalls Olaf: fixing the vsyscall support so that the binaries still work on 2.4 remove getline macro, caused problems with GNU sed make assert equal (void)0 under -DNDEBUG (Enrico Scholz) make __attribute_malloc__ #define safe (Matthias Andree) add BSD utimes to libcompat (Andreas Krennmair) remove gcc 3 #ifdef kludgery from include/string.h; it works with gcc 3.2.2+, don't know if it's gcc or us (Gerrit Pape) remove _null_auth declaration in librpc/rpc_prot.c (Thayne Harbaugh) fix regex bug with ^$ not matching "" (Anthony de Boer) Olaf: removing "/mmap.*" where no arch-specific impementation is needed. (added "syscalls.s/mmap.S") - fixing the vsyscall in the dynamic library... (self made problem) - removing warning in "res_query.c" - changing type of stream-mutex to recursive - sparc/sparc64: shrink of the unified syscall and the special syscalls (fork/pipe) to use the "unified_syscall_error_handler" add sendfile64 backwards compatibility glue add __attribute_dontuse__ to declare a few functions as deprecated use above to flag a few BSDisms ;-) include in errno.h, fixes __attribute_dontuse__ breakage endmntent now returns 1 (Florian Westphal) strtoul return value fixes (Jan Bobrowski) Olaf: fixing the diet wrapper for sparc and changing the options for mips a few i386/*.S fixes (Hynek Schlawack) remove =0 for static variables (Thomas Ogrisegg) fix strtoul (broke getaddrinfo and ssh) fix segfault in parser Olaf: checkin of the new libpthread implementation & added confstr Make gethostbyname2 case insensitive (Thomas Ogrisegg) RPC 64-bit cleanliness fixes (Gwenole Beauchesne) sysctl fix (Thomas Ogrisegg) make header files C++ compliant (__BEGIN_DECLS and __END_DECLS) remove more warnings (Yuri Kozlov) use expect() in a few strategic places try to add sigcontext and ucontext for x86_64 add ffs, ffsl, ffsll Olaf: fixing the error string list and sparc bug (Gerrit Pape) first throw, then attributes (Andreas Jabs) unbuffered fputc was broken on big endian (big oops, thanks Gerrit Pape) fix parisc struct stat (Gerrit Pape) add vasprintf (for elinks) fnmatch used [^e] instead of [!e] for negation (Heiko Berges) add sparc and parisc assembly routines (Thomas Ogrisegg) add swab (Johannes Stezenbach) make a{4} match exactly and not at least 4 times a (Ingo Oeser) Olaf: fixed a libdl ref-counter bug (Thomas Walpuski) All hail to the busybox chiefs! Instead of reporting bugs they find, they put a #error in their source code. Is Erik seeing the diet libc as uClibc competition that needs to be squashed even with unfair methods? People, if you find bugs, tell us! Fixed fputc and freopen (found in busybox comments) 0.22: fix i386 libm fix netinet/ip_icmp.h (Rui Prior) make strings.h susv3 compliant (Gunnar Ritter) remove stdio dependence in abort fix truncate64, ftruncate64 (Luc Van Oostenryck and Yuri Kozlov) fix and improve erand48() (Luc Van Oostenryck) fix realpath for non-existant directories (Gergely Nagy and Gerrit Pape) fix DNS timeout and IPv6 socket reuse strtoul now accepts "-1" as well (Thomas Ogrisegg) add i386 strcasecmp and __ltostr (Thomas Ogrisegg) add killpg prototype (Luc Van Oostenryck) remove some compiler warnings (Luc Van Oostenryck) better rand() from Knuth's TAOCP (Luc Van Oostenryck) fix unified x86_64 unified syscall 64-bit return value issue (Gwenole) the getdents64 emulation was broken and repairing it opened a can of worms. So I ripped it out. I also changed the readdir64 emulation to work if there is no getdents64. fix ia64 start.S (Thanks to Volker Birk for an account on his ia64 box) many ia64 fixes (waitpid, nice, fork, vfork, time, utime ...) More fixes from Gwenole (printf %p only printed the last 32 bits, I botched the getdents64 #ifdefs, we violated the x86_64 ABI) change signal() to do as glibc does remove a few more warnings add new 2.5 syscall #defines add epoll_create, epoll_ctl and epoll_wait the new x86 syscall numbers exceed 255, breaking our %al optimization I worked around it with conditional assembly in cpp macros. Ugh. more MIPS fixes (the stoned MIPS ABI for restartable syscalls expects the instruction before the syscall to be a load immediate) fix fread() from a pipe (oops, tried to lseek) #define _POSIX_VDISABLE in termios.h (Laurent Bercot) two *printf fixes (Gernot Tenchio) add nan and +-inf handling in __dtostr add _SC_NGROUPS_MAX support to sysconf (Felix J. Ogris) make assert() use expect(), slight optimization add i386 vfork (Thomas Ogrisegg) fix SA_NODEFER on sparc (Gerrit Pape, Thomas Bader) fix sin, cos and __dtostr (Gernot Tenchio) add /dev/epoll ioctl constants to sys/ioctl.h add linux/eventpoll.h for /dev/epoll fix lseek64 on 64-bit architectures Olaf: fix x86_64 start-code (we have reg-args) fixing some broken macros in sparc32-code (.udiv,.urem) adding strndup (GNU Extension) fix glob strncpy (R.L. Horn) fix regfree (Uwe Ohse) fix puts in full stdio mode (would omit \n) fix wrong types on powerpc, broke *stat (Gerrit Pape) allow more than 64k in i386 memchr (Karsten Scheibler) make strftime work it WANT_TZFILE_PARSER is not set (Gwenole Beauchesne) build parisc on parisc64, change libgcc link order on sparc (Gerrit Pape) 0.21: use gcc's size_t, ptrdiff_t and wchar_t types (Olaf) use -G 8 on MIPS to reduce code size (Johannes Stezenbach) add munlock (Jens L??s) argh, atexit fell victim to bit rot (or maybe Olaf) add WANT_INET_ADDR_DNS to make gethostbyname not look up IP numbers but use them to fill in the struct hostent directly. signal is now a correct signal (Olaf) read optimizer cflags for diet -Os gcc from ~/.diet/gcc, overriding the built-in defaults. add file "SECURITY". I will document design tradeoffs that have security implications there. fixed regex LINEEND condition add .size directive to i386 syscalls shove a few more bytes off the i386 socket calls setjmp, longjmp and clone for x86_64 are now implemented but not tested (Olaf) fix sparc signals 0.20: calloc was botched umount and stime for x86_64 (Gwenole Beauchesne) some malloc fixes for very big numbers (Enrico Scholz, me) x86_64 unified syscall did not preserve rbx violating ABI (Gwenole) realpath fix if path did not contain a slash (Gwenole) add ucontext add asm/statfs.h to work around people using 0.19: current gcc cvs makes __thread a keyword (Eric Troan) be more strict regarding hostile DNS packets (me) fix ia64 compile problems (Gerrit Pape) make killpg a function and not a macro (broke bash 2.05b) fix ia64 start code and unified syscall (me) add sparc/strlen.S from Thomas Ogrisegg add more space to ARM __jmp_buf in setjmp.h (Andre) fix libcompat/syscall.S (did't compile on arm) add integer overflow fix in xdr_array after bugtraq advisory (me) fix x86_64 socket calls and mmap (and some more) (Gwenole Beauchesne) add calloc integer overflow fix after RUS-CERT advisory (me) add fread and fwrite integer overflow fix (me) 0.18: add stpcpy (from Thomas Ogrisegg) check in mktime fix (from Luc Van Oostenryck) add libm2.s from contrib to i386 (oops, how long has it been sitting there?) add truncate64 and ftruncate64 and prototype for truncate (only had ftruncate) Michal Ludvig (SuSE) ported the diet libc to the x86_64 architecture (the upcoming AMD Hammer chips!). You can't even buy the chips yet and the diet libc already supports it! Amazing ;-) Michal's patch also fixed several of the outstanding warnings. Thanks! Andre sent a patch to add ARM profiling. He says it does not work yet, but it's a start. added getdents64 backwards compatibility and include it in large file support #defines perror now checks if the message is NULL like glibc (Thomas Ogrisegg) ftell did not take ungetc into account (Kevin Ryde through Debian). Thomas Ogrisegg sent a port to IA64! sigaddset, sigdelset and setismember segfaulted for signal 0 (Gunnar Ritter) Enrico Scholz reported several bugs in the header files. change __malloc__ to __attribute_malloc__ add pa-risc socketcall (but see TODO) (Felix J. Ogris) fix *rand48 initialization (Kevin Ryde) fnmatch infinite loop fix (Piotr Esden-Tempski) make signal() into a sigaction wrapper function add memrchr (Emil) remove __attribute__((const)) from getpid() (Yuri Kozlov) make getserv* also work if proto is NULL (Jens L??s) now clone on parisc works (Thomas Ogrisegg) getopt* fix from Thomas Walpuski add syscall() to libcompat (Thomas Ogrisegg) fix strncpy and strrchr i386 assembly versions for dynamic linking (John K. Hohm) allow short option grouping in getopt* (Ralf Wildenhues) make the DNS resolver IPv6 transport capable (WANT_IPV6_DNS) mention -v in diet.1 (Bryan Henderson) auto-detect gcc 3 on i386 and remove compiler option warnings putenv tweak (Thomas Ogrisegg) add missing socket syscalls for PA-RISC and IA64 (Thomas Ogrisegg) add cpio.h and tar.h (Thomas Ogrisegg) change opendir/readdir/closedir from malloc to mmap (Thomas Ogrisegg) cleanups from Florian LaRoche 0.17: fix several bugs in getservent_r Gunnar Ritter reported the following: moved tcgetpgrp and tcsetpgrp to unistd.h adjusted lstat->lstat64 #define to make it work with function pointers move __dietlibc__ #define from features.h to diet Thomas Ogrisegg sent x86 memccpy and strncpy routines and introduced an dietfeatures.h #define WANT_FULL_POSIX_COMPAT Thomas also sent me profiling support (so far only on x86, but profiling/PORTING describes what needs to be done for other architectures)! add contrib/dprof.c, also from Thomas. Andreas Krennmair sent a patch to add the BSD regex interface to libcompat Andre noticed that __dtostr never sets first to false. Oops! Andre has provided a largely untested patch that seems to fix the problem. Igor Gilitschenski sent a patch for the "%8.7lx" issue. abort did not flush all stdio streams fix some nasty regular expression bugs write a stupid malloc checker (contrib/debug-realloc.c) to help me debug my regular expressions. Please read contrib/debug-realloc.txt our i386 memchr,memcmp were broken for the count=0 case fix DNS domain search i386 memccpy exchanged esi and edi :-( I should do more checks before accepting external code... 0.16: "diet -v" or "diet -Os" segfaulted without further arguments. Andre found two very embarassing bugs in my four lines of md5 glue. I need to get more sleep. Thanks Ogrisegg found that ptrace does not work as documented and provided a wrapper that emulates the glibc behaviour. Dirk Engling saved 8 bytes and 4 cycles in the ARM clone() fix ptrace.h for S/390 and ARM provide a PORTING document so we don't lose track of which file need to be touched to port the diet libc to a new platform. remove a few warnings provide a prototype for usleep. make __dtostr work on ARM by using long instead of long long. Idea by Dirk Engling. fix an argument counting bug in *scanf (Thomas Ogrisegg) Forgot an #endif in asm/sigcontext.h (Mike Castle) Kurt Garloff sent in patches to fix struct termios on non-x86 architectures printf("%+05d\n",500) was broken (Raimar Falke told me, Olaf fixed it) create libcompat.a (and move daemon to it) add getdelim and getline *printf now recognize 'z' integer flag (and ignore it) Dirk Engling provided a strcpy.S for ARM. Olaf: fixed *scanf familie. It hadn't wored with "long long". Hans Lermen fixed i386/getenv.S diet -Os no longer discards -fpic and -fno-pic fix i386 rand/random to use correct RAND_MAX (thanks, Jaroslav Macodiseas) sys/ipc.h now includes sys/types.h Olaf: started to make the sparc64 port scandir should not sort if compar() is NULL (reported by Andrea Marrosu) 0.15: vfork sucks. I reverted to the old behavior where vfork==fork. fix bsearch (and remove i386 assembly bsearch, needs to be redone). Thanks Ogrisegg sent a patch to make the PA-RISC unified syscall thread-safe! remove vfork and add alarm to dynamic syscalls. fix diet-dyn to link in dyn_dstop.o and not dyn_stop.o. The MD5 code generated unaligned accesses when passed an unaligned pointer on little endian ARM and MIPS. MIPS unified syscall didn't compile anymore. Put up new mipsel target to cross compile for little endian mips. The mips target will again explicitly set endianness to big endian. Compiling natively on a MIPS box should not touch the endianness. Duh, when we removed return0, we broke tzset when the time zone parser was disabled. Uwe Ohse noticed this. Thanks! Fix gethostbyname to match host names case insensitively in /etc/hosts. Oops, this was reported 6 weeks ago but I overlooked the email. Thanks, Denis Rachal! vsnprintf's zero termination was broken. Uwe Ohse found a few more bugs: Remove WANT_BUGGY_GLIBC_STRSEP. The Linux man page is broken, glibc does it correctly. Make inet_aton use strtoul instead of strtol fdopen would close the file descriptor if it could not malloc the buffer. strftime updates. Make _FILE_OFFSET_BITS includes -Wundef clean Andre found a typo in endian.h for big endian mips Ryan told me that fmod was not included in libm. Oops. strstr(whatever,"") returned NULL, not whatever. Found by a new test suite entry for strstr that I wrote. Thomas Ogrisegg suggested or sent patches for the following: add for profiling support. make strncpy a #define in string.h to save a few bytes. an i386 assembler getenv implementation (roughly half the size) add grantpt, ptsname, unlockpt add a getenv test suite entry. Andre contributed an ARM assembler md5 implementation and he fixed mmap on ARM. add glibc macro names in sys/reboot.h. Mentioned by Laurent G. Bercot getservent_r did not parse lines without aliases. Thanks, Jaroslav Macodiseas! fix MIPS start code (argv[0] was always corrupt) removed annoying -Wconversion gcc switch add -v to diet.c and fix MIPS CFLAGS in diet. Thanks, Johannes Stezenbach Kurt Garloff sent these diffs: add fdatasync (and make it a pthread cancellation point) numerous alpha issues, like using .quad instead of .long for offsets, change strip to -strip in Makefile (so a failing strip does not abort the make), try to be more friendly to the gcc 2.96 that SuSE 7.1 AXP ships with. 0.14: fix brk again (missing __brk, trivial oversight) a new i386/atol.S that is 4 bytes smaller (and faster, too!). Thanks, Thomas Ogrisegg! Thomas also contributed a PA-RISC port including testandset, so libpthread will work once we implement clone! Great work, Thomas. made the fake locale more believable. If you need gettext, use http://www.ca.postgresql.org/~petere/gettext.html moved _exit into the unified syscall on x86. Uwe Ohse found many more bugs: getpass EINTR handling, ttyname, sysconf_cpus with SLASH_PROC_OK, liblatin1 was more or less completely broken if you gave it chars as arguments, not ints (signedness). execvp had a buffer overflow in case a PATH element exceeded PATH_MAX, but it's not a security problem since setuid programs need to set their path to some known value anyway. hasmntopt did not work with foo=bar style options Uwe also improved ftw's stack usage. Put movl instead of popl rationale in comment in i386/unified.S since three people have suggested saving a few bytes with popl now ;) I discovered __attribute__((malloc)) and started using it. For gcc 3, it improves the optimizer when functions return malloced pointers. Steven Rostedt pointed out that my setvbuf was broken with regard to size==0 and sent a patch to fix it. Thomas Ogrisegg made setenv smaller. Olaf: implemented the parisc clone and an atomic testandset, modified the libpthread to respect the parisc UPgrowing stack. still non functional, because the unified syscall uses errno :( tcgetospeed read from the wrong termios field. Thanks, Gunnar Ritter! Fixed asprintf (relied on vsnprintf(NULL,...) to return length but don't write anything which was no longer the case. It also allocated one byte unnecessarily, which Uwe Ohse found. Fix ttyname (readlink does not \0-terminate, forgot to do that). 0.13: add readdir64 and automatic mapping if _FILE_OFFSET_BITS == 64 make diet not include the linker safeguard stuff when preprocessing Olaf: port to S/390! fix vfork (it was put into dietlibc.a twice) res_query did not initialize last diet (not diet-dyn, of course) now adds -static to the gcc command line fixed fflush on input streams (tic from ncurses exposed this) duh, there is an alarm system call, too, so we use it and not setitimer fix comparison in gmtime_r that caused Jan 1 to be converted to Dec 32. rewrote __dtostr (it also has one more argument now) Thanks to Erik Troan for bringing these to my attention: make putenv behave like glibc (putenv("HOME") == unsetenv("HOME")) fix strncat for the case where n == 0 (security implications?) fix bsearch (it didn't find the very last element in the array, same bug in both the C and the i386 assembly version). fixed FNM_PATHNAME in fnmatch fix brk (the syscall was documented incorrectly in the Linux man page) Thanks, Thomas Ogrisegg! added negated character classes to fnmatch (not required by POSIX) make the utmp routines open utmp read-only if read-write doesn't work. remove syscalls.c directory, it is obsolete now with unified syscalls 0.12: more contributions from Frank Klemm. iconv can now do UCS-2, too. Imported several x86 assembly routines from Wouter van Kleunen. Lots of bug fixes, and several more i386 specific versions of common routines to make them smaller. add memmem (a GNU extension that looks useful) several changes from Michal Ludvig: inttypes.h gets C99 macros, add pivot_root syscall, %n for *scanf. add adjtimex (thanks, Laurent BERCOT) add Frank Klemm's optimized md5 add -Os option to diet (see diet.1). several IPv6 constants and HZ were missing, thanks Johannes Kloos. add 32-bit uid/gid syscalls. add rand48 (thanks, Johannes Kloos) fixed a lot of bugs in getopt* (thanks, Johannes) add strxfrm and tweak limits.h. glib-1.3.8 now compiles without changes. add a few more module syscalls. modutils-2.4.9 now compiles without changes. fix gethostent alias list termination. Major oops. add execle and two DNS constants (from Johannes Kloos). opendir did not close-on-exec (thanks, Laurent Bercot). DNS will now properly signal errors and set h_errno. A few more cleanups (thanks, Andreas Jabs and Matthias Andree). Added an uber-cool linker safeguard feature! Idea by Matthias Andree. If you enable WANT_SAFEGUARD in dietfeatures.h, diet will include an external reference to a symbol that is only in the diet libc. So, when you accidentally link a diet libc compiled object file against glibc, the linker will barf. This will bloat your object files, but you can remove all the references with "strip -R .note" from the binaries in the end (which you should do anyway). fix ARM unified syscall (select did not work). add getpwent_r ala glibc and replace getpwent do the same for getgrent and getspent remove entlib (new code is smaller) rewrite getserv* to use parselib (and provide ..._r, too) add getpwnam_r and getpwuid_r rewrite getproto* to use parselib (and protive ..._r, too) Olaf muddled with the dynamic linker. It's a clean-room implementation in the sense that it once worked for Olaf in a clean room ;) add if_nameindex and if_freenameindex. fixed arm unified syscalls to work with current binutils (; is no longer a line separator but starts a comment, switched to .macro) changed all st_[cma]time types to signed long so comparisons against LONG_MIN will work correctly. (GNU tar does this) fixed two bugs regarding ungetc. add getusershell, setusershell, endusershell (for vs_ftpd) add prctl, dirfd (also for vs_ftpd) fixed strftime (was completely hosed) added real make install target 0.11: fix major oops in DNS routines (only with WANT_FULL_RESOLV_CONF enabled). fix vsscanf bug (Thanks, David Chappell). add floor, ceil and memchr prototypes. add __builtin_expect and expect #defines for gcc versions below 3.0 cleaner errno vs __errno_location handling add placeholder iconv (iconv_open will always return EINVAL) try to remove kernel 2.4 header dependency in IPv6 sockaddr_in6 initialization of getaddrinfo. fix vsnprintf %X (printed lower case) I wrote a new getopt. It appears to actually work (it is POSIX compliant, it does not sort argv like the GNU version) and is only a little over 300 bytes on x86. Guillaume Cottenceau just wrote me that strncat should be even more broken than it already is: it should append n bytes AND THEN \0! I wonder how many programmers have produced off-by-one errors here... Fix regexec offset return. autoconf now believes that diet libc has POSIX regular expressions. Fix fnmatch (a/b/* matched a/b/c/d even if FNM_PATHNAME was set) Fix regular expression match for x* when there is no x at all. Fix memory leak in error case in gethostbyname(2|). Thanks, Dietz Pr?pper. Add %h to vsnprintf. Add FAQ. Make %h work for signed numbers and add %hh to vsnprintf. initgroups ignored the group argument :-( remove printf references and nested functions from glob. added an errno in libpthread that will display a prominent linker warning. started getting rid of kernel headers. Big task! :-( add res_mkquery. The diet libc can now compile and link mtr. Olaf: added a lot of code in libdl (not yet complete), changed the startup code to make it work with his libdl and ld.so (needs still work too) __dns_readstartfiles only took the first domain or search path. Thanks, Anthony de Boer Olaf: added clone and a new unified_syscall for PowerPC also dynlinker is now available (i386 only at this time) crufted together a stdarg.h implementation from the various gcc headers. implement getopt_long (ugh, the GNU people need professional help) fixed word delimiters in regex (they looked for space, i.e. "," did not work as delimiter) errno.h now declares sys_errlist and sys_nerr. added mkdtemp. Uwe Ohse reported all of the following bugs: ttyname should return 0 if !isatty. realpath returns NULL if "." cannot be opened putenv erroneously accepted (and mishandled) entries without "=". popen returned 255 instead of 127 if /bin/sh could not be run. fgetc did not set the internal EOF indicator on EOF. bsearch contained an assumption about integer arithmetic overflow behavior. system did not set SIGCHLD and thus contained a race. popen did not set close-on-exec and could leak an fd on malloc error. daemon did not check whether open returns an fd below 3 perror did not save errno. Olaf: Peter Jones reported some problems with perror; strerror had the same problem. Peter also posted a patch to atexit/exit. With some modifications it is now implemented. Unbuffered stdio and ungetc can no longer be disabled. I will try to implement part of it using ELF weak symbols. Added minimal sysconf (tehe) from David Chappell. Added overflow handling for strtoul and strtol. Added WANT_ETC_HOSTS in dietfeatures.h and made gethostbyname/2 use it before falling back to DNS if enabled. Added a littie backwards compatibility cruft for gpm (man, do these sources stink!) Added openpty. Squeeze a few bytes off the is* routines, courtesy of Peter Jones. Fix fseek return value. Add dirname and basename. Add a few i386 math routines contributed by Frank Klemm. Fixed getservent (did not allow _ and - in the aliases). Thanks, Oden Eriksson Added a float.h so configure believes we have ANSI header files. Fix a lot more stdio bugs that Uwe Ohse pointed out. Olaf: has added a new scanf and printf core that is suitable for all scanf and printf function implementations Imported a few more functions and optimizations from Frank Klemm (he also rewrote dtostr to have more precision) Olaf: checked in a new sig* function family (based on rt_sig*). legacy <2.2 signal-handling doesn't work at the moment. Made rudimentary iconv that can convert back and forth between iso-8859-1, utf-8 and ucs-4 (for debugging). Thanks to Markus Kuhn for the excellent utf-8(7)! 0.10: update getpagesize. add personality. add "%*s" and "%*.*s" support to vsnprintf. add putchar (apparently arm-linux-gcc will substitute printf("\n") with putchar('\n') behind your back...?! import include/scsi/ from glibc. add iopl. add execl and sigdelset prototypes. add getopt_long stuff to getopt.h (may compile but won't link). add RPC headers (no code yet). add mlockall, munlockall make "diet gcc foo.c" work. added Sun RPC code and removed as many warnings as possible in a heroic act of self-mutilation. added getproto* and getdtablesize for the RPC cruft :-( added getpass. mount from util-linux actually compiles now! fix the sig*set routines. mount actually works now *bg* fix fwrite dividing by zero when trying to fwrite n records of size 0. added an initial regex implementation (3500 bytes!!!). add llseek and lseek64 with optional lseek fall-back. add res_init. add asprintf (ugh, what an ugly function). expanded arpa/nameser.h to include backwards compatibility defines add ut_name alias to ut_host in struct utmp. add inet_ntop, inet_pton, gethostbyname2. add sysinfo, recvmsg, sendmsg. add endmntent, getmntent, setmntent. fix fnmatch (thanks, Guillaume Cottenceau!) add setenv. remove __restrict from mntent.h, add __restrict__ removal alias for older gcc versions in sys/cdefs.h. add rlim_t, sig_atomic_t declarations. add sigsetjmp #define for __sigsetjmp (oops). (Thanks to Chris Siebenmann for these three bug reports) add a gruesome hack to printf floating point to accept %f and kludge together support for %.2f. Don't look at the code, please! fixed tcsetpgrp (oops, this is embarassing! Thanks, Chris Siebenmann) imported fix for entlib by Jeff Garzik. add glob implementation from Guillaume Cottenceau (Thanks!!) add libdl fragments from Olaf (Yeah! One step closer to dynamic linking!) add REG_ICASE and word start/end handling to my regular expressions. my regular expressions now actually match substrings (i.e. "foobar" to "bar"). wrap getcwd to comply to man page (the syscall returns the number of bytes, not the buffer) add realpath. fix vfprintf. fix *scanf %s zero termination. add abs, labs, llabs. add , ioperm syscall. add flock to fixes to bsearch and the regular expressions. add fake herror. add scandir and alphasort. add killpg implemented a gross hack to make libpthread compile when dietfeatures.h does not define WANT_THREAD_SAFE (it's empty then). add getaddrinfo and freeaddrinfo (man, what a fucked up interface!) fix sigsuspend (syscall had completely fscked up arguments!) RLIM_INFINITY from the kernel is broken. Thanks to Chris Siebenmann for sending a patch. add getserv*. add WANT_FULL_RESOLV_CONF so that the DNS routines use "domain" and "search" from resolv.conf. 0.9: fixed initgroups (oops) Cleanup appending file open for stdio (thanks, James Antill) imported vfprintf fix from James Antill. add fnmatch change index, rindex and bcmp as weak ELF symbols (were #defined before) Olaf added character classes to *scanf. Put object and library files into a separate directory (bin-$ARCH). Add "cross" make target to make all architectures. Add "diet" program and man page. Add getgrnam, getgrgid Add cfmakeraw (Thanks, Antonio Musumeci) localtime won't call gettimeofday when the tzfile parser is used. 0.8: vsnprintf(0,...) estimated the length of strings with a padding width incorrectly. new reboot() from Olaf. added prototypes for getsockopt and setsockopt. added experimental sem* and shm* define EXIT_SUCCESS and EXIT_FAILURE added setvbuf (only changes mode, not buffer) added dietwarning.h (woohoo, linker warnings!) and used it to warn of insecurity (system, sprintf) or bloat (printf and stdio). added qsort() and bsearch(). Benchmark on 1000 random ints: glibc: 679414 cycles qsort and 3352 cycles bsearch diet libc: 300010 cycles qsort, 553 cycles bsearch I have no idea why glibc is so slow. added __isnan (references by libm.a from glibc). added popen() and pclose(). Now the diet libc can link slsh (from S-Lang!) corrected usleep. It was more of an msleep until now. corrected __dtostr (it looped when trying to format "0.0"). several fixes to stdio (thanks to S-Lang's excellent test suite!) added ungetc (does it work?) added inet_aton (yuck!) added gethostbyname, gethostbyaddr, gethostbyname_r and gethostbyaddr_r added h_errno and __h_errno_location added inet_ntoa added setpgrp and getpgrp, strsignal and execv (thanks, Olaf) add bcopy, index, rindex macros add isgraph and isxdigit add strftime (ugh!!!) Olaf fixed strftime, gmtime_r leap year bug. Jeff Garzik contributed a spec file. I put it in contrib and hope everbody knows what to do with it... Olaf checked in a ton of libpthread stuff. added mkstemp using /dev/urandom (harder to guess than getpid()). add large file backwards compatibility support (so gzip will run on kernel 2.2 and 2.0) added shutdown added nice added pseudo-locale support for is* (they are now weak aliases, isupper -> __isupper_ascii etc). So, for example, liblatin1 can overwrite the default is* functions. added liblatin1.a added tzfile implementation (does it work for anyone else?) added syslog(3) (thanks to Rene M?ller!) Jeff Garzik contributed getgr*, getpw* and getsp* in one tiny package. Thanks! merged duplicate code in execv and execvp into exec_lib.o 0.7.2: added several prototypes to already implemented functions and . Thanks for Abraham for pointing this out. added prototypes for process group and dup syscalls. Thanks to Abraham again. He also contributed an implementation for daemon(), an ugly BSD hack. I decided to diversify the lib/ directory a little and now created a libugly/ directory for stuff like system() and daemon() ;-) added libstdio and moved all that stdio crap from lib/ there. The idea is to start separating now what we will separate for shared libraries anyway. optimized x86 unified-syscall by Olaf. added limits.h, removed __ARCHBITS from endian.h (use __WORDSIZE from limits.h instead) added remove.c and enough cruft to limits.h to make it compile lzo, lzop and bzip2. added mktime, asctime_r, asctime and ctime (needed for gzip). Someone will need to implement a reader for the glibc localtime file format some day (man tzfile, ugh!) :-( added unlink prototype to unistd.h. added gmtime and gmtime_r. fixed sparc unified syscall error handling (please upgrade!). removed readdir glibc compatibility cruft. removed stat glibc compatibility cruft. oops, my fread was broken for pipes. Olaf found a bug in pipe() for sparc, too. 0.7.1: optimized away the static arrays from __ltostr and __lltostr. optimized away the static arrays (and more!) from strtoul and strtoull. added system (by Olaf). added tolower and toupper added getopt from Olaf (~600 bytes on x86!) added clone for mips (by Olaf). fixed longjmp and setjmp on sparc not to require glibc include files. added pause for all (by Olaf). added __attribute__ ((__const__)) to ctype.h added isupper and islower. added putc and putchar as macros. added strcasecmp and strncasecmp (thanks to Abraham vd Merwe for insightful discussions and patches I partially used for the last three) added getpriority and setpriority (also by Abraham) oops, I broke strtoul in a recent optimization attempt. oi, setjmp and longjmp were broken on other platforms, too! Thanks to S?bastien C?t? for reporting this. 0.7: clone support for i386,alpha,arm and sparc by Olaf. Initial dynamic loading glue for i386, also by Olaf. We don't have a dynamic loader yet, so this is not yet usable. added readv, sigdelset, sigaltstack, sigfillset, sigismember, usleep, vsprintf, writev, all by Olaf. imported readdir fix from Guillaume. Mhh, can the kernel interface really be this broken? Found a kludgy way to detect whether the kernel includes define struct stat64 (they also define STAT64_HAS_BROKEN_ST_INO). If this does not work for you, please tell me! Removed bogus __seek_types enum, it's a bunch of #defines now. Fixed stdio line buffering. The code was already there but I forgot to mark stdio and stdout as line buffered. This should really be done dynamically using isatty, though. Removed superfluous "if (1)" in execvp.c 0.6.14: *scanf did not append the 0 byte for %s. added creat and changed creat to call open directly instead of open64. did for fread what 0.6.10 did for fwrite. repaired buffered stdio a little (line buffering is still not supported). [All of these bugs have been reported by Guillaume. Thanks!] added __pure__ to strchr and strrchr in 0.6.13: included COPYING to make clear that the diet libc is covered by the GNU General Public License (and _not_ the LGPL). That means that you need to obtain a license from me if you want to use the diet libc in a proprietary program that you want to distribute. The x86 unified syscall swapped arguments #4 and #5 and noone noticed until now! Thanks to Guillaume Cottenceau for reporting this! The malloc had a subtle bug with small allocations that could cause segfault. Guillaume reported it, Olaf fixed it. 0.6.12: added assert, statfs and fstatfs added include/net/if.h so fget compiles again. 0.6.11: added putenv. 0.6.10: fixed fwrite. It returned the number of bytes written, not the number of records. Thanks to Albert D. Cahalan for pointing this out. fixed fgets. It returned EOF on empty lines. Thanks, Erik Frey. added brk and sbrk. harold@nb.com.sg made me do it. 0.6.9: fixed execvp not to return on ENOENT did for {open|read|close|seek|tell}dir what I did for stat before. The glibc compatibility part is currently non-functional. fixed white space handling in sscanf " (" would not match " (". fixed printf to accept 'l' flag. fixed getpwuid (ignored last line) 0.6.8: Olaf contributed initial thread-safe syscalls for i386, alpha, sparc, mips and arm. I did the one for ppc. They can be enabled in dietfeatures.h. added strlcpy and strlcat from OpenBSD. added stat64, fstat64 and lstat64. added endian.h and made ending of strlen.c endianness-aware added string routines size tweak to dietfeatures.h. Most of the string routines have been unrolled. This is up to three times as fast but creates up to three times larger code. Now you can disable the unrolling. added sendfile. I also added pread. It works on x86 and sparc but not on ppc and mips. I have no idea what's going on. strace disagrees with the kernel. Can anyone help? I asked the Linux kernel mailing list for help, too. added a few aliases of the type __libc_open for open. nm on libpthreads.so indicates that we will need them. 0.6.7: the sources now compile without warnings with -Wall. printf now prints "(null)" when %s is passed NULL. This can be removed with WANT_NULL_PRINTF in dietfeatures.h added vfprintf, execl, ttyname. stat, lstat and fstat are now #defined to __dietstat, __dietlstat and __dietfstat so they can use the normal kernel struct stat. stat, lstat and fstat are now C wrappers that convert to the glibc struct stat. So we can avoid that overhead for programs that use dietlibc headers. 0.6.6: changed the Makefiles so you can now set CFLAGS on the command line added memccmp (analogous to memccpy) and strncmp. Olaf fixed another bug in the sparc unified syscall. Paul Clifford contributed a C version of his strlen.S that is much more efficient than the previous strlen on all platforms! It also looks like technology from Roswell. ;-} added a "real" stdio. Well, almost. Please contribute! added dietfeatures.h so you can remove features you don't need. removed debug code from vsnprintf that changed \0 to ' ' (argh!). stdio now works with simple programs and minigzip from libz. stdio uses some major trickery to avoid linking the stdio, stderr and stdout (and reserving space for them) when they are not used. 0.6.5: Red Plait found several bugs in diet libc, most of them bugs in the new header files, but also missing sigset functions. Paul Clifford contributed an assembly strlen.S for ARM and fixed several bugs. Fixed ppc/setjmp and mips/pipe. Olaf contributed a new sparc unified syscall. 0.6.4: declared is* static inline in getservent. added assert_fail, strtoul, isalpha, isdigit, isalnum, isascii. changed strlen to return 0 when passed NULL. new, much smaller unified syscall for MIPS. Thanks to Olaf the Mad Scientist who actually implemented this without access to a MIPS box, just from reading the architecture manual. And it worked out of the box. started a set of system includes, mainly so that I can use lcc and my alpha-linux cross compiler (which is unable to cross-compile glibc). diet libc can now be compiled without any include files from a normal libc. The includes do declare more than diet libc currently delivers and they are still far from complete for real applications. I will only add assembly versions that are smaller _and_ faster than the C version. Larger routines are only accepted if they are called very often and are substantially faster. added i386 assembly strchr, which is smaller and faster than the old version. It is, however, larger than the version contributed by proton (thanks, anyway). added i386 strlen (31% faster, 14% smaller) "make t" will now create a map file called "mapfile". 0.6.3: added sys_errlist, strerror and perror added isblank added atol 0.6.2: mmap for ARM didn't compile. Thanks, Paul! 0.6.1: split mmap into the architecture specific subdirectories. getenv now copes with environ==NULL, thanks Paul Clifford. Paul also contributed a smaller ARM startup code. 0.6: strcat returned the wrong result. Thanks, Dietz Pr?pper. strtod now understands a negative exponent (oops, thanks Bertram Barth) Port to arm-linux-gnu, but on the Netwinder I use for testing the __dtostr does not work (I have no idea why!) The MIPS port now uses (much smaller) non-PIC code. That means that the applications you link against diet libc also have to be compiled non-PIC. I suggest copying the CFLAGS from the diet libc Makefile. Thanks to Ralf B?chle for helping me with this! I made subdirectories for the architectures and use VPATH to override VPATH so that make finds the source file automatically. That should simplify the sources greatly. Olaf Dreesen contributed Alpha support including setjmp and longjmp! ARM and MIPS now also have setjmp and longjmp "compile" and "load" are now make targets. Use them for djb programs. added contrib/elftrunc.c which will remove unnecessary ELF headers. Again, contributed from Olaf. Great work! 0.5.12: printf also does signed numbers. If you don't use atexit, dietlibc now does not link exit, only _exit. *printf now correctly returns the number of bytes written. Olaf contributed experimental sscanf and vsscanf implementations. If passed NULL as buffer, snprintf will not write anything but still return the number of bytes it would have written. Initial MIPS port! (Oh, the agony!) No setjmp and longjmp support yet! Please contribute! I even implemented unified syscalls for MIPS. Still, MIPS code is almost twice the size of SPARC code. If anyone knows why: please tell me! 0.5.11: I implemented new unified syscalls for x86, sparc and ppc, this time based on .s files and not .c files, and I moved the syscalls into subdirectores to clean the dietlibc sources up a little. A binary consisting of printf("%s is %d\n","olaf",23) is now 2864 bytes on sparc 2488 bytes on intel I kludgily implemented fprintf(stdout,... and fprintf(stderr,... to make a few more applications work. Olaf Dreesen also implemented some unified syscall stuff for x86. He discovered that with our unified syscall interface it actually costs <10 bytes total to make all system calls thread safe! I implemented atexit() (can register up to 4 callbacks). I implemented strtod and __dtostr (the opposite). Now we can add floating point support to vsnprintf and sscanf! 0.5.10: I actually saw that I can not only merge the errno handling code of the system calls on x86, I can also merge the rest (including the arguments) except for setting the system call number. All those system calls are now just a jump to a unified system call handler. I got rid of x86openclose again. The savings are substantial: chown from embutils went from 7664 to 7184 bytes! If I'd move the system call wrappers to assembly language, I could even reduce the alignment (does not matter since it's just a jump anyway) and get rid of the "ret" behind each jump (one byte per system call!) 0.5.9: added memchr, strpbrk, strstr, strtol, isspace (hehe) fixed strdup fixed return values for strcpy and strcat (thanks to Norbert Berzen) Olaf Dreesen contributed a strtol and initial {sn|vsn|}printf implementation (no signed integers, only strings and unsigned integers (but supporting octal, hex and decimal). Thanks, Olaf! (by the way: that code must be wonderful, I don't understand it at all *bg*) Olaf's printf does understand padding like in "%08d" and "%8d" and automatically pads pointers with '0'. Rewrote the x86 start code, old: 22 instructions, new: 12 instructions. Thanks to proton for inspiration on this. The new x86 start code also does not reference exit any more, thus saving 64 bytes for executables that don't call exit explicitly. [insert maniacal laughter] EVERY BYTE COUNTS!1!! ;-) Moved errno and environ to start.S, saving no byte binary size but speeding up compilation and slightly shortening dietlibc.a ;-) For x86: joined open and close into one assembler file, sharing the errno handling. This is a feasibility test and it actually saves a few bytes. I think I will reimplement the _syscall[1-6] macros on all platforms now to share the errno handling code for them. 0.5.8: fixed strchr to be able to look for 0. added _llseek, ftruncate, getpgid, getresgid, getresuid, getsid, memccpy, memmove, mprotect, setregid, setresgid, setresuid, setreuid, strncpy, swapon, truncate, strtok, strtok_r, strspn, strcspn (all contributed by Olaf Dreesen) added execvp, getcwd fixed __xmknod Note: can it be that the ftw interface really is so broken that I cannot implement it without having to implement some searching data structure? I included an experimental ftw implementation that will not follow symlinks. 0.5.7: oops, if_nametoindex was broken! 0.5.6: ported to ppc-linux. fixed i386 sigsetjmp (I mistyped the function name) included sigjmp.c 0.5.5: added wait, sys_siglist, longjmp/setjmp/sigsetjmp for i386 and sparc actually, it wasn't fork that wasn't working for sparc, it was pipe. I fixed it now. dietlibc/SPARC assumes -msupersparc (does not provide div, mul, etc) fixed readdir to use getdents and not the intel inline asm 0.5.4: ported to sparclinux (sparc32 only). Beware: does not work yet. added raise, abort, readlink, strcat, geteuid, geteuid, wait3, access 0.5.3: added tcsetattr and getenv to compile e3 0.5.2: added vhangup, tcgetattr, isatty and memcmp for fgetty (http://www.fefe.de/fgetty/) added localtime from uC-libc. 0.5.1: stat and friends actually work now. Yuck! Another case of translation between kernel and userland. Why can't the kernel people and the libc people simply agree on a standard? removed many unnecessary includes to speed up compilation. added -fomit-frame-pointer and i386 compilation target to reduce code size. inlined socketcall to reduce code size. "load" and "compile" are examples for djb code. 0.5: Olaf Dreesen contributed a much smaller implementation of malloc and friends. each object file is now treated with "strip -x -R .note -R .comment" split each system call into a separate object file added ntohs, htons, alarm, if_indextoname and if_nametoindex 0.4.1: oops, the strchr implementation was wrong. Thanks Jens Laas! 0.4: copied opendir and friends from uC-libc. added getservent and getservby* in gerservent.c 0.3: remove readdir system call added getdents system call added getpwnam/getpwuid implementation in getpwnam.c added a few string functions (in str*.c) dietlibc-0.33~cvs20120325/COPYING010064400000000000000000000431311173363226000127360ustar00 GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Library General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Library General Public License instead of this License. dietlibc-0.33~cvs20120325/FAQ010064400000000000000000000350321173363226000122360ustar00diet libc FAQ. Q: How do I compile this? I don't see a configure? A: Just type make. Q: How do I install it? make install? A: Yep. It will then install itself to /opt/diet, with the wrapper in /opt/diet/bin/diet. Or you don't install it at all. The diet libc comes with a wrapper called "diet", which can be found in bin-$(ARCH)/diet, i.e. bin-i386/diet for most of us. Copy this wrapper somewhere in your path (for example ~/bin) and then just compile stuff by prepending diet to the command line, e.g. "diet gcc -pipe -g -o t t.c". Q: How do I compile programs using autoconf with the diet libc? A: Set CC in the environment properly. For Bourne Shells: $ CC="diet gcc -nostdinc" ./configure --disable-nls That should be enough, but you might also want to set --disable-shared and --enable-static for packages using libtool. Q: My program complains about missing asm/* or linux/* header files! A: It is quite linux specific. You can try omitting the -nostdinc, but except for some cases conflicts are likely. You should not be using the kernel headers in your software. Q: Do you have cross compiling support? A: Yes. Just type something like "make ARCH=arm CROSS=arm-linux- all". For arm, alpha, mips, ppc, sparc and i386, shortcuts exist. You can also use "make arm", for example. You still use the same "diet" program as for normal compilation, but you can then say $ diet sparc-linux-gcc -pipe -g -o t t.c Programs using autoconf can be configured like this: $ CC="diet sparc-linux-gcc" ./configure --disable-nls Q: There are a few warnings about possibly uninitialized variables when compiling the diet libc. Can't you remove them? A: This type of warning can only be removed by a) compiling without warnings or b) initializing the variables in question. In all cases, the variables won't actually be used uninitialized, but adding an explicit initializer will add a few bytes of code. As you know, the goal of the diet libc is to not waste a single byte of code, so we don't add initializers ;-) Q: When linking binaries, I get warnings about stdio and printf all the time. What gives? A: Since the diet libc was written to make writing small programs possible, it also tries to assist in the process of seeing causes of bloat. Premier causes for bloat are stdio and the printf family of functions. The diet libc will also warn you if you still use assert() (which is normally not enabled in production code) or if you use functions that use static buffers (like gethostbyname and friends). Q: My program stopped parsing command line arguments properly! Now what? A: The getopt in the diet libc adheres to the Single Unix Specification. In particular, it initialized optind to 1 (not 0) and breaks if someone sets optint to 0 (as some misguided legacy programs to). Also, it does not reorder arguments, i.e. something like "rm -f foo -v" will not see -v as option but rather as non-option argument. If you need GNU getopt behaviour, please use GNU getopt instead of the diet libc code. Q: I get linker errors about missing __ctype_b! A: This happens when you link in code that was compiled with the glibc headers. The most common culprit is a library like -lncurses, -lcrypto or -lresolv. All external libraries you use have to be compiled with the diet libc headers (CC="diet gcc"), and there is no libresolv with the diet libc, it's in the main libc! Q: My program links, but when I run it, I get no output at all and it appears to terminate immediately. A: This normally happens if you link in glibc. The major reason for this was that shared libraries were linked in. diet sets -static since version 0.13, so if it still happens to you, you need to strace and debug your software. Q: Why aren't you compatible to glibc? I thought the interface was a standard? A: Yes, the interface is, but a lot of details are missing. For example, the diet libc uses a different "struct stat" layout than glibc. We use the one from the kernel, glibc uses an own one and links in translation code. This is part of the reason why glibc is so big and ugly. If we support all of this, we end up as bloated as glibc. Q: Where is the test suite? A: The humble beginnings are in the "test" directory, but it can't be run automatically yet. Q: GPL sucks! Now I can't compile my BSD programs with the diet libc! A: Wrong. You can compile them, and you can use them. You just can't redistribute the binaries. That said: I will not be sueing anybody for distributing binaries of BSD programs linked against dietlibc, as long as the source code is available somewhere publicly. Q: Where are the shared libaries? make install didn't install them! A: You have to explicitly build them with "make dyn". Since they are experimental and only supported on a small subset of the platforms, that is not default. Also, I recommend you only use shared libraries if you really know what you are doing. For example, you can't just use your system shared libraries, because they have a dependency on glibc in them, so the program will crash. And you have to explicitly compile the code with -fPIC or -fpic. You can then use them by substituting "diet-dyn" for "diet" on the command line. Q: My target platform does not have a MMU. Should I be using uClibc? A: I am not aware of any issues with MMU-less systems. You should be able to use the diet libc just fine. Having a MMU or not is mostly an issue for the kernel, not libc. Q: How do I make myself a cross compiler? A: untar binutils and gcc (I used version 2.11.2 and 3.0.4 respectively) Then use the --target=arm-linux (or whatever platform you want) configure options. For gcc, add --enable-languages=c (otherwise gcc will try to make C++, Objective C and Java, too, and those compilations will fail because they require installed libc headers which you don't have yet). I recommend using --enable-static --disable-shared, too, because otherwise the binutils shared libraries will overwrite each other if you install more than one cross binutils for different targets. binutils$ ./configure --enable-static --disable-shared --prefix=/opt/cross --target=arm-linux gcc$ ./configure --enable-static --disable-shared --prefix=/opt/cross --target=arm-linux --enable-languages=c For some platforms, gcc compilation will fail while trying to compile some part of libgcc.a because it depends on some libc header file. This is a gcc bug and you should complain using gccbug, because you can't cross-compile libc unless you successfully installed the cross compiler. Q: Where are the xdr_* symbols? Q: Where are the RPC symbols? Q: util-linux says that rpcgen output does not work?! A: Add -lrpc. The code is from Sun and frankly it is so ugly and so rarely used that I don't want to include it in libc. Q: I am missing some BSD/GNU extension! A: I started adding a few of them to libcompat. You have to link it in manually, though, as using them is bad for portability and I want people to make a conscious effort to write non-portable applications by not including them in the libc itself. Q: I'm just starting with the diet libc. Should I use the tarball or the CVS version? A: Always use the CVS version. We generally don't add unstable test stuff on the CVS tree, and our APIs are stable (they are standardized, remember?). In fact, we don't add much stuff at all. Most changes are bug fixes and optimizations, and in general you'll want those. Q: Does the diet libc support profiling (with gprof)? A: There is experimental support for profiling, but so far it only works on x86. To use it, do "make profiling" before make install. Then, diet will link in the support code if it finds a -pg on the gcc command line. Q: I get compiler errors in a line with caddr_t, u_long, n_short or nlong or similar. A: Add -D_BSD_SOURCE to the compiler command line. The diet libc tries to encourage portable and standards compliant programming, so it hides these legacy BSD types from the standard name space. The reason is that the Single Unix Specification contains a specification of the socket API but does not mention those types. Q: I get compiler errors in a line with u_int8_t or similar. A: Add -D_GNU_SOURCE to the compiler command line. See previous question. This is a very questionable GNU extension. The C Standard defines uint8_t, uint16_t and uint32_t. Use those instead. Q: Can I compile or use the diet libc with a compiler that is not gcc? A: Compile: no. Use: yes. Q: Can you please port the diet libc to FreeBSD/Solaris/Windows? A: No. Q: Why do you support non-embedded platforms like IA64 and x86_64? A: The diet libc is also useful for servers because it can improve performance by an order of magnitude for certain programming models. Please see http://www.fefe.de/fnord/ (in particular .../fnord/SPEED) for an example and/or read http://www.fefe.de/talk.pdf for some benchmarks. Q: I just compiled hello world and the binary is larger than with glibc! A: You forgot to add the dynamic glibc to your size comparison. Please use -static when linking with glibc to see the difference. Q: Should I compile my kernel with the diet libc? A: The kernel is not linked against any libc. In fact, the libc is the user space interface to the kernel. So unless you are talking about "user mode linux" (which is a special version of the kernel that happens to be a user space program) you cannot link the kernel against the diet libc. Linking user space Linux with the diet libc should be possible in theory but I don't think anyone has actually tried it. Q: I get errors when cross compiling the diet libc with the Hard Hat compiler chain. A: Their compiler and/or binutils is broken. Compile your own. At the time of this writing, I am successfully using gcc 3.1.1 and binutils 2.12.1 to compile the diet libc 0.22. Q: I can't link this software; it uses functions like ftok and cuserid. A: Some obsolete and/or questionable functions have been put into libcompat.a to quarantine them away. If your software uses these functions, it is broken. Please go through the code and replace these functions with their POSIX counterparts or get rid of it altogether. Q: Compiling software with "diet -Os gcc..." gives error messages about -malign-loops, -malign-jumps and -malign-functions being obsolete. A: UPDATE: the defaults have been changed as of 2005-04-23. diet -Os uses some platform dependant gcc options to create tighter code. Unfortunately, these options have been renamed on gcc 3. You can fix this by creating a file ~/.diet/gcc containing this line: -Os -fomit-frame-pointer -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2 If you get this options not for diet -Os gcc but for diet -Os i386-linux-gcc, put this in ~/.diet/i386-linux-gcc instead. Q: Compiling software with "diet -Os gcc..." gives error messages about -falign-loops, -falign-jumps and -falign-functions. A: See previous entry for an explanation. You are using gcc 2; please upgrade to gcc 3 or 4. As a workaround, put -Os -fomit-frame-pointer -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 into ~/.diet/gcc. Q: I see lots of uninitialized variables, like "static int foo;". What gives? A: "static" global variables are initialized to 0. ANSI C guarantees that. Technically speaking, static variables go into the .bss ELF segment, while "static int foo=0" goes into .data. Because .bss is zero filled by the OS, it does not need to be in the actual binary. So it is in fact better to not initialize static variables if the desired initialization value is 0 anyway. The same is true for pointers, by the way. On all platforms supported by the diet libc, numeric zero is also the pointer value for NULL. So not initializing a static pointer yields NULL. Q: My diet libc programs all segfault in User Mode Linux 2.6! A: This is a shortcoming of User Mode Linux. Edit dietfeatures.h, remove the WANT_SYSENTER #define, and then recompile the diet libc and your program. Oh, and bug the user mode linux people about this, it's their fault! ;) Q: dietlibc.a does not look so small to me! It's almost 600k! A: Use size(1) to find the real size, like this: $ ls -l bin-i386/dietlibc.a -rw-r--r-- 1 leitner users 597204 Nov 30 16:36 bin-i386/dietlibc.a $ size --totals bin-i386/dietlibc.a text data bss dec hex filename 62 4 0 66 42 unified.o (ex bin-i386/dietlibc.a) [...] 100 0 0 100 64 stackgap.o (ex bin-i386/dietlibc.a) 73908 1163 9298 84369 14991 (TOTALS) "text" is the code in the library, "data" is the variables, "bss" are the constants (string constants, mostly). So there are really only 70k code in the whole library, and you will probably only use a small part of it in your code. Q: I get an error message at link time, that "main" can not be found. A: Disable WANT_STACKGAP in dietfeatures.h or try upgrading your binutils. Q: I want to have a gcc that uses the diet libc by default. A: You will have to edit the "specs" file from gcc then. John K. Hohm sent these lines to use gcc with the dynamic diet libc (make dyn and make sure you have WANT_DYNAMIC in dietfeatures.h): *endfile: %{shared:dyn_dstop.o%s}%{!shared:%{static:dyn_stop.o%s}%{!static:dyn_dstop.o%s}} *startfile: %{shared:dyn_so_start.o%s}%{!shared:%{static:start.o%s dyn_start.o%s}%{!static:dstart.o%s dyn_dstart.o%s}} Q: Dynamically linked binaries don't work on Fedora 6! A: Fedora 6 ships with binutils that can create non-standard ELF binaries, and they hacked their gcc to generate them by default. You can see whether your gcc also does this with gcc -dumpspecs|grep "hash-style=gnu" and you can see if a shared library was build with this flag with readelf -S libname.so|grep GNU_HASH You can override this behavior like this: diet-dyn gcc -Wl,--hash-style=sysv -shared -o libx.so x.c ^^^^^^^^^^^^^^^^^^^^^ Q: How do I compile OpenSSL with dietlibc? A: Here's how I do it: ./config --prefix=/opt/diet no-dso make libssl.pc openssl.pc for i in libssl.pc openssl.pc Makefile; do (echo ",s/ *-ldl//g"; echo w) | ed $i; done make CC="diet -Os gcc -pipe -nostdinc" Then the libraries go to /opt/diet/lib, so you still need a symlink to lib-i386 or whatever your architecture is. dietlibc-0.33~cvs20120325/Makefile010064400000000000000000000455721173363226000133560ustar00INSTALL=install prefix?=/opt/diet # Set the following to install to a different root #DESTDIR=/tmp/fefix # Use "make DEBUG=1" to compile a debug version. LIBDIR=${prefix}/lib BINDIR=${prefix}/bin MAN1DIR=${prefix}/man/man1 MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6]t\?e\?[lb]/arm/') # This extra-ugly cruft is here so make will not run uname and sed each # time it looks at $(OBJDIR). This alone sped up running make when # nothing has to be done from 1 sec to 0.12 sec on a 900 MHz Athlon. # We don't use ARCH:=$(MYARCH) so we can detect unknown architectures. ifeq ($(MYARCH),i386) ARCH=i386 else ifeq ($(MYARCH),mips) ARCH=mips else ifeq ($(MYARCH),alpha) ARCH=alpha else ifeq ($(MYARCH),ppc) ARCH=ppc else ifeq ($(MYARCH),ppc64) ARCH=ppc64 else ifeq ($(MYARCH),arm) ARCH=arm else ifeq ($(MYARCH),sparc) ARCH=sparc else ifeq ($(MYARCH),sparc64) ARCH=sparc64 else ifeq ($(MYARCH),s390) ARCH=s390 else ifeq ($(MYARCH),s390x) ARCH=s390x else ifeq ($(MYARCH),mipsel) ARCH=mipsel else ifeq ($(MYARCH),parisc) ARCH=parisc else ifeq ($(MYARCH),parisc64) ARCH=parisc MYARCH=parisc else ifeq ($(MYARCH),x86_64) ARCH=x86_64 else ifeq ($(MYARCH),ia64) ARCH=ia64 else ifeq ($(MYARCH),armeb) ARCH=arm else $(error unknown architecture, please fix Makefile) endif endif endif endif endif endif endif endif endif endif endif endif endif endif endif endif # ARCH=$(MYARCH) OBJDIR=bin-$(ARCH) ILIBDIR=$(LIBDIR)-$(ARCH) HOME=$(shell pwd) WHAT= $(OBJDIR) $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o \ $(OBJDIR)/dietlibc.a $(OBJDIR)/liblatin1.a \ $(OBJDIR)/libcompat.a $(OBJDIR)/libm.a \ $(OBJDIR)/librpc.a $(OBJDIR)/libpthread.a \ $(OBJDIR)/libcrypt.a \ $(OBJDIR)/diet $(OBJDIR)/diet-i $(OBJDIR)/elftrunc \ $(OBJDIR)/dnsd all: $(WHAT) profiling: $(OBJDIR)/libgmon.a $(OBJDIR)/pstart.o CFLAGS=-pipe -nostdinc CROSS= CC=gcc INC=-I. -isystem include VPATH=lib:libstdio:libugly:libcruft:libcrypt:libshell:liblatin1:libcompat:libdl:librpc:libregex:libm:profiling SYSCALLOBJ=$(patsubst syscalls.s/%.S,$(OBJDIR)/%.o,$(wildcard syscalls.s/*.S)) LIBOBJ=$(patsubst lib/%.c,$(OBJDIR)/%.o,$(wildcard lib/*.c)) LIBUGLYOBJ=$(patsubst libugly/%.c,$(OBJDIR)/%.o,$(wildcard libugly/*.c)) LIBSTDIOOBJ=$(patsubst libstdio/%.c,$(OBJDIR)/%.o,$(wildcard libstdio/*.c)) LIBCRUFTOBJ=$(patsubst libcruft/%.c,$(OBJDIR)/%.o,$(wildcard libcruft/*.c)) LIBCRYPTOBJ=$(patsubst libcrypt/%.c,$(OBJDIR)/%.o,$(wildcard libcrypt/*.c)) LIBSHELLOBJ=$(patsubst libshell/%.c,$(OBJDIR)/%.o,$(wildcard libshell/*.c)) LIBCOMPATOBJ=$(patsubst libcompat/%.c,$(OBJDIR)/%.o,$(wildcard libcompat/*.c)) $(OBJDIR)/syscall.o LIBMATH=$(patsubst libm/%.c,%.o,$(wildcard libm/*.c)) LIBRPCOBJ=$(patsubst librpc/%.c,$(OBJDIR)/%.o,$(wildcard librpc/*.c)) LIBREGEXOBJ=$(patsubst libregex/%.c,$(OBJDIR)/%.o,$(wildcard libregex/*.c)) LIBDLOBJ=$(patsubst libdl/%.c,$(OBJDIR)/%.o,$(wildcard libdl/*.c)) $(OBJDIR)/_dl_jump.o LIBPTHREAD_OBJS=$(patsubst libpthread/%.c,$(OBJDIR)/%.o,$(shell ./threadsafe.sh)) $(OBJDIR)/__testandset.o LIBGMON_OBJS=$(OBJDIR)/__mcount.o $(OBJDIR)/monitor.o $(OBJDIR)/profil.o include $(ARCH)/Makefile.add LIBMATHOBJ=$(patsubst %,$(OBJDIR)/%,$(LIBMATH)) ifeq ($(CFLAGS),-pipe -nostdinc) CFLAGS+=-O -fomit-frame-pointer endif ifneq ($(DEBUG),) CFLAGS = -g COMMENT = : endif CFLAGS += -W -Wall -Wextra -Wchar-subscripts -Wmissing-prototypes -Wmissing-declarations -Wno-switch -Wno-unused -Wredundant-decls PWD=$(shell pwd) .SUFFIXES: .SUFFIXES: .S .c # added real dynamic dietlibc.so PICODIR = pic-$(ARCH) $(OBJDIR) $(PICODIR): mkdir $@ % :: %,v $(OBJDIR)/%: $(OBJDIR) ifeq ($(CC),tcc) $(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h $(CROSS)cpp $(INC) $< | $(CROSS)as -o $@ $(OBJDIR)/%.o: %.c tcc -I. -Iinclude -c $< -o $@ $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ else $(OBJDIR)/pstart.o: start.S $(CROSS)$(CC) $(INC) $(CFLAGS) -DPROFILING -c $< -o $@ $(OBJDIR)/%.o: %.S $(ARCH)/syscalls.h $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ $(OBJDIR)/pthread_%.o: libpthread/pthread_%.c $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ $(OBJDIR)/%.o: %.c $(CROSS)$(CC) $(INC) $(CFLAGS) -c $< -o $@ -D__dietlibc__ $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ endif ifeq ($(shell $(CC) -v 2>&1 | grep "gcc version"),gcc version 4.0.0) SAFE_CFLAGS=$(shell echo $(CFLAGS)|sed 's/-Os/-O2/') SAFER_CFLAGS=$(shell echo $(CFLAGS)|sed 's/-Os/-O/') else SAFE_CFLAGS=$(CFLAGS) SAFER_CFLAGS=$(CFLAGS) endif CC+=-D__dietlibc__ $(OBJDIR)/crypt.o: libcrypt/crypt.c $(CROSS)$(CC) $(INC) $(SAFER_CFLAGS) -c $< -o $@ DIETLIBC_OBJ = $(OBJDIR)/unified.o \ $(SYSCALLOBJ) $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ $(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ) \ $(OBJDIR)/__longjmp.o $(OBJDIR)/setjmp.o \ $(OBJDIR)/clone.o $(OBJDIR)/dietlibc.a: $(DIETLIBC_OBJ) $(OBJDIR)/start.o $(CROSS)ar cru $@ $(DIETLIBC_OBJ) $(OBJDIR)/librpc.a: $(LIBRPCOBJ) $(CROSS)ar cru $@ $(LIBRPCOBJ) $(OBJDIR)/libcrypt.a: touch dummy.c $(CROSS)$(CC) -c dummy.c $(CROSS)ar cru $@ dummy.o rm -f dummy.c dummy.o dummy.o: LIBLATIN1_OBJS=$(patsubst liblatin1/%.c,$(OBJDIR)/%.o,$(wildcard liblatin1/*.c)) $(OBJDIR)/liblatin1.a: $(LIBLATIN1_OBJS) $(CROSS)ar cru $@ $^ $(OBJDIR)/libgmon.a: $(LIBGMON_OBJS) $(CROSS)ar cru $@ $^ $(OBJDIR)/libpthread.a: $(LIBPTHREAD_OBJS) dietfeatures.h $(CROSS)ar cru $@ $(LIBPTHREAD_OBJS) $(OBJDIR)/libcompat.a: $(LIBCOMPATOBJ) $(CROSS)ar cru $@ $(LIBCOMPATOBJ) $(OBJDIR)/libm.a: $(LIBMATHOBJ) $(CROSS)ar cru $@ $(LIBMATHOBJ) LD_UNSET = env -u LD_RUN_PATH dyn: dyn_lib # added dynamic linker $(OBJDIR)/libdl.a: $(LIBDLOBJ) $(CROSS)ar cru $@ $(LIBDLOBJ) dyn_lib: $(PICODIR) $(PICODIR)/libc.so $(PICODIR)/dstart.o \ $(PICODIR)/dyn_so_start.o $(PICODIR)/dyn_start.o $(PICODIR)/dyn_stop.o \ $(PICODIR)/libpthread.so $(PICODIR)/libdl.so $(PICODIR)/libcompat.so \ $(PICODIR)/libm.so $(PICODIR)/diet-dyn $(PICODIR)/diet-dyn-i $(PICODIR)/%.o: %.S $(ARCH)/syscalls.h $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ $(PICODIR)/pthread_%.o: libpthread/pthread_%.c $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ $(PICODIR)/%.o: %.c $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ $(PICODIR)/dstart.o: start.S $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -c $< -o $@ $(PICODIR)/dyn_so_start.o: dyn_start.c $(CROSS)$(CC) $(INC) $(CFLAGS) -fPIC -D__DYN_LIB -D__DYN_LIB_SHARED -c $< -o $@ $(COMMENT) $(CROSS)strip -x -R .comment -R .note $@ DYN_LIBC_PIC = $(LIBOBJ) $(LIBSTDIOOBJ) $(LIBUGLYOBJ) \ $(LIBCRUFTOBJ) $(LIBCRYPTOBJ) $(LIBSHELLOBJ) $(LIBREGEXOBJ) DYN_LIBC_OBJ = $(PICODIR)/dyn_syscalls.o $(PICODIR)/errlist.o \ $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(DYN_LIBC_PIC)) DYN_PTHREAD_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBPTHREAD_OBJS)) DYN_LIBDL_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBDLOBJ)) DYN_LIBCOMPAT_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBCOMPATOBJ)) DYN_LIBMATH_OBJS = $(patsubst $(OBJDIR)/%.o,$(PICODIR)/%.o,$(LIBMATHOBJ)) $(PICODIR)/libc.so: $(PICODIR) $(DYN_LIBC_OBJ) $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBC_OBJ) -lgcc -Wl,-soname=libc.so $(PICODIR)/libpthread.so: $(DYN_PTHREAD_OBJS) dietfeatures.h $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_PTHREAD_OBJS) -L$(PICODIR) -lc -Wl,-soname=libpthread.so $(PICODIR)/libdl.so: libdl/_dl_main.c dietfeatures.h $(LD_UNSET) $(CROSS)$(CC) -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -nostdlib -shared -Bsymbolic -Wl,-Bsymbolic \ -o $@ $(SAFE_CFLAGS) $(INC) libdl/_dl_main.c -Wl,-soname=libdl.so $(OBJDIR)/pthread_create.o $(PICODIR)/pthread_create.o: dietfeatures.h $(OBJDIR)/pthread_internal.o $(PICODIR)/pthread_internal.o: dietfeatures.h #$(PICODIR)/libdl.so: $(DYN_LIBDL_OBJS) dietfeatures.h # $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBDL_OBJS) -L$(PICODIR) -ldietc -Wl,-soname=libdl.so $(PICODIR)/libcompat.so: $(DYN_LIBCOMPAT_OBJS) dietfeatures.h $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBCOMPAT_OBJS) -L$(PICODIR) -lc -Wl,-soname=libcompat.so $(PICODIR)/libm.so: $(DYN_LIBMATH_OBJS) dietfeatures.h $(LD_UNSET) $(CROSS)$(CC) -nostdlib -shared -o $@ $(CFLAGS) -fPIC $(DYN_LIBMATH_OBJS) -L$(PICODIR) -lc -Wl,-soname=libm.so $(SYSCALLOBJ): syscalls.h $(OBJDIR)/elftrunc: $(OBJDIR)/diet contrib/elftrunc.c bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/elftrunc.c $(OBJDIR)/dnsd: $(OBJDIR)/diet contrib/dnsd.c bin-$(MYARCH)/diet $(CROSS)$(CC) $(CFLAGS) -o $@ contrib/dnsd.c VERSION=dietlibc-$(shell head -n 1 CHANGES|sed 's/://') CURNAME=$(notdir $(shell pwd)) $(OBJDIR)/diet: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -DVERSION=\"$(VERSION)\" -lgcc $(CROSS)strip -R .comment -R .note $@ $(OBJDIR)/diet-i: $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o diet.c $(OBJDIR)/dietlibc.a $(OBJDIR)/dyn_stop.o $(CROSS)$(CC) -isystem include $(CFLAGS) -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -DVERSION=\"$(VERSION)\" -DINSTALLVERSION -lgcc $(CROSS)strip -R .comment -R .note $@ $(PICODIR)/diet-dyn: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c $(LD_UNSET) $(CROSS)$(CC) -isystem include $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(HOME)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(HOME)/$(PICODIR)/libdl.so $(CROSS)strip -R .command -R .note $@ $(PICODIR)/diet-dyn-i: $(PICODIR)/start.o $(PICODIR)/dyn_start.o diet.c $(LD_UNSET) $(CROSS)$(CC) -isystem include $(CFLAGS) -fPIC -nostdlib -o $@ $^ -DDIETHOME=\"$(prefix)\" -D__DYN_LIB -DVERSION=\"$(VERSION)\" -L$(PICODIR) -lc -lgcc $(PICODIR)/dyn_stop.o -Wl,-dynamic-linker=$(ILIBDIR)/libdl.so -DINSTALLVERSION $(CROSS)strip -R .command -R .note $@ $(OBJDIR)/djb: $(OBJDIR)/compile $(OBJDIR)/load $(OBJDIR)/compile: echo 'exec' $(CC) '$(CFLAGS) -I$(PWD)/$(OBJDIR)/include -c $${1+"$$@"}' > $@ chmod 755 $@ $(OBJDIR)/load: echo 'main="$$1"; shift; exec' $(CC) '-nostdlib -o "$$main" $(PWD)/$(OBJDIR)/start.o "$$main".o $${1+"$$@"} $(PWD)/$(OBJDIR)/dietlibc.a -lgcc' > $@ chmod 755 $@ clean: rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so rm -rf bin-* pic-* $(MAKE) -C examples clean $(MAKE) -C dynlinker clean $(MAKE) -C libdl clean tar: clean rename cd ..; tar cvvf $(VERSION).tar.bz2 --use=bzip2 --exclude CVS $(VERSION) rename: if test $(CURNAME) != $(VERSION); then cd .. && mv $(CURNAME) $(VERSION); fi $(OBJDIR)/exports: $(OBJDIR)/dietlibc.a nm -g $(OBJDIR)/dietlibc.a | grep '\' | awk '{ print $$3 }' | sort -u > $(OBJDIR)/exports .PHONY: t t1 t: $(CROSS)$(CC) -g $(CFLAGS) -fno-builtin -nostdlib -isystem include -o t t.c $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dietlibc.a -lgcc $(OBJDIR)/dyn_stop.o -Wl,-Map,mapfile t1: $(CROSS)$(CC) -g -o t1 t.c install-bin: $(OBJDIR)/start.o $(OBJDIR)/dietlibc.a $(OBJDIR)/librpc.a $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/elftrunc $(OBJDIR)/diet-i $(INSTALL) -d $(DESTDIR)$(ILIBDIR) $(DESTDIR)$(MAN1DIR) $(DESTDIR)$(BINDIR) $(INSTALL) $(OBJDIR)/start.o $(DESTDIR)$(ILIBDIR)/start.o $(INSTALL) -m 644 $(OBJDIR)/libm.a $(OBJDIR)/libpthread.a $(OBJDIR)/librpc.a \ $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompat.a $(OBJDIR)/libcrypt.a $(DESTDIR)$(ILIBDIR) $(INSTALL) -m 644 $(OBJDIR)/dietlibc.a $(DESTDIR)$(ILIBDIR)/libc.a ifeq ($(MYARCH),$(ARCH)) $(INSTALL) $(OBJDIR)/diet-i $(DESTDIR)$(BINDIR)/diet -$(INSTALL) $(PICODIR)/diet-dyn-i $(DESTDIR)$(BINDIR)/diet-dyn endif $(INSTALL) -m 755 $(OBJDIR)/elftrunc $(OBJDIR)/dnsd $(DESTDIR)$(BINDIR) $(INSTALL) -m 644 diet.1 $(DESTDIR)$(MAN1DIR)/diet.1 install-profiling: -$(INSTALL) $(OBJDIR)/pstart.o $(OBJDIR)/libgmon.a $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR) install-pic: -$(INSTALL) $(PICODIR)/libc.so $(DESTDIR)$(ILIBDIR)/libc.so -$(INSTALL) $(PICODIR)/libpthread.so $(DESTDIR)$(ILIBDIR)/libpthread.so -$(INSTALL) $(PICODIR)/libdl.so $(DESTDIR)$(ILIBDIR)/libdl.so -$(INSTALL) $(PICODIR)/libcompat.so $(DESTDIR)$(ILIBDIR)/libcompat.so -$(INSTALL) $(PICODIR)/libm.so $(DESTDIR)$(ILIBDIR)/libm.so -$(INSTALL) $(PICODIR)/dyn_start.o $(DESTDIR)$(ILIBDIR)/dyn_dstart.o -$(INSTALL) $(PICODIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)/dyn_dstop.o -$(INSTALL) $(PICODIR)/dstart.o $(PICODIR)/dyn_so_start.o $(DESTDIR)$(ILIBDIR) if test -f $(PICODIR)/libc.so -a ! -f $(DESTDIR)/etc/diet.ld.conf; then echo "$(ILIBDIR)" > $(DESTDIR)/etc/diet.ld.conf; fi install-headers: for i in `find include -name \*.h`; do install -m 644 -D $$i $(DESTDIR)$(prefix)/$$i; done install: install-bin install-profiling install-pic install-headers uninstall: for i in start.o libm.a libpthread.a librpc.a liblatin1.a libcompat.a libcrypt.a libc.a; do rm -f $(DESTDIR)$(ILIBDIR)/$$i; done rm -f $(DESTDIR)$(BINDIR)/diet $(DESTDIR)$(BINDIR)/diet-dyn for i in libgmon.a dyn_start.o dyn_stop.o libc.so libpthread.so libdl.so libcompat.so dyn_dstart.o dyn_dstop.o dyn_so_start.o; do rm -f $(DESTDIR)$(ILIBDIR)/$$i; done rm -f $(DESTDIR)$(MAN1DIR)/diet.1 $(DESTDIR)/etc/diet.ld.conf for i in `find include -name \*.h`; do rm -f $(DESTDIR)$(prefix)/$$i; done -rmdir $(DESTDIR)$(ILIBDIR) $(DESTDIR)$(MAN1DIR) $(DESTDIR)$(BINDIR) .PHONY: sparc ppc mips arm alpha i386 parisc mipsel powerpc s390 sparc64 .PHONY: x86_64 ia64 ppc64 s390x arm sparc alpha mips parisc s390 sparc64 x86_64 ia64 ppc64 s390x: $(MAKE) ARCH=$@ CROSS=$@-linux- all i386: ifeq ($(MYARCH),x86_64) $(MAKE) ARCH=$@ CC="$(CC) -m32" all else $(MAKE) ARCH=$@ CROSS=$@-linux- all endif ppc: ifeq ($(MYARCH),ppc64) $(MAKE) ARCH=$@ CC="$(CC) -m32" all else $(MAKE) ARCH=$@ CROSS=$@-linux- all endif # Cross compile for little endian MIPS mipsel: $(MAKE) ARCH=$@ CROSS=mips-linux- all mips-gnu: $(MAKE) ARCH=$@ CROSS=$@-linux-gnu- all # Some people named their cross compiler toolchain powerpc-linux-gcc powerpc: $(MAKE) ARCH=ppc CROSS=powerpc-linux- all hppa: ln -sf bin-parisc bin-hppa $(MAKE) ARCH=parisc CROSS=hppa-linux- all CROSS_ARCH=arm sparc ppc alpha i386 mips sparc64 x86_64 s390 parisc cross: $(MAKE) $(subst $(ARCH),,$(CROSS_ARCH)) # these depend on dietfeatures.h for large file backward compatibility $(OBJDIR)/__fstat64.o $(OBJDIR)/__lstat64.o $(OBJDIR)/__stat64.o $(OBJDIR)/lseek64.o $(OBJDIR)/readdir64.o $(OBJDIR)/stat64.o $(OBJDIR)/lstat64.o $(OBJDIR)/fstat64.o $(OBJDIR)/truncate64.o $(OBJDIR)/__truncate64.o $(OBJDIR)/ftruncate64.o $(OBJDIR)/__ftruncate64.o $(OBJDIR)/sendfile64.o $(OBJDIR)/__sendfile64.o $(PICODIR)/dyn_syscalls.o $(PICODIR)/__truncate64.o $(PICODIR)/__ftruncate64.o $(PICODIR)/__stat64.o $(PICODIR)/__lstat64.o $(PICODIR)/__fstat64.o $(OBJDIR)/__sendfile64.o $(OBJDIR)/fstatfs64.o $(OBJDIR)/statfs64.o: dietfeatures.h # these depend on dietfeatures.h for thread support $(OBJDIR)/alloc.o $(OBJDIR)/perror.o $(OBJDIR)/logging.o $(OBJDIR)/unified.o $(OBJDIR)/clone.o $(OBJDIR)/set_errno.o: dietfeatures.h # these depend on dietfeatures.h for linker warnings $(OBJDIR)/assert_fail.o $(OBJDIR)/sprintf.o $(OBJDIR)/vsnprintf.o $(OBJDIR)/___div.o $(OBJDIR)/fflush.o $(OBJDIR)/setvbuf.o $(OBJDIR)/system.o $(OBJDIR)/sendfile.o $(OBJDIR)/setenv.o: dietfeatures.h # these depend on dietfeatures.h for buffered stdio fclose.o $(OBJDIR)/fdglue.o $(OBJDIR)/fflush.o $(OBJDIR)/fgetc.o $(OBJDIR)/fputc.o $(OBJDIR)/fread.o $(OBJDIR)/fseek.o $(OBJDIR)/printf.o $(OBJDIR)/setvbuf.o $(OBJDIR)/stderr.o $(OBJDIR)/stdin.o $(OBJDIR)/stdout.o $(OBJDIR)/fwrite.o $(OBJDIR)/puts.o: dietfeatures.h # these depend on dietfeatures.h for fast string routines strcasecmp.o $(OBJDIR)/strcat.o $(OBJDIR)/strchr.o $(OBJDIR)/strcmp.o $(OBJDIR)/strcpy.o $(OBJDIR)/strlen.o $(OBJDIR)/strncasecmp.o $(OBJDIR)/strncat.o $(OBJDIR)/strrchr.o $(OBJDIR)/memchr.o: dietfeatures.h # this depends on dietfeatures.h for WANT_NON_COMPLIANT_STRNCAT $(OBJDIR)/strncpy.o: dietfeatures.h # these depend on dietfeatures.h for /proc $(OBJDIR)/ttyname.o $(OBJDIR)/sysconf_cpus.o: dietfeatures.h # these depend on dietfeatures.h for WANT_TZFILE_PARSER $(OBJDIR)/localtime_r.o $(OBJDIR)/strftime.o $(OBJDIR)/tzfile.o: dietfeatures.h # these depend on dietfeatures.h for WANT_SMALL_STDIO_BUFS $(LIBSTDIOOBJ): dietfeatures.h include/stdio.h dietstdio.h # these depend on dietfeatures.h for WANT_FULL_RESOLV_CONF $(OBJDIR)/dnscruft.o $(OBJDIR)/dnscruft2.o $(OBJDIR)/res_search.o $(OBJDIR)/res_query.o: dietfeatures.h # these depend on dietfeatures.h for WANT_THREAD_SAFE and errno $(LIBRPCOBJ) $(OBJDIR)/logging.o $(OBJDIR)/alloc.o $(OBJDIR)/cfsetospeed.o $(OBJDIR)/cfsetispeed.o \ $(OBJDIR)/execl.o $(OBJDIR)/execlp.o $(OBJDIR)/execv.o $(OBJDIR)/execvp.o $(OBJDIR)/isatty.o \ $(OBJDIR)/lockf.o $(OBJDIR)/perror.o $(OBJDIR)/remove.o $(OBJDIR)/set_errno.o $(OBJDIR)/sigemptyset.o \ $(OBJDIR)/tcsetattr.o $(OBJDIR)/dnscruft2.o $(OBJDIR)/dnscruft.o $(OBJDIR)/entlib.o \ $(OBJDIR)/gethostbyaddr.o $(OBJDIR)/gethostbyaddr_r.o $(OBJDIR)/gethostbyname.o \ $(OBJDIR)/gethostbyname_r.o $(OBJDIR)/gethostbyname2.o $(OBJDIR)/gethostbyname2_r.o \ $(OBJDIR)/inet_pton.o $(OBJDIR)/mkstemp.o $(OBJDIR)/mktemp.o $(OBJDIR)/tempnam.o \ $(OBJDIR)/glob.o $(OBJDIR)/realpath.o $(OBJDIR)/fdglue.o $(OBJDIR)/fdglue2.o \ $(OBJDIR)/getaddrinfo.o $(OBJDIR)/getnameinfo.o $(OBJDIR)/getprotoent.o \ $(OBJDIR)/getservent.o $(OBJDIR)/iconv.o $(OBJDIR)/iconv_open.o \ $(OBJDIR)/netent.o $(OBJDIR)/system.o $(OBJDIR)/stdin.o $(OBJDIR)/stdout.o \ $(OBJDIR)/stderr.o: dietfeatures.h # these depend on dietfeatures.h for WANT_CRYPT_MD5 $(OBJDIR)/crypt.o: dietfeatures.h # these depend on dietfeatures.h for WANT_FREAD_OPTIMIZATION $(OBJDIR)/fread.o $(OBJDIR)/fwrite.o: dietfeatures.h # these depend on dietfeatures.h for WANT_DYNAMIC $(OBJDIR)/start.o $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o: dietfeatures.h $(OBJDIR)/unified.o: dietuglyweaks.h $(OBJDIR)/adjtimex.o: include/sys/timex.h $(OBJDIR)/fgetc_unlocked.o $(OBJDIR)/fread.o $(OBJDIR)/ungetc.o: dietstdio.h # these depend on dietfeatures.h for WANT_LINKER_WARNINGS $(OBJDIR)/setlinebuf.o $(OBJDIR)/bzero.o $(OBJDIR)/setegid.o \ $(OBJDIR)/seteuid.o $(OBJDIR)/toascii.o: dietfeatures.h # these depend on dietfeatures.h for WANT_FULL_POSIX_COMPAT $(OBJDIR)/strncpy.o: dietfeatures.h $(OBJDIR)/strxfrm.o: dietfeatures.h $(OBJDIR)/stat.o $(OBJDIR)/fstat.o $(OBJDIR)/lstat.o: include/sys/stat.h $(OBJDIR)/stat64.o $(OBJDIR)/fstat64.o $(OBJDIR)/lstat64.o: include/sys/stat.h # these depend on dietfeatures.h for WANT_INET_ADDR_DNS $(OBJDIR)/gethostbyname_r.o: dietfeatures.h # WANT_PLUGPLAY_DNS $(OBJDIR)/getaddrinfo.o: dietfeatures.h $(OBJDIR)/strsignal.o: include/signal.h $(LIBPTHREAD_OBJS): include/pthread.h # CFLAGS+=-W -Wshadow -Wid-clash-31 -Wpointer-arith -Wcast-align -Wstrict-prototypes -Wwrite-strings # WANT_LARGEFILE_BACKCOMPAT $(OBJDIR)/fcntl64.o: dietfeatures.h # WANT_SSP # This facepalm brought to you by: Ubuntu! $(OBJDIR)/stackgap.o: lib/stackgap.c dietfeatures.h $(CROSS)$(CC) $(INC) $(CFLAGS) -c lib/stackgap.c -o $@ -D__dietlibc__ -fno-stack-protector $(COMMENT) -$(CROSS)strip -x -R .comment -R .note $@ # WANT_MALLOC_ZERO $(OBJDIR)/strndup.o: dietfeatures.h dietlibc-0.33~cvs20120325/PORTING010064400000000000000000000017331173363226000127520ustar00To port the diet libc to a new architecture, you need to: - edit Makefile to detect the architecture - create a directory for the architecture, and put a Makefile.add in it. Look at the other Makefile.adds for guidance. - provide start.S (the start code, look at glibc) - provide unified.S (the unified syscall) - provide syscalls.h (the syscall numbers, from asm/unistd.h) - provide setjmp and longjmp - edit include/setjmp.h - pipe, clone and mmap often need special care - edit include/sys/ioctl.h - edit include/sys/ptrace.h - edit include/asm/sigcontext.h - edit include/sys/ucontext.h - edit include/endian.h - edit include/fcntl.h - edit include/sys/mman.h - edit include/sys/shm.h - edit include/sys/stat.h - edit include/errno.h - edit syscalls.h - edit include/termios.h - edit diet.c to make it recognize the architecture and add proper CFLAGS - edit libcompat/syscall.S - edit include/fenv.h (I may have missed a few) dietlibc-0.33~cvs20120325/README010064400000000000000000000027741173363226000125730ustar00 The system library is a challenge to all those using the computer to write their own faster and better routines or to bow to the superior strength and skill of a true master. --http://www.inner.net/users/cmetz/program-like-a-klingon diet libc to statically link programs that don't need all the bloat from glibc. malloc, printf and scanf contributed from Olaf Dreesen. To compile: $ make make should compile the diet libc itself. When make is done, it will have created dietlibc.a in bin-i386 (or bin-ppc, bin-alpha, bin-sparc, bin-ppc or bin-arm, depending on your architecture). In that directory you will also find a program called "diet", which you need to copy in a directory in your $PATH: # install bin-i386/diet /usr/local/bin Then you can compile programs by prepending diet to the command line, i.e. $ diet gcc -s -Os -pipe -o t t.c diet is cross-compiler friendly and can also be used like this: $ diet sparc-linux-gcc -o t t.c diet will then link against dietlibc.a from bin-sparc, of course. diet comes with a man page (diet.1), which you can copy to an appropriate location, too: # cp diet.1 /usr/local/man/man1 After you compiled the diet libc successfully, I invite you to check out the embedded utils (http://www.fefe.de/embutils/). The embedded utils are small replacements for common utilities like mv, chown, ls, and even a small tar that can extract tar files. The license for the diet libc is the GNU General Public License, version 2 (as included in the file COPYING) or later. dietlibc-0.33~cvs20120325/README.security010064400000000000000000000027531173363226000144360ustar00The diet libc is not especially focused on providing a secure environment, but where it is possible to do something, we try to do it. 1. WANT_STACKGAP in dietfeatures.h This will randomize the stack layout slightly. The real memory cost is about one page of real memory. The code size increase is about 100 bytes, 86 for i386. The benefit is that buffer overflow exploits are harder because the address of the buffer fluctuates. 2. WANT_CRYPT_MD5 in dietfeatures.h This will enable MD5 style passwords in crypt(3). The standard Unix password mechanism is DES based and thus insecure by today's standards. Adding MD5 makes the code larger by some 5k. 3. WANT_NON_COMPLIANT_STRNCAT in dietfeatures.h strncat and strncpy are very user unfriendly. They copy zero terminated strings, and you can give them a limit on how much to copy, but they will not make sure the result is zero terminated, which most programmers would expect who are not familiar with the API. So, in the diet libc you can set this #define in dietfeatures.h to get the expected behaviour. Since the fix for the normal behaviour usually is to write \0 over the last byte of the buffer, this does not hurt usually (but is not standards compliant). 4. printf does not support %n. %n in printf is the attack vector for format string vulnerabilities. Almost nobody uses it anyway (except some part of the gcc build process, apparently). dietlibc-0.33~cvs20120325/SECURITY010064400000000000000000000011711173363226000130730ustar00The diet libc was written with small code and embedded devices in mind, not with security for network servers. Of course we still try to avoid buffer overflows, but there are some parts of the code where tradeoffs have been made. This file is meant to document them. 1. The DNS routines do not check whether the answer came from the IP of the DNS server. The rationale is that people who can sniff the network to find out the query, source port and DNS sequence number can also spoof DNS packets to appear to come from the server we asked, so it does not actually increase security to have that check. dietlibc-0.33~cvs20120325/THANKS010064400000000000000000000027761173363226000126300ustar00The malloc code was done by Olaf Dreesen, who also helped with the SPARC start code and fork(). Olaf also did the printf and scanf routines and he implemented pthreads (wow!) and his now writing a dynamic linker, and he ported the diet libc to S/390. Thomas Ogrisegg ported the diet libc to PA-RISC and IA64 and fixed a few things. I initially took some syscalls from Redhat minilibc, but the code has been completely replaced now. I initially took localtime and the directory reading routines from uClibc, but the code has been completely replaced now. syslog and crypt were contributed by René Müller. Jeff Garzik contributed {get,set}{pw,gr,sp}ent. Uwe Ohse went through the code and fixed many bugs. Frank Klemm contributed the math library and a lot of correctness and smallness patches and rewrote many functions in ix86 assembly language. Erik Troan found several important bugs and sent in patches to fix them. I also grabbed code from glibc (mostly assembly routines), and looked at the OpenBSD libc for inspiration. Michal Ludvig did the porting to x86_64 and Gwenole Beauchesne helped finish the port. Gwenole also reported many bugs and helped with some of the more obscure platforms. Johannes Stezenbach improved the MIPS port. Marian Jancar added s390x and ppc64 support. Gerrit Pape maintains the Debian port and helped immensely by relaying bug reports and doing testing on platforms I didn't have access to. Manuel Novoa III reported many bugs although he really works for the competition, uClibc ;-) dietlibc-0.33~cvs20120325/TODO010064400000000000000000000032651173363226000123770ustar00 - "locale" - real regerror - improve code size and quality with __restrict__. - FPU exception handling (for mawk) - res_mkquery should not assume op is QUERY - syslog - gethost/netent -> parselib? - Look at qsort (the make test suite exhibits the worst case) - Make __dtostr do scientific notation. - fix %g in printf. They are more or less completely b0rken (in particular rounding the last digit does not work). - qmail-queue dumps core since we added vfork. Editing fork.h to #define vfork to fork works. What happens here? - use TCP if buf[2]&2 is non-zero in DNS answers. - look at mktime: "Falls tm_isdst == -1 gesetzt, so sollte mktime versuchen herauszufinden, ob Sommerzeit eingestellt ist (und laut linux manpage auch tzname setzen), ansonsten die angegebene DST berücksichtigen." - better rand()? - try to make zebra compile. - printf %e - move DNS stuff to libresolv.a? - x86_64: readdir fails their test (Gwenole Beauchesne) - regular expressions standards compliance; test suite from AT&T - fgetpwent (needed for cvm) - investigate putting some libgcc symbols in dietlibc.so for gcc<3 - wordexp, wordfree (might as well write a /bin/sh then) implement AI_V4MAPPED in getaddrinfo (not in man page, only susv3) Also: AF_UNSPEC, AI_ADDRCONFIG set_thread_area -> set up TLD, for stack guard lsearch, lfind, hsearch, tsearch getopt configure check fails: { char *argv[3] = { "program", "-ab", NULL }; optind = OPTIND_MIN; opterr = 0; if (getopt (2, argv, "ab:") != 'a') return 13; if (getopt (2, argv, "ab:") != '?') return 14; /* fails here */ if (optopt != 'b') return 15; if (optind != 2) return 16; } dietlibc-0.33~cvs20120325/alpha/Makefile.add010064400000000000000000000002711173363226000151550ustar00 CFLAGS+=-Os -Iinclude -fomit-frame-pointer -fstrict-aliasing VPATH:=alpha:syscalls.s:$(VPATH) LIBOBJ+=$(patsubst %,$(OBJDIR)/%,divq.o divl.o remq.o reml.o __time.o __alarm.o __CAS.o) dietlibc-0.33~cvs20120325/alpha/__CAS.S010064400000000000000000000002561173363226000140210ustar00.text .global __CAS .type __CAS,@function __CAS: mb 1: ldq_l $0,0($16) cmpeq $0,$17,$1 beq $1,2f mov $18,$1 stq_c $1,0($16) beq $1,1b mb 2: ret .size __CAS, .-__CAS dietlibc-0.33~cvs20120325/alpha/__longjmp.S010064400000000000000000000013711173363226000150600ustar00#include .text .align 2 .global __longjmp .type __longjmp,@function __longjmp: mov $17, $0 /* a1 -> v0 */ ldq $9, (JB_S0*8) ($16) /* s0 */ ldq $10, (JB_S1*8) ($16) /* s1 */ ldq $11, (JB_S2*8) ($16) /* s2 */ ldq $12, (JB_S3*8) ($16) /* s3 */ ldq $13, (JB_S4*8) ($16) /* s4 */ ldq $14, (JB_S5*8) ($16) /* s5 */ ldq $26, (JB_PC*8) ($16) /* ra */ ldq $fp, (JB_FP*8) ($16) /* fp */ ldq $sp, (JB_SP*8) ($16) /* sp */ ldt $f2, (JB_F2*8) ($16) /* f2 */ ldt $f3, (JB_F3*8) ($16) /* f3 */ ldt $f4, (JB_F4*8) ($16) /* f4 */ ldt $f5, (JB_F5*8) ($16) /* f5 */ ldt $f6, (JB_F6*8) ($16) /* f6 */ ldt $f7, (JB_F7*8) ($16) /* f7 */ ldt $f8, (JB_F8*8) ($16) /* f8 */ ldt $f9, (JB_F9*8) ($16) /* f9 */ cmoveq $0, 0x1, $0 ret $31, ($26), 1 dietlibc-0.33~cvs20120325/alpha/__pause.c010064400000000000000000000002441173363226000145450ustar00#include #include int pause(void) { sigset_t set; sigemptyset(&set); sigprocmask(SIG_BLOCK, NULL, &set); return sigsuspend(&set); } dietlibc-0.33~cvs20120325/alpha/__testandset.S010064400000000000000000000005231173363226000155660ustar00.text .align 2 .global __testandset .type __testandset,@function __testandset: 1: ldq_l $0, 0($16) /* load lock */ bne $0, 1f /* ok there is a lock... */ lda $0, 1($31) /* load a 1 to register 0 */ stq_c $0, 0($16) /* write lock is locked :) */ beq $0, 1b /* oops someone changed MY lock */ 1: ret $31, ($26), 0x01 /* return */ dietlibc-0.33~cvs20120325/alpha/clone.S010064400000000000000000000010051173363226000142060ustar00#include "syscalls.h" #include .text .align 2 .weak clone clone: .global __clone .type __clone,@function __clone: ldiq $0, EINVAL beq $16, .Lerror beq $17, .Lerror subq $17, 16, $17 stq $16, 0($17) stq $19, 8($17) mov $18, $16 lda $0, __NR_clone($31) callsys bne $19, .Lerror beq $0, .Lstart_thread ret $31, ($26), 0x01 .Lerror: jmp error_unified_syscall .Lstart_thread: clr $fp ldq $27, 0($sp) ldq $16, 8($sp) jsr $26, ($27), 0x04 ldgp $gp, 0($26) mov $0, $16 jsr $26, exit dietlibc-0.33~cvs20120325/alpha/divl.S010064400000000000000000000027171173363226000140570ustar00/* taken from glibc 2.2 */ .set noreorder .set noat .ent __divlu .globl __divlu .align 3 __divlu : lda $30 , - 48 ($30 ) .frame $30 , 48 , $23 , 0 .prologue 0 .Ludiv: stq $1 , 0($30 ) zapnot $25 ,15, $1 stq $2 , 8($30 ) zapnot $24 ,15, $2 stq $0 , 16($30 ) clr $27 stq $3 , 24($30 ) ldiq $0 , 1 stq $4 ,32($30 ) beq $1 , .Ldivbyzero .align 3 1: cmpult $1 , $2 , $at s8addq $1 , $31 , $1 s8addq $0 , $31 , $0 bne $at , 1b 3: addq $27 ,$0 , $4 srl $0 , 1, $0 cmpule $1 , $2 , $at subq $2 , $1 , $3 cmovne $at ,$4 , $27 srl $1 , 1, $1 cmovne $at , $3 , $2 bne $0 , 3b .Ldone: ldq $1 , 0($30 ) ldq $2 , 8($30 ) ldq $0 , 16($30 ) ldq $3 , 24($30 ) ldq $4 ,32($30 ) lda $30 , 48 ($30 ) ret $31 , ($23 ), 1 .Ldivbyzero: mov $16 , $3 ldiq $16 , -2 call_pal 170 mov $3 , $16 clr $27 br .Ldone .end __divlu .ent __divl .globl __divl .align 3 __divl : lda $30 , - 48 ($30 ) .frame $30 , 48 , $23 , 0 .prologue 0 or $24 , $25 , $at sextl $at , $at bge $at , .Ludiv stq $24 , 0($30 ) negl $24 , $at stq $25 , 8($30 ) cmovge $at , $at , $24 stq $23 , 16($30 ) negl $25 , $at stq $3 , 24($30 ) cmovge $at , $at , $25 bsr $23 , __divlu ldq $24 , 0($30 ) ldq $25 , 8($30 ) xor $24 , $25 , $at negl $27 , $3 sextl $at , $at ldq $23 , 16($30 ) cmovlt $at , $3 , $27 ldq $3 , 24($30 ) lda $30 , 48 ($30 ) ret $31 , ($23 ), 1 .end __divl dietlibc-0.33~cvs20120325/alpha/divq.S010064400000000000000000000041221173363226000140540ustar00/* taken from glibc 2.2 */ .set noreorder .set noat .ent __divqu .globl __divqu .align 3 __divqu : lda $30 , - 48 ($30 ) .frame $30 , 48 , $23 , 0 .prologue 0 $udiv: stq $1 , 0($30 ) mov $25 , $1 stq $2 , 8($30 ) mov $24 , $2 stq $0 , 16($30 ) clr $27 stq $3 , 24($30 ) ldiq $0 , 1 stq $4 ,32($30 ) beq $1 , $divbyzero .align 3 1: cmpult $1 , $2 , $at blt $1 , 2f addq $1 , $1 , $1 addq $0 , $0 , $0 bne $at , 1b unop 2: 3: addq $27 ,$0 , $4 srl $0 , 1, $0 cmpule $1 , $2 , $at subq $2 , $1 , $3 cmovne $at ,$4 , $27 srl $1 , 1, $1 cmovne $at , $3 , $2 bne $0 , 3b $done: ldq $1 , 0($30 ) ldq $2 , 8($30 ) ldq $0 , 16($30 ) ldq $3 , 24($30 ) ldq $4 ,32($30 ) lda $30 , 48 ($30 ) ret $31 , ($23 ), 1 $divbyzero: mov $16 , $3 ldiq $16 , -2 call_pal 170 mov $3 , $16 clr $27 br $done .end __divqu .ent __divq .globl __divq .align 3 __divq : lda $30 , - 48 ($30 ) .frame $30 , 48 , $23 , 0 .prologue 0 or $24 , $25 , $at bge $at , $udiv stq $24 , 0($30 ) negq $24 , $at stq $25 , 8($30 ) cmovge $at , $at , $24 stq $23 , 16($30 ) negq $25 , $at stq $3 , 24($30 ) cmovge $at , $at , $25 bsr $23 , __divqu ldq $24 , 0($30 ) ldq $25 , 8($30 ) xor $24 , $25 , $at negq $27 , $3 ldq $23 , 16($30 ) cmovlt $at , $3 , $27 ldq $3 , 24($30 ) lda $30 , 48 ($30 ) ret $31 , ($23 ), 1 .end __divq dietlibc-0.33~cvs20120325/alpha/errlist.S010064400000000000000000000170031173363226000145770ustar00#ifdef __DYN_LIB .section .data #else .section .rodata #endif .align 8 .global sys_errlist .type sys_errlist,@object sys_errlist: .quad .LC000 .quad .LC001 .quad .LC002 .quad .LC003 .quad .LC004 .quad .LC005 .quad .LC006 .quad .LC007 .quad .LC008 .quad .LC009 .quad .LC010 .quad .LC011 .quad .LC012 .quad .LC013 .quad .LC014 .quad .LC015 .quad .LC016 .quad .LC017 .quad .LC018 .quad .LC019 .quad .LC020 .quad .LC021 .quad .LC022 .quad .LC023 .quad .LC024 .quad .LC025 .quad .LC026 .quad .LC027 .quad .LC028 .quad .LC029 .quad .LC030 .quad .LC031 .quad .LC032 .quad .LC033 .quad .LC034 .quad .LC035 .quad .LC036 .quad .LC037 .quad .LC038 .quad .LC039 .quad .LC040 .quad .LC041 .quad .LC042 .quad .LC043 .quad .LC044 .quad .LC045 .quad .LC046 .quad .LC047 .quad .LC048 .quad .LC049 .quad .LC050 .quad .LC051 .quad .LC052 .quad .LC053 .quad .LC054 .quad .LC055 .quad .LC056 .quad .LC057 .quad .LC058 .quad .LC059 .quad .LC060 .quad .LC061 .quad .LC062 .quad .LC063 .quad .LC064 .quad .LC065 .quad .LC066 .quad .LC067 .quad .LC068 .quad .LC069 .quad .LC070 .quad .LC071 .quad .LC072 .quad .LC073 .quad .LC074 .quad .LC075 .quad .LC076 .quad .LC077 .quad .LC078 .quad .LC079 .quad .LC080 .quad .LC081 .quad .LC082 .quad .LC083 .quad .LC084 .quad .LC085 .quad .LC086 .quad .LC087 .quad .LC088 .quad .LC089 .quad .LC090 .quad .LC091 .quad .LC092 .quad .LC093 .quad .LC094 .quad .LC095 .quad .LC096 .quad .LC097 .quad .LC098 .quad .LC099 .quad .LC100 .quad .LC101 .quad .LC102 .quad .LC103 .quad .LC104 .quad .LC105 .quad .LC106 .quad .LC107 .quad .LC108 .quad .LC109 .quad .LC110 .quad .LC111 .quad .LC112 .quad .LC113 .quad .LC114 .quad .LC115 .quad .LC116 .quad .LC117 .quad .LC118 .quad .LC119 .quad .LC120 .quad .LC121 .quad .LC122 .quad .LC123 .quad .LC124 .quad .LC125 .quad .LC126 .quad .LC127 .quad .LC128 .quad .LC129 .quad .LC130 .quad .LC131 .quad .LC132 .quad .LC133 .quad .LC134 .quad .LC135 .quad 0 .size sys_errlist,.-sys_errlist .align 4 .global sys_nerr .type sys_nerr,@object sys_nerr: .long 130 .size sys_nerr,4 #ifdef __DYN_LIB .section .rodata #endif .LC000: .string "Success" .LC001: .string "Operation not permitted" .LC002: .string "No such file or directory" .LC003: .string "No such process" .LC004: .string "Interrupted system call" .LC005: .string "I/O error" .LC006: .string "No such device or address" .LC007: .string "Arg list too long" .LC008: .string "Exec format error" .LC009: .string "Bad file number" .LC010: .string "No child processes" .LC011: .string "Resource deadlock would occur" .LC012: .string "Out of memory" .LC013: .string "Permission denied" .LC014: .string "Bad address" .LC015: .string "Block device required" .LC016: .string "Device or resource busy" .LC017: .string "File exists" .LC018: .string "Cross-device link" .LC019: .string "No such device" .LC020: .string "Not a directory" .LC021: .string "Is a directory" .LC022: .string "Invalid argument" .LC023: .string "File table overflow" .LC024: .string "Too many open files" .LC025: .string "Not a typewriter" .LC026: .string "Text file busy" .LC027: .string "File too large" .LC028: .string "No space left on device" .LC029: .string "Illegal seek" .LC030: .string "Read-only file system" .LC031: .string "Too many links" .LC032: .string "Broken pipe" .LC033: .string "Math argument out of domain of func" .LC034: .string "Math result not representable" .LC035: .string "Try again" .LC036: .string "Operation now in progress" .LC037: .string "Operation already in progress" .LC038: .string "Socket operation on non-socket" .LC039: .string "Destination address required" .LC040: .string "Message too long" .LC041: .string "Protocol wrong type for socket" .LC042: .string "Protocol not available" .LC043: .string "Protocol not supported" .LC044: .string "Socket type not supported" .LC045: .string "Operation not supported on transport endpoint" .LC046: .string "Protocol family not supported" .LC047: .string "Address family not supported by protocol" .LC048: .string "Address already in use" .LC049: .string "Cannot assign requested address" .LC050: .string "Network is down" .LC051: .string "Network is unreachable" .LC052: .string "Network dropped connection because of reset" .LC053: .string "Software caused connection abort" .LC054: .string "Connection reset by peer" .LC055: .string "No buffer space available" .LC056: .string "Transport endpoint is already connected" .LC057: .string "Transport endpoint is not connected" .LC058: .string "Cannot send after transport endpoint shutdown" .LC059: .string "Too many references: cannot splice" .LC060: .string "Connection timed out" .LC061: .string "Connection refused" .LC062: .string "Too many symbolic links encountered" .LC063: .string "File name too long" .LC064: .string "Host is down" .LC065: .string "No route to host" .LC066: .string "Directory not empty" .LC067: .string "Error 67" .LC068: .string "Too many users" .LC069: .string "Quota exceeded" .LC070: .string "Stale NFS file handle" .LC071: .string "Object is remote" .LC072: .string "Error 72" .LC073: .string "Error 73" .LC074: .string "Error 74" .LC075: .string "Error 75" .LC076: .string "Error 76" .LC077: .string "No record locks available" .LC078: .string "Function not implemented" .LC079: .string "Error 79" .LC080: .string "No message of desired type" .LC081: .string "Identifier removed" .LC082: .string "Out of streams resources" .LC083: .string "Timer expired" .LC084: .string "Not a data message" .LC085: .string "Protocol error" .LC086: .string "No data available" .LC087: .string "Device not a stream" .LC088: .string "Channel number out of range" .LC089: .string "Level 2 not synchronized" .LC090: .string "Level 3 halted" .LC091: .string "Level 3 reset" .LC092: .string "Package not installed" .LC093: .string "Link number out of range" .LC094: .string "Protocol driver not attached" .LC095: .string "No CSI structure available" .LC096: .string "Level 2 halted" .LC097: .string "Invalid exchange" .LC098: .string "Invalid request descriptor" .LC099: .string "Exchange full" .LC100: .string "No anode" .LC101: .string "Invalid request code" .LC102: .string "Invalid slot" .LC103: .string "Error 103" .LC104: .string "Bad font file format" .LC105: .string "Machine is not on the network" .LC106: .string "Link has been severed" .LC107: .string "Advertise error" .LC108: .string "Srmount error" .LC109: .string "Communication error on send" .LC110: .string "Multihop attempted" .LC111: .string "RFS specific error" .LC112: .string "Value too large for defined data type" .LC113: .string "Name not unique on network" .LC114: .string "File descriptor in bad state" .LC115: .string "Remote address changed" .LC116: .string "Illegal byte sequence" .LC117: .string "Structure needs cleaning" .LC118: .string "Not a XENIX named type file" .LC119: .string "No XENIX semaphores available" .LC120: .string "Is a named type file" .LC121: .string "Remote I/O error" .LC122: .string "Can not access a needed shared library" .LC123: .string "Accessing a corrupted shared library" .LC124: .string ".lib section in a.out corrupted" .LC125: .string "Attempting to link in too many shared libraries" .LC126: .string "Cannot exec a shared library directly" .LC127: .string "Interrupted system call should be restarted" .LC128: .string "Streams pipe error" .LC129: .string "No medium found" .LC130: .string "Wrong medium type" .LC131: .string "Operation canceled" .LC132: .string "Required key not available" .LC133: .string "Key has expired" .LC134: .string "Key has been revoked" .LC135: .string "Key was rejected by service" dietlibc-0.33~cvs20120325/alpha/getegid.S010064400000000000000000000002211173363226000145150ustar00.text .align 2 .global getegid getegid: lda $sp,-8($sp) stq $26, 0($sp) jsr getgid ldq $26, 0($sp) lda $sp, 8($sp) cmovge $0, $20, $0 ret dietlibc-0.33~cvs20120325/alpha/geteuid.S010064400000000000000000000002211173363226000145330ustar00.text .align 2 .global geteuid geteuid: lda $sp,-8($sp) stq $26, 0($sp) jsr getuid ldq $26, 0($sp) lda $sp, 8($sp) cmovge $0, $20, $0 ret dietlibc-0.33~cvs20120325/alpha/getgid.S010064400000000000000000000000571173363226000143570ustar00#include "syscalls.h" syscall(getxgid,getgid) dietlibc-0.33~cvs20120325/alpha/getpid.S010064400000000000000000000000571173363226000143700ustar00#include "syscalls.h" syscall(getxpid,getpid) dietlibc-0.33~cvs20120325/alpha/getppid.S010064400000000000000000000002211173363226000145410ustar00.text .align 2 .global getppid getppid: lda $sp,-8($sp) stq $26, 0($sp) jsr getpid ldq $26, 0($sp) lda $sp, 8($sp) cmovge $0, $20, $0 ret dietlibc-0.33~cvs20120325/alpha/getsockopt.S010064400000000000000000000000661173363226000152760ustar00#include "syscalls.h" syscall(getsockopt,getsockopt) dietlibc-0.33~cvs20120325/alpha/getuid.S010064400000000000000000000000571173363226000143750ustar00#include "syscalls.h" syscall(getxuid,getuid) dietlibc-0.33~cvs20120325/alpha/lseek64.S010064400000000000000000000000721173363226000143660ustar00#include "syscalls.h" .global lseek64 lseek64: br lseek dietlibc-0.33~cvs20120325/alpha/msgctl.S010064400000000000000000000000561173363226000144040ustar00#include "syscalls.h" syscall(msgctl,msgctl) dietlibc-0.33~cvs20120325/alpha/msgget.S010064400000000000000000000000561173363226000144010ustar00#include "syscalls.h" syscall(msgget,msgget) dietlibc-0.33~cvs20120325/alpha/msgrcv.S010064400000000000000000000000561173363226000144140ustar00#include "syscalls.h" syscall(msgrcv,msgrcv) dietlibc-0.33~cvs20120325/alpha/msgsnd.S010064400000000000000000000000561173363226000144060ustar00#include "syscalls.h" syscall(msgsnd,msgsnd) dietlibc-0.33~cvs20120325/alpha/n_sigprocmask.S010064400000000000000000000001271173363226000157510ustar00#include "syscalls.h" syscall_weak(osf_sigprocmask,__old_sigprocmask,__n_sigprocmask) dietlibc-0.33~cvs20120325/alpha/pipe.S010064400000000000000000000004721173363226000140520ustar00#include "syscalls.h" .text .align 2 .global pipe .type pipe,@function pipe: lda $0, __NR_pipe($31) callsys bne $19, .Lerror stl $0, 0($16) stl $20, 4($16) clr $0 ret $31, ($26), 0x01 .Lerror: br error_unified_syscall dietlibc-0.33~cvs20120325/alpha/reml.S010064400000000000000000000025131173363226000140520ustar00/* taken from glibc 2.2 */ .set noreorder .set noat .ent __remlu .globl __remlu .align 3 __remlu : lda $30 , -32($30) .frame $30 , 32 , $23 , 0 .prologue 0 .Ludiv: stq $1 , 0($30) zapnot $25 , 15 , $1 stq $2 , 8($30) zapnot $24 , 15 , $27 stq $0 , 16($30) clr $2 stq $3 , 24($30) ldiq $0 , 1 beq $1 , .Ldivbyzero .align 3 1: cmpult $1 , $27 , $at s8addq $1 , $31 , $1 s8addq $0 , $31 , $0 bne $at , 1b 3: srl $0 , 1 , $0 cmpule $1 , $27 , $at subq $27 , $1 , $3 srl $1 , 1 , $1 cmovne $at , $3 , $27 bne $0 , 3b .Ldone: ldq $1 , 0($30) ldq $2 , 8($30) ldq $0 , 16($30) ldq $3 , 24($30) lda $30 , 32($30) ret $31 , ($23), 1 .Ldivbyzero: mov $16 , $3 ldiq $16 , -2 call_pal 170 mov $3 , $16 clr $27 br .Ldone .end __remlu .ent __reml .globl __reml .align 3 __reml : lda $30 , - 32 ($30 ) .frame $30 , 32 , $23 , 0 .prologue 0 or $24 , $25 , $at sextl $at , $at bge $at , .Ludiv stq $24 , 0($30 ) negl $24 , $at stq $25 , 8($30 ) cmovge $at , $at , $24 stq $23 , 16($30 ) negl $25 , $at stq $3 , 24($30 ) cmovge $at , $at , $25 bsr $23 , __remlu ldq $24 , 0($30 ) ldq $25 , 8($30 ) mov $24 , $at negl $27 , $3 sextl $at , $at ldq $23 , 16($30 ) cmovlt $at , $3 , $27 ldq $3 , 24($30 ) lda $30 , 32 ($30 ) ret $31 , ($23 ), 1 .end __reml dietlibc-0.33~cvs20120325/alpha/remq.S010064400000000000000000000024741173363226000140650ustar00/* taken from glibc 2.2 */ .set noreorder .set noat .ent __remqu .globl __remqu .align 3 __remqu : lda $30 , - 32 ($30 ) .frame $30 , 32 , $23 , 0 .prologue 0 .Ludiv: stq $1 , 0($30 ) mov $25 , $1 stq $2 , 8($30 ) mov $24 , $27 stq $0 , 16($30 ) clr $2 stq $3 , 24($30 ) ldiq $0 , 1 beq $1 , .Ldivbyzero .align 3 1: cmpult $1 , $27 , $at blt $1 , 2f addq $1 , $1 , $1 addq $0 , $0 , $0 bne $at , 1b unop 2: 3: srl $0 , 1, $0 cmpule $1 , $27 , $at subq $27 , $1 , $3 srl $1 , 1, $1 cmovne $at , $3 , $27 bne $0 , 3b .Ldone: ldq $1 , 0($30 ) ldq $2 , 8($30 ) ldq $0 , 16($30 ) ldq $3 , 24($30 ) lda $30 , 32 ($30 ) ret $31 , ($23 ), 1 .Ldivbyzero: mov $16 , $3 ldiq $16 , -2 call_pal 170 mov $3 , $16 clr $27 br .Ldone .end __remqu .ent __remq .globl __remq .align 3 __remq : lda $30 , - 32 ($30 ) .frame $30 , 32 , $23 , 0 .prologue 0 or $24 , $25 , $at bge $at , .Ludiv stq $24 , 0($30 ) negq $24 , $at stq $25 , 8($30 ) cmovge $at , $at , $24 stq $23 , 16($30 ) negq $25 , $at stq $3 , 24($30 ) cmovge $at , $at , $25 bsr $23 , __remqu ldq $24 , 0($30 ) ldq $25 , 8($30 ) mov $24 , $at negq $27 , $3 ldq $23 , 16($30 ) cmovlt $at , $3 , $27 ldq $3 , 24($30 ) lda $30 , 32 ($30 ) ret $31 , ($23 ), 1 .end __remq dietlibc-0.33~cvs20120325/alpha/semctl.S010064400000000000000000000000561173363226000144020ustar00#include "syscalls.h" syscall(semctl,semctl) dietlibc-0.33~cvs20120325/alpha/semget.S010064400000000000000000000000561173363226000143770ustar00#include "syscalls.h" syscall(semget,semget) dietlibc-0.33~cvs20120325/alpha/semop.S010064400000000000000000000000541173363226000142340ustar00#include "syscalls.h" syscall(semop,semop) dietlibc-0.33~cvs20120325/alpha/seteuid.c010064400000000000000000000002141173363226000145710ustar00#include #include #undef seteuid int seteuid(uid_t euid); int seteuid(uid_t euid) { return setreuid(-1,euid); } dietlibc-0.33~cvs20120325/alpha/setjmp.S010064400000000000000000000015111173363226000144120ustar00#include .text .weak setjmp .type setjmp,@function setjmp: .weak __setjmp .type __setjmp,@function __setjmp: mov 0, $17 .global __sigsetjmp .type __sigsetjmp,@function __sigsetjmp: stq $9, (JB_S0*8) ($16) /* s0 */ stq $10, (JB_S1*8) ($16) /* s1 */ stq $11, (JB_S2*8) ($16) /* s2 */ stq $12, (JB_S3*8) ($16) /* s3 */ stq $13, (JB_S4*8) ($16) /* s4 */ stq $14, (JB_S5*8) ($16) /* s5 */ stq $26, (JB_PC*8) ($16) /* ra */ stq $fp, (JB_FP*8) ($16) /* fp */ stq $sp, (JB_SP*8) ($16) /* sp */ stt $f2, (JB_F2*8) ($16) /* f2 */ stt $f3, (JB_F3*8) ($16) /* f3 */ stt $f4, (JB_F4*8) ($16) /* f4 */ stt $f5, (JB_F5*8) ($16) /* f5 */ stt $f6, (JB_F6*8) ($16) /* f6 */ stt $f7, (JB_F7*8) ($16) /* f7 */ stt $f8, (JB_F8*8) ($16) /* f8 */ stt $f9, (JB_F9*8) ($16) /* f9 */ br $31, __sigjmp_save /* jmp __sigjmp_save */ dietlibc-0.33~cvs20120325/alpha/setsockopt.S010064400000000000000000000000661173363226000153120ustar00#include "syscalls.h" syscall(setsockopt,setsockopt) dietlibc-0.33~cvs20120325/alpha/shmat.S010064400000000000000000000000541173363226000142250ustar00#include "syscalls.h" syscall(shmat,shmat) dietlibc-0.33~cvs20120325/alpha/shmctl.S010064400000000000000000000000561173363226000144050ustar00#include "syscalls.h" syscall(shmctl,shmctl) dietlibc-0.33~cvs20120325/alpha/shmdt.S010064400000000000000000000000541173363226000142300ustar00#include "syscalls.h" syscall(shmdt,shmdt) dietlibc-0.33~cvs20120325/alpha/shmget.S010064400000000000000000000000561173363226000144020ustar00#include "syscalls.h" syscall(shmget,shmget) dietlibc-0.33~cvs20120325/alpha/sigaction.c010064400000000000000000000007701173363226000151160ustar00#include int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, long nr, void* restorer); int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { return __rt_sigaction(signum, act, oldact, _NSIG/8, 0); } int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) __attribute__((weak,alias("__libc_sigaction"))); dietlibc-0.33~cvs20120325/alpha/socketcall.S010064400000000000000000000001371173363226000152370ustar00#include "syscalls.h" /* * Doesn't exist on alpha ( accept, bind, ... are SYSCALLS !?! ) */ dietlibc-0.33~cvs20120325/alpha/start.S010064400000000000000000000012341173363226000142470ustar00#include "dietfeatures.h" .text .align 2 .set noreorder .global __start __start: .global _start _start: clr $fp /* clear frame pointer */ br $gp,.Lstart /* set global pointer */ .Lstart: ldgp $gp, 0($gp) /* prepare to call main */ ldl $16, 0($sp) /* argc / a0 */ lda $17, 8($sp) /* argv / a1 */ addq $16, 1, $18 /* argp / a2 */ s8addq $18, $17, $18 /* (8*(argc+1))+argv -> argp */ stq $18, environ #ifdef WANT_DYNAMIC /* in v0 ($0) is the ld.so _fini pointer */ mov $0, $19 /* mov v0(dynload) to a3 */ jsr $26, _dyn_start #else jsr $26, CALL_IN_STARTCODE #endif mov $0, $16 jsr $26, exit /* YES, CALL! for threads and atexit ! (+4 byte) */ dietlibc-0.33~cvs20120325/alpha/syscalls.h010064400000000000000000000325631173363226000150050ustar00 #define __NR_osf_syscall 0 /* not implemented */ #define __NR_exit 1 #define __NR_fork 2 #define __NR_read 3 #define __NR_write 4 #define __NR_osf_old_open 5 /* not implemented */ #define __NR_close 6 #define __NR_osf_wait4 7 #define __NR_osf_old_creat 8 /* not implemented */ #define __NR_link 9 #define __NR_unlink 10 #define __NR_osf_execve 11 /* not implemented */ #define __NR_chdir 12 #define __NR_fchdir 13 #define __NR_mknod 14 #define __NR_chmod 15 #define __NR_chown 16 #define __NR_brk 17 #define __NR_osf_getfsstat 18 /* not implemented */ #define __NR_lseek 19 #define __NR_getxpid 20 #define __NR_osf_mount 21 #define __NR_umount 22 #define __NR_setuid 23 #define __NR_getxuid 24 #define __NR_exec_with_loader 25 /* not implemented */ #define __NR_ptrace 26 #define __NR_osf_nrecvmsg 27 /* not implemented */ #define __NR_osf_nsendmsg 28 /* not implemented */ #define __NR_osf_nrecvfrom 29 /* not implemented */ #define __NR_osf_naccept 30 /* not implemented */ #define __NR_osf_ngetpeername 31 /* not implemented */ #define __NR_osf_ngetsockname 32 /* not implemented */ #define __NR_access 33 #define __NR_osf_chflags 34 /* not implemented */ #define __NR_osf_fchflags 35 /* not implemented */ #define __NR_sync 36 #define __NR_kill 37 #define __NR_osf_old_stat 38 /* not implemented */ #define __NR_setpgid 39 #define __NR_osf_old_lstat 40 /* not implemented */ #define __NR_dup 41 #define __NR_pipe 42 #define __NR_osf_set_program_attributes 43 #define __NR_osf_profil 44 /* not implemented */ #define __NR_open 45 #define __NR_osf_old_sigaction 46 /* not implemented */ #define __NR_getxgid 47 #define __NR_osf_sigprocmask 48 #define __NR_osf_getlogin 49 /* not implemented */ #define __NR_osf_setlogin 50 /* not implemented */ #define __NR_acct 51 #define __NR_sigpending 52 #define __NR_ioctl 54 #define __NR_osf_reboot 55 /* not implemented */ #define __NR_osf_revoke 56 /* not implemented */ #define __NR_symlink 57 #define __NR_readlink 58 #define __NR_execve 59 #define __NR_umask 60 #define __NR_chroot 61 #define __NR_osf_old_fstat 62 /* not implemented */ #define __NR_getpgrp 63 #define __NR_getpagesize 64 #define __NR_osf_mremap 65 /* not implemented */ #define __NR_vfork 66 #define __NR_stat 67 #define __NR_lstat 68 #define __NR_osf_sbrk 69 /* not implemented */ #define __NR_osf_sstk 70 /* not implemented */ #define __NR_mmap 71 /* OSF/1 mmap is superset of Linux */ #define __NR_osf_old_vadvise 72 /* not implemented */ #define __NR_munmap 73 #define __NR_mprotect 74 #define __NR_madvise 75 #define __NR_vhangup 76 #define __NR_osf_kmodcall 77 /* not implemented */ #define __NR_osf_mincore 78 /* not implemented */ #define __NR_getgroups 79 #define __NR_setgroups 80 #define __NR_osf_old_getpgrp 81 /* not implemented */ #define __NR_setpgrp 82 /* BSD alias for setpgid */ #define __NR_osf_setitimer 83 #define __NR_osf_old_wait 84 /* not implemented */ #define __NR_osf_table 85 /* not implemented */ #define __NR_osf_getitimer 86 #define __NR_gethostname 87 #define __NR_sethostname 88 #define __NR_getdtablesize 89 #define __NR_dup2 90 #define __NR_fstat 91 #define __NR_fcntl 92 #define __NR_osf_select 93 #define __NR_poll 94 #define __NR_fsync 95 #define __NR_setpriority 96 #define __NR_socket 97 #define __NR_connect 98 #define __NR_accept 99 #define __NR_getpriority 100 #define __NR_send 101 #define __NR_recv 102 #define __NR_sigreturn 103 #define __NR_bind 104 #define __NR_setsockopt 105 #define __NR_listen 106 #define __NR_osf_plock 107 /* not implemented */ #define __NR_osf_old_sigvec 108 /* not implemented */ #define __NR_osf_old_sigblock 109 /* not implemented */ #define __NR_osf_old_sigsetmask 110 /* not implemented */ #define __NR_sigsuspend 111 #define __NR_osf_sigstack 112 #define __NR_recvmsg 113 #define __NR_sendmsg 114 #define __NR_osf_old_vtrace 115 /* not implemented */ #define __NR_osf_gettimeofday 116 #define __NR_osf_getrusage 117 #define __NR_getsockopt 118 #define __NR_readv 120 #define __NR_writev 121 #define __NR_osf_settimeofday 122 #define __NR_fchown 123 #define __NR_fchmod 124 #define __NR_recvfrom 125 #define __NR_setreuid 126 #define __NR_setregid 127 #define __NR_rename 128 #define __NR_truncate 129 #define __NR_ftruncate 130 #define __NR_flock 131 #define __NR_setgid 132 #define __NR_sendto 133 #define __NR_shutdown 134 #define __NR_socketpair 135 #define __NR_mkdir 136 #define __NR_rmdir 137 #define __NR_osf_utimes 138 #define __NR_osf_old_sigreturn 139 /* not implemented */ #define __NR_osf_adjtime 140 /* not implemented */ #define __NR_getpeername 141 #define __NR_osf_gethostid 142 /* not implemented */ #define __NR_osf_sethostid 143 /* not implemented */ #define __NR_getrlimit 144 #define __NR_setrlimit 145 #define __NR_osf_old_killpg 146 /* not implemented */ #define __NR_setsid 147 #define __NR_quotactl 148 #define __NR_osf_oldquota 149 /* not implemented */ #define __NR_getsockname 150 #define __NR_osf_pid_block 153 /* not implemented */ #define __NR_osf_pid_unblock 154 /* not implemented */ #define __NR_sigaction 156 #define __NR_osf_sigwaitprim 157 /* not implemented */ #define __NR_osf_nfssvc 158 /* not implemented */ #define __NR_osf_getdirentries 159 #define __NR_osf_statfs 160 #define __NR_osf_fstatfs 161 #define __NR_osf_asynch_daemon 163 /* not implemented */ #define __NR_osf_getfh 164 /* not implemented */ #define __NR_osf_getdomainname 165 #define __NR_setdomainname 166 #define __NR_osf_exportfs 169 /* not implemented */ #define __NR_osf_alt_plock 181 /* not implemented */ #define __NR_osf_getmnt 184 /* not implemented */ #define __NR_osf_alt_sigpending 187 /* not implemented */ #define __NR_osf_alt_setsid 188 /* not implemented */ #define __NR_osf_swapon 199 #define __NR_msgctl 200 #define __NR_msgget 201 #define __NR_msgrcv 202 #define __NR_msgsnd 203 #define __NR_semctl 204 #define __NR_semget 205 #define __NR_semop 206 #define __NR_osf_utsname 207 #define __NR_lchown 208 #define __NR_osf_shmat 209 #define __NR_shmctl 210 #define __NR_shmdt 211 #define __NR_shmget 212 #define __NR_osf_mvalid 213 /* not implemented */ #define __NR_osf_getaddressconf 214 /* not implemented */ #define __NR_osf_msleep 215 /* not implemented */ #define __NR_osf_mwakeup 216 /* not implemented */ #define __NR_msync 217 #define __NR_osf_signal 218 /* not implemented */ #define __NR_osf_utc_gettime 219 /* not implemented */ #define __NR_osf_utc_adjtime 220 /* not implemented */ #define __NR_osf_security 222 /* not implemented */ #define __NR_osf_kloadcall 223 /* not implemented */ #define __NR_getpgid 233 #define __NR_getsid 234 #define __NR_sigaltstack 235 #define __NR_osf_waitid 236 /* not implemented */ #define __NR_osf_priocntlset 237 /* not implemented */ #define __NR_osf_sigsendset 238 /* not implemented */ #define __NR_osf_set_speculative 239 /* not implemented */ #define __NR_osf_msfs_syscall 240 /* not implemented */ #define __NR_osf_sysinfo 241 #define __NR_osf_uadmin 242 /* not implemented */ #define __NR_osf_fuser 243 /* not implemented */ #define __NR_osf_proplist_syscall 244 #define __NR_osf_ntp_adjtime 245 /* not implemented */ #define __NR_osf_ntp_gettime 246 /* not implemented */ #define __NR_osf_pathconf 247 /* not implemented */ #define __NR_osf_fpathconf 248 /* not implemented */ #define __NR_osf_uswitch 250 /* not implemented */ #define __NR_osf_usleep_thread 251 #define __NR_osf_audcntl 252 /* not implemented */ #define __NR_osf_audgen 253 /* not implemented */ #define __NR_sysfs 254 #define __NR_osf_subsys_info 255 /* not implemented */ #define __NR_osf_getsysinfo 256 #define __NR_osf_setsysinfo 257 #define __NR_osf_afs_syscall 258 /* not implemented */ #define __NR_osf_swapctl 259 /* not implemented */ #define __NR_osf_memcntl 260 /* not implemented */ #define __NR_osf_fdatasync 261 /* not implemented */ /* * Linux-specific system calls begin at 300 */ #define __NR_bdflush 300 #define __NR_sethae 301 #define __NR_mount 302 #define __NR_old_adjtimex 303 #define __NR_swapoff 304 #define __NR_getdents 305 #define __NR_create_module 306 #define __NR_init_module 307 #define __NR_delete_module 308 #define __NR_get_kernel_syms 309 #define __NR_syslog 310 #define __NR_reboot 311 #define __NR_clone 312 #define __NR_uselib 313 #define __NR_mlock 314 #define __NR_munlock 315 #define __NR_mlockall 316 #define __NR_munlockall 317 #define __NR_sysinfo 318 #define __NR__sysctl 319 /* 320 was sys_idle. */ #define __NR_oldumount 321 #define __NR_swapon 322 #define __NR_times 323 #define __NR_personality 324 #define __NR_setfsuid 325 #define __NR_setfsgid 326 #define __NR_ustat 327 #define __NR_statfs 328 #define __NR_fstatfs 329 #define __NR_sched_setparam 330 #define __NR_sched_getparam 331 #define __NR_sched_setscheduler 332 #define __NR_sched_getscheduler 333 #define __NR_sched_yield 334 #define __NR_sched_get_priority_max 335 #define __NR_sched_get_priority_min 336 #define __NR_sched_rr_get_interval 337 #define __NR_afs_syscall 338 #define __NR_uname 339 #define __NR_nanosleep 340 #define __NR_mremap 341 #define __NR_nfsservctl 342 #define __NR_setresuid 343 #define __NR_getresuid 344 #define __NR_pciconfig_read 345 #define __NR_pciconfig_write 346 #define __NR_query_module 347 #define __NR_prctl 348 #define __NR_pread 349 #define __NR_pwrite 350 #define __NR_rt_sigreturn 351 #define __NR_rt_sigaction 352 #define __NR_rt_sigprocmask 353 #define __NR_rt_sigpending 354 #define __NR_rt_sigtimedwait 355 #define __NR_rt_sigqueueinfo 356 #define __NR_rt_sigsuspend 357 #define __NR_select 358 #define __NR_gettimeofday 359 #define __NR_settimeofday 360 #define __NR_getitimer 361 #define __NR_setitimer 362 #define __NR_utimes 363 #define __NR_getrusage 364 #define __NR_wait4 365 #define __NR_adjtimex 366 #define __NR_getcwd 367 #define __NR_capget 368 #define __NR_capset 369 #define __NR_sendfile 370 #define __NR_setresgid 371 #define __NR_getresgid 372 #define __NR_dipc 373 #define __NR_pivot_root 374 #define __NR_mincore 375 #define __NR_pciconfig_iobase 376 #define __NR_getdents64 377 #define __NR_gettid 378 #define __NR_readahead 379 /* 380 is unused */ #define __NR_tkill 381 #define __NR_setxattr 382 #define __NR_lsetxattr 383 #define __NR_fsetxattr 384 #define __NR_getxattr 385 #define __NR_lgetxattr 386 #define __NR_fgetxattr 387 #define __NR_listxattr 388 #define __NR_llistxattr 389 #define __NR_flistxattr 390 #define __NR_removexattr 391 #define __NR_lremovexattr 392 #define __NR_fremovexattr 393 #define __NR_futex 394 #define __NR_sched_setaffinity 395 #define __NR_sched_getaffinity 396 #define __NR_tuxcall 397 #define __NR_io_setup 398 #define __NR_io_destroy 399 #define __NR_io_getevents 400 #define __NR_io_submit 401 #define __NR_io_cancel 402 #define __NR_exit_group 405 #define __NR_lookup_dcookie 406 #define __NR_sys_epoll_create 407 #define __NR_sys_epoll_ctl 408 #define __NR_sys_epoll_wait 409 #define __NR_remap_file_pages 410 #define __NR_set_tid_address 411 #define __NR_restart_syscall 412 #define __NR_fadvise64 413 #define __NR_timer_create 414 #define __NR_timer_settime 415 #define __NR_timer_gettime 416 #define __NR_timer_getoverrun 417 #define __NR_timer_delete 418 #define __NR_clock_settime 419 #define __NR_clock_gettime 420 #define __NR_clock_getres 421 #define __NR_clock_nanosleep 422 #define __NR_semtimedop 423 #define __NR_tgkill 424 #define __NR_stat64 425 #define __NR_lstat64 426 #define __NR_fstat64 427 #define __NR_vserver 428 #define __NR_mbind 429 #define __NR_get_mempolicy 430 #define __NR_set_mempolicy 431 #define __NR_mq_open 432 #define __NR_mq_unlink 433 #define __NR_mq_timedsend 434 #define __NR_mq_timedreceive 435 #define __NR_mq_notify 436 #define __NR_mq_getsetattr 437 #define __NR_waitid 438 #define __NR_add_key 439 #define __NR_request_key 440 #define __NR_keyctl 441 #define __NR_ioprio_set 442 #define __NR_ioprio_get 443 #define __NR_inotify_init 444 #define __NR_inotify_add_watch 445 #define __NR_inotify_rm_watch 446 #define __NR_fdatasync 447 #define __NR_kexec_load 448 #define __NR_migrate_pages 449 #define __NR_openat 450 #define __NR_mkdirat 451 #define __NR_mknodat 452 #define __NR_fchownat 453 #define __NR_futimesat 454 #define __NR_fstatat64 455 #define __NR_unlinkat 456 #define __NR_renameat 457 #define __NR_linkat 458 #define __NR_symlinkat 459 #define __NR_readlinkat 460 #define __NR_fchmodat 461 #define __NR_faccessat 462 #define __NR_pselect6 463 #define __NR_ppoll 464 #define __NR_unshare 465 #define __NR_set_robust_list 466 #define __NR_get_robust_list 467 #define __NR_splice 468 #define __NR_sync_file_range 469 #define __NR_tee 470 #define __NR_vmsplice 471 #define __NR_move_pages 472 #define __NR_getcpu 473 #define __NR_epoll_pwait 474 #define __NR_utimensat 475 #define __NR_signalfd 476 #define __NR_timerfd 477 #define __NR_eventfd 478 #define syscall_weak(name,wsym,sym) \ .text ; \ .align 2 ; \ .weak wsym; \ .type wsym,@function ; \ wsym: ; \ .global sym ; \ .type sym,@function ; \ sym: ; \ lda $0, __NR_##name($31) ; \ br __unified_syscall #define syscall(name,sym) \ .text ; \ .align 2 ; \ .global sym ; \ .type sym,@function ; \ sym: ; \ lda $0, __NR_##name($31) ; \ br __unified_syscall dietlibc-0.33~cvs20120325/alpha/time.S010064400000000000000000000000001173363226000140360ustar00dietlibc-0.33~cvs20120325/alpha/unified.S010064400000000000000000000015211173363226000145340ustar00#include #include "syscalls.h" .weak exit exit: .global _exit _exit: lda $0, __NR_exit .global __unified_syscall __unified_syscall: callsys bne $19, .Lerror /* here we go and "reuse" the return for weak-void functions */ #include "dietuglyweaks.h" ret $31, ($26), 0x01 .Lerror: .global error_unified_syscall error_unified_syscall: #ifdef WANT_THREAD_SAFE lda $sp, -16($sp) /* alloc 2 qwords on stack */ stq $26, 0($sp) /* save ra to stack */ stq $0, 8($sp) /* save v0 to stack */ jsr $26, __errno_location /* call __errno_location */ ldq $1, 8($sp) /* write old v0 to errno */ stl $1, 0($0) lda $0, -1($31) /* new return value is -1 */ ldq $26, 0($sp) /* restore return address */ lda $sp, 16($sp) /* free 2 qwords on stack */ #else lda $1, errno stl $0, 0($1) #endif ret $31, ($26), 0x01 /* return */ dietlibc-0.33~cvs20120325/alpha/waitpid.S010064400000000000000000000001671173363226000145570ustar00#include .text .align 2 .weak waitpid waitpid: .global __libc_waitpid __libc_waitpid: clr $19 br wait4 dietlibc-0.33~cvs20120325/arm/Makefile.add010064400000000000000000000004571173363226000146550ustar00 LIBOBJ+=$(OBJDIR)/md5asm.o $(OBJDIR)/__aeabi_unwind_cpp.o LIBOBJ+=$(OBJDIR)/__fadvise.o $(OBJDIR)/arm_fadvise.o CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing #ifdef __ARM_EABI__ #CFLAGS+=-mabi=aapcs-linux -mno-thumb-interwork #endif VPATH:=arm:syscalls.s:$(VPATH) LIBGMON_OBJS+=$(OBJDIR)/mcount.o dietlibc-0.33~cvs20120325/arm/__aeabi_unwind_cpp.S010064400000000000000000000011131173363226000163650ustar00.text .global __aeabi_unwind_cpp_pr0 .hidden __aeabi_unwind_cpp_pr0 .type __aeabi_unwind_cpp_pr0, %function .global __aeabi_unwind_cpp_pr1 .hidden __aeabi_unwind_cpp_pr1 .type __aeabi_unwind_cpp_pr1, %function .global __aeabi_unwind_cpp_pr2 .hidden __aeabi_unwind_cpp_pr2 .type __aeabi_unwind_cpp_pr2, %function __aeabi_unwind_cpp_pr0: __aeabi_unwind_cpp_pr1: __aeabi_unwind_cpp_pr2: mov pc, lr @ return from subroutine .size __aeabi_unwind_cpp_pr0,.-__aeabi_unwind_cpp_pr0 .size __aeabi_unwind_cpp_pr1,.-__aeabi_unwind_cpp_pr1 .size __aeabi_unwind_cpp_pr2,.-__aeabi_unwind_cpp_pr2 dietlibc-0.33~cvs20120325/arm/__fadvise.c010064400000000000000000000006131173363226000145430ustar00#include #include "syscalls.h" #ifndef __NR_fadvise64 long fadvise64_64(int fd, off64_t offset, off64_t len, int advice) { extern long __arm_fadvise64_64(int fd, int advice, off64_t offset, off64_t len); return __arm_fadvise64_64(fd, advice, offset, len); } int posix_fadvise(int fd, off64_t offset, off64_t len, int advise) __attribute__((__alias__("fadvise64_64"))); #endif dietlibc-0.33~cvs20120325/arm/__guard.S010064400000000000000000000002211173363226000141770ustar00.data .type __guard,#object .global __guard .type __stack_chk_guard,#object .global __stack_chk_guard __guard: __stack_chk_guard: .long 0xaff00 dietlibc-0.33~cvs20120325/arm/__longjmp.S010064400000000000000000000002611173363226000145470ustar00.text .global __longjmp .type __longjmp,function __longjmp: mov ip, r0 movs r0, r1 moveq r0, #1 #ifndef __SOFTFP__ lfm f4, 4, [ip], #48 #endif ldmia ip, {r4-r11, sp, pc} dietlibc-0.33~cvs20120325/arm/__testandset.S010064400000000000000000000001371173363226000152610ustar00.text .global __testandset __testandset: mov r2, r0 mov r1, #1 swp r0, r1, [r2] mov pc, lr dietlibc-0.33~cvs20120325/arm/arm_fadvise.S010064400000000000000000000001521173363226000150620ustar00#include "syscalls.h" #ifdef __NR_arm_fadvise64_64 syscall(arm_fadvise64_64, __arm_fadvise64_64); #endif dietlibc-0.33~cvs20120325/arm/clone.S010064400000000000000000000042611173363226000137070ustar00 #include #include "syscalls.h" .text .weak clone .global __clone @ @ Some slightly tricky stuff here... edit with care :-) @ #ifdef __ARM_EABI__ #define CLONE_VM 0x00000100 #define CLONE_THREAD 0x00010000 @ ; don't do this yet @#define RESET_PID clone: __clone: @ ; start with a sanity check cmp r0, #0 cmpne r1, #0 mvneq r0, #-EINVAL beq __unified_syscall @ handle as if error was returned by the syscall @ ; insert args into stack str r3, [r1, #-4]! str r0, [r1, #-4]! @ ; do the system call @ ; get the flags mov r0, r2 #ifdef RESET_PID mov ip, r2 #endif @ ; child sp is already in r1 stmfd sp!, {r4, r7} @stmdb sp!, {r4, r7} ldr r2, [sp, #8] ldr r3, [sp, #12] ldr r4, [sp, #16] ldr r7, =__NR_clone swi 0 cmp r0, #0 beq 1f ldmfd sp!, {r4, r7} blt __unified_syscall @ (return code < 0): handle as an error bx lr 1: #ifdef RESET_PID tst ip, #CLONE_THREAD bne 3f mov r0, #0xffff0fff mov lr, pc sub pc, r0, #31 mov r1, r0 tst ip, #CLONE_VM movne r0, #-1 ldr r7, =__NR_getpid swi 0 str r0, [r1, #PID_OFFSET] @ ; not defined yet ?? str r0, [r1, #TID_OFFSET] @ ; not defined yet ?? 3: #endif @ ; pick the function arg and call address off the stack and execute ldr r0, [sp, #4] mov lr, pc ldr pc, [sp], #8 @ ; and we're done, passing return value through r0 b _exit @ branch to _exit (PIC safe) #else clone: __clone: movs r12, r0 @ check function pointer cmpne r1, #0 @ if function check for stack pointer moveq r0, #-EINVAL @ if one is not available set errno value beq __unified_syscall @ handle as if error was returned by the syscall stmdb r1!, { r3, r12 } @ store function param (r3) and function ptr (r12) @ into what will become the childs stack. mov r0, r2 @ move flags argument to r0 swi __NR_clone @ call the syscall movs r0, r0 @ set condition codes blt __unified_syscall @ (return code < 0): handle as an error movne pc, lr @ (return code > 0): return to parent mov fp, #0 @ clear the frame pointer adr lr, 1f @ setup return address ldmia sp!, { r0, pc } @ load function param and jump to thread function 1: b _exit @ branch to _exit (PIC safe) #endif dietlibc-0.33~cvs20120325/arm/dyn_syscalls.S010064400000000000000000000223671173363226000153250ustar00/* * dynamic unified-syscalls * Olaf Dreesen */ #include "../syscalls.s/environ.S" #include "../syscalls.s/errno.S" #include #include "syscalls.h" .text __unified_syscall4: ldmfd sp!, {r4, r5, r6} __unified_syscall: cmn r0, #4096 movcc pc, lr rsb r1, r0, #0 /* and PIC-code with no REAL changes ... ARM RULZ ! */ stmdb sp!, {r1, lr} bl __errno_location(PLT) ldmia sp!, {r1, lr} str r1, [r0] mvn r0, #0 #include "dietuglyweaks.h" mov pc, lr /* ok now include all syscalls.s (*.S) and sysdep *.S */ #include "mmap.S" #include "waitpid.S" #include "select.S" #include "../syscalls.s/__getpagesize.S" #include "../syscalls.s/__pread.S" #include "../syscalls.s/__pwrite.S" #include "../syscalls.s/__reboot.S" #include "../syscalls.s/access.S" #include "../syscalls.s/adjtimex.S" #include "../syscalls.s/brk.S" #include "../syscalls.s/chdir.S" #include "../syscalls.s/chmod.S" #include "../syscalls.s/chown.S" #include "../syscalls.s/chroot.S" #include "../syscalls.s/close.S" #include "../syscalls.s/dup.S" #include "../syscalls.s/dup2.S" #include "../syscalls.s/execve.S" #include "../syscalls.s/fchdir.S" #include "../syscalls.s/fchmod.S" #include "../syscalls.s/fchown.S" #include "../syscalls.s/fcntl.S" #include "../syscalls.s/flock.S" #include "../syscalls.s/fork.S" #include "../syscalls.s/fstat.S" #include "../syscalls.s/fstat64.S" #include "../syscalls.s/fstatfs.S" #include "../syscalls.s/fsync.S" #include "../syscalls.s/ftruncate.S" #include "../syscalls.s/getcwd.S" #include "../syscalls.s/getdents.S" #include "../syscalls.s/getdents64.S" #include "../syscalls.s/getegid.S" #include "../syscalls.s/geteuid.S" #include "../syscalls.s/getgid.S" #include "../syscalls.s/getgroups.S" #include "../syscalls.s/getitimer.S" #include "../syscalls.s/getpgid.S" #include "../syscalls.s/getpid.S" #include "../syscalls.s/getppid.S" #include "../syscalls.s/getpriority.S" #include "../syscalls.s/getresgid.S" #include "../syscalls.s/getresuid.S" #include "../syscalls.s/getrlimit.S" #include "../syscalls.s/getrusage.S" #include "../syscalls.s/getsid.S" #include "../syscalls.s/gettimeofday.S" #include "../syscalls.s/settimeofday.S" #include "../syscalls.s/getuid.S" #include "../syscalls.s/ioctl.S" #include "../syscalls.s/ioperm.S" #include "../syscalls.s/iopl.S" #include "../syscalls.s/ipc.S" #include "../syscalls.s/kill.S" #include "../syscalls.s/lchown.S" #include "../syscalls.s/link.S" #include "../syscalls.s/_llseek.S" #include "../syscalls.s/lseek.S" #include "../syscalls.s/lstat.S" #include "../syscalls.s/lstat64.S" #include "../syscalls.s/mkdir.S" #include "../syscalls.s/mknod.S" #include "../syscalls.s/mlock.S" #include "../syscalls.s/mlockall.S" #include "../syscalls.s/mmap2.S" #include "../syscalls.s/mount.S" #include "../syscalls.s/mprotect.S" #include "../syscalls.s/mremap.S" #include "../syscalls.s/munlockall.S" #include "../syscalls.s/munmap.S" #include "../syscalls.s/n_sigaction.S" #include "../syscalls.s/n_sigpending.S" #include "../syscalls.s/n_sigprocmask.S" #include "../syscalls.s/n_sigsuspend.S" #include "../syscalls.s/nanosleep.S" #include "../syscalls.s/nice.S" #include "../syscalls.s/open.S" #include "../syscalls.s/pause.S" #include "../syscalls.s/personality.S" #include "../syscalls.s/pipe.S" #include "../syscalls.s/poll.S" #include "../syscalls.s/query_module.S" #include "../syscalls.s/init_module.S" #include "../syscalls.s/delete_module.S" #include "../syscalls.s/create_module.S" #include "../syscalls.s/read.S" #include "../syscalls.s/readlink.S" #include "../syscalls.s/readv.S" #include "../syscalls.s/rename.S" #include "../syscalls.s/rmdir.S" #include "../syscalls.s/rt_sigaction.S" #include "../syscalls.s/rt_sigpending.S" #include "../syscalls.s/rt_sigprocmask.S" #include "../syscalls.s/rt_sigqueueinfo.S" #include "../syscalls.s/rt_sigsuspend.S" #include "../syscalls.s/rt_sigtimedwait.S" #include "../syscalls.s/sched_getaffinity.S" #include "../syscalls.s/sched_setaffinity.S" #include "../syscalls.s/sched_get_priority_max.S" #include "../syscalls.s/sched_get_priority_min.S" #include "../syscalls.s/sched_getparam.S" #include "../syscalls.s/sched_getscheduler.S" #include "../syscalls.s/sched_rr_get_interval.S" #include "../syscalls.s/sched_setparam.S" #include "../syscalls.s/sched_setscheduler.S" #include "../syscalls.s/sched_yield.S" #include "../syscalls.s/sendfile.S" #include "../syscalls.s/sendfile64.S" #include "../syscalls.s/setdomainname.S" #include "../syscalls.s/setfsgid.S" #include "../syscalls.s/setfsuid.S" #include "../syscalls.s/setgid.S" #include "../syscalls.s/setgroups.S" #include "../syscalls.s/sethostname.S" #include "../syscalls.s/setitimer.S" #include "../syscalls.s/setpgid.S" #include "../syscalls.s/setpriority.S" #include "../syscalls.s/setregid.S" #include "../syscalls.s/setresgid.S" #include "../syscalls.s/setresuid.S" #include "../syscalls.s/setreuid.S" #include "../syscalls.s/setrlimit.S" #include "../syscalls.s/setsid.S" #include "../syscalls.s/setuid.S" #include "../syscalls.s/sigaltstack.S" //#include "../syscalls.s/signal.S" #include "../syscalls.s/socketcall.S" #include "../syscalls.s/stat.S" #include "../syscalls.s/stat64.S" #include "../syscalls.s/statfs.S" #include "../syscalls.s/stime.S" #include "../syscalls.s/swapoff.S" #include "../syscalls.s/swapon.S" #include "../syscalls.s/symlink.S" #include "../syscalls.s/sync.S" #include "../syscalls.s/sysctl.S" #include "../syscalls.s/sysinfo.S" #include "../syscalls.s/syslog.S" #include "../syscalls.s/sysfs.S" #include "../syscalls.s/time.S" #include "../syscalls.s/times.S" #include "../syscalls.s/truncate.S" #include "../syscalls.s/umask.S" #include "../syscalls.s/umount.S" #include "../syscalls.s/umount2.S" #include "../syscalls.s/uname.S" #include "../syscalls.s/unlink.S" #include "../syscalls.s/utime.S" #include "../syscalls.s/vhangup.S" #include "../syscalls.s/wait4.S" #include "../syscalls.s/write.S" #include "../syscalls.s/writev.S" #include "../syscalls.s/msync.S" #include "../syscalls.s/capget.S" #include "../syscalls.s/capset.S" #include "../syscalls.s/chown32.S" #include "../syscalls.s/fchown32.S" #include "../syscalls.s/getegid32.S" #include "../syscalls.s/geteuid32.S" #include "../syscalls.s/getgid32.S" #include "../syscalls.s/getgroups32.S" #include "../syscalls.s/getresgid32.S" #include "../syscalls.s/getuid32.S" #include "../syscalls.s/lchown32.S" #include "../syscalls.s/setfsgid32.S" #include "../syscalls.s/setfsuid32.S" #include "../syscalls.s/setgid32.S" #include "../syscalls.s/setregid32.S" #include "../syscalls.s/setresgid32.S" #include "../syscalls.s/setreuid32.S" #include "../syscalls.s/setuid32.S" #include "../syscalls.s/alarm.S" #include "../syscalls.s/ptrace.S" #include "../syscalls.s/ftruncate64.S" #include "../syscalls.s/truncate64.S" #include "../syscalls.s/ustat.S" #include "../syscalls.s/epoll_create.S" #include "../syscalls.s/epoll_ctl.S" #include "../syscalls.s/epoll_wait.S" #include "../syscalls.s/fcntl64.S" #include "../syscalls.s/timer_create.S" #include "../syscalls.s/timer_settime.S" #include "../syscalls.s/timer_gettime.S" #include "../syscalls.s/timer_getoverrun.S" #include "../syscalls.s/timer_delete.S" #include "../syscalls.s/clock_settime.S" #include "../syscalls.s/clock_gettime.S" #include "../syscalls.s/clock_getres.S" #include "../syscalls.s/clock_nanosleep.S" #include "../syscalls.s/mq_getsetattr.S" #include "../syscalls.s/mq_notify.S" #include "../syscalls.s/mq_open.S" #include "../syscalls.s/mq_timedreceive.S" #include "../syscalls.s/mq_timedsend.S" #include "../syscalls.s/mq_unlink.S" #include "../syscalls.s/statfs64.S" #include "../syscalls.s/fstatfs64.S" #include "../syscalls.s/tkill.S" #include "../syscalls.s/tgkill.S" #include "../syscalls.s/set_tid_address.S" #include "../syscalls.s/set_thread_area.S" #include "../syscalls.s/set_mempolicy.S" #include "../syscalls.s/rt_sigreturn.S" #include "../syscalls.s/gettid.S" #include "../syscalls.s/get_thread_area.S" #include "../syscalls.s/remap_file_pages.S" #include "../syscalls.s/readahead.S" #include "../syscalls.s/quotactl.S" #include "../syscalls.s/mincore.S" #include "../syscalls.s/mbind.S" #include "../syscalls.s/get_mempolicy.S" #include "../syscalls.s/futex.S" #include "../syscalls.s/fadvise64.S" #include "../syscalls.s/fadvise64_64.S" #include "../syscalls.s/vserver.S" #include "../syscalls.s/request_key.S" #include "../syscalls.s/keyctl.S" #include "../syscalls.s/add_key.S" #include "../syscalls.s/io_submit.S" #include "../syscalls.s/io_setup.S" #include "../syscalls.s/io_getevents.S" #include "../syscalls.s/io_destroy.S" #include "../syscalls.s/io_cancel.S" #include "../syscalls.s/inotify_rm_watch.S" #include "../syscalls.s/inotify_init.S" #include "../syscalls.s/inotify_add_watch.S" #include "../syscalls.s/setxattr.S" #include "../syscalls.s/lsetxattr.S" #include "../syscalls.s/fsetxattr.S" #include "../syscalls.s/removexattr.S" #include "../syscalls.s/lremovexattr.S" #include "../syscalls.s/fremovexattr.S" #include "../syscalls.s/listxattr.S" #include "../syscalls.s/llistxattr.S" #include "../syscalls.s/flistxattr.S" #include "../syscalls.s/getxattr.S" #include "../syscalls.s/lgetxattr.S" #include "../syscalls.s/fgetxattr.S" /* other asm-files w.o. changes ... */ __exit: swi $__NR_exit eor pc,lr,lr #define _exit __exit #include "clone.S" #undef _exit #define __sigjmp_save __sigjmp_save(PLT) #include "__longjmp.S" #include "setjmp.S" #include "__guard.S" dietlibc-0.33~cvs20120325/arm/mcount.S010064400000000000000000000025341173363226000141150ustar00 @ @ mcount.S: ARM assembler implementation of mcount @ @ mcount builds the following stack frame: @ @ | | @ ------------- @ sp on entry -> | | @ ------------- @ new fp ------> | previous pc | @ ------------- @ | previous lr | @ ------------- @ | previous sp | @ ------------- @ | previous fp | @ ------------- @ | previous r3 | @ ------------- @ | previous r2 | @ ------------- @ | previous r1 | @ ------------- @ new sp -------> | previous r0 | @ ------------- @ @ .text .global mcount mcount: mov ip, sp stmdb sp!, { r0 - r3, fp, ip, lr, pc } @ build stack frame sub fp, ip, #4 @ setup new fp ldr r0, [fp, #-12] @ r0 = previous fp ldr r0, [r0, #-4 ] @ r0 = pc from caller of mcount caller mov r1, lr @ r1 = pc from mcount caller bl __mcount @ call __mcount ldmdb fp, { r0 - r3, fp, sp, pc } @ restore context from stack frame and return. dietlibc-0.33~cvs20120325/arm/md5asm.S010064400000000000000000000475031173363226000140030ustar00/***************************************************************************** * Copyright (C) 2002 Andre McCurdy * * "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" * * This program is free software. you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY, without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * ****************************************************************************** * * History: * * 2002/02/12: Andre McCurdy * - Original created. * * 2002/02/13: Andre McCurdy * - Rewrote MD5Update in assembler (saves 52 bytes). * - Added guard so we don't compile anything for Big-Endian targets. * * 2002/02/22: Andre McCurdy * - Added new function MD5Update (a wrapper for the original version) which * checks for correct 32bit alignment of the input data pointer. * - Original MD5Update function renamed __MD5Update. * - __MD5Transform symbol no longer exported. * * 2002/02/25: Andre McCurdy * - MD5Update re-written in assembler (saves 12 bytes + lots of cycles :-) * * 2002/03/07: Andre McCurdy * - _Finally_ fixed hashing from an unaligned buffer in all cases :-) * ****************************************************************************** * * Notes: * * This code is believed to be Position Independent (ie can be safely used * as part of a shared library). * *****************************************************************************/ #include #if (__BYTE_ORDER == __LITTLE_ENDIAN) .global MD5Init .global MD5Update .text #ifdef __ARM_EABI__ .align 4 #else .align 2 #endif @ -- @ void MD5Init (MD5_CTX* context); @ -- MD5Init: adr r1, 1f @ r1 = base address of MD5InitData array ldmia r1, { r1 - r3, r12 } @ load 4 elements from MD5InitData array stmia r0, { r1 - r3, r12 } @ store into MD5 context->state[0..3] mov r1, #0 str r1, [r0, #0x10] @ initial count[0] = 0 str r1, [r0, #0x14] @ initial count[1] = 0 mov pc, lr @ return 1: .word 0x67452301 @ initial MD5 context->state[0] .word 0xefcdab89 @ initial MD5 context->state[1] .word 0x98badcfe @ initial MD5 context->state[2] .word 0x10325476 @ initial MD5 context->state[3] @ -- @ void MD5Update (MD5_CTX* context, const uint8_t* buf, signed int len); @ -- MD5Update: stmdb sp!, { r4 - r8, lr } add r4, r0, #(6 * 4) @ r4 = &context->buffer[0] ldmdb r4, { r0, r3 } @ r0 = count[0], r3 = count[1] mov r5, r1 @ r5 = input mov r6, r0, lsr #3 @ r6 = (context->count[0] >> 3) and r6, r6, #0x3f @ r6 = byteIndex = ((context->count[0] >> 3) & 0x3f) adds r0, r0, r2, lsl #3 adc r3, r3, r2, lsr #29 stmdb r4, { r0, r3 } @ context->count += (inputBytes * 8) rsb r7, r6, #64 @ r7 = (64 - byteIndex) == partLen subs r8, r2, r7 @ r8 = (inputBytes - partLen) add r0, r4, r6 bcc 2f mov r2, r7 bl memcpy @ memcpy (&context->buffer[byteIndex], input, partLen); sub r0, r4, #(6 * 4) mov r1, r4 mov r2, #1 bl __MD5Transform @ __MD5Transform (context->state, context->buffer, 1); sub r0, r4, #(6 * 4) add r1, r5, r7 mov r2, r8, lsr #6 @ r2 = len = ((inputBytes - partLen) / 64) tst r1, #3 @ if (input & 0x03) adr lr, 1f beq __MD5Transform @ __MD5Transform (context->state, &input[partLen], len); bne __UnalignedMD5Transform @ else __UnalignedMD5Transform (context->state, &input[partLen], len); 1: mov r0, r4 bic r2, r8, #0x3f add r1, r2, r7 add r1, r1, r5 sub r2, r8, r2 2: ldmia sp!, { r4 - r8, lr } b memcpy @ classic tail-call optimisation... @ -- @ static void __MD5Transform (uint32_t *buf, const uint32_t *in, int repeat); @ -- MD5MagicData: 1: .word 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee .word 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, ( 3f- 4f-4) .word 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, ( 3f- 4f-4) .word 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, ( 3f- 4f-4) .word 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, ( 4f- 4f-4) .word 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, ( 5f- 9f-4) .word 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, ( 6f- 9f-4) .word 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, ( 7f- 9f-4) .word 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, ( 9f- 9f-4) .word 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, (10f-14f-4) .word 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, (11f-14f-4) .word 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, (12f-14f-4) .word 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, (14f-14f-4) .word 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, (15f-19f-4) .word 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, (16f-19f-4) .word 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, (17f-19f-4) .word 0x6e4120A9, 0x20657264, 0x7543634d, 0x00796472, (19f-19f-4) __MD5Transform: cmp r2, #0 moveq pc, lr @ return if (repeat == 0) stmdb sp!, { r0, r2, r4 - r11, lr } @ stack 'buf', 'repeat' and all callee saved registers ldmia r0, { r2 - r5 } @ r2 = a, r3 = b, r4 = c, r5 = d 2: adr r0, 1b @ r0 = base address of MD5MagicData ldmia r0!, { r6 - r9 } @ load first 4 elements from MD5MagicData 3: ldmia r1!, { r10 - r12, lr } @ r10 = in[i], r11 = in[i+1], r12 = in[i+2], lr = in[i+3] add r10, r10, r6 @ r10 = in[i] + MD5MagicData[i] eor r6, r4, r5 @ r6 = (c ^ d) and r6, r6, r3 @ r6 = ((c ^ d) & b) eor r6, r6, r5 @ r6 = (((c ^ d) & b) ^ d) add r2, r2, r6 @ a = (((c ^ d) & b) ^ d) + a add r2, r2, r10 @ a = (((c ^ d) & b) ^ d) + a + (in[i] + MD5MagicData[i]) add r2, r3, r2, ROR #(32 - 7) @ a = b + (a rotated left by 7 places) add r11, r11, r7 @ r11 = in[i+1] + MD5MagicData[i+1] eor r7, r3, r4 @ r7 = (b ^ c) and r7, r7, r2 @ r7 = ((b ^ c) & a) eor r7, r7, r4 @ r7 = (((b ^ c) & a) ^ c) add r5, r5, r7 @ d = (((b ^ c) & a) ^ c) + d add r5, r5, r11 @ d = (((b ^ c) & a) ^ c) + d + (in[i+1] + MD5MagicData[i+1]) add r5, r2, r5, ROR #(32 - 12) @ d = a + (d rotated left by 12 places) add r12, r12, r8 @ r12 = in[i+2] + MD5MagicData[i+2] eor r8, r2, r3 @ r8 = (a ^ b) and r8, r8, r5 @ r8 = ((a ^ b) & d) eor r8, r8, r3 @ r8 = (((a ^ b) & d) ^ b) add r4, r4, r8 @ c = (((a ^ b) & d) ^ b) + c add r4, r4, r12 @ c = (((a ^ b) & d) ^ b) + c + (in[i+2] + MD5MagicData[i+2]) add r4, r5, r4, ROR #(32 - 17) @ c = d + (c rotated left by 17 places) add lr, lr, r9 @ lr = in[i+3] + MD5MagicData[i+3] eor r9, r5, r2 @ r9 = (d ^ a) and r9, r9, r4 @ r9 = ((d ^ a) & c) eor r9, r9, r2 @ r9 = (((d ^ a) & c) ^ a) add r3, r3, r9 @ b = (((d ^ a) & c) ^ a) + b add r3, r3, lr @ b = (((d ^ a) & c) ^ a) + b + (in[i+3] + MD5MagicData[i+3]) add r3, r4, r3, ROR #(32 - 22) @ b = c + (b rotated left by 22 places) ldmia r0!, { r6 - r10 } @ load next 4 elements from MD5MagicData add pc, pc, r10 @ and branch to next state 4: ldr r10, [r1, #-(15*4)] @ r10 = in[ 1] ldr r11, [r1, #-(10*4)] @ r11 = in[ 6] ldr r12, [r1, #-( 5*4)] @ r12 = in[11] ldr lr, [r1, #-(16*4)] @ lr = in[ 0] b 8f 5: ldr r10, [r1, #-(11*4)] @ r10 = in[ 5] ldr r11, [r1, #-( 6*4)] @ r11 = in[10] ldr r12, [r1, #-( 1*4)] @ r12 = in[15] ldr lr, [r1, #-(12*4)] @ lr = in[ 4] b 8f 6: ldr r10, [r1, #-( 7*4)] @ r10 = in[ 9] ldr r11, [r1, #-( 2*4)] @ r11 = in[14] ldr r12, [r1, #-(13*4)] @ r12 = in[ 3] ldr lr, [r1, #-( 8*4)] @ lr = in[ 8] b 8f 7: ldr r10, [r1, #-( 3*4)] @ r10 = in[13] ldr r11, [r1, #-(14*4)] @ r11 = in[ 2] ldr r12, [r1, #-( 9*4)] @ r12 = in[ 7] ldr lr, [r1, #-( 4*4)] @ lr = in[12] 8: add r10, r10, r6 @ r10 = in[x] + MD5MagicData[i] eor r6, r3, r4 @ r6 = (b ^ c) and r6, r6, r5 @ r6 = ((b ^ c) & d) eor r6, r6, r4 @ r6 = (((b ^ c) & d) ^ c) add r2, r2, r6 @ a = (((b ^ c) & d) ^ c) + a add r2, r2, r10 @ a = (((b ^ c) & d) ^ c) + a + (in[x] + MD5MagicData[i]) add r2, r3, r2, ROR #(32 - 5) @ a = b + (a rotated left by 5 places) add r11, r11, r7 @ r11 = in[x] + MD5MagicData[i+1] eor r7, r2, r3 @ r7 = (a ^ b) and r7, r7, r4 @ r7 = ((a ^ b) & c) eor r7, r7, r3 @ r7 = (((a ^ b) & c) ^ b) add r5, r5, r7 @ d = (((a ^ b) & c) ^ b) + d add r5, r5, r11 @ d = (((a ^ b) & c) ^ b) + d + (in[x] + MD5MagicData[i+1]) add r5, r2, r5, ROR #(32 - 9) @ d = a + (d rotated left by 9 places) add r12, r12, r8 @ r12 = in[x] + MD5MagicData[i+2] eor r8, r5, r2 @ r8 = (d ^ a) and r8, r8, r3 @ r8 = ((d ^ a) & b) eor r8, r8, r2 @ r8 = (((d ^ a) & b) ^ a) add r4, r4, r8 @ c = (((d ^ a) & b) ^ a) + c add r4, r4, r12 @ c = (((d ^ a) & b) ^ a) + c + (in[x] + MD5MagicData[i+2]) add r4, r5, r4, ROR #(32 - 14) @ c = d + (c rotated left by 14 places) add lr, lr, r9 @ lr = in[x] + MD5MagicData[i+3] eor r9, r4, r5 @ r9 = (c ^ d) and r9, r9, r2 @ r9 = ((c ^ d) & a) eor r9, r9, r5 @ r9 = (((c ^ d) & a) ^ d) add r3, r3, r9 @ b = (((c ^ d) & a) ^ d) + b add r3, r3, lr @ b = (((c ^ d) & a) ^ d) + b + (in[x] + MD5MagicData[i+3]) add r3, r4, r3, ROR #(32 - 20) @ b = c + (b rotated left by 20 places) ldmia r0!, { r6 - r10 } @ load next 4 elements from MD5MagicData add pc, pc, r10 @ and branch to next state 9: ldr r10, [r1, #-(11*4)] @ r10 = in[ 5] ldr r11, [r1, #-( 8*4)] @ r11 = in[ 8] ldr r12, [r1, #-( 5*4)] @ r12 = in[11] ldr lr, [r1, #-( 2*4)] @ lr = in[14] b 13f 10: ldr r10, [r1, #-(15*4)] @ r10 = in[ 1] ldr r11, [r1, #-(12*4)] @ r11 = in[ 4] ldr r12, [r1, #-( 9*4)] @ r12 = in[ 7] ldr lr, [r1, #-( 6*4)] @ lr = in[10] b 13f 11: ldr r10, [r1, #-( 3*4)] @ r10 = in[13] ldr r11, [r1, #-(16*4)] @ r11 = in[ 0] ldr r12, [r1, #-(13*4)] @ r12 = in[ 3] ldr lr, [r1, #-(10*4)] @ lr = in[ 6] b 13f 12: ldr r10, [r1, #-( 7*4)] @ r10 = in[ 9] ldr r11, [r1, #-( 4*4)] @ r11 = in[12] ldr r12, [r1, #-( 1*4)] @ r12 = in[15] ldr lr, [r1, #-(14*4)] @ lr = in[ 2] 13: add r10, r10, r6 @ r10 = in[x] + MD5MagicData[i] add r2, r2, r10 @ a += in[x] + MD5MagicData[i] eor r6, r3, r4 @ r6 = (b ^ c) eor r10, r6, r5 @ r10 = (b ^ c ^ d) add r2, r2, r10 @ a += (b ^ c ^ d) add r2, r3, r2, ROR #(32 - 4) @ a = b + (a rotated left by 4 places) add r11, r11, r7 @ r11 = in[x] + MD5MagicData[i+1] eor r7, r2, r6 @ r7 = (a ^ b ^ c) add r5, r5, r7 @ d = (a ^ b ^ c) + d add r5, r5, r11 @ d = (a ^ b ^ c) + d + (in[x] + MD5MagicData[i+1]) add r5, r2, r5, ROR #(32 - 11) @ d = a + (d rotated left by 11 places) add r12, r12, r8 @ r12 = in[x] + MD5MagicData[i+2] add r4, r4, r12 @ c += in[x] + MD5MagicData[i+2] eor r8, r5, r2 @ r8 = (d ^ a) eor r12, r8, r3 @ r12 = (d ^ a ^ b) add r4, r4, r12 @ c += (d ^ a ^ b) add r4, r5, r4, ROR #(32 - 16) @ c = d + (c rotated left by 16 places) add lr, lr, r9 @ lr = in[x] + MD5MagicData[i+3] eor r9, r4, r8 @ r9 = (c ^ d ^ a) add r3, r3, r9 @ b = (c ^ d ^ a) + b add r3, r3, lr @ b = (c ^ d ^ a) + b + (in[x] + MD5MagicData[i+3]) add r3, r4, r3, ROR #(32 - 23) @ b = c + (b rotated left by 23 places) ldmia r0!, { r6 - r10 } @ load next 4 elements from MD5MagicData add pc, pc, r10 @ and branch to next state 14: ldr r10, [r1, #-(16*4)] @ r10 = in[ 0] ldr r11, [r1, #-( 9*4)] @ r11 = in[ 7] ldr r12, [r1, #-( 2*4)] @ r12 = in[14] ldr lr, [r1, #-(11*4)] @ lr = in[ 5] b 18f 15: ldr r10, [r1, #-( 4*4)] @ r10 = in[12] ldr r11, [r1, #-(13*4)] @ r11 = in[ 3] ldr r12, [r1, #-( 6*4)] @ r12 = in[10] ldr lr, [r1, #-(15*4)] @ lr = in[ 1] b 18f 16: ldr r10, [r1, #-( 8*4)] @ r10 = in[ 8] ldr r11, [r1, #-( 1*4)] @ r11 = in[15] ldr r12, [r1, #-(10*4)] @ r12 = in[ 6] ldr lr, [r1, #-( 3*4)] @ lr = in[13] b 18f 17: ldr r10, [r1, #-(12*4)] @ r10 = in[ 4] ldr r11, [r1, #-( 5*4)] @ r11 = in[11] ldr r12, [r1, #-(14*4)] @ r12 = in[ 2] ldr lr, [r1, #-( 7*4)] @ lr = in[ 9] 18: add r10, r10, r6 @ r10 = in[x] + MD5MagicData[i] add r2, r2, r10 @ a += in[x] + MD5MagicData[i] mvn r6, r5 @ r6 = ( ~d) orr r6, r6, r3 @ r6 = (b | ~d) eor r6, r6, r4 @ r6 = (c ^ (b | ~d)) add r2, r2, r6 @ a += (c ^ (b | ~d)) add r2, r3, r2, ROR #(32 - 6) @ a = b + (a rotated left by 6 places) add r11, r11, r7 @ r11 = in[x] + MD5MagicData[i] add r5, r5, r11 @ d += in[x] + MD5MagicData[i] mvn r7, r4 @ r7 = ( ~c) orr r7, r7, r2 @ r7 = (a | ~c) eor r7, r7, r3 @ r7 = (b ^ (a | ~c)) add r5, r5, r7 @ d += (b ^ (a | ~c)) add r5, r2, r5, ROR #(32 - 10) @ d = a + (d rotated left by 10 places) add r12, r12, r8 @ r12 = in[x] + MD5MagicData[i] add r4, r4, r12 @ c += in[x] + MD5MagicData[i] mvn r8, r3 @ r8 = ( ~b) orr r8, r8, r5 @ r8 = (d | ~b) eor r8, r8, r2 @ r8 = (a ^ (d | ~b)) add r4, r4, r8 @ c += (a ^ (d | ~b)) add r4, r5, r4, ROR #(32 - 15) @ c = d + (c rotated left by 15 places) add lr, lr, r9 @ lr = in[x] + MD5MagicData[i] add r3, r3, lr @ b += in[x] + MD5MagicData[i] mvn r9, r2 @ r9 = ( ~a) orr r9, r9, r4 @ r9 = (c | ~a) eor r9, r9, r5 @ r9 = (d ^ (c | ~a)) add r3, r3, r9 @ b += (d ^ (c | ~a)) add r3, r4, r3, ROR #(32 - 21) @ b = c + (b rotated left by 21 places) ldmia r0!, { r6 - r10 } @ load next 4 elements from MD5MagicData add pc, pc, r10 @ and branch to next state 19: ldmia sp, { r0, r10 } @ fetch 'buf' and 'repeat' from the stack ldmia r0, { r6 - r9 } @ r6 = buf[0], r7 = buf[1], r8 = buf[2], r9 = buf[3] (original values..) subs r10, r10, #1 strne r10, [sp, #4] add r2, r6, r2 add r3, r7, r3 add r4, r8, r4 add r5, r9, r5 stmia r0, { r2 - r5 } bne 2b ldmia sp!, { r0, r2, r4 - r11, pc } @ restore all callee saved registers and return @ -- @ static void __UnalignedMD5Transform (uint32_t *buf, const uint8_t *in, int repeat); @ -- __UnalignedMD5Transform: stmdb sp!, { r4 - r7, lr } movs r4, r2, lsl #6 @ r4 = (repeat * 64) ldmeqia sp!, { r4 - r7, pc } @ if ((repeat * 64) == 0) return; mov r5, r0 @ r5 = state mov r6, r1 @ r6 = in sub sp, sp, #256 @ create 256 byte temp buffer 1: cmp r4, #256 mov r0, sp movcc r7, r4 movcs r7, #256 @ r7 = (blockCount * 64) = min((repeat * 64), (4 * 64)) mov r1, r6 mov r2, r7 bl memcpy @ memcpy (blockBuffer, in, (blockCount * 64)); mov r0, r5 mov r1, sp mov r2, r7, lsr #6 bl __MD5Transform @ __MD5Transform (state, blockBuffer, blockCount); subs r4, r4, #256 @ (repeat * 64) -= (4 * 64); add r6, r6, #256 @ in += (4 * 64); bgt 1b @ loop while (repeat > 0) add sp, sp, #256 @ return temp buffer to stack ldmia sp!, { r4 - r7, pc } @ return #endif /* __BYTE_ORDER == __LITTLE_ENDIAN */ dietlibc-0.33~cvs20120325/arm/mmap.S010064400000000000000000000013761173363226000135450ustar00#include #include "syscalls.h" .text @ @ mmap takes 6 parameters - ie more than can be passed in registers via the @ regular syscall interface. Instead, parameters are passed on the stack. @ @ On entry, the compiler will have already placed the fifth and sixth @ parameters on the stack - all we need do here is push the first four and @ call the syscall. @ .global mmap #ifdef __ARM_EABI__ mmap: str r5, [sp, #-4]! ldr r5, [sp, #8] str r4, [sp, #-4]! ldr r4, [sp, #8] mov ip, r7 mov r7, #__NR_mmap2 svc 0x00000000 mov r7, ip ldr r4, [sp], #4 ldr r5, [sp], #4 cmn r0, #4096 mov pc, lr @ return #else mmap: stmdb sp!, {r0, r1, r2, r3} mov r0, sp swi __NR_mmap add sp, sp, #16 b __unified_syscall #endif dietlibc-0.33~cvs20120325/arm/select.S010064400000000000000000000000621173363226000140610ustar00#include "syscalls.h" syscall(_newselect,select) dietlibc-0.33~cvs20120325/arm/setjmp.S010064400000000000000000000003551173363226000141110ustar00.text .weak setjmp setjmp: .global __setjmp __setjmp: mov r1, #0 .global __sigsetjmp __sigsetjmp: .weak sigsetjmp sigsetjmp: #ifndef __SOFTFP__ sfm f4, 4, [r0], #48 #endif stmia r0, {r4-r11, sp, lr} sub r0, r0, #48 b __sigjmp_save dietlibc-0.33~cvs20120325/arm/setsockopt.S010064400000000000000000000001241173363226000147770ustar00#ifdef __ARM_EABI__ #include "syscalls.h" syscall(setsockopt,setsockopt) #endif dietlibc-0.33~cvs20120325/arm/start.S010064400000000000000000000031511173363226000137410ustar00 #include "dietfeatures.h" #include "syscalls.h" .text #ifdef __ARM_EABI__ .align 4 #else .align 2 #endif .global _start .weak exit .global _exit #ifdef __ARM_EABI__ _start: mov fp, #0 @ clear the frame pointer ldr a1, [sp] @ argc add a2, sp, #4 @ argv ldr ip, .L3 add a3, a2, a1, lsl #2 @ &argv[argc] add a3, a3, #4 @ envp str a3, [ip, #0] @ environ = envp bl main @ @ The exit status from main() is already in r0. @ We need to branch to 'exit' in case we have linked with 'atexit'. @ bl exit exit: _exit: mov r7, #__NR_exit swi 0 @ never returns. .L3: .word environ #else _start: #ifdef WANT_DYNAMIC mov a4, a1 @ save dynamic ld.so _fini #endif mov fp, #0 @ clear the frame pointer ldr a1, [sp], #4 @ argc mov a2, sp @ argv ldr ip, .L3 add a3, a2, a1, lsl #2 @ &argv[argc] add a3, a3, #4 @ envp #ifdef __DYN_LIB ldr sl, .L4 1: add sl, pc, sl str a3, [sl, ip] @ environ = envp #else str a3, [ip, #0] @ environ = envp #endif #ifdef PROFILING stmdb sp!, { r0 - r3 } ldr r0, .L5 ldr r1, .L6 bl monitor ldmia sp!, { r0 - r3 } #endif #ifdef WANT_DYNAMIC bl _dyn_start #else bl CALL_IN_STARTCODE #endif @ @ The exit status from main() is already in r0. @ We need to branch to 'exit' in case we have linked with 'atexit'. @ bl exit exit: _exit: #ifdef PROFILING mov r4, r0 @ save a copy of exit status bl _stop_monitor mov r0, r4 #endif swi $__NR_exit @ never returns. #ifdef __DYN_LIB .L3: .word environ(GOT) .L4: .word _GLOBAL_OFFSET_TABLE_-(1b+8) #else .L3: .word environ #endif #ifdef PROFILING .L5: .word .text .L6: .word _etext #endif #endif dietlibc-0.33~cvs20120325/arm/strcpy.S010064400000000000000000000020071173363226000141270ustar00#include "dietfeatures.h" .text .align 2 .global strcpy strcpy: #ifndef WANT_SMALL_STRING_ROUTINES mov ip, r0 ands r2, r1, #3 ldr r3, [r1, -r2]! movne r2, r2, lsl #3 #ifdef __ARMEB__ movne r3, r3, lsl r2 #else movne r3, r3, lsr r2 #endif addne pc, pc, r2, lsl #1 mov r0, r0 @ nop .Lloop: #ifdef __ARMEB__ mov r3, r3, ror #24 tst r3, #255 strb r3, [ip], #1 moveq pc, lr mov r3, r3, ror #24 tst r3, #255 strb r3, [ip], #1 moveq pc, lr mov r3, r3, ror #24 tst r3, #255 strb r3, [ip], #1 moveq pc, lr mov r3, r3, ror #24 tst r3, #255 strb r3, [ip], #1 ldrne r3, [r1, #4]! #else tst r3, #255 strb r3, [ip], #1 moveq pc, lr mov r3, r3, lsr #8 tst r3, #255 strb r3, [ip], #1 moveq pc, lr mov r3, r3, lsr #8 tst r3, #255 strb r3, [ip], #1 moveq pc, lr mov r3, r3, lsr #8 tst r3, #255 strb r3, [ip], #1 ldrne r3, [r1, #4]! #endif #else ldrb r2, [r1], #1 mov r3, r0 .Lloop: strb r2, [r3], #1 tst r2, #255 ldrneb r2, [r1], #1 #endif bne .Lloop mov pc, lr .Lfe1: .size strcpy,.Lfe1-strcpy dietlibc-0.33~cvs20120325/arm/strlen.S010064400000000000000000000020231173363226000141100ustar00#include "dietfeatures.h" .text .align 2 .global strlen strlen: #if 0 teq a1, #0 @ is string pointer NULL ?? moveq pc, lr @ if so, return 0 #endif #ifndef WANT_SMALL_STRING_ROUTINES ands a3, a1, #3 ldr ip, .Lmagic mov a2, a1 ldr a4, [a1, -a3]! /* ensure junk bytes aren't nulls */ rsbne a3, a3, #4 movne a3, a3, lsl #3 #ifdef __ARMEB__ orrne a4, a4, ip, lsl a3 #else orrne a4, a4, ip, lsr a3 #endif .Lloop: sub a3, a4, ip bic a3, a3, a4 ands a3, a3, ip, lsl #7 ldreq a4, [a1, #4]! beq .Lloop /* a3 & 0x80808080 == a3 */ #ifdef __ARMEB__ tst a3, ip, lsl #16 + 7 moveq a3, a3, lsl #16 addeq a1, a1, #2 tst a3, #0x80000000 addeq a1, a1, #1 #else tst a3, ip, lsr #16 - 7 moveq a3, a3, lsr #16 addeq a1, a1, #2 tst a3, #0x80 addeq a1, a1, #1 #endif sub a1, a1, a2 #else ldrb a3, [a1], #1 mov a2, a1 .Lloop: tst a3, #255 ldrneb a3, [a1], #1 bne .Lloop sub a1, a1, a2 #endif mov pc, lr #ifndef WANT_SMALL_STRING_ROUTINES .Lmagic: .word 0x01010101 #endif .Lstrlen: .size strlen,.Lstrlen-strlen dietlibc-0.33~cvs20120325/arm/syscalls.h010064400000000000000000000704021173363226000144710ustar00#ifndef _ARM_SYSCALL_H #define _ARM_SYSCALL_H 1 #define __NR_OABI_SYSCALL_BASE 0x900000 #if defined(__thumb__) || defined(__ARM_EABI__) #define __NR_SYSCALL_BASE 0 #else #define __NR_SYSCALL_BASE __NR_OABI_SYSCALL_BASE #endif #define __NR_restart_syscall (__NR_SYSCALL_BASE+ 0) #define __NR_exit (__NR_SYSCALL_BASE+ 1) #define __NR_fork (__NR_SYSCALL_BASE+ 2) #define __NR_read (__NR_SYSCALL_BASE+ 3) #define __NR_write (__NR_SYSCALL_BASE+ 4) #define __NR_open (__NR_SYSCALL_BASE+ 5) #define __NR_close (__NR_SYSCALL_BASE+ 6) /* 7 was sys_waitpid */ #define __NR_creat (__NR_SYSCALL_BASE+ 8) #define __NR_link (__NR_SYSCALL_BASE+ 9) #define __NR_unlink (__NR_SYSCALL_BASE+ 10) #define __NR_execve (__NR_SYSCALL_BASE+ 11) #define __NR_chdir (__NR_SYSCALL_BASE+ 12) #define __NR_time (__NR_SYSCALL_BASE+ 13) #define __NR_mknod (__NR_SYSCALL_BASE+ 14) #define __NR_chmod (__NR_SYSCALL_BASE+ 15) #define __NR_lchown (__NR_SYSCALL_BASE+ 16) /* 17 was sys_break */ /* 18 was sys_stat */ #define __NR_lseek (__NR_SYSCALL_BASE+ 19) #define __NR_getpid (__NR_SYSCALL_BASE+ 20) #define __NR_mount (__NR_SYSCALL_BASE+ 21) #define __NR_umount (__NR_SYSCALL_BASE+ 22) #define __NR_setuid (__NR_SYSCALL_BASE+ 23) #define __NR_getuid (__NR_SYSCALL_BASE+ 24) #define __NR_stime (__NR_SYSCALL_BASE+ 25) #define __NR_ptrace (__NR_SYSCALL_BASE+ 26) #define __NR_alarm (__NR_SYSCALL_BASE+ 27) /* 28 was sys_fstat */ #define __NR_pause (__NR_SYSCALL_BASE+ 29) #define __NR_utime (__NR_SYSCALL_BASE+ 30) /* 31 was sys_stty */ /* 32 was sys_gtty */ #define __NR_access (__NR_SYSCALL_BASE+ 33) #define __NR_nice (__NR_SYSCALL_BASE+ 34) /* 35 was sys_ftime */ #define __NR_sync (__NR_SYSCALL_BASE+ 36) #define __NR_kill (__NR_SYSCALL_BASE+ 37) #define __NR_rename (__NR_SYSCALL_BASE+ 38) #define __NR_mkdir (__NR_SYSCALL_BASE+ 39) #define __NR_rmdir (__NR_SYSCALL_BASE+ 40) #define __NR_dup (__NR_SYSCALL_BASE+ 41) #define __NR_pipe (__NR_SYSCALL_BASE+ 42) #define __NR_times (__NR_SYSCALL_BASE+ 43) /* 44 was sys_prof */ #define __NR_brk (__NR_SYSCALL_BASE+ 45) #define __NR_setgid (__NR_SYSCALL_BASE+ 46) #define __NR_getgid (__NR_SYSCALL_BASE+ 47) /* 48 was sys_signal */ #define __NR_geteuid (__NR_SYSCALL_BASE+ 49) #define __NR_getegid (__NR_SYSCALL_BASE+ 50) #define __NR_acct (__NR_SYSCALL_BASE+ 51) #define __NR_umount2 (__NR_SYSCALL_BASE+ 52) /* 53 was sys_lock */ #define __NR_ioctl (__NR_SYSCALL_BASE+ 54) #define __NR_fcntl (__NR_SYSCALL_BASE+ 55) /* 56 was sys_mpx */ #define __NR_setpgid (__NR_SYSCALL_BASE+ 57) /* 58 was sys_ulimit */ /* 59 was sys_olduname */ #define __NR_umask (__NR_SYSCALL_BASE+ 60) #define __NR_chroot (__NR_SYSCALL_BASE+ 61) #define __NR_ustat (__NR_SYSCALL_BASE+ 62) #define __NR_dup2 (__NR_SYSCALL_BASE+ 63) #define __NR_getppid (__NR_SYSCALL_BASE+ 64) #define __NR_getpgrp (__NR_SYSCALL_BASE+ 65) #define __NR_setsid (__NR_SYSCALL_BASE+ 66) #define __NR_sigaction (__NR_SYSCALL_BASE+ 67) /* 68 was sys_sgetmask */ /* 69 was sys_ssetmask */ #define __NR_setreuid (__NR_SYSCALL_BASE+ 70) #define __NR_setregid (__NR_SYSCALL_BASE+ 71) #define __NR_sigsuspend (__NR_SYSCALL_BASE+ 72) #define __NR_sigpending (__NR_SYSCALL_BASE+ 73) #define __NR_sethostname (__NR_SYSCALL_BASE+ 74) #define __NR_setrlimit (__NR_SYSCALL_BASE+ 75) #define __NR_getrlimit (__NR_SYSCALL_BASE+ 76) /* Back compat 2GB limited rlimit */ #define __NR_getrusage (__NR_SYSCALL_BASE+ 77) #define __NR_gettimeofday (__NR_SYSCALL_BASE+ 78) #define __NR_settimeofday (__NR_SYSCALL_BASE+ 79) #define __NR_getgroups (__NR_SYSCALL_BASE+ 80) #define __NR_setgroups (__NR_SYSCALL_BASE+ 81) #define __NR_select (__NR_SYSCALL_BASE+ 82) #define __NR_symlink (__NR_SYSCALL_BASE+ 83) /* 84 was sys_lstat */ #define __NR_readlink (__NR_SYSCALL_BASE+ 85) #define __NR_uselib (__NR_SYSCALL_BASE+ 86) #define __NR_swapon (__NR_SYSCALL_BASE+ 87) #define __NR_reboot (__NR_SYSCALL_BASE+ 88) #define __NR_readdir (__NR_SYSCALL_BASE+ 89) #define __NR_mmap (__NR_SYSCALL_BASE+ 90) #define __NR_munmap (__NR_SYSCALL_BASE+ 91) #define __NR_truncate (__NR_SYSCALL_BASE+ 92) #define __NR_ftruncate (__NR_SYSCALL_BASE+ 93) #define __NR_fchmod (__NR_SYSCALL_BASE+ 94) #define __NR_fchown (__NR_SYSCALL_BASE+ 95) #define __NR_getpriority (__NR_SYSCALL_BASE+ 96) #define __NR_setpriority (__NR_SYSCALL_BASE+ 97) /* 98 was sys_profil */ #define __NR_statfs (__NR_SYSCALL_BASE+ 99) #define __NR_fstatfs (__NR_SYSCALL_BASE+100) /* 101 was sys_ioperm */ #define __NR_socketcall (__NR_SYSCALL_BASE+102) #define __NR_syslog (__NR_SYSCALL_BASE+103) #define __NR_setitimer (__NR_SYSCALL_BASE+104) #define __NR_getitimer (__NR_SYSCALL_BASE+105) #define __NR_stat (__NR_SYSCALL_BASE+106) #define __NR_lstat (__NR_SYSCALL_BASE+107) #define __NR_fstat (__NR_SYSCALL_BASE+108) /* 109 was sys_uname */ /* 110 was sys_iopl */ #define __NR_vhangup (__NR_SYSCALL_BASE+111) /* 112 was sys_idle */ #define __NR_syscall (__NR_SYSCALL_BASE+113) /* syscall to call a syscall! */ #define __NR_wait4 (__NR_SYSCALL_BASE+114) #define __NR_swapoff (__NR_SYSCALL_BASE+115) #define __NR_sysinfo (__NR_SYSCALL_BASE+116) #define __NR_ipc (__NR_SYSCALL_BASE+117) #define __NR_fsync (__NR_SYSCALL_BASE+118) #define __NR_sigreturn (__NR_SYSCALL_BASE+119) #define __NR_clone (__NR_SYSCALL_BASE+120) #define __NR_setdomainname (__NR_SYSCALL_BASE+121) #define __NR_uname (__NR_SYSCALL_BASE+122) /* 123 was sys_modify_ldt */ #define __NR_adjtimex (__NR_SYSCALL_BASE+124) #define __NR_mprotect (__NR_SYSCALL_BASE+125) #define __NR_sigprocmask (__NR_SYSCALL_BASE+126) /* 127 was sys_create_module */ #define __NR_init_module (__NR_SYSCALL_BASE+128) #define __NR_delete_module (__NR_SYSCALL_BASE+129) /* 130 was sys_get_kernel_syms */ #define __NR_quotactl (__NR_SYSCALL_BASE+131) #define __NR_getpgid (__NR_SYSCALL_BASE+132) #define __NR_fchdir (__NR_SYSCALL_BASE+133) #define __NR_bdflush (__NR_SYSCALL_BASE+134) #define __NR_sysfs (__NR_SYSCALL_BASE+135) #define __NR_personality (__NR_SYSCALL_BASE+136) /* 137 was sys_afs_syscall */ #define __NR_setfsuid (__NR_SYSCALL_BASE+138) #define __NR_setfsgid (__NR_SYSCALL_BASE+139) #define __NR__llseek (__NR_SYSCALL_BASE+140) #define __NR_getdents (__NR_SYSCALL_BASE+141) #define __NR__newselect (__NR_SYSCALL_BASE+142) #define __NR_flock (__NR_SYSCALL_BASE+143) #define __NR_msync (__NR_SYSCALL_BASE+144) #define __NR_readv (__NR_SYSCALL_BASE+145) #define __NR_writev (__NR_SYSCALL_BASE+146) #define __NR_getsid (__NR_SYSCALL_BASE+147) #define __NR_fdatasync (__NR_SYSCALL_BASE+148) #define __NR__sysctl (__NR_SYSCALL_BASE+149) #define __NR_mlock (__NR_SYSCALL_BASE+150) #define __NR_munlock (__NR_SYSCALL_BASE+151) #define __NR_mlockall (__NR_SYSCALL_BASE+152) #define __NR_munlockall (__NR_SYSCALL_BASE+153) #define __NR_sched_setparam (__NR_SYSCALL_BASE+154) #define __NR_sched_getparam (__NR_SYSCALL_BASE+155) #define __NR_sched_setscheduler (__NR_SYSCALL_BASE+156) #define __NR_sched_getscheduler (__NR_SYSCALL_BASE+157) #define __NR_sched_yield (__NR_SYSCALL_BASE+158) #define __NR_sched_get_priority_max (__NR_SYSCALL_BASE+159) #define __NR_sched_get_priority_min (__NR_SYSCALL_BASE+160) #define __NR_sched_rr_get_interval (__NR_SYSCALL_BASE+161) #define __NR_nanosleep (__NR_SYSCALL_BASE+162) #define __NR_mremap (__NR_SYSCALL_BASE+163) #define __NR_setresuid (__NR_SYSCALL_BASE+164) #define __NR_getresuid (__NR_SYSCALL_BASE+165) /* 166 was sys_vm86 */ /* 167 was sys_query_module */ #define __NR_poll (__NR_SYSCALL_BASE+168) #define __NR_nfsservctl (__NR_SYSCALL_BASE+169) #define __NR_setresgid (__NR_SYSCALL_BASE+170) #define __NR_getresgid (__NR_SYSCALL_BASE+171) #define __NR_prctl (__NR_SYSCALL_BASE+172) #define __NR_rt_sigreturn (__NR_SYSCALL_BASE+173) #define __NR_rt_sigaction (__NR_SYSCALL_BASE+174) #define __NR_rt_sigprocmask (__NR_SYSCALL_BASE+175) #define __NR_rt_sigpending (__NR_SYSCALL_BASE+176) #define __NR_rt_sigtimedwait (__NR_SYSCALL_BASE+177) #define __NR_rt_sigqueueinfo (__NR_SYSCALL_BASE+178) #define __NR_rt_sigsuspend (__NR_SYSCALL_BASE+179) #define __NR_pread64 (__NR_SYSCALL_BASE+180) #define __NR_pwrite64 (__NR_SYSCALL_BASE+181) #define __NR_chown (__NR_SYSCALL_BASE+182) #define __NR_getcwd (__NR_SYSCALL_BASE+183) #define __NR_capget (__NR_SYSCALL_BASE+184) #define __NR_capset (__NR_SYSCALL_BASE+185) #define __NR_sigaltstack (__NR_SYSCALL_BASE+186) #define __NR_sendfile (__NR_SYSCALL_BASE+187) /* 188 reserved */ /* 189 reserved */ #define __NR_vfork (__NR_SYSCALL_BASE+190) #define __NR_ugetrlimit (__NR_SYSCALL_BASE+191) /* SuS compliant getrlimit */ #define __NR_mmap2 (__NR_SYSCALL_BASE+192) #define __NR_truncate64 (__NR_SYSCALL_BASE+193) #define __NR_ftruncate64 (__NR_SYSCALL_BASE+194) #define __NR_stat64 (__NR_SYSCALL_BASE+195) #define __NR_lstat64 (__NR_SYSCALL_BASE+196) #define __NR_fstat64 (__NR_SYSCALL_BASE+197) #define __NR_lchown32 (__NR_SYSCALL_BASE+198) #define __NR_getuid32 (__NR_SYSCALL_BASE+199) #define __NR_getgid32 (__NR_SYSCALL_BASE+200) #define __NR_geteuid32 (__NR_SYSCALL_BASE+201) #define __NR_getegid32 (__NR_SYSCALL_BASE+202) #define __NR_setreuid32 (__NR_SYSCALL_BASE+203) #define __NR_setregid32 (__NR_SYSCALL_BASE+204) #define __NR_getgroups32 (__NR_SYSCALL_BASE+205) #define __NR_setgroups32 (__NR_SYSCALL_BASE+206) #define __NR_fchown32 (__NR_SYSCALL_BASE+207) #define __NR_setresuid32 (__NR_SYSCALL_BASE+208) #define __NR_getresuid32 (__NR_SYSCALL_BASE+209) #define __NR_setresgid32 (__NR_SYSCALL_BASE+210) #define __NR_getresgid32 (__NR_SYSCALL_BASE+211) #define __NR_chown32 (__NR_SYSCALL_BASE+212) #define __NR_setuid32 (__NR_SYSCALL_BASE+213) #define __NR_setgid32 (__NR_SYSCALL_BASE+214) #define __NR_setfsuid32 (__NR_SYSCALL_BASE+215) #define __NR_setfsgid32 (__NR_SYSCALL_BASE+216) #define __NR_getdents64 (__NR_SYSCALL_BASE+217) #define __NR_pivot_root (__NR_SYSCALL_BASE+218) #define __NR_mincore (__NR_SYSCALL_BASE+219) #define __NR_madvise (__NR_SYSCALL_BASE+220) #define __NR_fcntl64 (__NR_SYSCALL_BASE+221) /* 222 for tux */ /* 223 is unused */ #define __NR_gettid (__NR_SYSCALL_BASE+224) #define __NR_readahead (__NR_SYSCALL_BASE+225) #define __NR_setxattr (__NR_SYSCALL_BASE+226) #define __NR_lsetxattr (__NR_SYSCALL_BASE+227) #define __NR_fsetxattr (__NR_SYSCALL_BASE+228) #define __NR_getxattr (__NR_SYSCALL_BASE+229) #define __NR_lgetxattr (__NR_SYSCALL_BASE+230) #define __NR_fgetxattr (__NR_SYSCALL_BASE+231) #define __NR_listxattr (__NR_SYSCALL_BASE+232) #define __NR_llistxattr (__NR_SYSCALL_BASE+233) #define __NR_flistxattr (__NR_SYSCALL_BASE+234) #define __NR_removexattr (__NR_SYSCALL_BASE+235) #define __NR_lremovexattr (__NR_SYSCALL_BASE+236) #define __NR_fremovexattr (__NR_SYSCALL_BASE+237) #define __NR_tkill (__NR_SYSCALL_BASE+238) #define __NR_sendfile64 (__NR_SYSCALL_BASE+239) #define __NR_futex (__NR_SYSCALL_BASE+240) #define __NR_sched_setaffinity (__NR_SYSCALL_BASE+241) #define __NR_sched_getaffinity (__NR_SYSCALL_BASE+242) #define __NR_io_setup (__NR_SYSCALL_BASE+243) #define __NR_io_destroy (__NR_SYSCALL_BASE+244) #define __NR_io_getevents (__NR_SYSCALL_BASE+245) #define __NR_io_submit (__NR_SYSCALL_BASE+246) #define __NR_io_cancel (__NR_SYSCALL_BASE+247) #define __NR_exit_group (__NR_SYSCALL_BASE+248) #define __NR_lookup_dcookie (__NR_SYSCALL_BASE+249) #define __NR_epoll_create (__NR_SYSCALL_BASE+250) #define __NR_epoll_ctl (__NR_SYSCALL_BASE+251) #define __NR_epoll_wait (__NR_SYSCALL_BASE+252) #define __NR_remap_file_pages (__NR_SYSCALL_BASE+253) /* 254 for set_thread_area */ /* 255 for get_thread_area */ #define __NR_set_tid_address (__NR_SYSCALL_BASE+256) #define __NR_timer_create (__NR_SYSCALL_BASE+257) #define __NR_timer_settime (__NR_SYSCALL_BASE+258) #define __NR_timer_gettime (__NR_SYSCALL_BASE+259) #define __NR_timer_getoverrun (__NR_SYSCALL_BASE+260) #define __NR_timer_delete (__NR_SYSCALL_BASE+261) #define __NR_clock_settime (__NR_SYSCALL_BASE+262) #define __NR_clock_gettime (__NR_SYSCALL_BASE+263) #define __NR_clock_getres (__NR_SYSCALL_BASE+264) #define __NR_clock_nanosleep (__NR_SYSCALL_BASE+265) #define __NR_statfs64 (__NR_SYSCALL_BASE+266) #define __NR_fstatfs64 (__NR_SYSCALL_BASE+267) #define __NR_tgkill (__NR_SYSCALL_BASE+268) #define __NR_utimes (__NR_SYSCALL_BASE+269) #define __NR_arm_fadvise64_64 (__NR_SYSCALL_BASE+270) #define __NR_pciconfig_iobase (__NR_SYSCALL_BASE+271) #define __NR_pciconfig_read (__NR_SYSCALL_BASE+272) #define __NR_pciconfig_write (__NR_SYSCALL_BASE+273) #define __NR_mq_open (__NR_SYSCALL_BASE+274) #define __NR_mq_unlink (__NR_SYSCALL_BASE+275) #define __NR_mq_timedsend (__NR_SYSCALL_BASE+276) #define __NR_mq_timedreceive (__NR_SYSCALL_BASE+277) #define __NR_mq_notify (__NR_SYSCALL_BASE+278) #define __NR_mq_getsetattr (__NR_SYSCALL_BASE+279) #define __NR_waitid (__NR_SYSCALL_BASE+280) #define __NR_socket (__NR_SYSCALL_BASE+281) #define __NR_bind (__NR_SYSCALL_BASE+282) #define __NR_connect (__NR_SYSCALL_BASE+283) #define __NR_listen (__NR_SYSCALL_BASE+284) #define __NR_accept (__NR_SYSCALL_BASE+285) #define __NR_getsockname (__NR_SYSCALL_BASE+286) #define __NR_getpeername (__NR_SYSCALL_BASE+287) #define __NR_socketpair (__NR_SYSCALL_BASE+288) #define __NR_send (__NR_SYSCALL_BASE+289) #define __NR_sendto (__NR_SYSCALL_BASE+290) #define __NR_recv (__NR_SYSCALL_BASE+291) #define __NR_recvfrom (__NR_SYSCALL_BASE+292) #define __NR_shutdown (__NR_SYSCALL_BASE+293) #define __NR_setsockopt (__NR_SYSCALL_BASE+294) #define __NR_getsockopt (__NR_SYSCALL_BASE+295) #define __NR_sendmsg (__NR_SYSCALL_BASE+296) #define __NR_recvmsg (__NR_SYSCALL_BASE+297) #define __NR_semop (__NR_SYSCALL_BASE+298) #define __NR_semget (__NR_SYSCALL_BASE+299) #define __NR_semctl (__NR_SYSCALL_BASE+300) #define __NR_msgsnd (__NR_SYSCALL_BASE+301) #define __NR_msgrcv (__NR_SYSCALL_BASE+302) #define __NR_msgget (__NR_SYSCALL_BASE+303) #define __NR_msgctl (__NR_SYSCALL_BASE+304) #define __NR_shmat (__NR_SYSCALL_BASE+305) #define __NR_shmdt (__NR_SYSCALL_BASE+306) #define __NR_shmget (__NR_SYSCALL_BASE+307) #define __NR_shmctl (__NR_SYSCALL_BASE+308) #define __NR_add_key (__NR_SYSCALL_BASE+309) #define __NR_request_key (__NR_SYSCALL_BASE+310) #define __NR_keyctl (__NR_SYSCALL_BASE+311) #define __NR_semtimedop (__NR_SYSCALL_BASE+312) #define __NR_vserver (__NR_SYSCALL_BASE+313) #define __NR_ioprio_set (__NR_SYSCALL_BASE+314) #define __NR_ioprio_get (__NR_SYSCALL_BASE+315) #define __NR_inotify_init (__NR_SYSCALL_BASE+316) #define __NR_inotify_add_watch (__NR_SYSCALL_BASE+317) #define __NR_inotify_rm_watch (__NR_SYSCALL_BASE+318) #define __NR_mbind (__NR_SYSCALL_BASE+319) #define __NR_get_mempolicy (__NR_SYSCALL_BASE+320) #define __NR_set_mempolicy (__NR_SYSCALL_BASE+321) #define __NR_openat (__NR_SYSCALL_BASE+322) #define __NR_mkdirat (__NR_SYSCALL_BASE+323) #define __NR_mknodat (__NR_SYSCALL_BASE+324) #define __NR_fchownat (__NR_SYSCALL_BASE+325) #define __NR_futimesat (__NR_SYSCALL_BASE+326) #define __NR_fstatat64 (__NR_SYSCALL_BASE+327) #define __NR_unlinkat (__NR_SYSCALL_BASE+328) #define __NR_renameat (__NR_SYSCALL_BASE+329) #define __NR_linkat (__NR_SYSCALL_BASE+330) #define __NR_symlinkat (__NR_SYSCALL_BASE+331) #define __NR_readlinkat (__NR_SYSCALL_BASE+332) #define __NR_fchmodat (__NR_SYSCALL_BASE+333) #define __NR_faccessat (__NR_SYSCALL_BASE+334) /* 335 for pselect6 */ /* 336 for ppoll */ #define __NR_unshare (__NR_SYSCALL_BASE+337) #define __NR_set_robust_list (__NR_SYSCALL_BASE+338) #define __NR_get_robust_list (__NR_SYSCALL_BASE+339) #define __NR_splice (__NR_SYSCALL_BASE+340) #define __NR_arm_sync_file_range (__NR_SYSCALL_BASE+341) #define __NR_tee (__NR_SYSCALL_BASE+342) #define __NR_vmsplice (__NR_SYSCALL_BASE+343) #define __NR_move_pages (__NR_SYSCALL_BASE+344) #define __NR_getcpu (__NR_SYSCALL_BASE+345) /* 346 for epoll_pwait */ #define __NR_kexec_load (__NR_SYSCALL_BASE+347) #define __NR_utimensat (__NR_SYSCALL_BASE+348) #define __NR_signalfd (__NR_SYSCALL_BASE+349) #define __NR_timerfd (__NR_SYSCALL_BASE+350) #define __NR_eventfd (__NR_SYSCALL_BASE+351) #define __NR_fallocate (__NR_SYSCALL_BASE+352) #define __NR_timerfd_settime (__NR_SYSCALL_BASE+353) #define __NR_timerfd_gettime (__NR_SYSCALL_BASE+354) /* * The following SWIs are ARM private. */ #define __ARM_NR_BASE (__NR_SYSCALL_BASE+0x0f0000) #define __ARM_NR_breakpoint (__ARM_NR_BASE+1) #define __ARM_NR_cacheflush (__ARM_NR_BASE+2) #define __ARM_NR_usr26 (__ARM_NR_BASE+3) #define __ARM_NR_usr32 (__ARM_NR_BASE+4) #define __ARM_NR_set_tls (__ARM_NR_BASE+5) /* * The following syscalls are obsolete and no longer available for EABI. */ #if defined(__ARM_EABI__) && !defined(__KERNEL__) #undef __NR_time #undef __NR_umount #undef __NR_stime #undef __NR_alarm #undef __NR_utime #undef __NR_getrlimit #undef __NR_select #undef __NR_readdir #undef __NR_mmap #undef __NR_socketcall #undef __NR_syscall #undef __NR_ipc #endif /* ok the next few values are for the optimization of the unified syscalls * on arm. * If the syscall has #arguments * <=4 set to 0 * >4 set to 1 * * Since the majority of the syscalls need <=4 arguments this saves a lot * of byte (12 per syscall) and cycles (~16) */ #define __ARGS_exit 0 #define __ARGS_fork 0 #define __ARGS_read 0 #define __ARGS_write 0 #define __ARGS_open 0 #define __ARGS_close 0 #define __ARGS_waitpid 0 #define __ARGS_creat 0 #define __ARGS_link 0 #define __ARGS_unlink 0 #define __ARGS_execve 0 #define __ARGS_chdir 0 #define __ARGS_time 0 #define __ARGS_mknod 0 #define __ARGS_chmod 0 #define __ARGS_lchown 0 #define __ARGS_break 0 #define __ARGS_lseek 0 #define __ARGS_getpid 0 #define __ARGS_mount 1 #define __ARGS_umount 0 #define __ARGS_setuid 0 #define __ARGS_getuid 0 #define __ARGS_stime 0 #define __ARGS_ptrace 0 #define __ARGS_alarm 0 #define __ARGS_pause 0 #define __ARGS_utime 0 #define __ARGS_stty 0 #define __ARGS_gtty 0 #define __ARGS_access 0 #define __ARGS_nice 0 #define __ARGS_ftime 0 #define __ARGS_sync 0 #define __ARGS_kill 0 #define __ARGS_rename 0 #define __ARGS_mkdir 0 #define __ARGS_rmdir 0 #define __ARGS_dup 0 #define __ARGS_pipe 0 #define __ARGS_times 0 #define __ARGS_prof 0 #define __ARGS_brk 0 #define __ARGS_setgid 0 #define __ARGS_getgid 0 #define __ARGS_signal 0 #define __ARGS_geteuid 0 #define __ARGS_getegid 0 #define __ARGS_acct 0 #define __ARGS_umount2 0 #define __ARGS_lock 0 #define __ARGS_ioctl 0 #define __ARGS_fcntl 0 #define __ARGS_mpx 0 #define __ARGS_setpgid 0 #define __ARGS_ulimit 0 #define __ARGS_umask 0 #define __ARGS_chroot 0 #define __ARGS_ustat 0 #define __ARGS_dup2 0 #define __ARGS_getppid 0 #define __ARGS_getpgrp 0 #define __ARGS_setsid 0 #define __ARGS_sigaction 0 #define __ARGS_sgetmask 0 #define __ARGS_ssetmask 0 #define __ARGS_setreuid 0 #define __ARGS_setregid 0 #define __ARGS_sigsuspend 0 #define __ARGS_sigpending 0 #define __ARGS_sethostname 0 #define __ARGS_setrlimit 0 #define __ARGS_getrlimit 0 #define __ARGS_getrusage 0 #define __ARGS_gettimeofday 0 #define __ARGS_settimeofday 0 #define __ARGS_getgroups 0 #define __ARGS_setgroups 0 #define __ARGS_select 0 #define __ARGS_symlink 0 #define __ARGS_readlink 0 #define __ARGS_uselib 0 #define __ARGS_swapon 0 #define __ARGS_reboot 0 #define __ARGS_readdir 0 #define __ARGS_mmap 0 /* this is NOT 1 !!! (special case) */ #define __ARGS_munmap 0 #define __ARGS_truncate 0 #define __ARGS_ftruncate 0 #define __ARGS_fchmod 0 #define __ARGS_fchown 0 #define __ARGS_getpriority 0 #define __ARGS_setpriority 0 #define __ARGS_profil 0 #define __ARGS_statfs 0 #define __ARGS_fstatfs 0 #define __ARGS_ioperm 0 #define __ARGS_socketcall 0 #define __ARGS_syslog 0 #define __ARGS_setitimer 0 #define __ARGS_getitimer 0 #define __ARGS_stat 0 #define __ARGS_lstat 0 #define __ARGS_fstat 0 #define __ARGS_vhangup 0 #define __ARGS_idle 0 #define __ARGS_syscall 0 #define __ARGS_wait4 0 #define __ARGS_swapoff 0 #define __ARGS_sysinfo 0 #define __ARGS_ipc 1 #define __ARGS_fsync 0 #define __ARGS_sigreturn 0 #define __ARGS_clone 0 #define __ARGS_setdomainname 0 #define __ARGS_uname 0 #define __ARGS_modify_ldt 0 #define __ARGS_adjtimex 0 #define __ARGS_mprotect 0 #define __ARGS_sigprocmask 0 #define __ARGS_create_module 0 #define __ARGS_init_module 0 #define __ARGS_delete_module 0 #define __ARGS_get_kernel_syms 0 #define __ARGS_quotactl 0 #define __ARGS_getpgid 0 #define __ARGS_fchdir 0 #define __ARGS_bdflush 0 #define __ARGS_sysfs 0 #define __ARGS_personality 0 #define __ARGS_afs_syscall 0 #define __ARGS_setfsuid 0 #define __ARGS_setfsgid 0 #define __ARGS__llseek 1 #define __ARGS_getdents 0 #define __ARGS__newselect 1 #define __ARGS_flock 0 #define __ARGS_msync 0 #define __ARGS_readv 0 #define __ARGS_writev 0 #define __ARGS_getsid 0 #define __ARGS_fdatasync 0 #define __ARGS__sysctl 0 #define __ARGS_mlock 0 #define __ARGS_munlock 0 #define __ARGS_mlockall 0 #define __ARGS_munlockall 0 #define __ARGS_sched_setparam 0 #define __ARGS_sched_getparam 0 #define __ARGS_sched_setscheduler 0 #define __ARGS_sched_getscheduler 0 #define __ARGS_sched_yield 0 #define __ARGS_sched_get_priority_max 0 #define __ARGS_sched_get_priority_min 0 #define __ARGS_sched_rr_get_interval 0 #define __ARGS_nanosleep 0 #define __ARGS_mremap 0 #define __ARGS_setresuid 0 #define __ARGS_getresuid 0 #define __ARGS_vm86 0 #define __ARGS_query_module 1 #define __ARGS_poll 0 #define __ARGS_nfsservctl 0 #define __ARGS_setresgid 0 #define __ARGS_getresgid 0 #define __ARGS_prctl 1 #define __ARGS_rt_sigreturn 0 #define __ARGS_rt_sigaction 0 #define __ARGS_rt_sigprocmask 0 #define __ARGS_rt_sigpending 0 #define __ARGS_rt_sigtimedwait 0 #define __ARGS_rt_sigqueueinfo 0 #define __ARGS_rt_sigsuspend 0 #define __ARGS_pread 0 #define __ARGS_pwrite 0 #define __ARGS_pread64 0 #define __ARGS_pwrite64 0 #define __ARGS_chown 0 #define __ARGS_getcwd 0 #define __ARGS_capget 0 #define __ARGS_capset 0 #define __ARGS_sigaltstack 0 #define __ARGS_sendfile 0 #define __ARGS_vfork 0 #define __ARGS_ugetrlimit 0 #define __ARGS_mmap2 1 #define __ARGS_truncate64 0 #define __ARGS_ftruncate64 0 #define __ARGS_stat64 0 #define __ARGS_lstat64 0 #define __ARGS_fstat64 0 #define __ARGS_lchown32 0 #define __ARGS_getuid32 0 #define __ARGS_getgid32 0 #define __ARGS_geteuid32 0 #define __ARGS_getegid32 0 #define __ARGS_setreuid32 0 #define __ARGS_setregid32 0 #define __ARGS_getgroups32 0 #define __ARGS_setgroups32 0 #define __ARGS_fchown32 0 #define __ARGS_setresuid32 0 #define __ARGS_getresuid32 0 #define __ARGS_setresgid32 0 #define __ARGS_getresgid32 0 #define __ARGS_chown32 0 #define __ARGS_setuid32 0 #define __ARGS_setgid32 0 #define __ARGS_setfsuid32 0 #define __ARGS_setfsgid32 0 #define __ARGS_getdents64 0 #define __ARGS_pivot_root 0 #define __ARGS_mincore 0 #define __ARGS_madvise 0 #define __ARGS_fcntl64 0 #define __ARGS_security 0 #define __ARGS_gettid 0 #define __ARGS_readahead 0 #define __ARGS_setxattr 1 #define __ARGS_lsetxattr 1 #define __ARGS_fsetxattr 1 #define __ARGS_getxattr 0 #define __ARGS_lgetxattr 0 #define __ARGS_fgetxattr 0 #define __ARGS_listxattr 0 #define __ARGS_llistxattr 0 #define __ARGS_flistxattr 0 #define __ARGS_removexattr 0 #define __ARGS_lremovexattr 0 #define __ARGS_fremovexattr 0 #define __ARGS_tkill 0 #define __ARGS_sendfile64 0 #define __ARGS_futex 0 #define __ARGS_sched_setaffinity 0 #define __ARGS_sched_getaffinity 0 #define __ARGS_io_setup 0 #define __ARGS_io_destroy 0 #define __ARGS_io_getevents 0 #define __ARGS_io_submit 0 #define __ARGS_io_cancel 0 #define __ARGS_exit_group 0 #define __ARGS_lookup_dcookie 0 #define __ARGS_epoll_create 0 #define __ARGS_epoll_ctl 0 #define __ARGS_epoll_wait 0 #define __ARGS_remap_file_pages 0 #define __ARGS_set_thread_area 0 #define __ARGS_get_thread_area 0 #define __ARGS_set_tid_address 0 #define __ARGS_timer_create 0 #define __ARGS_timer_settime 0 #define __ARGS_timer_gettime 0 #define __ARGS_timer_getoverrun 0 #define __ARGS_timer_delete 0 #define __ARGS_clock_settime 0 #define __ARGS_clock_gettime 0 #define __ARGS_clock_getres 0 #define __ARGS_clock_nanosleep 0 #define __ARGS_statfs64 0 #define __ARGS_fstatfs64 0 #define __ARGS_tgkill 0 #define __ARGS_utimes 0 #define __ARGS_arm_fadvise64_64 1 #define __ARGS_fadvise64 0 #define __ARGS_fadvise64_64 0 #define __ARGS_pciconfig_iobase 0 #define __ARGS_pciconfig_read 1 #define __ARGS_pciconfig_write 1 #define __ARGS_mq_open 0 #define __ARGS_mq_unlink 0 #define __ARGS_mq_timedsend 0 #define __ARGS_mq_timedreceive 1 #define __ARGS_mq_notify 0 #define __ARGS_mq_getsetattr 0 #define __ARGS_waitid 0 #define __ARGS_socket 0 #define __ARGS_bind 0 #define __ARGS_connect 0 #define __ARGS_listen 0 #define __ARGS_accept 0 #define __ARGS_getsockname 0 #define __ARGS_getpeername 0 #define __ARGS_socketpair 0 #define __ARGS_send 0 #define __ARGS_sendto 0 #define __ARGS_recv 0 #define __ARGS_recvfrom 0 #define __ARGS_shutdown 0 #define __ARGS_setsockopt 0 #define __ARGS_getsockopt 0 #define __ARGS_sendmsg 0 #define __ARGS_recvmsg 0 #define __ARGS_semop 0 #define __ARGS_semget 0 #define __ARGS_semctl 0 #define __ARGS_msgsnd 0 #define __ARGS_msgrcv 0 #define __ARGS_msgget 0 #define __ARGS_msgctl 0 #define __ARGS_shmat 0 #define __ARGS_shmdt 0 #define __ARGS_shmget 0 #define __ARGS_shmctl 0 #define __ARGS_add_key 1 #define __ARGS_request_key 1 #define __ARGS_keyctl 0 #define __ARGS_vserver 0 #define __ARGS_ioprio_set 0 #define __ARGS_ioprio_get 0 #define __ARGS_inotify_init 0 #define __ARGS_inotify_add_watch 0 #define __ARGS_inotify_rm_watch 0 #define __ARGS_mbind 1 #define __ARGS_get_mempolicy 1 #define __ARGS_set_mempolicy 1 #define __ARGS_openat 0 #define __ARGS_mkdirat 0 #define __ARGS_mknodat 0 #define __ARGS_fchownat 1 #define __ARGS_futimesat 0 #define __ARGS_fstatat64 0 #define __ARGS_unlinkat 0 #define __ARGS_renameat 0 #define __ARGS_linkat 1 #define __ARGS_symlinkat 0 #define __ARGS_readlinkat 0 #define __ARGS_fchmodat 0 #define __ARGS_faccessat 0 /* 335 for pselect6 */ /* 336 for ppoll */ #define __ARGS_unshare 0 #define __ARGS_set_robust_list 0 #define __ARGS_get_robust_list 0 #define __ARGS_splice 1 #define __ARGS_arm_sync_file_range 0 #define __ARGS_sync_file_range2 0 #define __ARGS_tee 0 #define __ARGS_vmsplice 0 #define __ARGS_move_pages 1 #define __ARGS_getcpu 0 /* 346 for epoll_pwait */ #define __ARGS_kexec_load 0 #define __ARGS_utimensat 0 #define __ARGS_signalfd 0 #define __ARGS_timerfd 0 #define __ARGS_eventfd 0 #define __ARGS_fallocate 0 #define __ARGS_timerfd_settime 0 #define __ARGS_timerfd_gettime 0 #ifdef __ASSEMBLER__ #ifdef __ARM_EABI__ #define syscall_weak(name,wsym,sym) __syscall_weak __NR_##name, wsym, sym, __ARGS_##name .macro __syscall_weak name wsym sym typ .text .type \wsym,function .weak \wsym \wsym: .type \sym,function .global \sym \sym: stmfd sp!,{r4,r5,r7,lr} ldr r4, [sp,#16] ldr r5, [sp,#20] ldr r7, =\name swi 0 b __unified_syscall .endm #define syscall(name,sym) __syscall __NR_##name, sym, __ARGS_##name .macro __syscall name sym typ .text .type \sym,function .global \sym \sym: stmfd sp!,{r4,r5,r7,lr} ldr r4, [sp,#16] ldr r5, [sp,#20] ldr r7, =\name swi 0 b __unified_syscall .endm #else #define syscall_weak(name,wsym,sym) __syscall_weak $__NR_##name, wsym, sym, __ARGS_##name .macro __syscall_weak name wsym sym typ .text .type \wsym,function .weak \wsym \wsym: .type \sym,function .global \sym \sym: .ifgt \typ mov ip, sp stmfd sp!,{r4, r5, r6} ldmia ip, {r4, r5, r6} .endif swi \name .ifgt \typ b __unified_syscall4 .else b __unified_syscall .endif .endm #define syscall(name,sym) __syscall $__NR_##name, sym, __ARGS_##name .macro __syscall name sym typ .text .type \sym,function .global \sym \sym: .ifgt \typ mov ip, sp stmfd sp!,{r4, r5, r6} ldmia ip, {r4, r5, r6} .endif swi \name .ifgt \typ b __unified_syscall4 .else b __unified_syscall .endif .endm #endif #endif #endif dietlibc-0.33~cvs20120325/arm/unified.S010064400000000000000000000020341173363226000142260ustar00 #include .text #ifdef __ARM_EABI__ .align 4 #else .align 2 #endif .global __unified_syscall .global __unified_syscall4 #ifdef __ARM_EABI__ __unified_syscall4: __unified_syscall: cmn r0, #4096 rsbcs r2, r0, #0 ldrcs r3, 1f mvncs r0, #0 strcs r2, [r3] ldmfd sp!,{r4,r5,r7,pc} .balign 4 1: .word errno /* here we go and "reuse" the return for weak-void functions */ #include "dietuglyweaks.h" mov pc, lr @ return #else __unified_syscall4: ldmia sp!, {r4, r5, r6} __unified_syscall: cmn r0, #4096 movcc pc, lr @ return value comes direct from kernel. rsb r1, r0, #0 #ifdef WANT_THREAD_SAFE stmdb sp!, {r1, lr} bl __errno_location ldmia sp!, {r1, lr} #else ldr r0, .L0 #endif str r1, [r0] @ store error code into 'errno' mvn r0, #0 @ return value = -1 /* here we go and "reuse" the return for weak-void functions */ #include "dietuglyweaks.h" mov pc, lr @ return #ifndef WANT_THREAD_SAFE .L0: .long errno #endif #endif dietlibc-0.33~cvs20120325/arm/waitpid.S010064400000000000000000000003401173363226000142420ustar00.text #ifdef __ARM_EABI__ .align 4 #else .align 2 #endif .weak waitpid .type waitpid, %function waitpid: .global __libc_waitpid .type __libc_waitpid, %function __libc_waitpid: mov r3, #0 b wait4 .size waitpid, .-waitpid dietlibc-0.33~cvs20120325/binshstr.h010064400000000000000000000001421173363226000137030ustar00 extern const char __binsh [8]; #define __sh (__binsh + 5 ) /* end of binshstr.h */ dietlibc-0.33~cvs20120325/contrib/Makefile.dyn010064400000000000000000000005161173363226000155740ustar00CC = gcc DCC = diet gcc PDIET = /opt/diet/lib CFLAGS = -Wall -O2 LDFLAGS = -nostdlib -rdynamic LIBS = $(PDIET)/libdietc.so -lgcc DYN_LINK = -Wl,-rpath,$(PDIET),-dynamic-linker,$(PDIET)/diet-linux.so OBJS = dyn_prog: $(OBJS) $(CC) $(LDFLAGS) -o $@ $(PDIET)/start.o $(OBJS) $(LIBS) $(DYN_LINK) dietlibc-0.33~cvs20120325/contrib/bcd.c010064400000000000000000000116541173363226000142440ustar00 static long double powers [] = { 1.e+1, 1.e+2, 1.e+4, 1.e+8, 1.e+16, 1.e+32, 1.e+64, 1.e+128, 1.e+256 }; /* * So, die ist zum Zerlegen von Gleitkommazahlen am besten geeignet. * * Die nichtnegative übergebende Gleitkommazahl number wird in einen * Exponenten e und eine Mantisse m zerlegt mit: * * 1 <= m < 10 * number = m * 10^e * * Die Mantisse wird in precision Dezimalstellen zerlegt, die nach digits * geschrieben werden. digits[0] ist die Vorkommastelle, digits [1 ... * precision-1] die Nachkommastellen der Mantisse Zurückgeliefert wird der * Exponent. * * Für precision ist ein Wert von 0 erlaubt, Sinn machen allerdings erst * Werte ab 1. */ int __decompose_floatp ( long double number, unsigned char* digits, unsigned int precision ); int __decompose_floatp ( long double number, unsigned char* digits, unsigned int precision ) { int ret = 0; int i; double tmp; if ( number > 0.L ) { // Exponent abtrennen if ( number >= 10.L ) { for ( i = sizeof(powers)/sizeof(*powers)-1; i >= 0; i--) if ( number >= powers [i] ) { number /= powers [i]; ret += 1 << i; } } else if ( number < 1.L ) for ( i = sizeof(powers)/sizeof(*powers)-1; i >= 0; i--) if ( number * powers [i] < 10.L ) { number *= powers [i]; ret -= 1 << i; } // Runden (ohne Geradezahlregel => Bug) tmp = 5.; { unsigned int j; for ( j = 0; j < precision; j++ ) tmp *= 0.1; } number += tmp; // Dabei kann die Zahl in die nächste Dekade reinrutschen ... if ( number >= 10.L ) { number = 1.L; ret++; } } // Mantisse in ASCII konvertieren while ( precision-- ) { i = (int) number; number = (number - i) * 10.L; *digits++ = '0' + i; } // Exponent zurück return ret; } /* * So, die ist zum Zerlegen von Festkommazahlen am besten geeignet. * * Die nichtnegative übergebende Festkomma wird in einen Integeranteil und * einen Bruchanteil zerlegt. * * Der Bruchanteil wird in digits_frac[0...precision_frac-1] gespeichert, * falls precision_frac != 0 ist. * * Der Integeranteil wird ab digits_int + precision_int - 1 rückwrts * geschrieben. Zurückgeliefert wird ein Zeiger auf das erste Zeichen, das * bei der Konvertierung != '0' ist (Ausnahme ist die 0.0 selbst). Zeichen * zwischen digits_int und diesem Zeiger (exklusive des Zeichens unter dem * Zeiger) sind unbestimmt. Wünscht man dort Nullen oder Leerzeichen, * sollte man mittels memset() dieses vorher initialsieren. */ char* __decompose_fixp ( long double number, unsigned char* digits_int , unsigned int precision_int, unsigned char* digits_frac, unsigned int precision_frac ); char* __decompose_fixp ( long double number, unsigned char* digits_int , unsigned int precision_int, unsigned char* digits_frac, unsigned int precision_frac ) { long long int integer; double tmp; int i; // Runden (ohne Geradezahlregel => Bug) tmp = 0.5; { unsigned int j; for ( j = 0; j < precision_frac; j++ ) tmp *= 0.1; } number += tmp; integer = number; number -= integer; // Nachkommastellen while ( precision_frac-- ) { number *= 10.L; i = (int) number; number -= i; *digits_frac++ = '0' + i; } // Vorkommastellen while ( precision_int ) { i = (int) (integer % 10); integer /= 10; digits_int [--precision_int] = '0' + i; if ( integer == 0 ) break; } return digits_int + precision_int; } #if 0 #include #include long double test [] = { 1, M_PI, 123, 123456789, 12345678901234567, 1e300, 0.00123456789, 1.234567890123456e-300, 0 }; int main ( void ) { int i; int j; int k; char buff1 [32]; char buff2 [32]; char* retp; int ret; for ( i = 0; i < sizeof(test)/sizeof(*test); i++ ) { printf ("\n*** %30.20Lf ***\n\n", test[i] ); for ( j = 0; j <= 20; j++ ) { memset ( buff1, 0, sizeof(buff1) ); ret = __decompose_floatp ( test[i], buff1, j ); printf ( "floatp(%2u) = <%sE%+d>\n", j, buff1, ret ); } for ( j = 0; j <= 20; j++ ) { for ( k = 0; k <= 20; k++ ) { memset ( buff1, 0, sizeof(buff1) ); memset ( buff2, 0, sizeof(buff2) ); retp = __decompose_fixp ( test[i], buff1, j, buff2, k ); printf ( "fixp(%2u,%2u) = <%s.%s>\n", j, k, retp, buff2 ); } } } return 0; } #endif dietlibc-0.33~cvs20120325/contrib/debug-realloc.c010064400000000000000000000042101173363226000162070ustar00#include #include #include #ifdef DEBUG #include #endif static struct malloced { unsigned long len,maplen; struct malloced* next; unsigned long magic; }* root=0; static const unsigned long MAGIC=(unsigned long)0xfefec0dedeadbeefull; static void checkmagic() { struct malloced* x=root; while (x) { if (x->magic != MAGIC) abort(); x=x->next; } } static void* domalloc(size_t size) { char* n,* m; unsigned long s=size+sizeof(struct malloced); checkmagic(); s=(s+4096+4095)&~4095; // add one page, and round up to fill one page n=mmap(0,s,PROT_NONE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); if (n==MAP_FAILED) return 0; m=n-size; while (mlen=size; ((struct malloced*)n)->maplen=s; ((struct malloced*)n)->next=root; ((struct malloced*)n)->magic=MAGIC; root=(struct malloced*)n; return m; } void* malloc(size_t size) { void* m=domalloc(size);; #ifdef DEBUG printf("malloc(%zu) -> %p\n",size,m); #endif return m; } static void dofree(void* ptr) { struct malloced** x=&root; checkmagic(); while (*x) { if (((char*)(*x))+sizeof(struct malloced)<(char*)ptr && ((char*)(*x))+4096>(char*)ptr) { struct malloced* old=*x; *x=(*x)->next; mprotect(old,old->maplen,PROT_NONE); return; } x=&(*x)->next; } abort(); } void free(void* ptr) { #ifdef DEBUG printf("free(%p)\n",ptr); #endif dofree(ptr); } void *realloc(void *ptr, size_t size) { unsigned long oldsize=0; struct malloced* x=root; char* fnord; if (ptr) { oldsize=-1; while (x) { if (((char*)x)+sizeof(struct malloced)<(char*)ptr && ((char*)x)+4096>(char*)ptr) { oldsize=x->len; break; } x=x->next; } if (oldsize==(unsigned long)-1) abort(); } fnord=domalloc(size); memcpy(fnord,ptr,size>oldsize?oldsize:size); if (oldsize) dofree(ptr); #ifdef DEBUG printf("realloc(%p,%zu) -> %p\n",ptr,size,fnord); #endif return fnord; } dietlibc-0.33~cvs20120325/contrib/debug-realloc.txt010064400000000000000000000010331173363226000166040ustar00This is a stupid malloc debugger. malloc will always round up to a full page and then mmap one more page than that. It will then allocate the space in a way that makes the allocation end at one page, thus causing access behind the array border to segfault. realloc will malloc new memory, copy the old contents, and then mprotect the old memory away, so referencing it will cause a segfault, too. This is a big drain on resources and will slow down your program. But it may prove useful in finding bad memory references in your code. dietlibc-0.33~cvs20120325/contrib/dietlibc.spec010064400000000000000000000021661173363226000160010ustar00%define name dietlibc %define version 20010308 %define release 1mdk Summary: C library optimized for size Name: %{name} Version: %{version} Release: %{release} Copyright: GPL Group: Development/Other BuildRoot: %{_tmppath}/%{name}-%{version}-build Requires: common-licenses Source0: http://www.fefe.de/dietlibc/%{name}-%{version}.tar.bz2 Patch0: dietlibc-20010308-install-includes.patch.bz2 %description Small libc for building embedded applications. %package devel Group: Development/C Summary: Development files for dietlibc Requires: %name = %version-%release %description devel Small libc for building embedded applications. %prep %setup %patch0 -p1 %build %make "CFLAGS=-march=i586 -fomit-frame-pointer -Os" %install make prefix=%{_prefix} INSTALLPREFIX=$RPM_BUILD_ROOT install %clean rm -rf $RPM_BUILD_ROOT %files %defattr(-,root,root) %doc README THANKS CAVEAT BUGS AUTHOR %dir %{_prefix}/dietlibc %files devel %defattr(-,root,root) %doc CHANGES TODO %{_prefix}/dietlibc/* %{_libdir}/* %changelog * Thu Mar 8 2001 Jeff Garzik 20010308-1mdk - first mdk contribs version dietlibc-0.33~cvs20120325/contrib/dnsd.c010064400000000000000000000240361173363226000144420ustar00#define _BSD_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #include #include char myhostname[100]; int namelen; struct sockaddr* peer; socklen_t sl; /* zeroconf/bonjour */ int s6,s4; /* llmnr */ int ls6,ls4; char ifname[10]; struct sockaddr_in mysa4; struct sockaddr_in6 mysa6; struct msghdr mh; #define PKGSIZE 1500 static int scan_fromhex(unsigned char c) { c-='0'; if (c<=9) return c; c&=~0x20; c-='A'-'0'; if (c<6) return c+10; return -1; /* more readable but creates worse code: if (c>='0' && c<='9') return c-'0'; else if (c>='A' && c<='F') return c-'A'+10; else if (c>='a' && c<='f') return c-'a'+10; return -1; */ } static void getip(int interface) { int fd; struct cmsghdr* x; memset(&mysa4,0,sizeof(mysa4)); memset(&mysa6,0,sizeof(mysa6)); for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x)) if (x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO) { mysa4.sin_addr=((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_spec_dst; #ifdef DEBUG printf("found IP %x\n",mysa4.sin_addr.s_addr); #endif } fd=open("/proc/net/if_inet6",O_RDONLY); if (fd!=-1) { char buf[1024]; /* increase as necessary */ int i,j,len; len=read(fd,buf,sizeof buf); if (len>0) { int ok; char* c=buf; char* max=buf+len; ok=0; /* "fec000000000000102c09ffffe53fc52 01 40 40 00 eth0" */ while (csin_addr,4); } slen+=4+12; } if (type==28 || type==255) { /* AAAA or ANY */ if (!IN6_IS_ADDR_UNSPECIFIED(mysa6.sin6_addr.s6_addr32)) { memcpy(obuf+slen,"\xc0\x0c" /* goofy DNS compression */ "\x00\x1c" /* AAAA */ "\x00\x01" /* IN */ "\x00\x00\x02\x30" /* ttl */ "\x00\x10" /* 16 bytes payload */ ,12); memcpy(obuf+slen+12,&mysa6.sin6_addr,16); slen+=28; ++obuf[7]; } } if (obuf[7]) sendto(s,obuf,slen,0,peer,sl); } } struct sockaddr_in sa4; struct sockaddr_in6 sa6; struct pollfd pfd[4]; struct iovec iv; char abuf[100]; char buf[PKGSIZE+1]; static int v4if() { struct cmsghdr* x; for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x)) if (x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO) return ((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_ifindex; return 0; } static void recv4(int s) { int len; mh.msg_name=&sa4; mh.msg_namelen=sizeof(sa4); if ((len=recvmsg(s,&mh,0))==-1) { perror("recvmsg"); exit(3); } peer=(struct sockaddr*)&sa4; sl=sizeof(sa4); #ifdef DEBUG printf("v4: "); #endif handle(s,buf,len,v4if(),s==ls4); } static void recv6(int s) { int len,interface; #ifdef DEBUG char addrbuf[INET6_ADDRSTRLEN]; char ifbuf[IFNAMSIZ]; #endif mh.msg_name=&sa6; mh.msg_namelen=sizeof(sa6); #if 0 mh.msg_control=abuf; mh.msg_controllen=sizeof(abuf); #endif if ((len=recvmsg(s,&mh,0))==-1) { perror("recvmsg"); exit(3); } peer=(struct sockaddr*)&sa6; sl=sizeof(sa6); if (IN6_IS_ADDR_V4MAPPED(sa6.sin6_addr.s6_addr32)) { interface=v4if(); #ifdef DEBUG inet_ntop(AF_INET,(char*)(sa6.sin6_addr.s6_addr)+12,addrbuf,sizeof addrbuf); if_indextoname(interface,ifbuf); printf("v4: %s: ",ifbuf); #endif } else { interface=sa6.sin6_scope_id; #ifdef DEBUG inet_ntop(AF_INET6,sa6.sin6_addr.s6_addr,addrbuf,sizeof addrbuf); if_indextoname(interface,ifbuf); printf("v6: %s: ",ifbuf); #endif } handle(s,buf,len,interface,s==ls6); #ifdef DEBUG printf(" from %s\n",addrbuf); #endif } static void init_sockets(int* sock6,int* sock4,int port,char* v6ip,char* v4ip) { int s4,s6; int one=1; *sock6=-1; *sock4=-1; s6=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP); s4=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP); if (s4==-1 && s6==-1) { perror("socket"); return; } if (s6!=-1) { setsockopt(s6,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one)); memset(&sa6,0,sizeof(sa6)); sa6.sin6_family=PF_INET6; sa6.sin6_port=htons(port); if (bind(s6,(struct sockaddr*)&sa6,sizeof(struct sockaddr_in6))==-1) { perror("bind IPv6"); close(s6); s6=-1; } } if (s4!=-1) { setsockopt(s4,SOL_SOCKET,SO_REUSEADDR,&one,sizeof(one)); memset(&sa4,0,sizeof(sa4)); sa4.sin_family=PF_INET; sa4.sin_port=htons(port); if (bind(s4,(struct sockaddr*)&sa4,sizeof(struct sockaddr_in))==-1) { if (errno!=EADDRINUSE || s6==-1) perror("bind IPv4"); close(s4); s4=-1; } } if (s4==-1 && s6==-1) return; { int val=255; int one=1; if (s6!=-1) { struct ipv6_mreq opt; setsockopt(s6,IPPROTO_IPV6,IPV6_UNICAST_HOPS,&val,sizeof(val)); setsockopt(s6,IPPROTO_IPV6,IPV6_MULTICAST_LOOP,&one,sizeof(one)); memcpy(&opt.ipv6mr_multiaddr,v6ip,16); opt.ipv6mr_interface=0; setsockopt(s6,IPPROTO_IPV6,IPV6_ADD_MEMBERSHIP,&opt,sizeof opt); setsockopt(s6,IPPROTO_IPV6,IPV6_PKTINFO,&one,sizeof one); } { struct ip_mreq opt; int s=(s4==-1?s6:s4); setsockopt(s,SOL_IP,IP_TTL,&val,sizeof(val)); memcpy(&opt.imr_multiaddr.s_addr,v4ip,4); opt.imr_interface.s_addr=0; setsockopt(s,IPPROTO_IP,IP_ADD_MEMBERSHIP,&opt,sizeof(opt)); setsockopt(s,SOL_IP,IP_PKTINFO,&one,sizeof one); } } *sock4=s4; *sock6=s6; } int main() { int n=-1; mh.msg_name=&sa4; mh.msg_namelen=sizeof(sa4); mh.msg_iov=&iv; mh.msg_iovlen=1; iv.iov_base=buf; iv.iov_len=PKGSIZE; mh.msg_control=abuf; mh.msg_controllen=sizeof(abuf); if (gethostname(myhostname,64)==-1) { perror("gethostname"); return 1; } namelen=strlen(myhostname); init_sockets(&s6,&s4,5353,"\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb","\xe0\x00\x00\xfb"); init_sockets(&ls6,&ls4,5355,"\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x03","\xe0\x00\x00\xfc"); pfd[0].events=pfd[1].events=pfd[2].events=pfd[3].events=POLLIN; if (s6!=-1) pfd[++n].fd=s6; if (s4!=-1) pfd[++n].fd=s4; if (ls6!=-1) pfd[++n].fd=ls6; if (ls4!=-1) pfd[++n].fd=ls4; if (!++n) return 2; for (;;) { int i; switch (poll(pfd,n,5*1000)) { case -1: if (errno==EINTR) continue; perror("poll"); return 1; case 0: continue; } for (i=0; i #include #include #include #include #include #include #include #include #define GMON_OUT "gmon.out" #define A_OUT "test" #define xmalloc(x) (x *) calloc (1, sizeof (x)) #if defined(__alpha__) || defined(__sparc64__) # define ElfW(type) Elf64_##type # define ELFX_ST_TYPE ELF64_ST_TYPE # define ELFX_ST_BIND ELF64_ST_BIND #else # define ElfW(type) Elf32_##type # define ELFX_ST_TYPE ELF32_ST_TYPE # define ELFX_ST_BIND ELF32_ST_BIND #endif typedef struct __symbol__ { char *name; unsigned long length; unsigned long addr; unsigned long call_cnt; unsigned long prof_cnt; struct __symbol__ *next; struct __symbol__ *prev; } symbol_t; enum { STDIN, STDOUT, STDERR }; static symbol_t *sym_base = NULL; static unsigned long lowpc, highpc; static void die (const char *str) { write (STDOUT, str, strlen (str)); exit (1); } static symbol_t * lookup_symbol (unsigned long addr) { symbol_t *sym = sym_base; if (addr > highpc || addr < lowpc) return (NULL); while (sym) { if (sym->addr <= addr && sym->addr+sym->length >= addr) return (sym); sym = sym->next; } return (NULL); } static void add_sym (ElfW(Sym) *esym, char *str) { symbol_t *sb = sym_base; symbol_t *sym = xmalloc (symbol_t); sym->name = str; sym->length = esym->st_size; sym->addr = esym->st_value; if (!sb) { sym_base = sym; return; } if (!sym->length) { sym->next = sym_base; sym_base->prev = sym; sym_base = sym; return; } while (sb) { if (!sb->next || (sym->length >= sb->length && sym->length <= sb->next->length)) { sym->next = sb->next; sb->next = sym; sym->prev = sb; break; } sb = sb->next; } while (sym_base->prev) sym_base = sym_base->prev; } static void build_symbol_list (void *base) { ElfW(Ehdr) *ehdr = (ElfW(Ehdr) *) base; ElfW(Shdr) *shdr = (ElfW(Shdr) *) (base + ehdr->e_shoff), *bshdr = shdr; unsigned long l; for (l=0;le_shnum;l++,shdr++) { if (shdr->sh_type == SHT_SYMTAB) { ElfW(Sym) *esym = (ElfW(Sym) *) (base + shdr->sh_offset); char *str; unsigned long ul = shdr->sh_size / sizeof (*esym), uf; for (uf=0;ufst_info); if (!esym->st_name) continue; if (!(( type & STT_FUNC) || (type & STT_OBJECT))) continue; if (ELFX_ST_BIND (esym->st_info) & STB_WEAK) continue; str = (char *) (base+bshdr[shdr->sh_link].sh_offset+esym->st_name); add_sym (esym, str); } } } } int main (int argc, char *argv[]) { int fdg, fdp; unsigned long len; void *gp, *obj; static char *object = A_OUT, *monf = GMON_OUT; char *self = argv[0] + strlen (argv[0]) - 4; long esize = (*(long *) self == *(long *) "size"); if (argc != 1) if (esize) object = argv[1]; else { monf = argv[1]; if (argv[2]) object = argv[2]; } if (!esize && ((fdg = open (monf, O_RDONLY)) < 0)) die (GMON_OUT" could not be opened\n"); if ((fdp = open (object, O_RDONLY)) < 0) die (A_OUT" could not be opened\n"); if (!esize) { if ((gp = (char *) mmap (NULL, len = lseek (fdg, 0, SEEK_END), PROT_READ | PROT_WRITE, MAP_PRIVATE, fdg, 0)) == MAP_FAILED) die ("Error mmaping monitor-file\n"); if (*(long *) gp != *(long *) "gmon") die ("No valid monitorfile specified\n"); } if ((obj = mmap (NULL, (unsigned long ) lseek (fdp, 0, SEEK_END), PROT_READ | PROT_WRITE, MAP_PRIVATE, fdp, 0)) == MAP_FAILED) die ("Error mmaping object file\n"); else if (*(long *) obj != *(long *) ELFMAG) die ("Invalid ELF header\n"); build_symbol_list (obj); if (esize) { symbol_t *sym = sym_base; while (sym) { if (sym->length) printf ("%-45s: %ld\n", sym->name, sym->length); sym = sym->next; } return (0); } gp += sizeof (struct gmon_hdr); len -= sizeof (struct gmon_hdr); while (len--) { switch (*(char *) gp++) { case GMON_TAG_TIME_HIST: { struct gmon_hist_hdr *ghdr = (struct gmon_hist_hdr *) gp; lowpc = *(long *) ghdr->low_pc; highpc = *(long *) ghdr->high_pc; gp += sizeof (struct gmon_hist_hdr); len -= sizeof (struct gmon_hist_hdr); { long l = (*(long *) ghdr->hist_size) << 1; char *buf = gp; symbol_t *sym; gp += l; len -= l; while (l--) if (buf[l] && ((sym = lookup_symbol (lowpc+(l<<1))))) sym->prof_cnt += (short) buf[l]; } break; } case GMON_TAG_CG_ARC: { struct rawarc *arc = (struct rawarc *) gp; symbol_t *sym1 = lookup_symbol (arc->raw_frompc); symbol_t *sym2 = lookup_symbol (arc->raw_selfpc); gp += sizeof (*arc); len -= sizeof (*arc); sym2->call_cnt += arc->raw_count; if (sym1 && sym2) printf ("%s called %s %ld times\n", sym1->name, sym2->name, arc->raw_count); } } } { symbol_t *sym = sym_base; long count = 0; const double hundred = 100.0; double dcount, ff; do if (sym->prof_cnt) count += sym->prof_cnt; while ((sym = sym->next)); dcount = (double) count; ff = hundred/count; printf ("\nName %%Time Seconds #Calls\n"); sym = sym_base; while (sym) { if (sym->prof_cnt || sym->call_cnt) printf ("%-15s %-4.02f %.02ld.%-8.02ld %2ld\n", sym->name, (double) ff * sym->prof_cnt, sym->prof_cnt/100, sym->prof_cnt%100, sym->call_cnt); sym = sym->next; } } return (0); } dietlibc-0.33~cvs20120325/contrib/elftrunc.c010064400000000000000000000054721173363226000153370ustar00#include #include #include #include #include #include #include #include void die (int v,const char *s); void die (int v,const char *s) { write(2,s,strlen(s)); write(2,"\n",1); exit(v); } char fn[1024]; unsigned char buf[4096]; void trunc32(int fd); void trunc32(int fd) { Elf32_Ehdr eh32; Elf32_Phdr ph32; int in=fd, out, i; Elf32_Addr len,n; len=0; if ((n=read(in,&eh32,sizeof(eh32)))<1) die(3,"read elf hdr"); lseek(in,(off_t)eh32.e_phoff,SEEK_SET); for (i=0; (i0) ; i++) { switch (ph32.p_type) { case PT_DYNAMIC: case PT_INTERP: die(3,"File is not static !"); break; case PT_LOAD: if (len<(ph32.p_offset+ph32.p_filesz)) len=(ph32.p_offset+ph32.p_filesz); break; default: break; } } lseek(in,(off_t)n,SEEK_SET); len -= n; eh32.e_shoff=0; eh32.e_shnum=0; eh32.e_shstrndx=0; if ((out=open(fn,O_CREAT| O_TRUNC|O_WRONLY,0755))<0) die(2,"open outfile"); write(out,&eh32,n); while(len && n) { if ((n=read(in,buf,sizeof(buf)))) { write(out,buf,(len0); i++) { switch (ph64.p_type) { case PT_DYNAMIC: case PT_INTERP: die(3,"File is not static !"); break; case PT_LOAD: if (len<(ph64.p_offset+ph64.p_filesz)) len=(ph64.p_offset+ph64.p_filesz); break; default: break; } } lseek(in,n,SEEK_SET); len -= n; eh64.e_shoff=0; eh64.e_shnum=0; eh64.e_shstrndx=0; if ((out=open(fn,O_CREAT| O_TRUNC|O_WRONLY,0755))<0) die(2,"open outfile"); write(out,&eh64,(size_t)n); while(len && n>0) { if ((n=read(in,buf,sizeof(buf)))>0) { write(out,buf,(size_t)((len<(size_t)n)?len:(size_t)n)); len-=(len<(size_t)n)?len:(size_t)n; } else die(2,"read error"); } close(out); } int main(int argc, char *argv[]) { long n; int in; if (argc!=2 && argc!=3) die(0,"usage: elftrunc srcprogname [dstprogname]"); if ((in=open (argv[1],O_RDONLY))<0) die(1,"open input file"); if ((n=read(in,buf,EI_NIDENT))<1) die(2,"read header of input"); buf[n]=0; if (memcmp(buf,ELFMAG,SELFMAG)) die(2,"input file isn't an ELF !"); lseek(in,0,SEEK_SET); strncpy(fn,argv[1],sizeof(fn)-10); strcat(fn,".trunc"); if (buf[EI_CLASS]==ELFCLASS64) trunc64(in); else trunc32(in); close(in); if (argc==3) rename(fn,argv[2]); return 0; } dietlibc-0.33~cvs20120325/contrib/memchr.c010064400000000000000000000022421173363226000147600ustar00/* fast memchr -- Copyright (C) 2003 Thomas M. Ogrisegg */ #include #include "dietfeatures.h" #include "dietstring.h" #if __WORDSIZE == 64 # define MB 0x7efefefefefefeff #else # define MB 0x7efefeff #endif void * memchr (const void *s, int c, size_t n) { const unsigned char *pc = (unsigned char *) s; #ifdef WANT_SMALLER_STRING_ROUTINES for (;n--;pc++) if (*pc == c) return ((void *) pc); return (NULL); #else unsigned long l, lb, lt; int tmp; if ((tmp = STRALIGN(s)) || n < sizeof(unsigned long)) { if (n < sizeof(unsigned long)) tmp = n; for (; tmp-- && n--; pc++) if (*pc == c) return ((char *) pc); if (n == (size_t) - 1) return (NULL); } lb = c | c << 8; lb |= lb << 16; #if __WORDSIZE == 64 lb |= lb << 32; #endif while (n >= sizeof(unsigned long)) { l = *(unsigned long *) pc; lt = l ^ lb; if ((((lt + MB) ^ ~lt) & ~MB)) { while (l && (l & 0xff) != (unsigned long) c) l >>= 8, pc++; if (l) return ((char *) pc); } else pc += sizeof(unsigned long); n -= sizeof(unsigned long); } for (; n--; pc++) if (*pc == c) return ((char *) pc); return (NULL); #endif } dietlibc-0.33~cvs20120325/contrib/static.pl010064400000000000000000000036011173363226000151650ustar00#!/usr/bin/perl @arch=(alpha,arm,i386,mips,sparc,ppc); @vpath=(); open FILE,"Makefile" || die; open OUT,">sMakefile" || die; while () { if (m/^VPATH=(.*)\n$/) { @vpath=split /:/,$1; # foreach $m (@vpath) { print "vpath: $m\n"; } s/^/# /; } elsif (m/\$\(patsubst ([^,]*),([^,]*),\$\(wildcard ([^\/]*)\/([^\)\/]*)\)\)/) { my @list=(); my ($src,$dest,$dir,$glob) = ($1,$2,$3,$4); foreach $i (glob("$dir/$glob")) { # match "libcruft/%.c" to "libcruft/fnord.c" my $tmp=$i; my $j=$src; # print "comparing $i and $src\n"; while (length($j) && (substr($j,0,1) eq substr($tmp,0,1))) { substr($j,0,1)=""; substr($tmp,0,1)=""; } while (length($j) && (substr($j,length($j)-1,1) eq substr($tmp,length($tmp)-1,1))) { chop $j; chop $tmp; } my $foo=$dest; die "unable to match" unless $j eq "%"; $foo =~ s/\%/$tmp/; push @list,$foo; # print "foo = $foo\n"; $total{$foo}="?"; # print "$i, $src, $dest -> $foo\n"; } s/\$\(patsubst.*\)\)/join(' ',@list)/e; # print "$a - $b - $c\n"; } print OUT $_; } close FILE; print OUT "\n\ninclude sMakefile.\$(ARCH)\n"; close OUT; foreach $i (@arch) { my %dep; my @archvpath=@vpath; open SRC,"$i/Makefile.add" || die "no $i/Makefile.add?!\n"; open OUT,">sMakefile.$i" || die "could not create sMakefile.$i\n"; while () { if (m/^VPATH:?=(.*)\n$/) { # print; foreach $m (split /:/,$1) { unshift @archvpath,$m unless ($m eq "\$(VPATH)"); } s/^/# /; } } close SRC; # foreach $m (@archvpath) { print "vpath: $m\n"; } foreach $I (keys %total) { my $j=$I; $j =~ s/^\$\(OBJDIR\)\///; $j =~ s/\.o$//; # print STDERR "looking for $j...\n"; foreach $k (@archvpath) { # print STDERR "$k/$j.S\n"; if (-f "$k/$j.S") { print OUT "$i-bin/$j.o: $k/$j.S\n"; last; } } } close OUT; } dietlibc-0.33~cvs20120325/diet.1010064400000000000000000000021501173363226000127060ustar00.TH diet 1 "April 2001" .SH NAME .PP diet \- mangle gcc command line arguments .SH SYNOPSIS .PP .B diet [-v] [-Os] [\fInormal gcc command line\fP] .SH DESCRIPTION .PP diet is a small wrapper around gcc. It will try to look at the command line you specify and try to mangle it so that gcc will compile against the diet libc header files and link against the diet libc itself. diet tries to be smart for cross compiling. If the first argument is not gcc but sparc-linux-gcc, diet will guess that you want to cross compile for sparc and use bin-sparc/dietlibc.a instead of the dietlibc.a for your default architecture. The -v option will make diet print the modified gcc command line before executing it. When passed the -Os option before the gcc argument, diet will mangle the gcc options to include the best known for-size optimization settings for the platform. .SH FILES ~/.diet/\fIcompiler\fR may contain compiler options as you would specify them on the command line, i.e. separated by spaces. Those will then be used instead of the built-in defaults for diet -Os. .SH AUTHOR Felix von Leitner dietlibc-0.33~cvs20120325/diet.c010064400000000000000000000233471173363226000130030ustar00#include #include #include #include #include #include #include "dietfeatures.h" /* goal: * when invoked as * "diet gcc -c t.c" * exec * "gcc -I/path/to/dietlibc/include -c t.c" * * when invoked as * "diet sparc-linux-gcc -o t t.o" * exec * "sparc-linux-gcc -nostdlib -static -o t t.o /path/to/dietlibc/bin-sparc/start.o /path/to/dietlibc/bin-sparc/dietlibc.a" */ static void error(const char *message) { __write2(message); exit(1); } static const char* Os[] = { "i386","-Os","-mpreferred-stack-boundary=2", "-falign-functions=1","-falign-jumps=1", "-falign-loops=1","-fomit-frame-pointer",0, "x86_64","-Os",0, "sparc","-Os","-mcpu=supersparc",0, "sparc64","-Os","-m64","-mhard-quad-float",0, "alpha","-Os","-fomit-frame-pointer",0, "arm","-Os","-fomit-frame-pointer",0, "mips","-Os","-fomit-frame-pointer","-march=mips2",0, "mipsel","-Os","-fomit-frame-pointer","-march=mips2",0, "ppc","-Os","-fomit-frame-pointer","-mpowerpc-gpopt","-mpowerpc-gfxopt",0, "ppc64","-Os","-fomit-frame-pointer","-mpowerpc-gpopt","-mpowerpc-gfxopt",0, "s390","-Os","-fomit-frame-pointer",0, "s390x","-Os","-fomit-frame-pointer",0, "sh","-Os","-fomit-frame-pointer",0, "ia64","-Os","-fno-omit-frame-pointer",0, "x86_64","-Os","-fstrict-aliasing","-momit-leaf-frame-pointer","-mfancy-math-387",0, 0}; static void usage(void) { __write2( #ifdef __DYN_LIB "dyn-" #endif "diet version " VERSION #ifndef INSTALLVERSION " (non-install version in source tree)" #endif "\n\n"); error("usage: diet [-v] [-Os] gcc command line\n" "e.g. diet -Os gcc -c t.c\n" "or diet sparc-linux-gcc -o foo foo.c bar.o\n"); } int main(int argc,char *argv[]) { int _link=0; int compile=0; int preprocess=0; int verbose=0; int profile=0; char* diethome; char* platform; #ifdef __DYN_LIB int shared=0; #endif char* shortplatform=0; #ifdef WANT_SAFEGUARD char safeguard1[]="-include"; char* safeguard2; #endif const char *nostdlib="-nostdlib"; const char *libgcc="-lgcc"; char *libpthread="-lpthread"; char dashL[1000]; char dashstatic[]="-static"; int i; int mangleopts=0; int printpath=0; char manglebuf[1024]; int m; if (!(diethome = getenv("DIETHOME"))) diethome=DIETHOME; #ifdef WANT_SAFEGUARD safeguard2=alloca(strlen(diethome)+30); strcpy(safeguard2, diethome); strcat(safeguard2, "/include/dietref.h"); #endif platform=alloca(strlen(diethome)+100); strcpy(platform,diethome); #ifdef INSTALLVERSION strcat(platform,"/lib-"); #else #ifndef __DYN_LIB strcat(platform,"/bin-"); #else strcat(platform,"/pic-"); #endif #endif strcpy(dashL,"-L"); do { if (!argv[1]) usage(); if (!strcmp(argv[1],"-v")) { ++argv; --argc; verbose=1; } else if (!strcmp(argv[1],"-Os")) { ++argv; --argc; mangleopts=1; } else if (!strcmp(argv[1],"-L")) { ++argv; --argc; printpath=1; } else break; } while (1); { int i; m=0; for (i=1; i90) error("platform name too long!\n"); shortplatform=platform+len; memmove(shortplatform,argv[1],(size_t)(tmp2-cc)); platform[tmp2-cc+len]=0; if (shortplatform[0]=='i' && shortplatform[2]=='8' && shortplatform[3]=='6') shortplatform[1]='3'; } else { #ifdef __sparc__ #ifdef __arch64__ shortplatform="sparc64"; #else shortplatform="sparc"; #endif #endif #ifdef __powerpc__ shortplatform="ppc"; #endif #ifdef __powerpc64__ shortplatform="ppc64"; #endif #ifdef __i386__ shortplatform="i386"; #endif #ifdef __alpha__ shortplatform="alpha"; #endif #ifdef __arm__ shortplatform="arm"; #endif #ifdef __MIPSEL__ shortplatform="mipsel"; #endif #ifdef __MIPSEB__ shortplatform="mips"; #endif #ifdef __s390x__ shortplatform="s390x"; #else #ifdef __s390__ shortplatform="s390"; #endif #endif #ifdef __sh__ shortplatform="sh"; #endif #ifdef __hppa__ shortplatform="parisc"; #endif #ifdef __x86_64__ shortplatform=(m==32?"i386":"x86_64"); #endif #ifdef __ia64__ shortplatform="ia64"; #endif { char *tmp=platform+strlen(platform); strcpy(tmp,shortplatform); shortplatform=tmp; } } /* MIPS needs special handling. If argv contains -EL, change * platform name to mipsel */ if (!strcmp(shortplatform,"mips")) { int i; for (i=1; i=0) { int len=read(fd,manglebuf,1023); if (len>0) { int i; manglebuf[len]=0; *dest++=manglebuf; for (i=1; i struct __dirstream { int fd; char buf[PAGE_SIZE-(sizeof (int)*3)]; unsigned int num; unsigned int cur; }; /* stream data from opendir() */ dietlibc-0.33~cvs20120325/dietdns.h010064400000000000000000000002301173363226000134770ustar00 int __dns_gethostbyx_r(const char* name, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop, int lookfor); dietlibc-0.33~cvs20120325/dietfeatures.h010064400000000000000000000135211173363226000145400ustar00#ifndef _DIETFEATURES_H #define _DIETFEATURES_H /* feel free to comment some of these out to reduce code size */ #define WANT_FLOATING_POINT_IN_PRINTF #define WANT_FLOATING_POINT_IN_SCANF #define WANT_CHARACTER_CLASSES_IN_SCANF #define WANT_NULL_PRINTF /* #define WANT_ERROR_PRINTF */ #define WANT_LONGLONG_PRINTF #define WANT_LONGLONG_SCANF /* 128 or 2048 bytes buffer size? */ /* #define WANT_SMALL_STDIO_BUFS */ /* want fread to read() directly if size of data is larger than buffer? * This costs a few bytes but is worth it if the application is already * buffering. */ #define WANT_FREAD_OPTIMIZATION /* this is only for meaningful for ttyname and sysconf_cpus so far */ #define SLASH_PROC_OK /* use errno_location instead of errno; NEEDED FOR MULTI-THREADING! */ #define WANT_THREAD_SAFE /* support __thread; NEEDED FOR MULTI-THREADING! */ #define WANT_TLS /* make the startcode, etc. dynamic aware ({con,de}structors) */ /* #define WANT_DYNAMIC */ /* GDB support in the dynamic linker */ #define WANT_LD_SO_GDB_SUPPORT /* do you want smaller or faster string routines? */ #define WANT_FASTER_STRING_ROUTINES /* define this to have strncpy zero-fill and not just zero-terminate the * string */ /* #define WANT_FULL_POSIX_COMPAT */ /* on i386, Linux has an alternate syscall method since 2002/12/16 */ /* on my Athlon XP, it is twice as fast, but it's only in kernel 2.5 */ /* 20040118: enabling this breaks User Mode Linux! It's their fault. */ #define WANT_SYSENTER #define WANT_LINKER_WARNINGS /* you need to define this if you want to run your programs with large * file support on kernel 2.2 or 2.0 */ #define WANT_LARGEFILE_BACKCOMPAT /* do you want localtime(3) to read /etc/localtime? * Needed for daylight saving time etc. */ #define WANT_TZFILE_PARSER /* do you want the DNS routines to parse and use "domain" and "search" * lines from /etc/resolv.conf? Normally not used on boot floppies and * embedded environments. */ #define WANT_FULL_RESOLV_CONF /* do you want IPv6 transport support in the DNS resolver? */ #define WANT_IPV6_DNS /* do you want gethostbyname and friends to consult /etc/hosts? */ #define WANT_ETC_HOSTS /* do you want gethostbyname to understand dotted decimal IP numbers * directly and not try to resolve them? */ #define WANT_INET_ADDR_DNS /* do you want math functions high precision rather than fast/small? */ #define WANT_HIGH_PRECISION_MATH /* do you want support for matherr? */ #define WANT_MATHERR /* do you want crypt(3) to use MD5 if the salt starts with "$1$"? */ #define WANT_CRYPT_MD5 /* do you want diet to include a safeguard dependency to make linking * against glibc fail? This may fail with older binutils. */ #define WANT_SAFEGUARD /* This enables zeroconf DNS aka Rendezvous aka Bonjour. */ /* This code will try zeroconf DNS if you ask for host.local or if you * ask for an unqualified hostname */ #define WANT_PLUGPLAY_DNS /* This enables LLMNR, the MS variant of zeroconf DNS. This only works * if you also enabled WANT_PLUGPLAY_DNS */ #define WANT_LLMNR /* Uncomment this if you want DNS lookups to fail if /etc/hosts contains * an entry but it's for a different record type */ /* #define WANT_HOSTS_GIVEUP_EARLY */ /* Do you want valgrind support? If enabled, the startup code will * check for valgrind, and if detected, turn off optimized SIMD string * routines that cause false positives in valgrind. This enlarges and * slightly slows down your code! */ #define WANT_VALGRIND_SUPPORT /* do you want that malloc(0) return a pointer to a "zero-length" object * that is realloc-able; means realloc(..,size) gives a NEW object (like a * call to malloc(size)). * WARNING: this violates C99 */ /* #define WANT_MALLOC_ZERO */ /* do you want free to overwrite freed data immediately, in the hope of * catching people accessing pointers after they were freed? This does * a memset with 0x55 as a value. which is not NULL and not -1. Please * note that this is the shotgun method for debugging, what you really * want is valgrind. */ /* #define WANT_FREE_OVERWRITE */ /* This enables a stack gap. Basically, the start code does not run * main but stackgap, which then does alloca(random()) and calls main. * The effect is that buffer overflow exploits will no longer be able to * know the address of the buffer. Cost: 62 bytes code on x86. */ /* WARNING: this appears to break with some binutils versions. Works * for me with binutils 2.15. The symptom is an error message that * `main' can not be found. */ /* #define WANT_STACKGAP */ /* #define this if you want GNU bloat like program_invocation_short_name * and program_invocation_name to be there. This functionality is not * portable and adds useless bloat to libc. Help stomp out code * depending on this! util-linux, I'm looking at you here! */ #define WANT_GNU_STARTUP_BLOAT /* Include support for ProPolice/SSP, calls guard_setup */ /* ProPolice is part of gcc 4.1 and up, there were patches for earlier * versions. To make use of this, compile your application with * -fstack-protector. */ /* If you compile dietlibc without WANT_SSP and then try to link code * compiled with -fstack-protector against it, the binary will segfault * when calling that code. */ #if (__GNUC__>4) || ((__GNUC__==4) && (__GNUC_MINOR__>=1)) #define WANT_SSP #endif /* stop uncommenting here ;-) */ #if defined(WANT_SSP) || defined(WANT_STACKGAP) || defined(WANT_TLS) #define CALL_IN_STARTCODE stackgap #else #define CALL_IN_STARTCODE main #endif #ifndef WANT_FASTER_STRING_ROUTINES #define WANT_SMALL_STRING_ROUTINES #endif #ifdef WANT_THREAD_SAFE #ifndef __ASSEMBLER__ #define errno (*__errno_location()) #define _REENTRANT #endif #endif #ifdef __DYN_LIB /* with shared libraries you MUST have a dynamic aware startcode */ #ifndef WANT_DYNAMIC #define WANT_DYNAMIC #endif /* saveguard crashes with shared objects ... */ #ifdef WANT_SAFEGUARD #undef WANT_SAFEGUARD #endif #endif #endif dietlibc-0.33~cvs20120325/dieticonv.h010064400000000000000000000003121173363226000140320ustar00enum charset { INVALID=0, ISO_8859_1, UTF_8, UCS_2, UCS_4, UTF_16_BE, UTF_16_LE, UTF_16 }; #define ic_from(x) (((x) )&0xffff) #define ic_to(x) (((x)>>16)&0xffff) #include dietlibc-0.33~cvs20120325/dietlibm.h010064400000000000000000000001141173363226000136370ustar00#include double __poly(double x, size_t n, const double* c); dietlibc-0.33~cvs20120325/dietlocale.h010064400000000000000000000000731173363226000141570ustar00extern enum __encoding { CT_8BIT, CT_UTF8, } lc_ctype; dietlibc-0.33~cvs20120325/dietstdio.h010064400000000000000000000042351173363226000140460ustar00/* diet stdio */ #include #include #include "dietfeatures.h" #ifdef WANT_THREAD_SAFE #include #endif #include #ifdef WANT_SMALL_STDIO_BUFS #define BUFSIZE 128 #else #define BUFSIZE 2048 #endif struct __stdio_file { int fd; int flags; uint32_t bs; /* read: bytes in buffer */ uint32_t bm; /* position in buffer */ uint32_t buflen; /* length of buf */ char *buf; struct __stdio_file *next; /* for fflush */ pid_t popen_kludge; unsigned char ungetbuf; char ungotten; #ifdef WANT_THREAD_SAFE pthread_mutex_t m; #endif }; #define ERRORINDICATOR 1 #define EOFINDICATOR 2 #define BUFINPUT 4 #define BUFLINEWISE 8 #define NOBUF 16 #define STATICBUF 32 #define FDPIPE 64 #define CANREAD 128 #define CANWRITE 256 #define CHECKLINEWISE 512 #define _IONBF 0 #define _IOLBF 1 #define _IOFBF 2 #include /* internal function to flush buffer. * However, if next is BUFINPUT and the buffer is an input buffer, it * will not be flushed. Vice versa for output */ extern int __fflush4(FILE *stream,int next); extern int __buffered_outs(const char *s,size_t len); /* ..scanf */ struct arg_scanf { void *data; int (*getch)(void*); int (*putch)(int,void*); }; int __v_scanf(struct arg_scanf* fn, const char *format, va_list arg_ptr); struct arg_printf { void *data; int (*put)(void*,size_t,void*); }; int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr); extern FILE *__stdio_root; int __fflush_stdin(void); int __fflush_stdout(void); int __fflush_stderr(void); FILE* __stdio_init_file(int fd,int closeonerror,int mode); int __stdio_parse_mode(const char *mode) __attribute__((__pure__)); void __stdio_flushall(void); #ifndef __THREAD_INTERNAL_H__ int __libc_close(int fd); int __libc_open(const char*fn,int flags,...); ssize_t __libc_read(int fd,void*buf,size_t len); ssize_t __libc_write(int fd,const void*buf,size_t len); #endif FILE *fopen_unlocked(const char *path, const char *mode) __THROW; FILE *fdopen_unlocked(int fildes, const char *mode) __THROW; FILE *freopen_unlocked(const char *path, const char *mode, FILE *stream) __THROW; int __stdout_is_tty(void); int __stdin_is_tty(void); dietlibc-0.33~cvs20120325/dietstring.h010064400000000000000000000014561173363226000142340ustar00#ifndef _DIET_STRING_H_ #define _DIET_STRING_H_ #include #if __WORDSIZE == 64 # define MKW(x) (x|x<<8|x<<16|x<<24|x<<32|x<<40|x<<48|x<<56) # define STRALIGN(x) (((unsigned long)x&7)?8-((unsigned long)x&7):0) #else /* __WORDSIZE == 32 */ # define MKW(x) (x|x<<8|x<<16|x<<24) # define STRALIGN(x) (((unsigned long)x&3)?4-((unsigned long)x&3):0) #endif /* GFC(x) - returns first character */ /* INCSTR(x) - moves to next character */ #if __BYTE_ORDER == __LITTLE_ENDIAN # define GFC(x) ((x)&0xff) # define INCSTR(x) do { x >>= 8; } while (0) #else # define GFC(x) (((x)>>(sizeof(x)*8-8))&0xff) # define INCSTR(x) do { x <<= 8; } while (0) #endif #define UNALIGNED(x,y) (((unsigned long)x & (sizeof (unsigned long)-1)) ^ ((unsigned long)y & (sizeof (unsigned long)-1))) #endif /* _DIET_STRING_H_ */ dietlibc-0.33~cvs20120325/dietuglyweaks.h010064400000000000000000000007701173363226000147370ustar00#ifndef __DIET_UGLY_WEAKS__ #define __DIET_UGLY_WEAKS__ /* if you change something here ... KNOW what you're doing ! * it'll effect ALL platforms ! */ .macro DEF_G name .global \name .type \name,function \name: .endm .macro DEF_W name .weak \name .type \name,function \name: .endm DEF_W __fflush_stderr DEF_W __fflush_stdin DEF_W __fflush_stdout DEF_W __nop DEF_W __thread_doexit DEF_W flockfile DEF_W ftrylockfile DEF_W funlockfile DEF_G __you_tried_to_link_a_dietlibc_object_against_glibc #endif dietlibc-0.33~cvs20120325/dietwarning.h010064400000000000000000000005441173363226000143700ustar00#include "dietfeatures.h" #ifdef WANT_LINKER_WARNINGS #ifndef __ASSEMBLER__ #define link_warning(symbol,msg) \ asm (".section .gnu.warning." symbol "\n\t.string \"" msg "\"\n\t.previous"); #else #define link_warning(symbol,msg) \ .section .gnu.warning.##symbol ;\ .string msg ;\ .previous #endif #else #define link_warning(foo,bar) #endif dietlibc-0.33~cvs20120325/dyn_start.c010064400000000000000000000043601173363226000140570ustar00#include "dietfeatures.h" #ifdef WANT_DYNAMIC #include #include struct object { void *detail[7]; /* see gcc sources unwind-dw2-fde.h */ }; extern void __register_frame_info (const void *, struct object *) __attribute__((weak)); extern void __deregister_frame_info (const void *) __attribute__((weak)); typedef void(*structor)(void); __attribute__((section(".ctors"))) __attribute__((aligned(sizeof(structor)))) __attribute_used static structor __CTOR_LIST__[1]={((structor)-1)}; __attribute__((section(".dtors"))) __attribute__((aligned(sizeof(structor)))) __attribute_used static structor __DTOR_LIST__[1]={((structor)-1)}; /* see gcc-3.4/gcc/crtstuff.c */ #if !defined(EH_FRAME_SECTION_CONST) #if defined(__s390__) || defined(__x86_64__) # define EH_FRAME_SECTION_CONST const #endif #endif #if !defined(EH_FRAME_SECTION_CONST) # define EH_FRAME_SECTION_CONST #endif __attribute__((section(".eh_frame"))) __attribute__((aligned(sizeof(structor)))) __attribute_used EH_FRAME_SECTION_CONST char __EH_FRAME_BEGIN__[] = { }; static void __do_global_dtors_aux(void) { structor *df=__CTOR_LIST__; /* ugly trick to prevent warning */ for (df=((__DTOR_LIST__)+1);(*df) != (structor)0; df++) (*df)(); } void _fini(void) __attribute__((section(".fini"))); __attribute__((section(".fini"))) void _fini(void) { __do_global_dtors_aux(); if (__deregister_frame_info) __deregister_frame_info(__EH_FRAME_BEGIN__); } #ifdef WANT_STACKGAP int stackgap(int argc,char* argv[],char* envp[]); #endif #ifndef __DYN_LIB_SHARED /* pre main, post _start */ extern __attribute__((section(".init"))) void _init(void); int _dyn_start(int argc, char **argv, char **envp, structor dl_init); int _dyn_start(int argc, char **argv, char **envp, structor dl_init) { int main(int argc, char **argv, char **envp); #ifndef __arm__ /* GT: segfaults on arm, don't know why (for now) */ void _dl_aux_init_from_envp(char **envp); _dl_aux_init_from_envp(envp); #endif if (dl_init) atexit(dl_init); _init(); atexit(_fini); if (__register_frame_info) { static struct object ob; __register_frame_info(__EH_FRAME_BEGIN__, &ob); } #ifdef WANT_STACKGAP return stackgap(argc, argv, envp); #else return main(argc, argv, envp); #endif } #endif #endif dietlibc-0.33~cvs20120325/dyn_stop.c010064400000000000000000000021351173363226000137050ustar00#include "dietfeatures.h" #ifdef WANT_DYNAMIC #include #include typedef void(*structor)(void); __attribute__((section(".ctors"))) __attribute_used static structor __CTOR_END__[1]={((structor)0)}; __attribute__((section(".dtors"))) __attribute_used static structor __DTOR_END__[1]={((structor)0)}; /* see gcc-3.4/gcc/crtstuff.c */ #if !defined(EH_FRAME_SECTION_CONST) #if defined(__s390__) || defined(__x86_64__) # define EH_FRAME_SECTION_CONST const #endif #endif #if !defined(EH_FRAME_SECTION_CONST) # define EH_FRAME_SECTION_CONST #endif __attribute__((section(".eh_frame"))) __attribute_used #if __WORDSIZE == 32 EH_FRAME_SECTION_CONST char __FRAME_END__[4] = { 0, 0, 0, 0 }; #else EH_FRAME_SECTION_CONST char __FRAME_END__[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; #endif static void __do_global_ctors_aux(void) { structor *cf=__DTOR_END__; /* ugly trick to prevent warning */ for(cf=((__CTOR_END__)-1); (*cf) != (structor)-1; cf--) (*cf)(); } void _init(void) __attribute__((section(".init"))); __attribute__((section(".init"))) void _init(void) { __do_global_ctors_aux(); } #endif dietlibc-0.33~cvs20120325/dynlinker/Makefile010064400000000000000000000011271173363226000153410ustar00CC=gcc #CFLAGS = -Wall -g CFLAGS = -Wall -Os -fomit-frame-pointer ARCH = i386 DYNLINK = diet-linux.so all: $(DYNLINK) DLIBS = ../bin-$(ARCH)/libdl.a ../bin-$(ARCH)/dietlibc.a LINKOPS = -Wl,-Ttext=0x1080,-N,-eldso_start $(DYNLINK): ldso_start.S ldso_test.c $(DLIBS) $(CROSS)$(CC) -I.. -I../include $(CFLAGS) -c ldso_test.c $(CROSS)$(CC) -I.. -I../include $(CFLAGS) -c ldso_start.S $(CROSS)$(CC) -nostdlib $(LDFLAGS) -o $@ ldso_start.o ldso_test.o $(DLIBS) -lgcc $(LINKOPS) $(CROSS)strip -R .comment -R .note $@ install: $(DYNLINK) cp $(DYNLINK) /lib clean: $(RM) *.o *.a *.so *.out *~ dietlibc-0.33~cvs20120325/dynlinker/README010064400000000000000000000014171173363226000145630ustar00DYN-LINKER This is the Dynamic linker for the dietlibc. Written from scratch by Olaf Dreesen. Fri Sep 13 16:28:42 CEST 2002 THIS CODE IS OBSOLETE ! DON'T USE IT ANYMORE Replacement for standard ld.so It is still test-code only and depends on dietlibc/libdl code Mon Mar 11 19:44:20 CET 2002 This is now near obsolete code... Thu Nov 1 17:35:15 MET 2001 now "interact" with the loaded libdietc.so .... environ is of copy relocation type. (I think this has to be done different...) Mon Oct 22 14:55:51 MEST 2001 added a little helper-code to "interact" with a loaded libdl.so .... Thu Jun 21 16:03:52 MEST 2001 1. STATUS: it works on i386. ARM is in progress other no code available basicaly look to the libdl README. all supported there schould work here. dietlibc-0.33~cvs20120325/dynlinker/ldso_start.S010064400000000000000000000027771173363226000162170ustar00#include .text .globl ldso_start ldso_start: #ifdef __i386__ movl %esp, %ebp /* save stack pointer */ movl (%ebp), %ecx /* %ecx = argc */ leal 4(%ebp), %esi /* %esi = argv */ leal 4(%esi,%ecx,4), %eax /* eax = esi+4*ecx+4 = envp */ /* call ldso main */ pushl %eax pushl %esi pushl %ecx movl %eax, environ call main movl %ebp, %esp /* restore stack */ push %eax /* push start entry of program */ xorl %eax,%eax /* clear registers */ xorl %ebx,%ebx /* as if kernel starts s static program */ xorl %ecx,%ecx xorl %esi,%esi xorl %edi,%edi xorl %ebp,%ebp movl fini_entry, %edx /* the dynamic fini for all *.so loaded */ ret /* jump to entry point of program */ #endif #ifdef __arm__ mov r4, sp mov fp, #0 /* clear the frame pointer */ ldr a1, [sp], #4 /* argc */ mov a2, sp /* argv */ ldr ip, .L0 add a3, a2, a1, lsl #2 /* &argv[argc] */ add a3, a3, #4 /* envp */ str a3, [ip, #0] /* environ = envp */ bl main mov sp, r4 /* restore stack */ mov lr, a1 ldr a1, [pc, #.L1-(.+8)] /* the dynamic fini for all *.so loaded */ mov pc, lr /* jump to entry point of program */ .align 2 .L0: .word environ .L1: .word fini_entry #endif /* common data */ .data .section ".bss" .align 8 .global errno errno: .long 0 .global environ environ: .global __environ __environ: #if __WORDSIZE == 64 .quad 0 #else .long 0 #endif .global environ environ: .global __environ __environ: #if __WORDSIZE == 64 .quad 0 #else .long 0 #endif .global fini_entry fini_entry: .long 0 dietlibc-0.33~cvs20120325/dynlinker/ldso_test.c010064400000000000000000000101171173363226000160440ustar00#include #include #include #include "../libdl/_dl_int.h" struct elf_aux { unsigned long type; unsigned long val; }; unsigned long ph_size; unsigned long ph_num; unsigned long pg_size; void (*dyn_start)(); void ldso_start(void); extern void (*fini_entry)(void); static struct _dl_handle* dlh; static void tt_fini(void) { struct _dl_handle*tmp; #ifdef DEBUG pf("dyn fini\n"); #endif for(tmp=dlh;tmp;tmp=tmp->next) { if (tmp->fini) tmp->fini(); } } int main(int argc, char**argv, char**envp) { int i; unsigned int *ui=(unsigned int*)envp; struct elf_aux *ea; Elf32_Phdr *ph32=0; /* --- */ unsigned int o=0, s=0; /* --- */ dlh = _dl_get_handle(); fini_entry = tt_fini; while (*ui) ++ui; /* while (still an env-pointer) next */ /* now *ui points to the tailing NULL-pointer of the envirioment */ /* print the elf_aux table */ for (ea=(struct elf_aux*)(ui+1); ea->type; ea++) { switch (ea->type) { case AT_EXECFD: case AT_NOTELF: write(2,"Unsupported execution type\n",27); _exit(42); break; case AT_PHDR: ph32=(Elf32_Phdr*)ea->val; #ifdef DEBUG pf("program header @ "); ph(ea->val); pf("\n"); #endif break; case AT_PHENT: ph_size=ea->val; #ifdef DEBUG pf("program header size "); ph(ea->val); pf("\n"); #endif break; case AT_PHNUM: ph_num=ea->val; #ifdef DEBUG pf("program header # "); ph(ea->val); pf("\n"); #endif break; #if 0 case AT_BASE: #ifdef DEBUG pf("interpreter base: "); ph(ea->val); pf("\n"); #endif break; case AT_FLAGS: #ifdef DEBUG pf("flags "); ph(ea->val); pf("\n"); #endif break; case AT_UID: #ifdef DEBUG pf(" UID: "); ph(ea->val); pf("\n"); #endif break; case AT_EUID: #ifdef DEBUG pf("EUID: "); ph(ea->val); pf("\n"); #endif break; case AT_GID: #ifdef DEBUG pf(" GID: "); ph(ea->val); pf("\n"); #endif break; case AT_EGID: #ifdef DEBUG pf("EGID: "); ph(ea->val); pf("\n"); #endif break; #endif case AT_PAGESZ: pg_size=ea->val; #ifdef DEBUG pf("page size "); ph(ea->val); pf("\n"); #endif break; case AT_ENTRY: dyn_start=(void(*)())ea->val; #ifdef DEBUG pf("start program @ "); ph(ea->val); pf("\n"); #endif break; #if 0 case AT_PLATFORM: #ifdef DEBUG pf("CPU: "); ph(ea->val); pf("\n"); #endif break; case AT_HWCAP: #ifdef DEBUG pf("CPU capabilities: "); ph(ea->val); pf("\n"); #endif break; case AT_CLKTCK: #ifdef DEBUG pf("CLK per sec "); ph( ea->val); pf("\n"); #endif break; #endif default: break; } } for (i=0; (iname=0; dlh->fini=0; _dl_open_dep(); #if 1 { struct _dl_handle* dlso; if ((dlso = _dl_find_lib("libdl.so"))) { struct _dl_handle* *tmp; void(*rmp)(const char*rp); write(2,"libdl.so",8); write(2," used.\n",7); if ((tmp=_dlsym(dlso,"_dl_root_handle" ))) *tmp=_dl_root_handle; if ((tmp=_dlsym(dlso,"_dl_top_handle" ))) *tmp=_dl_top_handle; if ((tmp=_dlsym(dlso,"_dl_free_list" ))) *tmp=_dl_free_list; if ((rmp=_dlsym(dlso,"_dl_set_rpath"))) { rmp(_dl_get_rpath()); } } } { struct _dl_handle* dietc; if ((dietc=_dl_find_lib("libc.so"))) { char***tmp; if ((tmp=_dlsym(dietc,"environ"))) { *tmp=envp; } else _exit(665); } else _exit(666); } #endif /* all depending libs have been loaded, now start the program or die */ if (dyn_start) return (int)dyn_start; /* found an AT_ENTRY in table -> jump to it */ _exit(17); } dietlibc-0.33~cvs20120325/examples/Makefile010064400000000000000000000001021173363226000151500ustar00sln: sln.c diet gcc -s -pipe -Os -o sln sln.c clean: rm -f sln dietlibc-0.33~cvs20120325/examples/sln.c010064400000000000000000000005071173363226000144610ustar00#include int strlen(const char *s) { int len; for (len=0; *s; s++,len++) ; return len; } void die(char *s) { write(2,s,strlen(s)); exit(111); } main(int argc,char *argv[]) { if (argc<3) die("usage: sln dest src\n"); if (symlink(argv[2],argv[1]) == -1) die("symlink failed\n"); return 0; } dietlibc-0.33~cvs20120325/findcflags.sh010075500000000000000000000010341173363226000143360ustar00#!/bin/sh version=`${1:-gcc} -v 2>&1 |sed -n '/gcc version/ {s/gcc version //;p;}'` case $version in 2.9*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=1 -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 ;; 3.0*) echo -march=i386 -Os -fomit-frame-pointer -malign-functions=1 -malign-jumps=1 -malign-loops=1 -mpreferred-stack-boundary=2 ;; [34]*) echo -Os -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -mpreferred-stack-boundary=2;; *) echo -O2 -pipe -fomit-frame-pointer ;; esac dietlibc-0.33~cvs20120325/i386/Makefile.add010064400000000000000000000012261173363226000145620ustar00 M:=$(shell ./findcflags.sh $(CC)) LIBOBJ+=$(OBJDIR)/__ten.o $(OBJDIR)/md5asm.o $(OBJDIR)/__restore_rt.o \ $(OBJDIR)/__CAS.o LIBMATH+=acos.o asin.o atan.o ceil.o cos.o exp.o exp10.o exp2.o expm1.o fabs.o floor.o hypot.o log.o log2.o log10.o sin.o sqrt.o copysign.o sincos.o __half.o ldexp.o ilogb.o cbrt.o log1p.o fmod.o libm2.o atan2.o tan.o LIBMATH:=$(filter-out acosh.o asinh.o atanh.o cbrt.o copysign.o exp10.o exp2.o expm1.o ilogb.o log2.o,$(LIBMATH)) #CFLAGS+=-march=i386 -Os -fomit-frame-pointer -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mpreferred-stack-boundary=2 CFLAGS+=$(M) VPATH:=i386:syscalls.s:$(VPATH) LIBGMON_OBJS+=$(OBJDIR)/mcount.o dietlibc-0.33~cvs20120325/i386/PIC.h010064400000000000000000000033021173363226000131540ustar00#ifndef __I386_PIC_H__ #define __I386_PIC_H__ #ifdef __DYN_LIB #undef __i686 #if 1 /* don't trash the athlon return stack */ #if (__GNUC__ >= 3) // FIXME: how do I check for the binutils version ? .section .gnu.linkonce.t.__i686.get_pc_thunk.bx,"ax",@progbits .global __i686.get_pc_thunk.bx .hidden __i686.get_pc_thunk.bx .type __i686.get_pc_thunk.bx,@function __i686.get_pc_thunk.bx: movl (%esp), %ebx ret .previous .macro PIC_INIT call __i686.get_pc_thunk.bx addl $_GLOBAL_OFFSET_TABLE_, %ebx .endm #else .text .Lgetpic: mov (%esp),%ebx ret .macro PIC_INIT call .Lgetpic addl $_GLOBAL_OFFSET_TABLE_, %ebx .endm #endif #else /* standard code for PIC init */ .macro PIC_INIT call 0f 0: popl %ebx addl $_GLOBAL_OFFSET_TABLE_+[.-0b], %ebx .endm #endif #define PIC_SAVE pushl %ebx #define PIC_RESTORE popl %ebx /* get memory variable (var) in register (reg) */ .macro GET_VAR var reg movl \var@GOT(%ebx), \reg movl (\reg), \reg .endm /* put register (reg) into memory variable (var) TRASH register (tmp) */ .macro PUT_VAR reg var tmp movl \var@GOT(%ebx), \tmp movl \reg, (\tmp) .endm /* get memory variable (var) in register (reg) * IF no more PIC-code is needed */ .macro GET_1VAR var reg PIC_SAVE PIC_INIT GET_VAR \var, \reg PIC_RESTORE .endm /* put register (reg) into memory variable (var) * IF no more PIC-code is needed */ .macro PUT_1VAR reg var PIC_SAVE PIC_INIT PUT_VAR \reg, \var, %ebx PIC_RESTORE .endm #else #define PIC_SAVE #define PIC_RESTORE #define PIC_INIT .macro GET_VAR var reg movl \var, \reg .endm .macro PUT_VAR reg var tmp movl \reg, \var .endm .macro GET_1VAR var reg GET_VAR \var, \reg .endm .macro PUT_1VAR reg var PUT_VAR \reg, \var, none .endm #endif #endif dietlibc-0.33~cvs20120325/i386/__CAS.S010064400000000000000000000002441173363226000134220ustar00.text .global __CAS .type __CAS,@function __CAS: movl 4(%esp), %edx movl 8(%esp), %eax movl 12(%esp), %ecx lock cmpxchgl %ecx, (%edx) ret .size __CAS, .-__CAS dietlibc-0.33~cvs20120325/i386/__half.S010064400000000000000000000003201173363226000137210ustar00# # Definiert Konstante (float)0.5 unter dem Namen __half # Wird von etlichen Funktionen benutzt (sinh, cosh, atanh) # .global __half .data .type __half,@object .size __half,4 __half: .long 0x3f000000 dietlibc-0.33~cvs20120325/i386/__longjmp.S010064400000000000000000000007531173363226000144670ustar00#include .text .global __longjmp .type __longjmp,@function __longjmp: movl 4(%esp), %ecx /* User's jmp_buf in %ecx. */ movl 8(%esp), %eax /* Second argument is return value. */ /* Save the return address now. */ movl (JB_PC*4)(%ecx), %edx /* Restore registers. */ movl (JB_BX*4)(%ecx), %ebx movl (JB_SI*4)(%ecx), %esi movl (JB_DI*4)(%ecx), %edi movl (JB_BP*4)(%ecx), %ebp movl (JB_SP*4)(%ecx), %esp /* Jump to saved PC. */ jmp *%edx .size __longjmp,.-__longjmp; dietlibc-0.33~cvs20120325/i386/__restore_rt.S010064400000000000000000000006231173363226000152050ustar00#include "syscalls.h" .text .type __restore_rt,@function .global __restore_rt .align 8 __restore_rt: movl $__NR_rt_sigreturn,%eax int $0x80 hlt /* die if syscall returns */ .size __restore_rt,.-__restore_rt .text .type __restore,@function .global __restore .align 8 __restore: popl %eax movl $__NR_sigreturn,%eax int $0x80 hlt /* die if syscall returns */ .size __restore,.-__restore dietlibc-0.33~cvs20120325/i386/__ten.S010064400000000000000000000002201173363226000135740ustar00# # Definiert Konstante (float)10. unter dem Namen __ten # .global __ten .data .type __ten,@object .size __ten,4 __ten: .long 0x41200000 dietlibc-0.33~cvs20120325/i386/__testandset.S010064400000000000000000000002171173363226000151720ustar00.text .global __testandset .type __testandset,@function __testandset: xorl %eax, %eax movl 0x4(%esp),%edx incl %eax xchgl %eax,(%edx) ret dietlibc-0.33~cvs20120325/i386/accept.S010064400000000000000000000001111173363226000137460ustar00#include #include __socketcall(accept,ACCEPT) dietlibc-0.33~cvs20120325/i386/acos.S010064400000000000000000000006021173363226000134410ustar00 .text .global acosf,acos,acosl # ,__acos .type acosf,@function .type acos,@function .type acosl,@function # .type __acos,@function acosf: flds 4(%esp) jmp __acos acosl: fldt 4(%esp) jmp __acos acos: fldl 4(%esp) __acos: fld %st fmul %st fld1 fsubp fsqrt fxch %st(1) fpatan ret .ende: .size acos,.ende-acos .size acosf,.ende-acosf .size acosl,.ende-acosl dietlibc-0.33~cvs20120325/i386/acosh.S010064400000000000000000000004561173363226000136200ustar00.text .global acosh .type acosh,@function acosh: fldln2 fldl 4(%esp) fld %st(0) fmul %st(0),%st(0) fld1 fsubrp %st(0),%st(1) fsqrt faddp %st(0),%st(1) fyl2x ret .Lende: .size acosh,.Lende-acosh dietlibc-0.33~cvs20120325/i386/asin.S010064400000000000000000000005651173363226000134560ustar00 .text .global asinf,asin,asinl # ,__asin .type asinf,@function .type asin,@function .type asinl,@function # .type __asin,@function asinf: flds 4(%esp) jmp __asin asinl: fldt 4(%esp) jmp __asin asin: fldl 4(%esp) __asin: fld %st fmul %st fld1 fsubp fsqrt fpatan ret .ende: .size asin,.ende-asin .size asinf,.ende-asinf .size asinl,.ende-asinl dietlibc-0.33~cvs20120325/i386/asinh.S010064400000000000000000000004561173363226000136250ustar00.text .global asinh .type asinh,@function asinh: fldln2 fldl 4(%esp) fld %st(0) fmul %st(0),%st(0) fld1 faddp %st(0),%st(1) fsqrt faddp %st(0),%st(1) fyl2x ret .Lende: .size asinh,.Lende-asinh dietlibc-0.33~cvs20120325/i386/atan.S010064400000000000000000000004661173363226000134470ustar00 .text .global atanf,atan,atanl .type atanf,@function .type atan,@function .type atanl,@function atanf: flds 4(%esp) fld1 fpatan ret atan: fldl 4(%esp) fld1 fpatan ret atanl: fldt 4(%esp) fld1 fpatan ret .ende: .size atan,.ende-atan .size atanf,.ende-atanf .size atanl,.ende-atanl dietlibc-0.33~cvs20120325/i386/atan2.S010064400000000000000000000005351173363226000135260ustar00.text .global atan2f,atan2,atan2l .type atan2f,@function .type atan2,@function .type atan2l,@function atan2f: flds 4(%esp) flds 8(%esp) fpatan ret atan2l: fldt 4(%esp) fldt 16(%esp) fpatan ret atan2: fldl 4(%esp) fldl 12(%esp) fpatan ret .ende: .size atan2,.ende-atan2 .size atan2f,.ende-atan2f .size atan2l,.ende-atan2l dietlibc-0.33~cvs20120325/i386/atanh.S010064400000000000000000000005161173363226000136130ustar00.text .global atanh .type atanh,@function atanh: fldln2 fldl 4(%esp) fld1 fld %st(1) fadd %st(1),%st(0) fxch %st(1) fsubp %st(0),%st(2) fdivp %st(0),%st(1) fyl2x fmuls __half ret .Lende: .size atanh,.Lende-atanh dietlibc-0.33~cvs20120325/i386/atol.S010064400000000000000000000014631173363226000134610ustar00/* Copyright (C) 2001, 2002 Thomas M. Ogrisegg This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. atol.S i386 assembler implementation of atoi(3) & atol(3) */ .text .globl atoi .globl atol .type atoi,@function .type atol,@function atoi: atol: pushl %esi movl 0x8(%esp), %esi xorl %eax, %eax xorl %edx, %edx xorb %cl, %cl cld .LSpace: lodsb or %al, %al jz .Lreturn cmpb $0x20, %al jng .LSpace cmpb $'+', %al jz .Lfe5 cmpb $'-', %al jnz .Lfe3 inc %cl jmp .Lfe5 .Lfe2: imul $0xa, %edx addl %eax, %edx .Lfe5: lodsb .Lfe3: cmpb $47, %al jng .Lout subb $('0'), %al cmpb $9, %al jng .Lfe2 .Lout: movl %edx, %eax or %cl, %cl jz .Lreturn negl %eax .Lreturn: popl %esi ret .size atoi, . - atoi .size atol, . - atol dietlibc-0.33~cvs20120325/i386/atoll.S010064400000000000000000000031421173363226000136310ustar00 .text .type atoll,@function .global atoll atoll: movl 4(%esp),%ecx push %edi xorl %edi,%edi # sign = 0 decl %ecx .Lspaces: incl %ecx # while ( isspace(*p) ) p++; movb (%ecx),%al cmpb $' ',%al je .Lspaces subb $9,%al cmpb $5,%al jc .Lspaces # c = *p - 9; cmpb $'+'-9,%al # if ( c == '+' - 9 ) p++; je .Lpos cmpb $'-'-9,%al # else if ( c == '-' - 9 ) sign = -sign, p++; jne .Lnosign decl %edi .Lpos: incl %ecx .Lnosign: push %ebx push %esi push %ebp movl $10,%ebp xorl %esi,%esi # Hi(value) = 0; xorl %eax,%eax # Lo(value) = 0; .Lcont: movzbl (%ecx),%ebx # while ( (unsigned) (*p - '0') < 10 ) inc %ecx subl $'0',%ebx cmpl %ebp,%ebx jnc .Lfini imull %ebp,%esi # value *= 10, mull %ebp addl %edx,%esi addl %ebx,%eax # value += (*p - '0'); adcl $0,%esi jmp .Lcont .Lfini: xchg %edx,%esi # return sign== 0 ? +value xorl %edi,%eax # sign==-1 ? -value xorl %edi,%edx subl %edi,%eax sbbl %edi,%edx pop %ebp pop %esi pop %ebx pop %edi ret .Lende: .size atoll,.Lende-atoll dietlibc-0.33~cvs20120325/i386/bind.S010064400000000000000000000001051173363226000134260ustar00#include #include __socketcall(bind,BIND) dietlibc-0.33~cvs20120325/i386/cbrt.S010064400000000000000000000030501173363226000134460ustar00.text tab: .byte 0, 0, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4 .byte 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9 .byte 10,10,11,11,12,12,12,13,13,14,14,14,15,15,15,16 _3: .long 0x40400000 .global cbrt cbrt: fldl 4(%esp) movw 10(%esp),%ax movb %ah,%ch andw $0x7FFF,%ax jz zero /* cbrt(0) = 0 */ pushl %ebx cwd movl $16*3,%ebx /* AX 3FE0 3FF0 4000 4010 */ divw %bx /* AX 154 155 155 155 */ /* DX 20 0 10 20 */ shlw $5,%ax addb %ch,%ch rcrw %ax /* AX 1540 1550 1550 1550 */ addw $0x3FF0-0x1550,%ax /* AX 3FE0 3FF0 3FF0 3FF0 */ movw %dx,%bx addb tab(%ebx),%al adcb $0,%ah popl %ebx movw %ax,10(%esp) fldl 4(%esp) /* y x */ movl $4,%ecx lop: fld %st(0) /* y y x */ fmul %st(0),%st(0) /* y^2 y x */ fdivr %st(2),%st(0) /* x/y^2 y x */ fadd %st(1),%st(0) /* x/y^2+y y x */ faddp /* x/y^2+2y x */ fdivs _3 /* y' x */ loop lop fstp %st(1) /* y' */ zero: ret dietlibc-0.33~cvs20120325/i386/ceil.S010064400000000000000000000017411173363226000134350ustar00#include "PIC.h" .text .global ceilf,ceil,ceill,__flcetr .type ceilf,@function .type ceil,@function .type ceill,@function .type __flcetr,@function ceilf: flds 4(%esp) movb $0x08,%ah jmp .Lflcetr ceill: fldt 4(%esp) movb $0x08,%ah jmp .Lflcetr ceil: fldl 4(%esp) movb $0x08,%ah # Wspolny kod dla funkcji floor, ceil i trunc # W ah maska bitow 11 i 10 rejestru sterowania koprocesora #ifndef __DYN_LIB __flcetr: #endif .Lflcetr: xorl %ecx,%ecx # wyzerowanie rejestru movb %ah,%ch # i utworzenie maski w cx pushl %eax # krotsze niz subl $4,%esp fstcw (%esp) movw (%esp),%ax andb $0x03,%ah # wyzerowanie bitow 11 i 10 orl %ecx,%eax # ustawienie bitow z maski movw %ax,2(%esp) fldcw 2(%esp) frndint fldcw (%esp) # odtworzenie rejestru sterowania popl %eax # i polozenia stosu ret #ifdef __DYN_LIB __flcetr: PIC_RESTORE jmp .Lflcetr #endif .Lende: .size ceil,.Lende-ceil .size ceill,.Lende-ceill .size ceilf,.Lende-ceilf .size __flcetr,.Lende-__flcetr dietlibc-0.33~cvs20120325/i386/clone.S010064400000000000000000000016521173363226000136220ustar00#include "syscalls.h" #include #include "PIC.h" .text .type clone,@function .weak clone clone: .type __clone,@function .global __clone __clone: mov $-EINVAL, %eax movl 4(%esp), %ecx /* have non null thread_funcion */ jecxz .Lclone_error movl 8(%esp), %ecx /* have non null child_stack pointer */ jecxz .Lclone_error /* put the parameter on thread stack */ subl $8, %ecx movl 16(%esp), %eax /* arg */ movl %eax, 4(%ecx) movl 4(%esp), %eax /* thread_func */ movl %eax, 0(%ecx) /* the syscall */ pushl %ebx movl 16(%esp), %ebx /* flags */ movl $__NR_clone, %eax int $0x80 popl %ebx testl %eax, %eax jl .Lclone_error jne .Lreturn .Lstart_thread: xorl %ebp,%ebp call *%ebx pushl %eax call _exit .Lclone_error: negl %eax pushl %eax #ifdef PIC pushl %ebx PIC_INIT call __errno_location@PLT popl %ebx #else call __errno_location #endif popl %ecx movl %ecx, (%eax) orl $-1, %eax .Lreturn: ret dietlibc-0.33~cvs20120325/i386/connect.S010064400000000000000000000001131173363226000141420ustar00#include #include __socketcall(connect,CONNECT) dietlibc-0.33~cvs20120325/i386/copysign.S010064400000000000000000000005041173363226000143500ustar00 .text .type copysign,@function .global copysign # double copysign ( double value, double sign ); copysign: movb 12+7(%esp),%al movb 4+7(%esp),%ah andw $0x7F80,%ax orb %ah,%al movb %al,4+7(%esp) fldl 4(%esp) ret .ende: .size copysign,.ende-copysign dietlibc-0.33~cvs20120325/i386/cos.S010064400000000000000000000006601173363226000133040ustar00.text .global cosf,cos,cosl .type cosf,@function .type cos,@function .type cosl,@function cosf: flds 4(%esp) jmp 1f cos: fldl 4(%esp) 1: fcos fnstsw %ax testb $0x04, %ah je 3f fldpi fadd %st fxch %st(1) 2: fprem1 fnstsw %ax testb $0x04, %ah jne 2b fstp %st(1) fcos 3: ret cosl: fldt 4(%esp) jmp 1b .Lende: .size cos,.Lende-cos .size cosl,.Lende-cosl .size cosf,.Lende-cosf dietlibc-0.33~cvs20120325/i386/cosh.S010064400000000000000000000010751173363226000134550ustar00#include "PIC.h" .text .global coshf,cosh,coshl .type coshf,@function .type cosh,@function .type coshl,@function coshf: fldl2e fmuls 4(%esp) jmp fincosh cosh: fldl2e fmull 4(%esp) fincosh: #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __finexp@PLT PIC_RESTORE #else call __finexp #endif fld1 fdiv %st(1),%st(0) # st(0)=1/exp(x), st(1)=exp(x) faddp %st,%st(1) pushl $0x3f000000 # 1/2 flds (%esp) popl %eax fmulp ret coshl: fldl2e fldt 4(%esp) fmulp jmp fincosh .Lende: .size cosh,.Lende-cosh .size coshf,.Lende-coshf .size coshl,.Lende-coshl dietlibc-0.33~cvs20120325/i386/dyn_syscalls.S010064400000000000000000000262161173363226000152340ustar00/* * dynamic unified-syscalls * Olaf Dreesen */ #include "../syscalls.s/environ.S" #include "../syscalls.s/errno.S" #include #include "syscalls.h" #include "PIC.h" #ifdef WANT_SYSENTER .data .type __vsyscall,@object .global __vsyscall __vsyscall: .Lvsyscall: .long .Lcallint80 .text .Lcallint80: int $0x80 ret #endif /* ok now include all syscalls.s (*.S) and sysdep *.S */ #include "mmap.S" /* here on i386 I had split them some pre- some post-unified-syscall, * because the jumps pre-u.s.c. have only a 1 byte displacement. the first * post-u.s.c. have also 1 byte dsplacement the rest a 4 byte. * this pre/post split saves about 250 byte of code .... * * Please put additional syscalls AFTER the post-u.s.c. * or try to not break the savings :) */ #include "select.S" #include "../syscalls.s/fork.S" #include "../syscalls.s/read.S" #include "../syscalls.s/write.S" #include "../syscalls.s/open.S" #include "../syscalls.s/close.S" #include "../syscalls.s/waitpid.S" #include "../syscalls.s/getgid.S" #include "../syscalls.s/getpgid.S" #include "../syscalls.s/getpid.S" #include "../syscalls.s/getppid.S" #include "../syscalls.s/getuid.S" #include "../syscalls.s/kill.S" #include "../syscalls.s/ioctl.S" #include "../syscalls.s/_llseek.S" #include "../syscalls.s/lseek.S" #include "../syscalls.s/lstat.S" #include "../syscalls.s/lstat64.S" #include "../syscalls.s/mkdir.S" #include "../syscalls.s/mprotect.S" #include "../syscalls.s/nanosleep.S" #include "../syscalls.s/pipe.S" #include "../syscalls.s/poll.S" #include "../syscalls.s/readv.S" #include "../syscalls.s/stat.S" #include "../syscalls.s/stat64.S" #include "../syscalls.s/truncate.S" #include "../syscalls.s/umask.S" #include "../syscalls.s/wait4.S" #include "../syscalls.s/writev.S" #include "../syscalls.s/__getpagesize.S" #include "../syscalls.s/ustat.S" /* OK this is basicaly unified.S */ .text .type __you_tried_to_link_a_dietlibc_object_against_glibc,@function .type __nop,@function .type __unified_syscall_256,@function __unified_syscall_256: movzwl %ax, %eax jmp 1f .size __unified_syscall_256,.-__unified_syscall_256 .type exit,@function .weak exit exit: .type _exit,@function .type __exit,@function .global _exit _exit: __exit: mov $__NR_exit, %al .type __unified_syscall,@function __unified_syscall: movzbl %al, %eax 1: push %edi push %esi push %ebx movl %esp,%edi #ifdef WANT_SYSENTER /* PIC-code ... */ pushl %ebp PIC_INIT movl .Lvsyscall@GOTOFF(%ebx),%ebp pushl %ebx #endif movl 0x10(%edi),%ebx movl 0x14(%edi),%ecx movl 0x18(%edi),%edx movl 0x1c(%edi),%esi movl 0x20(%edi),%edi #ifdef WANT_SYSENTER call *%ebp popl %ebx popl %ebp #else int $0x80 #endif cmp $-124,%eax jbe .Lnoerror neg %eax /* PIC-code Ohhhhh My. */ push %eax #ifndef WANT_SYSENTER PIC_INIT #endif call __errno_location@PLT popl %ebx movl %ebx,(%eax) orl $-1,%eax .Lnoerror: pop %ebx pop %esi pop %edi #include "dietuglyweaks.h" ret #include "../syscalls.s/__pread.S" #include "../syscalls.s/__pwrite.S" #include "../syscalls.s/__reboot.S" #include "../syscalls.s/access.S" #include "../syscalls.s/adjtimex.S" #include "../syscalls.s/brk.S" #include "../syscalls.s/chdir.S" #include "../syscalls.s/chmod.S" #include "../syscalls.s/chown.S" #include "../syscalls.s/chroot.S" #include "../syscalls.s/dup.S" #include "../syscalls.s/dup2.S" #include "../syscalls.s/execve.S" #include "../syscalls.s/fchdir.S" #include "../syscalls.s/fchmod.S" #include "../syscalls.s/fchown.S" #include "../syscalls.s/fcntl.S" #include "../syscalls.s/flock.S" #include "../syscalls.s/fstat.S" #include "../syscalls.s/fstat64.S" #include "../syscalls.s/fstatfs.S" #include "../syscalls.s/fsync.S" #include "../syscalls.s/fdatasync.S" #include "../syscalls.s/ftruncate.S" #include "../syscalls.s/getcwd.S" #include "../syscalls.s/getdents.S" #include "../syscalls.s/getdents64.S" #include "../syscalls.s/getegid.S" #include "../syscalls.s/geteuid.S" #include "../syscalls.s/getgroups.S" #include "../syscalls.s/getitimer.S" #include "../syscalls.s/getpriority.S" #include "../syscalls.s/getresgid.S" #include "../syscalls.s/getresuid.S" #include "../syscalls.s/getrlimit.S" #include "../syscalls.s/getrusage.S" #include "../syscalls.s/getsid.S" #include "../syscalls.s/gettimeofday.S" #include "../syscalls.s/settimeofday.S" #include "../syscalls.s/ioperm.S" #include "../syscalls.s/iopl.S" #include "../syscalls.s/ipc.S" #include "../syscalls.s/lchown.S" #include "../syscalls.s/link.S" #include "../syscalls.s/mknod.S" #include "../syscalls.s/mlock.S" #include "../syscalls.s/mlockall.S" #include "../syscalls.s/mount.S" #include "../syscalls.s/mremap.S" #include "../syscalls.s/munlockall.S" #include "../syscalls.s/munmap.S" #include "../syscalls.s/n_sigaction.S" #include "../syscalls.s/n_sigpending.S" #include "../syscalls.s/n_sigprocmask.S" #include "../syscalls.s/n_sigsuspend.S" #include "../syscalls.s/nice.S" #include "../syscalls.s/pause.S" #include "../syscalls.s/personality.S" #include "../syscalls.s/query_module.S" #include "../syscalls.s/init_module.S" #include "../syscalls.s/delete_module.S" #include "../syscalls.s/create_module.S" #include "../syscalls.s/readlink.S" #include "../syscalls.s/rename.S" #include "../syscalls.s/rmdir.S" #include "../syscalls.s/rt_sigaction.S" #include "../syscalls.s/rt_sigpending.S" #include "../syscalls.s/rt_sigprocmask.S" #include "../syscalls.s/rt_sigqueueinfo.S" #include "../syscalls.s/rt_sigsuspend.S" #include "../syscalls.s/rt_sigtimedwait.S" #include "../syscalls.s/sched_getaffinity.S" #include "../syscalls.s/sched_setaffinity.S" #include "../syscalls.s/sched_get_priority_max.S" #include "../syscalls.s/sched_get_priority_min.S" #include "../syscalls.s/sched_getparam.S" #include "../syscalls.s/sched_getscheduler.S" #include "../syscalls.s/sched_rr_get_interval.S" #include "../syscalls.s/sched_setparam.S" #include "../syscalls.s/sched_setscheduler.S" #include "../syscalls.s/sched_yield.S" #include "../syscalls.s/sendfile.S" #include "../syscalls.s/setdomainname.S" #include "../syscalls.s/setfsgid.S" #include "../syscalls.s/setfsuid.S" #include "../syscalls.s/setgid.S" #include "../syscalls.s/setgroups.S" #include "../syscalls.s/sethostname.S" #include "../syscalls.s/setitimer.S" #include "../syscalls.s/setpgid.S" #include "../syscalls.s/setpriority.S" #include "../syscalls.s/setregid.S" #include "../syscalls.s/setresgid.S" #include "../syscalls.s/setresuid.S" #include "../syscalls.s/setreuid.S" #include "../syscalls.s/setrlimit.S" #include "../syscalls.s/setsid.S" #include "../syscalls.s/setuid.S" #include "../syscalls.s/sigaltstack.S" #include "../syscalls.s/statfs.S" #include "../syscalls.s/stime.S" #include "../syscalls.s/swapoff.S" #include "../syscalls.s/swapon.S" #include "../syscalls.s/symlink.S" #include "../syscalls.s/sync.S" #include "../syscalls.s/sysctl.S" #include "../syscalls.s/sysinfo.S" #include "../syscalls.s/syslog.S" #include "../syscalls.s/time.S" #include "../syscalls.s/times.S" #include "../syscalls.s/umount.S" #include "../syscalls.s/umount2.S" #include "../syscalls.s/uname.S" #include "../syscalls.s/unlink.S" #include "../syscalls.s/utime.S" #include "../syscalls.s/vhangup.S" #include "../syscalls.s/msync.S" #include "../syscalls.s/chown32.S" #include "../syscalls.s/fchown32.S" #include "../syscalls.s/getegid32.S" #include "../syscalls.s/geteuid32.S" #include "../syscalls.s/getgid32.S" #include "../syscalls.s/getgroups32.S" #include "../syscalls.s/getresgid32.S" #include "../syscalls.s/getuid32.S" #include "../syscalls.s/lchown32.S" #include "../syscalls.s/setfsgid32.S" #include "../syscalls.s/setfsuid32.S" #include "../syscalls.s/setgid32.S" #include "../syscalls.s/setregid32.S" #include "../syscalls.s/setresgid32.S" #include "../syscalls.s/setreuid32.S" #include "../syscalls.s/setuid32.S" #include "../syscalls.s/alarm.S" #include "../syscalls.s/ptrace.S" #include "../syscalls.s/truncate64.S" #include "../syscalls.s/ftruncate64.S" #include "../syscalls.s/epoll_create.S" #include "../syscalls.s/epoll_ctl.S" #include "../syscalls.s/epoll_wait.S" #include "../syscalls.s/sendfile64.S" #include "../syscalls.s/sysfs.S" #include "../syscalls.s/capget.S" #include "../syscalls.s/capset.S" #include "../syscalls.s/fcntl64.S" #include "../syscalls.s/timer_create.S" #include "../syscalls.s/timer_settime.S" #include "../syscalls.s/timer_gettime.S" #include "../syscalls.s/timer_getoverrun.S" #include "../syscalls.s/timer_delete.S" #include "../syscalls.s/clock_settime.S" #include "../syscalls.s/clock_gettime.S" #include "../syscalls.s/clock_getres.S" #include "../syscalls.s/clock_nanosleep.S" #include "../syscalls.s/mq_getsetattr.S" #include "../syscalls.s/mq_notify.S" #include "../syscalls.s/mq_open.S" #include "../syscalls.s/mq_timedreceive.S" #include "../syscalls.s/mq_timedsend.S" #include "../syscalls.s/mq_unlink.S" #include "../syscalls.s/statfs64.S" #include "../syscalls.s/fstatfs64.S" #include "../syscalls.s/tkill.S" #include "../syscalls.s/tgkill.S" #include "../syscalls.s/set_tid_address.S" #include "../syscalls.s/set_thread_area.S" #include "../syscalls.s/set_mempolicy.S" #include "../syscalls.s/rt_sigreturn.S" #include "../syscalls.s/gettid.S" #include "../syscalls.s/get_thread_area.S" #include "../syscalls.s/remap_file_pages.S" #include "../syscalls.s/readahead.S" #include "../syscalls.s/quotactl.S" #include "../syscalls.s/mincore.S" #include "../syscalls.s/mbind.S" #include "../syscalls.s/get_mempolicy.S" #include "../syscalls.s/futex.S" #include "../syscalls.s/fadvise64.S" #include "../syscalls.s/fadvise64_64.S" #include "../syscalls.s/vserver.S" #include "../syscalls.s/request_key.S" #include "../syscalls.s/keyctl.S" #include "../syscalls.s/add_key.S" #include "../syscalls.s/io_submit.S" #include "../syscalls.s/io_setup.S" #include "../syscalls.s/io_getevents.S" #include "../syscalls.s/io_destroy.S" #include "../syscalls.s/io_cancel.S" #include "../syscalls.s/inotify_rm_watch.S" #include "../syscalls.s/inotify_init.S" #include "../syscalls.s/inotify_add_watch.S" #include "../syscalls.s/setxattr.S" #include "../syscalls.s/lsetxattr.S" #include "../syscalls.s/fsetxattr.S" #include "../syscalls.s/removexattr.S" #include "../syscalls.s/lremovexattr.S" #include "../syscalls.s/fremovexattr.S" #include "../syscalls.s/listxattr.S" #include "../syscalls.s/llistxattr.S" #include "../syscalls.s/flistxattr.S" #include "../syscalls.s/getxattr.S" #include "../syscalls.s/lgetxattr.S" #include "../syscalls.s/fgetxattr.S" #include "../syscalls.s/timerfd.S" #include "../syscalls.s/__signalfd.S" #include "../syscalls.s/fallocate.S" #include "../syscalls.s/utimes.S" #undef __PIC__ #undef __socketcall /* oh what a kludge! */ #define socketcall .Lsocketcall #include "send.S" #include "recv.S" #include "socket.S" #include "accept.S" #include "shutdown.S" #include "socketpair.S" #include "setsockopt.S" #include "sendto.S" #include "sendmsg.S" #include "recvmsg.S" #include "recvfrom.S" #include "listen.S" #include "getsockopt.S" #include "getsockname.S" #include "getpeername.S" #include "connect.S" #include "bind.S" #undef socketcall .Lsocketcall: #include "socketcall.S" #define __PIC__ #undef __socketcall /* so now this was the last u.s.c. */ /* other asm-files ... */ #define PIC #define _exit __exit #include "clone.S" #undef _exit #include "__longjmp.S" #include "setjmp.S" #include "syscalls.s/__guard.S" dietlibc-0.33~cvs20120325/i386/exp.S010064400000000000000000000010731173363226000133130ustar00#include "PIC.h" .text .global expf,exp,expl,__finexp .type expf,@function .type exp,@function .type expl,@function .type __finexp,@function expf: fldl2e fmuls 4(%esp) jmp .Lfinexp expl: fldl2e fldt 4(%esp) fmulp jmp .Lfinexp exp: fldl2e fmull 4(%esp) #ifndef __DYN_LIB __finexp: #endif .Lfinexp: fst %st(1) frndint fst %st(2) fsubrp f2xm1 fld1 faddp fscale ret #ifdef __DYN_LIB __finexp: PIC_RESTORE jmp .Lfinexp #endif .Lende: .size exp,.Lende-exp .size expl,.Lende-expl .size expf,.Lende-expf .size __finexp,.Lende-__finexp dietlibc-0.33~cvs20120325/i386/exp10.S010064400000000000000000000016701173363226000134570ustar00 .text .type exp10,@function .global exp10 .type pow10,@function .global pow10 pow10: exp10: # note: 10^(x) = 2^(x*log2(10)) fldl2t fmull 4(%esp) # x*log2(10) fld %st(0) # x*log2(10) x*log2(10) frndint # int(x*log2(10)) x*log2(10) fxch # x*log2(10) int(x*log2(10)) fsub %st(1),%st(0) # frac(x*log2(10)) int(x*log2(10)) f2xm1 # 2^(fract(x*log2(10)))-1 int(x*log2(10)) fld1 # 1 2^(fract(x*log2(10)))-1 int(x*log2(10)) faddp %st(0),%st(1) # 2^(fract(x*log2(10))) int(x*log2(10)) fscale # 2^(x*log2(10)) int(x*log2(10)) fstp %st(1) # 2^(x*log2(10)) ret .ende: .size exp10,.ende-exp10 .size pow10,.ende-pow10 dietlibc-0.33~cvs20120325/i386/exp2.S010064400000000000000000000012441173363226000133750ustar00.text .type exp2,@function .global exp2 exp2: # note: exp2(x) = 2^x fldl 4(%esp) # x fld %st(0) # x x frndint # int(x) x fxch # x int(x) fsub %st(1),%st(0) # frac(x) int(x) f2xm1 # 2^(fract(x))-1 int(x) fld1 # 1 2^(fract(x))-1 int(x) faddp %st(0),%st(1) # 2^(fract(x)) int(x) fscale # 2^x int(x) fstp %st(1) # 2^x ret .ende: .size exp2,.ende-exp2 dietlibc-0.33~cvs20120325/i386/expm1.S010064400000000000000000000025571173363226000135610ustar00.text .type expm1,@function .global expm1 expm1: # note: exp(x) = 2^(x*log2(e)) fldl2e fmull 4(%esp) # x*log2(e) fld %st(0) # x*log2(e) x*log2(e) frndint # int(x*log2(e)) x*log2(e) fxch # x*log2(e) int(x*log2(e)) fsub %st(1),%st(0) # frac(x*log2(e)) int(x*log2(e)) f2xm1 # 2^(fract(x*log2(e)))-1 int(x*log2(e)) fscale # 2^(x*log2(e))-2^int(x*log2(e)) int(x*log2(e)) fxch # int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) fld1 # 1 int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) fscale # 2^int(x*log2(e)) int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) fstp %st(1) # 2^int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) fld1 # 1 2^int(x*log2(e)) 2^(x*log2(e))-2^int(x*log2(e)) fsubrp %st(1) # 2^int(x*log2(e))-1 2^(x*log2(e))-2^int(x*log2(e)) faddp %st(1) ret .ende: .size expm1,.ende-expm1 dietlibc-0.33~cvs20120325/i386/fabs.S010064400000000000000000000004321173363226000134300ustar00.text .global fabsf,fabs,fabsl .type fabsf,@function .type fabs,@function .type fabsl,@function fabsf: flds 4(%esp) fabs ret fabs: fldl 4(%esp) fabs ret fabsl: fldt 4(%esp) fabs ret .ende: .size fabs,.ende-fabs .size fabsl,.ende-fabsl .size fabsf,.ende-fabsf dietlibc-0.33~cvs20120325/i386/ffs.S010064400000000000000000000003371173363226000132770ustar00.text .align 0 .global ffs,ffsl .type ffs,@function .type ffsl,@function ffs: ffsl: xorl %eax,%eax orl 4(%esp),%eax jz .Ldone bsfl %eax,%eax incl %eax .Ldone: ret .Lende: .size ffsl,.Lende-ffsl .size ffs,.Lende-ffs dietlibc-0.33~cvs20120325/i386/ffsl.S010064400000000000000000000000001173363226000134360ustar00dietlibc-0.33~cvs20120325/i386/ffsll.S010064400000000000000000000004101173363226000136170ustar00.text .align 0 .global ffsll .type ffsll,@function ffsll: xorl %eax,%eax orl 4(%esp),%eax jz .Lsecond bsfl %eax,%eax incl %eax .Ldone: ret .Lsecond: orl 8(%esp),%eax jz .Ldone2 bsfl %eax,%eax addl $33,%eax .Ldone2: ret .Lende: .size ffsll,.Lende-ffsll dietlibc-0.33~cvs20120325/i386/floor.S010064400000000000000000000011071173363226000136360ustar00#include "PIC.h" .text .global floorf,floor,floorl .type floorf,@function .type floor,@function .type floorl,@function floorf: flds 4(%esp) movb $0x04,%ah #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __flcetr@PLT #else jmp __flcetr #endif floor: fldl 4(%esp) movb $0x04,%ah #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __flcetr@PLT #else jmp __flcetr #endif floorl: fldt 4(%esp) movb $0x04,%ah #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __flcetr@PLT #else jmp __flcetr #endif .Lende: .size floor,.Lende-floor .size floorl,.Lende-floorl .size floorf,.Lende-floorf dietlibc-0.33~cvs20120325/i386/fmod.S010064400000000000000000000007441173363226000134500ustar00.text .type fmod,@function .type fmodf,@function .type fmodl,@function .type __fmod2pi,@function .global fmod, fmodl, fmodf, __fmod2pi __fmod2pi: fldpi fadd %st(0) fxch jmp .Lfmod fmodf: flds 8(%esp) # y flds 4(%esp) # x jmp .Lfmod fmod: fldl 12(%esp) fldl 4(%esp) .Lfmod: fprem fstsw %ax sahf jp .Lfmod fstp %st(1) ret fmodl: fldt 16(%esp) fldt 4(%esp) jmp .Lfmod .ende: .size fmod,.ende-fmod .size fmodl,.ende-fmodl .size fmodf,.ende-fmodf dietlibc-0.33~cvs20120325/i386/getenv.S010064400000000000000000000012331173363226000140050ustar00#include "PIC.h" .text .global getenv .type getenv,@function getenv: pushl %esi pushl %edi movl 0xc(%esp), %edi cld movl %edi, %edx xorl %eax, %eax leal -1(%eax), %ecx repnz scasb not %ecx dec %ecx pushl %ecx movzbl (%edx), %ecx GET_1VAR environ, %esi # non-PIC: movl environ, %esi jmp .Lloop .Lprepare: movzbl (%edx), %ecx movl %eax, %esi .Lloop: lodsl or %eax, %eax jz .Lout cmpb %cl, (%eax) jnz .Lloop movl %edx, %edi xchg %esi, %eax movl (%esp), %ecx repz cmpsb jne .Lprepare or %ecx, %ecx jnz .Lprepare cmpb $'=', (%esi) jne .Lprepare leal 0x1(%esi), %eax .Lout: popl %ecx popl %edi popl %esi ret .size getenv, . - getenv dietlibc-0.33~cvs20120325/i386/getpeername.S010064400000000000000000000001231173363226000150060ustar00#include #include __socketcall(getpeername,GETPEERNAME) dietlibc-0.33~cvs20120325/i386/getsockname.S010064400000000000000000000001231173363226000150120ustar00#include #include __socketcall(getsockname,GETSOCKNAME) dietlibc-0.33~cvs20120325/i386/getsockopt.S010064400000000000000000000001211173363226000146720ustar00#include #include __socketcall(getsockopt,GETSOCKOPT) dietlibc-0.33~cvs20120325/i386/htonl.S010064400000000000000000000003231173363226000136400ustar00.text .global htonl .type htonl,@function .global ntohl .type ntohl,@function htonl: ntohl: movl 4(%esp),%eax xchgb %al,%ah rorl $16,%eax xchgb %al,%ah ret dietlibc-0.33~cvs20120325/i386/htons.S010064400000000000000000000002421173363226000136470ustar00.text .global htons .type htons,@function .global ntohs .type ntohs,@function htons: ntohs: movzwl 4(%esp),%eax xchgb %al,%ah ret dietlibc-0.33~cvs20120325/i386/hypot.S010064400000000000000000000007011173363226000136570ustar00.text .global hypotf,hypot,hypotl # ,__hypot .type hypotf,@function .type hypot,@function .type hypotl,@function # .type __hypot,@function hypotf: flds 8(%esp) flds 4(%esp) jmp __hypot hypotl: fldt 16(%esp) fldt 4(%esp) jmp __hypot hypot: fldl 12(%esp) fldl 4(%esp) __hypot: fmul %st(0),%st(0) fxch fmul %st(0),%st(0) faddp fsqrt ret .ende: .size hypot,.ende-hypot .size hypotf,.ende-hypotf .size hypotl,.ende-hypotl dietlibc-0.33~cvs20120325/i386/ilogb.S010064400000000000000000000004431173363226000136130ustar00# # int ilogb ( double x ); # # returns (int) log2 (fabs(x)) for x!=0 # returns MIN_INT for x==0 # .text .global ilogb .type ilogb,@function ilogb: movl 8(%esp),%eax addl %eax,%eax jz .Lzero shrl $21,%eax subl $1023,%eax ret .Lzero: stc rcrl %eax ret dietlibc-0.33~cvs20120325/i386/ipow.S010064400000000000000000000010651173363226000134760ustar00# # This is not standard, but often you only need such this function # which is much shorter than the generic pow() function. # # double ipow ( double mant, int expo ); # .text .global ipow .type ipow,@function ipow: fld1 movl 12(%esp),%ecx fldl 4(%esp) and %ecx,%ecx jns .Lstart negl %ecx fdivr %st(1),%st(0) jmp .Lstart .Lnext: fmul %st(0),%st(0) .Lstart:shrl %ecx jnc .Lnomul fmul %st(0),%st(1) .Lnomul:jnz .Lnext fcomp ret dietlibc-0.33~cvs20120325/i386/isleap.S010064400000000000000000000011551173363226000137750ustar00.text .globl __isleap .type __isleap,@function __isleap: movl 4(%esp),%eax testb $3,%al jne .Lretzero #if 1 movb $100,%cl /* this works only for 0 a.D. ... 25599 a.C. */ divb %cl andb %ah,%ah #else cltd /* This works for 2147483648 b.C. ... 2147483647 a.C. */ movl $100,%ecx divl %ecx andl %edx,%edx #endif jne .Lretone testb $3,%al jne .Lretzero .Lretone: xorl %eax,%eax incl %eax ret .Lretzero:xorl %eax,%eax ret dietlibc-0.33~cvs20120325/i386/ldexp.S010064400000000000000000000005411173363226000136320ustar00.text .global ldexpf,ldexp,ldexpl .type ldexpf,@function .type ldexp,@function .type ldexpl,@function ldexpf: fildl 8(%esp) flds 4(%esp) fscale ret ldexp: fildl 12(%esp) fldl 4(%esp) fscale ret ldexpl: fildl 16(%esp) fldt 4(%esp) fscale ret .ende: .size ldexpl,.ende-ldexpl .size ldexp,ldexpl-ldexp .size ldexpf,ldexp-ldexpf dietlibc-0.33~cvs20120325/i386/libm2.S010064400000000000000000000136361173363226000135340ustar00#include "PIC.h" .text #d.half: # .long 0x3f000000 # 1/2 #d.log1p: # .long 0x3ed413cc # < sqrt(2)-1-2^(-25) .global cbrtf,cbrt,cbrtl .type cbrtf,@function .type cbrt,@function .type cbrtl,@function cbrtf: flds 4(%esp) jmp __cbrt cbrtl: fldt 4(%esp) jmp __cbrt cbrt: fldl 4(%esp) # fldt 1/3 __cbrt: pushl $0x00003ffd # yes, this method of loading 1/3 pushl $0xaaaaaaaa # is shorter than keeping the data pushl $0xaaaaaaab # separate fldt (%esp) addl $12,%esp fxch # st(0)=x, st(1)=1/3 ftst fstsw %ax sahf jz 1f jnc finpow fchs call finpow fchs 1: ret # x^y; st(0)=x, st(1)=y (x > 0) finpow: fyl2x #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif .global exp2f,exp2,exp2l .type exp2f,@function .type exp2,@function .type exp2l,@function exp2f: flds 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif exp2: fldl 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif exp2l: fldt 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif .global exp10f,exp10,exp10l #,pow10f,pow10,pow10l .type exp10f,@function .type exp10,@function .type exp10l,@function # .type pow10f,@function # .type pow10,@function # .type pow10l,@function exp10f: #pow10f: fldl2t fmuls 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif exp10: #pow10: fldl2t fmull 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif exp10l: #pow10l: fldl2t fldt 4(%esp) fmulp #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif # exp(x)-1 .global expm1f,expm1,expm1l .type expm1f,@function .type expm1,@function .type expm1l,@function expm1f: fldl2e fmuls 4(%esp) jmp finem1 expm1l: fldl2e fldt 4(%esp) fmulp jmp finem1 expm1: fldl2e fmull 4(%esp) # -1 <= st <= 1 ? finem1: fst %st(1) # st(1)=st(0) fabs fld1 fcompp fstsw %ax sahf # |x| >= 1 jc 1f f2xm1 ret #ifdef __DYN_LIB 1: PIC_SAVE PIC_INIT call __finexp@PLT PIC_RESTORE #else 1: call __finexp #endif fld1 fsubrp ret # sinh(x)=(exp(x)-exp(-x))/2 # cosh(x)=(exp(x)+exp(-x))/2 # tanh(x)=sinh(x)/cosh(x) .global log2f,log2,log2l .type log2f,@function .type log2,@function .type log2l,@function log2f: fld1 flds 4(%esp) fyl2x ret log2l: fld1 fldt 4(%esp) fyl2x ret log2: fld1 fldl 4(%esp) fyl2x ret .global fmaf,fma,fmal .type fmaf,@function .type fma,@function .type fmal,@function fmaf: flds 4(%esp) fmuls 8(%esp) fadds 12(%esp) ret fma: fldl 4(%esp) fmull 12(%esp) faddl 20(%esp) ret fmal: fldt 4(%esp) fldt 16(%esp) fmulp %st,%st(1) fldt 28(%esp) faddp %st,%st(1) ret .global asinhf,asinh,asinhl .type asinhf,@function .type asinh,@function .type asinhl,@function asinhf: flds 4(%esp) jmp __asinh asinh: fldl 4(%esp) __asinh: fld %st(0) fmul %st(0),%st(0) fld1 faddp %st(0),%st(1) finasch: fsqrt faddp %st(0),%st(1) fldln2 fxch fyl2x ret asinhl: fldt 4(%esp) jmp __asinh .global acoshf,acosh,acoshl .type acoshf,@function .type acosh,@function .type acoshl,@function acoshf: flds 4(%esp) jmp __acosh acosh: fldl 4(%esp) __acosh: fld %st(0) fmul %st(0),%st(0) fld1 fsubrp %st(0),%st(1) # st1=st1-st0; pop jmp finasch acoshl: fldt 4(%esp) jmp __acosh .global atanhf,atanh,atanhl .type atanhf,@function .type atanh,@function .type atanhl,@function atanhf: flds 4(%esp) jmp __atanh atanh: fldl 4(%esp) __atanh: fst %st(1) fld1 # st0=1, st1=x, st2=x fadd %st(0),%st(2) # st0=1, st1=x, st2=x+1 fsubp %st(0),%st(1) # st0=1-x, st1=x+1 fdivrp %st(0),%st(1) fsqrt fldln2 fxch fyl2x ret atanhl: fldt 4(%esp) jmp __atanh .global dremf,drem,dreml .type dremf,@function .type drem,@function .type dreml,@function dremf: flds 8(%esp) # y flds 4(%esp) # x jmp __drem drem: fldl 12(%esp) fldl 4(%esp) __drem: fprem1 fstsw %ax sahf jp __drem ret dreml: fldt 16(%esp) fldt 4(%esp) jmp __drem # |ret| = |x|, sign(ret) = sign(y) .global copysignf,copysign,copysignl .type copysignf,@function .type copysign,@function .type copysignl,@function copysignf: flds 4(%esp) # x flds 8(%esp) # y jmp __copysign copysign: fldl 4(%esp) fldl 12(%esp) __copysign: fmul %st(1),%st # st = x*y ftst fstsw %ax fincstp sahf jnc 1f fchs 1: ret copysignl: fldt 4(%esp) fldt 16(%esp) jmp __copysign .global fdimf,fdim,fdiml .type fdimf,@function .type fdim,@function .type fdiml,@function fdimf: flds 4(%esp) fsubl 12(%esp) jmp __fdim fdim: fldl 4(%esp) fsubl 12(%esp) __fdim: fstsw %ax sahf jnc 1f fldz 1: ret fdiml: fldt 4(%esp) fldt 16(%esp) fsubp jmp __fdim .global truncf,trunc,truncl .type truncf,@function .type trunc,@function .type truncl,@function truncf: flds 4(%esp) movb $0x0c,%ah #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __flcetr@PLT #else jmp __flcetr #endif trunc: fldl 4(%esp) movb $0x0c,%ah #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __flcetr@PLT #else jmp __flcetr #endif truncl: fldt 4(%esp) movb $0x0c,%ah #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __flcetr@PLT #else jmp __flcetr #endif .global frexpf,frexp,frexpl .type frexpf,@function .type frexp,@function .type frexpl,@function frexpf: flds 4(%esp) movl 8(%esp),%eax jmp __frexp frexp: fldl 4(%esp) movl 12(%esp),%eax __frexp: fxtract fxch fistpl (%eax) pushl $0x3f000000 # 1/2 fmuls (%esp) incl (%eax) popl %eax ret frexpl: fldt 4(%esp) movl 16(%esp),%eax jmp __frexp .global logbf,logb,logbl .type logbf,@function .type logb,@function .type logbl,@function #logbf: flds 4(%esp) # fxtract # fxch # ret #logb: fldl 4(%esp) # fxtract # fxch # ret #logbl: fldt 4(%esp) # fxtract # fxch # ret .global ilogbf,ilogb,ilogbl .type ilogbf,@function .type ilogb,@function .type ilogbl,@function logbf: ilogbf: flds 4(%esp) jmp __ilogb logb: ilogb: fldl 4(%esp) __ilogb: fxtract pushl %eax fxch fistl (%esp) popl %eax ret logbl: ilogbl: fldt 4(%esp) jmp __ilogb dietlibc-0.33~cvs20120325/i386/listen.S010064400000000000000000000001111173363226000140050ustar00#include #include __socketcall(listen,LISTEN) dietlibc-0.33~cvs20120325/i386/log.S010064400000000000000000000004551173363226000133030ustar00.text .global logf,log,logl .type logf,@function .type log,@function .type logl,@function logf: fldln2 flds 4(%esp) fyl2x ret logl: fldln2 fldt 4(%esp) fyl2x ret log: fldln2 fldl 4(%esp) fyl2x ret .Lende: .size log,.Lende-log .size logl,.Lende-logl .size logf,.Lende-logf dietlibc-0.33~cvs20120325/i386/log10.S010064400000000000000000000005101173363226000134340ustar00.text .global log10f,log10,log10l .type log10f,@function .type log10,@function .type log10l,@function log10f: fldlg2 flds 4(%esp) fyl2x ret log10l: fldlg2 fldt 4(%esp) fyl2x ret log10: fldlg2 fldl 4(%esp) fyl2x ret .ende: .size log10,.ende-log10 .size log10f,.ende-log10f .size log10l,.ende-log10l dietlibc-0.33~cvs20120325/i386/log1p.S010064400000000000000000000010461173363226000135410ustar00.text .global log1pf,log1p,log1pl .type log1pf,@function .type log1p,@function .type log1pl,@function log1pf: flds 4(%esp) jmp __log1p log1pl: fldt 4(%esp) jmp __log1p log1p: fldl 4(%esp) __log1p: # Sprawdzenie zakresu parametru fst %st(1) pushl $0x3ed413cc # sqrt(2)-1-2^(-25) fabs flds (%esp) popl %eax fcompp # porownanie fstsw %ax fldln2 fxch sahf # |x| >= sqrt(2)-1 jc 1f fyl2xp1 ret 1: fld1 # x = x + 1 faddp fyl2x ret .ende: .size log1p,.ende-log1p .size log1pf,.ende-log1pf .size log1pl,.ende-log1pl dietlibc-0.33~cvs20120325/i386/log2.S010064400000000000000000000002201173363226000133530ustar00.text .type log2,@function .global log2 log2: fld1 fldl 4(%esp) fyl2x ret .ende: .size log2,.ende-log2 dietlibc-0.33~cvs20120325/i386/ltostr.S010064400000000000000000000021011173363226000140370ustar00/* Copyright (C) 2002 Thomas M. Ogrisegg __ltostr.S -- convert an integer into a string %eax = dividend %ebx = divisor %ecx = size of output-buffer %edi = output-buffer %ebp = if uppercase is set, then %ebp is 'A'-10 else %ebp is 'a'-10 */ .text .globl __ltostr __ltostr: pushl %esi pushl %edi # destination pushl %ebp pushl %ebx movl %esp, %eax movl 0x14(%eax), %edi movl 0x18(%eax), %ecx # size movl 0x20(%eax), %ebx # divisor movl 0x1c(%eax), %eax # dividend decl %ecx movl %ecx, %esi movl $('A'-0xa), %ebp xorl %edx, %edx # must be 0 -- used by idiv cmpl $0x0, 36(%esp) # check for uppercase jnz .Lnext addl $0x20, %ebp # set lowercase .Lnext: idiv %ebx, %eax cmpb $0x9, %dl jg .Lnext2 addb $'0', %dl jmp .Lstos .Lnext2: addl %ebp, %edx .Lstos: movb %dl, (%edi, %ecx) xorl %edx, %edx decl %ecx jz .Lout orl %eax, %eax jnz .Lnext .Lout: cld movl %esi, %ebx leal 1(%edi, %ecx), %esi subl %ebx, %ecx negl %ecx movl %ecx, %eax repnz movsb movb $0x0, (%edi) popl %ebx popl %ebp popl %edi popl %esi ret .size __ltostr, . - __ltostr dietlibc-0.33~cvs20120325/i386/mcount.S010064400000000000000000000014501173363226000140230ustar00/* Copyright (C) 2001, 2002 Thomas M. Ogrisegg This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. mcount.S i386 assembler implementation of mcount */ /* .section ".profile" */ .text .globl mcount .type mcount,@function mcount: /* save all generic registers which might be used by __mcount, but aren't automatically saved */ pushl %eax pushl %ecx pushl %edx /* push the instruction pointer of the calling function */ pushl 0xc(%esp) /* push the instruction pointer of the function that called the calling function */ pushl 0x4(%ebp) call __mcount /* clean up stack */ addl $0x8, %esp /* restore the previously saved registers */ popl %edx popl %ecx popl %eax ret .size mcount,.-mcount dietlibc-0.33~cvs20120325/i386/md5asm.S010064400000000000000000000214661173363226000137150ustar00#define S11 7 #define S12 12 #define S13 17 #define S14 22 #define S21 5 #define S22 9 #define S23 14 #define S24 20 #define S31 4 #define S32 11 #define S33 16 #define S34 23 #define S41 6 #define S42 10 #define S43 15 #define S44 21 // #define F(x, y, z) (x & y) + (~x & z) = x&y + (z - z&x) = z + y&x - z&x //#define F(x, y, z) movl x,%ebx; movl x,%eax; notl %ebx; andl y,%eax; andl z,%ebx; addl %ebx,%eax #define F(x, y, z) movl y,%eax; movl z,%ebx; andl x,%eax; andl x,%ebx; addl z,%eax; subl %ebx,%eax // #define G(x, y, z) (x & z) + (y & ~z) = x&z + (y - y&z) = y + x&z - y&z #define G(x, y, z) movl z,%ebx; movl z,%eax; notl %ebx; andl x,%eax; andl y,%ebx; addl %ebx,%eax //#define G(x, y, z) movl x,%eax; movl y,%ebx; andl z,%eax; andl z,%ebx; addl y,%eax; subl %ebx,%eax //#define G(x, y, z) movl z,%eax; movl z,%ebx; andl x,%eax; andl y,%ebx; addl y,%eax; subl %ebx,%eax // #define H(x, y, z) x ^ y ^ z #define H(x, y, z) movl z,%eax; xorl y,%eax; xorl x,%eax // #define I(x, y, z) y ^ (x | ~z) #define I(x, y, z) movl z,%eax; notl %eax; orl x,%eax; xorl y,%eax // #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) #define ROTATE_LEFT(x, n) roll $n,x // #define FF(a, b, c, d, x, s, ac) { (a) += F (b, c, d) + (x) + (word)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } // #define GG(a, b, c, d, x, s, ac) { (a) += G (b, c, d) + (x) + (word)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } // #define HH(a, b, c, d, x, s, ac) { (a) += H (b, c, d) + (x) + (word)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } // #define II(a, b, c, d, x, s, ac) { (a) += I (b, c, d) + (x) + (word)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } #define FF(a, b, c, d, x, s, ac) addl x, a; addl $ac,a; F (b, c, d); addl %eax,a; roll $s,a; addl b,a #define GG(a, b, c, d, x, s, ac) addl x, a; addl $ac,a; G (b, c, d); addl %eax,a; roll $s,a; addl b,a #define HH(a, b, c, d, x, s, ac) addl x, a; addl $ac,a; H (b, c, d); addl %eax,a; roll $s,a; addl b,a #define II(a, b, c, d, x, s, ac) addl x, a; addl $ac,a; I (b, c, d); addl %eax,a; roll $s,a; addl b,a // // x is ecx // word a = state [0]; // a is edx // word b = state [1]; // b is esi // word c = state [2]; // c is edi // word d = state [3]; // d is ebp #define X(n) 4*(n)(%ecx) #define X0 (%ecx) #define a %edx #define b %esi #define c %edi #define d %ebp /* MD5 basic transformation: Transforms state based on data block */ // void __MD5Transform ( word state[4], const word* x, size_t repeat ) .text .type __MD5Transform, @function .align 32 .global __MD5Transform .align 32 .Lrepeat: /* Round 1 */ FF (a, b, c, d, X0 , S11, 0xd76aa478); /* 1 */ FF (d, a, b, c, X( 1), S12, 0xe8c7b756); /* 2 */ FF (c, d, a, b, X( 2), S13, 0x242070db); /* 3 */ FF (b, c, d, a, X( 3), S14, 0xc1bdceee); /* 4 */ FF (a, b, c, d, X( 4), S11, 0xf57c0faf); /* 5 */ FF (d, a, b, c, X( 5), S12, 0x4787c62a); /* 6 */ FF (c, d, a, b, X( 6), S13, 0xa8304613); /* 7 */ FF (b, c, d, a, X( 7), S14, 0xfd469501); /* 8 */ FF (a, b, c, d, X( 8), S11, 0x698098d8); /* 9 */ FF (d, a, b, c, X( 9), S12, 0x8b44f7af); /* 10 */ FF (c, d, a, b, X(10), S13, 0xffff5bb1); /* 11 */ FF (b, c, d, a, X(11), S14, 0x895cd7be); /* 12 */ FF (a, b, c, d, X(12), S11, 0x6b901122); /* 13 */ FF (d, a, b, c, X(13), S12, 0xfd987193); /* 14 */ FF (c, d, a, b, X(14), S13, 0xa679438e); /* 15 */ FF (b, c, d, a, X(15), S14, 0x49b40821); /* 16 */ /* Round 2 */ GG (a, b, c, d, X( 1), S21, 0xf61e2562); /* 17 */ GG (d, a, b, c, X( 6), S22, 0xc040b340); /* 18 */ GG (c, d, a, b, X(11), S23, 0x265e5a51); /* 19 */ GG (b, c, d, a, X0 , S24, 0xe9b6c7aa); /* 20 */ GG (a, b, c, d, X( 5), S21, 0xd62f105d); /* 21 */ GG (d, a, b, c, X(10), S22, 0x02441453); /* 22 */ GG (c, d, a, b, X(15), S23, 0xd8a1e681); /* 23 */ GG (b, c, d, a, X( 4), S24, 0xe7d3fbc8); /* 24 */ GG (a, b, c, d, X( 9), S21, 0x21e1cde6); /* 25 */ GG (d, a, b, c, X(14), S22, 0xc33707d6); /* 26 */ GG (c, d, a, b, X( 3), S23, 0xf4d50d87); /* 27 */ GG (b, c, d, a, X( 8), S24, 0x455a14ed); /* 28 */ GG (a, b, c, d, X(13), S21, 0xa9e3e905); /* 29 */ GG (d, a, b, c, X( 2), S22, 0xfcefa3f8); /* 30 */ GG (c, d, a, b, X( 7), S23, 0x676f02d9); /* 31 */ GG (b, c, d, a, X(12), S24, 0x8d2a4c8a); /* 32 */ /* Round 3 */ HH (a, b, c, d, X( 5), S31, 0xfffa3942); /* 33 */ HH (d, a, b, c, X( 8), S32, 0x8771f681); /* 34 */ HH (c, d, a, b, X(11), S33, 0x6d9d6122); /* 35 */ HH (b, c, d, a, X(14), S34, 0xfde5380c); /* 36 */ HH (a, b, c, d, X( 1), S31, 0xa4beea44); /* 37 */ HH (d, a, b, c, X( 4), S32, 0x4bdecfa9); /* 38 */ HH (c, d, a, b, X( 7), S33, 0xf6bb4b60); /* 39 */ HH (b, c, d, a, X(10), S34, 0xbebfbc70); /* 40 */ HH (a, b, c, d, X(13), S31, 0x289b7ec6); /* 41 */ HH (d, a, b, c, X0 , S32, 0xeaa127fa); /* 42 */ HH (c, d, a, b, X( 3), S33, 0xd4ef3085); /* 43 */ HH (b, c, d, a, X( 6), S34, 0x04881d05); /* 44 */ HH (a, b, c, d, X( 9), S31, 0xd9d4d039); /* 45 */ HH (d, a, b, c, X(12), S32, 0xe6db99e5); /* 46 */ HH (c, d, a, b, X(15), S33, 0x1fa27cf8); /* 47 */ HH (b, c, d, a, X( 2), S34, 0xc4ac5665); /* 48 */ /* Round 4 */ II (a, b, c, d, X0 , S41, 0xf4292244); /* 49 */ II (d, a, b, c, X( 7), S42, 0x432aff97); /* 50 */ II (c, d, a, b, X(14), S43, 0xab9423a7); /* 51 */ II (b, c, d, a, X( 5), S44, 0xfc93a039); /* 52 */ II (a, b, c, d, X(12), S41, 0x655b59c3); /* 53 */ II (d, a, b, c, X( 3), S42, 0x8f0ccc92); /* 54 */ II (c, d, a, b, X(10), S43, 0xffeff47d); /* 55 */ II (b, c, d, a, X( 1), S44, 0x85845dd1); /* 56 */ II (a, b, c, d, X( 8), S41, 0x6fa87e4f); /* 57 */ II (d, a, b, c, X(15), S42, 0xfe2ce6e0); /* 58 */ II (c, d, a, b, X( 6), S43, 0xa3014314); /* 59 */ II (b, c, d, a, X(13), S44, 0x4e0811a1); /* 60 */ II (a, b, c, d, X( 4), S41, 0xf7537e82); /* 61 */ II (d, a, b, c, X(11), S42, 0xbd3af235); /* 62 */ II (c, d, a, b, X( 2), S43, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, X( 9), S44, 0xeb86d391); /* 64 */ // state [0] += a; // state [1] += b; // state [2] += c; // state [3] += d; addl $64,%ecx movl 4+32(%esp),%eax // state addl (%eax),a addl 4(%eax),b addl 8(%eax),c addl 12(%eax),d movl a, (%eax) movl b, 4(%eax) movl c, 8(%eax) movl d,12(%eax) .Lstart: decl 12+32(%esp) jns .Lrepeat popal ret __MD5Transform: __MD5TransformLocal: pushal movl 8+32(%esp),%ecx // x movl 4+32(%esp),%eax // state movl (%eax),a movl 4(%eax),b movl 8(%eax),c movl 12(%eax),d jmp .Lstart .Lende: .size __MD5Transform, .Lende-__MD5Transform .type MD5Init,@function .global MD5Init MD5Init: movl 4(%esp), %ecx xorl %eax,%eax movl $0x67452301, (%ecx) movl $0xefcdab89, 4(%ecx) movl $0x98badcfe, 8(%ecx) movl $0x10325476, 12(%ecx) movl %eax, 16(%ecx) movl %eax, 20(%ecx) ret .global MD5Update .type MD5Update,@function // void MD5Update ( MD5_CTX* context, const byte* input, size_t inputBytes ) #define CONTEXT 4+32(%esp) #define INPUT 8+32(%esp) #define INPUTBYTES 12+32(%esp) #define COUNT 16(%ebx) #define BUFFER 24(%ebx) MD5Update: pushal cld movl CONTEXT, %ebx // ByteIndex = (context->count[0] >> 3) & 0x3F; movl COUNT, %ebp shrl $3, %ebp andl $63,%ebp // ebp = ByteIndex // if ( (context->count[0] += inputBytes << 3 ) < (inputBytes << 3) ) // context->count[1]++; // context->count[1] += inputBytes >> (32-3); movl $8, %eax mull INPUTBYTES addl %eax, 0+COUNT adcl %edx, 4+COUNT // partLen = 64 - ByteIndex; movl $64, %eax subl %ebp, %eax // eax = partLen // i = 0; // if ( partLen <= inputBytes ) { xorl %ecx,%ecx // ecx = i cmpl INPUTBYTES, %eax ja .Lende2 // memcpy ( context->buffer + ByteIndex, input, partLen ); leal 24(%ebx,%ebp,1), %edi movl INPUT, %esi movl %eax, %ecx rep movsb // MD5Transform ( context->state, context->buffer, 1 ); pushl $1 leal BUFFER, %ecx pushl %ecx push %ebx call __MD5TransformLocal // len = (inputBytes - partLen) / 64; movl 12+INPUTBYTES, %ecx subl %eax, %ecx shrl $6, %ecx // MD5Transform ( context->state, input+partLen, len ); pushl %ecx pushl %esi pushl %ebx call __MD5TransformLocal addl $24,%esp // i = partLen + 64 * len; // ByteIndex = 0; shll $6, %ecx addl %eax, %ecx xorl %ebp, %ebp .Lende2: // } // memcpy ( context->buffer + ByteIndex, input + i, inputBytes - i ); movl INPUT, %esi addl %ecx, %esi negl %ecx addl INPUTBYTES, %ecx leal 24(%ebx,%ebp,1), %edi rep movsb popal ret dietlibc-0.33~cvs20120325/i386/memccpy.S010064400000000000000000000012041173363226000141500ustar00/* Copyright (C) 2002 Thomas M. Ogrisegg This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. memccpy.S i386 assembler implementation of memccpy(3) */ .text .global memccpy .type memccpy,@function memccpy: pushl %esi pushl %edi movl %esp, %ecx movl 0x0c(%ecx), %edi movl 0x10(%ecx), %esi movl 0x14(%ecx), %edx movl 0x18(%ecx), %ecx cld jecxz .Lerr .Lloop: lodsb stosb cmp %al, %dl jz .Lout decl %ecx jnz .Lloop .Lerr: xorl %edi, %edi .Lout: movl %edi, %eax popl %edi popl %esi ret .Lende: .size memccpy,.Lende-memccpy dietlibc-0.33~cvs20120325/i386/memchr.S010064400000000000000000000021151173363226000137700ustar00.text .global memchr .type memchr,@function memchr: push %edi mov 8(%esp),%edi /* edi = ptr */ movzxb 12(%esp),%eax mov 16(%esp),%ecx imul $0x01010101,%eax /* eax = simd vector, 8 x ch */ push %esi push %ebx jecxz .Lnull add %edi,%ecx /* ecx == max ptr */ 1: /* compare byte-wise until alignment */ test $3,%edi jz 1f cmp %al,(%edi) jz .Lfound inc %edi jmp 1b 1: /* compare word-wise */ cmp %edi,%ecx jb .Lnull mov (%edi),%edx xor %eax,%edx /* in the input vector, change the byte we want to 0 */ mov %edx,%ebx sub $0x01010101,%ebx not %edx and %ebx,%edx shr $7,%edx and $0x01010101,%edx /* this sequence did !! to every byte in edx */ jnz 1f add $4,%edi jmp 1b 1: /* there is a nonzero byte in %edx, try lower half */ test %dx,%dx jnz 1f /* not in lower half, swap halves */ shr $16,%edx add $2,%edi 1: test %dl,%dl jnz 1f /* no match in lower byte */ mov %dh,%dl inc %edi 1: .Lfound: cmp %edi,%ecx jbe .Lnull mov %edi,%eax pop %ebx pop %esi pop %edi ret .Lnull: xor %eax,%eax pop %ebx pop %esi pop %edi ret .Lhere: .size memchr,.Lhere-memchr dietlibc-0.33~cvs20120325/i386/memcmp.S010064400000000000000000000004431173363226000137750ustar00.text .global memcmp .type memcmp,function memcmp: pushl %esi pushl %edi xorl %eax,%eax movl %esp,%ecx movl 12(%ecx),%esi movl 16(%ecx),%edi movl 20(%ecx),%ecx jecxz .Lout cld rep cmpsb jz .Lout sbbl %eax,%eax orl $1,%eax .Lout: popl %edi popl %esi ret .size memcmp,.-memcmp dietlibc-0.33~cvs20120325/i386/memcpy.S010064400000000000000000000003171173363226000140110ustar00.text .align 0 .global memcpy .type memcpy,@function memcpy: pushl %esi pushl %edi movl 12(%esp),%edi movl 16(%esp),%esi movl 20(%esp),%ecx movl %edi, %eax cld rep movsb popl %edi popl %esi ret dietlibc-0.33~cvs20120325/i386/memset.S010064400000000000000000000002741173363226000140130ustar00.text .align 0 .global memset .type memset,@function memset: pushl %edi movl 8(%esp),%edi movl 12(%esp),%eax movl 16(%esp),%ecx cld pushl %edi rep stosb popl %eax popl %edi ret dietlibc-0.33~cvs20120325/i386/mmap.S010064400000000000000000000003021173363226000134430ustar00#include "syscalls.h" .text .global mmap .type mmap,@function mmap: mov $__NR_mmap,%al lea 0x4(%esp,1),%edx push %edx call __unified_syscall pop %ecx ret .Lende3: .size mmap,.Lende3-mmap dietlibc-0.33~cvs20120325/i386/mmap64.S010064400000000000000000000020471173363226000136250ustar00#include #include #include #ifdef __DYN_LIB #ifndef WANT_THREAD_SAFE #define WANT_THREAD_SAFE #endif #endif .text .global mmap64 .type mmap64,@function mmap64: /* man is this ugly! */ push %ebp push %edi push %esi push %ebx movl %esp, %edi movl 0x28(%edi), %eax movl 0x2c(%edi), %edx testl $0xfff, %eax /* offset in pages */ jnz .Leinval shrdl $12, %edx, %eax shrl $12, %edx jnz .Leinval movl %eax, %ebp movl 0x14(%edi),%ebx movl 0x18(%edi),%ecx movl 0x1c(%edi),%edx movl 0x20(%edi),%esi movl 0x24(%edi),%edi movl $__NR_mmap2,%eax int $0x80 cmp $-124,%eax jbe .Lnoerror neg %eax .Lerror: #ifdef WANT_THREAD_SAFE movl %eax,%ebx #ifdef __DYN_LIB call __errno_location@PLT #else call __errno_location #endif movl %ebx,(%eax) orl $-1,%eax #else mov %eax,errno sbb %eax,%eax # eax = eax - eax - CY = -1 #endif .Lnoerror: pop %ebx pop %esi pop %edi pop %ebp ret .Leinval: movl $EINVAL,%eax jmp .Lerror .Lende2: .size mmap64,.Lende2-mmap64 dietlibc-0.33~cvs20120325/i386/poly.S010064400000000000000000000004671173363226000135100ustar00 .text .global __poly .type __poly,@function # # double __poly ( double x, int n, const double* c ); # __poly: movl 16(%esp),%eax movl 12(%esp),%ecx leal (%eax,%ecx,8),%eax fldl 4(%esp) fldz .Lloop: fmul %st(1),%st(0) faddl (%eax) addl $-8,%eax decl %ecx jns .Lloop fstp %st(1) ret dietlibc-0.33~cvs20120325/i386/pow.S010064400000000000000000000022261173363226000133250ustar00#include "PIC.h" .text .global pow .type pow,@function # pow(x,y) .global powf,pow,powl .type powf,@function .type pow,@function .type powl,@function powf: flds 4(%esp) # x flds 8(%esp) # y jmp .L__pow powl: fldt 4(%esp) fldt 16(%esp) jmp .L__pow pow: fldl 4(%esp) fldl 12(%esp) # x^y; st(0)=y, st(1)=x .L__pow: ftst # y = 0 ? fstsw %ax fld1 # st(0)=1, st(1)=y, st(2)=x sahf jz 1f # return 1 fcomp %st(1) # y = 1 ? fstsw %ax fxch # st(0)=x, st(1)=y sahf jz 1f # return x ftst # x = 0 ? fstsw %ax sahf jz 1f jnc .Lfinpow # x > 0 fxch # st(0)=y, st(1)=x fld %st(0) # st(0)=y, st(1)=y, st(2)=x frndint # st(0)=int(y) fcomp %st(1) # y = int(y)? fstsw %ax fxch sahf jnz .Lfinpow # fyl2x -> st(0) = NaN # y even or odd ? fld1 fadd %st(0) # st(0) = 2 fdivr %st(2),%st(0) # st(0)=st(2)/2 frndint fadd %st(0),%st(0) fcomp %st(2) # st(0) = x, st(1) = y fstsw %ax fchs # st(0) = -x sahf jz .Lfinpow # y even call .Lfinpow # y odd fchs 1: ret .Lfinpow: fyl2x #ifdef __DYN_LIB PIC_SAVE PIC_INIT jmp __finexp@PLT #else jmp __finexp #endif .Lende: .size pow,.Lende-pow .size powf,.Lende-powf .size powl,.Lende-powl dietlibc-0.33~cvs20120325/i386/recv.S010064400000000000000000000001051173363226000134510ustar00#include #include __socketcall(recv,RECV) dietlibc-0.33~cvs20120325/i386/recvfrom.S010064400000000000000000000001151173363226000143360ustar00#include #include __socketcall(recvfrom,RECVFROM) dietlibc-0.33~cvs20120325/i386/recvmsg.S010064400000000000000000000001131173363226000141570ustar00#include #include __socketcall(recvmsg,RECVMSG) dietlibc-0.33~cvs20120325/i386/rint.S010064400000000000000000000004521173363226000134730ustar00.text .global rintf,rint,rintl .type rintf,@function .type rint,@function .type rintl,@function rintf: flds 4(%esp) frndint ret rint: fldl 4(%esp) frndint ret rintl: fldt 4(%esp) frndint ret .Lende: .size rint,.Lende-rint .size rintl,.Lende-rintl .size rintf,.Lende-rintf dietlibc-0.33~cvs20120325/i386/select.S010064400000000000000000000001051173363226000137710ustar00#include "syscalls.h" syscall_weak(_newselect,select,__libc_select) dietlibc-0.33~cvs20120325/i386/send.S010064400000000000000000000001051173363226000134430ustar00#include #include __socketcall(send,SEND) dietlibc-0.33~cvs20120325/i386/sendmsg.S010064400000000000000000000001131173363226000141510ustar00#include #include __socketcall(sendmsg,SENDMSG) dietlibc-0.33~cvs20120325/i386/sendto.S010064400000000000000000000001111173363226000140030ustar00#include #include __socketcall(sendto,SENDTO) dietlibc-0.33~cvs20120325/i386/setjmp.S010064400000000000000000000017511173363226000140240ustar00#include .text .weak setjmp .type setjmp,@function setjmp: .globl __setjmp .type __setjmp,@function __setjmp: movl 0(%esp), %ecx /* Save PC we are returning to now. */ leal 4(%esp), %edx /* Save SP as it will be after we return. */ movl (%edx), %eax pushl $0 pushl %eax call __sigsetjmp_internal add $8,%esp ret .globl __sigsetjmp .type __sigsetjmp,@function __sigsetjmp: movl 0(%esp), %ecx /* Save PC we are returning to now. */ leal 4(%esp), %edx /* Save SP as it will be after we return. */ movl (%edx), %eax __sigsetjmp_internal: /* Save registers. */ movl %ebx, (JB_BX*4)(%eax) movl %esi, (JB_SI*4)(%eax) movl %edi, (JB_DI*4)(%eax) movl %ebp, (JB_BP*4)(%eax) movl %edx, (JB_SP*4)(%eax) movl %ecx, (JB_PC*4)(%eax) /* Make a tail call to __sigjmp_save; it takes the same args. */ #ifdef PIC call 1f addl $_GLOBAL_OFFSET_TABLE_, %ecx jmp *__sigjmp_save@GOT(%ecx) 1: movl (%esp), %ecx ret #else jmp __sigjmp_save #endif .size __sigsetjmp,.-__sigsetjmp; dietlibc-0.33~cvs20120325/i386/setsockopt.S010064400000000000000000000001211173363226000147060ustar00#include #include __socketcall(setsockopt,SETSOCKOPT) dietlibc-0.33~cvs20120325/i386/shutdown.S010064400000000000000000000001151173363226000143660ustar00#include #include __socketcall(shutdown,SHUTDOWN) dietlibc-0.33~cvs20120325/i386/sigaction.c010064400000000000000000000016141173363226000145200ustar00#include #include #include "i386/syscalls.h" int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, long nr); void __restore_rt(void); void __restore(void); int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { struct sigaction *newact = (struct sigaction *)act; if (act) { newact = alloca(sizeof(*newact)); newact->sa_handler = act->sa_handler; newact->sa_flags = act->sa_flags | SA_RESTORER; newact->sa_restorer = (act->sa_flags & SA_SIGINFO) ? &__restore_rt : &__restore; newact->sa_mask = act->sa_mask; } return __rt_sigaction(signum, newact, oldact, _NSIG/8); } int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) __attribute__((weak,alias("__libc_sigaction"))); dietlibc-0.33~cvs20120325/i386/sin.S010064400000000000000000000006231173363226000133100ustar00 .text .global sinf,sin,sinl .type sinf,@function .type sin,@function .type sinl,@function sinf: flds 4(%esp) jmp 1f sin: fldl 4(%esp) 1: fsin fnstsw %ax testb $0x04, %ah je 3f fldpi fadd %st fxch %st(1) 2: fprem1 fnstsw %ax testb $0x04, %ah jne 2b fstp %st(1) fsin 3: ret sinl: fldt 4(%esp) jmp 1b .ende: .size sin,.ende-sin .size sinf,.ende-sinf .size sinl,.ende-sinl dietlibc-0.33~cvs20120325/i386/sincos.S010064400000000000000000000021021173363226000140070ustar00#include "PIC.h" .text .global sincosf,sincos,sincosl .type sincosf,@function .type sincos,@function .type sincosl,@function # void sincos ( double x, double* sinx, double* cosx ); sincosf: flds 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __fmod2pi@PLT PIC_RESTORE #else call __fmod2pi #endif movl 12(%esp),%eax movl 8(%esp),%ecx fsincos fstps (%eax) fstps (%ecx) ret sincos: fldl 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __fmod2pi@PLT PIC_RESTORE #else call __fmod2pi #endif movl 16(%esp),%eax movl 12(%esp),%ecx fsincos fstpl (%eax) fstpl (%ecx) ret sincosl: fldt 4(%esp) #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __fmod2pi@PLT PIC_RESTORE #else call __fmod2pi #endif movl 20(%esp),%eax movl 16(%esp),%ecx fsincos fstpt (%eax) fstpt (%ecx) ret .ende: .size sincos,.ende-sincos .size sincosf,.ende-sincosf .size sincosl,.ende-sincosl dietlibc-0.33~cvs20120325/i386/sinh.S010064400000000000000000000011011173363226000134500ustar00#include "PIC.h" .text .global sinhf,sinh,sinhl .type sinhf,@function .type sinh,@function .type sinhl,@function sinhf: fldl2e fmuls 4(%esp) jmp finsinh sinh: fldl2e fmull 4(%esp) finsinh: #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __finexp@PLT PIC_RESTORE #else call __finexp #endif fld1 fdiv %st(1),%st(0) # st(0)=1/exp(x), st(1)=exp(x) fsubrp %st(0),%st(1) pushl $0x3f000000 # 1/2 flds (%esp) popl %eax fmulp ret sinhl: fldl2e fldt 4(%esp) fmulp jmp finsinh .Lende: .size sinh,.Lende-sinh .size sinhf,.Lende-sinhf .size sinhl,.Lende-sinhl dietlibc-0.33~cvs20120325/i386/sleep.S010064400000000000000000000012511173363226000136250ustar00#include "PIC.h" .text .global sleep .type sleep,@function sleep: movl 4(%esp),%eax # Argument holen PIC_SAVE # non-PIC: empty line PIC_INIT # non-PIC: empty line pushl $0 # 0 ns pushl %eax # 'x' µs warten movl %esp,%eax pushl %eax # zweimal ein Zeiger auf das Stackobjekt pushl %eax # ptr ptr sec nsec return arg #ifdef __DYN_LIB call nanosleep@PLT #else call nanosleep #endif movl 20(%esp),%eax # 'x' holen subl 8(%esp),%eax # schon abgelaufende Zeit subtrahieren addl $16,%esp PIC_RESTORE # non-PIC: empty line ret dietlibc-0.33~cvs20120325/i386/socket.S010064400000000000000000000001111173363226000137770ustar00#include #include __socketcall(socket,SOCKET) dietlibc-0.33~cvs20120325/i386/socketcall.S010064400000000000000000000004161173363226000146430ustar00#include .text .global socketcall .type socketcall,@function socketcall: leal 4(%esp), %ecx pushl %ecx movzbl %al,%eax pushl %eax movb $__NR_socketcall,%al call __unified_syscall popl %ecx popl %ecx retl .Lende: .size socketcall,.Lende-socketcall dietlibc-0.33~cvs20120325/i386/socketpair.S010064400000000000000000000001211173363226000146540ustar00#include #include __socketcall(socketpair,SOCKETPAIR) dietlibc-0.33~cvs20120325/i386/sqrt.S010064400000000000000000000004401173363226000135050ustar00.text .global sqrtf,sqrt,sqrtl .type sqrtf,@function .type sqrt,@function .type sqrtl,@function sqrtf: flds 4(%esp) fsqrt ret sqrt: fldl 4(%esp) fsqrt ret sqrtl: fldt 4(%esp) fsqrt ret .ende: .size sqrt,.ende-sqrt .size sqrtf,.ende-sqrtf .size sqrtl,.ende-sqrtl dietlibc-0.33~cvs20120325/i386/sqrtl.S010064400000000000000000000002101173363226000136540ustar00.text .type sqrtl,@function .global sqrtl sqrtl: fldt 4(%esp) fsqrt ret .ende: .size sqrtl,.ende-sqrtl dietlibc-0.33~cvs20120325/i386/start.S010064400000000000000000000021641173363226000136560ustar00#include "dietfeatures.h" #include "PIC.h" .text .global _start _start: popl %ecx /* %ecx = argc */ movl %esp,%eax /* %eax = argv */ pushl %ecx leal 4(%eax,%ecx,4),%esi /* %esi = envp = (4*ecx)+%eax+4 */ #ifdef WANT_DYNAMIC /* in %edx we have the ld.so dynamic _fini ( register this if non null ) */ push %edx #endif pushl %esi pushl %eax pushl %ecx PIC_INIT /* non-PIC: this is an empty line */ PUT_VAR %esi, environ, %ecx /* non-PIC: movl %esi,environ */ #ifdef WANT_SYSENTER /* skip environment, scan for NULL */ 1: lodsl testl %eax,%eax jnz 1b /* The ELF auxvec follows the environment, consists of key/value pairs. We are looking for key 32, which stands for the vsyscall page */ 1: lodsl testl %eax,%eax jz 1f cmpl $32,%eax lodsl jne 1b PUT_VAR %eax, __vsyscall, %edx 1: #endif #ifdef PROFILING pushl $_etext pushl $.text call monitor addl $0x8, %esp #endif #ifdef WANT_DYNAMIC call _dyn_start #else call CALL_IN_STARTCODE #endif #ifdef PROFILING pushl %eax call _stop_monitor popl %eax #endif pushl %eax call exit hlt /* die now ! will ya ... */ .Lstart: .size _start,.Lstart-_start dietlibc-0.33~cvs20120325/i386/stpcpy.S010064400000000000000000000004141173363226000140370ustar00.text .global stpcpy .type stpcpy,@function stpcpy: pushl %edi pushl %esi movl 0xc(%esp), %edi movl 0x10(%esp), %esi cld .Lcopy: lodsb stosb testb %al, %al jnz .Lcopy movl %edi, %eax decl %eax popl %esi popl %edi ret .Lende: .size stpcpy,.Lende-stpcpy dietlibc-0.33~cvs20120325/i386/strcasecmp.S010064400000000000000000000006751173363226000146720ustar00.text .global strcasecmp .type strcasecmp,@function strcasecmp: pushl %esi movl 0x8(%esp), %esi movl 0xc(%esp), %edx xorl %eax, %eax xorl %ecx, %ecx cld .Lloop: lodsb movb (%edx), %cl incl %edx or %al, %al jz .Lfinifirst cmp $'A', %al jnge .Lcmp cmp $'z', %al jg .Lcmp or $0x20, %al or $0x20, %cl .Lcmp: subl %ecx, %eax jz .Lloop .Lret: popl %esi ret .Lfinifirst: subl %ecx, %eax jmp .Lret .size strcasecmp,.-strcasecmp dietlibc-0.33~cvs20120325/i386/strcat.S010064400000000000000000000004661173363226000140240ustar00.text .align 0 .global strcat .type strcat,@function strcat: pushl %edi pushl %esi movl 12(%esp), %edi movl 16(%esp), %esi pushl %edi cld xorl %eax, %eax xorl %ecx, %ecx decl %ecx repne scasb decl %edi .Lloop: lodsb stosb testb %al, %al jnz .Lloop popl %eax popl %esi popl %edi ret dietlibc-0.33~cvs20120325/i386/strchr.S010064400000000000000000000004151173363226000140230ustar00 .text .type strchr,@function .global strchr .weak index .type index,@function index: strchr: movl 4(%esp),%ecx movb 8(%esp),%dl .Lloop: movb (%ecx),%al cmpb %al,%dl jz .Lfound incl %ecx testb %al,%al jnz .Lloop xorl %ecx,%ecx .Lfound: movl %ecx,%eax ret dietlibc-0.33~cvs20120325/i386/strcmp.S010064400000000000000000000013161173363226000140270ustar00.text .global strcmp .type strcmp,@function .weak strcoll .type strcoll,@function #ifdef HIGH_PERFORMANCE .align 16 #endif .Ldiff: movzbl (%edx), %ecx subl %ecx, %eax # (unsigned char)*p - (unsigned char)*q, so wie die Original libc ret # und ohne Überlaufprobleme: # (int) ((signed char)c - (signed char)d) != (int)(signed char) ((unsigned char)c - (unsigned char)d) # c = 'ä', d = 'e': left expression: -129, right expression: 127 strcoll: strcmp: movl 4(%esp), %ecx movl 8(%esp), %edx xorl %eax, %eax .Lloop: # Schleifenanfang liegt genau auf Modulanfang + 0x10, damit alignbar movb (%ecx), %al cmpb (%edx), %al jnz .Ldiff incl %edx incl %ecx testb %al, %al jnz .Lloop ret dietlibc-0.33~cvs20120325/i386/strcpy.S010064400000000000000000000003671173363226000140500ustar00 .text .align 0 .global strcpy .type strcpy,@function strcpy: pushl %esi pushl %edi movl 12(%esp), %edx movl 16(%esp), %esi movl %edx, %edi cld .Lloop: lodsb stosb orb %al, %al jnz .Lloop popl %edi popl %esi movl %edx,%eax ret dietlibc-0.33~cvs20120325/i386/strlen.S010064400000000000000000000004321173363226000140240ustar00 .text .type strlen,@function .global strlen strlen: movl 4(%esp),%ecx xorl %eax,%eax jecxz .Lnull decl %eax .Llbl: incl %eax cmpb $0,(%ecx, %eax) jne .Llbl .Lnull: ret .Lende: .size strlen,.Lende-strlen dietlibc-0.33~cvs20120325/i386/strncmp.S010064400000000000000000000007111173363226000142030ustar00.text .global strncmp .type strncmp,function strncmp: pushl %esi pushl %edi movl %esp,%ecx movl 12(%ecx),%esi movl 16(%ecx),%edi movl 20(%ecx),%ecx jecxz .Lequal .Lloop: movzbl (%esi),%eax movzbl (%edi),%edx incl %esi incl %edi /* !equal ? */ subl %edx,%eax jnz .Lout /* end of c-string ? */ test %edx,%edx jz .Lequal /* do loop */ decl %ecx jnz .Lloop .Lequal: xorl %eax,%eax .Lout: popl %edi popl %esi ret .size strncmp,.-strncmp dietlibc-0.33~cvs20120325/i386/strncpy.S010064400000000000000000000013331173363226000142200ustar00/* Copyright (C) 2002 Thomas M. Ogrisegg This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. strncpy.S i386 assembler implementation of strncpy(3) */ #include "dietfeatures.h" .text .globl strncpy .type strncpy,@function strncpy: pushl %esi pushl %edi movl %esp, %ecx movl 0x0c(%ecx), %edi movl 0x10(%ecx), %esi movl 0x14(%ecx), %ecx movl %edi, %edx cld .Lloop: dec %ecx #ifdef WANT_NON_COMPLIANT_STRNCAT jz .Lout #else js .Lout #endif lodsb stosb or %al, %al jnz .Lloop #ifdef WANT_FULL_POSIX_COMPAT repnz stosb #endif .Lout: #ifdef WANT_NON_COMPLIANT_STRNCAT movb $0,(%edi) #endif movl %edx, %eax popl %edi popl %esi ret dietlibc-0.33~cvs20120325/i386/strrchr.S010064400000000000000000000003611173363226000142050ustar00.text .globl strrchr .type strrchr,@function strrchr: movl 0x4(%esp), %edx movb 0x8(%esp), %cl xorl %eax, %eax .Lloop: cmpb %cl, (%edx) jnz .Ltest0 movl %edx, %eax .Ltest0: cmpb $0,(%edx) jz .Lret incl %edx jmp .Lloop .Lret: ret dietlibc-0.33~cvs20120325/i386/syscalls.h010064400000000000000000000244431173363226000144070ustar00 #define __NR_exit 1 #define __NR_fork 2 #define __NR_read 3 #define __NR_write 4 #define __NR_open 5 #define __NR_close 6 #define __NR_waitpid 7 #define __NR_creat 8 #define __NR_link 9 #define __NR_unlink 10 #define __NR_execve 11 #define __NR_chdir 12 #define __NR_time 13 #define __NR_mknod 14 #define __NR_chmod 15 #define __NR_lchown 16 #define __NR_break 17 #define __NR_oldstat 18 #define __NR_lseek 19 #define __NR_getpid 20 #define __NR_mount 21 #define __NR_umount 22 #define __NR_setuid 23 #define __NR_getuid 24 #define __NR_stime 25 #define __NR_ptrace 26 #define __NR_alarm 27 #define __NR_oldfstat 28 #define __NR_pause 29 #define __NR_utime 30 #define __NR_stty 31 #define __NR_gtty 32 #define __NR_access 33 #define __NR_nice 34 #define __NR_ftime 35 #define __NR_sync 36 #define __NR_kill 37 #define __NR_rename 38 #define __NR_mkdir 39 #define __NR_rmdir 40 #define __NR_dup 41 #define __NR_pipe 42 #define __NR_times 43 #define __NR_prof 44 #define __NR_brk 45 #define __NR_setgid 46 #define __NR_getgid 47 #define __NR_signal 48 #define __NR_geteuid 49 #define __NR_getegid 50 #define __NR_acct 51 #define __NR_umount2 52 #define __NR_lock 53 #define __NR_ioctl 54 #define __NR_fcntl 55 #define __NR_mpx 56 #define __NR_setpgid 57 #define __NR_ulimit 58 #define __NR_oldolduname 59 #define __NR_umask 60 #define __NR_chroot 61 #define __NR_ustat 62 #define __NR_dup2 63 #define __NR_getppid 64 #define __NR_getpgrp 65 #define __NR_setsid 66 #define __NR_sigaction 67 #define __NR_sgetmask 68 #define __NR_ssetmask 69 #define __NR_setreuid 70 #define __NR_setregid 71 #define __NR_sigsuspend 72 #define __NR_sigpending 73 #define __NR_sethostname 74 #define __NR_setrlimit 75 #define __NR_getrlimit 76 /* Back compatible 2Gig limited rlimit */ #define __NR_getrusage 77 #define __NR_gettimeofday 78 #define __NR_settimeofday 79 #define __NR_getgroups 80 #define __NR_setgroups 81 #define __NR_select 82 #define __NR_symlink 83 #define __NR_oldlstat 84 #define __NR_readlink 85 #define __NR_uselib 86 #define __NR_swapon 87 #define __NR_reboot 88 #define __NR_readdir 89 #define __NR_mmap 90 #define __NR_munmap 91 #define __NR_truncate 92 #define __NR_ftruncate 93 #define __NR_fchmod 94 #define __NR_fchown 95 #define __NR_getpriority 96 #define __NR_setpriority 97 #define __NR_profil 98 #define __NR_statfs 99 #define __NR_fstatfs 100 #define __NR_ioperm 101 #define __NR_socketcall 102 #define __NR_syslog 103 #define __NR_setitimer 104 #define __NR_getitimer 105 #define __NR_stat 106 #define __NR_lstat 107 #define __NR_fstat 108 #define __NR_olduname 109 #define __NR_iopl 110 #define __NR_vhangup 111 #define __NR_idle 112 #define __NR_vm86old 113 #define __NR_wait4 114 #define __NR_swapoff 115 #define __NR_sysinfo 116 #define __NR_ipc 117 #define __NR_fsync 118 #define __NR_sigreturn 119 #define __NR_clone 120 #define __NR_setdomainname 121 #define __NR_uname 122 #define __NR_modify_ldt 123 #define __NR_adjtimex 124 #define __NR_mprotect 125 #define __NR_sigprocmask 126 #define __NR_create_module 127 #define __NR_init_module 128 #define __NR_delete_module 129 #define __NR_get_kernel_syms 130 #define __NR_quotactl 131 #define __NR_getpgid 132 #define __NR_fchdir 133 #define __NR_bdflush 134 #define __NR_sysfs 135 #define __NR_personality 136 #define __NR_afs_syscall 137 /* Syscall for Andrew File System */ #define __NR_setfsuid 138 #define __NR_setfsgid 139 #define __NR__llseek 140 #define __NR_getdents 141 #define __NR__newselect 142 #define __NR_flock 143 #define __NR_msync 144 #define __NR_readv 145 #define __NR_writev 146 #define __NR_getsid 147 #define __NR_fdatasync 148 #define __NR__sysctl 149 #define __NR_mlock 150 #define __NR_munlock 151 #define __NR_mlockall 152 #define __NR_munlockall 153 #define __NR_sched_setparam 154 #define __NR_sched_getparam 155 #define __NR_sched_setscheduler 156 #define __NR_sched_getscheduler 157 #define __NR_sched_yield 158 #define __NR_sched_get_priority_max 159 #define __NR_sched_get_priority_min 160 #define __NR_sched_rr_get_interval 161 #define __NR_nanosleep 162 #define __NR_mremap 163 #define __NR_setresuid 164 #define __NR_getresuid 165 #define __NR_vm86 166 #define __NR_query_module 167 #define __NR_poll 168 #define __NR_nfsservctl 169 #define __NR_setresgid 170 #define __NR_getresgid 171 #define __NR_prctl 172 #define __NR_rt_sigreturn 173 #define __NR_rt_sigaction 174 #define __NR_rt_sigprocmask 175 #define __NR_rt_sigpending 176 #define __NR_rt_sigtimedwait 177 #define __NR_rt_sigqueueinfo 178 #define __NR_rt_sigsuspend 179 #define __NR_pread 180 #define __NR_pwrite 181 #define __NR_chown 182 #define __NR_getcwd 183 #define __NR_capget 184 #define __NR_capset 185 #define __NR_sigaltstack 186 #define __NR_sendfile 187 #define __NR_getpmsg 188 /* some people actually want streams */ #define __NR_putpmsg 189 /* some people actually want streams */ #define __NR_vfork 190 #define __NR_ugetrlimit 191 /* SuS compliant getrlimit */ #define __NR_mmap2 192 #define __NR_truncate64 193 #define __NR_ftruncate64 194 #define __NR_stat64 195 #define __NR_lstat64 196 #define __NR_fstat64 197 #define __NR_lchown32 198 #define __NR_getuid32 199 #define __NR_getgid32 200 #define __NR_geteuid32 201 #define __NR_getegid32 202 #define __NR_setreuid32 203 #define __NR_setregid32 204 #define __NR_getgroups32 205 #define __NR_setgroups32 206 #define __NR_fchown32 207 #define __NR_setresuid32 208 #define __NR_getresuid32 209 #define __NR_setresgid32 210 #define __NR_getresgid32 211 #define __NR_chown32 212 #define __NR_setuid32 213 #define __NR_setgid32 214 #define __NR_setfsuid32 215 #define __NR_setfsgid32 216 #define __NR_pivot_root 217 #define __NR_mincore 218 #define __NR_madvise 219 #define __NR_madvise1 219 /* delete when C lib stub is removed */ #define __NR_getdents64 220 #define __NR_fcntl64 221 /* 223 is unused */ #define __NR_gettid 224 #define __NR_readahead 225 #define __NR_setxattr 226 #define __NR_lsetxattr 227 #define __NR_fsetxattr 228 #define __NR_getxattr 229 #define __NR_lgetxattr 230 #define __NR_fgetxattr 231 #define __NR_listxattr 232 #define __NR_llistxattr 233 #define __NR_flistxattr 234 #define __NR_removexattr 235 #define __NR_lremovexattr 236 #define __NR_fremovexattr 237 #define __NR_tkill 238 #define __NR_sendfile64 239 #define __NR_futex 240 #define __NR_sched_setaffinity 241 #define __NR_sched_getaffinity 242 #define __NR_set_thread_area 243 #define __NR_get_thread_area 244 #define __NR_io_setup 245 #define __NR_io_destroy 246 #define __NR_io_getevents 247 #define __NR_io_submit 248 #define __NR_io_cancel 249 #define __NR_fadvise64 250 #define __NR_exit_group 252 #define __NR_lookup_dcookie 253 #define __NR_epoll_create 254 #define __NR_epoll_ctl 255 #define __NR_epoll_wait 256 #define __NR_remap_file_pages 257 #define __NR_set_tid_address 258 #define __NR_timer_create 259 #define __NR_timer_settime (__NR_timer_create+1) #define __NR_timer_gettime (__NR_timer_create+2) #define __NR_timer_getoverrun (__NR_timer_create+3) #define __NR_timer_delete (__NR_timer_create+4) #define __NR_clock_settime (__NR_timer_create+5) #define __NR_clock_gettime (__NR_timer_create+6) #define __NR_clock_getres (__NR_timer_create+7) #define __NR_clock_nanosleep (__NR_timer_create+8) #define __NR_statfs64 268 #define __NR_fstatfs64 269 #define __NR_tgkill 270 #define __NR_utimes 271 #define __NR_fadvise64_64 272 #define __NR_vserver 273 #define __NR_mbind 274 #define __NR_get_mempolicy 275 #define __NR_set_mempolicy 276 #define __NR_mq_open 277 #define __NR_mq_unlink (__NR_mq_open+1) #define __NR_mq_timedsend (__NR_mq_open+2) #define __NR_mq_timedreceive (__NR_mq_open+3) #define __NR_mq_notify (__NR_mq_open+4) #define __NR_mq_getsetattr (__NR_mq_open+5) #define __NR_sys_kexec_load 283 #define __NR_waitid 284 /* #define __NR_sys_setaltroot 285 */ #define __NR_add_key 286 #define __NR_request_key 287 #define __NR_keyctl 288 #define __NR_ioprio_set 289 #define __NR_ioprio_get 290 #define __NR_inotify_init 291 #define __NR_inotify_add_watch 292 #define __NR_inotify_rm_watch 293 #define __NR_migrate_pages 294 #define __NR_openat 295 #define __NR_mkdirat 296 #define __NR_mknodat 297 #define __NR_fchownat 298 #define __NR_futimesat 299 #define __NR_fstatat64 300 #define __NR_unlinkat 301 #define __NR_renameat 302 #define __NR_linkat 303 #define __NR_symlinkat 304 #define __NR_readlinkat 305 #define __NR_fchmodat 306 #define __NR_faccessat 307 #define __NR_pselect6 308 #define __NR_ppoll 309 #define __NR_unshare 310 #define __NR_set_robust_list 311 #define __NR_get_robust_list 312 #define __NR_splice 313 #define __NR_sync_file_range 314 #define __NR_tee 315 #define __NR_vmsplice 316 #define __NR_move_pages 317 #define __NR_getcpu 318 #define __NR_epoll_pwait 319 #define __NR_utimensat 320 #define __NR_signalfd 321 #define __NR_timerfd 322 #define __NR_eventfd 323 #define __NR_fallocate 324 #define __NR_timerfd_settime 325 #define __NR_timerfd_gettime 326 #define __NR_signalfd4 327 #define __NR_eventfd2 328 #define __NR_epoll_create1 329 #define __NR_dup3 330 #define __NR_pipe2 331 #define __NR_inotify_init1 332 #define __NR_preadv 333 #define __NR_pwritev 334 #define __NR_rt_tgsigqueueinfo 335 #define __NR_perf_event_open 336 #define __NR_recvmmsg 337 #define __NR_fanotify_init 338 #define __NR_fanotify_mark 339 #define __NR_prlimit64 340 #define syscall_weak(name,wsym,sym) \ .text; \ .type wsym,@function; \ .weak wsym; \ wsym: ; \ .type sym,@function; \ .global sym; \ sym: \ movb $__NR_##name,%al; \ jmp __unified_syscall; \ .Lend##sym: ; \ .size sym,.Lend##sym-sym #define syscall(name,sym) \ .text; \ .type sym,@function; \ .global sym; \ sym: \ .ifle __NR_##name-255; \ movb $__NR_##name,%al; \ jmp __unified_syscall; \ .else; \ movw $__NR_##name,%ax; \ jmp __unified_syscall_256; \ .endif; \ .Lend##sym: ; \ .size sym,.Lend##sym-sym #ifndef __PIC__ #define __socketcall(name,NAME) \ .text; \ .type name,@function; \ .weak name; \ name: ; \ .type __libc_##name,@function; \ .global __libc_##name; \ __libc_##name: ; \ movb $SYS_##NAME,%al; \ jmp socketcall; \ .Lend##name:; \ .size name,.Lend##name-name #else #define __socketcall(name,NAME) #endif dietlibc-0.33~cvs20120325/i386/tan.S010064400000000000000000000007101173363226000132760ustar00#include "PIC.h" .text .global tanf,tan,tanl .type tanf,@function .type tan,@function .type tanl,@function tanf: flds 4(%esp) jmp __tan tan: fldl 4(%esp) __tan: #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __fmod2pi@PLT PIC_RESTORE #else call __fmod2pi #endif fsincos fdivrp ret tanl: fldt 4(%esp) jmp __tan .ende: .size tan,.ende-tan .size tanf,.ende-tanf .size tanl,.ende-tanl dietlibc-0.33~cvs20120325/i386/tanh.S010064400000000000000000000012361173363226000134520ustar00#include "PIC.h" .text .global tanhf,tanh,tanhl .type tanhf,@function .type tanh,@function .type tanhl,@function tanhf: fldl2e fmuls 4(%esp) jmp fintanh tanh: fldl2e fmull 4(%esp) fintanh: #ifdef __DYN_LIB PIC_SAVE PIC_INIT call __finexp@PLT PIC_RESTORE #else call __finexp #endif fld1 fdiv %st(1),%st # st(0)=1/exp(x), st(1)=exp(x) fst %st(2) # st(2)=1/exp(x) fadd %st(1),%st(0) fstp %st(3) # st(2)=exp(x)+exp(-x), st(1)=exp(-x), st(0)=exp(x) fsubp # st(1)=exp(x)+exp(-x), st(0)=exp(x)-exp(-x) fdivp ret tanhl: fldl2e fldt 4(%esp) fmulp jmp fintanh .Lende: .size tanh,.Lende-tanh .size tanhf,.Lende-tanhf .size tanhl,.Lende-tanhl dietlibc-0.33~cvs20120325/i386/unified.S010064400000000000000000000027731173363226000141520ustar00 #include #ifdef WANT_SYSENTER .data .type __vsyscall,@object .global __vsyscall __vsyscall: .Lvsyscall: .long .Lcallint80 #endif .text .global __unified_syscall_256 .type __unified_syscall_256,@function __unified_syscall_256: movzwl %ax,%eax jmp .L1 .L2: .size __unified_syscall_256,.L2-__unified_syscall_256 .weak exit exit: .global _exit .type _exit,@function _exit: movb $1,%al .global __unified_syscall .type __unified_syscall,@function __unified_syscall: .size _exit,__unified_syscall-_exit movzbl %al, %eax .L1: push %edi push %esi push %ebx push %ebp movl %esp,%edi /* we use movl instead of pop because otherwise a signal would destroy the stack frame and crash the program, although it would save a few bytes. */ movl 5*4(%edi),%ebx movl 6*4(%edi),%ecx movl 7*4(%edi),%edx movl 8*4(%edi),%esi movl 10*4(%edi),%ebp movl 9*4(%edi),%edi #ifdef WANT_SYSENTER call *.Lvsyscall /* 0xffffe000 */ #else int $0x80 #endif pop %ebp pop %ebx pop %esi pop %edi cmp $-132,%eax jb .Lnoerror neg %eax .global __error_unified_syscall .type __error_unified_syscall,@function __error_unified_syscall: #ifdef WANT_THREAD_SAFE push %eax call __errno_location pop (%eax) orl $-1,%eax #else mov %eax,errno sbb %eax,%eax # eax = eax - eax - CY = -1 #endif .Lnoerror: /* here we go and "reuse" the return for weak-void functions */ #include "dietuglyweaks.h" ret .L3: .size __unified_syscall,.L3-__unified_syscall #ifdef WANT_SYSENTER .Lcallint80: int $0x80 ret #endif dietlibc-0.33~cvs20120325/i386/usleep.S010064400000000000000000000007021173363226000140120ustar00#include "PIC.h" .text .global usleep .type usleep,@function usleep: movl 4(%esp),%eax PIC_SAVE # non-PIC: empty line PIC_INIT # non-PIC: empty line xorl %edx,%edx movl $1000000,%ecx divl %ecx imull $1000,%edx pushl %edx pushl %eax movl %esp,%eax pushl %eax pushl %eax #ifdef __DYN_LIB call nanosleep@PLT #else call nanosleep #endif addl $16,%esp PIC_RESTORE # non-PIC: empty line ret .Lende: .size usleep,.Lende-usleep dietlibc-0.33~cvs20120325/i386/vfork.S010064400000000000000000000002121173363226000136400ustar00.text .global vfork .type vfork,@function vfork: popl %edx xorl %eax,%eax movb $190, %al int $0x80 jmpl *%edx .size vfork, . - vfork dietlibc-0.33~cvs20120325/i386/write12.S010064400000000000000000000015211173363226000140120ustar00#include "PIC.h" .text .global __write1 .type __write1,@function .global __write2 .type __write2,@function # regparm=1, daher Stringadresse in %eax __write2: clc # CY = 0 .byte 0xB2 # zusammen mit nächstem Byte: mov dl,0xF9 __write1: stc # CY = 1 sbbl %ecx,%ecx # __write2: ecx=0, __write1: ecx=-1 incl %ecx incl %ecx # __write2: ecx=2, __write1: ecx=1 xorl %edx,%edx decl %edx .Lnext: incl %edx cmpb %ch,(%edx,%eax) # ch=0, da bei beiden Filedescriptoren Bits 15:8 0 sind jnz .Lnext # Stringlänge in edx, ohne eax zerstört zu haben PIC_SAVE # non-PIC: empty line PIC_INIT # non-PIC: empty line pushl %edx pushl %eax pushl %ecx #ifdef __DYN_LIB call write@PLT #else call write # alles ruf uf dn Stack und ab damit #endif addl $12,%esp # und das leidvolle Putzen PIC_RESTORE # non-PIC: empty line ret dietlibc-0.33~cvs20120325/ia64/Makefile.add010064400000000000000000000002121173363226000146260ustar00VPATH:=ia64:syscalls.s:$(VPATH) LIBOBJ+=$(OBJDIR)/__time.o $(OBJDIR)/__waitpid.o $(OBJDIR)/__nice.o $(OBJDIR)/__alarm.o $(OBJDIR)/__CAS.o dietlibc-0.33~cvs20120325/ia64/README010064400000000000000000000002051173363226000133210ustar00A Port for IA64. Does not yet support: clone, FPU and profiling. And includes some subtle bugs which will hopefully be fixed later. dietlibc-0.33~cvs20120325/ia64/__CAS.S010064400000000000000000000002651173363226000134770ustar00.text .global __CAS .type __CAS,@function __CAS: .mii mov ar.ccv = r33 nop 0 ;; nop 0 .mmb cmpxchg8.rel r8 = [r32], r34, ar.ccv mf br.ret.sptk.many b0 .size __CAS, .-__CAS dietlibc-0.33~cvs20120325/ia64/__longjmp.S010064400000000000000000000106551173363226000145430ustar00/* Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. Contributed by David Mosberger-Tang . The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. Note that __sigsetjmp() did NOT flush the register stack. Instead, we do it here since __longjmp() is usually much less frequently invoked than __sigsetjmp(). The only difficulty is that __sigsetjmp() didn't (and wouldn't be able to) save ar.rnat either. This is a problem because if we're not careful, we could end up loading random NaT bits. There are two cases: (i) ar.bsp < ia64_rse_rnat_addr(jmpbuf.ar_bsp) ar.rnat contains the desired bits---preserve ar.rnat across loadrs and write to ar.bspstore (ii) ar.bsp >= ia64_rse_rnat_addr(jmpbuf.ar_bsp) The desired ar.rnat is stored in ia64_rse_rnat_addr(jmpbuf.ar_bsp). Load those bits into ar.rnat after setting ar.bspstore. */ #if 0 #include #include #else #define LEAF(x) .text; .align 32; .proc x; .globl x; x: #define END(x) .endp x #define ret br.ret.sptk.few b0 #endif # define pPos p6 /* is rotate count positive? */ # define pNeg p7 /* is rotate count negative? */ /* __longjmp(__jmp_buf buf, int val) */ LEAF(__longjmp) alloc r8=ar.pfs,2,1,0,0 mov r27=ar.rsc add r2=0x98,in0 // r2 <- &jmpbuf.orig_jmp_buf_addr ;; ld8 r8=[r2],-16 // r8 <- orig_jmp_buf_addr mov r10=ar.bsp and r11=~0x3,r27 // clear ar.rsc.mode ;; flushrs // flush dirty regs to backing store (must be first in insn grp) ld8 r23=[r2],8 // r23 <- jmpbuf.ar_bsp sub r8=r8,in0 // r8 <- &orig_jmpbuf - &jmpbuf ;; ld8 r25=[r2] // r25 <- jmpbuf.ar_unat extr.u r8=r8,3,6 // r8 <- (&orig_jmpbuf - &jmpbuf)/8 & 0x3f ;; cmp.lt pNeg,pPos=r8,r0 mov r2=in0 ;; (pPos) mov r16=r8 (pNeg) add r16=64,r8 (pPos) sub r17=64,r8 (pNeg) sub r17=r0,r8 ;; mov ar.rsc=r11 // put RSE in enforced lazy mode shr.u r8=r25,r16 add r3=8,in0 // r3 <- &jmpbuf.r1 shl r9=r25,r17 ;; or r25=r8,r9 ;; mov r26=ar.rnat mov ar.unat=r25 // setup ar.unat (NaT bits for r1, r4-r7, and r12) ;; ld8.fill.nta sp=[r2],16 // r12 (sp) ld8.fill.nta gp=[r3],16 // r1 (gp) dep r11=-1,r23,3,6 // r11 <- ia64_rse_rnat_addr(jmpbuf.ar_bsp) ;; ld8.nta r16=[r2],16 // caller's unat ld8.nta r17=[r3],16 // fpsr ;; ld8.fill.nta r4=[r2],16 // r4 ld8.fill.nta r5=[r3],16 // r5 (gp) cmp.geu p8,p0=r10,r11 // p8 <- (ar.bsp >= jmpbuf.ar_bsp) ;; ld8.fill.nta r6=[r2],16 // r6 ld8.fill.nta r7=[r3],16 // r7 ;; mov ar.unat=r16 // restore caller's unat mov ar.fpsr=r17 // restore fpsr ;; ld8.nta r16=[r2],16 // b0 ld8.nta r17=[r3],16 // b1 ;; (p8) ld8 r26=[r11] // r26 <- *ia64_rse_rnat_addr(jmpbuf.ar_bsp) mov ar.bspstore=r23 // restore ar.bspstore ;; ld8.nta r18=[r2],16 // b2 ld8.nta r19=[r3],16 // b3 ;; ld8.nta r20=[r2],16 // b4 ld8.nta r21=[r3],16 // b5 ;; ld8.nta r11=[r2],16 // ar.pfs ld8.nta r22=[r3],56 // ar.lc ;; ld8.nta r24=[r2],32 // pr mov b0=r16 ;; ldf.fill.nta f2=[r2],32 ldf.fill.nta f3=[r3],32 mov b1=r17 ;; ldf.fill.nta f4=[r2],32 ldf.fill.nta f5=[r3],32 mov b2=r18 ;; ldf.fill.nta f16=[r2],32 ldf.fill.nta f17=[r3],32 mov b3=r19 ;; ldf.fill.nta f18=[r2],32 ldf.fill.nta f19=[r3],32 mov b4=r20 ;; ldf.fill.nta f20=[r2],32 ldf.fill.nta f21=[r3],32 mov b5=r21 ;; ldf.fill.nta f22=[r2],32 ldf.fill.nta f23=[r3],32 mov ar.lc=r22 ;; ldf.fill.nta f24=[r2],32 ldf.fill.nta f25=[r3],32 cmp.eq p8,p9=0,in1 ;; ldf.fill.nta f26=[r2],32 ldf.fill.nta f27=[r3],32 mov ar.pfs=r11 ;; ldf.fill.nta f28=[r2],32 ldf.fill.nta f29=[r3],32 ;; ldf.fill.nta f30=[r2] ldf.fill.nta f31=[r3] (p8) mov r8=1 mov ar.rnat=r26 // restore ar.rnat ;; mov ar.rsc=r27 // restore ar.rsc (p9) mov r8=in1 invala // virt. -> phys. regnum mapping may change mov pr=r24,-1 ret END(__longjmp) dietlibc-0.33~cvs20120325/ia64/__testandset.S010064400000000000000000000003741173363226000152500ustar00.text .globl __testandset .proc __testandset __testandset: mov ar.ccv = r0 mov r29 = 1 ld8 r3 = [r32] ;; cmpxchg8.acq r8 = [r32], r29, ar.ccv /* cmpxchg is atomic */ br.ret.sptk.clr b0 .endp __testandset .size __testandset, . - __testandset dietlibc-0.33~cvs20120325/ia64/__waitpid.c010064400000000000000000000002211173363226000145420ustar00#include #include pid_t waitpid(pid_t pid, int * wait_stat, int flags) { return wait4(pid, wait_stat, flags, 0); } dietlibc-0.33~cvs20120325/ia64/clone.S010064400000000000000000000015221173363226000136700ustar00/* This is untested code which probably won´t work out of the box! */ #include "syscalls.h" #include .text .globl __clone .proc __clone .weak __clone2 __clone2: __clone: mov r8 = EINVAL cmp.eq p6,p0=0,r32 ;; (p6) br.cond.spnt.few __error_unified_syscall cmp.eq p6,p0=0,r33 ;; (p6) br.cond.spnt.few __error_unified_syscall flushrs ;; mov.m r17 = ar.rsc mov r14 = r32 mov r18 = r33 mov r16 = r36;; mov r15 = __NR_clone2 break 0x100000 cmp.eq p6,p0=-1,r10 ;; (p6) br.cond.spnt.few __error_unified_syscall cmp.eq p6,p7=0,r8 ;; (p6) ld8 r34=[r14],8 (p6) mov.m ar.bspstore=r18 (p6) mov r32 = r16 mov.m ar.rsc = r17 (p7) br.ret.sptk b0 ;; ld8 r1 = [r14] mov b6 = r34 br.call.dptk.few b0=b6 mov r32 = r8 br.call.dptk.few b0=__error_unified_syscall br.ret.sptk.few b0 .endp __clone .size __clone, . - __clone dietlibc-0.33~cvs20120325/ia64/fork.S010064400000000000000000000004351173363226000135330ustar00#include "syscalls.h" #include #define SIGCLD 17 .text .globl fork .proc fork .weak __libc_fork .type fork,@function .type __libc_fork,@function fork: __libc_fork: alloc r2=ar.pfs,0,0,2,0 mov out0=SIGCLD mov out1=0 ;; mov r15 = __NR_clone br __unified_syscall dietlibc-0.33~cvs20120325/ia64/getsockopt.S010064400000000000000000000000701173363226000147470ustar00#include "syscalls.h" syscall(getsockopt, getsockopt); dietlibc-0.33~cvs20120325/ia64/msgctl.S010064400000000000000000000000561173363226000140620ustar00#include "syscalls.h" syscall(msgctl,msgctl) dietlibc-0.33~cvs20120325/ia64/msgget.S010064400000000000000000000000561173363226000140570ustar00#include "syscalls.h" syscall(msgget,msgget) dietlibc-0.33~cvs20120325/ia64/msgrcv.S010064400000000000000000000000561173363226000140720ustar00#include "syscalls.h" syscall(msgrcv,msgrcv) dietlibc-0.33~cvs20120325/ia64/msgsnd.S010064400000000000000000000000561173363226000140640ustar00#include "syscalls.h" syscall(msgsnd,msgsnd) dietlibc-0.33~cvs20120325/ia64/pipe.S010064400000000000000000000005021173363226000135220ustar00#include "syscalls.h" .text .globl pipe .proc pipe pipe: st8 [r12] = r32 mov r15 = __NR_pipe break.i 0x100000 ld8 r2 = [r12] cmp.eq p7,p6=-1,r10 ;; (p6) st4 [r2] = r8,4 mov r8 = r0 ;; (p7) br.cond.spnt.few __error_unified_syscall (p6) st4 [r2] = r9 (p6) br.ret.sptk.few b0 .endp pipe .size pipe, . - pipe dietlibc-0.33~cvs20120325/ia64/semctl.S010064400000000000000000000000561173363226000140600ustar00#include "syscalls.h" syscall(semctl,semctl) dietlibc-0.33~cvs20120325/ia64/semget.S010064400000000000000000000000561173363226000140550ustar00#include "syscalls.h" syscall(semget,semget) dietlibc-0.33~cvs20120325/ia64/semop.S010064400000000000000000000000541173363226000137120ustar00#include "syscalls.h" syscall(semop,semop) dietlibc-0.33~cvs20120325/ia64/setjmp.S010064400000000000000000000106671173363226000141040ustar00/* Copyright (C) 1999, 2000, 2001, 2002, 2004 Free Software Foundation, Inc. Contributed by David Mosberger-Tang . The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. The layout of the jmp_buf is as follows. This is subject to change and user-code should never depend on the particular layout of jmp_buf! offset: description: ------- ------------ 0x000 stack pointer (r12) ; unchangeable (see _JMPBUF_UNWINDS) 0x008 r1 (gp) 0x010 caller's unat 0x018 fpsr 0x020 r4 0x028 r5 0x030 r6 0x038 r7 0x040 rp (b0) 0x048 b1 0x050 b2 0x058 b3 0x060 b4 0x068 b5 0x070 ar.pfs 0x078 ar.lc 0x080 pr 0x088 ar.bsp ; unchangeable (see __longjmp.S) 0x090 ar.unat 0x098 &__jmp_buf ; address of the jmpbuf (needed to locate NaT bits in unat) 0x0a0 f2 0x0b0 f3 0x0c0 f4 0x0d0 f5 0x0e0 f16 0x0f0 f17 0x100 f18 0x110 f19 0x120 f20 0x130 f21 0x130 f22 0x140 f23 0x150 f24 0x160 f25 0x170 f26 0x180 f27 0x190 f28 0x1a0 f29 0x1b0 f30 0x1c0 f31 */ #if 0 #include #include #else #define LEAF(x) .text; .align 32; .proc x; .globl x; x: #define ENTRY(x) .text; .align 32; .proc x; .globl x; x: #define END(x) .endp x #define ret br.ret.sptk.few b0 #define libc_hidden_def(x) #define strong_alias(x,y) #define weak_extern(x) .weak x #define _GI___sigsetjmp __sigsetjmp #endif /* The following two entry points are the traditional entry points: */ LEAF(setjmp) alloc r8=ar.pfs,2,0,0,0 mov in1=1 br.cond.sptk.many _GI___sigsetjmp END(setjmp) LEAF(_setjmp) alloc r8=ar.pfs,2,0,0,0 mov in1=0 br.cond.sptk.many _GI___sigsetjmp END(_setjmp) libc_hidden_def (_setjmp) /* __sigsetjmp(__jmp_buf buf, int savemask) */ ENTRY(__sigsetjmp) #if 0 .prologue ASM_UNW_PRLG_RP|ASM_UNW_PRLG_PFS, ASM_UNW_PRLG_GRSAVE(2) #else .prologue 0x8|0x4, 32+2 #endif alloc loc1=ar.pfs,2,3,2,0 .save ar.unat, loc2 mov loc2=ar.unat ;; mov r17=ar.fpsr mov r2=in0 add r3=8,in0 ;; .mem.offset 8,0; st8.spill.nta [r2]=sp,16 // r12 (sp) .mem.offset 0,0; st8.spill.nta [r3]=gp,16 // r1 (gp) ;; st8.nta [r2]=loc2,16 // save caller's unat st8.nta [r3]=r17,16 // save fpsr add r8=0xa0,in0 ;; .mem.offset 8,0; st8.spill.nta [r2]=r4,16 // r4 .mem.offset 0,0; st8.spill.nta [r3]=r5,16 // r5 add r9=0xb0,in0 ;; stf.spill.nta [r8]=f2,32 stf.spill.nta [r9]=f3,32 mov loc0=rp .body ;; stf.spill.nta [r8]=f4,32 stf.spill.nta [r9]=f5,32 mov r17=b1 ;; stf.spill.nta [r8]=f16,32 stf.spill.nta [r9]=f17,32 mov r18=b2 ;; stf.spill.nta [r8]=f18,32 stf.spill.nta [r9]=f19,32 mov r19=b3 ;; stf.spill.nta [r8]=f20,32 stf.spill.nta [r9]=f21,32 mov r20=b4 ;; stf.spill.nta [r8]=f22,32 stf.spill.nta [r9]=f23,32 mov r21=b5 ;; stf.spill.nta [r8]=f24,32 stf.spill.nta [r9]=f25,32 mov r22=ar.lc ;; stf.spill.nta [r8]=f26,32 stf.spill.nta [r9]=f27,32 mov r24=pr ;; stf.spill.nta [r8]=f28,32 stf.spill.nta [r9]=f29,32 ;; stf.spill.nta [r8]=f30 stf.spill.nta [r9]=f31 .mem.offset 8,0; st8.spill.nta [r2]=r6,16 // r6 .mem.offset 0,0; st8.spill.nta [r3]=r7,16 // r7 ;; mov r23=ar.bsp mov r25=ar.unat mov out0=in0 st8.nta [r2]=loc0,16 // b0 st8.nta [r3]=r17,16 // b1 mov out1=in1 ;; st8.nta [r2]=r18,16 // b2 st8.nta [r3]=r19,16 // b3 ;; st8.nta [r2]=r20,16 // b4 st8.nta [r3]=r21,16 // b5 ;; st8.nta [r2]=loc1,16 // ar.pfs st8.nta [r3]=r22,16 // ar.lc ;; st8.nta [r2]=r24,16 // pr st8.nta [r3]=r23,16 // ar.bsp ;; st8.nta [r2]=r25 // ar.unat st8.nta [r3]=in0 // &__jmp_buf br.call.dpnt.few rp=__sigjmp_save .ret0: // force a new bundle ::q mov.m ar.unat=loc2 // restore caller's unat mov rp=loc0 mov ar.pfs=loc1 mov r8=0 ret END(__sigsetjmp) strong_alias(__sigsetjmp, _GI___sigsetjmp) weak_extern(_setjmp) weak_extern(setjmp) dietlibc-0.33~cvs20120325/ia64/setsockopt.S010064400000000000000000000000701173363226000147630ustar00#include "syscalls.h" syscall(setsockopt, setsockopt); dietlibc-0.33~cvs20120325/ia64/shmat.S010064400000000000000000000000541173363226000137030ustar00#include "syscalls.h" syscall(shmat,shmat) dietlibc-0.33~cvs20120325/ia64/shmctl.S010064400000000000000000000000561173363226000140630ustar00#include "syscalls.h" syscall(shmctl,shmctl) dietlibc-0.33~cvs20120325/ia64/shmdt.S010064400000000000000000000000541173363226000137060ustar00#include "syscalls.h" syscall(shmdt,shmdt) dietlibc-0.33~cvs20120325/ia64/shmget.S010064400000000000000000000000561173363226000140600ustar00#include "syscalls.h" syscall(shmget,shmget) dietlibc-0.33~cvs20120325/ia64/start.S010064400000000000000000000021671173363226000137330ustar00/* Copyright (C) 2002 Thomas M. Ogrisegg This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. This file is part of the IA64-Port of the dietlibc start.S Implemenation of the _start startup function */ #include "dietfeatures.h" .psr abi64 .psr lsb .lsb .text .globl _start .proc _start _start: alloc r2 = ar.pfs,0,0,7,0 adds out1 = 16, sp /* base arguments */ movl gp = @gprel(0f) /* base offset */ ;; 0: ld8 out0 = [out1], 8 /* load argc and set argv */ mov r9 = ip ;; shladd out2=out0,3,out1 /* envp = argv+8*argc */ sub gp = r9, gp /* subtract program counter */ ;; addl r15 = @ltoff(environ#), gp /* offset to environ */ adds out2 = 8, out2 /* envp += 8 */ ;; ld8 r14 = [r15] ;; st8 [r14] = out2 /* store envp in environ */ #ifdef WANT_DYNAMIC /* FIXME: dl_init parameter ??? */ br.call.sptk.few rp = _dyn_start #else br.call.sptk.few rp = CALL_IN_STARTCODE #endif ;; mov r32 = r8 /* store return code */ br exit /* branch to exit */ .endp _start .size _start, . - _start dietlibc-0.33~cvs20120325/ia64/syscalls.h010064400000000000000000000211341173363226000144530ustar00#ifndef __DLIBC_SYSCALL_H_ #define __DLIBC_SYSCALL_H_ #define __NR_ni_syscall 1024 #define __NR_exit 1025 #define __NR_read 1026 #define __NR_write 1027 #define __NR_open 1028 #define __NR_close 1029 #define __NR_creat 1030 #define __NR_link 1031 #define __NR_unlink 1032 #define __NR_execve 1033 #define __NR_chdir 1034 #define __NR_fchdir 1035 #define __NR_utimes 1036 #define __NR_mknod 1037 #define __NR_chmod 1038 #define __NR_chown 1039 #define __NR_lseek 1040 #define __NR_getpid 1041 #define __NR_getppid 1042 #define __NR_mount 1043 #define __NR_umount 1044 #define __NR_setuid 1045 #define __NR_getuid 1046 #define __NR_geteuid 1047 #define __NR_ptrace 1048 #define __NR_access 1049 #define __NR_sync 1050 #define __NR_fsync 1051 #define __NR_fdatasync 1052 #define __NR_kill 1053 #define __NR_rename 1054 #define __NR_mkdir 1055 #define __NR_rmdir 1056 #define __NR_dup 1057 #define __NR_pipe 1058 #define __NR_times 1059 #define __NR_brk 1060 #define __NR_setgid 1061 #define __NR_getgid 1062 #define __NR_getegid 1063 #define __NR_acct 1064 #define __NR_ioctl 1065 #define __NR_fcntl 1066 #define __NR_umask 1067 #define __NR_chroot 1068 #define __NR_ustat 1069 #define __NR_dup2 1070 #define __NR_setreuid 1071 #define __NR_setregid 1072 #define __NR_getresuid 1073 #define __NR_setresuid 1074 #define __NR_getresgid 1075 #define __NR_setresgid 1076 #define __NR_getgroups 1077 #define __NR_setgroups 1078 #define __NR_getpgid 1079 #define __NR_setpgid 1080 #define __NR_setsid 1081 #define __NR_getsid 1082 #define __NR_sethostname 1083 #define __NR_setrlimit 1084 #define __NR_getrlimit 1085 #define __NR_getrusage 1086 #define __NR_gettimeofday 1087 #define __NR_settimeofday 1088 #define __NR_select 1089 #define __NR_poll 1090 #define __NR_symlink 1091 #define __NR_readlink 1092 #define __NR_uselib 1093 #define __NR_swapon 1094 #define __NR_swapoff 1095 #define __NR_reboot 1096 #define __NR_truncate 1097 #define __NR_ftruncate 1098 #define __NR_fchmod 1099 #define __NR_fchown 1100 #define __NR_getpriority 1101 #define __NR_setpriority 1102 #define __NR_statfs 1103 #define __NR_fstatfs 1104 #define __NR_gettid 1105 #define __NR_semget 1106 #define __NR_semop 1107 #define __NR_semctl 1108 #define __NR_msgget 1109 #define __NR_msgsnd 1110 #define __NR_msgrcv 1111 #define __NR_msgctl 1112 #define __NR_shmget 1113 #define __NR_shmat 1114 #define __NR_shmdt 1115 #define __NR_shmctl 1116 /* also known as klogctl() in GNU libc: */ #define __NR_syslog 1117 #define __NR_setitimer 1118 #define __NR_getitimer 1119 /* 1120 was __NR_old_stat */ /* 1121 was __NR_old_lstat */ /* 1122 was __NR_old_fstat */ #define __NR_vhangup 1123 #define __NR_lchown 1124 #define __NR_remap_file_pages 1125 #define __NR_wait4 1126 #define __NR_sysinfo 1127 #define __NR_clone 1128 #define __NR_setdomainname 1129 #define __NR_uname 1130 #define __NR_adjtimex 1131 #define __NR_create_module 1132 #define __NR_init_module 1133 #define __NR_delete_module 1134 #define __NR_get_kernel_syms 1135 #define __NR_query_module 1136 #define __NR_quotactl 1137 #define __NR_bdflush 1138 #define __NR_sysfs 1139 #define __NR_personality 1140 #define __NR_afs_syscall 1141 #define __NR_setfsuid 1142 #define __NR_setfsgid 1143 #define __NR_getdents 1144 #define __NR_flock 1145 #define __NR_readv 1146 #define __NR_writev 1147 #define __NR_pread 1148 #define __NR_pwrite 1149 #define __NR__sysctl 1150 #define __NR_mmap 1151 #define __NR_munmap 1152 #define __NR_mlock 1153 #define __NR_mlockall 1154 #define __NR_mprotect 1155 #define __NR_mremap 1156 #define __NR_msync 1157 #define __NR_munlock 1158 #define __NR_munlockall 1159 #define __NR_sched_getparam 1160 #define __NR_sched_setparam 1161 #define __NR_sched_getscheduler 1162 #define __NR_sched_setscheduler 1163 #define __NR_sched_yield 1164 #define __NR_sched_get_priority_max 1165 #define __NR_sched_get_priority_min 1166 #define __NR_sched_rr_get_interval 1167 #define __NR_nanosleep 1168 #define __NR_nfsservctl 1169 #define __NR_prctl 1170 #define __NR_mmap2 1172 #define __NR_pciconfig_read 1173 #define __NR_pciconfig_write 1174 #define __NR_perfmonctl 1175 #define __NR_sigaltstack 1176 #define __NR_rt_sigaction 1177 #define __NR_rt_sigpending 1178 #define __NR_rt_sigprocmask 1179 #define __NR_rt_sigqueueinfo 1180 #define __NR_rt_sigreturn 1181 #define __NR_rt_sigsuspend 1182 #define __NR_rt_sigtimedwait 1183 #define __NR_getcwd 1184 #define __NR_capget 1185 #define __NR_capset 1186 #define __NR_sendfile 1187 #define __NR_getpmsg 1188 #define __NR_putpmsg 1189 #define __NR_socket 1190 #define __NR_bind 1191 #define __NR_connect 1192 #define __NR_listen 1193 #define __NR_accept 1194 #define __NR_getsockname 1195 #define __NR_getpeername 1196 #define __NR_socketpair 1197 #define __NR_send 1198 #define __NR_sendto 1199 #define __NR_recv 1200 #define __NR_recvfrom 1201 #define __NR_shutdown 1202 #define __NR_setsockopt 1203 #define __NR_getsockopt 1204 #define __NR_sendmsg 1205 #define __NR_recvmsg 1206 #define __NR_pivot_root 1207 #define __NR_mincore 1208 #define __NR_madvise 1209 #define __NR_stat 1210 #define __NR_lstat 1211 #define __NR_fstat 1212 #define __NR_clone2 1213 #define __NR_getdents64 1214 #define __NR_getunwind 1215 #define __NR_readahead 1216 #define __NR_setxattr 1217 #define __NR_lsetxattr 1218 #define __NR_fsetxattr 1219 #define __NR_getxattr 1220 #define __NR_lgetxattr 1221 #define __NR_fgetxattr 1222 #define __NR_listxattr 1223 #define __NR_llistxattr 1224 #define __NR_flistxattr 1225 #define __NR_removexattr 1226 #define __NR_lremovexattr 1227 #define __NR_fremovexattr 1228 #define __NR_tkill 1229 #define __NR_futex 1230 #define __NR_sched_setaffinity 1231 #define __NR_sched_getaffinity 1232 #define __NR_set_tid_address 1233 #define __NR_fadvise64 1234 #define __NR_tgkill 1235 #define __NR_exit_group 1236 #define __NR_lookup_dcookie 1237 #define __NR_io_setup 1238 #define __NR_io_destroy 1239 #define __NR_io_getevents 1240 #define __NR_io_submit 1241 #define __NR_io_cancel 1242 #define __NR_epoll_create 1243 #define __NR_epoll_ctl 1244 #define __NR_epoll_wait 1245 #define __NR_restart_syscall 1246 #define __NR_semtimedop 1247 #define __NR_timer_create 1248 #define __NR_timer_settime 1249 #define __NR_timer_gettime 1250 #define __NR_timer_getoverrun 1251 #define __NR_timer_delete 1252 #define __NR_clock_settime 1253 #define __NR_clock_gettime 1254 #define __NR_clock_getres 1255 #define __NR_clock_nanosleep 1256 #define __NR_fstatfs64 1257 #define __NR_statfs64 1258 #define __NR_mbind 1259 #define __NR_get_mempolicy 1260 #define __NR_set_mempolicy 1261 #define __NR_mq_open 1262 #define __NR_mq_unlink 1263 #define __NR_mq_timedsend 1264 #define __NR_mq_timedreceive 1265 #define __NR_mq_notify 1266 #define __NR_mq_getsetattr 1267 #define __NR_kexec_load 1268 #define __NR_vserver 1269 #define __NR_waitid 1270 #define __NR_add_key 1271 #define __NR_request_key 1272 #define __NR_keyctl 1273 #define __NR_ioprio_set 1274 #define __NR_ioprio_get 1275 #define __NR_set_zone_reclaim 1276 #define __NR_inotify_init 1277 #define __NR_inotify_add_watch 1278 #define __NR_inotify_rm_watch 1279 #define __NR_migrate_pages 1280 #define __NR_openat 1281 #define __NR_mkdirat 1282 #define __NR_mknodat 1283 #define __NR_fchownat 1284 #define __NR_futimesat 1285 #define __NR_newfstatat 1286 #define __NR_unlinkat 1287 #define __NR_renameat 1288 #define __NR_linkat 1289 #define __NR_symlinkat 1290 #define __NR_readlinkat 1291 #define __NR_fchmodat 1292 #define __NR_faccessat 1293 /* 1294, 1295 reserved for pselect/ppoll */ #define __NR_unshare 1296 #define __NR_splice 1297 #define __NR_set_robust_list 1298 #define __NR_get_robust_list 1299 #define __NR_sync_file_range 1300 #define __NR_tee 1301 #define __NR_vmsplice 1302 #define __NR_fallocate 1303 #define __NR_getcpu 1304 #define __NR_epoll_pwait 1305 #define __NR_utimensat 1306 #define __NR_signalfd 1307 #define __NR_timerfd 1308 #define __NR_eventfd 1309 #define __NR_timerfd_create 1310 #define __NR_timerfd_settime 1311 #define __NR_timerfd_gettime 1312 #define syscall(name, sym) \ .text; \ .globl sym; \ sym: \ mov r15 = __NR_##name; \ br __unified_syscall; #define syscall_weak(name, sym, wsym) \ .text; \ .weak wsym; \ wsym: \ .globl sym; \ sym: \ wsym: ; \ mov r15 = __NR_##name; \ br __unified_syscall; #endif dietlibc-0.33~cvs20120325/ia64/unified.S010064400000000000000000000014351173363226000142160ustar00/* Copyright (C) 2002 Thomas M. Ogrisegg This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. This file is part of the ia64-Port of dietlibc unified.S General system-call interface */ .lsb .text .globl __unified_syscall .proc __unified_syscall .globl __error_unified_syscall .proc __error_unified_syscall .globl _exit .proc _exit _exit: mov r15 = 1025 .endp _exit .size _exit, . - _exit __unified_syscall: break.i 0x100000 movl r2=errno cmp.eq p6,p0=-1,r10 ;; __error_unified_syscall: (p6) st4 [r2]=r8 (p6) mov r8=-1 #include "dietuglyweaks.h" br.ret.sptk.few rp .size __unified_syscall, __error_unified_syscall - __unified_syscall .size __error_unified_syscall, . - __error_unified_syscall dietlibc-0.33~cvs20120325/ia64/vfork.S010064400000000000000000000001561173363226000137210ustar00#include "syscalls.h" .text .globl vfork vfork: mov r15 = __NR_clone mov r32 = 16657 br __unified_syscall dietlibc-0.33~cvs20120325/include/alloca.h010064400000000000000000000003361173363226000147320ustar00#ifndef _ALLOCA_H #define _ALLOCA_H #include #include __BEGIN_DECLS #ifdef __GNUC__ #define alloca(x) __builtin_alloca(x) #else void *alloca(size_t size) __THROW; #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/ar.h010064400000000000000000000013361173363226000141020ustar00#ifndef _AR_H #define _AR_H /* this header is obsolete, don't rely on it! */ #include #define ARMAG "!\n" /* String that begins an archive file. */ #define SARMAG 8 /* Size of that string. */ #define ARFMAG "`\n" /* String in ar_fmag at end of each header. */ __BEGIN_DECLS struct ar_hdr { char ar_name[16]; /* Member file name, sometimes / terminated. */ char ar_date[12]; /* File date, decimal seconds since Epoch. */ char ar_uid[6], ar_gid[6]; /* User and group IDs, in ASCII decimal. */ char ar_mode[8]; /* File mode, in ASCII octal. */ char ar_size[10]; /* File size, in ASCII decimal. */ char ar_fmag[2]; /* Always contains ARFMAG. */ }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/arpa/inet.h010064400000000000000000000013311173363226000153550ustar00#ifndef _ARPA_INET_H #define _ARPA_INET_H #include #include #include __BEGIN_DECLS int inet_aton(const char* cp, struct in_addr* inp) __THROW; unsigned long int inet_addr(const char* cp) __THROW; unsigned long int inet_network(const char* cp) __THROW; char* inet_ntoa(struct in_addr in) __THROW; char* inet_ntoa_r(struct in_addr in,char* buf) __THROW; struct in_addr inet_makeaddr(int net, int host) __THROW; unsigned long int inet_lnaof(struct in_addr in) __THROW; unsigned long int inet_netof(struct in_addr in) __THROW; int inet_pton (int AF, const char* CP, void* BUF) __THROW; const char* inet_ntop (int AF, const void* CP, char* BUF, size_t LEN) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/arpa/nameser.h010064400000000000000000000226631173363226000160630ustar00#ifndef _ARPA_NAMESER_H #define _ARPA_NAMESER_H #include #include __BEGIN_DECLS #define NS_PACKETSZ 512 /* maximum packet size */ #define NS_MAXDNAME 1025 /* maximum domain name */ #define NS_MAXCDNAME 255 /* maximum compressed domain name */ #define NS_MAXLABEL 63 /* maximum length of domain label */ #define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ #define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ #define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ #define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */ #define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */ #define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */ #define NS_INADDRSZ 4 /* IPv4 T_A */ #define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */ #define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ #define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ /* * Currently defined type values for resources and queries. */ typedef enum __ns_type { ns_t_invalid = 0, /* Cookie. */ ns_t_a = 1, /* Host address. */ ns_t_ns = 2, /* Authoritative server. */ ns_t_md = 3, /* Mail destination. */ ns_t_mf = 4, /* Mail forwarder. */ ns_t_cname = 5, /* Canonical name. */ ns_t_soa = 6, /* Start of authority zone. */ ns_t_mb = 7, /* Mailbox domain name. */ ns_t_mg = 8, /* Mail group member. */ ns_t_mr = 9, /* Mail rename name. */ ns_t_null = 10, /* Null resource record. */ ns_t_wks = 11, /* Well known service. */ ns_t_ptr = 12, /* Domain name pointer. */ ns_t_hinfo = 13, /* Host information. */ ns_t_minfo = 14, /* Mailbox information. */ ns_t_mx = 15, /* Mail routing information. */ ns_t_txt = 16, /* Text strings. */ ns_t_rp = 17, /* Responsible person. */ ns_t_afsdb = 18, /* AFS cell database. */ ns_t_x25 = 19, /* X_25 calling address. */ ns_t_isdn = 20, /* ISDN calling address. */ ns_t_rt = 21, /* Router. */ ns_t_nsap = 22, /* NSAP address. */ ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ ns_t_sig = 24, /* Security signature. */ ns_t_key = 25, /* Security key. */ ns_t_px = 26, /* X.400 mail mapping. */ ns_t_gpos = 27, /* Geographical position (withdrawn). */ ns_t_aaaa = 28, /* Ip6 Address. */ ns_t_loc = 29, /* Location Information. */ ns_t_nxt = 30, /* Next domain (security). */ ns_t_eid = 31, /* Endpoint identifier. */ ns_t_nimloc = 32, /* Nimrod Locator. */ ns_t_srv = 33, /* Server Selection. */ ns_t_atma = 34, /* ATM Address */ ns_t_naptr = 35, /* Naming Authority PoinTeR */ ns_t_kx = 36, /* Key Exchange */ ns_t_cert = 37, /* Certification record */ ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ ns_t_sink = 40, /* Kitchen sink (experimentatl) */ ns_t_opt = 41, /* EDNS0 option (meta-RR) */ ns_t_tsig = 250, /* Transaction signature. */ ns_t_ixfr = 251, /* Incremental zone transfer. */ ns_t_axfr = 252, /* Transfer zone of authority. */ ns_t_mailb = 253, /* Transfer mailbox records. */ ns_t_maila = 254, /* Transfer mail agent records. */ ns_t_any = 255, /* Wildcard match. */ ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ ns_t_max = 65536 } ns_type; /* * Values for class field */ typedef enum __ns_class { ns_c_invalid = 0, /* Cookie. */ ns_c_in = 1, /* Internet. */ ns_c_2 = 2, /* unallocated/unsupported. */ ns_c_chaos = 3, /* MIT Chaos-net. */ ns_c_hs = 4, /* MIT Hesiod. */ /* Query class values which do not appear in resource records */ ns_c_none = 254, /* for prereq. sections in update requests */ ns_c_any = 255, /* Wildcard match. */ ns_c_max = 65536 } ns_class; /* * Currently defined opcodes. */ typedef enum __ns_opcode { ns_o_query = 0, /* Standard query. */ ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ ns_o_status = 2, /* Name server status query (unsupported). */ /* Opcode 3 is undefined/reserved. */ ns_o_notify = 4, /* Zone change notification. */ ns_o_update = 5, /* Zone update message. */ ns_o_max = 6 } ns_opcode; /* * Currently defined response codes. */ typedef enum __ns_rcode { ns_r_noerror = 0, /* No error occurred. */ ns_r_formerr = 1, /* Format error. */ ns_r_servfail = 2, /* Server failure. */ ns_r_nxdomain = 3, /* Name error. */ ns_r_notimpl = 4, /* Unimplemented. */ ns_r_refused = 5, /* Operation refused. */ /* these are for BIND_UPDATE */ ns_r_yxdomain = 6, /* Name exists */ ns_r_yxrrset = 7, /* RRset exists */ ns_r_nxrrset = 8, /* RRset does not exist */ ns_r_notauth = 9, /* Not authoritative for zone */ ns_r_notzone = 10, /* Zone of record different from zone section */ ns_r_max = 11, /* The following are TSIG extended errors */ ns_r_badsig = 16, ns_r_badkey = 17, ns_r_badtime = 18 } ns_rcode; typedef struct { unsigned id :16; /* query identification number */ #if BYTE_ORDER == BIG_ENDIAN /* fields in third byte */ unsigned qr: 1; /* response flag */ unsigned opcode: 4; /* purpose of message */ unsigned aa: 1; /* authoritive answer */ unsigned tc: 1; /* truncated message */ unsigned rd: 1; /* recursion desired */ /* fields in fourth byte */ unsigned ra: 1; /* recursion available */ unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ unsigned ad: 1; /* authentic data from named */ unsigned cd: 1; /* checking disabled by resolver */ unsigned rcode :4; /* response code */ #endif #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN /* fields in third byte */ unsigned rd :1; /* recursion desired */ unsigned tc :1; /* truncated message */ unsigned aa :1; /* authoritive answer */ unsigned opcode :4; /* purpose of message */ unsigned qr :1; /* response flag */ /* fields in fourth byte */ unsigned rcode :4; /* response code */ unsigned cd: 1; /* checking disabled by resolver */ unsigned ad: 1; /* authentic data from named */ unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ unsigned ra :1; /* recursion available */ #endif /* remaining bytes */ unsigned qdcount :16; /* number of question entries */ unsigned ancount :16; /* number of answer entries */ unsigned nscount :16; /* number of authority entries */ unsigned arcount :16; /* number of resource entries */ } HEADER; #define PACKETSZ NS_PACKETSZ #define MAXDNAME NS_MAXDNAME #define MAXCDNAME NS_MAXCDNAME #define MAXLABEL NS_MAXLABEL #define HFIXEDSZ NS_HFIXEDSZ #define QFIXEDSZ NS_QFIXEDSZ #define RRFIXEDSZ NS_RRFIXEDSZ #define INT32SZ NS_INT32SZ #define INT16SZ NS_INT16SZ #define INADDRSZ NS_INADDRSZ #define IN6ADDRSZ NS_IN6ADDRSZ #define INDIR_MASK NS_CMPRSFLGS #define NAMESERVER_PORT NS_DEFAULTPORT #define S_ZONE ns_s_zn #define S_PREREQ ns_s_pr #define S_UPDATE ns_s_ud #define S_ADDT ns_s_ar #define QUERY ns_o_query #define IQUERY ns_o_iquery #define STATUS ns_o_status #define NS_NOTIFY_OP ns_o_notify #define NS_UPDATE_OP ns_o_update #define NOERROR ns_r_noerror #define FORMERR ns_r_formerr #define SERVFAIL ns_r_servfail #define NXDOMAIN ns_r_nxdomain #define NOTIMP ns_r_notimpl #define REFUSED ns_r_refused #define YXDOMAIN ns_r_yxdomain #define YXRRSET ns_r_yxrrset #define NXRRSET ns_r_nxrrset #define NOTAUTH ns_r_notauth #define NOTZONE ns_r_notzone #define DELETE ns_uop_delete #define ADD ns_uop_add #define T_A ns_t_a #define T_NS ns_t_ns #define T_MD ns_t_md #define T_MF ns_t_mf #define T_CNAME ns_t_cname #define T_SOA ns_t_soa #define T_MB ns_t_mb #define T_MG ns_t_mg #define T_MR ns_t_mr #define T_NULL ns_t_null #define T_WKS ns_t_wks #define T_PTR ns_t_ptr #define T_HINFO ns_t_hinfo #define T_MINFO ns_t_minfo #define T_MX ns_t_mx #define T_TXT ns_t_txt #define T_RP ns_t_rp #define T_AFSDB ns_t_afsdb #define T_X25 ns_t_x25 #define T_ISDN ns_t_isdn #define T_RT ns_t_rt #define T_NSAP ns_t_nsap #define T_NSAP_PTR ns_t_nsap_ptr #define T_SIG ns_t_sig #define T_KEY ns_t_key #define T_PX ns_t_px #define T_GPOS ns_t_gpos #define T_AAAA ns_t_aaaa #define T_LOC ns_t_loc #define T_NXT ns_t_nxt #define T_EID ns_t_eid #define T_NIMLOC ns_t_nimloc #define T_SRV ns_t_srv #define T_ATMA ns_t_atma #define T_NAPTR ns_t_naptr #define T_TSIG ns_t_tsig #define T_IXFR ns_t_ixfr #define T_AXFR ns_t_axfr #define T_MAILB ns_t_mailb #define T_MAILA ns_t_maila #define T_ANY ns_t_any #define C_IN ns_c_in #define C_CHAOS ns_c_chaos #define C_HS ns_c_hs #define C_NONE ns_c_none #define C_ANY ns_c_any __END_DECLS #endif dietlibc-0.33~cvs20120325/include/arpa/tftp.h010064400000000000000000000021141173363226000153730ustar00#ifndef _ARPA_TFTP_H #define _ARPA_TFTP_H #include #define SEGSIZE 512 /* data segment size */ #define RRQ 01 /* read request */ #define WRQ 02 /* write request */ #define DATA 03 /* data packet */ #define ACK 04 /* acknowledgement */ #define ERROR 05 /* error code */ struct tftphdr { int16_t th_opcode; /* packet type */ union { uint16_t tu_block; /* block # */ int16_t tu_code; /* error code */ char tu_stuff[1]; /* request packet stuff */ } __attribute__ ((__packed__)) th_u; char th_data[1]; /* data or error string */ } __attribute__ ((__packed__)); #define th_block th_u.tu_block #define th_code th_u.tu_code #define th_stuff th_u.tu_stuff #define th_msg th_data #define EUNDEF 0 /* not defined */ #define ENOTFOUND 1 /* file not found */ #define EACCESS 2 /* access violation */ #define ENOSPACE 3 /* disk full or allocation exceeded */ #define EBADOP 4 /* illegal TFTP operation */ #define EBADID 5 /* unknown transfer ID */ #define EEXISTS 6 /* file already exists */ #define ENOUSER 7 /* no such user */ #endif dietlibc-0.33~cvs20120325/include/asm/alpha-sigcontext.h010064400000000000000000000013711173363226500175360ustar00struct sigcontext { /* * What should we have here? I'd probably better use the same * stack layout as OSF/1, just in case we ever want to try * running their binaries.. * * This is the basic layout, but I don't know if we'll ever * actually fill in all the values.. */ long sc_onstack; long sc_mask; long sc_pc; long sc_ps; long sc_regs[32]; long sc_ownedfp; long sc_fpregs[32]; unsigned long sc_fpcr; unsigned long sc_fp_control; unsigned long sc_reserved1, sc_reserved2; unsigned long sc_ssize; char * sc_sbase; unsigned long sc_traparg_a0; unsigned long sc_traparg_a1; unsigned long sc_traparg_a2; unsigned long sc_fp_trap_pc; unsigned long sc_fp_trigger_sum; unsigned long sc_fp_trigger_inst; }; dietlibc-0.33~cvs20120325/include/asm/arm-sigcontext.h010064400000000000000000000013341173363226500172270ustar00 #define PC(ctx) (ctx.arm_pc) /* * Signal context structure - contains all info to do with the state * before the signal handler was invoked. Note: only add new entries * to the end of the structure. */ struct sigcontext { unsigned long trap_no; unsigned long error_code; unsigned long oldmask; unsigned long arm_r0; unsigned long arm_r1; unsigned long arm_r2; unsigned long arm_r3; unsigned long arm_r4; unsigned long arm_r5; unsigned long arm_r6; unsigned long arm_r7; unsigned long arm_r8; unsigned long arm_r9; unsigned long arm_r10; unsigned long arm_fp; unsigned long arm_ip; unsigned long arm_sp; unsigned long arm_lr; unsigned long arm_pc; unsigned long arm_cpsr; unsigned long fault_address; }; dietlibc-0.33~cvs20120325/include/asm/i386-sigcontext.h010064400000000000000000000025771173363226500171530ustar00#include struct _fpreg { __u16 significand[4]; __u16 exponent; }; struct _fpxreg { __u16 significand[4]; __u16 exponent; __u16 padding[3]; }; struct _xmmreg { unsigned long element[4]; }; struct _fpstate { /* Regular FPU environment */ unsigned long cw; unsigned long sw; unsigned long tag; unsigned long ipoff; unsigned long cssel; unsigned long dataoff; unsigned long datasel; struct _fpreg _st[8]; __u16 status; __u16 magic; /* 0xffff = regular FPU data only */ /* FXSR FPU environment */ unsigned long _fxsr_env[6]; /* FXSR FPU env is ignored */ unsigned long mxcsr; unsigned long reserved; struct _fpxreg _fxsr_st[8]; /* FXSR FPU reg data is ignored */ struct _xmmreg _xmm[8]; unsigned long padding[56]; }; #define X86_FXSR_MAGIC 0x0000 #define PC(ctx) (ctx.eip) struct sigcontext { __u16 gs, __gsh; __u16 fs, __fsh; __u16 es, __esh; __u16 ds, __dsh; unsigned long edi; unsigned long esi; unsigned long ebp; unsigned long esp; unsigned long ebx; unsigned long edx; unsigned long ecx; unsigned long eax; unsigned long trapno; unsigned long err; unsigned long eip; __u16 cs, __csh; unsigned long eflags; unsigned long esp_at_signal; __u16 ss, __ssh; struct _fpstate * fpstate; unsigned long oldmask; unsigned long cr2; }; dietlibc-0.33~cvs20120325/include/asm/ia64-sigcontext.h010064400000000000000000000010631173363226500172120ustar00#include #define PC(ctx) (ctx.sc_ip) struct sigcontext { unsigned long sc_flags; unsigned long sc_nat; stack_t sc_stack; unsigned long sc_ip; unsigned long sc_cfm; unsigned long sc_um; unsigned long sc_ar_rsc; unsigned long sc_ar_bsp; unsigned long sc_ar_rnat; unsigned long sc_ar_ccv; unsigned long sc_ar_unat; unsigned long sc_ar_fpsr; unsigned long sc_ar_pfs; unsigned long sc_ar_lc; unsigned long sc_pr; unsigned long sc_br[8]; unsigned long sc_gr[32]; struct ia64_fpreg sc_fr[128]; sigset_t sc_mask; }; dietlibc-0.33~cvs20120325/include/asm/mips-sigcontext.h010064400000000000000000000012661173363226500174240ustar00 /* * Keep this struct definition in sync with the sigcontext fragment * in arch/mips/tools/offset.c */ struct sigcontext { unsigned int sc_regmask; /* Unused */ unsigned int sc_status; unsigned long long sc_pc; unsigned long long sc_regs[32]; unsigned long long sc_fpregs[32]; /* Unused */ unsigned int sc_ownedfp; unsigned int sc_fpc_csr; /* Unused */ unsigned int sc_fpc_eir; /* Unused */ unsigned int sc_ssflags; /* Unused */ unsigned long long sc_mdhi; unsigned long long sc_mdlo; unsigned int sc_cause; /* Unused */ unsigned int sc_badvaddr; /* Unused */ unsigned long sc_sigset[4]; /* kernel's sigset_t */ }; dietlibc-0.33~cvs20120325/include/asm/parisc-sigcontext.h010064400000000000000000000006461173363226500177360ustar00 #define PARISC_SC_FLAG_ONSTACK 1<<0 #define PARISC_SC_FLAG_IN_SYSCALL 1<<1 /* We will add more stuff here as it becomes necessary, until we know it works. */ struct sigcontext { unsigned long sc_flags; unsigned long sc_gr[32]; /* PSW in sc_gr[0] */ unsigned long long sc_fr[32]; /* FIXME, do we need other state info? */ unsigned long sc_iasq[2]; unsigned long sc_iaoq[2]; unsigned long sc_sar; /* cr11 */ }; dietlibc-0.33~cvs20120325/include/asm/ppc-sigcontext.h010064400000000000000000000032521173363226500172330ustar00#include #ifndef ASM_PPC_SIGCONTEXT_H struct pt_regs { unsigned long gpr[32]; unsigned long nip; unsigned long msr; unsigned long orig_gpr3; /* Used for restarting system calls */ unsigned long ctr; unsigned long link; unsigned long xer; unsigned long ccr; unsigned long mq; /* 601 only (not used at present) */ /* Used on APUS to hold IPL value. */ unsigned long trap; /* Reason for being here */ unsigned long dar; /* Fault registers */ unsigned long dsisr; unsigned long result; /* Result of a system call */ }; /* * Offsets used by 'ptrace' system call interface. * These can't be changed without breaking binary compatibility * with MkLinux, etc. */ #define PT_R0 0 #define PT_R1 1 #define PT_R2 2 #define PT_R3 3 #define PT_R4 4 #define PT_R5 5 #define PT_R6 6 #define PT_R7 7 #define PT_R8 8 #define PT_R9 9 #define PT_R10 10 #define PT_R11 11 #define PT_R12 12 #define PT_R13 13 #define PT_R14 14 #define PT_R15 15 #define PT_R16 16 #define PT_R17 17 #define PT_R18 18 #define PT_R19 19 #define PT_R20 20 #define PT_R21 21 #define PT_R22 22 #define PT_R23 23 #define PT_R24 24 #define PT_R25 25 #define PT_R26 26 #define PT_R27 27 #define PT_R28 28 #define PT_R29 29 #define PT_R30 30 #define PT_R31 31 #define PT_NIP 32 #define PT_MSR 33 #define PT_CTR 35 #define PT_LNK 36 #define PT_XER 37 #define PT_CCR 38 #define PT_MQ 39 #define PT_FPR0 48 /* each FP reg occupies 2 slots in this space */ #define PT_FPR31 (PT_FPR0 + 2*31) #define PT_FPSCR (PT_FPR0 + 2*32 + 1) #define sigcontext_struct sigcontext struct sigcontext { unsigned long _unused[4]; __s32 signal; unsigned long handler; unsigned long oldmask; struct pt_regs *regs; }; #endif dietlibc-0.33~cvs20120325/include/asm/s390-sigcontext.h010064400000000000000000000016301173363226500171450ustar00#define __NUM_GPRS 16 #define __NUM_FPRS 16 #define __NUM_ACRS 16 /* Has to be at least _NSIG_WORDS from asm/signal.h */ #define _SIGCONTEXT_NSIG 64 #define _SIGCONTEXT_NSIG_BPW 64 /* Size of stack frame allocated when calling signal handler. */ #define __SIGNAL_FRAMESIZE 160 #define _SIGCONTEXT_NSIG_WORDS (_SIGCONTEXT_NSIG / _SIGCONTEXT_NSIG_BPW) #define _SIGMASK_COPY_SIZE (sizeof(unsigned long)*_SIGCONTEXT_NSIG_WORDS) typedef struct { unsigned long mask; unsigned long addr; } __attribute__ ((aligned(8))) _psw_t; typedef struct { _psw_t psw; unsigned long gprs[__NUM_GPRS]; unsigned int acrs[__NUM_ACRS]; } _s390_regs_common; typedef struct { unsigned int fpc; double fprs[__NUM_FPRS]; } _s390_fp_regs; typedef struct { _s390_regs_common regs; _s390_fp_regs fpregs; } _sigregs; struct sigcontext { unsigned long oldmask[_SIGCONTEXT_NSIG_WORDS]; _sigregs *sregs; }; dietlibc-0.33~cvs20120325/include/asm/sigcontext.h010064400000000000000000000013401173363226500164470ustar00#ifndef _ASM_SIGCONTEXT_H #define _ASM_SIGCONTEXT_H #include __BEGIN_DECLS #if defined(__i386__) #include #endif #if defined(__x86_64__) #include #endif #ifdef __sparc__ #include #endif #ifdef __mips__ #include #endif #if defined(__powerpc__) || defined(__powerpc64__) #include #endif #ifdef __alpha__ #include #endif #ifdef __arm__ #include #endif #ifdef __hppa__ #include #endif #ifdef __ia64__ #include #endif #ifdef __s390__ #include #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/asm/sparc-sigcontext.h010064400000000000000000000023621173363226500175620ustar00 #define __SUNOS_MAXWIN 31 /* This is what SunOS does, so shall I. */ struct sigcontext { int sigc_onstack; /* state to restore */ int sigc_mask; /* sigmask to restore */ int sigc_sp; /* stack pointer */ int sigc_pc; /* program counter */ int sigc_npc; /* next program counter */ int sigc_psr; /* for condition codes etc */ int sigc_g1; /* User uses these two registers */ int sigc_o0; /* within the trampoline code. */ /* Now comes information regarding the users window set * at the time of the signal. */ int sigc_oswins; /* outstanding windows */ /* stack ptrs for each regwin buf */ char *sigc_spbuf[__SUNOS_MAXWIN]; /* Windows to restore after signal */ struct { unsigned long locals[8]; unsigned long ins[8]; } sigc_wbuf[__SUNOS_MAXWIN]; }; typedef struct { struct { unsigned long psr; unsigned long pc; unsigned long npc; unsigned long y; unsigned long u_regs[16]; /* globals and ins */ } si_regs; int si_mask; } __siginfo_t; typedef struct { unsigned long si_float_regs [32]; unsigned long si_fsr; unsigned long si_fpqdepth; struct { unsigned long *insn_addr; unsigned long insn; } si_fpqueue [16]; } __siginfo_fpu_t; dietlibc-0.33~cvs20120325/include/asm/statfs.h010064400000000000000000000000251173363226500155630ustar00#include dietlibc-0.33~cvs20120325/include/asm/types.h010064400000000000000000000015631173363226500154330ustar00#ifndef _ASM_TYPES_H #define _ASM_TYPES_H #include #include __BEGIN_DECLS #ifdef __alpha__ typedef uint32_t umode_t; #else typedef uint16_t umode_t; #endif typedef uint8_t __u8; typedef uint16_t __u16; typedef uint32_t __u32; #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef uint64_t __u64; #endif typedef int8_t __s8; typedef int16_t __s16; typedef int32_t __s32; #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef int64_t __s64; #endif #if defined(__s390__) || (__WORDSIZE==64) typedef unsigned long __kernel_size_t; #else typedef uint32_t __kernel_size_t; #endif #define __force typedef uint16_t __le16; typedef uint16_t __be16; typedef uint32_t __le32; typedef uint32_t __be32; typedef uint64_t __le64; typedef uint64_t __be64; typedef uint16_t __sum16; typedef uint32_t __wsum; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/asm/x86_64-sigcontext.h010064400000000000000000000021571173363226500174120ustar00#include /* FXSAVE frame */ /* Note: reserved1/2 may someday contain valuable data. Always save/restore them when you change signal frames. */ struct _fpstate { __u16 cwd; __u16 swd; __u16 twd; /* Note this is not the same as the 32bit/x87/FSAVE twd */ __u16 fop; __u64 rip; __u64 rdp; __u32 mxcsr; __u32 mxcsr_mask; __u32 st_space[32]; /* 8*16 bytes for each FP-reg */ __u32 xmm_space[64]; /* 16*16 bytes for each XMM-reg */ __u32 reserved2[24]; }; struct sigcontext { unsigned long r8; unsigned long r9; unsigned long r10; unsigned long r11; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long rdi; unsigned long rsi; unsigned long rbp; unsigned long rbx; unsigned long rdx; unsigned long rax; unsigned long rcx; unsigned long rsp; unsigned long rip; unsigned long eflags; /* RFLAGS */ __u16 cs; __u16 gs; __u16 fs; __u16 __pad0; unsigned long err; unsigned long trapno; unsigned long oldmask; unsigned long cr2; struct _fpstate *fpstate; /* zero when no FPU context */ unsigned long reserved1[8]; }; dietlibc-0.33~cvs20120325/include/assert.h010064400000000000000000000017731173363226000150060ustar00#ifndef _ASSERT_H #define _ASSERT_H #include __BEGIN_DECLS #ifdef __PRETTY_FUNCTION__ #define __ASSERT_FUNCTION __PRETTY_FUNCTION__ #else # if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L # define __ASSERT_FUNCTION __func__ # else # define __ASSERT_FUNCTION ((const char *) 0) # endif #endif #undef assert #ifdef NDEBUG #define assert(expr) ((void)0) #else /* This prints an "Assertion failed" message and aborts. */ extern void __assert_fail (const char *__assertion, const char *__file, unsigned int __line, const char *__function) __THROW __attribute__ ((__noreturn__)); #ifdef expect # define assert(expr) \ ((void) (expect((long)(expr),0) ? 0 : \ (__assert_fail (#expr, \ __FILE__, __LINE__, __ASSERT_FUNCTION), 0))) #else # define assert(expr) \ ((void) ((expr) ? 0 : \ (__assert_fail (#expr, \ __FILE__, __LINE__, __ASSERT_FUNCTION), 0))) #endif #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/attr/xattr.h010064400000000000000000000021271173363226500156200ustar00#ifndef _ATTR_XATTR_H #define _ATTR_XATTR_H #include #include enum { XATTR_CREATE=1, XATTR_REPLACE=2 }; #define XATTR_CREATE XATTR_CREATE #define XATTR_REPLACE XATTR_REPLACE #define XATTR_SECURITY_PREFIX "security." int setxattr(const char *path, const char *name, const void *value, size_t size, int flags); int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags); int fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags); ssize_t getxattr(const char *path, const char *name, void *value, size_t size); ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size); ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size); ssize_t listxattr(const char *path, char *list, size_t size); ssize_t llistxattr(const char *path, char *list, size_t size); ssize_t flistxattr(int filedes, char *list, size_t size); int removexattr(const char *path, const char *name); int lremovexattr(const char *path, const char *name); int fremovexattr(int filedes, const char *name); #endif dietlibc-0.33~cvs20120325/include/byteswap.h010064400000000000000000000007231173363226000153350ustar00#ifndef _BYTESWAP_H #define _BYTESWAP_H #warning "byteswap.h is an unportable GNU extension! Don't use!" static inline unsigned short bswap_16(unsigned short x) { return (x>>8) | (x<<8); } static inline unsigned int bswap_32(unsigned int x) { return (bswap_16(x&0xffff)<<16) | (bswap_16(x>>16)); } static inline unsigned long long bswap_64(unsigned long long x) { return (((unsigned long long)bswap_32(x&0xffffffffull))<<32) | (bswap_32(x>>32)); } #endif dietlibc-0.33~cvs20120325/include/clocale010064400000000000000000000007051173363226000146530ustar00#ifndef __DIETLIBC_CLOCALE_INCLUDED #define __DIETLIBC_CLOCALE_INCLUDED #include #include struct __locale_struct { struct locale_data *__locales[13]; const uint16_t *__ctype_b; const int32_t *__ctype_tolower; const int32_t *__ctype_toupper; const char *__names[13]; }; typedef struct __locale_struct *__locale_t; namespace std { using ::lconv; using ::localeconv; using ::setlocale; } #endif dietlibc-0.33~cvs20120325/include/cpio.h010064400000000000000000000010641173363226000144300ustar00#ifndef _CPIO_H_ #define _CPIO_H_ #define C_IRUSR 0000400 #define C_IWUSR 0000200 #define C_IXUSR 0000100 #define C_IRGRP 0000040 #define C_IWGRP 0000020 #define C_IXGRP 0000010 #define C_IROTH 0000004 #define C_IWOTH 0000002 #define C_IXOTH 0000001 #define C_ISUID 0004000 #define C_ISGID 0002000 #define C_ISVTX 0001000 #define C_ISDIR 0040000 #define C_ISFIFO 0010000 #define C_ISREG 0100000 #define C_ISBLK 0060000 #define C_ISCHR 0020000 #define C_ISCTG 0110000 #define C_ISLNK 0120000 #define C_ISSOCK 0140000 #define MAGIC "070707" #endif /* _CPIO_H_ */ dietlibc-0.33~cvs20120325/include/cstddef010064400000000000000000000004071173363226000146640ustar00#ifndef __DIETLIBC_CSTDDEF_INCLUDED #define __DIETLIBC_CSTDDEF_INCLUDED #include #if defined(__WINT_TYPE__) typedef __WINT_TYPE__ wint_t; #else typedef unsigned int wint_t; #endif namespace std { using ::ptrdiff_t; using ::size_t; } #endif dietlibc-0.33~cvs20120325/include/cstdlib010064400000000000000000000010601173363226000146700ustar00#ifndef __DIETLIBC_CSTDLIB_INCLUDED #define __DIETLIBC_CSTDLIB_INCLUDED #include namespace std { using ::div_t; using ::abort; using ::abs; using ::atexit; using ::atof; using ::atoi; using ::atol; using ::bsearch; using ::calloc; using ::div; using ::exit; using ::free; using ::getenv; using ::labs; using ::malloc; using ::qsort; using ::rand; using ::realloc; using ::srand; using ::strtod; using ::strtol; using ::strtoul; using ::system; } #endif dietlibc-0.33~cvs20120325/include/ctype.h010064400000000000000000000021731173363226000146240ustar00#ifndef _CTYPE_H #define _CTYPE_H #include __BEGIN_DECLS extern int isascii (int c) __THROW __attribute__ ((__const__)); extern int isblank (int c) __THROW __attribute__ ((__const__)); extern int isalnum (int c) __THROW __attribute__ ((__const__)); extern int isalpha (int c) __THROW __attribute__ ((__const__)); extern int isdigit (int c) __THROW __attribute__ ((__const__)); extern int isspace (int c) __THROW __attribute__ ((__const__)); extern int isupper (int c) __THROW __attribute__ ((__const__)); extern int islower (int c) __THROW __attribute__ ((__const__)); extern int toascii(int c) __THROW __attribute__ ((__const__)); extern int tolower(int c) __THROW __attribute__ ((__const__)); extern int toupper(int c) __THROW __attribute__ ((__const__)); extern int isprint(int c) __THROW __attribute__ ((__const__)); extern int ispunct(int c) __THROW __attribute__ ((__const__)); extern int iscntrl(int c) __THROW __attribute__ ((__const__)); /* fscking GNU extensions! */ extern int isxdigit(int c) __THROW __attribute__ ((__const__)); extern int isgraph(int c) __THROW __attribute__ ((__const__)); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/cwchar010064400000000000000000000014711173363226000145210ustar00#ifndef __DIETLIBC_CWCHAR_INCLUDED #define __DIETLIBC_CWCHAR_INCLUDED #include #if !defined(WEOF) # define WEOF (-1) #endif extern "C" { // dummy type typedef struct { int __count; union { wint_t __wch; char __wchb[4]; } __value; } mbstate_t; // dummy functions - not implemented size_t wcslen(const wchar_t *); wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); int wmemcmp(const wchar_t *, const wchar_t *, size_t); wchar_t *wmemcpy(wchar_t *, const wchar_t *, size_t); wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); wchar_t *wmemset(wchar_t *, wchar_t, size_t); } namespace std { using ::mbstate_t; using ::wint_t; using ::wcslen; using ::wmemchr; using ::wmemcmp; using ::wmemcpy; using ::wmemmove; using ::wmemset; } #endif dietlibc-0.33~cvs20120325/include/cwctype010064400000000000000000000025261173363226000147320ustar00#ifndef __DIETLIBC_CWCTYPE_INCLUDED #define __DIETLIBC_CWCTYPE_INCLUDED #include #include #include #include #if __BYTE_ORDER == __BIG_ENDIAN # define _ISbit(bit) (1 << (bit)) #else # define _ISbit(bit) ((bit) < 8 ? ((1 << (bit)) << 8) : ((1 << (bit)) >> 8)) #endif enum { _ISupper = _ISbit (0), /* UPPERCASE. */ _ISlower = _ISbit (1), /* lowercase. */ _ISalpha = _ISbit (2), /* Alphabetic. */ _ISdigit = _ISbit (3), /* Numeric. */ _ISxdigit = _ISbit (4), /* Hexadecimal numeric. */ _ISspace = _ISbit (5), /* Whitespace. */ _ISprint = _ISbit (6), /* Printing. */ _ISgraph = _ISbit (7), /* Graphical. */ _ISblank = _ISbit (8), /* Blank (usually SPC and TAB). */ _IScntrl = _ISbit (9), /* Control character. */ _ISpunct = _ISbit (10), /* Punctuation. */ _ISalnum = _ISbit (11) /* Alphanumeric. */ }; namespace std { using ::wctype_t; using ::wctrans_t; using ::wint_t; using ::iswalnum; using ::iswalpha; using ::iswblank; using ::iswcntrl; using ::iswctype; using ::iswdigit; using ::iswgraph; using ::iswlower; using ::iswprint; using ::iswpunct; using ::iswspace; using ::iswupper; using ::iswxdigit; using ::towctrans; using ::towlower; using ::towupper; using ::wctrans; using ::wctype; } #endif dietlibc-0.33~cvs20120325/include/daemon.h010064400000000000000000000001011173363226000147300ustar00#ifndef _DAEMON_H #define _DAEMON_H #include #endif dietlibc-0.33~cvs20120325/include/dietref.h010064400000000000000000000010541173363226000151170ustar00/* diet includes this file to create linker dependencies on the diet * libc, so trying to link an object file compiled with diet against * glibc will fail. */ #ifndef NODIETREF #ifdef __ASSEMBLER__ #include .section .note .long 4 .long 2f-1f .long 0 .ascii "diet" 1: #if (__WORDSIZE == 64) .quad __you_tried_to_link_a_dietlibc_object_against_glibc #else .long __you_tried_to_link_a_dietlibc_object_against_glibc #endif 2: .previous #else #include __dietref("__you_tried_to_link_a_dietlibc_object_against_glibc"); #endif #endif dietlibc-0.33~cvs20120325/include/dietrefdef.h010064400000000000000000000005351173363226000156010ustar00#ifndef __DIETREFDEF_H__ #include #if (__WORDSIZE == 64) #define __DIETREFDEF_H__ ".quad" #else #define __DIETREFDEF_H__ ".long" #endif #define __dietref(name) \ __asm__(".section .note\n" \ "\t.long 4\n" \ "\t.long 2f-1f\n" \ "\t.long 0\n" \ "\t.ascii \"diet\"\n" \ "1:\t" __DIETREFDEF_H__ " " name "\n2:" \ ".previous") #endif dietlibc-0.33~cvs20120325/include/dirent.h010064400000000000000000000046041173363226000147660ustar00#ifndef _DIRENT_H #define _DIRENT_H 1 #include #include #include __BEGIN_DECLS struct dirent { long d_ino; off_t d_off; uint16_t d_reclen; char d_name[256]; /* We must not include limits.h! */ }; #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L struct dirent64 { uint64_t d_ino; int64_t d_off; uint16_t d_reclen; unsigned char d_type; char d_name[256]; }; #endif #define d_fileno d_ino /* Backwards compatibility. */ #undef _DIRENT_HAVE_D_NAMLEN #define _DIRENT_HAVE_D_RECLEN #define _DIRENT_HAVE_D_OFF typedef struct __dirstream DIR; DIR *opendir (const char *__name) __THROW; DIR *fdopendir (int fd) __THROW; int closedir (DIR *__dirp) __THROW; struct dirent *readdir (DIR *__dirp) __THROW; struct dirent64 *readdir64 (DIR *__dirp) __THROW; void rewinddir (DIR *__dirp) __THROW; void seekdir (DIR *__dirp, long int __pos) __THROW; long int telldir (DIR *__dirp) __THROW; int scandir(const char *dir, struct dirent ***namelist, int (*selection)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); int scandir64(const char *dir, struct dirent64 ***namelist, int (*selection)(const struct dirent64 *), int (*compar)(const struct dirent64 **, const struct dirent64 **)); int alphasort(const struct dirent **a, const struct dirent **b) __THROW __attribute__((const)); int alphasort64(const struct dirent64 **a, const struct dirent64 **b) __THROW __attribute__((const)); #define MAXNAMLEN NAME_MAX #ifdef _BSD_SOURCE extern int dirfd(DIR *dirp) __THROW __attribute_dontuse__; #endif #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define dirent dirent64 #define readdir readdir64 #define scandir scandir64 #define alphasort alphasort64 #endif #ifdef _BSD_SOURCE /* File types for `d_type'. */ enum { DT_UNKNOWN = 0, # define DT_UNKNOWN DT_UNKNOWN DT_FIFO = 1, # define DT_FIFO DT_FIFO DT_CHR = 2, # define DT_CHR DT_CHR DT_DIR = 4, # define DT_DIR DT_DIR DT_BLK = 6, # define DT_BLK DT_BLK DT_REG = 8, # define DT_REG DT_REG DT_LNK = 10, # define DT_LNK DT_LNK DT_SOCK = 12, # define DT_SOCK DT_SOCK DT_WHT = 14 # define DT_WHT DT_WHT }; /* Convert between stat structure types and directory types. */ # define IFTODT(mode) (((mode) & 0170000) >> 12) # define DTTOIF(dirtype) ((dirtype) << 12) #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/dlfcn.h010064400000000000000000000011271173363226000145640ustar00#ifndef _DLFCN_H #define _DLFCN_H 1 #include #define RTLD_LAZY 0x00000 #define RTLD_NOW 0x00001 #define RTLD_LOCAL 0x00000 #define RTLD_GLOBAL 0x10000 #define RTLD_DEFAULT ((void*)1) #define RTLD_NEXT ((void*)2) __BEGIN_DECLS void *dlopen (const char *filename, int flag); const char *dlerror(void); void *dlsym(void *handle, const char *symbol); int dlclose (void *handle); #ifdef _GNU_SOURCE typedef struct { const char *dli_fname; void *dli_fbase; const char *dli_sname; void *dli_saddr; } Dl_info; int dladdr(void *addr, Dl_info *info); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/elf.h010064400000000000000000003054601173363226500142600ustar00#ifndef _ELF_H #define _ELF_H 1 /* Standard ELF types. */ #include #include __BEGIN_DECLS /* Type for a 16-bit quantity. */ typedef uint16_t Elf32_Half; typedef uint16_t Elf64_Half; /* Types for signed and unsigned 32-bit quantities. */ typedef uint32_t Elf32_Word; typedef int32_t Elf32_Sword; typedef uint32_t Elf64_Word; typedef int32_t Elf64_Sword; /* Types for signed and unsigned 64-bit quantities. */ typedef uint64_t Elf32_Xword; typedef int64_t Elf32_Sxword; typedef uint64_t Elf64_Xword; typedef int64_t Elf64_Sxword; /* Type of addresses. */ typedef uint32_t Elf32_Addr; typedef uint64_t Elf64_Addr; /* Type of file offsets. */ typedef uint32_t Elf32_Off; typedef uint64_t Elf64_Off; /* Type for section indices, which are 16-bit quantities. */ typedef uint16_t Elf32_Section; typedef uint16_t Elf64_Section; /* Type for version symbol information. */ typedef Elf32_Half Elf32_Versym; typedef Elf64_Half Elf64_Versym; /* The ELF file header. This appears at the start of every ELF file. */ #define EI_NIDENT (16) typedef struct { unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ Elf32_Half e_type; /* Object file type */ Elf32_Half e_machine; /* Architecture */ Elf32_Word e_version; /* Object file version */ Elf32_Addr e_entry; /* Entry point virtual address */ Elf32_Off e_phoff; /* Program header table file offset */ Elf32_Off e_shoff; /* Section header table file offset */ Elf32_Word e_flags; /* Processor-specific flags */ Elf32_Half e_ehsize; /* ELF header size in bytes */ Elf32_Half e_phentsize; /* Program header table entry size */ Elf32_Half e_phnum; /* Program header table entry count */ Elf32_Half e_shentsize; /* Section header table entry size */ Elf32_Half e_shnum; /* Section header table entry count */ Elf32_Half e_shstrndx; /* Section header string table index */ } Elf32_Ehdr; typedef struct { unsigned char e_ident[EI_NIDENT]; /* Magic number and other info */ Elf64_Half e_type; /* Object file type */ Elf64_Half e_machine; /* Architecture */ Elf64_Word e_version; /* Object file version */ Elf64_Addr e_entry; /* Entry point virtual address */ Elf64_Off e_phoff; /* Program header table file offset */ Elf64_Off e_shoff; /* Section header table file offset */ Elf64_Word e_flags; /* Processor-specific flags */ Elf64_Half e_ehsize; /* ELF header size in bytes */ Elf64_Half e_phentsize; /* Program header table entry size */ Elf64_Half e_phnum; /* Program header table entry count */ Elf64_Half e_shentsize; /* Section header table entry size */ Elf64_Half e_shnum; /* Section header table entry count */ Elf64_Half e_shstrndx; /* Section header string table index */ } Elf64_Ehdr; /* Fields in the e_ident array. The EI_* macros are indices into the array. The macros under each EI_* macro are the values the byte may have. */ #define EI_MAG0 0 /* File identification byte 0 index */ #define ELFMAG0 0x7f /* Magic number byte 0 */ #define EI_MAG1 1 /* File identification byte 1 index */ #define ELFMAG1 'E' /* Magic number byte 1 */ #define EI_MAG2 2 /* File identification byte 2 index */ #define ELFMAG2 'L' /* Magic number byte 2 */ #define EI_MAG3 3 /* File identification byte 3 index */ #define ELFMAG3 'F' /* Magic number byte 3 */ /* Conglomeration of the identification bytes, for easy testing as a word. */ #define ELFMAG "\177ELF" #define SELFMAG 4 #define EI_CLASS 4 /* File class byte index */ #define ELFCLASSNONE 0 /* Invalid class */ #define ELFCLASS32 1 /* 32-bit objects */ #define ELFCLASS64 2 /* 64-bit objects */ #define ELFCLASSNUM 3 #define EI_DATA 5 /* Data encoding byte index */ #define ELFDATANONE 0 /* Invalid data encoding */ #define ELFDATA2LSB 1 /* 2's complement, little endian */ #define ELFDATA2MSB 2 /* 2's complement, big endian */ #define ELFDATANUM 3 #define EI_VERSION 6 /* File version byte index */ /* Value must be EV_CURRENT */ #define EI_OSABI 7 /* OS ABI identification */ #define ELFOSABI_NONE 0 /* UNIX System V ABI */ #define ELFOSABI_SYSV 0 /* Alias. */ #define ELFOSABI_HPUX 1 /* HP-UX */ #define ELFOSABI_NETBSD 2 /* NetBSD. */ #define ELFOSABI_LINUX 3 /* Linux. */ #define ELFOSABI_SOLARIS 6 /* Sun Solaris. */ #define ELFOSABI_AIX 7 /* IBM AIX. */ #define ELFOSABI_IRIX 8 /* SGI Irix. */ #define ELFOSABI_FREEBSD 9 /* FreeBSD. */ #define ELFOSABI_TRU64 10 /* Compaq TRU64 UNIX. */ #define ELFOSABI_MODESTO 11 /* Novell Modesto. */ #define ELFOSABI_OPENBSD 12 /* OpenBSD. */ #define ELFOSABI_ARM 97 /* ARM */ #define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */ #define EI_ABIVERSION 8 /* ABI version */ #define EI_PAD 9 /* Byte index of padding bytes */ /* Legal values for e_type (object file type). */ #define ET_NONE 0 /* No file type */ #define ET_REL 1 /* Relocatable file */ #define ET_EXEC 2 /* Executable file */ #define ET_DYN 3 /* Shared object file */ #define ET_CORE 4 /* Core file */ #define ET_NUM 5 /* Number of defined types */ #define ET_LOOS 0xfe00 /* OS-specific range start */ #define ET_HIOS 0xfeff /* OS-specific range end */ #define ET_LOPROC 0xff00 /* Processor-specific range start */ #define ET_HIPROC 0xffff /* Processor-specific range end */ /* Legal values for e_machine (architecture). */ #define EM_NONE 0 /* No machine */ #define EM_M32 1 /* AT&T WE 32100 */ #define EM_SPARC 2 /* SUN SPARC */ #define EM_386 3 /* Intel 80386 */ #define EM_68K 4 /* Motorola m68k family */ #define EM_88K 5 /* Motorola m88k family */ #define EM_860 7 /* Intel 80860 */ #define EM_MIPS 8 /* MIPS R3000 big-endian */ #define EM_S370 9 /* IBM System/370 */ #define EM_MIPS_RS3_LE 10 /* MIPS R3000 little-endian */ #define EM_PARISC 15 /* HPPA */ #define EM_VPP500 17 /* Fujitsu VPP500 */ #define EM_SPARC32PLUS 18 /* Sun's "v8plus" */ #define EM_960 19 /* Intel 80960 */ #define EM_PPC 20 /* PowerPC */ #define EM_PPC64 21 /* PowerPC 64-bit */ #define EM_S390 22 /* IBM S390 */ #define EM_V800 36 /* NEC V800 series */ #define EM_FR20 37 /* Fujitsu FR20 */ #define EM_RH32 38 /* TRW RH-32 */ #define EM_RCE 39 /* Motorola RCE */ #define EM_ARM 40 /* ARM */ #define EM_FAKE_ALPHA 41 /* Digital Alpha */ #define EM_SH 42 /* Hitachi SH */ #define EM_SPARCV9 43 /* SPARC v9 64-bit */ #define EM_TRICORE 44 /* Siemens Tricore */ #define EM_ARC 45 /* Argonaut RISC Core */ #define EM_H8_300 46 /* Hitachi H8/300 */ #define EM_H8_300H 47 /* Hitachi H8/300H */ #define EM_H8S 48 /* Hitachi H8S */ #define EM_H8_500 49 /* Hitachi H8/500 */ #define EM_IA_64 50 /* Intel Merced */ #define EM_MIPS_X 51 /* Stanford MIPS-X */ #define EM_COLDFIRE 52 /* Motorola Coldfire */ #define EM_68HC12 53 /* Motorola M68HC12 */ #define EM_MMA 54 /* Fujitsu MMA Multimedia Accelerator*/ #define EM_PCP 55 /* Siemens PCP */ #define EM_NCPU 56 /* Sony nCPU embeeded RISC */ #define EM_NDR1 57 /* Denso NDR1 microprocessor */ #define EM_STARCORE 58 /* Motorola Start*Core processor */ #define EM_ME16 59 /* Toyota ME16 processor */ #define EM_ST100 60 /* STMicroelectronic ST100 processor */ #define EM_TINYJ 61 /* Advanced Logic Corp. Tinyj emb.fam*/ #define EM_X86_64 62 /* AMD x86-64 architecture */ #define EM_PDSP 63 /* Sony DSP Processor */ #define EM_FX66 66 /* Siemens FX66 microcontroller */ #define EM_ST9PLUS 67 /* STMicroelectronics ST9+ 8/16 mc */ #define EM_ST7 68 /* STmicroelectronics ST7 8 bit mc */ #define EM_68HC16 69 /* Motorola MC68HC16 microcontroller */ #define EM_68HC11 70 /* Motorola MC68HC11 microcontroller */ #define EM_68HC08 71 /* Motorola MC68HC08 microcontroller */ #define EM_68HC05 72 /* Motorola MC68HC05 microcontroller */ #define EM_SVX 73 /* Silicon Graphics SVx */ #define EM_ST19 74 /* STMicroelectronics ST19 8 bit mc */ #define EM_VAX 75 /* Digital VAX */ #define EM_CRIS 76 /* Axis Communications 32-bit embedded processor */ #define EM_JAVELIN 77 /* Infineon Technologies 32-bit embedded processor */ #define EM_FIREPATH 78 /* Element 14 64-bit DSP Processor */ #define EM_ZSP 79 /* LSI Logic 16-bit DSP Processor */ #define EM_MMIX 80 /* Donald Knuth's educational 64-bit processor */ #define EM_HUANY 81 /* Harvard University machine-independent object files */ #define EM_PRISM 82 /* SiTera Prism */ #define EM_AVR 83 /* Atmel AVR 8-bit microcontroller */ #define EM_FR30 84 /* Fujitsu FR30 */ #define EM_D10V 85 /* Mitsubishi D10V */ #define EM_D30V 86 /* Mitsubishi D30V */ #define EM_V850 87 /* NEC v850 */ #define EM_M32R 88 /* Mitsubishi M32R */ #define EM_MN10300 89 /* Matsushita MN10300 */ #define EM_MN10200 90 /* Matsushita MN10200 */ #define EM_PJ 91 /* picoJava */ #define EM_OPENRISC 92 /* OpenRISC 32-bit embedded processor */ #define EM_ARC_A5 93 /* ARC Cores Tangent-A5 */ #define EM_XTENSA 94 /* Tensilica Xtensa Architecture */ #define EM_NUM 95 /* If it is necessary to assign new unofficial EM_* values, please pick large random numbers (0x8523, 0xa7f2, etc.) to minimize the chances of collision with official or non-GNU unofficial values. */ #define EM_ALPHA 0x9026 /* Legal values for e_version (version). */ #define EV_NONE 0 /* Invalid ELF version */ #define EV_CURRENT 1 /* Current version */ #define EV_NUM 2 /* Section header. */ typedef struct { Elf32_Word sh_name; /* Section name (string tbl index) */ Elf32_Word sh_type; /* Section type */ Elf32_Word sh_flags; /* Section flags */ Elf32_Addr sh_addr; /* Section virtual addr at execution */ Elf32_Off sh_offset; /* Section file offset */ Elf32_Word sh_size; /* Section size in bytes */ Elf32_Word sh_link; /* Link to another section */ Elf32_Word sh_info; /* Additional section information */ Elf32_Word sh_addralign; /* Section alignment */ Elf32_Word sh_entsize; /* Entry size if section holds table */ } Elf32_Shdr; typedef struct { Elf64_Word sh_name; /* Section name (string tbl index) */ Elf64_Word sh_type; /* Section type */ Elf64_Xword sh_flags; /* Section flags */ Elf64_Addr sh_addr; /* Section virtual addr at execution */ Elf64_Off sh_offset; /* Section file offset */ Elf64_Xword sh_size; /* Section size in bytes */ Elf64_Word sh_link; /* Link to another section */ Elf64_Word sh_info; /* Additional section information */ Elf64_Xword sh_addralign; /* Section alignment */ Elf64_Xword sh_entsize; /* Entry size if section holds table */ } Elf64_Shdr; /* Special section indices. */ #define SHN_UNDEF 0 /* Undefined section */ #define SHN_LORESERVE 0xff00 /* Start of reserved indices */ #define SHN_LOPROC 0xff00 /* Start of processor-specific */ #define SHN_HIPROC 0xff1f /* End of processor-specific */ #define SHN_LOOS 0xff20 /* Start of OS-specific */ #define SHN_HIOS 0xff3f /* End of OS-specific */ #define SHN_ABS 0xfff1 /* Associated symbol is absolute */ #define SHN_COMMON 0xfff2 /* Associated symbol is common */ #define SHN_XINDEX 0xffff /* Index is in extra table. */ #define SHN_HIRESERVE 0xffff /* End of reserved indices */ /* Legal values for sh_type (section type). */ #define SHT_NULL 0 /* Section header table entry unused */ #define SHT_PROGBITS 1 /* Program data */ #define SHT_SYMTAB 2 /* Symbol table */ #define SHT_STRTAB 3 /* String table */ #define SHT_RELA 4 /* Relocation entries with addends */ #define SHT_HASH 5 /* Symbol hash table */ #define SHT_DYNAMIC 6 /* Dynamic linking information */ #define SHT_NOTE 7 /* Notes */ #define SHT_NOBITS 8 /* Program space with no data (bss) */ #define SHT_REL 9 /* Relocation entries, no addends */ #define SHT_SHLIB 10 /* Reserved */ #define SHT_DYNSYM 11 /* Dynamic linker symbol table */ #define SHT_INIT_ARRAY 14 /* Array of constructors */ #define SHT_FINI_ARRAY 15 /* Array of destructors */ #define SHT_PREINIT_ARRAY 16 /* Array of pre-constructors */ #define SHT_GROUP 17 /* Section group */ #define SHT_SYMTAB_SHNDX 18 /* Extended section indeces */ #define SHT_NUM 19 /* Number of defined types. */ #define SHT_LOOS 0x60000000 /* Start OS-specific */ #define SHT_GNU_LIBLIST 0x6ffffff7 /* Prelink library list */ #define SHT_CHECKSUM 0x6ffffff8 /* Checksum for DSO content. */ #define SHT_LOSUNW 0x6ffffffa /* Sun-specific low bound. */ #define SHT_SUNW_move 0x6ffffffa #define SHT_SUNW_COMDAT 0x6ffffffb #define SHT_SUNW_syminfo 0x6ffffffc #define SHT_GNU_verdef 0x6ffffffd /* Version definition section. */ #define SHT_GNU_verneed 0x6ffffffe /* Version needs section. */ #define SHT_GNU_versym 0x6fffffff /* Version symbol table. */ #define SHT_HISUNW 0x6fffffff /* Sun-specific high bound. */ #define SHT_HIOS 0x6fffffff /* End OS-specific type */ #define SHT_LOPROC 0x70000000 /* Start of processor-specific */ #define SHT_HIPROC 0x7fffffff /* End of processor-specific */ #define SHT_LOUSER 0x80000000 /* Start of application-specific */ #define SHT_HIUSER 0x8fffffff /* End of application-specific */ /* Legal values for sh_flags (section flags). */ #define SHF_WRITE (1 << 0) /* Writable */ #define SHF_ALLOC (1 << 1) /* Occupies memory during execution */ #define SHF_EXECINSTR (1 << 2) /* Executable */ #define SHF_MERGE (1 << 4) /* Might be merged */ #define SHF_STRINGS (1 << 5) /* Contains nul-terminated strings */ #define SHF_INFO_LINK (1 << 6) /* `sh_info' contains SHT index */ #define SHF_LINK_ORDER (1 << 7) /* Preserve order after combining */ #define SHF_OS_NONCONFORMING (1 << 8) /* Non-standard OS specific handling required */ #define SHF_GROUP (1 << 9) /* Section is member of a group. */ #define SHF_TLS (1 << 10) /* Section hold thread-local data. */ #define SHF_MASKOS 0x0ff00000 /* OS-specific. */ #define SHF_MASKPROC 0xf0000000 /* Processor-specific */ /* Section group handling. */ #define GRP_COMDAT 0x1 /* Mark group as COMDAT. */ /* Symbol table entry. */ typedef struct { Elf32_Word st_name; /* Symbol name (string tbl index) */ Elf32_Addr st_value; /* Symbol value */ Elf32_Word st_size; /* Symbol size */ unsigned char st_info; /* Symbol type and binding */ unsigned char st_other; /* Symbol visibility */ Elf32_Section st_shndx; /* Section index */ } Elf32_Sym; typedef struct { Elf64_Word st_name; /* Symbol name (string tbl index) */ unsigned char st_info; /* Symbol type and binding */ unsigned char st_other; /* Symbol visibility */ Elf64_Section st_shndx; /* Section index */ Elf64_Addr st_value; /* Symbol value */ Elf64_Xword st_size; /* Symbol size */ } Elf64_Sym; /* The syminfo section if available contains additional information about every dynamic symbol. */ typedef struct { Elf32_Half si_boundto; /* Direct bindings, symbol bound to */ Elf32_Half si_flags; /* Per symbol flags */ } Elf32_Syminfo; typedef struct { Elf64_Half si_boundto; /* Direct bindings, symbol bound to */ Elf64_Half si_flags; /* Per symbol flags */ } Elf64_Syminfo; /* Possible values for si_boundto. */ #define SYMINFO_BT_SELF 0xffff /* Symbol bound to self */ #define SYMINFO_BT_PARENT 0xfffe /* Symbol bound to parent */ #define SYMINFO_BT_LOWRESERVE 0xff00 /* Beginning of reserved entries */ /* Possible bitmasks for si_flags. */ #define SYMINFO_FLG_DIRECT 0x0001 /* Direct bound symbol */ #define SYMINFO_FLG_PASSTHRU 0x0002 /* Pass-thru symbol for translator */ #define SYMINFO_FLG_COPY 0x0004 /* Symbol is a copy-reloc */ #define SYMINFO_FLG_LAZYLOAD 0x0008 /* Symbol bound to object to be lazy loaded */ /* Syminfo version values. */ #define SYMINFO_NONE 0 #define SYMINFO_CURRENT 1 #define SYMINFO_NUM 2 /* How to extract and insert information held in the st_info field. */ #define ELF32_ST_BIND(val) (((unsigned char) (val)) >> 4) #define ELF32_ST_TYPE(val) ((val) & 0xf) #define ELF32_ST_INFO(bind, type) (((bind) << 4) + ((type) & 0xf)) /* Both Elf32_Sym and Elf64_Sym use the same one-byte st_info field. */ #define ELF64_ST_BIND(val) ELF32_ST_BIND (val) #define ELF64_ST_TYPE(val) ELF32_ST_TYPE (val) #define ELF64_ST_INFO(bind, type) ELF32_ST_INFO ((bind), (type)) /* Legal values for ST_BIND subfield of st_info (symbol binding). */ #define STB_LOCAL 0 /* Local symbol */ #define STB_GLOBAL 1 /* Global symbol */ #define STB_WEAK 2 /* Weak symbol */ #define STB_NUM 3 /* Number of defined types. */ #define STB_LOOS 10 /* Start of OS-specific */ #define STB_HIOS 12 /* End of OS-specific */ #define STB_LOPROC 13 /* Start of processor-specific */ #define STB_HIPROC 15 /* End of processor-specific */ /* Legal values for ST_TYPE subfield of st_info (symbol type). */ #define STT_NOTYPE 0 /* Symbol type is unspecified */ #define STT_OBJECT 1 /* Symbol is a data object */ #define STT_FUNC 2 /* Symbol is a code object */ #define STT_SECTION 3 /* Symbol associated with a section */ #define STT_FILE 4 /* Symbol's name is file name */ #define STT_COMMON 5 /* Symbol is a common data object */ #define STT_TLS 6 /* Symbol is thread-local data object*/ #define STT_NUM 7 /* Number of defined types. */ #define STT_LOOS 10 /* Start of OS-specific */ #define STT_HIOS 12 /* End of OS-specific */ #define STT_LOPROC 13 /* Start of processor-specific */ #define STT_HIPROC 15 /* End of processor-specific */ /* Symbol table indices are found in the hash buckets and chain table of a symbol hash table section. This special index value indicates the end of a chain, meaning no further symbols are found in that bucket. */ #define STN_UNDEF 0 /* End of a chain. */ /* How to extract and insert information held in the st_other field. */ #define ELF32_ST_VISIBILITY(o) ((o) & 0x03) /* For ELF64 the definitions are the same. */ #define ELF64_ST_VISIBILITY(o) ELF32_ST_VISIBILITY (o) /* Symbol visibility specification encoded in the st_other field. */ #define STV_DEFAULT 0 /* Default symbol visibility rules */ #define STV_INTERNAL 1 /* Processor specific hidden class */ #define STV_HIDDEN 2 /* Sym unavailable in other modules */ #define STV_PROTECTED 3 /* Not preemptible, not exported */ /* Relocation table entry without addend (in section of type SHT_REL). */ typedef struct { Elf32_Addr r_offset; /* Address */ Elf32_Word r_info; /* Relocation type and symbol index */ } Elf32_Rel; /* I have seen two different definitions of the Elf64_Rel and Elf64_Rela structures, so we'll leave them out until Novell (or whoever) gets their act together. */ /* The following, at least, is used on Sparc v9, MIPS, and Alpha. */ typedef struct { Elf64_Addr r_offset; /* Address */ Elf64_Xword r_info; /* Relocation type and symbol index */ } Elf64_Rel; /* Relocation table entry with addend (in section of type SHT_RELA). */ typedef struct { Elf32_Addr r_offset; /* Address */ Elf32_Word r_info; /* Relocation type and symbol index */ Elf32_Sword r_addend; /* Addend */ } Elf32_Rela; typedef struct { Elf64_Addr r_offset; /* Address */ Elf64_Xword r_info; /* Relocation type and symbol index */ Elf64_Sxword r_addend; /* Addend */ } Elf64_Rela; /* How to extract and insert information held in the r_info field. */ #define ELF32_R_SYM(val) ((val) >> 8) #define ELF32_R_TYPE(val) ((val) & 0xff) #define ELF32_R_INFO(sym, type) (((sym) << 8) + ((type) & 0xff)) #define ELF64_R_SYM(i) ((i) >> 32) #define ELF64_R_TYPE(i) ((i) & 0xffffffff) #define ELF64_R_INFO(sym,type) ((((Elf64_Xword) (sym)) << 32) + (type)) /* Program segment header. */ typedef struct { Elf32_Word p_type; /* Segment type */ Elf32_Off p_offset; /* Segment file offset */ Elf32_Addr p_vaddr; /* Segment virtual address */ Elf32_Addr p_paddr; /* Segment physical address */ Elf32_Word p_filesz; /* Segment size in file */ Elf32_Word p_memsz; /* Segment size in memory */ Elf32_Word p_flags; /* Segment flags */ Elf32_Word p_align; /* Segment alignment */ } Elf32_Phdr; typedef struct { Elf64_Word p_type; /* Segment type */ Elf64_Word p_flags; /* Segment flags */ Elf64_Off p_offset; /* Segment file offset */ Elf64_Addr p_vaddr; /* Segment virtual address */ Elf64_Addr p_paddr; /* Segment physical address */ Elf64_Xword p_filesz; /* Segment size in file */ Elf64_Xword p_memsz; /* Segment size in memory */ Elf64_Xword p_align; /* Segment alignment */ } Elf64_Phdr; /* Legal values for p_type (segment type). */ enum { PT_NULL = 0, /* Program header table entry unused */ PT_LOAD = 1, /* Loadable program segment */ PT_DYNAMIC = 2, /* Dynamic linking information */ PT_INTERP = 3, /* Program interpreter */ PT_NOTE = 4, /* Auxiliary information */ PT_SHLIB = 5, /* Reserved */ PT_PHDR = 6, /* Entry for header table itself */ PT_TLS = 7, /* Thread-local storage segment */ PT_NUM = 8, /* Number of defined types */ PT_LOOS = 0x60000000, /* Start of OS-specific */ PT_GNU_EH_FRAME = 0x6474e550, /* GCC .eh_frame_hdr segment */ PT_GNU_STACK = 0x6474e551, /* Indicates stack executability */ PT_LOSUNW = 0x6ffffffa, PT_SUNWBSS = 0x6ffffffa, /* Sun Specific segment */ PT_SUNWSTACK = 0x6ffffffb, /* Stack segment */ PT_HISUNW = 0x6fffffff, PT_HIOS = 0x6fffffff, /* End of OS-specific */ PT_LOPROC = 0x70000000, /* Start of processor-specific */ PT_HIPROC = 0x7fffffff /* End of processor-specific */ }; #define PT_NULL PT_NULL #define PT_LOAD PT_LOAD #define PT_DYNAMIC PT_DYNAMIC #define PT_INTERP PT_INTERP #define PT_NOTE PT_NOTE #define PT_SHLIB PT_SHLIB #define PT_PHDR PT_PHDR #define PT_TLS PT_TLS #define PT_NUM PT_NUM #define PT_LOOS PT_LOOS #define PT_GNU_EH_FRAME PT_GNU_EH_FRAME #define PT_GNU_STACK PT_GNU_STACK #define PT_LOSUNW PT_LOSUNW #define PT_SUNWBSS PT_SUNWBSS #define PT_SUNWSTACK PT_SUNWSTACK #define PT_HISUNW PT_HISUNW #define PT_HIOS PT_HIOS #define PT_LOPROC PT_LOPROC #define PT_HIPROC PT_HIPROC /* Legal values for p_flags (segment flags). */ #define PF_X (1 << 0) /* Segment is executable */ #define PF_W (1 << 1) /* Segment is writable */ #define PF_R (1 << 2) /* Segment is readable */ #define PF_MASKOS 0x0ff00000 /* OS-specific */ #define PF_MASKPROC 0xf0000000 /* Processor-specific */ /* Legal values for note segment descriptor types for core files. */ #define NT_PRSTATUS 1 /* Contains copy of prstatus struct */ #define NT_FPREGSET 2 /* Contains copy of fpregset struct */ #define NT_PRPSINFO 3 /* Contains copy of prpsinfo struct */ #define NT_PRXREG 4 /* Contains copy of prxregset struct */ #define NT_TASKSTRUCT 4 /* Contains copy of task structure */ #define NT_PLATFORM 5 /* String from sysinfo(SI_PLATFORM) */ #define NT_AUXV 6 /* Contains copy of auxv array */ #define NT_GWINDOWS 7 /* Contains copy of gwindows struct */ #define NT_ASRS 8 /* Contains copy of asrset struct */ #define NT_PSTATUS 10 /* Contains copy of pstatus struct */ #define NT_PSINFO 13 /* Contains copy of psinfo struct */ #define NT_PRCRED 14 /* Contains copy of prcred struct */ #define NT_UTSNAME 15 /* Contains copy of utsname struct */ #define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */ #define NT_LWPSINFO 17 /* Contains copy of lwpinfo struct */ #define NT_PRFPXREG 20 /* Contains copy of fprxregset struct*/ /* Legal values for the note segment descriptor types for object files. */ #define NT_VERSION 1 /* Contains a version string. */ /* Dynamic section entry. */ typedef struct { Elf32_Sword d_tag; /* Dynamic entry type */ union { Elf32_Word d_val; /* Integer value */ Elf32_Addr d_ptr; /* Address value */ } d_un; } Elf32_Dyn; typedef struct { Elf64_Sxword d_tag; /* Dynamic entry type */ union { Elf64_Xword d_val; /* Integer value */ Elf64_Addr d_ptr; /* Address value */ } d_un; } Elf64_Dyn; /* Legal values for d_tag (dynamic entry type). */ #define DT_NULL 0 /* Marks end of dynamic section */ #define DT_NEEDED 1 /* Name of needed library */ #define DT_PLTRELSZ 2 /* Size in bytes of PLT relocs */ #define DT_PLTGOT 3 /* Processor defined value */ #define DT_HASH 4 /* Address of symbol hash table */ #define DT_STRTAB 5 /* Address of string table */ #define DT_SYMTAB 6 /* Address of symbol table */ #define DT_RELA 7 /* Address of Rela relocs */ #define DT_RELASZ 8 /* Total size of Rela relocs */ #define DT_RELAENT 9 /* Size of one Rela reloc */ #define DT_STRSZ 10 /* Size of string table */ #define DT_SYMENT 11 /* Size of one symbol table entry */ #define DT_INIT 12 /* Address of init function */ #define DT_FINI 13 /* Address of termination function */ #define DT_SONAME 14 /* Name of shared object */ #define DT_RPATH 15 /* Library search path (deprecated) */ #define DT_SYMBOLIC 16 /* Start symbol search here */ #define DT_REL 17 /* Address of Rel relocs */ #define DT_RELSZ 18 /* Total size of Rel relocs */ #define DT_RELENT 19 /* Size of one Rel reloc */ #define DT_PLTREL 20 /* Type of reloc in PLT */ #define DT_DEBUG 21 /* For debugging; unspecified */ #define DT_TEXTREL 22 /* Reloc might modify .text */ #define DT_JMPREL 23 /* Address of PLT relocs */ #define DT_BIND_NOW 24 /* Process relocations of object */ #define DT_INIT_ARRAY 25 /* Array with addresses of init fct */ #define DT_FINI_ARRAY 26 /* Array with addresses of fini fct */ #define DT_INIT_ARRAYSZ 27 /* Size in bytes of DT_INIT_ARRAY */ #define DT_FINI_ARRAYSZ 28 /* Size in bytes of DT_FINI_ARRAY */ #define DT_RUNPATH 29 /* Library search path */ #define DT_FLAGS 30 /* Flags for the object being loaded */ #define DT_ENCODING 32 /* Start of encoded range */ #define DT_PREINIT_ARRAY 32 /* Array with addresses of preinit fct*/ #define DT_PREINIT_ARRAYSZ 33 /* size in bytes of DT_PREINIT_ARRAY */ #define DT_NUM 34 /* Number used */ #define DT_LOOS 0x6000000d /* Start of OS-specific */ #define DT_HIOS 0x6ffff000 /* End of OS-specific */ #define DT_LOPROC 0x70000000 /* Start of processor-specific */ #define DT_HIPROC 0x7fffffff /* End of processor-specific */ #define DT_PROCNUM DT_MIPS_NUM /* Most used by any processor */ /* DT_* entries which fall between DT_VALRNGHI & DT_VALRNGLO use the Dyn.d_un.d_val field of the Elf*_Dyn structure. This follows Sun's approach. */ #define DT_VALRNGLO 0x6ffffd00 #define DT_GNU_PRELINKED 0x6ffffdf5 /* Prelinking timestamp */ #define DT_GNU_CONFLICTSZ 0x6ffffdf6 /* Size of conflict section */ #define DT_GNU_LIBLISTSZ 0x6ffffdf7 /* Size of library list */ #define DT_CHECKSUM 0x6ffffdf8 #define DT_PLTPADSZ 0x6ffffdf9 #define DT_MOVEENT 0x6ffffdfa #define DT_MOVESZ 0x6ffffdfb #define DT_FEATURE_1 0x6ffffdfc /* Feature selection (DTF_*). */ #define DT_POSFLAG_1 0x6ffffdfd /* Flags for DT_* entries, effecting the following DT_* entry. */ #define DT_SYMINSZ 0x6ffffdfe /* Size of syminfo table (in bytes) */ #define DT_SYMINENT 0x6ffffdff /* Entry size of syminfo */ #define DT_VALRNGHI 0x6ffffdff #define DT_VALTAGIDX(tag) (DT_VALRNGHI - (tag)) /* Reverse order! */ #define DT_VALNUM 12 /* DT_* entries which fall between DT_ADDRRNGHI & DT_ADDRRNGLO use the Dyn.d_un.d_ptr field of the Elf*_Dyn structure. If any adjustment is made to the ELF object after it has been built these entries will need to be adjusted. */ #define DT_ADDRRNGLO 0x6ffffe00 #define DT_GNU_HASH 0x6ffffe05 #define DT_TLSDESC_PLT 0x6ffffe06 #define DT_TLSDESC_GOT 0x6ffffe07 #define DT_GNU_CONFLICT 0x6ffffef8 /* Start of conflict section */ #define DT_GNU_LIBLIST 0x6ffffef9 /* Library list */ #define DT_CONFIG 0x6ffffefa /* Configuration information. */ #define DT_DEPAUDIT 0x6ffffefb /* Dependency auditing. */ #define DT_AUDIT 0x6ffffefc /* Object auditing. */ #define DT_PLTPAD 0x6ffffefd /* PLT padding. */ #define DT_MOVETAB 0x6ffffefe /* Move table. */ #define DT_SYMINFO 0x6ffffeff /* Syminfo table. */ #define DT_ADDRRNGHI 0x6ffffeff #define DT_ADDRTAGIDX(tag) (DT_ADDRRNGHI - (tag)) /* Reverse order! */ #define DT_ADDRNUM 10 /* The versioning entry types. The next are defined as part of the GNU extension. */ #define DT_VERSYM 0x6ffffff0 #define DT_RELACOUNT 0x6ffffff9 #define DT_RELCOUNT 0x6ffffffa /* These were chosen by Sun. */ #define DT_FLAGS_1 0x6ffffffb /* State flags, see DF_1_* below. */ #define DT_VERDEF 0x6ffffffc /* Address of version definition table */ #define DT_VERDEFNUM 0x6ffffffd /* Number of version definitions */ #define DT_VERNEED 0x6ffffffe /* Address of table with needed versions */ #define DT_VERNEEDNUM 0x6fffffff /* Number of needed versions */ #define DT_VERSIONTAGIDX(tag) (DT_VERNEEDNUM - (tag)) /* Reverse order! */ #define DT_VERSIONTAGNUM 16 /* Sun added these machine-independent extensions in the "processor-specific" range. Be compatible. */ #define DT_AUXILIARY 0x7ffffffd /* Shared object to load before self */ #define DT_FILTER 0x7fffffff /* Shared object to get values from */ #define DT_EXTRATAGIDX(tag) ((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) #define DT_EXTRANUM 3 /* Values of `d_un.d_val' in the DT_FLAGS entry. */ #define DF_ORIGIN 0x00000001 /* Object may use DF_ORIGIN */ #define DF_SYMBOLIC 0x00000002 /* Symbol resolutions starts here */ #define DF_TEXTREL 0x00000004 /* Object contains text relocations */ #define DF_BIND_NOW 0x00000008 /* No lazy binding for this object */ #define DF_STATIC_TLS 0x00000010 /* Module uses the static TLS model */ /* State flags selectable in the `d_un.d_val' element of the DT_FLAGS_1 entry in the dynamic section. */ #define DF_1_NOW 0x00000001 /* Set RTLD_NOW for this object. */ #define DF_1_GLOBAL 0x00000002 /* Set RTLD_GLOBAL for this object. */ #define DF_1_GROUP 0x00000004 /* Set RTLD_GROUP for this object. */ #define DF_1_NODELETE 0x00000008 /* Set RTLD_NODELETE for this object.*/ #define DF_1_LOADFLTR 0x00000010 /* Trigger filtee loading at runtime.*/ #define DF_1_INITFIRST 0x00000020 /* Set RTLD_INITFIRST for this object*/ #define DF_1_NOOPEN 0x00000040 /* Set RTLD_NOOPEN for this object. */ #define DF_1_ORIGIN 0x00000080 /* $ORIGIN must be handled. */ #define DF_1_DIRECT 0x00000100 /* Direct binding enabled. */ #define DF_1_TRANS 0x00000200 #define DF_1_INTERPOSE 0x00000400 /* Object is used to interpose. */ #define DF_1_NODEFLIB 0x00000800 /* Ignore default lib search path. */ #define DF_1_NODUMP 0x00001000 /* Object can't be dldump'ed. */ #define DF_1_CONFALT 0x00002000 /* Configuration alternative created.*/ #define DF_1_ENDFILTEE 0x00004000 /* Filtee terminates filters search. */ #define DF_1_DISPRELDNE 0x00008000 /* Disp reloc applied at build time. */ #define DF_1_DISPRELPND 0x00010000 /* Disp reloc applied at run-time. */ /* Flags for the feature selection in DT_FEATURE_1. */ #define DTF_1_PARINIT 0x00000001 #define DTF_1_CONFEXP 0x00000002 /* Flags in the DT_POSFLAG_1 entry effecting only the next DT_* entry. */ #define DF_P1_LAZYLOAD 0x00000001 /* Lazyload following object. */ #define DF_P1_GROUPPERM 0x00000002 /* Symbols from next object are not generally available. */ /* Version definition sections. */ typedef struct { Elf32_Half vd_version; /* Version revision */ Elf32_Half vd_flags; /* Version information */ Elf32_Half vd_ndx; /* Version Index */ Elf32_Half vd_cnt; /* Number of associated aux entries */ Elf32_Word vd_hash; /* Version name hash value */ Elf32_Word vd_aux; /* Offset in bytes to verdaux array */ Elf32_Word vd_next; /* Offset in bytes to next verdef entry */ } Elf32_Verdef; typedef struct { Elf64_Half vd_version; /* Version revision */ Elf64_Half vd_flags; /* Version information */ Elf64_Half vd_ndx; /* Version Index */ Elf64_Half vd_cnt; /* Number of associated aux entries */ Elf64_Word vd_hash; /* Version name hash value */ Elf64_Word vd_aux; /* Offset in bytes to verdaux array */ Elf64_Word vd_next; /* Offset in bytes to next verdef entry */ } Elf64_Verdef; /* Legal values for vd_version (version revision). */ #define VER_DEF_NONE 0 /* No version */ #define VER_DEF_CURRENT 1 /* Current version */ #define VER_DEF_NUM 2 /* Given version number */ /* Legal values for vd_flags (version information flags). */ #define VER_FLG_BASE 0x1 /* Version definition of file itself */ #define VER_FLG_WEAK 0x2 /* Weak version identifier */ /* Versym symbol index values. */ #define VER_NDX_LOCAL 0 /* Symbol is local. */ #define VER_NDX_GLOBAL 1 /* Symbol is global. */ #define VER_NDX_LORESERVE 0xff00 /* Beginning of reserved entries. */ #define VER_NDX_ELIMINATE 0xff01 /* Symbol is to be eliminated. */ /* Auxialiary version information. */ typedef struct { Elf32_Word vda_name; /* Version or dependency names */ Elf32_Word vda_next; /* Offset in bytes to next verdaux entry */ } Elf32_Verdaux; typedef struct { Elf64_Word vda_name; /* Version or dependency names */ Elf64_Word vda_next; /* Offset in bytes to next verdaux entry */ } Elf64_Verdaux; /* Version dependency section. */ typedef struct { Elf32_Half vn_version; /* Version of structure */ Elf32_Half vn_cnt; /* Number of associated aux entries */ Elf32_Word vn_file; /* Offset of filename for this dependency */ Elf32_Word vn_aux; /* Offset in bytes to vernaux array */ Elf32_Word vn_next; /* Offset in bytes to next verneed entry */ } Elf32_Verneed; typedef struct { Elf64_Half vn_version; /* Version of structure */ Elf64_Half vn_cnt; /* Number of associated aux entries */ Elf64_Word vn_file; /* Offset of filename for this dependency */ Elf64_Word vn_aux; /* Offset in bytes to vernaux array */ Elf64_Word vn_next; /* Offset in bytes to next verneed entry */ } Elf64_Verneed; /* Legal values for vn_version (version revision). */ #define VER_NEED_NONE 0 /* No version */ #define VER_NEED_CURRENT 1 /* Current version */ #define VER_NEED_NUM 2 /* Given version number */ /* Auxiliary needed version information. */ typedef struct { Elf32_Word vna_hash; /* Hash value of dependency name */ Elf32_Half vna_flags; /* Dependency specific information */ Elf32_Half vna_other; /* Unused */ Elf32_Word vna_name; /* Dependency name string offset */ Elf32_Word vna_next; /* Offset in bytes to next vernaux entry */ } Elf32_Vernaux; typedef struct { Elf64_Word vna_hash; /* Hash value of dependency name */ Elf64_Half vna_flags; /* Dependency specific information */ Elf64_Half vna_other; /* Unused */ Elf64_Word vna_name; /* Dependency name string offset */ Elf64_Word vna_next; /* Offset in bytes to next vernaux entry */ } Elf64_Vernaux; /* Legal values for vna_flags. */ #define VER_FLG_WEAK 0x2 /* Weak version identifier */ /* Auxiliary vector. */ /* This vector is normally only used by the program interpreter. The usual definition in an ABI supplement uses the name auxv_t. The vector is not usually defined in a standard file, but it can't hurt. We rename it to avoid conflicts. The sizes of these types are an arrangement between the exec server and the program interpreter, so we don't fully specify them here. */ typedef struct { int32_t a_type; /* Entry type */ union { long int a_val; /* Integer value */ void *a_ptr; /* Pointer value */ void (*a_fcn) (void); /* Function pointer value */ } a_un; } Elf32_auxv_t; typedef struct { long int a_type; /* Entry type */ union { long int a_val; /* Integer value */ void *a_ptr; /* Pointer value */ void (*a_fcn) (void); /* Function pointer value */ } a_un; } Elf64_auxv_t; /* Legal values for a_type (entry type). */ #define AT_NULL 0 /* End of vector */ #define AT_IGNORE 1 /* Entry should be ignored */ #define AT_EXECFD 2 /* File descriptor of program */ #define AT_PHDR 3 /* Program headers for program */ #define AT_PHENT 4 /* Size of program header entry */ #define AT_PHNUM 5 /* Number of program headers */ #define AT_PAGESZ 6 /* System page size */ #define AT_BASE 7 /* Base address of interpreter */ #define AT_FLAGS 8 /* Flags */ #define AT_ENTRY 9 /* Entry point of program */ #define AT_NOTELF 10 /* Program is not ELF */ #define AT_UID 11 /* Real uid */ #define AT_EUID 12 /* Effective uid */ #define AT_GID 13 /* Real gid */ #define AT_EGID 14 /* Effective gid */ #define AT_CLKTCK 17 /* Frequency of times() */ /* Some more special a_type values describing the hardware. */ #define AT_PLATFORM 15 /* String identifying platform. */ #define AT_HWCAP 16 /* Machine dependent hints about processor capabilities. */ /* This entry gives some information about the FPU initialization performed by the kernel. */ #define AT_FPUCW 18 /* Used FPU control word. */ /* Cache block sizes. */ #define AT_DCACHEBSIZE 19 /* Data cache block size. */ #define AT_ICACHEBSIZE 20 /* Instruction cache block size. */ #define AT_UCACHEBSIZE 21 /* Unified cache block size. */ /* A special ignored value for PPC, used by the kernel to control the interpretation of the AUXV. Must be > 16. */ #define AT_IGNOREPPC 22 /* Entry should be ignored. */ #define AT_SECURE 23 /* Boolean, was exec setuid-like? */ /* Pointer to the global system page used for system calls and other nice things. */ #define AT_SYSINFO 32 #define AT_SYSINFO_EHDR 33 /* Note section contents. Each entry in the note section begins with a header of a fixed form. */ typedef struct { Elf32_Word n_namesz; /* Length of the note's name. */ Elf32_Word n_descsz; /* Length of the note's descriptor. */ Elf32_Word n_type; /* Type of the note. */ } Elf32_Nhdr; typedef struct { Elf64_Word n_namesz; /* Length of the note's name. */ Elf64_Word n_descsz; /* Length of the note's descriptor. */ Elf64_Word n_type; /* Type of the note. */ } Elf64_Nhdr; /* Known names of notes. */ /* Solaris entries in the note section have this name. */ #define ELF_NOTE_SOLARIS "SUNW Solaris" /* Note entries for GNU systems have this name. */ #define ELF_NOTE_GNU "GNU" /* Defined types of notes for Solaris. */ /* Value of descriptor (one word) is desired pagesize for the binary. */ #define ELF_NOTE_PAGESIZE_HINT 1 /* Defined note types for GNU systems. */ /* ABI information. The descriptor consists of words: word 0: OS descriptor word 1: major version of the ABI word 2: minor version of the ABI word 3: subminor version of the ABI */ #define ELF_NOTE_ABI 1 /* Known OSes. These value can appear in word 0 of an ELF_NOTE_ABI note section entry. */ #define ELF_NOTE_OS_LINUX 0 #define ELF_NOTE_OS_GNU 1 #define ELF_NOTE_OS_SOLARIS2 2 #define ELF_NOTE_OS_FREEBSD 3 /* Move records. */ typedef struct { Elf32_Xword m_value; /* Symbol value. */ Elf32_Word m_info; /* Size and index. */ Elf32_Word m_poffset; /* Symbol offset. */ Elf32_Half m_repeat; /* Repeat count. */ Elf32_Half m_stride; /* Stride info. */ } Elf32_Move; typedef struct { Elf64_Xword m_value; /* Symbol value. */ Elf64_Xword m_info; /* Size and index. */ Elf64_Xword m_poffset; /* Symbol offset. */ Elf64_Half m_repeat; /* Repeat count. */ Elf64_Half m_stride; /* Stride info. */ } Elf64_Move; /* Macro to construct move records. */ #define ELF32_M_SYM(info) ((info) >> 8) #define ELF32_M_SIZE(info) ((unsigned char) (info)) #define ELF32_M_INFO(sym, size) (((sym) << 8) + (unsigned char) (size)) #define ELF64_M_SYM(info) ELF32_M_SYM (info) #define ELF64_M_SIZE(info) ELF32_M_SIZE (info) #define ELF64_M_INFO(sym, size) ELF32_M_INFO (sym, size) /* Motorola 68k specific definitions. */ /* Values for Elf32_Ehdr.e_flags. */ #define EF_CPU32 0x00810000 /* m68k relocs. */ #define R_68K_NONE 0 /* No reloc */ #define R_68K_32 1 /* Direct 32 bit */ #define R_68K_16 2 /* Direct 16 bit */ #define R_68K_8 3 /* Direct 8 bit */ #define R_68K_PC32 4 /* PC relative 32 bit */ #define R_68K_PC16 5 /* PC relative 16 bit */ #define R_68K_PC8 6 /* PC relative 8 bit */ #define R_68K_GOT32 7 /* 32 bit PC relative GOT entry */ #define R_68K_GOT16 8 /* 16 bit PC relative GOT entry */ #define R_68K_GOT8 9 /* 8 bit PC relative GOT entry */ #define R_68K_GOT32O 10 /* 32 bit GOT offset */ #define R_68K_GOT16O 11 /* 16 bit GOT offset */ #define R_68K_GOT8O 12 /* 8 bit GOT offset */ #define R_68K_PLT32 13 /* 32 bit PC relative PLT address */ #define R_68K_PLT16 14 /* 16 bit PC relative PLT address */ #define R_68K_PLT8 15 /* 8 bit PC relative PLT address */ #define R_68K_PLT32O 16 /* 32 bit PLT offset */ #define R_68K_PLT16O 17 /* 16 bit PLT offset */ #define R_68K_PLT8O 18 /* 8 bit PLT offset */ #define R_68K_COPY 19 /* Copy symbol at runtime */ #define R_68K_GLOB_DAT 20 /* Create GOT entry */ #define R_68K_JMP_SLOT 21 /* Create PLT entry */ #define R_68K_RELATIVE 22 /* Adjust by program base */ /* Keep this the last entry. */ #define R_68K_NUM 23 /* Intel 80386 specific definitions. */ /* i386 relocs. */ #define R_386_NONE 0 /* No reloc */ #define R_386_32 1 /* Direct 32 bit */ #define R_386_PC32 2 /* PC relative 32 bit */ #define R_386_GOT32 3 /* 32 bit GOT entry */ #define R_386_PLT32 4 /* 32 bit PLT address */ #define R_386_COPY 5 /* Copy symbol at runtime */ #define R_386_GLOB_DAT 6 /* Create GOT entry */ #define R_386_JMP_SLOT 7 /* Create PLT entry */ #define R_386_RELATIVE 8 /* Adjust by program base */ #define R_386_GOTOFF 9 /* 32 bit offset to GOT */ #define R_386_GOTPC 10 /* 32 bit PC relative offset to GOT */ #define R_386_32PLT 11 #define R_386_TLS_TPOFF 14 /* Offset in static TLS block */ #define R_386_TLS_IE 15 /* Address of GOT entry for static TLS block offset */ #define R_386_TLS_GOTIE 16 /* GOT entry for static TLS block offset */ #define R_386_TLS_LE 17 /* Offset relative to static TLS block */ #define R_386_TLS_GD 18 /* Direct 32 bit for GNU version of general dynamic thread local data */ #define R_386_TLS_LDM 19 /* Direct 32 bit for GNU version of local dynamic thread local data in LE code */ #define R_386_16 20 #define R_386_PC16 21 #define R_386_8 22 #define R_386_PC8 23 #define R_386_TLS_GD_32 24 /* Direct 32 bit for general dynamic thread local data */ #define R_386_TLS_GD_PUSH 25 /* Tag for pushl in GD TLS code */ #define R_386_TLS_GD_CALL 26 /* Relocation for call to __tls_get_addr() */ #define R_386_TLS_GD_POP 27 /* Tag for popl in GD TLS code */ #define R_386_TLS_LDM_32 28 /* Direct 32 bit for local dynamic thread local data in LE code */ #define R_386_TLS_LDM_PUSH 29 /* Tag for pushl in LDM TLS code */ #define R_386_TLS_LDM_CALL 30 /* Relocation for call to __tls_get_addr() in LDM code */ #define R_386_TLS_LDM_POP 31 /* Tag for popl in LDM TLS code */ #define R_386_TLS_LDO_32 32 /* Offset relative to TLS block */ #define R_386_TLS_IE_32 33 /* GOT entry for negated static TLS block offset */ #define R_386_TLS_LE_32 34 /* Negated offset relative to static TLS block */ #define R_386_TLS_DTPMOD32 35 /* ID of module containing symbol */ #define R_386_TLS_DTPOFF32 36 /* Offset in TLS block */ #define R_386_TLS_TPOFF32 37 /* Negated offset in static TLS block */ /* Keep this the last entry. */ #define R_386_NUM 38 /* SUN SPARC specific definitions. */ /* Legal values for ST_TYPE subfield of st_info (symbol type). */ #define STT_REGISTER 13 /* Global register reserved to app. */ /* Values for Elf64_Ehdr.e_flags. */ #define EF_SPARCV9_MM 3 #define EF_SPARCV9_TSO 0 #define EF_SPARCV9_PSO 1 #define EF_SPARCV9_RMO 2 #define EF_SPARC_LEDATA 0x800000 /* little endian data */ #define EF_SPARC_EXT_MASK 0xFFFF00 #define EF_SPARC_32PLUS 0x000100 /* generic V8+ features */ #define EF_SPARC_SUN_US1 0x000200 /* Sun UltraSPARC1 extensions */ #define EF_SPARC_HAL_R1 0x000400 /* HAL R1 extensions */ #define EF_SPARC_SUN_US3 0x000800 /* Sun UltraSPARCIII extensions */ /* SPARC relocs. */ #define R_SPARC_NONE 0 /* No reloc */ #define R_SPARC_8 1 /* Direct 8 bit */ #define R_SPARC_16 2 /* Direct 16 bit */ #define R_SPARC_32 3 /* Direct 32 bit */ #define R_SPARC_DISP8 4 /* PC relative 8 bit */ #define R_SPARC_DISP16 5 /* PC relative 16 bit */ #define R_SPARC_DISP32 6 /* PC relative 32 bit */ #define R_SPARC_WDISP30 7 /* PC relative 30 bit shifted */ #define R_SPARC_WDISP22 8 /* PC relative 22 bit shifted */ #define R_SPARC_HI22 9 /* High 22 bit */ #define R_SPARC_22 10 /* Direct 22 bit */ #define R_SPARC_13 11 /* Direct 13 bit */ #define R_SPARC_LO10 12 /* Truncated 10 bit */ #define R_SPARC_GOT10 13 /* Truncated 10 bit GOT entry */ #define R_SPARC_GOT13 14 /* 13 bit GOT entry */ #define R_SPARC_GOT22 15 /* 22 bit GOT entry shifted */ #define R_SPARC_PC10 16 /* PC relative 10 bit truncated */ #define R_SPARC_PC22 17 /* PC relative 22 bit shifted */ #define R_SPARC_WPLT30 18 /* 30 bit PC relative PLT address */ #define R_SPARC_COPY 19 /* Copy symbol at runtime */ #define R_SPARC_GLOB_DAT 20 /* Create GOT entry */ #define R_SPARC_JMP_SLOT 21 /* Create PLT entry */ #define R_SPARC_RELATIVE 22 /* Adjust by program base */ #define R_SPARC_UA32 23 /* Direct 32 bit unaligned */ /* Additional Sparc64 relocs. */ #define R_SPARC_PLT32 24 /* Direct 32 bit ref to PLT entry */ #define R_SPARC_HIPLT22 25 /* High 22 bit PLT entry */ #define R_SPARC_LOPLT10 26 /* Truncated 10 bit PLT entry */ #define R_SPARC_PCPLT32 27 /* PC rel 32 bit ref to PLT entry */ #define R_SPARC_PCPLT22 28 /* PC rel high 22 bit PLT entry */ #define R_SPARC_PCPLT10 29 /* PC rel trunc 10 bit PLT entry */ #define R_SPARC_10 30 /* Direct 10 bit */ #define R_SPARC_11 31 /* Direct 11 bit */ #define R_SPARC_64 32 /* Direct 64 bit */ #define R_SPARC_OLO10 33 /* 10bit with secondary 13bit addend */ #define R_SPARC_HH22 34 /* Top 22 bits of direct 64 bit */ #define R_SPARC_HM10 35 /* High middle 10 bits of ... */ #define R_SPARC_LM22 36 /* Low middle 22 bits of ... */ #define R_SPARC_PC_HH22 37 /* Top 22 bits of pc rel 64 bit */ #define R_SPARC_PC_HM10 38 /* High middle 10 bit of ... */ #define R_SPARC_PC_LM22 39 /* Low miggle 22 bits of ... */ #define R_SPARC_WDISP16 40 /* PC relative 16 bit shifted */ #define R_SPARC_WDISP19 41 /* PC relative 19 bit shifted */ #define R_SPARC_7 43 /* Direct 7 bit */ #define R_SPARC_5 44 /* Direct 5 bit */ #define R_SPARC_6 45 /* Direct 6 bit */ #define R_SPARC_DISP64 46 /* PC relative 64 bit */ #define R_SPARC_PLT64 47 /* Direct 64 bit ref to PLT entry */ #define R_SPARC_HIX22 48 /* High 22 bit complemented */ #define R_SPARC_LOX10 49 /* Truncated 11 bit complemented */ #define R_SPARC_H44 50 /* Direct high 12 of 44 bit */ #define R_SPARC_M44 51 /* Direct mid 22 of 44 bit */ #define R_SPARC_L44 52 /* Direct low 10 of 44 bit */ #define R_SPARC_REGISTER 53 /* Global register usage */ #define R_SPARC_UA64 54 /* Direct 64 bit unaligned */ #define R_SPARC_UA16 55 /* Direct 16 bit unaligned */ #define R_SPARC_TLS_GD_HI22 56 #define R_SPARC_TLS_GD_LO10 57 #define R_SPARC_TLS_GD_ADD 58 #define R_SPARC_TLS_GD_CALL 59 #define R_SPARC_TLS_LDM_HI22 60 #define R_SPARC_TLS_LDM_LO10 61 #define R_SPARC_TLS_LDM_ADD 62 #define R_SPARC_TLS_LDM_CALL 63 #define R_SPARC_TLS_LDO_HIX22 64 #define R_SPARC_TLS_LDO_LOX10 65 #define R_SPARC_TLS_LDO_ADD 66 #define R_SPARC_TLS_IE_HI22 67 #define R_SPARC_TLS_IE_LO10 68 #define R_SPARC_TLS_IE_LD 69 #define R_SPARC_TLS_IE_LDX 70 #define R_SPARC_TLS_IE_ADD 71 #define R_SPARC_TLS_LE_HIX22 72 #define R_SPARC_TLS_LE_LOX10 73 #define R_SPARC_TLS_DTPMOD32 74 #define R_SPARC_TLS_DTPMOD64 75 #define R_SPARC_TLS_DTPOFF32 76 #define R_SPARC_TLS_DTPOFF64 77 #define R_SPARC_TLS_TPOFF32 78 #define R_SPARC_TLS_TPOFF64 79 /* Keep this the last entry. */ #define R_SPARC_NUM 80 /* For Sparc64, legal values for d_tag of Elf64_Dyn. */ #define DT_SPARC_REGISTER 0x70000001 #define DT_SPARC_NUM 2 /* Bits present in AT_HWCAP, primarily for Sparc32. */ #define HWCAP_SPARC_FLUSH 1 /* The cpu supports flush insn. */ #define HWCAP_SPARC_STBAR 2 #define HWCAP_SPARC_SWAP 4 #define HWCAP_SPARC_MULDIV 8 #define HWCAP_SPARC_V9 16 /* The cpu is v9, so v8plus is ok. */ #define HWCAP_SPARC_ULTRA3 32 /* MIPS R3000 specific definitions. */ /* Legal values for e_flags field of Elf32_Ehdr. */ #define EF_MIPS_NOREORDER 1 /* A .noreorder directive was used */ #define EF_MIPS_PIC 2 /* Contains PIC code */ #define EF_MIPS_CPIC 4 /* Uses PIC calling sequence */ #define EF_MIPS_XGOT 8 #define EF_MIPS_64BIT_WHIRL 16 #define EF_MIPS_ABI2 32 #define EF_MIPS_ABI_ON32 64 #define EF_MIPS_ARCH 0xf0000000 /* MIPS architecture level */ /* Legal values for MIPS architecture level. */ #define EF_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ #define EF_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ #define EF_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ #define EF_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ #define EF_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ #define EF_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ #define EF_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ /* The following are non-official names and should not be used. */ #define E_MIPS_ARCH_1 0x00000000 /* -mips1 code. */ #define E_MIPS_ARCH_2 0x10000000 /* -mips2 code. */ #define E_MIPS_ARCH_3 0x20000000 /* -mips3 code. */ #define E_MIPS_ARCH_4 0x30000000 /* -mips4 code. */ #define E_MIPS_ARCH_5 0x40000000 /* -mips5 code. */ #define E_MIPS_ARCH_32 0x60000000 /* MIPS32 code. */ #define E_MIPS_ARCH_64 0x70000000 /* MIPS64 code. */ /* Special section indices. */ #define SHN_MIPS_ACOMMON 0xff00 /* Allocated common symbols */ #define SHN_MIPS_TEXT 0xff01 /* Allocated test symbols. */ #define SHN_MIPS_DATA 0xff02 /* Allocated data symbols. */ #define SHN_MIPS_SCOMMON 0xff03 /* Small common symbols */ #define SHN_MIPS_SUNDEFINED 0xff04 /* Small undefined symbols */ /* Legal values for sh_type field of Elf32_Shdr. */ #define SHT_MIPS_LIBLIST 0x70000000 /* Shared objects used in link */ #define SHT_MIPS_MSYM 0x70000001 #define SHT_MIPS_CONFLICT 0x70000002 /* Conflicting symbols */ #define SHT_MIPS_GPTAB 0x70000003 /* Global data area sizes */ #define SHT_MIPS_UCODE 0x70000004 /* Reserved for SGI/MIPS compilers */ #define SHT_MIPS_DEBUG 0x70000005 /* MIPS ECOFF debugging information*/ #define SHT_MIPS_REGINFO 0x70000006 /* Register usage information */ #define SHT_MIPS_PACKAGE 0x70000007 #define SHT_MIPS_PACKSYM 0x70000008 #define SHT_MIPS_RELD 0x70000009 #define SHT_MIPS_IFACE 0x7000000b #define SHT_MIPS_CONTENT 0x7000000c #define SHT_MIPS_OPTIONS 0x7000000d /* Miscellaneous options. */ #define SHT_MIPS_SHDR 0x70000010 #define SHT_MIPS_FDESC 0x70000011 #define SHT_MIPS_EXTSYM 0x70000012 #define SHT_MIPS_DENSE 0x70000013 #define SHT_MIPS_PDESC 0x70000014 #define SHT_MIPS_LOCSYM 0x70000015 #define SHT_MIPS_AUXSYM 0x70000016 #define SHT_MIPS_OPTSYM 0x70000017 #define SHT_MIPS_LOCSTR 0x70000018 #define SHT_MIPS_LINE 0x70000019 #define SHT_MIPS_RFDESC 0x7000001a #define SHT_MIPS_DELTASYM 0x7000001b #define SHT_MIPS_DELTAINST 0x7000001c #define SHT_MIPS_DELTACLASS 0x7000001d #define SHT_MIPS_DWARF 0x7000001e /* DWARF debugging information. */ #define SHT_MIPS_DELTADECL 0x7000001f #define SHT_MIPS_SYMBOL_LIB 0x70000020 #define SHT_MIPS_EVENTS 0x70000021 /* Event section. */ #define SHT_MIPS_TRANSLATE 0x70000022 #define SHT_MIPS_PIXIE 0x70000023 #define SHT_MIPS_XLATE 0x70000024 #define SHT_MIPS_XLATE_DEBUG 0x70000025 #define SHT_MIPS_WHIRL 0x70000026 #define SHT_MIPS_EH_REGION 0x70000027 #define SHT_MIPS_XLATE_OLD 0x70000028 #define SHT_MIPS_PDR_EXCEPTION 0x70000029 /* Legal values for sh_flags field of Elf32_Shdr. */ #define SHF_MIPS_GPREL 0x10000000 /* Must be part of global data area */ #define SHF_MIPS_MERGE 0x20000000 #define SHF_MIPS_ADDR 0x40000000 #define SHF_MIPS_STRINGS 0x80000000 #define SHF_MIPS_NOSTRIP 0x08000000 #define SHF_MIPS_LOCAL 0x04000000 #define SHF_MIPS_NAMES 0x02000000 #define SHF_MIPS_NODUPE 0x01000000 /* Symbol tables. */ /* MIPS specific values for `st_other'. */ #define STO_MIPS_DEFAULT 0x0 #define STO_MIPS_INTERNAL 0x1 #define STO_MIPS_HIDDEN 0x2 #define STO_MIPS_PROTECTED 0x3 #define STO_MIPS_SC_ALIGN_UNUSED 0xff /* MIPS specific values for `st_info'. */ #define STB_MIPS_SPLIT_COMMON 13 /* Entries found in sections of type SHT_MIPS_GPTAB. */ typedef union { struct { Elf32_Word gt_current_g_value; /* -G value used for compilation */ Elf32_Word gt_unused; /* Not used */ } gt_header; /* First entry in section */ struct { Elf32_Word gt_g_value; /* If this value were used for -G */ Elf32_Word gt_bytes; /* This many bytes would be used */ } gt_entry; /* Subsequent entries in section */ } Elf32_gptab; /* Entry found in sections of type SHT_MIPS_REGINFO. */ typedef struct { Elf32_Word ri_gprmask; /* General registers used */ Elf32_Word ri_cprmask[4]; /* Coprocessor registers used */ Elf32_Sword ri_gp_value; /* $gp register value */ } Elf32_RegInfo; /* Entries found in sections of type SHT_MIPS_OPTIONS. */ typedef struct { unsigned char kind; /* Determines interpretation of the variable part of descriptor. */ unsigned char size; /* Size of descriptor, including header. */ Elf32_Section section; /* Section header index of section affected, 0 for global options. */ Elf32_Word info; /* Kind-specific information. */ } Elf_Options; /* Values for `kind' field in Elf_Options. */ #define ODK_NULL 0 /* Undefined. */ #define ODK_REGINFO 1 /* Register usage information. */ #define ODK_EXCEPTIONS 2 /* Exception processing options. */ #define ODK_PAD 3 /* Section padding options. */ #define ODK_HWPATCH 4 /* Hardware workarounds performed */ #define ODK_FILL 5 /* record the fill value used by the linker. */ #define ODK_TAGS 6 /* reserve space for desktop tools to write. */ #define ODK_HWAND 7 /* HW workarounds. 'AND' bits when merging. */ #define ODK_HWOR 8 /* HW workarounds. 'OR' bits when merging. */ /* Values for `info' in Elf_Options for ODK_EXCEPTIONS entries. */ #define OEX_FPU_MIN 0x1f /* FPE's which MUST be enabled. */ #define OEX_FPU_MAX 0x1f00 /* FPE's which MAY be enabled. */ #define OEX_PAGE0 0x10000 /* page zero must be mapped. */ #define OEX_SMM 0x20000 /* Force sequential memory mode? */ #define OEX_FPDBUG 0x40000 /* Force floating point debug mode? */ #define OEX_PRECISEFP OEX_FPDBUG #define OEX_DISMISS 0x80000 /* Dismiss invalid address faults? */ #define OEX_FPU_INVAL 0x10 #define OEX_FPU_DIV0 0x08 #define OEX_FPU_OFLO 0x04 #define OEX_FPU_UFLO 0x02 #define OEX_FPU_INEX 0x01 /* Masks for `info' in Elf_Options for an ODK_HWPATCH entry. */ #define OHW_R4KEOP 0x1 /* R4000 end-of-page patch. */ #define OHW_R8KPFETCH 0x2 /* may need R8000 prefetch patch. */ #define OHW_R5KEOP 0x4 /* R5000 end-of-page patch. */ #define OHW_R5KCVTL 0x8 /* R5000 cvt.[ds].l bug. clean=1. */ #define OPAD_PREFIX 0x1 #define OPAD_POSTFIX 0x2 #define OPAD_SYMBOL 0x4 /* Entry found in `.options' section. */ typedef struct { Elf32_Word hwp_flags1; /* Extra flags. */ Elf32_Word hwp_flags2; /* Extra flags. */ } Elf_Options_Hw; /* Masks for `info' in ElfOptions for ODK_HWAND and ODK_HWOR entries. */ #define OHWA0_R4KEOP_CHECKED 0x00000001 #define OHWA1_R4KEOP_CLEAN 0x00000002 /* MIPS relocs. */ #define R_MIPS_NONE 0 /* No reloc */ #define R_MIPS_16 1 /* Direct 16 bit */ #define R_MIPS_32 2 /* Direct 32 bit */ #define R_MIPS_REL32 3 /* PC relative 32 bit */ #define R_MIPS_26 4 /* Direct 26 bit shifted */ #define R_MIPS_HI16 5 /* High 16 bit */ #define R_MIPS_LO16 6 /* Low 16 bit */ #define R_MIPS_GPREL16 7 /* GP relative 16 bit */ #define R_MIPS_LITERAL 8 /* 16 bit literal entry */ #define R_MIPS_GOT16 9 /* 16 bit GOT entry */ #define R_MIPS_PC16 10 /* PC relative 16 bit */ #define R_MIPS_CALL16 11 /* 16 bit GOT entry for function */ #define R_MIPS_GPREL32 12 /* GP relative 32 bit */ #define R_MIPS_SHIFT5 16 #define R_MIPS_SHIFT6 17 #define R_MIPS_64 18 #define R_MIPS_GOT_DISP 19 #define R_MIPS_GOT_PAGE 20 #define R_MIPS_GOT_OFST 21 #define R_MIPS_GOT_HI16 22 #define R_MIPS_GOT_LO16 23 #define R_MIPS_SUB 24 #define R_MIPS_INSERT_A 25 #define R_MIPS_INSERT_B 26 #define R_MIPS_DELETE 27 #define R_MIPS_HIGHER 28 #define R_MIPS_HIGHEST 29 #define R_MIPS_CALL_HI16 30 #define R_MIPS_CALL_LO16 31 #define R_MIPS_SCN_DISP 32 #define R_MIPS_REL16 33 #define R_MIPS_ADD_IMMEDIATE 34 #define R_MIPS_PJUMP 35 #define R_MIPS_RELGOT 36 #define R_MIPS_JALR 37 /* Keep this the last entry. */ #define R_MIPS_NUM 38 /* Legal values for p_type field of Elf32_Phdr. */ #define PT_MIPS_REGINFO 0x70000000 /* Register usage information */ #define PT_MIPS_RTPROC 0x70000001 /* Runtime procedure table. */ #define PT_MIPS_OPTIONS 0x70000002 /* Special program header types. */ #define PF_MIPS_LOCAL 0x10000000 /* Legal values for d_tag field of Elf32_Dyn. */ #define DT_MIPS_RLD_VERSION 0x70000001 /* Runtime linker interface version */ #define DT_MIPS_TIME_STAMP 0x70000002 /* Timestamp */ #define DT_MIPS_ICHECKSUM 0x70000003 /* Checksum */ #define DT_MIPS_IVERSION 0x70000004 /* Version string (string tbl index) */ #define DT_MIPS_FLAGS 0x70000005 /* Flags */ #define DT_MIPS_BASE_ADDRESS 0x70000006 /* Base address */ #define DT_MIPS_MSYM 0x70000007 #define DT_MIPS_CONFLICT 0x70000008 /* Address of CONFLICT section */ #define DT_MIPS_LIBLIST 0x70000009 /* Address of LIBLIST section */ #define DT_MIPS_LOCAL_GOTNO 0x7000000a /* Number of local GOT entries */ #define DT_MIPS_CONFLICTNO 0x7000000b /* Number of CONFLICT entries */ #define DT_MIPS_LIBLISTNO 0x70000010 /* Number of LIBLIST entries */ #define DT_MIPS_SYMTABNO 0x70000011 /* Number of DYNSYM entries */ #define DT_MIPS_UNREFEXTNO 0x70000012 /* First external DYNSYM */ #define DT_MIPS_GOTSYM 0x70000013 /* First GOT entry in DYNSYM */ #define DT_MIPS_HIPAGENO 0x70000014 /* Number of GOT page table entries */ #define DT_MIPS_RLD_MAP 0x70000016 /* Address of run time loader map. */ #define DT_MIPS_DELTA_CLASS 0x70000017 /* Delta C++ class definition. */ #define DT_MIPS_DELTA_CLASS_NO 0x70000018 /* Number of entries in DT_MIPS_DELTA_CLASS. */ #define DT_MIPS_DELTA_INSTANCE 0x70000019 /* Delta C++ class instances. */ #define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a /* Number of entries in DT_MIPS_DELTA_INSTANCE. */ #define DT_MIPS_DELTA_RELOC 0x7000001b /* Delta relocations. */ #define DT_MIPS_DELTA_RELOC_NO 0x7000001c /* Number of entries in DT_MIPS_DELTA_RELOC. */ #define DT_MIPS_DELTA_SYM 0x7000001d /* Delta symbols that Delta relocations refer to. */ #define DT_MIPS_DELTA_SYM_NO 0x7000001e /* Number of entries in DT_MIPS_DELTA_SYM. */ #define DT_MIPS_DELTA_CLASSSYM 0x70000020 /* Delta symbols that hold the class declaration. */ #define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 /* Number of entries in DT_MIPS_DELTA_CLASSSYM. */ #define DT_MIPS_CXX_FLAGS 0x70000022 /* Flags indicating for C++ flavor. */ #define DT_MIPS_PIXIE_INIT 0x70000023 #define DT_MIPS_SYMBOL_LIB 0x70000024 #define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 #define DT_MIPS_LOCAL_GOTIDX 0x70000026 #define DT_MIPS_HIDDEN_GOTIDX 0x70000027 #define DT_MIPS_PROTECTED_GOTIDX 0x70000028 #define DT_MIPS_OPTIONS 0x70000029 /* Address of .options. */ #define DT_MIPS_INTERFACE 0x7000002a /* Address of .interface. */ #define DT_MIPS_DYNSTR_ALIGN 0x7000002b #define DT_MIPS_INTERFACE_SIZE 0x7000002c /* Size of the .interface section. */ #define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d /* Address of rld_text_rsolve function stored in GOT. */ #define DT_MIPS_PERF_SUFFIX 0x7000002e /* Default suffix of dso to be added by rld on dlopen() calls. */ #define DT_MIPS_COMPACT_SIZE 0x7000002f /* (O32)Size of compact rel section. */ #define DT_MIPS_GP_VALUE 0x70000030 /* GP value for aux GOTs. */ #define DT_MIPS_AUX_DYNAMIC 0x70000031 /* Address of aux .dynamic. */ #define DT_MIPS_NUM 0x32 /* Legal values for DT_MIPS_FLAGS Elf32_Dyn entry. */ #define RHF_NONE 0 /* No flags */ #define RHF_QUICKSTART (1 << 0) /* Use quickstart */ #define RHF_NOTPOT (1 << 1) /* Hash size not power of 2 */ #define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) /* Ignore LD_LIBRARY_PATH */ #define RHF_NO_MOVE (1 << 3) #define RHF_SGI_ONLY (1 << 4) #define RHF_GUARANTEE_INIT (1 << 5) #define RHF_DELTA_C_PLUS_PLUS (1 << 6) #define RHF_GUARANTEE_START_INIT (1 << 7) #define RHF_PIXIE (1 << 8) #define RHF_DEFAULT_DELAY_LOAD (1 << 9) #define RHF_REQUICKSTART (1 << 10) #define RHF_REQUICKSTARTED (1 << 11) #define RHF_CORD (1 << 12) #define RHF_NO_UNRES_UNDEF (1 << 13) #define RHF_RLD_ORDER_SAFE (1 << 14) /* Entries found in sections of type SHT_MIPS_LIBLIST. */ typedef struct { Elf32_Word l_name; /* Name (string table index) */ Elf32_Word l_time_stamp; /* Timestamp */ Elf32_Word l_checksum; /* Checksum */ Elf32_Word l_version; /* Interface version */ Elf32_Word l_flags; /* Flags */ } Elf32_Lib; typedef struct { Elf64_Word l_name; /* Name (string table index) */ Elf64_Word l_time_stamp; /* Timestamp */ Elf64_Word l_checksum; /* Checksum */ Elf64_Word l_version; /* Interface version */ Elf64_Word l_flags; /* Flags */ } Elf64_Lib; /* Legal values for l_flags. */ #define LL_NONE 0 #define LL_EXACT_MATCH (1 << 0) /* Require exact match */ #define LL_IGNORE_INT_VER (1 << 1) /* Ignore interface version */ #define LL_REQUIRE_MINOR (1 << 2) #define LL_EXPORTS (1 << 3) #define LL_DELAY_LOAD (1 << 4) #define LL_DELTA (1 << 5) /* Entries found in sections of type SHT_MIPS_CONFLICT. */ typedef Elf32_Addr Elf32_Conflict; /* HPPA specific definitions. */ /* Legal values for e_flags field of Elf32_Ehdr. */ #define EF_PARISC_TRAPNIL 0x00010000 /* Trap nil pointer dereference. */ #define EF_PARISC_EXT 0x00020000 /* Program uses arch. extensions. */ #define EF_PARISC_LSB 0x00040000 /* Program expects little endian. */ #define EF_PARISC_WIDE 0x00080000 /* Program expects wide mode. */ #define EF_PARISC_NO_KABP 0x00100000 /* No kernel assisted branch prediction. */ #define EF_PARISC_LAZYSWAP 0x00400000 /* Allow lazy swapping. */ #define EF_PARISC_ARCH 0x0000ffff /* Architecture version. */ /* Defined values for `e_flags & EF_PARISC_ARCH' are: */ #define EFA_PARISC_1_0 0x020b /* PA-RISC 1.0 big-endian. */ #define EFA_PARISC_1_1 0x0210 /* PA-RISC 1.1 big-endian. */ #define EFA_PARISC_2_0 0x0214 /* PA-RISC 2.0 big-endian. */ /* Additional section indeces. */ #define SHN_PARISC_ANSI_COMMON 0xff00 /* Section for tenatively declared symbols in ANSI C. */ #define SHN_PARISC_HUGE_COMMON 0xff01 /* Common blocks in huge model. */ /* Legal values for sh_type field of Elf32_Shdr. */ #define SHT_PARISC_EXT 0x70000000 /* Contains product specific ext. */ #define SHT_PARISC_UNWIND 0x70000001 /* Unwind information. */ #define SHT_PARISC_DOC 0x70000002 /* Debug info for optimized code. */ /* Legal values for sh_flags field of Elf32_Shdr. */ #define SHF_PARISC_SHORT 0x20000000 /* Section with short addressing. */ #define SHF_PARISC_HUGE 0x40000000 /* Section far from gp. */ #define SHF_PARISC_SBP 0x80000000 /* Static branch prediction code. */ /* Legal values for ST_TYPE subfield of st_info (symbol type). */ #define STT_PARISC_MILLICODE 13 /* Millicode function entry point. */ #define STT_HP_OPAQUE (STT_LOOS + 0x1) #define STT_HP_STUB (STT_LOOS + 0x2) /* HPPA relocs. */ #define R_PARISC_NONE 0 /* No reloc. */ #define R_PARISC_DIR32 1 /* Direct 32-bit reference. */ #define R_PARISC_DIR21L 2 /* Left 21 bits of eff. address. */ #define R_PARISC_DIR17R 3 /* Right 17 bits of eff. address. */ #define R_PARISC_DIR17F 4 /* 17 bits of eff. address. */ #define R_PARISC_DIR14R 6 /* Right 14 bits of eff. address. */ #define R_PARISC_PCREL32 9 /* 32-bit rel. address. */ #define R_PARISC_PCREL21L 10 /* Left 21 bits of rel. address. */ #define R_PARISC_PCREL17R 11 /* Right 17 bits of rel. address. */ #define R_PARISC_PCREL17F 12 /* 17 bits of rel. address. */ #define R_PARISC_PCREL14R 14 /* Right 14 bits of rel. address. */ #define R_PARISC_DPREL21L 18 /* Left 21 bits of rel. address. */ #define R_PARISC_DPREL14R 22 /* Right 14 bits of rel. address. */ #define R_PARISC_GPREL21L 26 /* GP-relative, left 21 bits. */ #define R_PARISC_GPREL14R 30 /* GP-relative, right 14 bits. */ #define R_PARISC_LTOFF21L 34 /* LT-relative, left 21 bits. */ #define R_PARISC_LTOFF14R 38 /* LT-relative, right 14 bits. */ #define R_PARISC_SECREL32 41 /* 32 bits section rel. address. */ #define R_PARISC_SEGBASE 48 /* No relocation, set segment base. */ #define R_PARISC_SEGREL32 49 /* 32 bits segment rel. address. */ #define R_PARISC_PLTOFF21L 50 /* PLT rel. address, left 21 bits. */ #define R_PARISC_PLTOFF14R 54 /* PLT rel. address, right 14 bits. */ #define R_PARISC_LTOFF_FPTR32 57 /* 32 bits LT-rel. function pointer. */ #define R_PARISC_LTOFF_FPTR21L 58 /* LT-rel. fct ptr, left 21 bits. */ #define R_PARISC_LTOFF_FPTR14R 62 /* LT-rel. fct ptr, right 14 bits. */ #define R_PARISC_FPTR64 64 /* 64 bits function address. */ #define R_PARISC_PLABEL32 65 /* 32 bits function address. */ #define R_PARISC_PCREL64 72 /* 64 bits PC-rel. address. */ #define R_PARISC_PCREL22F 74 /* 22 bits PC-rel. address. */ #define R_PARISC_PCREL14WR 75 /* PC-rel. address, right 14 bits. */ #define R_PARISC_PCREL14DR 76 /* PC rel. address, right 14 bits. */ #define R_PARISC_PCREL16F 77 /* 16 bits PC-rel. address. */ #define R_PARISC_PCREL16WF 78 /* 16 bits PC-rel. address. */ #define R_PARISC_PCREL16DF 79 /* 16 bits PC-rel. address. */ #define R_PARISC_DIR64 80 /* 64 bits of eff. address. */ #define R_PARISC_DIR14WR 83 /* 14 bits of eff. address. */ #define R_PARISC_DIR14DR 84 /* 14 bits of eff. address. */ #define R_PARISC_DIR16F 85 /* 16 bits of eff. address. */ #define R_PARISC_DIR16WF 86 /* 16 bits of eff. address. */ #define R_PARISC_DIR16DF 87 /* 16 bits of eff. address. */ #define R_PARISC_GPREL64 88 /* 64 bits of GP-rel. address. */ #define R_PARISC_GPREL14WR 91 /* GP-rel. address, right 14 bits. */ #define R_PARISC_GPREL14DR 92 /* GP-rel. address, right 14 bits. */ #define R_PARISC_GPREL16F 93 /* 16 bits GP-rel. address. */ #define R_PARISC_GPREL16WF 94 /* 16 bits GP-rel. address. */ #define R_PARISC_GPREL16DF 95 /* 16 bits GP-rel. address. */ #define R_PARISC_LTOFF64 96 /* 64 bits LT-rel. address. */ #define R_PARISC_LTOFF14WR 99 /* LT-rel. address, right 14 bits. */ #define R_PARISC_LTOFF14DR 100 /* LT-rel. address, right 14 bits. */ #define R_PARISC_LTOFF16F 101 /* 16 bits LT-rel. address. */ #define R_PARISC_LTOFF16WF 102 /* 16 bits LT-rel. address. */ #define R_PARISC_LTOFF16DF 103 /* 16 bits LT-rel. address. */ #define R_PARISC_SECREL64 104 /* 64 bits section rel. address. */ #define R_PARISC_SEGREL64 112 /* 64 bits segment rel. address. */ #define R_PARISC_PLTOFF14WR 115 /* PLT-rel. address, right 14 bits. */ #define R_PARISC_PLTOFF14DR 116 /* PLT-rel. address, right 14 bits. */ #define R_PARISC_PLTOFF16F 117 /* 16 bits LT-rel. address. */ #define R_PARISC_PLTOFF16WF 118 /* 16 bits PLT-rel. address. */ #define R_PARISC_PLTOFF16DF 119 /* 16 bits PLT-rel. address. */ #define R_PARISC_LTOFF_FPTR64 120 /* 64 bits LT-rel. function ptr. */ #define R_PARISC_LTOFF_FPTR14WR 123 /* LT-rel. fct. ptr., right 14 bits. */ #define R_PARISC_LTOFF_FPTR14DR 124 /* LT-rel. fct. ptr., right 14 bits. */ #define R_PARISC_LTOFF_FPTR16F 125 /* 16 bits LT-rel. function ptr. */ #define R_PARISC_LTOFF_FPTR16WF 126 /* 16 bits LT-rel. function ptr. */ #define R_PARISC_LTOFF_FPTR16DF 127 /* 16 bits LT-rel. function ptr. */ #define R_PARISC_LORESERVE 128 #define R_PARISC_COPY 128 /* Copy relocation. */ #define R_PARISC_IPLT 129 /* Dynamic reloc, imported PLT */ #define R_PARISC_EPLT 130 /* Dynamic reloc, exported PLT */ #define R_PARISC_TPREL32 153 /* 32 bits TP-rel. address. */ #define R_PARISC_TPREL21L 154 /* TP-rel. address, left 21 bits. */ #define R_PARISC_TPREL14R 158 /* TP-rel. address, right 14 bits. */ #define R_PARISC_LTOFF_TP21L 162 /* LT-TP-rel. address, left 21 bits. */ #define R_PARISC_LTOFF_TP14R 166 /* LT-TP-rel. address, right 14 bits.*/ #define R_PARISC_LTOFF_TP14F 167 /* 14 bits LT-TP-rel. address. */ #define R_PARISC_TPREL64 216 /* 64 bits TP-rel. address. */ #define R_PARISC_TPREL14WR 219 /* TP-rel. address, right 14 bits. */ #define R_PARISC_TPREL14DR 220 /* TP-rel. address, right 14 bits. */ #define R_PARISC_TPREL16F 221 /* 16 bits TP-rel. address. */ #define R_PARISC_TPREL16WF 222 /* 16 bits TP-rel. address. */ #define R_PARISC_TPREL16DF 223 /* 16 bits TP-rel. address. */ #define R_PARISC_LTOFF_TP64 224 /* 64 bits LT-TP-rel. address. */ #define R_PARISC_LTOFF_TP14WR 227 /* LT-TP-rel. address, right 14 bits.*/ #define R_PARISC_LTOFF_TP14DR 228 /* LT-TP-rel. address, right 14 bits.*/ #define R_PARISC_LTOFF_TP16F 229 /* 16 bits LT-TP-rel. address. */ #define R_PARISC_LTOFF_TP16WF 230 /* 16 bits LT-TP-rel. address. */ #define R_PARISC_LTOFF_TP16DF 231 /* 16 bits LT-TP-rel. address. */ #define R_PARISC_HIRESERVE 255 /* Legal values for p_type field of Elf32_Phdr/Elf64_Phdr. */ #define PT_HP_TLS (PT_LOOS + 0x0) #define PT_HP_CORE_NONE (PT_LOOS + 0x1) #define PT_HP_CORE_VERSION (PT_LOOS + 0x2) #define PT_HP_CORE_KERNEL (PT_LOOS + 0x3) #define PT_HP_CORE_COMM (PT_LOOS + 0x4) #define PT_HP_CORE_PROC (PT_LOOS + 0x5) #define PT_HP_CORE_LOADABLE (PT_LOOS + 0x6) #define PT_HP_CORE_STACK (PT_LOOS + 0x7) #define PT_HP_CORE_SHM (PT_LOOS + 0x8) #define PT_HP_CORE_MMF (PT_LOOS + 0x9) #define PT_HP_PARALLEL (PT_LOOS + 0x10) #define PT_HP_FASTBIND (PT_LOOS + 0x11) #define PT_HP_OPT_ANNOT (PT_LOOS + 0x12) #define PT_HP_HSL_ANNOT (PT_LOOS + 0x13) #define PT_HP_STACK (PT_LOOS + 0x14) #define PT_PARISC_ARCHEXT 0x70000000 #define PT_PARISC_UNWIND 0x70000001 /* Legal values for p_flags field of Elf32_Phdr/Elf64_Phdr. */ #define PF_PARISC_SBP 0x08000000 #define PF_HP_PAGE_SIZE 0x00100000 #define PF_HP_FAR_SHARED 0x00200000 #define PF_HP_NEAR_SHARED 0x00400000 #define PF_HP_CODE 0x01000000 #define PF_HP_MODIFY 0x02000000 #define PF_HP_LAZYSWAP 0x04000000 #define PF_HP_SBP 0x08000000 /* Alpha specific definitions. */ /* Legal values for e_flags field of Elf64_Ehdr. */ #define EF_ALPHA_32BIT 1 /* All addresses must be < 2GB. */ #define EF_ALPHA_CANRELAX 2 /* Relocations for relaxing exist. */ /* Legal values for sh_type field of Elf64_Shdr. */ /* These two are primerily concerned with ECOFF debugging info. */ #define SHT_ALPHA_DEBUG 0x70000001 #define SHT_ALPHA_REGINFO 0x70000002 /* Legal values for sh_flags field of Elf64_Shdr. */ #define SHF_ALPHA_GPREL 0x10000000 /* Legal values for st_other field of Elf64_Sym. */ #define STO_ALPHA_NOPV 0x80 /* No PV required. */ #define STO_ALPHA_STD_GPLOAD 0x88 /* PV only used for initial ldgp. */ /* Alpha relocs. */ #define R_ALPHA_NONE 0 /* No reloc */ #define R_ALPHA_REFLONG 1 /* Direct 32 bit */ #define R_ALPHA_REFQUAD 2 /* Direct 64 bit */ #define R_ALPHA_GPREL32 3 /* GP relative 32 bit */ #define R_ALPHA_LITERAL 4 /* GP relative 16 bit w/optimization */ #define R_ALPHA_LITUSE 5 /* Optimization hint for LITERAL */ #define R_ALPHA_GPDISP 6 /* Add displacement to GP */ #define R_ALPHA_BRADDR 7 /* PC+4 relative 23 bit shifted */ #define R_ALPHA_HINT 8 /* PC+4 relative 16 bit shifted */ #define R_ALPHA_SREL16 9 /* PC relative 16 bit */ #define R_ALPHA_SREL32 10 /* PC relative 32 bit */ #define R_ALPHA_SREL64 11 /* PC relative 64 bit */ #define R_ALPHA_GPRELHIGH 17 /* GP relative 32 bit, high 16 bits */ #define R_ALPHA_GPRELLOW 18 /* GP relative 32 bit, low 16 bits */ #define R_ALPHA_GPREL16 19 /* GP relative 16 bit */ #define R_ALPHA_COPY 24 /* Copy symbol at runtime */ #define R_ALPHA_GLOB_DAT 25 /* Create GOT entry */ #define R_ALPHA_JMP_SLOT 26 /* Create PLT entry */ #define R_ALPHA_RELATIVE 27 /* Adjust by program base */ #define R_ALPHA_TLS_GD_HI 28 #define R_ALPHA_TLSGD 29 #define R_ALPHA_TLS_LDM 30 #define R_ALPHA_DTPMOD64 31 #define R_ALPHA_GOTDTPREL 32 #define R_ALPHA_DTPREL64 33 #define R_ALPHA_DTPRELHI 34 #define R_ALPHA_DTPRELLO 35 #define R_ALPHA_DTPREL16 36 #define R_ALPHA_GOTTPREL 37 #define R_ALPHA_TPREL64 38 #define R_ALPHA_TPRELHI 39 #define R_ALPHA_TPRELLO 40 #define R_ALPHA_TPREL16 41 /* Keep this the last entry. */ #define R_ALPHA_NUM 46 /* Magic values of the LITUSE relocation addend. */ #define LITUSE_ALPHA_ADDR 0 #define LITUSE_ALPHA_BASE 1 #define LITUSE_ALPHA_BYTOFF 2 #define LITUSE_ALPHA_JSR 3 #define LITUSE_ALPHA_TLS_GD 4 #define LITUSE_ALPHA_TLS_LDM 5 /* PowerPC specific declarations */ /* Values for Elf32/64_Ehdr.e_flags. */ #define EF_PPC_EMB 0x80000000 /* PowerPC embedded flag */ /* Cygnus local bits below */ #define EF_PPC_RELOCATABLE 0x00010000 /* PowerPC -mrelocatable flag*/ #define EF_PPC_RELOCATABLE_LIB 0x00008000 /* PowerPC -mrelocatable-lib flag */ /* PowerPC relocations defined by the ABIs */ #define R_PPC_NONE 0 #define R_PPC_ADDR32 1 /* 32bit absolute address */ #define R_PPC_ADDR24 2 /* 26bit address, 2 bits ignored. */ #define R_PPC_ADDR16 3 /* 16bit absolute address */ #define R_PPC_ADDR16_LO 4 /* lower 16bit of absolute address */ #define R_PPC_ADDR16_HI 5 /* high 16bit of absolute address */ #define R_PPC_ADDR16_HA 6 /* adjusted high 16bit */ #define R_PPC_ADDR14 7 /* 16bit address, 2 bits ignored */ #define R_PPC_ADDR14_BRTAKEN 8 #define R_PPC_ADDR14_BRNTAKEN 9 #define R_PPC_REL24 10 /* PC relative 26 bit */ #define R_PPC_REL14 11 /* PC relative 16 bit */ #define R_PPC_REL14_BRTAKEN 12 #define R_PPC_REL14_BRNTAKEN 13 #define R_PPC_GOT16 14 #define R_PPC_GOT16_LO 15 #define R_PPC_GOT16_HI 16 #define R_PPC_GOT16_HA 17 #define R_PPC_PLTREL24 18 #define R_PPC_COPY 19 #define R_PPC_GLOB_DAT 20 #define R_PPC_JMP_SLOT 21 #define R_PPC_RELATIVE 22 #define R_PPC_LOCAL24PC 23 #define R_PPC_UADDR32 24 #define R_PPC_UADDR16 25 #define R_PPC_REL32 26 #define R_PPC_PLT32 27 #define R_PPC_PLTREL32 28 #define R_PPC_PLT16_LO 29 #define R_PPC_PLT16_HI 30 #define R_PPC_PLT16_HA 31 #define R_PPC_SDAREL16 32 #define R_PPC_SECTOFF 33 #define R_PPC_SECTOFF_LO 34 #define R_PPC_SECTOFF_HI 35 #define R_PPC_SECTOFF_HA 36 /* PowerPC relocations defined for the TLS access ABI. */ #define R_PPC_TLS 67 /* none (sym+add)@tls */ #define R_PPC_DTPMOD32 68 /* word32 (sym+add)@dtpmod */ #define R_PPC_TPREL16 69 /* half16* (sym+add)@tprel */ #define R_PPC_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ #define R_PPC_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ #define R_PPC_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ #define R_PPC_TPREL32 73 /* word32 (sym+add)@tprel */ #define R_PPC_DTPREL16 74 /* half16* (sym+add)@dtprel */ #define R_PPC_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ #define R_PPC_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ #define R_PPC_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ #define R_PPC_DTPREL32 78 /* word32 (sym+add)@dtprel */ #define R_PPC_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ #define R_PPC_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ #define R_PPC_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ #define R_PPC_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ #define R_PPC_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ #define R_PPC_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ #define R_PPC_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ #define R_PPC_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ #define R_PPC_GOT_TPREL16 87 /* half16* (sym+add)@got@tprel */ #define R_PPC_GOT_TPREL16_LO 88 /* half16 (sym+add)@got@tprel@l */ #define R_PPC_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ #define R_PPC_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ #define R_PPC_GOT_DTPREL16 91 /* half16* (sym+add)@got@dtprel */ #define R_PPC_GOT_DTPREL16_LO 92 /* half16* (sym+add)@got@dtprel@l */ #define R_PPC_GOT_DTPREL16_HI 93 /* half16* (sym+add)@got@dtprel@h */ #define R_PPC_GOT_DTPREL16_HA 94 /* half16* (sym+add)@got@dtprel@ha */ /* Keep this the last entry. */ #define R_PPC_NUM 95 /* The remaining relocs are from the Embedded ELF ABI, and are not in the SVR4 ELF ABI. */ #define R_PPC_EMB_NADDR32 101 #define R_PPC_EMB_NADDR16 102 #define R_PPC_EMB_NADDR16_LO 103 #define R_PPC_EMB_NADDR16_HI 104 #define R_PPC_EMB_NADDR16_HA 105 #define R_PPC_EMB_SDAI16 106 #define R_PPC_EMB_SDA2I16 107 #define R_PPC_EMB_SDA2REL 108 #define R_PPC_EMB_SDA21 109 /* 16 bit offset in SDA */ #define R_PPC_EMB_MRKREF 110 #define R_PPC_EMB_RELSEC16 111 #define R_PPC_EMB_RELST_LO 112 #define R_PPC_EMB_RELST_HI 113 #define R_PPC_EMB_RELST_HA 114 #define R_PPC_EMB_BIT_FLD 115 #define R_PPC_EMB_RELSDA 116 /* 16 bit relative offset in SDA */ /* Diab tool relocations. */ #define R_PPC_DIAB_SDA21_LO 180 /* like EMB_SDA21, but lower 16 bit */ #define R_PPC_DIAB_SDA21_HI 181 /* like EMB_SDA21, but high 16 bit */ #define R_PPC_DIAB_SDA21_HA 182 /* like EMB_SDA21, adjusted high 16 */ #define R_PPC_DIAB_RELSDA_LO 183 /* like EMB_RELSDA, but lower 16 bit */ #define R_PPC_DIAB_RELSDA_HI 184 /* like EMB_RELSDA, but high 16 bit */ #define R_PPC_DIAB_RELSDA_HA 185 /* like EMB_RELSDA, adjusted high 16 */ /* This is a phony reloc to handle any old fashioned TOC16 references that may still be in object files. */ #define R_PPC_TOC16 255 /* PowerPC64 relocations defined by the ABIs */ #define R_PPC64_NONE R_PPC_NONE #define R_PPC64_ADDR32 R_PPC_ADDR32 /* 32bit absolute address */ #define R_PPC64_ADDR24 R_PPC_ADDR24 /* 26bit address, word aligned */ #define R_PPC64_ADDR16 R_PPC_ADDR16 /* 16bit absolute address */ #define R_PPC64_ADDR16_LO R_PPC_ADDR16_LO /* lower 16bits of address */ #define R_PPC64_ADDR16_HI R_PPC_ADDR16_HI /* high 16bits of address. */ #define R_PPC64_ADDR16_HA R_PPC_ADDR16_HA /* adjusted high 16bits. */ #define R_PPC64_ADDR14 R_PPC_ADDR14 /* 16bit address, word aligned */ #define R_PPC64_ADDR14_BRTAKEN R_PPC_ADDR14_BRTAKEN #define R_PPC64_ADDR14_BRNTAKEN R_PPC_ADDR14_BRNTAKEN #define R_PPC64_REL24 R_PPC_REL24 /* PC-rel. 26 bit, word aligned */ #define R_PPC64_REL14 R_PPC_REL14 /* PC relative 16 bit */ #define R_PPC64_REL14_BRTAKEN R_PPC_REL14_BRTAKEN #define R_PPC64_REL14_BRNTAKEN R_PPC_REL14_BRNTAKEN #define R_PPC64_GOT16 R_PPC_GOT16 #define R_PPC64_GOT16_LO R_PPC_GOT16_LO #define R_PPC64_GOT16_HI R_PPC_GOT16_HI #define R_PPC64_GOT16_HA R_PPC_GOT16_HA #define R_PPC64_COPY R_PPC_COPY #define R_PPC64_GLOB_DAT R_PPC_GLOB_DAT #define R_PPC64_JMP_SLOT R_PPC_JMP_SLOT #define R_PPC64_RELATIVE R_PPC_RELATIVE #define R_PPC64_UADDR32 R_PPC_UADDR32 #define R_PPC64_UADDR16 R_PPC_UADDR16 #define R_PPC64_REL32 R_PPC_REL32 #define R_PPC64_PLT32 R_PPC_PLT32 #define R_PPC64_PLTREL32 R_PPC_PLTREL32 #define R_PPC64_PLT16_LO R_PPC_PLT16_LO #define R_PPC64_PLT16_HI R_PPC_PLT16_HI #define R_PPC64_PLT16_HA R_PPC_PLT16_HA #define R_PPC64_SECTOFF R_PPC_SECTOFF #define R_PPC64_SECTOFF_LO R_PPC_SECTOFF_LO #define R_PPC64_SECTOFF_HI R_PPC_SECTOFF_HI #define R_PPC64_SECTOFF_HA R_PPC_SECTOFF_HA #define R_PPC64_ADDR30 37 /* word30 (S + A - P) >> 2 */ #define R_PPC64_ADDR64 38 /* doubleword64 S + A */ #define R_PPC64_ADDR16_HIGHER 39 /* half16 #higher(S + A) */ #define R_PPC64_ADDR16_HIGHERA 40 /* half16 #highera(S + A) */ #define R_PPC64_ADDR16_HIGHEST 41 /* half16 #highest(S + A) */ #define R_PPC64_ADDR16_HIGHESTA 42 /* half16 #highesta(S + A) */ #define R_PPC64_UADDR64 43 /* doubleword64 S + A */ #define R_PPC64_REL64 44 /* doubleword64 S + A - P */ #define R_PPC64_PLT64 45 /* doubleword64 L + A */ #define R_PPC64_PLTREL64 46 /* doubleword64 L + A - P */ #define R_PPC64_TOC16 47 /* half16* S + A - .TOC */ #define R_PPC64_TOC16_LO 48 /* half16 #lo(S + A - .TOC.) */ #define R_PPC64_TOC16_HI 49 /* half16 #hi(S + A - .TOC.) */ #define R_PPC64_TOC16_HA 50 /* half16 #ha(S + A - .TOC.) */ #define R_PPC64_TOC 51 /* doubleword64 .TOC */ #define R_PPC64_PLTGOT16 52 /* half16* M + A */ #define R_PPC64_PLTGOT16_LO 53 /* half16 #lo(M + A) */ #define R_PPC64_PLTGOT16_HI 54 /* half16 #hi(M + A) */ #define R_PPC64_PLTGOT16_HA 55 /* half16 #ha(M + A) */ #define R_PPC64_ADDR16_DS 56 /* half16ds* (S + A) >> 2 */ #define R_PPC64_ADDR16_LO_DS 57 /* half16ds #lo(S + A) >> 2 */ #define R_PPC64_GOT16_DS 58 /* half16ds* (G + A) >> 2 */ #define R_PPC64_GOT16_LO_DS 59 /* half16ds #lo(G + A) >> 2 */ #define R_PPC64_PLT16_LO_DS 60 /* half16ds #lo(L + A) >> 2 */ #define R_PPC64_SECTOFF_DS 61 /* half16ds* (R + A) >> 2 */ #define R_PPC64_SECTOFF_LO_DS 62 /* half16ds #lo(R + A) >> 2 */ #define R_PPC64_TOC16_DS 63 /* half16ds* (S + A - .TOC.) >> 2 */ #define R_PPC64_TOC16_LO_DS 64 /* half16ds #lo(S + A - .TOC.) >> 2 */ #define R_PPC64_PLTGOT16_DS 65 /* half16ds* (M + A) >> 2 */ #define R_PPC64_PLTGOT16_LO_DS 66 /* half16ds #lo(M + A) >> 2 */ /* PowerPC64 relocations defined for the TLS access ABI. */ #define R_PPC64_TLS 67 /* none (sym+add)@tls */ #define R_PPC64_DTPMOD64 68 /* doubleword64 (sym+add)@dtpmod */ #define R_PPC64_TPREL16 69 /* half16* (sym+add)@tprel */ #define R_PPC64_TPREL16_LO 70 /* half16 (sym+add)@tprel@l */ #define R_PPC64_TPREL16_HI 71 /* half16 (sym+add)@tprel@h */ #define R_PPC64_TPREL16_HA 72 /* half16 (sym+add)@tprel@ha */ #define R_PPC64_TPREL64 73 /* doubleword64 (sym+add)@tprel */ #define R_PPC64_DTPREL16 74 /* half16* (sym+add)@dtprel */ #define R_PPC64_DTPREL16_LO 75 /* half16 (sym+add)@dtprel@l */ #define R_PPC64_DTPREL16_HI 76 /* half16 (sym+add)@dtprel@h */ #define R_PPC64_DTPREL16_HA 77 /* half16 (sym+add)@dtprel@ha */ #define R_PPC64_DTPREL64 78 /* doubleword64 (sym+add)@dtprel */ #define R_PPC64_GOT_TLSGD16 79 /* half16* (sym+add)@got@tlsgd */ #define R_PPC64_GOT_TLSGD16_LO 80 /* half16 (sym+add)@got@tlsgd@l */ #define R_PPC64_GOT_TLSGD16_HI 81 /* half16 (sym+add)@got@tlsgd@h */ #define R_PPC64_GOT_TLSGD16_HA 82 /* half16 (sym+add)@got@tlsgd@ha */ #define R_PPC64_GOT_TLSLD16 83 /* half16* (sym+add)@got@tlsld */ #define R_PPC64_GOT_TLSLD16_LO 84 /* half16 (sym+add)@got@tlsld@l */ #define R_PPC64_GOT_TLSLD16_HI 85 /* half16 (sym+add)@got@tlsld@h */ #define R_PPC64_GOT_TLSLD16_HA 86 /* half16 (sym+add)@got@tlsld@ha */ #define R_PPC64_GOT_TPREL16_DS 87 /* half16ds* (sym+add)@got@tprel */ #define R_PPC64_GOT_TPREL16_LO_DS 88 /* half16ds (sym+add)@got@tprel@l */ #define R_PPC64_GOT_TPREL16_HI 89 /* half16 (sym+add)@got@tprel@h */ #define R_PPC64_GOT_TPREL16_HA 90 /* half16 (sym+add)@got@tprel@ha */ #define R_PPC64_GOT_DTPREL16_DS 91 /* half16ds* (sym+add)@got@dtprel */ #define R_PPC64_GOT_DTPREL16_LO_DS 92 /* half16ds (sym+add)@got@dtprel@l */ #define R_PPC64_GOT_DTPREL16_HI 93 /* half16 (sym+add)@got@dtprel@h */ #define R_PPC64_GOT_DTPREL16_HA 94 /* half16 (sym+add)@got@dtprel@ha */ #define R_PPC64_TPREL16_DS 95 /* half16ds* (sym+add)@tprel */ #define R_PPC64_TPREL16_LO_DS 96 /* half16ds (sym+add)@tprel@l */ #define R_PPC64_TPREL16_HIGHER 97 /* half16 (sym+add)@tprel@higher */ #define R_PPC64_TPREL16_HIGHERA 98 /* half16 (sym+add)@tprel@highera */ #define R_PPC64_TPREL16_HIGHEST 99 /* half16 (sym+add)@tprel@highest */ #define R_PPC64_TPREL16_HIGHESTA 100 /* half16 (sym+add)@tprel@highesta */ #define R_PPC64_DTPREL16_DS 101 /* half16ds* (sym+add)@dtprel */ #define R_PPC64_DTPREL16_LO_DS 102 /* half16ds (sym+add)@dtprel@l */ #define R_PPC64_DTPREL16_HIGHER 103 /* half16 (sym+add)@dtprel@higher */ #define R_PPC64_DTPREL16_HIGHERA 104 /* half16 (sym+add)@dtprel@highera */ #define R_PPC64_DTPREL16_HIGHEST 105 /* half16 (sym+add)@dtprel@highest */ #define R_PPC64_DTPREL16_HIGHESTA 106 /* half16 (sym+add)@dtprel@highesta */ /* Keep this the last entry. */ #define R_PPC64_NUM 107 /* PowerPC64 specific values for the Dyn d_tag field. */ #define DT_PPC64_GLINK (DT_LOPROC + 0) #define DT_PPC64_NUM 1 /* ARM specific declarations */ /* Processor specific flags for the ELF header e_flags field. */ #define EF_ARM_RELEXEC 0x01 #define EF_ARM_HASENTRY 0x02 #define EF_ARM_INTERWORK 0x04 #define EF_ARM_APCS_26 0x08 #define EF_ARM_APCS_FLOAT 0x10 #define EF_ARM_PIC 0x20 #define EF_ARM_ALIGN8 0x40 /* 8-bit structure alignment is in use */ #define EF_ARM_NEW_ABI 0x80 #define EF_ARM_OLD_ABI 0x100 /* Other constants defined in the ARM ELF spec. version B-01. */ /* NB. These conflict with values defined above. */ #define EF_ARM_SYMSARESORTED 0x04 #define EF_ARM_DYNSYMSUSESEGIDX 0x08 #define EF_ARM_MAPSYMSFIRST 0x10 #define EF_ARM_EABIMASK 0XFF000000 #define EF_ARM_EABI_VERSION(flags) ((flags) & EF_ARM_EABIMASK) #define EF_ARM_EABI_UNKNOWN 0x00000000 #define EF_ARM_EABI_VER1 0x01000000 #define EF_ARM_EABI_VER2 0x02000000 #define EF_ARM_EABI_VER4 0x04000000 /* Additional symbol types for Thumb */ #define STT_ARM_TFUNC 0xd /* ARM-specific values for sh_flags */ #define SHF_ARM_ENTRYSECT 0x10000000 /* Section contains an entry point */ #define SHF_ARM_COMDEF 0x80000000 /* Section may be multiply defined in the input to a link step */ /* ARM-specific program header flags */ #define PF_ARM_SB 0x10000000 /* Segment contains the location addressed by the static base */ /* ARM relocs. */ #define R_ARM_NONE 0 /* No reloc */ #define R_ARM_PC24 1 /* PC relative 26 bit branch */ #define R_ARM_ABS32 2 /* Direct 32 bit */ #define R_ARM_REL32 3 /* PC relative 32 bit */ #define R_ARM_PC13 4 #define R_ARM_ABS16 5 /* Direct 16 bit */ #define R_ARM_ABS12 6 /* Direct 12 bit */ #define R_ARM_THM_ABS5 7 #define R_ARM_ABS8 8 /* Direct 8 bit */ #define R_ARM_SBREL32 9 #define R_ARM_THM_PC22 10 #define R_ARM_THM_PC8 11 #define R_ARM_AMP_VCALL9 12 #define R_ARM_SWI24 13 #define R_ARM_THM_SWI8 14 #define R_ARM_XPC25 15 #define R_ARM_THM_XPC22 16 #define R_ARM_COPY 20 /* Copy symbol at runtime */ #define R_ARM_GLOB_DAT 21 /* Create GOT entry */ #define R_ARM_JUMP_SLOT 22 /* Create PLT entry */ #define R_ARM_RELATIVE 23 /* Adjust by program base */ #define R_ARM_GOTOFF 24 /* 32 bit offset to GOT */ #define R_ARM_GOTPC 25 /* 32 bit PC relative offset to GOT */ #define R_ARM_GOT32 26 /* 32 bit GOT entry */ #define R_ARM_PLT32 27 /* 32 bit PLT address */ #define R_ARM_ALU_PCREL_7_0 32 #define R_ARM_ALU_PCREL_15_8 33 #define R_ARM_ALU_PCREL_23_15 34 #define R_ARM_LDR_SBREL_11_0 35 #define R_ARM_ALU_SBREL_19_12 36 #define R_ARM_ALU_SBREL_27_20 37 #define R_ARM_GNU_VTENTRY 100 #define R_ARM_GNU_VTINHERIT 101 #define R_ARM_THM_PC11 102 /* thumb unconditional branch */ #define R_ARM_THM_PC9 103 /* thumb conditional branch */ #define R_ARM_RXPC25 249 #define R_ARM_RSBREL32 250 #define R_ARM_THM_RPC22 251 #define R_ARM_RREL32 252 #define R_ARM_RABS22 253 #define R_ARM_RPC24 254 #define R_ARM_RBASE 255 /* Keep this the last entry. */ #define R_ARM_NUM 256 /* IA-64 specific declarations. */ /* Processor specific flags for the Ehdr e_flags field. */ #define EF_IA_64_MASKOS 0x0000000f /* os-specific flags */ #define EF_IA_64_ABI64 0x00000010 /* 64-bit ABI */ #define EF_IA_64_ARCH 0xff000000 /* arch. version mask */ /* Processor specific values for the Phdr p_type field. */ #define PT_IA_64_ARCHEXT (PT_LOPROC + 0) /* arch extension bits */ #define PT_IA_64_UNWIND (PT_LOPROC + 1) /* ia64 unwind bits */ /* Processor specific flags for the Phdr p_flags field. */ #define PF_IA_64_NORECOV 0x80000000 /* spec insns w/o recovery */ /* Processor specific values for the Shdr sh_type field. */ #define SHT_IA_64_EXT (SHT_LOPROC + 0) /* extension bits */ #define SHT_IA_64_UNWIND (SHT_LOPROC + 1) /* unwind bits */ /* Processor specific flags for the Shdr sh_flags field. */ #define SHF_IA_64_SHORT 0x10000000 /* section near gp */ #define SHF_IA_64_NORECOV 0x20000000 /* spec insns w/o recovery */ /* Processor specific values for the Dyn d_tag field. */ #define DT_IA_64_PLT_RESERVE (DT_LOPROC + 0) #define DT_IA_64_NUM 1 /* IA-64 relocations. */ #define R_IA64_NONE 0x00 /* none */ #define R_IA64_IMM14 0x21 /* symbol + addend, add imm14 */ #define R_IA64_IMM22 0x22 /* symbol + addend, add imm22 */ #define R_IA64_IMM64 0x23 /* symbol + addend, mov imm64 */ #define R_IA64_DIR32MSB 0x24 /* symbol + addend, data4 MSB */ #define R_IA64_DIR32LSB 0x25 /* symbol + addend, data4 LSB */ #define R_IA64_DIR64MSB 0x26 /* symbol + addend, data8 MSB */ #define R_IA64_DIR64LSB 0x27 /* symbol + addend, data8 LSB */ #define R_IA64_GPREL22 0x2a /* @gprel(sym + add), add imm22 */ #define R_IA64_GPREL64I 0x2b /* @gprel(sym + add), mov imm64 */ #define R_IA64_GPREL32MSB 0x2c /* @gprel(sym + add), data4 MSB */ #define R_IA64_GPREL32LSB 0x2d /* @gprel(sym + add), data4 LSB */ #define R_IA64_GPREL64MSB 0x2e /* @gprel(sym + add), data8 MSB */ #define R_IA64_GPREL64LSB 0x2f /* @gprel(sym + add), data8 LSB */ #define R_IA64_LTOFF22 0x32 /* @ltoff(sym + add), add imm22 */ #define R_IA64_LTOFF64I 0x33 /* @ltoff(sym + add), mov imm64 */ #define R_IA64_PLTOFF22 0x3a /* @pltoff(sym + add), add imm22 */ #define R_IA64_PLTOFF64I 0x3b /* @pltoff(sym + add), mov imm64 */ #define R_IA64_PLTOFF64MSB 0x3e /* @pltoff(sym + add), data8 MSB */ #define R_IA64_PLTOFF64LSB 0x3f /* @pltoff(sym + add), data8 LSB */ #define R_IA64_FPTR64I 0x43 /* @fptr(sym + add), mov imm64 */ #define R_IA64_FPTR32MSB 0x44 /* @fptr(sym + add), data4 MSB */ #define R_IA64_FPTR32LSB 0x45 /* @fptr(sym + add), data4 LSB */ #define R_IA64_FPTR64MSB 0x46 /* @fptr(sym + add), data8 MSB */ #define R_IA64_FPTR64LSB 0x47 /* @fptr(sym + add), data8 LSB */ #define R_IA64_PCREL60B 0x48 /* @pcrel(sym + add), brl */ #define R_IA64_PCREL21B 0x49 /* @pcrel(sym + add), ptb, call */ #define R_IA64_PCREL21M 0x4a /* @pcrel(sym + add), chk.s */ #define R_IA64_PCREL21F 0x4b /* @pcrel(sym + add), fchkf */ #define R_IA64_PCREL32MSB 0x4c /* @pcrel(sym + add), data4 MSB */ #define R_IA64_PCREL32LSB 0x4d /* @pcrel(sym + add), data4 LSB */ #define R_IA64_PCREL64MSB 0x4e /* @pcrel(sym + add), data8 MSB */ #define R_IA64_PCREL64LSB 0x4f /* @pcrel(sym + add), data8 LSB */ #define R_IA64_LTOFF_FPTR22 0x52 /* @ltoff(@fptr(s+a)), imm22 */ #define R_IA64_LTOFF_FPTR64I 0x53 /* @ltoff(@fptr(s+a)), imm64 */ #define R_IA64_LTOFF_FPTR32MSB 0x54 /* @ltoff(@fptr(s+a)), data4 MSB */ #define R_IA64_LTOFF_FPTR32LSB 0x55 /* @ltoff(@fptr(s+a)), data4 LSB */ #define R_IA64_LTOFF_FPTR64MSB 0x56 /* @ltoff(@fptr(s+a)), data8 MSB */ #define R_IA64_LTOFF_FPTR64LSB 0x57 /* @ltoff(@fptr(s+a)), data8 LSB */ #define R_IA64_SEGREL32MSB 0x5c /* @segrel(sym + add), data4 MSB */ #define R_IA64_SEGREL32LSB 0x5d /* @segrel(sym + add), data4 LSB */ #define R_IA64_SEGREL64MSB 0x5e /* @segrel(sym + add), data8 MSB */ #define R_IA64_SEGREL64LSB 0x5f /* @segrel(sym + add), data8 LSB */ #define R_IA64_SECREL32MSB 0x64 /* @secrel(sym + add), data4 MSB */ #define R_IA64_SECREL32LSB 0x65 /* @secrel(sym + add), data4 LSB */ #define R_IA64_SECREL64MSB 0x66 /* @secrel(sym + add), data8 MSB */ #define R_IA64_SECREL64LSB 0x67 /* @secrel(sym + add), data8 LSB */ #define R_IA64_REL32MSB 0x6c /* data 4 + REL */ #define R_IA64_REL32LSB 0x6d /* data 4 + REL */ #define R_IA64_REL64MSB 0x6e /* data 8 + REL */ #define R_IA64_REL64LSB 0x6f /* data 8 + REL */ #define R_IA64_LTV32MSB 0x74 /* symbol + addend, data4 MSB */ #define R_IA64_LTV32LSB 0x75 /* symbol + addend, data4 LSB */ #define R_IA64_LTV64MSB 0x76 /* symbol + addend, data8 MSB */ #define R_IA64_LTV64LSB 0x77 /* symbol + addend, data8 LSB */ #define R_IA64_PCREL21BI 0x79 /* @pcrel(sym + add), 21bit inst */ #define R_IA64_PCREL22 0x7a /* @pcrel(sym + add), 22bit inst */ #define R_IA64_PCREL64I 0x7b /* @pcrel(sym + add), 64bit inst */ #define R_IA64_IPLTMSB 0x80 /* dynamic reloc, imported PLT, MSB */ #define R_IA64_IPLTLSB 0x81 /* dynamic reloc, imported PLT, LSB */ #define R_IA64_COPY 0x84 /* copy relocation */ #define R_IA64_SUB 0x85 /* Addend and symbol difference */ #define R_IA64_LTOFF22X 0x86 /* LTOFF22, relaxable. */ #define R_IA64_LDXMOV 0x87 /* Use of LTOFF22X. */ #define R_IA64_TPREL14 0x91 /* @tprel(sym + add), imm14 */ #define R_IA64_TPREL22 0x92 /* @tprel(sym + add), imm22 */ #define R_IA64_TPREL64I 0x93 /* @tprel(sym + add), imm64 */ #define R_IA64_TPREL64MSB 0x96 /* @tprel(sym + add), data8 MSB */ #define R_IA64_TPREL64LSB 0x97 /* @tprel(sym + add), data8 LSB */ #define R_IA64_LTOFF_TPREL22 0x9a /* @ltoff(@tprel(s+a)), imm2 */ #define R_IA64_DTPMOD64MSB 0xa6 /* @dtpmod(sym + add), data8 MSB */ #define R_IA64_DTPMOD64LSB 0xa7 /* @dtpmod(sym + add), data8 LSB */ #define R_IA64_LTOFF_DTPMOD22 0xaa /* @ltoff(@dtpmod(sym + add)), imm22 */ #define R_IA64_DTPREL14 0xb1 /* @dtprel(sym + add), imm14 */ #define R_IA64_DTPREL22 0xb2 /* @dtprel(sym + add), imm22 */ #define R_IA64_DTPREL64I 0xb3 /* @dtprel(sym + add), imm64 */ #define R_IA64_DTPREL32MSB 0xb4 /* @dtprel(sym + add), data4 MSB */ #define R_IA64_DTPREL32LSB 0xb5 /* @dtprel(sym + add), data4 LSB */ #define R_IA64_DTPREL64MSB 0xb6 /* @dtprel(sym + add), data8 MSB */ #define R_IA64_DTPREL64LSB 0xb7 /* @dtprel(sym + add), data8 LSB */ #define R_IA64_LTOFF_DTPREL22 0xba /* @ltoff(@dtprel(s+a)), imm22 */ /* SH specific declarations */ /* SH relocs. */ #define R_SH_NONE 0 #define R_SH_DIR32 1 #define R_SH_REL32 2 #define R_SH_DIR8WPN 3 #define R_SH_IND12W 4 #define R_SH_DIR8WPL 5 #define R_SH_DIR8WPZ 6 #define R_SH_DIR8BP 7 #define R_SH_DIR8W 8 #define R_SH_DIR8L 9 #define R_SH_SWITCH16 25 #define R_SH_SWITCH32 26 #define R_SH_USES 27 #define R_SH_COUNT 28 #define R_SH_ALIGN 29 #define R_SH_CODE 30 #define R_SH_DATA 31 #define R_SH_LABEL 32 #define R_SH_SWITCH8 33 #define R_SH_GNU_VTINHERIT 34 #define R_SH_GNU_VTENTRY 35 #define R_SH_TLS_GD_32 144 #define R_SH_TLS_LD_32 145 #define R_SH_TLS_LDO_32 146 #define R_SH_TLS_IE_32 147 #define R_SH_TLS_LE_32 148 #define R_SH_TLS_DTPMOD32 149 #define R_SH_TLS_DTPOFF32 150 #define R_SH_TLS_TPOFF32 151 #define R_SH_GOT32 160 #define R_SH_PLT32 161 #define R_SH_COPY 162 #define R_SH_GLOB_DAT 163 #define R_SH_JMP_SLOT 164 #define R_SH_RELATIVE 165 #define R_SH_GOTOFF 166 #define R_SH_GOTPC 167 /* Keep this the last entry. */ #define R_SH_NUM 256 /* Additional s390 relocs */ #define R_390_NONE 0 /* No reloc. */ #define R_390_8 1 /* Direct 8 bit. */ #define R_390_12 2 /* Direct 12 bit. */ #define R_390_16 3 /* Direct 16 bit. */ #define R_390_32 4 /* Direct 32 bit. */ #define R_390_PC32 5 /* PC relative 32 bit. */ #define R_390_GOT12 6 /* 12 bit GOT offset. */ #define R_390_GOT32 7 /* 32 bit GOT offset. */ #define R_390_PLT32 8 /* 32 bit PC relative PLT address. */ #define R_390_COPY 9 /* Copy symbol at runtime. */ #define R_390_GLOB_DAT 10 /* Create GOT entry. */ #define R_390_JMP_SLOT 11 /* Create PLT entry. */ #define R_390_RELATIVE 12 /* Adjust by program base. */ #define R_390_GOTOFF32 13 /* 32 bit offset to GOT. */ #define R_390_GOTPC 14 /* 32 bit PC relative offset to GOT. */ #define R_390_GOT16 15 /* 16 bit GOT offset. */ #define R_390_PC16 16 /* PC relative 16 bit. */ #define R_390_PC16DBL 17 /* PC relative 16 bit shifted by 1. */ #define R_390_PLT16DBL 18 /* 16 bit PC rel. PLT shifted by 1. */ #define R_390_PC32DBL 19 /* PC relative 32 bit shifted by 1. */ #define R_390_PLT32DBL 20 /* 32 bit PC rel. PLT shifted by 1. */ #define R_390_GOTPCDBL 21 /* 32 bit PC rel. GOT shifted by 1. */ #define R_390_64 22 /* Direct 64 bit. */ #define R_390_PC64 23 /* PC relative 64 bit. */ #define R_390_GOT64 24 /* 64 bit GOT offset. */ #define R_390_PLT64 25 /* 64 bit PC relative PLT address. */ #define R_390_GOTENT 26 /* 32 bit PC rel. to GOT entry >> 1. */ #define R_390_GOTOFF16 27 /* 16 bit offset to GOT. */ #define R_390_GOTOFF64 28 /* 64 bit offset to GOT. */ #define R_390_GOTPLT12 29 /* 12 bit offset to jump slot. */ #define R_390_GOTPLT16 30 /* 16 bit offset to jump slot. */ #define R_390_GOTPLT32 31 /* 32 bit offset to jump slot. */ #define R_390_GOTPLT64 32 /* 64 bit offset to jump slot. */ #define R_390_GOTPLTENT 33 /* 32 bit rel. offset to jump slot. */ #define R_390_PLTOFF16 34 /* 16 bit offset from GOT to PLT. */ #define R_390_PLTOFF32 35 /* 32 bit offset from GOT to PLT. */ #define R_390_PLTOFF64 36 /* 16 bit offset from GOT to PLT. */ #define R_390_TLS_LOAD 37 /* Tag for load insn in TLS code. */ #define R_390_TLS_GDCALL 38 /* Tag for function call in general dynamic TLS code. */ #define R_390_TLS_LDCALL 39 /* Tag for function call in local dynamic TLS code. */ #define R_390_TLS_GD32 40 /* Direct 32 bit for general dynamic thread local data. */ #define R_390_TLS_GD64 41 /* Direct 64 bit for general dynamic thread local data. */ #define R_390_TLS_GOTIE12 42 /* 12 bit GOT offset for static TLS block offset. */ #define R_390_TLS_GOTIE32 43 /* 32 bit GOT offset for static TLS block offset. */ #define R_390_TLS_GOTIE64 44 /* 64 bit GOT offset for static TLS block offset. */ #define R_390_TLS_LDM32 45 /* Direct 32 bit for local dynamic thread local data in LE code. */ #define R_390_TLS_LDM64 46 /* Direct 64 bit for local dynamic thread local data in LE code. */ #define R_390_TLS_IE32 47 /* 32 bit address of GOT entry for negated static TLS block offset. */ #define R_390_TLS_IE64 48 /* 64 bit address of GOT entry for negated static TLS block offset. */ #define R_390_TLS_IEENT 49 /* 32 bit rel. offset to GOT entry for negated static TLS block offset. */ #define R_390_TLS_LE32 50 /* 32 bit negated offset relative to static TLS block. */ #define R_390_TLS_LE64 51 /* 64 bit negated offset relative to static TLS block. */ #define R_390_TLS_LDO32 52 /* 32 bit offset relative to TLS block. */ #define R_390_TLS_LDO64 53 /* 64 bit offset relative to TLS block. */ #define R_390_TLS_DTPMOD 54 /* ID of module containing symbol. */ #define R_390_TLS_DTPOFF 55 /* Offset in TLS block. */ #define R_390_TLS_TPOFF 56 /* Negated offset in static TLS block. */ /* Keep this the last entry. */ #define R_390_NUM 57 /* CRIS relocations. */ #define R_CRIS_NONE 0 #define R_CRIS_8 1 #define R_CRIS_16 2 #define R_CRIS_32 3 #define R_CRIS_8_PCREL 4 #define R_CRIS_16_PCREL 5 #define R_CRIS_32_PCREL 6 #define R_CRIS_GNU_VTINHERIT 7 #define R_CRIS_GNU_VTENTRY 8 #define R_CRIS_COPY 9 #define R_CRIS_GLOB_DAT 10 #define R_CRIS_JUMP_SLOT 11 #define R_CRIS_RELATIVE 12 #define R_CRIS_16_GOT 13 #define R_CRIS_32_GOT 14 #define R_CRIS_16_GOTPLT 15 #define R_CRIS_32_GOTPLT 16 #define R_CRIS_32_GOTREL 17 #define R_CRIS_32_PLT_GOTREL 18 #define R_CRIS_32_PLT_PCREL 19 #define R_CRIS_NUM 20 /* AMD x86-64 relocations. */ #define R_X86_64_NONE 0 /* No reloc */ #define R_X86_64_64 1 /* Direct 64 bit */ #define R_X86_64_PC32 2 /* PC relative 32 bit signed */ #define R_X86_64_GOT32 3 /* 32 bit GOT entry */ #define R_X86_64_PLT32 4 /* 32 bit PLT address */ #define R_X86_64_COPY 5 /* Copy symbol at runtime */ #define R_X86_64_GLOB_DAT 6 /* Create GOT entry */ #define R_X86_64_JUMP_SLOT 7 /* Create PLT entry */ #define R_X86_64_RELATIVE 8 /* Adjust by program base */ #define R_X86_64_GOTPCREL 9 /* 32 bit signed PC relative offset to GOT */ #define R_X86_64_32 10 /* Direct 32 bit zero extended */ #define R_X86_64_32S 11 /* Direct 32 bit sign extended */ #define R_X86_64_16 12 /* Direct 16 bit zero extended */ #define R_X86_64_PC16 13 /* 16 bit sign extended pc relative */ #define R_X86_64_8 14 /* Direct 8 bit sign extended */ #define R_X86_64_PC8 15 /* 8 bit sign extended pc relative */ #define R_X86_64_DTPMOD64 16 /* ID of module containing symbol */ #define R_X86_64_DTPOFF64 17 /* Offset in module's TLS block */ #define R_X86_64_TPOFF64 18 /* Offset in initial TLS block */ #define R_X86_64_TLSGD 19 /* 32 bit signed PC relative offset to two GOT entries for GD symbol */ #define R_X86_64_TLSLD 20 /* 32 bit signed PC relative offset to two GOT entries for LD symbol */ #define R_X86_64_DTPOFF32 21 /* Offset in TLS block */ #define R_X86_64_GOTTPOFF 22 /* 32 bit signed PC relative offset to GOT entry for IE symbol */ #define R_X86_64_TPOFF32 23 /* Offset in initial TLS block */ #define R_X86_64_NUM 24 #if defined(__alpha__) || defined(__s390__) typedef uint64_t Elf_Symndx; #else typedef uint32_t Elf_Symndx; #endif #define __ELF_NATIVE_CLASS __WORDSIZE __END_DECLS #endif /* elf.h */ dietlibc-0.33~cvs20120325/include/endian.h010064400000000000000000000026631173363226500147470ustar00#ifndef _ENDIAN_H #define _ENDIAN_H #define __LITTLE_ENDIAN 1234 #define __BIG_ENDIAN 4321 #ifdef __mips__ #if _MIPS_SIM == _MIPS_SIM_ABI64 #define __mips64__ #else #undef __mips64__ #endif #endif #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) || defined(__alpha__) #define __BYTE_ORDER __LITTLE_ENDIAN #define __FLOAT_WORD_ORDER __BYTE_ORDER #endif #if (defined(__mips__) && !defined(__MIPSEB)) || (defined(__arm__) && !defined(__ARMEB__)) || ((defined(__powerpc__) || defined(__sparc__)) && defined(__LITTLE_ENDIAN__)) #define __BYTE_ORDER __LITTLE_ENDIAN #define __FLOAT_WORD_ORDER __BYTE_ORDER #endif /* rest is big endian */ #ifndef __BYTE_ORDER #define __BYTE_ORDER __BIG_ENDIAN #define __FLOAT_WORD_ORDER __BYTE_ORDER #endif #define LITTLE_ENDIAN __LITTLE_ENDIAN #define BIG_ENDIAN __BIG_ENDIAN #define BYTE_ORDER __BYTE_ORDER #if __BYTE_ORDER == __LITTLE_ENDIAN # define __LONG_LONG_PAIR(HI, LO) LO, HI #elif __BYTE_ORDER == __BIG_ENDIAN # define __LONG_LONG_PAIR(HI, LO) HI, LO #endif #if defined(__alpha__) || defined(__mips64__) || defined(__sparc_v9__) || defined(__x86_64__) || defined(__ia64__) || defined(__powerpc64__) || defined(__s390x__) #define __WORDSIZE 64 #endif #if defined(__x86_64__) || defined(__powerpc64__) || defined(__sparc_v9__) #define __WORDSIZE_COMPAT32 1 #endif #if defined(__sparc__) && (__arch64__) #define __WORDSIZE 64 #endif #ifndef __WORDSIZE #define __WORDSIZE 32 #endif #endif dietlibc-0.33~cvs20120325/include/err.h010064400000000000000000000025601173363226500142750ustar00#ifndef _ERR_H #define _ERR_H #include #include __BEGIN_DECLS void err(int s, const char *f, ...) __attribute__((__deprecated__,__noreturn__,__format__(__printf__,2,3))); void errc(int s, int e, const char *f, ...) __attribute__((__deprecated__,__noreturn__,__format__(__printf__,3,4))); void errx(int s, const char *f, ...) __attribute__((__deprecated__,__noreturn__,__format__(__printf__,2,3))); void warn(const char *f, ...) __attribute__((__deprecated__,__format__(__printf__,1,2))); void warnc(int e, const char *f, ...) __attribute__((__deprecated__,__format__(__printf__,2,3))); void warnx(const char *f, ...) __attribute__((__deprecated__,__format__(__printf__,1,2))); void verr(int s, const char *f, va_list va) __attribute__((__deprecated__,__noreturn__,__format__(__printf__,2,0))); void verrc(int s, int e, const char *f, va_list va) __attribute__((__deprecated__,__noreturn__,__format__(__printf__,3,0))); void verrx(int s, const char *f, va_list va) __attribute__((__deprecated__,__noreturn__,__format__(__printf__,2,0))); void vwarn(const char *f, va_list va) __attribute__((__deprecated__,__format__(__printf__,1,0))); void vwarnc(int e, const char *f, va_list va) __attribute__((__deprecated__,__format__(__printf__,2,0))); void vwarnx(const char *f, va_list va) __attribute__((__deprecated__,__format__(__printf__,1,0))); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/errno.h010064400000000000000000001020751173363226500146340ustar00#ifndef _ERRNO_H #define _ERRNO_H #if defined(__alpha__) #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EDEADLK 11 /* Resource deadlock would occur */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define EAGAIN 35 /* Try again */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define EINPROGRESS 36 /* Operation now in progress */ #define EALREADY 37 /* Operation already in progress */ #define ENOTSOCK 38 /* Socket operation on non-socket */ #define EDESTADDRREQ 39 /* Destination address required */ #define EMSGSIZE 40 /* Message too long */ #define EPROTOTYPE 41 /* Protocol wrong type for socket */ #define ENOPROTOOPT 42 /* Protocol not available */ #define EPROTONOSUPPORT 43 /* Protocol not supported */ #define ESOCKTNOSUPPORT 44 /* Socket type not supported */ #define EOPNOTSUPP 45 /* Operation not supported on transport endpoint */ #define ENOTSUP EOPNOTSUPP/* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 46 /* Protocol family not supported */ #define EAFNOSUPPORT 47 /* Address family not supported by protocol */ #define EADDRINUSE 48 /* Address already in use */ #define EADDRNOTAVAIL 49 /* Cannot assign requested address */ #define ENETDOWN 50 /* Network is down */ #define ENETUNREACH 51 /* Network is unreachable */ #define ENETRESET 52 /* Network dropped connection because of reset */ #define ECONNABORTED 53 /* Software caused connection abort */ #define ECONNRESET 54 /* Connection reset by peer */ #define ENOBUFS 55 /* No buffer space available */ #define EISCONN 56 /* Transport endpoint is already connected */ #define ENOTCONN 57 /* Transport endpoint is not connected */ #define ESHUTDOWN 58 /* Cannot send after transport endpoint shutdown */ #define ETOOMANYREFS 59 /* Too many references: cannot splice */ #define ETIMEDOUT 60 /* Connection timed out */ #define ECONNREFUSED 61 /* Connection refused */ #define ELOOP 62 /* Too many symbolic links encountered */ #define ENAMETOOLONG 63 /* File name too long */ #define EHOSTDOWN 64 /* Host is down */ #define EHOSTUNREACH 65 /* No route to host */ #define ENOTEMPTY 66 /* Directory not empty */ #define EUSERS 68 /* Too many users */ #define EDQUOT 69 /* Quota exceeded */ #define ESTALE 70 /* Stale NFS file handle */ #define EREMOTE 71 /* Object is remote */ #define ENOLCK 77 /* No record locks available */ #define ENOSYS 78 /* Function not implemented */ #define ENOMSG 80 /* No message of desired type */ #define EIDRM 81 /* Identifier removed */ #define ENOSR 82 /* Out of streams resources */ #define ETIME 83 /* Timer expired */ #define EBADMSG 84 /* Not a data message */ #define EPROTO 85 /* Protocol error */ #define ENODATA 86 /* No data available */ #define ENOSTR 87 /* Device not a stream */ #define ENOPKG 92 /* Package not installed */ #define EILSEQ 116 /* Illegal byte sequence */ /* The following are just random noise.. */ #define ECHRNG 88 /* Channel number out of range */ #define EL2NSYNC 89 /* Level 2 not synchronized */ #define EL3HLT 90 /* Level 3 halted */ #define EL3RST 91 /* Level 3 reset */ #define ELNRNG 93 /* Link number out of range */ #define EUNATCH 94 /* Protocol driver not attached */ #define ENOCSI 95 /* No CSI structure available */ #define EL2HLT 96 /* Level 2 halted */ #define EBADE 97 /* Invalid exchange */ #define EBADR 98 /* Invalid request descriptor */ #define EXFULL 99 /* Exchange full */ #define ENOANO 100 /* No anode */ #define EBADRQC 101 /* Invalid request code */ #define EBADSLT 102 /* Invalid slot */ #define EDEADLOCK EDEADLK #define EBFONT 104 /* Bad font file format */ #define ENONET 105 /* Machine is not on the network */ #define ENOLINK 106 /* Link has been severed */ #define EADV 107 /* Advertise error */ #define ESRMNT 108 /* Srmount error */ #define ECOMM 109 /* Communication error on send */ #define EMULTIHOP 110 /* Multihop attempted */ #define EDOTDOT 111 /* RFS specific error */ #define EOVERFLOW 112 /* Value too large for defined data type */ #define ENOTUNIQ 113 /* Name not unique on network */ #define EBADFD 114 /* File descriptor in bad state */ #define EREMCHG 115 /* Remote address changed */ #define EUCLEAN 117 /* Structure needs cleaning */ #define ENOTNAM 118 /* Not a XENIX named type file */ #define ENAVAIL 119 /* No XENIX semaphores available */ #define EISNAM 120 /* Is a named type file */ #define EREMOTEIO 121 /* Remote I/O error */ #define ELIBACC 122 /* Can not access a needed shared library */ #define ELIBBAD 123 /* Accessing a corrupted shared library */ #define ELIBSCN 124 /* .lib section in a.out corrupted */ #define ELIBMAX 125 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 126 /* Cannot exec a shared library directly */ #define ERESTART 127 /* Interrupted system call should be restarted */ #define ESTRPIPE 128 /* Streams pipe error */ #define ENOMEDIUM 129 /* No medium found */ #define EMEDIUMTYPE 130 /* Wrong medium type */ #define ECANCELED 131 /* Operation Cancelled */ #define ENOKEY 132 /* Required key not available */ #define EKEYEXPIRED 133 /* Key has expired */ #define EKEYREVOKED 134 /* Key has been revoked */ #define EKEYREJECTED 135 /* Key was rejected by service */ #define __SYS_NERR ((EKEYREJECTED) + 1) #elif defined(__mips__) #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define ENOMSG 35 /* No message of desired type */ #define EIDRM 36 /* Identifier removed */ #define ECHRNG 37 /* Channel number out of range */ #define EL2NSYNC 38 /* Level 2 not synchronized */ #define EL3HLT 39 /* Level 3 halted */ #define EL3RST 40 /* Level 3 reset */ #define ELNRNG 41 /* Link number out of range */ #define EUNATCH 42 /* Protocol driver not attached */ #define ENOCSI 43 /* No CSI structure available */ #define EL2HLT 44 /* Level 2 halted */ #define EDEADLK 45 /* Resource deadlock would occur */ #define ENOLCK 46 /* No record locks available */ #define EBADE 50 /* Invalid exchange */ #define EBADR 51 /* Invalid request descriptor */ #define EXFULL 52 /* Exchange full */ #define ENOANO 53 /* No anode */ #define EBADRQC 54 /* Invalid request code */ #define EBADSLT 55 /* Invalid slot */ #define EDEADLOCK 56 /* File locking deadlock error */ #define EBFONT 59 /* Bad font file format */ #define ENOSTR 60 /* Device not a stream */ #define ENODATA 61 /* No data available */ #define ETIME 62 /* Timer expired */ #define ENOSR 63 /* Out of streams resources */ #define ENONET 64 /* Machine is not on the network */ #define ENOPKG 65 /* Package not installed */ #define EREMOTE 66 /* Object is remote */ #define ENOLINK 67 /* Link has been severed */ #define EADV 68 /* Advertise error */ #define ESRMNT 69 /* Srmount error */ #define ECOMM 70 /* Communication error on send */ #define EPROTO 71 /* Protocol error */ #define EDOTDOT 73 /* RFS specific error */ #define EMULTIHOP 74 /* Multihop attempted */ #define EBADMSG 77 /* Not a data message */ #define ENAMETOOLONG 78 /* File name too long */ #define EOVERFLOW 79 /* Value too large for defined data type */ #define ENOTUNIQ 80 /* Name not unique on network */ #define EBADFD 81 /* File descriptor in bad state */ #define EREMCHG 82 /* Remote address changed */ #define ELIBACC 83 /* Can not access a needed shared library */ #define ELIBBAD 84 /* Accessing a corrupted shared library */ #define ELIBSCN 85 /* .lib section in a.out corrupted */ #define ELIBMAX 86 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 87 /* Cannot exec a shared library directly */ #define EILSEQ 88 /* Illegal byte sequence */ #define ENOSYS 89 /* Function not implemented */ #define ELOOP 90 /* Too many symbolic links encountered */ #define ERESTART 91 /* Interrupted system call should be restarted */ #define ESTRPIPE 92 /* Streams pipe error */ #define ENOTEMPTY 93 /* Directory not empty */ #define EUSERS 94 /* Too many users */ #define ENOTSOCK 95 /* Socket operation on non-socket */ #define EDESTADDRREQ 96 /* Destination address required */ #define EMSGSIZE 97 /* Message too long */ #define EPROTOTYPE 98 /* Protocol wrong type for socket */ #define ENOPROTOOPT 99 /* Protocol not available */ #define EPROTONOSUPPORT 120 /* Protocol not supported */ #define ESOCKTNOSUPPORT 121 /* Socket type not supported */ #define EOPNOTSUPP 122 /* Operation not supported on transport endpoint */ #define ENOTSUP EOPNOTSUPP/* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 123 /* Protocol family not supported */ #define EAFNOSUPPORT 124 /* Address family not supported by protocol */ #define EADDRINUSE 125 /* Address already in use */ #define EADDRNOTAVAIL 126 /* Cannot assign requested address */ #define ENETDOWN 127 /* Network is down */ #define ENETUNREACH 128 /* Network is unreachable */ #define ENETRESET 129 /* Network dropped connection because of reset */ #define ECONNABORTED 130 /* Software caused connection abort */ #define ECONNRESET 131 /* Connection reset by peer */ #define ENOBUFS 132 /* No buffer space available */ #define EISCONN 133 /* Transport endpoint is already connected */ #define ENOTCONN 134 /* Transport endpoint is not connected */ #define EUCLEAN 135 /* Structure needs cleaning */ #define ENOTNAM 137 /* Not a XENIX named type file */ #define ENAVAIL 138 /* No XENIX semaphores available */ #define EISNAM 139 /* Is a named type file */ #define EREMOTEIO 140 /* Remote I/O error */ #define EINIT 141 /* Reserved */ #define EREMDEV 142 /* Error 142 */ #define ESHUTDOWN 143 /* Cannot send after transport endpoint shutdown */ #define ETOOMANYREFS 144 /* Too many references: cannot splice */ #define ETIMEDOUT 145 /* Connection timed out */ #define ECONNREFUSED 146 /* Connection refused */ #define EHOSTDOWN 147 /* Host is down */ #define EHOSTUNREACH 148 /* No route to host */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define EALREADY 149 /* Operation already in progress */ #define EINPROGRESS 150 /* Operation now in progress */ #define ESTALE 151 /* Stale NFS file handle */ #define ECANCELED 158 /* AIO operation canceled */ #define ENOMEDIUM 159 /* No medium found */ #define EMEDIUMTYPE 160 /* Wrong medium type */ #define ENOKEY 161 /* Required key not available */ #define EKEYEXPIRED 162 /* Key has expired */ #define EKEYREVOKED 163 /* Key has been revoked */ #define EKEYREJECTED 164 /* Key was rejected by service */ #define EDQUOT 1133 /* Quota exceeded */ #define __SYS_NERR ((EKEYREJECTED) + 1) #elif defined(__sparc__) #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define EINPROGRESS 36 /* Operation now in progress */ #define EALREADY 37 /* Operation already in progress */ #define ENOTSOCK 38 /* Socket operation on non-socket */ #define EDESTADDRREQ 39 /* Destination address required */ #define EMSGSIZE 40 /* Message too long */ #define EPROTOTYPE 41 /* Protocol wrong type for socket */ #define ENOPROTOOPT 42 /* Protocol not available */ #define EPROTONOSUPPORT 43 /* Protocol not supported */ #define ESOCKTNOSUPPORT 44 /* Socket type not supported */ #define EOPNOTSUPP 45 /* Op not supported on transport endpoint */ #define ENOTSUP EOPNOTSUPP/* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 46 /* Protocol family not supported */ #define EAFNOSUPPORT 47 /* Address family not supported by protocol */ #define EADDRINUSE 48 /* Address already in use */ #define EADDRNOTAVAIL 49 /* Cannot assign requested address */ #define ENETDOWN 50 /* Network is down */ #define ENETUNREACH 51 /* Network is unreachable */ #define ENETRESET 52 /* Net dropped connection because of reset */ #define ECONNABORTED 53 /* Software caused connection abort */ #define ECONNRESET 54 /* Connection reset by peer */ #define ENOBUFS 55 /* No buffer space available */ #define EISCONN 56 /* Transport endpoint is already connected */ #define ENOTCONN 57 /* Transport endpoint is not connected */ #define ESHUTDOWN 58 /* No send after transport endpoint shutdown */ #define ETOOMANYREFS 59 /* Too many references: cannot splice */ #define ETIMEDOUT 60 /* Connection timed out */ #define ECONNREFUSED 61 /* Connection refused */ #define ELOOP 62 /* Too many symbolic links encountered */ #define ENAMETOOLONG 63 /* File name too long */ #define EHOSTDOWN 64 /* Host is down */ #define EHOSTUNREACH 65 /* No route to host */ #define ENOTEMPTY 66 /* Directory not empty */ #define EPROCLIM 67 /* SUNOS: Too many processes */ #define EUSERS 68 /* Too many users */ #define EDQUOT 69 /* Quota exceeded */ #define ESTALE 70 /* Stale NFS file handle */ #define EREMOTE 71 /* Object is remote */ #define ENOSTR 72 /* Device not a stream */ #define ETIME 73 /* Timer expired */ #define ENOSR 74 /* Out of streams resources */ #define ENOMSG 75 /* No message of desired type */ #define EBADMSG 76 /* Not a data message */ #define EIDRM 77 /* Identifier removed */ #define EDEADLK 78 /* Resource deadlock would occur */ #define ENOLCK 79 /* No record locks available */ #define ENONET 80 /* Machine is not on the network */ #define ERREMOTE 81 /* SunOS: Too many lvls of remote in path */ #define ENOLINK 82 /* Link has been severed */ #define EADV 83 /* Advertise error */ #define ESRMNT 84 /* Srmount error */ #define ECOMM 85 /* Communication error on send */ #define EPROTO 86 /* Protocol error */ #define EMULTIHOP 87 /* Multihop attempted */ #define EDOTDOT 88 /* RFS specific error */ #define EREMCHG 89 /* Remote address changed */ #define ENOSYS 90 /* Function not implemented */ #define ESTRPIPE 91 /* Streams pipe error */ #define EOVERFLOW 92 /* Value too large for defined data type */ #define EBADFD 93 /* File descriptor in bad state */ #define ECHRNG 94 /* Channel number out of range */ #define EL2NSYNC 95 /* Level 2 not synchronized */ #define EL3HLT 96 /* Level 3 halted */ #define EL3RST 97 /* Level 3 reset */ #define ELNRNG 98 /* Link number out of range */ #define EUNATCH 99 /* Protocol driver not attached */ #define ENOCSI 100 /* No CSI structure available */ #define EL2HLT 101 /* Level 2 halted */ #define EBADE 102 /* Invalid exchange */ #define EBADR 103 /* Invalid request descriptor */ #define EXFULL 104 /* Exchange full */ #define ENOANO 105 /* No anode */ #define EBADRQC 106 /* Invalid request code */ #define EBADSLT 107 /* Invalid slot */ #define EDEADLOCK 108 /* File locking deadlock error */ #define EBFONT 109 /* Bad font file format */ #define ELIBEXEC 110 /* Cannot exec a shared library directly */ #define ENODATA 111 /* No data available */ #define ELIBBAD 112 /* Accessing a corrupted shared library */ #define ENOPKG 113 /* Package not installed */ #define ELIBACC 114 /* Can not access a needed shared library */ #define ENOTUNIQ 115 /* Name not unique on network */ #define ERESTART 116 /* Interrupted syscall should be restarted */ #define EUCLEAN 117 /* Structure needs cleaning */ #define ENOTNAM 118 /* Not a XENIX named type file */ #define ENAVAIL 119 /* No XENIX semaphores available */ #define EISNAM 120 /* Is a named type file */ #define EREMOTEIO 121 /* Remote I/O error */ #define EILSEQ 122 /* Illegal byte sequence */ #define ELIBMAX 123 /* Atmpt to link in too many shared libs */ #define ELIBSCN 124 /* .lib section in a.out corrupted */ #define ENOMEDIUM 125 /* No medium found */ #define EMEDIUMTYPE 126 /* Wrong medium type */ #define ECANCELED 127 /* Operation Cancelled */ #define ENOKEY 128 /* Required key not available */ #define EKEYEXPIRED 129 /* Key has expired */ #define EKEYREVOKED 130 /* Key has been revoked */ #define EKEYREJECTED 131 /* Key was rejected by service */ #define __SYS_NERR ((EKEYREJECTED) + 1) #elif defined(__hppa__) #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Argument list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define ENOMSG 35 /* No message of desired type */ #define EIDRM 36 /* Identifier removed */ #define ECHRNG 37 /* Channel number out of range */ #define EL2NSYNC 38 /* Level 2 not synchronized */ #define EL3HLT 39 /* Level 3 halted */ #define EL3RST 40 /* Level 3 reset */ #define ELNRNG 41 /* Link number out of range */ #define EUNATCH 42 /* Protocol driver not attached */ #define ENOCSI 43 /* No CSI structure available */ #define EL2HLT 44 /* Level 2 halted */ #define EDEADLK 45 /* Resource deadlock would occur */ #define EDEADLOCK EDEADLK #define ENOLCK 46 /* No record locks available */ #define EILSEQ 47 /* Illegal byte sequence */ #define ENONET 50 /* Machine is not on the network */ #define ENODATA 51 /* No data available */ #define ETIME 52 /* Timer expired */ #define ENOSR 53 /* Out of streams resources */ #define ENOSTR 54 /* Device not a stream */ #define ENOPKG 55 /* Package not installed */ #define ENOLINK 57 /* Link has been severed */ #define EADV 58 /* Advertise error */ #define ESRMNT 59 /* Srmount error */ #define ECOMM 60 /* Communication error on send */ #define EPROTO 61 /* Protocol error */ #define EMULTIHOP 64 /* Multihop attempted */ #define EDOTDOT 66 /* RFS specific error */ #define EBADMSG 67 /* Not a data message */ #define EUSERS 68 /* Too many users */ #define EDQUOT 69 /* Quota exceeded */ #define ESTALE 70 /* Stale NFS file handle */ #define EREMOTE 71 /* Object is remote */ #define EOVERFLOW 72 /* Value too large for defined data type */ /* these errnos are defined by Linux but not HPUX. */ #define EBADE 160 /* Invalid exchange */ #define EBADR 161 /* Invalid request descriptor */ #define EXFULL 162 /* Exchange full */ #define ENOANO 163 /* No anode */ #define EBADRQC 164 /* Invalid request code */ #define EBADSLT 165 /* Invalid slot */ #define EBFONT 166 /* Bad font file format */ #define ENOTUNIQ 167 /* Name not unique on network */ #define EBADFD 168 /* File descriptor in bad state */ #define EREMCHG 169 /* Remote address changed */ #define ELIBACC 170 /* Can not access a needed shared library */ #define ELIBBAD 171 /* Accessing a corrupted shared library */ #define ELIBSCN 172 /* .lib section in a.out corrupted */ #define ELIBMAX 173 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 174 /* Cannot exec a shared library directly */ #define ERESTART 175 /* Interrupted system call should be restarted */ #define ESTRPIPE 176 /* Streams pipe error */ #define EUCLEAN 177 /* Structure needs cleaning */ #define ENOTNAM 178 /* Not a XENIX named type file */ #define ENAVAIL 179 /* No XENIX semaphores available */ #define EISNAM 180 /* Is a named type file */ #define EREMOTEIO 181 /* Remote I/O error */ #define ENOMEDIUM 182 /* No medium found */ #define EMEDIUMTYPE 183 /* Wrong medium type */ #define ENOKEY 184 /* Required key not available */ #define EKEYEXPIRED 185 /* Key has expired */ #define EKEYREVOKED 186 /* Key has been revoked */ #define EKEYREJECTED 187 /* Key was rejected by service */ /* We now return you to your regularly scheduled HPUX. */ #define ENOSYM 215 /* symbol does not exist in executable */ #define ENOTSOCK 216 /* Socket operation on non-socket */ #define EDESTADDRREQ 217 /* Destination address required */ #define EMSGSIZE 218 /* Message too long */ #define EPROTOTYPE 219 /* Protocol wrong type for socket */ #define ENOPROTOOPT 220 /* Protocol not available */ #define EPROTONOSUPPORT 221 /* Protocol not supported */ #define ESOCKTNOSUPPORT 222 /* Socket type not supported */ #define EOPNOTSUPP 223 /* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 224 /* Protocol family not supported */ #define EAFNOSUPPORT 225 /* Address family not supported by protocol */ #define EADDRINUSE 226 /* Address already in use */ #define EADDRNOTAVAIL 227 /* Cannot assign requested address */ #define ENETDOWN 228 /* Network is down */ #define ENETUNREACH 229 /* Network is unreachable */ #define ENETRESET 230 /* Network dropped connection because of reset */ #define ECONNABORTED 231 /* Software caused connection abort */ #define ECONNRESET 232 /* Connection reset by peer */ #define ENOBUFS 233 /* No buffer space available */ #define EISCONN 234 /* Transport endpoint is already connected */ #define ENOTCONN 235 /* Transport endpoint is not connected */ #define ESHUTDOWN 236 /* Cannot send after transport endpoint shutdown */ #define ETOOMANYREFS 237 /* Too many references: cannot splice */ #define EREFUSED ECONNREFUSED /* for HP's NFS apparently */ #define ETIMEDOUT 238 /* Connection timed out */ #define ECONNREFUSED 239 /* Connection refused */ #define EREMOTERELEASE 240 /* Remote peer released connection */ #define EHOSTDOWN 241 /* Host is down */ #define EHOSTUNREACH 242 /* No route to host */ #define EALREADY 244 /* Operation already in progress */ #define EINPROGRESS 245 /* Operation now in progress */ #define EWOULDBLOCK 246 /* Operation would block (Linux returns EAGAIN) */ #define ENOTEMPTY 247 /* Directory not empty */ #define ENAMETOOLONG 248 /* File name too long */ #define ELOOP 249 /* Too many symbolic links encountered */ #define ENOSYS 251 /* Function not implemented */ #define ENOTSUP 252 /* Function not implemented (POSIX.4 / HPUX) */ #define ECANCELLED 253 /* aio request was canceled before complete (POSIX.4 / HPUX) */ #define __SYS_NERR ((ECANCELLED) + 1) #else /* i386, arm, ppc, x86_64, ia64 */ #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */ #define EIO 5 /* I/O error */ #define ENXIO 6 /* No such device or address */ #define E2BIG 7 /* Arg list too long */ #define ENOEXEC 8 /* Exec format error */ #define EBADF 9 /* Bad file number */ #define ECHILD 10 /* No child processes */ #define EAGAIN 11 /* Try again */ #define ENOMEM 12 /* Out of memory */ #define EACCES 13 /* Permission denied */ #define EFAULT 14 /* Bad address */ #define ENOTBLK 15 /* Block device required */ #define EBUSY 16 /* Device or resource busy */ #define EEXIST 17 /* File exists */ #define EXDEV 18 /* Cross-device link */ #define ENODEV 19 /* No such device */ #define ENOTDIR 20 /* Not a directory */ #define EISDIR 21 /* Is a directory */ #define EINVAL 22 /* Invalid argument */ #define ENFILE 23 /* File table overflow */ #define EMFILE 24 /* Too many open files */ #define ENOTTY 25 /* Not a typewriter */ #define ETXTBSY 26 /* Text file busy */ #define EFBIG 27 /* File too large */ #define ENOSPC 28 /* No space left on device */ #define ESPIPE 29 /* Illegal seek */ #define EROFS 30 /* Read-only file system */ #define EMLINK 31 /* Too many links */ #define EPIPE 32 /* Broken pipe */ #define EDOM 33 /* Math argument out of domain of func */ #define ERANGE 34 /* Math result not representable */ #define EDEADLK 35 /* Resource deadlock would occur */ #define ENAMETOOLONG 36 /* File name too long */ #define ENOLCK 37 /* No record locks available */ #define ENOSYS 38 /* Function not implemented */ #define ENOTEMPTY 39 /* Directory not empty */ #define ELOOP 40 /* Too many symbolic links encountered */ #define EWOULDBLOCK EAGAIN /* Operation would block */ #define ENOMSG 42 /* No message of desired type */ #define EIDRM 43 /* Identifier removed */ #define ECHRNG 44 /* Channel number out of range */ #define EL2NSYNC 45 /* Level 2 not synchronized */ #define EL3HLT 46 /* Level 3 halted */ #define EL3RST 47 /* Level 3 reset */ #define ELNRNG 48 /* Link number out of range */ #define EUNATCH 49 /* Protocol driver not attached */ #define ENOCSI 50 /* No CSI structure available */ #define EL2HLT 51 /* Level 2 halted */ #define EBADE 52 /* Invalid exchange */ #define EBADR 53 /* Invalid request descriptor */ #define EXFULL 54 /* Exchange full */ #define ENOANO 55 /* No anode */ #define EBADRQC 56 /* Invalid request code */ #define EBADSLT 57 /* Invalid slot */ #define EDEADLOCK EDEADLK #define EBFONT 59 /* Bad font file format */ #define ENOSTR 60 /* Device not a stream */ #define ENODATA 61 /* No data available */ #define ETIME 62 /* Timer expired */ #define ENOSR 63 /* Out of streams resources */ #define ENONET 64 /* Machine is not on the network */ #define ENOPKG 65 /* Package not installed */ #define EREMOTE 66 /* Object is remote */ #define ENOLINK 67 /* Link has been severed */ #define EADV 68 /* Advertise error */ #define ESRMNT 69 /* Srmount error */ #define ECOMM 70 /* Communication error on send */ #define EPROTO 71 /* Protocol error */ #define EMULTIHOP 72 /* Multihop attempted */ #define EDOTDOT 73 /* RFS specific error */ #define EBADMSG 74 /* Not a data message */ #define EOVERFLOW 75 /* Value too large for defined data type */ #define ENOTUNIQ 76 /* Name not unique on network */ #define EBADFD 77 /* File descriptor in bad state */ #define EREMCHG 78 /* Remote address changed */ #define ELIBACC 79 /* Can not access a needed shared library */ #define ELIBBAD 80 /* Accessing a corrupted shared library */ #define ELIBSCN 81 /* .lib section in a.out corrupted */ #define ELIBMAX 82 /* Attempting to link in too many shared libraries */ #define ELIBEXEC 83 /* Cannot exec a shared library directly */ #define EILSEQ 84 /* Illegal byte sequence */ #define ERESTART 85 /* Interrupted system call should be restarted */ #define ESTRPIPE 86 /* Streams pipe error */ #define EUSERS 87 /* Too many users */ #define ENOTSOCK 88 /* Socket operation on non-socket */ #define EDESTADDRREQ 89 /* Destination address required */ #define EMSGSIZE 90 /* Message too long */ #define EPROTOTYPE 91 /* Protocol wrong type for socket */ #define ENOPROTOOPT 92 /* Protocol not available */ #define EPROTONOSUPPORT 93 /* Protocol not supported */ #define ESOCKTNOSUPPORT 94 /* Socket type not supported */ #define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ #define ENOTSUP EOPNOTSUPP/* Operation not supported on transport endpoint */ #define EPFNOSUPPORT 96 /* Protocol family not supported */ #define EAFNOSUPPORT 97 /* Address family not supported by protocol */ #define EADDRINUSE 98 /* Address already in use */ #define EADDRNOTAVAIL 99 /* Cannot assign requested address */ #define ENETDOWN 100 /* Network is down */ #define ENETUNREACH 101 /* Network is unreachable */ #define ENETRESET 102 /* Network dropped connection because of reset */ #define ECONNABORTED 103 /* Software caused connection abort */ #define ECONNRESET 104 /* Connection reset by peer */ #define ENOBUFS 105 /* No buffer space available */ #define EISCONN 106 /* Transport endpoint is already connected */ #define ENOTCONN 107 /* Transport endpoint is not connected */ #define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ #define ETOOMANYREFS 109 /* Too many references: cannot splice */ #define ETIMEDOUT 110 /* Connection timed out */ #define ECONNREFUSED 111 /* Connection refused */ #define EHOSTDOWN 112 /* Host is down */ #define EHOSTUNREACH 113 /* No route to host */ #define EALREADY 114 /* Operation already in progress */ #define EINPROGRESS 115 /* Operation now in progress */ #define ESTALE 116 /* Stale NFS file handle */ #define EUCLEAN 117 /* Structure needs cleaning */ #define ENOTNAM 118 /* Not a XENIX named type file */ #define ENAVAIL 119 /* No XENIX semaphores available */ #define EISNAM 120 /* Is a named type file */ #define EREMOTEIO 121 /* Remote I/O error */ #define EDQUOT 122 /* Quota exceeded */ #define ENOMEDIUM 123 /* No medium found */ #define EMEDIUMTYPE 124 /* Wrong medium type */ #define ECANCELED 125 /* Operation Canceled */ #define ENOKEY 126 /* Required key not available */ #define EKEYEXPIRED 127 /* Key has expired */ #define EKEYREVOKED 128 /* Key has been revoked */ #define EKEYREJECTED 129 /* Key was rejected by service */ #define __SYS_NERR ((EKEYREJECTED) + 1) #endif #ifndef __ASSEMBLER__ #include __BEGIN_DECLS #ifndef _REENTRANT extern int errno; #else #define errno (*__errno_location()) #endif extern int *__errno_location(void); #define __set_errno(x) errno=(x) #ifdef _BSD_SOURCE /* don't use, use strerror() instead! */ extern const char *const sys_errlist[] __attribute_dontuse__; extern int sys_nerr __attribute_dontuse__; #endif #ifdef _GNU_SOURCE extern char* program_invocation_name __attribute_dontuse__; extern char* program_invocation_short_name __attribute_dontuse__; #endif __END_DECLS #endif #endif dietlibc-0.33~cvs20120325/include/fcntl.h010064400000000000000000000520261173363226500146150ustar00#ifndef _FCNTL_H #define _FCNTL_H #include #include #include #include #include __BEGIN_DECLS #define F_LINUX_SPECIFIC_BASE 1024 #if defined(__i386__) || defined(__s390__) || defined(__x86_64__) || defined(__ia64__) /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ #define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_CREAT 0100 /* not fcntl */ #define O_EXCL 0200 /* not fcntl */ #define O_NOCTTY 0400 /* not fcntl */ #define O_TRUNC 01000 /* not fcntl */ #define O_APPEND 02000 #define O_NONBLOCK 04000 #define O_NDELAY O_NONBLOCK #define O_SYNC 010000 #define FASYNC 020000 /* fcntl, for BSD compatibility */ #define O_DIRECT 040000 /* direct disk access hint - currently ignored */ #define O_LARGEFILE 0100000 #define O_DIRECTORY 0200000 /* must be a directory */ #define O_NOFOLLOW 0400000 /* don't follow links */ #define O_NOATIME 01000000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #define F_GETLK 5 #define F_SETLK 6 #define F_SETLKW 7 #define F_SETOWN 8 /* for sockets. */ #define F_GETOWN 9 /* for sockets. */ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ #define F_GETLK64 12 /* using 'struct flock64' */ #define F_SETLK64 13 #define F_SETLKW64 14 #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 0 #define F_WRLCK 1 #define F_UNLCK 2 /* for old implementation of bsd flock () */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* for leases */ #define F_INPROGRESS 16 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; pid_t l_pid; }; struct flock64 { int16_t l_type; int16_t l_whence; loff_t l_start; loff_t l_len; pid_t l_pid; }; #elif defined(__alpha__) /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ #define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_CREAT 01000 /* not fcntl */ #define O_TRUNC 02000 /* not fcntl */ #define O_EXCL 04000 /* not fcntl */ #define O_NOCTTY 010000 /* not fcntl */ #define O_NONBLOCK 00004 #define O_APPEND 00010 #define O_NDELAY O_NONBLOCK #define O_SYNC 040000 #define FASYNC 020000 /* fcntl, for BSD compatibility */ #define O_DIRECTORY 0100000 /* must be a directory */ #define O_NOFOLLOW 0200000 /* don't follow links */ #define O_LARGEFILE 0400000 /* will be set by the kernel on every open */ #define O_DIRECT 02000000 /* direct disk access - should check with OSF/1 */ #define O_NOATIME 04000000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #define F_GETLK 7 #define F_SETLK 8 #define F_SETLKW 9 #define F_SETOWN 5 /* for sockets. */ #define F_GETOWN 6 /* for sockets. */ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 1 #define F_WRLCK 2 #define F_UNLCK 8 /* for old implementation of bsd flock () */ #define F_EXLCK 16 /* or 3 */ #define F_SHLCK 32 /* or 4 */ #define F_INPROGRESS 64 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; pid_t l_pid; }; #elif defined(__mips__) /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ #define O_ACCMODE 0x0003 #define O_RDONLY 0x0000 #define O_WRONLY 0x0001 #define O_RDWR 0x0002 #define O_APPEND 0x0008 #define O_SYNC 0x0010 #define O_NONBLOCK 0x0080 #define O_CREAT 0x0100 /* not fcntl */ #define O_TRUNC 0x0200 /* not fcntl */ #define O_EXCL 0x0400 /* not fcntl */ #define O_NOCTTY 0x0800 /* not fcntl */ #define FASYNC 0x1000 /* fcntl, for BSD compatibility */ #define O_LARGEFILE 0x2000 /* allow large file opens - currently ignored */ #define O_DIRECT 0x8000 /* direct disk access hint - currently ignored */ #define O_DIRECTORY 0x10000 /* must be a directory */ #define O_NOFOLLOW 0x20000 /* don't follow links */ #define O_NOATIME 0x40000 #define O_NDELAY O_NONBLOCK #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #define F_GETLK 14 #define F_SETLK 6 #define F_SETLKW 7 #define F_SETOWN 24 /* for sockets. */ #define F_GETOWN 23 /* for sockets. */ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ #ifndef __mips64__ #define F_GETLK64 33 /* using 'struct flock64' */ #define F_SETLK64 34 #define F_SETLKW64 35 #endif /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 0 #define F_WRLCK 1 #define F_UNLCK 2 /* for old implementation of bsd flock () */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* for leases */ #define F_INPROGRESS 16 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent XXXXXXXXXXXXXXXXXX blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ #ifndef __mips64__ struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; long l_sysid; /* XXXXXXXXXXXXXXXXXXXXXXXXX */ pid_t l_pid; long pad[4]; /* ZZZZZZZZZZZZZZZZZZZZZZZZZZ */ }; struct flock64 { int16_t l_type; int16_t l_whence; loff_t l_start; loff_t l_len; pid_t l_pid; }; #else struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; pid_t l_pid; }; #define flock64 flock #endif #elif defined(__sparc__) /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ #define O_RDONLY 0x0000 #define O_WRONLY 0x0001 #define O_RDWR 0x0002 #define O_ACCMODE 0x0003 #define O_APPEND 0x0008 #define FASYNC 0x0040 /* fcntl, for BSD compatibility */ #define O_CREAT 0x0200 /* not fcntl */ #define O_TRUNC 0x0400 /* not fcntl */ #define O_EXCL 0x0800 /* not fcntl */ #define O_SYNC 0x2000 #define O_NONBLOCK 0x4000 #define O_NDELAY (0x0004 | O_NONBLOCK) #define O_NOCTTY 0x8000 /* not fcntl */ #define O_DIRECTORY 0x10000 /* must be a directory */ #define O_NOFOLLOW 0x20000 /* don't follow links */ #define O_LARGEFILE 0x40000 #define O_DIRECT 0x100000 /* direct disk access hint */ #define O_NOATIME 0x200000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #define F_GETOWN 5 /* for sockets. */ #define F_SETOWN 6 /* for sockets. */ #define F_GETLK 7 #define F_SETLK 8 #define F_SETLKW 9 #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ #define F_GETLK64 12 /* using 'struct flock64' */ #define F_SETLK64 13 #define F_SETLKW64 14 /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 1 #define F_WRLCK 2 #define F_UNLCK 3 /* for old implementation of bsd flock () */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* for leases */ #define F_INPROGRESS 16 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; pid_t l_pid; int16_t __unused; }; #ifdef __arch64__ #define flock64 flock #else struct flock64 { int16_t l_type; int16_t l_whence; loff_t l_start; loff_t l_len; pid_t l_pid; int16_t __unused; }; #endif #elif defined(__powerpc__) || defined(__powerpc64__) /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ #define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_CREAT 0100 /* not fcntl */ #define O_EXCL 0200 /* not fcntl */ #define O_NOCTTY 0400 /* not fcntl */ #define O_TRUNC 01000 /* not fcntl */ #define O_APPEND 02000 #define O_NONBLOCK 04000 #define O_NDELAY O_NONBLOCK #define O_SYNC 010000 #define FASYNC 020000 /* fcntl, for BSD compatibility */ #define O_DIRECTORY 040000 /* must be a directory */ #define O_NOFOLLOW 0100000 /* don't follow links */ #define O_LARGEFILE 0200000 #define O_DIRECT 0400000 /* direct disk access hint - currently ignored */ #define O_NOATIME 01000000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #define F_GETLK 5 #define F_SETLK 6 #define F_SETLKW 7 #define F_SETOWN 8 /* for sockets. */ #define F_GETOWN 9 /* for sockets. */ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ #define F_GETLK64 12 /* using 'struct flock64' */ #define F_SETLK64 13 #define F_SETLKW64 14 /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 0 #define F_WRLCK 1 #define F_UNLCK 2 /* for old implementation of bsd flock () */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* for leases */ #define F_INPROGRESS 16 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; pid_t l_pid; }; struct flock64 { int16_t l_type; int16_t l_whence; loff_t l_start; loff_t l_len; pid_t l_pid; }; #elif defined (__arm__) /* open/fcntl - O_SYNC is only implemented on blocks devices and on files located on an ext2 file system */ #define O_ACCMODE 0003 #define O_RDONLY 00 #define O_WRONLY 01 #define O_RDWR 02 #define O_CREAT 0100 /* not fcntl */ #define O_EXCL 0200 /* not fcntl */ #define O_NOCTTY 0400 /* not fcntl */ #define O_TRUNC 01000 /* not fcntl */ #define O_APPEND 02000 #define O_NONBLOCK 04000 #define O_NDELAY O_NONBLOCK #define O_SYNC 010000 #define FASYNC 020000 /* fcntl, for BSD compatibility */ #define O_DIRECTORY 040000 /* must be a directory */ #define O_NOFOLLOW 0100000 /* don't follow links */ #define O_DIRECT 0200000 /* direct disk access hint - currently ignored */ #define O_LARGEFILE 0400000 #define O_NOATIME 01000000 #define F_DUPFD 0 /* dup */ #define F_GETFD 1 /* get close_on_exec */ #define F_SETFD 2 /* set/clear close_on_exec */ #define F_GETFL 3 /* get file->f_flags */ #define F_SETFL 4 /* set file->f_flags */ #define F_GETLK 5 #define F_SETLK 6 #define F_SETLKW 7 #define F_SETOWN 8 /* for sockets. */ #define F_GETOWN 9 /* for sockets. */ #define F_SETSIG 10 /* for sockets. */ #define F_GETSIG 11 /* for sockets. */ #define F_GETLK64 12 /* using 'struct flock64' */ #define F_SETLK64 13 #define F_SETLKW64 14 /* for F_[GET|SET]FL */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ /* for posix fcntl() and lockf() */ #define F_RDLCK 0 #define F_WRLCK 1 #define F_UNLCK 2 /* for old implementation of bsd flock () */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* for leases */ #define F_INPROGRESS 16 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ struct flock { int16_t l_type; int16_t l_whence; off_t l_start; off_t l_len; pid_t l_pid; }; struct flock64 { int16_t l_type; int16_t l_whence; loff_t l_start; loff_t l_len; pid_t l_pid; }; #elif defined(__hppa__) /* Copied from bits/fcntl.h */ #define O_RDONLY 00000000 #define O_WRONLY 00000001 #define O_RDWR 00000002 #define O_ACCMODE 00000003 #define O_APPEND 00000010 #define O_BLKSEEK 00000100 /* HPUX only */ #define O_CREAT 00000400 /* not fcntl */ #define O_TRUNC 00001000 /* not fcntl */ #define O_EXCL 00002000 /* not fcntl */ #define O_LARGEFILE 00004000 #define O_ASYNC 00020000 #define O_SYNC 00100000 #define O_NONBLOCK 00200004 /* HPUX has separate NDELAY & NONBLOCK */ #define O_NDELAY O_NONBLOCK #define O_NOCTTY 00400000 /* not fcntl */ #define O_DSYNC 01000000 /* HPUX only */ #define O_RSYNC 02000000 /* HPUX only */ #define O_NOATIME 04000000 #define O_DIRECTORY 00010000 #define O_DIRECT 00040000 /* direct disk access hint - currently ignored */ #define O_NOFOLLOW 00000200 /* don't follow links */ #define O_INVISIBLE 04000000 /* invisible I/O, for DMAPI/XDSM */ #define F_DUPFD 0 /* Duplicate file descriptor. */ #define F_GETFD 1 /* Get file descriptor flags. */ #define F_SETFD 2 /* Set file descriptor flags. */ #define F_GETFL 3 /* Get file status flags. */ #define F_SETFL 4 /* Set file status flags. */ #define F_GETLK 5 /* Get record locking info. */ #define F_SETLK 6 /* Set record locking info (non-blocking). */ #define F_SETLKW 7 /* Set record locking info (blocking). */ #define F_GETLK64 8 /* Get record locking info. */ #define F_SETLK64 9 /* Set record locking info (non-blocking). */ #define F_SETLKW64 10 /* Set record locking info (blocking). */ #define F_GETOWN 11 /* for sockets. */ #define F_SETOWN 12 /* for sockets. */ #define F_SETSIG 13 /* for sockets. */ #define F_GETSIG 14 /* for sockets. */ #define FD_CLOEXEC 1 /* actually anything with low bit set goes */ #define F_RDLCK 1 /* Read lock. */ #define F_WRLCK 2 /* Write lock. */ #define F_UNLCK 3 /* Remove lock. */ #define F_EXLCK 4 /* or 3 */ #define F_SHLCK 8 /* or 4 */ /* for leases */ #define F_INPROGRESS 16 /* operations for bsd flock(), also used by the kernel implementation */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* or'd with one of the above to prevent blocking */ #define LOCK_UN 8 /* remove lock */ #define LOCK_MAND 32 /* This is a mandatory flock */ #define LOCK_READ 64 /* ... Which allows concurrent read operations */ #define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ #define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ struct flock { int16_t l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ int16_t l_whence; /* Where `l_start' is relative to (like `lseek'). */ off_t l_start; /* Offset where the lock begins. */ off_t l_len; /* Size of the locked area; zero means until EOF. */ pid_t l_pid; /* Process holding the lock. */ }; struct flock64 { int16_t l_type; /* Type of lock: F_RDLCK, F_WRLCK, or F_UNLCK. */ int16_t l_whence; /* Where `l_start' is relative to (like `lseek'). */ off64_t l_start; /* Offset where the lock begins. */ off64_t l_len; /* Size of the locked area; zero means until EOF. */ pid_t l_pid; /* Process holding the lock. */ }; #endif extern int fcntl (int __fd, int __cmd, ...) __THROW; #ifndef __NO_STAT64 extern int fcntl64 (int __fd, int __cmd, ...) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define fcntl fcntl64 #endif #endif #if !defined(O_ASYNC) && defined(FASYNC) #define O_ASYNC FASYNC #endif #if defined(_LINUX_SOURCE) || defined(_GNU_SOURCE) ssize_t readahead(int fd, off64_t *offset, size_t count) __THROW; #endif #ifdef _GNU_SOURCE #define SPLICE_F_MOVE (0x01) /* move pages instead of copying */ #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */ /* we may still block on the fd we splice */ /* from/to, of course */ #define SPLICE_F_MORE (0x04) /* expect more data */ #define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */ long tee(int fd_in, int fd_out, size_t len, unsigned int flags) __THROW; #include long vmsplice(int fd, const struct iovec *iov, unsigned long nr_segs, unsigned int flags) __THROW; long splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) __THROW; int sync_file_range(int fd, off64_t offset, off64_t nbytes, unsigned int flags) __THROW; #define FALLOC_FL_KEEP_SIZE 1 int fallocate(int fd, int mode, loff_t offset, loff_t len) __THROW; #endif #if defined(_ATFILE_SOURCE) || ((_XOPEN_SOURCE + 0) >= 700) || ((_POSIX_C_SOURCE + 0) >= 200809L) #define AT_FDCWD -100 /* Special value used to indicate openat should use the current working directory. */ #define AT_SYMLINK_NOFOLLOW 0x100 /* Do not follow symbolic links. */ #define AT_REMOVEDIR 0x200 /* Remove directory instead of unlinking file. */ #define AT_SYMLINK_FOLLOW 0x400 /* Follow symbolic links. */ int openat(int dirfd, const char *pathname, int flags, ...); int faccessat(int dirfd, const char *pathname, int mode, int flags); int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags); int fchownat(int dirfd, const char *pathname, uid_t owner, gid_t group, int flags); int fstatat(int dirfd, const char *pathname, struct stat *buf, int flags); int futimesat(int dirfd, const char *pathname, const struct timeval times[2]); int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags); int mkdirat(int dirfd, const char *pathname, mode_t mode); int mknodat(int dirfd, const char *pathname, mode_t mode, dev_t dev); int readlinkat(int dirfd, const char *pathname, char *buf, size_t bufsiz); int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath); int symlinkat(const char *oldpath, int newdirfd, const char *newpath); int unlinkat(int dirfd, const char *pathname, int flags); int mkfifoat(int dirfd, const char *pathname, mode_t mode); int utimensat(int dirfd, const char *pathname, struct timespec* t); #endif #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0) >= 600 #include "linux/fadvise.h" int posix_fallocate(int fd, off64_t offset, off64_t len) __THROW; int posix_fadvise(int fd, off64_t offset, off64_t len, int advice) __THROW; #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/features.h010064400000000000000000000001631173363226500153200ustar00#ifndef _FEATURES_H #define _FEATURES_H #ifndef __dietlibc__ #error "not using the diet wrapper?!" #endif #endif dietlibc-0.33~cvs20120325/include/fenv.h010064400000000000000000000162501173363226500144440ustar00#ifndef _FENV_H #define _FENV_H #include __BEGIN_DECLS #if defined(__i386__) enum { FE_INVALID = 0x01, #define FE_INVALID FE_INVALID __FE_DENORM = 0x02, FE_DIVBYZERO = 0x04, #define FE_DIVBYZERO FE_DIVBYZERO FE_OVERFLOW = 0x08, #define FE_OVERFLOW FE_OVERFLOW FE_UNDERFLOW = 0x10, #define FE_UNDERFLOW FE_UNDERFLOW FE_INEXACT = 0x20 #define FE_INEXACT FE_INEXACT }; #define FE_ALL_EXCEPT \ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID) enum { FE_TONEAREST = 0, #define FE_TONEAREST FE_TONEAREST FE_DOWNWARD = 0x400, #define FE_DOWNWARD FE_DOWNWARD FE_UPWARD = 0x800, #define FE_UPWARD FE_UPWARD FE_TOWARDZERO = 0xc00 #define FE_TOWARDZERO FE_TOWARDZERO }; #define FE_DFL_ENV ((__const fenv_t *) -1) /* Type representing exception flags. */ typedef unsigned short int fexcept_t; /* Type representing floating-point environment. This function corresponds to the layout of the block written by the `fstenv'. */ typedef struct { unsigned short int __control_word; unsigned short int __unused1; unsigned short int __status_word; unsigned short int __unused2; unsigned short int __tags; unsigned short int __unused3; unsigned int __eip; unsigned short int __cs_selector; unsigned int __opcode:11; unsigned int __unused4:5; unsigned int __data_offset; unsigned short int __data_selector; unsigned short int __unused5; } fenv_t; #elif defined(__ia64__) enum { FE_INEXACT = 1UL << 5, #define FE_INEXACT FE_INEXACT FE_UNDERFLOW = 1UL << 4, #define FE_UNDERFLOW FE_UNDERFLOW FE_OVERFLOW = 1UL << 3, #define FE_OVERFLOW FE_OVERFLOW FE_DIVBYZERO = 1UL << 2, #define FE_DIVBYZERO FE_DIVBYZERO FE_UNNORMAL = 1UL << 1, #define FE_UNNORMAL FE_UNNORMAL FE_INVALID = 1UL << 0, #define FE_INVALID FE_INVALID FE_ALL_EXCEPT = (FE_INEXACT | FE_UNDERFLOW | FE_OVERFLOW | FE_DIVBYZERO | FE_UNNORMAL | FE_INVALID) #define FE_ALL_EXCEPT FE_ALL_EXCEPT }; enum { FE_TOWARDZERO = 3, #define FE_TOWARDZERO FE_TOWARDZERO FE_UPWARD = 2, #define FE_UPWARD FE_UPWARD FE_DOWNWARD = 1, #define FE_DOWNWARD FE_DOWNWARD FE_TONEAREST = 0, #define FE_TONEAREST FE_TONEAREST }; #define FE_DFL_ENV ((__const fenv_t *) 0xc009804c0270033fUL) typedef unsigned long int fexcept_t; typedef unsigned long int fenv_t; #elif defined(__powerpc__) enum { FE_INEXACT = 1 << (31 - 6), #define FE_INEXACT FE_INEXACT FE_DIVBYZERO = 1 << (31 - 5), #define FE_DIVBYZERO FE_DIVBYZERO FE_UNDERFLOW = 1 << (31 - 4), #define FE_UNDERFLOW FE_UNDERFLOW FE_OVERFLOW = 1 << (31 - 3), #define FE_OVERFLOW FE_OVERFLOW /* ... except for FE_INVALID, for which we use bit 31. FE_INVALID actually corresponds to bits 7 through 12 and 21 through 23 in the FPSCR, but we can't use that because the current draft says that it must be a power of 2. Instead we use bit 2 which is the summary bit for all the FE_INVALID exceptions, which kind of makes sense. */ FE_INVALID = 1 << (31 - 2), #define FE_INVALID FE_INVALID }; #define FE_ALL_EXCEPT \ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID) enum { FE_TONEAREST = 0, #define FE_TONEAREST FE_TONEAREST FE_TOWARDZERO = 1, #define FE_TOWARDZERO FE_TOWARDZERO FE_UPWARD = 2, #define FE_UPWARD FE_UPWARD FE_DOWNWARD = 3 #define FE_DOWNWARD FE_DOWNWARD }; typedef unsigned int fexcept_t; typedef double fenv_t; extern const fenv_t __fe_dfl_env; #define FE_DFL_ENV (&__fe_dfl_env) #elif defined(__s390__) enum { FE_INVALID = 0x80, #define FE_INVALID FE_INVALID FE_DIVBYZERO = 0x40, #define FE_DIVBYZERO FE_DIVBYZERO FE_OVERFLOW = 0x20, #define FE_OVERFLOW FE_OVERFLOW FE_UNDERFLOW = 0x10, #define FE_UNDERFLOW FE_UNDERFLOW FE_INEXACT = 0x08 #define FE_INEXACT FE_INEXACT }; #define FE_ALL_EXCEPT \ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID) enum { FE_TONEAREST = 0, #define FE_TONEAREST FE_TONEAREST FE_DOWNWARD = 0x3, #define FE_DOWNWARD FE_DOWNWARD FE_UPWARD = 0x2, #define FE_UPWARD FE_UPWARD FE_TOWARDZERO = 0x1 #define FE_TOWARDZERO FE_TOWARDZERO }; #define FE_DFL_ENV ((__const fenv_t *) -1) typedef unsigned int fexcept_t; /* size of fpc */ typedef struct { fexcept_t fpc; void *ieee_instruction_pointer; /* failing instruction for ieee exceptions */ } fenv_t; #elif defined(__sparc__) enum { FE_INVALID = (1 << 9), #define FE_INVALID FE_INVALID FE_OVERFLOW = (1 << 8), #define FE_OVERFLOW FE_OVERFLOW FE_UNDERFLOW = (1 << 7), #define FE_UNDERFLOW FE_UNDERFLOW FE_DIVBYZERO = (1 << 6), #define FE_DIVBYZERO FE_DIVBYZERO FE_INEXACT = (1 << 5) #define FE_INEXACT FE_INEXACT }; #define FE_ALL_EXCEPT \ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID) enum { FE_TONEAREST = (0U << 30), #define FE_TONEAREST FE_TONEAREST FE_TOWARDZERO = (1U << 30), #define FE_TOWARDZERO FE_TOWARDZERO FE_UPWARD = (2U << 30), #define FE_UPWARD FE_UPWARD FE_DOWNWARD = (3U << 30) #define FE_DOWNWARD FE_DOWNWARD }; #define __FE_ROUND_MASK (3U << 30) #define FE_DFL_ENV ((__const fenv_t *) -1) typedef unsigned long int fexcept_t; typedef unsigned long int fenv_t; #elif defined(__x86_64__) enum { FE_INVALID = 0x01, #define FE_INVALID FE_INVALID __FE_DENORM = 0x02, FE_DIVBYZERO = 0x04, #define FE_DIVBYZERO FE_DIVBYZERO FE_OVERFLOW = 0x08, #define FE_OVERFLOW FE_OVERFLOW FE_UNDERFLOW = 0x10, #define FE_UNDERFLOW FE_UNDERFLOW FE_INEXACT = 0x20 #define FE_INEXACT FE_INEXACT }; #define FE_ALL_EXCEPT \ (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID) enum { FE_TONEAREST = 0, #define FE_TONEAREST FE_TONEAREST FE_DOWNWARD = 0x400, #define FE_DOWNWARD FE_DOWNWARD FE_UPWARD = 0x800, #define FE_UPWARD FE_UPWARD FE_TOWARDZERO = 0xc00 #define FE_TOWARDZERO FE_TOWARDZERO }; #define FE_DFL_ENV ((__const fenv_t *) -1) typedef unsigned short int fexcept_t; typedef struct { unsigned short int __control_word; unsigned short int __unused1; unsigned short int __status_word; unsigned short int __unused2; unsigned short int __tags; unsigned short int __unused3; unsigned int __eip; unsigned short int __cs_selector; unsigned int __opcode:11; unsigned int __unused4:5; unsigned int __data_offset; unsigned short int __data_selector; unsigned short int __unused5; unsigned int __mxcsr; } fenv_t; #else #error unsupported platform, edit include/fenv.h #endif int feclearexcept(int); int fegetexceptflag(fexcept_t *, int); int feraiseexcept(int); int fesetexceptflag(const fexcept_t *, int); int fetestexcept(int); int fegetround(void); int fesetround(int); int fegetenv(fenv_t *); int feholdexcept(fenv_t *); int fesetenv(const fenv_t *); int feupdateenv(const fenv_t *); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/float.h010064400000000000000000000062761173363226500146220ustar00#ifndef _FLOAT_H #define _FLOAT_H /* blatantly copied from gcc headers for sparc */ /* Radix of exponent representation */ #undef FLT_RADIX #define FLT_RADIX 2 /* Number of base-FLT_RADIX digits in the significand of a float */ #undef FLT_MANT_DIG #define FLT_MANT_DIG 24 /* Number of decimal digits of precision in a float */ #undef FLT_DIG #define FLT_DIG 6 /* Addition rounds to 0: zero, 1: nearest, 2: +inf, 3: -inf, -1: unknown */ #undef FLT_ROUNDS #define FLT_ROUNDS 1 /* Difference between 1.0 and the minimum float greater than 1.0 */ #undef FLT_EPSILON #define FLT_EPSILON 1.19209290e-07F /* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ #undef FLT_MIN_EXP #define FLT_MIN_EXP (-125) /* Minimum normalised float */ #undef FLT_MIN #define FLT_MIN 1.17549435e-38F /* Minimum int x such that 10**x is a normalised float */ #undef FLT_MIN_10_EXP #define FLT_MIN_10_EXP (-37) /* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ #undef FLT_MAX_EXP #define FLT_MAX_EXP 128 /* Maximum float */ #undef FLT_MAX #define FLT_MAX 3.40282347e+38F /* Maximum int x such that 10**x is a representable float */ #undef FLT_MAX_10_EXP #define FLT_MAX_10_EXP 38 /* Number of base-FLT_RADIX digits in the significand of a double */ #undef DBL_MANT_DIG #define DBL_MANT_DIG 53 /* Number of decimal digits of precision in a double */ #undef DBL_DIG #define DBL_DIG 15 /* Difference between 1.0 and the minimum double greater than 1.0 */ #undef DBL_EPSILON #define DBL_EPSILON 2.2204460492503131e-16 /* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ #undef DBL_MIN_EXP #define DBL_MIN_EXP (-1021) /* Minimum normalised double */ #undef DBL_MIN #define DBL_MIN 2.2250738585072014e-308 /* Minimum int x such that 10**x is a normalised double */ #undef DBL_MIN_10_EXP #define DBL_MIN_10_EXP (-307) /* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ #undef DBL_MAX_EXP #define DBL_MAX_EXP 1024 /* Maximum double */ #undef DBL_MAX #define DBL_MAX 1.7976931348623157e+308 /* Maximum int x such that 10**x is a representable double */ #undef DBL_MAX_10_EXP #define DBL_MAX_10_EXP 308 /* Number of base-FLT_RADIX digits in the significand of a long double */ #undef LDBL_MANT_DIG #define LDBL_MANT_DIG 53 /* Number of decimal digits of precision in a long double */ #undef LDBL_DIG #define LDBL_DIG 15 /* Difference between 1.0 and the minimum long double greater than 1.0 */ #undef LDBL_EPSILON #define LDBL_EPSILON 2.2204460492503131e-16L /* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ #undef LDBL_MIN_EXP #define LDBL_MIN_EXP (-1021) /* Minimum normalised long double */ #undef LDBL_MIN #define LDBL_MIN 2.2250738585072014e-308L /* Minimum int x such that 10**x is a normalised long double */ #undef LDBL_MIN_10_EXP #define LDBL_MIN_10_EXP (-307) /* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ #undef LDBL_MAX_EXP #define LDBL_MAX_EXP 1024 /* Maximum long double */ #undef LDBL_MAX #define LDBL_MAX 1.7976931348623157e+308L /* Maximum int x such that 10**x is a representable long double */ #undef LDBL_MAX_10_EXP #define LDBL_MAX_10_EXP 308 #endif dietlibc-0.33~cvs20120325/include/fnmatch.h010064400000000000000000000005211173363226500151200ustar00#ifndef _FNMATCH_H #define _FNMATCH_H #include __BEGIN_DECLS int fnmatch(const char *pattern, const char *string, int flags) __THROW; #define FNM_NOESCAPE 1 #define FNM_PATHNAME 2 #define FNM_FILE_NAME 2 #define FNM_PERIOD 4 #define FNM_LEADING_DIR 8 #define FNM_CASEFOLD 16 #define FNM_NOMATCH 1 __END_DECLS #endif dietlibc-0.33~cvs20120325/include/ftw.h010064400000000000000000000031571173363226500143100ustar00#ifndef _FTW_H #define _FTW_H #include #include __BEGIN_DECLS struct FTW { int base; int level; }; int ftw(const char *dir, int (*fn)(const char *file, const struct stat *sb, int flag), int depth); int nftw(const char *dir, int (*fn)(const char *file, const struct stat *sb, int flag, struct FTW *s), int depth, int flags); #ifndef __NO_STAT64 int ftw64(const char *dir, int (*fn)(const char *file, const struct stat64 *sb, int flag), int depth); #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define ftw(dir,fn,depth) ftw64(dir,fn,depth) #endif #endif enum { FTW_F, /* Regular file. */ #define FTW_F FTW_F FTW_D, /* Directory. */ #define FTW_D FTW_D FTW_DNR, /* Unreadable directory. */ #define FTW_DNR FTW_DNR FTW_NS, /* Unstatable file. */ #define FTW_NS FTW_NS FTW_SL, /* Symbolic link. */ # define FTW_SL FTW_SL /* These flags are only passed from the `nftw' function. */ FTW_DP, /* Directory, all subdirs have been visited. */ # define FTW_DP FTW_DP FTW_SLN /* Symbolic link naming non-existing file. */ # define FTW_SLN FTW_SLN }; typedef int (*__ftw_func_t) (const char *__filename, const struct stat *__status, int __flag); typedef int (*__nftw_func_t) (const char *__filename, const struct stat *__status, int __flag, struct FTW *__info); #ifndef __NO_STAT64 typedef int (*__ftw64_func_t) (const char *__filename, const struct stat64 *__status, int __flag); typedef int (*__nftw64_func_t) (const char *__filename, const struct stat64 *__status, int __flag, struct FTW *__info); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/getopt.h010064400000000000000000000010621173363226500150030ustar00#ifndef __GETOPT_H__ #define __GETOPT_H__ #include __BEGIN_DECLS struct option { const char* name; int has_arg; int* flag; int val; }; #define no_argument 0 #define required_argument 1 #define optional_argument 2 extern int getopt_long(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); extern int getopt_long_only(int argc, char *const *argv, const char *shortopts, const struct option *longopts, int *longind); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/glob.h010064400000000000000000000043441173363226500144320ustar00#ifndef _GLOB_H #define _GLOB_H #include #include __BEGIN_DECLS typedef struct { size_t gl_pathc; /* Count of paths matched so far */ char **gl_pathv; /* List of matched pathnames. */ size_t gl_offs; /* Slots to reserve in `gl_pathv'. */ int gl_flags; /* Set to FLAGS, maybe | GLOB_MAGCHAR. */ } glob_t; int glob(const char *pattern, int flags, int errfunc(const char * epath, int eerrno), glob_t *pglob) __THROW; void globfree(glob_t *pglob) __THROW; /* Bits set in the FLAGS argument to `glob'. */ #define GLOB_ERR (1 << 0)/* Return on read errors. */ #define GLOB_MARK (1 << 1)/* Append a slash to each name. */ #define GLOB_NOSORT (1 << 2)/* Don't sort the names. */ #define GLOB_DOOFFS (1 << 3)/* Insert PGLOB->gl_offs NULLs. */ #define GLOB_NOCHECK (1 << 4)/* If nothing matches, return the pattern. */ #define GLOB_APPEND (1 << 5)/* Append to results of a previous call. */ #define GLOB_NOESCAPE (1 << 6)/* Backslashes don't quote metacharacters. */ #define GLOB_PERIOD (1 << 7)/* Leading `.' can be matched by metachars. */ #define GLOB_MAGCHAR (1 << 8)/* Set in gl_flags if any metachars seen. */ #define GLOB_ALTDIRFUNC (1 << 9)/* Use gl_opendir et al functions. */ #define GLOB_BRACE (1 << 10)/* Expand "{a,b}" to "a" "b". */ #define GLOB_NOMAGIC (1 << 11)/* If no magic chars, return the pattern. */ #define GLOB_TILDE (1 << 12)/* Expand ~user and ~ to home directories. */ #define GLOB_ONLYDIR (1 << 13)/* Match only directories. */ #define GLOB_TILDE_CHECK (1 << 14)/* Like GLOB_TILDE but return an error if the user name is not available. */ #define __GLOB_FLAGS (GLOB_ERR|GLOB_MARK|GLOB_NOSORT|GLOB_DOOFFS| \ GLOB_NOESCAPE|GLOB_NOCHECK|GLOB_APPEND| \ GLOB_PERIOD|GLOB_ALTDIRFUNC|GLOB_BRACE| \ GLOB_NOMAGIC|GLOB_TILDE|GLOB_ONLYDIR|GLOB_TILDE_CHECK) /* Error returns from `glob'. */ #define GLOB_NOSPACE 1 /* Ran out of memory. */ #define GLOB_ABORTED 2 /* Read error. */ #define GLOB_NOMATCH 3 /* No matches found. */ #define GLOB_NOSYS 4 /* Not implemented. */ /* Previous versions of this file defined GLOB_ABEND instead of GLOB_ABORTED. Provide a compatibility definition here. */ #define GLOB_ABEND GLOB_ABORTED __END_DECLS #endif dietlibc-0.33~cvs20120325/include/grp.h010064400000000000000000000020641173363226500142740ustar00#ifndef _GRP_H #define _GRP_H #include #include __BEGIN_DECLS struct group { char *gr_name; /* Group name. */ char *gr_passwd; /* Password. */ gid_t gr_gid; /* Group ID. */ char **gr_mem; /* Member list. */ }; struct group *getgrgid (gid_t uid) __THROW; struct group *getgrnam (const char *name) __THROW; struct group *getgrent(void) __THROW; void setgrent(void) __THROW; void endgrent(void) __THROW; int getgrent_r(struct group *res, char *buf, size_t buflen, struct group **res_sig) __THROW; int getgrnam_r(const char* name, struct group *res, char *buf, size_t buflen, struct group **res_sig) __THROW; int getgrgid_r(uid_t uid, struct group *res, char *buf, size_t buflen, struct group **res_sig) __THROW; int setgroups(size_t n, const gid_t *groups) __THROW; int setgroups32(size_t n, const gid32_t *groups) __THROW; int initgroups(const char *user, gid_t group) __THROW; int getgrouplist(const char*user,gid_t group,gid_t*groups,int*ngroups) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/iconv.h010064400000000000000000000014731173363226500146250ustar00#ifndef _ICONV_H #define _ICONV_H #include #include __BEGIN_DECLS /* Identifier for conversion method from one codeset to another. */ typedef uint32_t iconv_t; /* Allocate descriptor for code conversion from codeset FROMCODE to codeset TOCODE. */ extern iconv_t iconv_open (const char *tocode, const char *fromcode) __THROW; /* Convert at most *INBYTESLEFT bytes from *INBUF according to the code conversion algorithm specified by CD and place up to *OUTBYTESLEFT bytes in buffer at *OUTBUF. */ extern size_t iconv (iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft) __THROW; /* Free resources allocated for descriptor CD for code conversion. */ extern int iconv_close (iconv_t cd) __THROW; __END_DECLS #endif /* iconv.h */ dietlibc-0.33~cvs20120325/include/inttypes.h010064400000000000000000000154371173363226500153730ustar00#ifndef _INTTYPES_H #define _INTTYPES_H #include #include __BEGIN_DECLS # if __WORDSIZE == 64 # define __PRI64_PREFIX "l" # define __PRIPTR_PREFIX "l" # else # define __PRI64_PREFIX "ll" # define __PRIPTR_PREFIX # endif /* Macros for printing format specifiers. */ /* Decimal notation. */ # define PRId8 "d" # define PRId16 "d" # define PRId32 "d" # define PRId64 __PRI64_PREFIX "d" # define PRIdLEAST8 "d" # define PRIdLEAST16 "d" # define PRIdLEAST32 "d" # define PRIdLEAST64 __PRI64_PREFIX "d" # define PRIdFAST8 "d" # define PRIdFAST16 "d" # define PRIdFAST32 "d" # define PRIdFAST64 __PRI64_PREFIX "d" # define PRIi8 "i" # define PRIi16 "i" # define PRIi32 "i" # define PRIi64 __PRI64_PREFIX "i" # define PRIiLEAST8 "i" # define PRIiLEAST16 "i" # define PRIiLEAST32 "i" # define PRIiLEAST64 __PRI64_PREFIX "i" # define PRIiFAST8 "i" # define PRIiFAST16 "i" # define PRIiFAST32 "i" # define PRIiFAST64 __PRI64_PREFIX "i" /* Octal notation. */ # define PRIo8 "o" # define PRIo16 "o" # define PRIo32 "o" # define PRIo64 __PRI64_PREFIX "o" # define PRIoLEAST8 "o" # define PRIoLEAST16 "o" # define PRIoLEAST32 "o" # define PRIoLEAST64 __PRI64_PREFIX "o" # define PRIoFAST8 "o" # define PRIoFAST16 "o" # define PRIoFAST32 "o" # define PRIoFAST64 __PRI64_PREFIX "o" /* Unsigned integers. */ # define PRIu8 "u" # define PRIu16 "u" # define PRIu32 "u" # define PRIu64 __PRI64_PREFIX "u" # define PRIuLEAST8 "u" # define PRIuLEAST16 "u" # define PRIuLEAST32 "u" # define PRIuLEAST64 __PRI64_PREFIX "u" # define PRIuFAST8 "u" # define PRIuFAST16 "u" # define PRIuFAST32 "u" # define PRIuFAST64 __PRI64_PREFIX "u" /* lowercase hexadecimal notation. */ # define PRIx8 "x" # define PRIx16 "x" # define PRIx32 "x" # define PRIx64 __PRI64_PREFIX "x" # define PRIxLEAST8 "x" # define PRIxLEAST16 "x" # define PRIxLEAST32 "x" # define PRIxLEAST64 __PRI64_PREFIX "x" # define PRIxFAST8 "x" # define PRIxFAST16 "x" # define PRIxFAST32 "x" # define PRIxFAST64 __PRI64_PREFIX "x" /* UPPERCASE hexadecimal notation. */ # define PRIX8 "X" # define PRIX16 "X" # define PRIX32 "X" # define PRIX64 __PRI64_PREFIX "X" # define PRIXLEAST8 "X" # define PRIXLEAST16 "X" # define PRIXLEAST32 "X" # define PRIXLEAST64 __PRI64_PREFIX "X" # define PRIXFAST8 "X" # define PRIXFAST16 "X" # define PRIXFAST32 "X" # define PRIXFAST64 __PRI64_PREFIX "X" /* Macros for printing `intmax_t' and `uintmax_t'. */ # define PRIdMAX __PRI64_PREFIX "d" # define PRIiMAX __PRI64_PREFIX "i" # define PRIoMAX __PRI64_PREFIX "o" # define PRIuMAX __PRI64_PREFIX "u" # define PRIxMAX __PRI64_PREFIX "x" # define PRIXMAX __PRI64_PREFIX "X" /* Macros for printing `intptr_t' and `uintptr_t'. */ # define PRIdPTR __PRIPTR_PREFIX "d" # define PRIiPTR __PRIPTR_PREFIX "i" # define PRIoPTR __PRIPTR_PREFIX "o" # define PRIuPTR __PRIPTR_PREFIX "u" # define PRIxPTR __PRIPTR_PREFIX "x" # define PRIXPTR __PRIPTR_PREFIX "X" /* Macros for scanning format specifiers. */ /* Signed decimal notation. */ # define SCNd8 "hhd" # define SCNd16 "hd" # define SCNd32 "d" # define SCNd64 __PRI64_PREFIX "d" # define SCNdLEAST8 "hhd" # define SCNdLEAST16 "hd" # define SCNdLEAST32 "d" # define SCNdLEAST64 __PRI64_PREFIX "d" # define SCNdFAST8 "hhd" # define SCNdFAST16 __PRIPTR_PREFIX "d" # define SCNdFAST32 __PRIPTR_PREFIX "d" # define SCNdFAST64 __PRI64_PREFIX "d" /* Signed decimal notation. */ # define SCNi8 "hhi" # define SCNi16 "hi" # define SCNi32 "i" # define SCNi64 __PRI64_PREFIX "i" # define SCNiLEAST8 "hhi" # define SCNiLEAST16 "hi" # define SCNiLEAST32 "i" # define SCNiLEAST64 __PRI64_PREFIX "i" # define SCNiFAST8 "hhi" # define SCNiFAST16 __PRIPTR_PREFIX "i" # define SCNiFAST32 __PRIPTR_PREFIX "i" # define SCNiFAST64 __PRI64_PREFIX "i" /* Unsigned decimal notation. */ # define SCNu8 "hhu" # define SCNu16 "hu" # define SCNu32 "u" # define SCNu64 __PRI64_PREFIX "u" # define SCNuLEAST8 "hhu" # define SCNuLEAST16 "hu" # define SCNuLEAST32 "u" # define SCNuLEAST64 __PRI64_PREFIX "u" # define SCNuFAST8 "hhu" # define SCNuFAST16 __PRIPTR_PREFIX "u" # define SCNuFAST32 __PRIPTR_PREFIX "u" # define SCNuFAST64 __PRI64_PREFIX "u" /* Octal notation. */ # define SCNo8 "hho" # define SCNo16 "ho" # define SCNo32 "o" # define SCNo64 __PRI64_PREFIX "o" # define SCNoLEAST8 "hho" # define SCNoLEAST16 "ho" # define SCNoLEAST32 "o" # define SCNoLEAST64 __PRI64_PREFIX "o" # define SCNoFAST8 "hho" # define SCNoFAST16 __PRIPTR_PREFIX "o" # define SCNoFAST32 __PRIPTR_PREFIX "o" # define SCNoFAST64 __PRI64_PREFIX "o" /* Hexadecimal notation. */ # define SCNx8 "hhx" # define SCNx16 "hx" # define SCNx32 "x" # define SCNx64 __PRI64_PREFIX "x" # define SCNxLEAST8 "hhx" # define SCNxLEAST16 "hx" # define SCNxLEAST32 "x" # define SCNxLEAST64 __PRI64_PREFIX "x" # define SCNxFAST8 "hhx" # define SCNxFAST16 __PRIPTR_PREFIX "x" # define SCNxFAST32 __PRIPTR_PREFIX "x" # define SCNxFAST64 __PRI64_PREFIX "x" /* Macros for scanning `intmax_t' and `uintmax_t'. */ # define SCNdMAX __PRI64_PREFIX "d" # define SCNiMAX __PRI64_PREFIX "i" # define SCNoMAX __PRI64_PREFIX "o" # define SCNuMAX __PRI64_PREFIX "u" # define SCNxMAX __PRI64_PREFIX "x" /* Macros for scanning `intptr_t' and `uintptr_t'. */ # define SCNdPTR __PRIPTR_PREFIX "d" # define SCNiPTR __PRIPTR_PREFIX "i" # define SCNoPTR __PRIPTR_PREFIX "o" # define SCNuPTR __PRIPTR_PREFIX "u" # define SCNxPTR __PRIPTR_PREFIX "x" typedef signed char int8_t; #if defined(__SHRT_MAX__) && (__SHRT_MAX__ + 0 != 32767) typedef int int16_t __attribute__((__mode__(__HI__))); #else typedef signed short int16_t; #endif #if defined(__INT_MAX__) && (__INT_MAX__ + 0 != 2147483647) typedef int int32_t __attribute__((__mode__(__SI__))); #else typedef signed int int32_t; #endif typedef unsigned char uint8_t; #if defined(__SHRT_MAX__) && (__SHRT_MAX__ + 0 != 32767) typedef unsigned int uint16_t __attribute__((__mode__(__HI__))); #else typedef unsigned short uint16_t; #endif #if defined(__INT_MAX__) && (__INT_MAX__ + 0 != 2147483647) typedef unsigned int uint32_t __attribute__((__mode__(__SI__))); #else typedef unsigned int uint32_t; #endif typedef signed long int intptr_t; typedef unsigned long int uintptr_t; #if __WORDSIZE == 64 typedef signed long int64_t; typedef unsigned long uint64_t; typedef signed long int intmax_t; typedef unsigned long int uintmax_t; #else __extension__ typedef signed long long int64_t; __extension__ typedef unsigned long long uint64_t; __extension__ typedef signed long long int intmax_t; __extension__ typedef unsigned long long int uintmax_t; #endif intmax_t strtoimax (const char *nptr, char **endptr, int base); uintmax_t strtoumax (const char *nptr, char **endptr, int base); intmax_t imaxabs(intmax_t j) __attribute_const__; typedef struct { intmax_t quot,rem; } imaxdiv_t; imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator) __attribute_const__; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/langinfo.h010064400000000000000000000001441173363226500152760ustar00#ifndef _LANGINFO_H #define _LANGINFO_H #include char *nl_langinfo(nl_item); #endif dietlibc-0.33~cvs20120325/include/libgen.h010064400000000000000000000002501173363226500147370ustar00#ifndef _LIBGEN_H #define _LIBGEN_H #include __BEGIN_DECLS char *dirname(char *path) __THROW; char *basename(char *path) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/libintl.h010064400000000000000000000021721173363226500151410ustar00#ifndef _LIBINTL_H #define _LIBINTL_H #include #include #include __BEGIN_DECLS char* gettext(const char* msgid) __THROW; char* dgettext(const char* domainname, const char* msgid) __THROW; char* dcgettext(const char *domainname, const char *msgid, int category) __THROW; char* ngettext (const char* msgid, const char* msgid_plural, unsigned long int n) __THROW; char* dngettext (const char* domainname, const char* msgid, const char* msgid_plural, unsigned long int n) __THROW; char* dcngettext(const char* domainname, const char* msgid1, const char* msgid2, unsigned long int n, int __category) __THROW; char* textdomain(const char *domainname) __THROW; char* bindtextdomain(const char *domainname, const char *dirname) __THROW; char* bind_textdomain_codeset(const char *domainname, const char *codeset) __THROW; #define gettext(msgid) dgettext(0,msgid) #define dgettext(domainname,msgid) dcgettext(domainname,msgid,LC_MESSAGES) #define ngettext(msgid1,msgid2,n) dngettext(0,msgid1,msgid2,n) #define dngettext(dn,msgid1,msgid2,n) dngettext(dn,msgid1,msgid2,n,LC_MESSAGES) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/limits.h010064400000000000000000000040321173363226500150020ustar00#ifndef _LIMITS_H #define _LIMITS_H #include #ifndef __SCHAR_MAX__ #define __SCHAR_MAX__ 0x7f #endif #ifndef __SHRT_MAX__ #define __SHRT_MAX__ 0x7fff #endif #ifndef __INT_MAX__ #define __INT_MAX__ 0x7fffffff #endif #ifndef __LONG_MAX__ #if __WORDSIZE == 64 #define __LONG_MAX__ 0x7fffffffffffffffl #else #define __LONG_MAX__ 0x7fffffffl #endif #endif #define CHAR_BIT 8 #define SCHAR_MIN (-1 - SCHAR_MAX) #define SCHAR_MAX (__SCHAR_MAX__) #define UCHAR_MAX (SCHAR_MAX * 2 + 1) #ifdef __CHAR_UNSIGNED__ #undef CHAR_MIN #define CHAR_MIN 0 #undef CHAR_MAX #define CHAR_MAX UCHAR_MAX #else #undef CHAR_MIN #define CHAR_MIN SCHAR_MIN #undef CHAR_MAX #define CHAR_MAX SCHAR_MAX #endif #define SHRT_MIN (-1 - SHRT_MAX) #define SHRT_MAX (__SHRT_MAX__) #define USHRT_MAX (SHRT_MAX * 2 + 1) #define INT_MIN (-1 - INT_MAX) #define INT_MAX (__INT_MAX__) #define UINT_MAX (INT_MAX * 2u + 1) #define LONG_MIN (-1l - LONG_MAX) #define LONG_MAX (__LONG_MAX__) #define ULONG_MAX (LONG_MAX * 2ul + 1) #define LLONG_MAX 0x7fffffffffffffffll #define LLONG_MIN (-1ll - LLONG_MAX) /* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */ #define ULLONG_MAX (~0ull) #define SSIZE_MIN LONG_MIN #define SSIZE_MAX LONG_MAX #define PASS_MAX 256 #define NR_OPEN 1024 #define NGROUPS_MAX 32 /* supplemental group IDs are available */ #define ARG_MAX 131072 /* # bytes of args + environ for exec() */ #define CHILD_MAX 999 /* no limit :-) */ #define OPEN_MAX 256 /* # open files a process may have */ #define LINK_MAX 127 /* # links a file may have */ #define MAX_CANON 255 /* size of the canonical input queue */ #define MAX_INPUT 255 /* size of the type-ahead buffer */ #define NAME_MAX 255 /* # chars in a file name */ #define PATH_MAX 4095 /* # chars in a path name */ #define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */ #define RTSIG_MAX 32 #define LINE_MAX 2048 /* mutt demanded these */ #define _POSIX_PATH_MAX PATH_MAX #define MB_LEN_MAX 16 #ifdef _XOPEN_SOURCE #define IOV_MAX 1024 #endif #endif dietlibc-0.33~cvs20120325/include/link.h010064400000000000000000000011201173363226500144310ustar00#ifndef _LINK_H #define _LINK_H #include __BEGIN_DECLS #define ElfW(type) _ElfW (Elf, __ELF_NATIVE_CLASS, type) #define _ElfW(e,w,t) _ElfW_1 (e, w, _##t) #define _ElfW_1(e,w,t) e##w##t #ifdef _GNU_SOURCE struct dl_phdr_info { ElfW(Addr) dlpi_addr; const char *dlpi_name; const ElfW(Phdr) *dlpi_phdr; ElfW(Half) dlpi_phnum; unsigned long long int dlpi_adds; unsigned long long int dlpi_subs; }; extern int dl_iterate_phdr (int (*callback) (struct dl_phdr_info *info, size_t size, void *data), void *data); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/linux/aio.h010064400000000000000000000033431173363226500154140ustar00#ifndef _LINUX_AIO_H #define _LINUX_AIO_H #ifdef typedef unsigned long aio_context_t; enum { IOCB_CMD_PREAD = 0, IOCB_CMD_PWRITE = 1, IOCB_CMD_FSYNC = 2, IOCB_CMD_FDSYNC = 3, /* These two are experimental. */ IOCB_CMD_PREADX = 4, IOCB_CMD_POLL = 5, /* */ IOCB_CMD_NOOP = 6, }; struct io_event { uint64_t data; /* the data field from the iocb */ uint64_t obj; /* what iocb this event came from */ int64_t res; /* result code for this event */ int64_t res2; /* secondary result */ }; #if __BYTE_ORDER == __LITTLE_ENDIAN #define PADDED(x,y) x, y #elif __BYTE_ORDER == __BIG_ENDIAN #define PADDED(x,y) y, x #else #error edit for your odd byteorder. #endif /* * we always use a 64bit off_t when communicating * with userland. its up to libraries to do the * proper padding and aio_error abstraction */ struct iocb { /* these are internal to the kernel/libc. */ uint64_t aio_data; /* data to be returned in event's data */ uint32_t PADDED(aio_key, aio_reserved1); /* the kernel sets aio_key to the req # */ /* common fields */ uint16_t aio_lio_opcode; /* see IOCB_CMD_ above */ int16_t aio_reqprio; uint32_t aio_fildes; uint64_t aio_buf; uint64_t aio_nbytes; int64_t aio_offset; /* extra parameters */ uint64_t aio_reserved2; /* TODO: use this for a (struct sigevent *) */ uint64_t aio_reserved3; }; /* 64 bytes */ long io_setup (unsigned nr_events, aio_context_t *ctxp); long io_destroy (aio_context_t ctx); long io_submit (aio_context_t ctx_id, long nr, struct iocb **iocbpp); long io_cancel (aio_context_t ctx_id, struct iocb *iocb, struct io_event *result); long io_getevents (aio_context_t ctx_id, long min_nr, long nr, struct io_event *events,struct timespec *timeout); #endif dietlibc-0.33~cvs20120325/include/linux/eventpoll.h010064400000000000000000000006511173363226500166530ustar00#ifndef _LINUX_EVENTPOLL_H #define _LINUX_EVENTPOLL_H #include #include #include #include __BEGIN_DECLS #define POLLFD_X_PAGE (PAGE_SIZE / sizeof(struct pollfd)) #define EP_FDS_PAGES(n) (((n) + POLLFD_X_PAGE - 1) / POLLFD_X_PAGE) #define EP_MAP_SIZE(n) (EP_FDS_PAGES(n) * PAGE_SIZE * 2) struct evpoll { int ep_timeout; unsigned long ep_resoff; }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/linux/fadvise.h010064400000000000000000000013561173363226500162670ustar00#ifndef _LINUX_FADVISE_H #define _LINUX_FADVISE_H #define POSIX_FADV_NORMAL 0 /* No further special treatment. */ #define POSIX_FADV_RANDOM 1 /* Expect random page references. */ #define POSIX_FADV_SEQUENTIAL 2 /* Expect sequential page references. */ #define POSIX_FADV_WILLNEED 3 /* Will need these pages. */ /* * The advise values for POSIX_FADV_DONTNEED and POSIX_ADV_NOREUSE * for s390-64 differ from the values for the rest of the world. */ #if defined(__s390x__) #define POSIX_FADV_DONTNEED 6 /* Don't need these pages. */ #define POSIX_FADV_NOREUSE 7 /* Data will be accessed once. */ #else #define POSIX_FADV_DONTNEED 4 /* Don't need these pages. */ #define POSIX_FADV_NOREUSE 5 /* Data will be accessed once. */ #endif #endif dietlibc-0.33~cvs20120325/include/linux/fd.h010064400000000000000000000256311173363226500152410ustar00#ifndef _LINUX_FD_H #define _LINUX_FD_H #include /* * Geometry */ struct floppy_struct { unsigned int size, /* nr of sectors total */ sect, /* sectors per track */ head, /* nr of heads */ track, /* nr of tracks */ stretch; /* !=0 means double track steps */ #define FD_STRETCH 1 #define FD_SWAPSIDES 2 #define FD_ZEROBASED 4 unsigned char gap, /* gap1 size */ rate, /* data rate. |= 0x40 for perpendicular */ #define FD_2M 0x4 #define FD_SIZECODEMASK 0x38 #define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8) #define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \ 512 : 128 << FD_SIZECODE(floppy) ) #define FD_PERP 0x40 spec1, /* stepping rate, head unload time */ fmt_gap; /* gap2 size */ const char * name; /* used only for predefined formats */ }; /* commands needing write access have 0x40 set */ /* commands needing super user access have 0x80 set */ #define FDCLRPRM _IO(2, 0x41) /* clear user-defined parameters */ #define FDSETPRM _IOW(2, 0x42, struct floppy_struct) #define FDSETMEDIAPRM FDSETPRM /* set user-defined parameters for current media */ #define FDDEFPRM _IOW(2, 0x43, struct floppy_struct) #define FDGETPRM _IOR(2, 0x04, struct floppy_struct) #define FDDEFMEDIAPRM FDDEFPRM #define FDGETMEDIAPRM FDGETPRM /* set/get disk parameters */ #define FDMSGON _IO(2,0x45) #define FDMSGOFF _IO(2,0x46) /* issue/don't issue kernel messages on media type change */ /* * Formatting (obsolete) */ #define FD_FILL_BYTE 0xF6 /* format fill byte. */ struct format_descr { unsigned int device,head,track; }; #define FDFMTBEG _IO(2,0x47) /* begin formatting a disk */ #define FDFMTTRK _IOW(2,0x48, struct format_descr) /* format the specified track */ #define FDFMTEND _IO(2,0x49) /* end formatting a disk */ /* * Error thresholds */ struct floppy_max_errors { unsigned int abort, /* number of errors to be reached before aborting */ read_track, /* maximal number of errors permitted to read an * entire track at once */ reset, /* maximal number of errors before a reset is tried */ recal, /* maximal number of errors before a recalibrate is * tried */ /* * Threshold for reporting FDC errors to the console. * Setting this to zero may flood your screen when using * ultra cheap floppies ;-) */ reporting; }; #define FDSETEMSGTRESH _IO(2,0x4a) /* set fdc error reporting threshold */ #define FDFLUSH _IO(2,0x4b) /* flush buffers for media; either for verifying media, or for * handling a media change without closing the file descriptor */ #define FDSETMAXERRS _IOW(2, 0x4c, struct floppy_max_errors) #define FDGETMAXERRS _IOR(2, 0x0e, struct floppy_max_errors) /* set/get abortion and read_track threshold. See also floppy_drive_params * structure */ typedef char floppy_drive_name[16]; #define FDGETDRVTYP _IOR(2, 0x0f, floppy_drive_name) /* get drive type: 5 1/4 or 3 1/2 */ /* * Drive parameters (user modifiable) */ struct floppy_drive_params { signed char cmos; /* CMOS type */ /* Spec2 is (HLD<<1 | ND), where HLD is head load time (1=2ms, 2=4 ms * etc) and ND is set means no DMA. Hardcoded to 6 (HLD=6ms, use DMA). */ unsigned long max_dtr; /* Step rate, usec */ unsigned long hlt; /* Head load/settle time, msec */ unsigned long hut; /* Head unload time (remnant of * 8" drives) */ unsigned long srt; /* Step rate, usec */ unsigned long spinup; /* time needed for spinup (expressed * in jiffies) */ unsigned long spindown; /* timeout needed for spindown */ unsigned char spindown_offset; /* decides in which position the disk * will stop */ unsigned char select_delay; /* delay to wait after select */ unsigned char rps; /* rotations per second */ unsigned char tracks; /* maximum number of tracks */ unsigned long timeout; /* timeout for interrupt requests */ unsigned char interleave_sect; /* if there are more sectors, use * interleave */ struct floppy_max_errors max_errors; char flags; /* various flags, including ftd_msg */ /* * Announce successful media type detection and media information loss after * disk changes. * Also used to enable/disable printing of overrun warnings. */ #define FTD_MSG 0x10 #define FD_BROKEN_DCL 0x20 #define FD_DEBUG 0x02 #define FD_SILENT_DCL_CLEAR 0x4 #define FD_INVERTED_DCL 0x80 /* must be 0x80, because of hardware considerations */ char read_track; /* use readtrack during probing? */ /* * Auto-detection. Each drive type has eight formats which are * used in succession to try to read the disk. If the FDC cannot lock onto * the disk, the next format is tried. This uses the variable 'probing'. */ short autodetect[8]; /* autodetected formats */ int checkfreq; /* how often should the drive be checked for disk * changes */ int native_format; /* native format of this drive */ }; enum { FD_NEED_TWADDLE_BIT, /* more magic */ FD_VERIFY_BIT, /* inquire for write protection */ FD_DISK_NEWCHANGE_BIT, /* change detected, and no action undertaken yet * to clear media change status */ FD_UNUSED_BIT, FD_DISK_CHANGED_BIT, /* disk has been changed since last i/o */ FD_DISK_WRITABLE_BIT /* disk is writable */ }; #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params) #define FDGETDRVPRM _IOR(2, 0x11, struct floppy_drive_params) /* set/get drive parameters */ /* * Current drive state (not directly modifiable by user, readonly) */ struct floppy_drive_struct { unsigned long flags; /* values for these flags */ #define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT) #define FD_VERIFY (1 << FD_VERIFY_BIT) #define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT) #define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT) #define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT) unsigned long spinup_date; unsigned long select_date; unsigned long first_read_date; short probed_format; short track; /* current track */ short maxblock; /* id of highest block read */ short maxtrack; /* id of highest half track read */ int generation; /* how many diskchanges? */ /* * (User-provided) media information is _not_ discarded after a media change * if the corresponding keep_data flag is non-zero. Positive values are * decremented after each probe. */ int keep_data; /* Prevent "aliased" accesses. */ int fd_ref; int fd_device; unsigned long last_checked; /* when was the drive last checked for a disk * change? */ char *dmabuf; int bufblocks; }; #define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct) #define FDPOLLDRVSTAT _IOR(2, 0x13, struct floppy_drive_struct) /* get drive state: GET returns the cached state, POLL polls for new state */ /* * reset FDC */ enum reset_mode { FD_RESET_IF_NEEDED, /* reset only if the reset flags is set */ FD_RESET_IF_RAWCMD, /* obsolete */ FD_RESET_ALWAYS /* reset always */ }; #define FDRESET _IO(2, 0x54) /* * FDC state */ struct floppy_fdc_state { int spec1; /* spec1 value last used */ int spec2; /* spec2 value last used */ int dtr; unsigned char version; /* FDC version code */ unsigned char dor; unsigned long address; /* io address */ unsigned int rawcmd:2; unsigned int reset:1; unsigned int need_configure:1; unsigned int perp_mode:2; unsigned int has_fifo:1; unsigned int driver_version; /* version code for floppy driver */ #define FD_DRIVER_VERSION 0x100 /* user programs using the floppy API should use floppy_fdc_state to * get the version number of the floppy driver that they are running * on. If this version number is bigger than the one compiled into the * user program (the FD_DRIVER_VERSION define), it should be prepared * to bigger structures */ unsigned char track[4]; /* Position of the heads of the 4 units attached to this FDC, * as stored on the FDC. In the future, the position as stored * on the FDC might not agree with the actual physical * position of these drive heads. By allowing such * disagreement, it will be possible to reset the FDC without * incurring the expensive cost of repositioning all heads. * Right now, these positions are hard wired to 0. */ }; #define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state) /* * Asynchronous Write error tracking */ struct floppy_write_errors { /* Write error logging. * * These fields can be cleared with the FDWERRORCLR ioctl. * Only writes that were attempted but failed due to a physical media * error are logged. write(2) calls that fail and return an error code * to the user process are not counted. */ unsigned int write_errors; /* number of physical write errors * encountered */ /* position of first and last write errors */ unsigned long first_error_sector; int first_error_generation; unsigned long last_error_sector; int last_error_generation; unsigned int badness; /* highest retry count for a read or write * operation */ }; #define FDWERRORCLR _IO(2, 0x56) /* clear write error and badness information */ #define FDWERRORGET _IOR(2, 0x17, struct floppy_write_errors) /* get write error and badness information */ /* * Raw commands */ /* new interface flag: now we can do them in batches */ #define FDHAVEBATCHEDRAWCMD struct floppy_raw_cmd { unsigned int flags; #define FD_RAW_READ 1 #define FD_RAW_WRITE 2 #define FD_RAW_NO_MOTOR 4 #define FD_RAW_DISK_CHANGE 4 /* out: disk change flag was set */ #define FD_RAW_INTR 8 /* wait for an interrupt */ #define FD_RAW_SPIN 0x10 /* spin up the disk for this command */ #define FD_RAW_NO_MOTOR_AFTER 0x20 /* switch the motor off after command * completion */ #define FD_RAW_NEED_DISK 0x40 /* this command needs a disk to be present */ #define FD_RAW_NEED_SEEK 0x80 /* this command uses an implied seek (soft) */ /* more "in" flags */ #define FD_RAW_MORE 0x100 /* more records follow */ #define FD_RAW_STOP_IF_FAILURE 0x200 /* stop if we encounter a failure */ #define FD_RAW_STOP_IF_SUCCESS 0x400 /* stop if command successful */ #define FD_RAW_SOFTFAILURE 0x800 /* consider the return value for failure * detection too */ /* more "out" flags */ #define FD_RAW_FAILURE 0x10000 /* command sent to fdc, fdc returned error */ #define FD_RAW_HARDFAILURE 0x20000 /* fdc had to be reset, or timed out */ void *data; char *kernel_data; /* location of data buffer in the kernel */ struct floppy_raw_cmd *next; /* used for chaining of raw cmd's * within the kernel */ long length; /* in: length of dma transfer. out: remaining bytes */ long phys_length; /* physical length, if different from dma length */ int buffer_length; /* length of allocated buffer */ unsigned char rate; unsigned char cmd_count; unsigned char cmd[16]; unsigned char reply_count; unsigned char reply[16]; int track; int resultcode; int reserved1; int reserved2; }; #define FDRAWCMD _IO(2, 0x58) /* send a raw command to the fdc. Structure size not included, because of * batches */ #define FDTWADDLE _IO(2, 0x59) /* flicker motor-on bit before reading a sector. Experimental */ #define FDEJECT _IO(2, 0x5a) /* eject the disk */ #endif dietlibc-0.33~cvs20120325/include/linux/if.h010064400000000000000000000026211173363226500152400ustar00#ifndef _LINUX_IF_H #define _LINUX_IF_H #include #define IF_GET_IFACE 0x0001 /* for querying only */ #define IF_GET_PROTO 0x0002 /* For definitions see hdlc.h */ #define IF_IFACE_V35 0x1000 /* V.35 serial interface */ #define IF_IFACE_V24 0x1001 /* V.24 serial interface */ #define IF_IFACE_X21 0x1002 /* X.21 serial interface */ #define IF_IFACE_T1 0x1003 /* T1 telco serial interface */ #define IF_IFACE_E1 0x1004 /* E1 telco serial interface */ #define IF_IFACE_SYNC_SERIAL 0x1005 /* can't be set by software */ #define IF_IFACE_X21D 0x1006 /* X.21 Dual Clocking (FarSite) */ /* For definitions see hdlc.h */ #define IF_PROTO_HDLC 0x2000 /* raw HDLC protocol */ #define IF_PROTO_PPP 0x2001 /* PPP protocol */ #define IF_PROTO_CISCO 0x2002 /* Cisco HDLC protocol */ #define IF_PROTO_FR 0x2003 /* Frame Relay protocol */ #define IF_PROTO_FR_ADD_PVC 0x2004 /* Create FR PVC */ #define IF_PROTO_FR_DEL_PVC 0x2005 /* Delete FR PVC */ #define IF_PROTO_X25 0x2006 /* X.25 */ #define IF_PROTO_HDLC_ETH 0x2007 /* raw HDLC, Ethernet emulation */ #define IF_PROTO_FR_ADD_ETH_PVC 0x2008 /* Create FR Ethernet-bridged PVC */ #define IF_PROTO_FR_DEL_ETH_PVC 0x2009 /* Delete FR Ethernet-bridged PVC */ #define IF_PROTO_FR_PVC 0x200A /* for reading PVC status */ #define IF_PROTO_FR_ETH_PVC 0x200B #define IF_PROTO_RAW 0x200C /* RAW Socket */ #endif dietlibc-0.33~cvs20120325/include/linux/if_ether.h010064400000000000000000000001271173363226500164260ustar00#ifndef _LINUX_IF_ETHER_H #define _LINUX_IF_ETHER_H #include #endif dietlibc-0.33~cvs20120325/include/linux/if_tun.h010064400000000000000000000015101173363226500161220ustar00#ifndef _LINUX_IF_TUN_H #define _LINUX_IF_TUN_H /* Read queue size */ #define TUN_READQ_SIZE 500 /* TUN device flags */ #define TUN_TUN_DEV 0x0001 #define TUN_TAP_DEV 0x0002 #define TUN_TYPE_MASK 0x000f #define TUN_FASYNC 0x0010 #define TUN_NOCHECKSUM 0x0020 #define TUN_NO_PI 0x0040 #define TUN_ONE_QUEUE 0x0080 #define TUN_PERSIST 0x0100 /* Ioctl defines */ #define TUNSETNOCSUM _IOW('T', 200, int) #define TUNSETDEBUG _IOW('T', 201, int) #define TUNSETIFF _IOW('T', 202, int) #define TUNSETPERSIST _IOW('T', 203, int) #define TUNSETOWNER _IOW('T', 204, int) #define TUNSETLINK _IOW('T', 205, int) /* TUNSETIFF ifr flags */ #define IFF_TUN 0x0001 #define IFF_TAP 0x0002 #define IFF_NO_PI 0x1000 #define IFF_ONE_QUEUE 0x2000 struct tun_pi { unsigned short flags; unsigned short proto; }; #define TUN_PKT_STRIP 0x0001 #endif dietlibc-0.33~cvs20120325/include/linux/kd.h010064400000000000000000000131541173363226500152430ustar00#ifndef _LINUX_KD_H #define _LINUX_KD_H #include __BEGIN_DECLS /* 0x4B is 'K', to avoid collision with termios and vt */ #define GIO_FONT 0x4B60 /* gets font in expanded form */ #define PIO_FONT 0x4B61 /* use font in expanded form */ #define GIO_FONTX 0x4B6B /* get font using struct consolefontdesc */ #define PIO_FONTX 0x4B6C /* set font using struct consolefontdesc */ struct consolefontdesc { unsigned short charcount; /* characters in font (256 or 512) */ unsigned short charheight; /* scan lines per character (1-32) */ char* chardata; /* font data in expanded form */ }; #define PIO_FONTRESET 0x4B6D /* reset to default font */ #define GIO_CMAP 0x4B70 /* gets colour palette on VGA+ */ #define PIO_CMAP 0x4B71 /* sets colour palette on VGA+ */ #define KIOCSOUND 0x4B2F /* start sound generation (0 for off) */ #define KDMKTONE 0x4B30 /* generate tone */ #define KDGETLED 0x4B31 /* return current led state */ #define KDSETLED 0x4B32 /* set led state [lights, not flags] */ #define LED_SCR 0x01 /* scroll lock led */ #define LED_NUM 0x02 /* num lock led */ #define LED_CAP 0x04 /* caps lock led */ #define KDGKBTYPE 0x4B33 /* get keyboard type */ #define KB_84 0x01 #define KB_101 0x02 /* this is what we always answer */ #define KB_OTHER 0x03 #define KDADDIO 0x4B34 /* add i/o port as valid */ #define KDDELIO 0x4B35 /* del i/o port as valid */ #define KDENABIO 0x4B36 /* enable i/o to video board */ #define KDDISABIO 0x4B37 /* disable i/o to video board */ #define KDSETMODE 0x4B3A /* set text/graphics mode */ #define KD_TEXT 0x00 #define KD_GRAPHICS 0x01 #define KD_TEXT0 0x02 /* obsolete */ #define KD_TEXT1 0x03 /* obsolete */ #define KDGETMODE 0x4B3B /* get current mode */ #define KDMAPDISP 0x4B3C /* map display into address space */ #define KDUNMAPDISP 0x4B3D /* unmap display from address space */ typedef char scrnmap_t; #define E_TABSZ 256 #define GIO_SCRNMAP 0x4B40 /* get screen mapping from kernel */ #define PIO_SCRNMAP 0x4B41 /* put screen mapping table in kernel */ #define GIO_UNISCRNMAP 0x4B69 /* get full Unicode screen mapping */ #define PIO_UNISCRNMAP 0x4B6A /* set full Unicode screen mapping */ #define GIO_UNIMAP 0x4B66 /* get unicode-to-font mapping from kernel */ struct unipair { unsigned short unicode; unsigned short fontpos; }; struct unimapdesc { unsigned short entry_ct; struct unipair *entries; }; #define PIO_UNIMAP 0x4B67 /* put unicode-to-font mapping in kernel */ #define PIO_UNIMAPCLR 0x4B68 /* clear table, possibly advise hash algorithm */ struct unimapinit { unsigned short advised_hashsize; /* 0 if no opinion */ unsigned short advised_hashstep; /* 0 if no opinion */ unsigned short advised_hashlevel; /* 0 if no opinion */ }; #define UNI_DIRECT_BASE 0xF000 /* start of Direct Font Region */ #define UNI_DIRECT_MASK 0x01FF /* Direct Font Region bitmask */ #define K_RAW 0x00 #define K_XLATE 0x01 #define K_MEDIUMRAW 0x02 #define K_UNICODE 0x03 #define KDGKBMODE 0x4B44 /* gets current keyboard mode */ #define KDSKBMODE 0x4B45 /* sets current keyboard mode */ #define K_METABIT 0x03 #define K_ESCPREFIX 0x04 #define KDGKBMETA 0x4B62 /* gets meta key handling mode */ #define KDSKBMETA 0x4B63 /* sets meta key handling mode */ #define K_SCROLLLOCK 0x01 #define K_NUMLOCK 0x02 #define K_CAPSLOCK 0x04 #define KDGKBLED 0x4B64 /* get led flags (not lights) */ #define KDSKBLED 0x4B65 /* set led flags (not lights) */ struct kbentry { unsigned char kb_table; unsigned char kb_index; unsigned short kb_value; }; #define K_NORMTAB 0x00 #define K_SHIFTTAB 0x01 #define K_ALTTAB 0x02 #define K_ALTSHIFTTAB 0x03 #define KDGKBENT 0x4B46 /* gets one entry in translation table */ #define KDSKBENT 0x4B47 /* sets one entry in translation table */ struct kbsentry { unsigned char kb_func; unsigned char kb_string[512]; }; #define KDGKBSENT 0x4B48 /* gets one function key string entry */ #define KDSKBSENT 0x4B49 /* sets one function key string entry */ struct kbdiacr { unsigned char diacr, base, result; }; struct kbdiacrs { unsigned int kb_cnt; /* number of entries in following array */ struct kbdiacr kbdiacr[256]; /* MAX_DIACR from keyboard.h */ }; #define KDGKBDIACR 0x4B4A /* read kernel accent table */ #define KDSKBDIACR 0x4B4B /* write kernel accent table */ struct kbkeycode { unsigned int scancode, keycode; }; #define KDGETKEYCODE 0x4B4C /* read kernel keycode table entry */ #define KDSETKEYCODE 0x4B4D /* write kernel keycode table entry */ #define KDSIGACCEPT 0x4B4E /* accept kbd generated signals */ struct kbd_repeat { int delay; /* in msec; <= 0: don't change */ int rate; /* in msec; <= 0: don't change */ }; #define KDKBDREP 0x4B52 /* set keyboard delay/repeat rate; * actually used values are returned */ #define KDFONTOP 0x4B72 /* font operations */ struct console_font_op { unsigned int op; /* operation code KD_FONT_OP_* */ unsigned int flags; /* KD_FONT_FLAG_* */ unsigned int width, height; /* font size */ unsigned int charcount; unsigned char* data; /* font data with height fixed to 32 */ }; #define KD_FONT_OP_SET 0 /* Set font */ #define KD_FONT_OP_GET 1 /* Get font */ #define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, data points to name / NULL */ #define KD_FONT_OP_COPY 3 /* Copy from another console */ #define KD_FONT_FLAG_DONT_RECALC 1 /* Don't recalculate hw charcell size [compat] */ #ifdef __KERNEL__ #define KD_FONT_FLAG_OLD 0x80000000 /* Invoked via old interface [compat] */ #endif /* note: 0x4B00-0x4B4E all have had a value at some time; don't reuse for the time being */ /* note: 0x4B60-0x4B6D, 0x4B70-0x4B72 used above */ __END_DECLS #endif /* _LINUX_KD_H */ dietlibc-0.33~cvs20120325/include/linux/keyboard.h010064400000000000000000000305751173363226500164530ustar00#ifndef __LINUX_KEYBOARD_H #define __LINUX_KEYBOARD_H #define KG_SHIFT 0 #define KG_CTRL 2 #define KG_ALT 3 #define KG_ALTGR 1 #define KG_SHIFTL 4 #define KG_KANASHIFT 4 #define KG_SHIFTR 5 #define KG_CTRLL 6 #define KG_CTRLR 7 #define KG_CAPSSHIFT 8 #define NR_SHIFT 9 #define NR_KEYS 256 #define MAX_NR_KEYMAPS 256 /* This means 128Kb if all keymaps are allocated. Only the superuser may increase the number of keymaps beyond MAX_NR_OF_USER_KEYMAPS. */ #define MAX_NR_OF_USER_KEYMAPS 256 /* should be at least 7 */ #define MAX_NR_FUNC 256 /* max nr of strings assigned to keys */ #define KT_LATIN 0 /* we depend on this being zero */ #define KT_LETTER 11 /* symbol that can be acted upon by CapsLock */ #define KT_FN 1 #define KT_SPEC 2 #define KT_PAD 3 #define KT_DEAD 4 #define KT_CONS 5 #define KT_CUR 6 #define KT_SHIFT 7 #define KT_META 8 #define KT_ASCII 9 #define KT_LOCK 10 #define KT_SLOCK 12 #define KT_DEAD2 13 #define KT_BRL 14 #define K(t,v) (((t)<<8)|(v)) #define KTYP(x) ((x) >> 8) #define KVAL(x) ((x) & 0xff) #define K_F1 K(KT_FN,0) #define K_F2 K(KT_FN,1) #define K_F3 K(KT_FN,2) #define K_F4 K(KT_FN,3) #define K_F5 K(KT_FN,4) #define K_F6 K(KT_FN,5) #define K_F7 K(KT_FN,6) #define K_F8 K(KT_FN,7) #define K_F9 K(KT_FN,8) #define K_F10 K(KT_FN,9) #define K_F11 K(KT_FN,10) #define K_F12 K(KT_FN,11) #define K_F13 K(KT_FN,12) #define K_F14 K(KT_FN,13) #define K_F15 K(KT_FN,14) #define K_F16 K(KT_FN,15) #define K_F17 K(KT_FN,16) #define K_F18 K(KT_FN,17) #define K_F19 K(KT_FN,18) #define K_F20 K(KT_FN,19) #define K_FIND K(KT_FN,20) #define K_INSERT K(KT_FN,21) #define K_REMOVE K(KT_FN,22) #define K_SELECT K(KT_FN,23) #define K_PGUP K(KT_FN,24) /* PGUP is a synonym for PRIOR */ #define K_PGDN K(KT_FN,25) /* PGDN is a synonym for NEXT */ #define K_MACRO K(KT_FN,26) #define K_HELP K(KT_FN,27) #define K_DO K(KT_FN,28) #define K_PAUSE K(KT_FN,29) #define K_F21 K(KT_FN,30) #define K_F22 K(KT_FN,31) #define K_F23 K(KT_FN,32) #define K_F24 K(KT_FN,33) #define K_F25 K(KT_FN,34) #define K_F26 K(KT_FN,35) #define K_F27 K(KT_FN,36) #define K_F28 K(KT_FN,37) #define K_F29 K(KT_FN,38) #define K_F30 K(KT_FN,39) #define K_F31 K(KT_FN,40) #define K_F32 K(KT_FN,41) #define K_F33 K(KT_FN,42) #define K_F34 K(KT_FN,43) #define K_F35 K(KT_FN,44) #define K_F36 K(KT_FN,45) #define K_F37 K(KT_FN,46) #define K_F38 K(KT_FN,47) #define K_F39 K(KT_FN,48) #define K_F40 K(KT_FN,49) #define K_F41 K(KT_FN,50) #define K_F42 K(KT_FN,51) #define K_F43 K(KT_FN,52) #define K_F44 K(KT_FN,53) #define K_F45 K(KT_FN,54) #define K_F46 K(KT_FN,55) #define K_F47 K(KT_FN,56) #define K_F48 K(KT_FN,57) #define K_F49 K(KT_FN,58) #define K_F50 K(KT_FN,59) #define K_F51 K(KT_FN,60) #define K_F52 K(KT_FN,61) #define K_F53 K(KT_FN,62) #define K_F54 K(KT_FN,63) #define K_F55 K(KT_FN,64) #define K_F56 K(KT_FN,65) #define K_F57 K(KT_FN,66) #define K_F58 K(KT_FN,67) #define K_F59 K(KT_FN,68) #define K_F60 K(KT_FN,69) #define K_F61 K(KT_FN,70) #define K_F62 K(KT_FN,71) #define K_F63 K(KT_FN,72) #define K_F64 K(KT_FN,73) #define K_F65 K(KT_FN,74) #define K_F66 K(KT_FN,75) #define K_F67 K(KT_FN,76) #define K_F68 K(KT_FN,77) #define K_F69 K(KT_FN,78) #define K_F70 K(KT_FN,79) #define K_F71 K(KT_FN,80) #define K_F72 K(KT_FN,81) #define K_F73 K(KT_FN,82) #define K_F74 K(KT_FN,83) #define K_F75 K(KT_FN,84) #define K_F76 K(KT_FN,85) #define K_F77 K(KT_FN,86) #define K_F78 K(KT_FN,87) #define K_F79 K(KT_FN,88) #define K_F80 K(KT_FN,89) #define K_F81 K(KT_FN,90) #define K_F82 K(KT_FN,91) #define K_F83 K(KT_FN,92) #define K_F84 K(KT_FN,93) #define K_F85 K(KT_FN,94) #define K_F86 K(KT_FN,95) #define K_F87 K(KT_FN,96) #define K_F88 K(KT_FN,97) #define K_F89 K(KT_FN,98) #define K_F90 K(KT_FN,99) #define K_F91 K(KT_FN,100) #define K_F92 K(KT_FN,101) #define K_F93 K(KT_FN,102) #define K_F94 K(KT_FN,103) #define K_F95 K(KT_FN,104) #define K_F96 K(KT_FN,105) #define K_F97 K(KT_FN,106) #define K_F98 K(KT_FN,107) #define K_F99 K(KT_FN,108) #define K_F100 K(KT_FN,109) #define K_F101 K(KT_FN,110) #define K_F102 K(KT_FN,111) #define K_F103 K(KT_FN,112) #define K_F104 K(KT_FN,113) #define K_F105 K(KT_FN,114) #define K_F106 K(KT_FN,115) #define K_F107 K(KT_FN,116) #define K_F108 K(KT_FN,117) #define K_F109 K(KT_FN,118) #define K_F110 K(KT_FN,119) #define K_F111 K(KT_FN,120) #define K_F112 K(KT_FN,121) #define K_F113 K(KT_FN,122) #define K_F114 K(KT_FN,123) #define K_F115 K(KT_FN,124) #define K_F116 K(KT_FN,125) #define K_F117 K(KT_FN,126) #define K_F118 K(KT_FN,127) #define K_F119 K(KT_FN,128) #define K_F120 K(KT_FN,129) #define K_F121 K(KT_FN,130) #define K_F122 K(KT_FN,131) #define K_F123 K(KT_FN,132) #define K_F124 K(KT_FN,133) #define K_F125 K(KT_FN,134) #define K_F126 K(KT_FN,135) #define K_F127 K(KT_FN,136) #define K_F128 K(KT_FN,137) #define K_F129 K(KT_FN,138) #define K_F130 K(KT_FN,139) #define K_F131 K(KT_FN,140) #define K_F132 K(KT_FN,141) #define K_F133 K(KT_FN,142) #define K_F134 K(KT_FN,143) #define K_F135 K(KT_FN,144) #define K_F136 K(KT_FN,145) #define K_F137 K(KT_FN,146) #define K_F138 K(KT_FN,147) #define K_F139 K(KT_FN,148) #define K_F140 K(KT_FN,149) #define K_F141 K(KT_FN,150) #define K_F142 K(KT_FN,151) #define K_F143 K(KT_FN,152) #define K_F144 K(KT_FN,153) #define K_F145 K(KT_FN,154) #define K_F146 K(KT_FN,155) #define K_F147 K(KT_FN,156) #define K_F148 K(KT_FN,157) #define K_F149 K(KT_FN,158) #define K_F150 K(KT_FN,159) #define K_F151 K(KT_FN,160) #define K_F152 K(KT_FN,161) #define K_F153 K(KT_FN,162) #define K_F154 K(KT_FN,163) #define K_F155 K(KT_FN,164) #define K_F156 K(KT_FN,165) #define K_F157 K(KT_FN,166) #define K_F158 K(KT_FN,167) #define K_F159 K(KT_FN,168) #define K_F160 K(KT_FN,169) #define K_F161 K(KT_FN,170) #define K_F162 K(KT_FN,171) #define K_F163 K(KT_FN,172) #define K_F164 K(KT_FN,173) #define K_F165 K(KT_FN,174) #define K_F166 K(KT_FN,175) #define K_F167 K(KT_FN,176) #define K_F168 K(KT_FN,177) #define K_F169 K(KT_FN,178) #define K_F170 K(KT_FN,179) #define K_F171 K(KT_FN,180) #define K_F172 K(KT_FN,181) #define K_F173 K(KT_FN,182) #define K_F174 K(KT_FN,183) #define K_F175 K(KT_FN,184) #define K_F176 K(KT_FN,185) #define K_F177 K(KT_FN,186) #define K_F178 K(KT_FN,187) #define K_F179 K(KT_FN,188) #define K_F180 K(KT_FN,189) #define K_F181 K(KT_FN,190) #define K_F182 K(KT_FN,191) #define K_F183 K(KT_FN,192) #define K_F184 K(KT_FN,193) #define K_F185 K(KT_FN,194) #define K_F186 K(KT_FN,195) #define K_F187 K(KT_FN,196) #define K_F188 K(KT_FN,197) #define K_F189 K(KT_FN,198) #define K_F190 K(KT_FN,199) #define K_F191 K(KT_FN,200) #define K_F192 K(KT_FN,201) #define K_F193 K(KT_FN,202) #define K_F194 K(KT_FN,203) #define K_F195 K(KT_FN,204) #define K_F196 K(KT_FN,205) #define K_F197 K(KT_FN,206) #define K_F198 K(KT_FN,207) #define K_F199 K(KT_FN,208) #define K_F200 K(KT_FN,209) #define K_F201 K(KT_FN,210) #define K_F202 K(KT_FN,211) #define K_F203 K(KT_FN,212) #define K_F204 K(KT_FN,213) #define K_F205 K(KT_FN,214) #define K_F206 K(KT_FN,215) #define K_F207 K(KT_FN,216) #define K_F208 K(KT_FN,217) #define K_F209 K(KT_FN,218) #define K_F210 K(KT_FN,219) #define K_F211 K(KT_FN,220) #define K_F212 K(KT_FN,221) #define K_F213 K(KT_FN,222) #define K_F214 K(KT_FN,223) #define K_F215 K(KT_FN,224) #define K_F216 K(KT_FN,225) #define K_F217 K(KT_FN,226) #define K_F218 K(KT_FN,227) #define K_F219 K(KT_FN,228) #define K_F220 K(KT_FN,229) #define K_F221 K(KT_FN,230) #define K_F222 K(KT_FN,231) #define K_F223 K(KT_FN,232) #define K_F224 K(KT_FN,233) #define K_F225 K(KT_FN,234) #define K_F226 K(KT_FN,235) #define K_F227 K(KT_FN,236) #define K_F228 K(KT_FN,237) #define K_F229 K(KT_FN,238) #define K_F230 K(KT_FN,239) #define K_F231 K(KT_FN,240) #define K_F232 K(KT_FN,241) #define K_F233 K(KT_FN,242) #define K_F234 K(KT_FN,243) #define K_F235 K(KT_FN,244) #define K_F236 K(KT_FN,245) #define K_F237 K(KT_FN,246) #define K_F238 K(KT_FN,247) #define K_F239 K(KT_FN,248) #define K_F240 K(KT_FN,249) #define K_F241 K(KT_FN,250) #define K_F242 K(KT_FN,251) #define K_F243 K(KT_FN,252) #define K_F244 K(KT_FN,253) #define K_F245 K(KT_FN,254) #define K_UNDO K(KT_FN,255) #define K_HOLE K(KT_SPEC,0) #define K_ENTER K(KT_SPEC,1) #define K_SH_REGS K(KT_SPEC,2) #define K_SH_MEM K(KT_SPEC,3) #define K_SH_STAT K(KT_SPEC,4) #define K_BREAK K(KT_SPEC,5) #define K_CONS K(KT_SPEC,6) #define K_CAPS K(KT_SPEC,7) #define K_NUM K(KT_SPEC,8) #define K_HOLD K(KT_SPEC,9) #define K_SCROLLFORW K(KT_SPEC,10) #define K_SCROLLBACK K(KT_SPEC,11) #define K_BOOT K(KT_SPEC,12) #define K_CAPSON K(KT_SPEC,13) #define K_COMPOSE K(KT_SPEC,14) #define K_SAK K(KT_SPEC,15) #define K_DECRCONSOLE K(KT_SPEC,16) #define K_INCRCONSOLE K(KT_SPEC,17) #define K_SPAWNCONSOLE K(KT_SPEC,18) #define K_BARENUMLOCK K(KT_SPEC,19) #define K_ALLOCATED K(KT_SPEC,126) /* dynamically allocated keymap */ #define K_NOSUCHMAP K(KT_SPEC,127) /* returned by KDGKBENT */ #define K_P0 K(KT_PAD,0) #define K_P1 K(KT_PAD,1) #define K_P2 K(KT_PAD,2) #define K_P3 K(KT_PAD,3) #define K_P4 K(KT_PAD,4) #define K_P5 K(KT_PAD,5) #define K_P6 K(KT_PAD,6) #define K_P7 K(KT_PAD,7) #define K_P8 K(KT_PAD,8) #define K_P9 K(KT_PAD,9) #define K_PPLUS K(KT_PAD,10) /* key-pad plus */ #define K_PMINUS K(KT_PAD,11) /* key-pad minus */ #define K_PSTAR K(KT_PAD,12) /* key-pad asterisk (star) */ #define K_PSLASH K(KT_PAD,13) /* key-pad slash */ #define K_PENTER K(KT_PAD,14) /* key-pad enter */ #define K_PCOMMA K(KT_PAD,15) /* key-pad comma: kludge... */ #define K_PDOT K(KT_PAD,16) /* key-pad dot (period): kludge... */ #define K_PPLUSMINUS K(KT_PAD,17) /* key-pad plus/minus */ #define K_PPARENL K(KT_PAD,18) /* key-pad left parenthesis */ #define K_PPARENR K(KT_PAD,19) /* key-pad right parenthesis */ #define NR_PAD 20 #define K_DGRAVE K(KT_DEAD,0) #define K_DACUTE K(KT_DEAD,1) #define K_DCIRCM K(KT_DEAD,2) #define K_DTILDE K(KT_DEAD,3) #define K_DDIERE K(KT_DEAD,4) #define K_DCEDIL K(KT_DEAD,5) #define NR_DEAD 6 #define K_DOWN K(KT_CUR,0) #define K_LEFT K(KT_CUR,1) #define K_RIGHT K(KT_CUR,2) #define K_UP K(KT_CUR,3) #define K_SHIFT K(KT_SHIFT,KG_SHIFT) #define K_CTRL K(KT_SHIFT,KG_CTRL) #define K_ALT K(KT_SHIFT,KG_ALT) #define K_ALTGR K(KT_SHIFT,KG_ALTGR) #define K_SHIFTL K(KT_SHIFT,KG_SHIFTL) #define K_SHIFTR K(KT_SHIFT,KG_SHIFTR) #define K_CTRLL K(KT_SHIFT,KG_CTRLL) #define K_CTRLR K(KT_SHIFT,KG_CTRLR) #define K_CAPSSHIFT K(KT_SHIFT,KG_CAPSSHIFT) #define K_ASC0 K(KT_ASCII,0) #define K_ASC1 K(KT_ASCII,1) #define K_ASC2 K(KT_ASCII,2) #define K_ASC3 K(KT_ASCII,3) #define K_ASC4 K(KT_ASCII,4) #define K_ASC5 K(KT_ASCII,5) #define K_ASC6 K(KT_ASCII,6) #define K_ASC7 K(KT_ASCII,7) #define K_ASC8 K(KT_ASCII,8) #define K_ASC9 K(KT_ASCII,9) #define K_HEX0 K(KT_ASCII,10) #define K_HEX1 K(KT_ASCII,11) #define K_HEX2 K(KT_ASCII,12) #define K_HEX3 K(KT_ASCII,13) #define K_HEX4 K(KT_ASCII,14) #define K_HEX5 K(KT_ASCII,15) #define K_HEX6 K(KT_ASCII,16) #define K_HEX7 K(KT_ASCII,17) #define K_HEX8 K(KT_ASCII,18) #define K_HEX9 K(KT_ASCII,19) #define K_HEXa K(KT_ASCII,20) #define K_HEXb K(KT_ASCII,21) #define K_HEXc K(KT_ASCII,22) #define K_HEXd K(KT_ASCII,23) #define K_HEXe K(KT_ASCII,24) #define K_HEXf K(KT_ASCII,25) #define NR_ASCII 26 #define K_SHIFTLOCK K(KT_LOCK,KG_SHIFT) #define K_CTRLLOCK K(KT_LOCK,KG_CTRL) #define K_ALTLOCK K(KT_LOCK,KG_ALT) #define K_ALTGRLOCK K(KT_LOCK,KG_ALTGR) #define K_SHIFTLLOCK K(KT_LOCK,KG_SHIFTL) #define K_SHIFTRLOCK K(KT_LOCK,KG_SHIFTR) #define K_CTRLLLOCK K(KT_LOCK,KG_CTRLL) #define K_CTRLRLOCK K(KT_LOCK,KG_CTRLR) #define K_CAPSSHIFTLOCK K(KT_LOCK,KG_CAPSSHIFT) #define K_SHIFT_SLOCK K(KT_SLOCK,KG_SHIFT) #define K_CTRL_SLOCK K(KT_SLOCK,KG_CTRL) #define K_ALT_SLOCK K(KT_SLOCK,KG_ALT) #define K_ALTGR_SLOCK K(KT_SLOCK,KG_ALTGR) #define K_SHIFTL_SLOCK K(KT_SLOCK,KG_SHIFTL) #define K_SHIFTR_SLOCK K(KT_SLOCK,KG_SHIFTR) #define K_CTRLL_SLOCK K(KT_SLOCK,KG_CTRLL) #define K_CTRLR_SLOCK K(KT_SLOCK,KG_CTRLR) #define K_CAPSSHIFT_SLOCK K(KT_SLOCK,KG_CAPSSHIFT) #define NR_LOCK 9 #define K_BRL_BLANK K(KT_BRL, 0) #define K_BRL_DOT1 K(KT_BRL, 1) #define K_BRL_DOT2 K(KT_BRL, 2) #define K_BRL_DOT3 K(KT_BRL, 3) #define K_BRL_DOT4 K(KT_BRL, 4) #define K_BRL_DOT5 K(KT_BRL, 5) #define K_BRL_DOT6 K(KT_BRL, 6) #define K_BRL_DOT7 K(KT_BRL, 7) #define K_BRL_DOT8 K(KT_BRL, 8) #define K_BRL_DOT9 K(KT_BRL, 9) #define K_BRL_DOT10 K(KT_BRL, 10) #define NR_BRL 11 #define MAX_DIACR 256 #endif dietlibc-0.33~cvs20120325/include/linux/loop.h010064400000000000000000000022601173363226500156120ustar00#ifndef _LINUX_LOOP_H #define _LINUX_LOOP_H #include __BEGIN_DECLS /* stolen form kernel */ #define LO_NAME_SIZE 64 #define LO_KEY_SIZE 32 /* Loop flags */ #define LO_FLAGS_DO_BMAP 1 #define LO_FLAGS_READ_ONLY 2 #define LO_FLAGS_BH_REMAP 4 struct loop_info { int lo_number; /* ioctl r/o */ dev_t lo_device; /* ioctl r/o */ unsigned long lo_inode; /* ioctl r/o */ dev_t lo_rdevice; /* ioctl r/o */ int lo_offset; int lo_encrypt_type; int lo_encrypt_key_size; /* ioctl w/o */ int lo_flags; /* ioctl r/o */ char lo_name[LO_NAME_SIZE]; unsigned char lo_encrypt_key[LO_KEY_SIZE]; /* ioctl w/o */ unsigned long lo_init[2]; char reserved[4]; }; /* Loop filter types */ #define LO_CRYPT_NONE 0 #define LO_CRYPT_XOR 1 #define LO_CRYPT_DES 2 #define LO_CRYPT_FISH2 3 /* Brand new Twofish encryption */ #define LO_CRYPT_BLOW 4 #define LO_CRYPT_CAST128 5 #define LO_CRYPT_IDEA 6 #define LO_CRYPT_DUMMY 9 #define LO_CRYPT_SKIPJACK 10 #define MAX_LO_CRYPT 20 /* IOCTL commands --- we will commandeer 0x4C ('L') */ #define LOOP_SET_FD 0x4C00 #define LOOP_CLR_FD 0x4C01 #define LOOP_SET_STATUS 0x4C02 #define LOOP_GET_STATUS 0x4C03 __END_DECLS #endif dietlibc-0.33~cvs20120325/include/linux/nfs.h010064400000000000000000000047571173363226500154440ustar00/* * NFS protocol definitions * * This file contains constants mostly for Version 2 of the protocol, * but also has a couple of NFSv3 bits in (notably the error codes). */ #ifndef _LINUX_NFS_H #define _LINUX_NFS_H #include __BEGIN_DECLS #define NFS_PROGRAM 100003 #define NFS_PORT 2049 #define NFS_MAXDATA 8192 #define NFS_MAXPATHLEN 1024 #define NFS_MAXNAMLEN 255 #define NFS_MAXGROUPS 16 #define NFS_FHSIZE 32 #define NFS_COOKIESIZE 4 #define NFS_FIFO_DEV (-1) #define NFSMODE_FMT 0170000 #define NFSMODE_DIR 0040000 #define NFSMODE_CHR 0020000 #define NFSMODE_BLK 0060000 #define NFSMODE_REG 0100000 #define NFSMODE_LNK 0120000 #define NFSMODE_SOCK 0140000 #define NFSMODE_FIFO 0010000 #define NFS_MNT_PROGRAM 100005 #define NFS_MNT_PORT 627 /* * NFS stats. The good thing with these values is that NFSv3 errors are * a superset of NFSv2 errors (with the exception of NFSERR_WFLUSH which * no-one uses anyway), so we can happily mix code as long as we make sure * no NFSv3 errors are returned to NFSv2 clients. * Error codes that have a `--' in the v2 column are not part of the * standard, but seem to be widely used nevertheless. */ enum nfs_stat { NFS_OK = 0, /* v2 v3 */ NFSERR_PERM = 1, /* v2 v3 */ NFSERR_NOENT = 2, /* v2 v3 */ NFSERR_IO = 5, /* v2 v3 */ NFSERR_NXIO = 6, /* v2 v3 */ NFSERR_EAGAIN = 11, /* v2 v3 */ NFSERR_ACCES = 13, /* v2 v3 */ NFSERR_EXIST = 17, /* v2 v3 */ NFSERR_XDEV = 18, /* v3 */ NFSERR_NODEV = 19, /* v2 v3 */ NFSERR_NOTDIR = 20, /* v2 v3 */ NFSERR_ISDIR = 21, /* v2 v3 */ NFSERR_INVAL = 22, /* v2 v3 that Sun forgot */ NFSERR_FBIG = 27, /* v2 v3 */ NFSERR_NOSPC = 28, /* v2 v3 */ NFSERR_ROFS = 30, /* v2 v3 */ NFSERR_MLINK = 31, /* v3 */ NFSERR_OPNOTSUPP = 45, /* v2 v3 */ NFSERR_NAMETOOLONG = 63, /* v2 v3 */ NFSERR_NOTEMPTY = 66, /* v2 v3 */ NFSERR_DQUOT = 69, /* v2 v3 */ NFSERR_STALE = 70, /* v2 v3 */ NFSERR_REMOTE = 71, /* v2 v3 */ NFSERR_WFLUSH = 99, /* v2 */ NFSERR_BADHANDLE = 10001, /* v3 */ NFSERR_NOT_SYNC = 10002, /* v3 */ NFSERR_BAD_COOKIE = 10003, /* v3 */ NFSERR_NOTSUPP = 10004, /* v3 */ NFSERR_TOOSMALL = 10005, /* v3 */ NFSERR_SERVERFAULT = 10006, /* v3 */ NFSERR_BADTYPE = 10007, /* v3 */ NFSERR_JUKEBOX = 10008 /* v3 */ }; /* NFSv2 file types - beware, these are not the same in NFSv3 */ enum nfs_ftype { NFNON = 0, NFREG = 1, NFDIR = 2, NFBLK = 3, NFCHR = 4, NFLNK = 5, NFSOCK = 6, NFBAD = 7, NFFIFO = 8 }; __END_DECLS #endif /* _LINUX_NFS_H */ dietlibc-0.33~cvs20120325/include/linux/soundcard.h010064400000000000000000001352121173363226500166270ustar00#ifndef SOUNDCARD_H #define SOUNDCARD_H /* * Copyright by Hannu Savolainen 1993-1997 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. 2. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * OSS interface version. With versions earlier than 3.6 this value is * an integer with value less than 361. In versions 3.6 and later * it's a six digit hexadecimal value. For example value * of 0x030600 represents OSS version 3.6.0. * Use ioctl(fd, OSS_GETVERSION, &int) to get the version number of * the currently active driver. */ #define SOUND_VERSION 0x030802 #define OPEN_SOUND_SYSTEM #include __BEGIN_DECLS /* In Linux we need to be prepared for cross compiling */ #include /* * Supported card ID numbers (Should be somewhere else?) */ #define SNDCARD_ADLIB 1 #define SNDCARD_SB 2 #define SNDCARD_PAS 3 #define SNDCARD_GUS 4 #define SNDCARD_MPU401 5 #define SNDCARD_SB16 6 #define SNDCARD_SB16MIDI 7 #define SNDCARD_UART6850 8 #define SNDCARD_GUS16 9 #define SNDCARD_MSS 10 #define SNDCARD_PSS 11 #define SNDCARD_SSCAPE 12 #define SNDCARD_PSS_MPU 13 #define SNDCARD_PSS_MSS 14 #define SNDCARD_SSCAPE_MSS 15 #define SNDCARD_TRXPRO 16 #define SNDCARD_TRXPRO_SB 17 #define SNDCARD_TRXPRO_MPU 18 #define SNDCARD_MAD16 19 #define SNDCARD_MAD16_MPU 20 #define SNDCARD_CS4232 21 #define SNDCARD_CS4232_MPU 22 #define SNDCARD_MAUI 23 #define SNDCARD_PSEUDO_MSS 24 #define SNDCARD_GUSPNP 25 #define SNDCARD_UART401 26 /* Sound card numbers 27 to N are reserved. Don't add more numbers here. */ /*********************************** * IOCTL Commands for /dev/sequencer */ #ifndef _SIOWR #if defined(_IOWR) && (defined(_AIX) || (!defined(sun) && !defined(sparc) && !defined(__sparc__) && !defined(__INCioctlh) && !defined(__Lynx__))) /* Use already defined ioctl defines if they exist (except with Sun or Sparc) */ #define SIOCPARM_MASK IOCPARM_MASK #define SIOC_VOID IOC_VOID #define SIOC_OUT IOC_OUT #define SIOC_IN IOC_IN #define SIOC_INOUT IOC_INOUT #define _SIOC_SIZE _IOC_SIZE #define _SIOC_DIR _IOC_DIR #define _SIOC_NONE _IOC_NONE #define _SIOC_READ _IOC_READ #define _SIOC_WRITE _IOC_WRITE #define _SIO _IO #define _SIOR _IOR #define _SIOW _IOW #define _SIOWR _IOWR #else /* Ioctl's have the command encoded in the lower word, * and the size of any in or out parameters in the upper * word. The high 2 bits of the upper word are used * to encode the in/out status of the parameter; for now * we restrict parameters to at most 8191 bytes. */ /* #define SIOCTYPE (0xff<<8) */ #define SIOCPARM_MASK 0x1fff /* parameters must be < 8192 bytes */ #define SIOC_VOID 0x00000000 /* no parameters */ #define SIOC_OUT 0x20000000 /* copy out parameters */ #define SIOC_IN 0x40000000 /* copy in parameters */ #define SIOC_INOUT (SIOC_IN|SIOC_OUT) /* the 0x20000000 is so we can distinguish new ioctl's from old */ #define _SIO(x,y) ((int)(SIOC_VOID|(x<<8)|y)) #define _SIOR(x,y,t) ((int)(SIOC_OUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y)) #define _SIOW(x,y,t) ((int)(SIOC_IN|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y)) /* this should be _SIORW, but stdio got there first */ #define _SIOWR(x,y,t) ((int)(SIOC_INOUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y)) #define _SIOC_SIZE(x) ((x>>16)&SIOCPARM_MASK) #define _SIOC_DIR(x) (x & 0xf0000000) #define _SIOC_NONE SIOC_VOID #define _SIOC_READ SIOC_OUT #define _SIOC_WRITE SIOC_IN # endif /* _IOWR */ #endif /* !_SIOWR */ #define SNDCTL_SEQ_RESET _SIO ('Q', 0) #define SNDCTL_SEQ_SYNC _SIO ('Q', 1) #define SNDCTL_SYNTH_INFO _SIOWR('Q', 2, struct synth_info) #define SNDCTL_SEQ_CTRLRATE _SIOWR('Q', 3, int) /* Set/get timer resolution (HZ) */ #define SNDCTL_SEQ_GETOUTCOUNT _SIOR ('Q', 4, int) #define SNDCTL_SEQ_GETINCOUNT _SIOR ('Q', 5, int) #define SNDCTL_SEQ_PERCMODE _SIOW ('Q', 6, int) #define SNDCTL_FM_LOAD_INSTR _SIOW ('Q', 7, struct sbi_instrument) /* Obsolete. Don't use!!!!!! */ #define SNDCTL_SEQ_TESTMIDI _SIOW ('Q', 8, int) #define SNDCTL_SEQ_RESETSAMPLES _SIOW ('Q', 9, int) #define SNDCTL_SEQ_NRSYNTHS _SIOR ('Q',10, int) #define SNDCTL_SEQ_NRMIDIS _SIOR ('Q',11, int) #define SNDCTL_MIDI_INFO _SIOWR('Q',12, struct midi_info) #define SNDCTL_SEQ_THRESHOLD _SIOW ('Q',13, int) #define SNDCTL_SYNTH_MEMAVL _SIOWR('Q',14, int) /* in=dev#, out=memsize */ #define SNDCTL_FM_4OP_ENABLE _SIOW ('Q',15, int) /* in=dev# */ #define SNDCTL_SEQ_PANIC _SIO ('Q',17) #define SNDCTL_SEQ_OUTOFBAND _SIOW ('Q',18, struct seq_event_rec) #define SNDCTL_SEQ_GETTIME _SIOR ('Q',19, int) #define SNDCTL_SYNTH_ID _SIOWR('Q',20, struct synth_info) #define SNDCTL_SYNTH_CONTROL _SIOWR('Q',21, struct synth_control) #define SNDCTL_SYNTH_REMOVESAMPLE _SIOWR('Q',22, struct remove_sample) typedef struct synth_control { int devno; /* Synthesizer # */ char data[4000]; /* Device spesific command/data record */ }synth_control; typedef struct remove_sample { int devno; /* Synthesizer # */ int bankno; /* MIDI bank # (0=General MIDI) */ int instrno; /* MIDI instrument number */ } remove_sample; typedef struct seq_event_rec { unsigned char arr[8]; } seq_event_rec; #define SNDCTL_TMR_TIMEBASE _SIOWR('T', 1, int) #define SNDCTL_TMR_START _SIO ('T', 2) #define SNDCTL_TMR_STOP _SIO ('T', 3) #define SNDCTL_TMR_CONTINUE _SIO ('T', 4) #define SNDCTL_TMR_TEMPO _SIOWR('T', 5, int) #define SNDCTL_TMR_SOURCE _SIOWR('T', 6, int) # define TMR_INTERNAL 0x00000001 # define TMR_EXTERNAL 0x00000002 # define TMR_MODE_MIDI 0x00000010 # define TMR_MODE_FSK 0x00000020 # define TMR_MODE_CLS 0x00000040 # define TMR_MODE_SMPTE 0x00000080 #define SNDCTL_TMR_METRONOME _SIOW ('T', 7, int) #define SNDCTL_TMR_SELECT _SIOW ('T', 8, int) /* * Some big endian/little endian handling macros */ #if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__sparc__) || defined(HPPA) || defined(PPC) || defined(__mc68000__) /* Big endian machines */ # define _PATCHKEY(id) (0xfd00|id) # define AFMT_S16_NE AFMT_S16_BE #else # define _PATCHKEY(id) ((id<<8)|0xfd) # define AFMT_S16_NE AFMT_S16_LE #endif /* * Sample loading mechanism for internal synthesizers (/dev/sequencer) * The following patch_info structure has been designed to support * Gravis UltraSound. It tries to be universal format for uploading * sample based patches but is probably too limited. * * (PBD) As Hannu guessed, the GUS structure is too limited for * the WaveFront, but this is the right place for a constant definition. */ struct patch_info { unsigned short key; /* Use WAVE_PATCH here */ #define WAVE_PATCH _PATCHKEY(0x04) #define GUS_PATCH WAVE_PATCH #define WAVEFRONT_PATCH _PATCHKEY(0x06) short device_no; /* Synthesizer number */ short instr_no; /* Midi pgm# */ unsigned int mode; /* * The least significant byte has the same format than the GUS .PAT * files */ #define WAVE_16_BITS 0x01 /* bit 0 = 8 or 16 bit wave data. */ #define WAVE_UNSIGNED 0x02 /* bit 1 = Signed - Unsigned data. */ #define WAVE_LOOPING 0x04 /* bit 2 = looping enabled-1. */ #define WAVE_BIDIR_LOOP 0x08 /* bit 3 = Set is bidirectional looping. */ #define WAVE_LOOP_BACK 0x10 /* bit 4 = Set is looping backward. */ #define WAVE_SUSTAIN_ON 0x20 /* bit 5 = Turn sustaining on. (Env. pts. 3)*/ #define WAVE_ENVELOPES 0x40 /* bit 6 = Enable envelopes - 1 */ #define WAVE_FAST_RELEASE 0x80 /* bit 7 = Shut off immediately after note off */ /* (use the env_rate/env_offs fields). */ /* Linux specific bits */ #define WAVE_VIBRATO 0x00010000 /* The vibrato info is valid */ #define WAVE_TREMOLO 0x00020000 /* The tremolo info is valid */ #define WAVE_SCALE 0x00040000 /* The scaling info is valid */ #define WAVE_FRACTIONS 0x00080000 /* Fraction information is valid */ /* Reserved bits */ #define WAVE_ROM 0x40000000 /* For future use */ #define WAVE_MULAW 0x20000000 /* For future use */ /* Other bits must be zeroed */ int len; /* Size of the wave data in bytes */ int loop_start, loop_end; /* Byte offsets from the beginning */ /* * The base_freq and base_note fields are used when computing the * playback speed for a note. The base_note defines the tone frequency * which is heard if the sample is played using the base_freq as the * playback speed. * * The low_note and high_note fields define the minimum and maximum note * frequencies for which this sample is valid. It is possible to define * more than one samples for an instrument number at the same time. The * low_note and high_note fields are used to select the most suitable one. * * The fields base_note, high_note and low_note should contain * the note frequency multiplied by 1000. For example value for the * middle A is 440*1000. */ unsigned int base_freq; unsigned int base_note; unsigned int high_note; unsigned int low_note; int panning; /* -128=left, 127=right */ int detuning; /* New fields introduced in version 1.99.5 */ /* Envelope. Enabled by mode bit WAVE_ENVELOPES */ unsigned char env_rate[ 6 ]; /* GUS HW ramping rate */ unsigned char env_offset[ 6 ]; /* 255 == 100% */ /* * The tremolo, vibrato and scale info are not supported yet. * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or * WAVE_SCALE */ unsigned char tremolo_sweep; unsigned char tremolo_rate; unsigned char tremolo_depth; unsigned char vibrato_sweep; unsigned char vibrato_rate; unsigned char vibrato_depth; int scale_frequency; unsigned int scale_factor; /* from 0 to 2048 or 0 to 2 */ int volume; int fractions; int reserved1; int spare[2]; char data[1]; /* The waveform data starts here */ }; struct sysex_info { short key; /* Use SYSEX_PATCH or MAUI_PATCH here */ #define SYSEX_PATCH _PATCHKEY(0x05) #define MAUI_PATCH _PATCHKEY(0x06) short device_no; /* Synthesizer number */ int len; /* Size of the sysex data in bytes */ unsigned char data[1]; /* Sysex data starts here */ }; /* * /dev/sequencer input events. * * The data written to the /dev/sequencer is a stream of events. Events * are records of 4 or 8 bytes. The first byte defines the size. * Any number of events can be written with a write call. There * is a set of macros for sending these events. Use these macros if you * want to maximize portability of your program. * * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events. * (All input events are currently 4 bytes long. Be prepared to support * 8 byte events also. If you receive any event having first byte >= 128, * it's a 8 byte event. * * The events are documented at the end of this file. * * Normal events (4 bytes) * There is also a 8 byte version of most of the 4 byte events. The * 8 byte one is recommended. */ #define SEQ_NOTEOFF 0 #define SEQ_FMNOTEOFF SEQ_NOTEOFF /* Just old name */ #define SEQ_NOTEON 1 #define SEQ_FMNOTEON SEQ_NOTEON #define SEQ_WAIT TMR_WAIT_ABS #define SEQ_PGMCHANGE 3 #define SEQ_FMPGMCHANGE SEQ_PGMCHANGE #define SEQ_SYNCTIMER TMR_START #define SEQ_MIDIPUTC 5 #define SEQ_DRUMON 6 /*** OBSOLETE ***/ #define SEQ_DRUMOFF 7 /*** OBSOLETE ***/ #define SEQ_ECHO TMR_ECHO /* For synching programs with output */ #define SEQ_AFTERTOUCH 9 #define SEQ_CONTROLLER 10 /******************************************* * Midi controller numbers ******************************************* * Controllers 0 to 31 (0x00 to 0x1f) and * 32 to 63 (0x20 to 0x3f) are continuous * controllers. * In the MIDI 1.0 these controllers are sent using * two messages. Controller numbers 0 to 31 are used * to send the MSB and the controller numbers 32 to 63 * are for the LSB. Note that just 7 bits are used in MIDI bytes. */ #define CTL_BANK_SELECT 0x00 #define CTL_MODWHEEL 0x01 #define CTL_BREATH 0x02 /* undefined 0x03 */ #define CTL_FOOT 0x04 #define CTL_PORTAMENTO_TIME 0x05 #define CTL_DATA_ENTRY 0x06 #define CTL_MAIN_VOLUME 0x07 #define CTL_BALANCE 0x08 /* undefined 0x09 */ #define CTL_PAN 0x0a #define CTL_EXPRESSION 0x0b /* undefined 0x0c */ /* undefined 0x0d */ /* undefined 0x0e */ /* undefined 0x0f */ #define CTL_GENERAL_PURPOSE1 0x10 #define CTL_GENERAL_PURPOSE2 0x11 #define CTL_GENERAL_PURPOSE3 0x12 #define CTL_GENERAL_PURPOSE4 0x13 /* undefined 0x14 - 0x1f */ /* undefined 0x20 */ /* The controller numbers 0x21 to 0x3f are reserved for the */ /* least significant bytes of the controllers 0x00 to 0x1f. */ /* These controllers are not recognised by the driver. */ /* Controllers 64 to 69 (0x40 to 0x45) are on/off switches. */ /* 0=OFF and 127=ON (intermediate values are possible) */ #define CTL_DAMPER_PEDAL 0x40 #define CTL_SUSTAIN 0x40 /* Alias */ #define CTL_HOLD 0x40 /* Alias */ #define CTL_PORTAMENTO 0x41 #define CTL_SOSTENUTO 0x42 #define CTL_SOFT_PEDAL 0x43 /* undefined 0x44 */ #define CTL_HOLD2 0x45 /* undefined 0x46 - 0x4f */ #define CTL_GENERAL_PURPOSE5 0x50 #define CTL_GENERAL_PURPOSE6 0x51 #define CTL_GENERAL_PURPOSE7 0x52 #define CTL_GENERAL_PURPOSE8 0x53 /* undefined 0x54 - 0x5a */ #define CTL_EXT_EFF_DEPTH 0x5b #define CTL_TREMOLO_DEPTH 0x5c #define CTL_CHORUS_DEPTH 0x5d #define CTL_DETUNE_DEPTH 0x5e #define CTL_CELESTE_DEPTH 0x5e /* Alias for the above one */ #define CTL_PHASER_DEPTH 0x5f #define CTL_DATA_INCREMENT 0x60 #define CTL_DATA_DECREMENT 0x61 #define CTL_NONREG_PARM_NUM_LSB 0x62 #define CTL_NONREG_PARM_NUM_MSB 0x63 #define CTL_REGIST_PARM_NUM_LSB 0x64 #define CTL_REGIST_PARM_NUM_MSB 0x65 /* undefined 0x66 - 0x78 */ /* reserved 0x79 - 0x7f */ /* Pseudo controllers (not midi compatible) */ #define CTRL_PITCH_BENDER 255 #define CTRL_PITCH_BENDER_RANGE 254 #define CTRL_EXPRESSION 253 /* Obsolete */ #define CTRL_MAIN_VOLUME 252 /* Obsolete */ #define SEQ_BALANCE 11 #define SEQ_VOLMODE 12 /* * Volume mode decides how volumes are used */ #define VOL_METHOD_ADAGIO 1 #define VOL_METHOD_LINEAR 2 /* * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as * input events. */ /* * Event codes 0xf0 to 0xfc are reserved for future extensions. */ #define SEQ_FULLSIZE 0xfd /* Long events */ /* * SEQ_FULLSIZE events are used for loading patches/samples to the * synthesizer devices. These events are passed directly to the driver * of the associated synthesizer device. There is no limit to the size * of the extended events. These events are not queued but executed * immediately when the write() is called (execution can take several * seconds of time). * * When a SEQ_FULLSIZE message is written to the device, it must * be written using exactly one write() call. Other events cannot * be mixed to the same write. * * For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the * /dev/sequencer. Don't write other data together with the instrument structure * Set the key field of the structure to FM_PATCH. The device field is used to * route the patch to the corresponding device. * * For wave table use struct patch_info. Initialize the key field * to WAVE_PATCH. */ #define SEQ_PRIVATE 0xfe /* Low level HW dependent events (8 bytes) */ #define SEQ_EXTENDED 0xff /* Extended events (8 bytes) OBSOLETE */ /* * Record for FM patches */ typedef unsigned char sbi_instr_data[32]; struct sbi_instrument { unsigned short key; /* FM_PATCH or OPL3_PATCH */ #define FM_PATCH _PATCHKEY(0x01) #define OPL3_PATCH _PATCHKEY(0x03) short device; /* Synth# (0-4) */ int channel; /* Program# to be initialized */ sbi_instr_data operators; /* Register settings for operator cells (.SBI format) */ }; struct synth_info { /* Read only */ char name[30]; int device; /* 0-N. INITIALIZE BEFORE CALLING */ int synth_type; #define SYNTH_TYPE_FM 0 #define SYNTH_TYPE_SAMPLE 1 #define SYNTH_TYPE_MIDI 2 /* Midi interface */ int synth_subtype; #define FM_TYPE_ADLIB 0x00 #define FM_TYPE_OPL3 0x01 #define MIDI_TYPE_MPU401 0x401 #define SAMPLE_TYPE_BASIC 0x10 #define SAMPLE_TYPE_GUS SAMPLE_TYPE_BASIC #define SAMPLE_TYPE_WAVEFRONT 0x11 int perc_mode; /* No longer supported */ int nr_voices; int nr_drums; /* Obsolete field */ int instr_bank_size; unsigned int capabilities; #define SYNTH_CAP_PERCMODE 0x00000001 /* No longer used */ #define SYNTH_CAP_OPL3 0x00000002 /* Set if OPL3 supported */ #define SYNTH_CAP_INPUT 0x00000004 /* Input (MIDI) device */ int dummies[19]; /* Reserve space */ }; struct sound_timer_info { char name[32]; int caps; }; #define MIDI_CAP_MPU401 1 /* MPU-401 intelligent mode */ struct midi_info { char name[30]; int device; /* 0-N. INITIALIZE BEFORE CALLING */ unsigned int capabilities; /* To be defined later */ int dev_type; int dummies[18]; /* Reserve space */ }; /******************************************** * ioctl commands for the /dev/midi## */ typedef struct { unsigned char cmd; char nr_args, nr_returns; unsigned char data[30]; } mpu_command_rec; #define SNDCTL_MIDI_PRETIME _SIOWR('m', 0, int) #define SNDCTL_MIDI_MPUMODE _SIOWR('m', 1, int) #define SNDCTL_MIDI_MPUCMD _SIOWR('m', 2, mpu_command_rec) /******************************************** * IOCTL commands for /dev/dsp and /dev/audio */ #define SNDCTL_DSP_RESET _SIO ('P', 0) #define SNDCTL_DSP_SYNC _SIO ('P', 1) #define SNDCTL_DSP_SPEED _SIOWR('P', 2, int) #define SNDCTL_DSP_STEREO _SIOWR('P', 3, int) #define SNDCTL_DSP_GETBLKSIZE _SIOWR('P', 4, int) #define SNDCTL_DSP_SAMPLESIZE SNDCTL_DSP_SETFMT #define SNDCTL_DSP_CHANNELS _SIOWR('P', 6, int) #define SOUND_PCM_WRITE_CHANNELS SNDCTL_DSP_CHANNELS #define SOUND_PCM_WRITE_FILTER _SIOWR('P', 7, int) #define SNDCTL_DSP_POST _SIO ('P', 8) #define SNDCTL_DSP_SUBDIVIDE _SIOWR('P', 9, int) #define SNDCTL_DSP_SETFRAGMENT _SIOWR('P',10, int) /* Audio data formats (Note! U8=8 and S16_LE=16 for compatibility) */ #define SNDCTL_DSP_GETFMTS _SIOR ('P',11, int) /* Returns a mask */ #define SNDCTL_DSP_SETFMT _SIOWR('P',5, int) /* Selects ONE fmt*/ # define AFMT_QUERY 0x00000000 /* Return current fmt */ # define AFMT_MU_LAW 0x00000001 # define AFMT_A_LAW 0x00000002 # define AFMT_IMA_ADPCM 0x00000004 # define AFMT_U8 0x00000008 # define AFMT_S16_LE 0x00000010 /* Little endian signed 16*/ # define AFMT_S16_BE 0x00000020 /* Big endian signed 16 */ # define AFMT_S8 0x00000040 # define AFMT_U16_LE 0x00000080 /* Little endian U16 */ # define AFMT_U16_BE 0x00000100 /* Big endian U16 */ # define AFMT_MPEG 0x00000200 /* MPEG (2) audio */ # define AFMT_AC3 0x00000400 /* Dolby Digital AC3 */ /* because they *do* exist and we want to use them --Monty */ # define AFMT_S24_LE 0x00000800 # define AFMT_S24_BE 0x00001000 # define AFMT_U24_LE 0x00002000 # define AFMT_U24_BE 0x00004000 # define AFMT_S32_LE 0x00008000 # define AFMT_S32_BE 0x00010000 # define AFMT_U32_LE 0x00020000 # define AFMT_U32_BE 0x00040000 /* * Buffer status queries. */ typedef struct audio_buf_info { int fragments; /* # of available fragments (partially usend ones not counted) */ int fragstotal; /* Total # of fragments allocated */ int fragsize; /* Size of a fragment in bytes */ int bytes; /* Available space in bytes (includes partially used fragments) */ /* Note! 'bytes' could be more than fragments*fragsize */ } audio_buf_info; #define SNDCTL_DSP_GETOSPACE _SIOR ('P',12, audio_buf_info) #define SNDCTL_DSP_GETISPACE _SIOR ('P',13, audio_buf_info) #define SNDCTL_DSP_NONBLOCK _SIO ('P',14) #define SNDCTL_DSP_GETCAPS _SIOR ('P',15, int) # define DSP_CAP_REVISION 0x000000ff /* Bits for revision level (0 to 255) */ # define DSP_CAP_DUPLEX 0x00000100 /* Full duplex record/playback */ # define DSP_CAP_REALTIME 0x00000200 /* Real time capability */ # define DSP_CAP_BATCH 0x00000400 /* Device has some kind of */ /* internal buffers which may */ /* cause some delays and */ /* decrease precision of timing */ # define DSP_CAP_COPROC 0x00000800 /* Has a coprocessor */ /* Sometimes it's a DSP */ /* but usually not */ # define DSP_CAP_TRIGGER 0x00001000 /* Supports SETTRIGGER */ # define DSP_CAP_MMAP 0x00002000 /* Supports mmap() */ # define DSP_CAP_MULTI 0x00004000 /* support multiple open */ # define DSP_CAP_BIND 0x00008000 /* channel binding to front/rear/cneter/lfe */ #define SNDCTL_DSP_GETTRIGGER _SIOR ('P',16, int) #define SNDCTL_DSP_SETTRIGGER _SIOW ('P',16, int) # define PCM_ENABLE_INPUT 0x00000001 # define PCM_ENABLE_OUTPUT 0x00000002 typedef struct count_info { int bytes; /* Total # of bytes processed */ int blocks; /* # of fragment transitions since last time */ int ptr; /* Current DMA pointer value */ } count_info; #define SNDCTL_DSP_GETIPTR _SIOR ('P',17, count_info) #define SNDCTL_DSP_GETOPTR _SIOR ('P',18, count_info) typedef struct buffmem_desc { unsigned *buffer; int size; } buffmem_desc; #define SNDCTL_DSP_MAPINBUF _SIOR ('P', 19, buffmem_desc) #define SNDCTL_DSP_MAPOUTBUF _SIOR ('P', 20, buffmem_desc) #define SNDCTL_DSP_SETSYNCRO _SIO ('P', 21) #define SNDCTL_DSP_SETDUPLEX _SIO ('P', 22) #define SNDCTL_DSP_GETODELAY _SIOR ('P', 23, int) #define SNDCTL_DSP_GETCHANNELMASK _SIOWR('P', 64, int) #define SNDCTL_DSP_BIND_CHANNEL _SIOWR('P', 65, int) # define DSP_BIND_QUERY 0x00000000 # define DSP_BIND_FRONT 0x00000001 # define DSP_BIND_SURR 0x00000002 # define DSP_BIND_CENTER_LFE 0x00000004 # define DSP_BIND_HANDSET 0x00000008 # define DSP_BIND_MIC 0x00000010 # define DSP_BIND_MODEM1 0x00000020 # define DSP_BIND_MODEM2 0x00000040 # define DSP_BIND_I2S 0x00000080 # define DSP_BIND_SPDIF 0x00000100 #define SNDCTL_DSP_SETSPDIF _SIOW ('P', 66, int) #define SNDCTL_DSP_GETSPDIF _SIOR ('P', 67, int) # define SPDIF_PRO 0x0001 # define SPDIF_N_AUD 0x0002 # define SPDIF_COPY 0x0004 # define SPDIF_PRE 0x0008 # define SPDIF_CC 0x07f0 # define SPDIF_L 0x0800 # define SPDIF_DRS 0x4000 # define SPDIF_V 0x8000 /* * Application's profile defines the way how playback underrun situations should be handled. * * APF_NORMAL (the default) and APF_NETWORK make the driver to cleanup the * playback buffer whenever an underrun occurs. This consumes some time * prevents looping the existing buffer. * APF_CPUINTENS is intended to be set by CPU intensive applications which * are likely to run out of time occasionally. In this mode the buffer cleanup is * disabled which saves CPU time but also let's the previous buffer content to * be played during the "pause" after the underrun. */ #define SNDCTL_DSP_PROFILE _SIOW ('P', 23, int) #define APF_NORMAL 0 /* Normal applications */ #define APF_NETWORK 1 /* Underruns probably caused by an "external" delay */ #define APF_CPUINTENS 2 /* Underruns probably caused by "overheating" the CPU */ #define SOUND_PCM_READ_RATE _SIOR ('P', 2, int) #define SOUND_PCM_READ_CHANNELS _SIOR ('P', 6, int) #define SOUND_PCM_READ_BITS _SIOR ('P', 5, int) #define SOUND_PCM_READ_FILTER _SIOR ('P', 7, int) /* Some alias names */ #define SOUND_PCM_WRITE_BITS SNDCTL_DSP_SETFMT #define SOUND_PCM_WRITE_RATE SNDCTL_DSP_SPEED #define SOUND_PCM_POST SNDCTL_DSP_POST #define SOUND_PCM_RESET SNDCTL_DSP_RESET #define SOUND_PCM_SYNC SNDCTL_DSP_SYNC #define SOUND_PCM_SUBDIVIDE SNDCTL_DSP_SUBDIVIDE #define SOUND_PCM_SETFRAGMENT SNDCTL_DSP_SETFRAGMENT #define SOUND_PCM_GETFMTS SNDCTL_DSP_GETFMTS #define SOUND_PCM_SETFMT SNDCTL_DSP_SETFMT #define SOUND_PCM_GETOSPACE SNDCTL_DSP_GETOSPACE #define SOUND_PCM_GETISPACE SNDCTL_DSP_GETISPACE #define SOUND_PCM_NONBLOCK SNDCTL_DSP_NONBLOCK #define SOUND_PCM_GETCAPS SNDCTL_DSP_GETCAPS #define SOUND_PCM_GETTRIGGER SNDCTL_DSP_GETTRIGGER #define SOUND_PCM_SETTRIGGER SNDCTL_DSP_SETTRIGGER #define SOUND_PCM_SETSYNCRO SNDCTL_DSP_SETSYNCRO #define SOUND_PCM_GETIPTR SNDCTL_DSP_GETIPTR #define SOUND_PCM_GETOPTR SNDCTL_DSP_GETOPTR #define SOUND_PCM_MAPINBUF SNDCTL_DSP_MAPINBUF #define SOUND_PCM_MAPOUTBUF SNDCTL_DSP_MAPOUTBUF /* * ioctl calls to be used in communication with coprocessors and * DSP chips. */ typedef struct copr_buffer { int command; /* Set to 0 if not used */ int flags; #define CPF_NONE 0x0000 #define CPF_FIRST 0x0001 /* First block */ #define CPF_LAST 0x0002 /* Last block */ int len; int offs; /* If required by the device (0 if not used) */ unsigned char data[4000]; /* NOTE! 4000 is not 4k */ } copr_buffer; typedef struct copr_debug_buf { int command; /* Used internally. Set to 0 */ int parm1; int parm2; int flags; int len; /* Length of data in bytes */ } copr_debug_buf; typedef struct copr_msg { int len; unsigned char data[4000]; } copr_msg; #define SNDCTL_COPR_RESET _SIO ('C', 0) #define SNDCTL_COPR_LOAD _SIOWR('C', 1, copr_buffer) #define SNDCTL_COPR_RDATA _SIOWR('C', 2, copr_debug_buf) #define SNDCTL_COPR_RCODE _SIOWR('C', 3, copr_debug_buf) #define SNDCTL_COPR_WDATA _SIOW ('C', 4, copr_debug_buf) #define SNDCTL_COPR_WCODE _SIOW ('C', 5, copr_debug_buf) #define SNDCTL_COPR_RUN _SIOWR('C', 6, copr_debug_buf) #define SNDCTL_COPR_HALT _SIOWR('C', 7, copr_debug_buf) #define SNDCTL_COPR_SENDMSG _SIOWR('C', 8, copr_msg) #define SNDCTL_COPR_RCVMSG _SIOR ('C', 9, copr_msg) /********************************************* * IOCTL commands for /dev/mixer */ /* * Mixer devices * * There can be up to 20 different analog mixer channels. The * SOUND_MIXER_NRDEVICES gives the currently supported maximum. * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells * the devices supported by the particular mixer. */ #define SOUND_MIXER_NRDEVICES 25 #define SOUND_MIXER_VOLUME 0 #define SOUND_MIXER_BASS 1 #define SOUND_MIXER_TREBLE 2 #define SOUND_MIXER_SYNTH 3 #define SOUND_MIXER_PCM 4 #define SOUND_MIXER_SPEAKER 5 #define SOUND_MIXER_LINE 6 #define SOUND_MIXER_MIC 7 #define SOUND_MIXER_CD 8 #define SOUND_MIXER_IMIX 9 /* Recording monitor */ #define SOUND_MIXER_ALTPCM 10 #define SOUND_MIXER_RECLEV 11 /* Recording level */ #define SOUND_MIXER_IGAIN 12 /* Input gain */ #define SOUND_MIXER_OGAIN 13 /* Output gain */ /* * The AD1848 codec and compatibles have three line level inputs * (line, aux1 and aux2). Since each card manufacturer have assigned * different meanings to these inputs, it's inpractical to assign * specific meanings (line, cd, synth etc.) to them. */ #define SOUND_MIXER_LINE1 14 /* Input source 1 (aux1) */ #define SOUND_MIXER_LINE2 15 /* Input source 2 (aux2) */ #define SOUND_MIXER_LINE3 16 /* Input source 3 (line) */ #define SOUND_MIXER_DIGITAL1 17 /* Digital (input) 1 */ #define SOUND_MIXER_DIGITAL2 18 /* Digital (input) 2 */ #define SOUND_MIXER_DIGITAL3 19 /* Digital (input) 3 */ #define SOUND_MIXER_PHONEIN 20 /* Phone input */ #define SOUND_MIXER_PHONEOUT 21 /* Phone output */ #define SOUND_MIXER_VIDEO 22 /* Video/TV (audio) in */ #define SOUND_MIXER_RADIO 23 /* Radio in */ #define SOUND_MIXER_MONITOR 24 /* Monitor (usually mic) volume */ /* Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) */ /* Not counted to SOUND_MIXER_NRDEVICES, but use the same number space */ #define SOUND_ONOFF_MIN 28 #define SOUND_ONOFF_MAX 30 /* Note! Number 31 cannot be used since the sign bit is reserved */ #define SOUND_MIXER_NONE 31 /* * The following unsupported macros are no longer functional. * Use SOUND_MIXER_PRIVATE# macros in future. */ #define SOUND_MIXER_ENHANCE SOUND_MIXER_NONE #define SOUND_MIXER_MUTE SOUND_MIXER_NONE #define SOUND_MIXER_LOUD SOUND_MIXER_NONE #define SOUND_DEVICE_LABELS {"Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \ "Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \ "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \ "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"} #define SOUND_DEVICE_NAMES {"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \ "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \ "line1", "line2", "line3", "dig1", "dig2", "dig3", \ "phin", "phout", "video", "radio", "monitor"} /* Device bitmask identifiers */ #define SOUND_MIXER_RECSRC 0xff /* Arg contains a bit for each recording source */ #define SOUND_MIXER_DEVMASK 0xfe /* Arg contains a bit for each supported device */ #define SOUND_MIXER_RECMASK 0xfd /* Arg contains a bit for each supported recording source */ #define SOUND_MIXER_CAPS 0xfc # define SOUND_CAP_EXCL_INPUT 0x00000001 /* Only one recording source at a time */ #define SOUND_MIXER_STEREODEVS 0xfb /* Mixer channels supporting stereo */ #define SOUND_MIXER_OUTSRC 0xfa /* Arg contains a bit for each input source to output */ #define SOUND_MIXER_OUTMASK 0xf9 /* Arg contains a bit for each supported input source to output */ /* Device mask bits */ #define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME) #define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS) #define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE) #define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH) #define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM) #define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER) #define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE) #define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC) #define SOUND_MASK_CD (1 << SOUND_MIXER_CD) #define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX) #define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM) #define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV) #define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN) #define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN) #define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1) #define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2) #define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3) #define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1) #define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2) #define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3) #define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN) #define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT) #define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO) #define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO) #define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR) /* Obsolete macros */ #define SOUND_MASK_MUTE (1 << SOUND_MIXER_MUTE) #define SOUND_MASK_ENHANCE (1 << SOUND_MIXER_ENHANCE) #define SOUND_MASK_LOUD (1 << SOUND_MIXER_LOUD) #define MIXER_READ(dev) _SIOR('M', dev, int) #define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME) #define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS) #define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE) #define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH) #define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM) #define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER) #define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE) #define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC) #define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD) #define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX) #define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM) #define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV) #define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN) #define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN) #define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1) #define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2) #define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3) /* Obsolete macros */ #define SOUND_MIXER_READ_MUTE MIXER_READ(SOUND_MIXER_MUTE) #define SOUND_MIXER_READ_ENHANCE MIXER_READ(SOUND_MIXER_ENHANCE) #define SOUND_MIXER_READ_LOUD MIXER_READ(SOUND_MIXER_LOUD) #define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC) #define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK) #define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK) #define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS) #define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS) #define MIXER_WRITE(dev) _SIOWR('M', dev, int) #define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME) #define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS) #define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE) #define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH) #define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM) #define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER) #define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE) #define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC) #define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD) #define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX) #define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM) #define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV) #define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN) #define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN) #define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1) #define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2) #define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3) /* Obsolete macros */ #define SOUND_MIXER_WRITE_MUTE MIXER_WRITE(SOUND_MIXER_MUTE) #define SOUND_MIXER_WRITE_ENHANCE MIXER_WRITE(SOUND_MIXER_ENHANCE) #define SOUND_MIXER_WRITE_LOUD MIXER_WRITE(SOUND_MIXER_LOUD) #define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC) typedef struct mixer_info { char id[16]; char name[32]; int modify_counter; int fillers[10]; } mixer_info; typedef struct _old_mixer_info /* Obsolete */ { char id[16]; char name[32]; } _old_mixer_info; #define SOUND_MIXER_INFO _SIOR ('M', 101, mixer_info) #define SOUND_OLD_MIXER_INFO _SIOR ('M', 101, _old_mixer_info) /* * A mechanism for accessing "proprietary" mixer features. This method * permits passing 128 bytes of arbitrary data between a mixer application * and the mixer driver. Interpretation of the record is defined by * the particular mixer driver. */ typedef unsigned char mixer_record[128]; #define SOUND_MIXER_ACCESS _SIOWR('M', 102, mixer_record) /* * Two ioctls for special souncard function */ #define SOUND_MIXER_AGC _SIOWR('M', 103, int) #define SOUND_MIXER_3DSE _SIOWR('M', 104, int) /* * The SOUND_MIXER_PRIVATE# commands can be redefined by low level drivers. * These features can be used when accessing device specific features. */ #define SOUND_MIXER_PRIVATE1 _SIOWR('M', 111, int) #define SOUND_MIXER_PRIVATE2 _SIOWR('M', 112, int) #define SOUND_MIXER_PRIVATE3 _SIOWR('M', 113, int) #define SOUND_MIXER_PRIVATE4 _SIOWR('M', 114, int) #define SOUND_MIXER_PRIVATE5 _SIOWR('M', 115, int) /* * SOUND_MIXER_GETLEVELS and SOUND_MIXER_SETLEVELS calls can be used * for querying current mixer settings from the driver and for loading * default volume settings _prior_ activating the mixer (loading * doesn't affect current state of the mixer hardware). These calls * are for internal use only. */ typedef struct mixer_vol_table { int num; /* Index to volume table */ char name[32]; int levels[32]; } mixer_vol_table; #define SOUND_MIXER_GETLEVELS _SIOWR('M', 116, mixer_vol_table) #define SOUND_MIXER_SETLEVELS _SIOWR('M', 117, mixer_vol_table) /* * An ioctl for identifying the driver version. It will return value * of the SOUND_VERSION macro used when compiling the driver. * This call was introduced in OSS version 3.6 and it will not work * with earlier versions (returns EINVAL). */ #define OSS_GETVERSION _SIOR ('M', 118, int) /* * Level 2 event types for /dev/sequencer */ /* * The 4 most significant bits of byte 0 specify the class of * the event: * * 0x8X = system level events, * 0x9X = device/port specific events, event[1] = device/port, * The last 4 bits give the subtype: * 0x02 = Channel event (event[3] = chn). * 0x01 = note event (event[4] = note). * (0x01 is not used alone but always with bit 0x02). * event[2] = MIDI message code (0x80=note off etc.) * */ #define EV_SEQ_LOCAL 0x80 #define EV_TIMING 0x81 #define EV_CHN_COMMON 0x92 #define EV_CHN_VOICE 0x93 #define EV_SYSEX 0x94 /* * Event types 200 to 220 are reserved for application use. * These numbers will not be used by the driver. */ /* * Events for event type EV_CHN_VOICE */ #define MIDI_NOTEOFF 0x80 #define MIDI_NOTEON 0x90 #define MIDI_KEY_PRESSURE 0xA0 /* * Events for event type EV_CHN_COMMON */ #define MIDI_CTL_CHANGE 0xB0 #define MIDI_PGM_CHANGE 0xC0 #define MIDI_CHN_PRESSURE 0xD0 #define MIDI_PITCH_BEND 0xE0 #define MIDI_SYSTEM_PREFIX 0xF0 /* * Timer event types */ #define TMR_WAIT_REL 1 /* Time relative to the prev time */ #define TMR_WAIT_ABS 2 /* Absolute time since TMR_START */ #define TMR_STOP 3 #define TMR_START 4 #define TMR_CONTINUE 5 #define TMR_TEMPO 6 #define TMR_ECHO 8 #define TMR_CLOCK 9 /* MIDI clock */ #define TMR_SPP 10 /* Song position pointer */ #define TMR_TIMESIG 11 /* Time signature */ /* * Local event types */ #define LOCL_STARTAUDIO 1 #if (!defined(__KERNEL__) && !defined(KERNEL) && !defined(INKERNEL) && !defined(_KERNEL)) || defined(USE_SEQ_MACROS) /* * Some convenience macros to simplify programming of the * /dev/sequencer interface * * These macros define the API which should be used when possible. */ #define SEQ_DECLAREBUF() SEQ_USE_EXTBUF() void seqbuf_dump(void); /* This function must be provided by programs */ extern int OSS_init(int seqfd, int buflen); extern void OSS_seqbuf_dump(int fd, unsigned char *buf, int buflen); extern void OSS_seq_advbuf(int len, int fd, unsigned char *buf, int buflen); extern void OSS_seq_needbuf(int len, int fd, unsigned char *buf, int buflen); extern void OSS_patch_caching(int dev, int chn, int patch, int fd, unsigned char *buf, int buflen); extern void OSS_drum_caching(int dev, int chn, int patch, int fd, unsigned char *buf, int buflen); extern void OSS_write_patch(int fd, unsigned char *buf, int len); extern int OSS_write_patch2(int fd, unsigned char *buf, int len); #define SEQ_PM_DEFINES int __foo_bar___ #ifdef OSSLIB # define SEQ_USE_EXTBUF() \ extern unsigned char *_seqbuf; \ extern int _seqbuflen;extern int _seqbufptr # define SEQ_DEFINEBUF(len) SEQ_USE_EXTBUF();static int _requested_seqbuflen=len # define _SEQ_ADVBUF(len) OSS_seq_advbuf(len, seqfd, _seqbuf, _seqbuflen) # define _SEQ_NEEDBUF(len) OSS_seq_needbuf(len, seqfd, _seqbuf, _seqbuflen) # define SEQ_DUMPBUF() OSS_seqbuf_dump(seqfd, _seqbuf, _seqbuflen) # define SEQ_LOAD_GMINSTR(dev, instr) \ OSS_patch_caching(dev, -1, instr, seqfd, _seqbuf, _seqbuflen) # define SEQ_LOAD_GMDRUM(dev, drum) \ OSS_drum_caching(dev, -1, drum, seqfd, _seqbuf, _seqbuflen) #else /* !OSSLIB */ # define SEQ_LOAD_GMINSTR(dev, instr) # define SEQ_LOAD_GMDRUM(dev, drum) # define SEQ_USE_EXTBUF() \ extern unsigned char _seqbuf[]; \ extern int _seqbuflen;extern int _seqbufptr #ifndef USE_SIMPLE_MACROS /* Sample seqbuf_dump() implementation: * * SEQ_DEFINEBUF (2048); -- Defines a buffer for 2048 bytes * * int seqfd; -- The file descriptor for /dev/sequencer. * * void * seqbuf_dump () * { * if (_seqbufptr) * if (write (seqfd, _seqbuf, _seqbufptr) == -1) * { * perror ("write /dev/sequencer"); * exit (-1); * } * _seqbufptr = 0; * } */ #define SEQ_DEFINEBUF(len) unsigned char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0 #define _SEQ_NEEDBUF(len) if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump() #define _SEQ_ADVBUF(len) _seqbufptr += len #define SEQ_DUMPBUF seqbuf_dump #else /* * This variation of the sequencer macros is used just to format one event * using fixed buffer. * * The program using the macro library must define the following macros before * using this library. * * #define _seqbuf name of the buffer (unsigned char[]) * #define _SEQ_ADVBUF(len) If the applic needs to know the exact * size of the event, this macro can be used. * Otherwise this must be defined as empty. * #define _seqbufptr Define the name of index variable or 0 if * not required. */ #define _SEQ_NEEDBUF(len) /* empty */ #endif #endif /* !OSSLIB */ #define SEQ_VOLUME_MODE(dev, mode) {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = SEQ_EXTENDED;\ _seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\ _seqbuf[_seqbufptr+2] = (dev);\ _seqbuf[_seqbufptr+3] = (mode);\ _seqbuf[_seqbufptr+4] = 0;\ _seqbuf[_seqbufptr+5] = 0;\ _seqbuf[_seqbufptr+6] = 0;\ _seqbuf[_seqbufptr+7] = 0;\ _SEQ_ADVBUF(8);} /* * Midi voice messages */ #define _CHN_VOICE(dev, event, chn, note, parm) \ {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = EV_CHN_VOICE;\ _seqbuf[_seqbufptr+1] = (dev);\ _seqbuf[_seqbufptr+2] = (event);\ _seqbuf[_seqbufptr+3] = (chn);\ _seqbuf[_seqbufptr+4] = (note);\ _seqbuf[_seqbufptr+5] = (parm);\ _seqbuf[_seqbufptr+6] = (0);\ _seqbuf[_seqbufptr+7] = 0;\ _SEQ_ADVBUF(8);} #define SEQ_START_NOTE(dev, chn, note, vol) \ _CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol) #define SEQ_STOP_NOTE(dev, chn, note, vol) \ _CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol) #define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \ _CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure) /* * Midi channel messages */ #define _CHN_COMMON(dev, event, chn, p1, p2, w14) \ {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = EV_CHN_COMMON;\ _seqbuf[_seqbufptr+1] = (dev);\ _seqbuf[_seqbufptr+2] = (event);\ _seqbuf[_seqbufptr+3] = (chn);\ _seqbuf[_seqbufptr+4] = (p1);\ _seqbuf[_seqbufptr+5] = (p2);\ *(short *)&_seqbuf[_seqbufptr+6] = (w14);\ _SEQ_ADVBUF(8);} /* * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits * sending any MIDI bytes but it's absolutely not possible. Trying to do * so _will_ cause problems with MPU401 intelligent mode). * * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be * sent by calling SEQ_SYSEX() several times (there must be no other events * between them). First sysex fragment must have 0xf0 in the first byte * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte * between these sysex start and end markers cannot be larger than 0x7f. Also * lengths of each fragments (except the last one) must be 6. * * Breaking the above rules may work with some MIDI ports but is likely to * cause fatal problems with some other devices (such as MPU401). */ #define SEQ_SYSEX(dev, buf, len) \ {int ii, ll=(len); \ unsigned char *bufp=buf;\ if (ll>6)ll=6;\ _SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = EV_SYSEX;\ _seqbuf[_seqbufptr+1] = (dev);\ for(ii=0;ii>8)&0xff);\ _seqbuf[_seqbufptr+7] = 0;\ _SEQ_ADVBUF(8);} /* * The following 5 macros are incorrectly implemented and obsolete. * Use SEQ_BENDER and SEQ_CONTROL (with proper controller) instead. */ #define SEQ_PITCHBEND(dev, voice, value) SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER, value) #define SEQ_BENDER_RANGE(dev, voice, value) SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value) #define SEQ_EXPRESSION(dev, voice, value) SEQ_CONTROL(dev, voice, CTL_EXPRESSION, value*128) #define SEQ_MAIN_VOLUME(dev, voice, value) SEQ_CONTROL(dev, voice, CTL_MAIN_VOLUME, (value*16383)/100) #define SEQ_PANNING(dev, voice, pos) SEQ_CONTROL(dev, voice, CTL_PAN, (pos+128) / 2) /* * Timing and syncronization macros */ #define _TIMER_EVENT(ev, parm) {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr+0] = EV_TIMING; \ _seqbuf[_seqbufptr+1] = (ev); \ _seqbuf[_seqbufptr+2] = 0;\ _seqbuf[_seqbufptr+3] = 0;\ *(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \ _SEQ_ADVBUF(8);} #define SEQ_START_TIMER() _TIMER_EVENT(TMR_START, 0) #define SEQ_STOP_TIMER() _TIMER_EVENT(TMR_STOP, 0) #define SEQ_CONTINUE_TIMER() _TIMER_EVENT(TMR_CONTINUE, 0) #define SEQ_WAIT_TIME(ticks) _TIMER_EVENT(TMR_WAIT_ABS, ticks) #define SEQ_DELTA_TIME(ticks) _TIMER_EVENT(TMR_WAIT_REL, ticks) #define SEQ_ECHO_BACK(key) _TIMER_EVENT(TMR_ECHO, key) #define SEQ_SET_TEMPO(value) _TIMER_EVENT(TMR_TEMPO, value) #define SEQ_SONGPOS(pos) _TIMER_EVENT(TMR_SPP, pos) #define SEQ_TIME_SIGNATURE(sig) _TIMER_EVENT(TMR_TIMESIG, sig) /* * Local control events */ #define _LOCAL_EVENT(ev, parm) {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr+0] = EV_SEQ_LOCAL; \ _seqbuf[_seqbufptr+1] = (ev); \ _seqbuf[_seqbufptr+2] = 0;\ _seqbuf[_seqbufptr+3] = 0;\ *(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \ _SEQ_ADVBUF(8);} #define SEQ_PLAYAUDIO(devmask) _LOCAL_EVENT(LOCL_STARTAUDIO, devmask) /* * Events for the level 1 interface only */ #define SEQ_MIDIOUT(device, byte) {_SEQ_NEEDBUF(4);\ _seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\ _seqbuf[_seqbufptr+1] = (byte);\ _seqbuf[_seqbufptr+2] = (device);\ _seqbuf[_seqbufptr+3] = 0;\ _SEQ_ADVBUF(4);} /* * Patch loading. */ #ifdef OSSLIB # define SEQ_WRPATCH(patchx, len) \ OSS_write_patch(seqfd, (char*)(patchx), len) # define SEQ_WRPATCH2(patchx, len) \ OSS_write_patch2(seqfd, (char*)(patchx), len) #else # define SEQ_WRPATCH(patchx, len) \ {if (_seqbufptr) SEQ_DUMPBUF();\ if (write(seqfd, (char*)(patchx), len)==-1) \ perror("Write patch: /dev/sequencer");} # define SEQ_WRPATCH2(patchx, len) \ (SEQ_DUMPBUF(), write(seqfd, (char*)(patchx), len)) #endif #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/linux/types.h010064400000000000000000000001161173363226500160030ustar00#ifndef _LINUX_TYPES_H #define _LINUX_TYPES_H #include #endif dietlibc-0.33~cvs20120325/include/linux/vt.h010064400000000000000000000057531173363226500153040ustar00#ifndef _LINUX_VT_H #define _LINUX_VT_H /* * These constants are also useful for user-level apps (e.g., VC * resizing). */ #define MIN_NR_CONSOLES 1 /* must be at least 1 */ #define MAX_NR_CONSOLES 63 /* serial lines start at 64 */ #define MAX_NR_USER_CONSOLES 63 /* must be root to allocate above this */ /* Note: the ioctl VT_GETSTATE does not work for consoles 16 and higher (since it returns a short) */ /* 0x56 is 'V', to avoid collision with termios and kd */ #define VT_OPENQRY 0x5600 /* find available vt */ struct vt_mode { char mode; /* vt mode */ char waitv; /* if set, hang on writes if not active */ short relsig; /* signal to raise on release req */ short acqsig; /* signal to raise on acquisition */ short frsig; /* unused (set to 0) */ }; #define VT_GETMODE 0x5601 /* get mode of active vt */ #define VT_SETMODE 0x5602 /* set mode of active vt */ #define VT_AUTO 0x00 /* auto vt switching */ #define VT_PROCESS 0x01 /* process controls switching */ #define VT_ACKACQ 0x02 /* acknowledge switch */ struct vt_stat { unsigned short v_active; /* active vt */ unsigned short v_signal; /* signal to send */ unsigned short v_state; /* vt bitmask */ }; #define VT_GETSTATE 0x5603 /* get global vt state info */ #define VT_SENDSIG 0x5604 /* signal to send to bitmask of vts */ #define VT_RELDISP 0x5605 /* release display */ #define VT_ACTIVATE 0x5606 /* make vt active */ #define VT_WAITACTIVE 0x5607 /* wait for vt active */ #define VT_DISALLOCATE 0x5608 /* free memory associated to vt */ struct vt_sizes { unsigned short v_rows; /* number of rows */ unsigned short v_cols; /* number of columns */ unsigned short v_scrollsize; /* number of lines of scrollback */ }; #define VT_RESIZE 0x5609 /* set kernel's idea of screensize */ struct vt_consize { unsigned short v_rows; /* number of rows */ unsigned short v_cols; /* number of columns */ unsigned short v_vlin; /* number of pixel rows on screen */ unsigned short v_clin; /* number of pixel rows per character */ unsigned short v_vcol; /* number of pixel columns on screen */ unsigned short v_ccol; /* number of pixel columns per character */ }; #define VT_RESIZEX 0x560A /* set kernel's idea of screensize + more */ #define VT_LOCKSWITCH 0x560B /* disallow vt switching */ #define VT_UNLOCKSWITCH 0x560C /* allow vt switching */ #define VT_GETHIFONTMASK 0x560D /* return hi font mask */ struct vt_event { unsigned int event; #define VT_EVENT_SWITCH 0x0001 /* Console switch */ #define VT_EVENT_BLANK 0x0002 /* Screen blank */ #define VT_EVENT_UNBLANK 0x0004 /* Screen unblank */ #define VT_EVENT_RESIZE 0x0008 /* Resize display */ #define VT_MAX_EVENT 0x000F unsigned int oldev; /* Old console */ unsigned int newev; /* New console (if changing) */ unsigned int pad[4]; /* Padding for expansion */ }; #define VT_WAITEVENT 0x560E /* Wait for an event */ struct vt_setactivate { unsigned int console; struct vt_mode mode; }; #define VT_SETACTIVATE 0x560F /* Activate and set the mode of a console */ #endif dietlibc-0.33~cvs20120325/include/locale.h010064400000000000000000000067721173363226500147550ustar00#ifndef _LOCALE_H #define _LOCALE_H #include __BEGIN_DECLS enum { LC_CTYPE = 0, #define LC_CTYPE LC_CTYPE LC_NUMERIC = 1, #define LC_NUMERIC LC_NUMERIC LC_TIME = 2, #define LC_TIME LC_TIME LC_COLLATE = 3, #define LC_COLLATE LC_COLLATE LC_MONETARY = 4, #define LC_MONETARY LC_MONETARY LC_MESSAGES = 5, #define LC_MESSAGES LC_MESSAGES LC_ALL = 6, #define LC_ALL LC_ALL LC_PAPER = 7, #define LC_PAPER LC_PAPER LC_NAME = 8, #define LC_NAME LC_NAME LC_ADDRESS = 9, #define LC_ADDRESS LC_ADDRESS LC_TELEPHONE = 10, #define LC_TELEPHONE LC_TELEPHONE LC_MEASUREMENT = 11, #define LC_MEASUREMENT LC_MEASUREMENT LC_IDENTIFICATION = 12 #define LC_IDENTIFICATION LC_IDENTIFICATION }; /* Structure giving information about numeric and monetary notation. */ struct lconv { /* Numeric (non-monetary) information. */ char *decimal_point; char *thousands_sep; /* Each element is the number of digits in each group; elements with higher indices are farther left. An element with value CHAR_MAX means that no further grouping is done. An element with value 0 means that the previous element is used for all groups farther left. */ char *grouping; /* Monetary information. */ /* First three chars are a currency symbol from ISO 4217. Fourth char is the separator. Fifth char is '\0'. */ char *int_curr_symbol; char *currency_symbol; /* Local currency symbol. */ char *mon_decimal_point; /* Decimal point character. */ char *mon_thousands_sep; /* Thousands separator. */ char *mon_grouping; /* Like `grouping' element (above). */ char *positive_sign; /* Sign for positive values. */ char *negative_sign; /* Sign for negative values. */ char int_frac_digits; /* Int'l fractional digits. */ char frac_digits; /* Local fractional digits. */ /* 1 if currency_symbol precedes a positive value, 0 if succeeds. */ char p_cs_precedes; /* 1 iff a space separates currency_symbol from a positive value. */ char p_sep_by_space; /* 1 if currency_symbol precedes a negative value, 0 if succeeds. */ char n_cs_precedes; /* 1 iff a space separates currency_symbol from a negative value. */ char n_sep_by_space; /* Positive and negative sign positions: 0 Parentheses surround the quantity and currency_symbol. 1 The sign string precedes the quantity and currency_symbol. 2 The sign string follows the quantity and currency_symbol. 3 The sign string immediately precedes the currency_symbol. 4 The sign string immediately follows the currency_symbol. */ char p_sign_posn; char n_sign_posn; /* 1 if int_curr_symbol precedes a positive value, 0 if succeeds. */ char int_p_cs_precedes; /* 1 iff a space separates int_curr_symbol from a positive value. */ char int_p_sep_by_space; /* 1 if int_curr_symbol precedes a negative value, 0 if succeeds. */ char int_n_cs_precedes; /* 1 iff a space separates int_curr_symbol from a negative value. */ char int_n_sep_by_space; /* Positive and negative sign positions: 0 Parentheses surround the quantity and int_curr_symbol. 1 The sign string precedes the quantity and int_curr_symbol. 2 The sign string follows the quantity and int_curr_symbol. 3 The sign string immediately precedes the int_curr_symbol. 4 The sign string immediately follows the int_curr_symbol. */ char int_p_sign_posn; char int_n_sign_posn; }; char *setlocale (int category, const char *locale) __THROW; struct lconv *localeconv (void) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/malloc.h010064400000000000000000000000241173363226500147450ustar00#include dietlibc-0.33~cvs20120325/include/math.h010064400000000000000000000101451173363226500144340ustar00#ifndef _MATH_H #define _MATH_H #include __BEGIN_DECLS #define M_E 2.7182818284590452354 /* e */ #define M_LOG2E 1.4426950408889634074 /* log_2 e */ #define M_LOG10E 0.43429448190325182765 /* log_10 e */ #define M_LN2 0.69314718055994530942 /* log_e 2 */ #define M_LN10 2.30258509299404568402 /* log_e 10 */ #define M_PI 3.14159265358979323846 /* pi */ #define M_PI_2 1.57079632679489661923 /* pi/2 */ #define M_PI_4 0.78539816339744830962 /* pi/4 */ #define M_1_PI 0.31830988618379067154 /* 1/pi */ #define M_2_PI 0.63661977236758134308 /* 2/pi */ #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ #define M_El 2.7182818284590452353602874713526625L /* e */ #define M_LOG2El 1.4426950408889634073599246810018922L /* log_2 e */ #define M_LOG10El 0.4342944819032518276511289189166051L /* log_10 e */ #define M_LN2l 0.6931471805599453094172321214581766L /* log_e 2 */ #define M_LN10l 2.3025850929940456840179914546843642L /* log_e 10 */ #define M_PIl 3.1415926535897932384626433832795029L /* pi */ #define M_PI_2l 1.5707963267948966192313216916397514L /* pi/2 */ #define M_PI_4l 0.7853981633974483096156608458198757L /* pi/4 */ #define M_1_PIl 0.3183098861837906715377675267450287L /* 1/pi */ #define M_2_PIl 0.6366197723675813430755350534900574L /* 2/pi */ #define M_2_SQRTPIl 1.1283791670955125738961589031215452L /* 2/sqrt(pi) */ #define M_SQRT2l 1.4142135623730950488016887242096981L /* sqrt(2) */ #define M_SQRT1_2l 0.7071067811865475244008443621048490L /* 1/sqrt(2) */ double sin(double d) __THROW __attribute__((__const__)); double cos(double d) __THROW __attribute__((__const__)); double tan(double d) __THROW __attribute__((__const__)); double sinh(double d) __THROW __attribute__((__const__)); double cosh(double d) __THROW __attribute__((__const__)); double tanh(double d) __THROW __attribute__((__const__)); double asin(double d) __THROW __attribute__((__const__)); double acos(double d) __THROW __attribute__((__const__)); double atan(double d) __THROW __attribute__((__const__)); double asinh(double d) __THROW __attribute__((__const__)); double acosh(double d) __THROW __attribute__((__const__)); double atanh(double d) __THROW __attribute__((__const__)); double exp(double d) __THROW __attribute__((__const__)); double exp10(double d) __THROW __attribute__((__const__)); double log(double d) __THROW __attribute__((__const__)); double log10(double d) __THROW __attribute__((__const__)); double exp2(double d) __THROW __attribute__((__const__)); double log2(double d) __THROW __attribute__((__const__)); double pow(double x, double y) __THROW __attribute__((__const__)); double sqrt(double x) __THROW __attribute__((__const__)); double fabs(double x) __THROW __attribute__((__const__)); double fmod(double x, double y) __THROW __attribute__((__const__)); double floor(double x) __attribute__((__const__)); double ceil(double x) __attribute__((__const__)); double expm1(double x) __THROW __attribute__((__const__)); double hypot(double x, double y) __THROW __attribute__((__const__)); double atan2(double x, double y) __THROW __attribute__((__const__)); double copysign(double value, double sign) __attribute__((__const__)); # define HUGE_VAL \ (__extension__ \ ((union { unsigned long long __ll; double __d; }) \ { __ll: 0x7ff0000000000000ULL }).__d) # define HUGE_VALF \ (__extension__ \ ((union { unsigned int __i; float __f; }) \ { __i: 0x7f800000UL }).__f) #ifdef _GNU_SOURCE void sincos(double x, double* sinx, double* cosx); double ipow (double mant, int expo); #endif int isnan(double d) __attribute__((__const__)); int isinf(double d) __attribute__((__const__)); int finite(double d) __attribute__((__const__)); double j0(double x); double j1(double x); double jn(int n, double x); double y0(double x); double y1(double x); double yn(int n, double x); double erf(double x); double erfc(double x); double lgamma(double x); double rint(double x); double modf(double x, double * iptr); double frexp(double x, int *exp); double ldexp(double x, int exp); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/md5.h010064400000000000000000000030761173363226500141750ustar00/* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. License to copy and use this software is granted provided that it is identified as the "RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing this software or this function. License is also granted to make and use derivative works provided that such works are identified as "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm" in all material mentioning or referencing the derived work. RSA Data Security, Inc. makes no representations concerning either the merchantability of this software or the suitability of this software for any particular purpose. It is provided "as is" without express or implied warranty of any kind. These notices must be retained in any copies of any part of this documentation and/or software. */ #ifndef _MD5_H #define _MD5_H #include __BEGIN_DECLS /* Define the MD5 context structure. Please DO NOT change the order or contents of the structure as various assembler files depend on it !! */ typedef struct { uint32_t state[4]; /* state (ABCD) */ uint32_t count[2]; /* number of bits, modulo 2^64 (least sig word first) */ uint8_t buffer[64]; /* input buffer for incomplete buffer data */ } MD5_CTX; void MD5Init(MD5_CTX* ctx); void MD5Update(MD5_CTX* ctx, const uint8_t* buf, size_t len); void MD5Final(uint8_t digest[16], MD5_CTX* ctx); char* md5crypt(const char* pw, const char* salt); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/memory.h010064400000000000000000000001011173363226500150020ustar00#ifndef _MEMORY_H #define _MEMORY_H #include #endif dietlibc-0.33~cvs20120325/include/mntent.h010064400000000000000000000044441173363226500150150ustar00#ifndef _MNTENT_H #define _MNTENT_H #include #include #include #define MNTTAB _PATH_MNTTAB /* Deprecated alias. */ #define MOUNTED _PATH_MOUNTED /* Deprecated alias. */ /* General filesystem types. */ #define MNTTYPE_IGNORE "ignore" /* Ignore this entry. */ #define MNTTYPE_NFS "nfs" /* Network file system. */ #define MNTTYPE_SWAP "swap" /* Swap device. */ /* Generic mount options. */ #define MNTOPT_DEFAULTS "defaults" /* Use all default options. */ #define MNTOPT_RO "ro" /* Read only. */ #define MNTOPT_RW "rw" /* Read/write. */ #define MNTOPT_SUID "suid" /* Set uid allowed. */ #define MNTOPT_NOSUID "nosuid" /* No set uid allowed. */ #define MNTOPT_NOAUTO "noauto" /* Do not auto mount. */ __BEGIN_DECLS /* Structure describing a mount table entry. */ struct mntent { char *mnt_fsname; /* Device or server for filesystem. */ char *mnt_dir; /* Directory mounted on. */ char *mnt_type; /* Type of filesystem: ufs, nfs, etc. */ char *mnt_opts; /* Comma-separated options for fs. */ int mnt_freq; /* Dump frequency (in days). */ int mnt_passno; /* Pass number for `fsck'. */ }; /* Prepare to begin reading and/or writing mount table entries from the beginning of FILE. MODE is as for `fopen'. */ extern FILE *setmntent (const char *file, const char *mode) __THROW; /* Read one mount table entry from STREAM. Returns a pointer to storage reused on the next call, or null for EOF or error (use feof/ferror to check). */ extern struct mntent *getmntent (FILE* stream) __THROW; #ifdef __USE_MISC /* Reentrant version of the above function. */ extern struct mntent *getmntent_r (FILE* stream, struct mntent* result, char* buffer, int bufsize) __THROW; #endif /* Write the mount table entry described by MNT to STREAM. Return zero on success, nonzero on failure. */ extern int addmntent (FILE* stream, const struct mntent* mnt) __THROW; /* Close a stream opened with `setmntent'. */ extern int endmntent (FILE *stream) __THROW; /* Search MNT->mnt_opts for an option matching OPT. Returns the address of the substring, or null if none found. */ extern char *hasmntopt (const struct mntent *__mnt, const char *opt) __THROW; __END_DECLS #endif /* mntent.h */ dietlibc-0.33~cvs20120325/include/mqueue.h010064400000000000000000000027001173363226500150020ustar00#ifndef _MQUEUE_H #define _MQUEUE_H #include #include #define MQ_PRIO_MAX 32768 /* per-uid limit of kernel memory used by mqueue, in bytes */ #define MQ_BYTES_MAX 819200 typedef int mqd_t; struct mq_attr { long mq_flags; /* message queue flags */ long mq_maxmsg; /* maximum number of messages */ long mq_msgsize; /* maximum message size */ long mq_curmsgs; /* number of messages currently queued */ long __reserved[4]; /* ignored for input, zeroed for output */ }; #define NOTIFY_NONE 0 #define NOTIFY_WOKENUP 1 #define NOTIFY_REMOVED 2 #define NOTIFY_COOKIE_LEN 32 __BEGIN_DECLS mqd_t mq_open(const char *name, int oflag, ...) __THROW; int mq_unlink(const char *name) __THROW; int mq_send(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio) __THROW; int mq_timedsend(mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned msg_prio, const struct timespec *abs_timeout) __THROW; ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned *msg_prio) __THROW; ssize_t mq_timedreceive(mqd_t mqdes, char *restrict msg_ptr, size_t msg_len, unsigned *restrict msg_prio, const struct timespec *restrict abs_timeout) __THROW; int mq_notify(mqd_t mqdes, const struct sigevent *notification) __THROW; int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat) __THROW; int mq_setattr(mqd_t mqdes, const struct mq_attr *restrict mqstat, struct mq_attr *restrict omqstat) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/net/ethernet.h010064400000000000000000000034511173363226500161110ustar00#ifndef __NET_ETHERNET_H #define __NET_ETHERNET_H #include #include #include /* IEEE 802.3 Ethernet constants */ __BEGIN_DECLS /* This is a name for the 48 bit ethernet address available on many systems. */ struct ether_addr { uint8_t ether_addr_octet[ETH_ALEN]; } __attribute__ ((__packed__)); /* 10Mb/s ethernet header */ struct ether_header { uint8_t ether_dhost[ETH_ALEN]; /* destination eth addr */ uint8_t ether_shost[ETH_ALEN]; /* source ether addr */ uint16_t ether_type; /* packet type ID field */ } __attribute__ ((__packed__)); /* Ethernet protocol ID's */ #define ETHERTYPE_PUP 0x0200 /* Xerox PUP */ #define ETHERTYPE_IP 0x0800 /* IP */ #define ETHERTYPE_ARP 0x0806 /* Address resolution */ #define ETHERTYPE_REVARP 0x8035 /* Reverse ARP */ #define ETHER_ADDR_LEN ETH_ALEN /* size of ethernet addr */ #define ETHER_TYPE_LEN 2 /* bytes in type field */ #define ETHER_CRC_LEN 4 /* bytes in CRC field */ #define ETHER_HDR_LEN ETH_HLEN /* total octets in header */ #define ETHER_MIN_LEN (ETH_ZLEN + ETHER_CRC_LEN) /* min packet length */ #define ETHER_MAX_LEN (ETH_FRAME_LEN + ETHER_CRC_LEN) /* max packet length */ /* make sure ethenet length is valid */ #define ETHER_IS_VALID_LEN(foo) \ ((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) /* * The ETHERTYPE_NTRAILER packet types starting at ETHERTYPE_TRAIL have * (type-ETHERTYPE_TRAIL)*512 bytes of data followed * by an ETHER type (as given above) and then the (variable-length) header. */ #define ETHERTYPE_TRAIL 0x1000 /* Trailer packet */ #define ETHERTYPE_NTRAILER 16 #define ETHERMTU ETH_DATA_LEN #define ETHERMIN (ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/net/if.h010064400000000000000000000067611173363226500147000ustar00#ifndef _NET_IF_H #define _NET_IF_H #include #include __BEGIN_DECLS /* Standard interface flags. */ #define IFF_UP 0x1 /* interface is up */ #define IFF_BROADCAST 0x2 /* broadcast address valid */ #define IFF_DEBUG 0x4 /* turn on debugging */ #define IFF_LOOPBACK 0x8 /* is a loopback net */ #define IFF_POINTOPOINT 0x10 /* interface is has p-p link */ #define IFF_NOTRAILERS 0x20 /* avoid use of trailers */ #define IFF_RUNNING 0x40 /* resources allocated */ #define IFF_NOARP 0x80 /* no ARP protocol */ #define IFF_PROMISC 0x100 /* receive all packets */ #define IFF_ALLMULTI 0x200 /* receive all multicast packets*/ #define IFF_MASTER 0x400 /* master of a load balancer */ #define IFF_SLAVE 0x800 /* slave of a load balancer */ #define IFF_MULTICAST 0x1000 /* Supports multicast */ #define IFF_PORTSEL 0x2000 /* can set media type */ #define IFF_AUTOMEDIA 0x4000 /* auto media select active */ #define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses*/ #define IFF_LOWER_UP 0x10000 /* driver signals L1 up */ #define IFF_DORMANT 0x20000 /* driver signals dormant */ #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|\ IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT) struct ifmap { unsigned long mem_start; unsigned long mem_end; uint16_t base_addr; unsigned char irq; unsigned char dma; unsigned char port; /* 3 bytes spare */ }; struct ifreq { #define IFHWADDRLEN 6 #define IF_NAMESIZE 16 #define IFNAMSIZ IF_NAMESIZE union { char ifrn_name[IF_NAMESIZE]; /* if name, e.g. "en0" */ } ifr_ifrn; union { struct sockaddr ifru_addr; struct sockaddr ifru_dstaddr; struct sockaddr ifru_broadaddr; struct sockaddr ifru_netmask; struct sockaddr ifru_hwaddr; int16_t ifru_flags; int32_t ifru_ivalue; int32_t ifru_mtu; struct ifmap ifru_map; char ifru_slave[IF_NAMESIZE]; /* Just fits the size */ char ifru_newname[IF_NAMESIZE]; char* ifru_data; } ifr_ifru; }; #define ifr_name ifr_ifrn.ifrn_name /* interface name */ #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */ #define ifr_addr ifr_ifru.ifru_addr /* address */ #define ifr_dstaddr ifr_ifru.ifru_dstaddr /* other end of p-p lnk */ #define ifr_broadaddr ifr_ifru.ifru_broadaddr /* broadcast address */ #define ifr_netmask ifr_ifru.ifru_netmask /* interface net mask */ #define ifr_flags ifr_ifru.ifru_flags /* flags */ #define ifr_metric ifr_ifru.ifru_ivalue /* metric */ #define ifr_mtu ifr_ifru.ifru_mtu /* mtu */ #define ifr_map ifr_ifru.ifru_map /* device map */ #define ifr_slave ifr_ifru.ifru_slave /* slave device */ #define ifr_data ifr_ifru.ifru_data /* for use by interface */ #define ifr_ifindex ifr_ifru.ifru_ivalue /* interface index */ #define ifr_bandwidth ifr_ifru.ifru_ivalue /* link bandwidth */ #define ifr_qlen ifr_ifru.ifru_ivalue /* Queue length */ #define ifr_newname ifr_ifru.ifru_newname /* New name */ struct ifconf { int32_t ifc_len; /* size of buffer */ union { char * ifcu_buf; struct ifreq *ifcu_req; } ifc_ifcu; }; #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */ #define ifc_req ifc_ifcu.ifcu_req /* array of structures */ unsigned int if_nametoindex (const char *ifname) __THROW; char *if_indextoname (unsigned int ifindex, char *ifname) __THROW; struct if_nameindex { uint32_t if_index; char *if_name; }; struct if_nameindex* if_nameindex(void) __THROW; void if_freenameindex(struct if_nameindex* ptr) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/net/if_arp.h010064400000000000000000000104021173363226500155250ustar00#ifndef _NET_IF_ARP_H #define _NET_IF_ARP_H #include __BEGIN_DECLS #define MAX_ADDR_LEN 7 /* ARP protocol HARDWARE identifiers. */ #define ARPHRD_NETROM 0 /* from KA9Q: NET/ROM pseudo */ #define ARPHRD_ETHER 1 /* Ethernet 10Mbps */ #define ARPHRD_EETHER 2 /* Experimental Ethernet */ #define ARPHRD_AX25 3 /* AX.25 Level 2 */ #define ARPHRD_PRONET 4 /* PROnet token ring */ #define ARPHRD_CHAOS 5 /* Chaosnet */ #define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB */ #define ARPHRD_ARCNET 7 /* ARCnet */ #define ARPHRD_APPLETLK 8 /* APPLEtalk */ #define ARPHRD_DLCI 15 /* Frame Relay DLCI */ #define ARPHRD_ATM 19 /* ATM */ #define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id) */ /* Dummy types for non ARP hardware */ #define ARPHRD_SLIP 256 #define ARPHRD_CSLIP 257 #define ARPHRD_SLIP6 258 #define ARPHRD_CSLIP6 259 #define ARPHRD_RSRVD 260 /* Notional KISS type */ #define ARPHRD_ADAPT 264 #define ARPHRD_ROSE 270 #define ARPHRD_X25 271 /* CCITT X.25 */ #define ARPHRD_HWX25 272 /* Boards with X.25 in firmware */ #define ARPHRD_PPP 512 #define ARPHRD_CISCO 513 /* Cisco HDLC */ #define ARPHRD_HDLC ARPHRD_CISCO #define ARPHRD_LAPB 516 /* LAPB */ #define ARPHRD_DDCMP 517 /* Digital's DDCMP protocol */ #define ARPHRD_RAWHDLC 518 /* Raw HDLC */ #define ARPHRD_TUNNEL 768 /* IPIP tunnel */ #define ARPHRD_TUNNEL6 769 /* IPIP6 tunnel */ #define ARPHRD_FRAD 770 /* Frame Relay Access Device */ #define ARPHRD_SKIP 771 /* SKIP vif */ #define ARPHRD_LOOPBACK 772 /* Loopback device */ #define ARPHRD_LOCALTLK 773 /* Localtalk device */ #define ARPHRD_FDDI 774 /* Fiber Distributed Data Interface */ #define ARPHRD_BIF 775 /* AP1000 BIF */ #define ARPHRD_SIT 776 /* sit0 device - IPv6-in-IPv4 */ #define ARPHRD_IPDDP 777 /* IP over DDP tunneller */ #define ARPHRD_IPGRE 778 /* GRE over IP */ #define ARPHRD_PIMREG 779 /* PIMSM register interface */ #define ARPHRD_HIPPI 780 /* High Performance Parallel Interface */ #define ARPHRD_ASH 781 /* Nexus 64Mbps Ash */ #define ARPHRD_ECONET 782 /* Acorn Econet */ #define ARPHRD_IRDA 783 /* Linux-IrDA */ /* ARP works differently on different FC media .. so */ #define ARPHRD_FCPP 784 /* Point to point fibrechannel */ #define ARPHRD_FCAL 785 /* Fibrechannel arbitrated loop */ #define ARPHRD_FCPL 786 /* Fibrechannel public loop */ #define ARPHRD_FCFABRIC 787 /* Fibrechannel fabric */ /* 787->799 reserved for fibrechannel media types */ #define ARPHRD_IEEE802_TR 800 /* Magic type ident for TR */ #define ARPHRD_IEEE80211 801 /* IEEE 802.11 */ #define ARPHRD_VOID 0xFFFF /* Void type, nothing is known */ /* ARP protocol opcodes. */ #define ARPOP_REQUEST 1 /* ARP request */ #define ARPOP_REPLY 2 /* ARP reply */ #define ARPOP_RREQUEST 3 /* RARP request */ #define ARPOP_RREPLY 4 /* RARP reply */ #define ARPOP_InREQUEST 8 /* InARP request */ #define ARPOP_InREPLY 9 /* InARP reply */ #define ARPOP_NAK 10 /* (ATM)ARP NAK */ /* ARP ioctl request. */ struct arpreq { struct sockaddr arp_pa; /* protocol address */ struct sockaddr arp_ha; /* hardware address */ int arp_flags; /* flags */ struct sockaddr arp_netmask; /* netmask (only for proxy arps) */ char arp_dev[16]; }; struct arpreq_old { struct sockaddr arp_pa; /* protocol address */ struct sockaddr arp_ha; /* hardware address */ int arp_flags; /* flags */ struct sockaddr arp_netmask; /* netmask (only for proxy arps) */ }; /* ARP Flag values. */ #define ATF_COM 0x02 /* completed entry (ha valid) */ #define ATF_PERM 0x04 /* permanent entry */ #define ATF_PUBL 0x08 /* publish entry */ #define ATF_USETRAILERS 0x10 /* has requested trailers */ #define ATF_NETMASK 0x20 /* want to use a netmask (only for proxy entries) */ #define ATF_DONTPUB 0x40 /* don't answer this addresses */ /* * This structure defines an ethernet arp header. */ struct arphdr { unsigned short ar_hrd; /* format of hardware address */ unsigned short ar_pro; /* format of protocol address */ unsigned char ar_hln; /* length of hardware address */ unsigned char ar_pln; /* length of protocol address */ unsigned short ar_op; /* ARP opcode (command) */ }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/net/if_ether.h010064400000000000000000000063371173363226500160660ustar00#ifndef _NET_IF_ETHER_H #define _NET_IF_ETHER_H #include __BEGIN_DECLS /* taken from */ #define ETH_ALEN 6 /* Octets in one ethernet addr */ #define ETH_HLEN 14 /* Total octets in header. */ #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */ #define ETH_DATA_LEN 1500 /* Max. octets in payload */ #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */ /* * These are the defined Ethernet Protocol ID's. */ #define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */ #define ETH_P_PUP 0x0200 /* Xerox PUP packet */ #define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */ #define ETH_P_IP 0x0800 /* Internet Protocol packet */ #define ETH_P_X25 0x0805 /* CCITT X.25 */ #define ETH_P_ARP 0x0806 /* Address Resolution packet */ #define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */ #define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */ #define ETH_P_DEC 0x6000 /* DEC Assigned proto */ #define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */ #define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */ #define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */ #define ETH_P_LAT 0x6004 /* DEC LAT */ #define ETH_P_DIAG 0x6005 /* DEC Diagnostics */ #define ETH_P_CUST 0x6006 /* DEC Customer use */ #define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */ #define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */ #define ETH_P_ATALK 0x809B /* Appletalk DDP */ #define ETH_P_AARP 0x80F3 /* Appletalk AARP */ #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */ #define ETH_P_IPX 0x8137 /* IPX over DIX */ #define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */ #define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */ #define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */ #define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */ #define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport over Ethernet */ /* * Non DIX types. Won't clash for 1500 types. */ #define ETH_P_802_3 0x0001 /* Dummy type for 802.3 frames */ #define ETH_P_AX25 0x0002 /* Dummy protocol id for AX.25 */ #define ETH_P_ALL 0x0003 /* Every packet (be careful!!!) */ #define ETH_P_802_2 0x0004 /* 802.2 frames */ #define ETH_P_SNAP 0x0005 /* Internal only */ #define ETH_P_DDCMP 0x0006 /* DEC DDCMP: Internal only */ #define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/ #define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */ #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */ #define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/ #define ETH_P_TR_802_2 0x0011 /* 802.2 frames */ #define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */ #define ETH_P_CONTROL 0x0016 /* Card specific control frames */ #define ETH_P_IRDA 0x0017 /* Linux-IrDA */ #define ETH_P_ECONET 0x0018 /* Acorn Econet */ /* * This is an Ethernet frame header. */ struct ethhdr { unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ unsigned char h_source[ETH_ALEN]; /* source ether addr */ unsigned short h_proto; /* packet type ID field */ }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/net/route.h010064400000000000000000000032761173363226500154360ustar00#ifndef _NET_ROUTE_H #define _NET_ROUTE_H #include #include __BEGIN_DECLS /* This structure gets passed by the SIOCADDRT and SIOCDELRT calls. */ struct rtentry { unsigned long rt_pad1; struct sockaddr rt_dst; /* target address */ struct sockaddr rt_gateway; /* gateway addr (RTF_GATEWAY) */ struct sockaddr rt_genmask; /* target network mask (IP) */ unsigned short rt_flags; short rt_pad2; unsigned long rt_pad3; void *rt_pad4; short rt_metric; /* +1 for binary compatibility! */ char *rt_dev; /* forcing the device at add */ unsigned long rt_mtu; /* per route MTU/Window */ #define rt_mss rt_mtu /* Compatibility :-( */ unsigned long rt_window; /* Window clamping */ unsigned short rt_irtt; /* Initial RTT */ }; #define RTF_UP 0x0001 /* route usable */ #define RTF_GATEWAY 0x0002 /* destination is a gateway */ #define RTF_HOST 0x0004 /* host entry (net otherwise) */ #define RTF_REINSTATE 0x0008 /* reinstate route after tmout */ #define RTF_DYNAMIC 0x0010 /* created dyn. (by redirect) */ #define RTF_MODIFIED 0x0020 /* modified dyn. (by redirect) */ #define RTF_MTU 0x0040 /* specific MTU for this route */ #define RTF_MSS RTF_MTU /* Compatibility :-( */ #define RTF_WINDOW 0x0080 /* per route window clamping */ #define RTF_IRTT 0x0100 /* Initial round trip time */ #define RTF_REJECT 0x0200 /* Reject route */ struct in6_rtmsg { struct in6_addr rtmsg_dst; struct in6_addr rtmsg_src; struct in6_addr rtmsg_gateway; uint32_t rtmsg_type; uint16_t rtmsg_dst_len; uint16_t rtmsg_src_len; uint32_t rtmsg_metric; unsigned long int rtmsg_info; uint32_t rtmsg_flags; int rtmsg_ifindex; }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/netdb.h010064400000000000000000000102671173363226500146040ustar00#ifndef _NETDB_H #define _NETDB_H #include #include __BEGIN_DECLS /* Absolute file name for network data base files. */ #define _PATH_HEQUIV "/etc/hosts.equiv" #define _PATH_HOSTS "/etc/hosts" #define _PATH_NETWORKS "/etc/networks" #define _PATH_NSSWITCH_CONF "/etc/nsswitch.conf" #define _PATH_PROTOCOLS "/etc/protocols" #define _PATH_SERVICES "/etc/services" /* Description of data base entry for a single service. */ struct servent { char *s_name; /* Official service name. */ char **s_aliases; /* Alias list. */ int s_port; /* Port number. */ char *s_proto; /* Protocol to use. */ }; extern void endservent (void) __THROW; extern void setservent(int stayopen) __THROW; extern int getservent_r(struct servent *res, char *buf, size_t buflen, struct servent **res_sig) __THROW; extern int getservbyname_r(const char* name,const char* proto, struct servent *res, char *buf, size_t buflen, struct servent **res_sig) __THROW; extern int getservbyport_r(int port,const char* proto, struct servent *res, char *buf, size_t buflen, struct servent **res_sig) __THROW; extern struct servent *getservent(void) __THROW; extern struct servent *getservbyname (const char *__name, const char *__proto) __THROW; extern struct servent *getservbyport (int __port, const char *__proto) __THROW; struct hostent { char *h_name; /* Official name of host. */ char **h_aliases; /* Alias list. */ int h_addrtype; /* Host address type. */ socklen_t h_length; /* Length of address. */ char **h_addr_list; /* List of addresses from name server. */ #define h_addr h_addr_list[0] /* Address, for backward compatibility. */ }; extern void endhostent (void) __THROW; extern struct hostent *gethostent (void) __THROW; extern struct hostent *gethostent_r (char* buf,int len) __THROW; extern struct hostent *gethostbyaddr (const void *__addr, socklen_t __len, int __type) __THROW; extern struct hostent *gethostbyname (const char *__name) __THROW; extern struct hostent *gethostbyname2 (const char *__name, int __af) __THROW; /* this glibc "invention" is so ugly, I'm going to throw up any minute * now */ extern int gethostbyname_r(const char* NAME, struct hostent* RESULT_BUF,char* BUF, size_t BUFLEN, struct hostent** RESULT, int* H_ERRNOP) __THROW; #define HOST_NOT_FOUND 1 #define TRY_AGAIN 2 #define NO_RECOVERY 3 #define NO_ADDRESS 4 #define NO_DATA 5 extern int gethostbyaddr_r(const char* addr, size_t length, int format, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop) __THROW; int gethostbyname2_r(const char* name, int AF, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop) __THROW; struct protoent { char *p_name; /* official protocol name */ char **p_aliases; /* alias list */ int p_proto; /* protocol number */ }; struct protoent *getprotoent(void) __THROW; struct protoent *getprotobyname(const char *name) __THROW; struct protoent *getprotobynumber(int proto) __THROW; void setprotoent(int stayopen) __THROW; void endprotoent(void) __THROW; int getprotoent_r(struct protoent *res, char *buf, size_t buflen, struct protoent **res_sig) __THROW; int getprotobyname_r(const char* name, struct protoent *res, char *buf, size_t buflen, struct protoent **res_sig) __THROW; int getprotobynumber_r(int proto, struct protoent *res, char *buf, size_t buflen, struct protoent **res_sig) __THROW; void sethostent(int stayopen) __THROW; /* dummy */ extern int h_errno; struct netent { char *n_name; /* official network name */ char **n_aliases; /* alias list */ int n_addrtype; /* net address type */ unsigned long int n_net; /* network number */ }; struct netent *getnetbyaddr(unsigned long net, int type) __THROW; void endnetent(void) __THROW; void setnetent(int stayopen) __THROW; struct netent *getnetbyname(const char *name) __THROW; struct netent *getnetent(void) __THROW; extern const char *hstrerror (int err_num) __THROW; void herror(const char *s) __THROW; #define NI_MAXHOST 1025 #define NI_MAXSERV 32 __END_DECLS #endif dietlibc-0.33~cvs20120325/include/netinet/ether.h010064400000000000000000000001311173363226500162520ustar00#ifndef _NETINET_ETHER_H #define _NETINET_ETHER_H #include #endif dietlibc-0.33~cvs20120325/include/netinet/if_ether.h010064400000000000000000000001331173363226500167320ustar00#ifndef _NETINET_IF_ETHER_H #define _NETINET_IF_ETHER_H #include #endif dietlibc-0.33~cvs20120325/include/netinet/in.h010064400000000000000000000306131173363226500155610ustar00#ifndef _NETINET_IN_H #define _NETINET_IN_H #include #include #include __BEGIN_DECLS /* Standard well-defined IP protocols. */ enum { IPPROTO_IP = 0, /* Dummy protocol for TCP */ #define IPPROTO_IP IPPROTO_IP IPPROTO_ICMP = 1, /* Internet Control Message Protocol */ #define IPPROTO_ICMP IPPROTO_ICMP IPPROTO_IGMP = 2, /* Internet Group Management Protocol */ #define IPPROTO_IGMP IPPROTO_IGMP IPPROTO_IPIP = 4, /* IPIP tunnels (older KA9Q tunnels use 94) */ #define IPPROTO_IPIP IPPROTO_IPIP IPPROTO_TCP = 6, /* Transmission Control Protocol */ #define IPPROTO_TCP IPPROTO_TCP IPPROTO_EGP = 8, /* Exterior Gateway Protocol */ #define IPPROTO_EGP IPPROTO_EGP IPPROTO_PUP = 12, /* PUP protocol */ #define IPPROTO_PUP IPPROTO_PUP IPPROTO_UDP = 17, /* User Datagram Protocol */ #define IPPROTO_UDP IPPROTO_UDP IPPROTO_IDP = 22, /* XNS IDP protocol */ #define IPPROTO_IDP IPPROTO_IDP IPPROTO_RSVP = 46, /* RSVP protocol */ #define IPPROTO_RSVP IPPROTO_RSVP IPPROTO_GRE = 47, /* Cisco GRE tunnels (rfc 1701,1702) */ #define IPPROTO_GRE IPPROTO_GRE IPPROTO_IPV6 = 41, /* IPv6-in-IPv4 tunnelling */ #define IPPROTO_IPV6 IPPROTO_IPV6 IPPROTO_PIM = 103, /* Protocol Independent Multicast */ #define IPPROTO_PIM IPPROTO_PIM IPPROTO_ESP = 50, /* Encapsulation Security Payload protocol */ #define IPPROTO_ESP IPPROTO_ESP IPPROTO_AH = 51, /* Authentication Header protocol */ #define IPPROTO_AH IPPROTO_AH IPPROTO_COMP = 108, /* Compression Header protocol */ #define IPPROTO_COMP IPPROTO_COMP IPPROTO_SCTP = 132, /* Stream Control Transmission Protocol. */ #define IPPROTO_SCTP IPPROTO_SCTP IPPROTO_UDPLITE = 136, /* UDP-Lite protocol. */ #define IPPROTO_UDPLITE IPPROTO_UDPLITE IPPROTO_RAW = 255, /* Raw IP packets */ #define IPPROTO_RAW IPPROTO_RAW IPPROTO_MAX }; #define IP_TOS 1 #define IP_TTL 2 #define IP_HDRINCL 3 #define IP_OPTIONS 4 #define IP_ROUTER_ALERT 5 #define IP_RECVOPTS 6 #define IP_RETOPTS 7 #define IP_PKTINFO 8 #define IP_PKTOPTIONS 9 #define IP_MTU_DISCOVER 10 #define IP_RECVERR 11 #define IP_RECVTTL 12 #define IP_RECVTOS 13 #define IP_MTU 14 #define IP_FREEBIND 15 /* BSD compatibility */ #define IP_RECVRETOPTS IP_RETOPTS /* IP_MTU_DISCOVER values */ #define IP_PMTUDISC_DONT 0 /* Never send DF frames */ #define IP_PMTUDISC_WANT 1 /* Use per route hints */ #define IP_PMTUDISC_DO 2 /* Always DF */ #define IP_MULTICAST_IF 32 #define IP_MULTICAST_TTL 33 #define IP_MULTICAST_LOOP 34 #define IP_ADD_MEMBERSHIP 35 #define IP_DROP_MEMBERSHIP 36 /* These need to appear somewhere around here */ #define IP_DEFAULT_MULTICAST_TTL 1 #define IP_DEFAULT_MULTICAST_LOOP 1 #define IN6ADDR_ANY_INIT {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }}} #define IN6ADDR_LOOPBACK_INIT {{{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }}} extern const struct in6_addr in6addr_any; extern const struct in6_addr in6addr_loopback; typedef uint16_t in_port_t; typedef uint32_t in_addr_t; struct in_addr { in_addr_t s_addr; }; struct ip_mreq { struct in_addr imr_multiaddr; /* IP multicast address of group */ struct in_addr imr_interface; /* local IP address of interface */ }; struct ip_mreqn { struct in_addr imr_multiaddr; /* IP multicast address of group */ struct in_addr imr_address; /* local IP address of interface */ int32_t imr_ifindex; /* Interface index */ }; struct in_pktinfo { int32_t ipi_ifindex; struct in_addr ipi_spec_dst; struct in_addr ipi_addr; }; /* Structure describing an Internet (IP) socket address. */ #define __SOCK_SIZE__ 16 /* sizeof(struct sockaddr) */ struct sockaddr_in { sa_family_t sin_family; /* Address family */ in_port_t sin_port; /* Port number */ struct in_addr sin_addr; /* Internet address */ /* Pad to size of `struct sockaddr'. */ unsigned char sin_zero[__SOCK_SIZE__ - sizeof(int16_t) - sizeof(uint16_t) - sizeof(struct in_addr)]; }; /* * Definitions of the bits in an Internet address integer. * On subnets, host and network parts are found according * to the subnet mask, not these masks. */ #define IN_CLASSA(a) ((((long int) (a)) & 0x80000000) == 0) #define IN_CLASSA_NET 0xff000000 #define IN_CLASSA_NSHIFT 24 #define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) #define IN_CLASSA_MAX 128 #define IN_CLASSB(a) ((((long int) (a)) & 0xc0000000) == 0x80000000) #define IN_CLASSB_NET 0xffff0000 #define IN_CLASSB_NSHIFT 16 #define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) #define IN_CLASSB_MAX 65536 #define IN_CLASSC(a) ((((long int) (a)) & 0xe0000000) == 0xc0000000) #define IN_CLASSC_NET 0xffffff00 #define IN_CLASSC_NSHIFT 8 #define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) #define IN_CLASSD(a) ((((long int) (a)) & 0xf0000000) == 0xe0000000) #define IN_MULTICAST(a) IN_CLASSD(a) #define IN_MULTICAST_NET 0xF0000000 #define IN_EXPERIMENTAL(a) ((((long int) (a)) & 0xf0000000) == 0xf0000000) #define IN_BADCLASS(a) IN_EXPERIMENTAL((a)) /* Address to accept any incoming messages. */ #define INADDR_ANY ((unsigned long int) 0x00000000) /* Address to send to all hosts. */ #define INADDR_BROADCAST ((unsigned long int) 0xffffffff) /* Address indicating an error return. */ #define INADDR_NONE ((unsigned long int) 0xffffffff) /* Network number for local host loopback. */ #define IN_LOOPBACKNET 127 /* Address to loopback in software to local host. */ #define INADDR_LOOPBACK 0x7f000001 /* 127.0.0.1 */ #define IN_LOOPBACK(a) ((((long int) (a)) & 0xff000000) == 0x7f000000) /* Defines for Multicast INADDR */ #define INADDR_UNSPEC_GROUP 0xe0000000U /* 224.0.0.0 */ #define INADDR_ALLHOSTS_GROUP 0xe0000001U /* 224.0.0.1 */ #define INADDR_ALLRTRS_GROUP 0xe0000002U /* 224.0.0.2 */ #define INADDR_MAX_LOCAL_GROUP 0xe00000ffU /* 224.0.0.255 */ struct in6_addr { union { uint8_t u6_addr8[16]; uint16_t u6_addr16[8]; uint32_t u6_addr32[4]; } in6_u; #define s6_addr in6_u.u6_addr8 #define s6_addr16 in6_u.u6_addr16 #define s6_addr32 in6_u.u6_addr32 }; struct sockaddr_in6 { uint16_t sin6_family; /* AF_INET6 */ uint16_t sin6_port; /* Transport layer port # */ uint32_t sin6_flowinfo; /* IPv6 flow information */ struct in6_addr sin6_addr; /* IPv6 address */ uint32_t sin6_scope_id; /* scope id (new in RFC2553) */ }; struct sockaddr_in_pad { sa_family_t sin_family; /* Address family */ in_port_t sin_port; /* Port number */ struct in_addr sin_addr; /* Internet address */ /* Pad to size of `struct sockaddr_in6'. */ unsigned char sin_zero[sizeof(struct sockaddr_in6) - sizeof(int16_t) - sizeof(uint16_t) - sizeof(struct in_addr)]; }; struct ipv6_mreq { /* IPv6 multicast address of group */ struct in6_addr ipv6mr_multiaddr; /* local IPv6 address of interface */ int32_t ipv6mr_interface; }; struct in6_flowlabel_req { struct in6_addr flr_dst; uint32_t flr_label; uint8_t flr_action; uint8_t flr_share; uint16_t flr_flags; uint16_t flr_expires; uint16_t flr_linger; uint32_t __flr_pad; /* Options in format of IPV6_PKTOPTIONS */ }; #define IPV6_FL_A_GET 0 #define IPV6_FL_A_PUT 1 #define IPV6_FL_A_RENEW 2 #define IPV6_FL_F_CREATE 1 #define IPV6_FL_F_EXCL 2 #define IPV6_FL_S_NONE 0 #define IPV6_FL_S_EXCL 1 #define IPV6_FL_S_PROCESS 2 #define IPV6_FL_S_USER 3 #define IPV6_FL_S_ANY 255 #define IPV6_FLOWINFO_FLOWLABEL 0x000fffff #define IPV6_FLOWINFO_PRIORITY 0x0ff00000 /* * IPV6 extension headers */ #define IPPROTO_HOPOPTS 0 /* IPv6 hop-by-hop options */ #define IPPROTO_ROUTING 43 /* IPv6 routing header */ #define IPPROTO_FRAGMENT 44 /* IPv6 fragmentation header */ #define IPPROTO_ICMPV6 58 /* ICMPv6 */ #define IPPROTO_NONE 59 /* IPv6 no next header */ #define IPPROTO_DSTOPTS 60 /* IPv6 destination options */ /* IPv6 TLV options. */ #define IPV6_TLV_PAD0 0 #define IPV6_TLV_PADN 1 #define IPV6_TLV_ROUTERALERT 5 #define IPV6_TLV_JUMBO 194 /* IPV6 socket options. */ #define IPV6_ADDRFORM 1 #define IPV6_PKTINFO 2 #define IPV6_HOPOPTS 3 #define IPV6_DSTOPTS 4 #define IPV6_RTHDR 5 #define IPV6_PKTOPTIONS 6 #define IPV6_CHECKSUM 7 #define IPV6_HOPLIMIT 8 #define IPV6_NEXTHOP 9 #define IPV6_AUTHHDR 10 #define IPV6_FLOWINFO 11 #define IPV6_UNICAST_HOPS 16 #define IPV6_MULTICAST_IF 17 #define IPV6_MULTICAST_HOPS 18 #define IPV6_MULTICAST_LOOP 19 #define IPV6_ADD_MEMBERSHIP 20 #define IPV6_DROP_MEMBERSHIP 21 #define IPV6_ROUTER_ALERT 22 #define IPV6_MTU_DISCOVER 23 #define IPV6_MTU 24 #define IPV6_RECVERR 25 /* IPV6_MTU_DISCOVER values */ #define IPV6_PMTUDISC_DONT 0 #define IPV6_PMTUDISC_WANT 1 #define IPV6_PMTUDISC_DO 2 /* Flowlabel */ #define IPV6_FLOWLABEL_MGR 32 #define IPV6_FLOWINFO_SEND 33 #define IPV6_MIN_MTU 1280 struct in6_pktinfo { struct in6_addr ipi6_addr; int32_t ipi6_ifindex; }; struct in6_ifreq { struct in6_addr ifr6_addr; uint32_t ifr6_prefixlen; int32_t ifr6_ifindex; }; #define IPV6_SRCRT_STRICT 0x01 /* this hop must be a neighbor */ #define IPV6_SRCRT_TYPE_0 0 /* IPv6 type 0 Routing Header */ /* routing header */ struct ipv6_rt_hdr { uint8_t nexthdr; uint8_t hdrlen; uint8_t type; uint8_t segments_left; /* type specific data, variable length field */ }; struct ipv6_opt_hdr { uint8_t nexthdr; uint8_t hdrlen; /* TLV encoded option data follows. */ }; #define ipv6_destopt_hdr ipv6_opt_hdr #define ipv6_hopopt_hdr ipv6_opt_hdr /* routing header type 0 (used in cmsghdr struct) */ #if !defined(__STRICT_ANSI__) || (__STDC_VERSION__ + 0 >= 199900L) struct rt0_hdr { struct ipv6_rt_hdr rt_hdr; uint32_t bitmap; /* strict/loose bit map */ struct in6_addr addr[0]; #define rt0_type rt_hdr.type; }; #endif struct ipv6hdr { #if __BYTE_ORDER == __LITTLE_ENDIAN uint32_t flow_lbl:20, priority:8, version:4; #else uint32_t version:4, priority:8, flow_lbl:20; #endif uint16_t payload_len; uint8_t nexthdr; uint8_t hop_limit; struct in6_addr saddr; struct in6_addr daddr; }; /* fnord */ #define IPPORT_RESERVED 1024 #define INET_ADDRSTRLEN 16 #define INET6_ADDRSTRLEN 46 #undef htonl #undef htons #undef ntohl #undef ntohs uint32_t htonl(uint32_t hostlong); uint16_t htons(uint16_t hostshort); uint32_t ntohl(uint32_t netlong); uint16_t ntohs(uint16_t netshort); #define IN6_IS_ADDR_UNSPECIFIED(a) \ (((__const uint32_t *) (a))[0] == 0 \ && ((__const uint32_t *) (a))[1] == 0 \ && ((__const uint32_t *) (a))[2] == 0 \ && ((__const uint32_t *) (a))[3] == 0) #define IN6_IS_ADDR_LOOPBACK(a) \ (((__const uint32_t *) (a))[0] == 0 \ && ((__const uint32_t *) (a))[1] == 0 \ && ((__const uint32_t *) (a))[2] == 0 \ && ((__const uint32_t *) (a))[3] == htonl (1)) #define IN6_IS_ADDR_MULTICAST(a) (((__const uint8_t *) (a))[0] == 0xff) #define IN6_IS_ADDR_LINKLOCAL(a) \ ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \ == htonl (0xfe800000)) #define IN6_IS_ADDR_SITELOCAL(a) \ ((((__const uint32_t *) (a))[0] & htonl (0xffc00000)) \ == htonl (0xfec00000)) #define IN6_IS_ADDR_V4MAPPED(a) \ ((((__const uint32_t *) (a))[0] == 0) \ && (((__const uint32_t *) (a))[1] == 0) \ && (((__const uint32_t *) (a))[2] == htonl (0xffff))) #define IN6_IS_ADDR_V4COMPAT(a) \ ((((__const uint32_t *) (a))[0] == 0) \ && (((__const uint32_t *) (a))[1] == 0) \ && (((__const uint32_t *) (a))[2] == 0) \ && (ntohl (((__const uint32_t *) (a))[3]) > 1)) #define IN6_ARE_ADDR_EQUAL(a,b) \ ((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \ && (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \ && (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \ && (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3])) /* old legacy bullshit */ int bindresvport(int sd, struct sockaddr_in* _sin); #define IN6_IS_ADDR_MC_NODELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) \ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x1)) #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) \ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x2)) #define IN6_IS_ADDR_MC_SITELOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) \ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x5)) #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ (IN6_IS_ADDR_MULTICAST(a) \ && ((((__const uint8_t *) (a))[1] & 0xf) == 0x8)) #define IN6_IS_ADDR_MC_GLOBAL(a) \ (IN6_IS_ADDR_MULTICAST(a) \ && ((((__const uint8_t *) (a))[1] & 0xf) == 0xe)) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/netinet/in_systm.h010064400000000000000000000000001173363226500170030ustar00dietlibc-0.33~cvs20120325/include/netinet/ip.h010064400000000000000000000076501173363226500155700ustar00#ifndef _NETINET_IP_H #define _NETINET_IP_H #include #include #include __BEGIN_DECLS #define IPVERSION 4 /* IP version number */ #define IP_MAXPACKET 65535 /* maximum packet size */ #define IPTOS_TOS_MASK 0x1E #define IPTOS_TOS(tos) ((tos)&IPTOS_TOS_MASK) #define IPTOS_LOWDELAY 0x10 #define IPTOS_THROUGHPUT 0x08 #define IPTOS_RELIABILITY 0x04 #define IPTOS_MINCOST 0x02 #define IPTOS_LOWCOST IPTOS_MINCOST #define IPTOS_PREC_MASK 0xE0 #define IPTOS_PREC(tos) ((tos)&IPTOS_PREC_MASK) #define IPTOS_PREC_NETCONTROL 0xe0 #define IPTOS_PREC_INTERNETCONTROL 0xc0 #define IPTOS_PREC_CRITIC_ECP 0xa0 #define IPTOS_PREC_FLASHOVERRIDE 0x80 #define IPTOS_PREC_FLASH 0x60 #define IPTOS_PREC_IMMEDIATE 0x40 #define IPTOS_PREC_PRIORITY 0x20 #define IPTOS_PREC_ROUTINE 0x00 /* IP options */ #define IPOPT_COPY 0x80 #define IPOPT_CLASS_MASK 0x60 #define IPOPT_NUMBER_MASK 0x1f #define IPOPT_COPIED(o) ((o)&IPOPT_COPY) #define IPOPT_CLASS(o) ((o)&IPOPT_CLASS_MASK) #define IPOPT_NUMBER(o) ((o)&IPOPT_NUMBER_MASK) #define IPOPT_CONTROL 0x00 #define IPOPT_RESERVED1 0x20 #define IPOPT_MEASUREMENT 0x40 #define IPOPT_RESERVED2 0x60 #define IPOPT_END (0 |IPOPT_CONTROL) #define IPOPT_NOOP (1 |IPOPT_CONTROL) #define IPOPT_SEC (2 |IPOPT_CONTROL|IPOPT_COPY) #define IPOPT_LSRR (3 |IPOPT_CONTROL|IPOPT_COPY) #define IPOPT_TIMESTAMP (4 |IPOPT_MEASUREMENT) #define IPOPT_RR (7 |IPOPT_CONTROL) #define IPOPT_SID (8 |IPOPT_CONTROL|IPOPT_COPY) #define IPOPT_SSRR (9 |IPOPT_CONTROL|IPOPT_COPY) #define IPOPT_RA (20|IPOPT_CONTROL|IPOPT_COPY) #define IPVERSION 4 #define MAXTTL 255 #define IPDEFTTL 64 /* struct timestamp, struct route and MAX_ROUTES are removed. REASONS: it is clear that nobody used them because: - MAX_ROUTES value was wrong. - "struct route" was wrong. - "struct timestamp" had fatally misaligned bitfields and was completely unusable. */ #define IPOPT_OPTVAL 0 #define IPOPT_OLEN 1 #define IPOPT_OFFSET 2 #define IPOPT_MINOFF 4 #define MAX_IPOPTLEN 40 #define IPOPT_NOP IPOPT_NOOP #define IPOPT_EOL IPOPT_END #define IPOPT_TS IPOPT_TIMESTAMP #define IPOPT_TS_TSONLY 0 /* timestamps only */ #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */ #define IPOPT_TS_PRESPEC 3 /* specified modules only */ struct iphdr { /* size 20/0x14 */ #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int ihl:4, version:4; /* offset 0; version=ip version (4) */ #else unsigned int version:4, ihl:4; /* offset 0; ihl=ip header length, measured in words (5) */ #endif unsigned char tos; /* offset 1 */ unsigned short tot_len; /* offset 2; total bytes in packet in network byte order */ unsigned short id; /* offset 4 */ unsigned short frag_off; /* offset 6 */ unsigned char ttl; /* offset 8 */ unsigned char protocol; /* offset 9; 1=ICMP, 6=TCP, 17=UDP (see netinet/in.h) */ unsigned short check; /* offset 10/0xa */ unsigned int saddr; /* offset 12/0xc */ unsigned int daddr; /* offset 16/0x10 */ /*The options start here. */ }; struct ip { #if __BYTE_ORDER == __LITTLE_ENDIAN unsigned int ip_hl:4; /* header length */ unsigned int ip_v:4; /* version */ #endif #if __BYTE_ORDER == __BIG_ENDIAN unsigned int ip_v:4; /* version */ unsigned int ip_hl:4; /* header length */ #endif unsigned char ip_tos; /* type of service */ unsigned short ip_len; /* total length */ unsigned short ip_id; /* identification */ unsigned short ip_off; /* fragment offset field */ #define IP_RF 0x8000 /* reserved fragment flag */ #define IP_DF 0x4000 /* dont fragment flag */ #define IP_MF 0x2000 /* more fragments flag */ #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */ unsigned char ip_ttl; /* time to live */ unsigned char ip_p; /* protocol */ unsigned short ip_sum; /* checksum */ struct in_addr ip_src, ip_dst; /* source and dest address */ }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/netinet/ip_icmp.h010064400000000000000000000130741173363226500165750ustar00#ifndef NETINET_IP_ICMP_H #define NETINET_IP_ICMP_H #include #include #include __BEGIN_DECLS struct icmphdr { uint8_t type; /* message type */ uint8_t code; /* type sub-code */ uint16_t checksum; union { struct { uint16_t id; uint16_t sequence; } echo; /* echo datagram */ uint32_t gateway; /* gateway address */ struct { uint16_t __unused; uint16_t mtu; } frag; /* path mtu discovery */ } un; }; #define ICMP_ECHOREPLY 0 /* Echo Reply */ #define ICMP_DEST_UNREACH 3 /* Destination Unreachable */ #define ICMP_SOURCE_QUENCH 4 /* Source Quench */ #define ICMP_REDIRECT 5 /* Redirect (change route) */ #define ICMP_ECHO 8 /* Echo Request */ #define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */ #define ICMP_PARAMETERPROB 12 /* Parameter Problem */ #define ICMP_TIMESTAMP 13 /* Timestamp Request */ #define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */ #define ICMP_INFO_REQUEST 15 /* Information Request */ #define ICMP_INFO_REPLY 16 /* Information Reply */ #define ICMP_ADDRESS 17 /* Address Mask Request */ #define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */ #define NR_ICMP_TYPES 18 /* Codes for UNREACH. */ #define ICMP_NET_UNREACH 0 /* Network Unreachable */ #define ICMP_HOST_UNREACH 1 /* Host Unreachable */ #define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */ #define ICMP_PORT_UNREACH 3 /* Port Unreachable */ #define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */ #define ICMP_SR_FAILED 5 /* Source Route failed */ #define ICMP_NET_UNKNOWN 6 #define ICMP_HOST_UNKNOWN 7 #define ICMP_HOST_ISOLATED 8 #define ICMP_NET_ANO 9 #define ICMP_HOST_ANO 10 #define ICMP_NET_UNR_TOS 11 #define ICMP_HOST_UNR_TOS 12 #define ICMP_PKT_FILTERED 13 /* Packet filtered */ #define ICMP_PREC_VIOLATION 14 /* Precedence violation */ #define ICMP_PREC_CUTOFF 15 /* Precedence cut off */ #define NR_ICMP_UNREACH 15 /* instead of hardcoding immediate value */ /* Codes for REDIRECT. */ #define ICMP_REDIR_NET 0 /* Redirect Net */ #define ICMP_REDIR_HOST 1 /* Redirect Host */ #define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */ #define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */ /* Codes for TIME_EXCEEDED. */ #define ICMP_EXC_TTL 0 /* TTL count exceeded */ #define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */ /* * Lower bounds on packet lengths for various types. * For the error advice packets must first insure that the * packet is large enough to contain the returned ip header. * Only then can we do the check to see if 64 bits of packet * data have been returned, since we need to check the returned * ip header length. */ #define ICMP_MINLEN 8 /* abs minimum */ #define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */ #define ICMP_MASKLEN 12 /* address mask */ #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ #ifndef _IP_VHL #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) /* N.B.: must separately check that ip_hl >= 5 */ #else #define ICMP_ADVLEN(p) (8 + (IP_VHL_HL((p)->icmp_ip.ip_vhl) << 2) + 8) /* N.B.: must separately check that header length >= 5 */ #endif /* Definition of type and code fields. */ /* defined above: ICMP_ECHOREPLY, ICMP_REDIRECT, ICMP_ECHO */ #define ICMP_UNREACH 3 /* dest unreachable, codes: */ #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ #define ICMP_ROUTERADVERT 9 /* router advertisement */ #define ICMP_ROUTERSOLICIT 10 /* router solicitation */ #define ICMP_TIMXCEED 11 /* time exceeded, code: */ #define ICMP_PARAMPROB 12 /* ip header bad */ #define ICMP_TSTAMP 13 /* timestamp request */ #define ICMP_TSTAMPREPLY 14 /* timestamp reply */ #define ICMP_IREQ 15 /* information request */ #define ICMP_IREQREPLY 16 /* information reply */ #define ICMP_MASKREQ 17 /* address mask request */ #define ICMP_MASKREPLY 18 /* address mask reply */ #define ICMP_MAXTYPE 18 /* UNREACH codes */ #define ICMP_UNREACH_NET 0 /* bad net */ #define ICMP_UNREACH_HOST 1 /* bad host */ #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ #define ICMP_UNREACH_PORT 3 /* bad port */ #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ #define ICMP_UNREACH_NET_UNKNOWN 6 /* unknown net */ #define ICMP_UNREACH_HOST_UNKNOWN 7 /* unknown host */ #define ICMP_UNREACH_ISOLATED 8 /* src host isolated */ #define ICMP_UNREACH_NET_PROHIB 9 /* net denied */ #define ICMP_UNREACH_HOST_PROHIB 10 /* host denied */ #define ICMP_UNREACH_TOSNET 11 /* bad tos for net */ #define ICMP_UNREACH_TOSHOST 12 /* bad tos for host */ #define ICMP_UNREACH_FILTER_PROHIB 13 /* admin prohib */ #define ICMP_UNREACH_HOST_PRECEDENCE 14 /* host prec vio. */ #define ICMP_UNREACH_PRECEDENCE_CUTOFF 15 /* prec cutoff */ /* REDIRECT codes */ #define ICMP_REDIRECT_NET 0 /* for network */ #define ICMP_REDIRECT_HOST 1 /* for host */ #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ /* TIMEXCEED codes */ #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ /* PARAMPROB code */ #define ICMP_PARAMPROB_OPTABSENT 1 /* req. opt. absent */ #define ICMP_INFOTYPE(type) \ ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/netinet/tcp.h010064400000000000000000000105351173363226500157420ustar00#ifndef _NETINET_TCP_H #define _NETINET_TCP_H #include #include __BEGIN_DECLS struct tcphdr { /* size 20/0x14 40/0x28 with IP header */ uint16_t source; /* offset 0 20/0x14 */ uint16_t dest; /* offset 2 22/0x16 */ uint32_t seq; /* offset 4 24/0x18 */ uint32_t ack_seq; /* offset 8 28/0x1c */ #if __BYTE_ORDER == __LITTLE_ENDIAN uint16_t res1:4, doff:4, fin:1, syn:1, rst:1, psh:1, ack:1, urg:1, ece:1, cwr:1; #else uint16_t doff:4, res1:4, cwr:1, ece:1, urg:1, ack:1, psh:1, rst:1, syn:1, fin:1; #endif /* offset 12/0xc 32/0x20 */ uint16_t window; /* offset 14/0xe 34/0x22 */ uint16_t check; /* offset 16/0x10 36/0x24 */ uint16_t urg_ptr; /* offset 18/0x12 38/0x26 */ }; enum { TCP_ESTABLISHED = 1, TCP_SYN_SENT, TCP_SYN_RECV, TCP_FIN_WAIT1, TCP_FIN_WAIT2, TCP_TIME_WAIT, TCP_CLOSE, TCP_CLOSE_WAIT, TCP_LAST_ACK, TCP_LISTEN, TCP_CLOSING, /* now a valid state */ TCP_MAX_STATES /* Leave at the end! */ }; #define TCP_STATE_MASK 0xF #define TCP_ACTION_FIN (1 << 7) enum { TCPF_ESTABLISHED = (1 << 1), TCPF_SYN_SENT = (1 << 2), TCPF_SYN_RECV = (1 << 3), TCPF_FIN_WAIT1 = (1 << 4), TCPF_FIN_WAIT2 = (1 << 5), TCPF_TIME_WAIT = (1 << 6), TCPF_CLOSE = (1 << 7), TCPF_CLOSE_WAIT = (1 << 8), TCPF_LAST_ACK = (1 << 9), TCPF_LISTEN = (1 << 10), TCPF_CLOSING = (1 << 11) }; /* * The union cast uses a gcc extension to avoid aliasing problems * (union is compatible to any of its members) * This means this part of the code is -fstrict-aliasing safe now. */ union tcp_word_hdr { struct tcphdr hdr; uint32_t words[5]; }; #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3]) enum { #if __BYTE_ORDER == __LITTLE_ENDIAN TCP_FLAG_CWR = 0x00008000, TCP_FLAG_ECE = 0x00004000, TCP_FLAG_URG = 0x00002000, TCP_FLAG_ACK = 0x00001000, TCP_FLAG_PSH = 0x00000800, TCP_FLAG_RST = 0x00000400, TCP_FLAG_SYN = 0x00000200, TCP_FLAG_FIN = 0x00000100, TCP_RESERVED_BITS = 0x0000C00F, TCP_DATA_OFFSET = 0x000000F0 #else TCP_FLAG_CWR = 0x00800000, TCP_FLAG_ECE = 0x00400000, TCP_FLAG_URG = 0x00200000, TCP_FLAG_ACK = 0x00100000, TCP_FLAG_PSH = 0x00080000, TCP_FLAG_RST = 0x00040000, TCP_FLAG_SYN = 0x00020000, TCP_FLAG_FIN = 0x00010000, TCP_RESERVED_BITS = 0x0FC00000, TCP_DATA_OFFSET = 0xF0000000 #endif }; /* TCP socket options */ #define TCP_NODELAY 1 /* Turn off Nagle's algorithm. */ #define TCP_MAXSEG 2 /* Limit MSS */ #define TCP_CORK 3 /* Never send partially complete segments */ #define TCP_KEEPIDLE 4 /* Start keeplives after this period */ #define TCP_KEEPINTVL 5 /* Interval between keepalives */ #define TCP_KEEPCNT 6 /* Number of keepalives before death */ #define TCP_SYNCNT 7 /* Number of SYN retransmits */ #define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */ #define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */ #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */ #define TCP_INFO 11 /* Information about this connection. */ #define TCP_QUICKACK 12 /* Block/reenable quick acks */ #define TCPI_OPT_TIMESTAMPS 1 #define TCPI_OPT_SACK 2 #define TCPI_OPT_WSCALE 4 #define TCPI_OPT_ECN 8 enum tcp_ca_state { TCP_CA_Open = 0, #define TCPF_CA_Open (1< #include __BEGIN_DECLS struct udphdr { /* size 8 28/0x1c with IP header */ uint16_t source; /* offset 0 20/0x14 */ uint16_t dest; /* offset 2 22/0x16 */ uint16_t len; /* offset 4 24/0x18 */ uint16_t check; /* offset 6 26/0x1a */ }; #define SOL_UDP 17 /* sockopt level for UDP */ __END_DECLS #endif dietlibc-0.33~cvs20120325/include/netpacket/packet.h010064400000000000000000000020201173363226500167210ustar00#ifndef __NETPACKET_PACKET_H #define __NETPACKET_PACKET_H #include __BEGIN_DECLS struct sockaddr_ll { unsigned short int sll_family; unsigned short int sll_protocol; int sll_ifindex; unsigned short int sll_hatype; unsigned char sll_pkttype; unsigned char sll_halen; unsigned char sll_addr[8]; }; #define PACKET_HOST 0 /* To us. */ #define PACKET_BROADCAST 1 /* To all. */ #define PACKET_MULTICAST 2 /* To group. */ #define PACKET_OTHERHOST 3 /* To someone else. */ #define PACKET_OUTGOING 4 /* Originated by us. */ #define PACKET_LOOPBACK 5 #define PACKET_FASTROUTE 6 /* Packet socket options. */ #define PACKET_ADD_MEMBERSHIP 1 #define PACKET_DROP_MEMBERSHIP 2 #define PACKET_RECV_OUTPUT 3 #define PACKET_RX_RING 5 #define PACKET_STATISTICS 6 struct packet_mreq { int mr_ifindex; unsigned short int mr_type; unsigned short int mr_alen; unsigned char mr_address[8]; }; #define PACKET_MR_MULTICAST 0 #define PACKET_MR_PROMISC 1 #define PACKET_MR_ALLMULTI 2 __END_DECLS #endif dietlibc-0.33~cvs20120325/include/nl_types.h010064400000000000000000000012131173363226500153340ustar00#ifndef _NL_TYPES_H #define _NL_TYPES_H typedef enum { CODESET, D_T_FMT, D_FMT, T_FMT, T_FMT_AMPM, AM_STR, PM_STR, DAY_1, DAY_2, DAY_3, DAY_4, DAY_5, DAY_6, DAY_7, ABDAY_1, ABDAY_2, ABDAY_3, ABDAY_4, ABDAY_5, ABDAY_6, ABDAY_7, MON_1, MON_2, MON_3, MON_4, MON_5, MON_6, MON_7, MON_8, MON_9, MON_10, MON_11, MON_12, ABMON_1, ABMON_2, ABMON_3, ABMON_4, ABMON_5, ABMON_6, ABMON_7, ABMON_8, ABMON_9, ABMON_10, ABMON_11, ABMON_12, ERA, ERA_D_FMT, ERA_D_T_FMT, ERA_T_FMT, ALT_DIGITS, RADIXCHAR, THOUSEP, YESEXPR, NOEXPR, CRNCYSTR } nl_item; typedef void* nl_catd; enum { NL_SETD=0, NL_CAT_LOCALE=1 }; #endif dietlibc-0.33~cvs20120325/include/paths.h010064400000000000000000000014351173363226500146240ustar00#ifndef _PATHS_H #define _PATHS_H #define _PATH_BSHELL "/bin/sh" #define _PATH_DEFPATH "/bin:/usr/bin:" #define _PATH_DEVNULL "/dev/null" #define _PATH_CONSOLE "/dev/console" #define _PATH_PASSWD "/etc/passwd" #define _PATH_GROUP "/etc/group" #define _PATH_SHADOW "/etc/shadow" #define _PATH_SHELLS "/etc/shells" #define _PATH_VARRUN "/var/run/" /* puke */ #define _PATH_MAILDIR "/var/mail" #define _PATH_TTY "/dev/tty" #define _PATH_MNTTAB "/etc/fstab" #define _PATH_MOUNTED "/etc/mtab" #define _PATH_DEV "/dev/" #define _PATH_TMP "/tmp/" #define _PATH_UTMP "/var/run/utmp" #define _PATH_WTMP "/var/log/wtmp" #ifdef _BSD_SOURCE /* die, BSD, die!!! */ #define UTMP_FILE _PATH_UTMP #define WTMP_FILE _PATH_WTMP #endif #define _PATH_UTMPX _PATH_UTMP #define _PATH_WTMPX _PATH_WTMP #endif dietlibc-0.33~cvs20120325/include/poll.h010064400000000000000000000022351173363226500144520ustar00#ifndef _POLL_H #define _POLL_H #include __BEGIN_DECLS enum { POLLIN = 0x0001, #define POLLIN POLLIN POLLPRI = 0x0002, #define POLLPRI POLLPRI POLLOUT = 0x0004, #define POLLOUT POLLOUT POLLERR = 0x0008, #define POLLERR POLLERR POLLHUP = 0x0010, #define POLLHUP POLLHUP POLLNVAL = 0x0020, #define POLLNVAL POLLNVAL POLLRDNORM = 0x0040, #define POLLRDNORM POLLRDNORM POLLRDBAND = 0x0080, #define POLLRDBAND POLLRDBAND POLLWRBAND = 0x0200, #define POLLWRBAND POLLWRBAND POLLMSG = 0x0400, #define POLLMSG POLLMSG /* POLLREMOVE is for /dev/epoll (/dev/misc/eventpoll), * a new event notification mechanism for 2.6 */ POLLREMOVE = 0x1000, #define POLLREMOVE POLLREMOVE }; #if defined(__sparc__) || defined (__mips__) #define POLLWRNORM POLLOUT #else #define POLLWRNORM 0x0100 #endif struct pollfd { int fd; short events; short revents; }; typedef unsigned int nfds_t; extern int poll(struct pollfd *ufds, nfds_t nfds, int timeout) __THROW; #ifdef _GNU_SOURCE #include int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask) __THROW; #endif __END_DECLS #endif /* _POLL_H */ dietlibc-0.33~cvs20120325/include/pthread.h010064400000000000000000000166131173363226500151400ustar00#ifndef _PTHREAD_H #define _PTHREAD_H 1 #include #include #include __BEGIN_DECLS #define PTHREAD_STACK_SIZE 16384 #if defined(__alpha__) || defined(__x86_64__) || defined(__sparc64__) #define PTHREAD_STACK_MAXSIZE (32<<20) #elif defined(__ia64__) #define PTHREAD_STACK_MAXSIZE (16<<20) #else #define PTHREAD_STACK_MAXSIZE (8<<20) #endif #define PTHREAD_STACK_MINSIZE 16384 #define PTHREAD_THREADS_MAX 1024 #define MAX_SPIN_COUNT 50 #define SPIN_SLEEP_DURATION 2000001 #define PTHREAD_DESTRUCTOR_ITERATIONS 1 #define PTHREAD_KEYS_MAX 32 typedef struct _pthread_descr_struct*_pthread_descr; typedef int pthread_t; /* Fast locks */ #ifdef __hppa__ struct _pthread_fastlock { int __spinlock; } __attribute__((__aligned__(16))); #define PTHREAD_SPIN_LOCKED 0 #define PTHREAD_SPIN_UNLOCKED 1 #else struct _pthread_fastlock { int __spinlock; }; #define PTHREAD_SPIN_LOCKED 1 #define PTHREAD_SPIN_UNLOCKED 0 #endif /* Mutexes */ typedef struct { struct _pthread_fastlock lock; _pthread_descr owner; int kind; unsigned int count; } pthread_mutex_t; enum { PTHREAD_MUTEX_FAST_NP, #define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_RECURSIVE_NP, #define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_ERRORCHECK_NP, #define PTHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP }; enum { PTHREAD_PROCESS_PRIVATE, #define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_SHARED #define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED }; #define PTHREAD_MUTEX_INITIALIZER \ {{PTHREAD_SPIN_UNLOCKED},0,PTHREAD_MUTEX_FAST_NP,0} #define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ {{PTHREAD_SPIN_UNLOCKED},0,PTHREAD_MUTEX_RECURSIVE_NP,0} #define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ {{PTHREAD_SPIN_UNLOCKED},0,PTHREAD_MUTEX_ERRORCHECK_NP,0} typedef struct { int __mutexkind; } pthread_mutexattr_t; int pthread_mutexattr_init(pthread_mutexattr_t*attr); int pthread_mutexattr_destroy(pthread_mutexattr_t*attr); int pthread_mutexattr_getkind_np(const pthread_mutexattr_t*attr,int*kind); int pthread_mutexattr_setkind_np(pthread_mutexattr_t*attr,int kind); int pthread_mutex_init(pthread_mutex_t*mutex, const pthread_mutexattr_t*mutexattr); int pthread_mutex_lock(pthread_mutex_t*mutex); int pthread_mutex_unlock(pthread_mutex_t*mutex); int pthread_mutex_trylock(pthread_mutex_t*mutex); int pthread_mutex_destroy(pthread_mutex_t*mutex); /* Conditions */ typedef void* pthread_condattr_t; typedef struct { struct _pthread_fastlock lock; _pthread_descr wait_chain; } pthread_cond_t; #define PTHREAD_COND_INITIALIZER \ {{PTHREAD_SPIN_UNLOCKED},0} int pthread_cond_init(pthread_cond_t*cond,pthread_condattr_t*cond_attr); int pthread_cond_destroy(pthread_cond_t*cond); int pthread_cond_signal(pthread_cond_t*cond); int pthread_cond_broadcast(pthread_cond_t*cond); int pthread_cond_timedwait(pthread_cond_t*cond,pthread_mutex_t*mutex, const struct timespec*abstime); int pthread_cond_wait(pthread_cond_t*cond,pthread_mutex_t*mutex); /* only for completeness (always return NULL) */ int pthread_condattr_init(pthread_condattr_t*attr); int pthread_condattr_destroy(pthread_condattr_t*attr); int pthread_condattr_getpshared(const pthread_condattr_t*attr,int*pshared); int pthread_condattr_setpshared(pthread_condattr_t*attr,int pshared); /* thread specific variables */ typedef unsigned int pthread_key_t; int pthread_key_create(pthread_key_t*key,void(*destructor)(void*)); int pthread_key_delete(pthread_key_t key); int pthread_setspecific(pthread_key_t key,const void*value); void*pthread_getspecific(pthread_key_t key); /* Attributes for threads. */ typedef struct { int __detachstate; int __schedpolicy; struct sched_param __schedparam; int __inheritsched; int __scope; void * __stackaddr; unsigned long __stacksize; } pthread_attr_t; enum { PTHREAD_CREATE_JOINABLE, #define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_DETACHED #define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED }; enum { PTHREAD_EXPLICIT_SCHED, #define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED PTHREAD_INHERIT_SCHED #define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED }; enum { /* for completeness */ PTHREAD_SCOPE_SYSTEM, #define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_PROCESS #define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS }; int pthread_attr_init(pthread_attr_t*attr); int pthread_attr_destroy(pthread_attr_t*attr); int pthread_attr_setdetachstate(pthread_attr_t*attr,const int detachstate); int pthread_attr_getdetachstate(const pthread_attr_t*attr,int*detachstate); int pthread_attr_setschedpolicy(pthread_attr_t*attr,const int policy); int pthread_attr_getschedpolicy(const pthread_attr_t*attr,int*policy); int pthread_attr_setschedparam(pthread_attr_t*attr, const struct sched_param*param); int pthread_attr_getschedparam(const pthread_attr_t*attr, struct sched_param*param); int pthread_attr_setinheritsched(pthread_attr_t*attr,const int inherit); int pthread_attr_getinheritsched(const pthread_attr_t*attr,int*inherit); int pthread_attr_setscope(pthread_attr_t*attr,const int scope); int pthread_attr_getscope(const pthread_attr_t*attr,int*scope); int pthread_attr_setstackaddr(pthread_attr_t*attr,void*stack); int pthread_attr_getstackaddr(const pthread_attr_t*attr,void**stack); int pthread_attr_setstacksize(pthread_attr_t*attr,const size_t stacksize); int pthread_attr_getstacksize(const pthread_attr_t*attr,size_t*stacksize); int pthread_setschedparam(const pthread_t target_thread,const int policy, const struct sched_param*param); int pthread_getschedparam(const pthread_t target_thread,int*policy, struct sched_param*param); /* ONCE */ typedef int pthread_once_t; #define PTHREAD_ONCE_INIT PTHREAD_SPIN_UNLOCKED int pthread_once(pthread_once_t*once_control,void(*init_routine)(void)); /* CANCEL */ enum { PTHREAD_CANCEL_ENABLE, #define PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_DISABLE, #define PTHREAD_CANCEL_DISABLE PTHREAD_CANCEL_DISABLE }; enum { PTHREAD_CANCEL_DEFERRED, #define PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_ASYNCHRONOUS, #define PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ASYNCHRONOUS }; #define PTHREAD_CANCELED ((void *) -1) int pthread_kill(pthread_t thread,int sig); int pthread_cancel(pthread_t thread); int pthread_setcancelstate(int state,int*oldstate); int pthread_setcanceltype(int type,int*oldtype); void pthread_testcancel(void); /* CLEANUP */ void pthread_cleanup_push(void(*routine)(void*),void*arg); void pthread_cleanup_pop(int execute); void pthread_cleanup_push_defer_np(void(*routine)(void*),void*arg); void pthread_cleanup_pop_restore_np(int execute); /* FORK */ int pthread_atfork(void(*prepare)(void),void(*parent)(void), void(*child)(void)); /* THREADS */ pthread_t pthread_self(void); int pthread_create(pthread_t*__threadarg, const pthread_attr_t*__attr, void*(*__start_routine)(void *), void*__arg); void pthread_exit(void*__retval) __attribute__((__noreturn__)); int pthread_join(pthread_t __th,void**__thread_return); int pthread_detach(pthread_t __th); int pthread_equal(pthread_t __thread1,pthread_t __thread2); int pthread_sigmask(int how,const sigset_t*newset,sigset_t*oldset); /* these two aren't actually supported right now */ int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr, int *restrict type); int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/pty.h010064400000000000000000000006451173363226500143230ustar00#ifndef _PTY_H #define _PTY_H #include #include __BEGIN_DECLS /* Create pseudo tty master slave pair with NAME and set terminal * attributes according to TERMP and WINP and return handles for both * ends in AMASTER and ASLAVE. */ extern int openpty (int *__amaster, int *__aslave, char *__name, struct termios *__termp, struct winsize *__winp) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/pwd.h010064400000000000000000000024301173363226500142730ustar00#ifndef _PWD_H #define _PWD_H #include #include #include __BEGIN_DECLS struct passwd { char *pw_name; /* Username. */ char *pw_passwd; /* Password. */ uid_t pw_uid; /* User ID. */ gid_t pw_gid; /* Group ID. */ char *pw_gecos; /* Real name. */ char *pw_dir; /* Home directory. */ char *pw_shell; /* Shell program. */ }; extern struct passwd *getpwuid (uid_t uid) __THROW; extern struct passwd *getpwnam (const char *name) __THROW; extern struct passwd *getpwent(void) __THROW; extern void setpwent(void) __THROW; extern void endpwent(void) __THROW; extern int putpwent(const struct passwd *p, FILE *stream) __THROW __attribute_dontuse__; int getpwent_r(struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) __THROW; int getpwnam_r(const char* name, struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) __THROW; int getpwuid_r(uid_t uid, struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) __THROW; /* NON STANDARD */ extern struct passwd *fgetpwent(FILE * fp); extern void fsetpwent(int fd) __THROW; extern int fgetpwent_r(int fd,struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/regex.h010064400000000000000000000040721173363226500146170ustar00#ifndef _REGEX_H #define _REGEX_H #include #include __BEGIN_DECLS typedef ptrdiff_t regoff_t; typedef struct { regoff_t rm_so; regoff_t rm_eo; } regmatch_t; #define REG_EXTENDED 1 #define REG_ICASE 2 #define REG_NOSUB 4 #define REG_NEWLINE 8 #define REG_NOTBOL 1 #define REG_NOTEOL 2 #define REG_NOMATCH -1 #define RE_DUP_MAX 8192 struct __regex_t; typedef int (*matcher)(void*,const char*,int ofs,struct __regex_t* t,int plus,int eflags); typedef struct __regex_t { struct regex { matcher m; void* next; int pieces; int num; struct branch* b; } r; int brackets,cflags; regmatch_t* l; } regex_t; #define re_nsub r.pieces int regcomp(regex_t* preg, const char* regex, int cflags) __THROW; int regexec(const regex_t* preg, const char* string, size_t nmatch, regmatch_t pmatch[], int eflags) __THROW; size_t regerror(int errcode, const regex_t* preg, char* errbuf, size_t errbuf_size) __THROW; void regfree(regex_t* preg) __THROW; enum __regex_errors { REG_NOERROR, REG_BADRPT, /* Invalid use of repetition operators such as using `*' as the first character. */ REG_BADBR, /* Invalid use of back reference operator. */ REG_EBRACE, /* Un-matched brace interval operators. */ REG_EBRACK, /* Un-matched bracket list operators. */ REG_ERANGE, /* Invalid use of the range operator, eg. the ending point of the range occurs prior to the starting point. */ REG_ECTYPE, /* Unknown character class name. */ REG_ECOLLATE, /* Invalid collating element. */ REG_EPAREN, /* Un-matched parenthesis group operators. */ REG_ESUBREG, /* Invalid back reference to a subexpression. */ REG_EEND, /* Non specific error. This is not defined by POSIX.2. */ REG_EESCAPE, /* Trailing backslash. */ REG_BADPAT, /* Invalid use of pattern operators such as group or list. */ REG_ESIZE, /* Compiled regular expression requires a pattern buffer larger than 64Kb. This is not defined by POSIX.2. */ REG_ESPACE /* regcomp ran out of space */ }; char* re_comp(char* regex); int re_exec(char* string); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/resolv.h010064400000000000000000000107161173363226500150210ustar00#ifndef _RESOLV_H #define _RESOLV_H #include #include #include #include __BEGIN_DECLS #ifndef _PATH_RESCONF #define _PATH_RESCONF "/etc/resolv.conf" #endif /* * Global defines and variables for resolver stub. */ #define MAXNS 8 /* max # name servers we'll track */ #define MAXDFLSRCH 3 /* # default domain levels to try */ #define MAXDNSRCH 6 /* max # domains in search path */ #define LOCALDOMAINPARTS 2 /* min levels in name that is "local" */ #define RES_TIMEOUT 5 /* min. seconds between retries */ #define MAXRESOLVSORT 10 /* number of net to sort on */ #define RES_MAXNDOTS 15 /* should reflect bit field size */ typedef struct __res_state { int retrans; /* retransmission time interval */ int retry; /* number of times to retransmit */ unsigned long options; /* option flags - see below. */ int nscount; /* number of name servers */ struct sockaddr_in_pad nsaddr_list[MAXNS]; /* address of name server */ #define nsaddr nsaddr_list[0] /* for backward compatibility */ unsigned short id; /* current message id */ char *dnsrch[MAXDNSRCH+1]; /* components of domain to search */ char defdname[256]; /* default domain (deprecated) */ unsigned long pfcode; /* RES_PRF_ flags - see below. */ unsigned ndots:4; /* threshold for initial abs. query */ unsigned nsort:4; /* number of elements in sort_list[] */ char unused[3]; struct { struct in_addr addr; uint32_t mask; } sort_list[MAXRESOLVSORT]; char pad[72]; /* on an i386 this means 512b total */ } * res_state; /* * Resolver options (keep these in synch with res_debug.c, please) */ #define RES_INIT 0x00000001 /* address initialized */ #define RES_DEBUG 0x00000002 /* print debug messages */ #define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/ #define RES_USEVC 0x00000008 /* use virtual circuit */ #define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */ #define RES_IGNTC 0x00000020 /* ignore trucation errors */ #define RES_RECURSE 0x00000040 /* recursion desired */ #define RES_DEFNAMES 0x00000080 /* use default domain name */ #define RES_STAYOPEN 0x00000100 /* Keep TCP socket open */ #define RES_DNSRCH 0x00000200 /* search up local domain tree */ #define RES_INSECURE1 0x00000400 /* type 1 security disabled */ #define RES_INSECURE2 0x00000800 /* type 2 security disabled */ #define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */ #define RES_USE_INET6 0x00002000 /* use/map IPv6 in gethostbyname() */ #define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH) /* * Resolver "pfcode" values. Used by dig. */ #define RES_PRF_STATS 0x00000001 /* 0x00000002 */ #define RES_PRF_CLASS 0x00000004 #define RES_PRF_CMD 0x00000008 #define RES_PRF_QUES 0x00000010 #define RES_PRF_ANS 0x00000020 #define RES_PRF_AUTH 0x00000040 #define RES_PRF_ADD 0x00000080 #define RES_PRF_HEAD1 0x00000100 #define RES_PRF_HEAD2 0x00000200 #define RES_PRF_TTLID 0x00000400 #define RES_PRF_HEADX 0x00000800 #define RES_PRF_QUERY 0x00001000 #define RES_PRF_REPLY 0x00002000 #define RES_PRF_INIT 0x00004000 /* 0x00008000 */ struct res_sym { int number; /* Identifying number, like T_MX */ char * name; /* Its symbolic name, like "MX" */ char * humanname; /* Its fun name, like "mail exchanger" */ }; extern struct __res_state _res; extern const struct res_sym __p_class_syms[]; extern const struct res_sym __p_type_syms[]; int res_init(void) __THROW; int res_query(const char *dname, int _class, int type, unsigned char *answer, int anslen) __THROW; int res_search(const char *dname, int _class, int type, unsigned char *answer, int anslen) __THROW; int res_querydomain(const char *name, const char *domain, int _class, int type, unsigned char *answer, int anslen) __THROW; int res_mkquery(int op, const char *dname, int _class, int type, char *data, int datalen, const unsigned char* newrr, char *buf, int buflen) __THROW; int res_send(const char *msg, int msglen, char *answer, int anslen) __THROW; int dn_comp(unsigned char *msg, unsigned char *comp_dn, int length, unsigned char **dnptrs, unsigned char *exp_dn, unsigned char **lastdnptr) __THROW; int dn_expand(const unsigned char *msg, const unsigned char *eomorig, const unsigned char *comp_dn, unsigned char *exp_dn, int length) __THROW; void res_close(void) __THROW __attribute_dontuse__; int dn_skipname(const unsigned char* cur,const unsigned char* eom) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/rpc/auth.h010064400000000000000000000145451173363226500152400ustar00/* @(#)auth.h 2.3 88/08/07 4.0 RPCSRC; from 1.17 88/02/08 SMI */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * auth.h, Authentication interface. * * Copyright (C) 1984, Sun Microsystems, Inc. * * The data structures are completely opaque to the client. The client * is required to pass a AUTH * to routines that create rpc * "sessions". */ #ifndef _RPC_AUTH_H #define _RPC_AUTH_H 1 #include #include #include __BEGIN_DECLS #define MAX_AUTH_BYTES 400 #define MAXNETNAMELEN 255 /* maximum length of network user's name */ /* * Status returned from authentication check */ enum auth_stat { AUTH_OK=0, /* * failed at remote end */ AUTH_BADCRED=1, /* bogus credentials (seal broken) */ AUTH_REJECTEDCRED=2, /* client should begin new session */ AUTH_BADVERF=3, /* bogus verifier (seal broken) */ AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */ AUTH_TOOWEAK=5, /* rejected due to security reasons */ /* * failed locally */ AUTH_INVALIDRESP=6, /* bogus response verifier */ AUTH_FAILED=7 /* some unknown reason */ }; union des_block { struct { uint32_t high; uint32_t low; } key; char c[8]; }; typedef union des_block des_block; extern bool_t xdr_des_block (XDR *__xdrs, des_block *__blkp) __THROW; /* * Authentication info. Opaque to client. */ struct opaque_auth { enum_t oa_flavor; /* flavor of auth */ char* oa_base; /* address of more auth stuff */ unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */ }; /* * Auth handle, interface to client side authenticators. */ typedef struct AUTH AUTH; struct AUTH { struct opaque_auth ah_cred; struct opaque_auth ah_verf; union des_block ah_key; struct auth_ops { void (*ah_nextverf) (AUTH *); int (*ah_marshal) (AUTH *, XDR *); /* nextverf & serialize */ int (*ah_validate) (AUTH *, struct opaque_auth *); /* validate verifier */ int (*ah_refresh) (AUTH *); /* refresh credentials */ void (*ah_destroy) (AUTH *); /* destroy this structure */ } *ah_ops; char* ah_private; }; /* * Authentication ops. * The ops and the auth handle provide the interface to the authenticators. * * AUTH *auth; * XDR *xdrs; * struct opaque_auth verf; */ #define AUTH_NEXTVERF(auth) \ ((*((auth)->ah_ops->ah_nextverf))(auth)) #define auth_nextverf(auth) \ ((*((auth)->ah_ops->ah_nextverf))(auth)) #define AUTH_MARSHALL(auth, xdrs) \ ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) #define auth_marshall(auth, xdrs) \ ((*((auth)->ah_ops->ah_marshal))(auth, xdrs)) #define AUTH_VALIDATE(auth, verfp) \ ((*((auth)->ah_ops->ah_validate))((auth), verfp)) #define auth_validate(auth, verfp) \ ((*((auth)->ah_ops->ah_validate))((auth), verfp)) #define AUTH_REFRESH(auth) \ ((*((auth)->ah_ops->ah_refresh))(auth)) #define auth_refresh(auth) \ ((*((auth)->ah_ops->ah_refresh))(auth)) #define AUTH_DESTROY(auth) \ ((*((auth)->ah_ops->ah_destroy))(auth)) #define auth_destroy(auth) \ ((*((auth)->ah_ops->ah_destroy))(auth)) extern struct opaque_auth _null_auth; /* * These are the various implementations of client side authenticators. */ /* * Unix style authentication * AUTH *authunix_create(machname, uid, gid, len, aup_gids) * char *machname; * int uid; * int gid; * int len; * int *aup_gids; */ extern AUTH *authunix_create (char *__machname,uid_t __uid, gid_t __gid, int __len, gid_t *__aup_gids) __THROW; extern AUTH *authunix_create_default (void) __THROW; extern AUTH *authnone_create (void) __THROW; extern AUTH *authdes_create (const char *__servername, unsigned int __window, struct sockaddr *__syncaddr, des_block *__ckey) __THROW; extern AUTH *authdes_pk_create (const char *, netobj *, unsigned int, struct sockaddr *, des_block *) __THROW; #define AUTH_NONE 0 /* no authentication */ #define AUTH_NULL 0 /* backward compatibility */ #define AUTH_SYS 1 /* unix style (uid, gids) */ #define AUTH_UNIX AUTH_SYS #define AUTH_SHORT 2 /* short hand unix style */ #define AUTH_DES 3 /* des style (encrypted timestamps) */ #define AUTH_DH AUTH_DES /* Diffie-Hellman (this is DES) */ #define AUTH_KERB 4 /* kerberos style */ /* * Netname manipulating functions * */ extern int getnetname (char *) __THROW; extern int host2netname (char *, const char *, const char *) __THROW; extern int user2netname (char *, const uid_t, const char *) __THROW; extern int netname2user (const char *, uid_t *, gid_t *, int *, gid_t *) __THROW; extern int netname2host (const char *, char *, const int) __THROW; /* * * These routines interface to the keyserv daemon * */ extern int key_decryptsession (char *, des_block *) __THROW; extern int key_decryptsession_pk (char *, netobj *, des_block *) __THROW; extern int key_encryptsession (char *, des_block *) __THROW; extern int key_encryptsession_pk (char *, netobj *, des_block *) __THROW; extern int key_gendes (des_block *) __THROW; extern int key_setsecret (char *) __THROW; extern int key_secretkey_is_set (void) __THROW; extern int key_get_conv (char *, des_block *) __THROW; /* * XDR an opaque authentication struct. */ extern bool_t xdr_opaque_auth (XDR *, struct opaque_auth *) __THROW; __END_DECLS #endif /* rpc/auth.h */ dietlibc-0.33~cvs20120325/include/rpc/auth_des.h010064400000000000000000000071251173363226500160670ustar00/* Copyright (C) 1996, 1997, 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _RPC_AUTH_DES_H #define _RPC_AUTH_DES_H 1 #include #include __BEGIN_DECLS /* There are two kinds of "names": fullnames and nicknames */ enum authdes_namekind { ADN_FULLNAME, ADN_NICKNAME }; /* A fullname contains the network name of the client, a conversation key and the window */ struct authdes_fullname { char *name; /* network name of client, up to MAXNETNAMELEN */ des_block key; /* conversation key */ uint32_t window; /* associated window */ }; /* A credential */ struct authdes_cred { enum authdes_namekind adc_namekind; struct authdes_fullname adc_fullname; uint32_t adc_nickname; }; /* A timeval replacement for !32bit platforms */ struct rpc_timeval { uint32_t tv_sec; /* Seconds. */ uint32_t tv_usec; /* Microseconds. */ }; /* A des authentication verifier */ struct authdes_verf { union { struct rpc_timeval adv_ctime; /* clear time */ des_block adv_xtime; /* crypt time */ } adv_time_u; uint32_t adv_int_u; }; /* des authentication verifier: client variety adv_timestamp is the current time. adv_winverf is the credential window + 1. Both are encrypted using the conversation key. */ #define adv_timestamp adv_time_u.adv_ctime #define adv_xtimestamp adv_time_u.adv_xtime #define adv_winverf adv_int_u /* des authentication verifier: server variety adv_timeverf is the client's timestamp + client's window adv_nickname is the server's nickname for the client. adv_timeverf is encrypted using the conversation key. */ #define adv_timeverf adv_time_u.adv_ctime #define adv_xtimeverf adv_time_u.adv_xtime #define adv_nickname adv_int_u /* Map a des credential into a unix cred. */ extern int authdes_getucred (const struct authdes_cred * __adc, uid_t * __uid, gid_t * __gid, short *__grouplen, gid_t * __groups) __THROW; /* Get the public key for NAME and place it in KEY. NAME can only be up to MAXNETNAMELEN bytes long and the destination buffer KEY should have HEXKEYBYTES + 1 bytes long to fit all characters from the key. */ extern int getpublickey (const char *__name, char *__key) __THROW; /* Get the secret key for NAME and place it in KEY. PASSWD is used to decrypt the encrypted key stored in the database. NAME can only be up to MAXNETNAMELEN bytes long and the destination buffer KEY should have HEXKEYBYTES + 1 bytes long to fit all characters from the key. */ extern int getsecretkey (const char *__name, char *__key, const char *__passwd) __THROW; extern int rtime (struct sockaddr_in *__addrp, struct rpc_timeval *__timep, struct rpc_timeval *__timeout) __THROW; __END_DECLS #endif /* rpc/auth_des.h */ dietlibc-0.33~cvs20120325/include/rpc/auth_unix.h010064400000000000000000000052501173363226500162740ustar00/* @(#)auth_unix.h 2.2 88/07/29 4.0 RPCSRC; from 1.8 88/02/08 SMI */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* @(#)auth_unix.h 1.5 86/07/16 SMI */ /* * auth_unix.h, Protocol for UNIX style authentication parameters for RPC * * Copyright (C) 1984, Sun Microsystems, Inc. */ /* * The system is very weak. The client uses no encryption for it * credentials and only sends null verifiers. The server sends backs * null verifiers or optionally a verifier that suggests a new short hand * for the credentials. */ #ifndef _RPC_AUTH_UNIX_H #define _RPC_AUTH_UNIX_H 1 #include #include #include #include #include __BEGIN_DECLS /* The machine name is part of a credential; it may not exceed 255 bytes */ #define MAX_MACHINE_NAME 255 /* gids compose part of a credential; there may not be more than 16 of them */ #define NGRPS 16 /* * Unix style credentials. */ struct authunix_parms { unsigned long aup_time; char *aup_machname; uid_t aup_uid; gid_t aup_gid; unsigned int aup_len; gid_t *aup_gids; }; extern bool_t xdr_authunix_parms (XDR *__xdrs, struct authunix_parms *__p) __THROW; /* * If a response verifier has flavor AUTH_SHORT, * then the body of the response verifier encapsulates the following structure; * again it is serialized in the obvious fashion. */ struct short_hand_verf { struct opaque_auth new_cred; }; __END_DECLS #endif /* rpc/auth_unix.h */ dietlibc-0.33~cvs20120325/include/rpc/clnt.h010064400000000000000000000306221173363226500152310ustar00/* @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC; from 1.31 88/02/08 SMI*/ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * clnt.h - Client side remote procedure call interface. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_CLNT_H #define _RPC_CLNT_H 1 #include #include #include #include #include __BEGIN_DECLS /* * Rpc calls return an enum clnt_stat. This should be looked at more, * since each implementation is required to live with this (implementation * independent) list of errors. */ enum clnt_stat { RPC_SUCCESS=0, /* call succeeded */ /* * local errors */ RPC_CANTENCODEARGS=1, /* can't encode arguments */ RPC_CANTDECODERES=2, /* can't decode results */ RPC_CANTSEND=3, /* failure in sending call */ RPC_CANTRECV=4, /* failure in receiving result */ RPC_TIMEDOUT=5, /* call timed out */ /* * remote errors */ RPC_VERSMISMATCH=6, /* rpc versions not compatible */ RPC_AUTHERROR=7, /* authentication error */ RPC_PROGUNAVAIL=8, /* program not available */ RPC_PROGVERSMISMATCH=9, /* program version mismatched */ RPC_PROCUNAVAIL=10, /* procedure unavailable */ RPC_CANTDECODEARGS=11, /* decode arguments error */ RPC_SYSTEMERROR=12, /* generic "other problem" */ RPC_NOBROADCAST = 21, /* Broadcasting not supported */ /* * callrpc & clnt_create errors */ RPC_UNKNOWNHOST=13, /* unknown host name */ RPC_UNKNOWNPROTO=17, /* unknown protocol */ RPC_UNKNOWNADDR = 19, /* Remote address unknown */ /* * rpcbind errors */ RPC_RPCBFAILURE=14, /* portmapper failed in its call */ #define RPC_PMAPFAILURE RPC_RPCBFAILURE RPC_PROGNOTREGISTERED=15, /* remote program is not registered */ RPC_N2AXLATEFAILURE = 22, /* Name to addr translation failed */ /* * unspecified error */ RPC_FAILED=16, RPC_INTR=18, RPC_TLIERROR=20, RPC_UDERROR=23, /* * asynchronous errors */ RPC_INPROGRESS = 24, RPC_STALERACHANDLE = 25 }; /* * Error info. */ struct rpc_err { enum clnt_stat re_status; union { int RE_errno; /* related system error */ enum auth_stat RE_why; /* why the auth error occurred */ struct { unsigned long low; /* lowest verion supported */ unsigned long high; /* highest verion supported */ } RE_vers; struct { /* maybe meaningful if RPC_FAILED */ long s1; long s2; } RE_lb; /* life boot & debugging only */ } ru; #define re_errno ru.RE_errno #define re_why ru.RE_why #define re_vers ru.RE_vers #define re_lb ru.RE_lb }; /* * Client rpc handle. * Created by individual implementations, see e.g. rpc_udp.c. * Client is responsible for initializing auth, see e.g. auth_none.c. */ typedef struct CLIENT CLIENT; struct CLIENT { AUTH *cl_auth; /* authenticator */ struct clnt_ops { enum clnt_stat (*cl_call) (CLIENT *, unsigned long, xdrproc_t, char*, xdrproc_t, char*, struct timeval); /* call remote procedure */ void (*cl_abort) (void); /* abort a call */ void (*cl_geterr) (CLIENT *, struct rpc_err *); /* get specific error code */ bool_t (*cl_freeres) (CLIENT *, xdrproc_t, char*); /* frees results */ void (*cl_destroy) (CLIENT *); /* destroy this structure */ bool_t (*cl_control) (CLIENT *, int, char *); /* the ioctl() of rpc */ } *cl_ops; char* cl_private; /* private stuff */ }; /* * client side rpc interface ops * * Parameter types are: * */ /* * enum clnt_stat * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout) * CLIENT *rh; * unsigned long proc; * xdrproc_t xargs; * char* argsp; * xdrproc_t xres; * char* resp; * struct timeval timeout; */ #define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \ ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) #define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \ ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, argsp, xres, resp, secs)) /* * void * CLNT_ABORT(rh); * CLIENT *rh; */ #define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh)) #define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh)) /* * struct rpc_err * CLNT_GETERR(rh); * CLIENT *rh; */ #define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) #define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp)) /* * bool_t * CLNT_FREERES(rh, xres, resp); * CLIENT *rh; * xdrproc_t xres; * char* resp; */ #define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) #define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp)) /* * bool_t * CLNT_CONTROL(cl, request, info) * CLIENT *cl; * unsigned int request; * char *info; */ #define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) #define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in)) /* * control operations that apply to all transports * * Note: options marked XXX are no-ops in this implementation of RPC. * The are present in TI-RPC but can't be implemented here since they * depend on the presence of STREAMS/TLI, which we don't have. */ #define CLSET_TIMEOUT 1 /* set timeout (timeval) */ #define CLGET_TIMEOUT 2 /* get timeout (timeval) */ #define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */ #define CLGET_FD 6 /* get connections file descriptor */ #define CLGET_SVC_ADDR 7 /* get server's address (netbuf) XXX */ #define CLSET_FD_CLOSE 8 /* close fd while clnt_destroy */ #define CLSET_FD_NCLOSE 9 /* Do not close fd while clnt_destroy*/ #define CLGET_XID 10 /* Get xid */ #define CLSET_XID 11 /* Set xid */ #define CLGET_VERS 12 /* Get version number */ #define CLSET_VERS 13 /* Set version number */ #define CLGET_PROG 14 /* Get program number */ #define CLSET_PROG 15 /* Set program number */ #define CLSET_SVC_ADDR 16 /* get server's address (netbuf) XXX */ #define CLSET_PUSH_TIMOD 17 /* push timod if not already present XXX */ #define CLSET_POP_TIMOD 18 /* pop timod XXX */ /* * Connectionless only control operations */ #define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */ #define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */ /* * void * CLNT_DESTROY(rh); * CLIENT *rh; */ #define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) #define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh)) /* * RPCTEST is a test program which is accessible on every rpc * transport/port. It is used for testing, performance evaluation, * and network administration. */ #define RPCTEST_PROGRAM ((unsigned long)1) #define RPCTEST_VERSION ((unsigned long)1) #define RPCTEST_NULL_PROC ((unsigned long)2) #define RPCTEST_NULL_BATCH_PROC ((unsigned long)3) /* * By convention, procedure 0 takes null arguments and returns them */ #define NULLPROC ((unsigned long)0) /* * Below are the client handle creation routines for the various * implementations of client side rpc. They can return NULL if a * creation failure occurs. */ /* * Memory based rpc (for speed check and testing) * CLIENT * * clntraw_create(prog, vers) * unsigned long prog; * unsigned long vers; */ extern CLIENT *clntraw_create (const unsigned long __prog, const unsigned long __vers) __THROW; /* * Generic client creation routine. Supported protocols are "udp", "tcp" and * "unix" * CLIENT * * clnt_create(host, prog, vers, prot) * char *host; -- hostname * unsigned long prog; -- program number * u_ong vers; -- version number * char *prot; -- protocol */ extern CLIENT *clnt_create (const char *__host, const unsigned long __prog, const unsigned long __vers, const char *__prot) __THROW; /* * TCP based rpc * CLIENT * * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) * struct sockaddr_in *raddr; * unsigned long prog; * unsigned long version; * register int *sockp; * unsigned int sendsz; * unsigned int recvsz; */ extern CLIENT *clnttcp_create (struct sockaddr_in *__raddr, unsigned long __prog, unsigned long __version, int *__sockp, unsigned int __sendsz, unsigned int __recvsz) __THROW; /* * UDP based rpc. * CLIENT * * clntudp_create(raddr, program, version, wait, sockp) * struct sockaddr_in *raddr; * unsigned long program; * unsigned long version; * struct timeval wait_resend; * int *sockp; * * Same as above, but you specify max packet sizes. * CLIENT * * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz) * struct sockaddr_in *raddr; * unsigned long program; * unsigned long version; * struct timeval wait_resend; * int *sockp; * unsigned int sendsz; * unsigned int recvsz; */ extern CLIENT *clntudp_create (struct sockaddr_in *__raddr, unsigned long __program, unsigned long __version, struct timeval __wait_resend, int *__sockp) __THROW; extern CLIENT *clntudp_bufcreate (struct sockaddr_in *__raddr, unsigned long __program, unsigned long __version, struct timeval __wait_resend, int *__sockp, unsigned int __sendsz, unsigned int __recvsz) __THROW; /* * AF_UNIX based rpc * CLIENT * * clntunix_create(raddr, prog, vers, sockp, sendsz, recvsz) * struct sockaddr_un *raddr; * unsigned long prog; * unsigned long version; * register int *sockp; * unsigned int sendsz; * unsigned int recvsz; */ extern CLIENT *clntunix_create (struct sockaddr_un *__raddr, unsigned long __program, unsigned long __version, int *__sockp, unsigned int __sendsz, unsigned int __recvsz) __THROW; extern int callrpc (const char *__host, const unsigned long __prognum, const unsigned long __versnum, const unsigned long __procnum, const xdrproc_t __inproc, const char *__in, const xdrproc_t __outproc, char *__out) __THROW; extern int _rpc_dtablesize (void) __THROW; /* * Print why creation failed */ extern void clnt_pcreateerror (const char *__msg) __THROW; /* stderr */ extern char *clnt_spcreateerror(const char *__msg) __THROW; /* string */ /* * Like clnt_perror(), but is more verbose in its output */ extern void clnt_perrno (enum clnt_stat __num) __THROW; /* stderr */ /* * Print an English error message, given the client error code */ extern void clnt_perror (CLIENT *__clnt, const char *__msg) __THROW; /* stderr */ extern char *clnt_sperror (CLIENT *__clnt, const char *__msg) __THROW; /* string */ /* * If a creation fails, the following allows the user to figure out why. */ struct rpc_createerr { enum clnt_stat cf_stat; struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */ }; extern struct rpc_createerr rpc_createerr; /* * Copy error message to buffer. */ extern char *clnt_sperrno (enum clnt_stat __num) __THROW; /* string */ /* * get the port number on the host for the rpc program,version and proto */ extern int getrpcport (const char * __host, unsigned long __prognum, unsigned long __versnum, unsigned int proto) __THROW; /* * get the local host's IP address without consulting * name service library functions */ extern void get_myaddress (struct sockaddr_in *) __THROW; #define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */ #define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */ __END_DECLS #endif /* rpc/clnt.h */ dietlibc-0.33~cvs20120325/include/rpc/des_crypt.h010064400000000000000000000060351173363226500162660ustar00/* * @(#)des_crypt.h 2.1 88/08/11 4.0 RPCSRC; from 1.4 88/02/08 (C) 1986 SMI * * des_crypt.h, des library routine interface * Copyright (C) 1986, Sun Microsystems, Inc. */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ #ifndef __DES_CRYPT_H__ #define __DES_CRYPT_H__ 1 #include __BEGIN_DECLS #define DES_MAXDATA 8192 /* max bytes encrypted in one call */ #define DES_DIRMASK (1 << 0) #define DES_ENCRYPT (0*DES_DIRMASK) /* Encrypt */ #define DES_DECRYPT (1*DES_DIRMASK) /* Decrypt */ #define DES_DEVMASK (1 << 1) #define DES_HW (0*DES_DEVMASK) /* Use hardware device */ #define DES_SW (1*DES_DEVMASK) /* Use software device */ #define DESERR_NONE 0 /* succeeded */ #define DESERR_NOHWDEVICE 1 /* succeeded, but hw device not available */ #define DESERR_HWERROR 2 /* failed, hardware/driver error */ #define DESERR_BADPARAM 3 /* failed, bad parameter to call */ #define DES_FAILED(err) \ ((err) > DESERR_NOHWDEVICE) /* * cbc_crypt() * ecb_crypt() * * Encrypt (or decrypt) len bytes of a buffer buf. * The length must be a multiple of eight. * The key should have odd parity in the low bit of each byte. * ivec is the input vector, and is updated to the new one (cbc only). * The mode is created by oring together the appropriate parameters. * DESERR_NOHWDEVICE is returned if DES_HW was specified but * there was no hardware to do it on (the data will still be * encrypted though, in software). */ /* * Cipher Block Chaining mode */ extern int cbc_crypt (char *__key, char *__buf, unsigned __len, unsigned __mode, char *__ivec) __THROW; /* * Electronic Code Book mode */ extern int ecb_crypt (char *__key, char *__buf, unsigned __len, unsigned __mode) __THROW; /* * Set des parity for a key. * DES parity is odd and in the low bit of each byte */ extern void des_setparity (char *__key) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/rpc/key_prot.h010064400000000000000000000270441173363226500161310ustar00/* * Please do not edit this file. * It was generated using rpcgen. */ #ifndef _KEY_PROT_H_RPCGEN #define _KEY_PROT_H_RPCGEN #include /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ #if 0 #pragma ident "@(#)key_prot.x 1.7 94/04/29 SMI" #endif /* Copyright (c) 1990, 1991 Sun Microsystems, Inc. */ /* * Compiled from key_prot.x using rpcgen. * DO NOT EDIT THIS FILE! * This is NOT source code! */ #define PROOT 3 #define HEXMODULUS "d4a0ba0250b6fd2ec626e7efd637df76c716e22d0944b88b" #define HEXKEYBYTES 48 #define KEYSIZE 192 #define KEYBYTES 24 #define KEYCHECKSUMSIZE 16 enum keystatus { KEY_SUCCESS = 0, KEY_NOSECRET = 1, KEY_UNKNOWN = 2, KEY_SYSTEMERR = 3, }; typedef enum keystatus keystatus; #ifdef __cplusplus extern "C" bool_t xdr_keystatus(XDR *, keystatus*); #elif __STDC__ extern bool_t xdr_keystatus(XDR *, keystatus*); #else /* Old Style C */ bool_t xdr_keystatus(); #endif /* Old Style C */ typedef char keybuf[HEXKEYBYTES]; #ifdef __cplusplus extern "C" bool_t xdr_keybuf(XDR *, keybuf); #elif __STDC__ extern bool_t xdr_keybuf(XDR *, keybuf); #else /* Old Style C */ bool_t xdr_keybuf(); #endif /* Old Style C */ typedef char *netnamestr; #ifdef __cplusplus extern "C" bool_t xdr_netnamestr(XDR *, netnamestr*); #elif __STDC__ extern bool_t xdr_netnamestr(XDR *, netnamestr*); #else /* Old Style C */ bool_t xdr_netnamestr(); #endif /* Old Style C */ struct cryptkeyarg { netnamestr remotename; des_block deskey; }; typedef struct cryptkeyarg cryptkeyarg; #ifdef __cplusplus extern "C" bool_t xdr_cryptkeyarg(XDR *, cryptkeyarg*); #elif __STDC__ extern bool_t xdr_cryptkeyarg(XDR *, cryptkeyarg*); #else /* Old Style C */ bool_t xdr_cryptkeyarg(); #endif /* Old Style C */ struct cryptkeyarg2 { netnamestr remotename; netobj remotekey; des_block deskey; }; typedef struct cryptkeyarg2 cryptkeyarg2; #ifdef __cplusplus extern "C" bool_t xdr_cryptkeyarg2(XDR *, cryptkeyarg2*); #elif __STDC__ extern bool_t xdr_cryptkeyarg2(XDR *, cryptkeyarg2*); #else /* Old Style C */ bool_t xdr_cryptkeyarg2(); #endif /* Old Style C */ struct cryptkeyres { keystatus status; union { des_block deskey; } cryptkeyres_u; }; typedef struct cryptkeyres cryptkeyres; #ifdef __cplusplus extern "C" bool_t xdr_cryptkeyres(XDR *, cryptkeyres*); #elif __STDC__ extern bool_t xdr_cryptkeyres(XDR *, cryptkeyres*); #else /* Old Style C */ bool_t xdr_cryptkeyres(); #endif /* Old Style C */ #define MAXGIDS 16 struct unixcred { unsigned int uid; unsigned int gid; struct { unsigned int gids_len; unsigned int *gids_val; } gids; }; typedef struct unixcred unixcred; #ifdef __cplusplus extern "C" bool_t xdr_unixcred(XDR *, unixcred*); #elif __STDC__ extern bool_t xdr_unixcred(XDR *, unixcred*); #else /* Old Style C */ bool_t xdr_unixcred(); #endif /* Old Style C */ struct getcredres { keystatus status; union { unixcred cred; } getcredres_u; }; typedef struct getcredres getcredres; #ifdef __cplusplus extern "C" bool_t xdr_getcredres(XDR *, getcredres*); #elif __STDC__ extern bool_t xdr_getcredres(XDR *, getcredres*); #else /* Old Style C */ bool_t xdr_getcredres(); #endif /* Old Style C */ struct key_netstarg { keybuf st_priv_key; keybuf st_pub_key; netnamestr st_netname; }; typedef struct key_netstarg key_netstarg; #ifdef __cplusplus extern "C" bool_t xdr_key_netstarg(XDR *, key_netstarg*); #elif __STDC__ extern bool_t xdr_key_netstarg(XDR *, key_netstarg*); #else /* Old Style C */ bool_t xdr_key_netstarg(); #endif /* Old Style C */ struct key_netstres { keystatus status; union { key_netstarg knet; } key_netstres_u; }; typedef struct key_netstres key_netstres; #ifdef __cplusplus extern "C" bool_t xdr_key_netstres(XDR *, key_netstres*); #elif __STDC__ extern bool_t xdr_key_netstres(XDR *, key_netstres*); #else /* Old Style C */ bool_t xdr_key_netstres(); #endif /* Old Style C */ #ifndef opaque #define opaque char #endif #define KEY_PROG ((unsigned long)100029) #define KEY_VERS ((unsigned long)1) #ifdef __cplusplus #define KEY_SET ((unsigned long)1) extern "C" keystatus * key_set_1(opaque *, CLIENT *); extern "C" keystatus * key_set_1_svc(opaque *, struct svc_req *); #define KEY_ENCRYPT ((unsigned long)2) extern "C" cryptkeyres * key_encrypt_1(cryptkeyarg *, CLIENT *); extern "C" cryptkeyres * key_encrypt_1_svc(cryptkeyarg *, struct svc_req *); #define KEY_DECRYPT ((unsigned long)3) extern "C" cryptkeyres * key_decrypt_1(cryptkeyarg *, CLIENT *); extern "C" cryptkeyres * key_decrypt_1_svc(cryptkeyarg *, struct svc_req *); #define KEY_GEN ((unsigned long)4) extern "C" des_block * key_gen_1(void *, CLIENT *); extern "C" des_block * key_gen_1_svc(void *, struct svc_req *); #define KEY_GETCRED ((unsigned long)5) extern "C" getcredres * key_getcred_1(netnamestr *, CLIENT *); extern "C" getcredres * key_getcred_1_svc(netnamestr *, struct svc_req *); #elif __STDC__ #define KEY_SET ((unsigned long)1) extern keystatus * key_set_1(opaque *, CLIENT *); extern keystatus * key_set_1_svc(opaque *, struct svc_req *); #define KEY_ENCRYPT ((unsigned long)2) extern cryptkeyres * key_encrypt_1(cryptkeyarg *, CLIENT *); extern cryptkeyres * key_encrypt_1_svc(cryptkeyarg *, struct svc_req *); #define KEY_DECRYPT ((unsigned long)3) extern cryptkeyres * key_decrypt_1(cryptkeyarg *, CLIENT *); extern cryptkeyres * key_decrypt_1_svc(cryptkeyarg *, struct svc_req *); #define KEY_GEN ((unsigned long)4) extern des_block * key_gen_1(void *, CLIENT *); extern des_block * key_gen_1_svc(void *, struct svc_req *); #define KEY_GETCRED ((unsigned long)5) extern getcredres * key_getcred_1(netnamestr *, CLIENT *); extern getcredres * key_getcred_1_svc(netnamestr *, struct svc_req *); #else /* Old Style C */ #define KEY_SET ((unsigned long)1) extern keystatus * key_set_1(); extern keystatus * key_set_1_svc(); #define KEY_ENCRYPT ((unsigned long)2) extern cryptkeyres * key_encrypt_1(); extern cryptkeyres * key_encrypt_1_svc(); #define KEY_DECRYPT ((unsigned long)3) extern cryptkeyres * key_decrypt_1(); extern cryptkeyres * key_decrypt_1_svc(); #define KEY_GEN ((unsigned long)4) extern des_block * key_gen_1(); extern des_block * key_gen_1_svc(); #define KEY_GETCRED ((unsigned long)5) extern getcredres * key_getcred_1(); extern getcredres * key_getcred_1_svc(); #endif /* Old Style C */ #define KEY_VERS2 ((unsigned long)2) #ifdef __cplusplus extern "C" keystatus * key_set_2(opaque *, CLIENT *); extern "C" keystatus * key_set_2_svc(opaque *, struct svc_req *); extern "C" cryptkeyres * key_encrypt_2(cryptkeyarg *, CLIENT *); extern "C" cryptkeyres * key_encrypt_2_svc(cryptkeyarg *, struct svc_req *); extern "C" cryptkeyres * key_decrypt_2(cryptkeyarg *, CLIENT *); extern "C" cryptkeyres * key_decrypt_2_svc(cryptkeyarg *, struct svc_req *); extern "C" des_block * key_gen_2(void *, CLIENT *); extern "C" des_block * key_gen_2_svc(void *, struct svc_req *); extern "C" getcredres * key_getcred_2(netnamestr *, CLIENT *); extern "C" getcredres * key_getcred_2_svc(netnamestr *, struct svc_req *); #define KEY_ENCRYPT_PK ((unsigned long)6) extern "C" cryptkeyres * key_encrypt_pk_2(cryptkeyarg2 *, CLIENT *); extern "C" cryptkeyres * key_encrypt_pk_2_svc(cryptkeyarg2 *, struct svc_req *); #define KEY_DECRYPT_PK ((unsigned long)7) extern "C" cryptkeyres * key_decrypt_pk_2(cryptkeyarg2 *, CLIENT *); extern "C" cryptkeyres * key_decrypt_pk_2_svc(cryptkeyarg2 *, struct svc_req *); #define KEY_NET_PUT ((unsigned long)8) extern "C" keystatus * key_net_put_2(key_netstarg *, CLIENT *); extern "C" keystatus * key_net_put_2_svc(key_netstarg *, struct svc_req *); #define KEY_NET_GET ((unsigned long)9) extern "C" key_netstres * key_net_get_2(void *, CLIENT *); extern "C" key_netstres * key_net_get_2_svc(void *, struct svc_req *); #define KEY_GET_CONV ((unsigned long)10) extern "C" cryptkeyres * key_get_conv_2(opaque *, CLIENT *); extern "C" cryptkeyres * key_get_conv_2_svc(opaque *, struct svc_req *); #elif __STDC__ extern keystatus * key_set_2(opaque *, CLIENT *); extern keystatus * key_set_2_svc(opaque *, struct svc_req *); extern cryptkeyres * key_encrypt_2(cryptkeyarg *, CLIENT *); extern cryptkeyres * key_encrypt_2_svc(cryptkeyarg *, struct svc_req *); extern cryptkeyres * key_decrypt_2(cryptkeyarg *, CLIENT *); extern cryptkeyres * key_decrypt_2_svc(cryptkeyarg *, struct svc_req *); extern des_block * key_gen_2(void *, CLIENT *); extern des_block * key_gen_2_svc(void *, struct svc_req *); extern getcredres * key_getcred_2(netnamestr *, CLIENT *); extern getcredres * key_getcred_2_svc(netnamestr *, struct svc_req *); #define KEY_ENCRYPT_PK ((unsigned long)6) extern cryptkeyres * key_encrypt_pk_2(cryptkeyarg2 *, CLIENT *); extern cryptkeyres * key_encrypt_pk_2_svc(cryptkeyarg2 *, struct svc_req *); #define KEY_DECRYPT_PK ((unsigned long)7) extern cryptkeyres * key_decrypt_pk_2(cryptkeyarg2 *, CLIENT *); extern cryptkeyres * key_decrypt_pk_2_svc(cryptkeyarg2 *, struct svc_req *); #define KEY_NET_PUT ((unsigned long)8) extern keystatus * key_net_put_2(key_netstarg *, CLIENT *); extern keystatus * key_net_put_2_svc(key_netstarg *, struct svc_req *); #define KEY_NET_GET ((unsigned long)9) extern key_netstres * key_net_get_2(void *, CLIENT *); extern key_netstres * key_net_get_2_svc(void *, struct svc_req *); #define KEY_GET_CONV ((unsigned long)10) extern cryptkeyres * key_get_conv_2(opaque *, CLIENT *); extern cryptkeyres * key_get_conv_2_svc(opaque *, struct svc_req *); #else /* Old Style C */ extern keystatus * key_set_2(); extern keystatus * key_set_2_svc(); extern cryptkeyres * key_encrypt_2(); extern cryptkeyres * key_encrypt_2_svc(); extern cryptkeyres * key_decrypt_2(); extern cryptkeyres * key_decrypt_2_svc(); extern des_block * key_gen_2(); extern des_block * key_gen_2_svc(); extern getcredres * key_getcred_2(); extern getcredres * key_getcred_2_svc(); #define KEY_ENCRYPT_PK ((unsigned long)6) extern cryptkeyres * key_encrypt_pk_2(); extern cryptkeyres * key_encrypt_pk_2_svc(); #define KEY_DECRYPT_PK ((unsigned long)7) extern cryptkeyres * key_decrypt_pk_2(); extern cryptkeyres * key_decrypt_pk_2_svc(); #define KEY_NET_PUT ((unsigned long)8) extern keystatus * key_net_put_2(); extern keystatus * key_net_put_2_svc(); #define KEY_NET_GET ((unsigned long)9) extern key_netstres * key_net_get_2(); extern key_netstres * key_net_get_2_svc(); #define KEY_GET_CONV ((unsigned long)10) extern cryptkeyres * key_get_conv_2(); extern cryptkeyres * key_get_conv_2_svc(); #endif /* Old Style C */ #endif /* !_KEY_PROT_H_RPCGEN */ dietlibc-0.33~cvs20120325/include/rpc/netdb.h010064400000000000000000000050071173363226500153640ustar00/* @(#)netdb.h 2.1 88/07/29 3.9 RPCSRC */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* @(#)rpc.h 1.8 87/07/24 SMI */ /* Cleaned up for GNU C library roland@gnu.ai.mit.edu: added multiple inclusion protection and use of . In GNU this file is #include'd by . */ #ifndef _RPC_NETDB_H #define _RPC_NETDB_H 1 #include #define __need_size_t #include __BEGIN_DECLS struct rpcent { char *r_name; /* Name of server for this rpc program. */ char **r_aliases; /* Alias list. */ int r_number; /* RPC program number. */ }; extern void setrpcent (int __stayopen) __THROW; extern void endrpcent (void) __THROW; extern struct rpcent *getrpcbyname (const char *__name) __THROW; extern struct rpcent *getrpcbynumber (int __number) __THROW; extern struct rpcent *getrpcent (void) __THROW; #ifdef __USE_MISC extern int getrpcbyname_r (const char *__name, struct rpcent *__result_buf, char *__buffer, size_t __buflen, struct rpcent **__result) __THROW; extern int getrpcbynumber_r (int __number, struct rpcent *__result_buf, char *__buffer, size_t __buflen, struct rpcent **__result) __THROW; extern int getrpcent_r (struct rpcent *__result_buf, char *__buffer, size_t __buflen, struct rpcent **__result) __THROW; #endif __END_DECLS #endif /* rpc/netdb.h */ dietlibc-0.33~cvs20120325/include/rpc/pmap_clnt.h010064400000000000000000000071531173363226500162510ustar00/* @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC; from 1.11 88/02/08 SMI */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * pmap_clnt.h * Supplies C routines to get to portmap services. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_PMAP_CLNT_H #define _RPC_PMAP_CLNT_H 1 #include #include #include #include __BEGIN_DECLS typedef bool_t (*resultproc_t) (char* resp, struct sockaddr_in *raddr); /* * Usage: * success = pmap_set(program, version, protocol, port); * success = pmap_unset(program, version); * port = pmap_getport(address, program, version, protocol); * head = pmap_getmaps(address); * clnt_stat = pmap_rmtcall(address, program, version, procedure, * xdrargs, argsp, xdrres, resp, tout, port_ptr) * (works for udp only.) * clnt_stat = clnt_broadcast(program, version, procedure, * xdrargs, argsp, xdrres, resp, eachresult) * (like pmap_rmtcall, except the call is broadcasted to all * locally connected nets. For each valid response received, * the procedure eachresult is called. Its form is: * done = eachresult(resp, raddr) * bool_t done; * char* resp; * struct sockaddr_in raddr; * where resp points to the results of the call and raddr is the * address if the responder to the broadcast. */ extern bool_t pmap_set (const unsigned long __program, const unsigned long __vers, int __protocol, unsigned short __port) __THROW; extern bool_t pmap_unset (const unsigned long __program, const unsigned long __vers) __THROW; extern struct pmaplist *pmap_getmaps (struct sockaddr_in *__address) __THROW; extern enum clnt_stat pmap_rmtcall (struct sockaddr_in *__addr, const unsigned long __prog, const unsigned long __vers, const unsigned long __proc, xdrproc_t __xdrargs, char* __argsp, xdrproc_t __xdrres, char* __resp, struct timeval __tout, unsigned long *__port_ptr) __THROW; extern enum clnt_stat clnt_broadcast (const unsigned long __prog, const unsigned long __vers, const unsigned long __proc, xdrproc_t __xargs, char* __argsp, xdrproc_t __xresults, char* __resultsp, resultproc_t __eachresult) __THROW; extern unsigned short pmap_getport (struct sockaddr_in *__address, const unsigned long __program, const unsigned long __version, unsigned int __protocol) __THROW; __END_DECLS #endif /* rpc/pmap_clnt.h */ dietlibc-0.33~cvs20120325/include/rpc/pmap_prot.h010064400000000000000000000071011173363226500162660ustar00/* @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC; from 1.14 88/02/08 SMI */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * pmap_prot.h * Protocol for the local binder service, or pmap. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_PMAP_PROT_H #define _RPC_PMAP_PROT_H 1 #include #include __BEGIN_DECLS /* The following procedures are supported by the protocol: * * PMAPPROC_NULL() returns () * takes nothing, returns nothing * * PMAPPROC_SET(struct pmap) returns (bool_t) * TRUE is success, FALSE is failure. Registers the tuple * [prog, vers, prot, port]. * * PMAPPROC_UNSET(struct pmap) returns (bool_t) * TRUE is success, FALSE is failure. Un-registers pair * [prog, vers]. prot and port are ignored. * * PMAPPROC_GETPORT(struct pmap) returns (long unsigned). * 0 is failure. Otherwise returns the port number where the pair * [prog, vers] is registered. It may lie! * * PMAPPROC_DUMP() RETURNS (struct pmaplist *) * * PMAPPROC_CALLIT(unsigned, unsigned, unsigned, string<>) * RETURNS (port, string<>); * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs); * Calls the procedure on the local machine. If it is not registered, * this procedure is quite; ie it does not return error information!!! * This procedure only is supported on rpc/udp and calls via * rpc/udp. This routine only passes null authentication parameters. * This file has no interface to xdr routines for PMAPPROC_CALLIT. * * The service supports remote procedure calls on udp/ip or tcp/ip socket 111. */ #define PMAPPORT ((unsigned short)111) #define PMAPPROG ((unsigned long)100000) #define PMAPVERS ((unsigned long)2) #define PMAPVERS_PROTO ((unsigned long)2) #define PMAPVERS_ORIG ((unsigned long)1) #define PMAPPROC_NULL ((unsigned long)0) #define PMAPPROC_SET ((unsigned long)1) #define PMAPPROC_UNSET ((unsigned long)2) #define PMAPPROC_GETPORT ((unsigned long)3) #define PMAPPROC_DUMP ((unsigned long)4) #define PMAPPROC_CALLIT ((unsigned long)5) struct pmap { long unsigned pm_prog; long unsigned pm_vers; long unsigned pm_prot; long unsigned pm_port; }; extern bool_t xdr_pmap (XDR *__xdrs, struct pmap *__regs) __THROW; struct pmaplist { struct pmap pml_map; struct pmaplist *pml_next; }; extern bool_t xdr_pmaplist (XDR *__xdrs, struct pmaplist **__rp) __THROW; __END_DECLS #endif /* rpc/pmap_prot.h */ dietlibc-0.33~cvs20120325/include/rpc/pmap_rmt.h010064400000000000000000000040441173363226500161070ustar00/* @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC; from 1.2 88/02/08 SMI */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * Structures and XDR routines for parameters to and replies from * the portmapper remote-call-service. * * Copyright (C) 1986, Sun Microsystems, Inc. */ #ifndef _RPC_PMAP_RMT_H #define _RPC_PMAP_RMT_H 1 #include #include #include #include __BEGIN_DECLS struct rmtcallargs { unsigned long prog, vers, proc, arglen; char* args_ptr; xdrproc_t xdr_args; }; extern bool_t xdr_rmtcall_args (XDR *__xdrs, struct rmtcallargs *__crp) __THROW; struct rmtcallres { unsigned long *port_ptr; unsigned long resultslen; char* results_ptr; xdrproc_t xdr_results; }; extern bool_t xdr_rmtcallres (XDR *__xdrs, struct rmtcallres *__crp) __THROW; __END_DECLS #endif /* rpc/pmap_rmt.h */ dietlibc-0.33~cvs20120325/include/rpc/rpc.h010064400000000000000000000050661173363226500150610ustar00/* @(#)rpc.h 2.3 88/08/10 4.0 RPCSRC; from 1.9 88/02/08 SMI */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * rpc.h, Just includes the billions of rpc header files necessary to * do remote procedure calling. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_RPC_H #define _RPC_RPC_H 1 #include /* some typedefs */ #include /* external data representation interfaces */ #include /* generic (de)serializer */ /* Client side only authentication */ #include /* generic authenticator (client side) */ /* Client side (mostly) remote procedure call */ #include /* generic rpc stuff */ /* semi-private protocol headers */ #include /* protocol for rpc messages */ #include /* protocol for unix style cred */ #include /* protocol for des style cred */ /* Server side only remote procedure callee */ #include /* service manager and multiplexer */ #include /* service side authenticator */ /* * COMMENT OUT THE NEXT INCLUDE IF RUNNING ON SUN OS OR ON A VERSION * OF UNIX BASED ON NFSSRC. These systems will already have the structures * defined by included in . */ /* routines for parsing /etc/rpc */ #include /* structures and routines to parse /etc/rpc */ #endif /* rpc/rpc.h */ dietlibc-0.33~cvs20120325/include/rpc/rpc_des.h010064400000000000000000000042371173363226500157130ustar00/* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * Generic DES driver interface * Keep this file hardware independent! * Copyright (c) 1986 by Sun Microsystems, Inc. */ #ifndef _DES_H #define _DES_H #include __BEGIN_DECLS #define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */ #define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */ enum desdir { ENCRYPT, DECRYPT }; enum desmode { CBC, ECB }; /* * parameters to ioctl call */ struct desparams { u_char des_key[8]; /* key (with low bit parity) */ enum desdir des_dir; /* direction */ enum desmode des_mode; /* mode */ u_char des_ivec[8]; /* input vector */ unsigned des_len; /* number of bytes to crypt */ union { u_char UDES_data[DES_QUICKLEN]; u_char *UDES_buf; } UDES; #define des_data UDES.UDES_data /* direct data here if quick */ #define des_buf UDES.UDES_buf /* otherwise, pointer to data */ }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/rpc/rpc_msg.h010064400000000000000000000107761173363226500157330ustar00/* @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* @(#)rpc_msg.h 1.7 86/07/16 SMI */ #ifndef _RPC_MSG_H #define _RPC_MSG_H 1 #include #include #include /* * rpc_msg.h * rpc message definition * * Copyright (C) 1984, Sun Microsystems, Inc. */ #define RPC_MSG_VERSION ((unsigned long) 2) #define RPC_SERVICE_PORT ((unsigned short) 2048) __BEGIN_DECLS /* * Bottom up definition of an rpc message. * NOTE: call and reply use the same overall struct but * different parts of unions within it. */ enum msg_type { CALL=0, REPLY=1 }; enum reply_stat { MSG_ACCEPTED=0, MSG_DENIED=1 }; enum accept_stat { SUCCESS=0, PROG_UNAVAIL=1, PROG_MISMATCH=2, PROC_UNAVAIL=3, GARBAGE_ARGS=4, SYSTEM_ERR=5 }; enum reject_stat { RPC_MISMATCH=0, AUTH_ERROR=1 }; /* * Reply part of an rpc exchange */ /* * Reply to an rpc request that was accepted by the server. * Note: there could be an error even though the request was * accepted. */ struct accepted_reply { struct opaque_auth ar_verf; enum accept_stat ar_stat; union { struct { unsigned long low; unsigned long high; } AR_versions; struct { char* where; xdrproc_t proc; } AR_results; /* and many other null cases */ } ru; #define ar_results ru.AR_results #define ar_vers ru.AR_versions }; /* * Reply to an rpc request that was rejected by the server. */ struct rejected_reply { enum reject_stat rj_stat; union { struct { unsigned long low; unsigned long high; } RJ_versions; enum auth_stat RJ_why; /* why authentication did not work */ } ru; #define rj_vers ru.RJ_versions #define rj_why ru.RJ_why }; /* * Body of a reply to an rpc request. */ struct reply_body { enum reply_stat rp_stat; union { struct accepted_reply RP_ar; struct rejected_reply RP_dr; } ru; #define rp_acpt ru.RP_ar #define rp_rjct ru.RP_dr }; /* * Body of an rpc request call. */ struct call_body { unsigned long cb_rpcvers; /* must be equal to two */ unsigned long cb_prog; unsigned long cb_vers; unsigned long cb_proc; struct opaque_auth cb_cred; struct opaque_auth cb_verf; /* protocol specific - provided by client */ }; /* * The rpc message */ struct rpc_msg { unsigned long rm_xid; enum msg_type rm_direction; union { struct call_body RM_cmb; struct reply_body RM_rmb; } ru; #define rm_call ru.RM_cmb #define rm_reply ru.RM_rmb }; #define acpted_rply ru.RM_rmb.ru.RP_ar #define rjcted_rply ru.RM_rmb.ru.RP_dr /* * XDR routine to handle a rpc message. * xdr_callmsg(xdrs, cmsg) * XDR *xdrs; * struct rpc_msg *cmsg; */ extern bool_t xdr_callmsg (XDR *__xdrs, struct rpc_msg *__cmsg) __THROW; /* * XDR routine to pre-serialize the static part of a rpc message. * xdr_callhdr(xdrs, cmsg) * XDR *xdrs; * struct rpc_msg *cmsg; */ extern bool_t xdr_callhdr (XDR *__xdrs, struct rpc_msg *__cmsg) __THROW; /* * XDR routine to handle a rpc reply. * xdr_replymsg(xdrs, rmsg) * XDR *xdrs; * struct rpc_msg *rmsg; */ extern bool_t xdr_replymsg (XDR *__xdrs, struct rpc_msg *__rmsg) __THROW; /* * Fills in the error part of a reply message. * _seterr_reply(msg, error) * struct rpc_msg *msg; * struct rpc_err *error; */ extern void _seterr_reply (struct rpc_msg *__msg, struct rpc_err *__error) __THROW; __END_DECLS #endif /* rpc/rpc_msg.h */ dietlibc-0.33~cvs20120325/include/rpc/svc.h010064400000000000000000000241341173363226500150650ustar00/* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * svc.h, Server-side remote procedure call interface. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_SVC_H #define _RPC_SVC_H 1 #include #include __BEGIN_DECLS /* * This interface must manage two items concerning remote procedure calling: * * 1) An arbitrary number of transport connections upon which rpc requests * are received. The two most notable transports are TCP and UDP; they are * created and registered by routines in svc_tcp.c and svc_udp.c, respectively; * they in turn call xprt_register and xprt_unregister. * * 2) An arbitrary number of locally registered services. Services are * described by the following four data: program number, version number, * "service dispatch" function, a transport handle, and a boolean that * indicates whether or not the exported program should be registered with a * local binder service; if true the program's number and version and the * port number from the transport handle are registered with the binder. * These data are registered with the rpc svc system via svc_register. * * A service's dispatch function is called whenever an rpc request comes in * on a transport. The request's program and version numbers must match * those of the registered service. The dispatch function is passed two * parameters, struct svc_req * and SVCXPRT *, defined below. */ enum xprt_stat { XPRT_DIED, XPRT_MOREREQS, XPRT_IDLE }; /* * Server side transport handle */ typedef struct SVCXPRT SVCXPRT; struct SVCXPRT { int xp_sock; unsigned short xp_port; /* associated port number */ const struct xp_ops { bool_t (*xp_recv) (SVCXPRT *__xprt, struct rpc_msg *__msg); /* receive incoming requests */ enum xprt_stat (*xp_stat) (SVCXPRT *__xprt); /* get transport status */ bool_t (*xp_getargs) (SVCXPRT *__xprt, xdrproc_t __xdr_args, char* args_ptr); /* get arguments */ bool_t (*xp_reply) (SVCXPRT *__xprt, struct rpc_msg *__msg); /* send reply */ bool_t (*xp_freeargs) (SVCXPRT *__xprt, xdrproc_t __xdr_args, char* args_ptr); /* free mem allocated for args */ void (*xp_destroy) (SVCXPRT *__xprt); /* destroy this struct */ } *xp_ops; int xp_addrlen; /* length of remote address */ struct sockaddr_in xp_raddr; /* remote address */ struct opaque_auth xp_verf; /* raw response verifier */ char* xp_p1; /* private */ char* xp_p2; /* private */ char xp_pad [256]; /* padding, internal use */ }; /* * Approved way of getting address of caller */ #define svc_getcaller(x) (&(x)->xp_raddr) /* * Operations defined on an SVCXPRT handle * * SVCXPRT *xprt; * struct rpc_msg *msg; * xdrproc_t xargs; * char* argsp; */ #define SVC_RECV(xprt, msg) \ (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) #define svc_recv(xprt, msg) \ (*(xprt)->xp_ops->xp_recv)((xprt), (msg)) #define SVC_STAT(xprt) \ (*(xprt)->xp_ops->xp_stat)(xprt) #define svc_stat(xprt) \ (*(xprt)->xp_ops->xp_stat)(xprt) #define SVC_GETARGS(xprt, xargs, argsp) \ (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) #define svc_getargs(xprt, xargs, argsp) \ (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp)) #define SVC_REPLY(xprt, msg) \ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) #define svc_reply(xprt, msg) \ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg)) #define SVC_FREEARGS(xprt, xargs, argsp) \ (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) #define svc_freeargs(xprt, xargs, argsp) \ (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp)) #define SVC_DESTROY(xprt) \ (*(xprt)->xp_ops->xp_destroy)(xprt) #define svc_destroy(xprt) \ (*(xprt)->xp_ops->xp_destroy)(xprt) /* * Service request */ struct svc_req { rpcprog_t rq_prog; /* service program number */ rpcvers_t rq_vers; /* service protocol version */ rpcproc_t rq_proc; /* the desired procedure */ struct opaque_auth rq_cred; /* raw creds from the wire */ char* rq_clntcred; /* read only cooked cred */ SVCXPRT *rq_xprt; /* associated transport */ }; #ifndef __DISPATCH_FN_T #define __DISPATCH_FN_T typedef void (*__dispatch_fn_t) (struct svc_req*, SVCXPRT*); #endif /* * Service registration * * svc_register(xprt, prog, vers, dispatch, protocol) * SVCXPRT *xprt; * rpcprog_t prog; * rpcvers_t vers; * void (*dispatch)(struct svc_req*, SVCXPRT*); * rpcprot_t protocol; like TCP or UDP, zero means do not register */ extern bool_t svc_register (SVCXPRT *__xprt, rpcprog_t __prog, rpcvers_t __vers, __dispatch_fn_t __dispatch, rpcprot_t __protocol) __THROW; /* * Service un-registration * * svc_unregister(prog, vers) * rpcprog_t prog; * rpcvers_t vers; */ extern void svc_unregister (rpcprog_t __prog, rpcvers_t __vers) __THROW; /* * Transport registration. * * xprt_register(xprt) * SVCXPRT *xprt; */ extern void xprt_register (SVCXPRT *__xprt) __THROW; /* * Transport un-register * * xprt_unregister(xprt) * SVCXPRT *xprt; */ extern void xprt_unregister (SVCXPRT *__xprt) __THROW; /* * When the service routine is called, it must first check to see if it * knows about the procedure; if not, it should call svcerr_noproc * and return. If so, it should deserialize its arguments via * SVC_GETARGS (defined above). If the deserialization does not work, * svcerr_decode should be called followed by a return. Successful * decoding of the arguments should be followed the execution of the * procedure's code and a call to svc_sendreply. * * Also, if the service refuses to execute the procedure due to too- * weak authentication parameters, svcerr_weakauth should be called. * Note: do not confuse access-control failure with weak authentication! * * NB: In pure implementations of rpc, the caller always waits for a reply * msg. This message is sent when svc_sendreply is called. * Therefore pure service implementations should always call * svc_sendreply even if the function logically returns void; use * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows * for the abuse of pure rpc via batched calling or pipelining. In the * case of a batched call, svc_sendreply should NOT be called since * this would send a return message, which is what batching tries to avoid. * It is the service/protocol writer's responsibility to know which calls are * batched and which are not. Warning: responding to batch calls may * deadlock the caller and server processes! */ extern bool_t svc_sendreply (SVCXPRT *xprt, xdrproc_t __xdr_results, char* __xdr_location) __THROW; extern void svcerr_decode (SVCXPRT *__xprt) __THROW; extern void svcerr_weakauth (SVCXPRT *__xprt) __THROW; extern void svcerr_noproc (SVCXPRT *__xprt) __THROW; extern void svcerr_progvers (SVCXPRT *__xprt, rpcvers_t __low_vers, rpcvers_t __high_vers) __THROW; extern void svcerr_auth (SVCXPRT *__xprt, enum auth_stat __why) __THROW; extern void svcerr_noprog (SVCXPRT *__xprt) __THROW; extern void svcerr_systemerr (SVCXPRT *__xprt) __THROW; /* * Lowest level dispatching -OR- who owns this process anyway. * Somebody has to wait for incoming requests and then call the correct * service routine. The routine svc_run does infinite waiting; i.e., * svc_run never returns. * Since another (coexistent) package may wish to selectively wait for * incoming calls or other events outside of the rpc architecture, the * routine svc_getreq is provided. It must be passed readfds, the * "in-place" results of a select system call (see select, section 2). */ /* * Global keeper of rpc service descriptors in use * dynamic; must be inspected before each call to select */ extern struct pollfd *svc_pollfd; extern int svc_max_pollfd; extern fd_set svc_fdset; #define svc_fds svc_fdset.fds_bits[0] /* compatibility */ /* * a small program implemented by the svc_rpc implementation itself; * also see clnt.h for protocol numbers. */ extern void svc_getreq (int __rdfds) __THROW; extern void svc_getreq_common (const int __fd) __THROW; extern void svc_getreqset (fd_set *__readfds) __THROW; extern void svc_getreq_poll (struct pollfd *, const int) __THROW; extern void svc_exit (void) __THROW; extern void svc_run (void) __THROW; /* * Socket to use on svcxxx_create call to get default socket */ #define RPC_ANYSOCK -1 /* * These are the existing service side transport implementations */ /* * Memory based rpc for testing and timing. */ extern SVCXPRT *svcraw_create (void) __THROW; /* * Udp based rpc. */ extern SVCXPRT *svcudp_create (int __sock) __THROW; extern SVCXPRT *svcudp_bufcreate (int __sock, unsigned int __sendsz, unsigned int __recvsz) __THROW; /* * Tcp based rpc. */ extern SVCXPRT *svctcp_create (int __sock, unsigned int __sendsize, unsigned int __recvsize) __THROW; /* * Unix based rpc. */ extern SVCXPRT *svcunix_create (int __sock, unsigned int __sendsize, unsigned int __recvsize, char *__path) __THROW; __END_DECLS #endif /* rpc/svc.h */ dietlibc-0.33~cvs20120325/include/rpc/svc_auth.h010064400000000000000000000033351173363226500161060ustar00/* @(#)svc_auth.h 2.1 88/07/29 4.0 RPCSRC */ /* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* @(#)svc_auth.h 1.6 86/07/16 SMI */ /* * svc_auth.h, Service side of rpc authentication. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_SVC_AUTH_H #define _RPC_SVC_AUTH_H 1 #include #include __BEGIN_DECLS /* * Server side authenticator */ extern enum auth_stat _authenticate (struct svc_req *__rqst, struct rpc_msg *__msg) __THROW; __END_DECLS #endif /* rpc/svc_auth.h */ dietlibc-0.33~cvs20120325/include/rpc/types.h010064400000000000000000000044041173363226500154340ustar00/* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* fixincludes should not add extern "C" to this file */ /* * Rpc additions to */ #ifndef _RPC_TYPES_H #define _RPC_TYPES_H 1 #include __BEGIN_DECLS typedef int bool_t; typedef int enum_t; /* This needs to be changed to uint32_t in the future */ typedef unsigned long rpcprog_t; typedef unsigned long rpcvers_t; typedef unsigned long rpcproc_t; typedef unsigned long rpcprot_t; typedef unsigned long rpcport_t; #define __dontcare__ -1 #ifndef FALSE # define FALSE (0) #endif #ifndef TRUE # define TRUE (1) #endif #include /* For malloc decl. */ #define mem_alloc(bsize) malloc(bsize) #define mem_free(ptr, bsize) free(ptr) #ifndef makedev /* ie, we haven't already included it */ #include #endif #include #include #include #ifndef INADDR_LOOPBACK #define INADDR_LOOPBACK 0x7F000001UL #endif #ifndef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 64 #endif __END_DECLS #endif /* rpc/types.h */ dietlibc-0.33~cvs20120325/include/rpc/xdr.h010064400000000000000000000340251173363226500150670ustar00/* * Sun RPC is a product of Sun Microsystems, Inc. and is provided for * unrestricted use provided that this legend is included on all tape * media and as a part of the software program in whole or part. Users * may copy or modify Sun RPC without charge, but are not authorized * to license or distribute it to anyone else except as part of a product or * program developed by the user. * * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE. * * Sun RPC is provided with no support and without any obligation on the * part of Sun Microsystems, Inc. to assist in its use, correction, * modification or enhancement. * * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC * OR ANY PART THEREOF. * * In no event will Sun Microsystems, Inc. be liable for any lost revenue * or profits or other special, indirect and consequential damages, even if * Sun has been advised of the possibility of such damages. * * Sun Microsystems, Inc. * 2550 Garcia Avenue * Mountain View, California 94043 */ /* * xdr.h, External Data Representation Serialization Routines. * * Copyright (C) 1984, Sun Microsystems, Inc. */ #ifndef _RPC_XDR_H #define _RPC_XDR_H 1 #include #include #include /* We need FILE. */ #include __BEGIN_DECLS /* * XDR provides a conventional way for converting between C data * types and an external bit-string representation. Library supplied * routines provide for the conversion on built-in C data types. These * routines and utility routines defined here are used to help implement * a type encode/decode routine for each user-defined type. * * Each data type provides a single procedure which takes two arguments: * * bool_t * xdrproc(xdrs, argresp) * XDR *xdrs; * *argresp; * * xdrs is an instance of a XDR handle, to which or from which the data * type is to be converted. argresp is a pointer to the structure to be * converted. The XDR handle contains an operation field which indicates * which of the operations (ENCODE, DECODE * or FREE) is to be performed. * * XDR_DECODE may allocate space if the pointer argresp is null. This * data can be freed with the XDR_FREE operation. * * We write only one procedure per data type to make it easy * to keep the encode and decode procedures for a data type consistent. * In many cases the same code performs all operations on a user defined type, * because all the hard work is done in the component type routines. * decode as a series of calls on the nested data types. */ /* * Xdr operations. XDR_ENCODE causes the type to be encoded into the * stream. XDR_DECODE causes the type to be extracted from the stream. * XDR_FREE can be used to release the space allocated by an XDR_DECODE * request. */ enum xdr_op { XDR_ENCODE = 0, XDR_DECODE = 1, XDR_FREE = 2 }; /* * This is the number of bytes per unit of external data. */ #define BYTES_PER_XDR_UNIT (4) /* * This only works if the above is a power of 2. But it's defined to be * 4 by the appropriate RFCs. So it will work. And it's normally quicker * than the old routine. */ #if 1 #define RNDUP(x) (((x) + BYTES_PER_XDR_UNIT - 1) & ~(BYTES_PER_XDR_UNIT - 1)) #else /* this is the old routine */ #define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \ * BYTES_PER_XDR_UNIT) #endif /* * The XDR handle. * Contains operation which is being applied to the stream, * an operations vector for the particular implementation (e.g. see xdr_mem.c), * and two private fields for the use of the particular implementation. */ typedef struct XDR XDR; struct XDR { enum xdr_op x_op; /* operation; fast additional param */ struct xdr_ops { bool_t (*x_getlong) (XDR *__xdrs, long *__lp); /* get a long from underlying stream */ bool_t (*x_putlong) (XDR *__xdrs, const long *__lp); /* put a long to " */ bool_t (*x_getbytes) (XDR *__xdrs, char* __addr, unsigned int __len); /* get some bytes from " */ bool_t (*x_putbytes) (XDR *__xdrs, const char *__addr, unsigned int __len); /* put some bytes to " */ unsigned int (*x_getpostn) (const XDR *__xdrs); /* returns bytes off from beginning */ bool_t (*x_setpostn) (XDR *__xdrs, unsigned int __pos); /* lets you reposition the stream */ int32_t *(*x_inline) (XDR *__xdrs, unsigned int __len); /* buf quick ptr to buffered data */ void (*x_destroy) (XDR *__xdrs); /* free privates of this xdr_stream */ bool_t (*x_getint32) (XDR *__xdrs, int32_t *__ip); /* get a int from underlying stream */ bool_t (*x_putint32) (XDR *__xdrs, const int32_t *__ip); /* put a int to " */ } *x_ops; char* x_public; /* users' data */ char* x_private; /* pointer to private data */ char* x_base; /* private used for position info */ unsigned int x_handy; /* extra private word */ }; /* * A xdrproc_t exists for each data type which is to be encoded or decoded. * * The second argument to the xdrproc_t is a pointer to an opaque pointer. * The opaque pointer generally points to a structure of the data type * to be decoded. If this pointer is 0, then the type routines should * allocate dynamic storage of the appropriate size and return it. * bool_t (*xdrproc_t)(XDR *, char* *); */ typedef bool_t (*xdrproc_t) (XDR *, void *,...); /* * Operations defined on a XDR handle * * XDR *xdrs; * int32_t *int32p; * long *longp; * char* addr; * unsigned int len; * unsigned int pos; */ #define XDR_GETINT32(xdrs, int32p) \ (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) #define xdr_getint32(xdrs, int32p) \ (*(xdrs)->x_ops->x_getint32)(xdrs, int32p) #define XDR_PUTINT32(xdrs, int32p) \ (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) #define xdr_putint32(xdrs, int32p) \ (*(xdrs)->x_ops->x_putint32)(xdrs, int32p) #define XDR_GETLONG(xdrs, longp) \ (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define xdr_getlong(xdrs, longp) \ (*(xdrs)->x_ops->x_getlong)(xdrs, longp) #define XDR_PUTLONG(xdrs, longp) \ (*(xdrs)->x_ops->x_putlong)(xdrs, longp) #define xdr_putlong(xdrs, longp) \ (*(xdrs)->x_ops->x_putlong)(xdrs, longp) #define XDR_GETBYTES(xdrs, addr, len) \ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define xdr_getbytes(xdrs, addr, len) \ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len) #define XDR_PUTBYTES(xdrs, addr, len) \ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define xdr_putbytes(xdrs, addr, len) \ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len) #define XDR_GETPOS(xdrs) \ (*(xdrs)->x_ops->x_getpostn)(xdrs) #define xdr_getpos(xdrs) \ (*(xdrs)->x_ops->x_getpostn)(xdrs) #define XDR_SETPOS(xdrs, pos) \ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define xdr_setpos(xdrs, pos) \ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos) #define XDR_INLINE(xdrs, len) \ (*(xdrs)->x_ops->x_inline)(xdrs, len) #define xdr_inline(xdrs, len) \ (*(xdrs)->x_ops->x_inline)(xdrs, len) #define XDR_DESTROY(xdrs) \ do { \ if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs); \ } while (0) #define xdr_destroy(xdrs) \ do { \ if ((xdrs)->x_ops->x_destroy) \ (*(xdrs)->x_ops->x_destroy)(xdrs); \ } while (0) /* * Support struct for discriminated unions. * You create an array of xdrdiscrim structures, terminated with * a entry with a null procedure pointer. The xdr_union routine gets * the discriminant value and then searches the array of structures * for a matching value. If a match is found the associated xdr routine * is called to handle that part of the union. If there is * no match, then a default routine may be called. * If there is no match and no default routine it is an error. */ #define NULL_xdrproc_t ((xdrproc_t)0) struct xdr_discrim { int value; xdrproc_t proc; }; /* * Inline routines for fast encode/decode of primitive data types. * Caveat emptor: these use single memory cycles to get the * data from the underlying buffer, and will fail to operate * properly if the data is not aligned. The standard way to use these * is to say: * if ((buf = XDR_INLINE(xdrs, count)) == NULL) * return (FALSE); * <<< macro calls >>> * where ``count'' is the number of bytes of data occupied * by the primitive data types. * * N.B. and frozen for all time: each data type here uses 4 bytes * of external representation. */ #define IXDR_GET_INT32(buf) ((int32_t)ntohl((uint32_t)*(buf)++)) #define IXDR_PUT_INT32(buf, v) (*(buf)++ = (int32_t)htonl((uint32_t)(v))) #define IXDR_GET_U_INT32(buf) ((uint32_t)IXDR_GET_INT32(buf)) #define IXDR_PUT_U_INT32(buf, v) IXDR_PUT_INT32(buf, (int32_t)(v)) /* WARNING: The IXDR_*_LONG defines are removed by Sun for new platforms * and shouldn't be used any longer. Code which use this defines or longs * in the RPC code will not work on 64bit Solaris platforms ! */ #define IXDR_GET_LONG(buf) ((long)IXDR_GET_U_INT32(buf)) #define IXDR_PUT_LONG(buf, v) ((long)IXDR_PUT_INT32(buf, (long)(v))) #define IXDR_GET_U_LONG(buf) ((unsigned long)IXDR_GET_LONG(buf)) #define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG(buf, (long)(v)) #define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf)) #define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf)) #define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf)) #define IXDR_GET_U_SHORT(buf) ((unsigned short)IXDR_GET_LONG(buf)) #define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG(buf, (long)(v)) #define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG(buf, (long)(v)) #define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG(buf, (long)(v)) #define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG(buf, (long)(v)) /* * These are the "generic" xdr routines. * None of these can have const applied because it's not possible to * know whether the call is a read or a write to the passed parameter * also, the XDR structure is always updated by some of these calls. */ extern bool_t xdr_void (void) __THROW; extern bool_t xdr_short (XDR *__xdrs, short *__sp) __THROW; extern bool_t xdr_u_short (XDR *__xdrs, unsigned short *__usp) __THROW; extern bool_t xdr_int (XDR *__xdrs, int *__ip) __THROW; extern bool_t xdr_u_int (XDR *__xdrs, unsigned int *__up) __THROW; extern bool_t xdr_long (XDR *__xdrs, long *__lp) __THROW; extern bool_t xdr_u_long (XDR *__xdrs, unsigned long *__ulp) __THROW; extern bool_t xdr_hyper (XDR *__xdrs, int64_t *__llp) __THROW; extern bool_t xdr_u_hyper (XDR *__xdrs, uint64_t *__ullp) __THROW; extern bool_t xdr_longlong_t (XDR *__xdrs, int64_t *__llp) __THROW; extern bool_t xdr_u_longlong_t (XDR *__xdrs, uint64_t *__ullp) __THROW; extern bool_t xdr_int8_t (XDR *__xdrs, int8_t *__ip) __THROW; extern bool_t xdr_uint8_t (XDR *__xdrs, uint8_t *__up) __THROW; extern bool_t xdr_int16_t (XDR *__xdrs, int16_t *__ip) __THROW; extern bool_t xdr_uint16_t (XDR *__xdrs, uint16_t *__up) __THROW; extern bool_t xdr_int32_t (XDR *__xdrs, int32_t *__ip) __THROW; extern bool_t xdr_uint32_t (XDR *__xdrs, uint32_t *__up) __THROW; extern bool_t xdr_int64_t (XDR *__xdrs, int64_t *__ip) __THROW; extern bool_t xdr_uint64_t (XDR *__xdrs, uint64_t *__up) __THROW; extern bool_t xdr_bool (XDR *__xdrs, bool_t *__bp) __THROW; extern bool_t xdr_enum (XDR *__xdrs, enum_t *__ep) __THROW; extern bool_t xdr_array (XDR * _xdrs, char* *__addrp, unsigned int *__sizep, unsigned int __maxsize, unsigned int __elsize, xdrproc_t __elproc) __THROW; extern bool_t xdr_bytes (XDR *__xdrs, char **__cpp, unsigned int *__sizep, unsigned int __maxsize) __THROW; extern bool_t xdr_opaque (XDR *__xdrs, char* __cp, unsigned int __cnt) __THROW; extern bool_t xdr_string (XDR *__xdrs, char **__cpp, unsigned int __maxsize) __THROW; extern bool_t xdr_union (XDR *__xdrs, enum_t *__dscmp, char *__unp, const struct xdr_discrim *__choices, xdrproc_t dfault) __THROW; extern bool_t xdr_char (XDR *__xdrs, char *__cp) __THROW; extern bool_t xdr_u_char (XDR *__xdrs, unsigned char *__cp) __THROW; extern bool_t xdr_vector (XDR *__xdrs, char *__basep, unsigned int __nelem, unsigned int __elemsize, xdrproc_t __xdr_elem) __THROW; extern bool_t xdr_float (XDR *__xdrs, float *__fp) __THROW; extern bool_t xdr_double (XDR *__xdrs, double *__dp) __THROW; extern bool_t xdr_reference (XDR *__xdrs, char* *__xpp, unsigned int __size, xdrproc_t __proc) __THROW; extern bool_t xdr_pointer (XDR *__xdrs, char **__objpp, unsigned int __obj_size, xdrproc_t __xdr_obj) __THROW; extern bool_t xdr_wrapstring (XDR *__xdrs, char **__cpp) __THROW; extern unsigned long xdr_sizeof (xdrproc_t, void *) __THROW; /* * Common opaque bytes objects used by many rpc protocols; * declared here due to commonality. */ #define MAX_NETOBJ_SZ 1024 struct netobj { unsigned int n_len; char *n_bytes; }; typedef struct netobj netobj; extern bool_t xdr_netobj (XDR *__xdrs, struct netobj *__np) __THROW; /* * These are the public routines for the various implementations of * xdr streams. */ /* XDR using memory buffers */ extern void xdrmem_create (XDR *__xdrs, const char* __addr, unsigned int __size, enum xdr_op __xop) __THROW; /* XDR using stdio library */ extern void xdrstdio_create (XDR *__xdrs, FILE *__file, enum xdr_op __xop) __THROW; /* XDR pseudo records for tcp */ extern void xdrrec_create (XDR *__xdrs, unsigned int __sendsize, unsigned int __recvsize, char* __tcp_handle, int (*__readit) (char *, char *, int), int (*__writeit) (char *, char *, int)) __THROW; /* make end of xdr record */ extern bool_t xdrrec_endofrecord (XDR *__xdrs, bool_t __sendnow) __THROW; /* move to beginning of next record */ extern bool_t xdrrec_skiprecord (XDR *__xdrs) __THROW; /* true if no more input */ extern bool_t xdrrec_eof (XDR *__xdrs) __THROW; /* free memory buffers for xdr */ extern void xdr_free (xdrproc_t __proc, char *__objp) __THROW; __END_DECLS #endif /* rpc/xdr.h */ dietlibc-0.33~cvs20120325/include/sched.h010064400000000000000000000070551173363226500145770ustar00#ifndef _SCHED_H #define _SCHED_H 1 #include #include __BEGIN_DECLS /* * Scheduling policies */ #define SCHED_OTHER 0 #define SCHED_FIFO 1 #define SCHED_RR 2 /* * This is an additional bit set when we want to * yield the CPU for one re-schedule.. */ #define SCHED_YIELD 0x10 struct sched_param { int sched_priority; }; /* END OF COPY form kernel-header */ int __sched_setparam(pid_t pid, const struct sched_param* p); int sched_setparam(pid_t pid, const struct sched_param* p); int __sched_getparam(pid_t pid, struct sched_param* p); int sched_getparam(pid_t pid, struct sched_param* p); int __sched_getscheduler(pid_t pid); int sched_getscheduler(pid_t pid); int __sched_setscheduler(pid_t pid, int policy, const struct sched_param* p); int sched_setscheduler(pid_t pid, int policy, const struct sched_param* p); int __sched_yield(void); int sched_yield(void); int __sched_get_priority_max(int policy); int sched_get_priority_max(int policy); int __sched_get_priority_min(int policy); int sched_get_priority_min(int policy); int __sched_rr_get_interval(pid_t pid, struct timespec* tp); int sched_rr_get_interval(pid_t pid, struct timespec* tp); #ifdef _GNU_SOURCE /* * cloning flags: */ #define CSIGNAL 0x000000ff /* signal mask to be sent at exit */ #define CLONE_VM 0x00000100 /* set if VM shared between processes */ #define CLONE_FS 0x00000200 /* set if fs info shared between processes */ #define CLONE_FILES 0x00000400 /* set if open files shared between processes */ #define CLONE_SIGHAND 0x00000800 /* set if signal handlers and blocked signals shared */ #define CLONE_PID 0x00001000 /* set if pid shared */ #define CLONE_PTRACE 0x00002000 /* set if we want to let tracing continue on the child too */ #define CLONE_VFORK 0x00004000 /* set if the parent wants the child to wake it up on mm_release */ #define CLONE_PARENT 0x00008000 /* set if we want to have the same parent as the cloner */ #define CLONE_THREAD 0x00010000 /* Same thread group? */ #define CLONE_SIGNAL (CLONE_SIGHAND | CLONE_THREAD) int clone(int *(*fn)(void*),void* stack,int flags,void* arg, ...); int unshare(int flags); /* * Linux CPU affinity. * For simplicity it supports up to 32 CPUs for 32 bits systems and up to * 64 for 64 bits systems. Add the other CPU_SET(3) macros when needed. */ typedef unsigned long cpu_set_t; static inline void CPU_ZERO(cpu_set_t *set) {*set = 0;} static inline void CPU_SET(int cpu, cpu_set_t *set) {*set |= (1UL << cpu);} static inline void CPU_CLR(int cpu, cpu_set_t *set) {*set &= ~(1UL << cpu);} static inline int CPU_ISSET(int cpu, cpu_set_t *set) { return !!(*set & (1UL << cpu)); } static inline int CPU_COUNT(cpu_set_t *set) { int c; unsigned long v; /* Peter Wegner/Derrick Lehmer/Brian Kernighan's method */ for (c = 0, v = *set; v; c++) v &= v - 1; // clear the least significant bit set return c; } static inline void CPU_AND(cpu_set_t *dest, cpu_set_t *s1, cpu_set_t *s2){ *dest = *s1 & *s2; } static inline void CPU_OR(cpu_set_t *dest, cpu_set_t *s1, cpu_set_t *s2){ *dest = *s1 | *s2; } static inline void CPU_XOR(cpu_set_t *dest, cpu_set_t *s1, cpu_set_t *s2){ *dest = *s1 ^ *s2; } static inline int CPU_EQUAL(cpu_set_t *s1, cpu_set_t *s2){ return *s1 == *s2; } int sched_setaffinity(pid_t pid, size_t size, cpu_set_t *mask); int sched_getaffinity(pid_t pid, size_t size, cpu_set_t *mask); #define pthread_setaffinity_np sched_setaffinity #define pthread_getaffinity_np sched_getaffinity #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/scsi/scsi.h010064400000000000000000000156701173363226500154150ustar00/* Copyright (C) 1998, 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * This header file contains public constants and structures used by * the scsi code for linux. */ #ifndef _SCSI_SCSI_H #define _SCSI_SCSI_H 1 #include __BEGIN_DECLS /* * SCSI opcodes */ #define TEST_UNIT_READY 0x00 #define REZERO_UNIT 0x01 #define REQUEST_SENSE 0x03 #define FORMAT_UNIT 0x04 #define READ_BLOCK_LIMITS 0x05 #define REASSIGN_BLOCKS 0x07 #define READ_6 0x08 #define WRITE_6 0x0a #define SEEK_6 0x0b #define READ_REVERSE 0x0f #define WRITE_FILEMARKS 0x10 #define SPACE 0x11 #define INQUIRY 0x12 #define RECOVER_BUFFERED_DATA 0x14 #define MODE_SELECT 0x15 #define RESERVE 0x16 #define RELEASE 0x17 #define COPY 0x18 #define ERASE 0x19 #define MODE_SENSE 0x1a #define START_STOP 0x1b #define RECEIVE_DIAGNOSTIC 0x1c #define SEND_DIAGNOSTIC 0x1d #define ALLOW_MEDIUM_REMOVAL 0x1e #define SET_WINDOW 0x24 #define READ_CAPACITY 0x25 #define READ_10 0x28 #define WRITE_10 0x2a #define SEEK_10 0x2b #define WRITE_VERIFY 0x2e #define VERIFY 0x2f #define SEARCH_HIGH 0x30 #define SEARCH_EQUAL 0x31 #define SEARCH_LOW 0x32 #define SET_LIMITS 0x33 #define PRE_FETCH 0x34 #define READ_POSITION 0x34 #define SYNCHRONIZE_CACHE 0x35 #define LOCK_UNLOCK_CACHE 0x36 #define READ_DEFECT_DATA 0x37 #define MEDIUM_SCAN 0x38 #define COMPARE 0x39 #define COPY_VERIFY 0x3a #define WRITE_BUFFER 0x3b #define READ_BUFFER 0x3c #define UPDATE_BLOCK 0x3d #define READ_LONG 0x3e #define WRITE_LONG 0x3f #define CHANGE_DEFINITION 0x40 #define WRITE_SAME 0x41 #define READ_TOC 0x43 #define LOG_SELECT 0x4c #define LOG_SENSE 0x4d #define MODE_SELECT_10 0x55 #define RESERVE_10 0x56 #define RELEASE_10 0x57 #define MODE_SENSE_10 0x5a #define PERSISTENT_RESERVE_IN 0x5e #define PERSISTENT_RESERVE_OUT 0x5f #define MOVE_MEDIUM 0xa5 #define READ_12 0xa8 #define WRITE_12 0xaa #define WRITE_VERIFY_12 0xae #define SEARCH_HIGH_12 0xb0 #define SEARCH_EQUAL_12 0xb1 #define SEARCH_LOW_12 0xb2 #define READ_ELEMENT_STATUS 0xb8 #define SEND_VOLUME_TAG 0xb6 #define WRITE_LONG_2 0xea /* * Status codes */ #define GOOD 0x00 #define CHECK_CONDITION 0x01 #define CONDITION_GOOD 0x02 #define BUSY 0x04 #define INTERMEDIATE_GOOD 0x08 #define INTERMEDIATE_C_GOOD 0x0a #define RESERVATION_CONFLICT 0x0c #define COMMAND_TERMINATED 0x11 #define QUEUE_FULL 0x14 #define STATUS_MASK 0x3e /* * SENSE KEYS */ #define NO_SENSE 0x00 #define RECOVERED_ERROR 0x01 #define NOT_READY 0x02 #define MEDIUM_ERROR 0x03 #define HARDWARE_ERROR 0x04 #define ILLEGAL_REQUEST 0x05 #define UNIT_ATTENTION 0x06 #define DATA_PROTECT 0x07 #define BLANK_CHECK 0x08 #define COPY_ABORTED 0x0a #define ABORTED_COMMAND 0x0b #define VOLUME_OVERFLOW 0x0d #define MISCOMPARE 0x0e /* * DEVICE TYPES */ #define TYPE_DISK 0x00 #define TYPE_TAPE 0x01 #define TYPE_PROCESSOR 0x03 /* HP scanners use this */ #define TYPE_WORM 0x04 /* Treated as ROM by our system */ #define TYPE_ROM 0x05 #define TYPE_SCANNER 0x06 #define TYPE_MOD 0x07 /* Magneto-optical disk - * - treated as TYPE_DISK */ #define TYPE_MEDIUM_CHANGER 0x08 #define TYPE_ENCLOSURE 0x0d /* Enclosure Services Device */ #define TYPE_NO_LUN 0x7f /* * standard mode-select header prepended to all mode-select commands * * moved here from cdrom.h -- kraxel */ struct ccs_modesel_head { unsigned char _r1; /* reserved. */ unsigned char medium; /* device-specific medium type. */ unsigned char _r2; /* reserved. */ unsigned char block_desc_length; /* block descriptor length. */ unsigned char density; /* device-specific density code. */ unsigned char number_blocks_hi; /* number of blocks in this block desc. */ unsigned char number_blocks_med; unsigned char number_blocks_lo; unsigned char _r3; unsigned char block_length_hi; /* block length for blocks in this desc. */ unsigned char block_length_med; unsigned char block_length_lo; }; /* * MESSAGE CODES */ #define COMMAND_COMPLETE 0x00 #define EXTENDED_MESSAGE 0x01 #define EXTENDED_MODIFY_DATA_POINTER 0x00 #define EXTENDED_SDTR 0x01 #define EXTENDED_EXTENDED_IDENTIFY 0x02 /* SCSI-I only */ #define EXTENDED_WDTR 0x03 #define SAVE_POINTERS 0x02 #define RESTORE_POINTERS 0x03 #define DISCONNECT 0x04 #define INITIATOR_ERROR 0x05 #define ABORT 0x06 #define MESSAGE_REJECT 0x07 #define NOP 0x08 #define MSG_PARITY_ERROR 0x09 #define LINKED_CMD_COMPLETE 0x0a #define LINKED_FLG_CMD_COMPLETE 0x0b #define BUS_DEVICE_RESET 0x0c #define INITIATE_RECOVERY 0x0f /* SCSI-II only */ #define RELEASE_RECOVERY 0x10 /* SCSI-II only */ #define SIMPLE_QUEUE_TAG 0x20 #define HEAD_OF_QUEUE_TAG 0x21 #define ORDERED_QUEUE_TAG 0x22 /* * Here are some scsi specific ioctl commands which are sometimes useful. */ /* These are a few other constants only used by scsi devices. */ #define SCSI_IOCTL_GET_IDLUN 0x5382 /* Used to turn on and off tagged queuing for scsi devices. */ #define SCSI_IOCTL_TAGGED_ENABLE 0x5383 #define SCSI_IOCTL_TAGGED_DISABLE 0x5384 /* Used to obtain the host number of a device. */ #define SCSI_IOCTL_PROBE_HOST 0x5385 /* Used to get the bus number for a device. */ #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 __END_DECLS #endif /* scsi/scsi.h */ dietlibc-0.33~cvs20120325/include/scsi/scsi_ioctl.h010064400000000000000000000026021173363226500165760ustar00/* Copyright (C) 1999 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef _SCSI_IOCTL_H #define _SCSI_IOCTL_H /* IOCTLs for SCSI. */ #define SCSI_IOCTL_SEND_COMMAND 1 /* Send a command to the SCSI host. */ #define SCSI_IOCTL_TEST_UNIT_READY 2 /* Test if unit is ready. */ #define SCSI_IOCTL_BENCHMARK_COMMAND 3 #define SCSI_IOCTL_SYNC 4 /* Request synchronous parameters. */ #define SCSI_IOCTL_START_UNIT 5 #define SCSI_IOCTL_STOP_UNIT 6 #define SCSI_IOCTL_DOORLOCK 0x5380 /* Lock the eject mechanism. */ #define SCSI_IOCTL_DOORUNLOCK 0x5381 /* Unlock the mechanism. */ #endif dietlibc-0.33~cvs20120325/include/scsi/sg.h010064400000000000000000000267551173363226500150730ustar00/* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The GNU C Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with the GNU C Library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* History: Started: Aug 9 by Lawrence Foard (entropy@world.std.com), to allow user process control of SCSI devices. Development Sponsored by Killy Corp. NY NY */ #ifndef _SCSI_SG_H #define _SCSI_SG_H 1 #include __BEGIN_DECLS /* New interface introduced in the 3.x SG drivers follows */ /* Same structure as used by readv() Linux system call. It defines one scatter-gather element. */ typedef struct sg_iovec { void * iov_base; /* Starting address */ size_t iov_len; /* Length in bytes */ } sg_iovec_t; typedef struct sg_io_hdr { int interface_id; /* [i] 'S' for SCSI generic (required) */ int dxfer_direction; /* [i] data transfer direction */ unsigned char cmd_len; /* [i] SCSI command length ( <= 16 bytes) */ unsigned char mx_sb_len; /* [i] max length to write to sbp */ unsigned short int iovec_count; /* [i] 0 implies no scatter gather */ unsigned int dxfer_len; /* [i] byte count of data transfer */ void * dxferp; /* [i], [*io] points to data transfer memory or scatter gather list */ unsigned char * cmdp; /* [i], [*i] points to command to perform */ unsigned char * sbp; /* [i], [*o] points to sense_buffer memory */ unsigned int timeout; /* [i] MAX_UINT->no timeout (unit: millisec) */ unsigned int flags; /* [i] 0 -> default, see SG_FLAG... */ int pack_id; /* [i->o] unused internally (normally) */ void * usr_ptr; /* [i->o] unused internally */ unsigned char status; /* [o] scsi status */ unsigned char masked_status;/* [o] shifted, masked scsi status */ unsigned char msg_status; /* [o] messaging level data (optional) */ unsigned char sb_len_wr; /* [o] byte count actually written to sbp */ unsigned short int host_status; /* [o] errors from host adapter */ unsigned short int driver_status;/* [o] errors from software driver */ int resid; /* [o] dxfer_len - actual_transferred */ unsigned int duration; /* [o] time taken by cmd (unit: millisec) */ unsigned int info; /* [o] auxiliary information */ } sg_io_hdr_t; /* Use negative values to flag difference from original sg_header structure. */ #define SG_DXFER_NONE -1 /* e.g. a SCSI Test Unit Ready command */ #define SG_DXFER_TO_DEV -2 /* e.g. a SCSI WRITE command */ #define SG_DXFER_FROM_DEV -3 /* e.g. a SCSI READ command */ #define SG_DXFER_TO_FROM_DEV -4 /* treated like SG_DXFER_FROM_DEV with the additional property than during indirect IO the user buffer is copied into the kernel buffers before the transfer */ /* following flag values can be "or"-ed together */ #define SG_FLAG_DIRECT_IO 1 /* default is indirect IO */ #define SG_FLAG_LUN_INHIBIT 2 /* default is to put device's lun into */ /* the 2nd byte of SCSI command */ #define SG_FLAG_NO_DXFER 0x10000 /* no transfer of kernel buffers to/from */ /* user space (debug indirect IO) */ /* The following 'info' values are "or"-ed together. */ #define SG_INFO_OK_MASK 0x1 #define SG_INFO_OK 0x0 /* no sense, host nor driver "noise" */ #define SG_INFO_CHECK 0x1 /* something abnormal happened */ #define SG_INFO_DIRECT_IO_MASK 0x6 #define SG_INFO_INDIRECT_IO 0x0 /* data xfer via kernel buffers (or no xfer) */ #define SG_INFO_DIRECT_IO 0x2 /* direct IO requested and performed */ #define SG_INFO_MIXED_IO 0x4 /* part direct, part indirect IO */ /* Request information about a specific SG device, used by SG_GET_SCSI_ID ioctl (). */ struct sg_scsi_id { /* Host number as in "scsi" where 'n' is one of 0, 1, 2 etc. */ int host_no; int channel; /* SCSI id of target device. */ int scsi_id; int lun; /* TYPE_... defined in . */ int scsi_type; /* Host (adapter) maximum commands per lun. */ short int h_cmd_per_lun; /* Device (or adapter) maximum queue length. */ short int d_queue_depth; /* Unused, set to 0 for now. */ int unused[2]; }; /* Used by SG_GET_REQUEST_TABLE ioctl(). */ typedef struct sg_req_info { char req_state; /* 0 -> not used, 1 -> written, 2 -> ready to read */ char orphan; /* 0 -> normal request, 1 -> from interruped SG_IO */ char sg_io_owned; /* 0 -> complete with read(), 1 -> owned by SG_IO */ char problem; /* 0 -> no problem detected, 1 -> error to report */ int pack_id; /* pack_id associated with request */ void * usr_ptr; /* user provided pointer (in new interface) */ unsigned int duration; /* millisecs elapsed since written (req_state==1) or request duration (req_state==2) */ int unused; } sg_req_info_t; /* IOCTLs: Those ioctls that are relevant to the SG 3.x drivers follow. [Those that only apply to the SG 2.x drivers are at the end of the file.] (_GET_s yield result via 'int *' 3rd argument unless otherwise indicated) */ #define SG_EMULATED_HOST 0x2203 /* true for emulated host adapter (ATAPI) */ /* Used to configure SCSI command transformation layer for ATAPI devices */ /* Only supported by the ide-scsi driver */ #define SG_SET_TRANSFORM 0x2204 /* N.B. 3rd arg is not pointer but value: */ /* 3rd arg = 0 to disable transform, 1 to enable it */ #define SG_GET_TRANSFORM 0x2205 #define SG_SET_RESERVED_SIZE 0x2275 /* request a new reserved buffer size */ #define SG_GET_RESERVED_SIZE 0x2272 /* actual size of reserved buffer */ /* The following ioctl has a 'sg_scsi_id_t *' object as its 3rd argument. */ #define SG_GET_SCSI_ID 0x2276 /* Yields fd's bus, chan, dev, lun + type */ /* SCSI id information can also be obtained from SCSI_IOCTL_GET_IDLUN */ /* Override host setting and always DMA using low memory ( <16MB on i386) */ #define SG_SET_FORCE_LOW_DMA 0x2279 /* 0-> use adapter setting, 1-> force */ #define SG_GET_LOW_DMA 0x227a /* 0-> use all ram for dma; 1-> low dma ram */ /* When SG_SET_FORCE_PACK_ID set to 1, pack_id is input to read() which tries to fetch a packet with a matching pack_id, waits, or returns EAGAIN. If pack_id is -1 then read oldest waiting. When ...FORCE_PACK_ID set to 0 then pack_id ignored by read() and oldest readable fetched. */ #define SG_SET_FORCE_PACK_ID 0x227b #define SG_GET_PACK_ID 0x227c /* Yields oldest readable pack_id (or -1) */ #define SG_GET_NUM_WAITING 0x227d /* Number of commands awaiting read() */ /* Yields max scatter gather tablesize allowed by current host adapter */ #define SG_GET_SG_TABLESIZE 0x227F /* 0 implies can't do scatter gather */ #define SG_GET_VERSION_NUM 0x2282 /* Example: version 2.1.34 yields 20134 */ /* Returns -EBUSY if occupied. 3rd argument pointer to int (see next) */ #define SG_SCSI_RESET 0x2284 /* Associated values that can be given to SG_SCSI_RESET follow */ #define SG_SCSI_RESET_NOTHING 0 #define SG_SCSI_RESET_DEVICE 1 #define SG_SCSI_RESET_BUS 2 #define SG_SCSI_RESET_HOST 3 /* synchronous SCSI command ioctl, (only in version 3 interface) */ #define SG_IO 0x2285 /* similar effect as write() followed by read() */ #define SG_GET_REQUEST_TABLE 0x2286 /* yields table of active requests */ /* How to treat EINTR during SG_IO ioctl(), only in SG 3.x series */ #define SG_SET_KEEP_ORPHAN 0x2287 /* 1 -> hold for read(), 0 -> drop (def) */ #define SG_GET_KEEP_ORPHAN 0x2288 #define SG_SCATTER_SZ (8 * 4096) /* PAGE_SIZE not available to user */ /* Largest size (in bytes) a single scatter-gather list element can have. The value must be a power of 2 and <= (PAGE_SIZE * 32) [131072 bytes on i386]. The minimum value is PAGE_SIZE. If scatter-gather not supported by adapter then this value is the largest data block that can be read/written by a single scsi command. The user can find the value of PAGE_SIZE by calling getpagesize() defined in unistd.h . */ #define SG_DEFAULT_RETRIES 1 /* Defaults, commented if they differ from original sg driver */ #define SG_DEF_FORCE_LOW_DMA 0 /* was 1 -> memory below 16MB on i386 */ #define SG_DEF_FORCE_PACK_ID 0 #define SG_DEF_KEEP_ORPHAN 0 #define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ /* load time option */ /* maximum outstanding requests, write() yields EDOM if exceeded */ #define SG_MAX_QUEUE 16 #define SG_BIG_BUFF SG_DEF_RESERVED_SIZE /* for backward compatibility */ /* Alternate style type names, "..._t" variants preferred */ typedef struct sg_io_hdr Sg_io_hdr; typedef struct sg_io_vec Sg_io_vec; typedef struct sg_scsi_id Sg_scsi_id; typedef struct sg_req_info Sg_req_info; /* vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv */ /* The older SG interface based on the 'sg_header' structure follows. */ /* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */ #define SG_MAX_SENSE 16 /* this only applies to the sg_header interface */ struct sg_header { /* Length of incoming packet (including header). */ int pack_len; /* Maximal length of expected reply. */ int reply_len; /* Id number of packet. */ int pack_id; /* 0==ok, otherwise error number. */ int result; /* Force 12 byte command length for group 6 & 7 commands. */ unsigned int twelve_byte:1; /* SCSI status from target. */ unsigned int target_status:5; /* Host status (see "DID" codes). */ unsigned int host_status:8; /* Driver status+suggestion. */ unsigned int driver_status:8; /* Unused. */ unsigned int other_flags:10; /* Output in 3 cases: when target_status is CHECK_CONDITION or when target_status is COMMAND_TERMINATED or when (driver_status & DRIVER_SENSE) is true. */ unsigned char sense_buffer[SG_MAX_SENSE]; }; /* IOCTLs: The following are not required (or ignored) when the sg_io_hdr_t interface is used. They are kept for backward compatibility with the original and version 2 drivers. */ #define SG_SET_TIMEOUT 0x2201 /* Set timeout; *(int *)arg==timeout. */ #define SG_GET_TIMEOUT 0x2202 /* Get timeout; return timeout. */ /* Get/set command queuing state per fd (default is SG_DEF_COMMAND_Q). */ #define SG_GET_COMMAND_Q 0x2270 /* Yields 0 (queuing off) or 1 (on). */ #define SG_SET_COMMAND_Q 0x2271 /* Change queuing state with 0 or 1. */ /* Turn on error sense trace (1..8), dump this device to log/console (9) or dump all sg device states ( >9 ) to log/console. */ #define SG_SET_DEBUG 0x227e /* 0 -> turn off debug */ #define SG_NEXT_CMD_LEN 0x2283 /* Override SCSI command length with given number on the next write() on this file descriptor. */ /* Defaults, commented if they differ from original sg driver */ #define SG_DEFAULT_TIMEOUT (60*HZ) /* HZ == 'jiffies in 1 second' */ #define SG_DEF_COMMAND_Q 0 /* command queuing is always on when the new interface is used */ #define SG_DEF_UNDERRUN_FLAG 0 __END_DECLS #endif /* scsi/sg.h */ dietlibc-0.33~cvs20120325/include/semaphore.h010064400000000000000000000014131173363226500154640ustar00#ifndef __SEMAPHORE_H__ #define __SEMAPHORE_H__ #include #include __BEGIN_DECLS typedef struct { pthread_mutex_t lock; pthread_cond_t cond; int value; uint32_t magic; } sem_t; #define SEM_FAILED ((sem_t*)0) #define SEM_VALUE_MAX ((int)((~0u)>>1)) #define SEM_MAGIC 0x35d108f2 int sem_destroy(sem_t*sem) __THROW; int sem_getvalue(sem_t*sem,int*sval) __THROW; int sem_init(sem_t*sem,int pshared,unsigned int value) __THROW; int sem_post(sem_t*sem) __THROW; int sem_trywait(sem_t*sem) __THROW; int sem_wait(sem_t*sem) __THROW; sem_t*sem_open(const char*name,int oflag,...) __THROW; int sem_close(sem_t*sem) __THROW; int sem_unlink(const char*name) __THROW; int sem_timedwait(sem_t*sem,const struct timespec*abstime) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/setjmp.h010064400000000000000000000120721173363226500150060ustar00#ifndef _SETJMP_H #define _SETJMP_H #include __BEGIN_DECLS #ifdef __i386__ #ifndef __ASSEMBLER__ typedef long __jmp_buf[6]; #endif # define JB_BX 0 # define JB_SI 1 # define JB_DI 2 # define JB_BP 3 # define JB_SP 4 # define JB_PC 5 # define JB_SIZE 24 #endif #ifdef __x86_64__ #ifndef __ASSEMBLER__ typedef long __jmp_buf[8]; #endif # define JB_RBX 0 # define JB_RBP 1 # define JB_R12 2 # define JB_R13 3 # define JB_R14 4 # define JB_R15 5 # define JB_RSP 6 # define JB_PC 7 # define JB_SIZE 64 #endif #ifdef __s390__ #ifndef __ASSEMBLER__ typedef struct { long int gregs[10]; long fpregs[4]; } __jmp_buf[1]; #endif #define __JB_GPR6 0 #define __JB_GPR7 1 #define __JB_GPR8 2 #define __JB_GPR9 3 #define __JB_GPR10 4 #define __JB_GPR11 5 #define __JB_GPR12 6 #define __JB_GPR13 7 #define __JB_GPR14 8 #define __JB_GPR15 9 #define _JMPBUF_UNWINDS(jmpbuf, address) ((int) (address) < (jmpbuf)->gregs[__JB_GPR15]) #endif #ifdef __alpha__ #define JB_S0 0 #define JB_S1 1 #define JB_S2 2 #define JB_S3 3 #define JB_S4 4 #define JB_S5 5 #define JB_PC 6 #define JB_FP 7 #define JB_SP 8 #define JB_F2 9 #define JB_F3 10 #define JB_F4 11 #define JB_F5 12 #define JB_F6 13 #define JB_F7 14 #define JB_F8 15 #define JB_F9 16 #ifndef __ASSEMBLER__ typedef long int __jmp_buf[17]; #endif #endif #ifdef __mips__ #ifndef __ASSEMBLER__ typedef struct { void * __pc; /* Program counter. */ void * __sp; /* Stack pointer. */ int __regs[8]; /* Callee-saved registers s0 through s7. */ void * __fp; /* The frame pointer. */ void * __gp; /* The global pointer. */ int __fpc_csr; /* Floating point status register. */ double __fpregs[6]; /* Callee-saved floating point registers. */ } __jmp_buf[1]; #endif #endif #ifdef __sparc__ #ifdef __arch64__ #define MC_TSTATE 0 #define MC_PC 1 #define MC_NPC 2 #define MC_Y 3 #define MC_G1 4 #define MC_G2 5 #define MC_G3 6 #define MC_G4 7 #define MC_G5 8 #define MC_G6 9 #define MC_G7 10 #define MC_O0 11 #define MC_O1 12 #define MC_O2 13 #define MC_O3 14 #define MC_O4 15 #define MC_O5 16 #define MC_O6 17 #define MC_O7 18 #define MC_NGREG 19 #define FLAG_SAVEMASK 512 #ifndef __ASSEMBLER__ #include /* this equal to ucontext from "include/asm-sparc64/uctx.h" */ typedef struct __sparc64_jmp_buf { struct __sparc64_jmp_buf *uc_link; unsigned long uc_flags; sigset_t uc_sigmask; struct { unsigned long mc_gregs[MC_NGREG]; unsigned long mc_fp; unsigned long mc_i7; struct { union { unsigned int sregs[32]; unsigned long dregs[32]; long double qregs[16]; } mcfpu_fregs; unsigned long mcfpu_fsr; unsigned long mcfpu_fprs; unsigned long mcfpu_gsr; struct { unsigned long *mcfq_addr; unsigned int mcfq_insn; } *mcfpu_fq; unsigned char mcfpu_qcnt; unsigned char mcfpu_qentsz; unsigned char mcfpu_enab; } mc_fpregs; } uc_mcontext; } __jmp_buf[1]; #endif #else #define JB_SP 0 #define JB_FP 1 #define JB_PC 2 #ifndef __ASSEMBLER__ typedef int __jmp_buf[3]; #endif #endif #endif #ifdef __arm__ #define __JMP_BUF_SP 8 #ifndef __ASSEMBLER__ typedef int __jmp_buf[24]; #endif #endif #if defined(__powerpc__) || defined(__powerpc64__) /* 40 registers: 22 GPRs (4 or 8 bytes) + 18 FPRs (8 bytes) */ #define JB_GPR1 0 /* Also known as the stack pointer */ #define JB_GPR2 1 #define JB_LR 2 /* The address we will return to */ #define JB_GPRS 3 /* GPRs 14 through 31 are saved, 18 in total */ #define JB_CR 21 /* Condition code registers. */ #define JB_FPRS 22 /* FPRs 14 through 31 are saved, 18*2 words total */ #if defined(__powerpc64__) #define JB_SIZE (40*8) #ifndef __ASSEMBLER__ typedef long __jmp_buf[40]; #endif #else #define JB_SIZE (58*4) /* == 22*4 + 18*8 */ #ifndef __ASSEMBLER__ typedef long __jmp_buf[58] __attribute__ ((__aligned__(8))); #endif #endif #endif #ifdef __hppa__ #ifndef __ASSEMBLER__ typedef double __jmp_buf[21]; #endif #endif #ifdef __ia64__ #ifndef __ASSEMBLER__ typedef long __jmp_buf[70] __attribute__ ((__aligned__(16))); #endif #endif #ifndef __ASSEMBLER__ #include /* typedef int sig_atomic_t; */ #define __sig_atomic_t sig_atomic_t /* Calling environment, plus possibly a saved signal mask. */ typedef struct __jmp_buf_tag { /* C++ doesn't like tagless structs. */ /* NOTE: The machine-dependent definitions of `__sigsetjmp' * assume that a `jmp_buf' begins with a `__jmp_buf'. * Do not move this member or add others before it. */ __jmp_buf __jmpbuf; /* Calling environment. */ int __mask_was_saved; /* Saved the signal mask? */ sigset_t __saved_mask; /* Saved signal mask. */ } jmp_buf[1]; extern int __sigsetjmp(jmp_buf __env,int __savemask) __THROW; extern void longjmp(jmp_buf __env,int __val) __THROW __attribute__((__noreturn__)); typedef jmp_buf sigjmp_buf; extern void siglongjmp(sigjmp_buf __env,int __val) __THROW __attribute__((__noreturn__)); #ifdef _BSD_SOURCE #define setjmp(env) __sigsetjmp(env,1) #else #define setjmp(env) __sigsetjmp(env,0) #endif #define sigsetjmp(a,b) __sigsetjmp(a,b) #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/shadow.h010064400000000000000000000017261173363226500147750ustar00#ifndef _SHADOW_H #define _SHADOW_H #include #include __BEGIN_DECLS struct spwd { char* sp_namp; /* user login name */ char* sp_pwdp; /* encrypted password */ long sp_lstchg; /* last password change */ int sp_min; /* days until change allowed. */ int sp_max; /* days before change required */ int sp_warn; /* days warning for expiration */ int sp_inact; /* days before account inactive */ int sp_expire; /* date when account expires */ int sp_flag; /* reserved for future use */ }; extern struct spwd* getspent(void) __THROW; extern void setspent(void) __THROW; extern void endspent(void) __THROW; extern struct spwd* getspnam (const char* __name) __THROW; int getspent_r(struct spwd* res, char* buf, size_t buflen, struct spwd** res_sig) __THROW; int getspnam_r(const char* name, struct spwd* res, char* buf, size_t buflen, struct spwd** res_sig) __THROW; __END_DECLS #endif /* _SHADOW_H */ dietlibc-0.33~cvs20120325/include/signal.h010064400000000000000000000343711173363226500147670ustar00#ifndef _SIGNAL_H #define _SIGNAL_H #include __BEGIN_DECLS #define __WANT_POSIX1B_SIGNALS__ #include #include #define NSIG 32 #ifdef __mips__ #define _NSIG 128 #else #define _NSIG 64 #endif #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 #define SIGILL 4 #define SIGTRAP 5 #define SIGABRT 6 #define SIGIOT 6 #define SIGFPE 8 #define SIGKILL 9 #define SIGSEGV 11 #define SIGPIPE 13 #define SIGALRM 14 #define SIGTERM 15 #define SIGUNUSED 31 #if defined(__i386__) || defined(__x86_64__) || defined(__powerpc__) || defined(__arm__) \ || defined(__s390__) || defined(__ia64__) || defined(__powerpc64__) #define SIGBUS 7 #define SIGUSR1 10 #define SIGUSR2 12 #define SIGSTKFLT 16 #define SIGCHLD 17 #define SIGCONT 18 #define SIGSTOP 19 #define SIGTSTP 20 #define SIGTTIN 21 #define SIGTTOU 22 #define SIGURG 23 #define SIGXCPU 24 #define SIGXFSZ 25 #define SIGVTALRM 26 #define SIGPROF 27 #define SIGWINCH 28 #define SIGIO 29 #define SIGPWR 30 #define SIGSYS 31 #elif defined(__alpha__) || defined(__sparc__) #define SIGEMT 7 #define SIGBUS 10 #define SIGSYS 12 #define SIGURG 16 #define SIGSTOP 17 #define SIGTSTP 18 #define SIGCONT 19 #define SIGCHLD 20 #define SIGTTIN 21 #define SIGTTOU 22 #define SIGIO 23 #define SIGXCPU 24 #define SIGXFSZ 25 #define SIGVTALRM 26 #define SIGPROF 27 #define SIGWINCH 28 #define SIGPWR 29 #define SIGUSR1 30 #define SIGUSR2 31 #if defined(__alpha__) #define SIGINFO SIGPWR #endif #elif defined(__mips__) #define SIGEMT 7 #define SIGBUS 10 #define SIGSYS 12 #define SIGUSR1 16 #define SIGUSR2 17 #define SIGCHLD 18 #define SIGPWR 19 #define SIGWINCH 20 #define SIGURG 21 #define SIGIO 22 #define SIGSTOP 23 #define SIGTSTP 24 #define SIGCONT 25 #define SIGTTIN 26 #define SIGTTOU 27 #define SIGVTALRM 28 #define SIGPROF 29 #define SIGXCPU 30 #define SIGXFSZ 31 #elif defined(__hppa__) #define SIGEMT 7 #define SIGBUS 10 #define SIGSYS 12 #define SIGUSR1 16 #define SIGUSR2 17 #define SIGCHLD 18 #define SIGPWR 19 #define SIGVTALRM 20 #define SIGPROF 21 #define SIGIO 22 #define SIGWINCH 23 #define SIGSTOP 24 #define SIGTSTP 25 #define SIGCONT 26 #define SIGTTIN 27 #define SIGTTOU 28 #define SIGURG 29 #define SIGLOST 30 #define SIGUNUSED 31 #define SIGRESERVE SIGUNUSE #define SIGXCPU 33 #define SIGXFSZ 34 #define SIGSTKFLT 36 #else #error signal layout not yet known #endif #define SIGCLD SIGCHLD #define SIGPOLL SIGIO /* These should not be considered constants from userland. */ #ifdef __hppa__ #define SIGRTMIN 37 #else #define SIGLOST SIGPWR #define SIGRTMIN 32 #endif #define SIGRTMAX (_NSIG-1) /* SA_FLAGS values: */ #if defined(__alpha__) #define SA_ONSTACK 0x00000001 #define SA_RESTART 0x00000002 #define SA_NOCLDSTOP 0x00000004 #define SA_NODEFER 0x00000008 #define SA_RESETHAND 0x00000010 #define SA_NOCLDWAIT 0x00000020 /* not supported yet */ #define SA_SIGINFO 0x00000040 #define SA_INTERRUPT 0x20000000 /* dummy -- ignored */ #elif defined(__hppa__) #define SA_ONSTACK 0x00000001 #define SA_RESETHAND 0x00000004 #define SA_NOCLDSTOP 0x00000008 #define SA_SIGINFO 0x00000010 #define SA_NODEFER 0x00000020 #define SA_RESTART 0x00000040 #define SA_NOCLDWAIT 0x00000080 /* not supported yet */ #define _SA_SIGGFAULT 0x00000100 /* HPUX */ #define SA_INTERRUPT 0x20000000 /* dummy -- ignored */ #define SA_RESTORER 0x04000000 /* obsolete -- ignored */ #elif defined (__sparc__) #define SV_SSTACK 1 /* This signal handler should use sig-stack */ #define SV_INTR 2 /* Sig return should not restart system call */ #define SV_RESET 4 /* Set handler to SIG_DFL upon taken signal */ #define SV_IGNCHILD 8 /* Do not send SIGCHLD */ #define SA_NOCLDSTOP SV_IGNCHILD #define SA_STACK SV_SSTACK #define SA_ONSTACK SV_SSTACK #define SA_RESTART SV_INTR #define SA_RESETHAND SV_RESET #define SA_INTERRUPT 0x10 #define SA_NODEFER 0x20 #define SA_SHIRQ 0x40 #define SA_NOCLDWAIT 0x100 /* not supported yet */ #define SA_SIGINFO 0x200 #else #if defined (__mips__) #define SA_NOCLDSTOP 0x00000001 #define SA_SIGINFO 0x00000008 #define SA_NOCLDWAIT 0x00010000 /* Not supported yet */ #else #define SA_NOCLDSTOP 0x00000001 #define SA_NOCLDWAIT 0x00000002 /* not supported yet */ #define SA_SIGINFO 0x00000004 #endif #if defined(__arm__) #define SA_THIRTYTWO 0x02000000 #endif #define SA_RESTORER 0x04000000 #define SA_ONSTACK 0x08000000 #define SA_RESTART 0x10000000 #define SA_INTERRUPT 0x20000000 /* dummy -- ignored */ #define SA_NODEFER 0x40000000 #define SA_RESETHAND 0x80000000 #endif /* ugh, historic Linux legacy, for gpm :-( */ #define SA_NOMASK SA_NODEFER #define SA_ONESHOT SA_RESETHAND /* sigaltstack controls */ #define SS_ONSTACK 1 #define SS_DISABLE 2 #define MINSIGSTKSZ 2048 #define SIGSTKSZ 8192 #if defined(__sparc__) #define SIG_BLOCK 1 #define SIG_UNBLOCK 2 #define SIG_SETMASK 4 #elif defined(__alpha__) || defined(__mips__) #define SIG_BLOCK 1 #define SIG_UNBLOCK 2 #define SIG_SETMASK 3 #else #define SIG_BLOCK 0 /* for blocking signals */ #define SIG_UNBLOCK 1 /* for unblocking signals */ #define SIG_SETMASK 2 /* for setting the signal mask */ #endif typedef int sig_atomic_t; typedef void (*sighandler_t)(int); #ifdef _BSD_SOURCE typedef sighandler_t sig_t; #endif #ifdef _GNU_SOURCE typedef sighandler_t __sighandler_t; /* shoot the glibc people! */ #endif #define SIG_DFL ((sighandler_t)0L) /* default signal handling */ #define SIG_IGN ((sighandler_t)1L) /* ignore signal */ #define SIG_ERR ((sighandler_t)-1L) /* error return from signal */ typedef union sigval { int sival_int; void *sival_ptr; } sigval_t; #define SI_MAX_SIZE 128 #if __WORDSIZE == 64 #define SI_PAD_SIZE ((SI_MAX_SIZE/sizeof(int32_t)) - 4) #else #define SI_PAD_SIZE ((SI_MAX_SIZE/sizeof(int32_t)) - 3) #endif #ifdef __sparc_v9__ typedef int32_t __band_t; #else typedef long __band_t; #endif typedef struct siginfo { int32_t si_signo; int32_t si_errno; int32_t si_code; union { int32_t _pad[SI_PAD_SIZE]; /* kill() */ struct { pid_t _pid; /* sender's pid */ uid_t _uid; /* sender's uid */ } _kill; /* POSIX.1b timers */ struct { uint32_t _timer1; uint32_t _timer2; } _timer; /* POSIX.1b signals */ struct { pid_t _pid; /* sender's pid */ uid_t _uid; /* sender's uid */ sigval_t _sigval; } _rt; /* SIGCHLD */ struct { pid_t _pid; /* which child */ uid_t _uid; /* sender's uid */ int32_t _status; /* exit code */ clock_t _utime; clock_t _stime; } _sigchld; /* SIGILL, SIGFPE, SIGSEGV, SIGBUS */ struct { void *_addr; /* faulting insn/memory ref. */ } _sigfault; /* SIGPOLL */ struct { __band_t _band; /* POLL_IN, POLL_OUT, POLL_MSG */ int32_t _fd; } _sigpoll; } _sifields; } siginfo_t; /* * How these fields are to be accessed. */ #define si_pid _sifields._kill._pid #define si_uid _sifields._kill._uid #define si_status _sifields._sigchld._status #define si_utime _sifields._sigchld._utime #define si_stime _sifields._sigchld._stime #define si_value _sifields._rt._sigval #define si_int _sifields._rt._sigval.sival_int #define si_ptr _sifields._rt._sigval.sival_ptr #define si_addr _sifields._sigfault._addr #define si_band _sifields._sigpoll._band #define si_fd _sifields._sigpoll._fd /* Values for `si_code'. Positive values are reserved for kernel-generated signals. */ enum { SI_ASYNCNL = -6, /* Sent by asynch name lookup completion. */ # define SI_ASYNCNL SI_ASYNCNL SI_SIGIO, /* Sent by queued SIGIO. */ # define SI_SIGIO SI_SIGIO SI_ASYNCIO, /* Sent by AIO completion. */ # define SI_ASYNCIO SI_ASYNCIO SI_MESGQ, /* Sent by real time mesq state change. */ # define SI_MESGQ SI_MESGQ SI_TIMER, /* Sent by timer expiration. */ # define SI_TIMER SI_TIMER SI_QUEUE, /* Sent by sigqueue. */ # define SI_QUEUE SI_QUEUE SI_USER, /* Sent by kill, sigsend, raise. */ # define SI_USER SI_USER SI_KERNEL = 0x80 /* Send by kernel. */ #define SI_KERNEL SI_KERNEL }; /* `si_code' values for SIGILL signal. */ enum { ILL_ILLOPC = 1, /* Illegal opcode. */ # define ILL_ILLOPC ILL_ILLOPC ILL_ILLOPN, /* Illegal operand. */ # define ILL_ILLOPN ILL_ILLOPN ILL_ILLADR, /* Illegal addressing mode. */ # define ILL_ILLADR ILL_ILLADR ILL_ILLTRP, /* Illegal trap. */ # define ILL_ILLTRP ILL_ILLTRP ILL_PRVOPC, /* Privileged opcode. */ # define ILL_PRVOPC ILL_PRVOPC ILL_PRVREG, /* Privileged register. */ # define ILL_PRVREG ILL_PRVREG ILL_COPROC, /* Coprocessor error. */ # define ILL_COPROC ILL_COPROC ILL_BADSTK /* Internal stack error. */ # define ILL_BADSTK ILL_BADSTK }; /* `si_code' values for SIGFPE signal. */ enum { FPE_INTDIV = 1, /* Integer divide by zero. */ # define FPE_INTDIV FPE_INTDIV FPE_INTOVF, /* Integer overflow. */ # define FPE_INTOVF FPE_INTOVF FPE_FLTDIV, /* Floating point divide by zero. */ # define FPE_FLTDIV FPE_FLTDIV FPE_FLTOVF, /* Floating point overflow. */ # define FPE_FLTOVF FPE_FLTOVF FPE_FLTUND, /* Floating point underflow. */ # define FPE_FLTUND FPE_FLTUND FPE_FLTRES, /* Floating point inexact result. */ # define FPE_FLTRES FPE_FLTRES FPE_FLTINV, /* Floating point invalid operation. */ # define FPE_FLTINV FPE_FLTINV FPE_FLTSUB /* Subscript out of range. */ # define FPE_FLTSUB FPE_FLTSUB }; /* `si_code' values for SIGSEGV signal. */ enum { SEGV_MAPERR = 1, /* Address not mapped to object. */ # define SEGV_MAPERR SEGV_MAPERR SEGV_ACCERR /* Invalid permissions for mapped object. */ # define SEGV_ACCERR SEGV_ACCERR }; /* `si_code' values for SIGBUS signal. */ enum { BUS_ADRALN = 1, /* Invalid address alignment. */ # define BUS_ADRALN BUS_ADRALN BUS_ADRERR, /* Non-existant physical address. */ # define BUS_ADRERR BUS_ADRERR BUS_OBJERR /* Object specific hardware error. */ # define BUS_OBJERR BUS_OBJERR }; /* `si_code' values for SIGTRAP signal. */ enum { TRAP_BRKPT = 1, /* Process breakpoint. */ # define TRAP_BRKPT TRAP_BRKPT TRAP_TRACE /* Process trace trap. */ # define TRAP_TRACE TRAP_TRACE }; /* `si_code' values for SIGCHLD signal. */ enum { CLD_EXITED = 1, /* Child has exited. */ # define CLD_EXITED CLD_EXITED CLD_KILLED, /* Child was killed. */ # define CLD_KILLED CLD_KILLED CLD_DUMPED, /* Child terminated abnormally. */ # define CLD_DUMPED CLD_DUMPED CLD_TRAPPED, /* Traced child has trapped. */ # define CLD_TRAPPED CLD_TRAPPED CLD_STOPPED, /* Child has stopped. */ # define CLD_STOPPED CLD_STOPPED CLD_CONTINUED /* Stopped child has continued. */ # define CLD_CONTINUED CLD_CONTINUED }; /* `si_code' values for SIGPOLL signal. */ enum { POLL_IN = 1, /* Data input available. */ # define POLL_IN POLL_IN POLL_OUT, /* Output buffers available. */ # define POLL_OUT POLL_OUT POLL_MSG, /* Input message available. */ # define POLL_MSG POLL_MSG POLL_ERR, /* I/O error. */ # define POLL_ERR POLL_ERR POLL_PRI, /* High priority input available. */ # define POLL_PRI POLL_PRI POLL_HUP /* Device disconnected. */ # define POLL_HUP POLL_HUP }; #define _NSIG_WORDS ((_NSIG/sizeof(long))>>3) typedef struct { unsigned long sig[_NSIG_WORDS]; } sigset_t; struct sigaction { #if defined(__alpha__) || defined(__ia64__) || defined(__hppa__) union { sighandler_t _sa_handler; void (*_sa_sigaction)(int, siginfo_t*, void*); } _u; unsigned long sa_flags; sigset_t sa_mask; #elif defined(__mips__) unsigned long sa_flags; union { sighandler_t _sa_handler; void (*_sa_sigaction)(int, siginfo_t*, void*); } _u; sigset_t sa_mask; void (*sa_restorer)(void); int32_t sa_resv[1]; #else /* arm, i386, ppc, s390, sparc, saprc64, x86_64 */ union { sighandler_t _sa_handler; void (*_sa_sigaction)(int, siginfo_t*, void*); } _u; unsigned long sa_flags; void (*sa_restorer)(void); sigset_t sa_mask; #endif }; #define sa_handler _u._sa_handler #define sa_sigaction _u._sa_sigaction #define SIGEV_SIGNAL 0 /* notify via signal */ #define SIGEV_NONE 1 /* other notification: meaningless */ #define SIGEV_THREAD 2 /* deliver via thread creation */ #define SIGEV_THREAD_ID 4 /* deliver to thread */ #define SIGEV_MAX_SIZE 64 #ifndef SIGEV_PAD_SIZE #define SIGEV_PAD_SIZE ((SIGEV_MAX_SIZE/sizeof(int32_t)) - 3) #endif typedef struct sigevent { sigval_t sigev_value; int32_t sigev_signo; int32_t sigev_notify; union { int32_t _pad[SIGEV_PAD_SIZE]; int32_t _tid; struct { void(*_function)(sigval_t); void*_attribute; /* really pthread_attr_t */ } _sigev_thread; } _sigev_un; } sigevent_t; #define sigev_notify_function _sigev_un._sigev_thread._function #define sigev_notify_attributes _sigev_un._sigev_thread._attribute #define sigev_notify_thread_id _sigev_un._tid typedef struct sigaltstack { #if defined(__mips__) void *ss_sp; size_t ss_size; int32_t ss_flags; #else void *ss_sp; int32_t ss_flags; size_t ss_size; #endif } stack_t; int sigaltstack(const struct sigaltstack *newstack, struct sigaltstack *oldstack) __THROW; int sigemptyset(sigset_t *set) __THROW; int sigfillset(sigset_t *set) __THROW; int sigaddset(sigset_t *set, int signum) __THROW; int sigdelset(sigset_t *set, int signum) __THROW; int sigismember(const sigset_t *set, int signo) __THROW; int sigsuspend(const sigset_t *mask) __THROW; int sigpending(sigset_t *set) __THROW; int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) __THROW; #ifdef _GNU_SOURCE int sigisemptyset(const sigset_t *set) __THROW __pure; int sigorset(sigset_t *set, const sigset_t *left, const sigset_t *right) __THROW; int sigandset(sigset_t *set, const sigset_t *left, const sigset_t *right) __THROW; #endif sighandler_t signal(int signum, sighandler_t action); int raise (int sig) __THROW; int kill(pid_t pid, int sig) __THROW; int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) __THROW; #include int sigtimedwait(const sigset_t *mask, siginfo_t *info, const struct timespec *ts) __THROW; int sigqueueinfo(pid_t pid, int sig, siginfo_t *info) __THROW; int siginterrupt(int sig, int flag) __THROW; int killpg(pid_t pgrp, int sig) __THROW; /* 0 is OK ! kernel puts in MAX_THREAD_TIMEOUT :) */ #define sigwaitinfo(m, i) sigtimedwait((m),(i),0) int sigwait(const sigset_t* set,int* sig) __THROW; extern const char *const* sys_siglist; #include __END_DECLS #endif dietlibc-0.33~cvs20120325/include/stdarg-cruft.h010064400000000000000000000231041173363226500161070ustar00#include #if defined(__sparc__) || defined(__alpha__) || defined(__mips__) enum { __no_type_class = -1, __void_type_class, __integer_type_class, __char_type_class, __enumeral_type_class, __boolean_type_class, __pointer_type_class, __reference_type_class, __offset_type_class, __real_type_class, __complex_type_class, __function_type_class, __method_type_class, __record_type_class, __union_type_class, __array_type_class, __string_type_class, __set_type_class, __file_type_class, __lang_type_class }; #endif #if defined(__sparc__) typedef char* va_list; #define va_end(ap) ap=0 #define va_start(AP, LASTARG) \ (__builtin_next_arg (LASTARG), AP = (char *) __builtin_saveregs ()) #define __va_rounded_size(TYPE) \ (((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) /* We don't declare the union member `d' to have type TYPE because that would lose in C++ if TYPE has a constructor. */ /* We cast to void * and then to TYPE * because this avoids a warning about increasing the alignment requirement. The casts to char * avoid warnings about invalid pointer arithmetic. */ #define va_arg(pvar,TYPE) \ __extension__ \ (*({((__builtin_classify_type (*(TYPE*) 0) >= __record_type_class \ || (__builtin_classify_type (*(TYPE*) 0) == __real_type_class \ && sizeof (TYPE) == 16)) \ ? ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE *), \ *(TYPE **) (void *) ((char *)(pvar) - __va_rounded_size (TYPE *))) \ : __va_rounded_size (TYPE) == 8 \ ? ({ union {char __d[sizeof (TYPE)]; int __i[2];} __u; \ __u.__i[0] = ((int *) (void *) (pvar))[0]; \ __u.__i[1] = ((int *) (void *) (pvar))[1]; \ (pvar) = (char *)(pvar) + 8; \ (TYPE *) (void *) __u.__d; }) \ : ((pvar) = (char *)(pvar) + __va_rounded_size (TYPE), \ ((TYPE *) (void *) ((char *)(pvar) - __va_rounded_size (TYPE)))));})) #elif defined(__mips__) typedef char * va_list; #ifdef __mips64__ #define __va_rounded_size(__TYPE) \ (((sizeof (__TYPE) + 8 - 1) / 8) * 8) #else #define __va_rounded_size(__TYPE) \ (((sizeof (__TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int)) #endif #ifdef __mips64__ #define __va_reg_size 8 #else #define __va_reg_size 4 #endif #define va_start(__AP, __LASTARG) \ (__AP = (va_list) __builtin_next_arg (__LASTARG)) #ifdef __mips64__ #ifdef __MIPSEB__ #define va_arg(__AP, __type) \ ((__type *) (void *) (__AP = (char *) \ ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \ + __va_rounded_size (__type))))[-1] #else #define va_arg(__AP, __type) \ ((__AP = (char *) ((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) \ + __va_rounded_size (__type))), \ *(__type *) (void *) (__AP - __va_rounded_size (__type))) #endif #else /* not __mips64 */ #ifdef __MIPSEB__ /* For big-endian machines. */ #define va_arg(__AP, __type) \ ((__AP = (char *) ((__alignof__ (__type) > 4 \ ? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \ : ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \ + __va_rounded_size (__type))), \ *(__type *) (void *) (__AP - __va_rounded_size (__type))) #else /* For little-endian machines. */ #define va_arg(__AP, __type) \ ((__type *) (void *) (__AP = (char *) ((__alignof__(__type) > 4 \ ? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \ : ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) \ + __va_rounded_size(__type))))[-1] #endif #endif #elif defined(__powerpc__) typedef struct __va_list_tag { unsigned char gpr; /* index into the array of 8 GPRs stored in the register save area gpr=0 corresponds to r3, gpr=1 to r4, etc. */ unsigned char fpr; /* index into the array of 8 FPRs stored in the register save area fpr=0 corresponds to f1, fpr=1 to f2, etc. */ char *overflow_arg_area; /* location on stack that holds the next overflow argument */ char *reg_save_area; /* where r3:r10 and f1:f8, if saved are stored */ } va_list[1]; #define __va_overflow(AP) (AP)->overflow_arg_area #ifdef __OPTIMIZE__ extern void __va_arg_type_violation(void) __attribute__((__noreturn__)); #else #define __va_arg_type_violation() #endif typedef struct { long __gp_save[8]; /* save area for GP registers */ double __fp_save[8]; /* save area for FP registers */ } __va_regsave_t; /* Macros to access the register save area */ /* We cast to void * and then to TYPE * because this avoids a warning about increasing the alignment requirement. */ #define __VA_FP_REGSAVE(AP,OFS,TYPE) \ ((TYPE *) (void *) (&(((__va_regsave_t *) \ (AP)->reg_save_area)->__fp_save[OFS]))) #define __VA_GP_REGSAVE(AP,OFS,TYPE) \ ((TYPE *) (void *) (&(((__va_regsave_t *) \ (AP)->reg_save_area)->__gp_save[OFS]))) #define __va_start_common(AP, FAKE) \ __builtin_memcpy ((AP), __builtin_saveregs (), sizeof(va_list)) #define va_start(AP,LASTARG) \ (__builtin_next_arg (LASTARG), __va_start_common (AP, 0)) #ifdef _SOFT_FLOAT #define __va_float_p(TYPE) 0 #else #define __va_float_p(TYPE) (__builtin_classify_type(*(TYPE *)0) == 8) #endif #define __va_aggregate_p(TYPE) (__builtin_classify_type(*(TYPE *)0) >= 12) #define __va_size(TYPE) ((sizeof(TYPE) + sizeof (long) - 1) / sizeof (long)) #define va_arg(AP,TYPE) \ __extension__ (*({ \ register TYPE *__ptr; \ \ if (__va_float_p (TYPE) && sizeof (TYPE) < 16) \ { \ unsigned char __fpr = (AP)->fpr; \ if (__fpr < 8) \ { \ __ptr = __VA_FP_REGSAVE (AP, __fpr, TYPE); \ (AP)->fpr = __fpr + 1; \ } \ else if (sizeof (TYPE) == 8) \ { \ unsigned long __addr = (unsigned long) (__va_overflow (AP)); \ __ptr = (TYPE *)((__addr + 7) & -8); \ __va_overflow (AP) = (char *)(__ptr + 1); \ } \ else \ { \ /* float is promoted to double. */ \ __va_arg_type_violation (); \ } \ } \ \ /* Aggregates and long doubles are passed by reference. */ \ else if (__va_aggregate_p (TYPE) || __va_float_p (TYPE)) \ { \ unsigned char __gpr = (AP)->gpr; \ if (__gpr < 8) \ { \ __ptr = * __VA_GP_REGSAVE (AP, __gpr, TYPE *); \ (AP)->gpr = __gpr + 1; \ } \ else \ { \ TYPE **__pptr = (TYPE **) (__va_overflow (AP)); \ __ptr = * __pptr; \ __va_overflow (AP) = (char *) (__pptr + 1); \ } \ } \ \ /* Only integrals remaining. */ \ else \ { \ /* longlong is aligned. */ \ if (sizeof (TYPE) == 8) \ { \ unsigned char __gpr = (AP)->gpr; \ if (__gpr < 7) \ { \ __gpr += __gpr & 1; \ __ptr = __VA_GP_REGSAVE (AP, __gpr, TYPE); \ (AP)->gpr = __gpr + 2; \ } \ else \ { \ unsigned long __addr = (unsigned long) (__va_overflow (AP)); \ __ptr = (TYPE *)((__addr + 7) & -8); \ (AP)->gpr = 8; \ __va_overflow (AP) = (char *)(__ptr + 1); \ } \ } \ else if (sizeof (TYPE) == 4) \ { \ unsigned char __gpr = (AP)->gpr; \ if (__gpr < 8) \ { \ __ptr = __VA_GP_REGSAVE (AP, __gpr, TYPE); \ (AP)->gpr = __gpr + 1; \ } \ else \ { \ __ptr = (TYPE *) __va_overflow (AP); \ __va_overflow (AP) = (char *)(__ptr + 1); \ } \ } \ else \ { \ /* Everything else was promoted to int. */ \ __va_arg_type_violation (); \ } \ } \ __ptr; \ })) #define va_end(AP) ((void)0) /* Copy va_list into another variable of this type. */ #define __va_copy(dest, src) *(dest) = *(src) #elif defined(__alpha__) typedef struct { char *__base; /* Pointer to first integer register. */ int __offset; /* Byte offset of args so far. */ } va_list; #define va_start(pvar, firstarg) \ (__builtin_next_arg (firstarg), \ (pvar) = *(va_list *) __builtin_saveregs ()) #define va_end(__va) ((void) 0) #define __va_tsize(__type) \ (((sizeof (__type) + __extension__ sizeof (long long) - 1) \ / __extension__ sizeof (long long)) * __extension__ sizeof (long long)) #define va_arg(__va, __type) \ (*(((__va).__offset += __va_tsize (__type)), \ (__type *)(void *)((__va).__base + (__va).__offset \ - (((__builtin_classify_type (* (__type *) 0) \ == __real_type_class) && (__va).__offset <= (6 * 8)) \ ? (6 * 8) + 8 : __va_tsize (__type))))) #else /* !__sparc__ && !__powerpc__ && !__mips__ && !__alpha__*/ typedef char* va_list; /* this only works when everything is passed on the stack (i.e. x86) */ #if __WORDSIZE == 64 #define va_start(ap,argn) ap=((char*)&argn)+8 #else #define va_start(ap,argn) ap=((char*)&argn)+4 #endif #define va_arg(ap,type) (ap+=sizeof(type), *(type*)((void*)ap-sizeof(type))) #endif #ifndef __va_copy #define __va_copy(x,y) x=y #endif #ifndef va_end #define va_end(ap) ((void)0) #endif dietlibc-0.33~cvs20120325/include/stdarg.h010064400000000000000000000010471173363226500147700ustar00#ifndef _STDARG_H #define _STDARG_H #include #include __BEGIN_DECLS #if (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)) typedef __builtin_va_list va_list; #define va_start(v,l) __builtin_va_start((v),(l)) #define va_end __builtin_va_end #define va_arg __builtin_va_arg #define __va_copy(d,s) __builtin_va_copy((d),(s)) #endif #ifndef va_end #include #endif #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L #define va_copy(d,s) __va_copy(d,s) #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/stdbool.h010064400000000000000000000004641173363226500151540ustar00#ifndef _STDBOOL_H #define _STDBOOL_H /* believe it or not but the Single Unix Specification actually * specifies this header, see * http://www.opengroup.org/onlinepubs/007904975/basedefs/stdbool.h.html */ #define bool _Bool #define true 1 #define false 0 #define __bool_true_false_are_defined 1 #endif dietlibc-0.33~cvs20120325/include/stddef.h010064400000000000000000000010501173363226500147470ustar00#ifndef _STDDEF_H #define _STDDEF_H #include __BEGIN_DECLS /* ugh. This is normally provided by gcc. */ #ifdef __GNUC__ typedef __PTRDIFF_TYPE__ ptrdiff_t; typedef __SIZE_TYPE__ size_t; #if !defined(__cplusplus) typedef __WCHAR_TYPE__ wchar_t; #endif #else typedef signed long ptrdiff_t; typedef unsigned long size_t; typedef int wchar_t; #endif #undef NULL #if defined(__cplusplus) #define NULL 0 #else #define NULL (void*)0 #endif #undef offsetof #define offsetof(type,member) ((size_t) &((type*)0)->member) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/stdint.h010064400000000000000000000070661173363226500150200ustar00#ifndef _STDINT_H #define _STDINT_H #include #include __BEGIN_DECLS typedef int8_t int_least8_t; typedef int16_t int_least16_t; typedef int32_t int_least32_t; typedef int64_t int_least64_t; typedef uint8_t uint_least8_t; typedef uint16_t uint_least16_t; typedef uint32_t uint_least32_t; typedef uint64_t uint_least64_t; typedef signed char int_fast8_t; typedef signed long int int_fast16_t; typedef signed long int int_fast32_t; typedef int64_t int_fast64_t; typedef unsigned char uint_fast8_t; typedef unsigned long int uint_fast16_t; typedef unsigned long int uint_fast32_t; typedef uint64_t uint_fast64_t; /* The ISO C99 standard specifies that in C++ implementations these should only be defined if explicitly requested. */ #if !defined __cplusplus || defined __STDC_LIMIT_MACROS #define INT8_MAX (127) #define INT16_MAX (32767) #define INT32_MAX (2147483647) #define INT64_MAX (9223372036854775807ll) #define INT8_MIN (-1 - INT8_MAX) #define INT16_MIN (-1 - INT16_MAX) #define INT32_MIN (-1 - INT32_MAX) #define INT64_MIN (-1 - INT64_MAX) #define INT_LEAST8_MAX INT8_MAX #define INT_LEAST8_MIN INT8_MIN #define INT_LEAST16_MAX INT16_MAX #define INT_LEAST16_MIN INT16_MIN #define INT_LEAST32_MAX INT32_MAX #define INT_LEAST32_MIN INT32_MIN #define INT_LEAST64_MAX INT64_MAX #define INT_LEAST64_MIN INT64_MIN #define UINT8_MAX 0xff #define UINT16_MAX 0xffff #define UINT32_MAX 0xfffffffful #define UINT64_MAX 0xffffffffffffffffull #define UINT_LEAST8_MAX UINT8_MAX #define UINT_LEAST16_MAX UINT16_MAX #define UINT_LEAST32_MAX UINT32_MAX #define UINT_LEAST64_MAX UINT64_MAX #if __WORDSIZE == 64 #define INTPTR_MIN INT64_MIN #define INTPTR_MAX INT64_MAX #define UINTPTR_MAX UINT64_MAX #else #define INTPTR_MIN INT32_MIN #define INTPTR_MAX INT32_MAX #define UINTPTR_MAX UINT32_MAX #endif #define SIZE_MAX UINTPTR_MAX #define PTRDIFF_MIN INTPTR_MIN #define PTRDIFF_MAX INTPTR_MAX #define INTMAX_MIN INT64_MIN #define INTMAX_MAX INT64_MAX #define UINTMAX_MAX UINT64_MAX #define INT_FAST8_MIN INT8_MIN #define INT_FAST8_MAX INT8_MAX #define INT_FAST64_MIN INT64_MIN #define INT_FAST64_MAX INT64_MAX #define UINT_FAST8_MAX UINT8_MAX #define UINT_FAST64_MAX UINT64_MAX #define INT_FAST16_MIN INTPTR_MIN #define INT_FAST16_MAX INTPTR_MAX #define UINT_FAST16_MAX UINTPTR_MAX #define INT_FAST32_MIN INTPTR_MIN #define INT_FAST32_MAX INTPTR_MAX #define UINT_FAST32_MAX UINTPTR_MAX #define SIG_ATOMIC_MAX ((int)(~0u << sizeof(int)*8-1)) #define SIG_ATOMIC_MIN ((int)((~0u << sizeof(int)*8-1)-1)) #ifndef WCHAR_MIN #define WCHAR_MIN ((int)(~0u << sizeof(int)*8-1)) #define WCHAR_MAX ((int)((~0u << sizeof(int)*8-1)-1)) #endif #define WINT_MIN 0 #define WINT_MAX (~(wint_t)0) #endif /* C++ && limit macros */ /* The ISO C99 standard specifies that in C++ implementations these should only be defined if explicitly requested. */ #if !defined __cplusplus || defined __STDC_CONSTANT_MACROS /* Signed. */ # define INT8_C(c) c # define INT16_C(c) c # define INT32_C(c) c # if __WORDSIZE == 64 # define INT64_C(c) c ## L # else # define INT64_C(c) c ## LL # endif /* Unsigned. */ # define UINT8_C(c) c # define UINT16_C(c) c # define UINT32_C(c) c ## U # if __WORDSIZE == 64 # define UINT64_C(c) c ## UL # else # define UINT64_C(c) c ## ULL # endif /* Maximal type. */ # if __WORDSIZE == 64 # define INTMAX_C(c) c ## L # define UINTMAX_C(c) c ## UL # else # define INTMAX_C(c) c ## LL # define UINTMAX_C(c) c ## ULL # endif #endif /* C++ && constant macros */ #if defined(__WINT_TYPE__) typedef __WINT_TYPE__ wint_t; #else typedef unsigned int wint_t; #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/stdio.h010064400000000000000000000162071173363226500146320ustar00#ifndef _STDIO_H #define _STDIO_H #include #include #include #include __BEGIN_DECLS struct __stdio_file; typedef struct __stdio_file FILE; extern FILE *stdin, *stdout, *stderr; FILE *fopen (const char *path, const char *mode) __THROW; FILE *fdopen (int fildes, const char *mode) __THROW; FILE *freopen (const char *path, const char *mode, FILE *stream) __THROW; int printf(const char *format, ...) __THROW __attribute__((__format__(__printf__,1,2))); int fprintf(FILE *stream, const char *format, ...) __THROW __attribute__((__format__(__printf__,2,3))); int sprintf(char *str, const char *format, ...) __THROW __attribute__((__format__(__printf__,2,3))); int snprintf(char *str, size_t size, const char *format, ...) __THROW __attribute__((__format__(__printf__,3,4))); int asprintf(char **ptr, const char* format, ...) __THROW __attribute_malloc__ __attribute__((__format__(__printf__,2,3))); int scanf(const char *format, ...) __THROW __attribute__((__format__(__scanf__,1,2))); int fscanf(FILE *stream, const char *format, ...) __THROW __attribute__((__format__(__scanf__,2,3))); int sscanf(const char *str, const char *format, ...) __THROW __attribute__((__format__(__scanf__,2,3))); int vprintf(const char *format, va_list ap) __THROW __attribute__((__format__(__printf__,1,0))); int vfprintf(FILE *stream, const char *format, va_list ap) __THROW __attribute__((__format__(__printf__,2,0))); int vsprintf(char *str, const char *format, va_list ap) __THROW __attribute__((__format__(__printf__,2,0))); int vsnprintf(char *str, size_t size, const char *format, va_list ap) __THROW __attribute__((__format__(__printf__,3,0))); int fdprintf(int fd, const char *format, ...) __THROW __attribute__((__format__(__printf__,2,3))); int vfdprintf(int fd, const char *format, va_list ap) __THROW __attribute__((__format__(__printf__,2,0))); int vscanf(const char *format, va_list ap) __THROW __attribute__((__format__(__scanf__,1,0))); int vsscanf(const char *str, const char *format, va_list ap) __THROW __attribute__((__format__(__scanf__,2,0))); int vfscanf(FILE *stream, const char *format, va_list ap) __THROW __attribute__((__format__(__scanf__,2,0))); int fgetc(FILE *stream) __THROW; int fgetc_unlocked(FILE *stream) __THROW; char *fgets(char *s, int size, FILE *stream) __THROW; char *fgets_unlocked(char *s, int size, FILE *stream) __THROW; char *gets(char *s) __THROW; int ungetc(int c, FILE *stream) __THROW; int ungetc_unlocked(int c, FILE *stream) __THROW; int fputc(int c, FILE *stream) __THROW; int fputc_unlocked(int c, FILE *stream) __THROW; int fputs(const char *s, FILE *stream) __THROW; int fputs_unlocked(const char *s, FILE *stream) __THROW; int getc(FILE *stream) __THROW; int getchar(void) __THROW; int putchar(int c) __THROW; int putchar_unlocked(int c) __THROW; #if !defined(__cplusplus) #define putc(c,stream) fputc(c,stream) #define putchar(c) fputc(c,stdout) #define putc_unlocked(c,stream) fputc_unlocked(c,stream) #define putchar_unlocked(c) fputc_unlocked(c,stdout) #else inline int putc(int c, FILE *stream) __THROW { return fputc(c,stream); } inline int putc_unlocked(int c, FILE *stream) __THROW { return fputc_unlocked(c,stream); } #endif #if !defined(__cplusplus) #define getc(stream) fgetc(stream) #define getchar() fgetc(stdin) #define getc_unlocked(stream) fgetc_unlocked(stream) #define getchar_unlocked() fgetc_unlocked(stdin) #else inline int getc_unlocked(FILE *stream) __THROW { return fgetc_unlocked(stream); } inline int getchar_unlocked(void) __THROW { return fgetc_unlocked(stdin); } #endif int puts(const char *s) __THROW; int fseek(FILE *stream, long offset, int whence) __THROW; int fseek_unlocked(FILE *stream, long offset, int whence) __THROW; long ftell(FILE *stream) __THROW; long ftell_unlocked(FILE *stream) __THROW; int fseeko(FILE *stream, off_t offset, int whence) __THROW; int fseeko_unlocked(FILE *stream, off_t offset, int whence) __THROW; off_t ftello(FILE *stream) __THROW; off_t ftello_unlocked(FILE *stream) __THROW; #if __WORDSIZE == 32 int fseeko64(FILE *stream, loff_t offset, int whence) __THROW; int fseeko64_unlocked(FILE *stream, loff_t offset, int whence) __THROW; loff_t ftello64(FILE *stream) __THROW; loff_t ftello64_unlocked(FILE *stream) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define off_t loff_t #define fseeko(foo,bar,baz) fseeko64(foo,bar,baz) #define ftello(foo) ftello64(foo) #endif #endif void rewind(FILE *stream) __THROW; int fgetpos(FILE *stream, fpos_t *pos) __THROW; int fsetpos(FILE *stream, fpos_t *pos) __THROW; size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) __THROW; size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream) __THROW; size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) __THROW; size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream) __THROW; int fflush(FILE *stream) __THROW; int fflush_unlocked(FILE *stream) __THROW; int fclose(FILE *stream) __THROW; int fclose_unlocked(FILE *stream) __THROW; int feof(FILE *stream) __THROW; int feof_unlocked(FILE *stream) __THROW; int ferror(FILE *stream) __THROW; int ferror_unlocked(FILE *stream) __THROW; int fileno(FILE *stream) __THROW; int fileno_unlocked(FILE *stream) __THROW; void clearerr(FILE *stream) __THROW; void clearerr_unlocked(FILE *stream) __THROW; int remove(const char *pathname) __THROW; int rename(const char *oldpath, const char *newpath) __THROW; void perror(const char *s) __THROW; #define EOF (-1) #define BUFSIZ 1024 #define _IONBF 0 #define _IOLBF 1 #define _IOFBF 2 int setvbuf(FILE *stream, char *buf, int mode , size_t size) __THROW; int setvbuf_unlocked(FILE *stream, char *buf, int mode , size_t size) __THROW; #if !defined(__cplusplus) #define setbuf(stream,buf) setvbuf(stream,buf,buf?_IOFBF:_IONBF,BUFSIZ) #define setbuffer(stream,buf,size) setvbuf(stream,buf,buf?_IOFBF:_IONBF,size) #define setlinebuf(stream) setvbuf(stream,0,_IOLBF,BUFSIZ) #else inline int setbuf(FILE *stream, char *buf) __THROW { return setvbuf(stream,buf,buf?_IOFBF:_IONBF,BUFSIZ); } inline int setbuffer(FILE *stream, char *buf, size_t size) __THROW { return setvbuf(stream,buf,buf?_IOFBF:_IONBF,size); } inline int setlinebuf(FILE *stream) __THROW { return setvbuf(stream,0,_IOLBF,BUFSIZ); } #endif FILE *popen(const char *command, const char *type) __THROW; int pclose(FILE *stream) __THROW; #ifndef SEEK_SET #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 #endif #define L_tmpnam 128 #define P_tmpdir "/tmp" char* tmpnam(char *s) __THROW; /* DO NOT USE!!! Use mkstemp instead! */ char* tempnam(char* dir,char* _template); /* dito */ FILE* tmpfile(void) __THROW; FILE* tmpfile_unlocked(void) __THROW; #define FILENAME_MAX 4095 #define FOPEN_MAX 16 #define TMP_MAX 10000 /* this is so bad, we moved it to -lcompat */ #define L_ctermid 9 char* ctermid(char* s); /* returns "/dev/tty" */ void flockfile(FILE* f) __THROW; void funlockfile(FILE* f) __THROW; int ftrylockfile (FILE *__stream) __THROW; #ifdef _GNU_SOURCE int vasprintf(char **strp, const char *fmt, va_list ap); ssize_t getline(char **lineptr, size_t *n, FILE *stream); ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/stdlib.h010064400000000000000000000077061173363226500147750ustar00#ifndef _STDLIB_H #define _STDLIB_H #ifndef __ASSEMBLER__ #include #include #include __BEGIN_DECLS void *calloc(size_t nmemb, size_t size) __THROW __attribute_malloc__; void *malloc(size_t size) __THROW __attribute_malloc__; void free(void *ptr) __THROW; void *realloc(void *ptr, size_t size) __THROW __attribute_malloc__; char *getenv(const char *name) __THROW __pure; int putenv(const char *string) __THROW; int setenv(const char *name, const char *value, int overwrite) __THROW; int unsetenv(const char *name) __THROW; int system (const char * string) __THROW; int atexit(void (*function)(void)) __THROW; float strtof(const char *nptr, char **endptr) __THROW; double strtod(const char *nptr, char **endptr) __THROW; long double strtold(const char *nptr, char **endptr) __THROW; long int strtol(const char *nptr, char **endptr, int base) __THROW; unsigned long int strtoul(const char *nptr, char **endptr, int base) __THROW; extern int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase) __THROW; extern int __dtostr(double d,char *buf,unsigned int maxlen,unsigned int prec,unsigned int prec2,int g) __THROW; #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L __extension__ long long int strtoll(const char *nptr, char **endptr, int base) __THROW; __extension__ unsigned long long int strtoull(const char *nptr, char **endptr, int base) __THROW; __extension__ int __lltostr(char *s, unsigned int size, unsigned long long i, unsigned int base, int UpCase) __THROW; #endif int atoi(const char *nptr) __THROW; long int atol(const char *nptr) __THROW; double atof(const char *nptr) __THROW; __extension__ long long int atoll(const char *nptr); void exit(int status) __THROW __attribute__((__noreturn__)); void abort(void) __THROW; extern int rand(void) __THROW; extern int rand_r(unsigned int *seed) __THROW; extern void srand(unsigned int seed) __THROW; #ifdef _BSD_SOURCE extern int random(void) __THROW __attribute_dontuse__; extern void srandom(unsigned int seed) __THROW __attribute_dontuse__; #endif typedef unsigned short randbuf[3]; double drand48(void) __THROW; long lrand48(void) __THROW; long mrand48(void) __THROW; void srand48(long seed) __THROW; unsigned short *seed48(randbuf buf) __THROW; void lcong48(unsigned short param[7]) __THROW; long jrand48(randbuf buf) __THROW; long nrand48(randbuf buf) __THROW; double erand48(randbuf buf) __THROW; void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); extern char **environ; char *realpath(const char *path, char *resolved_path) __THROW; int mkstemp(char *_template); char* mkdtemp(char *_template); char* mktemp(char *_template); int abs(int i) __THROW __attribute__((__const__)); long int labs(long int i) __THROW __attribute__((__const__)); __extension__ long long int llabs(long long int i) __THROW __attribute__((__const__)); #ifdef _XOPEN_SOURCE int grantpt (int fd) __THROW; int unlockpt (int fd) __THROW; char *ptsname (int fd) __THROW; #endif #endif #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define RAND_MAX 0x7ffffffe #define MB_CUR_MAX 5 /* now these functions are the greatest bullshit I have ever seen. * The ISO people must be out of their minds. */ typedef struct { int quot,rem; } div_t; typedef struct { long quot,rem; } ldiv_t; div_t div(int numerator, int denominator); ldiv_t ldiv(long numerator, long denominator); typedef struct { long long quot,rem; } lldiv_t; lldiv_t lldiv(long long numerator, long long denominator); #ifdef _GNU_SOURCE int clearenv(void); #endif int mbtowc(wchar_t *pwc, const char *s, size_t n) __THROW; int wctomb(char *s, wchar_t wc) __THROW; size_t mbstowcs(wchar_t *dest, const char *src, size_t n) __THROW; int mblen(const char* s,size_t n) __THROW __pure; size_t wcstombs(char *dest, const wchar_t *src, size_t n) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/string.h010064400000000000000000000100341173363226500150060ustar00#ifndef _STRING_H #define _STRING_H #include #include __BEGIN_DECLS char *strcpy(char* __restrict__ dest, const char* __restrict__ src) __THROW __nonnull((1,2)); void *memccpy(void* __restrict__ dest, const void* __restrict__ src, int c, size_t n) __THROW __nonnull((1,2)); void *memmove(void* dest, const void *src, size_t n) __THROW __nonnull((1,2)); int memccmp(const void* s1, const void* s2, int c, size_t n) __THROW __pure __nonnull((1,2)); void* memset(void* s, int c, size_t n) __THROW __nonnull((1)); int memcmp(const void* s1, const void* s2, size_t n) __THROW __pure __nonnull((1,2)); void* memcpy(void* __restrict__ dest, const void* __restrict__ src, size_t n) __THROW __nonnull((1,2)); char *strncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n) __THROW __nonnull((1,2)); int strncmp(const char* s1, const char* s2, size_t n) __THROW __pure __nonnull((1,2)); char *strcat(char* __restrict__ dest, const char* __restrict__ src) __THROW __nonnull((1,2)); char *strncat(char* __restrict__ dest, const char* __restrict__ src, size_t n) __THROW __nonnull((1,2)); int strcmp(const char *s1, const char *s2) __THROW __pure __nonnull((1,2)); size_t strlen(const char *s) __THROW __pure __nonnull((1)); #ifdef _GNU_SOURCE size_t strnlen(const char *s,size_t maxlen) __THROW __pure __nonnull((1)); #endif char *strstr(const char *haystack, const char *needle) __THROW __pure __nonnull((1,2)); char *strdup(const char *s) __THROW __attribute_malloc__ __nonnull((1)); char *strchr(const char *s, int c) __THROW __pure __nonnull((1)); char *strrchr(const char *s, int c) __THROW __pure __nonnull((1)); size_t strspn(const char *s, const char *_accept) __THROW __nonnull((1,2)); size_t strcspn(const char *s, const char *reject) __THROW __nonnull((1,2)); char *strpbrk(const char *s, const char *_accept) __THROW __nonnull((1,2)); char *strsep(char ** __restrict__ stringp, const char * __restrict__ delim) __THROW __nonnull((1,2)); void* memchr(const void *s, int c, size_t n) __THROW __pure __nonnull((1)); #ifdef _GNU_SOURCE void* memrchr(const void *s, int c, size_t n) __THROW __pure __nonnull((1)); #endif /* I would like to make this const, but Paul Jarc points out it has to * be char* :-( */ char *strerror(int errnum) __THROW __attribute_const__; /* work around b0rken GNU crapware like tar 1.13.19 */ #define strerror strerror int strerror_r(int errnum,char* buf,size_t n) __THROW __attribute_dontuse__; #ifdef _GNU_SOURCE char *strsignal(int signum) __THROW __attribute_const__; void *memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) __THROW __nonnull((1,3)); void* mempcpy(void* __restrict__ dest,const void* __restrict__ src,size_t n) __THROW __nonnull((1,2)); char *strndup(const char *s,size_t n) __THROW __attribute_malloc__ __nonnull((1)); #define strdupa(s) ({ const char* tmp=s; size_t l=strlen(tmp)+1; char* x=alloca(l); memcpy(x,tmp,l); }) #define strndupa(s,n) ({ const char* tmp=s; const char* y=memchr(tmp,0,(n)); size_t l=y?y-tmp:n; char* x=alloca(l+1); x[l]=0; memcpy(x,tmp,l); }) #endif char *strtok(char * __restrict__ s, const char * __restrict__ delim) __THROW __nonnull((2)); char *strtok_r(char * __restrict__ s, const char * __restrict__ delim, char ** __restrict__ ptrptr) __THROW __nonnull((2,3)); size_t strlcpy(char * __restrict__ dst, const char * __restrict__ src, size_t size) __THROW __nonnull((1,2)); size_t strlcat(char * __restrict__ dst, const char * __restrict__ src, size_t size) __THROW __nonnull((1,2)); int strcoll(const char *s1, const char *s2) __THROW __nonnull((1,2)); size_t strxfrm(char *dest, const char * __restrict__ src, size_t n) __THROW __nonnull((1,2)); #ifdef _BSD_SOURCE #include #endif char *stpcpy(char * __restrict__ dest, const char * __restrict__ src) __THROW __nonnull((1,2)); char* stpncpy(char* __restrict__ dest, const char* __restrict__ src, size_t n) __THROW __nonnull((1,2)); #ifdef _GNU_SOURCE int ffsl(long i) __THROW __attribute_const__; int ffsll(long long i) __THROW __attribute_const__; #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/strings.h010064400000000000000000000015171173363226500151770ustar00#ifndef _STRINGS_H #define _STRINGS_H #include #include __BEGIN_DECLS int strcasecmp(const char *s1, const char *s2) __THROW __pure; int strncasecmp(const char *s1, const char *s2, size_t n) __THROW __pure; int ffs(int i) __THROW __attribute__((__const__)); int bcmp(const void *, const void *, size_t) __THROW __pure __attribute_dontuse__; void bcopy(const void *, void *, size_t) __THROW __attribute_dontuse__; void bzero(void *, size_t) __THROW __attribute_dontuse__; char *index(const char *, int) __THROW __pure __attribute_dontuse__; char *rindex(const char *, int) __THROW __pure __attribute_dontuse__; #define bzero(s,n) memset(s,0,n) #define bcopy(src,dest,n) memmove(dest,src,n) #define bcmp(a,b,n) memcmp(a,b,n) #define index(a,b) strchr(a,b) #define rindex(a,b) strrchr(a,b) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/alpha-ioctl.h010064400000000000000000000130551173363226500165210ustar00#define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 13 #define _IOC_DIRBITS 3 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit. * And this turns out useful to catch old ioctl numbers in header * files for us. */ #define _IOC_NONE 1U #define _IOC_READ 2U #define _IOC_WRITE 4U #define _IOC(dir,type,nr,size) \ ((unsigned int) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT))) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode them.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* ...and for the drivers/sound files... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) #define FIOCLEX _IO('f', 1) #define FIONCLEX _IO('f', 2) #define FIOASYNC _IOW('f', 125, int) #define FIONBIO _IOW('f', 126, int) #define FIONREAD _IOR('f', 127, int) #define TIOCINQ FIONREAD #define FIOQSIZE _IOR('f', 128, loff_t) #define TIOCGETP _IOR('t', 8, struct sgttyb) #define TIOCSETP _IOW('t', 9, struct sgttyb) #define TIOCSETN _IOW('t', 10, struct sgttyb) /* TIOCSETP wo flush */ #define TIOCSETC _IOW('t', 17, struct tchars) #define TIOCGETC _IOR('t', 18, struct tchars) #define TCGETS _IOR('t', 19, struct termios) #define TCSETS _IOW('t', 20, struct termios) #define TCSETSW _IOW('t', 21, struct termios) #define TCSETSF _IOW('t', 22, struct termios) #define TCGETA _IOR('t', 23, struct termio) #define TCSETA _IOW('t', 24, struct termio) #define TCSETAW _IOW('t', 25, struct termio) #define TCSETAF _IOW('t', 28, struct termio) #define TCSBRK _IO('t', 29) #define TCXONC _IO('t', 30) #define TCFLSH _IO('t', 31) #define TIOCSWINSZ _IOW('t', 103, struct winsize) #define TIOCGWINSZ _IOR('t', 104, struct winsize) #define TIOCSTART _IO('t', 110) /* start output, like ^Q */ #define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ #define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ #define TIOCGLTC _IOR('t', 116, struct ltchars) #define TIOCSLTC _IOW('t', 117, struct ltchars) #define TIOCSPGRP _IOW('t', 118, int) #define TIOCGPGRP _IOR('t', 119, int) #define TIOCEXCL 0x540C #define TIOCNXCL 0x540D #define TIOCSCTTY 0x540E #define TIOCSTI 0x5412 #define TIOCMGET 0x5415 #define TIOCMBIS 0x5416 #define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 # define TIOCM_LE 0x001 # define TIOCM_DTR 0x002 # define TIOCM_RTS 0x004 # define TIOCM_ST 0x008 # define TIOCM_SR 0x010 # define TIOCM_CTS 0x020 # define TIOCM_CAR 0x040 # define TIOCM_RNG 0x080 # define TIOCM_DSR 0x100 # define TIOCM_CD TIOCM_CAR # define TIOCM_RI TIOCM_RNG # define TIOCM_OUT1 0x2000 # define TIOCM_OUT2 0x4000 # define TIOCM_LOOP 0x8000 #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 # define TIOCPKT_DATA 0 # define TIOCPKT_FLUSHREAD 1 # define TIOCPKT_FLUSHWRITE 2 # define TIOCPKT_STOP 4 # define TIOCPKT_START 8 # define TIOCPKT_NOSTOP 16 # define TIOCPKT_DOSTOP 32 #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 #define TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5426 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID 0x5429 /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ /* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */ # define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ #define TIOCGHAYESESP 0x545E /* Get Hayes ESP configuration */ #define TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */ /* Socket-level I/O control calls. */ #define FIOGETOWN _IOR('f', 123, int) #define FIOSETOWN _IOW('f', 124, int) #define SIOCATMARK _IOR('s', 7, int) #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) #define SIOCGSTAMP 0x8906 /* Get stamp - linux-specific */ dietlibc-0.33~cvs20120325/include/sys/arm-ioctl.h010064400000000000000000000116111173363226500162070ustar00 /* ioctl command encoding: 32 bits total, command in lower 16 bits, * size of the parameter structure in the lower 14 bits of the * upper 16 bits. * Encoding the size of the parameter structure in the ioctl request * is useful for catching programs compiled with old versions * and to avoid overwriting user space outside the user buffer area. * The highest 2 bits are reserved for indicating the ``access mode''. * NOTE: This limits the max parameter size to 16kB -1 ! */ /* * The following is for compatibility across the various Linux * platforms. The i386 ioctl numbering scheme doesn't really enforce * a type field. De facto, however, the top 8 bits of the lower 16 * bits are indeed used as a type field, so we might just as well make * this explicit here. Please be sure to use the decoding macros * below from now on. */ #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * Direction bits. */ #define _IOC_NONE 0U #define _IOC_WRITE 1U #define _IOC_READ 2U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode ioctl numbers.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* ...and for the drivers/sound files... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) /* 0x54 is just a magic number to make these relatively unique ('T') */ #define TCGETS 0x5401 #define TCSETS 0x5402 #define TCSETSW 0x5403 #define TCSETSF 0x5404 #define TCGETA 0x5405 #define TCSETA 0x5406 #define TCSETAW 0x5407 #define TCSETAF 0x5408 #define TCSBRK 0x5409 #define TCXONC 0x540A #define TCFLSH 0x540B #define TIOCEXCL 0x540C #define TIOCNXCL 0x540D #define TIOCSCTTY 0x540E #define TIOCGPGRP 0x540F #define TIOCSPGRP 0x5410 #define TIOCOUTQ 0x5411 #define TIOCSTI 0x5412 #define TIOCGWINSZ 0x5413 #define TIOCSWINSZ 0x5414 #define TIOCMGET 0x5415 #define TIOCMBIS 0x5416 #define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A #define FIONREAD 0x541B #define TIOCINQ FIONREAD #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 #define FIONBIO 0x5421 #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 #define TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5426 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID 0x5429 /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define FIONCLEX 0x5450 /* these numbers need to be adjusted. */ #define FIOCLEX 0x5451 #define FIOASYNC 0x5452 #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ #define FIOQSIZE 0x545E /* Used for packet mode */ #define TIOCPKT_DATA 0 #define TIOCPKT_FLUSHREAD 1 #define TIOCPKT_FLUSHWRITE 2 #define TIOCPKT_STOP 4 #define TIOCPKT_START 8 #define TIOCPKT_NOSTOP 16 #define TIOCPKT_DOSTOP 32 #define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ /* Socket-level I/O control calls. */ #define FIOSETOWN 0x8901 #define SIOCSPGRP 0x8902 #define FIOGETOWN 0x8903 #define SIOCGPGRP 0x8904 #define SIOCATMARK 0x8905 #define SIOCGSTAMP 0x8906 /* Get stamp */ dietlibc-0.33~cvs20120325/include/sys/atomic.h010064400000000000000000000030471173363226500156000ustar00#ifndef _SYS_ATOMIC_H #define _SYS_ATOMIC_H #include /* this file defines __CAS (compare and swap) and __atomic_add */ #ifdef __arm__ /* The situation with atomic instructions on ARM is horrible. * So much so that the Linux kernel is offering an undocumented * interface for a cmpxchg emulation that works on the current kernel. * You reach it by jumping to the address 0xffff0fc0 */ typedef int (__kernel_cmpxchg_t)(int oldval, int newval, int *ptr); #define __kernel_cmpxchg (*(__kernel_cmpxchg_t *)0xffff0fc0) #define CAS(ptr,oldval,newval) __kernel_cmpxchg(oldval,newval,ptr) #else #if defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) /* recent gcc versions and the intel compiler have built-ins for this */ #define __CAS(ptr,oldval,newval) __sync_val_compare_and_swap(ptr,oldval,newval) #else /* This function does this, atomically: if (*ptr == oldval) { *ptr=newval; return oldval; } else return *ptr; It can be used to implement lock-free data structures or locking primitives. */ size_t __CAS(size_t* ptr,size_t oldval,size_t newval); #if (defined(__sparc__) && !defined(__arch64__)) || defined(__hppa__) #define NO_CAS #endif #endif #endif #if defined(__INTEL_COMPILER) || (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 1)) #define __atomic_add(ptr,val) __sync_fetch_and_add(ptr,val) #else static inline size_t __atomic_add(size_t* ptr,size_t val) { size_t r,o; do { r=__CAS(ptr,(o=*ptr),*ptr+val); } while (r!=o); return r; } #endif #endif dietlibc-0.33~cvs20120325/include/sys/cdefs.h010064400000000000000000000050151173363226500154050ustar00#ifndef _SYS_CDEFS_H #define _SYS_CDEFS_H #ifndef __cplusplus #define __THROW #define __BEGIN_DECLS #define __END_DECLS #else #define __THROW throw () #define __BEGIN_DECLS extern "C" { #define __END_DECLS } #endif #ifndef __GNUC__ #define __attribute__(xyz) #define __extension__ #endif #if (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)) #define __pure __attribute__ ((__pure__)) #else #define __pure #endif #if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95) #define __restrict__ #endif #ifndef __STRICT_ANSI__ #define restrict __restrict__ #if __GNUC__ < 3 #define __builtin_expect(foo,bar) (foo) #define __expect(foo,bar) (foo) #define __malloc__ #else #define __expect(foo,bar) __builtin_expect((long)(foo),bar) #define __attribute_malloc__ __attribute__((__malloc__)) #endif #endif /* idea for these macros taken from Linux kernel */ #define __likely(foo) __expect((foo),1) #define __unlikely(foo) __expect((foo),0) #ifndef __attribute_malloc__ #define __attribute_malloc__ #endif #define __P(x) x #define __ptr_t void* #if defined(__STRICT_ANSI__) && __STDC_VERSION__ + 0 < 199900L #define inline #endif #ifndef __i386__ #define __regparm__(x) #endif #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)) #define __attribute_dontuse__ __attribute__((__deprecated__)) #else #define __attribute_dontuse__ #define __deprecated__ #endif #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) # define __nonnull(params) __attribute__ ((__nonnull__ params)) #else # define __nonnull(params) #endif #if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)) # define __attribute_used __attribute__ ((__used__)) #else # define __attribute_used # define __warn_unused_result__ #endif #if (__GNUC__ >= 4) #define __needsNULL__(x) __sentinel__(x) #else #define __needsNULL__(x) #define __sentinel__ #endif #if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) # define __cold__ # define __hot__ #endif #if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) #define __attribute_alloc__(x) #define __attribute_alloc2__(x,y) #else #define __attribute_alloc__(x) __attribute__((alloc_size(x)) #define __attribute_alloc2__(x,y) __attribute__((alloc_size(x,y)) #endif #if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 5)) #define __attribute_const__ #else #define __attribute_const__ __attribute__((const)) #endif #if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 8)) #define __attribute_formatarg__(x) #else #define __attribute_formatarg__(x) __attribute__((format_arg(x))) #endif #endif dietlibc-0.33~cvs20120325/include/sys/epoll.h010064400000000000000000000031631173363226500154360ustar00#ifndef _SYS_EPOLL_H #define _SYS_EPOLL_H #include #include #include #include __BEGIN_DECLS /* Valid opcodes ( "op" parameter ) to issue to epoll_ctl() */ #define EPOLL_CTL_ADD 1 /* Add a file decriptor to the interface */ #define EPOLL_CTL_DEL 2 /* Remove a file decriptor from the interface */ #define EPOLL_CTL_MOD 3 /* Change file decriptor epoll_event structure */ enum EPOLL_EVENTS { EPOLLIN = 0x001, #define EPOLLIN EPOLLIN EPOLLPRI = 0x002, #define EPOLLPRI EPOLLPRI EPOLLOUT = 0x004, #define EPOLLOUT EPOLLOUT #ifdef _XOPEN_SOURCE EPOLLRDNORM = 0x040, #define EPOLLRDNORM EPOLLRDNORM EPOLLRDBAND = 0x080, #define EPOLLRDBAND EPOLLRDBAND EPOLLWRNORM = 0x100, #define EPOLLWRNORM EPOLLWRNORM EPOLLWRBAND = 0x200, #define EPOLLWRBAND EPOLLWRBAND #endif /* #ifdef __USE_XOPEN */ #ifdef _GNU_SOURCE EPOLLMSG = 0x400, #define EPOLLMSG EPOLLMSG #endif /* #ifdef __USE_GNU */ EPOLLERR = 0x008, #define EPOLLERR EPOLLERR EPOLLHUP = 0x010, #define EPOLLHUP EPOLLHUP EPOLLET = (1<<31) #define EPOLLET EPOLLET }; typedef union epoll_data { void *ptr; int fd; uint32_t u32; uint64_t u64; } epoll_data_t; struct epoll_event { uint32_t events; epoll_data_t data; } #ifdef __x86_64__ __attribute__((__packed__)) #endif ; int epoll_create(int size) __THROW; int epoll_ctl(int epfd, int op, int fd, struct epoll_event* event) __THROW; int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout) __THROW; int epoll_pwait(int epfd, struct epoll_event *events, int maxevents, int timeout, const sigset_t* sigmask) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/file.h010064400000000000000000000003531173363226500152400ustar00#ifndef _SYS_FILE_H #define _SYS_FILE_H #include #include __BEGIN_DECLS extern int fcntl(int fd, int cmd, ...) __THROW; extern int flock(int fd, int operation) __THROW; __END_DECLS #endif /* _SYS_FILE_H */ dietlibc-0.33~cvs20120325/include/sys/fsuid.h010064400000000000000000000003651173363226500154360ustar00#ifndef __FSUID_H #define __FSUID_H 1 #include __BEGIN_DECLS /* Linux only: */ int setfsuid(uid_t uid); int setfsgid(gid_t gid); int setfsuid32(uid32_t fsuid) __THROW; int setfsgid32(gid32_t fsgid) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/futex.h010064400000000000000000000004101173363226500154460ustar00#ifndef _SYS_FUTEX_H #define _SYS_FUTEX_H #include enum { FUTEX_WAIT=0, FUTEX_WAKE=1, FUTEX_FD=2, FUTEX_REQUEUE=3, FUTEX_CMP_REQUEUE=4, }; long futex(int* uaddr,int op,int val,const struct timespec* timeout,int* uaddr2,int val3); #endif dietlibc-0.33~cvs20120325/include/sys/gmon.h010064400000000000000000000040011173363226500152530ustar00#ifndef __DLC_GMON_H_ #define __DLC_GMON_H_ #include __BEGIN_DECLS # define HISTCOUNTER unsigned short # define HISTFRACTION 2 # define HASHFRACTION 2 # define ARCDENSITY 2 # define MINARCS 50 # define MAXARCS (( 1 << (8 * sizeof(HISTCOUNTER))) - 2) # define ROUNDDOWN(x,y) (((x)/(y))*y) # define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*y) # define PROF_SECTION __attribute__ ((section (".profile"))) struct tostruct { unsigned long selfpc; signed long count; unsigned short link; unsigned short pad; }; struct rawarc { unsigned long raw_frompc; unsigned long raw_selfpc; signed long raw_count; }; struct monparam { unsigned short *kcount; unsigned long kcountsize; struct rawarc *arcs; unsigned long arcnum; unsigned long lowpc; unsigned long highpc; unsigned long textsize; }; struct gmonparam { long state; unsigned short *kcount; unsigned long kcountsize; unsigned short *froms; unsigned long fromsize; struct tostruct *tos; unsigned long tossize; long tolimit; unsigned long lowpc; unsigned long highpc; unsigned long textsize; unsigned long hashfraction; unsigned long log_hashfraction; }; struct gmon_hdr { char cookie[4]; long version; char spare[12]; }; struct gmon_hist_hdr { long low_pc; long high_pc; long hist_size; long prof_rate; char dimen[15]; char dimen_abbrev; }; struct gmon_cg_arc_record { long from_pc; long self_pc; long count; }; struct __bb { long zero_word; char *filename; long *counts; long ncounts; struct __bb *next; unsigned long *addresses; }; typedef enum { GMON_TAG_TIME_HIST, GMON_TAG_CG_ARC, GMON_TAG_BB_COUNT } GMON_Record_Tag; enum { GMON_PROF_ON, GMON_PROF_BUSY, GMON_PROF_ERROR, GMON_PROF_OFF }; enum { GPROF_STATE, GPROF_COUNT, GPROF_FROMS, GPROF_TOS, GPROF_GMONPARAM }; extern struct gmonparam gmparam; extern struct __bb * __bb_head; extern void __monstartup(unsigned long, unsigned long); extern void monstartup(unsigned long, unsigned long); extern void _mcleanup(void); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/gmon_out.h010064400000000000000000000000261173363226500161450ustar00#include dietlibc-0.33~cvs20120325/include/sys/hppa-ioctl.h010064400000000000000000000107651173363226500163710ustar00#ifndef __ARCH_PARISC_IOCTLS_H__ #define __ARCH_PARISC_IOCTLS_H__ #ifndef _ASM_PARISC_IOCTL_H #define _ASM_PARISC_IOCTL_H #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * Direction bits. */ #define _IOC_NONE 0U #define _IOC_WRITE 2U #define _IOC_READ 1U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode ioctl numbers.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* ...and for the drivers/sound files... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) #endif /* _ASM_PARISC_IOCTL_H */ /* 0x54 is just a magic number to make these relatively unique ('T') */ #define TCGETS _IOR('T', 16, struct termios) /* TCGETATTR */ #define TCSETS _IOW('T', 17, struct termios) /* TCSETATTR */ #define TCSETSW _IOW('T', 18, struct termios) /* TCSETATTRD */ #define TCSETSF _IOW('T', 19, struct termios) /* TCSETATTRF */ #define TCGETA _IOR('T', 1, struct termio) #define TCSETA _IOW('T', 2, struct termio) #define TCSETAW _IOW('T', 3, struct termio) #define TCSETAF _IOW('T', 4, struct termio) #define TCSBRK _IO('T', 5) #define TCXONC _IO('T', 6) #define TCFLSH _IO('T', 7) #define TIOCEXCL 0x540C #define TIOCNXCL 0x540D #define TIOCSCTTY 0x540E #define TIOCGPGRP _IOR('T', 30, int) #define TIOCSPGRP _IOW('T', 29, int) #define TIOCOUTQ 0x5411 #define TIOCSTI 0x5412 #define TIOCGWINSZ 0x5413 #define TIOCSWINSZ 0x5414 #define TIOCMGET 0x5415 #define TIOCMBIS 0x5416 #define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A #define FIONREAD 0x541B #define TIOCINQ FIONREAD #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 #define FIONBIO 0x5421 #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 #define TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5426 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID _IOR('T', 20, int) /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define FIONCLEX 0x5450 /* these numbers need to be adjusted. */ #define FIOCLEX 0x5451 #define FIOASYNC 0x5452 #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ #define TIOCGHAYESESP 0x545E /* Get Hayes ESP configuration */ #define TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */ #define FIOQSIZE 0x5460 /* Get exact space used by quota */ /* Used for packet mode */ #define TIOCPKT_DATA 0 #define TIOCPKT_FLUSHREAD 1 #define TIOCPKT_FLUSHWRITE 2 #define TIOCPKT_STOP 4 #define TIOCPKT_START 8 #define TIOCPKT_NOSTOP 16 #define TIOCPKT_DOSTOP 32 #define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ #endif /* _ASM_PARISC_IOCTLS_H */ dietlibc-0.33~cvs20120325/include/sys/i386-ioctl.h010064400000000000000000000110561173363226500161240ustar00 /* * The following is for compatibility across the various Linux * platforms. The i386 ioctl numbering scheme doesn't really enforce * a type field. De facto, however, the top 8 bits of the lower 16 * bits are indeed used as a type field, so we might just as well make * this explicit here. Please be sure to use the decoding macros * below from now on. */ #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * Direction bits. */ #define _IOC_NONE 0U #define _IOC_WRITE 1U #define _IOC_READ 2U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode ioctl numbers.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* ...and for the drivers/sound files... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) /* 0x54 is just a magic number to make these relatively unique ('T') */ #define TCGETS 0x5401 #define TCSETS 0x5402 #define TCSETSW 0x5403 #define TCSETSF 0x5404 #define TCGETA 0x5405 #define TCSETA 0x5406 #define TCSETAW 0x5407 #define TCSETAF 0x5408 #define TCSBRK 0x5409 #define TCXONC 0x540A #define TCFLSH 0x540B #define TIOCEXCL 0x540C #define TIOCNXCL 0x540D #define TIOCSCTTY 0x540E #define TIOCGPGRP 0x540F #define TIOCSPGRP 0x5410 #define TIOCOUTQ 0x5411 #define TIOCSTI 0x5412 #define TIOCGWINSZ 0x5413 #define TIOCSWINSZ 0x5414 #define TIOCMGET 0x5415 #define TIOCMBIS 0x5416 #define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A #define FIONREAD 0x541B #define TIOCINQ FIONREAD #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 #define FIONBIO 0x5421 #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 #define TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5426 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID 0x5429 /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define FIONCLEX 0x5450 /* these numbers need to be adjusted. */ #define FIOCLEX 0x5451 #define FIOASYNC 0x5452 #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ #define TIOCGHAYESESP 0x545E /* Get Hayes ESP configuration */ #define TIOCSHAYESESP 0x545F /* Set Hayes ESP configuration */ #define FIOQSIZE 0x5460 /* Used for packet mode */ #define TIOCPKT_DATA 0 #define TIOCPKT_FLUSHREAD 1 #define TIOCPKT_FLUSHWRITE 2 #define TIOCPKT_STOP 4 #define TIOCPKT_START 8 #define TIOCPKT_NOSTOP 16 #define TIOCPKT_DOSTOP 32 #define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ /* Socket-level I/O control calls. */ #define FIOSETOWN 0x8901 #define SIOCSPGRP 0x8902 #define FIOGETOWN 0x8903 #define SIOCGPGRP 0x8904 #define SIOCATMARK 0x8905 #define SIOCGSTAMP 0x8906 /* Get stamp */ dietlibc-0.33~cvs20120325/include/sys/inotify.h010064400000000000000000000046751173363226500160150ustar00#ifndef _SYS_INOTIFY_H #define _SYS_INOTIFY_H #include #include struct inotify_event { int32_t wd; /* watch descriptor */ uint32_t mask, /* watch mask */ cookie, /* cookie to synchronize two events */ len; /* length (including nulls) of name */ char name[0]; /* stub for possible name */ }; /* the following are legal, implemented events that user-space can watch for */ #define IN_ACCESS 0x00000001 /* File was accessed */ #define IN_MODIFY 0x00000002 /* File was modified */ #define IN_ATTRIB 0x00000004 /* Metadata changed */ #define IN_CLOSE_WRITE 0x00000008 /* Writtable file was closed */ #define IN_CLOSE_NOWRITE 0x00000010 /* Unwrittable file closed */ #define IN_OPEN 0x00000020 /* File was opened */ #define IN_MOVED_FROM 0x00000040 /* File was moved from X */ #define IN_MOVED_TO 0x00000080 /* File was moved to Y */ #define IN_CREATE 0x00000100 /* Subfile was created */ #define IN_DELETE 0x00000200 /* Subfile was deleted */ #define IN_DELETE_SELF 0x00000400 /* Self was deleted */ #define IN_MOVE_SELF 0x00000800 /* Self was moved */ /* the following are legal events. they are sent as needed to any watch */ #define IN_UNMOUNT 0x00002000 /* Backing fs was unmounted */ #define IN_Q_OVERFLOW 0x00004000 /* Event queued overflowed */ #define IN_IGNORED 0x00008000 /* File was ignored */ /* helper events */ #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) /* close */ #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) /* moves */ /* special flags */ #define IN_ONLYDIR 0x01000000 /* only watch the path if it is a directory */ #define IN_DONT_FOLLOW 0x02000000 /* don't follow a sym link */ #define IN_MASK_ADD 0x20000000 /* add to the mask of an already existing watch */ #define IN_ISDIR 0x40000000 /* event occurred against dir */ #define IN_ONESHOT 0x80000000 /* only send event once */ /* * All of the events - we build the list by hand so that we can add flags in * the future and not break backward compatibility. Apps will get only the * events that they originally wanted. Be sure to add new events here! */ #define IN_ALL_EVENTS (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \ IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | \ IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | \ IN_MOVE_SELF) __BEGIN_DECLS int inotify_init(void) __THROW; int inotify_add_watch(int fd,const char* path,unsigned long mask); int inotify_rm_watch(int fd,int wd); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/io.h010064400000000000000000000023411173363226500147270ustar00#ifndef _SYS_IO_H #define _SYS_IO_H #include __BEGIN_DECLS extern int ioperm(unsigned long from, unsigned long num, int turn_on) __THROW; extern int iopl(int level) __THROW; #ifndef __STRICT_ANSI__ /* anyone have a cleaner solution for this mess? */ #if defined(__i386__) || defined(__x86_64__) static inline unsigned char inb (unsigned short int port) { unsigned char _v; __asm__ __volatile__ ("inb %w1,%0":"=a" (_v):"Nd" (port)); return _v; } static inline unsigned short inw (unsigned short int port) { unsigned short _v; __asm__ __volatile__ ("inw %w1,%0":"=a" (_v):"Nd" (port)); return _v; } static inline unsigned int inl (unsigned short int port) { unsigned int _v; __asm__ __volatile__ ("inl %w1,%0":"=a" (_v):"Nd" (port)); return _v; } static inline void outb (unsigned char value, unsigned short int port) { __asm__ __volatile__ ("outb %b0,%w1": :"a" (value), "Nd" (port)); } static inline void outw (unsigned short value, unsigned short int port) { __asm__ __volatile__ ("outw %w0,%w1": :"a" (value), "Nd" (port)); } static inline void outl (unsigned int value, unsigned short int port) { __asm__ __volatile__ ("outl %0,%w1": :"a" (value), "Nd" (port)); } #endif #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/ioctl.h010064400000000000000000000014721173363226500154360ustar00#ifndef _IOCTL_H #define _IOCTL_H #include __BEGIN_DECLS #if defined(__i386__) || defined(__x86_64__) || defined(__ia64__) #include #elif defined(__alpha__) #include #elif defined(__arm__) #include #elif defined(__sparc__) #include #elif defined(__mips__) #include #elif defined(__powerpc__) || defined(__powerpc64__) #include #elif defined(__s390__) #include #elif defined(__hppa__) #include #endif /* used for /dev/epoll */ #define EP_ALLOC _IOR('P', 1, int) #define EP_POLL _IOWR('P', 2, struct evpoll) #define EP_FREE _IO('P', 3) #define EP_ISPOLLED _IOWR('P', 4, struct pollfd) int ioctl(int d, long int request, ...) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/ipc.h010064400000000000000000000023421173363226500150740ustar00#ifndef _SYS_IPC_H #define _SYS_IPC_H #include #include __BEGIN_DECLS #define SEMOP 1 #define SEMGET 2 #define SEMCTL 3 #define MSGSND 11 #define MSGRCV 12 #define MSGGET 13 #define MSGCTL 14 #define SHMAT 21 #define SHMDT 22 #define SHMGET 23 #define SHMCTL 24 #define IPC_PRIVATE ((key_t) 0) #define IPC_CREAT 00001000 /* create if key is nonexistent */ #define IPC_EXCL 00002000 /* fail if key exists */ #define IPC_NOWAIT 00004000 /* return error on wait */ #define IPC_RMID 0 /* remove resource */ #define IPC_SET 1 /* set ipc_perm options */ #define IPC_STAT 2 /* get ipc_perm options */ #define IPC_INFO 3 /* see ipcs */ /* * Version flags for semctl, msgctl, and shmctl commands * These are passed as bitflags or-ed with the actual command */ #define IPC_OLD 0 /* Old version (no 32-bit UID support on many architectures) */ #define IPC_64 0x0100 /* New version (support 32-bit UIDs, bigger message sizes, etc. */ struct ipc_perm { key_t key; uid_t uid; gid_t gid; uid_t cuid; gid_t cgid; mode_t mode; uint16_t seq; }; /* this is so bad, we moved it to -lcompat */ key_t ftok(const char *pathname, int proj_id); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/kd.h010064400000000000000000000133321173363226500147200ustar00#ifndef _SYS_KD_H #define _SYS_KD_H #include __BEGIN_DECLS /* 0x4B is 'K', to avoid collision with termios and vt */ #define GIO_FONT 0x4B60 /* gets font in expanded form */ #define PIO_FONT 0x4B61 /* use font in expanded form */ #define GIO_FONTX 0x4B6B /* get font using struct consolefontdesc */ #define PIO_FONTX 0x4B6C /* set font using struct consolefontdesc */ struct consolefontdesc { unsigned short charcount; /* characters in font (256 or 512) */ unsigned short charheight; /* scan lines per character (1-32) */ char *chardata; /* font data in expanded form */ }; #define PIO_FONTRESET 0x4B6D /* reset to default font */ #define GIO_CMAP 0x4B70 /* gets colour palette on VGA+ */ #define PIO_CMAP 0x4B71 /* sets colour palette on VGA+ */ #define KIOCSOUND 0x4B2F /* start sound generation (0 for off) */ #define KDMKTONE 0x4B30 /* generate tone */ #define KDGETLED 0x4B31 /* return current led state */ #define KDSETLED 0x4B32 /* set led state [lights, not flags] */ #define LED_SCR 0x01 /* scroll lock led */ #define LED_CAP 0x04 /* caps lock led */ #define LED_NUM 0x02 /* num lock led */ #define KDGKBTYPE 0x4B33 /* get keyboard type */ #define KB_84 0x01 #define KB_101 0x02 /* this is what we always answer */ #define KB_OTHER 0x03 #define KDADDIO 0x4B34 /* add i/o port as valid */ #define KDDELIO 0x4B35 /* del i/o port as valid */ #define KDENABIO 0x4B36 /* enable i/o to video board */ #define KDDISABIO 0x4B37 /* disable i/o to video board */ #define KDSETMODE 0x4B3A /* set text/graphics mode */ #define KD_TEXT 0x00 #define KD_GRAPHICS 0x01 #define KD_TEXT0 0x02 /* obsolete */ #define KD_TEXT1 0x03 /* obsolete */ #define KDGETMODE 0x4B3B /* get current mode */ #define KDMAPDISP 0x4B3C /* map display into address space */ #define KDUNMAPDISP 0x4B3D /* unmap display from address space */ typedef char scrnmap_t; #define E_TABSZ 256 #define GIO_SCRNMAP 0x4B40 /* get screen mapping from kernel */ #define PIO_SCRNMAP 0x4B41 /* put screen mapping table in kernel */ #define GIO_UNISCRNMAP 0x4B69 /* get full Unicode screen mapping */ #define PIO_UNISCRNMAP 0x4B6A /* set full Unicode screen mapping */ #define GIO_UNIMAP 0x4B66 /* get unicode-to-font mapping from kernel */ struct unipair { unsigned short unicode; unsigned short fontpos; }; struct unimapdesc { unsigned short entry_ct; struct unipair *entries; }; #define PIO_UNIMAP 0x4B67 /* put unicode-to-font mapping in kernel */ #define PIO_UNIMAPCLR 0x4B68 /* clear table, possibly advise hash algorithm */ struct unimapinit { unsigned short advised_hashsize; /* 0 if no opinion */ unsigned short advised_hashstep; /* 0 if no opinion */ unsigned short advised_hashlevel; /* 0 if no opinion */ }; #define UNI_DIRECT_BASE 0xF000 /* start of Direct Font Region */ #define UNI_DIRECT_MASK 0x01FF /* Direct Font Region bitmask */ #define K_RAW 0x00 #define K_XLATE 0x01 #define K_MEDIUMRAW 0x02 #define K_UNICODE 0x03 #define KDGKBMODE 0x4B44 /* gets current keyboard mode */ #define KDSKBMODE 0x4B45 /* sets current keyboard mode */ #define K_METABIT 0x03 #define K_ESCPREFIX 0x04 #define KDGKBMETA 0x4B62 /* gets meta key handling mode */ #define KDSKBMETA 0x4B63 /* sets meta key handling mode */ #define K_SCROLLLOCK 0x01 #define K_CAPSLOCK 0x02 #define K_NUMLOCK 0x04 #define KDGKBLED 0x4B64 /* get led flags (not lights) */ #define KDSKBLED 0x4B65 /* set led flags (not lights) */ struct kbentry { unsigned char kb_table; unsigned char kb_index; unsigned short kb_value; }; #define K_NORMTAB 0x00 #define K_SHIFTTAB 0x01 #define K_ALTTAB 0x02 #define K_ALTSHIFTTAB 0x03 #define KDGKBENT 0x4B46 /* gets one entry in translation table */ #define KDSKBENT 0x4B47 /* sets one entry in translation table */ struct kbsentry { unsigned char kb_func; unsigned char kb_string[512]; }; #define KDGKBSENT 0x4B48 /* gets one function key string entry */ #define KDSKBSENT 0x4B49 /* sets one function key string entry */ struct kbdiacr { unsigned char diacr, base, result; }; struct kbdiacrs { unsigned int kb_cnt; /* number of entries in following array */ struct kbdiacr kbdiacr[256]; /* MAX_DIACR from keyboard.h */ }; #define KDGKBDIACR 0x4B4A /* read kernel accent table */ #define KDSKBDIACR 0x4B4B /* write kernel accent table */ struct kbkeycode { unsigned int scancode, keycode; }; #define KDGETKEYCODE 0x4B4C /* read kernel keycode table entry */ #define KDSETKEYCODE 0x4B4D /* write kernel keycode table entry */ #define KDSIGACCEPT 0x4B4E /* accept kbd generated signals */ struct hwclk_time { unsigned int sec; /* 0..59 */ unsigned int min; /* 0..59 */ unsigned int hour; /* 0..23 */ unsigned int day; /* 1..31 */ unsigned int mon; /* 0..11 */ unsigned int year; /* 70... */ int wday; /* 0..6, 0 is Sunday, -1 means unknown/don't set */ }; #define KDGHWCLK 0x4B50 /* get hardware clock */ #define KDSHWCLK 0x4B51 /* set hardware clock */ struct kbd_repeat { int delay; /* in msec; <= 0: don't change */ int rate; /* in msec; <= 0: don't change */ }; #define KDKBDREP 0x4B52 /* set keyboard delay/repeat rate; * actually used values are returned */ #define KDFONTOP 0x4B72 /* font operations */ struct console_font_op { unsigned int op; /* operation code KD_FONT_OP_* */ unsigned int flags; /* KD_FONT_FLAG_* */ unsigned int width, height; /* font size */ unsigned int charcount; unsigned char *data; /* font data with height fixed to 32 */ }; #define KD_FONT_OP_SET 0 /* Set font */ #define KD_FONT_OP_GET 1 /* Get font */ #define KD_FONT_OP_SET_DEFAULT 2 /* Set font to default, data points to name / NULL */ #define KD_FONT_OP_COPY 3 /* Copy from another console */ #define KD_FONT_FLAG_DONT_RECALC 1 /* Don't recalculate hw charcell size [compat] */ __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/key.h010064400000000000000000000043141173363226500151120ustar00#ifndef _SYS_KEY_H #define _SYS_KEY_H #include #include typedef int32_t key_serial_t; typedef uint32_t key_perm_t; /* special process keyring shortcut IDs */ #define KEY_SPEC_THREAD_KEYRING -1 /* - key ID for thread-specific keyring */ #define KEY_SPEC_PROCESS_KEYRING -2 /* - key ID for process-specific keyring */ #define KEY_SPEC_SESSION_KEYRING -3 /* - key ID for session-specific keyring */ #define KEY_SPEC_USER_KEYRING -4 /* - key ID for UID-specific keyring */ #define KEY_SPEC_USER_SESSION_KEYRING -5 /* - key ID for UID-session keyring */ #define KEY_SPEC_GROUP_KEYRING -6 /* - key ID for GID-specific keyring */ /* request-key default keyrings */ #define KEY_REQKEY_DEFL_NO_CHANGE -1 #define KEY_REQKEY_DEFL_DEFAULT 0 #define KEY_REQKEY_DEFL_THREAD_KEYRING 1 #define KEY_REQKEY_DEFL_PROCESS_KEYRING 2 #define KEY_REQKEY_DEFL_SESSION_KEYRING 3 #define KEY_REQKEY_DEFL_USER_KEYRING 4 #define KEY_REQKEY_DEFL_USER_SESSION_KEYRING 5 #define KEY_REQKEY_DEFL_GROUP_KEYRING 6 /* keyctl commands */ #define KEYCTL_GET_KEYRING_ID 0 /* ask for a keyring's ID */ #define KEYCTL_JOIN_SESSION_KEYRING 1 /* join or start named session keyring */ #define KEYCTL_UPDATE 2 /* update a key */ #define KEYCTL_REVOKE 3 /* revoke a key */ #define KEYCTL_CHOWN 4 /* set ownership of a key */ #define KEYCTL_SETPERM 5 /* set perms on a key */ #define KEYCTL_DESCRIBE 6 /* describe a key */ #define KEYCTL_CLEAR 7 /* clear contents of a keyring */ #define KEYCTL_LINK 8 /* link a key into a keyring */ #define KEYCTL_UNLINK 9 /* unlink a key from a keyring */ #define KEYCTL_SEARCH 10 /* search for a key in a keyring */ #define KEYCTL_READ 11 /* read a key or keyring's contents */ #define KEYCTL_INSTANTIATE 12 /* instantiate a partially constructed key */ #define KEYCTL_NEGATE 13 /* negate a partially constructed key */ #define KEYCTL_SET_REQKEY_KEYRING 14 /* set default request-key keyring */ key_serial_t add_key(const char *type, const char *desc, const void *payload, size_t plen, key_serial_t keyring); key_serial_t request_key(const char *type, const char *description, const char *callout_info, key_serial_t dest_keyring); key_serial_t keyctl(int cmd, ...); #endif dietlibc-0.33~cvs20120325/include/sys/klog.h010064400000000000000000000002501173363226500152510ustar00#ifndef _SYS_KLOG_H #define _SYS_KLOG_H #include __BEGIN_DECLS extern int klogctl (int __type, char *__bufp, int __len) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/mips-ioctl.h010064400000000000000000000142451173363226500164060ustar00#define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 13 #define _IOC_DIRBITS 3 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * We to additionally limit parameters to a maximum 255 bytes. */ #define _IOC_SLMASK 0xff /* * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit. * And this turns out useful to catch old ioctl numbers in header * files for us. */ #define _IOC_NONE 1U #define _IOC_READ 2U #define _IOC_WRITE 4U /* * The following are included for compatibility */ #define _IOC_VOID 0x20000000 #define _IOC_OUT 0x40000000 #define _IOC_IN 0x80000000 #define _IOC_INOUT (IOC_IN|IOC_OUT) #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ (((size) & _IOC_SLMASK) << _IOC_SIZESHIFT)) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode them.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* ...and for the drivers/sound files... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) #if defined(__USE_MISC) || defined (__KERNEL__) #define tIOC ('t' << 8) #endif #define TCGETA 0x5401 #define TCSETA 0x5402 #define TCSETAW 0x5403 #define TCSETAF 0x5404 #define TCSBRK 0x5405 #define TCXONC 0x5406 #define TCFLSH 0x5407 #define TCGETS 0x540d #define TCSETS 0x540e #define TCSETSW 0x540f #define TCSETSF 0x5410 #define TIOCEXCL 0x740d /* set exclusive use of tty */ #define TIOCNXCL 0x740e /* reset exclusive use of tty */ #define TIOCOUTQ 0x7472 /* output queue size */ #define TIOCSTI 0x5472 /* simulate terminal input */ #define TIOCMGET 0x741d /* get all modem bits */ #define TIOCMBIS 0x741b /* bis modem bits */ #define TIOCMBIC 0x741c /* bic modem bits */ #define TIOCMSET 0x741a /* set all modem bits */ #define TIOCPKT 0x5470 /* pty: set/clear packet mode */ #define TIOCPKT_DATA 0x00 /* data packet */ #define TIOCPKT_FLUSHREAD 0x01 /* flush packet */ #define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */ #define TIOCPKT_STOP 0x04 /* stop output */ #define TIOCPKT_START 0x08 /* start output */ #define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */ #define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */ #if 0 #define TIOCPKT_IOCTL 0x40 /* state change of pty driver */ #endif #define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */ #define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */ #define TIOCNOTTY 0x5471 /* void tty association */ #if defined(__USE_MISC) || defined (__KERNEL__) #define TIOCSETD (tIOC | 1) #define TIOCGETD (tIOC | 0) #endif #define FIOCLEX 0x6601 #define FIONCLEX 0x6602 /* these numbers need to be adjusted. */ #define FIOASYNC 0x667d #define FIONBIO 0x667e #define FIOQSIZE 0x667f #if defined(__USE_MISC) || defined (__KERNEL__) #define TIOCGLTC (tIOC | 116) /* get special local chars */ #define TIOCSLTC (tIOC | 117) /* set special local chars */ #endif #define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */ #define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */ #define TIOCCONS _IOW('t', 120, int) /* become virtual console */ #define FIONREAD 0x467f #define TIOCINQ FIONREAD #if defined(__USE_MISC) || defined (__KERNEL__) #define TIOCGETP (tIOC | 8) #define TIOCSETP (tIOC | 9) #define TIOCSETN (tIOC | 10) /* TIOCSETP wo flush */ #endif #if 0 #define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */ #define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */ #define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */ #define TIOCGETD _IOR('t', 26, int) /* get line discipline */ #define TIOCSETD _IOW('t', 27, int) /* set line discipline */ /* 127-124 compat */ #endif /* I hope the range from 0x5480 on is free ... */ #define TIOCSCTTY 0x5480 /* become controlling tty */ #define TIOCGSOFTCAR 0x5481 #define TIOCSSOFTCAR 0x5482 #define TIOCLINUX 0x5483 #define TIOCGSERIAL 0x5484 #define TIOCSSERIAL 0x5485 #define TCSBRKP 0x5486 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5487 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID 0x7416 /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define TIOCSERCONFIG 0x5488 #define TIOCSERGWILD 0x5489 #define TIOCSERSWILD 0x548a #define TIOCGLCKTRMIOS 0x548b #define TIOCSLCKTRMIOS 0x548c #define TIOCSERGSTRUCT 0x548d /* For debugging only */ #define TIOCSERGETLSR 0x548e /* Get line status register */ #define TIOCSERGETMULTI 0x548f /* Get multiport config */ #define TIOCSERSETMULTI 0x5490 /* Set multiport config */ #define TIOCMIWAIT 0x5491 /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x5492 /* read serial port inline interrupt counts */ #define TIOCGHAYESESP 0x5493 /* Get Hayes ESP configuration */ #define TIOCSHAYESESP 0x5494 /* Set Hayes ESP configuration */ /* Socket-level I/O control calls. */ #define FIOGETOWN _IOR('f', 123, int) #define FIOSETOWN _IOW('f', 124, int) #define SIOCATMARK _IOR('s', 7, int) #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) #define SIOCGSTAMP 0x8906 /* Get stamp - linux-specific */ dietlibc-0.33~cvs20120325/include/sys/mman.h010064400000000000000000000226711173363226500152600ustar00#ifndef _SYS_MMAN_H #define _SYS_MMAN_H #include #include #include __BEGIN_DECLS #define MREMAP_MAYMOVE 1UL #define MREMAP_FIXED 2UL #define PROT_READ 0x1 /* page can be read */ #define PROT_WRITE 0x2 /* page can be written */ #define PROT_EXEC 0x4 /* page can be executed */ #define PROT_NONE 0x0 /* page can not be accessed */ #define MAP_SHARED 0x01 /* Share changes */ #define MAP_PRIVATE 0x02 /* Changes are private */ #if defined(__mips__) #define MAP_FIXED 0x010 /* Interpret addr exactly */ #define MAP_NORESERVE 0x0400 /* don't check for reservations */ #define MAP_ANONYMOUS 0x0800 /* don't use a file */ #define MAP_GROWSDOWN 0x1000 /* stack-like segment */ #define MAP_DENYWRITE 0x2000 /* ETXTBSY */ #define MAP_EXECUTABLE 0x4000 /* mark it as an executable */ #define MAP_LOCKED 0x8000 /* pages are locked */ #define MAP_POPULATE 0x10000 #define MS_ASYNC 0x0001 /* sync memory asynchronously */ #define MS_INVALIDATE 0x0002 /* invalidate mappings & caches */ #define MS_SYNC 0x0004 /* synchronous memory sync */ #define MCL_CURRENT 1 /* lock all current mappings */ #define MCL_FUTURE 2 /* lock all future mappings */ #define MADV_NORMAL 0x0 /* default page-in behavior */ #define MADV_RANDOM 0x1 /* page-in minimum required */ #define MADV_SEQUENTIAL 0x2 /* read-ahead aggressively */ #define MADV_WILLNEED 0x3 /* pre-fault pages */ #define MADV_DONTNEED 0x4 /* discard these pages */ #elif defined(__alpha__) #define MAP_FIXED 0x100 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x10 /* don't use a file */ #define MAP_GROWSDOWN 0x1000 /* stack-like segment */ #define MAP_DENYWRITE 0x2000 /* ETXTBSY */ #define MAP_EXECUTABLE 0x4000 /* mark it as an executable */ #define MAP_LOCKED 0x8000 /* lock the mapping */ #define MAP_NORESERVE 0x10000 /* don't check for reservations */ #define MAP_POPULATE 0x20000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_SYNC 2 /* synchronous memory sync */ #define MS_INVALIDATE 4 /* invalidate the caches */ #define MCL_CURRENT 8192 /* lock all currently mapped pages */ #define MCL_FUTURE 16384 /* lock all additions to address space */ #define MADV_NORMAL 0 /* no further special treatment */ #define MADV_RANDOM 1 /* expect random page references */ #define MADV_SEQUENTIAL 2 /* expect sequential page references */ #define MADV_WILLNEED 3 /* will need these pages */ #define MADV_SPACEAVAIL 5 /* ensure resources are available */ #define MADV_DONTNEED 6 /* dont need these pages */ #elif defined(__i386__) || defined(__s390__) || defined(__x86_64__) #define MAP_FIXED 0x10 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x20 /* don't use a file */ #define MAP_GROWSDOWN 0x0100 /* stack-like segment */ #define MAP_DENYWRITE 0x0800 /* ETXTBSY */ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ #define MAP_POPULATE 0x8000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ #define MCL_CURRENT 1 /* lock all current mappings */ #define MCL_FUTURE 2 /* lock all future mappings */ #define MADV_NORMAL 0x0 /* default page-in behavior */ #define MADV_RANDOM 0x1 /* page-in minimum required */ #define MADV_SEQUENTIAL 0x2 /* read-ahead aggressively */ #define MADV_WILLNEED 0x3 /* pre-fault pages */ #define MADV_DONTNEED 0x4 /* discard these pages */ #elif defined(__sparc__) || defined (__powerpc__) || defined (__powerpc64__) #define MAP_FIXED 0x10 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x20 /* don't use a file */ #define MAP_RENAME MAP_ANONYMOUS /* In SunOS terminology */ #define MAP_NORESERVE 0x40 /* don't reserve swap pages */ #define MAP_INHERIT 0x80 /* SunOS doesn't do this, but... */ #define MAP_LOCKED 0x100 /* lock the mapping */ #define _MAP_NEW 0x80000000 /* Binary compatibility is fun... */ #define MAP_GROWSDOWN 0x0100 /* stack-like segment */ #define MAP_DENYWRITE 0x0800 /* ETXTBSY */ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_POPULATE 0x8000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ #define MCL_CURRENT 0x2000 /* lock all currently mapped pages */ #define MCL_FUTURE 0x4000 /* lock all additions to address space */ #define MADV_NORMAL 0x0 /* default page-in behavior */ #define MADV_RANDOM 0x1 /* page-in minimum required */ #define MADV_SEQUENTIAL 0x2 /* read-ahead aggressively */ #define MADV_WILLNEED 0x3 /* pre-fault pages */ #define MADV_DONTNEED 0x4 /* discard these pages */ #define MADV_FREE 0x5 /* (Solaris) contents can be freed */ #elif defined (__arm__) #define MAP_FIXED 0x10 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x20 /* don't use a file */ #define MAP_GROWSDOWN 0x0100 /* stack-like segment */ #define MAP_DENYWRITE 0x0800 /* ETXTBSY */ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ #define MAP_POPULATE 0x8000 #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ #define MCL_CURRENT 1 /* lock all current mappings */ #define MCL_FUTURE 2 /* lock all future mappings */ #define MADV_NORMAL 0x0 /* default page-in behavior */ #define MADV_RANDOM 0x1 /* page-in minimum required */ #define MADV_SEQUENTIAL 0x2 /* read-ahead aggressively */ #define MADV_WILLNEED 0x3 /* pre-fault pages */ #define MADV_DONTNEED 0x4 /* discard these pages */ #elif defined(__hppa__) #define MAP_TYPE 0x03 /* Mask for type of mapping */ #define MAP_FIXED 0x04 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x10 /* don't use a file */ #define MAP_DENYWRITE 0x0800 /* ETXTBSY */ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ #define MAP_GROWSDOWN 0x8000 /* stack-like segment */ #define MAP_POPULATE 0x10000 #define MS_SYNC 1 /* synchronous memory sync */ #define MS_ASYNC 2 /* sync memory asynchronously */ #define MS_INVALIDATE 4 /* invalidate the caches */ #define MCL_CURRENT 1 /* lock all current mappings */ #define MCL_FUTURE 2 #define MADV_NORMAL 0 /* no further special treatment */ #define MADV_RANDOM 1 /* expect random page references */ #define MADV_SEQUENTIAL 2 /* expect sequential page references */ #define MADV_WILLNEED 3 /* will need these pages */ #define MADV_DONTNEED 4 /* don't need these pages */ #define MADV_SPACEAVAIL 5 /* insure that resources are reserved */ #define MADV_VPS_PURGE 6 /* Purge pages from VM page cache */ #define MADV_VPS_INHERIT 7 /* Inherit parents page size */ #define MADV_4K_PAGES 12 /* Use 4K pages */ #define MADV_16K_PAGES 14 /* Use 16K pages */ #define MADV_64K_PAGES 16 /* Use 64K pages */ #define MADV_256K_PAGES 18 /* Use 256K pages */ #define MADV_1M_PAGES 20 /* Use 1 Megabyte pages */ #define MADV_4M_PAGES 22 /* Use 4 Megabyte pages */ #define MADV_16M_PAGES 24 /* Use 16 Megabyte pages */ #define MADV_64M_PAGES 26 /* Use 64 Megabyte pages */ #elif defined(__ia64__) #define MAP_TYPE 0x0f /* Mask for type of mapping */ #define MAP_FIXED 0x10 /* Interpret addr exactly */ #define MAP_ANONYMOUS 0x20 /* don't use a file */ #define MAP_GROWSDOWN 0x0100 /* stack-like segment */ #define MAP_GROWSUP 0x0200 /* register stack-like segment */ #define MAP_DENYWRITE 0x0800 /* ETXTBSY */ #define MAP_EXECUTABLE 0x1000 /* mark it as an executable */ #define MAP_LOCKED 0x2000 /* pages are locked */ #define MAP_NORESERVE 0x4000 /* don't check for reservations */ #define MAP_POPULATE 0x8000 #define MAP_WRITECOMBINED 0x10000 /* write-combine the area */ #define MAP_NONCACHED 0x20000 /* don't cache the memory */ #define MS_ASYNC 1 /* sync memory asynchronously */ #define MS_INVALIDATE 2 /* invalidate the caches */ #define MS_SYNC 4 /* synchronous memory sync */ #define MADV_NORMAL 0x0 /* default page-in behavior */ #define MADV_RANDOM 0x1 /* page-in minimum required */ #define MADV_SEQUENTIAL 0x2 /* read-ahead aggressively */ #define MADV_WILLNEED 0x3 /* pre-fault pages */ #define MADV_DONTNEED 0x4 /* discard these pages */ #endif /* compatibility flags */ #define MAP_ANON MAP_ANONYMOUS #define MAP_FILE 0 #define MAP_FAILED ((void *) -1) extern void *mmap (void *__addr, size_t __len, int __prot, int __flags, int __fd, off_t __offset); extern int munmap (void *__addr, size_t __len) __THROW; extern int mprotect (void *__addr, size_t __len, int __prot) __THROW; extern int msync (void *__addr, size_t __len, int __flags) __THROW; extern void *mremap (void *__addr, size_t __old_len, size_t __new_len, unsigned long __may_move) __THROW; extern int mincore (void *__start, size_t __len, unsigned char *__vec); extern void *mmap64 (void *__addr, size_t __len, int __prot, int __flags, int __fd, off64_t __offset) __THROW; #ifndef __NO_STAT64 #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define mmap(a,b,c,d,e,f) mmap64(a,b,c,d,e,f) #endif #endif int mlockall(int flags) __THROW; int mlock(const void *addr, size_t len) __THROW; int munlock(const void *addr, size_t len) __THROW; int munlockall(void) __THROW; int madvise(void *start, size_t length, int advice) __THROW; #define _POSIX_MAPPED_FILES __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/mount.h010064400000000000000000000076141173363226500154720ustar00#ifndef _SYS_MOUNT_H #define _SYS_MOUNT_H #include #include #define _LINUX_CONFIG_H __BEGIN_DECLS #define BLOCK_SIZE 1024 #define BLOCK_SIZE_BITS 10 /* These are the fs-independent mount-flags: up to 16 flags are supported */ enum { MS_RDONLY = 1, /* Mount read-only. */ #define MS_RDONLY MS_RDONLY MS_NOSUID = 2, /* Ignore suid and sgid bits. */ #define MS_NOSUID MS_NOSUID MS_NODEV = 4, /* Disallow access to device special files. */ #define MS_NODEV MS_NODEV MS_NOEXEC = 8, /* Disallow program execution. */ #define MS_NOEXEC MS_NOEXEC MS_SYNCHRONOUS = 16, /* Writes are synced at once. */ #define MS_SYNCHRONOUS MS_SYNCHRONOUS MS_REMOUNT = 32, /* Alter flags of a mounted FS. */ #define MS_REMOUNT MS_REMOUNT MS_MANDLOCK = 64, /* Allow mandatory locks on an FS. */ #define MS_MANDLOCK MS_MANDLOCK S_WRITE = 128, /* Write on file/directory/symlink. */ #define S_WRITE S_WRITE S_APPEND = 256, /* Append-only file. */ #define S_APPEND S_APPEND S_IMMUTABLE = 512, /* Immutable file. */ #define S_IMMUTABLE S_IMMUTABLE MS_NOATIME = 1024, /* Do not update access times. */ #define MS_NOATIME MS_NOATIME MS_NODIRATIME = 2048, /* Do not update directory access times. */ #define MS_NODIRATIME MS_NODIRATIME MS_BIND = 4096, /* Bind directory at different place. */ #define MS_BIND MS_BIND MS_MOVE = 8192, #define MS_MOVE MS_MOVE MS_REC = 16384, #define MS_REC MS_REC MS_SILENT = 32768, #define MS_VERBOSE MS_SILENT #define MS_SILENT MS_SILENT MS_POSIXACL = (1<<16), /* VFS does not apply the umask */ #define MS_POSIXACL MS_POSIXACL MS_UNBINDABLE = (1<<17), /* change to unbindable */ MS_PRIVATE = (1<<18), /* change to private */ #define MS_PRIVATE MS_PRIVATE MS_SLAVE = (1<<19), /* change to slave */ #define MS_SLAVE MS_SLAVE MS_SHARED = (1<<20), /* change to shared */ #define MS_SHARED MS_SHARED MS_RELATIME = (1<<21), /* Update atime relative to mtime/ctime. */ #define MS_RELATIME MS_RELATIME MS_KERNMOUNT = (1<<22), /* this is a kern_mount call */ #define MS_KERNMOUNT MS_KERNMOUNT MS_I_VERSION = (1<<23), /* Update inode I_version field */ #define MS_I_VERSION MS_I_VERSION MS_STRICTATIME = (1<<24), /* Always perform atime updates */ #define MS_STRICTATIME MS_STRICTATIME MS_NOSEC = (1<<28), #define MS_NOSEC MS_NOSEC MS_BORN = (1<<29), #define MS_BORN MS_BORN MS_ACTIVE = (1<<30), #define MS_ACTIVE MS_ACTIVE MS_NOUSER = (1<<31), #define MS_NOUSER MS_NOUSER }; /* Flags that can be altered by MS_REMOUNT */ #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION) /* Magic mount flag number. Has to be or-ed to the flag values. */ #define MS_MGC_VAL 0xc0ed0000 /* Magic flag number to indicate "new" flags */ #define MS_MGC_MSK 0xffff0000 /* Magic flag number mask */ /* The read-only stuff doesn't really belong here, but any other place is probably as bad and I don't want to create yet another include file. */ #define BLKROSET _IO(0x12, 93) /* Set device read-only (0 = read-write). */ #define BLKROGET _IO(0x12, 94) /* Get read-only status (0 = read_write). */ #define BLKRRPART _IO(0x12, 95) /* Re-read partition table. */ #define BLKGETSIZE _IO(0x12, 96) /* Return device size. */ #define BLKFLSBUF _IO(0x12, 97) /* Flush buffer cache. */ #define BLKRASET _IO(0x12, 98) /* Set read ahead for block device. */ #define BLKRAGET _IO(0x12, 99) /* Get current read ahead setting. */ /* Possible value for FLAGS parameter of `umount2'. */ enum { MNT_FORCE = 1, /* Force unmounting. */ #define MNT_FORCE MNT_FORCE MNT_DETACH = 2 /* Just detach, unmount when last reference dies. */ #define MNT_DETACH MNT_DETACH }; int mount(const char* specialfile, const char* dir, const char* filesystemtype, unsigned long rwflag, const void * data) __THROW; int umount(const char *specialfile) __THROW; int umount2(const char *specialfile, int mflag) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/msg.h010064400000000000000000000035521173363226500151130ustar00#ifndef _SYS_MSG_H #define _SYS_MSG_H #include __BEGIN_DECLS /* ipcs ctl commands */ #define MSG_STAT 11 #define MSG_INFO 12 /* msgrcv options */ #define MSG_NOERROR 010000 /* no error if message is too big */ #define MSG_EXCEPT 020000 /* recv any msg except of specified type.*/ struct msqid_ds { struct ipc_perm msg_perm; struct msg *msg_first; /* first message on queue,unused */ struct msg *msg_last; /* last message in queue,unused */ time_t msg_stime; /* last msgsnd time */ time_t msg_rtime; /* last msgrcv time */ time_t msg_ctime; /* last change time */ unsigned long msg_lcbytes; /* Reuse junk fields for 32 bit */ unsigned long msg_lqbytes; /* ditto */ unsigned short msg_cbytes; /* current number of bytes on queue */ unsigned short msg_qnum; /* number of messages in queue */ unsigned short msg_qbytes; /* max number of bytes on queue */ pid_t msg_lspid; /* pid of last msgsnd */ pid_t msg_lrpid; /* last receive pid */ }; /* message buffer for msgsnd and msgrcv calls */ struct msgbuf { long mtype; /* type of message */ char mtext[1]; /* message text */ }; /* buffer for msgctl calls IPC_INFO, MSG_INFO */ struct msginfo { int msgpool; int msgmap; int msgmax; int msgmnb; int msgmni; int msgssz; int msgtql; unsigned short msgseg; }; #define MSGMNI 16 /* <= IPCMNI */ /* max # of msg queue identifiers */ #define MSGMAX 8192 /* <= INT_MAX */ /* max size of message (bytes) */ #define MSGMNB 16384 /* <= INT_MAX */ /* default max size of a message queue */ extern int msgctl (int msqid, int cmd, struct msqid_ds *buf) __THROW; extern int msgget (key_t key, int msgflg) __THROW; extern int msgrcv (int msqid, void *msgp, size_t msgsz, long int msgtyp, int msgflg) __THROW; extern int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/mtio.h010064400000000000000000000317561173363226500153040ustar00#ifndef _SYS_MTIO_H #define _SYS_MTIO_H #include __BEGIN_DECLS /* structure for MTIOCTOP - mag tape op command */ struct mtop { short int mt_op; /* operations defined below */ int mt_count; /* how many of them */ }; /* Magnetic Tape operations [Not all operations supported by all drivers]: */ #define MTRESET 0 /* +reset drive in case of problems */ #define MTFSF 1 /* forward space over FileMark, * position at first record of next file */ #define MTBSF 2 /* backward space FileMark (position before FM) */ #define MTFSR 3 /* forward space record */ #define MTBSR 4 /* backward space record */ #define MTWEOF 5 /* write an end-of-file record (mark) */ #define MTREW 6 /* rewind */ #define MTOFFL 7 /* rewind and put the drive offline (eject?) */ #define MTNOP 8 /* no op, set status only (read with MTIOCGET) */ #define MTRETEN 9 /* retension tape */ #define MTBSFM 10 /* +backward space FileMark, position at FM */ #define MTFSFM 11 /* +forward space FileMark, position at FM */ #define MTEOM 12 /* goto end of recorded media (for appending files). * MTEOM positions after the last FM, ready for * appending another file. */ #define MTERASE 13 /* erase tape -- be careful! */ #define MTRAS1 14 /* run self test 1 (nondestructive) */ #define MTRAS2 15 /* run self test 2 (destructive) */ #define MTRAS3 16 /* reserved for self test 3 */ #define MTSETBLK 20 /* set block length (SCSI) */ #define MTSETDENSITY 21 /* set tape density (SCSI) */ #define MTSEEK 22 /* seek to block (Tandberg, etc.) */ #define MTTELL 23 /* tell block (Tandberg, etc.) */ #define MTSETDRVBUFFER 24 /* set the drive buffering according to SCSI-2 */ /* ordinary buffered operation with code 1 */ #define MTFSS 25 /* space forward over setmarks */ #define MTBSS 26 /* space backward over setmarks */ #define MTWSM 27 /* write setmarks */ #define MTLOCK 28 /* lock the drive door */ #define MTUNLOCK 29 /* unlock the drive door */ #define MTLOAD 30 /* execute the SCSI load command */ #define MTUNLOAD 31 /* execute the SCSI unload command */ #define MTCOMPRESSION 32/* control compression with SCSI mode page 15 */ #define MTSETPART 33 /* Change the active tape partition */ #define MTMKPART 34 /* Format the tape with one or two partitions */ /* structure for MTIOCGET - mag tape get status command */ struct mtget { long int mt_type; /* type of magtape device */ long int mt_resid; /* residual count: (not sure) * number of bytes ignored, or * number of files not skipped, or * number of records not skipped. */ /* the following registers are device dependent */ long int mt_dsreg; /* status register */ long int mt_gstat; /* generic (device independent) status */ long int mt_erreg; /* error register */ /* The next two fields are not always used */ /* these really are daddr_t, but that is only declared with _BSD_SOURCE */ long mt_fileno; /* number of current file on tape */ long mt_blkno; /* current block number */ }; /* * Constants for mt_type. Not all of these are supported, * and these are not all of the ones that are supported. */ #define MT_ISUNKNOWN 0x01 #define MT_ISQIC02 0x02 /* Generic QIC-02 tape streamer */ #define MT_ISWT5150 0x03 /* Wangtek 5150EQ, QIC-150, QIC-02 */ #define MT_ISARCHIVE_5945L2 0x04 /* Archive 5945L-2, QIC-24, QIC-02? */ #define MT_ISCMSJ500 0x05 /* CMS Jumbo 500 (QIC-02?) */ #define MT_ISTDC3610 0x06 /* Tandberg 6310, QIC-24 */ #define MT_ISARCHIVE_VP60I 0x07 /* Archive VP60i, QIC-02 */ #define MT_ISARCHIVE_2150L 0x08 /* Archive Viper 2150L */ #define MT_ISARCHIVE_2060L 0x09 /* Archive Viper 2060L */ #define MT_ISARCHIVESC499 0x0A /* Archive SC-499 QIC-36 controller */ #define MT_ISQIC02_ALL_FEATURES 0x0F /* Generic QIC-02 with all features */ #define MT_ISWT5099EEN24 0x11 /* Wangtek 5099-een24, 60MB, QIC-24 */ #define MT_ISTEAC_MT2ST 0x12 /* Teac MT-2ST 155mb drive, Teac DC-1 card (Wangtek type) */ #define MT_ISEVEREX_FT40A 0x32 /* Everex FT40A (QIC-40) */ #define MT_ISDDS1 0x51 /* DDS device without partitions */ #define MT_ISDDS2 0x52 /* DDS device with partitions */ #define MT_ISONSTREAM_SC 0x61 /* OnStream SCSI tape drives (SC-x0) and SCSI emulated (DI, DP, USB) */ #define MT_ISSCSI1 0x71 /* Generic ANSI SCSI-1 tape unit */ #define MT_ISSCSI2 0x72 /* Generic ANSI SCSI-2 tape unit */ /* QIC-40/80/3010/3020 ftape supported drives. * 20bit vendor ID + 0x800000 (see ftape-vendors.h) */ #define MT_ISFTAPE_UNKNOWN 0x800000 /* obsolete */ #define MT_ISFTAPE_FLAG 0x800000 struct mt_tape_info { long int t_type; /* device type id (mt_type) */ char* t_name; /* descriptive name */ }; #define MT_TAPE_INFO { \ {MT_ISUNKNOWN, "Unknown type of tape device"}, \ {MT_ISQIC02, "Generic QIC-02 tape streamer"}, \ {MT_ISWT5150, "Wangtek 5150, QIC-150"}, \ {MT_ISARCHIVE_5945L2, "Archive 5945L-2"}, \ {MT_ISCMSJ500, "CMS Jumbo 500"}, \ {MT_ISTDC3610, "Tandberg TDC 3610, QIC-24"}, \ {MT_ISARCHIVE_VP60I, "Archive VP60i, QIC-02"}, \ {MT_ISARCHIVE_2150L, "Archive Viper 2150L"}, \ {MT_ISARCHIVE_2060L, "Archive Viper 2060L"}, \ {MT_ISARCHIVESC499, "Archive SC-499 QIC-36 controller"}, \ {MT_ISQIC02_ALL_FEATURES, "Generic QIC-02 tape, all features"}, \ {MT_ISWT5099EEN24, "Wangtek 5099-een24, 60MB"}, \ {MT_ISTEAC_MT2ST, "Teac MT-2ST 155mb data cassette drive"}, \ {MT_ISEVEREX_FT40A, "Everex FT40A, QIC-40"}, \ {MT_ISONSTREAM_SC, "OnStream SC-, DI-, DP-, or USB tape drive"}, \ {MT_ISSCSI1, "Generic SCSI-1 tape"}, \ {MT_ISSCSI2, "Generic SCSI-2 tape"}, \ {0, NULL} \ } /* structure for MTIOCPOS - mag tape get position command */ struct mtpos { long int mt_blkno; /* current block number */ }; /* structure for MTIOCGETCONFIG/MTIOCSETCONFIG primarily intended * as an interim solution for QIC-02 until DDI is fully implemented. */ struct mtconfiginfo { long int mt_type; /* drive type */ long int ifc_type; /* interface card type */ unsigned short int irqnr; /* IRQ number to use */ unsigned short int dmanr; /* DMA channel to use */ unsigned short int port; /* IO port base address */ unsigned long int debug; /* debugging flags */ unsigned int have_dens:1; unsigned int have_bsf:1; unsigned int have_fsr:1; unsigned int have_bsr:1; unsigned int have_eod:1; unsigned int have_seek:1; unsigned int have_tell:1; unsigned int have_ras1:1; unsigned int have_ras2:1; unsigned int have_ras3:1; unsigned int have_qfa:1; unsigned int pad1:5; char reserved[10]; }; /* structure for MTIOCVOLINFO, query information about the volume * currently positioned at (zftape) */ struct mtvolinfo { unsigned int mt_volno; /* vol-number */ unsigned int mt_blksz; /* blocksize used when recording */ unsigned int mt_rawsize; /* raw tape space consumed, in kb */ unsigned int mt_size; /* volume size after decompression, in kb */ unsigned int mt_cmpr:1; /* this volume has been compressed */ }; /* raw access to a floppy drive, read and write an arbitrary segment. * For ftape/zftape to support formatting etc. */ #define MT_FT_RD_SINGLE 0 #define MT_FT_RD_AHEAD 1 #define MT_FT_WR_ASYNC 0 /* start tape only when all buffers are full */ #define MT_FT_WR_MULTI 1 /* start tape, continue until buffers are empty */ #define MT_FT_WR_SINGLE 2 /* write a single segment and stop afterwards */ #define MT_FT_WR_DELETE 3 /* write deleted data marks, one segment at time */ struct mtftseg { unsigned int mt_segno; /* the segment to read or write */ unsigned int mt_mode; /* modes for read/write (sync/async etc.) */ int mt_result; /* result of r/w request, not of the ioctl */ void *mt_data; /* User space buffer: must be 29kb */ }; /* get tape capacity (ftape/zftape) */ struct mttapesize { unsigned long mt_capacity; /* entire, uncompressed capacity of a cartridge */ unsigned long mt_used; /* what has been used so far, raw uncompressed amount */ }; /* possible values of the ftfmt_op field */ #define FTFMT_SET_PARMS 1 /* set software parms */ #define FTFMT_GET_PARMS 2 /* get software parms */ #define FTFMT_FORMAT_TRACK 3 /* start formatting a tape track */ #define FTFMT_STATUS 4 /* monitor formatting a tape track */ #define FTFMT_VERIFY 5 /* verify the given segment */ struct ftfmtparms { unsigned char ft_qicstd; /* QIC-40/QIC-80/QIC-3010/QIC-3020 */ unsigned char ft_fmtcode; /* Refer to the QIC specs */ unsigned char ft_fhm; /* floppy head max */ unsigned char ft_ftm; /* floppy track max */ unsigned short ft_spt; /* segments per track */ unsigned short ft_tpc; /* tracks per cartridge */ }; struct ftfmttrack { unsigned int ft_track; /* track to format */ unsigned char ft_gap3; /* size of gap3, for FORMAT_TRK */ }; struct ftfmtstatus { unsigned int ft_segment; /* segment currently being formatted */ }; struct ftfmtverify { unsigned int ft_segment; /* segment to verify */ unsigned long ft_bsm; /* bsm as result of VERIFY cmd */ }; struct mtftformat { unsigned int fmt_op; /* operation to perform */ union fmt_arg { struct ftfmtparms fmt_parms; /* format parameters */ struct ftfmttrack fmt_track; /* ctrl while formatting */ struct ftfmtstatus fmt_status; struct ftfmtverify fmt_verify; /* for verifying */ } fmt_arg; }; /* mag tape io control commands */ #define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */ #define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */ #define MTIOCPOS _IOR('m', 3, struct mtpos) /* get tape position */ /* The next two are used by the QIC-02 driver for runtime reconfiguration. * See tpqic02.h for struct mtconfiginfo. */ #define MTIOCGETCONFIG _IOR('m', 4, struct mtconfiginfo) /* get tape config */ #define MTIOCSETCONFIG _IOW('m', 5, struct mtconfiginfo) /* set tape config */ /* the next six are used by the floppy ftape drivers and its frontends * sorry, but MTIOCTOP commands are write only. */ #define MTIOCRDFTSEG _IOWR('m', 6, struct mtftseg) /* read a segment */ #define MTIOCWRFTSEG _IOWR('m', 7, struct mtftseg) /* write a segment */ #define MTIOCVOLINFO _IOR('m', 8, struct mtvolinfo) /* info about volume */ #define MTIOCGETSIZE _IOR('m', 9, struct mttapesize)/* get cartridge size*/ #define MTIOCFTFORMAT _IOWR('m', 10, struct mtftformat) /* format ftape */ #define MTIOCFTCMD _IOWR('m', 11, struct mtftcmd) /* send QIC-117 cmd */ /* Generic Mag Tape (device independent) status macros for examining * mt_gstat -- HP-UX compatible. * There is room for more generic status bits here, but I don't * know which of them are reserved. At least three or so should * be added to make this really useful. */ #define GMT_EOF(x) ((x) & 0x80000000) #define GMT_BOT(x) ((x) & 0x40000000) #define GMT_EOT(x) ((x) & 0x20000000) #define GMT_SM(x) ((x) & 0x10000000) /* DDS setmark */ #define GMT_EOD(x) ((x) & 0x08000000) /* DDS EOD */ #define GMT_WR_PROT(x) ((x) & 0x04000000) /* #define GMT_ ? ((x) & 0x02000000) */ #define GMT_ONLINE(x) ((x) & 0x01000000) #define GMT_D_6250(x) ((x) & 0x00800000) #define GMT_D_1600(x) ((x) & 0x00400000) #define GMT_D_800(x) ((x) & 0x00200000) /* #define GMT_ ? ((x) & 0x00100000) */ /* #define GMT_ ? ((x) & 0x00080000) */ #define GMT_DR_OPEN(x) ((x) & 0x00040000) /* door open (no tape) */ /* #define GMT_ ? ((x) & 0x00020000) */ #define GMT_IM_REP_EN(x) ((x) & 0x00010000) /* immediate report mode */ /* 16 generic status bits unused */ /* SCSI-tape specific definitions */ /* Bitfield shifts in the status */ #define MT_ST_BLKSIZE_SHIFT 0 #define MT_ST_BLKSIZE_MASK 0xffffff #define MT_ST_DENSITY_SHIFT 24 #define MT_ST_DENSITY_MASK 0xff000000 #define MT_ST_SOFTERR_SHIFT 0 #define MT_ST_SOFTERR_MASK 0xffff /* Bitfields for the MTSETDRVBUFFER ioctl */ #define MT_ST_OPTIONS 0xf0000000 #define MT_ST_BOOLEANS 0x10000000 #define MT_ST_SETBOOLEANS 0x30000000 #define MT_ST_CLEARBOOLEANS 0x40000000 #define MT_ST_WRITE_THRESHOLD 0x20000000 #define MT_ST_DEF_BLKSIZE 0x50000000 #define MT_ST_DEF_OPTIONS 0x60000000 #define MT_ST_TIMEOUTS 0x70000000 #define MT_ST_SET_TIMEOUT (MT_ST_TIMEOUTS | 0x000000) #define MT_ST_SET_LONG_TIMEOUT (MT_ST_TIMEOUTS | 0x100000) #define MT_ST_BUFFER_WRITES 0x1 #define MT_ST_ASYNC_WRITES 0x2 #define MT_ST_READ_AHEAD 0x4 #define MT_ST_DEBUGGING 0x8 #define MT_ST_TWO_FM 0x10 #define MT_ST_FAST_MTEOM 0x20 #define MT_ST_AUTO_LOCK 0x40 #define MT_ST_DEF_WRITES 0x80 #define MT_ST_CAN_BSR 0x100 #define MT_ST_NO_BLKLIMS 0x200 #define MT_ST_CAN_PARTITIONS 0x400 #define MT_ST_SCSI2LOGICAL 0x800 #define MT_ST_SYSV 0x1000 /* The mode parameters to be controlled. Parameter chosen with bits 20-28 */ #define MT_ST_CLEAR_DEFAULT 0xfffff #define MT_ST_DEF_DENSITY (MT_ST_DEF_OPTIONS | 0x100000) #define MT_ST_DEF_COMPRESSION (MT_ST_DEF_OPTIONS | 0x200000) #define MT_ST_DEF_DRVBUFFER (MT_ST_DEF_OPTIONS | 0x300000) /* The offset for the arguments for the special HP changer load command. */ #define MT_ST_HPLOADER_OFFSET 10000 /* Specify default tape device. */ #ifndef DEFTAPE #define DEFTAPE "/dev/tape/0" #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/param.h010064400000000000000000000010011173363226500154100ustar00#ifndef _SYS_PARAM_H #define _SYS_PARAM_H #include #define MAXPATHLEN PATH_MAX #define MAXHOSTNAMELEN 64 #define NGROUPS 32 #define NOGROUP (-1) #define NOFILE OPEN_MAX #undef MIN #undef MAX #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) #ifdef __alpha__ #define HZ 1024 #else #define HZ 100 #endif #ifndef howmany # define howmany(x, y) (((x)+((y)-1))/(y)) #endif #define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) #define powerof2(x) ((((x)-1)&(x))==0) #endif dietlibc-0.33~cvs20120325/include/sys/personality.h010064400000000000000000000035551173363226500167010ustar00#ifndef _PERSONALITY_H #define _PERSONALITY_H #include /* * Flags for bug emulation. * * These occupy the top three bytes. */ enum { ADDR_NO_RANDOMIZE = 0x0040000, /* disable randomization of VA space */ FDPIC_FUNCPTRS = 0x0080000, /* userspace function ptrs point to descriptors * (signal handling) */ MMAP_PAGE_ZERO = 0x0100000, ADDR_COMPAT_LAYOUT = 0x0200000, READ_IMPLIES_EXEC = 0x0400000, ADDR_LIMIT_32BIT = 0x0800000, SHORT_INODE = 0x1000000, WHOLE_SECONDS = 0x2000000, STICKY_TIMEOUTS = 0x4000000, ADDR_LIMIT_3GB = 0x8000000, }; /* * Personality types. * * These go in the low byte. Avoid using the top bit, it will * conflict with error returns. */ enum { PER_LINUX = 0x0000, PER_LINUX_32BIT = 0x0000 | ADDR_LIMIT_32BIT, PER_LINUX_FDPIC = 0x0000 | FDPIC_FUNCPTRS, PER_SVR4 = 0x0001 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO, PER_SVR3 = 0x0002 | STICKY_TIMEOUTS | SHORT_INODE, PER_SCOSVR3 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS | SHORT_INODE, PER_OSR5 = 0x0003 | STICKY_TIMEOUTS | WHOLE_SECONDS, PER_WYSEV386 = 0x0004 | STICKY_TIMEOUTS | SHORT_INODE, PER_ISCR4 = 0x0005 | STICKY_TIMEOUTS, PER_BSD = 0x0006, PER_SUNOS = 0x0006 | STICKY_TIMEOUTS, PER_XENIX = 0x0007 | STICKY_TIMEOUTS | SHORT_INODE, PER_LINUX32 = 0x0008, PER_LINUX32_3GB = 0x0008 | ADDR_LIMIT_3GB, PER_IRIX32 = 0x0009 | STICKY_TIMEOUTS,/* IRIX5 32-bit */ PER_IRIXN32 = 0x000a | STICKY_TIMEOUTS,/* IRIX6 new 32-bit */ PER_IRIX64 = 0x000b | STICKY_TIMEOUTS,/* IRIX6 64-bit */ PER_RISCOS = 0x000c, PER_SOLARIS = 0x000d | STICKY_TIMEOUTS, PER_UW7 = 0x000e | STICKY_TIMEOUTS | MMAP_PAGE_ZERO, PER_OSF4 = 0x000f, /* OSF/1 v4 */ PER_HPUX = 0x0010, PER_MASK = 0x00ff, }; __BEGIN_DECLS /* Set different ABIs (personalities). */ extern int personality (unsigned long int __persona) __THROW; __END_DECLS #endif /* _PERSONALITY_H */ dietlibc-0.33~cvs20120325/include/sys/poll.h010064400000000000000000000002541173363226500152670ustar00/* ah, the sublime brokenness... susv3 defines poll.h, the Linux man * page defines sys/poll.h; duh! */ #ifndef _SYS_POLL_H #define _SYS_POLL_H #include #endif dietlibc-0.33~cvs20120325/include/sys/ppc-ioctl.h010064400000000000000000000126251173363226500162200ustar00 #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 13 #define _IOC_DIRBITS 3 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * Direction bits _IOC_NONE could be 0, but OSF/1 gives it a bit. * And this turns out useful to catch old ioctl numbers in header * files for us. */ #define _IOC_NONE 1U #define _IOC_READ 2U #define _IOC_WRITE 4U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode them.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* various drivers, such as the pcmcia stuff, need these... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) #define FIOCLEX _IO('f', 1) #define FIONCLEX _IO('f', 2) #define FIOASYNC _IOW('f', 125, int) #define FIONBIO _IOW('f', 126, int) #define FIONREAD _IOR('f', 127, int) #define TIOCINQ FIONREAD #define FIOQSIZE _IOR('f', 128, loff_t) #define TIOCGETP _IOR('t', 8, struct sgttyb) #define TIOCSETP _IOW('t', 9, struct sgttyb) #define TIOCSETN _IOW('t', 10, struct sgttyb) /* TIOCSETP wo flush */ #define TIOCSETC _IOW('t', 17, struct tchars) #define TIOCGETC _IOR('t', 18, struct tchars) #define TCGETS _IOR('t', 19, struct termios) #define TCSETS _IOW('t', 20, struct termios) #define TCSETSW _IOW('t', 21, struct termios) #define TCSETSF _IOW('t', 22, struct termios) #define TCGETA _IOR('t', 23, struct termio) #define TCSETA _IOW('t', 24, struct termio) #define TCSETAW _IOW('t', 25, struct termio) #define TCSETAF _IOW('t', 28, struct termio) #define TCSBRK _IO('t', 29) #define TCXONC _IO('t', 30) #define TCFLSH _IO('t', 31) #define TIOCSWINSZ _IOW('t', 103, struct winsize) #define TIOCGWINSZ _IOR('t', 104, struct winsize) #define TIOCSTART _IO('t', 110) /* start output, like ^Q */ #define TIOCSTOP _IO('t', 111) /* stop output, like ^S */ #define TIOCOUTQ _IOR('t', 115, int) /* output queue size */ #define TIOCGLTC _IOR('t', 116, struct ltchars) #define TIOCSLTC _IOW('t', 117, struct ltchars) #define TIOCSPGRP _IOW('t', 118, int) #define TIOCGPGRP _IOR('t', 119, int) #define TIOCEXCL 0x540C #define TIOCNXCL 0x540D #define TIOCSCTTY 0x540E #define TIOCSTI 0x5412 #define TIOCMGET 0x5415 #define TIOCMBIS 0x5416 #define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 # define TIOCM_LE 0x001 # define TIOCM_DTR 0x002 # define TIOCM_RTS 0x004 # define TIOCM_ST 0x008 # define TIOCM_SR 0x010 # define TIOCM_CTS 0x020 # define TIOCM_CAR 0x040 # define TIOCM_RNG 0x080 # define TIOCM_DSR 0x100 # define TIOCM_CD TIOCM_CAR # define TIOCM_RI TIOCM_RNG #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 # define TIOCPKT_DATA 0 # define TIOCPKT_FLUSHREAD 1 # define TIOCPKT_FLUSHWRITE 2 # define TIOCPKT_STOP 4 # define TIOCPKT_START 8 # define TIOCPKT_NOSTOP 16 # define TIOCPKT_DOSTOP 32 #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 #define TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5426 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID 0x5429 /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ /* ioctl (fd, TIOCSERGETLSR, &result) where result may be as below */ # define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ #if 0 /* These are defined this way on Alpha - maybe later. */ /* Socket-level I/O control calls. */ #define FIOGETOWN _IOR('f', 123, int) #define FIOSETOWN _IOW('f', 124, int) #define SIOCATMARK _IOR('s', 7, int) #define SIOCSPGRP _IOW('s', 8, pid_t) #define SIOCGPGRP _IOR('s', 9, pid_t) #define SIOCGSTAMP 0x8906 /* Get stamp - linux-specific */ #endif dietlibc-0.33~cvs20120325/include/sys/prctl.h010064400000000000000000000051431173363226500154470ustar00#ifndef _SYS_PRCTL_H #define _SYS_PRCTL_H #include /* Values to pass as first argument to prctl() */ #define PR_SET_PDEATHSIG 1 /* Second arg is a signal */ #define PR_GET_PDEATHSIG 2 /* Second arg is a ptr to return the signal */ /* Get/set current->mm->dumpable */ #define PR_GET_DUMPABLE 3 #define PR_SET_DUMPABLE 4 /* Get/set unaligned access control bits (if meaningful) */ #define PR_GET_UNALIGN 5 #define PR_SET_UNALIGN 6 # define PR_UNALIGN_NOPRINT 1 /* silently fix up unaligned user accesses */ # define PR_UNALIGN_SIGBUS 2 /* generate SIGBUS on unaligned user access */ /* Get/set whether or not to drop capabilities on setuid() away from uid 0 */ #define PR_GET_KEEPCAPS 7 #define PR_SET_KEEPCAPS 8 /* Get/set floating-point emulation control bits (if meaningful) */ #define PR_GET_FPEMU 9 #define PR_SET_FPEMU 10 # define PR_FPEMU_NOPRINT 1 /* silently emulate fp operations accesses */ # define PR_FPEMU_SIGFPE 2 /* don't emulate fp operations, send SIGFPE instead */ /* Get/set floating-point exception mode (if meaningful) */ #define PR_GET_FPEXC 11 #define PR_SET_FPEXC 12 # define PR_FP_EXC_SW_ENABLE 0x80 /* Use FPEXC for FP exception enables */ # define PR_FP_EXC_DIV 0x010000 /* floating point divide by zero */ # define PR_FP_EXC_OVF 0x020000 /* floating point overflow */ # define PR_FP_EXC_UND 0x040000 /* floating point underflow */ # define PR_FP_EXC_RES 0x080000 /* floating point inexact result */ # define PR_FP_EXC_INV 0x100000 /* floating point invalid operation */ # define PR_FP_EXC_DISABLED 0 /* FP exceptions disabled */ # define PR_FP_EXC_NONRECOV 1 /* async non-recoverable exc. mode */ # define PR_FP_EXC_ASYNC 2 /* async recoverable exception mode */ # define PR_FP_EXC_PRECISE 3 /* precise exception mode */ /* Get/set whether we use statistical process timing or accurate timestamp * based process timing */ #define PR_GET_TIMING 13 #define PR_SET_TIMING 14 # define PR_TIMING_STATISTICAL 0 /* Normal, traditional, statistical process timing */ # define PR_TIMING_TIMESTAMP 1 /* Accurate timestamp based process timing */ #define PR_SET_NAME 15 /* Set process name */ #define PR_GET_NAME 16 /* Get process name */ /* Get/set process endian */ #define PR_GET_ENDIAN 19 #define PR_SET_ENDIAN 20 # define PR_ENDIAN_BIG 0 # define PR_ENDIAN_LITTLE 1 /* True little endian mode */ # define PR_ENDIAN_PPC_LITTLE 2 /* "PowerPC" pseudo little endian */ __BEGIN_DECLS int prctl(int option, unsigned long arg2, ...) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/ptrace.h010064400000000000000000000521361173363226500156050ustar00#ifndef _SYS_PTRACE_H #define _SYS_PTRACE_H #include #include __BEGIN_DECLS #define PTRACE_TRACEME 0 #define PTRACE_PEEKTEXT 1 #define PTRACE_PEEKDATA 2 #define PTRACE_PEEKUSR 3 #define PTRACE_PEEKUSER PTRACE_PEEKUSR #define PTRACE_POKETEXT 4 #define PTRACE_POKEDATA 5 #define PTRACE_POKEUSR 6 #define PTRACE_POKEUSER PTRACE_POKEUSR #define PTRACE_CONT 7 #define PTRACE_KILL 8 #define PTRACE_SINGLESTEP 9 #define PTRACE_ATTACH 0x10 #define PTRACE_DETACH 0x11 #define PTRACE_SYSCALL 24 /* 0x4200-0x4300 are reserved for architecture-independent additions. */ #define PTRACE_SETOPTIONS 0x4200 #define PTRACE_GETEVENTMSG 0x4201 #define PTRACE_GETSIGINFO 0x4202 #define PTRACE_SETSIGINFO 0x4203 /* options set using PTRACE_SETOPTIONS */ #define PTRACE_O_TRACESYSGOOD 0x00000001 #define PTRACE_O_TRACEFORK 0x00000002 #define PTRACE_O_TRACEVFORK 0x00000004 #define PTRACE_O_TRACECLONE 0x00000008 #define PTRACE_O_TRACEEXEC 0x00000010 #define PTRACE_O_TRACEVFORKDONE 0x00000020 #define PTRACE_O_TRACEEXIT 0x00000040 #define PTRACE_O_MASK 0x0000007f /* Wait extended result codes for the above trace options. */ #define PTRACE_EVENT_FORK 1 #define PTRACE_EVENT_VFORK 2 #define PTRACE_EVENT_CLONE 3 #define PTRACE_EVENT_EXEC 4 #define PTRACE_EVENT_VFORK_DONE 5 #define PTRACE_EVENT_EXIT 6 #define PT_TRACE_ME PTRACE_TRACEME #define PT_READ_I PTRACE_PEEKTEXT #define PT_READ_D PTRACE_PEEKDATA #define PT_READ_U PTRACE_PEEKUSER #define PT_WRITE_I PTRACE_POKETEXT #define PT_WRITE_D PTRACE_POKEDATA #define PT_WRITE_U PTRACE_POKEUSER #define PT_CONTINUE PTRACE_CONT #define PT_KILL PTRACE_KILL #define PT_STEP PTRACE_SINGLESTEP #define PT_GETREGS PTRACE_GETREGS #define PT_SETREGS PTRACE_SETREGS #define PT_GETFPREGS PTRACE_GETFPREGS #define PT_SETFPREGS PTRACE_SETFPREGS #define PT_ATTACH PTRACE_ATTACH #define PT_DETACH PTRACE_DETACH #if defined(__i386__) #define EBX 0 #define ECX 1 #define EDX 2 #define ESI 3 #define EDI 4 #define EBP 5 #define EAX 6 #define DS 7 #define ES 8 #define FS 9 #define GS 10 #define ORIG_EAX 11 #define EIP 12 #define CS 13 #define EFL 14 #define UESP 15 #define SS 16 #define FRAME_SIZE 17 /* this struct defines the way the registers are stored on the stack during a system call. */ struct pt_regs { long ebx; long ecx; long edx; long esi; long edi; long ebp; long eax; int32_t xds; int32_t xes; long orig_eax; long eip; int32_t xcs; long eflags; long esp; int32_t xss; }; /* Arbitrarily choose the same ptrace numbers as used by the Sparc code. */ #define PTRACE_GETREGS 12 #define PTRACE_SETREGS 13 #define PTRACE_GETFPREGS 14 #define PTRACE_SETFPREGS 15 #define PTRACE_GETFPXREGS 18 #define PTRACE_SETFPXREGS 19 #define PTRACE_SETOPTIONS 21 /* options set using PTRACE_SETOPTIONS */ #define PTRACE_O_TRACESYSGOOD 0x00000001 #elif defined(__x86_64__) struct pt_regs { unsigned long r15; unsigned long r14; unsigned long r13; unsigned long r12; unsigned long rbp; unsigned long rbx; /* arguments: non interrupts/non tracing syscalls only save upto here*/ unsigned long r11; unsigned long r10; unsigned long r9; unsigned long r8; unsigned long rax; unsigned long rcx; unsigned long rdx; unsigned long rsi; unsigned long rdi; unsigned long orig_rax; /* end of arguments */ /* cpu exception frame or undefined */ unsigned long rip; unsigned long cs; unsigned long eflags; unsigned long rsp; unsigned long ss; /* top of stack page */ }; #elif defined(__s390__) #define PT_PSWMASK 0x00 #define PT_PSWADDR 0x04 #define PT_GPR0 0x08 #define PT_GPR1 0x0C #define PT_GPR2 0x10 #define PT_GPR3 0x14 #define PT_GPR4 0x18 #define PT_GPR5 0x1C #define PT_GPR6 0x20 #define PT_GPR7 0x24 #define PT_GPR8 0x28 #define PT_GPR9 0x2C #define PT_GPR10 0x30 #define PT_GPR11 0x34 #define PT_GPR12 0x38 #define PT_GPR13 0x3C #define PT_GPR14 0x40 #define PT_GPR15 0x44 #define PT_ACR0 0x48 #define PT_ACR1 0x4C #define PT_ACR2 0x50 #define PT_ACR3 0x54 #define PT_ACR4 0x58 #define PT_ACR5 0x5C #define PT_ACR6 0x60 #define PT_ACR7 0x64 #define PT_ACR8 0x68 #define PT_ACR9 0x6C #define PT_ACR10 0x70 #define PT_ACR11 0x74 #define PT_ACR12 0x78 #define PT_ACR13 0x7C #define PT_ACR14 0x80 #define PT_ACR15 0x84 #define PT_ORIGGPR2 0x88 #define PT_FPC 0x90 #define PT_FPR0_HI 0x98 #define PT_FPR0_LO 0x9C #define PT_FPR1_HI 0xA0 #define PT_FPR1_LO 0xA4 #define PT_FPR2_HI 0xA8 #define PT_FPR2_LO 0xAC #define PT_FPR3_HI 0xB0 #define PT_FPR3_LO 0xB4 #define PT_FPR4_HI 0xB8 #define PT_FPR4_LO 0xBC #define PT_FPR5_HI 0xC0 #define PT_FPR5_LO 0xC4 #define PT_FPR6_HI 0xC8 #define PT_FPR6_LO 0xCC #define PT_FPR7_HI 0xD0 #define PT_FPR7_LO 0xD4 #define PT_FPR8_HI 0xD8 #define PT_FPR8_LO 0XDC #define PT_FPR9_HI 0xE0 #define PT_FPR9_LO 0xE4 #define PT_FPR10_HI 0xE8 #define PT_FPR10_LO 0xEC #define PT_FPR11_HI 0xF0 #define PT_FPR11_LO 0xF4 #define PT_FPR12_HI 0xF8 #define PT_FPR12_LO 0xFC #define PT_FPR13_HI 0x100 #define PT_FPR13_LO 0x104 #define PT_FPR14_HI 0x108 #define PT_FPR14_LO 0x10C #define PT_FPR15_HI 0x110 #define PT_FPR15_LO 0x114 #define PT_CR_9 0x118 #define PT_CR_10 0x11C #define PT_CR_11 0x120 #define PT_IEEE_IP 0x13C #define PT_LASTOFF PT_IEEE_IP #define PT_ENDREGS 0x140-1 #define NUM_GPRS 16 #define NUM_FPRS 16 #define NUM_CRS 16 #define NUM_ACRS 16 #define GPR_SIZE 4 #define FPR_SIZE 8 #define FPC_SIZE 4 #define FPC_PAD_SIZE 4 /* gcc insists on aligning the fpregs */ #define CR_SIZE 4 #define ACR_SIZE 4 #define STACK_FRAME_OVERHEAD 96 /* size of minimum stack frame */ /* this typedef defines how a Program Status Word looks like */ typedef struct { uint32_t mask; uint32_t addr; } psw_t __attribute__ ((__aligned__(8))); typedef union { float f; double d; uint64_t ui; struct { uint32_t hi; uint32_t lo; } fp; } freg_t; typedef struct { uint32_t fpc; freg_t fprs[NUM_FPRS]; } s390_fp_regs; #define FPC_EXCEPTION_MASK 0xF8000000 #define FPC_FLAGS_MASK 0x00F80000 #define FPC_DXC_MASK 0x0000FF00 #define FPC_RM_MASK 0x00000003 #define FPC_VALID_MASK 0xF8F8FF03 typedef struct { psw_t psw; uint32_t gprs[NUM_GPRS]; uint32_t acrs[NUM_ACRS]; uint32_t orig_gpr2; } s390_regs; struct pt_regs { psw_t psw; uint32_t gprs[NUM_GPRS]; uint32_t acrs[NUM_ACRS]; uint32_t orig_gpr2; uint32_t trap; uint32_t old_ilc; }; typedef struct { uint32_t cr[3]; } per_cr_words __attribute__((__packed__)); #define PER_EM_MASK 0xE8000000 typedef uint32_t addr_t; typedef struct { uint32_t em_branching : 1; uint32_t em_instruction_fetch : 1; /* * Switching on storage alteration automatically fixes * the storage alteration event bit in the users std. */ uint32_t em_storage_alteration : 1; uint32_t em_gpr_alt_unused : 1; uint32_t em_store_real_address : 1; uint32_t : 3; uint32_t branch_addr_ctl : 1; uint32_t : 1; uint32_t storage_alt_space_ctl : 1; uint32_t : 21; addr_t starting_addr; addr_t ending_addr; } per_cr_bits __attribute__((__packed__)); typedef struct { uint16_t perc_atmid; /* 0x096 */ uint32_t address; /* 0x098 */ uint8_t access_id; /* 0x0a1 */ } per_lowcore_words __attribute__((__packed__)); typedef struct { uint32_t perc_branching : 1; /* 0x096 */ uint32_t perc_instruction_fetch : 1; uint32_t perc_storage_alteration : 1; uint32_t perc_gpr_alt_unused : 1; uint32_t perc_store_real_address : 1; uint32_t : 4; uint32_t atmid_validity_bit : 1; uint32_t atmid_psw_bit_32 : 1; uint32_t atmid_psw_bit_5 : 1; uint32_t atmid_psw_bit_16 : 1; uint32_t atmid_psw_bit_17 : 1; uint32_t si : 2; addr_t address; /* 0x098 */ uint32_t : 4; /* 0x0a1 */ uint32_t access_id : 4; } per_lowcore_bits __attribute__((__packed__)); typedef struct { union { per_cr_words words; per_cr_bits bits; } control_regs __attribute__((__packed__)); /* * Use these flags instead of setting em_instruction_fetch * directly they are used so that single stepping can be * switched on & off while not affecting other tracing */ uint32_t single_step : 1; uint32_t instruction_fetch : 1; uint32_t : 30; /* * These addresses are copied into cr10 & cr11 if single * stepping is switched off */ uint32_t starting_addr; uint32_t ending_addr; union { per_lowcore_words words; per_lowcore_bits bits; } lowcore; } per_struct __attribute__((__packed__)); typedef struct { uint32_t len; addr_t kernel_addr; addr_t process_addr; } ptrace_area; /* * S/390 specific non posix ptrace requests. I chose unusual values so * they are unlikely to clash with future ptrace definitions. */ #define PTRACE_PEEKUSR_AREA 0x5000 #define PTRACE_POKEUSR_AREA 0x5001 #define PTRACE_PEEKTEXT_AREA 0x5002 #define PTRACE_PEEKDATA_AREA 0x5003 #define PTRACE_POKETEXT_AREA 0x5004 #define PTRACE_POKEDATA_AREA 0x5005 /* * PT_PROT definition is loosely based on hppa bsd definition in * gdb/hppab-nat.c */ #define PTRACE_PROT 21 typedef enum { ptprot_set_access_watchpoint, ptprot_set_write_watchpoint, ptprot_disable_watchpoint } ptprot_flags; typedef struct { addr_t lowaddr; addr_t hiaddr; ptprot_flags prot; } ptprot_area; /* Sequence of bytes for breakpoint illegal instruction. */ #define S390_BREAKPOINT {0x0,0x1} #define S390_BREAKPOINT_U16 ((uint16_t)0x0001) #define S390_SYSCALL_OPCODE ((uint16_t)0x0a00) #define S390_SYSCALL_SIZE 2 /* * The user_regs_struct defines the way the user registers are * store on the stack for signal handling. */ struct user_regs_struct { psw_t psw; uint32_t gprs[NUM_GPRS]; uint32_t acrs[NUM_ACRS]; uint32_t orig_gpr2; s390_fp_regs fp_regs; /* * These per registers are in here so that gdb can modify them * itself as there is no "official" ptrace interface for hardware * watchpoints. This is the way intel does it. */ per_struct per_info; addr_t ieee_instruction_pointer; /* Used to give failing instruction back to user for ieee exceptions */ }; #elif defined(__arm__) /* this assumes armv */ #define USR26_MODE 0x00 #define FIQ26_MODE 0x01 #define IRQ26_MODE 0x02 #define SVC26_MODE 0x03 #define USR_MODE 0x10 #define FIQ_MODE 0x11 #define IRQ_MODE 0x12 #define SVC_MODE 0x13 #define ABT_MODE 0x17 #define UND_MODE 0x1b #define SYSTEM_MODE 0x1f #define MODE_MASK 0x1f #define T_BIT 0x20 #define F_BIT 0x40 #define I_BIT 0x80 #define CC_V_BIT (1 << 28) #define CC_C_BIT (1 << 29) #define CC_Z_BIT (1 << 30) #define CC_N_BIT (1 << 31) #define PCMASK 0 struct pt_regs { long uregs[18]; }; #define ARM_cpsr uregs[16] #define ARM_pc uregs[15] #define ARM_lr uregs[14] #define ARM_sp uregs[13] #define ARM_ip uregs[12] #define ARM_fp uregs[11] #define ARM_r10 uregs[10] #define ARM_r9 uregs[9] #define ARM_r8 uregs[8] #define ARM_r7 uregs[7] #define ARM_r6 uregs[6] #define ARM_r5 uregs[5] #define ARM_r4 uregs[4] #define ARM_r3 uregs[3] #define ARM_r2 uregs[2] #define ARM_r1 uregs[1] #define ARM_r0 uregs[0] #define ARM_ORIG_r0 uregs[17] #elif defined(__alpha__) struct pt_regs { unsigned long r0; unsigned long r1; unsigned long r2; unsigned long r3; unsigned long r4; unsigned long r5; unsigned long r6; unsigned long r7; unsigned long r8; unsigned long r19; unsigned long r20; unsigned long r21; unsigned long r22; unsigned long r23; unsigned long r24; unsigned long r25; unsigned long r26; unsigned long r27; unsigned long r28; unsigned long hae; /* JRP - These are the values provided to a0-a2 by PALcode */ unsigned long trap_a0; unsigned long trap_a1; unsigned long trap_a2; /* These are saved by PAL-code: */ unsigned long ps; unsigned long pc; unsigned long gp; unsigned long r16; unsigned long r17; unsigned long r18; }; struct switch_stack { unsigned long r9; unsigned long r10; unsigned long r11; unsigned long r12; unsigned long r13; unsigned long r14; unsigned long r15; unsigned long r26; unsigned long fp[32]; /* fp[31] is fpcr */ }; #elif defined(__mips__) /* 0 - 31 are integer registers, 32 - 63 are fp registers. */ #define FPR_BASE 32 #define PC 64 #define CAUSE 65 #define BADVADDR 66 #define MMHI 67 #define MMLO 68 #define FPC_CSR 69 #define FPC_EIR 70 struct pt_regs { /* Pad bytes for argument save space on the stack. */ unsigned long pad0[6]; /* Saved main processor registers. */ unsigned long regs[32]; /* Other saved registers. */ unsigned long lo; unsigned long hi; /* saved cp0 registers */ unsigned long cp0_epc; unsigned long cp0_badvaddr; unsigned long cp0_status; unsigned long cp0_cause; }; #elif defined(__sparc__) struct pt_regs { unsigned long psr; unsigned long pc; unsigned long npc; unsigned long y; unsigned long u_regs[16]; /* globals and ins */ }; #define UREG_G0 0 #define UREG_G1 1 #define UREG_G2 2 #define UREG_G3 3 #define UREG_G4 4 #define UREG_G5 5 #define UREG_G6 6 #define UREG_G7 7 #define UREG_I0 8 #define UREG_I1 9 #define UREG_I2 10 #define UREG_I3 11 #define UREG_I4 12 #define UREG_I5 13 #define UREG_I6 14 #define UREG_I7 15 #define UREG_WIM UREG_G0 #define UREG_FADDR UREG_G0 #define UREG_FP UREG_I6 #define UREG_RETPC UREG_I7 /* A register window */ struct reg_window { unsigned long locals[8]; unsigned long ins[8]; }; /* A Sparc stack frame */ struct sparc_stackf { unsigned long locals[8]; unsigned long ins[6]; struct sparc_stackf *fp; unsigned long callers_pc; char *structptr; unsigned long xargs[6]; unsigned long xxargs[1]; }; #define TRACEREG_SZ sizeof(struct pt_regs) #define STACKFRAME_SZ sizeof(struct sparc_stackf) #define REGWIN_SZ sizeof(struct reg_window) /* These are for pt_regs. */ #define PT_PSR 0x0 #define PT_PC 0x4 #define PT_NPC 0x8 #define PT_Y 0xc #define PT_G0 0x10 #define PT_WIM PT_G0 #define PT_G1 0x14 #define PT_G2 0x18 #define PT_G3 0x1c #define PT_G4 0x20 #define PT_G5 0x24 #define PT_G6 0x28 #define PT_G7 0x2c #define PT_I0 0x30 #define PT_I1 0x34 #define PT_I2 0x38 #define PT_I3 0x3c #define PT_I4 0x40 #define PT_I5 0x44 #define PT_I6 0x48 #define PT_FP PT_I6 #define PT_I7 0x4c /* Reg_window offsets */ #define RW_L0 0x00 #define RW_L1 0x04 #define RW_L2 0x08 #define RW_L3 0x0c #define RW_L4 0x10 #define RW_L5 0x14 #define RW_L6 0x18 #define RW_L7 0x1c #define RW_I0 0x20 #define RW_I1 0x24 #define RW_I2 0x28 #define RW_I3 0x2c #define RW_I4 0x30 #define RW_I5 0x34 #define RW_I6 0x38 #define RW_I7 0x3c /* Stack_frame offsets */ #define SF_L0 0x00 #define SF_L1 0x04 #define SF_L2 0x08 #define SF_L3 0x0c #define SF_L4 0x10 #define SF_L5 0x14 #define SF_L6 0x18 #define SF_L7 0x1c #define SF_I0 0x20 #define SF_I1 0x24 #define SF_I2 0x28 #define SF_I3 0x2c #define SF_I4 0x30 #define SF_I5 0x34 #define SF_FP 0x38 #define SF_PC 0x3c #define SF_RETP 0x40 #define SF_XARG0 0x44 #define SF_XARG1 0x48 #define SF_XARG2 0x4c #define SF_XARG3 0x50 #define SF_XARG4 0x54 #define SF_XARG5 0x58 #define SF_XXARG 0x5c /* Stuff for the ptrace system call */ #define PTRACE_SUNATTACH 10 #define PTRACE_SUNDETACH 11 #define PTRACE_GETREGS 12 #define PTRACE_SETREGS 13 #define PTRACE_GETFPREGS 14 #define PTRACE_SETFPREGS 15 #define PTRACE_READDATA 16 #define PTRACE_WRITEDATA 17 #define PTRACE_READTEXT 18 #define PTRACE_WRITETEXT 19 #define PTRACE_GETFPAREGS 20 #define PTRACE_SETFPAREGS 21 #define PTRACE_GETUCODE 29 /* stupid bsd-ism */ #elif defined(__powerpc__) || defined (__powerpc64__) #include #elif defined(__hppa__) #include struct pt_regs { unsigned long gr[32]; /* PSW is in gr[0] */ uint64_t fr[32]; unsigned long sr[ 8]; unsigned long iasq[2]; unsigned long iaoq[2]; unsigned long cr27; unsigned long pad0; /* available for other uses */ unsigned long orig_r28; unsigned long ksp; unsigned long kpc; unsigned long sar; /* CR11 */ unsigned long iir; /* CR19 */ unsigned long isr; /* CR20 */ unsigned long ior; /* CR21 */ unsigned long ipsw; /* CR22 */ }; #define PTRACE_SINGLEBLOCK 12 /* resume execution until next branch */ #define PTRACE_GETSIGINFO 13 /* get child's siginfo structure */ #define PTRACE_SETSIGINFO 14 /* set child's siginfo structure */ #elif defined(__ia64__) struct ia64_fpreg { union { unsigned long bits[2]; } u; } __attribute__ ((__aligned__ (16))); struct pt_regs { unsigned long cr_ipsr; /* interrupted task's psr */ unsigned long cr_iip; /* interrupted task's instruction pointer */ unsigned long cr_ifs; /* interrupted task's function state */ unsigned long ar_unat; /* interrupted task's NaT register (preserved) */ unsigned long ar_pfs; /* prev function state */ unsigned long ar_rsc; /* RSE configuration */ unsigned long ar_rnat; /* RSE NaT */ unsigned long ar_bspstore; /* RSE bspstore */ unsigned long pr; /* 64 predicate registers (1 bit each) */ unsigned long b6; /* scratch */ unsigned long loadrs; /* size of dirty partition << 16 */ unsigned long r1; /* the gp pointer */ unsigned long r2; /* scratch */ unsigned long r3; /* scratch */ unsigned long r12; /* interrupted task's memory stack pointer */ unsigned long r13; /* thread pointer */ unsigned long r14; /* scratch */ unsigned long r15; /* scratch */ unsigned long r8; /* scratch (return value register 0) */ unsigned long r9; /* scratch (return value register 1) */ unsigned long r10; /* scratch (return value register 2) */ unsigned long r11; /* scratch (return value register 3) */ unsigned long r16; /* scratch */ unsigned long r17; /* scratch */ unsigned long r18; /* scratch */ unsigned long r19; /* scratch */ unsigned long r20; /* scratch */ unsigned long r21; /* scratch */ unsigned long r22; /* scratch */ unsigned long r23; /* scratch */ unsigned long r24; /* scratch */ unsigned long r25; /* scratch */ unsigned long r26; /* scratch */ unsigned long r27; /* scratch */ unsigned long r28; /* scratch */ unsigned long r29; /* scratch */ unsigned long r30; /* scratch */ unsigned long r31; /* scratch */ unsigned long ar_ccv; /* compare/exchange value (scratch) */ unsigned long ar_fpsr; /* floating point status (preserved) */ unsigned long b0; /* return pointer (bp) */ unsigned long b7; /* scratch */ struct ia64_fpreg f6; /* scratch */ struct ia64_fpreg f7; /* scratch */ struct ia64_fpreg f8; /* scratch */ struct ia64_fpreg f9; /* scratch */ }; struct switch_stack { unsigned long caller_unat; /* user NaT collection register (preserved) */ unsigned long ar_fpsr; /* floating-point status register */ struct ia64_fpreg f2; /* preserved */ struct ia64_fpreg f3; /* preserved */ struct ia64_fpreg f4; /* preserved */ struct ia64_fpreg f5; /* preserved */ struct ia64_fpreg f10; /* scratch, but untouched by kernel */ struct ia64_fpreg f11; /* scratch, but untouched by kernel */ struct ia64_fpreg f12; /* scratch, but untouched by kernel */ struct ia64_fpreg f13; /* scratch, but untouched by kernel */ struct ia64_fpreg f14; /* scratch, but untouched by kernel */ struct ia64_fpreg f15; /* scratch, but untouched by kernel */ struct ia64_fpreg f16; /* preserved */ struct ia64_fpreg f17; /* preserved */ struct ia64_fpreg f18; /* preserved */ struct ia64_fpreg f19; /* preserved */ struct ia64_fpreg f20; /* preserved */ struct ia64_fpreg f21; /* preserved */ struct ia64_fpreg f22; /* preserved */ struct ia64_fpreg f23; /* preserved */ struct ia64_fpreg f24; /* preserved */ struct ia64_fpreg f25; /* preserved */ struct ia64_fpreg f26; /* preserved */ struct ia64_fpreg f27; /* preserved */ struct ia64_fpreg f28; /* preserved */ struct ia64_fpreg f29; /* preserved */ struct ia64_fpreg f30; /* preserved */ struct ia64_fpreg f31; /* preserved */ unsigned long r4; /* preserved */ unsigned long r5; /* preserved */ unsigned long r6; /* preserved */ unsigned long r7; /* preserved */ unsigned long b0; /* so we can force a direct return in copy_thread */ unsigned long b1; unsigned long b2; unsigned long b3; unsigned long b4; unsigned long b5; unsigned long ar_pfs; /* previous function state */ unsigned long ar_lc; /* loop counter (preserved) */ unsigned long ar_unat; /* NaT bits for r4-r7 */ unsigned long ar_rnat; /* RSE NaT collection register */ unsigned long ar_bspstore; /* RSE dirty base (preserved) */ unsigned long pr; /* 64 predicate registers (1 bit each) */ }; #endif extern long int ptrace(int request, ...) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/quota.h010064400000000000000000000073071173363226500154600ustar00#ifndef _SYS_QUOTA_H #define _SYS_QUOTA_H 1 #include #include #include /* * Convert diskblocks to blocks and the other way around. * currently only to fool the BSD source. :-) */ #define dbtob(num) ((num) << 10) #define btodb(num) ((num) >> 10) /* * Convert count of filesystem blocks to diskquota blocks, meant * for filesystems where i_blksize != BLOCK_SIZE */ #define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / BLOCK_SIZE) /* * Definitions for disk quotas imposed on the average user * (big brother finally hits Linux). * * The following constants define the amount of time given a user * before the soft limits are treated as hard limits (usually resulting * in an allocation failure). The timer is started when the user crosses * their soft limit, it is reset when they go below their soft limit. */ #define MAX_IQ_TIME 604800 /* (7*24*60*60) 1 week */ #define MAX_DQ_TIME 604800 /* (7*24*60*60) 1 week */ #define MAXQUOTAS 2 #define USRQUOTA 0 /* element used for user quotas */ #define GRPQUOTA 1 /* element used for group quotas */ /* * Definitions for the default names of the quotas files. */ #define INITQFNAMES { \ "user", /* USRQUOTA */ \ "group", /* GRPQUOTA */ \ "undefined", \ }; #define QUOTAFILENAME "quota" #define QUOTAGROUP "staff" #define NR_DQHASH 43 /* Just an arbitrary number any suggestions ? */ #define NR_DQUOTS 256 /* Number of quotas active at one time */ /* * Command definitions for the 'quotactl' system call. * The commands are broken into a main command defined below * and a subcommand that is used to convey the type of * quota that is being manipulated (see above). */ #define SUBCMDMASK 0x00ff #define SUBCMDSHIFT 8 #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) #define Q_QUOTAON 0x0100 /* enable quotas */ #define Q_QUOTAOFF 0x0200 /* disable quotas */ #define Q_GETQUOTA 0x0300 /* get limits and usage */ #define Q_SETQUOTA 0x0400 /* set limits and usage */ #define Q_SETUSE 0x0500 /* set usage */ #define Q_SYNC 0x0600 /* sync disk copy of a filesystems quotas */ #define Q_SETQLIM 0x0700 /* set limits */ #define Q_GETSTATS 0x0800 /* get collected stats */ #define Q_RSQUASH 0x1000 /* set root_squash option */ /* * The following structure defines the format of the disk quota file * (as it appears on disk) - the file is an array of these structures * indexed by user or group number. */ struct dqblk { uint32_t dqb_bhardlimit; /* absolute limit on disk blks alloc */ uint32_t dqb_bsoftlimit; /* preferred limit on disk blks */ uint32_t dqb_curblocks; /* current block count */ uint32_t dqb_ihardlimit; /* maximum # allocated inodes */ uint32_t dqb_isoftlimit; /* preferred inode limit */ uint32_t dqb_curinodes; /* current # allocated inodes */ time_t dqb_btime; /* time limit for excessive disk use */ time_t dqb_itime; /* time limit for excessive files */ }; /* * Shorthand notation. */ #define dq_bhardlimit dq_dqb.dqb_bhardlimit #define dq_bsoftlimit dq_dqb.dqb_bsoftlimit #define dq_curblocks dq_dqb.dqb_curblocks #define dq_ihardlimit dq_dqb.dqb_ihardlimit #define dq_isoftlimit dq_dqb.dqb_isoftlimit #define dq_curinodes dq_dqb.dqb_curinodes #define dq_btime dq_dqb.dqb_btime #define dq_itime dq_dqb.dqb_itime #define dqoff(UID) ((loff_t)((UID) * sizeof (struct dqblk))) struct dqstats { uint32_t lookups; uint32_t drops; uint32_t reads; uint32_t writes; uint32_t cache_hits; uint32_t pages_allocated; uint32_t allocated_dquots; uint32_t free_dquots; uint32_t syncs; }; __BEGIN_DECLS extern int quotactl (int __cmd, const char *__special, int __id, void* __addr) __THROW; __END_DECLS #endif /* sys/quota.h */ dietlibc-0.33~cvs20120325/include/sys/reboot.h010064400000000000000000000014541173363226500156160ustar00#ifndef _SYS_REBOOT_H #define _SYS_REBOOT_H #include __BEGIN_DECLS #define LINUX_REBOOT_MAGIC1 0xfee1dead #define LINUX_REBOOT_MAGIC2 672274793 #define LINUX_REBOOT_MAGIC2A 85072278 #define LINUX_REBOOT_MAGIC2B 369367448 #define LINUX_REBOOT_CMD_RESTART 0x01234567 #define LINUX_REBOOT_CMD_HALT 0xCDEF0123 #define LINUX_REBOOT_CMD_CAD_ON 0x89ABCDEF #define LINUX_REBOOT_CMD_CAD_OFF 0x00000000 #define LINUX_REBOOT_CMD_POWER_OFF 0x4321FEDC #define LINUX_REBOOT_CMD_RESTART2 0xA1B2C3D4 /* Reboot or halt the system. */ int reboot (int flag); /* the glibc people changed their macro names :-/ */ #define RB_AUTOBOOT 0x01234567 #define RB_HALT_SYSTEM 0xcdef0123 #define RB_ENABLE_CAD 0x89abcdef #define RB_DISABLE_CAD 0 #define RB_POWER_OFF 0x4321fedc __END_DECLS #endif /* _SYS_REBOOT_H */ dietlibc-0.33~cvs20120325/include/sys/resource.h010064400000000000000000000065511173363226500161560ustar00#ifndef _SYS_RESOURCE_H #define _SYS_RESOURCE_H #include #include __BEGIN_DECLS #define RUSAGE_SELF 0 #define RUSAGE_CHILDREN (-1) #define RUSAGE_BOTH (-2) /* sys_wait4() uses this */ struct rusage { struct timeval ru_utime; /* user time used */ struct timeval ru_stime; /* system time used */ long ru_maxrss; /* maximum resident set size */ long ru_ixrss; /* integral shared memory size */ long ru_idrss; /* integral unshared data size */ long ru_isrss; /* integral unshared stack size */ long ru_minflt; /* page reclaims */ long ru_majflt; /* page faults */ long ru_nswap; /* swaps */ long ru_inblock; /* block input operations */ long ru_oublock; /* block output operations */ long ru_msgsnd; /* messages sent */ long ru_msgrcv; /* messages received */ long ru_nsignals; /* signals received */ long ru_nvcsw; /* voluntary context switches */ long ru_nivcsw; /* involuntary " */ }; struct rlimit { unsigned long rlim_cur; unsigned long rlim_max; }; #define PRIO_MIN (-20) #define PRIO_MAX 20 #define PRIO_PROCESS 0 #define PRIO_PGRP 1 #define PRIO_USER 2 #define RLIMIT_CPU 0 /* CPU time in ms */ #define RLIMIT_FSIZE 1 /* Maximum filesize */ #define RLIMIT_DATA 2 /* max data size */ #define RLIMIT_STACK 3 /* max stack size */ #define RLIMIT_CORE 4 /* max core file size */ #if defined(__alpha__) #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NPROC 8 /* max number of processes */ #define RLIMIT_NOFILE 6 /* max number of open files */ #define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ #define RLIMIT_AS 7 /* address space limit */ #elif defined(__mips__) #define RLIMIT_RSS 7 /* max resident set size */ #define RLIMIT_NPROC 8 /* max number of processes */ #define RLIMIT_NOFILE 5 /* max number of open files */ #define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ #define RLIMIT_AS 6 /* address space limit */ #elif defined(__sparc__) #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NPROC 7 /* max number of processes */ #define RLIMIT_NOFILE 6 /* max number of open files */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #else #define RLIMIT_RSS 5 /* max resident set size */ #define RLIMIT_NPROC 6 /* max number of processes */ #define RLIMIT_NOFILE 7 /* max number of open files */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ #define RLIMIT_AS 9 /* address space limit */ #endif #define RLIMIT_LOCKS 10 /* maximum file locks held */ #define RLIMIT_SIGPENDING 11 /* max number of pending signals */ #define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ #define RLIMIT_NICE 13 /* max nice prio allowed to raise to 0-39 for nice level 19 .. -20 */ #define RLIMIT_RTPRIO 14 /* maximum realtime priority */ #define RLIMIT_RTTIME 15 /* timeout for RT tasks in us */ #define RLIM_NLIMITS 16 #if defined(__alpha__) || defined(__mips__) || defined(__sparc__) #define RLIM_INFINITY ((long)(~0UL>>1)) #else #define RLIM_INFINITY (~0UL) #endif int getpriority(int which, int who) __THROW; int setpriority(int which, int who, int prio) __THROW; int getrlimit (int resource, struct rlimit *rlim); int getrusage (int who, struct rusage *usage); int setrlimit (int resource, const struct rlimit *rlim); typedef unsigned long rlim_t; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/s390-ioctl.h010064400000000000000000000112731173363226500161320ustar00 /* ioctl command encoding: 32 bits total, command in lower 16 bits, * size of the parameter structure in the lower 14 bits of the * upper 16 bits. * Encoding the size of the parameter structure in the ioctl request * is useful for catching programs compiled with old versions * and to avoid overwriting user space outside the user buffer area. * The highest 2 bits are reserved for indicating the ``access mode''. * NOTE: This limits the max parameter size to 16kB -1 ! */ /* * The following is for compatibility across the various Linux * platforms. The i386 ioctl numbering scheme doesn't really enforce * a type field. De facto, however, the top 8 bits of the lower 16 * bits are indeed used as a type field, so we might just as well make * this explicit here. Please be sure to use the decoding macros * below from now on. */ #define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 14 #define _IOC_DIRBITS 2 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT+_IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT+_IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT+_IOC_SIZEBITS) /* * Direction bits. */ #define _IOC_NONE 0U #define _IOC_WRITE 1U #define _IOC_READ 2U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) /* used to create numbers */ #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* used to decode ioctl numbers.. */ #define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & _IOC_SIZEMASK) /* ...and for the drivers/sound files... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_SIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) /* 0x54 is just a magic number to make these relatively unique ('T') */ #define TCGETS 0x5401 #define TCSETS 0x5402 #define TCSETSW 0x5403 #define TCSETSF 0x5404 #define TCGETA 0x5405 #define TCSETA 0x5406 #define TCSETAW 0x5407 #define TCSETAF 0x5408 #define TCSBRK 0x5409 #define TCXONC 0x540A #define TCFLSH 0x540B #define TIOCEXCL 0x540C #define TIOCNXCL 0x540D #define TIOCSCTTY 0x540E #define TIOCGPGRP 0x540F #define TIOCSPGRP 0x5410 #define TIOCOUTQ 0x5411 #define TIOCSTI 0x5412 #define TIOCGWINSZ 0x5413 #define TIOCSWINSZ 0x5414 #define TIOCMGET 0x5415 #define TIOCMBIS 0x5416 #define TIOCMBIC 0x5417 #define TIOCMSET 0x5418 #define TIOCGSOFTCAR 0x5419 #define TIOCSSOFTCAR 0x541A #define FIONREAD 0x541B #define TIOCINQ FIONREAD #define TIOCLINUX 0x541C #define TIOCCONS 0x541D #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TIOCPKT 0x5420 #define FIONBIO 0x5421 #define TIOCNOTTY 0x5422 #define TIOCSETD 0x5423 #define TIOCGETD 0x5424 #define TCSBRKP 0x5425 /* Needed for POSIX tcsendbreak() */ #define TIOCTTYGSTRUCT 0x5426 /* For debugging only */ #define TIOCSBRK 0x5427 /* BSD compatibility */ #define TIOCCBRK 0x5428 /* BSD compatibility */ #define TIOCGSID 0x5429 /* Return the session ID of FD */ #define TIOCGPTN _IOR('T',0x30, unsigned int) /* Get Pty Number (of pty-mux device) */ #define TIOCSPTLCK _IOW('T',0x31, int) /* Lock/unlock Pty */ #define FIONCLEX 0x5450 /* these numbers need to be adjusted. */ #define FIOCLEX 0x5451 #define FIOASYNC 0x5452 #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* wait for a change on serial input line(s) */ #define TIOCGICOUNT 0x545D /* read serial port inline interrupt counts */ #define FIOQSIZE 0x545E /* Used for packet mode */ #define TIOCPKT_DATA 0 #define TIOCPKT_FLUSHREAD 1 #define TIOCPKT_FLUSHWRITE 2 #define TIOCPKT_STOP 4 #define TIOCPKT_START 8 #define TIOCPKT_NOSTOP 16 #define TIOCPKT_DOSTOP 32 #define TIOCSER_TEMT 0x01 /* Transmitter physically empty */ dietlibc-0.33~cvs20120325/include/sys/select.h010064400000000000000000000017001173363226500155750ustar00#ifndef _SYS_SELECT_H #define _SYS_SELECT_H #include #include __BEGIN_DECLS typedef long int fd_mask; #define NFDBITS (8 * sizeof(unsigned long)) #define FD_SETSIZE 1024 #define __FDSET_LONGS (FD_SETSIZE/NFDBITS) #define __FDELT(d) ((d) / NFDBITS) #define __FDMASK(d) (1UL << ((d) % NFDBITS)) typedef struct { unsigned long fds_bits [__FDSET_LONGS]; } fd_set; #define FD_SET(d, set) ((set)->fds_bits[__FDELT(d)] |= __FDMASK(d)) #define FD_CLR(d, set) ((set)->fds_bits[__FDELT(d)] &= ~__FDMASK(d)) #define FD_ISSET(d, set) (((set)->fds_bits[__FDELT(d)] & __FDMASK(d)) != 0) #define FD_ZERO(set) \ ((void) memset ((void*) (set), 0, sizeof (fd_set))) int select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout) __THROW; int pselect(int n, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const struct timespec *timeout, const sigset_t *sigmask) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/sem.h010064400000000000000000000050431173363226500151060ustar00#ifndef _SYS_SEM_H #define _SYS_SEM_H #include __BEGIN_DECLS /* semop flags */ #define SEM_UNDO 0x1000 /* undo the operation on exit */ /* semctl Command Definitions. */ #define GETPID 11 /* get sempid */ #define GETVAL 12 /* get semval */ #define GETALL 13 /* get all semval's */ #define GETNCNT 14 /* get semncnt */ #define GETZCNT 15 /* get semzcnt */ #define SETVAL 16 /* set semval */ #define SETALL 17 /* set all semval's */ /* ipcs ctl cmds */ #define SEM_STAT 18 #define SEM_INFO 19 struct semid_ds { struct ipc_perm sem_perm; /* permissions .. see ipc.h */ time_t sem_otime; /* last semop time */ time_t sem_ctime; /* last change time */ struct sem *sem_base; /* ptr to first semaphore in array */ struct sem_queue *sem_pending; /* pending operations to be processed */ struct sem_queue **sem_pending_last; /* last pending operation */ struct sem_undo *undo; /* undo requests on this array */ uint16_t sem_nsems; /* no. of semaphores in array */ }; /* semop system calls takes an array of these. */ struct sembuf { uint16_t sem_num; /* semaphore index in array */ int16_t sem_op; /* semaphore operation */ int16_t sem_flg; /* operation flags */ }; /* please complain to the glibc goons for the following misbehaviour */ #if 0 /* arg for semctl system calls. */ union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ unsigned short *array; /* array for GETALL & SETALL */ struct seminfo *__buf; /* buffer for IPC_INFO */ void *__pad; }; #endif #define _SEM_SEMUN_UNDEFINED struct seminfo { int32_t semmap; int32_t semmni; int32_t semmns; int32_t semmnu; int32_t semmsl; int32_t semopm; int32_t semume; int32_t semusz; int32_t semvmx; int32_t semaem; }; #define SEMMNI 128 /* <= IPCMNI max # of semaphore identifiers */ #define SEMMSL 250 /* <= 8 000 max num of semaphores per id */ #define SEMMNS (SEMMNI*SEMMSL) /* <= INT_MAX max # of semaphores in system */ #define SEMOPM 32 /* <= 1 000 max num of ops per semop call */ #define SEMVMX 32767 /* <= 32767 semaphore maximum value */ extern int semget( key_t key, int nsems, int semflg) __THROW; /* The prototype really is: * extern int semctl(int semid, int semnum, int cmd, union semun arg) __THROW; * glibc bug compatibility forces us to write it like this: */ extern int semctl(int semid, int semnum, int cmd, ...) __THROW; extern int semop(int semid, struct sembuf *sops, unsigned nsops) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/sendfile.h010064400000000000000000000010231173363226500161050ustar00#ifndef _SYS_SENDFILE_H #define _SYS_SENDFILE_H #include #include #include __BEGIN_DECLS extern ssize_t sendfile (int out_fd, int in_fd, off_t* offset, size_t count) __THROW; #ifndef __NO_STAT64 extern ssize_t sendfile64 (int out_fd, int in_fd, loff_t* offset, size_t count) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define sendfile(outfd,infd,offset,count) sendfile64(outfd,infd,offset,count) #endif #endif __END_DECLS #endif /* sys/sendfile.h */ dietlibc-0.33~cvs20120325/include/sys/shm.h010064400000000000000000000047161173363226500151170ustar00#ifndef _SYS_SHM_H #define _SYS_SHM_H #include __BEGIN_DECLS #define SHMMAX 0x2000000 /* max shared seg size (bytes) */ #define SHMMIN 1 /* min shared seg size (bytes) */ #define SHMMNI 4096 /* max num of segs system wide */ #define SHMALL (SHMMAX/PAGE_SIZE*(SHMMNI/16)) /* max shm system wide (pages) */ #define SHMSEG SHMMNI /* max shared segs per process */ struct shmid_ds { struct ipc_perm shm_perm; /* operation perms */ int32_t shm_segsz; /* size of segment (bytes) */ time_t shm_atime; /* last attach time */ time_t shm_dtime; /* last detach time */ time_t shm_ctime; /* last change time */ pid_t shm_cpid; /* pid of creator */ pid_t shm_lpid; /* pid of last operator */ uint16_t shm_nattch; /* no. of current attaches */ uint16_t shm_unused; /* compatibility */ void *shm_unused2; /* ditto - used by DIPC */ void *shm_unused3; /* unused */ }; /* permission flag for shmget */ #define SHM_R 0400 /* or S_IRUGO from */ #define SHM_W 0200 /* or S_IWUGO from */ /* mode for attach */ #define SHM_RDONLY 010000 /* read-only access */ #define SHM_RND 020000 /* round attach address to SHMLBA boundary */ #define SHM_REMAP 040000 /* take-over region on attach */ /* super user shmctl commands */ #define SHM_LOCK 11 #define SHM_UNLOCK 12 /* ipcs ctl commands */ #define SHM_STAT 13 #define SHM_INFO 14 /* Obsolete, used only for backwards compatibility */ struct shminfo { int32_t shmmax; int32_t shmmin; int32_t shmmni; int32_t shmseg; int32_t shmall; }; struct shm_info { int32_t used_ids; unsigned long shm_tot; /* total allocated shm */ unsigned long shm_rss; /* total resident shm */ unsigned long shm_swp; /* total swapped shm */ unsigned long swap_attempts; unsigned long swap_successes; }; #if defined(__i386__) || defined(__mips__) || defined(__arm__) || defined(__powerpc__) || defined (__powerpc64__) || defined(__s390__) || defined(__hppa__) || defined(__x86_64__) || defined(__ia64__) #define PAGE_SIZE 4096UL #define PAGE_SHIFT 12 #elif defined(__alpha__) || defined(__sparc__) /* sun4* has 4k except sun4 architecture, sparc64 has 8k */ #define PAGE_SIZE 8192UL #define PAGE_SHIFT 13 #endif extern int shmget(key_t key, int size, int shmflg) __THROW; extern void *shmat(int shmid, const void *shmaddr, int shmflg) __THROW; extern int shmdt (const void *shmaddr) __THROW; extern int shmctl(int shmid, int cmd, struct shmid_ds *buf) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/signal.h010064400000000000000000000000241173363226500155710ustar00#include dietlibc-0.33~cvs20120325/include/sys/signalfd.h010064400000000000000000000011161173363226500161060ustar00#ifndef _SYS_SIGNALFD_H #define _SYS_SIGNALFD_H #include struct signalfd_siginfo { uint32_t ssi_signo; int32_t ssi_errno; int32_t ssi_code; uint32_t ssi_pid; uint32_t ssi_uid; int32_t ssi_fd; uint32_t ssi_tid; uint32_t ssi_band; uint32_t ssi_overrun; uint32_t ssi_trapno; int32_t ssi_status; int32_t ssi_int; uint64_t ssi_ptr; uint64_t ssi_utime; uint64_t ssi_stime; uint64_t ssi_addr; uint8_t __pad[48]; }; __BEGIN_DECLS extern int signalfd (int __fd, const sigset_t *__mask, int __flags) __nonnull ((2)) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/socket.h010064400000000000000000000405451173363226500156200ustar00#ifndef _SYS_SOCKET_H #define _SYS_SOCKET_H #include #include __BEGIN_DECLS /* For setsockoptions(2) */ #if defined(__alpha__) || defined(__mips__) #define SOL_SOCKET 0xffff #define SO_DEBUG 0x0001 #define SO_REUSEADDR 0x0004 #define SO_TYPE 0x1008 #define SO_ERROR 0x1007 #define SO_DONTROUTE 0x0010 #define SO_BROADCAST 0x0020 #define SO_SNDBUF 0x1001 #define SO_RCVBUF 0x1002 #define SO_KEEPALIVE 0x0008 #define SO_OOBINLINE 0x0100 #define SO_NO_CHECK 11 #define SO_PRIORITY 12 #define SO_LINGER 0x0080 #define SO_BSDCOMPAT 14 /* To add :#define SO_REUSEPORT 15 */ #define SO_PASSCRED 17 #define SO_PEERCRED 18 #define SO_RCVLOWAT 0x1004 #define SO_SNDLOWAT 0x1003 #define SO_RCVTIMEO 0x1006 #define SO_SNDTIMEO 0x1005 #define SO_ACCEPTCONN 0x1009 #define SO_STYLE SO_TYPE /* Synonym */ #elif defined(__hppa__) #define SOL_SOCKET 0xffff #define SO_DEBUG 0x0001 #define SO_REUSEADDR 0x0004 #define SO_KEEPALIVE 0x0008 #define SO_DONTROUTE 0x0010 #define SO_BROADCAST 0x0020 #define SO_LINGER 0x0080 #define SO_OOBINLINE 0x0100 /* To add :#define SO_REUSEPORT 0x0200 */ #define SO_SNDBUF 0x1001 #define SO_RCVBUF 0x1002 #define SO_SNDLOWAT 0x1003 #define SO_RCVLOWAT 0x1004 #define SO_SNDTIMEO 0x1005 #define SO_RCVTIMEO 0x1006 #define SO_ERROR 0x1007 #define SO_TYPE 0x1008 #define SO_PEERNAME 0x2000 #define SO_NO_CHECK 0x400b #define SO_PRIORITY 0x400c #define SO_BSDCOMPAT 0x400e #define SO_PASSCRED 0x4010 #define SO_PEERCRED 0x4011 #define SO_TIMESTAMP 0x4012 #define SCM_TIMESTAMP SO_TIMESTAMP /* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 0x4016 #define SO_SECURITY_ENCRYPTION_TRANSPORT 0x4017 #define SO_SECURITY_ENCRYPTION_NETWORK 0x4018 #define SO_BINDTODEVICE 0x4019 /* Socket filtering */ #define SO_ATTACH_FILTER 0x401a #define SO_DETACH_FILTER 0x401b #define SO_ACCEPTCONN 0x401c #elif defined(__sparc__) #define SOL_SOCKET 0xffff #define SO_DEBUG 0x0001 #define SO_PASSCRED 0x0002 #define SO_REUSEADDR 0x0004 #define SO_KEEPALIVE 0x0008 #define SO_DONTROUTE 0x0010 #define SO_BROADCAST 0x0020 #define SO_PEERCRED 0x0040 #define SO_LINGER 0x0080 #define SO_OOBINLINE 0x0100 /* To add :#define SO_REUSEPORT 0x0200 */ #define SO_BSDCOMPAT 0x0400 #define SO_RCVLOWAT 0x0800 #define SO_SNDLOWAT 0x1000 #define SO_RCVTIMEO 0x2000 #define SO_SNDTIMEO 0x4000 #define SO_ACCEPTCONN 0x8000 #define SO_DONTLINGER (~SO_LINGER) /* Older SunOS compat. hack */ #define SO_SNDBUF 0x1001 #define SO_RCVBUF 0x1002 #define SO_ERROR 0x1007 #define SO_TYPE 0x1008 #define SO_ATTACH_FILTER 0x001a #define SO_DETACH_FILTER 0x001b #define SO_PEERNAME 0x001c #define SO_TIMESTAMP 0x001d #define SCM_TIMESTAMP SO_TIMESTAMP /* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 0x5001 #define SO_SECURITY_ENCRYPTION_TRANSPORT 0x5002 #define SO_SECURITY_ENCRYPTION_NETWORK 0x5004 #else #define SOL_SOCKET 1 #define SO_DEBUG 1 #define SO_REUSEADDR 2 #define SO_TYPE 3 #define SO_ERROR 4 #define SO_DONTROUTE 5 #define SO_BROADCAST 6 #define SO_SNDBUF 7 #define SO_RCVBUF 8 #define SO_KEEPALIVE 9 #define SO_OOBINLINE 10 #define SO_NO_CHECK 11 #define SO_PRIORITY 12 #define SO_LINGER 13 #define SO_BSDCOMPAT 14 /* To add :#define SO_REUSEPORT 15 */ #define SO_PASSCRED 16 #define SO_PEERCRED 17 #define SO_RCVLOWAT 18 #define SO_SNDLOWAT 19 #define SO_RCVTIMEO 20 #define SO_SNDTIMEO 21 #define SO_ACCEPTCONN 30 #endif #if !defined(__hppa__) && !defined(__sparc__) /* Security levels - as per NRL IPv6 - don't actually do anything */ #define SO_SECURITY_AUTHENTICATION 22 #define SO_SECURITY_ENCRYPTION_TRANSPORT 23 #define SO_SECURITY_ENCRYPTION_NETWORK 24 #define SO_BINDTODEVICE 25 /* Socket filtering */ #define SO_ATTACH_FILTER 26 #define SO_DETACH_FILTER 27 #define SO_PEERNAME 28 #define SO_TIMESTAMP 29 #define SCM_TIMESTAMP SO_TIMESTAMP #endif /* Socket types. */ #ifdef __mips__ #define SOCK_DGRAM 1 /* datagram (conn.less) socket */ #define SOCK_STREAM 2 /* stream (connection) socket */ #else #define SOCK_STREAM 1 /* stream (connection) socket */ #define SOCK_DGRAM 2 /* datagram (conn.less) socket */ #endif #define SOCK_RAW 3 /* raw socket */ #define SOCK_RDM 4 /* reliably-delivered message */ #define SOCK_SEQPACKET 5 /* sequential packet socket */ #define SOCK_PACKET 10 /* linux specific way of */ /* getting packets at the dev */ /* level. For writing rarp and */ /* other similar things on the */ /* user level. */ struct sockaddr { sa_family_t sa_family; char sa_data[14]; }; struct linger { int32_t l_onoff; int32_t l_linger; }; struct iovec { void* iov_base; /* BSD uses caddr_t (1003.1g requires void *) */ size_t iov_len; /* Must be size_t (1003.1g) */ }; struct msghdr { void* msg_name; /* Socket name */ socklen_t msg_namelen; /* Length of name */ struct iovec* msg_iov; /* Data blocks */ size_t msg_iovlen; /* Number of blocks */ void* msg_control; /* Per protocol magic (eg BSD file descriptor passing) */ size_t msg_controllen; /* Length of cmsg list */ uint32_t msg_flags; }; struct cmsghdr { size_t cmsg_len; /* data byte count, including hdr */ int32_t cmsg_level; /* originating protocol */ int32_t cmsg_type; /* protocol-specific type */ }; #define UIO_FASTIOV 8 #define UIO_MAXIOV 1024 /* "Socket"-level control message types: */ #define SCM_RIGHTS 0x01 /* rw: access rights (array of int) */ #define SCM_CREDENTIALS 0x02 /* rw: struct ucred */ #define SCM_CONNECT 0x03 /* rw: struct scm_connect */ struct ucred { pid_t pid; uid_t uid; gid_t gid; }; /* Supported address families. */ #define AF_UNSPEC 0 #define AF_UNIX 1 /* Unix domain sockets */ #define AF_LOCAL 1 /* POSIX name for AF_UNIX */ #define AF_INET 2 /* Internet IP Protocol */ #define AF_AX25 3 /* Amateur Radio AX.25 */ #define AF_IPX 4 /* Novell IPX */ #define AF_APPLETALK 5 /* AppleTalk DDP */ #define AF_NETROM 6 /* Amateur Radio NET/ROM */ #define AF_BRIDGE 7 /* Multiprotocol bridge */ #define AF_ATMPVC 8 /* ATM PVCs */ #define AF_X25 9 /* Reserved for X.25 project */ #define AF_INET6 10 /* IP version 6 */ #define AF_ROSE 11 /* Amateur Radio X.25 PLP */ #define AF_DECnet 12 /* Reserved for DECnet project */ #define AF_NETBEUI 13 /* Reserved for 802.2LLC project*/ #define AF_SECURITY 14 /* Security callback pseudo AF */ #define AF_KEY 15 /* PF_KEY key management API */ #define AF_NETLINK 16 #define AF_ROUTE AF_NETLINK /* Alias to emulate 4.4BSD */ #define AF_PACKET 17 /* Packet family */ #define AF_ASH 18 /* Ash */ #define AF_ECONET 19 /* Acorn Econet */ #define AF_ATMSVC 20 /* ATM SVCs */ #define AF_SNA 22 /* Linux SNA Project (nutters!) */ #define AF_IRDA 23 /* IRDA sockets */ #define AF_PPPOX 24 /* PPPoX sockets */ #define AF_WANPIPE 25 /* Wanpipe API Sockets */ #define AF_MAX 32 /* For now.. */ /* Protocol families, same as address families. */ #define PF_UNSPEC AF_UNSPEC #define PF_UNIX AF_UNIX #define PF_LOCAL AF_LOCAL #define PF_INET AF_INET #define PF_AX25 AF_AX25 #define PF_IPX AF_IPX #define PF_APPLETALK AF_APPLETALK #define PF_NETROM AF_NETROM #define PF_BRIDGE AF_BRIDGE #define PF_ATMPVC AF_ATMPVC #define PF_X25 AF_X25 #define PF_INET6 AF_INET6 #define PF_ROSE AF_ROSE #define PF_DECnet AF_DECnet #define PF_NETBEUI AF_NETBEUI #define PF_SECURITY AF_SECURITY #define PF_KEY AF_KEY #define PF_NETLINK AF_NETLINK #define PF_ROUTE AF_ROUTE #define PF_PACKET AF_PACKET #define PF_ASH AF_ASH #define PF_ECONET AF_ECONET #define PF_ATMSVC AF_ATMSVC #define PF_SNA AF_SNA #define PF_IRDA AF_IRDA #define PF_PPPOX AF_PPPOX #define PF_WANPIPE AF_WANPIPE #define PF_MAX AF_MAX /* Maximum queue length specifiable by listen. */ #define SOMAXCONN 128 /* Flags we can use with send/ and recv. Added those for 1003.1g not all are supported yet */ #define MSG_OOB 1 #define MSG_PEEK 2 #define MSG_DONTROUTE 4 #define MSG_TRYHARD 4 /* Synonym for MSG_DONTROUTE for DECnet */ #define MSG_CTRUNC 8 #define MSG_PROBE 0x10 /* Do not send. Only probe path f.e. for MTU */ #define MSG_TRUNC 0x20 #define MSG_DONTWAIT 0x40 /* Nonblocking io */ #define MSG_EOR 0x80 /* End of record */ #define MSG_WAITALL 0x100 /* Wait for a full request */ #define MSG_FIN 0x200 #define MSG_EOF MSG_FIN #define MSG_SYN 0x400 #define MSG_CONFIRM 0x800 /* Confirm path validity */ #define MSG_RST 0x1000 #define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue */ #define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE */ #define MSG_MORE 0x8000 /* Sender will send more */ /* Setsockoptions(2) level. Thanks to BSD these must match IPPROTO_xxx */ #define SOL_IP 0 /* #define SOL_ICMP 1 No-no-no! Due to Linux :-) we cannot use SOL_ICMP=1 */ #define SOL_TCP 6 #define SOL_UDP 17 #define SOL_IPV6 41 #define SOL_ICMPV6 58 #define SOL_RAW 255 #define SOL_IPX 256 #define SOL_AX25 257 #define SOL_ATALK 258 #define SOL_NETROM 259 #define SOL_ROSE 260 #define SOL_DECNET 261 #define SOL_X25 262 #define SOL_PACKET 263 #define SOL_ATM 264 /* ATM layer (cell level) */ #define SOL_AAL 265 /* ATM Adaption Layer (packet level) */ #define SOL_IRDA 266 /* IPX options */ #define IPX_TYPE 1 #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) ) #define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg)) #define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg)) static inline struct cmsghdr* __cmsg_nxthdr(void *__ctl, size_t __size, struct cmsghdr *__cmsg) { struct cmsghdr * __ptr; __ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len)); if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size) return (struct cmsghdr *)0; return __ptr; } static inline struct cmsghdr* cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg) { return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg); } #define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)))) #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len)) #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) #define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ? \ (struct cmsghdr *)(ctl) : \ (struct cmsghdr *)NULL) #define CMSG_FIRSTHDR(msg) __CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen) struct sockaddr_storage { sa_family_t ss_family; uint32_t __ss_align; char __ss_padding[(128 - (2 * sizeof (uint32_t ))) ]; }; #ifndef SOCK_DGRAM /* the Linux kernel headers suck really badly on non-x86 */ #define SOCK_STREAM 1 /* stream (connection) socket */ #define SOCK_DGRAM 2 /* datagram (conn.less) socket */ #define SOCK_RAW 3 /* raw socket */ #define SOCK_RDM 4 /* reliably-delivered message */ #define SOCK_SEQPACKET 5 /* sequential packet socket */ #define SOCK_PACKET 10 /* linux specific way of */ #endif int socket(int domain, int type, int protocol) __THROW; int accept(int s, struct sockaddr *addr, socklen_t *addrlen) __THROW; int connect(int sockfd, const struct sockaddr *serv_addr, socklen_t addrlen) __THROW; int bind(int sockfd, const struct sockaddr *my_addr, socklen_t addrlen) __THROW; int recv(int s, void *buf, size_t len, int flags) __THROW; int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) __THROW; int recvmsg(int s, struct msghdr *msg, int flags) __THROW; int send(int s, const void *msg, size_t len, int flags) __THROW; int sendto(int s, const void *msg, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) __THROW; int sendmsg(int s, const struct msghdr *msg, int flags) __THROW; int getpeername(int s, struct sockaddr *name, socklen_t *namelen) __THROW; int getsockname(int s , struct sockaddr * name , socklen_t * namelen) __THROW; int getsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) __THROW; int setsockopt(int s, int level, int optname, const void *optval, socklen_t optlen) __THROW; int listen(int s, int backlog) __THROW; #define SHUT_RD 0 #define SHUT_WR 1 #define SHUT_RDWR 2 int shutdown(int s, int how) __THROW; int socketpair(int d, int type, int protocol, int sv[2]); /* currently not supported: */ #define NI_NOFQDN 1 #define NI_NUMERICHOST 2 #define NI_NAMEREQD 4 #define NI_NUMERICSERV 8 #define NI_DGRAM 16 struct addrinfo { int ai_flags; int ai_family; int ai_socktype; int ai_protocol; size_t ai_addrlen; struct sockaddr *ai_addr; char *ai_canonname; struct addrinfo *ai_next; }; int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t hostlen, char *serv, size_t servlen, int flags) __THROW; int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) __THROW; void freeaddrinfo(struct addrinfo *res) __THROW; const char *gai_strerror(int errcode) __THROW; #define EAI_FAMILY -1 #define EAI_SOCKTYPE -2 #define EAI_BADFLAGS -3 #define EAI_NONAME -4 #define EAI_SERVICE -5 #define EAI_ADDRFAMILY -6 #define EAI_NODATA -7 #define EAI_MEMORY -8 #define EAI_FAIL -9 #define EAI_AGAIN -10 #define EAI_SYSTEM -11 #define AI_NUMERICHOST 1 #define AI_CANONNAME 2 #define AI_PASSIVE 4 /* Linux-specific socket ioctls */ #define SIOCINQ FIONREAD #define SIOCOUTQ TIOCOUTQ /* Routing table calls. */ #define SIOCADDRT 0x890B /* add routing table entry */ #define SIOCDELRT 0x890C /* delete routing table entry */ #define SIOCRTMSG 0x890D /* call to routing system */ /* Socket configuration controls. */ #define SIOCGIFNAME 0x8910 /* get iface name */ #define SIOCSIFLINK 0x8911 /* set iface channel */ #define SIOCGIFCONF 0x8912 /* get iface list */ #define SIOCGIFFLAGS 0x8913 /* get flags */ #define SIOCSIFFLAGS 0x8914 /* set flags */ #define SIOCGIFADDR 0x8915 /* get PA address */ #define SIOCSIFADDR 0x8916 /* set PA address */ #define SIOCGIFDSTADDR 0x8917 /* get remote PA address */ #define SIOCSIFDSTADDR 0x8918 /* set remote PA address */ #define SIOCGIFBRDADDR 0x8919 /* get broadcast PA address */ #define SIOCSIFBRDADDR 0x891a /* set broadcast PA address */ #define SIOCGIFNETMASK 0x891b /* get network PA mask */ #define SIOCSIFNETMASK 0x891c /* set network PA mask */ #define SIOCGIFMETRIC 0x891d /* get metric */ #define SIOCSIFMETRIC 0x891e /* set metric */ #define SIOCGIFMEM 0x891f /* get memory address (BSD) */ #define SIOCSIFMEM 0x8920 /* set memory address (BSD) */ #define SIOCGIFMTU 0x8921 /* get MTU size */ #define SIOCSIFMTU 0x8922 /* set MTU size */ #define SIOCSIFNAME 0x8923 /* set interface name */ #define SIOCSIFHWADDR 0x8924 /* set hardware address */ #define SIOCGIFENCAP 0x8925 /* get/set encapsulations */ #define SIOCSIFENCAP 0x8926 #define SIOCGIFHWADDR 0x8927 /* Get hardware address */ #define SIOCGIFSLAVE 0x8929 /* Driver slaving support */ #define SIOCSIFSLAVE 0x8930 #define SIOCADDMULTI 0x8931 /* Multicast address lists */ #define SIOCDELMULTI 0x8932 #define SIOCGIFINDEX 0x8933 /* name -> if_index mapping */ #define SIOGIFINDEX SIOCGIFINDEX /* misprint compatibility :-) */ #define SIOCSIFPFLAGS 0x8934 /* set/get extended flags set */ #define SIOCGIFPFLAGS 0x8935 #define SIOCDIFADDR 0x8936 /* delete PA address */ #define SIOCSIFHWBROADCAST 0x8937 /* set hardware broadcast addr */ #define SIOCGIFCOUNT 0x8938 /* get number of devices */ #define SIOCGIFBR 0x8940 /* Bridging support */ #define SIOCSIFBR 0x8941 /* Set bridging options */ #define SIOCGIFTXQLEN 0x8942 /* Get the tx queue length */ #define SIOCSIFTXQLEN 0x8943 /* Set the tx queue length */ #define SIOCGIFDIVERT 0x8944 /* Frame diversion support */ #define SIOCSIFDIVERT 0x8945 /* Set frame diversion options */ #define SIOCETHTOOL 0x8946 /* Ethtool interface */ /* ARP cache control calls. */ /* 0x8950 - 0x8952 * obsolete calls, don't re-use */ #define SIOCDARP 0x8953 /* delete ARP table entry */ #define SIOCGARP 0x8954 /* get ARP table entry */ #define SIOCSARP 0x8955 /* set ARP table entry */ /* RARP cache control calls. */ #define SIOCDRARP 0x8960 /* delete RARP table entry */ #define SIOCGRARP 0x8961 /* get RARP table entry */ #define SIOCSRARP 0x8962 /* set RARP table entry */ /* Driver configuration calls */ #define SIOCGIFMAP 0x8970 /* Get device parameters */ #define SIOCSIFMAP 0x8971 /* Set device parameters */ /* DLCI configuration calls */ #define SIOCADDDLCI 0x8980 /* Create new DLCI device */ #define SIOCDELDLCI 0x8981 /* Delete DLCI device */ #define SIOCDEVPRIVATE 0x89F0 /* to 89FF */ #define _LINUX_SOCKET_H __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/soundcard.h010064400000000000000000001347141173363226500163140ustar00#ifndef _SYS_SOUNDCARD_H #define _SYS_SOUNDCARD_H /* * Copyright by Hannu Savolainen 1993-1997 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. 2. * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ /* * OSS interface version. With versions earlier than 3.6 this value is * an integer with value less than 361. In versions 3.6 and later * it's a six digit hexadecimal value. For example value * of 0x030600 represents OSS version 3.6.0. * Use ioctl(fd, OSS_GETVERSION, &int) to get the version number of * the currently active driver. */ #define SOUND_VERSION 0x030802 #define OPEN_SOUND_SYSTEM /* In Linux we need to be prepared for cross compiling */ #include __BEGIN_DECLS /* * Supported card ID numbers (Should be somewhere else?) */ #define SNDCARD_ADLIB 1 #define SNDCARD_SB 2 #define SNDCARD_PAS 3 #define SNDCARD_GUS 4 #define SNDCARD_MPU401 5 #define SNDCARD_SB16 6 #define SNDCARD_SB16MIDI 7 #define SNDCARD_UART6850 8 #define SNDCARD_GUS16 9 #define SNDCARD_MSS 10 #define SNDCARD_PSS 11 #define SNDCARD_SSCAPE 12 #define SNDCARD_PSS_MPU 13 #define SNDCARD_PSS_MSS 14 #define SNDCARD_SSCAPE_MSS 15 #define SNDCARD_TRXPRO 16 #define SNDCARD_TRXPRO_SB 17 #define SNDCARD_TRXPRO_MPU 18 #define SNDCARD_MAD16 19 #define SNDCARD_MAD16_MPU 20 #define SNDCARD_CS4232 21 #define SNDCARD_CS4232_MPU 22 #define SNDCARD_MAUI 23 #define SNDCARD_PSEUDO_MSS 24 #define SNDCARD_GUSPNP 25 #define SNDCARD_UART401 26 /* Sound card numbers 27 to N are reserved. Don't add more numbers here. */ /*********************************** * IOCTL Commands for /dev/sequencer */ #ifndef _SIOWR #if defined(_IOWR) && (defined(_AIX) || (!defined(sun) && !defined(sparc) && !defined(__sparc__) && !defined(__INCioctlh) && !defined(__Lynx__))) /* Use already defined ioctl defines if they exist (except with Sun or Sparc) */ #define SIOCPARM_MASK IOCPARM_MASK #define SIOC_VOID IOC_VOID #define SIOC_OUT IOC_OUT #define SIOC_IN IOC_IN #define SIOC_INOUT IOC_INOUT #define _SIOC_SIZE _IOC_SIZE #define _SIOC_DIR _IOC_DIR #define _SIOC_NONE _IOC_NONE #define _SIOC_READ _IOC_READ #define _SIOC_WRITE _IOC_WRITE #define _SIO _IO #define _SIOR _IOR #define _SIOW _IOW #define _SIOWR _IOWR #else /* Ioctl's have the command encoded in the lower word, * and the size of any in or out parameters in the upper * word. The high 2 bits of the upper word are used * to encode the in/out status of the parameter; for now * we restrict parameters to at most 8191 bytes. */ /* #define SIOCTYPE (0xff<<8) */ #define SIOCPARM_MASK 0x1fff /* parameters must be < 8192 bytes */ #define SIOC_VOID 0x00000000 /* no parameters */ #define SIOC_OUT 0x20000000 /* copy out parameters */ #define SIOC_IN 0x40000000 /* copy in parameters */ #define SIOC_INOUT (SIOC_IN|SIOC_OUT) /* the 0x20000000 is so we can distinguish new ioctl's from old */ #define _SIO(x,y) ((int)(SIOC_VOID|(x<<8)|y)) #define _SIOR(x,y,t) ((int)(SIOC_OUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y)) #define _SIOW(x,y,t) ((int)(SIOC_IN|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y)) /* this should be _SIORW, but stdio got there first */ #define _SIOWR(x,y,t) ((int)(SIOC_INOUT|((sizeof(t)&SIOCPARM_MASK)<<16)|(x<<8)|y)) #define _SIOC_SIZE(x) ((x>>16)&SIOCPARM_MASK) #define _SIOC_DIR(x) (x & 0xf0000000) #define _SIOC_NONE SIOC_VOID #define _SIOC_READ SIOC_OUT #define _SIOC_WRITE SIOC_IN # endif /* _IOWR */ #endif /* !_SIOWR */ #define SNDCTL_SEQ_RESET _SIO ('Q', 0) #define SNDCTL_SEQ_SYNC _SIO ('Q', 1) #define SNDCTL_SYNTH_INFO _SIOWR('Q', 2, struct synth_info) #define SNDCTL_SEQ_CTRLRATE _SIOWR('Q', 3, int) /* Set/get timer resolution (HZ) */ #define SNDCTL_SEQ_GETOUTCOUNT _SIOR ('Q', 4, int) #define SNDCTL_SEQ_GETINCOUNT _SIOR ('Q', 5, int) #define SNDCTL_SEQ_PERCMODE _SIOW ('Q', 6, int) #define SNDCTL_FM_LOAD_INSTR _SIOW ('Q', 7, struct sbi_instrument) /* Obsolete. Don't use!!!!!! */ #define SNDCTL_SEQ_TESTMIDI _SIOW ('Q', 8, int) #define SNDCTL_SEQ_RESETSAMPLES _SIOW ('Q', 9, int) #define SNDCTL_SEQ_NRSYNTHS _SIOR ('Q',10, int) #define SNDCTL_SEQ_NRMIDIS _SIOR ('Q',11, int) #define SNDCTL_MIDI_INFO _SIOWR('Q',12, struct midi_info) #define SNDCTL_SEQ_THRESHOLD _SIOW ('Q',13, int) #define SNDCTL_SYNTH_MEMAVL _SIOWR('Q',14, int) /* in=dev#, out=memsize */ #define SNDCTL_FM_4OP_ENABLE _SIOW ('Q',15, int) /* in=dev# */ #define SNDCTL_SEQ_PANIC _SIO ('Q',17) #define SNDCTL_SEQ_OUTOFBAND _SIOW ('Q',18, struct seq_event_rec) #define SNDCTL_SEQ_GETTIME _SIOR ('Q',19, int) #define SNDCTL_SYNTH_ID _SIOWR('Q',20, struct synth_info) #define SNDCTL_SYNTH_CONTROL _SIOWR('Q',21, struct synth_control) #define SNDCTL_SYNTH_REMOVESAMPLE _SIOWR('Q',22, struct remove_sample) typedef struct synth_control { int devno; /* Synthesizer # */ char data[4000]; /* Device spesific command/data record */ }synth_control; typedef struct remove_sample { int devno; /* Synthesizer # */ int bankno; /* MIDI bank # (0=General MIDI) */ int instrno; /* MIDI instrument number */ } remove_sample; typedef struct seq_event_rec { unsigned char arr[8]; } seq_event_rec; #define SNDCTL_TMR_TIMEBASE _SIOWR('T', 1, int) #define SNDCTL_TMR_START _SIO ('T', 2) #define SNDCTL_TMR_STOP _SIO ('T', 3) #define SNDCTL_TMR_CONTINUE _SIO ('T', 4) #define SNDCTL_TMR_TEMPO _SIOWR('T', 5, int) #define SNDCTL_TMR_SOURCE _SIOWR('T', 6, int) # define TMR_INTERNAL 0x00000001 # define TMR_EXTERNAL 0x00000002 # define TMR_MODE_MIDI 0x00000010 # define TMR_MODE_FSK 0x00000020 # define TMR_MODE_CLS 0x00000040 # define TMR_MODE_SMPTE 0x00000080 #define SNDCTL_TMR_METRONOME _SIOW ('T', 7, int) #define SNDCTL_TMR_SELECT _SIOW ('T', 8, int) /* * Some big endian/little endian handling macros */ #if defined(_AIX) || defined(AIX) || defined(sparc) || defined(__sparc__) || defined(HPPA) || defined(PPC) /* Big endian machines */ # define _PATCHKEY(id) (0xfd00|id) # define AFMT_S16_NE AFMT_S16_BE #else # define _PATCHKEY(id) ((id<<8)|0xfd) # define AFMT_S16_NE AFMT_S16_LE #endif /* * Sample loading mechanism for internal synthesizers (/dev/sequencer) * The following patch_info structure has been designed to support * Gravis UltraSound. It tries to be universal format for uploading * sample based patches but is probably too limited. * * (PBD) As Hannu guessed, the GUS structure is too limited for * the WaveFront, but this is the right place for a constant definition. */ struct patch_info { unsigned short key; /* Use WAVE_PATCH here */ #define WAVE_PATCH _PATCHKEY(0x04) #define GUS_PATCH WAVE_PATCH #define WAVEFRONT_PATCH _PATCHKEY(0x06) short device_no; /* Synthesizer number */ short instr_no; /* Midi pgm# */ unsigned int mode; /* * The least significant byte has the same format than the GUS .PAT * files */ #define WAVE_16_BITS 0x01 /* bit 0 = 8 or 16 bit wave data. */ #define WAVE_UNSIGNED 0x02 /* bit 1 = Signed - Unsigned data. */ #define WAVE_LOOPING 0x04 /* bit 2 = looping enabled-1. */ #define WAVE_BIDIR_LOOP 0x08 /* bit 3 = Set is bidirectional looping. */ #define WAVE_LOOP_BACK 0x10 /* bit 4 = Set is looping backward. */ #define WAVE_SUSTAIN_ON 0x20 /* bit 5 = Turn sustaining on. (Env. pts. 3)*/ #define WAVE_ENVELOPES 0x40 /* bit 6 = Enable envelopes - 1 */ #define WAVE_FAST_RELEASE 0x80 /* bit 7 = Shut off immediately after note off */ /* (use the env_rate/env_offs fields). */ /* Linux specific bits */ #define WAVE_VIBRATO 0x00010000 /* The vibrato info is valid */ #define WAVE_TREMOLO 0x00020000 /* The tremolo info is valid */ #define WAVE_SCALE 0x00040000 /* The scaling info is valid */ #define WAVE_FRACTIONS 0x00080000 /* Fraction information is valid */ /* Reserved bits */ #define WAVE_ROM 0x40000000 /* For future use */ #define WAVE_MULAW 0x20000000 /* For future use */ /* Other bits must be zeroed */ int len; /* Size of the wave data in bytes */ int loop_start, loop_end; /* Byte offsets from the beginning */ /* * The base_freq and base_note fields are used when computing the * playback speed for a note. The base_note defines the tone frequency * which is heard if the sample is played using the base_freq as the * playback speed. * * The low_note and high_note fields define the minimum and maximum note * frequencies for which this sample is valid. It is possible to define * more than one samples for an instrument number at the same time. The * low_note and high_note fields are used to select the most suitable one. * * The fields base_note, high_note and low_note should contain * the note frequency multiplied by 1000. For example value for the * middle A is 440*1000. */ unsigned int base_freq; unsigned int base_note; unsigned int high_note; unsigned int low_note; int panning; /* -128=left, 127=right */ int detuning; /* New fields introduced in version 1.99.5 */ /* Envelope. Enabled by mode bit WAVE_ENVELOPES */ unsigned char env_rate[ 6 ]; /* GUS HW ramping rate */ unsigned char env_offset[ 6 ]; /* 255 == 100% */ /* * The tremolo, vibrato and scale info are not supported yet. * Enable by setting the mode bits WAVE_TREMOLO, WAVE_VIBRATO or * WAVE_SCALE */ unsigned char tremolo_sweep; unsigned char tremolo_rate; unsigned char tremolo_depth; unsigned char vibrato_sweep; unsigned char vibrato_rate; unsigned char vibrato_depth; int scale_frequency; unsigned int scale_factor; /* from 0 to 2048 or 0 to 2 */ int volume; int fractions; int reserved1; int spare[2]; char data[1]; /* The waveform data starts here */ }; struct sysex_info { short key; /* Use SYSEX_PATCH or MAUI_PATCH here */ #define SYSEX_PATCH _PATCHKEY(0x05) #define MAUI_PATCH _PATCHKEY(0x06) short device_no; /* Synthesizer number */ int len; /* Size of the sysex data in bytes */ unsigned char data[1]; /* Sysex data starts here */ }; /* * /dev/sequencer input events. * * The data written to the /dev/sequencer is a stream of events. Events * are records of 4 or 8 bytes. The first byte defines the size. * Any number of events can be written with a write call. There * is a set of macros for sending these events. Use these macros if you * want to maximize portability of your program. * * Events SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO. Are also input events. * (All input events are currently 4 bytes long. Be prepared to support * 8 byte events also. If you receive any event having first byte >= 128, * it's a 8 byte event. * * The events are documented at the end of this file. * * Normal events (4 bytes) * There is also a 8 byte version of most of the 4 byte events. The * 8 byte one is recommended. */ #define SEQ_NOTEOFF 0 #define SEQ_FMNOTEOFF SEQ_NOTEOFF /* Just old name */ #define SEQ_NOTEON 1 #define SEQ_FMNOTEON SEQ_NOTEON #define SEQ_WAIT TMR_WAIT_ABS #define SEQ_PGMCHANGE 3 #define SEQ_FMPGMCHANGE SEQ_PGMCHANGE #define SEQ_SYNCTIMER TMR_START #define SEQ_MIDIPUTC 5 #define SEQ_DRUMON 6 /*** OBSOLETE ***/ #define SEQ_DRUMOFF 7 /*** OBSOLETE ***/ #define SEQ_ECHO TMR_ECHO /* For synching programs with output */ #define SEQ_AFTERTOUCH 9 #define SEQ_CONTROLLER 10 /******************************************* * Midi controller numbers ******************************************* * Controllers 0 to 31 (0x00 to 0x1f) and * 32 to 63 (0x20 to 0x3f) are continuous * controllers. * In the MIDI 1.0 these controllers are sent using * two messages. Controller numbers 0 to 31 are used * to send the MSB and the controller numbers 32 to 63 * are for the LSB. Note that just 7 bits are used in MIDI bytes. */ #define CTL_BANK_SELECT 0x00 #define CTL_MODWHEEL 0x01 #define CTL_BREATH 0x02 /* undefined 0x03 */ #define CTL_FOOT 0x04 #define CTL_PORTAMENTO_TIME 0x05 #define CTL_DATA_ENTRY 0x06 #define CTL_MAIN_VOLUME 0x07 #define CTL_BALANCE 0x08 /* undefined 0x09 */ #define CTL_PAN 0x0a #define CTL_EXPRESSION 0x0b /* undefined 0x0c */ /* undefined 0x0d */ /* undefined 0x0e */ /* undefined 0x0f */ #define CTL_GENERAL_PURPOSE1 0x10 #define CTL_GENERAL_PURPOSE2 0x11 #define CTL_GENERAL_PURPOSE3 0x12 #define CTL_GENERAL_PURPOSE4 0x13 /* undefined 0x14 - 0x1f */ /* undefined 0x20 */ /* The controller numbers 0x21 to 0x3f are reserved for the */ /* least significant bytes of the controllers 0x00 to 0x1f. */ /* These controllers are not recognised by the driver. */ /* Controllers 64 to 69 (0x40 to 0x45) are on/off switches. */ /* 0=OFF and 127=ON (intermediate values are possible) */ #define CTL_DAMPER_PEDAL 0x40 #define CTL_SUSTAIN 0x40 /* Alias */ #define CTL_HOLD 0x40 /* Alias */ #define CTL_PORTAMENTO 0x41 #define CTL_SOSTENUTO 0x42 #define CTL_SOFT_PEDAL 0x43 /* undefined 0x44 */ #define CTL_HOLD2 0x45 /* undefined 0x46 - 0x4f */ #define CTL_GENERAL_PURPOSE5 0x50 #define CTL_GENERAL_PURPOSE6 0x51 #define CTL_GENERAL_PURPOSE7 0x52 #define CTL_GENERAL_PURPOSE8 0x53 /* undefined 0x54 - 0x5a */ #define CTL_EXT_EFF_DEPTH 0x5b #define CTL_TREMOLO_DEPTH 0x5c #define CTL_CHORUS_DEPTH 0x5d #define CTL_DETUNE_DEPTH 0x5e #define CTL_CELESTE_DEPTH 0x5e /* Alias for the above one */ #define CTL_PHASER_DEPTH 0x5f #define CTL_DATA_INCREMENT 0x60 #define CTL_DATA_DECREMENT 0x61 #define CTL_NONREG_PARM_NUM_LSB 0x62 #define CTL_NONREG_PARM_NUM_MSB 0x63 #define CTL_REGIST_PARM_NUM_LSB 0x64 #define CTL_REGIST_PARM_NUM_MSB 0x65 /* undefined 0x66 - 0x78 */ /* reserved 0x79 - 0x7f */ /* Pseudo controllers (not midi compatible) */ #define CTRL_PITCH_BENDER 255 #define CTRL_PITCH_BENDER_RANGE 254 #define CTRL_EXPRESSION 253 /* Obsolete */ #define CTRL_MAIN_VOLUME 252 /* Obsolete */ #define SEQ_BALANCE 11 #define SEQ_VOLMODE 12 /* * Volume mode decides how volumes are used */ #define VOL_METHOD_ADAGIO 1 #define VOL_METHOD_LINEAR 2 /* * Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as * input events. */ /* * Event codes 0xf0 to 0xfc are reserved for future extensions. */ #define SEQ_FULLSIZE 0xfd /* Long events */ /* * SEQ_FULLSIZE events are used for loading patches/samples to the * synthesizer devices. These events are passed directly to the driver * of the associated synthesizer device. There is no limit to the size * of the extended events. These events are not queued but executed * immediately when the write() is called (execution can take several * seconds of time). * * When a SEQ_FULLSIZE message is written to the device, it must * be written using exactly one write() call. Other events cannot * be mixed to the same write. * * For FM synths (YM3812/OPL3) use struct sbi_instrument and write it to the * /dev/sequencer. Don't write other data together with the instrument structure * Set the key field of the structure to FM_PATCH. The device field is used to * route the patch to the corresponding device. * * For wave table use struct patch_info. Initialize the key field * to WAVE_PATCH. */ #define SEQ_PRIVATE 0xfe /* Low level HW dependent events (8 bytes) */ #define SEQ_EXTENDED 0xff /* Extended events (8 bytes) OBSOLETE */ /* * Record for FM patches */ typedef unsigned char sbi_instr_data[32]; struct sbi_instrument { unsigned short key; /* FM_PATCH or OPL3_PATCH */ #define FM_PATCH _PATCHKEY(0x01) #define OPL3_PATCH _PATCHKEY(0x03) short device; /* Synth# (0-4) */ int channel; /* Program# to be initialized */ sbi_instr_data operators; /* Register settings for operator cells (.SBI format) */ }; struct synth_info { /* Read only */ char name[30]; int device; /* 0-N. INITIALIZE BEFORE CALLING */ int synth_type; #define SYNTH_TYPE_FM 0 #define SYNTH_TYPE_SAMPLE 1 #define SYNTH_TYPE_MIDI 2 /* Midi interface */ int synth_subtype; #define FM_TYPE_ADLIB 0x00 #define FM_TYPE_OPL3 0x01 #define MIDI_TYPE_MPU401 0x401 #define SAMPLE_TYPE_BASIC 0x10 #define SAMPLE_TYPE_GUS SAMPLE_TYPE_BASIC #define SAMPLE_TYPE_WAVEFRONT 0x11 int perc_mode; /* No longer supported */ int nr_voices; int nr_drums; /* Obsolete field */ int instr_bank_size; unsigned int capabilities; #define SYNTH_CAP_PERCMODE 0x00000001 /* No longer used */ #define SYNTH_CAP_OPL3 0x00000002 /* Set if OPL3 supported */ #define SYNTH_CAP_INPUT 0x00000004 /* Input (MIDI) device */ int dummies[19]; /* Reserve space */ }; struct sound_timer_info { char name[32]; int caps; }; #define MIDI_CAP_MPU401 1 /* MPU-401 intelligent mode */ struct midi_info { char name[30]; int device; /* 0-N. INITIALIZE BEFORE CALLING */ unsigned int capabilities; /* To be defined later */ int dev_type; int dummies[18]; /* Reserve space */ }; /******************************************** * ioctl commands for the /dev/midi## */ typedef struct { unsigned char cmd; char nr_args, nr_returns; unsigned char data[30]; } mpu_command_rec; #define SNDCTL_MIDI_PRETIME _SIOWR('m', 0, int) #define SNDCTL_MIDI_MPUMODE _SIOWR('m', 1, int) #define SNDCTL_MIDI_MPUCMD _SIOWR('m', 2, mpu_command_rec) /******************************************** * IOCTL commands for /dev/dsp and /dev/audio */ #define SNDCTL_DSP_RESET _SIO ('P', 0) #define SNDCTL_DSP_SYNC _SIO ('P', 1) #define SNDCTL_DSP_SPEED _SIOWR('P', 2, int) #define SNDCTL_DSP_STEREO _SIOWR('P', 3, int) #define SNDCTL_DSP_GETBLKSIZE _SIOWR('P', 4, int) #define SNDCTL_DSP_SAMPLESIZE SNDCTL_DSP_SETFMT #define SNDCTL_DSP_CHANNELS _SIOWR('P', 6, int) #define SOUND_PCM_WRITE_CHANNELS SNDCTL_DSP_CHANNELS #define SOUND_PCM_WRITE_FILTER _SIOWR('P', 7, int) #define SNDCTL_DSP_POST _SIO ('P', 8) #define SNDCTL_DSP_SUBDIVIDE _SIOWR('P', 9, int) #define SNDCTL_DSP_SETFRAGMENT _SIOWR('P',10, int) /* Audio data formats (Note! U8=8 and S16_LE=16 for compatibility) */ #define SNDCTL_DSP_GETFMTS _SIOR ('P',11, int) /* Returns a mask */ #define SNDCTL_DSP_SETFMT _SIOWR('P',5, int) /* Selects ONE fmt*/ #define AFMT_QUERY 0x00000000 /* Return current fmt */ #define AFMT_MU_LAW 0x00000001 #define AFMT_A_LAW 0x00000002 #define AFMT_IMA_ADPCM 0x00000004 #define AFMT_U8 0x00000008 #define AFMT_S16_LE 0x00000010 /* Little endian signed 16*/ #define AFMT_S16_BE 0x00000020 /* Big endian signed 16 */ #define AFMT_S8 0x00000040 #define AFMT_U16_LE 0x00000080 /* Little endian U16 */ #define AFMT_U16_BE 0x00000100 /* Big endian U16 */ #define AFMT_MPEG 0x00000200 /* MPEG (2) audio */ #define AFMT_AC3 0x00000400 /* Dolby Digital AC3 */ #define AFMT_S24_LE 0x00000800 #define AFMT_S24_BE 0x00001000 #define AFMT_U24_LE 0x00002000 #define AFMT_U24_BE 0x00004000 #define AFMT_S32_LE 0x00008000 #define AFMT_S32_BE 0x00010000 #define AFMT_U32_LE 0x00020000 #define AFMT_U32_BE 0x00040000 /* * Buffer status queries. */ typedef struct audio_buf_info { int fragments; /* # of available fragments (partially usend ones not counted) */ int fragstotal; /* Total # of fragments allocated */ int fragsize; /* Size of a fragment in bytes */ int bytes; /* Available space in bytes (includes partially used fragments) */ /* Note! 'bytes' could be more than fragments*fragsize */ } audio_buf_info; #define SNDCTL_DSP_GETOSPACE _SIOR ('P',12, audio_buf_info) #define SNDCTL_DSP_GETISPACE _SIOR ('P',13, audio_buf_info) #define SNDCTL_DSP_NONBLOCK _SIO ('P',14) #define SNDCTL_DSP_GETCAPS _SIOR ('P',15, int) # define DSP_CAP_REVISION 0x000000ff /* Bits for revision level (0 to 255) */ # define DSP_CAP_DUPLEX 0x00000100 /* Full duplex record/playback */ # define DSP_CAP_REALTIME 0x00000200 /* Real time capability */ # define DSP_CAP_BATCH 0x00000400 /* Device has some kind of */ /* internal buffers which may */ /* cause some delays and */ /* decrease precision of timing */ # define DSP_CAP_COPROC 0x00000800 /* Has a coprocessor */ /* Sometimes it's a DSP */ /* but usually not */ # define DSP_CAP_TRIGGER 0x00001000 /* Supports SETTRIGGER */ # define DSP_CAP_MMAP 0x00002000 /* Supports mmap() */ # define DSP_CAP_MULTI 0x00004000 /* support multiple open */ # define DSP_CAP_BIND 0x00008000 /* channel binding to front/rear/cneter/lfe */ #define SNDCTL_DSP_GETTRIGGER _SIOR ('P',16, int) #define SNDCTL_DSP_SETTRIGGER _SIOW ('P',16, int) # define PCM_ENABLE_INPUT 0x00000001 # define PCM_ENABLE_OUTPUT 0x00000002 typedef struct count_info { int bytes; /* Total # of bytes processed */ int blocks; /* # of fragment transitions since last time */ int ptr; /* Current DMA pointer value */ } count_info; #define SNDCTL_DSP_GETIPTR _SIOR ('P',17, count_info) #define SNDCTL_DSP_GETOPTR _SIOR ('P',18, count_info) typedef struct buffmem_desc { unsigned *buffer; int size; } buffmem_desc; #define SNDCTL_DSP_MAPINBUF _SIOR ('P', 19, buffmem_desc) #define SNDCTL_DSP_MAPOUTBUF _SIOR ('P', 20, buffmem_desc) #define SNDCTL_DSP_SETSYNCRO _SIO ('P', 21) #define SNDCTL_DSP_SETDUPLEX _SIO ('P', 22) #define SNDCTL_DSP_GETODELAY _SIOR ('P', 23, int) #define SNDCTL_DSP_GETCHANNELMASK _SIOWR('P', 64, int) #define SNDCTL_DSP_BIND_CHANNEL _SIOWR('P', 65, int) # define DSP_BIND_QUERY 0x00000000 # define DSP_BIND_FRONT 0x00000001 # define DSP_BIND_SURR 0x00000002 # define DSP_BIND_CENTER_LFE 0x00000004 # define DSP_BIND_HANDSET 0x00000008 # define DSP_BIND_MIC 0x00000010 # define DSP_BIND_MODEM1 0x00000020 # define DSP_BIND_MODEM2 0x00000040 # define DSP_BIND_I2S 0x00000080 # define DSP_BIND_SPDIF 0x00000100 #define SNDCTL_DSP_SETSPDIF _SIOW ('P', 66, int) #define SNDCTL_DSP_GETSPDIF _SIOR ('P', 67, int) # define SPDIF_PRO 0x0001 # define SPDIF_N_AUD 0x0002 # define SPDIF_COPY 0x0004 # define SPDIF_PRE 0x0008 # define SPDIF_CC 0x07f0 # define SPDIF_L 0x0800 # define SPDIF_DRS 0x4000 # define SPDIF_V 0x8000 /* * Application's profile defines the way how playback underrun situations should be handled. * * APF_NORMAL (the default) and APF_NETWORK make the driver to cleanup the * playback buffer whenever an underrun occurs. This consumes some time * prevents looping the existing buffer. * APF_CPUINTENS is intended to be set by CPU intensive applications which * are likely to run out of time occasionally. In this mode the buffer cleanup is * disabled which saves CPU time but also let's the previous buffer content to * be played during the "pause" after the underrun. */ #define SNDCTL_DSP_PROFILE _SIOW ('P', 23, int) #define APF_NORMAL 0 /* Normal applications */ #define APF_NETWORK 1 /* Underruns probably caused by an "external" delay */ #define APF_CPUINTENS 2 /* Underruns probably caused by "overheating" the CPU */ #define SOUND_PCM_READ_RATE _SIOR ('P', 2, int) #define SOUND_PCM_READ_CHANNELS _SIOR ('P', 6, int) #define SOUND_PCM_READ_BITS _SIOR ('P', 5, int) #define SOUND_PCM_READ_FILTER _SIOR ('P', 7, int) /* Some alias names */ #define SOUND_PCM_WRITE_BITS SNDCTL_DSP_SETFMT #define SOUND_PCM_WRITE_RATE SNDCTL_DSP_SPEED #define SOUND_PCM_POST SNDCTL_DSP_POST #define SOUND_PCM_RESET SNDCTL_DSP_RESET #define SOUND_PCM_SYNC SNDCTL_DSP_SYNC #define SOUND_PCM_SUBDIVIDE SNDCTL_DSP_SUBDIVIDE #define SOUND_PCM_SETFRAGMENT SNDCTL_DSP_SETFRAGMENT #define SOUND_PCM_GETFMTS SNDCTL_DSP_GETFMTS #define SOUND_PCM_SETFMT SNDCTL_DSP_SETFMT #define SOUND_PCM_GETOSPACE SNDCTL_DSP_GETOSPACE #define SOUND_PCM_GETISPACE SNDCTL_DSP_GETISPACE #define SOUND_PCM_NONBLOCK SNDCTL_DSP_NONBLOCK #define SOUND_PCM_GETCAPS SNDCTL_DSP_GETCAPS #define SOUND_PCM_GETTRIGGER SNDCTL_DSP_GETTRIGGER #define SOUND_PCM_SETTRIGGER SNDCTL_DSP_SETTRIGGER #define SOUND_PCM_SETSYNCRO SNDCTL_DSP_SETSYNCRO #define SOUND_PCM_GETIPTR SNDCTL_DSP_GETIPTR #define SOUND_PCM_GETOPTR SNDCTL_DSP_GETOPTR #define SOUND_PCM_MAPINBUF SNDCTL_DSP_MAPINBUF #define SOUND_PCM_MAPOUTBUF SNDCTL_DSP_MAPOUTBUF /* * ioctl calls to be used in communication with coprocessors and * DSP chips. */ typedef struct copr_buffer { int command; /* Set to 0 if not used */ int flags; #define CPF_NONE 0x0000 #define CPF_FIRST 0x0001 /* First block */ #define CPF_LAST 0x0002 /* Last block */ int len; int offs; /* If required by the device (0 if not used) */ unsigned char data[4000]; /* NOTE! 4000 is not 4k */ } copr_buffer; typedef struct copr_debug_buf { int command; /* Used internally. Set to 0 */ int parm1; int parm2; int flags; int len; /* Length of data in bytes */ } copr_debug_buf; typedef struct copr_msg { int len; unsigned char data[4000]; } copr_msg; #define SNDCTL_COPR_RESET _SIO ('C', 0) #define SNDCTL_COPR_LOAD _SIOWR('C', 1, copr_buffer) #define SNDCTL_COPR_RDATA _SIOWR('C', 2, copr_debug_buf) #define SNDCTL_COPR_RCODE _SIOWR('C', 3, copr_debug_buf) #define SNDCTL_COPR_WDATA _SIOW ('C', 4, copr_debug_buf) #define SNDCTL_COPR_WCODE _SIOW ('C', 5, copr_debug_buf) #define SNDCTL_COPR_RUN _SIOWR('C', 6, copr_debug_buf) #define SNDCTL_COPR_HALT _SIOWR('C', 7, copr_debug_buf) #define SNDCTL_COPR_SENDMSG _SIOWR('C', 8, copr_msg) #define SNDCTL_COPR_RCVMSG _SIOR ('C', 9, copr_msg) /********************************************* * IOCTL commands for /dev/mixer */ /* * Mixer devices * * There can be up to 20 different analog mixer channels. The * SOUND_MIXER_NRDEVICES gives the currently supported maximum. * The SOUND_MIXER_READ_DEVMASK returns a bitmask which tells * the devices supported by the particular mixer. */ #define SOUND_MIXER_NRDEVICES 25 #define SOUND_MIXER_VOLUME 0 #define SOUND_MIXER_BASS 1 #define SOUND_MIXER_TREBLE 2 #define SOUND_MIXER_SYNTH 3 #define SOUND_MIXER_PCM 4 #define SOUND_MIXER_SPEAKER 5 #define SOUND_MIXER_LINE 6 #define SOUND_MIXER_MIC 7 #define SOUND_MIXER_CD 8 #define SOUND_MIXER_IMIX 9 /* Recording monitor */ #define SOUND_MIXER_ALTPCM 10 #define SOUND_MIXER_RECLEV 11 /* Recording level */ #define SOUND_MIXER_IGAIN 12 /* Input gain */ #define SOUND_MIXER_OGAIN 13 /* Output gain */ /* * The AD1848 codec and compatibles have three line level inputs * (line, aux1 and aux2). Since each card manufacturer have assigned * different meanings to these inputs, it's inpractical to assign * specific meanings (line, cd, synth etc.) to them. */ #define SOUND_MIXER_LINE1 14 /* Input source 1 (aux1) */ #define SOUND_MIXER_LINE2 15 /* Input source 2 (aux2) */ #define SOUND_MIXER_LINE3 16 /* Input source 3 (line) */ #define SOUND_MIXER_DIGITAL1 17 /* Digital (input) 1 */ #define SOUND_MIXER_DIGITAL2 18 /* Digital (input) 2 */ #define SOUND_MIXER_DIGITAL3 19 /* Digital (input) 3 */ #define SOUND_MIXER_PHONEIN 20 /* Phone input */ #define SOUND_MIXER_PHONEOUT 21 /* Phone output */ #define SOUND_MIXER_VIDEO 22 /* Video/TV (audio) in */ #define SOUND_MIXER_RADIO 23 /* Radio in */ #define SOUND_MIXER_MONITOR 24 /* Monitor (usually mic) volume */ /* Some on/off settings (SOUND_SPECIAL_MIN - SOUND_SPECIAL_MAX) */ /* Not counted to SOUND_MIXER_NRDEVICES, but use the same number space */ #define SOUND_ONOFF_MIN 28 #define SOUND_ONOFF_MAX 30 /* Note! Number 31 cannot be used since the sign bit is reserved */ #define SOUND_MIXER_NONE 31 /* * The following unsupported macros are no longer functional. * Use SOUND_MIXER_PRIVATE# macros in future. */ #define SOUND_MIXER_ENHANCE SOUND_MIXER_NONE #define SOUND_MIXER_MUTE SOUND_MIXER_NONE #define SOUND_MIXER_LOUD SOUND_MIXER_NONE #define SOUND_DEVICE_LABELS {"Vol ", "Bass ", "Trebl", "Synth", "Pcm ", "Spkr ", "Line ", \ "Mic ", "CD ", "Mix ", "Pcm2 ", "Rec ", "IGain", "OGain", \ "Line1", "Line2", "Line3", "Digital1", "Digital2", "Digital3", \ "PhoneIn", "PhoneOut", "Video", "Radio", "Monitor"} #define SOUND_DEVICE_NAMES {"vol", "bass", "treble", "synth", "pcm", "speaker", "line", \ "mic", "cd", "mix", "pcm2", "rec", "igain", "ogain", \ "line1", "line2", "line3", "dig1", "dig2", "dig3", \ "phin", "phout", "video", "radio", "monitor"} /* Device bitmask identifiers */ #define SOUND_MIXER_RECSRC 0xff /* Arg contains a bit for each recording source */ #define SOUND_MIXER_DEVMASK 0xfe /* Arg contains a bit for each supported device */ #define SOUND_MIXER_RECMASK 0xfd /* Arg contains a bit for each supported recording source */ #define SOUND_MIXER_CAPS 0xfc # define SOUND_CAP_EXCL_INPUT 0x00000001 /* Only one recording source at a time */ #define SOUND_MIXER_STEREODEVS 0xfb /* Mixer channels supporting stereo */ #define SOUND_MIXER_OUTSRC 0xfa /* Arg contains a bit for each input source to output */ #define SOUND_MIXER_OUTMASK 0xf9 /* Arg contains a bit for each supported input source to output */ /* Device mask bits */ #define SOUND_MASK_VOLUME (1 << SOUND_MIXER_VOLUME) #define SOUND_MASK_BASS (1 << SOUND_MIXER_BASS) #define SOUND_MASK_TREBLE (1 << SOUND_MIXER_TREBLE) #define SOUND_MASK_SYNTH (1 << SOUND_MIXER_SYNTH) #define SOUND_MASK_PCM (1 << SOUND_MIXER_PCM) #define SOUND_MASK_SPEAKER (1 << SOUND_MIXER_SPEAKER) #define SOUND_MASK_LINE (1 << SOUND_MIXER_LINE) #define SOUND_MASK_MIC (1 << SOUND_MIXER_MIC) #define SOUND_MASK_CD (1 << SOUND_MIXER_CD) #define SOUND_MASK_IMIX (1 << SOUND_MIXER_IMIX) #define SOUND_MASK_ALTPCM (1 << SOUND_MIXER_ALTPCM) #define SOUND_MASK_RECLEV (1 << SOUND_MIXER_RECLEV) #define SOUND_MASK_IGAIN (1 << SOUND_MIXER_IGAIN) #define SOUND_MASK_OGAIN (1 << SOUND_MIXER_OGAIN) #define SOUND_MASK_LINE1 (1 << SOUND_MIXER_LINE1) #define SOUND_MASK_LINE2 (1 << SOUND_MIXER_LINE2) #define SOUND_MASK_LINE3 (1 << SOUND_MIXER_LINE3) #define SOUND_MASK_DIGITAL1 (1 << SOUND_MIXER_DIGITAL1) #define SOUND_MASK_DIGITAL2 (1 << SOUND_MIXER_DIGITAL2) #define SOUND_MASK_DIGITAL3 (1 << SOUND_MIXER_DIGITAL3) #define SOUND_MASK_PHONEIN (1 << SOUND_MIXER_PHONEIN) #define SOUND_MASK_PHONEOUT (1 << SOUND_MIXER_PHONEOUT) #define SOUND_MASK_RADIO (1 << SOUND_MIXER_RADIO) #define SOUND_MASK_VIDEO (1 << SOUND_MIXER_VIDEO) #define SOUND_MASK_MONITOR (1 << SOUND_MIXER_MONITOR) /* Obsolete macros */ #define SOUND_MASK_MUTE (1 << SOUND_MIXER_MUTE) #define SOUND_MASK_ENHANCE (1 << SOUND_MIXER_ENHANCE) #define SOUND_MASK_LOUD (1 << SOUND_MIXER_LOUD) #define MIXER_READ(dev) _SIOR('M', dev, int) #define SOUND_MIXER_READ_VOLUME MIXER_READ(SOUND_MIXER_VOLUME) #define SOUND_MIXER_READ_BASS MIXER_READ(SOUND_MIXER_BASS) #define SOUND_MIXER_READ_TREBLE MIXER_READ(SOUND_MIXER_TREBLE) #define SOUND_MIXER_READ_SYNTH MIXER_READ(SOUND_MIXER_SYNTH) #define SOUND_MIXER_READ_PCM MIXER_READ(SOUND_MIXER_PCM) #define SOUND_MIXER_READ_SPEAKER MIXER_READ(SOUND_MIXER_SPEAKER) #define SOUND_MIXER_READ_LINE MIXER_READ(SOUND_MIXER_LINE) #define SOUND_MIXER_READ_MIC MIXER_READ(SOUND_MIXER_MIC) #define SOUND_MIXER_READ_CD MIXER_READ(SOUND_MIXER_CD) #define SOUND_MIXER_READ_IMIX MIXER_READ(SOUND_MIXER_IMIX) #define SOUND_MIXER_READ_ALTPCM MIXER_READ(SOUND_MIXER_ALTPCM) #define SOUND_MIXER_READ_RECLEV MIXER_READ(SOUND_MIXER_RECLEV) #define SOUND_MIXER_READ_IGAIN MIXER_READ(SOUND_MIXER_IGAIN) #define SOUND_MIXER_READ_OGAIN MIXER_READ(SOUND_MIXER_OGAIN) #define SOUND_MIXER_READ_LINE1 MIXER_READ(SOUND_MIXER_LINE1) #define SOUND_MIXER_READ_LINE2 MIXER_READ(SOUND_MIXER_LINE2) #define SOUND_MIXER_READ_LINE3 MIXER_READ(SOUND_MIXER_LINE3) /* Obsolete macros */ #define SOUND_MIXER_READ_MUTE MIXER_READ(SOUND_MIXER_MUTE) #define SOUND_MIXER_READ_ENHANCE MIXER_READ(SOUND_MIXER_ENHANCE) #define SOUND_MIXER_READ_LOUD MIXER_READ(SOUND_MIXER_LOUD) #define SOUND_MIXER_READ_RECSRC MIXER_READ(SOUND_MIXER_RECSRC) #define SOUND_MIXER_READ_DEVMASK MIXER_READ(SOUND_MIXER_DEVMASK) #define SOUND_MIXER_READ_RECMASK MIXER_READ(SOUND_MIXER_RECMASK) #define SOUND_MIXER_READ_STEREODEVS MIXER_READ(SOUND_MIXER_STEREODEVS) #define SOUND_MIXER_READ_CAPS MIXER_READ(SOUND_MIXER_CAPS) #define MIXER_WRITE(dev) _SIOWR('M', dev, int) #define SOUND_MIXER_WRITE_VOLUME MIXER_WRITE(SOUND_MIXER_VOLUME) #define SOUND_MIXER_WRITE_BASS MIXER_WRITE(SOUND_MIXER_BASS) #define SOUND_MIXER_WRITE_TREBLE MIXER_WRITE(SOUND_MIXER_TREBLE) #define SOUND_MIXER_WRITE_SYNTH MIXER_WRITE(SOUND_MIXER_SYNTH) #define SOUND_MIXER_WRITE_PCM MIXER_WRITE(SOUND_MIXER_PCM) #define SOUND_MIXER_WRITE_SPEAKER MIXER_WRITE(SOUND_MIXER_SPEAKER) #define SOUND_MIXER_WRITE_LINE MIXER_WRITE(SOUND_MIXER_LINE) #define SOUND_MIXER_WRITE_MIC MIXER_WRITE(SOUND_MIXER_MIC) #define SOUND_MIXER_WRITE_CD MIXER_WRITE(SOUND_MIXER_CD) #define SOUND_MIXER_WRITE_IMIX MIXER_WRITE(SOUND_MIXER_IMIX) #define SOUND_MIXER_WRITE_ALTPCM MIXER_WRITE(SOUND_MIXER_ALTPCM) #define SOUND_MIXER_WRITE_RECLEV MIXER_WRITE(SOUND_MIXER_RECLEV) #define SOUND_MIXER_WRITE_IGAIN MIXER_WRITE(SOUND_MIXER_IGAIN) #define SOUND_MIXER_WRITE_OGAIN MIXER_WRITE(SOUND_MIXER_OGAIN) #define SOUND_MIXER_WRITE_LINE1 MIXER_WRITE(SOUND_MIXER_LINE1) #define SOUND_MIXER_WRITE_LINE2 MIXER_WRITE(SOUND_MIXER_LINE2) #define SOUND_MIXER_WRITE_LINE3 MIXER_WRITE(SOUND_MIXER_LINE3) /* Obsolete macros */ #define SOUND_MIXER_WRITE_MUTE MIXER_WRITE(SOUND_MIXER_MUTE) #define SOUND_MIXER_WRITE_ENHANCE MIXER_WRITE(SOUND_MIXER_ENHANCE) #define SOUND_MIXER_WRITE_LOUD MIXER_WRITE(SOUND_MIXER_LOUD) #define SOUND_MIXER_WRITE_RECSRC MIXER_WRITE(SOUND_MIXER_RECSRC) typedef struct mixer_info { char id[16]; char name[32]; int modify_counter; int fillers[10]; } mixer_info; typedef struct _old_mixer_info /* Obsolete */ { char id[16]; char name[32]; } _old_mixer_info; #define SOUND_MIXER_INFO _SIOR ('M', 101, mixer_info) #define SOUND_OLD_MIXER_INFO _SIOR ('M', 101, _old_mixer_info) /* * A mechanism for accessing "proprietary" mixer features. This method * permits passing 128 bytes of arbitrary data between a mixer application * and the mixer driver. Interpretation of the record is defined by * the particular mixer driver. */ typedef unsigned char mixer_record[128]; #define SOUND_MIXER_ACCESS _SIOWR('M', 102, mixer_record) /* * Two ioctls for special souncard function */ #define SOUND_MIXER_AGC _SIOWR('M', 103, int) #define SOUND_MIXER_3DSE _SIOWR('M', 104, int) /* * The SOUND_MIXER_PRIVATE# commands can be redefined by low level drivers. * These features can be used when accessing device specific features. */ #define SOUND_MIXER_PRIVATE1 _SIOWR('M', 111, int) #define SOUND_MIXER_PRIVATE2 _SIOWR('M', 112, int) #define SOUND_MIXER_PRIVATE3 _SIOWR('M', 113, int) #define SOUND_MIXER_PRIVATE4 _SIOWR('M', 114, int) #define SOUND_MIXER_PRIVATE5 _SIOWR('M', 115, int) /* * SOUND_MIXER_GETLEVELS and SOUND_MIXER_SETLEVELS calls can be used * for querying current mixer settings from the driver and for loading * default volume settings _prior_ activating the mixer (loading * doesn't affect current state of the mixer hardware). These calls * are for internal use only. */ typedef struct mixer_vol_table { int num; /* Index to volume table */ char name[32]; int levels[32]; } mixer_vol_table; #define SOUND_MIXER_GETLEVELS _SIOWR('M', 116, mixer_vol_table) #define SOUND_MIXER_SETLEVELS _SIOWR('M', 117, mixer_vol_table) /* * An ioctl for identifying the driver version. It will return value * of the SOUND_VERSION macro used when compiling the driver. * This call was introduced in OSS version 3.6 and it will not work * with earlier versions (returns EINVAL). */ #define OSS_GETVERSION _SIOR ('M', 118, int) /* * Level 2 event types for /dev/sequencer */ /* * The 4 most significant bits of byte 0 specify the class of * the event: * * 0x8X = system level events, * 0x9X = device/port specific events, event[1] = device/port, * The last 4 bits give the subtype: * 0x02 = Channel event (event[3] = chn). * 0x01 = note event (event[4] = note). * (0x01 is not used alone but always with bit 0x02). * event[2] = MIDI message code (0x80=note off etc.) * */ #define EV_SEQ_LOCAL 0x80 #define EV_TIMING 0x81 #define EV_CHN_COMMON 0x92 #define EV_CHN_VOICE 0x93 #define EV_SYSEX 0x94 /* * Event types 200 to 220 are reserved for application use. * These numbers will not be used by the driver. */ /* * Events for event type EV_CHN_VOICE */ #define MIDI_NOTEOFF 0x80 #define MIDI_NOTEON 0x90 #define MIDI_KEY_PRESSURE 0xA0 /* * Events for event type EV_CHN_COMMON */ #define MIDI_CTL_CHANGE 0xB0 #define MIDI_PGM_CHANGE 0xC0 #define MIDI_CHN_PRESSURE 0xD0 #define MIDI_PITCH_BEND 0xE0 #define MIDI_SYSTEM_PREFIX 0xF0 /* * Timer event types */ #define TMR_WAIT_REL 1 /* Time relative to the prev time */ #define TMR_WAIT_ABS 2 /* Absolute time since TMR_START */ #define TMR_STOP 3 #define TMR_START 4 #define TMR_CONTINUE 5 #define TMR_TEMPO 6 #define TMR_ECHO 8 #define TMR_CLOCK 9 /* MIDI clock */ #define TMR_SPP 10 /* Song position pointer */ #define TMR_TIMESIG 11 /* Time signature */ /* * Local event types */ #define LOCL_STARTAUDIO 1 #if (!defined(__KERNEL__) && !defined(KERNEL) && !defined(INKERNEL) && !defined(_KERNEL)) || defined(USE_SEQ_MACROS) /* * Some convenience macros to simplify programming of the * /dev/sequencer interface * * These macros define the API which should be used when possible. */ #define SEQ_DECLAREBUF() SEQ_USE_EXTBUF() void seqbuf_dump(void); /* This function must be provided by programs */ extern int OSS_init(int seqfd, int buflen); extern void OSS_seqbuf_dump(int fd, unsigned char *buf, int buflen); extern void OSS_seq_advbuf(int len, int fd, unsigned char *buf, int buflen); extern void OSS_seq_needbuf(int len, int fd, unsigned char *buf, int buflen); extern void OSS_patch_caching(int dev, int chn, int patch, int fd, unsigned char *buf, int buflen); extern void OSS_drum_caching(int dev, int chn, int patch, int fd, unsigned char *buf, int buflen); extern void OSS_write_patch(int fd, unsigned char *buf, int len); extern int OSS_write_patch2(int fd, unsigned char *buf, int len); #define SEQ_PM_DEFINES int __foo_bar___ #ifdef OSSLIB # define SEQ_USE_EXTBUF() \ extern unsigned char *_seqbuf; \ extern int _seqbuflen;extern int _seqbufptr # define SEQ_DEFINEBUF(len) SEQ_USE_EXTBUF();static int _requested_seqbuflen=len # define _SEQ_ADVBUF(len) OSS_seq_advbuf(len, seqfd, _seqbuf, _seqbuflen) # define _SEQ_NEEDBUF(len) OSS_seq_needbuf(len, seqfd, _seqbuf, _seqbuflen) # define SEQ_DUMPBUF() OSS_seqbuf_dump(seqfd, _seqbuf, _seqbuflen) # define SEQ_LOAD_GMINSTR(dev, instr) \ OSS_patch_caching(dev, -1, instr, seqfd, _seqbuf, _seqbuflen) # define SEQ_LOAD_GMDRUM(dev, drum) \ OSS_drum_caching(dev, -1, drum, seqfd, _seqbuf, _seqbuflen) #else /* !OSSLIB */ # define SEQ_LOAD_GMINSTR(dev, instr) # define SEQ_LOAD_GMDRUM(dev, drum) # define SEQ_USE_EXTBUF() \ extern unsigned char _seqbuf[]; \ extern int _seqbuflen;extern int _seqbufptr #ifndef USE_SIMPLE_MACROS /* Sample seqbuf_dump() implementation: * * SEQ_DEFINEBUF (2048); -- Defines a buffer for 2048 bytes * * int seqfd; -- The file descriptor for /dev/sequencer. * * void * seqbuf_dump () * { * if (_seqbufptr) * if (write (seqfd, _seqbuf, _seqbufptr) == -1) * { * perror ("write /dev/sequencer"); * exit (-1); * } * _seqbufptr = 0; * } */ #define SEQ_DEFINEBUF(len) unsigned char _seqbuf[len]; int _seqbuflen = len;int _seqbufptr = 0 #define _SEQ_NEEDBUF(len) if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump() #define _SEQ_ADVBUF(len) _seqbufptr += len #define SEQ_DUMPBUF seqbuf_dump #else /* * This variation of the sequencer macros is used just to format one event * using fixed buffer. * * The program using the macro library must define the following macros before * using this library. * * #define _seqbuf name of the buffer (unsigned char[]) * #define _SEQ_ADVBUF(len) If the applic needs to know the exact * size of the event, this macro can be used. * Otherwise this must be defined as empty. * #define _seqbufptr Define the name of index variable or 0 if * not required. */ #define _SEQ_NEEDBUF(len) /* empty */ #endif #endif /* !OSSLIB */ #define SEQ_VOLUME_MODE(dev, mode) {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = SEQ_EXTENDED;\ _seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\ _seqbuf[_seqbufptr+2] = (dev);\ _seqbuf[_seqbufptr+3] = (mode);\ _seqbuf[_seqbufptr+4] = 0;\ _seqbuf[_seqbufptr+5] = 0;\ _seqbuf[_seqbufptr+6] = 0;\ _seqbuf[_seqbufptr+7] = 0;\ _SEQ_ADVBUF(8);} /* * Midi voice messages */ #define _CHN_VOICE(dev, event, chn, note, parm) \ {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = EV_CHN_VOICE;\ _seqbuf[_seqbufptr+1] = (dev);\ _seqbuf[_seqbufptr+2] = (event);\ _seqbuf[_seqbufptr+3] = (chn);\ _seqbuf[_seqbufptr+4] = (note);\ _seqbuf[_seqbufptr+5] = (parm);\ _seqbuf[_seqbufptr+6] = (0);\ _seqbuf[_seqbufptr+7] = 0;\ _SEQ_ADVBUF(8);} #define SEQ_START_NOTE(dev, chn, note, vol) \ _CHN_VOICE(dev, MIDI_NOTEON, chn, note, vol) #define SEQ_STOP_NOTE(dev, chn, note, vol) \ _CHN_VOICE(dev, MIDI_NOTEOFF, chn, note, vol) #define SEQ_KEY_PRESSURE(dev, chn, note, pressure) \ _CHN_VOICE(dev, MIDI_KEY_PRESSURE, chn, note, pressure) /* * Midi channel messages */ #define _CHN_COMMON(dev, event, chn, p1, p2, w14) \ {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = EV_CHN_COMMON;\ _seqbuf[_seqbufptr+1] = (dev);\ _seqbuf[_seqbufptr+2] = (event);\ _seqbuf[_seqbufptr+3] = (chn);\ _seqbuf[_seqbufptr+4] = (p1);\ _seqbuf[_seqbufptr+5] = (p2);\ *(short *)&_seqbuf[_seqbufptr+6] = (w14);\ _SEQ_ADVBUF(8);} /* * SEQ_SYSEX permits sending of sysex messages. (It may look that it permits * sending any MIDI bytes but it's absolutely not possible. Trying to do * so _will_ cause problems with MPU401 intelligent mode). * * Sysex messages are sent in blocks of 1 to 6 bytes. Longer messages must be * sent by calling SEQ_SYSEX() several times (there must be no other events * between them). First sysex fragment must have 0xf0 in the first byte * and the last byte (buf[len-1] of the last fragment must be 0xf7. No byte * between these sysex start and end markers cannot be larger than 0x7f. Also * lengths of each fragments (except the last one) must be 6. * * Breaking the above rules may work with some MIDI ports but is likely to * cause fatal problems with some other devices (such as MPU401). */ #define SEQ_SYSEX(dev, buf, len) \ {int ii, ll=(len); \ unsigned char *bufp=buf;\ if (ll>6)ll=6;\ _SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr] = EV_SYSEX;\ _seqbuf[_seqbufptr+1] = (dev);\ for(ii=0;ii>8)&0xff);\ _seqbuf[_seqbufptr+7] = 0;\ _SEQ_ADVBUF(8);} /* * The following 5 macros are incorrectly implemented and obsolete. * Use SEQ_BENDER and SEQ_CONTROL (with proper controller) instead. */ #define SEQ_PITCHBEND(dev, voice, value) SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER, value) #define SEQ_BENDER_RANGE(dev, voice, value) SEQ_V2_X_CONTROL(dev, voice, CTRL_PITCH_BENDER_RANGE, value) #define SEQ_EXPRESSION(dev, voice, value) SEQ_CONTROL(dev, voice, CTL_EXPRESSION, value*128) #define SEQ_MAIN_VOLUME(dev, voice, value) SEQ_CONTROL(dev, voice, CTL_MAIN_VOLUME, (value*16383)/100) #define SEQ_PANNING(dev, voice, pos) SEQ_CONTROL(dev, voice, CTL_PAN, (pos+128) / 2) /* * Timing and syncronization macros */ #define _TIMER_EVENT(ev, parm) {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr+0] = EV_TIMING; \ _seqbuf[_seqbufptr+1] = (ev); \ _seqbuf[_seqbufptr+2] = 0;\ _seqbuf[_seqbufptr+3] = 0;\ *(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \ _SEQ_ADVBUF(8);} #define SEQ_START_TIMER() _TIMER_EVENT(TMR_START, 0) #define SEQ_STOP_TIMER() _TIMER_EVENT(TMR_STOP, 0) #define SEQ_CONTINUE_TIMER() _TIMER_EVENT(TMR_CONTINUE, 0) #define SEQ_WAIT_TIME(ticks) _TIMER_EVENT(TMR_WAIT_ABS, ticks) #define SEQ_DELTA_TIME(ticks) _TIMER_EVENT(TMR_WAIT_REL, ticks) #define SEQ_ECHO_BACK(key) _TIMER_EVENT(TMR_ECHO, key) #define SEQ_SET_TEMPO(value) _TIMER_EVENT(TMR_TEMPO, value) #define SEQ_SONGPOS(pos) _TIMER_EVENT(TMR_SPP, pos) #define SEQ_TIME_SIGNATURE(sig) _TIMER_EVENT(TMR_TIMESIG, sig) /* * Local control events */ #define _LOCAL_EVENT(ev, parm) {_SEQ_NEEDBUF(8);\ _seqbuf[_seqbufptr+0] = EV_SEQ_LOCAL; \ _seqbuf[_seqbufptr+1] = (ev); \ _seqbuf[_seqbufptr+2] = 0;\ _seqbuf[_seqbufptr+3] = 0;\ *(unsigned int *)&_seqbuf[_seqbufptr+4] = (parm); \ _SEQ_ADVBUF(8);} #define SEQ_PLAYAUDIO(devmask) _LOCAL_EVENT(LOCL_STARTAUDIO, devmask) /* * Events for the level 1 interface only */ #define SEQ_MIDIOUT(device, byte) {_SEQ_NEEDBUF(4);\ _seqbuf[_seqbufptr] = SEQ_MIDIPUTC;\ _seqbuf[_seqbufptr+1] = (byte);\ _seqbuf[_seqbufptr+2] = (device);\ _seqbuf[_seqbufptr+3] = 0;\ _SEQ_ADVBUF(4);} /* * Patch loading. */ #ifdef OSSLIB # define SEQ_WRPATCH(patchx, len) \ OSS_write_patch(seqfd, (char*)(patchx), len) # define SEQ_WRPATCH2(patchx, len) \ OSS_write_patch2(seqfd, (char*)(patchx), len) #else # define SEQ_WRPATCH(patchx, len) \ {if (_seqbufptr) SEQ_DUMPBUF();\ if (write(seqfd, (char*)(patchx), len)==-1) \ perror("Write patch: /dev/sequencer");} # define SEQ_WRPATCH2(patchx, len) \ (SEQ_DUMPBUF(), write(seqfd, (char*)(patchx), len)) #endif #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/sparc-ioctl.h010064400000000000000000000165521173363226500165510ustar00#define _IOC_NRBITS 8 #define _IOC_TYPEBITS 8 #define _IOC_SIZEBITS 13 /* Actually 14, see below. */ #define _IOC_DIRBITS 3 #define _IOC_NRMASK ((1 << _IOC_NRBITS)-1) #define _IOC_TYPEMASK ((1 << _IOC_TYPEBITS)-1) #define _IOC_SIZEMASK ((1 << _IOC_SIZEBITS)-1) #define _IOC_XSIZEMASK ((1 << (_IOC_SIZEBITS+1))-1) #define _IOC_DIRMASK ((1 << _IOC_DIRBITS)-1) #define _IOC_NRSHIFT 0 #define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS) #define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS) #define _IOC_DIRSHIFT (_IOC_SIZESHIFT + _IOC_SIZEBITS) #define _IOC_NONE 1U #define _IOC_READ 2U #define _IOC_WRITE 4U #define _IOC(dir,type,nr,size) \ (((dir) << _IOC_DIRSHIFT) | \ ((type) << _IOC_TYPESHIFT) | \ ((nr) << _IOC_NRSHIFT) | \ ((size) << _IOC_SIZESHIFT)) #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) #define _IOWR(type,nr,size) _IOC(_IOC_READ|_IOC_WRITE,(type),(nr),sizeof(size)) /* Used to decode ioctl numbers in drivers despite the leading underscore... */ #define _IOC_DIR(nr) \ ( (((((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) & (_IOC_WRITE|_IOC_READ)) != 0)? \ (((nr) >> _IOC_DIRSHIFT) & (_IOC_WRITE|_IOC_READ)): \ (((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) ) #define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & _IOC_TYPEMASK) #define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & _IOC_NRMASK) #define _IOC_SIZE(nr) \ ((((((nr) >> _IOC_DIRSHIFT) & _IOC_DIRMASK) & (_IOC_WRITE|_IOC_READ)) == 0)? \ 0: (((nr) >> _IOC_SIZESHIFT) & _IOC_XSIZEMASK)) /* ...and for the PCMCIA... */ #define IOC_IN (_IOC_WRITE << _IOC_DIRSHIFT) #define IOC_OUT (_IOC_READ << _IOC_DIRSHIFT) #define IOC_INOUT ((_IOC_WRITE|_IOC_READ) << _IOC_DIRSHIFT) #define IOCSIZE_MASK (_IOC_XSIZEMASK << _IOC_SIZESHIFT) #define IOCSIZE_SHIFT (_IOC_SIZESHIFT) /* Big T */ #define TCGETA _IOR('T', 1, struct termio) #define TCSETA _IOW('T', 2, struct termio) #define TCSETAW _IOW('T', 3, struct termio) #define TCSETAF _IOW('T', 4, struct termio) #define TCSBRK _IO('T', 5) #define TCXONC _IO('T', 6) #define TCFLSH _IO('T', 7) #define TCGETS _IOR('T', 8, struct termios) #define TCSETS _IOW('T', 9, struct termios) #define TCSETSW _IOW('T', 10, struct termios) #define TCSETSF _IOW('T', 11, struct termios) /* Note that all the ioctls that are not available in Linux have a * double underscore on the front to: a) avoid some programs to * thing we support some ioctls under Linux (autoconfiguration stuff) */ /* Little t */ #define TIOCGETD _IOR('t', 0, int) #define TIOCSETD _IOW('t', 1, int) #define __TIOCHPCL _IO('t', 2) /* SunOS Specific */ #define __TIOCMODG _IOR('t', 3, int) /* SunOS Specific */ #define __TIOCMODS _IOW('t', 4, int) /* SunOS Specific */ #define __TIOCGETP _IOR('t', 8, struct sgttyb) /* SunOS Specific */ #define __TIOCSETP _IOW('t', 9, struct sgttyb) /* SunOS Specific */ #define __TIOCSETN _IOW('t', 10, struct sgttyb) /* SunOS Specific */ #define TIOCEXCL _IO('t', 13) #define TIOCNXCL _IO('t', 14) #define __TIOCFLUSH _IOW('t', 16, int) /* SunOS Specific */ #define __TIOCSETC _IOW('t', 17, struct tchars) /* SunOS Specific */ #define __TIOCGETC _IOR('t', 18, struct tchars) /* SunOS Specific */ #define __TIOCTCNTL _IOW('t', 32, int) /* SunOS Specific */ #define __TIOCSIGNAL _IOW('t', 33, int) /* SunOS Specific */ #define __TIOCSETX _IOW('t', 34, int) /* SunOS Specific */ #define __TIOCGETX _IOR('t', 35, int) /* SunOS Specific */ #define TIOCCONS _IO('t', 36) #define __TIOCSSIZE _IOW('t', 37, struct sunos_ttysize) /* SunOS Specific */ #define __TIOCGSIZE _IOR('t', 38, struct sunos_ttysize) /* SunOS Specific */ #define TIOCGSOFTCAR _IOR('t', 100, int) #define TIOCSSOFTCAR _IOW('t', 101, int) #define __TIOCUCNTL _IOW('t', 102, int) /* SunOS Specific */ #define TIOCSWINSZ _IOW('t', 103, struct winsize) #define TIOCGWINSZ _IOR('t', 104, struct winsize) #define __TIOCREMOTE _IOW('t', 105, int) /* SunOS Specific */ #define TIOCMGET _IOR('t', 106, int) #define TIOCMBIC _IOW('t', 107, int) #define TIOCMBIS _IOW('t', 108, int) #define TIOCMSET _IOW('t', 109, int) #define __TIOCSTART _IO('t', 110) /* SunOS Specific */ #define __TIOCSTOP _IO('t', 111) /* SunOS Specific */ #define TIOCPKT _IOW('t', 112, int) #define TIOCNOTTY _IO('t', 113) #define TIOCSTI _IOW('t', 114, char) #define TIOCOUTQ _IOR('t', 115, int) #define __TIOCGLTC _IOR('t', 116, struct ltchars) /* SunOS Specific */ #define __TIOCSLTC _IOW('t', 117, struct ltchars) /* SunOS Specific */ /* 118 is the non-posix setpgrp tty ioctl */ /* 119 is the non-posix getpgrp tty ioctl */ #define __TIOCCDTR _IO('t', 120) /* SunOS Specific */ #define __TIOCSDTR _IO('t', 121) /* SunOS Specific */ #define TIOCCBRK _IO('t', 122) #define TIOCSBRK _IO('t', 123) #define __TIOCLGET _IOW('t', 124, int) /* SunOS Specific */ #define __TIOCLSET _IOW('t', 125, int) /* SunOS Specific */ #define __TIOCLBIC _IOW('t', 126, int) /* SunOS Specific */ #define __TIOCLBIS _IOW('t', 127, int) /* SunOS Specific */ #define __TIOCISPACE _IOR('t', 128, int) /* SunOS Specific */ #define __TIOCISIZE _IOR('t', 129, int) /* SunOS Specific */ #define TIOCSPGRP _IOW('t', 130, int) #define TIOCGPGRP _IOR('t', 131, int) #define TIOCSCTTY _IO('t', 132) #define TIOCGSID _IOR('t', 133, int) /* Get minor device of a pty master's FD -- Solaris equiv is ISPTM */ #define TIOCGPTN _IOR('t', 134, unsigned int) /* Get Pty Number */ #define TIOCSPTLCK _IOW('t', 135, int) /* Lock/unlock PTY */ /* Little f */ #define FIOCLEX _IO('f', 1) #define FIONCLEX _IO('f', 2) #define FIOASYNC _IOW('f', 125, int) #define FIONBIO _IOW('f', 126, int) #define FIONREAD _IOR('f', 127, int) #define TIOCINQ FIONREAD #define FIOQSIZE _IOR('f', 128, loff_t) /* SCARY Rutgers local SunOS kernel hackery, perhaps I will support it * someday. This is completely bogus, I know... */ #define __TCGETSTAT _IO('T', 200) /* Rutgers specific */ #define __TCSETSTAT _IO('T', 201) /* Rutgers specific */ /* Linux specific, no SunOS equivalent. */ #define TIOCLINUX 0x541C #define TIOCGSERIAL 0x541E #define TIOCSSERIAL 0x541F #define TCSBRKP 0x5425 #define TIOCTTYGSTRUCT 0x5426 #define TIOCSERCONFIG 0x5453 #define TIOCSERGWILD 0x5454 #define TIOCSERSWILD 0x5455 #define TIOCGLCKTRMIOS 0x5456 #define TIOCSLCKTRMIOS 0x5457 #define TIOCSERGSTRUCT 0x5458 /* For debugging only */ #define TIOCSERGETLSR 0x5459 /* Get line status register */ #define TIOCSERGETMULTI 0x545A /* Get multiport config */ #define TIOCSERSETMULTI 0x545B /* Set multiport config */ #define TIOCMIWAIT 0x545C /* Wait input */ #define TIOCGICOUNT 0x545D /* Read serial port inline interrupt counts */ /* Used for packet mode */ #define TIOCPKT_DATA 0 #define TIOCPKT_FLUSHREAD 1 #define TIOCPKT_FLUSHWRITE 2 #define TIOCPKT_STOP 4 #define TIOCPKT_START 8 #define TIOCPKT_NOSTOP 16 #define TIOCPKT_DOSTOP 32 /* Socket-level I/O control calls. */ #define FIOSETOWN 0x8901 #define SIOCSPGRP 0x8902 #define FIOGETOWN 0x8903 #define SIOCGPGRP 0x8904 #define SIOCATMARK 0x8905 #define SIOCGSTAMP 0x8906 /* Get stamp */ dietlibc-0.33~cvs20120325/include/sys/stat.h010064400000000000000000000346701173363226500153050ustar00#ifndef _SYS_STAT_H #define _SYS_STAT_H #include #include #include __BEGIN_DECLS #if defined(__i386__) struct stat { uint32_t st_dev; unsigned long st_ino; uint16_t st_mode; uint16_t st_nlink; uint16_t st_uid; uint16_t st_gid; uint32_t st_rdev; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; unsigned long __unused4; unsigned long __unused5; }; struct stat64 { uint64_t st_dev; unsigned char __pad0[4]; #define STAT64_HAS_BROKEN_ST_INO 1 unsigned long __st_ino; uint32_t st_mode; uint32_t st_nlink; unsigned long st_uid; unsigned long st_gid; uint64_t st_rdev; unsigned char __pad3[4]; __extension__ long long st_size __attribute__((__packed__)); unsigned long st_blksize; uint64_t st_blocks; /* Number 512-byte blocks allocated. */ time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; __extension__ unsigned long long st_ino __attribute__((__packed__)); }; #elif defined(__sparc__) && defined(__arch64__) struct stat { uint32_t st_dev; unsigned long st_ino; uint32_t st_mode; int16_t st_nlink; uint32_t st_uid; uint32_t st_gid; uint32_t st_rdev; long st_size; time_t st_atime; time_t st_mtime; time_t st_ctime; long st_blksize; long st_blocks; unsigned long __unused4[2]; }; struct stat64 { unsigned long st_dev, st_ino, st_nlink; unsigned int st_mode, st_uid, st_gid, __pad0; unsigned long st_rdev; long st_size, st_blksize, st_blocks; unsigned long st_atime,st_atime_nsec,st_mtime,st_mtime_nsec,st_ctime,st_ctime_nsec; long __unused[3]; }; #elif defined(__sparc__) struct stat { uint16_t st_dev; unsigned long st_ino; uint16_t st_mode; int16_t st_nlink; uint16_t st_uid; uint16_t st_gid; uint16_t st_rdev; long st_size; time_t st_atime; unsigned long __unused1; time_t st_mtime; unsigned long __unused2; time_t st_ctime; unsigned long __unused3; long st_blksize; long st_blocks; unsigned long __unused4[2]; }; struct stat64 { uint64_t st_dev, st_ino; uint32_t st_mode, st_nlink, st_uid, st_gid; uint64_t st_rdev; unsigned char __pad3[8]; int64_t st_size; uint32_t st_blksize; unsigned char __pad4[8]; uint32_t st_blocks; time_t st_atime; uint32_t st_atime_nsec; time_t st_mtime; uint32_t st_mtime_nsec; time_t st_ctime; uint32_t st_ctime_nsec; uint32_t __unused4; uint32_t __unused5; }; #elif defined(__alpha__) struct stat { uint32_t st_dev; uint32_t st_ino; uint32_t st_mode; uint32_t st_nlink; uint32_t st_uid; uint32_t st_gid; uint32_t st_rdev; signed long st_size; time_t st_atime; time_t st_mtime; time_t st_ctime; uint32_t st_blksize; int32_t st_blocks; uint32_t st_flags; uint32_t st_gen; }; struct stat64 { unsigned long st_dev; unsigned long st_ino; unsigned long st_rdev; long st_size; unsigned long st_blocks; unsigned int st_mode; unsigned int st_uid; unsigned int st_gid; unsigned int st_blksize; unsigned int st_nlink; unsigned int __pad0; unsigned long st_atime; unsigned long st_atime_nsec; unsigned long st_mtime; unsigned long st_mtime_nsec; unsigned long st_ctime; unsigned long st_ctime_nsec; long __unused[3]; }; #elif defined(__mips__) struct stat { uint32_t st_dev; long st_pad1[3]; /* Reserved for network id */ ino_t st_ino; uint32_t st_mode; int32_t st_nlink; int32_t st_uid; int32_t st_gid; uint32_t st_rdev; long st_pad2[2]; long st_size; long st_pad3; /* * Actually this should be timestruc_t st_atime, st_mtime and st_ctime * but we don't have it under Linux. */ time_t st_atime; long st_atime_nsec; time_t st_mtime; long st_mtime_nsec; time_t st_ctime; long st_ctime_nsec; long st_blksize; long st_blocks; char st_fstype[16]; /* Filesystem type name */ long st_pad4[14]; }; struct stat64 { unsigned long st_dev; unsigned long st_pad0[3]; /* Reserved for st_dev expansion */ __extension__ unsigned long long st_ino; uint32_t st_mode; uint32_t st_nlink; uint32_t st_uid; uint32_t st_gid; unsigned long st_rdev; unsigned long st_pad1[3]; /* Reserved for st_rdev expansion */ __extension__ long long st_size; /* * Actually this should be timestruc_t st_atime, st_mtime and st_ctime * but we don't have it under Linux. */ time_t st_atime; unsigned long reserved0; /* Reserved for st_atime expansion */ time_t st_mtime; unsigned long reserved1; /* Reserved for st_atime expansion */ time_t st_ctime; unsigned long reserved2; /* Reserved for st_atime expansion */ unsigned long st_blksize; unsigned long st_pad2; __extension__ long long st_blocks; }; #elif defined(__powerpc__) || defined(__powerpc64__) #if defined(__powerpc__) && !defined(__powerpc64__) struct stat { dev_t st_dev; ino_t st_ino; mode_t st_mode; nlink_t st_nlink; uid_t st_uid; gid_t st_gid; dev_t st_rdev; off_t st_size; unsigned long st_blksize; unsigned long st_blocks; time_t st_atime; unsigned long __unused1; time_t st_mtime; unsigned long __unused2; time_t st_ctime; unsigned long __unused3; unsigned long __unused4; unsigned long __unused5; }; #else struct stat { unsigned long st_dev; ino_t st_ino; nlink_t st_nlink; uint32_t st_mode; uint32_t st_uid; uint32_t st_gid; unsigned long st_rdev; off_t st_size; unsigned long st_blksize; unsigned long st_blocks; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; unsigned long __unused4; unsigned long __unused5; unsigned long __unused6; }; #endif /* This matches struct stat64 in glibc2.1. */ struct stat64 { __extension__ unsigned long long st_dev; /* Device. */ __extension__ unsigned long long st_ino; /* File serial number. */ uint32_t st_mode; /* File mode. */ uint32_t st_nlink; /* Link count. */ uint32_t st_uid; /* User ID of the file's owner. */ uint32_t st_gid; /* Group ID of the file's group. */ __extension__ unsigned long long st_rdev; /* Device number, if device. */ uint16_t __pad2; __extension__ long long st_size; /* Size of file, in bytes. */ long st_blksize; /* Optimal block size for I/O. */ __extension__ long long st_blocks; /* Number 512-byte blocks allocated. */ time_t st_atime; /* Time of last access. */ unsigned long int __unused1; time_t st_mtime; /* Time of last modification. */ unsigned long int __unused2; time_t st_ctime; /* Time of last status change. */ unsigned long int __unused3; unsigned long int __unused4; unsigned long int __unused5; }; #elif defined(__arm__) struct stat { uint32_t st_dev; unsigned long st_ino; uint16_t st_mode; uint16_t st_nlink; uint16_t st_uid; uint16_t st_gid; uint32_t st_rdev; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; unsigned long __unused4; unsigned long __unused5; }; /* This matches struct stat64 in glibc2.1, hence the absolutely * insane amounts of padding around dev_t's. */ struct stat64 { uint64_t st_dev; unsigned char __pad0[4]; #define STAT64_HAS_BROKEN_ST_INO 1 unsigned long __st_ino; uint32_t st_mode; uint32_t st_nlink; unsigned long st_uid; unsigned long st_gid; uint64_t st_rdev; unsigned char __pad3[4]; __extension__ long long st_size; unsigned long st_blksize; uint64_t st_blocks; /* Number 512-byte blocks allocated. */ time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; __extension__ unsigned long long st_ino; }; #elif defined(__s390__) #if defined(__s390x__) struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; uint32_t st_mode; uint32_t st_uid; uint32_t st_gid; uint32_t __pad1; unsigned long st_rdev; unsigned long st_size; time_t st_atime; unsigned long st_atime_nsec; /* reserved for atime.nanoseconds */ time_t st_mtime; unsigned long st_mtime_nsec; /* reserved for mtime.nanoseconds */ time_t st_ctime; unsigned long st_ctime_nsec; /* reserved for ctime.nanoseconds */ unsigned long st_blksize; long st_blocks; unsigned long __unused[3]; }; #else struct stat { uint16_t st_dev; uint16_t __pad1; unsigned long st_ino; uint16_t st_mode; uint16_t st_nlink; uint16_t st_uid; uint16_t st_gid; uint16_t st_rdev; uint16_t __pad2; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; unsigned long __unused4; unsigned long __unused5; }; #endif struct stat64 { uint64_t st_dev; uint32_t __pad1; #define STAT64_HAS_BROKEN_ST_INO 1 unsigned long __st_ino; uint32_t st_mode; uint32_t st_nlink; unsigned long st_uid; unsigned long st_gid; uint64_t st_rdev; uint32_t __pad3; __extension__ long long st_size; unsigned long st_blksize; unsigned char __pad4[4]; unsigned long __pad5; /* future possible st_blocks high bits */ unsigned long st_blocks; /* Number 512-byte blocks allocated. */ time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; __extension__ unsigned long long st_ino; }; #elif defined(__hppa__) struct stat { unsigned long st_dev; /* dev_t is 32 bits on parisc */ unsigned long st_ino; /* 32 bits */ uint16_t st_mode; /* 16 bits */ uint16_t st_nlink; /* 16 bits */ uint16_t st_reserved1; /* old st_uid */ uint16_t st_reserved2; /* old st_gid */ unsigned long st_rdev; unsigned long st_size; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; long st_blksize; long st_blocks; unsigned long __unused1; /* ACL stuff */ unsigned long __unused2; /* network */ unsigned long __unused3; /* network */ unsigned long __unused4; /* cnodes */ uint16_t __unused5; /* netsite */ int16_t st_fstype; unsigned long st_realdev; uint16_t st_basemode; uint16_t st_spareshort; unsigned long st_uid; unsigned long st_gid; unsigned long st_spare4[3]; }; struct stat64 { unsigned long long st_dev; uint32_t __pad1; #define STAT64_HAS_BROKEN_ST_INO 1 unsigned long __st_ino; unsigned long st_mode; unsigned long st_nlink; unsigned long st_uid; unsigned long st_gid; unsigned long long st_rdev; uint32_t __pad2; unsigned long long st_size; unsigned long st_blksize; unsigned long long st_blocks; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; unsigned long long st_ino; }; #elif defined(__x86_64__) struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; uint32_t st_mode; uint32_t st_uid; uint32_t st_gid; uint32_t __pad0; unsigned long st_rdev; unsigned long st_size; unsigned long st_blksize; unsigned long st_blocks; time_t st_atime; unsigned long st_atime_nsec; time_t st_mtime; unsigned long st_mtime_nsec; time_t st_ctime; unsigned long st_ctime_nsec; long __unused[3]; }; #elif defined(__ia64__) struct stat { unsigned long st_dev; unsigned long st_ino; unsigned long st_nlink; uint32_t st_mode; uint32_t st_uid; uint32_t st_gid; uint32_t __pad; unsigned long st_rdev; unsigned long st_size; time_t st_atime; unsigned long reserved; time_t st_mtime; unsigned long reserved2; time_t st_ctime; unsigned long reserved3; unsigned long st_blksize; long st_blocks; unsigned long pad[3]; }; #endif #define S_IFMT 00170000 #define S_IFSOCK 0140000 #define S_IFLNK 0120000 #define S_IFREG 0100000 #define S_IFBLK 0060000 #define S_IFDIR 0040000 #define S_IFCHR 0020000 #define S_IFIFO 0010000 #define S_ISUID 0004000 #define S_ISGID 0002000 #define S_ISVTX 0001000 #define S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK) #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR) #define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK) #define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO) #define S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK) #define S_IRWXU 00700 #define S_IRUSR 00400 #define S_IWUSR 00200 #define S_IXUSR 00100 #define S_IRWXG 00070 #define S_IRGRP 00040 #define S_IWGRP 00020 #define S_IXGRP 00010 #define S_IRWXO 00007 #define S_IROTH 00004 #define S_IWOTH 00002 #define S_IXOTH 00001 extern int stat(const char *__file, struct stat *__buf) __THROW; extern int fstat(int __fd, struct stat *__buf) __THROW; extern int lstat(const char *__file, struct stat *__buf) __THROW; #if __WORDSIZE == 64 #define __NO_STAT64 #else extern int stat64(const char *__file, struct stat64 *__buf) __THROW; extern int fstat64(int __fd, struct stat64 *__buf) __THROW; extern int lstat64(const char *__file, struct stat64 *__buf) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define lstat lstat64 #define fstat fstat64 #define stat stat64 #define pread pread64 #define pwrite pwrite64 #endif #endif #define major(dev) ({ unsigned long long l=(dev); ((l>>8) & 0xfff) | (l >> 32) & 0xfffff000; }) #define minor(dev) ({ unsigned long long l=(dev); (l & 0xff) | ((l>>12)&0xffffff00); }) #define makedev(maj,min) ({ unsigned long long a=(maj), i=(min); ((a&0xfff)<<8) | (i&0xff) | ((a&~0xfff)<<32) | ((i&0xfffff00)<<12); }) extern int chmod (const char *__file, mode_t __mode) __THROW; extern int fchmod (int __fd, mode_t __mode) __THROW; extern mode_t umask (mode_t __mask) __THROW; extern int mkdir (const char *__path, mode_t __mode) __THROW; extern int mknod (const char *__path, mode_t __mode, dev_t __dev) __THROW; extern int mkfifo (const char *__path, mode_t __mode) __THROW; #define S_IREAD S_IRUSR #define S_IWRITE S_IWUSR #define S_IEXEC S_IXUSR __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/statfs.h010064400000000000000000000067571173363226500156430ustar00#ifndef _SYS_STATFS_H #define _SYS_STATFS_H #include #include #include __BEGIN_DECLS typedef struct { int32_t __val[2]; } __kernel_fsid_t; #if defined(__mips64__) struct statfs { int64_t f_type; #define f_fstyp f_type int64_t f_bsize; int64_t f_frsize; /* Fragment size - unsupported */ int64_t f_blocks; int64_t f_bfree; int64_t f_files; int64_t f_ffree; int64_t f_bavail; /* Linux specials */ __kernel_fsid_t f_fsid; int64_t f_namelen; int64_t f_spare[6]; }; struct statfs64 { /* Same as struct statfs */ int64_t f_type; int64_t f_bsize; int64_t f_frsize; /* Fragment size - unsupported */ int64_t f_blocks; int64_t f_bfree; int64_t f_files; int64_t f_ffree; int64_t f_bavail; /* Linux specials */ __kernel_fsid_t f_fsid; int64_t f_namelen; int64_t f_spare[6]; }; #elif defined(__mips__) struct statfs { int32_t f_type; #define f_fstyp f_type int32_t f_bsize; int32_t f_frsize; /* Fragment size - unsupported */ int32_t f_blocks; int32_t f_bfree; int32_t f_files; int32_t f_ffree; int32_t f_bavail; /* Linux specials */ __kernel_fsid_t f_fsid; int32_t f_namelen; int32_t f_spare[6]; }; struct statfs64 { uint32_t f_type; uint32_t f_bsize; uint32_t f_frsize; /* Fragment size - unsupported */ uint32_t __pad; uint64_t f_blocks; uint64_t f_bfree; uint64_t f_files; uint64_t f_ffree; uint64_t f_bavail; __kernel_fsid_t f_fsid; uint32_t f_namelen; uint32_t f_spare[6]; }; #elif defined(__s390x__) /* S/390 64-bit mode */ struct statfs { int32_t f_type; int32_t f_bsize; int64_t f_blocks; int64_t f_bfree; int64_t f_bavail; int64_t f_files; int64_t f_ffree; __kernel_fsid_t f_fsid; int32_t f_namelen; int32_t f_frsize; int32_t f_spare[5]; }; struct statfs64 { int32_t f_type; int32_t f_bsize; int64_t f_blocks; int64_t f_bfree; int64_t f_bavail; int64_t f_files; int64_t f_ffree; __kernel_fsid_t f_fsid; int32_t f_namelen; int32_t f_frsize; int32_t f_spare[5]; }; #elif __WORDSIZE == 64 /* generic 64-bit */ struct statfs { int64_t f_type; int64_t f_bsize; int64_t f_blocks; int64_t f_bfree; int64_t f_bavail; int64_t f_files; int64_t f_ffree; __kernel_fsid_t f_fsid; int64_t f_namelen; int64_t f_frsize; int64_t f_spare[5]; }; struct statfs64 { int64_t f_type; int64_t f_bsize; int64_t f_blocks; int64_t f_bfree; int64_t f_bavail; int64_t f_files; int64_t f_ffree; __kernel_fsid_t f_fsid; int64_t f_namelen; int64_t f_frsize; int64_t f_spare[5]; }; #else /* generic 32-bit */ struct statfs { uint32_t f_type; uint32_t f_bsize; uint32_t f_blocks; uint32_t f_bfree; uint32_t f_bavail; uint32_t f_files; uint32_t f_ffree; __kernel_fsid_t f_fsid; uint32_t f_namelen; uint32_t f_frsize; uint32_t f_spare[5]; }; struct statfs64 { uint32_t f_type; uint32_t f_bsize; uint64_t f_blocks; uint64_t f_bfree; uint64_t f_bavail; uint64_t f_files; uint64_t f_ffree; __kernel_fsid_t f_fsid; uint32_t f_namelen; uint32_t f_frsize; uint32_t f_spare[5]; }; #endif int statfs(const char *path, struct statfs *buf) __THROW; int fstatfs(int fd, struct statfs *buf) __THROW; #if __WORDSIZE == 32 int statfs64(const char *path, struct statfs64 *buf) __THROW; int fstatfs64(int fd, struct statfs64 *buf) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define statfs statfs64 #define fstatfs fstatfs64 #endif #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/statvfs.h010064400000000000000000000040521173363226500160130ustar00#ifndef _SYS_STATVFS_H #define _SYS_STATVFS_H #include #include __BEGIN_DECLS struct statvfs { unsigned long f_bsize; /* file system block size */ unsigned long f_frsize; /* fragment size */ fsblkcnt_t f_blocks; /* size of fs in f_frsize units */ fsblkcnt_t f_bfree; /* # free blocks */ fsblkcnt_t f_bavail; /* # free blocks for non-root */ fsfilcnt_t f_files; /* # inodes */ fsfilcnt_t f_ffree; /* # free inodes */ fsfilcnt_t f_favail; /* # free inodes for non-root */ unsigned long f_fsid; /* file system ID */ unsigned long f_flag; /* mount flags */ unsigned long f_namemax; /* maximum filename length */ }; int statvfs(const char *path, struct statvfs *buf) __THROW; int fstatvfs(int fd, struct statvfs *buf) __THROW; /* Definitions for the flag in `f_flag'. These definitions should be kept in sync with the definitions in . */ enum { ST_RDONLY = 1, /* Mount read-only. */ #define ST_RDONLY ST_RDONLY ST_NOSUID = 2 /* Ignore suid and sgid bits. */ #define ST_NOSUID ST_NOSUID #ifdef __USE_GNU , ST_NODEV = 4, /* Disallow access to device special files. */ # define ST_NODEV ST_NODEV ST_NOEXEC = 8, /* Disallow program execution. */ # define ST_NOEXEC ST_NOEXEC ST_SYNCHRONOUS = 16, /* Writes are synced at once. */ # define ST_SYNCHRONOUS ST_SYNCHRONOUS ST_MANDLOCK = 64, /* Allow mandatory locks on an FS. */ # define ST_MANDLOCK ST_MANDLOCK ST_WRITE = 128, /* Write on file/directory/symlink. */ # define ST_WRITE ST_WRITE ST_APPEND = 256, /* Append-only file. */ # define ST_APPEND ST_APPEND ST_IMMUTABLE = 512, /* Immutable file. */ # define ST_IMMUTABLE ST_IMMUTABLE ST_NOATIME = 1024, /* Do not update access times. */ # define ST_NOATIME ST_NOATIME ST_NODIRATIME = 2048, /* Do not update directory access times. */ # define ST_NODIRATIME ST_NODIRATIME ST_RELATIME = 4096 /* Update atime relative to mtime/ctime. */ # define ST_RELATIME ST_RELATIME #endif /* Use GNU. */ }; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/swap.h010064400000000000000000000006151173363226500152740ustar00#ifndef _SYS_SWAP_H #define _SYS_SWAP_H #include #define SWAP_FLAG_PREFER 0x8000 /* set if swap priority specified */ #define SWAP_FLAG_PRIO_MASK 0x7fff #define SWAP_FLAG_PRIO_SHIFT 0 #define MAX_SWAPFILES 32 __BEGIN_DECLS extern int swapon (const char *path, int flags) __THROW; extern int swapoff (const char *path) __THROW; __END_DECLS #endif /* _SYS_SWAP_H */ dietlibc-0.33~cvs20120325/include/sys/syscall.h010064400000000000000000000001461173363226500157730ustar00#ifndef _SYSCALL_H #define _SYSCALL_H #include int syscall(int number, ...); #endif dietlibc-0.33~cvs20120325/include/sys/sysctl.h010064400000000000000000000003071173363226500156410ustar00#ifndef _SYS_SYSCTL_H_ #define _SYS_SYSCTL_H_ #include #include __BEGIN_DECLS extern int sysctl (int *, int, void *, size_t *, void *, size_t); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/sysinfo.h010064400000000000000000000017471173363226500160230ustar00#ifndef _SYS_SYSINFO_H #define _SYS_SYSINFO_H #include __BEGIN_DECLS #define SI_LOAD_SHIFT 16 struct sysinfo { long uptime; /* Seconds since boot */ unsigned long loads[3]; /* 1, 5, and 15 minute load averages */ unsigned long totalram; /* Total usable main memory size */ unsigned long freeram; /* Available memory size */ unsigned long sharedram; /* Amount of shared memory */ unsigned long bufferram; /* Memory used by buffers */ unsigned long totalswap; /* Total swap space size */ unsigned long freeswap; /* swap space still available */ unsigned short procs; /* Number of current processes */ unsigned short pad; /* explicit padding */ unsigned long totalhigh; /* Total high memory size */ unsigned long freehigh; /* Available high memory size */ unsigned int mem_unit; /* Memory unit size in bytes */ char _f[20-2*sizeof(long)-sizeof(int)]; /* Padding: libc5 uses this.. */ }; int sysinfo(struct sysinfo *info) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/syslog.h010064400000000000000000000072321173363226500156440ustar00#ifndef _SYS_SYSLOG_H #define _SYS_SYSLOG_H 1 #include #include __BEGIN_DECLS #define _PATH_LOG "/dev/log" /* * priorities/facilities are encoded into a single 32-bit quantity, where the * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility * (0-big number). Both the priorities and the facilities map roughly * one-to-one to strings in the syslogd(8) source code. This mapping is * included in this file. * * priorities (these are ordered) */ #define LOG_EMERG 0 /* system is unusable */ #define LOG_ALERT 1 /* action must be taken immediately */ #define LOG_CRIT 2 /* critical conditions */ #define LOG_ERR 3 /* error conditions */ #define LOG_WARNING 4 /* warning conditions */ #define LOG_NOTICE 5 /* normal but significant condition */ #define LOG_INFO 6 /* informational */ #define LOG_DEBUG 7 /* debug-level messages */ #define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ /* extract priority */ #define LOG_PRI(p) ((p) & LOG_PRIMASK) #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) /* facility codes */ #define LOG_KERN (0<<3) /* kernel messages */ #define LOG_USER (1<<3) /* random user-level messages */ #define LOG_MAIL (2<<3) /* mail system */ #define LOG_DAEMON (3<<3) /* system daemons */ #define LOG_AUTH (4<<3) /* security/authorization messages */ #define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ #define LOG_LPR (6<<3) /* line printer subsystem */ #define LOG_NEWS (7<<3) /* network news subsystem */ #define LOG_UUCP (8<<3) /* UUCP subsystem */ #define LOG_CRON (9<<3) /* clock daemon */ #define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ #define LOG_FTP (11<<3) /* ftp daemon */ /* other codes through 15 reserved for system use */ #define LOG_LOCAL0 (16<<3) /* reserved for local use */ #define LOG_LOCAL1 (17<<3) /* reserved for local use */ #define LOG_LOCAL2 (18<<3) /* reserved for local use */ #define LOG_LOCAL3 (19<<3) /* reserved for local use */ #define LOG_LOCAL4 (20<<3) /* reserved for local use */ #define LOG_LOCAL5 (21<<3) /* reserved for local use */ #define LOG_LOCAL6 (22<<3) /* reserved for local use */ #define LOG_LOCAL7 (23<<3) /* reserved for local use */ #define LOG_NFACILITIES 24 /* current number of facilities */ #define LOG_FACMASK 0x03f8 /* mask to extract facility part */ /* facility of pri */ #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) /* * arguments to setlogmask. */ #define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ /* * Option flags for openlog. * * LOG_ODELAY no longer does anything. * LOG_NDELAY is the inverse of what it used to be. */ #define LOG_PID 0x01 /* log the pid with each message */ #define LOG_CONS 0x02 /* log on the console if errors in sending */ #define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ #define LOG_NDELAY 0x08 /* don't delay open */ #define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ #define LOG_PERROR 0x20 /* log to stderr as well */ /* Open connection to system logger. */ /* against the glibc-routine ident has not to be const ! */ /* instead ident is limited to 80 characters ! */ void openlog (const char *ident, int option, int facility); void closelog (void) __THROW; int setlogmask (int mask) __THROW; void syslog (int priority, const char *format, ...) __THROW; void vsyslog (int priority, const char *format, va_list arg_ptr) __THROW; /* yuck yuck yuck, only needed for syslogd. */ typedef struct _code { const char *const c_name; int c_val; } CODE; extern CODE prioritynames[]; extern CODE facilitynames[]; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/sysmacros.h010064400000000000000000000001111173363226500163340ustar00#ifndef _SYSMACROS_H #define _SYSMACROS_H #include #endif dietlibc-0.33~cvs20120325/include/sys/time.h010064400000000000000000000046501173363226500152630ustar00#ifndef _SYS_TIME_H #define _SYS_TIME_H 1 #include #include __BEGIN_DECLS struct timespec { time_t tv_sec; /* seconds */ long tv_nsec; /* nanoseconds */ }; struct timeval { time_t tv_sec; /* seconds */ suseconds_t tv_usec; /* microseconds */ }; struct timezone { int tz_minuteswest; /* minutes west of Greenwich */ int tz_dsttime; /* type of dst correction */ }; #include #define ITIMER_REAL 0 #define ITIMER_VIRTUAL 1 #define ITIMER_PROF 2 struct itimerspec { struct timespec it_interval; /* timer period */ struct timespec it_value; /* timer expiration */ }; struct itimerval { struct timeval it_interval; /* timer interval */ struct timeval it_value; /* current value */ }; #if defined _GNU_SOURCE || defined _BSD_SOURCE typedef struct timezone *__timezone_ptr_t; #else typedef void *__timezone_ptr_t; #endif int getitimer(int which, struct itimerval *value) __THROW; int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue) __THROW; int gettimeofday(struct timeval *tv, struct timezone *tz) __THROW; int settimeofday(const struct timeval *tv , const struct timezone *tz) __THROW; extern int adjtime (const struct timeval *delta, struct timeval *olddelta) __THROW; struct tm { int tm_sec; /* Seconds. [0-60] (1 leap second) */ int tm_min; /* Minutes. [0-59] */ int tm_hour; /* Hours. [0-23] */ int tm_mday; /* Day. [1-31] */ int tm_mon; /* Month. [0-11] */ int tm_year; /* Year - 1900. */ int tm_wday; /* Day of week. [0-6] */ int tm_yday; /* Days in year.[0-365] */ int tm_isdst; /* DST. [-1/0/1]*/ long int tm_gmtoff; /* Seconds east of UTC. */ const char *tm_zone; /* Timezone abbreviation. */ }; #ifdef _BSD_SOURCE /* another wonderful BSD invention... :( */ #define timercmp(a,b,CMP) (((a)->tv_sec == (b)->tv_sec) ? ((a)->tv_usec CMP (b)->tv_usec) : ((a)->tv_sec CMP (b)->tv_sec)) #define timerclear(x) ((x)->tv_sec=(x)->tv_usec=0) #define timeradd(a,b,x) do { (x)->tv_sec=(a)->tv_sec+(b)->tv_sec; if (((x)->tv_usec=(a)->tv_usec+(b)->tv_usec)>=1000000) { ++(x)->tv_sec; (x)->tv_usec-=1000000; } } while (0) #define timersub(a,b,x) do { (x)->tv_sec=(a)->tv_sec-(b)->tv_sec; if (((x)->tv_usec=(a)->tv_usec-(b)->tv_usec)<0) { --(x)->tv_sec; (x)->tv_usec+=1000000; } } while (0) #define timerisset(x) ((x)->tv_sec || (x)->tv_usec) int utimes(const char * filename, struct timeval * tvp); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/timeb.h010064400000000000000000000003571173363226500154250ustar00#ifndef __SYS_TIMEB_H #define __SYS_TIMEB_H 1 #include __BEGIN_DECLS struct timeb { time_t time; unsigned short millitm; short timezone; short dstflag; }; int ftime(struct timeb *tp); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/timerfd.h010064400000000000000000000005551173363226500157570ustar00#ifndef _SYS_TIMERFD_H #define _SYS_TIMERFD_H #include enum { TFD_TIMER_ABSTIME = 1 }; __BEGIN_DECLS int timerfd_create (clockid_t clock_id, int flags) __THROW; int timerfd_settime (int ufd, int flags, const struct itimerspec *utmr, struct itimerspec *otmr) __THROW; int timerfd_gettime (int ufd, struct itimerspec *otmr) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/times.h010064400000000000000000000004111173363226500154350ustar00#ifndef _SYS_TIMES_H #define _SYS_TIMES_H #include #include __BEGIN_DECLS struct tms { clock_t tms_utime; clock_t tms_stime; clock_t tms_cutime; clock_t tms_cstime; }; clock_t times(struct tms *buf) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/timex.h010064400000000000000000000041041173363226500154450ustar00#ifndef _SYS_TIMEX_H #define _SYS_TIMEX_H #include #include __BEGIN_DECLS struct timex { uint32_t modes; /* mode selector */ long int offset; /* time offset (usec) */ long int freq; /* frequency offset (scaled ppm) */ long int maxerror; /* maximum error (usec) */ long int esterror; /* estimated error (usec) */ int32_t status; /* clock command/status */ long int constant; /* pll time constant */ long int precision; /* clock precision (usec) (read only) */ long int tolerance; /* clock frequency tolerance (ppm) (read only) */ struct timeval time; /* (read only) */ long int tick; /* (modified) usecs between clock ticks */ long int ppsfreq; /* pps frequency (scaled ppm) (ro) */ long int jitter; /* pps jitter (us) (ro) */ int32_t shift; /* interval duration (s) (shift) (ro) */ long int stabil; /* pps stability (scaled ppm) (ro) */ long int jitcnt; /* jitter limit exceeded (ro) */ long int calcnt; /* calibration intervals (ro) */ long int errcnt; /* calibration errors (ro) */ long int stbcnt; /* stability limit exceeded (ro) */ /* ??? */ int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; int32_t :32; }; #define ADJ_OFFSET 0x0001 /* time offset */ #define ADJ_FREQUENCY 0x0002 /* frequency offset */ #define ADJ_MAXERROR 0x0004 /* maximum time error */ #define ADJ_ESTERROR 0x0008 /* estimated time error */ #define ADJ_STATUS 0x0010 /* clock status */ #define ADJ_TIMECONST 0x0020 /* pll time constant */ #define ADJ_TICK 0x4000 /* tick value */ #define ADJ_OFFSET_SINGLESHOT 0x8001 /* old-fashioned adjtime */ #define TIME_OK 0 /* clock synchronized */ #define TIME_INS 1 /* insert leap second */ #define TIME_DEL 2 /* delete leap second */ #define TIME_OOP 3 /* leap second in progress */ #define TIME_WAIT 4 /* leap second has occurred */ #define TIME_BAD 5 /* clock not synchronized */ int adjtimex(struct timex *buf); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/tls.h010064400000000000000000000024441173363226500151260ustar00#ifndef _SYS_TLS_H #define _SYS_TLS_H #include #include #include /* Type for the dtv. */ typedef union dtv { size_t counter; struct { void *val; bool is_static; } pointer; } dtv_t; typedef struct { void *tcb; /* Pointer to the TCB. Not necessary the thread descriptor used by libpthread. */ dtv_t *dtv; void *self; /* Pointer to the thread descriptor. */ int multiple_threads; #ifdef __x86_64__ int gscope_flag; #endif uintptr_t sysinfo; uintptr_t stack_guard; uintptr_t pointer_guard; #ifdef __i386__ int gscope_flag; #endif } tcbhead_t; tcbhead_t* __get_cur_tcb(void) __THROW; #if defined(__i386__) struct user_desc { unsigned int entry_number; unsigned long base_addr; unsigned int limit; unsigned int seg_32bit:1; unsigned int contents:2; unsigned int read_exec_only:1; unsigned int limit_in_pages:1; unsigned int seg_not_present:1; unsigned int useable:1; }; int set_thread_area(struct user_desc* uinfo); #elif defined(__x86_64__) #define ARCH_SET_GS 0x1001 #define ARCH_SET_FS 0x1002 #define ARCH_GET_FS 0x1003 #define ARCH_GET_GS 0x1004 int arch_prctl(unsigned int what, void* where); #else #warning "need proper sys/tls.h for this platform" #endif #endif dietlibc-0.33~cvs20120325/include/sys/types.h010064400000000000000000000121011173363226500154570ustar00#ifndef _SYS_TYPES_H #define _SYS_TYPES_H #include #include __BEGIN_DECLS typedef unsigned long int blkcnt_t; /* Used for file block counts */ typedef unsigned long int blksize_t; /* Used for block sizes */ typedef unsigned long int clock_t; /* Used for system times in clock ticks or CLOCKS_PER_SEC (see ). */ typedef uint64_t fsblkcnt_t; typedef uint64_t fsfilcnt_t; /* TODO: pthread_attr_t Used to identify a thread attribute object. pthread_cond_t Used for condition variables. pthread_condattr_t Used to identify a condition attribute object. pthread_key_t Used for thread-specific data keys. pthread_mutex_t Used for mutexes. pthread_mutexattr_t Used to identify a mutex attribute object. pthread_once_t Used for dynamic package initialisation. pthread_rwlock_t Used for read-write locks. pthread_rwlockattr_t Used for read-write lock attributes. pthread_t Used to identify a thread. */ #if defined(__alpha__) || defined(__ia64__) || defined(__sparc64__) || defined(__s390x__) typedef uint32_t dev_t; /* Used for device IDs. */ typedef uint32_t gid_t; /* Used for group IDs. */ typedef uint32_t mode_t; /* Used for some file attributes. */ typedef uint32_t nlink_t; /* Used for link counts. */ typedef uint32_t uid_t; /* Used for user IDs. */ #elif defined(__arm__) || defined(__i386__) || defined(__sparc__) || defined(__s390__) /* make sure __s390x__ hits before __s390__ */ typedef uint32_t dev_t; typedef uint16_t gid_t; typedef uint16_t mode_t; typedef uint16_t nlink_t; typedef uint16_t uid_t; #elif defined(__hppa__) typedef uint32_t dev_t; typedef uint32_t gid_t; typedef uint16_t mode_t; typedef uint16_t nlink_t; typedef uint32_t uid_t; #elif defined(__mips__) typedef uint32_t dev_t; typedef int32_t gid_t; typedef uint32_t mode_t; typedef int32_t nlink_t; typedef int32_t uid_t; #elif defined(__powerpc__) && !defined(__powerpc64__) typedef uint32_t dev_t; typedef uint32_t gid_t; typedef uint32_t mode_t; typedef uint16_t nlink_t; typedef uint32_t uid_t; #elif defined(__powerpc64__) || defined(__x86_64__) typedef unsigned long dev_t; typedef uint32_t gid_t; typedef uint32_t mode_t; typedef unsigned long nlink_t; typedef uint32_t uid_t; #endif typedef int32_t id_t; /* Used as a general identifier; can be used to contain at least a pid_t, uid_t or a gid_t. */ typedef unsigned long ino_t; /* Used for file serial numbers. */ typedef int32_t key_t; /* Used for interprocess communication. */ typedef int32_t pid_t; /* Used for process IDs and process group IDs. */ typedef signed long ssize_t; /* Used for a count of bytes or an error indication. */ typedef signed long suseconds_t; /* Used for time in microseconds. */ typedef signed long time_t; /* Used for time in seconds. */ typedef signed long useconds_t; /* Used for time in microseconds. */ /* non-susv2 types: */ __extension__ typedef signed long long loff_t; /* 64-bit offset */ __extension__ typedef signed long long off64_t; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 typedef off64_t off_t; #else typedef signed long off_t; /* Used for file sizes. */ #endif __extension__ typedef unsigned long long ino64_t; __extension__ typedef signed long long blkcnt64_t; typedef uint32_t uid32_t; typedef uint32_t gid32_t; typedef int32_t clockid_t; typedef int32_t timer_t; typedef long int fpos_t; #define __socklen_t_defined typedef uint32_t socklen_t; typedef uint16_t sa_family_t; #ifdef _BSD_SOURCE /* die, BSD, die! */ typedef char* caddr_t __attribute_dontuse__; typedef unsigned char u_char __attribute_dontuse__; typedef unsigned short u_short __attribute_dontuse__; typedef unsigned int u_int __attribute_dontuse__; typedef unsigned char uchar __attribute_dontuse__; typedef unsigned short ushort __attribute_dontuse__; typedef unsigned int uint __attribute_dontuse__; typedef uint32_t u_long __attribute_dontuse__; typedef uint32_t n_long __attribute_dontuse__; typedef uint32_t n_time __attribute_dontuse__; typedef uint16_t n_short __attribute_dontuse__; typedef uint32_t ulong __attribute_dontuse__; typedef uint32_t nlong __attribute_dontuse__; typedef uint32_t ntime __attribute_dontuse__; typedef uint16_t nshort __attribute_dontuse__; /* never heard of these two, but dump uses them */ #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef int64_t quad_t __attribute_dontuse__; typedef uint64_t u_quad_t __attribute_dontuse__; #endif typedef long daddr_t __attribute_dontuse__; typedef daddr_t __daddr_t __attribute_dontuse__; #endif #ifdef _GNU_SOURCE typedef uint8_t u_int8_t __attribute_dontuse__; typedef uint16_t u_int16_t __attribute_dontuse__; typedef uint32_t u_int32_t __attribute_dontuse__; #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L typedef uint64_t u_int64_t __attribute_dontuse__; #endif #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/ucontext.h010064400000000000000000000053731173363226500162010ustar00#ifndef _SYS_UCONTEXT_H #define _SYS_UCONTEXT_H #include #include __BEGIN_DECLS #if !defined(__sparc__) && !defined(__sparc64__) typedef struct sigcontext mcontext_t; #endif #if defined(__i386__) || defined(__arm__) || defined(__mips__) || defined(__mips64__) || defined(__powerpc__) || defined(__powerpc64__) || defined(__hppa__) struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ }; #elif defined(__alpha__) struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; unsigned long uc_osf_sigmask; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ }; #elif defined(__sparc__) || defined(__sparc64__) #define MC_TSTATE 0 #define MC_PC 1 #define MC_NPC 2 #define MC_Y 3 #define MC_G1 4 #define MC_G2 5 #define MC_G3 6 #define MC_G4 7 #define MC_G5 8 #define MC_G6 9 #define MC_G7 10 #define MC_O0 11 #define MC_O1 12 #define MC_O2 13 #define MC_O3 14 #define MC_O4 15 #define MC_O5 16 #define MC_O6 17 #define MC_O7 18 #define MC_NGREG 19 typedef unsigned long mc_greg_t; typedef mc_greg_t mc_gregset_t[MC_NGREG]; #define MC_MAXFPQ 16 struct mc_fq { unsigned long *mcfq_addr; unsigned int mcfq_insn; }; typedef struct mc_fpu { union { unsigned int sregs[32]; unsigned long dregs[32]; long double qregs[16]; } mcfpu_fregs; unsigned long mcfpu_fsr; unsigned long mcfpu_fprs; unsigned long mcfpu_gsr; struct mc_fq *mcfpu_fq; unsigned char mcfpu_qcnt; unsigned char mcfpu_qentsz; unsigned char mcfpu_enab; } mc_fpu_t; typedef struct { mc_gregset_t mc_gregs; mc_greg_t mc_fp; mc_greg_t mc_i7; mc_fpu_t mc_fpregs; } mcontext_t; struct ucontext { struct ucontext *uc_link; unsigned long uc_flags; sigset_t uc_sigmask; mcontext_t uc_mcontext; }; #elif defined(__s390__) struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; _sigregs uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ }; #elif defined(__ia64__) /* oh my god is this ugly! --fefe*/ struct ucontext { struct sigcontext uc_mcontext; }; #define uc_link uc_mcontext.sc_gr[0] /* wrong type; nobody cares */ #define uc_sigmask uc_mcontext.sc_sigmask #define uc_stack uc_mcontext.sc_stack #elif defined(__x86_64__) struct ucontext { unsigned long uc_flags; struct ucontext *uc_link; stack_t uc_stack; struct sigcontext uc_mcontext; sigset_t uc_sigmask; /* mask last for extensibility */ }; #else #error NEED TO PORT ! #endif typedef struct ucontext ucontext_t; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/uio.h010064400000000000000000000004611173363226500151150ustar00#ifndef _SYS_UIO #define _SYS_UIO 1 #include __BEGIN_DECLS /* I have no idea why susv3 specifies count as int instead of size_t */ ssize_t readv(int filedes, const struct iovec *vector, int count); ssize_t writev(int filedes, const struct iovec *vector, int count); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/un.h010064400000000000000000000003731173363226500147450ustar00#ifndef _SYS_UN_H #define _SYS_UN_H #include __BEGIN_DECLS #define UNIX_PATH_MAX 108 struct sockaddr_un { sa_family_t sun_family; /* AF_UNIX */ char sun_path[UNIX_PATH_MAX]; /* pathname */ }; __END_DECLS #endif /* sys/un.h */ dietlibc-0.33~cvs20120325/include/sys/utsname.h010064400000000000000000000021021173363226500157670ustar00#ifndef _SYS_UTSNAME_H #define _SYS_UTSNAME_H 1 #include __BEGIN_DECLS /* Length of the entries in `struct utsname' is 65. */ #define _UTSNAME_LENGTH 65 #define _UTSNAME_NODENAME_LENGTH _UTSNAME_LENGTH /* Linux provides as additional information in the `struct utsname' the name of the current domain. Define _UTSNAME_DOMAIN_LENGTH to a value != 0 to activate this entry. */ #define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH struct utsname { /* Name of the implementation of the operating system. */ char sysname[_UTSNAME_LENGTH]; /* Name of this node on the network. */ char nodename[_UTSNAME_NODENAME_LENGTH]; /* Current release level of this implementation. */ char release[_UTSNAME_LENGTH]; /* Current version level of this release. */ char version[_UTSNAME_LENGTH]; /* Name of the hardware type the system is running on. */ char machine[_UTSNAME_LENGTH]; /* Name of the domain of this node on the network. */ char domainname[_UTSNAME_DOMAIN_LENGTH]; }; extern int uname (struct utsname *__name) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/vfs.h010064400000000000000000000001071173363226500151140ustar00#ifndef _SYS_VFS_H #define _SYS_VFS_H #include #endif dietlibc-0.33~cvs20120325/include/sys/vm86.h010064400000000000000000000065441173363226500151310ustar00#ifndef _SYS_VM86_H #define _SYS_VM86_H #include #include /* * I'm guessing at the VIF/VIP flag usage, but hope that this is how * the Pentium uses them. Linux will return from vm86 mode when both * VIF and VIP is set. * * On a Pentium, we could probably optimize the virtual flags directly * in the eflags register instead of doing it "by hand" in vflags... * * Linus */ #define TF_MASK 0x00000100 #define IF_MASK 0x00000200 #define IOPL_MASK 0x00003000 #define NT_MASK 0x00004000 #define VM_MASK 0x00020000 #define AC_MASK 0x00040000 #define VIF_MASK 0x00080000 /* virtual interrupt flag */ #define VIP_MASK 0x00100000 /* virtual interrupt pending */ #define ID_MASK 0x00200000 #define BIOSSEG 0x0f000 #define CPU_086 0 #define CPU_186 1 #define CPU_286 2 #define CPU_386 3 #define CPU_486 4 #define CPU_586 5 /* * Return values for the 'vm86()' system call */ #define VM86_TYPE(retval) ((retval) & 0xff) #define VM86_ARG(retval) ((retval) >> 8) #define VM86_SIGNAL 0 /* return due to signal */ #define VM86_UNKNOWN 1 /* unhandled GP fault - IO-instruction or similar */ #define VM86_INTx 2 /* int3/int x instruction (ARG = x) */ #define VM86_STI 3 /* sti/popf/iret instruction enabled virtual interrupts */ /* * Additional return values when invoking new vm86() */ #define VM86_PICRETURN 4 /* return due to pending PIC request */ #define VM86_TRAP 6 /* return due to DOS-debugger request */ /* * function codes when invoking new vm86() */ #define VM86_PLUS_INSTALL_CHECK 0 #define VM86_ENTER 1 #define VM86_ENTER_NO_BYPASS 2 #define VM86_REQUEST_IRQ 3 #define VM86_FREE_IRQ 4 #define VM86_GET_IRQ_BITS 5 #define VM86_GET_AND_RESET_IRQ 6 /* * This is the stack-layout seen by the user space program when we have * done a translation of "SAVE_ALL" from vm86 mode. The real kernel layout * is 'kernel_vm86_regs' (see below). */ struct vm86_regs { /* * normal regs, with special meaning for the segment descriptors.. */ int32_t ebx; int32_t ecx; int32_t edx; int32_t esi; int32_t edi; int32_t ebp; int32_t eax; int32_t __null_ds; int32_t __null_es; int32_t __null_fs; int32_t __null_gs; int32_t orig_eax; int32_t eip; uint16_t cs, __csh; int32_t eflags; int32_t esp; uint16_t ss, __ssh; /* * these are specific to v86 mode: */ uint16_t es, __esh; uint16_t ds, __dsh; uint16_t fs, __fsh; uint16_t gs, __gsh; }; struct revectored_struct { uint32_t __map[8]; /* 256 bits */ }; struct vm86_struct { struct vm86_regs regs; uint32_t flags; uint32_t screen_bitmap; uint32_t cpu_type; struct revectored_struct int_revectored; struct revectored_struct int21_revectored; }; /* * flags masks */ #define VM86_SCREEN_BITMAP 0x0001 struct vm86plus_info_struct { uint32_t force_return_for_pic:1; uint32_t vm86dbg_active:1; /* for debugger */ uint32_t vm86dbg_TFpendig:1; /* for debugger */ uint32_t unused:28; uint32_t is_vm86pus:1; /* for vm86 internal use */ uint8_t vm86dbg_intxxtab[32]; /* for debugger */ }; struct vm86plus_struct { struct vm86_regs regs; uint32_t flags; uint32_t screen_bitmap; uint32_t cpu_type; struct revectored_struct int_revectored; struct revectored_struct int21_revectored; struct vm86plus_info_struct vm86plus; }; __BEGIN_DECLS /* Enter virtual 8086 mode. */ extern int vm86 (uint32_t __subfunction, struct vm86plus_struct *__info) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sys/wait.h010064400000000000000000000034751173363226500152750ustar00#ifndef _SYS_WAIT_H #define _SYS_WAIT_H #include #include __BEGIN_DECLS #define WNOHANG 0x00000001 #define WUNTRACED 0x00000002 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads in this group */ #define __WALL 0x40000000 /* Wait on all children, regardless of type */ #define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */ /* If WIFEXITED(STATUS), the low-order 8 bits of the status. */ #define __WEXITSTATUS(status) (((status) & 0xff00) >> 8) #define WEXITSTATUS __WEXITSTATUS /* If WIFSIGNALED(STATUS), the terminating signal. */ #define __WTERMSIG(status) ((status) & 0x7f) #define WTERMSIG __WTERMSIG /* If WIFSTOPPED(STATUS), the signal that stopped the child. */ #define __WSTOPSIG(status) __WEXITSTATUS(status) #define WSTOPSIG __WSTOPSIG /* Nonzero if STATUS indicates normal termination. */ #define WIFEXITED(status) (__WTERMSIG(status) == 0) /* Nonzero if STATUS indicates termination by a signal. */ #define WIFSIGNALED(status) (!WIFSTOPPED(status) && !WIFEXITED(status)) /* Nonzero if STATUS indicates the child is stopped. */ #define WIFSTOPPED(status) (((status) & 0xff) == 0x7f) /* Nonzero if STATUS indicates the child dumped core. */ #define WCOREDUMP(status) ((status) & 0x80) #ifdef _BSD_SOURCE #define W_STOPCODE(sig) ((sig) << 8 | 0x7f) #endif pid_t wait(int *status) __THROW; pid_t waitpid(pid_t pid, int *status, int options) __THROW; pid_t wait3(int *status, int options, struct rusage *rusage) __THROW; pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage) __THROW; typedef enum { P_ALL, /* Wait for any child. */ P_PID, /* Wait for specified process. */ P_PGID /* Wait for members of process group. */ } idtype_t; int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/sysexits.h010064400000000000000000000006671173363226500154060ustar00#ifndef _SYSEXITS_H #define _SYSEXITS_H 1 #define EX_OK 0 #define EX__BASE 64 #define EX_USAGE 64 #define EX_DATAERR 65 #define EX_NOINPUT 66 #define EX_NOUSER 67 #define EX_NOHOST 68 #define EX_UNAVAILABLE 69 #define EX_SOFTWARE 70 #define EX_OSERR 71 #define EX_OSFILE 72 #define EX_CANTCREAT 73 #define EX_IOERR 74 #define EX_TEMPFAIL 75 #define EX_PROTOCOL 76 #define EX_NOPERM 77 #define EX_CONFIG 78 #define EX__MAX 78 #endif dietlibc-0.33~cvs20120325/include/syslog.h010064400000000000000000000000301173363226500150130ustar00#include dietlibc-0.33~cvs20120325/include/tar.h010064400000000000000000000011501173363226500142650ustar00#ifndef _TAR_H_ #define _TAR_H_ #define TMAGIC "ustar" #define TVERSION "00" #define TMAGLEN 6 #define TVERSLEN 2 #define REGTYPE '0' #define AREGTYPE '\0' #define LNKTYPE '1' #define SYMTYPE '2' #define CHRTYPE '3' #define BLKTYPE '4' #define DIRTYPE '5' #define FIFOTYPE '6' #define CONTTYPE '7' #define TSUID 04000 #define TSGID 02000 #define TSVTX 01000 #define TUREAD 00400 #define TUWRITE 00200 #define TUEXEC 00100 #define TGREAD 00040 #define TGWRITE 00020 #define TGEXEC 00010 #define TOREAD 00004 #define TOWRITE 00002 #define TOEXEC 00001 #endif /* _TAR_H_ */ dietlibc-0.33~cvs20120325/include/termio.h010064400000000000000000000001521173363226500147770ustar00/* this looks horribly wrong, but glibc does it like that */ #include #include dietlibc-0.33~cvs20120325/include/termios.h010064400000000000000000000230261173363226500151670ustar00#ifndef _TERMIOS_H #define _TERMIOS_H #include #include __BEGIN_DECLS struct winsize { uint16_t ws_row; uint16_t ws_col; uint16_t ws_xpixel; uint16_t ws_ypixel; }; #define NCC 8 struct termio { uint16_t c_iflag; /* input mode flags */ uint16_t c_oflag; /* output mode flags */ uint16_t c_cflag; /* control mode flags */ uint16_t c_lflag; /* local mode flags */ unsigned char c_line; /* line discipline */ unsigned char c_cc[NCC]; /* control characters */ }; /* modem lines */ #ifdef __mips__ #define TIOCM_LE 0x001 #define TIOCM_DTR 0x002 #define TIOCM_RTS 0x004 #define TIOCM_ST 0x010 #define TIOCM_SR 0x020 #define TIOCM_CTS 0x040 #define TIOCM_CAR 0x100 #define TIOCM_RNG 0x200 #define TIOCM_DSR 0x400 #define TIOCM_CD TIOCM_CAR #define TIOCM_RI TIOCM_RNG #define TIOCM_OUT1 0x2000 #define TIOCM_OUT2 0x4000 #define TIOCM_LOOP 0x8000 #else #define TIOCM_LE 0x001 #define TIOCM_DTR 0x002 #define TIOCM_RTS 0x004 #define TIOCM_ST 0x008 #define TIOCM_SR 0x010 #define TIOCM_CTS 0x020 #define TIOCM_CAR 0x040 #define TIOCM_RNG 0x080 #define TIOCM_DSR 0x100 #define TIOCM_CD TIOCM_CAR #define TIOCM_RI TIOCM_RNG #define TIOCM_OUT1 0x2000 #define TIOCM_OUT2 0x4000 #define TIOCM_LOOP 0x8000 #endif /* line disciplines */ #define N_TTY 0 #define N_SLIP 1 #define N_MOUSE 2 #define N_PPP 3 #define N_STRIP 4 #define N_AX25 5 #define N_X25 6 /* X.25 async */ #define N_6PACK 7 #define N_MASC 8 /* Reserved for Mobitex module */ #define N_R3964 9 /* Reserved for Simatic R3964 module */ #define N_PROFIBUS_FDL 10 /* Reserved for Profibus */ #define N_IRDA 11 /* Linux IR - http://irda.sourceforge.net/ */ #define N_SMSBLOCK 12 /* SMS block mode - for talking to GSM data cards about SMS messages */ #define N_HDLC 13 /* synchronous HDLC */ #define N_SYNC_PPP 14 /* synchronous PPP */ #define N_HCI 15 /* Bluetooth HCI UART */ typedef unsigned char cc_t; typedef uint32_t speed_t; typedef uint32_t tcflag_t; #define _POSIX_VDISABLE '\0' #if defined(__i386__) || defined(__arm__) || defined(__ia64__) || defined(__hppa__) || defined(__s390__) || defined(__s390x__) || defined(__x86_64__) #define NCCS 19 struct termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ }; #elif defined(__mips__) #define NCCS 23 struct termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ /* * Seems nonexistent in the ABI, but Linux assumes existence ... */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ }; #elif defined(__powerpc__) || defined(__powerpc64__) || defined(__alpha__) #define NCCS 19 struct termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_cc[NCCS]; /* control characters */ cc_t c_line; /* line discipline (== c_cc[19]) */ speed_t c_ispeed; /* input speed */ speed_t c_ospeed; /* output speed */ }; #elif defined(__sparc__) #define NCCS 17 struct termios { tcflag_t c_iflag; /* input mode flags */ tcflag_t c_oflag; /* output mode flags */ tcflag_t c_cflag; /* control mode flags */ tcflag_t c_lflag; /* local mode flags */ cc_t c_line; /* line discipline */ cc_t c_cc[NCCS]; /* control characters */ }; #else # error "Struct termios undefined on your architecture" #endif /* c_cc characters */ #if defined(__alpha__) #define VEOF 0 #define VEOL 1 #define VEOL2 2 #define VERASE 3 #define VWERASE 4 #define VKILL 5 #define VREPRINT 6 #define VSWTC 7 #define VINTR 8 #define VQUIT 9 #define VSUSP 10 #define VSTART 12 #define VSTOP 13 #define VLNEXT 14 #define VDISCARD 15 #define VMIN 16 #define VTIME 17 #elif defined(__mips__) #define VINTR 0 #define VQUIT 1 #define VERASE 2 #define VKILL 3 #define VMIN 4 #define VTIME 5 #define VEOL2 6 #define VSWTC 7 #define VSWTCH VSWTC #define VSTART 8 #define VSTOP 9 #define VSUSP 10 #define VREPRINT 12 #define VDISCARD 13 #define VWERASE 14 #define VLNEXT 15 #define VEOF 16 #define VEOL 17 #elif defined(__powerpc__) || defined(__powerpc64__) #define VINTR 0 #define VQUIT 1 #define VERASE 2 #define VKILL 3 #define VEOF 4 #define VMIN 5 #define VEOL 6 #define VTIME 7 #define VEOL2 8 #define VSWTC 9 #define VWERASE 10 #define VREPRINT 11 #define VSUSP 12 #define VSTART 13 #define VSTOP 14 #define VLNEXT 15 #define VDISCARD 16 #elif defined(__sparc__) #define VINTR 0 #define VQUIT 1 #define VERASE 2 #define VKILL 3 #define VEOF 4 #define VEOL 5 #define VEOL2 6 #define VSWTC 7 #define VSTART 8 #define VSTOP 9 #define VSUSP 10 #define VDSUSP 11 #define VREPRINT 12 #define VDISCARD 13 #define VWERASE 14 #define VLNEXT 15 #define VMIN VEOF #define VTIME VEOL #else /* arm, i386, parisc, s390, x86_64 */ #define VINTR 0 #define VQUIT 1 #define VERASE 2 #define VKILL 3 #define VEOF 4 #define VTIME 5 #define VMIN 6 #define VSWTC 7 #define VSTART 8 #define VSTOP 9 #define VSUSP 10 #define VEOL 11 #define VREPRINT 12 #define VDISCARD 13 #define VWERASE 14 #define VLNEXT 15 #define VEOL2 16 #endif /* c_iflag bits */ #define IGNBRK 0000001 #define BRKINT 0000002 #define IGNPAR 0000004 #define PARMRK 0000010 #define INPCK 0000020 #define ISTRIP 0000040 #define INLCR 0000100 #define IGNCR 0000200 #define ICRNL 0000400 #define IUCLC 0001000 #define IXON 0002000 #define IXANY 0004000 #define IXOFF 0010000 #define IMAXBEL 0020000 #define IUTF8 0040000 /* c_oflag bits */ #define OPOST 0000001 #define OLCUC 0000002 #define ONLCR 0000004 #define OCRNL 0000010 #define ONOCR 0000020 #define ONLRET 0000040 #define OFILL 0000100 #define OFDEL 0000200 #define NLDLY 0000400 #define NL0 0000000 #define NL1 0000400 #define CRDLY 0003000 #define CR0 0000000 #define CR1 0001000 #define CR2 0002000 #define CR3 0003000 #define TABDLY 0014000 #define TAB0 0000000 #define TAB1 0004000 #define TAB2 0010000 #define TAB3 0014000 #define XTABS 0014000 #define BSDLY 0020000 #define BS0 0000000 #define BS1 0020000 #define VTDLY 0040000 #define VT0 0000000 #define VT1 0040000 #define FFDLY 0100000 #define FF0 0000000 #define FF1 0100000 /* c_cflag bit meaning */ #define CBAUD 0010017 #define B0 0000000 /* hang up */ #define B50 0000001 #define B75 0000002 #define B110 0000003 #define B134 0000004 #define B150 0000005 #define B200 0000006 #define B300 0000007 #define B600 0000010 #define B1200 0000011 #define B1800 0000012 #define B2400 0000013 #define B4800 0000014 #define B9600 0000015 #define B19200 0000016 #define B38400 0000017 #define EXTA B19200 #define EXTB B38400 #define CSIZE 0000060 #define CS5 0000000 #define CS6 0000020 #define CS7 0000040 #define CS8 0000060 #define CSTOPB 0000100 #define CREAD 0000200 #define PARENB 0000400 #define PARODD 0001000 #define HUPCL 0002000 #define CLOCAL 0004000 #define CBAUDEX 0010000 #define B57600 0010001 #define B115200 0010002 #define B230400 0010003 #define B460800 0010004 #define B500000 0010005 #define B576000 0010006 #define B921600 0010007 #define B1000000 0010010 #define B1152000 0010011 #define B1500000 0010012 #define B2000000 0010013 #define B2500000 0010014 #define B3000000 0010015 #define B3500000 0010016 #define B4000000 0010017 #define CIBAUD 002003600000 /* input baud rate (not used) */ #define CMSPAR 010000000000 /* mark or space (stick) parity */ #define CRTSCTS 020000000000 /* flow control */ /* c_lflag bits */ #if defined (__powerpc__) || defined (__alpha__) #define ISIG 0x00000080 #define ICANON 0x00000100 #define XCASE 0x00004000 #define ECHO 0x00000008 #define ECHOE 0x00000002 #define ECHOK 0x00000004 #define ECHONL 0x00000010 #define NOFLSH 0x80000000 #define TOSTOP 0x00400000 #define ECHOCTL 0x00000040 #define ECHOPRT 0x00000020 #define ECHOKE 0x00000001 #define FLUSHO 0x00800000 #define IEXTEN 0x00000400 #define PENDIN 0x20000000 #else #define ISIG 0000001 #define ICANON 0000002 #define XCASE 0000004 #define ECHO 0000010 #define ECHOE 0000020 #define ECHOK 0000040 #define ECHONL 0000100 #define NOFLSH 0000200 #define ECHOCTL 0001000 #define ECHOPRT 0002000 #define ECHOKE 0004000 #endif #ifdef __mips__ #define IEXTEN 0000400 #define FLUSHO 0020000 #define TOSTOP 0100000 #else #define TOSTOP 0000400 #define FLUSHO 0010000 #define IEXTEN 0100000 #endif #define PENDIN 0040000 /* tcflow() and TCXONC use these */ #define TCOOFF 0 #define TCOON 1 #define TCIOFF 2 #define TCION 3 /* tcflush() and TCFLSH use these */ #define TCIFLUSH 0 #define TCOFLUSH 1 #define TCIOFLUSH 2 /* tcsetattr uses these */ #ifdef __mips__ #define TCSANOW 0x540e #define TCSADRAIN 0x540f #define TCSAFLUSH 0x5410 #else #define TCSANOW 0 #define TCSADRAIN 1 #define TCSAFLUSH 2 #endif int tcgetattr(int fd, struct termios *termios_p) __THROW; int tcsetattr(int fd, int optional_actions, struct termios *termios_p) __THROW; speed_t cfgetospeed(const struct termios *termios_p) __THROW; int cfsetospeed(struct termios *termios_p, speed_t speed) __THROW; speed_t cfgetispeed(const struct termios *termios_p) __THROW; int cfsetispeed(struct termios *termios_p, speed_t speed) __THROW; void cfmakeraw(struct termios *t) __THROW; int tcflush(int fd, int queue_selector) __THROW; int tcdrain(int fd) __THROW; int tcflow (int fd,int action) __THROW; int tcsendbreak (int fd,int duration) __THROW; pid_t tcgetsid(int fildes) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/time.h010064400000000000000000000044371173363226500144500ustar00#ifndef _TIME_H #define _TIME_H #include #include #include #include __BEGIN_DECLS int __isleap(int year); #define CLOCK_REALTIME 0 #define CLOCK_MONOTONIC 1 #define CLOCK_PROCESS_CPUTIME_ID 2 #define CLOCK_THREAD_CPUTIME_ID 3 #define CLOCK_REALTIME_HR 4 #define CLOCK_MONOTONIC_HR 5 int clock_settime(clockid_t clock_id,const struct timespec*tp); int clock_gettime(clockid_t clock_id,struct timespec*tp); int clock_getres(clockid_t clock_id,struct timespec*res); int clock_nanosleep(clockid_t clock_id, int flags,const struct timespec *rqtp, struct timespec *rmtp); #define TIMER_ABSTIME 1 int timer_create(clockid_t clock_id,struct sigevent*evp,timer_t*timerid) __THROW; int timer_delete(timer_t timerid) __THROW; int timer_settime(timer_t timerid,int flags,const struct itimerspec*ival,struct itimerspec*oval) __THROW; int timer_gettime(timer_t timerid,const struct itimerspec*val) __THROW; int timer_getoverrun(timer_t timerid) __THROW; int nanosleep(const struct timespec *req, struct timespec *rem) __THROW; time_t mktime(struct tm *timeptr) __THROW __pure; char *asctime(const struct tm *timeptr) __THROW; char *asctime_r(const struct tm *timeptr, char *buf) __THROW; char *ctime(const time_t *timep) __THROW; char *ctime_r(const time_t *timep, char* buf) __THROW; size_t strftime(char *s, size_t max, const char *format, const struct tm *tm) __THROW __attribute__((__format__(__strftime__,3,0))); time_t time(time_t *t) __THROW; int stime(time_t *t) __THROW; double difftime(time_t time1, time_t time0) __THROW __attribute__((__const__)); #define CLOCKS_PER_SEC 1000000l extern long int timezone; extern int daylight; extern char* tzname[2]; void tzset (void) __THROW; struct tm* localtime(const time_t* t) __THROW; struct tm* gmtime(const time_t* t) __THROW; struct tm* localtime_r(const time_t* t, struct tm* r) __THROW; struct tm* gmtime_r(const time_t* t, struct tm* r) __THROW; clock_t clock(void); char *strptime(const char *s, const char *format, struct tm *tm); #ifdef _GNU_SOURCE time_t timegm(struct tm *timeptr) __THROW __attribute_dontuse__ __pure ; time_t timelocal(struct tm *timeptr) __THROW __attribute_dontuse__ __pure; #endif #define CLK_TCK ((clock_t)sysconf(_SC_CLK_TCK)) __END_DECLS #endif dietlibc-0.33~cvs20120325/include/unistd.h010064400000000000000000000216151173363226500150150ustar00#ifndef _UNISTD_H #define _UNISTD_H #include #include #include #include #include __BEGIN_DECLS extern int optind,opterr,optopt; extern char *optarg; int getopt(int argc, char *const argv[], const char *options); /* Values for the second argument to access. These may be OR'd together. */ #define R_OK 4 /* Test for read permission. */ #define W_OK 2 /* Test for write permission. */ #define X_OK 1 /* Test for execute permission. */ #define F_OK 0 /* Test for existence. */ /* Test for access to NAME using the real UID and real GID. */ int access (const char *__name, int __type) __THROW; #ifndef SEEK_SET #define SEEK_SET 0 #define SEEK_CUR 1 #define SEEK_END 2 #endif #define STDIN_FILENO 0 #define STDOUT_FILENO 1 #define STDERR_FILENO 2 off_t lseek(int fildes, off_t offset, int whence) __THROW; #if __WORDSIZE == 32 loff_t lseek64(int fildes, loff_t offset, int whence) __THROW; #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define lseek(fildes,offset,whence) lseek64(fildes,offset,whence) #endif #endif int chdir(const char *path) __THROW; int fchdir(int fd) __THROW; int rmdir(const char *pathname) __THROW; char *getcwd(char *buf, size_t size) __attribute__((__warn_unused_result__)) __THROW; #ifdef _GNU_SOURCE char *get_current_dir_name (void) __THROW __attribute_dontuse__; #endif int open(const char* pathname,int flags, ...) __THROW; int open64(const char* pathname,int flags, ...) __THROW; int creat(const char* pathname,mode_t mode) __THROW; int creat64(const char* pathname,mode_t mode) __THROW; ssize_t write(int fd,const void* buf,size_t len) __THROW; ssize_t read(int fd,void* buf,size_t len) __THROW; int close(int fd) __THROW; int unlink(const char *pathname) __THROW; ssize_t pread(int fd, void *buf, size_t count, off_t offset); ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset); ssize_t pread64(int fd, void *buf, size_t count, off64_t offset); ssize_t pwrite64(int fd, const void *buf, size_t count, off64_t offset); int execve(const char *filename, char *const argv [], char *const envp[]) __THROW; int execlp(const char *file, const char *arg, ...) __THROW; int execv(const char *path, char *const argv[]) __THROW; int execvp(const char *file, char *const argv[]) __THROW; int execl(const char *path, ...) __THROW; int execle(const char *path, ...) __THROW; pid_t getpid(void) __THROW __pure; pid_t getppid(void) __THROW; int setpgid (pid_t pid,pid_t pgid) __THROW; pid_t getpgid (pid_t pid) __THROW; int setpgrp (void) __THROW; pid_t getpgrp (void) __THROW; pid_t getsid(pid_t pid) __THROW; pid_t setsid (void) __THROW; int dup (int oldfd) __THROW; int dup2 (int oldfd,int newfd) __THROW; struct dirent; struct dirent64; int getdents(int fd, struct dirent *dirp, unsigned int count) __THROW; int getdents64(int fd, struct dirent64 *dirp, unsigned int count) __THROW; pid_t fork(void) __THROW; pid_t vfork(void) __THROW; int readlink(const char *path, char *buf, size_t bufsiz) __THROW; int symlink(const char *oldpath, const char *newpath) __THROW; int link(const char *oldpath, const char *newpath) __THROW; int chown(const char *path, uid_t owner, gid_t group) __THROW; int fchown(int fd, uid_t owner, gid_t group) __THROW; int lchown(const char *path, uid_t owner, gid_t group) __THROW; int fsync(int fd) __THROW; #define _POSIX_SYNCHRONIZED_IO int fdatasync(int fd) __THROW; int pipe(int filedes[2]) __THROW; char *ttyname (int desc) __THROW; int brk(void *end_data_segment) __THROW; void *sbrk(ptrdiff_t increment) __THROW; int gethostname(char *name, size_t len) __THROW; int sethostname(const char *name, size_t len) __THROW; int usleep(unsigned long useconds) __THROW; unsigned int sleep(unsigned int seconds) __THROW; unsigned int alarm(unsigned int seconds) __THROW; int sync(void) __THROW; int isatty(int desc) __THROW; void _exit(int status) __THROW __attribute__((__noreturn__)); int daemon(int nochdir,int noclose) __THROW; int pause(void) __THROW; char* getlogin(void) __THROW; /* warning: the diet libc getlogin() simply returns getenv("LOGNAME") */ int chroot(const char *path) __THROW; uid_t getuid(void) __THROW; uid_t geteuid(void) __THROW; gid_t getgid(void) __THROW; gid_t getegid(void) __THROW; int setuid(uid_t uid) __THROW; /* int seteuid(uid_t uid) __THROW; */ int setgid(gid_t gid) __THROW; /* int setegid(gid_t gid) __THROW; */ int setregid(gid_t rgid, gid_t egid) __THROW; int setreuid(uid_t ruid, uid_t euid) __THROW; #define seteuid(euid) setreuid(-1,euid) #define setegid(egid) setregid(-1,egid) int truncate(const char *path, off_t length) __THROW; int ftruncate(int fd, off_t length) __THROW; #if __WORDSIZE == 32 int truncate64(const char *path, loff_t length) __THROW; int ftruncate64(int fd, loff_t length) __THROW; #endif int nice(int inc) __THROW; char *crypt(const char *key, const char *salt) __THROW; void encrypt(char block[64], int edflag) __THROW; void setkey(const char *key) __THROW; size_t getpagesize(void) __THROW __attribute__((__const__,__pure__)); int getdomainname(char *name, size_t len) __THROW; int setdomainname(const char *name, size_t len) __THROW; int getgroups(int size, gid_t list[]) __THROW; int getdtablesize(void) __THROW; char *getpass(const char * prompt) __THROW; /* warning: linux specific: */ int llseek(int fildes, unsigned long hi, unsigned long lo, loff_t* result,int whence) __THROW; /* include to get all the definitions! */ struct __sysctl_args; int _sysctl(struct __sysctl_args *args) __THROW; #define _CS_PATH 1 size_t confstr(int name,char*buf,size_t len) __THROW; #define _SC_CLK_TCK 1 #define _SC_ARG_MAX 2 #define _SC_NGROUPS_MAX 3 #define _SC_OPEN_MAX 4 #define _SC_PAGESIZE 5 #define _SC_NPROCESSORS_ONLN 6 #define _SC_NPROCESSORS_CONF _SC_NPROCESSORS_ONLN #define _SC_PHYS_PAGES 7 long sysconf(int name) __THROW; #define _PC_PATH_MAX 1 #define _PC_VDISABLE 2 pid_t tcgetpgrp(int fd) __THROW; int tcsetpgrp(int fd, pid_t pgrpid) __THROW; int profil(unsigned short *buf, size_t bufsiz, size_t offset, unsigned int scale); /* Linux only: */ int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid) __THROW; int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid) __THROW; int setresuid(uid_t ruid, uid_t euid, uid_t suid) __THROW; int setresgid(gid_t rgid, gid_t egid, gid_t sgid) __THROW; /* 32-bit uid support */ int chown32(const char *path, uid32_t owner, gid32_t group) __THROW; int fchown32(int fd, uid32_t owner, gid32_t group) __THROW; int lchown32(const char *path, uid32_t owner, gid32_t group) __THROW; uid32_t getuid32(void) __THROW; uid32_t geteuid32(void) __THROW; gid32_t getgid32(void) __THROW; gid32_t getegid32(void) __THROW; int setuid32(uid32_t uid) __THROW; int setgid32(gid32_t gid) __THROW; int setreuid32(uid32_t ruid, uid32_t euid) __THROW; int setregid32(gid32_t rgid, gid32_t egid) __THROW; #define seteuid32(euid) setreuid32(-1,euid) #define setegid32(egid) setregid32(-1,egid) int getgroups32(int size, gid32_t list[]) __THROW; int getresuid32(uid32_t *ruid, uid32_t *euid, uid32_t *suid); int getresgid32(gid32_t *rgid, gid32_t *egid, gid32_t *sgid); int setresuid32(uid32_t ruid, uid32_t euid, uid32_t suid) __THROW; int setresgid32(gid32_t rgid, gid32_t egid, gid32_t sgid) __THROW; #ifdef _BSD_SOURCE char *getusershell(void) __attribute_dontuse__; void setusershell(void) __attribute_dontuse__; void endusershell(void) __attribute_dontuse__; #endif /* this is so bad, we moved it to -lcompat */ #define L_cuserid 17 char* cuserid(char * string); /* ugh! */ #define _POSIX_VERSION 199506L #define F_ULOCK 0 /* Unlock a previously locked region. */ #define F_LOCK 1 /* Lock a region for exclusive use. */ #define F_TLOCK 2 /* Test and lock a region for exclusive use. */ #define F_TEST 3 /* Test a region for other processes locks. */ int lockf (int __fd, int __cmd, off_t __len) __THROW; int lockf64 (int __fd, int __cmd, off64_t __len) __THROW; void swab(const void *src, void *dest, ssize_t nbytes) __THROW; int vhangup(void) __THROW; extern char **__environ; #if __WORDSIZE == 32 #if defined _FILE_OFFSET_BITS && _FILE_OFFSET_BITS == 64 #define open open64 #define creat creat64 #define truncate truncate64 #define ftruncate ftruncate64 #define getdents getdents64 #endif #endif #ifdef _LINUX_SOURCE int pivot_root(const char *new_root, const char *put_old) __THROW; /* Linux 2.6 module loading infrastructure: * init_module takes a buffer where you read the module file into */ long init_module(void *module, unsigned long len, const char *options) __THROW; /* flags can be O_EXCL | O_NONBLOCK | O_TRUNC (forced unloading) * O_EXCL is there so the kernel can spot old rmmod versions */ long delete_module(const char* name,unsigned int flags) __THROW; pid_t gettid(void) __THROW __pure; int tkill(pid_t tid, int sig) __THROW; int tgkill(pid_t tgid, pid_t tid, int sig) __THROW; /* see linux/fadvise.h */ long fadvise64(int fd,off64_t offset,size_t len,int advice); long fadvise64_64(int fd,off64_t offset,off64_t len,int advice); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/ustat.h010064400000000000000000000007441173363226500146470ustar00#ifndef _USTAT_H #define _USTAT_H #include #include __BEGIN_DECLS struct ustat { #if defined(__mips__) || (defined(__sparc__) && !defined(__arch64__)) long f_tfree; /* should be daddr_t f_tfree */ #else int f_tfree; /* should be daddr_t f_tfree */ #endif unsigned long f_tinode; /* should be ino_t f_tinode */ char f_fname[6]; char f_fpack[6]; }; int ustat(dev_t dev, struct ustat* ubuf) __THROW __attribute_dontuse__; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/utime.h010064400000000000000000000004571173363226500146330ustar00#ifndef _UTIME_H #define _UTIME_H #include #include #include __BEGIN_DECLS struct utimbuf { time_t actime; /* access time */ time_t modtime; /* modification time */ }; int utime(const char* filename, const struct utimbuf* buf) __THROW; __END_DECLS #endif dietlibc-0.33~cvs20120325/include/utmp.h010064400000000000000000000063301173363226500144710ustar00#ifndef _UTMP_H #define _UTMP_H #include #include #include #include __BEGIN_DECLS #define UT_LINESIZE 32 #define UT_NAMESIZE 32 #define UT_HOSTSIZE 256 /* The structure describing an entry in the database of previous logins. */ struct lastlog { #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 int32_t ll_time; #else time_t ll_time; #endif char ll_line[UT_LINESIZE]; char ll_host[UT_HOSTSIZE]; }; /* The structure describing the status of a terminated process. This type is used in `struct utmp' below. */ struct exit_status { short int e_termination; /* Process termination status. */ short int e_exit; /* Process exit status. */ }; /* The structure describing an entry in the user accounting database. */ struct utmp { short int ut_type; /* Type of login. */ pid_t ut_pid; /* Process ID of login process. */ char ut_line[UT_LINESIZE]; /* Devicename. */ char ut_id[4]; /* Inittab ID. */ char ut_user[UT_NAMESIZE]; /* Username. */ char ut_host[UT_HOSTSIZE]; /* Hostname for remote login. */ #define ut_name ut_user struct exit_status ut_exit; /* Exit status of a process marked as DEAD_PROCESS. */ /* The ut_session and ut_tv fields must be the same size when compiled 32- and 64-bit. This allows data files and shared memory to be shared between 32- and 64-bit applications. */ #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 int32_t ut_session; /* Session ID, used for windowing. */ struct { int32_t tv_sec; /* Seconds. */ int32_t tv_usec; /* Microseconds. */ } ut_tv; /* Time entry was made. */ #else long int ut_session; /* Session ID, used for windowing. */ struct timeval ut_tv; /* Time entry was made. */ #endif #define ut_time ut_tv.tv_sec #define ut_addr ut_addr_v6[0] int32_t ut_addr_v6[4]; /* Internet address of remote host. */ char __unused[20]; /* Reserved for future use. */ }; #ifndef _UTMPX_H /* untmpx.h hasn't already defined these. */ /* Values for the `ut_type' field of a `struct utmp'. */ #define EMPTY 0 /* No valid user accounting information. */ #define RUN_LVL 1 /* The system's runlevel. */ #define BOOT_TIME 2 /* Time of system boot. */ #define NEW_TIME 3 /* Time after system clock changed. */ #define OLD_TIME 4 /* Time when system clock changed. */ #define INIT_PROCESS 5 /* Process spawned by the init process. */ #define LOGIN_PROCESS 6 /* Session leader of a logged in user. */ #define USER_PROCESS 7 /* Normal process. */ #define DEAD_PROCESS 8 /* Terminated process. */ #define ACCOUNTING 9 #endif /* Tell the user that we have a modern system with UT_HOST, UT_PID, UT_TYPE, UT_ID and UT_TV fields. */ #define _HAVE_UT_TYPE 1 #define _HAVE_UT_PID 1 #define _HAVE_UT_ID 1 #define _HAVE_UT_TV 1 #define _HAVE_UT_HOST 1 struct utmp *getutent(void) __THROW; struct utmp *getutid(struct utmp *ut) __THROW; struct utmp *getutline(struct utmp *ut) __THROW; void pututline(struct utmp *ut) __THROW; void setutent(void) __THROW; void endutent(void) __THROW; void utmpname(const char *file) __THROW; void updwtmp(const char *wtmp_file, const struct utmp *ut); void logwtmp(const char *line, const char *name, const char *host); __END_DECLS #endif dietlibc-0.33~cvs20120325/include/utmpx.h010064400000000000000000000056571173363226500146740ustar00#ifndef _UTMPX_H #define _UTMPX_H #include #include #include #include /* For the getutmp{,x} functions we need the `struct utmp'. */ #ifdef _GNU_SOURCE struct utmp; #endif #define __UT_LINESIZE 32 #define __UT_NAMESIZE 32 #define __UT_HOSTSIZE 256 __BEGIN_DECLS /* The structure describing the status of a terminated process. This type is used in `struct utmpx below. */ struct __exit_status { short int e_termination; /* Process termination status. */ short int e_exit; /* Process exit status. */ }; /* The structure describing an entry in the user accounting database. */ struct utmpx { short int ut_type; /* Type of login. */ pid_t ut_pid; /* Process ID of login process. */ char ut_line[__UT_LINESIZE]; /* Devicename. */ char ut_id[4]; /* Inittab ID. */ char ut_user[__UT_NAMESIZE]; /* Username. */ char ut_host[__UT_HOSTSIZE]; /* Hostname for remote login. */ struct __exit_status ut_exit; /* Exit status of a process marked as DEAD_PROCESS. */ /* The ut_session and ut_tv fields must be the same size when compiled 32- and 64-bit. This allows data files and shared memory to be shared between 32- and 64-bit applications. */ #if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32 int32_t ut_session; /* Session ID, used for windowing. */ struct { int32_t tv_sec; /* Seconds. */ int32_t tv_usec; /* Microseconds. */ } ut_tv; /* Time entry was made. */ #else long int ut_session; /* Session ID, used for windowing. */ struct timeval ut_tv; /* Time entry was made. */ #endif int32_t ut_addr_v6[4]; /* Internet address of remote host. */ char __unused[20]; /* Reserved for future use. */ }; #ifndef _UTMP_H /* utmp.h hasn't already defined these. */ /* Values for the `ut_type' field of a `struct utmpx'. */ #define EMPTY 0 /* No valid user accounting information. */ #define RUN_LVL 1 /* The system's runlevel. */ #define BOOT_TIME 2 /* Time of system boot. */ #define NEW_TIME 3 /* Time after system clock changed. */ #define OLD_TIME 4 /* Time when system clock changed. */ #define INIT_PROCESS 5 /* Process spawned by the init process. */ #define LOGIN_PROCESS 6 /* Session leader of a logged in user. */ #define USER_PROCESS 7 /* Normal process. */ #define DEAD_PROCESS 8 /* Terminated process. */ #define ACCOUNTING 9 #endif /* Apparently, these functions are all considered possible cancellation * points, thus no __THROW */ struct utmpx *getutxent(void); struct utmpx *getutxid(struct utmpx *ut); struct utmpx *getutxline(struct utmpx *ut); struct utmpx *pututxline(struct utmpx *ut); void setutxent(void); void endutxent(void); #ifdef _GNU_SOURCE void utmpxname (const char *file); void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx); void getutmp (const struct utmpx *utmpx, struct utmp *utmp); void getutmpx (const struct utmp *utmp, struct utmpx *utmpx); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/wchar.h010064400000000000000000000101031173363226500146010ustar00#ifndef _WCHAR_H #define _WCHAR_H #include #include #include #include __BEGIN_DECLS #if defined(__WINT_TYPE__) typedef __WINT_TYPE__ wint_t; #else typedef unsigned int wint_t; #endif typedef int (*wctype_t)(wint_t) __THROW __attribute__((__const__)); #ifndef WCHAR_MIN #define WCHAR_MIN (-2147483647 - 1) #define WCHAR_MAX (2147483647) #endif #ifndef WEOF #define WEOF 0xffffffffu #endif struct tm; typedef struct { int count; wchar_t sofar; } mbstate_t; wint_t btowc(int); wint_t fgetwc(FILE *); wchar_t* fgetws(wchar_t *__restrict__, int, FILE *__restrict__); wint_t fputwc(wchar_t, FILE *); int fputws(const wchar_t *__restrict__, FILE *__restrict__); int fwide(FILE *, int); int fwprintf(FILE *__restrict__, const wchar_t *__restrict__, ...); int fwscanf(FILE *__restrict__, const wchar_t *__restrict__, ...); wint_t getwc(FILE *); wint_t getwchar(void); size_t mbrlen(const char *__restrict__, size_t, mbstate_t *__restrict__); size_t mbrtowc(wchar_t *__restrict__, const char *__restrict__, size_t, mbstate_t *__restrict__); int mbsinit(const mbstate_t *); size_t mbsrtowcs(wchar_t *__restrict__, const char **__restrict__, size_t, mbstate_t *__restrict__); wint_t putwc(wchar_t, FILE *); wint_t putwchar(wchar_t); int swprintf(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, ...); int swscanf(const wchar_t *__restrict__, const wchar_t *__restrict__, ...); wint_t ungetwc(wint_t, FILE *); int vfwprintf(FILE *__restrict__, const wchar_t *__restrict__, va_list); int vfwscanf(FILE *__restrict__, const wchar_t *__restrict__, va_list); int vwprintf(const wchar_t *__restrict__, va_list); int vswprintf(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, va_list); int vswscanf(const wchar_t *__restrict__, const wchar_t *__restrict__, va_list); int vwscanf(const wchar_t *__restrict__, va_list); size_t wcrtomb(char *__restrict__, wchar_t, mbstate_t *__restrict__); wchar_t *wcscat(wchar_t *__restrict__, const wchar_t *__restrict__); wchar_t *wcschr(const wchar_t *, wchar_t); int wcscmp(const wchar_t *, const wchar_t *); int wcscoll(const wchar_t *, const wchar_t *); wchar_t* wcscpy(wchar_t *__restrict__, const wchar_t *__restrict__); size_t wcscspn(const wchar_t *, const wchar_t *); size_t wcsftime(wchar_t *__restrict__, size_t, const wchar_t *__restrict__, const struct tm *__restrict__); size_t wcslen(const wchar_t *) __pure; wchar_t *wcsncat(wchar_t *__restrict__, const wchar_t *__restrict__, size_t); int wcsncmp(const wchar_t *, const wchar_t *, size_t); wchar_t *wcsncpy(wchar_t *__restrict__, const wchar_t *__restrict__, size_t); wchar_t *wcspbrk(const wchar_t *, const wchar_t *); wchar_t *wcsrchr(const wchar_t *, wchar_t); size_t wcsrtombs(char *__restrict__, const wchar_t **__restrict__, size_t, mbstate_t *__restrict__); size_t wcsspn(const wchar_t *, const wchar_t *); wchar_t *wcsstr(const wchar_t *__restrict__, const wchar_t *__restrict__); double wcstod(const wchar_t *__restrict__, wchar_t **__restrict__); float wcstof(const wchar_t *__restrict__, wchar_t **__restrict__); wchar_t *wcstok(wchar_t *__restrict__, const wchar_t *__restrict__, wchar_t **__restrict__); long wcstol(const wchar_t *__restrict__, wchar_t **__restrict__, int); long double wcstold(const wchar_t *__restrict__, wchar_t **__restrict__); long long wcstoll(const wchar_t *__restrict__, wchar_t **__restrict__, int); unsigned long wcstoul(const wchar_t *__restrict__, wchar_t **__restrict__, int); unsigned long long wcstoull(const wchar_t *__restrict__, wchar_t **__restrict__, int); size_t wcsxfrm(wchar_t *__restrict__, const wchar_t *__restrict__, size_t); int wctob(wint_t); wchar_t *wmemchr(const wchar_t *, wchar_t, size_t); int wmemcmp(const wchar_t *, const wchar_t *, size_t); wchar_t *wmemcpy(wchar_t *__restrict__, const wchar_t *__restrict__, size_t); wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t); wchar_t *wmemset(wchar_t *, wchar_t, size_t); int wprintf(const wchar_t *__restrict__, ...); int wscanf(const wchar_t *__restrict__, ...); #ifdef _XOPEN_SOURCE int wcwidth(wchar_t c); int wcswidth(const wchar_t *s, size_t n); #endif __END_DECLS #endif dietlibc-0.33~cvs20120325/include/wctype.h010064400000000000000000000020671173363226500150220ustar00#ifndef _WCTYPE_H #define _WCTYPE_H #include #include typedef const int32_t* wctrans_t; int iswalnum(wint_t) __THROW __attribute__ ((__const__)); int iswalpha(wint_t) __THROW __attribute__ ((__const__)); int iswblank(wint_t) __THROW __attribute__ ((__const__)); int iswcntrl(wint_t) __THROW __attribute__ ((__const__)); int iswdigit(wint_t) __THROW __attribute__ ((__const__)); int iswgraph(wint_t) __THROW __attribute__ ((__const__)); int iswlower(wint_t) __THROW __attribute__ ((__const__)); int iswprint(wint_t) __THROW __attribute__ ((__const__)); int iswpunct(wint_t) __THROW __attribute__ ((__const__)); int iswspace(wint_t) __THROW __attribute__ ((__const__)); int iswupper(wint_t) __THROW __attribute__ ((__const__)); int iswxdigit(wint_t) __THROW __attribute__ ((__const__)); int iswctype(wint_t, wctype_t) __THROW __attribute__ ((__const__)); wint_t towctrans(wint_t, wctrans_t) __THROW; wint_t towlower(wint_t) __THROW; wint_t towupper(wint_t) __THROW; wctrans_t wctrans(const char *) __THROW; wctype_t wctype(const char *) __THROW; #endif dietlibc-0.33~cvs20120325/include/write12.h010064400000000000000000000003311173363226500147740ustar00#include #include __BEGIN_DECLS ssize_t __write1 ( const char* s ) __attribute__ (( __regparm__(1) )); ssize_t __write2 ( const char* s ) __attribute__ (( __regparm__(1) )); __END_DECLS dietlibc-0.33~cvs20120325/internal.h010064400000000000000000000001021173363226000136570ustar00 const void* vdso_dlsym(const char* elfimage,const char* symbol); dietlibc-0.33~cvs20120325/lib/__alarm.c010064400000000000000000000006421173363226500142140ustar00#include #include #include "syscalls.h" #ifndef __NR_alarm unsigned int alarm(unsigned int seconds) { struct itimerval old, new; unsigned int ret; new.it_interval.tv_usec=0; new.it_interval.tv_sec=0; new.it_value.tv_usec =0; new.it_value.tv_sec =(long)seconds; if (setitimer(ITIMER_REAL,&new,&old)==-1) return 0; return old.it_value.tv_sec+(old.it_value.tv_usec?1:0); } #endif dietlibc-0.33~cvs20120325/lib/__dtostr.c010064400000000000000000000075071173363226500144460ustar00#include #include #include /* convert double to string. Helper for sprintf. */ static int copystring(char* buf,int maxlen, const char* s) { int i; for (i=0; i<3&&i>52)&((1<<11)-1))-1023; #else #if __BYTE_ORDER == __LITTLE_ENDIAN signed long e=(((((unsigned long*)&d)[1])>>20)&((1<<11)-1))-1023; #else signed long e=(((*((unsigned long*)&d))>>20)&((1<<11)-1))-1023; #endif #endif /* unsigned long long m=u.l & ((1ull<<52)-1); */ /* step 2: exponent is base 2, compute exponent for base 10 */ signed long e10; /* step 3: calculate 10^e10 */ unsigned int i; double backup=d; double tmp; char *oldbuf=buf; if ((i=isinf(d))) return copystring(buf,maxlen,i>0?"inf":"-inf"); if (isnan(d)) return copystring(buf,maxlen,"nan"); e10=1+(long)(e*0.30102999566398119802); /* log10(2) */ /* Wir iterieren von Links bis wir bei 0 sind oder maxlen erreicht * ist. Wenn maxlen erreicht ist, machen wir das nochmal in * scientific notation. Wenn dann von prec noch was übrig ist, geben * wir einen Dezimalpunkt aus und geben prec2 Nachkommastellen aus. * Wenn prec2 Null ist, geben wir so viel Stellen aus, wie von prec * noch übrig ist. */ if (d==0.0) { prec2=prec2==0?1:prec2+2; prec2=prec2>maxlen?8:prec2; i=0; if (prec2 && (long long)u.l<0) { buf[0]='-'; ++i; } for (; i0) { int first=1; /* are we about to write the first digit? */ tmp = 10.0; i=e10; while (i>10) { tmp=tmp*1e10; i-=10; } while (i>1) { tmp=tmp*10; --i; } /* the number is greater than 1. Iterate through digits before the * decimal point until we reach the decimal point or maxlen is * reached (in which case we switch to scientific notation). */ while (tmp>0.9) { char digit; double fraction=d/tmp; digit=(int)(fraction); /* floor() */ if (!first || digit) { first=0; *buf=digit+'0'; ++buf; if (!maxlen) { /* use scientific notation */ int len=__dtostr(backup/tmp,oldbuf,maxlen,prec,prec2,0); int initial=1; if (len==0) return 0; maxlen-=len; buf+=len; if (maxlen>0) { *buf='e'; ++buf; } --maxlen; for (len=1000; len>0; len/=10) { if (e10>=len || !initial) { if (maxlen>0) { *buf=(e10/len)+'0'; ++buf; } --maxlen; initial=0; e10=e10%len; } } if (maxlen>0) goto fini; return 0; } d-=digit*tmp; --maxlen; } tmp/=10.0; } } else { tmp = 0.1; } if (buf==oldbuf) { if (!maxlen) return 0; --maxlen; *buf='0'; ++buf; } if (prec2 || prec>(unsigned int)(buf-oldbuf)+1) { /* more digits wanted */ if (!maxlen) return 0; --maxlen; *buf='.'; ++buf; if (g) { if (prec2) prec=prec2; prec-=buf-oldbuf-1; } else { prec-=buf-oldbuf-1; if (prec2) prec=prec2; } if (prec>maxlen) return 0; while (prec>0) { char digit; double fraction=d/tmp; digit=(int)(fraction); /* floor() */ *buf=digit+'0'; ++buf; d-=digit*tmp; tmp/=10.0; --prec; } } fini: *buf=0; return buf-oldbuf; } dietlibc-0.33~cvs20120325/lib/__fcntl64.c010064400000000000000000000022361173363226500144010ustar00#include #include "dietfeatures.h" #ifdef WANT_LARGEFILE_BACKCOMPAT #include #ifndef __NO_STAT64 #include #include extern int __dietlibc_fcntl64(int __fd, int cmd, ...); int fcntl64(int fd, int cmd, ...) { va_list va; va_start(va,cmd); switch (cmd) { case F_GETLK: case F_SETLK: case F_SETLKW: { struct flock64* x = va_arg(va,struct flock64*); struct flock tmp; int res; if ((res=__dietlibc_fcntl64(fd,cmd,x))) { if (errno!=ENOSYS) return -1; tmp.l_type=x->l_type; tmp.l_whence=x->l_whence; tmp.l_start=x->l_start; tmp.l_len=x->l_len; tmp.l_pid=x->l_pid; if (tmp.l_len != x->l_len || tmp.l_start != x->l_start) { errno=EOVERFLOW; return -1; } res=fcntl(fd,cmd,&tmp); if (cmd==F_GETLK) { x->l_type=tmp.l_type; x->l_whence=tmp.l_whence; x->l_start=tmp.l_start; x->l_len=tmp.l_len; x->l_pid=tmp.l_pid; } } return res; } default: { long arg = va_arg(va,long); int res; if ((res=__dietlibc_fcntl64(fd,cmd,arg))==-1) { if (errno!=ENOSYS) return -1; return fcntl(fd,cmd,arg); } return res; } } } #endif #endif dietlibc-0.33~cvs20120325/lib/__finite.c010064400000000000000000000002131173363226500143700ustar00#include int finite(double d) { return isinf(d)==0 && isnan(d)==0; } int __finite(double d) __attribute__((alias("finite"))); dietlibc-0.33~cvs20120325/lib/__fstat64.c010064400000000000000000000007621173363226500144160ustar00#include #include "dietfeatures.h" #ifdef WANT_LARGEFILE_BACKCOMPAT #include #ifndef __NO_STAT64 extern int __dietlibc_fstat64(int __fd, struct stat64 *__buf); extern void __stat64_cvt(const struct stat *src,struct stat64 *dest); int fstat64(int __fd, struct stat64 *__buf) { if (__dietlibc_fstat64(__fd,__buf)) { struct stat temp; if (errno!=ENOSYS) return -1; if (fstat(__fd,&temp)) return -1; __stat64_cvt(&temp,__buf); } return 0; } #endif #endif dietlibc-0.33~cvs20120325/lib/__fstatfs64.c010064400000000000000000000011411173363226500147370ustar00#include #include "dietfeatures.h" #include #if __WORDSIZE == 32 extern int __dietlibc_fstatfs64(int fd, size_t bufsize, struct statfs64 *__buf); extern void __statfs64_cvt(const struct statfs *src,struct statfs64 *dest); int fstatfs64(int fd, struct statfs64 *__buf) { #ifdef WANT_LARGEFILE_BACKCOMPAT if (__dietlibc_fstatfs64(fd,sizeof(*__buf),__buf)) { struct statfs temp; if (errno!=ENOSYS) return -1; if (fstatfs(fd,&temp)) return -1; __statfs64_cvt(&temp,__buf); } return 0; #else return __dietlibc_fstatfs64(fd,sizeof(*__buf),__buf); #endif } #endif dietlibc-0.33~cvs20120325/lib/__ftruncate64.c010064400000000000000000000007551173363226500152720ustar00#include #include "dietfeatures.h" #ifdef WANT_LARGEFILE_BACKCOMPAT #include #include "syscalls.h" #include #ifndef __NO_STAT64 #ifdef __NR_ftruncate64 extern int __dietlibc_ftruncate64(int fd, loff_t o); int ftruncate64(int fd, loff_t o) { int tmp; if ((tmp=__dietlibc_ftruncate64(fd,o))==-1) { if (errno!=ENOSYS) return -1; if (o>0x7fffffff) { errno=EOVERFLOW; return -1; } return ftruncate(fd,o); } return tmp; } #endif #endif #endif dietlibc-0.33~cvs20120325/lib/__getcwd.c010064400000000000000000000005051173363226500143730ustar00#include #include #include extern int __syscall_getcwd(char* buf, size_t size); char *getcwd(char *buf, size_t size) { if (__unlikely(!size)) { errno=EINVAL; buf=0; } else { int tmp; if ((tmp=__syscall_getcwd(buf,size-1))<0) return 0; buf[tmp]=0; } return buf; } dietlibc-0.33~cvs20120325/lib/__isinf.c010064400000000000000000000011101173363226500142170ustar00#include int isinf(double d) { union { unsigned long long l; double d; } u; u.d=d; return (u.l==0x7FF0000000000000ll?1:u.l==0xFFF0000000000000ll?-1:0); } int __isinf(double d) __attribute__((alias("isinf"))); #if 0 TestFromIeeeExtended("7FFF0000000000000000"); /* +infinity */ TestFromIeeeExtended("FFFF0000000000000000"); /* -infinity */ TestFromIeeeExtended("7FFF8001000000000000"); /* Quiet NaN(1) */ TestFromIeeeExtended("7FFF0001000000000000"); /* Signalling NaN(1) */ TestFromIeeeExtended("3FFFFEDCBA9876543210"); /* accuracy test */ #endif dietlibc-0.33~cvs20120325/lib/__isnan.c010064400000000000000000000011411173363226500142230ustar00#include int isnan(double d) { union { unsigned long long l; double d; } u; u.d=d; return (u.l==0x7FF8000000000000ll || u.l==0x7FF0000000000000ll || u.l==0xfff8000000000000ll); } int __isnan(double d) __attribute__((alias("isnan"))); #if 0 TestFromIeeeExtended("7FFF0000000000000000"); /* +infinity */ TestFromIeeeExtended("FFFF0000000000000000"); /* -infinity */ TestFromIeeeExtended("7FFF8001000000000000"); /* Quiet NaN(1) */ TestFromIeeeExtended("7FFF0001000000000000"); /* Signalling NaN(1) */ TestFromIeeeExtended("3FFFFEDCBA9876543210"); /* accuracy test */ #endif dietlibc-0.33~cvs20120325/lib/__lltostr.c010064400000000000000000000007631173363226500146270ustar00#include int __lltostr(char *s, int size, unsigned long long i, int base, char UpCase); int __lltostr(char *s, int size, unsigned long long i, int base, char UpCase) { char *tmp; unsigned int j=0; s[--size]=0; tmp=s+size; if ((base==0)||(base>36)) base=10; j=0; if (!i) { *(--tmp)='0'; j=1; } while((tmp>s)&&(i)) { tmp--; if ((*tmp=i%base+'0')>'9') *tmp+=(UpCase?'A':'a')-'9'-1; i=i/base; j++; } memmove(s,tmp,j+1); return j; } dietlibc-0.33~cvs20120325/lib/__lstat64.c010064400000000000000000000010121173363226500144110ustar00#include #include "dietfeatures.h" #ifdef WANT_LARGEFILE_BACKCOMPAT #include #ifndef __NO_STAT64 extern int __dietlibc_lstat64(const char *__file, struct stat64 *__buf); extern void __stat64_cvt(const struct stat *src,struct stat64 *dest); int lstat64(const char *__file, struct stat64 *__buf) { if (__dietlibc_lstat64(__file,__buf)) { struct stat temp; if (errno!=ENOSYS) return -1; if (lstat(__file,&temp)) return -1; __stat64_cvt(&temp,__buf); } return 0; } #endif #endif dietlibc-0.33~cvs20120325/lib/__ltostr.c010064400000000000000000000007021173363226500144440ustar00#include #include int __ltostr(char *s, unsigned int size, unsigned long i, unsigned int base, int UpCase) { char *tmp; unsigned int j=0; s[--size]=0; tmp=s+size; if ((base==0)||(base>36)) base=10; j=0; if (!i) { *(--tmp)='0'; j=1; } while((tmp>s)&&(i)) { tmp--; if ((*tmp=i%base+'0')>'9') *tmp+=(UpCase?'A':'a')-'9'-1; i=i/base; j++; } memmove(s,tmp,j+1); return j; } dietlibc-0.33~cvs20120325/lib/__mmap.c010064400000000000000000000010101173363226500140400ustar00#include #include #include #ifndef __NR_mmap void*__mmap2(void*start,size_t length,int prot,int flags,int fd,off_t pgoffset); void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { size_t pgsz = 4096; /* TODO: fix for dynamic PAGESIZEs needed? */ void *res; if (__unlikely(offset & (pgsz - 1))) { errno = -EINVAL; res = MAP_FAILED; } else res = __mmap2(addr, length, prot, flags, fd, offset / pgsz); return res; } #endif dietlibc-0.33~cvs20120325/lib/__nice.c010064400000000000000000000002701173363226500140330ustar00#include "syscalls.h" #include #include #ifndef __NR_nice int nice(int i) { return setpriority(PRIO_PROCESS,0,getpriority(PRIO_PROCESS,0)+i); } #endif dietlibc-0.33~cvs20120325/lib/__ptrace.c010064400000000000000000000015171173363226500144000ustar00/* we need this because we need to use the glibc prototype which uses * varargs :-( */ #include #define ptrace fnord #include #undef ptrace #include #include extern int __diet_ptrace(int request, pid_t pid, void *addr, void *data); int ptrace(int request, pid_t pid, void *addr, void *data); int ptrace(int request, pid_t pid, void *addr, void *data) { errno=0; switch (request) { case PTRACE_TRACEME: case PTRACE_KILL: case PTRACE_ATTACH: case PTRACE_DETACH: return (__diet_ptrace (request, pid, NULL, NULL)); case PTRACE_PEEKDATA: case PTRACE_PEEKUSER: case PTRACE_PEEKTEXT: { long result; if (__diet_ptrace (request, pid, addr, &result) == -1) return (-1); return (result); } default: return (__diet_ptrace (request, pid, addr, data)); } } dietlibc-0.33~cvs20120325/lib/__sched_getaffinity.c010064400000000000000000000004421173363226500165750ustar00#define _GNU_SOURCE #include extern int __syscall_sched_getaffinity(pid_t, size_t, cpu_set_t*); int sched_getaffinity(pid_t pid, size_t size, cpu_set_t *mask) { int ret; *mask = 0; ret = __syscall_sched_getaffinity(pid, size, mask); if (ret > 0) return 0; return ret; } dietlibc-0.33~cvs20120325/lib/__sendfile64.c010064400000000000000000000012631173363226500150630ustar00#include #include "dietfeatures.h" #ifdef WANT_LARGEFILE_BACKCOMPAT #include #ifndef __NO_STAT64 extern ssize_t __dietlibc_sendfile64 (int out_fd, int in_fd, loff_t* offset, size_t count); ssize_t sendfile64 (int out_fd, int in_fd, loff_t* offset, size_t count) { static int havesendfile64=1; ssize_t r = -1; if (havesendfile64) { r=__dietlibc_sendfile64(out_fd,in_fd,offset,count); if (r==-1 && errno==ENOSYS) havesendfile64=0; } if (!havesendfile64) { off_t o=*offset; if (*offset>0x7fffffff) { errno=EINVAL; return -1; } r=sendfile(out_fd,in_fd,&o,count); *offset=o; return r; } return r; } #endif #endif dietlibc-0.33~cvs20120325/lib/__stat64.c010064400000000000000000000010061173363226500142400ustar00#include #include "dietfeatures.h" #ifdef WANT_LARGEFILE_BACKCOMPAT #include #ifndef __NO_STAT64 extern int __dietlibc_stat64(const char *__file, struct stat64 *__buf); extern void __stat64_cvt(const struct stat *src,struct stat64 *dest); int stat64(const char *__file, struct stat64 *__buf) { if (__dietlibc_stat64(__file,__buf)) { struct stat temp; if (errno!=ENOSYS) return -1; if (stat(__file,&temp)) return -1; __stat64_cvt(&temp,__buf); } return 0; } #endif #endif dietlibc-0.33~cvs20120325/lib/__stat64_cvt.c010064400000000000000000000011041173363226500151130ustar00#include #ifndef __NO_STAT64 void __stat64_cvt(const struct stat *src,struct stat64 *dest); void __stat64_cvt(const struct stat *src,struct stat64 *dest) { dest->st_dev=src->st_dev; dest->st_ino=src->st_ino; dest->st_mode=src->st_mode; dest->st_nlink=src->st_nlink; dest->st_uid=src->st_uid; dest->st_gid=src->st_gid; dest->st_rdev=src->st_rdev; dest->st_size=src->st_size; dest->st_blksize=src->st_blksize; dest->st_blocks=src->st_blocks; dest->st_atime=src->st_atime; dest->st_mtime=src->st_mtime; dest->st_ctime=src->st_ctime; } #endif dietlibc-0.33~cvs20120325/lib/__statfs64.c010064400000000000000000000011761173363226500146010ustar00#include #include "dietfeatures.h" #include #if __WORDSIZE == 32 extern int __dietlibc_statfs64(const char *path, size_t bufsize, struct statfs64 *__buf); extern void __statfs64_cvt(const struct statfs *src,struct statfs64 *dest); int statfs64(const char *__file, struct statfs64 *__buf) { #ifdef WANT_LARGEFILE_BACKCOMPAT if (__dietlibc_statfs64(__file,sizeof(*__buf),__buf)) { struct statfs temp; if (errno!=ENOSYS) return -1; if (statfs(__file,&temp)) return -1; __statfs64_cvt(&temp,__buf); } return 0; #else return __dietlibc_statfs64(__file,sizeof(*__buf),__buf); #endif } #endif dietlibc-0.33~cvs20120325/lib/__stime.c010064400000000000000000000003661173363226500142440ustar00#include #include #include #include #ifndef __NR_stime int stime(time_t *when) { struct timeval tv; tv.tv_sec = *when; tv.tv_usec = 0; return settimeofday(&tv, (struct timezone *)0); } #endif dietlibc-0.33~cvs20120325/lib/__sysctl.c010064400000000000000000000012201173363226500144320ustar00/* includes linux/sysctl.h, and we don't want to rely in Linux kernel * headers for building the diet libc: */ /* #include */ #include struct __sysctl_args { int *name; int nlen; void *oldval; size_t *oldlenp; void *newval; size_t newlen; unsigned long __unused[4]; }; extern int sysctl (int *, int, void *, size_t *, void *, size_t); int sysctl (int *name, int nlen, void *oldval, size_t *oldlenp, void *newval, size_t newlen) { struct __sysctl_args args; args.name = name; args.nlen = nlen; args.oldval = oldval; args.oldlenp = oldlenp; args.newval = newval; args.newlen = newlen; return (_sysctl (&args)); } dietlibc-0.33~cvs20120325/lib/__time.c010064400000000000000000000003741173363226500140600ustar00#include #include #include #ifndef __NR_time time_t time(time_t *t) { struct timeval tv; if (__unlikely(gettimeofday(&tv, NULL) < 0)) tv.tv_sec = -1; if (t) *t = tv.tv_sec; return tv.tv_sec; } #endif dietlibc-0.33~cvs20120325/lib/__truncate64.c010064400000000000000000000007641173363226500151240ustar00#include "dietfeatures.h" #include #ifdef WANT_LARGEFILE_BACKCOMPAT #include #include "syscalls.h" #include #ifndef __NO_STAT64 #ifdef __NR_truncate64 extern int __dietlibc_truncate64(const char* f, loff_t o); int truncate64(const char* f, loff_t o) { int tmp; if ((tmp=__dietlibc_truncate64(f,o))==-1) { if (errno!=ENOSYS) return -1; if (o>0x7fffffff) { errno=EOVERFLOW; return -1; } return truncate(f,o); } return tmp; } #endif #endif #endif dietlibc-0.33~cvs20120325/lib/__umount.c010064400000000000000000000002171173363226500144450ustar00#include #include "syscalls.h" #ifndef __NR_umount int umount(const char *target) { return umount2(target, 0); } #endif dietlibc-0.33~cvs20120325/lib/__utime.c010064400000000000000000000006001173363226500142350ustar00#include #include #ifndef __NR_utime int utime(const char *filename, const struct utimbuf *times) { if (times == NULL) return utimes(filename, NULL); else { struct timeval tvs[2]; tvs[0].tv_sec = times->actime; tvs[0].tv_usec = 0; tvs[1].tv_sec = times->modtime; tvs[1].tv_usec = 0; return utimes(filename, tvs); } } #endif dietlibc-0.33~cvs20120325/lib/__v_printf.c010064400000000000000000000201701173363226500147450ustar00#include "dietfeatures.h" #include #include #include #include #include #include "dietstdio.h" #include "dietwarning.h" #define MAX_WIDTH 10*1024 static inline unsigned long skip_to(const char *format) { unsigned long nr; for (nr=0; format[nr] && (format[nr]!='%'); ++nr); return nr; } #define A_WRITE(fn,buf,sz) ((fn)->put((void*)(buf),(sz),(fn)->data)) #define B_WRITE(fn,buf,sz) { if ((unsigned long)(sz) > (((unsigned long)(int)(-1))>>1) || len+(int)(sz)15;len-=16,nr+=16) { A_WRITE(fn,pad_line[(padwith=='0')?1:0],16); } if (len>0) { A_WRITE(fn,pad_line[(padwith=='0')?1:0],(unsigned int)len); nr+=len; } *dlen += nr; return 0; } int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr) { unsigned int len=0; #ifdef WANT_ERROR_PRINTF int _errno = errno; #endif while (*format) { unsigned long sz = skip_to(format); if (sz) { B_WRITE(fn,format,sz); len+=sz; format+=sz; } if (*format=='%') { char buf[128]; union { char*s; } u_str; #define s u_str.s int retval; unsigned char ch, padwith=' ', precpadwith=' '; char flag_in_sign=0; char flag_upcase=0; char flag_hash=0; char flag_left=0; char flag_space=0; char flag_sign=0; char flag_dot=0; signed char flag_long=0; unsigned int base; unsigned int width=0, preci=0; long number=0; #ifdef WANT_LONGLONG_PRINTF long long llnumber=0; #endif ++format; inn_printf: switch(ch=*format++) { case 0: return -1; break; /* FLAGS */ case '#': flag_hash=-1; case 'h': --flag_long; goto inn_printf; #if __WORDSIZE != 64 case 'j': #endif case 'q': /* BSD ... */ case 'L': ++flag_long; /* fall through */ #if __WORDSIZE == 64 case 'j': #endif case 'z': case 'l': ++flag_long; goto inn_printf; case '-': flag_left=1; goto inn_printf; case ' ': flag_space=1; goto inn_printf; case '+': flag_sign=1; goto inn_printf; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if(flag_dot) return -1; width=strtoul(format-1,(char**)&s,10); if (width>MAX_WIDTH) return -1; if (ch=='0' && !flag_left) padwith='0'; format=s; goto inn_printf; case '*': { /* A negative field width is taken as a '-' flag followed by * a positive field width **/ int tmp; if ((tmp=va_arg(arg_ptr,int))<0) { flag_left=1; tmp=-tmp; } if ((width=(unsigned long)tmp)>MAX_WIDTH) return -1; goto inn_printf; } case '.': flag_dot=1; if (*format=='*') { int tmp=va_arg(arg_ptr,int); preci=tmp<0?0:tmp; ++format; } else { long int tmp=strtol(format,(char**)&s,10); preci=tmp<0?0:tmp; format=s; } if (preci>MAX_WIDTH) return -1; goto inn_printf; /* print a char or % */ case 'c': ch=(char)va_arg(arg_ptr,int); case '%': B_WRITE(fn,&ch,1); ++len; break; #ifdef WANT_ERROR_PRINTF /* print an error message */ case 'm': s=strerror(_errno); sz=strlen(s); B_WRITE(fn,s,sz); len+=sz; break; #endif /* print a string */ case 's': s=va_arg(arg_ptr,char *); #ifdef WANT_NULL_PRINTF if (!s) s="(null)"; #endif sz = strlen(s); if (flag_dot && sz>preci) sz=preci; preci=0; flag_dot^=flag_dot; padwith=precpadwith=' '; print_out: { char *sign=s; int todo=0; int vs; if (! (width||preci) ) { B_WRITE(fn,s,sz); len+=sz; break; } if (flag_in_sign) todo=1; if (flag_hash>0) todo=flag_hash; if (todo) { s+=todo; sz-=todo; width-=todo; } /* These are the cases for 1234 or "1234" respectively: %.6u -> "001234" %6u -> " 1234" %06u -> "001234" %-6u -> "1234 " %.6s -> "1234" %6s -> " 1234" %06s -> " 1234" %-6s -> "1234 " %6.5u -> " 01234" %6.5s -> " 1234" In this code, for %6.5s, 6 is width, 5 is preci. flag_dot means there was a '.' and preci is set. flag_left means there was a '-'. sz is 4 (strlen("1234")). padwith will be '0' for %06u, ' ' otherwise. precpadwith is '0' for %u, ' ' for %s. */ if (flag_dot && width==0) width=preci; if (!flag_dot) preci=sz; if (!flag_left && padwith==' ') { /* do left-side padding with spaces */ if (write_pad(&len,fn,width-preci,padwith)) return -1; } if (todo) { B_WRITE(fn,sign,todo); len+=todo; } if (!flag_left && padwith!=' ') { /* do left-side padding with '0' */ if (write_pad(&len,fn,width-preci,padwith)) return -1; } /* do preci padding */ if (write_pad(&len,fn,preci-sz,precpadwith)) return -1; /* write actual string */ B_WRITE(fn,s,sz); len+=sz; if (flag_left) { if (write_pad(&len,fn,width-preci,padwith)) return -1; } break; } /* print an integer value */ case 'b': base=2; sz=0; goto num_printf; case 'p': flag_hash=2; flag_long=1; ch='x'; case 'X': flag_upcase=(ch=='X'); case 'x': base=16; sz=0; if (flag_hash) { buf[1]='0'; buf[2]=ch; flag_hash=2; sz=2; } if (preci>width) width=preci; goto num_printf; case 'd': case 'i': flag_in_sign=1; case 'u': base=10; sz=0; goto num_printf; case 'o': base=8; sz=0; if (flag_hash) { buf[1]='0'; flag_hash=1; ++sz; } num_printf: s=buf+1; if (flag_long>0) { #ifdef WANT_LONGLONG_PRINTF if (flag_long>1) llnumber=va_arg(arg_ptr,long long); else #endif number=va_arg(arg_ptr,long); } else { number=va_arg(arg_ptr,int); if (sizeof(int) != sizeof(long) && !flag_in_sign) number&=((unsigned int)-1); } if (flag_in_sign) { #ifdef WANT_LONGLONG_PRINTF if ((flag_long>1)&&(llnumber<0)) { llnumber=-llnumber; flag_in_sign=2; } else #endif if (number<0) { number=-number; flag_in_sign=2; } } if (flag_long<0) number&=0xffff; if (flag_long<-1) number&=0xff; #ifdef WANT_LONGLONG_PRINTF if (flag_long>1) retval = __lltostr(s+sz,sizeof(buf)-5,(unsigned long long) llnumber,base,flag_upcase); else #endif retval = __ltostr(s+sz,sizeof(buf)-5,(unsigned long) number,base,flag_upcase); /* When 0 is printed with an explicit precision 0, the output is empty. */ if (flag_dot && retval == 1 && s[sz] == '0') { if (preci == 0||flag_hash > 0) { sz = 0; } flag_hash = 0; } else sz += retval; if (flag_in_sign==2) { *(--s)='-'; ++sz; } else if ((flag_in_sign)&&(flag_sign || flag_space)) { *(--s)=(flag_sign)?'+':' '; ++sz; } else flag_in_sign=0; precpadwith='0'; goto print_out; #ifdef WANT_FLOATING_POINT_IN_PRINTF /* print a floating point value */ case 'f': case 'g': { int g=(ch=='g'); double d=va_arg(arg_ptr,double); s=buf+1; if (width==0) width=1; if (!flag_dot) preci=6; if (flag_sign || d < +0.0) flag_in_sign=1; sz=__dtostr(d,s,sizeof(buf)-1,width,preci,g); if (flag_dot) { char *tmp; if ((tmp=strchr(s,'.'))) { if (preci || flag_hash) ++tmp; while (preci>0 && *++tmp) --preci; *tmp=0; } else if (flag_hash) { s[sz]='.'; s[++sz]='\0'; } } if (g) { char *tmp,*tmp1; /* boy, is _this_ ugly! */ if ((tmp=strchr(s,'.'))) { tmp1=strchr(tmp,'e'); while (*tmp) ++tmp; if (tmp1) tmp=tmp1; while (*--tmp=='0') ; if (*tmp!='.') ++tmp; *tmp=0; if (tmp1) strcpy(tmp,tmp1); } } if ((flag_sign || flag_space) && d>=0) { *(--s)=(flag_sign)?'+':' '; ++sz; } sz=strlen(s); if (width #include #include #include #include #include #include "dietstdio.h" #include "dietwarning.h" #define A_GETC(fn) (++consumed,(fn)->getch((fn)->data)) #define A_PUTC(c,fn) (--consumed,(fn)->putch((c),(fn)->data)) int __v_scanf(struct arg_scanf* fn, const char *format, va_list arg_ptr) { unsigned int ch; /* format act. char */ int n=0; /* arg_ptr tmps */ #ifdef WANT_FLOATING_POINT_IN_SCANF double *pd; float *pf; #endif #ifdef WANT_LONGLONG_SCANF long long *pll; #endif long *pl; short *ph; int *pi; char *s; unsigned int consumed=0; /* get one char */ int tpch= A_GETC(fn); //while ((tpch!=-1)&&(*format)) while (*format) { ch=*format++; switch (ch) { /* end of format string ?!? */ case 0: return 0; /* skip spaces ... */ case ' ': case '\f': case '\t': case '\v': case '\n': case '\r': while((*format)&&(isspace(*format))) ++format; while(isspace(tpch)) tpch=A_GETC(fn); break; /* format string ... */ case '%': { unsigned int _div=0; int width=-1; char flag_width=0; char flag_discard=0; char flag_half=0; char flag_long=0; char flag_longlong=0; in_scan: ch=*format++; if(ch!='n' && tpch==-1) goto err_out; switch (ch) { /* end of format string ?!? */ case 0: return 0; /* check for % */ case '%': if ((unsigned char)tpch != ch) goto err_out; tpch=A_GETC(fn); break; /* FLAGS */ case '*': flag_discard=1; goto in_scan; case 'h': flag_half=1; goto in_scan; case 'l': if (flag_long) flag_longlong=1; flag_long=1; goto in_scan; case 'q': case 'L': flag_longlong=1; goto in_scan; /* WIDTH */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': width=strtol(format-1,&s,10); format=s; flag_width=1; goto in_scan; /* scan for integer / strtol reimplementation ... */ case 'p': case 'X': case 'x': _div+=6; case 'd': _div+=2; case 'o': _div+=8; case 'u': case 'i': { #ifdef WANT_LONGLONG_SCANF unsigned long long v=0; #else unsigned long v=0; #endif unsigned int consumedsofar; int neg=0; while(isspace(tpch)) tpch=A_GETC(fn); if (tpch=='-') { tpch=A_GETC(fn); neg=1; } if (tpch=='+') tpch=A_GETC(fn); if (tpch==-1) return n; consumedsofar=consumed; if (!flag_width) { if ((_div==16) && (tpch=='0')) goto scan_hex; if (!_div) { _div=10; if (tpch=='0') { _div=8; scan_hex: tpch=A_GETC(fn); if ((tpch|32)=='x') { tpch=A_GETC(fn); _div=16; } } } } while ((width)&&(tpch!=-1)) { register unsigned long c=tpch&0xff; #ifdef WANT_LONGLONG_SCANF register unsigned long long d=c|0x20; #else register unsigned long d=c|0x20; #endif c=(d>='a'?d-'a'+10:c<='9'?c-'0':0xff); if (c>=_div) break; d=v*_div; #ifdef WANT_LONGLONG_SCANF v=(d=-((unsigned long long)LLONG_MIN)) { l=(neg)?LLONG_MIN:LLONG_MAX; } else { if (neg) v*=-1; } #else register long l=v; if (v>=-((unsigned long)LONG_MIN)) { l=(neg)?LONG_MIN:LONG_MAX; } else { if (neg) v*=-1; } #endif } if (!flag_discard) { #ifdef WANT_LONGLONG_SCANF if (flag_longlong) { pll=(long long *)va_arg(arg_ptr,long long*); *pll=v; } else #endif if (flag_long) { pl=(long *)va_arg(arg_ptr,long*); *pl=v; } else if (flag_half) { ph=(short*)va_arg(arg_ptr,short*); *ph=v; } else { pi=(int *)va_arg(arg_ptr,int*); *pi=v; } if(consumedsofar error */ while (width && (tpch!=-1) && (!isspace(tpch))) { if (!flag_discard) *s=tpch; if (tpch) ++s; else break; --width; tpch=A_GETC(fn); } if (!flag_discard) { *s=0; ++n; } break; /* consumed-count */ case 'n': if (!flag_discard) { pi=(int *)va_arg(arg_ptr,int *); // ++n; /* in accordance to ANSI C we don't count this conversion */ *pi=consumed-1; } break; #ifdef WANT_CHARACTER_CLASSES_IN_SCANF case '[': { char cset[256]; int flag_not=0; int flag_dash=0; int matched=0; memset(cset,0,sizeof(cset)); ch=*format++; /* first char specials */ if (ch=='^') { flag_not=1; ch=*format++; } if ((ch=='-')||(ch==']')) { cset[ch]=1; ch=*format++; } /* almost all non special chars */ for (;(*format) && (*format!=']');++format) { if (flag_dash) { register unsigned char tmp=*format; for (;ch<=tmp;++ch) cset[ch]=1; flag_dash=0; ch=*format; } else if (*format=='-') flag_dash=1; else { cset[ch]=1; ch=*format; } } /* last char specials */ if (flag_dash) cset['-']=1; else cset[ch]=1; /* like %c or %s */ if (!flag_discard) s=(char *)va_arg(arg_ptr,char*); while (width && (tpch>=0) && (cset[tpch]^flag_not)) { if (!flag_discard) *s=tpch; if (tpch) ++s; else break; --width; tpch=A_GETC(fn); matched=1; } if (!flag_discard) *s=0; ++format; if (matched && !flag_discard) ++n; } break; #endif default: goto err_out; } } break; /* check if equal format string... */ default: if ((unsigned char)tpch != ch) goto err_out; tpch=A_GETC(fn); break; } } /* maybe a "%n" follows */ if(*format) { while(isspace(*format)) format++; if(format[0] == '%' && format[1] == 'n') { pi = (int *) va_arg(arg_ptr, int *); *pi = consumed - 1; } } err_out: if (tpch<0 && n==0) return EOF; A_PUTC(tpch,fn); return n; } link_warning("__v_scanf","warning: the scanf functions add several kilobytes of bloat."); dietlibc-0.33~cvs20120325/lib/_brk.c010064400000000000000000000004761173363226500135440ustar00#include extern void* __diet_brk(void *end_data_segment); void* __curbrk=0; int __libc_brk(void *end_data_segment); int __libc_brk(void *end_data_segment) { return ((__curbrk=__diet_brk(end_data_segment))==(void*)-1?-1:0); } int brk(void *end_data_segment) __attribute__((weak,alias("__libc_brk"))); dietlibc-0.33~cvs20120325/lib/_getpriority.c010064400000000000000000000003241173363226500153370ustar00#include extern int __syscall_getpriority(int which, int who); int getpriority(int which, int who) { int r; r = __syscall_getpriority(which, who); if (r >= 0) r = 20 - r; return r; } dietlibc-0.33~cvs20120325/lib/abort.c010064400000000000000000000006351173363226500137330ustar00#include #include #include #include #ifndef __PIC__ void __stdio_flushall(void) __attribute__((weak)); void __stdio_flushall(void) { } #else #include "dietstdio.h" #endif void abort() { sigset_t t; __stdio_flushall(); if (!sigemptyset(&t) && !sigaddset(&t, SIGABRT)) sigprocmask(SIG_UNBLOCK, &t, 0); while (1) if (raise(SIGABRT)) exit(127); } dietlibc-0.33~cvs20120325/lib/abs.c010064400000000000000000000002331173363226500133630ustar00#include #include int abs(int i) { return i>=0?i:-i; } #if __WORDSIZE == 32 long labs(long i) __attribute__((alias("abs"))); #endif dietlibc-0.33~cvs20120325/lib/accept.c010064400000000000000000000006371173363226500140650ustar00#include "syscalls.h" #ifdef __NR_socketcall #include extern int socketcall(int callno,long* args); int __libc_accept(int a, void * addr, void * addr2); int __libc_accept(int a, void * addr, void * addr2) { long args[] = { a, (long) addr, (long) addr2 }; return socketcall(SYS_ACCEPT, args); } int accept(int a, void * addr, void * addr2) __attribute__((weak,alias("__libc_accept"))); #endif dietlibc-0.33~cvs20120325/lib/adjtime.c010064400000000000000000000007101173363226500142330ustar00#include #include int adjtime (const struct timeval *itv, struct timeval *otv) { struct timex tmp; if (itv) { tmp.offset = (itv->tv_usec % 1000000L) + (itv->tv_sec + itv->tv_usec / 1000000L) * 1000000L; tmp.modes = ADJ_OFFSET_SINGLESHOT; } else tmp.modes = 0; if (adjtimex(&tmp)==-1) return -1; if (otv) { otv->tv_usec = tmp.offset % 1000000; otv->tv_sec = tmp.offset / 1000000; } return 0; } dietlibc-0.33~cvs20120325/lib/alloc.c010064400000000000000000000134551173363226500137220ustar00/* * malloc/free by O.Dreesen * * first TRY: * lists w/magics * and now the second TRY * let the kernel map all the stuff (if there is something to do) */ #include #include #include #include "dietfeatures.h" #include #include #include #include #include #include /* for PAGE_SIZE */ /* -- HELPER CODE --------------------------------------------------------- */ #ifndef MAP_FAILED #define MAP_FAILED ((void*)-1) #endif #ifndef NULL #define NULL ((void*)0) #endif typedef struct { void* next; size_t size; } __alloc_t; #define BLOCK_START(b) (((void*)(b))-sizeof(__alloc_t)) #define BLOCK_RET(b) (((void*)(b))+sizeof(__alloc_t)) #define MEM_BLOCK_SIZE PAGE_SIZE #define PAGE_ALIGN(s) (((s)+MEM_BLOCK_SIZE-1)&(unsigned long)(~(MEM_BLOCK_SIZE-1))) /* a simple mmap :) */ #if defined(__i386__) #define REGPARM(x) __attribute__((regparm(x))) #else #define REGPARM(x) #endif static void REGPARM(1) *do_mmap(size_t size) { return mmap(0, size, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, -1, (size_t)0); } /* -- SMALL MEM ----------------------------------------------------------- */ static __alloc_t* __small_mem[8]; #define __SMALL_NR(i) (MEM_BLOCK_SIZE/(i)) #define __MIN_SMALL_SIZE __SMALL_NR(256) /* 16 / 32 */ #define __MAX_SMALL_SIZE __SMALL_NR(2) /* 2048 / 4096 */ #define GET_SIZE(s) (__MIN_SMALL_SIZE<>__ind_shift(); while(size) { size>>=1; ++idx; } // } return idx; } /* small mem */ static void __small_free(void*_ptr,size_t _size) REGPARM(2); static void REGPARM(2) __small_free(void*_ptr,size_t _size) { __alloc_t* ptr=BLOCK_START(_ptr); size_t size=_size; size_t idx=get_index(size); #ifdef WANT_FREE_OVERWRITE memset(ptr,0x55,size); /* allways zero out small mem */ #else memset(ptr,0,size); /* allways zero out small mem */ #endif ptr->next=__small_mem[idx]; __small_mem[idx]=ptr; } static void* REGPARM(1) __small_malloc(size_t _size) { __alloc_t *ptr; size_t size=_size; size_t idx; idx=get_index(size); ptr=__small_mem[idx]; if (ptr==0) { /* no free blocks ? */ register int i,nr; ptr=do_mmap(MEM_BLOCK_SIZE); if (ptr==MAP_FAILED) return MAP_FAILED; __small_mem[idx]=ptr; nr=__SMALL_NR(size)-1; for (i=0;inext=(((void*)ptr)+size); ptr=ptr->next; } ptr->next=0; ptr=__small_mem[idx]; } /* get a free block */ __small_mem[idx]=ptr->next; ptr->next=0; return ptr; } /* -- PUBLIC FUNCTIONS ---------------------------------------------------- */ static void _alloc_libc_free(void *ptr) { register size_t size; if (ptr) { size=((__alloc_t*)BLOCK_START(ptr))->size; if (size) { if (size<=__MAX_SMALL_SIZE) __small_free(ptr,size); else munmap(BLOCK_START(ptr),size); } } } void __libc_free(void *ptr) __attribute__((alias("_alloc_libc_free"))); void free(void *ptr) __attribute__((weak,alias("_alloc_libc_free"))); void if_freenameindex(void* ptr) __attribute__((alias("free"))); #ifdef WANT_MALLOC_ZERO static __alloc_t zeromem[2]; #endif static void* _alloc_libc_malloc(size_t size) { __alloc_t* ptr; size_t need; #ifdef WANT_MALLOC_ZERO if (!size) return BLOCK_RET(zeromem); #else if (!size) goto err_out; #endif size+=sizeof(__alloc_t); if (sizesize=need; return BLOCK_RET(ptr); err_out: (*__errno_location())=ENOMEM; return 0; } void* __libc_malloc(size_t size) __attribute__((alias("_alloc_libc_malloc"))); void* malloc(size_t size) __attribute__((weak,alias("_alloc_libc_malloc"))); void* __libc_calloc(size_t nmemb, size_t _size); void* __libc_calloc(size_t nmemb, size_t _size) { register size_t size=_size*nmemb; if (nmemb && size/nmemb!=_size) { (*__errno_location())=ENOMEM; return 0; } #ifdef WANT_FREE_OVERWRITE if (size<__MAX_SMALL_SIZE) { void* x=malloc(size); memset(x,0,size); return x; } else #endif return malloc(size); } void* calloc(size_t nmemb, size_t _size) __attribute__((weak,alias("__libc_calloc"))); void* __libc_realloc(void* ptr, size_t _size); void* __libc_realloc(void* ptr, size_t _size) { register size_t size=_size; if (ptr) { if (size) { __alloc_t* tmp=BLOCK_START(ptr); size+=sizeof(__alloc_t); if (sizesize!=size) { if ((tmp->size<=__MAX_SMALL_SIZE)) { void *new=_alloc_libc_malloc(_size); if (new) { register __alloc_t* foo=BLOCK_START(new); size=foo->size; if (size>tmp->size) size=tmp->size; if (size) memcpy(new,ptr,size-sizeof(__alloc_t)); _alloc_libc_free(ptr); } ptr=new; } else { register __alloc_t* foo; size=PAGE_ALIGN(size); foo=mremap(tmp,tmp->size,size,MREMAP_MAYMOVE); if (foo==MAP_FAILED) { retzero: (*__errno_location())=ENOMEM; ptr=0; } else { foo->size=size; ptr=BLOCK_RET(foo); } } } } else { /* size==0 */ _alloc_libc_free(ptr); ptr = NULL; } } else { /* ptr==0 */ if (size) { ptr=_alloc_libc_malloc(size); } } return ptr; } void* realloc(void* ptr, size_t size) __attribute__((weak,alias("__libc_realloc"))); dietlibc-0.33~cvs20120325/lib/assert_fail.c010064400000000000000000000016141173363226500151160ustar00#include #include #include #include "dietwarning.h" #include void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function); void __assert_fail (const char *assertion, const char *file, unsigned int line, const char *function) { unsigned int alen=strlen(assertion); unsigned int flen=strlen(file); unsigned int fulen=function?strlen(function):0; char *buf=(char*)alloca(alen+flen+fulen+50); if (buf) { char *tmp; *buf=0; if (file) strcat(strcat(buf,file),":"); tmp=buf+strlen(buf); __ltostr(tmp,10,line,10,0); strcat(buf,": "); if (function) strcat(strcat(buf,function),": "); strcat(buf,"Assertion `"); strcat(buf,assertion); strcat(buf,"' failed.\n"); __write2(buf); } abort(); } link_warning("__assert_fail","warning: your code still has assertions enabled!") dietlibc-0.33~cvs20120325/lib/atexit.c010064400000000000000000000011221173363226500141120ustar00#include #include typedef void (*function)(void); #define NUM_ATEXIT 32 static function __atexitlist[NUM_ATEXIT]; static int atexit_counter; int atexit(function t) { if (atexit_counter double atof(const char *nptr) { #if 0 return strtod(nptr,0); #else double tmp=strtod(nptr,0); return tmp; #endif } dietlibc-0.33~cvs20120325/lib/atoi.c010064400000000000000000000005471173363226500135620ustar00#include #include #include #if __WORDSIZE == 64 int atoi(const char* s) { long int v=0; int sign=1; while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) s++; switch (*s) { case '-': sign=-1; case '+': ++s; } while ((unsigned int) (*s - '0') < 10u) { v=v*10+*s-'0'; ++s; } return sign==-1?-v:v; } #endif dietlibc-0.33~cvs20120325/lib/atol.c010064400000000000000000000007521173363226500135630ustar00#include #include #include long int atol(const char* s) { long int v=0; int sign=0; while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s; switch (*s) { case '-': sign=-1; case '+': ++s; } while ((unsigned int) (*s - '0') < 10u) { v=v*10+*s-'0'; ++s; } return sign?-v:v; } #if __WORDSIZE == 64 long long int atoll(const char* s) __attribute__((alias("atol"))); #else int atoi(const char* s) __attribute__((alias("atol"))); #endif dietlibc-0.33~cvs20120325/lib/atoll.c010064400000000000000000000005671173363226500137430ustar00#include #include #include #if __WORDSIZE != 64 long long int atoll(const char* s) { long long int v=0; int sign=1; while ( *s == ' ' || (unsigned int)(*s - 9) < 5u) ++s; switch (*s) { case '-': sign=-1; case '+': ++s; } while ((unsigned int) (*s - '0') < 10u) { v=v*10+*s-'0'; ++s; } return sign==-1?-v:v; } #endif dietlibc-0.33~cvs20120325/lib/bind.c010064400000000000000000000005501173363226500135340ustar00#include "syscalls.h" #ifdef __NR_socketcall #include extern int socketcall(int callno,long* args); int __libc_bind(int a, void * b, int c); int __libc_bind(int a, void * b, int c) { long args[] = { a, (long) b, c }; return socketcall(SYS_BIND, args); } int bind(int a, void * b, int c) __attribute__((weak,alias("__libc_bind"))); #endif dietlibc-0.33~cvs20120325/lib/binshstr.c010064400000000000000000000001231173363226500144500ustar00#include "binshstr.h" const char __binsh [] = "/bin/sh"; /* end of binshstr.c */ dietlibc-0.33~cvs20120325/lib/bsearch.c010064400000000000000000000007051173363226500142310ustar00#include #include void *bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compar)(const void* , const void* )) { size_t m; while (__likely(nmemb)) { int tmp; void *p; m=nmemb/2; p=(void *) (((const char *) base) + (m * size)); if ((tmp=(*compar)(key,p))<0) { nmemb=m; } else if (tmp>0) { base=p+size; nmemb-=m+1; } else return p; } return 0; } dietlibc-0.33~cvs20120325/lib/btowc.c010064400000000000000000000003621173363226500137370ustar00#include #include "dietlocale.h" wint_t btowc(int c) { if (c==0) return 0; if (c==EOF) return WEOF; switch (lc_ctype) { case CT_8BIT: return c>0xff?WEOF:1; case CT_UTF8: return c>0x7f?WEOF:1; } return WEOF; } dietlibc-0.33~cvs20120325/lib/cfgetospeed.c010064400000000000000000000003731173363226500151130ustar00#include #include speed_t cfgetospeed(const struct termios *termios_p) { return ((termios_p->c_cflag & (CBAUD|CBAUDEX))); } speed_t cfgetispeed(const struct termios *termios_p) __attribute__((weak,alias("cfgetospeed"))); dietlibc-0.33~cvs20120325/lib/cfmakeraw.c010064400000000000000000000005341173363226500145620ustar00#include #include void cfmakeraw(struct termios *t) { t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); t->c_oflag &= ~OPOST; t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); t->c_cflag &= ~(CSIZE|PARENB); t->c_cflag |= CS8; t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 0; } dietlibc-0.33~cvs20120325/lib/cfsetispeed.c010064400000000000000000000007231173363226500151200ustar00#include #include #include "dietfeatures.h" #define IBAUD0 020000000000 int cfsetispeed(struct termios *termios_p, speed_t speed) { if ((speed & (speed_t)~CBAUD) != 0 && (speed < B57600 || speed > B460800)) { errno=EINVAL; return -1; } if (speed == 0) termios_p->c_iflag |= IBAUD0; else { termios_p->c_iflag &= ~IBAUD0; termios_p->c_cflag &= ~(CBAUD | CBAUDEX); termios_p->c_cflag |= speed; } return 0; } dietlibc-0.33~cvs20120325/lib/cfsetospeed.c010064400000000000000000000005151173363226500151250ustar00#include #include #include "dietfeatures.h" int cfsetospeed(struct termios *termios_p, speed_t speed) { if ((speed & (speed_t)~CBAUD) != 0 && (speed < B57600 || speed > B460800)) { errno=EINVAL; return -1; } termios_p->c_cflag &= ~(CBAUD | CBAUDEX); termios_p->c_cflag |= speed; return 0; } dietlibc-0.33~cvs20120325/lib/closedir.c010064400000000000000000000003041173363226500144210ustar00#include "dietdirent.h" #include #include #include #include int closedir (DIR* d) { int res=close(d->fd); munmap (d, PAGE_SIZE); return res; } dietlibc-0.33~cvs20120325/lib/connect.c010064400000000000000000000005671173363226500142610ustar00#include "syscalls.h" #ifdef __NR_socketcall #include extern int socketcall(int callno,long* args); int __libc_connect(int a, void * b, int c); int __libc_connect(int a, void * b, int c) { long args[] = { a, (long) b, c }; return socketcall(SYS_CONNECT, args); } int connect(int a, void * b, int c) __attribute__((weak,alias("__libc_connect"))); #endif dietlibc-0.33~cvs20120325/lib/creat.c010064400000000000000000000003771173363226500137250ustar00#include int __libc_creat(const char *file,mode_t mode); int __libc_creat(const char *file,mode_t mode) { return open(file,O_WRONLY|O_CREAT|O_TRUNC,mode); } int creat(const char *file,mode_t mode) __attribute__((weak,alias("__libc_creat"))); dietlibc-0.33~cvs20120325/lib/creat64.c010064400000000000000000000002631173363226500140710ustar00#include #ifndef O_LARGEFILE #define O_LARGEFILE 0 #endif int creat64(const char *file,mode_t mode) { return open(file,O_WRONLY|O_CREAT|O_TRUNC|O_LARGEFILE,mode); } dietlibc-0.33~cvs20120325/lib/div.c010064400000000000000000000004211173363226500133770ustar00#include "dietwarning.h" #include div_t div(int numerator, int denominator) { div_t x; x.quot=numerator/denominator; x.rem=numerator-x.quot*denominator; return x; } link_warning("div","warning: your code uses div(), which is completely superfluous!"); dietlibc-0.33~cvs20120325/lib/errlistu.c010064400000000000000000000001431173363226500144670ustar00/* * used by perror() and strerror() */ const char __sys_err_unknown [] = "[unknown error]"; dietlibc-0.33~cvs20120325/lib/errno_location.c010064400000000000000000000001621173363226500156340ustar00extern int errno; int *__errno_location(void) __attribute__((weak)); int *__errno_location() { return &errno; } dietlibc-0.33~cvs20120325/lib/exec_lib.c010064400000000000000000000007511173363226500143750ustar00#include #include #include extern char **environ; int __exec_shell(const char *file, char *const argv[]); int __exec_shell(const char *file, char *const argv[]) { int i; const char** shell_argv; for (i = 0; argv[i]; ++i); ++i; shell_argv=alloca(sizeof(char*)*(i+1)); shell_argv[0] = _PATH_BSHELL; shell_argv[1] = file; for (; i > 1; i--) shell_argv[i] = argv[i - 1]; return execve(_PATH_BSHELL, (char*const*)shell_argv, environ); } dietlibc-0.33~cvs20120325/lib/exec_lib.h010064400000000000000000000002321173363226500143740ustar00#ifndef __EXEC_LIB_H #define __EXEC_LIB_H #include extern int __exec_shell(const char *file, char *const argv[]); #endif /* __EXEC_LIB_H */ dietlibc-0.33~cvs20120325/lib/execl.c010064400000000000000000000007761173363226500137320ustar00#include #include #include #include #include "dietfeatures.h" int execl( const char *path,...) { va_list ap,bak; int n,i; char **argv,*tmp; va_start(ap, path); va_copy(bak,ap); n=1; while ((tmp=va_arg(ap,char *))) ++n; va_end (ap); if ((argv=(char **)alloca(n*sizeof(char*)))) { for (i=0; i #include #include #include #include "dietfeatures.h" int execle( const char *path,...) { va_list ap; int n,i; char **argv,*tmp, **env; va_start(ap, path); n=1; while ((tmp=va_arg(ap,char *))) ++n; va_end (ap); if ((argv=(char **)alloca(n*sizeof(char*)))) { va_start(ap, path); for (i=0; i #include #include #include #include "dietfeatures.h" int execlp(const char* file, const char *arg,...) { va_list ap,bak; int n,i; char **argv,*tmp; va_start(ap, arg); va_copy(bak,ap); n=2; while ((tmp=va_arg(ap,char *))) ++n; va_end (ap); if ((argv=(char **)alloca(n*sizeof(char*)))) { argv[0]=(char*)arg; for (i=0; i #include #include #include #include #include "exec_lib.h" #include "dietfeatures.h" int execv(const char *file, char *const argv[]) { if (execve(file,argv,environ)==-1) { if (errno==ENOEXEC) __exec_shell(file,argv); } return -1; } dietlibc-0.33~cvs20120325/lib/execvp.c010064400000000000000000000022041173363226500141100ustar00#include #include #include #include #include #include "exec_lib.h" #include "dietfeatures.h" int execvp(const char *file, char *const argv[]) { const char *path=getenv("PATH"); char *cur,*next; char buf[PATH_MAX]; if (strchr((char*)file,'/')) { if (execve(file,argv,environ)==-1) { if (errno==ENOEXEC) __exec_shell(file,argv); return -1; } } if (!path) path=_PATH_DEFPATH; for (cur=(char*)path; cur; cur=next) { next=strchr(cur,':'); if (!next) next=cur+strlen(cur); if (next==cur) { buf[0]='.'; cur--; } else { if (next-cur>=PATH_MAX-3) { error: errno=EINVAL; return -1; } memmove(buf,cur,(size_t)(next-cur)); } buf[next-cur]='/'; { int len=strlen(file); if (len+(next-cur)>=PATH_MAX-2) goto error; memmove(&buf[next-cur+1],file,strlen(file)+1); } if (execve(buf,argv,environ)==-1) { if (errno==ENOEXEC) return __exec_shell(buf,argv); if ((errno!=EACCES) && (errno!=ENOENT) && (errno!=ENOTDIR)) return -1; } if (*next==0) break; next++; } return -1; } dietlibc-0.33~cvs20120325/lib/fdopendir.c010064400000000000000000000006111173363226500145700ustar00#include "dietdirent.h" #include #include #include #include #include DIR* fdopendir ( int fd ) { DIR* t = NULL; if ( fd >= 0 ) { t = (DIR *) mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (t == MAP_FAILED) lose: close (fd); else t->fd = fd; } return t; } dietlibc-0.33~cvs20120325/lib/ffs.c010064400000000000000000000010401173363226500133710ustar00#include int ffs(int i) { int plus=0; /* return index of rightmost bit set */ /* ffs(1) == 1, ffs(2) == 2, ffs(256) == 9, ffs(257)=1 */ #if 0 if (sizeof(i)==8) /* fold 64-bit archs */ if ((i&0xffffffff)==0) { plus=32; i>>=32; } #endif if ((i&0xffff)==0) { plus+=16; i>>=16; } if ((i&0xff)==0) { plus+=8; i>>=8; } if ((i&0xf)==0) { plus+=4; i>>=4; } if (i&1) return plus+1; if (i&2) return plus+2; if (i&4) return plus+3; if (i&8) return plus+4; return 0; } dietlibc-0.33~cvs20120325/lib/fstatvfs.c010064400000000000000000000004371173363226500144640ustar00#define _FILE_OFFSET_BITS 64 #include #include extern void __statvfs_cvt(struct statfs* from,struct statvfs* to); int fstatvfs(int fd, struct statvfs *sv) { struct statfs ss; if (fstatfs(fd,&ss)==-1) return -1; __statvfs_cvt(&ss,sv); return 0; } dietlibc-0.33~cvs20120325/lib/ftw.c010064400000000000000000000037151173363226500134260ustar00#include #include #include #include #include #include #include #include #ifdef __dietlibc__ #include "dietdirent.h" #endif #ifndef O_DIRECTORY #define O_DIRECTORY 0 #endif int ftw(const char*dir,int(*f)(const char*file,const struct stat*sb,int flag),int dpth){ char* cd; size_t cdl; DIR* d; struct dirent* de; struct stat sb; int r; unsigned int oldlen=0; char* filename = NULL; int previous=open(".",O_RDONLY|O_DIRECTORY); #if !defined(__dietlibc__) && !defined(__MINGW32__) int thisdir; #endif if (chdir(dir)) return-1; cd=alloca(PATH_MAX+1); if (!getcwd(cd,PATH_MAX) || !(d=opendir("."))) { close(previous); return -1; } cd[PATH_MAX]='\0'; cdl=strlen(cd); #if !defined(__dietlibc__) && !defined(__MINGW32__) if ((thisdir=open(".",O_RDONLY|O_DIRECTORY))==-1) { closedir(d); return; } #endif while((de=readdir(d))){ int flg; size_t nl; if(de->d_name[0]=='.'){if(!de->d_name[1])continue;if(de->d_name[1]=='.'&&!de->d_name[2])continue;} nl=strlen(de->d_name); if (nl+cdl+2>oldlen) filename=alloca(oldlen=nl+cdl+2); memmove(filename,cd,cdl); filename[cdl]='/'; memmove(filename+cdl+1,de->d_name,nl+1); if(!lstat(de->d_name,&sb)){ if(S_ISLNK(sb.st_mode))flg=FTW_SL;else if(S_ISDIR(sb.st_mode))flg=FTW_D;else flg=FTW_F; }else flg=FTW_NS; r=f(filename,&sb,flg); if(r){ err: #if !defined(__dietlibc__) && !defined(__MINGW32__) close(thisdir); #endif closedir(d); fchdir(previous); close(previous); return r; } if(flg==FTW_D&&dpth){ r=ftw(filename,f,dpth-1); #ifndef __dietlibc__ #ifdef __MINGW32__ chdir(".."); #else fchdir(thisdir); #endif #else fchdir(d->fd); #endif if (r) goto err; } } fchdir(previous); close(previous); #if !defined(__dietlibc__) && !defined(__MINGW32__) close(thisdir); #endif return closedir(d); } dietlibc-0.33~cvs20120325/lib/ftw64.c010064400000000000000000000041601173363226500135730ustar00#define _FILE_OFFSET_BITS 64 #include #include #include #include #include #include #include #include #ifdef __dietlibc__ #include "dietdirent.h" #endif #ifndef O_DIRECTORY #define O_DIRECTORY 0 #endif #ifdef __NO_STAT64 int ftw64(const char*dir,int(*f)(const char*file,const struct stat* sb,int flag),int dpth) __THROW; #endif int ftw64(const char*dir,int(*f)(const char*file,const struct stat* sb,int flag),int dpth){ char* cd; size_t cdl; DIR* d; struct dirent* de; struct stat sb; int r; unsigned int oldlen=0; char* filename = NULL; int previous=open(".",O_RDONLY|O_DIRECTORY); #if !defined(__dietlibc__) && !defined(__MINGW32__) int thisdir; #endif if (chdir(dir)) return -1; cd=alloca(PATH_MAX+1); if (!getcwd(cd,PATH_MAX) || !(d=opendir("."))) { close(previous); return -1; } cd[PATH_MAX]='\0'; cdl=strlen(cd); #if !defined(__dietlibc__) && !defined(__MINGW32__) if ((thisdir=open(".",O_RDONLY|O_DIRECTORY))==-1) { closedir(d); return -1; } #endif while((de=readdir(d))){ int flg; size_t nl; if(de->d_name[0]=='.'){if(!de->d_name[1])continue;if(de->d_name[1]=='.'&&!de->d_name[2])continue;} nl=strlen(de->d_name); if (nl+cdl+2>oldlen) filename=alloca(oldlen=nl+cdl+2); memmove(filename,cd,cdl); filename[cdl]='/'; memmove(filename+cdl+1,de->d_name,nl+1); if(!lstat(de->d_name,&sb)){ if(S_ISLNK(sb.st_mode))flg=FTW_SL;else if(S_ISDIR(sb.st_mode))flg=FTW_D;else flg=FTW_F; }else flg=FTW_NS; r=f(filename,&sb,flg); if(r){ err: #if !defined(__dietlibc__) && !defined(__MINGW32__) close(thisdir); #endif closedir(d); fchdir(previous); close(previous); return r; } if(flg==FTW_D&&dpth){ r=ftw(filename,f,dpth-1); #ifndef __dietlibc__ #ifdef __MINGW32__ chdir(".."); #else fchdir(thisdir); #endif #else fchdir(d->fd); #endif if (r) goto err; } } fchdir(previous); close(previous); #if !defined(__dietlibc__) && !defined(__MINGW32__) close(thisdir); #endif return closedir(d); } dietlibc-0.33~cvs20120325/lib/getdomainname.c010064400000000000000000000005401173363226500154270ustar00#define _GNU_SOURCE #include #include #include int getdomainname(char *name,size_t len) { struct utsname u; int res=uname(&u); if (res==0) { size_t i; if (len>=_UTSNAME_DOMAIN_LENGTH) len=_UTSNAME_DOMAIN_LENGTH; for (i=0; i #include extern char *getenv(const char *s) { int i; unsigned int len; if (!environ || !s) return 0; len = strlen(s); for (i = 0;environ[i];++i) if ((memcmp(environ[i],s,len)==0) && (environ[i][len] == '=')) return environ[i] + len + 1; return 0; } dietlibc-0.33~cvs20120325/lib/gethostname.c010064400000000000000000000005411173363226500151360ustar00#define _GNU_SOURCE #include #include #include int gethostname(char *name,size_t len) { struct utsname u; int res=uname(&u); if (res==0) { size_t i; if (len>=_UTSNAME_NODENAME_LENGTH) len=_UTSNAME_NODENAME_LENGTH; for (i=0; i #include static void getopterror(int which) { static char error1[]="Unknown option `-x'.\n"; static char error2[]="Missing argument for `-x'.\n"; if (opterr) { if (which) { error2[23]=optopt; write(2,error2,28); } else { error1[17]=optopt; write(2,error1,22); } } } int getopt(int argc, char * const argv[], const char *optstring) { static int lastidx,lastofs; char *tmp; if (optind==0) { optind=1; lastidx=0; } /* whoever started setting optind to 0 should be shot */ again: if (optind>argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0) return -1; if (argv[optind][1]=='-' && argv[optind][2]==0) { ++optind; return -1; } if (lastidx!=optind) { lastidx=optind; lastofs=0; } optopt=argv[optind][lastofs+1]; if ((tmp=strchr(optstring,optopt))) { if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */ ++optind; goto again; } if (tmp[1]==':') { /* argument expected */ if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */ if (!*(optarg=argv[optind]+lastofs+2)) optarg=0; goto found; } optarg=argv[optind+1]; if (!optarg) { /* missing argument */ ++optind; if (*optstring==':') return ':'; getopterror(1); return ':'; } ++optind; } else { ++lastofs; return optopt; } found: ++optind; return optopt; } else { /* not found */ getopterror(0); ++optind; return '?'; } } dietlibc-0.33~cvs20120325/lib/getpeername.c010064400000000000000000000006751173363226500151240ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_getpeername(int a, void * b, int *c); int __libc_getpeername(int a, void * b, int *c) { long args[] = { a, (long) b, (long) c }; return socketcall(SYS_GETPEERNAME, args); } int getpeername(int a, struct sockaddr* b, socklen_t *c) __attribute__((weak,alias("__libc_getpeername"))); #endif dietlibc-0.33~cvs20120325/lib/getpgrp.c010064400000000000000000000000761173363226500142730ustar00#include pid_t getpgrp() { return getpgid(0); } dietlibc-0.33~cvs20120325/lib/getsockname.c010064400000000000000000000006641173363226500151260ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_getsockname(int a, void * b, int c); int __libc_getsockname(int a, void * b, int c) { long args[] = { a, (long) b, c }; return socketcall(SYS_GETSOCKNAME, args); } int getsockname(int a, struct sockaddr* b, socklen_t* c) __attribute__((weak,alias("__libc_getsockname"))); #endif dietlibc-0.33~cvs20120325/lib/getsockopt.c010064400000000000000000000007461173363226500150110ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_getsockopt(int a, int b, int c, void *d, int e); int __libc_getsockopt(int a, int b, int c, void *d, int e) { long args[] = { a, b, c, (long)d, e }; return socketcall(SYS_GETSOCKOPT, args); } int getsockopt(int s, int level, int optname, void * optval, socklen_t *optlen) __attribute__((weak,alias("__libc_getsockopt"))); #endif dietlibc-0.33~cvs20120325/lib/htonl.c010064400000000000000000000004771173363226500137540ustar00#include #include uint32_t htonl(uint32_t hostlong) { #if __BYTE_ORDER==__LITTLE_ENDIAN return (hostlong>>24) | ((hostlong&0xff0000)>>8) | ((hostlong&0xff00)<<8) | (hostlong<<24); #else return hostlong; #endif } uint32_t ntohl(uint32_t hostlong) __attribute__((weak,alias("htonl"))); dietlibc-0.33~cvs20120325/lib/htons.c010064400000000000000000000004221173363226500137510ustar00#include #include uint16_t htons(uint16_t hostshort) { #if __BYTE_ORDER==__LITTLE_ENDIAN return ((hostshort>>8)&0xff) | (hostshort<<8); #else return hostshort; #endif } uint16_t ntohs(uint16_t hostshort) __attribute__((weak,alias("htons"))); dietlibc-0.33~cvs20120325/lib/if_indextoname.c010064400000000000000000000010441173363226500156100ustar00#include #include #include #include #ifndef SOCK_DGRAM #define SOCK_DGRAM 2 #endif char* if_indextoname(unsigned int interface,char* blub) { struct ifreq ifr; int fd; fd=socket(AF_INET6,SOCK_DGRAM,0); if (fd<0) fd=socket(AF_INET,SOCK_DGRAM,0); ifr.ifr_ifindex=interface; if (ioctl(fd,SIOCGIFNAME,&ifr)==0) { int i; close(fd); for (i=0; i #include #include #include #include #include struct if_nameindex* if_nameindex(void) { struct ifconf ic; int fd,len,i; struct if_nameindex* x=0,* y; char *dest; fd=socket(AF_INET6,SOCK_DGRAM,0); if (fd<0) fd=socket(AF_INET,SOCK_DGRAM,0); ic.ifc_buf=0; ic.ifc_len=0; if (ioctl(fd,SIOCGIFCONF,&ic)<0) goto b0rken; ic.ifc_buf=alloca((size_t)ic.ifc_len); if (ioctl(fd,SIOCGIFCONF,&ic)<0) goto b0rken; len=(ic.ifc_len/sizeof(struct ifreq)); x=(struct if_nameindex*)malloc((len+1)*sizeof(struct if_nameindex)+len*IFNAMSIZ); if (!x) goto b0rken; dest=(char*)(x+len+1); y=x; for (i=0; iif_name=dest; memcpy(dest,ir->ifr_name,IFNAMSIZ); if (ioctl(fd,SIOCGIFINDEX,ir)==-1) continue; y->if_index=ir->ifr_ifindex; dest+=IFNAMSIZ; ++y; } y->if_name=0; y->if_index=0; b0rken: close(fd); return x; } dietlibc-0.33~cvs20120325/lib/if_nametoindex.c010064400000000000000000000010161173363226500156070ustar00#include #include #include #include #ifndef SOCK_DGRAM #define SOCK_DGRAM 2 #endif unsigned int if_nametoindex(const char* blub) { struct ifreq ifr; int fd; int ret=0; char *tmp; int len=sizeof(ifr.ifr_name); fd=socket(AF_INET6,SOCK_DGRAM,0); if (fd<0) fd=socket(AF_INET,SOCK_DGRAM,0); for (tmp=ifr.ifr_name; len>0; --len) { if ((*tmp++=*blub++)==0) break; } if (ioctl(fd,SIOCGIFINDEX,&ifr)==0) ret=ifr.ifr_ifindex; close(fd); return ret; } dietlibc-0.33~cvs20120325/lib/ipv6constants.c010064400000000000000000000002171173363226500154410ustar00#include "netinet/in.h" const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; dietlibc-0.33~cvs20120325/lib/isalnum.c010064400000000000000000000002141173363226500142650ustar00#include int isalnum(int ch) { return (unsigned int)((ch | 0x20) - 'a') < 26u || (unsigned int)( ch - '0') < 10u; } dietlibc-0.33~cvs20120325/lib/isalpha.c010064400000000000000000000001361173363226500142410ustar00#include int isalpha(int ch) { return (unsigned int)((ch | 0x20) - 'a') < 26u; } dietlibc-0.33~cvs20120325/lib/isascii.c010064400000000000000000000001241173363226500142410ustar00#include int isascii ( int ch ) { return (unsigned int)ch < 128u; } dietlibc-0.33~cvs20120325/lib/isatty.c010064400000000000000000000004721173363226500141400ustar00#define ioctl libc_ioctl #include #undef ioctl #include #include #include #include "dietfeatures.h" int isatty(int fd) { int save; int is_tty; struct termios term; save = errno; is_tty = ioctl(fd, TCGETS, &term) == 0; errno = save; return is_tty; } dietlibc-0.33~cvs20120325/lib/isblank.c010064400000000000000000000001251173363226500142410ustar00#include int isblank ( int ch ) { return ch == ' ' || ch == '\t'; } dietlibc-0.33~cvs20120325/lib/iscntrl.c010064400000000000000000000003211173363226500142720ustar00#include int __iscntrl_ascii ( int ch ); int __iscntrl_ascii ( int ch ) { return (unsigned int)ch < 32u || ch == 127; } int iscntrl ( int ch ) __attribute__((weak,alias("__iscntrl_ascii"))); dietlibc-0.33~cvs20120325/lib/isdigit.c010064400000000000000000000003121173363226500142500ustar00#include int __isdigit_ascii ( int ch ); int __isdigit_ascii ( int ch ) { return (unsigned int)(ch - '0') < 10u; } int isdigit ( int ch ) __attribute__((weak,alias("__isdigit_ascii"))); dietlibc-0.33~cvs20120325/lib/isgraph.c010064400000000000000000000002731173363226500142570ustar00int __isgraph_ascii ( int ch ); int __isgraph_ascii ( int ch ) { return (unsigned int)(ch - '!') < 127u - '!'; } int isgraph ( int ch ) __attribute__((weak,alias("__isgraph_ascii"))); dietlibc-0.33~cvs20120325/lib/islower.c010064400000000000000000000003131173363226500143010ustar00#include int __islower_ascii ( int ch ); int __islower_ascii ( int ch ) { return (unsigned int) (ch - 'a') < 26u; } int islower ( int ch ) __attribute__((weak,alias("__islower_ascii"))); dietlibc-0.33~cvs20120325/lib/isprint.c010064400000000000000000000001561173363226500143120ustar00#include #include "dietlocale.h" int isprint (int ch) { ch&=0x7f; return (ch>=32 && ch<127); } dietlibc-0.33~cvs20120325/lib/ispunct.c010064400000000000000000000003371173363226500143100ustar00#include int __ispunct_ascii ( int ch ); int __ispunct_ascii ( int ch ) { return isprint (ch) && !isalnum (ch) && !isspace (ch); } int ispunct ( int ch ) __attribute__((weak,alias("__ispunct_ascii"))); dietlibc-0.33~cvs20120325/lib/isspace.c010064400000000000000000000003261173363226500142500ustar00#include int __isspace_ascii ( int ch ); int __isspace_ascii ( int ch ) { return (unsigned int)(ch - 9) < 5u || ch == ' '; } int isspace ( int ch ) __attribute__((weak,alias("__isspace_ascii"))); dietlibc-0.33~cvs20120325/lib/isupper.c010064400000000000000000000003121173363226500143030ustar00#include int __isupper_ascii ( int ch ); int __isupper_ascii ( int ch ) { return (unsigned int)(ch - 'A') < 26u; } int isupper ( int ch ) __attribute__((weak,alias("__isupper_ascii"))); dietlibc-0.33~cvs20120325/lib/iswalnum.c010064400000000000000000000003451173363226500144610ustar00#include #include int __iswalnum_ascii(wint_t c); int __iswalnum_ascii(wint_t c) { return (((unsigned char)c == c)?isalnum(c):0); } int iswalnum(wint_t c) __attribute__((weak,alias("__iswalnum_ascii"))); dietlibc-0.33~cvs20120325/lib/iswalpha.c010064400000000000000000000003451173363226500144320ustar00#include #include int __iswalpha_ascii(wint_t c); int __iswalpha_ascii(wint_t c) { return (((unsigned char)c == c)?isalpha(c):0); } int iswalpha(wint_t c) __attribute__((weak,alias("__iswalpha_ascii"))); dietlibc-0.33~cvs20120325/lib/iswblank.c010064400000000000000000000003031173363226500144260ustar00#include int __iswblank_ascii(wint_t c); int __iswblank_ascii(wint_t c) { return (c == ' ' || c == '\t'); } int iswblank(wint_t c) __attribute__((weak,alias("__iswblank_ascii"))); dietlibc-0.33~cvs20120325/lib/iswcntrl.c010064400000000000000000000003171173363226500144660ustar00#include int __iswcntrl_ascii(wint_t c); int __iswcntrl_ascii(wint_t c) { return ((unsigned int)c < 32u || c == 127); } int iswcntrl(wint_t c) __attribute__((weak,alias("__iswcntrl_ascii"))); dietlibc-0.33~cvs20120325/lib/iswdigit.c010064400000000000000000000001321173363226500144370ustar00#include int iswdigit(wint_t c) { return (unsigned int)(c - '0') < 10u; } dietlibc-0.33~cvs20120325/lib/iswgraph.c010064400000000000000000000003201173363226500144370ustar00#include int __iswgraph_ascii(wint_t c); int __iswgraph_ascii(wint_t c) { return (unsigned int)(c - '!') < 127u - '!'; } int iswgraph(wint_t c) __attribute__((weak,alias("__iswgraph_ascii"))); dietlibc-0.33~cvs20120325/lib/iswlower.c010064400000000000000000000003161173363226500144730ustar00#include int __iswlower_ascii(wint_t c); int __iswlower_ascii(wint_t c) { return (unsigned int) (c - 'a') < 26u; } int iswlower ( wint_t ch ) __attribute__((weak,alias("__iswlower_ascii"))); dietlibc-0.33~cvs20120325/lib/iswprint.c010064400000000000000000000003221173363226500144740ustar00#include int __iswprint_ascii(wint_t c); int __iswprint_ascii(wint_t c) { return (unsigned int)(c - ' ') < 127u - ' '; } int iswprint(wint_t c) __attribute__((weak,alias("__iswprint_ascii"))); dietlibc-0.33~cvs20120325/lib/iswpunct.c010064400000000000000000000003301173363226500144700ustar00#include int __iswpunct_ascii(wint_t c); int __iswpunct_ascii(wint_t c) { return iswprint (c) && !iswalnum(c) && !iswspace(c); } int iswpunct(wint_t c) __attribute__((weak,alias("__iswpunct_ascii"))); dietlibc-0.33~cvs20120325/lib/iswspace.c010064400000000000000000000003241173363226500144350ustar00#include int __iswspace_ascii(wint_t c); int __iswspace_ascii(wint_t c) { return (unsigned int)(c - 9) < 5u || c == ' '; } int iswspace(wint_t c) __attribute__((weak,alias("__iswspace_ascii"))); dietlibc-0.33~cvs20120325/lib/iswupper.c010064400000000000000000000003241173363226500144750ustar00#include int __iswupper_ascii ( wint_t c ); int __iswupper_ascii ( wint_t c ) { return (unsigned int)(c - 'A') < 26u; } int iswupper ( wint_t c ) __attribute__((weak,alias("__iswupper_ascii"))); dietlibc-0.33~cvs20120325/lib/iswxdigit.c010064400000000000000000000004161173363226500146340ustar00#include int __iswxdigit_ascii(wint_t c); int __iswxdigit_ascii(wint_t c) { return (unsigned int)( c - '0') < 10u || (unsigned int)((c | 0x20) - 'a') < 6u; } int iswxdigit(wint_t c) __attribute__((weak,alias("__iswxdigit_ascii"))); dietlibc-0.33~cvs20120325/lib/isxdigit.c010064400000000000000000000003731173363226500144470ustar00int __isxdigit_ascii ( int ch ); int __isxdigit_ascii ( int ch ) { return (unsigned int)( ch - '0') < 10u || (unsigned int)((ch | 0x20) - 'a') < 6u; } int isxdigit ( int ch ) __attribute__((weak,alias("__isxdigit_ascii"))); dietlibc-0.33~cvs20120325/lib/labs.c010064400000000000000000000004151173363226500135410ustar00#include #include #include #if __WORDSIZE == 64 long int labs(long int i) { return i>=0?i:-i; } long long int llabs(long long int i) __attribute__((alias("labs"))); intmax_t imaxabs(intmax_t i) __attribute__((alias("labs"))); #endif dietlibc-0.33~cvs20120325/lib/lc_ctype.c010064400000000000000000000000731173363226500144220ustar00#include "dietlocale.h" enum __encoding lc_ctype=CT_8BIT; dietlibc-0.33~cvs20120325/lib/ldiv.c010064400000000000000000000002451173363226500135570ustar00#include ldiv_t ldiv(long numerator, long denominator) { ldiv_t x; x.quot=numerator/denominator; x.rem=numerator-x.quot*denominator; return x; } dietlibc-0.33~cvs20120325/lib/listen.c010064400000000000000000000005531173363226500141210ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_listen(int a, int b); int __libc_listen(int a, int b) { long args[] = { a, b, 0 }; return socketcall(SYS_LISTEN, args); } int listen(int s, int backlog) __attribute__((weak,alias("__libc_listen"))); #endif dietlibc-0.33~cvs20120325/lib/llabs.c010064400000000000000000000003331173363226500137140ustar00#include #include #include #if __WORDSIZE != 64 long long int llabs(long long int i) { if (i<0) i=-i; return i; } intmax_t imaxabs(intmax_t i) __attribute__((alias("llabs"))); #endif dietlibc-0.33~cvs20120325/lib/lldiv.c010064400000000000000000000004731173363226500137360ustar00#define _GNU_SOURCE #include #include lldiv_t lldiv(long long numerator, long long denominator) { lldiv_t x; x.quot=numerator/denominator; x.rem=numerator-x.quot*denominator; return x; } imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator) __attribute__((alias("lldiv"))); dietlibc-0.33~cvs20120325/lib/lockf.c010064400000000000000000000013061173363226500137160ustar00#include #include #include #include #include "dietfeatures.h" int lockf(int fd, int cmd, off_t len) { struct flock fl; fl.l_whence=SEEK_CUR; fl.l_start=0; fl.l_len=len; fl.l_pid=0; switch (cmd) { case F_TEST: if (fcntl(fd,F_GETLK,&fl)<0) return -1; if (fl.l_type == F_UNLCK || fl.l_pid == getpid ()) return 0; errno=EACCES; return -1; case F_ULOCK: fl.l_type=F_UNLCK; cmd=F_SETLK; break; case F_LOCK: fl.l_type = F_WRLCK; cmd = F_SETLKW; break; case F_TLOCK: fl.l_type = F_WRLCK; cmd = F_SETLK; break; default: errno=EINVAL; return -1; } return fcntl(fd,cmd,&fl); } dietlibc-0.33~cvs20120325/lib/longjmp.c010064400000000000000000000011041173363226500142620ustar00#include #include void __longjmp(void*env,int val); void __libc_longjmp(sigjmp_buf env,int val); void __libc_longjmp(sigjmp_buf env,int val) { if (env[0].__mask_was_saved) { sigprocmask(SIG_SETMASK,(sigset_t*)&env[0].__saved_mask,0); } if (val==0) val=1; __longjmp(env[0].__jmpbuf,val); } void __siglongjmp(sigjmp_buf env,int val) __attribute__((alias("__libc_longjmp"))); void longjmp(sigjmp_buf env,int val) __attribute__((weak,alias("__libc_longjmp"))); void siglongjmp(sigjmp_buf env,int val) __attribute__((weak,alias("__libc_longjmp"))); dietlibc-0.33~cvs20120325/lib/lseek64.c010064400000000000000000000006101173363226500140720ustar00#include #include "dietfeatures.h" #include #ifndef __NO_STAT64 #include loff_t lseek64(int fildes, loff_t offset, int whence) { loff_t tmp; if (llseek(fildes,(unsigned long)(offset>>32),(unsigned long)offset&0xffffffff,&tmp,whence)) { if (errno!=ENOSYS) return -1; return (loff_t)lseek(fildes,(off_t)offset,whence); } return tmp; } #endif dietlibc-0.33~cvs20120325/lib/mblen.c010064400000000000000000000001511173363226500137120ustar00#include #include int mblen(const char* s,size_t n) { return mbrlen(s,n,NULL); } dietlibc-0.33~cvs20120325/lib/mbrlen.c010064400000000000000000000003121173363226500140730ustar00#include #include static mbstate_t internal; size_t mbrlen(const char *s, size_t n, mbstate_t *ps) { static mbstate_t internal; return mbrtowc (NULL, s, n, ps ?: &internal); } dietlibc-0.33~cvs20120325/lib/mbrtowc.c010064400000000000000000000024001173363226500142710ustar00#include "dietlocale.h" #include #include static mbstate_t internal; size_t mbrtowc(wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { size_t i; if (!ps) ps=&internal; if (!s) { if (ps->count) { errno=EILSEQ; return (size_t)-1; } else { ps->count=0; ps->sofar=0; return 0; } } for (i=0; icount) { /* we have an unfinished multibyte sequence */ if ((c&0xc0)!=0x80) { /* expected a continuation, didn't get one */ kaputt: errno=EILSEQ; ps->count=0; return (size_t)-1; } ps->sofar=(ps->sofar << 6) + (c & 0x3f); if (!--ps->count) { complete: if (pwc) { *pwc=ps->sofar; ++pwc; } if (ps->sofar) { ps->sofar=0; return i+1; } else { ps->count=0; ps->sofar=0; return 0; } } } else { if (c&0x80) { /* start of multibyte sequence? */ unsigned char x=c<<1; unsigned char cnt=0; while (x&0x80) { x<<=1; ++cnt; } if (!cnt || cnt>5) goto kaputt; ps->sofar=x>>(cnt+1); ps->count=cnt; } else { ps->sofar=c; goto complete; } } } } return n; } dietlibc-0.33~cvs20120325/lib/mbsinit.c010064400000000000000000000001231173363226500142610ustar00#include int mbsinit(const mbstate_t* s) { return (!s || s->sofar); } dietlibc-0.33~cvs20120325/lib/mbsrtowcs.c010064400000000000000000000005041173363226500146420ustar00#include size_t mbsrtowcs(wchar_t *dest, const char **src, size_t len, mbstate_t *ps) { const char* orig=*src; size_t i; if (!dest) len=(size_t)-1; for (i=0; i #include size_t mbstowcs(wchar_t *dest, const char *src, size_t n) { const char** s=&src; return mbsrtowcs(dest,s,n,NULL); } dietlibc-0.33~cvs20120325/lib/mbtowc.c010064400000000000000000000001761173363226500141170ustar00#include #include int mbtowc(wchar_t *pwc, const char *s, size_t n) { return mbrtowc(pwc,s,n,NULL); } dietlibc-0.33~cvs20120325/lib/memccpy.c010064400000000000000000000004641173363226500142610ustar00#define _POSIX_SOURCE #define _XOPEN_SOURCE #include #include void *memccpy(void *dst, const void *src, int c, size_t count) { char *a = dst; const char *b = src; while (count--) { *a++ = *b; if (*b==c) { return (void *)a; } b++; } return 0; } dietlibc-0.33~cvs20120325/lib/memchr.c010064400000000000000000000003651173363226500140770ustar00#include #include "dietfeatures.h" #include "dietstring.h" void* memchr(const void *s, int c, size_t n) { const unsigned char *pc = (unsigned char *) s; for (;n--;pc++) if (*pc == c) return ((void *) pc); return 0; } dietlibc-0.33~cvs20120325/lib/memcmp.c010064400000000000000000000010461173363226500140770ustar00#include #include /* gcc is broken and has a non-SUSv2 compliant internal prototype. * This causes it to warn about a type mismatch here. Ignore it. */ int memcmp(const void *dst, const void *src, size_t count) { register int r; register const unsigned char *d=dst; register const unsigned char *s=src; ++count; while (__likely(--count)) { if (__unlikely(r=(*d - *s))) return r; ++d; ++s; } return 0; } int bcmp(const char *a,const char *b,size_t c) __attribute__((weak,alias("memcmp"))); dietlibc-0.33~cvs20120325/lib/memcpy.c010064400000000000000000000021231173363226500141100ustar00/* fast memcpy -- Copyright (C) 2003 Thomas M. Ogrisegg */ #include #include "dietfeatures.h" #include "dietstring.h" void * memcpy (void *dst, const void *src, size_t n) { void *res = dst; unsigned char *c1, *c2; #ifdef WANT_SMALL_STRING_ROUTINES c1 = (unsigned char *) dst; c2 = (unsigned char *) src; while (n--) *c1++ = *c2++; return (res); #else int tmp; unsigned long *lx1 = NULL; const unsigned long *lx2 = NULL; if (!UNALIGNED(dst, src) && n > sizeof(unsigned long)) { if ((tmp = STRALIGN(dst))) { c1 = (unsigned char *) dst; c2 = (unsigned char *) src; while (tmp-- && n--) *c1++ = *c2++; if (n == (size_t) - 1) return (res); dst = c1; src = c2; } lx1 = (unsigned long *) dst; lx2 = (unsigned long *) src; for (; n >= sizeof(unsigned long); n -= sizeof(unsigned long)) *lx1++ = *lx2++; } if (n) { c1 = (unsigned char *) (lx1?lx1:dst); c2 = (unsigned char *) (lx1?lx2:src); while (n--) *c1++ = *c2++; } return (res); #endif } dietlibc-0.33~cvs20120325/lib/memmem.c010064400000000000000000000004631173363226500141000ustar00#define _GNU_SOURCE 23 #include #include void *memmem(const void* haystack, size_t hl, const void* needle, size_t nl) { int i; if (nl>hl) return 0; for (i=hl-nl+1; i; --i) { if (!memcmp(haystack,needle,nl)) return (char*)haystack; ++haystack; } return 0; } dietlibc-0.33~cvs20120325/lib/memmove.c010064400000000000000000000005761173363226500142750ustar00#define _POSIX_SOURCE #define _XOPEN_SOURCE #include #include void *memmove(void *dst, const void *src, size_t count) { char *a = dst; const char *b = src; if (src!=dst) { if (src>dst) { while (count--) *a++ = *b++; } else { a+=count-1; b+=count-1; while (count--) *a-- = *b--; } } return dst; } dietlibc-0.33~cvs20120325/lib/memrchr.c010064400000000000000000000004701173363226500142560ustar00#define _GNU_SOURCE #include #include void* memrchr(const void *s, int c, size_t n) { register const char* t=s; register const char* last=0; int i; for (i=n; i; --i) { if (*t==c) last=t; ++t; } return (void*)last; /* man, what an utterly b0rken prototype */ } dietlibc-0.33~cvs20120325/lib/memset.c010064400000000000000000000005731173363226500141170ustar00#include #include /* gcc is broken and has a non-SUSv2 compliant internal prototype. * This causes it to warn about a type mismatch here. Ignore it. */ void* memset(void * dst, int s, size_t count) { register char * a = dst; count++; /* this actually creates smaller code than using count-- */ while (--count) *a++ = s; return dst; } dietlibc-0.33~cvs20120325/lib/mkfifo.c010064400000000000000000000002031173363226500140660ustar00#include #include int mkfifo(const char *fn,mode_t mode) { return mknod(fn,(mode_t)(mode|S_IFIFO),0); } dietlibc-0.33~cvs20120325/lib/mmap64.c010064400000000000000000000012061173363226500137230ustar00#include #include #include #include #include #ifdef __NR_mmap2 void*__mmap2(void*start,size_t length,int prot,int flags,int fd,off_t pgoffset); void*__libc_mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset); void*__libc_mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset) { if (offset&(PAGE_SIZE-1)) { errno=-EINVAL; return MAP_FAILED; } return __mmap2(addr,len,prot,flags,fd,offset>>PAGE_SHIFT); } void*mmap64(void*addr,size_t len,int prot,int flags,int fd,off64_t offset) __attribute__((weak,alias("__libc_mmap64"))); #endif dietlibc-0.33~cvs20120325/lib/mq_getattr.c010064400000000000000000000001701173363226500147650ustar00#include int mq_getattr(mqd_t mqdes, struct mq_attr *mqstat) { return mq_setattr(mqdes, NULL, mqstat); } dietlibc-0.33~cvs20120325/lib/mq_receive.c010064400000000000000000000002641173363226500147410ustar00#include ssize_t mq_receive(mqd_t mqdes, char *msg_ptr, size_t msg_len, unsigned int *msg_prio) { return mq_timedreceive(mqdes, msg_ptr, msg_len, msg_prio, NULL); } dietlibc-0.33~cvs20120325/lib/mq_send.c010064400000000000000000000002601173363226500142440ustar00#include int mq_send (mqd_t mqdes, const char *msg_ptr, size_t msg_len, unsigned int msg_prio) { return mq_timedsend(mqdes, msg_ptr, msg_len, msg_prio, NULL); } dietlibc-0.33~cvs20120325/lib/msgctl.c010064400000000000000000000003151173363226500141100ustar00#include #include #include extern int __ipc(int,int,int,int,void*); int msgctl(int msqid, int cmd, struct msqid_ds *buf) { return __ipc(MSGCTL,msqid,cmd,0,buf); } dietlibc-0.33~cvs20120325/lib/msgget.c010064400000000000000000000002641173363226500141100ustar00#include #include #include extern int __ipc(int,key_t,int,int,int); int msgget(key_t key,int flag) { return __ipc(MSGGET,key,flag,0,0); } dietlibc-0.33~cvs20120325/lib/msgrcv.c010064400000000000000000000005641173363226500141260ustar00#include #include #include extern int __ipc(int,int,size_t,int,void*); struct ipc_kludge { struct msgbuf *msgp; long msgtyp; }; int msgrcv(int msqid, void *msgp, size_t msgsz, long int msgtyp, int msgflg) { struct ipc_kludge tmp; tmp.msgp = msgp; tmp.msgtyp = msgtyp; return __ipc(MSGRCV,msqid, msgsz, msgflg, &tmp); } dietlibc-0.33~cvs20120325/lib/msgsnd.c010064400000000000000000000003571173363226500141200ustar00#include #include #include extern int __ipc(int,int,size_t,int,const void*); int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg) { return __ipc(MSGSND,msqid, msgsz, msgflg, msgp); } dietlibc-0.33~cvs20120325/lib/nice.c010064400000000000000000000005701173363226500135400ustar00#define _REENTRANT #include #include #include int nice(int incr) { int prio; int res; errno=0; prio = getpriority(PRIO_PROCESS,0) + incr; if (prio < PRIO_MIN) prio=PRIO_MIN; if (prio >= PRIO_MAX) prio=PRIO_MAX-1; if (setpriority (PRIO_PROCESS, 0, prio)==-1) return -1; else return getpriority(PRIO_PROCESS, 0); } dietlibc-0.33~cvs20120325/lib/open64.c010064400000000000000000000005261173363226500137360ustar00#include #include #ifndef O_LARGEFILE #define O_LARGEFILE 0 #endif int __libc_open64(const char* file,int oflag,int mode); int __libc_open64(const char* file,int oflag,int mode) { return open(file,oflag|O_LARGEFILE,mode); } int open64(const char* file,int oflag,...) __attribute__((weak,alias("__libc_open64"))); dietlibc-0.33~cvs20120325/lib/opendir.c010064400000000000000000000010011173363226500142500ustar00#include "dietdirent.h" #include #include #include #include #include DIR* opendir ( const char* name ) { int fd = open (name, O_RDONLY | O_DIRECTORY); DIR* t = NULL; if ( fd >= 0 ) { if (fcntl (fd, F_SETFD, FD_CLOEXEC) < 0) goto lose; t = (DIR *) mmap (NULL, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (t == MAP_FAILED) lose: close (fd); else t->fd = fd; } return t; } dietlibc-0.33~cvs20120325/lib/perror.c010064400000000000000000000011161173363226500141300ustar00#include "dietfeatures.h" #include #include #include #define _BSD_SOURCE #undef __attribute_dontuse__ #define __attribute_dontuse__ #include extern const char __sys_err_unknown []; void perror ( const char* prepend ) { register const char* message = __sys_err_unknown; if ( (unsigned int) errno < (unsigned int) __SYS_NERR ) message = sys_errlist [errno]; if (prepend) { write ( 2, prepend, strlen(prepend) ); write ( 2, ": ", 2 ); } write ( 2, message, strlen(message) ); write ( 2, "\n", 1 ); } dietlibc-0.33~cvs20120325/lib/posix_fallocate.c010064400000000000000000000002441173363226500157740ustar00#define _GNU_SOURCE #define _XOPEN_SOURCE 600 #include int posix_fallocate(int fd, off64_t offset, off64_t len) { return fallocate(fd,0,offset,len); } dietlibc-0.33~cvs20120325/lib/pread.c010064400000000000000000000005371173363226500137200ustar00#include #include #include ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset); ssize_t __libc_pread(int fd, void *buf, size_t count, off_t offset) { return pread64(fd,buf,count,offset); } ssize_t pread(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pread"))); dietlibc-0.33~cvs20120325/lib/pselect.c010064400000000000000000000010501173363226500142530ustar00#include int pselect(int n, fd_set* readfds, fd_set* writefds, fd_set* exceptfds, const struct timespec *timeout, const sigset_t *sigmask) { struct timeval t; sigset_t old; int r; if (timeout) { t.tv_sec=timeout->tv_sec; t.tv_usec=timeout->tv_nsec/1000; if (!t.tv_sec && !t.tv_usec && timeout->tv_nsec) ++t.tv_usec; } if (sigmask) sigprocmask(SIG_SETMASK,sigmask,&old); r=select(n,readfds,writefds,exceptfds, timeout?&t:0); if (sigmask) sigprocmask(SIG_SETMASK,&old,0); return r; } dietlibc-0.33~cvs20120325/lib/putenv.c010064400000000000000000000016521173363226500141450ustar00#include #include #include int putenv(const char *string) { size_t len; int envc; int remove=0; char *tmp; const char **ep; char **newenv; static char **origenv; if (!origenv) origenv=environ; if (!(tmp=strchr(string,'='))) { len=strlen(string); remove=1; } else len=tmp-string; for (envc=0, ep=(const char**)environ; (ep && *ep); ++ep) { if (*string == **ep && !memcmp(string,*ep,len) && (*ep)[len]=='=') { if (remove) { for (; ep[1]; ++ep) ep[0]=ep[1]; ep[0]=0; return 0; } *ep=string; return 0; } ++envc; } if (tmp) { newenv = (char**) realloc(environ==origenv?0:environ, (envc+2)*sizeof(char*)); if (!newenv) return -1; if (envc && (environ==origenv)) { memcpy(newenv,origenv,envc*sizeof(char*)); } newenv[envc]=(char*)string; newenv[envc+1]=0; environ=newenv; } return 0; } dietlibc-0.33~cvs20120325/lib/pwrite.c010064400000000000000000000005501173363226500141320ustar00#include #include #include size_t __libc_pwrite(int fd, void *buf, size_t count, off_t offset); size_t __libc_pwrite(int fd, void *buf, size_t count, off_t offset) { return pwrite64(fd,buf,count,offset); } ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pwrite"))); dietlibc-0.33~cvs20120325/lib/qsort.c010064400000000000000000000030041173363226500137650ustar00#include #include static void exch(char* base,size_t size,size_t a,size_t b) { char* x=base+a*size; char* y=base+b*size; while (size) { char z=*x; *x=*y; *y=z; --size; ++x; ++y; } } /* Quicksort with 3-way partitioning, ala Sedgewick */ /* Blame him for the scary variable names */ /* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */ static void quicksort(char* base,size_t size,ssize_t l,ssize_t r, int (*compar)(const void*,const void*)) { ssize_t i=l-1, j=r, p=l-1, q=r, k; char* v=base+r*size; if (r<=l) return; for (;;) { while (++i != r && compar(base+i*size,v)<0) ; while (compar(v,base+(--j)*size)<0) if (j == l) break; if (i >= j) break; exch(base,size,i,j); if (compar(base+i*size,v)==0) exch(base,size,++p,i); if (compar(v,base+j*size)==0) exch(base,size,j,--q); } exch(base,size,i,r); j = i-1; ++i; for (k=l; kq; k--, i++) exch(base,size,i,k); quicksort(base,size,l,j,compar); quicksort(base,size,i,r,compar); } void qsort(void* base,size_t nmemb,size_t size,int (*compar)(const void*,const void*)) { /* check for integer overflows */ if (nmemb >= (((size_t)-1)>>1) || size >= (((size_t)-1)>>1)) return; #if 0 if (sizeof(size_t) < sizeof(unsigned long long)) { if ((unsigned long long)size * nmemb > (size_t)-1) return; } else { if (size*nmemb/nmemb != size) return; } #endif if (nmemb>1) quicksort(base,size,0,nmemb-1,compar); } dietlibc-0.33~cvs20120325/lib/raise.c010064400000000000000000000001641173363226500137240ustar00#include #include #include int raise(int sig) { return kill(getpid(),sig); } dietlibc-0.33~cvs20120325/lib/rand.c010064400000000000000000000003721173363226500135460ustar00#include static unsigned int seed=1; int rand(void) { return rand_r(&seed); } void srand(unsigned int i) { seed=i?i:23; } int random(void) __attribute__((alias("rand"))); void srandom(unsigned int i) __attribute__((alias("srand"))); dietlibc-0.33~cvs20120325/lib/rand48.c010064400000000000000000000030511173363226500137170ustar00#include static randbuf rand48buf; #define A_0 0xE66D #define A_1 0xDEEC #define A_2 0x5 #define C 0xB static randbuf a = { A_0, A_1, A_2 }; static unsigned short c = C; static void calc_next(randbuf buf) { randbuf tmp; long t; t = buf[0] * a[0] + c; tmp[0] = t & 0xffff; tmp[1] = (t >> 16) & 0xffff; t = buf[1] * a[0] + buf[0] * a[1] + tmp[1]; tmp[1] = t & 0xffff; tmp[2] = (t >> 16) & 0xffff; t = buf[2] * a[0] + buf[1] * a[1] + buf[0] * a[2] + tmp[2]; tmp[2] = t & 0xffff; buf[0] = tmp[0]; buf[1] = tmp[1]; buf[2] = tmp[2]; } double drand48(void) { return erand48(rand48buf); } long lrand48(void) { return nrand48(rand48buf); } long mrand48(void) { return jrand48(rand48buf); } void srand48(long seed) { rand48buf[1] = (seed >> 16) & 0xffff; rand48buf[2] = seed & 0xffff; rand48buf[0] = 0x330e; a[0] = A_0; a[1] = A_1; a[2] = A_2; c = C; } unsigned short *seed48(randbuf buf) { static randbuf oldx; int i; for (i = 0; i < 3; i++) { oldx[i] = rand48buf[i]; rand48buf[i] = buf[i]; } a[0] = A_0; a[1] = A_1; a[2] = A_2; c = C; return (unsigned short *)&oldx; } void lcong48(unsigned short param[7]) { int i; for (i = 0; i < 3; i++) { rand48buf[i] = param[i]; a[i] = param[i + 3]; } c = param[6]; } long jrand48(randbuf buf) { long ret; ret = buf[2] << 16 | buf[1]; calc_next(buf); return ret; } long nrand48(randbuf buf) { return jrand48(buf) & 0x7FFFFFFFL; } double erand48(randbuf buf) { double ret; ret = ((buf[0] / 65536.0 + buf[1]) / 65536.0 + buf[2]) / 65536.0; calc_next(buf); return ret; } dietlibc-0.33~cvs20120325/lib/rand_r.c010064400000000000000000000010411173363226500140610ustar00/* Copyright (C) 2002 Luc Van Oostenryck This is free software. You can redistribute and modify it under the terms of the GNU General Public Public License. */ #include #include /* Knuth's TAOCP section 3.6 */ #define M ((1U<<31) -1) #define A 48271 #define Q 44488 // M/A #define R 3399 // M%A; R < Q !!! // FIXME: ISO C/SuS want a longer period int rand_r(unsigned int* seed) { int32_t X; X = *seed; X = A*(X%Q) - R * (int32_t) (X/Q); if (X < 0) X += M; *seed = X; return X; } dietlibc-0.33~cvs20120325/lib/readdir.c010064400000000000000000000005641173363226500142370ustar00#include "dietdirent.h" #include #include #include struct dirent* readdir(DIR *d) { if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) { int res=getdents(d->fd,(struct dirent*)d->buf,sizeof (d->buf)-1); if (res<=0) return 0; d->num=res; d->cur=0; } return (struct dirent*)(d->buf+d->cur); } dietlibc-0.33~cvs20120325/lib/readdir64.c010064400000000000000000000030751173363226500144110ustar00#include "dietfeatures.h" #include "dietdirent.h" #include #include #include #include #include #include "syscalls.h" #ifndef __NR_getdents64 #define WANT_LARGEFILE_BACKCOMPAT #endif #ifndef WANT_LARGEFILE_BACKCOMPAT struct dirent64* readdir64(DIR *d) { if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) { int res=getdents64(d->fd,(struct dirent64*)d->buf, sizeof (d->buf)-1); if (res<=0) return 0; d->num=res; d->cur=0; } return (struct dirent64*)(d->buf+d->cur); } #else struct dirent64* readdir64(DIR *d) { #ifdef __NR_getdents64 static int trygetdents64=1; #endif struct dirent* o; static struct dirent64 d64; #ifdef __NR_getdents64 again: if (!trygetdents64) { #endif if (!d->num || (d->cur += ((struct dirent*)(d->buf+d->cur))->d_reclen)>=d->num) { int res=getdents(d->fd,(struct dirent*)d->buf, sizeof (d->buf)-1); if (res<=0) return 0; d->num=res; d->cur=0; } o=(struct dirent*)(d->buf+d->cur); d64.d_ino=o->d_ino; d64.d_off=o->d_off; d64.d_reclen=o->d_reclen; strcpy(d64.d_name,o->d_name); d64.d_type=0; /* is this correct? */ return &d64; #ifdef __NR_getdents64 } if (!d->num || (d->cur += ((struct dirent64*)(d->buf+d->cur))->d_reclen)>=d->num) { int res=getdents64(d->fd,(struct dirent64*)d->buf,sizeof (d->buf)); if (res<=0) { if (errno==ENOSYS) { trygetdents64=0; goto again; } return 0; } d->num=res; d->cur=0; } return (struct dirent64*)(d->buf+d->cur); #endif } #endif dietlibc-0.33~cvs20120325/lib/reboot.c010064400000000000000000000002651173363226500141150ustar00#include int __reboot(unsigned int magic1, unsigned int magic2, int cmd); int reboot(int cmd) { return __reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd); } dietlibc-0.33~cvs20120325/lib/recv.c010064400000000000000000000007061173363226500135620ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_recv(int a, const void * b, size_t c, int flags); int __libc_recv(int a, const void * b, size_t c, int flags) { long args[] = { a, (long) b, c, flags }; return socketcall(SYS_RECV, args); } int recv(int a, const void * b, size_t c, int flags) __attribute__ ((weak, alias("__libc_recv"))); #endif dietlibc-0.33~cvs20120325/lib/recvfrom.c010064400000000000000000000010671173363226500144470ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_recvfrom(int a, const void * b, size_t c, int flags, void *to, void *tolen); int __libc_recvfrom(int a, const void * b, size_t c, int flags, void *to, void *tolen) { long args[] = { a, (long) b, c, flags, (long) to, (long) tolen }; return socketcall(SYS_RECVFROM, args); } int recvfrom(int a, const void * b, size_t c, int flags, void *to, void *tolen) __attribute__ ((weak,alias("__libc_recvfrom"))) ; #endif dietlibc-0.33~cvs20120325/lib/recvmsg.c010064400000000000000000000007021173363226500142650ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_recvmsg(int a, struct msghdr* msg, int flags); int __libc_recvmsg(int a, struct msghdr* msg, int flags) { long args[] = { a, (long) msg, flags }; return socketcall(SYS_RECVMSG, args); } int recvmsg(int a, struct msghdr *msg, int flags) __attribute__ ((weak,alias("__libc_recvmsg"))) ; #endif dietlibc-0.33~cvs20120325/lib/remove.c010064400000000000000000000003501173363226500141130ustar00#include #include #include "dietfeatures.h" #include int remove(const char* filename) { if (unlink(filename)) { if (errno==EISDIR) return rmdir(filename); return -1; } return 0; } dietlibc-0.33~cvs20120325/lib/rewind.c010064400000000000000000000001521173363226500141060ustar00#include #include void rewind( FILE *stream) { fseek(stream, 0L, SEEK_SET); } dietlibc-0.33~cvs20120325/lib/rewinddir.c010064400000000000000000000002351173363226500146070ustar00#include "dietdirent.h" #include #include void rewinddir(DIR *d) { if (lseek(d->fd,0,SEEK_SET) != (off_t)-1) d->num=d->cur=0; } dietlibc-0.33~cvs20120325/lib/sbrk.c010064400000000000000000000007441173363226500135660ustar00#include extern int __libc_brk(void *end_data_segment); extern void* __curbrk; void* __libc_sbrk(ptrdiff_t increment); void* __libc_sbrk(ptrdiff_t increment) { void* oldbrk; if (__curbrk==0) if (__libc_brk(0) < 0) return (void*)-1; if (increment==0) return __curbrk; oldbrk=__curbrk; if (__libc_brk((char*)oldbrk+increment)<0) return (void*)-1; return oldbrk; } void* sbrk (ptrdiff_t increment) __attribute__((weak,alias("__libc_sbrk"))); dietlibc-0.33~cvs20120325/lib/seekdir.c010064400000000000000000000003441173363226500142470ustar00#include "dietdirent.h" #include #include void seekdir(DIR *d,off_t offset) { if (lseek(d->fd,offset,SEEK_SET) != (off_t)-1) { d->num=d->cur=0; ((struct dirent *)(d->buf))->d_off = offset; } } dietlibc-0.33~cvs20120325/lib/semctl.c010064400000000000000000000007621173363226500141140ustar00#include #include extern int __ipc(int,int,int,int,void*); union semun { int val; /* value for SETVAL */ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */ unsigned short *array; /* array for GETALL & SETALL */ struct seminfo *__buf; /* buffer for IPC_INFO */ void *__pad; }; int semctl(int semid, int semnum, int cmd, union semun arg); int semctl(int semid, int semnum, int cmd, union semun arg) { return __ipc(SEMCTL,semid,semnum,cmd,&arg); } dietlibc-0.33~cvs20120325/lib/semget.c010064400000000000000000000003101173363226500140760ustar00#include #include #include extern int __ipc(int,key_t,int,int,int); int semget(key_t key, int nsems, int semflg) { return __ipc(SEMGET,key,nsems,semflg,0); } dietlibc-0.33~cvs20120325/lib/semop.c010064400000000000000000000003271173363226500137450ustar00#include #include #include extern int __ipc(int,int,unsigned,int,void*); int semop(int semid,struct sembuf *sops,unsigned nsops) { return __ipc(SEMOP,semid,nsops,0,sops); } dietlibc-0.33~cvs20120325/lib/send.c010064400000000000000000000007061173363226500135540ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_send(int a, const void * b, size_t c, int flags); int __libc_send(int a, const void * b, size_t c, int flags) { long args[] = { a, (long) b, c, flags }; return socketcall(SYS_SEND, args); } int send(int a, const void * b, size_t c, int flags) __attribute__ ((weak, alias("__libc_send"))); #endif dietlibc-0.33~cvs20120325/lib/sendmsg.c010064400000000000000000000007241173363226500142630ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_sendmsg(int a, const struct msghdr* msg, int flags); int __libc_sendmsg(int a, const struct msghdr* msg, int flags) { long args[] = { a, (long) msg, flags }; return socketcall(SYS_SENDMSG, args); } int sendmsg(int a, const struct msghdr *msg, int flags) __attribute__ ((weak,alias("__libc_sendmsg"))) ; #endif dietlibc-0.33~cvs20120325/lib/sendto.c010064400000000000000000000010711173363226500141130ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_sendto(int a, const void * b, size_t c, int flags, void *to, int tolen); int __libc_sendto(int a, const void * b, size_t c, int flags, void *to, int tolen) { long args[] = { a, (long) b, c, flags, (long) to, tolen }; return socketcall(SYS_SENDTO, args); } int sendto(int a, const void * b, size_t c, int flags, const struct sockaddr* to, socklen_t tolen) __attribute__ ((weak, alias("__libc_sendto"))); #endif dietlibc-0.33~cvs20120325/lib/setlinebuf.c010064400000000000000000000004701173363226500147610ustar00#include #include "dietwarning.h" #undef setlinebuf /* there is no previous prototype because it is a #define */ void setlinebuf(FILE* stream); void setlinebuf(FILE* stream) { setvbuf(stream,0,_IOLBF,BUFSIZ); } link_warning("setlinebuf","warning: you used setlinebuf without including ") dietlibc-0.33~cvs20120325/lib/setpgrp.c010064400000000000000000000000761173363226500143070ustar00#include int setpgrp() { return setpgid(0,0); } dietlibc-0.33~cvs20120325/lib/setsockopt.c010064400000000000000000000007651173363226500150260ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_setsockopt(int a, int b, int c, void *d, void *e); int __libc_setsockopt(int a, int b, int c, void *d, void *e) { long args[] = { a, b, c, (long)d, (long) e }; return socketcall(SYS_SETSOCKOPT, args); } int setsockopt(int s, int level, int optname, const void* optval, socklen_t optlen) __attribute__((weak,alias("__libc_setsockopt"))); #endif dietlibc-0.33~cvs20120325/lib/shmat.c010064400000000000000000000005431173363226500137360ustar00#include #include #include extern void* __ipc(int,int,int,void*,const void*); void* shmat(int shmid,const void* shmaddr,int shmflg) { void* raddr; register void* result; result=__ipc(SHMAT,shmid,shmflg,&raddr,shmaddr); if ((unsigned long)result <= -(unsigned long)8196) result=raddr; return result; } dietlibc-0.33~cvs20120325/lib/shmctl.c010064400000000000000000000003151173363226500141110ustar00#include #include #include extern int __ipc(int,int,int,int,void*); int shmctl(int shmid, int cmd, struct shmid_ds *buf) { return __ipc(SHMCTL,shmid,cmd,0,buf); } dietlibc-0.33~cvs20120325/lib/shmdt.c010064400000000000000000000002721173363226500137400ustar00#include #include #include extern int __ipc(int,int,int,int,const void*); int shmdt(const void* shmaddr) { return __ipc(SHMDT,0,0,0,shmaddr); } dietlibc-0.33~cvs20120325/lib/shmget.c010064400000000000000000000003061173363226500141060ustar00#include #include #include extern int __ipc(int,key_t,int,int,int); int shmget(key_t key, int size, int shmflg) { return __ipc(SHMGET,key,size,shmflg,0); } dietlibc-0.33~cvs20120325/lib/shutdown.c010064400000000000000000000005761173363226500145030ustar00#include "syscalls.h" #ifdef __NR_socketcall #include #include extern int socketcall(int callno,long* args); int __libc_shutdown(int s, int how); int __libc_shutdown(int s, int how) { long args[] = { s, (long) how, 0 }; return socketcall(SYS_SHUTDOWN, args); } int shutdown(int s, int how) __attribute__((weak,alias("__libc_shutdown"))); #endif dietlibc-0.33~cvs20120325/lib/sigaction.c010064400000000000000000000007451173363226500146060ustar00#include int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, long nr); int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) { return __rt_sigaction(signum, act, oldact, _NSIG/8); } int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) __attribute__((weak,alias("__libc_sigaction"))); dietlibc-0.33~cvs20120325/lib/sigaddset.c010064400000000000000000000007361173363226500145750ustar00#include #include #define __sigmask(sig) ( ((unsigned long)1) << (((sig)-1) % (8*sizeof(unsigned long))) ) #define __sigword(sig) ( ((sig)-1) / (8*sizeof(unsigned long)) ) int sigaddset(sigset_t *set, int signo) { if ((signo<1)||(signo>SIGRTMAX)) { (*__errno_location())=EINVAL; return -1; } else { unsigned long __mask = __sigmask (signo); unsigned long __word = __sigword (signo); set->sig[__word]|=__mask; return 0; } } dietlibc-0.33~cvs20120325/lib/sigandset.c010064400000000000000000000005301173363226500145770ustar00#define _GNU_SOURCE #include int sigandset(sigset_t*set,const sigset_t*left,const sigset_t*right) { set->sig[0]=left->sig[0]&right->sig[0]; if (_NSIG_WORDS>1) set->sig[1]=left->sig[1]&right->sig[1]; if (_NSIG_WORDS>2) { set->sig[2]=left->sig[2]&right->sig[2]; set->sig[3]=left->sig[3]&right->sig[3]; } return 0; } dietlibc-0.33~cvs20120325/lib/sigdelset.c010064400000000000000000000007371173363226500146120ustar00#include #include #define __sigmask(sig) ( ((unsigned long)1) << (((sig)-1) % (8*sizeof(unsigned long))) ) #define __sigword(sig) ( ((sig)-1) / (8*sizeof(unsigned long)) ) int sigdelset(sigset_t *set, int signo) { if ((signo<1)||(signo>SIGRTMAX)) { (*__errno_location())=EINVAL; return -1; } else { unsigned long __mask = __sigmask (signo); unsigned long __word = __sigword (signo); set->sig[__word]&=~__mask; return 0; } } dietlibc-0.33~cvs20120325/lib/sigemptyset.c010064400000000000000000000002731173363226500151770ustar00#include int sigemptyset(sigset_t *set) { set->sig[0]=0; if (_NSIG_WORDS>1) set->sig[1]=0; if (_NSIG_WORDS>2) { set->sig[2]=0; set->sig[3]=0; } return 0; } dietlibc-0.33~cvs20120325/lib/sigfillset.c010064400000000000000000000003711173363226500147660ustar00#include int sigfillset(sigset_t *set) { set->sig[0]=(unsigned long)-1; if (_NSIG_WORDS>1) set->sig[1]=(unsigned long)-1; if (_NSIG_WORDS>2) { set->sig[2]=(unsigned long)-1; set->sig[3]=(unsigned long)-1; } return 0; } dietlibc-0.33~cvs20120325/lib/siginterrupt.c010064400000000000000000000004021173363226500153530ustar00#include int siginterrupt(int sig, int flag) { int ret; struct sigaction act; sigaction(sig, 0, &act); if (flag) act.sa_flags &= ~SA_RESTART; else act.sa_flags |= SA_RESTART; ret = sigaction(sig, &act, 0); return ret; } dietlibc-0.33~cvs20120325/lib/sigisemptyset.c010064400000000000000000000003741173363226500155350ustar00#define _GNU_SOURCE #include int sigisemptyset(const sigset_t*set) { unsigned long ret; ret=set->sig[0]; if (_NSIG_WORDS>1) ret|=set->sig[1]; if (_NSIG_WORDS>2) { ret|=set->sig[2]; ret|=set->sig[3]; } return ret != 0; } dietlibc-0.33~cvs20120325/lib/sigismember.c010064400000000000000000000007461173363226500151350ustar00#include #include #define __sigmask(sig) ( ((unsigned long)1) << (((sig)-1) % (8*sizeof(unsigned long))) ) #define __sigword(sig) ( ((sig)-1) / (8*sizeof(unsigned long)) ) int sigismember(const sigset_t *set, int signo) { if ((signo<1)||(signo>SIGRTMAX)) { (*__errno_location())=EINVAL; return -1; } else { unsigned long __mask = __sigmask (signo); unsigned long __word = __sigword (signo); return (set->sig[__word] & __mask)?1:0; } } dietlibc-0.33~cvs20120325/lib/sigjmp.c010064400000000000000000000004501173363226500141100ustar00#include #include int __sigjmp_save(sigjmp_buf env,int savemask); int __sigjmp_save(sigjmp_buf env,int savemask) { env[0].__mask_was_saved = 0; if (savemask) { env[0].__mask_was_saved=(sigprocmask(SIG_BLOCK,(sigset_t*)0,&env[0].__saved_mask)==0); } return 0; } dietlibc-0.33~cvs20120325/lib/signal.c010064400000000000000000000005301173363226500140730ustar00#include sighandler_t signal(int signum, sighandler_t action) { struct sigaction sa,oa; sa.sa_handler=action; sigemptyset(&sa.sa_mask); if (sigaddset(&sa.sa_mask,signum) != 0) return SIG_ERR; sa.sa_flags = SA_NODEFER; /* FIXME ??? */ if (sigaction(signum,&sa,&oa) != 0) return SIG_ERR; return oa.sa_handler; } dietlibc-0.33~cvs20120325/lib/signalfd.c010064400000000000000000000004621173363226500144110ustar00#include #include #include extern int __signalfd(int fd,const sigset_t* mask,size_t nsig); int signalfd(int fd,const sigset_t* mask,int flags) { if (flags) { /* bizarre glibc bullshit */ errno=EINVAL; return -1; } return __signalfd(fd,mask,_NSIG/8); } dietlibc-0.33~cvs20120325/lib/sigorset.c010064400000000000000000000005271173363226500144630ustar00#define _GNU_SOURCE #include int sigorset(sigset_t*set,const sigset_t*left,const sigset_t*right) { set->sig[0]=left->sig[0]|right->sig[0]; if (_NSIG_WORDS>1) set->sig[1]=left->sig[1]|right->sig[1]; if (_NSIG_WORDS>2) { set->sig[2]=left->sig[2]|right->sig[2]; set->sig[3]=left->sig[3]|right->sig[3]; } return 0; } dietlibc-0.33~cvs20120325/lib/sigpending.c010064400000000000000000000002151173363226500147450ustar00#include int __rt_sigpending(sigset_t *set, long nr); int sigpending(sigset_t *set) { return __rt_sigpending(set, _NSIG/8); } dietlibc-0.33~cvs20120325/lib/sigprocmask.c010064400000000000000000000003401173363226500151370ustar00#include int __rt_sigprocmask(int how, const sigset_t *set, sigset_t *oldsetm, long nr); int sigprocmask(int how, const sigset_t *set, sigset_t *oldset) { return __rt_sigprocmask(how, set, oldset, _NSIG/8); } dietlibc-0.33~cvs20120325/lib/sigqueueinfo.c010064400000000000000000000002701173363226500153220ustar00#include int __rt_sigqueueinfo(pid_t pid, int sig, siginfo_t *info); int sigqueueinfo(pid_t pid, int sig, siginfo_t *info) { return __rt_sigqueueinfo(pid, sig, info); } dietlibc-0.33~cvs20120325/lib/sigsuspend.c010064400000000000000000000004501173363226500150030ustar00#include int __rt_sigsuspend(const sigset_t *mask, long nr); int __libc_sigsuspend(const sigset_t *mask); int __libc_sigsuspend(const sigset_t *mask) { return __rt_sigsuspend(mask, _NSIG/8); } int sigsuspend(const sigset_t *mask) __attribute__((weak,alias("__libc_sigsuspend"))); dietlibc-0.33~cvs20120325/lib/sigtimedwait.c010064400000000000000000000003761173363226500153200ustar00#include int __rt_sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *ts, long nr); int sigtimedwait(const sigset_t *set, siginfo_t *info, const struct timespec *ts) { return __rt_sigtimedwait(set,info,ts,_NSIG/8); } dietlibc-0.33~cvs20120325/lib/sigwait.c010064400000000000000000000002341173363226500142660ustar00#include int sigwait(const sigset_t* set,int* sig) { siginfo_t si; int r=sigwaitinfo(set,&si); if (r!=-1) *sig=si.si_signo; return r; } dietlibc-0.33~cvs20120325/lib/sleep.c010064400000000000000000000002631173363226500137310ustar00#include #include unsigned int sleep(unsigned int secs) { struct timespec t; t.tv_sec=secs; t.tv_nsec=0; nanosleep(&t,&t); return secs-t.tv_sec; } dietlibc-0.33~cvs20120325/lib/snprintf.c010064400000000000000000000003771173363226500144720ustar00#include #include #include int snprintf(char *str,size_t size,const char *format,...) { int n; va_list arg_ptr; va_start(arg_ptr, format); n=vsnprintf(str,size,format,arg_ptr); va_end (arg_ptr); return n; } dietlibc-0.33~cvs20120325/lib/socket.c010064400000000000000000000005401173363226500141070ustar00#include "syscalls.h" #ifdef __NR_socketcall #include extern int socketcall(int callno,long* args); int __libc_socket(int a, int b, int c); int __libc_socket(int a, int b, int c) { long args[] = { a, b, c }; return socketcall(SYS_SOCKET, args); } int socket(int a,int b,int c) __attribute__((weak,alias("__libc_socket"))); #endif dietlibc-0.33~cvs20120325/lib/socketpair.c010064400000000000000000000007131173363226500147650ustar00#include "syscalls.h" #ifdef __NR_socketcall #include extern int socketcall(int callno,long* args); int __libc_socketpair(int a, int type, int protocol, int sv[2]); int __libc_socketpair(int a, int type, int protocol, int sv[2]) { long args[] = { a, type, protocol, (long)sv }; return socketcall(SYS_SOCKETPAIR, args); } int socketpair(int d, int type, int protocol, int sv[2]) __attribute__((weak,alias("__libc_socketpair"))); #endif dietlibc-0.33~cvs20120325/lib/sprintf.c010064400000000000000000000004021173363226500143010ustar00#include #include #include #include int sprintf(char *dest,const char *format,...) { int n; va_list arg_ptr; va_start(arg_ptr, format); n=vsprintf(dest,format,arg_ptr); va_end (arg_ptr); return n; } dietlibc-0.33~cvs20120325/lib/sscanf.c010064400000000000000000000003331173363226500140740ustar00#include #include int sscanf(const char *str, const char *format, ...) { int n; va_list arg_ptr; va_start(arg_ptr, format); n=vsscanf(str,format,arg_ptr); va_end (arg_ptr); return n; } dietlibc-0.33~cvs20120325/lib/stack_smash_handler.c010064400000000000000000000010421173363226500166120ustar00#include #include /* this is only used with ProPolice in gcc 3.x */ void __stack_smash_handler(char* func,unsigned int damaged); void __stack_smash_handler(char* func,unsigned int damaged) { char buf[sizeof(char*)*2+1]; int i; for (i=0; i<(int)sizeof(buf)-1; ++i) { char c=damaged&0xf; c+=c<10?'0':'a'; buf[sizeof(buf)-2-i]=c; damaged>>=4; } buf[sizeof(buf)-1]=0; __write2("stack smashed in "); __write2(func); __write2(" (value 0x"); __write2(buf); __write2(")\n"); _exit(127); } dietlibc-0.33~cvs20120325/lib/stack_smash_handler2.c010064400000000000000000000005371173363226500167040ustar00#include #include void __stack_chk_fail(void); /* earlier versions of ProPolice actually gave the address and function * name as arguments to the handler, so it could print some useful * diagnostics. No more. :-( */ void __stack_chk_fail(void) { __write2("smashed stack detected, program terminated.\n"); _exit(127); } dietlibc-0.33~cvs20120325/lib/stack_smash_handler3.c010064400000000000000000000007251173363226500167040ustar00#include extern void __stack_chk_fail(void) __attribute__((noreturn)); /* this is only called from implicitly generated code, so there is no * explicit prototype anywhere */ void __attribute__((noreturn)) __stack_chk_fail_local(void); /* no idea why sometimes this is called instead of __stack_chk_fail, * but it apparently only happens with shared libraries */ void __attribute__((noreturn)) __stack_chk_fail_local(void) { __stack_chk_fail (); } dietlibc-0.33~cvs20120325/lib/stackgap.c010064400000000000000000000126041173363226500144200ustar00/* Warning: this code sets up the machine registers and segments needed * for -fstack-protector to work. If you compile this function with * -fstack-protector, it will reference those registers before they are * set up properly, causing a segmentation fault. Ubuntu adds * -fstack-protector to their gcc default options, so this breaks. I * added a workaround to the Makefile to make sure this code is always * compiled with -fno-stack-protector for this reason. Or, as a friend * put it: yo dawg. I herd u liek stack protektion. :-) */ #include #include #include #include #include #include #include #include #include "dietfeatures.h" #ifdef WANT_GNU_STARTUP_BLOAT char* program_invocation_name; char* program_invocation_short_name; #endif void* __vdso; extern int main(int argc,char* argv[],char* envp[]); #if defined(WANT_SSP) extern unsigned long __guard; #endif #if defined(WANT_VALGRIND_SUPPORT) int __valgrind=1; #endif #ifdef __i386__ int __modern_linux; #endif #ifdef WANT_TLS /* __tdatasize is the size of the initialized thread local data section * __tmemsize is the size of the complete thread local data section * (including uninitialized data) * __tdataptr is a pointer to the initialized thread local data section * __tmemsize is already rounded up to meet alignment * the final memory layout is [tdata] [tbss (zero)] [tcb] */ size_t __tdatasize, __tmemsize; void* __tdataptr; static void findtlsdata(long* auxvec) { #if (__WORDSIZE == 64) Elf64_Phdr* x=0; #else Elf32_Phdr* x=0; #endif size_t i,n=0; while (*auxvec) { if (auxvec[0]==3) { /* AT_PHDR */ x=(void*)auxvec[1]; if (n) break; } else if (auxvec[0]==5) { /* AT_PHNUM */ n=auxvec[1]; if (x) break; } auxvec+=2; } /* if we don't find the entry, the kernel let us down */ if (!x || !n) return; /* a kernel this old does not support thread local storage anyway */ for (i=0; itcb=mainthread; mainthread->dtv=0; mainthread->self=0; mainthread->multiple_threads=0; #if defined(WANT_SSP) mainthread->stack_guard=__guard; #endif #if defined(__x86_64__) arch_prctl(ARCH_SET_FS, mainthread); #elif defined(__i386__) unsigned int sd[4]; sd[0]=-1; sd[1]=(unsigned long int)mainthread; sd[2]=0xfffff; /* 4 GB limit */ sd[3]=0x51; /* bitfield, see struct user_desc in asm-i386/ldt.h */ if (__modern_linux>=0) { if (set_thread_area((struct user_desc*)(void*)&sd)==0) { asm volatile ("movw %w0, %%gs" :: "q" (sd[0]*8+3)); __modern_linux=1; } else __modern_linux=-1; } #elif defined(__alpha__) || defined(__s390__) __builtin_set_thread_pointer(mainthread); #elif defined(__ia64__) || defined(__powerpc__) register tcbhead_t* __thread_self __asm__("r13"); __thread_self=mainthread; #elif defined(__sparc__) register tcbhead_t* __thread_self __asm("%g7"); __thread_self=mainthread; #else #warning "no idea how to enable TLS on this platform, edit lib/stackgap.c" #endif } #endif static void* find_in_auxvec(long* x,long what) { while (*x) { if (*x==what) return (void*)x[1]; x+=2; } return NULL; } int stackgap(int argc,char* argv[],char* envp[]); int stackgap(int argc,char* argv[],char* envp[]) { long* auxvec=(long*)envp; #if defined(WANT_STACKGAP) || defined(WANT_SSP) || defined(WANT_TLS) char* rand; char* tlsdata; while (*auxvec) ++auxvec; ++auxvec; /* skip envp to get to auxvec */ #ifdef WANT_STACKGAP unsigned short s; #endif #if defined(WANT_STACKGAP) || defined(WANT_SSP) volatile char* gap; rand=find_in_auxvec(auxvec,25); if (!rand) { char myrand[10]; int fd=open("/dev/urandom",O_RDONLY); read(fd,myrand,10); close(fd); rand=myrand; } #endif #ifdef WANT_STACKGAP s=*(unsigned short*)(rand+8); #endif #ifdef WANT_SSP __guard=*(unsigned long*)rand; #endif #ifdef WANT_STACKGAP gap=alloca(s); #endif #endif __vdso=find_in_auxvec(auxvec,33); // AT_SYSINFO_EHDR -> vdso start address #ifdef __x86_64__ if (!__vdso) __vdso=(char*)0xffffffffff600000; #endif #ifdef WANT_TLS findtlsdata(auxvec); if (__unlikely(__tmemsize+sizeof(tcbhead_t)512*1024*1024) || __unlikely(__tmemsize<__tdatasize)) return 111; tlsdata=alloca(__tmemsize+sizeof(tcbhead_t)); memcpy(tlsdata,__tdataptr,__tdatasize); memset(tlsdata+__tdatasize,0,__tmemsize-__tdatasize); __setup_tls(__tcb_mainthread=(tcbhead_t*)(tlsdata+__tmemsize)); #elif defined(WANT_SSP) tlsdata=alloca(sizeof(tcbhead_t)); __setup_tls(__tcb_mainthread=(tcbhead_t*)(tlsdata)); #endif #if defined(WANT_VALGRIND_SUPPORT) { const char* v=getenv("LD_PRELOAD"); __valgrind=(v && strstr(v,"valgrind")); } #endif #ifdef WANT_GNU_STARTUP_BLOAT program_invocation_name=argv[0]; { char* c; for (c=program_invocation_short_name=program_invocation_name; *c; ++c) if (*c=='/') program_invocation_short_name=c+1; } #endif return main(argc,argv,envp); } dietlibc-0.33~cvs20120325/lib/statfs64_cvt.c010064400000000000000000000007661173363226500151630ustar00#include #if __WORDSIZE == 32 void __statfs64_cvt(const struct statfs *src,struct statfs64 *dest); void __statfs64_cvt(const struct statfs *src,struct statfs64 *dest) { dest->f_type=src->f_type; dest->f_bsize=src->f_bsize; dest->f_frsize=src->f_frsize; dest->f_blocks=src->f_blocks; dest->f_bfree=src->f_bfree; dest->f_files=src->f_files; dest->f_ffree=src->f_ffree; dest->f_bavail=src->f_bavail; dest->f_fsid=src->f_fsid; dest->f_namelen=src->f_namelen; } #endif dietlibc-0.33~cvs20120325/lib/statvfs.c010064400000000000000000000004521173363226500143130ustar00#define _FILE_OFFSET_BITS 64 #include #include extern void __statvfs_cvt(struct statfs* from,struct statvfs* to); int statvfs(const char *path, struct statvfs *sv) { struct statfs ss; if (statfs(path,&ss)==-1) return -1; __statvfs_cvt(&ss,sv); return 0; } dietlibc-0.33~cvs20120325/lib/statvfs_cvt.c010064400000000000000000000010171173363226500151650ustar00#define _FILE_OFFSET_BITS 64 #include #include void __statvfs_cvt(struct statfs* from,struct statvfs* to); void __statvfs_cvt(struct statfs* from,struct statvfs* to) { to->f_bsize=from->f_bsize; to->f_frsize=from->f_frsize; to->f_blocks=from->f_blocks; to->f_bfree=from->f_bfree; to->f_bavail=from->f_bavail; to->f_files=from->f_files; to->f_ffree=from->f_ffree; to->f_favail=from->f_ffree; to->f_fsid=from->f_fsid.__val[0]; to->f_flag=0; to->f_namemax=from->f_namelen; } dietlibc-0.33~cvs20120325/lib/strcasecmp.c010064400000000000000000000006721173363226500147710ustar00#include int strcasecmp ( const char* s1, const char* s2 ) { register unsigned int x2; register unsigned int x1; while (1) { x2 = *s2 - 'A'; if (__unlikely(x2 < 26u)) x2 += 32; x1 = *s1 - 'A'; if (__unlikely(x1 < 26u)) x1 += 32; s1++; s2++; if ( __unlikely(x2 != x1) ) break; if ( __unlikely(x1 == (unsigned int)-'A') ) break; } return x1 - x2; } dietlibc-0.33~cvs20120325/lib/strcat.c010064400000000000000000000005501173363226500141200ustar00#include "dietfeatures.h" #include char* strcat(register char* s,register const char* t) { char *dest=s; s+=strlen(s); for (;;) { if (!(*s = *t)) break; ++s; ++t; #ifndef WANT_SMALL_STRING_ROUTINES if (!(*s = *t)) break; ++s; ++t; if (!(*s = *t)) break; ++s; ++t; if (!(*s = *t)) break; ++s; ++t; #endif } return dest; } dietlibc-0.33~cvs20120325/lib/strchr.c010064400000000000000000000010631173363226500141250ustar00#include "dietfeatures.h" #include char *strchr(register const char *t, int c) { register char ch; ch = c; for (;;) { if (__unlikely(*t == ch)) break; if (__unlikely(!*t)) return 0; ++t; #ifndef WANT_SMALL_STRING_ROUTINES if (__unlikely(*t == ch)) break; if (__unlikely(!*t)) return 0; ++t; if (__unlikely(*t == ch)) break; if (__unlikely(!*t)) return 0; ++t; if (__unlikely(*t == ch)) break; if (__unlikely(!*t)) return 0; ++t; #endif } return (char*)t; } char *index(char *t,int c) __attribute__((weak,alias("strchr"))); dietlibc-0.33~cvs20120325/lib/strcmp.c010064400000000000000000000023551173363226500141350ustar00/* fast strcmp -- Copyright (C) 2003 Thomas M. Ogrisegg */ #include #include "dietfeatures.h" #include "dietstring.h" int strcmp (const char *s1, const char *s2) { #ifdef WANT_SMALL_STRING_ROUTINES while (*s1 && *s1 == *s2) s1++, s2++; return (*s1 - *s2); #else const unsigned long *lx1, *lx2; unsigned long l1, l2; int tmp; if (UNALIGNED(s1, s2)) { while (*s1 && *s1 == *s2) s1++, s2++; return (*s1 - *s2); } if ((tmp = STRALIGN(s1))) for (; tmp--; s1++, s2++) if (!*s1 || *s1 != *s2) return (*s1 - *s2); lx1 = (unsigned long *) s1; lx2 = (unsigned long *) s2; while (1) { l1 = *lx1++; l2 = *lx2++; if ((((l1 - MKW(0x1ul)) & ~l1) & MKW(0x80ul)) || ((((l2 - MKW(0x1ul)) & ~l2) & MKW(0x80ul))) || l1 != l2) { unsigned char c1, c2; while (1) { c1 = GFC(l1); c2 = GFC(l2); if (!c1 || c1 != c2) return (c1 - c2); INCSTR(l1); INCSTR(l2); } } } #endif } int strcoll(const char *s,const char* t) __attribute__((weak,alias("strcmp"))); dietlibc-0.33~cvs20120325/lib/strcpy.c010064400000000000000000000014431173363226500141460ustar00/* fast strcpy -- Copyright (C) 2003 Thomas M. Ogrisegg */ #include #include "dietfeatures.h" #include "dietstring.h" char * strcpy (char *s1, const char *s2) { char *res = s1; #ifdef WANT_SMALL_STRING_ROUTINES while ((*s1++ = *s2++)); return (res); #else int tmp; unsigned long l; if (UNALIGNED(s1, s2)) { while ((*s1++ = *s2++)); return (res); } if ((tmp = STRALIGN(s1))) { while (tmp-- && (*s1++ = *s2++)); if (tmp != -1) return (res); } while (1) { l = *(const unsigned long *) s2; if (((l - MKW(0x1ul)) & ~l) & MKW(0x80ul)) { while ((*s1++ = GFC(l))) INCSTR(l); return (res); } *(unsigned long *) s1 = l; s2 += sizeof(unsigned long); s1 += sizeof(unsigned long); } #endif } dietlibc-0.33~cvs20120325/lib/strcspn.c010064400000000000000000000003501173363226500143120ustar00#include #include size_t strcspn(const char *s, const char *reject) { size_t l=0; int i; for (; *s; ++s) { for (i=0; reject[i]; ++i) if (*s==reject[i]) return l; ++l; } return l; } dietlibc-0.33~cvs20120325/lib/strdup.c010064400000000000000000000002601173363226500141370ustar00#include #include char *strdup(const char *s) { size_t l=strlen(s)+1; char *tmp=(char *)malloc(l); if (!tmp) return 0; return memcpy(tmp,s,l); } dietlibc-0.33~cvs20120325/lib/strerror.c010064400000000000000000000007441173363226500145070ustar00#include "dietfeatures.h" #include #include #define _BSD_SOURCE #undef __attribute_dontuse__ #define __attribute_dontuse__ #include extern const char __sys_err_unknown[]; char*strerror(int errnum) { register const char*message=__sys_err_unknown; if ( (unsigned int)errnum < (unsigned int)__SYS_NERR ) message=sys_errlist[errnum]; #if defined(__mips__) if ( errnum == 1133 ) message="Quota exceeded"; #endif return (char*)message; } dietlibc-0.33~cvs20120325/lib/strlcat.c010064400000000000000000000047731173363226500143070ustar00/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ /* * Copyright (c) 1998 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include #include /* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left). At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(initial dst) + strlen(src); if retval >= siz, * truncation occurred. */ size_t strlcat(dst, src, siz) char *dst; const char *src; size_t siz; { register char *d = dst; register const char *s = src; register size_t n = siz; size_t dlen; /* Find the end of dst and adjust bytes left but don't go past end */ while (*d != '\0' && n-- != 0) d++; dlen = d - dst; n = siz - dlen; if (n == 0) return(dlen + strlen(s)); while (*s != '\0') { if (n != 1) { *d++ = *s; n--; } s++; } *d = '\0'; return(dlen + (s - src)); /* count does not include NUL */ } dietlibc-0.33~cvs20120325/lib/strlcpy.3010064400000000000000000000106221173363226500142410ustar00.\" $OpenBSD: strlcpy.3,v 1.10 2000/11/06 01:03:25 aaron Exp $ .\" .\" Copyright (c) 1998, 2000 Todd C. Miller .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. The name of the author may not be used to endorse or promote products .\" derived from this software without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, .\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY .\" AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL .\" THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, .\" EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, .\" PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; .\" OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR .\" OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF .\" ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. .\" .Dd June 22, 1998 .Dt STRLCPY 3 .Os .Sh NAME .Nm strlcpy , .Nm strlcat .Nd size-bounded string copying and concatenation .Sh SYNOPSIS .Fd #include .Ft size_t .Fn strlcpy "char *dst" "const char *src" "size_t size" .Ft size_t .Fn strlcat "char *dst" "const char *src" "size_t size" .Sh DESCRIPTION The .Fn strlcpy and .Fn strlcat functions copy and concatenate strings respectively. They are designed to be safer, more consistent, and less error prone replacements for .Xr strncpy 3 and .Xr strncat 3 . Unlike those functions, .Fn strlcpy and .Fn strlcat take the full size of the buffer (not just the length) and guarantee to NUL-terminate the result (as long as .Fa size is larger than 0 or, in the case of .Fn strlcat , as long as there is at least one byte free in .Fa dst ) . Note that you should include a byte for the NUL in .Fa size . Also note that .Fn strlcpy and .Fn strlcat only operate on true .Dq C strings. This means that for .Fn strlcpy .Fa src must be NUL-terminated and for .Fn strlcat both .Fa src and .Fa dst must be NUL-terminated. .Pp The .Fn strlcpy function copies up to .Fa size - 1 characters from the NUL-terminated string .Fa src to .Fa dst , NUL-terminating the result. .Pp The .Fn strlcat function appends the NUL-terminated string .Fa src to the end of .Fa dst . It will append at most .Fa size - strlen(dst) - 1 bytes, NUL-terminating the result. .Sh RETURN VALUES The .Fn strlcpy and .Fn strlcat functions return the total length of the string they tried to create. For .Fn strlcpy that means the length of .Fa src . For .Fn strlcat that means the initial length of .Fa dst plus the length of .Fa src . While this may seem somewhat confusing it was done to make truncation detection simple. .Sh EXAMPLES The following code fragment illustrates the simple case: .Bd -literal -offset indent char *s, *p, buf[BUFSIZ]; \&... (void)strlcpy(buf, s, sizeof(buf)); (void)strlcat(buf, p, sizeof(buf)); .Ed .Pp To detect truncation, perhaps while building a pathname, something like the following might be used: .Bd -literal -offset indent char *dir, *file, pname[MAXPATHLEN]; \&... if (strlcpy(pname, dir, sizeof(pname)) >= sizeof(pname)) goto toolong; if (strlcat(pname, file, sizeof(pname)) >= sizeof(pname)) goto toolong; .Ed .Pp Since we know how many characters we copied the first time, we can speed things up a bit by using a copy instead of an append: .Bd -literal -offset indent char *dir, *file, pname[MAXPATHLEN]; size_t n; \&... n = strlcpy(pname, dir, sizeof(pname)); if (n >= sizeof(pname)) goto toolong; if (strlcpy(pname + n, file, sizeof(pname) - n) >= sizeof(pname) - n) goto toolong; .Ed .Pp However, one may question the validity of such optimizations, as they defeat the whole purpose of .Fn strlcpy and .Fn strlcat . As a matter of fact, the first version of this manual page got it wrong. .Sh SEE ALSO .Xr snprintf 3 , .Xr strncat 3 , .Xr strncpy 3 dietlibc-0.33~cvs20120325/lib/strlcpy.c010064400000000000000000000046401173363226500143240ustar00/* $OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $ */ /* * Copyright (c) 1998 Todd C. Miller * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if defined(LIBC_SCCS) && !defined(lint) static char *rcsid = "$OpenBSD: strlcpy.c,v 1.3 1999/04/24 01:17:37 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include #include /* * Copy src to string dst of size siz. At most siz-1 characters * will be copied. Always NUL terminates (unless siz == 0). * Returns strlen(src); if retval >= siz, truncation occurred. */ size_t strlcpy(dst, src, siz) char *dst; const char *src; size_t siz; { register char *d = dst; register const char *s = src; register size_t n = siz; /* Copy as many bytes as will fit */ if (n != 0 && --n != 0) { do { if ((*d++ = *s++) == 0) break; } while (--n != 0); } /* Not enough room in dst, add NUL and traverse rest of src */ if (n == 0) { if (siz != 0) *d = '\0'; /* NUL-terminate dst */ while (*s++) ; } return(s - src - 1); /* count does not include NUL */ } dietlibc-0.33~cvs20120325/lib/strlen.c010064400000000000000000000035511173363226500141330ustar00#include #include "dietfeatures.h" #include #include #ifdef WANT_SMALL_STRING_ROUTINES size_t strlen(const char *s) { register size_t i; if (__unlikely(!s)) return 0; for (i=0; __likely(*s); ++s) ++i; return i; } #else #if __WORDSIZE == 64 typedef uint64_t word_t; #elif __WORDSIZE == 32 typedef uint32_t word_t; #else #error unsupported __WORDSIZE #endif static word_t const magic = (word_t)(0x0101010101010101ull); size_t strlen(const char *s) { const char *t = s; word_t word; word_t mask; if (__unlikely(!s)) return 0; /* Byte compare up until word boundary */ for (; ((unsigned long) t & (sizeof(magic)-1)); t++) if (!*t) return t - s; /* Word compare */ do { word = *((word_t const *) t); t += sizeof word; word = (word - magic) &~ word; word &= (magic << 7); } while (__likely(word == 0)); #if __BYTE_ORDER == __LITTLE_ENDIAN (void)mask; switch (sizeof(word)) { case 8: /* word & 0x8080808080808080 == word */ word = (word - 1) & (magic << 8); word += (word << 32); word += (word << 16); word += (word << 8); t += word >> 56; break; case 4: /* word & 0x80808080 == word */ word = (word - 1) & (magic << 10); word += (word << 8) + (word << 16); t += word >> 26; break; default: { char exc[sizeof(word)==8]; (void)exc; } } #else mask = (magic << 7); switch (sizeof(word)) { case 8: mask <<= 4*8; if ((word & mask) == 0) { t += 4; word <<= 4*8; } /* fallthrough */ case 4: mask <<= 2*8; if ((word & mask) == 0) { t += 2; word <<= 2*8; } /* fallthrough */ case 2: mask <<= 1*8; if ((word & mask) == 0) { t += 1; word <<= 1*8; } break; default: { char exc[sizeof(word)==8]; (void)exc; } } #endif return t - sizeof(word) - s; } #endif dietlibc-0.33~cvs20120325/lib/strncasecmp.c010064400000000000000000000011041173363226500151360ustar00#include #include int strncasecmp ( const char* s1, const char* s2, size_t len ) { register unsigned int x2; register unsigned int x1; register const char* end = s1 + len; while (1) { if ( __unlikely(s1 >= end) ) return 0; x2 = *s2 - 'A'; if (__unlikely(x2 < 26u)) x2 += 32; x1 = *s1 - 'A'; if (__unlikely(x1 < 26u)) x1 += 32; s1++; s2++; if ( __unlikely(x2 != x1) ) break; if ( __unlikely(x1 == (unsigned int)-'A') ) break; } return x1 - x2; } dietlibc-0.33~cvs20120325/lib/strncat.c010064400000000000000000000013301173363226500142730ustar00#include "dietfeatures.h" #include /* gcc is broken and has a non-SUSv2 compliant internal prototype. * This causes it to warn about a type mismatch here. Ignore it. */ char *strncat(char *s, const char *t, size_t n) { char *dest=s; register char *max; s+=strlen(s); if (__unlikely((max=s+n)==s)) goto fini; for (;;) { if (__unlikely(!(*s = *t))) break; if (__unlikely(++s==max)) break; ++t; #ifndef WANT_SMALL_STRING_ROUTINES if (__unlikely(!(*s = *t))) break; if (__unlikely(++s==max)) break; ++t; if (__unlikely(!(*s = *t))) break; if (__unlikely(++s==max)) break; ++t; if (__unlikely(!(*s = *t))) break; if (__unlikely(++s==max)) break; ++t; #endif } *s=0; fini: return dest; } dietlibc-0.33~cvs20120325/lib/strncmp.c010064400000000000000000000010161173363226500143040ustar00#include #include /* gcc is broken and has a non-SUSv2 compliant internal prototype. * This causes it to warn about a type mismatch here. Ignore it. */ int strncmp(const char *s1, const char *s2, size_t n) { register const unsigned char* a=(const unsigned char*)s1; register const unsigned char* b=(const unsigned char*)s2; register const unsigned char* fini=a+n; while (a!=fini) { register int res=*a-*b; if (res) return res; if (!*a) return 0; ++a; ++b; } return 0; } dietlibc-0.33~cvs20120325/lib/strncpy.c010064400000000000000000000010031173363226500143140ustar00#define _POSIX_SOURCE #define _XOPEN_SOURCE #include #include #include "dietfeatures.h" /* gcc is broken and has a non-SUSv2 compliant internal prototype. * This causes it to warn about a type mismatch here. Ignore it. */ char *strncpy(char *dest, const char *src, size_t n) { #ifdef WANT_FULL_POSIX_COMPAT memset(dest,0,n); #endif memccpy(dest,src,0,n); #ifdef WANT_NON_COMPLIANT_STRNCAT if (n) dest[n-1]=0; /* maybe we should rather abort() if n is 0? */ #endif return dest; } dietlibc-0.33~cvs20120325/lib/strpbrk.c010064400000000000000000000003451173363226500143110ustar00#include #include char *strpbrk(const char *s, const char *accept) { register unsigned int i; for (; *s; s++) for (i=0; accept[i]; i++) if (*s == accept[i]) return (char*)s; return 0; } dietlibc-0.33~cvs20120325/lib/strrchr.c010064400000000000000000000011431173363226500143060ustar00#include #include "dietfeatures.h" char *strrchr(const char *t, int c) { register char ch; register const char *l=0; ch = c; for (;;) { if (__unlikely(*t == ch)) l=t; if (__unlikely(!*t)) return (char*)l; ++t; #ifndef WANT_SMALL_STRING_ROUTINES if (__unlikely(*t == ch)) l=t; if (__unlikely(!*t)) return (char*)l; ++t; if (__unlikely(*t == ch)) l=t; if (__unlikely(!*t)) return (char*)l; ++t; if (__unlikely(*t == ch)) l=t; if (__unlikely(!*t)) return (char*)l; ++t; #endif } return (char*)l; } char *rindex(const char *t,int c) __attribute__((weak,alias("strrchr"))); dietlibc-0.33~cvs20120325/lib/strsep.c010064400000000000000000000006021173363226500141360ustar00#include char *strsep(char **stringp, const char *delim) { register char *tmp=*stringp; register char *tmp2=tmp; register const char *tmp3; if (!*stringp) return 0; for (tmp2=tmp; *tmp2; ++tmp2) { for (tmp3=delim; *tmp3; ++tmp3) if (*tmp2==*tmp3) { /* delimiter found */ *tmp2=0; *stringp=tmp2+1; return tmp; } } *stringp=0; return tmp; } dietlibc-0.33~cvs20120325/lib/strspn.c010064400000000000000000000004011173363226500141440ustar00#include #include size_t strspn(const char *s, const char *accept) { size_t l = 0; const char *a; for (; *s; s++) { for (a = accept; *a && *s != *a; a++); if (!*a) break; else l++; } return l; } dietlibc-0.33~cvs20120325/lib/strstr.c010064400000000000000000000006011173363226500141560ustar00#include #include char *strstr(const char *haystack, const char *needle) { size_t nl=strlen(needle); size_t hl=strlen(haystack); size_t i; if (!nl) goto found; if (nl>hl) return 0; for (i=hl-nl+1; __likely(i); --i) { if (*haystack==*needle && !memcmp(haystack,needle,nl)) found: return (char*)haystack; ++haystack; } return 0; } dietlibc-0.33~cvs20120325/lib/strtod.c010064400000000000000000000030471173363226500141430ustar00#include #include #include double strtod(const char* s, char** endptr) { register const char* p = s; register long double value = 0.L; int sign = +1; long double factor; unsigned int expo; while ( isspace(*p) ) p++; switch (*p) { case '-': sign = -1; case '+': p++; default : break; } while ( (unsigned int)(*p - '0') < 10u ) value = value*10 + (*p++ - '0'); if ( *p == '.' ) { factor = 1.; p++; while ( (unsigned int)(*p - '0') < 10u ) { factor *= 0.1; value += (*p++ - '0') * factor; } } if ( (*p | 32) == 'e' ) { expo = 0; factor = 10.L; switch (*++p) { // ja hier weiß ich nicht, was mindestens nach einem 'E' folgenden MUSS. case '-': factor = 0.1; case '+': p++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; default : value = 0.L; p = s; goto done; } while ( (unsigned int)(*p - '0') < 10u ) expo = 10 * expo + (*p++ - '0'); while ( 1 ) { if ( expo & 1 ) value *= factor; if ( (expo >>= 1) == 0 ) break; factor *= factor; } } done: if ( endptr != NULL ) *endptr = (char*)p; return value * sign; } dietlibc-0.33~cvs20120325/lib/strtof.c010064400000000000000000000030451173363226500141430ustar00#include #include #include float strtof(const char* s, char** endptr) { register const char* p = s; register float value = 0.; int sign = +1; float factor; unsigned int expo; while ( isspace(*p) ) p++; switch (*p) { case '-': sign = -1; case '+': p++; default : break; } while ( (unsigned int)(*p - '0') < 10u ) value = value*10 + (*p++ - '0'); if ( *p == '.' ) { factor = 1.; p++; while ( (unsigned int)(*p - '0') < 10u ) { factor *= 0.1; value += (*p++ - '0') * factor; } } if ( (*p | 32) == 'e' ) { expo = 0; factor = 10.L; switch (*++p) { // ja hier weiß ich nicht, was mindestens nach einem 'E' folgenden MUSS. case '-': factor = 0.1; case '+': p++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; default : value = 0.L; p = s; goto done; } while ( (unsigned int)(*p - '0') < 10u ) expo = 10 * expo + (*p++ - '0'); while ( 1 ) { if ( expo & 1 ) value *= factor; if ( (expo >>= 1) == 0 ) break; factor *= factor; } } done: if ( endptr != NULL ) *endptr = (char*)p; return value * sign; } dietlibc-0.33~cvs20120325/lib/strtok.c010064400000000000000000000002041173363226500141420ustar00#include static char *strtok_pos; char *strtok(char *s, const char *delim) { return strtok_r(s,delim,&strtok_pos); } dietlibc-0.33~cvs20120325/lib/strtok_r.c010064400000000000000000000005061173363226500144700ustar00#include char*strtok_r(char*s,const char*delim,char**ptrptr) { char*tmp=0; if (s==0) s=*ptrptr; s+=strspn(s,delim); /* overread leading delimiter */ if (__likely(*s)) { tmp=s; s+=strcspn(s,delim); if (__likely(*s)) *s++=0; /* not the end ? => terminate it */ } *ptrptr=s; return tmp; } dietlibc-0.33~cvs20120325/lib/strtol.c010064400000000000000000000012641173363226500141520ustar00#include #include "dietfeatures.h" #include #include #include #if __WORDSIZE == 64 #define ABS_LONG_MIN 9223372036854775808UL #else #define ABS_LONG_MIN 2147483648UL #endif long int strtol(const char *nptr, char **endptr, int base) { int neg=0; unsigned long int v; const char*orig=nptr; while(isspace(*nptr)) nptr++; if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; ++nptr; } v=strtoul(nptr,endptr,base); if (endptr && *endptr==nptr) *endptr=(char *)orig; if (v>=ABS_LONG_MIN) { if (v==ABS_LONG_MIN && neg) { errno=0; return v; } errno=ERANGE; return (neg?LONG_MIN:LONG_MAX); } return (neg?-v:v); } dietlibc-0.33~cvs20120325/lib/strtold.c010064400000000000000000000030551173363226500143160ustar00#include #include #include long double strtold(const char* s, char** endptr) { register const char* p = s; register long double value = 0.L; int sign = +1; long double factor; unsigned int expo; while ( isspace(*p) ) p++; switch (*p) { case '-': sign = -1; case '+': p++; default : break; } while ( (unsigned int)(*p - '0') < 10u ) value = value*10 + (*p++ - '0'); if ( *p == '.' ) { factor = 1.; p++; while ( (unsigned int)(*p - '0') < 10u ) { factor *= 0.1; value += (*p++ - '0') * factor; } } if ( (*p | 32) == 'e' ) { expo = 0; factor = 10.L; switch (*++p) { // ja hier weiß ich nicht, was mindestens nach einem 'E' folgenden MUSS. case '-': factor = 0.1; case '+': p++; break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': break; default : value = 0.L; p = s; goto done; } while ( (unsigned int)(*p - '0') < 10u ) expo = 10 * expo + (*p++ - '0'); while ( 1 ) { if ( expo & 1 ) value *= factor; if ( (expo >>= 1) == 0 ) break; factor *= factor; } } done: if ( endptr != NULL ) *endptr = (char*)p; return value * sign; } dietlibc-0.33~cvs20120325/lib/strtoll.c010064400000000000000000000012671173363226500143310ustar00#include #include #include #include #include long long int strtoll(const char *nptr, char **endptr, int base) { int neg=0; unsigned long long int v; const char*orig=nptr; while(isspace(*nptr)) nptr++; if (*nptr == '-' && isalnum(nptr[1])) { neg=-1; nptr++; } v=strtoull(nptr,endptr,base); if (endptr && *endptr==nptr) *endptr=(char *)orig; if (v>LLONG_MAX) { if (v==0x8000000000000000ull && neg) { errno=0; return v; } errno=ERANGE; return (neg?LLONG_MIN:LLONG_MAX); } return (neg?-v:v); } intmax_t strtoimax(const char *nptr, char **endptr, int base) __attribute__((alias("strtoll"))); dietlibc-0.33~cvs20120325/lib/strtoul.c010064400000000000000000000024031173363226500143330ustar00#include #include #include #include unsigned long int strtoul(const char *ptr, char **endptr, int base) { int neg = 0, overflow = 0; unsigned long int v=0; const char* orig; const char* nptr=ptr; while(isspace(*nptr)) ++nptr; if (*nptr == '-') { neg=1; nptr++; } else if (*nptr == '+') ++nptr; orig=nptr; if (base==16 && nptr[0]=='0') goto skip0x; if (base) { register unsigned int b=base-2; if (__unlikely(b>34)) { errno=EINVAL; return 0; } } else { if (*nptr=='0') { base=8; skip0x: if ((nptr[1]=='x'||nptr[1]=='X') && isxdigit(nptr[2])) { nptr+=2; base=16; } } else base=10; } while(__likely(*nptr)) { register unsigned char c=*nptr; c=(c>='a'?c-'a'+10:c>='A'?c-'A'+10:c<='9'?c-'0':0xff); if (__unlikely(c>=base)) break; /* out of base */ { register unsigned long x=(v&0xff)*base+c; register unsigned long w=(v>>8)*base+(x>>8); if (w>(ULONG_MAX>>8)) overflow=1; v=(w<<8)+(x&0xff); } ++nptr; } if (__unlikely(nptr==orig)) { /* no conversion done */ nptr=ptr; errno=EINVAL; v=0; } if (endptr) *endptr=(char *)nptr; if (overflow) { errno=ERANGE; return ULONG_MAX; } return (neg?-v:v); } dietlibc-0.33~cvs20120325/lib/strtoull.c010064400000000000000000000030261173363226500145110ustar00#include #include #include #include #include unsigned long long int strtoull(const char *ptr, char **endptr, int base) { int neg = 0, overflow = 0; long long int v=0; const char* orig; const char* nptr=ptr; while(isspace(*nptr)) ++nptr; if (*nptr == '-') { neg=1; nptr++; } else if (*nptr == '+') ++nptr; orig=nptr; if (base==16 && nptr[0]=='0') goto skip0x; if (base) { register unsigned int b=base-2; if (__unlikely(b>34)) { errno=EINVAL; return 0; } } else { if (*nptr=='0') { base=8; skip0x: if (((*(nptr+1)=='x')||(*(nptr+1)=='X')) && isxdigit(nptr[2])) { nptr+=2; base=16; } } else base=10; } while(__likely(*nptr)) { register unsigned char c=*nptr; c=(c>='a'?c-'a'+10:c>='A'?c-'A'+10:c<='9'?c-'0':0xff); if (__unlikely(c>=base)) break; /* out of base */ { register unsigned long x=(v&0xff)*base+c; register unsigned long long w=(v>>8)*base+(x>>8); if (w>(ULLONG_MAX>>8)) overflow=1; v=(w<<8)+(x&0xff); } ++nptr; } if (__unlikely(nptr==orig)) { /* no conversion done */ nptr=ptr; errno=EINVAL; v=0; } if (endptr) *endptr=(char *)nptr; if (overflow) { errno=ERANGE; return ULLONG_MAX; } return (neg?-v:v); } /* die, BSD, die!!! */ unsigned long long int strtouq(const char *nptr, char **endptr, int base) __attribute__((alias("strtoull"))); uintmax_t strtoumax(const char *nptr, char **endptr, int base) __attribute__((alias("strtoull"))); dietlibc-0.33~cvs20120325/lib/strxfrm.c010064400000000000000000000003521173363226500143250ustar00#include #include #include "dietfeatures.h" size_t strxfrm(char *dest, const char *src, size_t n) { #ifdef WANT_FULL_POSIX_COMPAT memset(dest,0,n); #endif memccpy(dest,src,0,n); return strlen(dest); } dietlibc-0.33~cvs20120325/lib/swab.c010064400000000000000000000003241173363226500135530ustar00#include void swab(const void *src, void *dest, ssize_t nbytes) { ssize_t i; const char *s=src; char *d=dest; nbytes&=~1; for (i=0; i int __libc_tcdrain(int fd); int __libc_tcdrain(int fd) { return ioctl(fd, TCSBRK, 1); } int tcdrain(int fd) __attribute__((weak,alias("__libc_tcdrain"))); dietlibc-0.33~cvs20120325/lib/tcflow.c010064400000000000000000000010471173363226500141200ustar00#include "dietfeatures.h" #include #include #include int tcflow ( int fd, int action ) { #if TCOOFF==0 && TCOON==1 && TCIOFF==2 && TCION==3 if ( (unsigned int)action < 4u ) return ioctl ( fd, TCXONC, action ); errno = EINVAL; return -1; #else int arg = 0; switch (action) { case TCION: arg++; case TCIOFF: arg++; case TCOON: arg++; case TCOOFF: return ioctl ( fd, TCXONC, arg ); default: errno = EINVAL; return -1; } #endif } dietlibc-0.33~cvs20120325/lib/tcflush.c010064400000000000000000000003531173363226500142710ustar00#include int __libc_tcflush(int fd, int queue_selector); int __libc_tcflush(int fd, int queue_selector) { return ioctl(fd, TCFLSH, queue_selector); } int tcflush(int fd) __attribute__((weak,alias("__libc_tcflush"))); dietlibc-0.33~cvs20120325/lib/tcgetattr.c010064400000000000000000000002211173363226500146140ustar00#include #include int tcgetattr(int fildes, struct termios *termios_p) { return ioctl(fildes, TCGETS, termios_p); } dietlibc-0.33~cvs20120325/lib/tcgetpgrp.c010064400000000000000000000003051173363226500146150ustar00#include #include #include pid_t tcgetpgrp(int fildes) { int32_t foo = -1; if (ioctl(fildes, TIOCGPGRP, &foo)==-1) return -1; else return foo; } dietlibc-0.33~cvs20120325/lib/tcgetsid.c010064400000000000000000000002151173363226500144240ustar00#include #include pid_t tcgetsid(int fildes) { pid_t pid; return ioctl(fildes, TIOCGSID, &pid)==-1?-1:pid; } dietlibc-0.33~cvs20120325/lib/tcsendbreak.c010064400000000000000000000003311173363226500151020ustar00#include "dietfeatures.h" #include #include #include int tcsendbreak (int fd,int duration) { if (duration <= 0) return (ioctl (fd,TCSBRKP,0)); errno = EINVAL; return (-1); } dietlibc-0.33~cvs20120325/lib/tcsetattr.c010064400000000000000000000015761173363226500146460ustar00#include #include #include #include "dietfeatures.h" #if !defined(__powerpc__) && !defined(__sparc__) && !defined(__alpha__) && !defined(__hppa__) #if TCSANOW==0 && TCSADRAIN==1 && TCSAFLUSH==2 && TCSETSW-TCSETS==1 && TCSETSF-TCSETS==2 #define shortcut #endif #endif int tcsetattr ( int fildes, int optional_actions, struct termios* termios_p ) { #ifdef shortcut if ( (unsigned int)optional_actions < 3u ) return ioctl ( fildes, TCSETS+optional_actions, termios_p ); errno = EINVAL; return -1; #else switch ( optional_actions ) { case TCSANOW: return ioctl ( fildes, TCSETS , termios_p ); case TCSADRAIN: return ioctl ( fildes, TCSETSW, termios_p ); case TCSAFLUSH: return ioctl ( fildes, TCSETSF, termios_p ); default: errno = EINVAL; return -1; } #endif } dietlibc-0.33~cvs20120325/lib/tcsetpgrp.c010064400000000000000000000002311173363226500146270ustar00#include #include #include int tcsetpgrp(int fildes, pid_t pgrpid) { return ioctl(fildes, TIOCSPGRP, &pgrpid); } dietlibc-0.33~cvs20120325/lib/telldir.c010064400000000000000000000003241173363226500142560ustar00#include "dietdirent.h" #include #include off_t telldir(DIR *d) { off_t result = 0; if (lseek(d->fd,0,SEEK_CUR)) result=((struct dirent*)(d->buf+d->cur))->d_off; return result; } dietlibc-0.33~cvs20120325/lib/timerfd_create.c010064400000000000000000000003311173363226500155720ustar00#include extern int __timerfd(int ufd, int clockid, int flags, const struct itimerspec *utmr); int timerfd_create (clockid_t __clock_id, int __flags) { return __timerfd(-1,__clock_id,__flags,0); } dietlibc-0.33~cvs20120325/lib/tolower.c010064400000000000000000000001671173363226500143170ustar00#include int tolower(int ch) { if ( (unsigned int)(ch - 'A') < 26u ) ch += 'a' - 'A'; return ch; } dietlibc-0.33~cvs20120325/lib/toupper.c010064400000000000000000000001761173363226500143220ustar00#include inline int toupper(int ch) { if ( (unsigned int)(ch - 'a') < 26u ) ch += 'A' - 'a'; return ch; } dietlibc-0.33~cvs20120325/lib/towlower.c010064400000000000000000000001731173363226500145030ustar00#include wint_t towlower(wint_t c) { if ( (unsigned int)(c - 'A') < 26u ) c += 'a' - 'A'; return c; } dietlibc-0.33~cvs20120325/lib/towupper.c010064400000000000000000000001731173363226500145060ustar00#include wint_t towupper(wint_t c) { if ( (unsigned int)(c - 'a') < 26u ) c += 'A' - 'a'; return c; } dietlibc-0.33~cvs20120325/lib/ttyname.c010064400000000000000000000022161173363226500143020ustar00#include "dietfeatures.h" #include #include #include #ifdef __linux__ #include char *ttyname(int fd) { #ifdef SLASH_PROC_OK char ibuf[20]; static char obuf[20]; int len; if (!isatty(fd)) return 0; strcpy(ibuf,"/proc/self/fd/"); ibuf[__ltostr(ibuf+14,6,(unsigned long)fd,10,0)+14]=0; if ((len=readlink(ibuf,obuf,sizeof(obuf)-1))<0) return 0; obuf[len]=0; return obuf; #else static char buf[20]; struct stat s; char *c=buf+8; int n; if (!isatty(fd)) return 0; if (fstat(fd,&s)) return 0; strcpy(buf,"/dev/tty"); if (S_ISCHR(s.st_mode)) { n=minor(s.st_rdev); switch (major(s.st_rdev)) { case 4: if (n>63) { n-=64; *c='S'; ++c; } num: c[__ltostr(c,6,n,10,0)]=0; break; case 2: buf[8]='p'-(n>>4); buf[9]=n%4+'0'; if (buf[9]>'9') *c+='a'-'0'; buf[10]=0; goto duh; case 136: case 137: case 138: case 139: buf[7]='s'; duh: buf[5]='p'; n+=(major(s.st_rdev)-136)<<8; *c='/'; ++c; goto num; default: return 0; } return buf; } return 0; #endif } #endif dietlibc-0.33~cvs20120325/lib/usleep.c010064400000000000000000000004021173363226500141110ustar00#include #include /* nano * 1000 == usecs * usecs * 1000 == msecs * msecs * 1000 = secs */ int usleep(unsigned long usecs) { struct timespec t; t.tv_sec=usecs/1000000; t.tv_nsec=(usecs%1000000)*1000; return nanosleep(&t,&t); } dietlibc-0.33~cvs20120325/lib/vdso_dlsym.c010064400000000000000000000043471173363226500150130ustar00#include #include #include #include #include #include #include "internal.h" #if (__WORDSIZE == 64) #define phdr Elf64_Phdr #define ehdr Elf64_Ehdr #define shdr Elf64_Shdr #define sym Elf64_Sym #else #define phdr Elf32_Phdr #define ehdr Elf32_Ehdr #define shdr Elf32_Shdr #define sym Elf32_Sym #endif const void* vdso_dlsym(const char* elfimage,const char* symbol) { /* WARNING: this does NO validation AT ALL. */ /* It is meant to be used on the VDSO ELF .so mapped into user space * by the kernel. Since the kernel gave it to us, it is trustworthy. * A real dlsym would have to check all the pointers and offsets * against the file and section sizes, obviously. */ const ehdr* eh=(ehdr*)elfimage; const char* dynstringtable=0; { size_t i; /* first traverse the section list to find ".dynstr" * we need the offset of .dynstr because the names in the symbol * list are given as offsets inside .dynstr */ for (i=0; ie_shnum; ++i) { const shdr* sh=(shdr*)(elfimage + eh->e_shoff + i*eh->e_shentsize); if (sh->sh_type==3 && (sh->sh_flags&2)) { // type SHT_STRTAB and flags has SHF_ALLOC dynstringtable = elfimage + sh->sh_offset; break; } } } /* now traverse .dynsym */ if (dynstringtable) { size_t i; for (i=0; ie_shnum; ++i) { const shdr* sh=(shdr*)(elfimage + eh->e_shoff + i*eh->e_shentsize); if (sh->sh_type==11) { size_t j; // printf(".dynsym @ %p\n",vdso + sh->sh_offset); for (j=0; j*sh->sh_entsize < sh->sh_size; ++j) { const sym* es=(sym*)(elfimage + sh->sh_offset + j*sh->sh_entsize); // printf("%p: %s\n",((shdr*)(elfimage + eh->e_shoff + es->st_shndx * eh->e_shentsize))->sh-offset + es->st_value-eh->e_entry, dynstringtable+es->st_name); if (!strcmp(dynstringtable+es->st_name,symbol)) { const shdr* sec=(shdr*)(elfimage + eh->e_shoff + es->st_shndx*eh->e_shentsize); size_t ofs=es->st_value-sec->sh_addr+sec->sh_offset; // if (ofs>sec->sh_size) return 0; // printf("found symbol \"%s\" at offset %p\n",dynstringtable+es->st_name,es->st_value); return elfimage + ofs; } } } sh = (shdr*)((char*)sh + eh->e_shentsize); } } return 0; } dietlibc-0.33~cvs20120325/lib/vfork.c010064400000000000000000000000671173363226500137520ustar00#include pid_t vfork() { return fork(); } dietlibc-0.33~cvs20120325/lib/vsnprintf.c010064400000000000000000000015301173363226500146500ustar00#include #include #include #include #include #include "dietstdio.h" struct str_data { char* str; size_t len; size_t size; }; static int swrite(void*ptr, size_t nmemb, struct str_data* sd) { size_t tmp=sd->size-sd->len; if (tmp>0) { size_t len=nmemb; if (len>tmp) len=tmp; if (sd->str) { memcpy(sd->str+sd->len,ptr,len); sd->str[sd->len+len]=0; } sd->len+=len; } return nmemb; } int vsnprintf(char* str, size_t size, const char *format, va_list arg_ptr) { int n; struct str_data sd = { str, 0, size?size-1:0 }; struct arg_printf ap = { &sd, (int(*)(void*,size_t,void*)) swrite }; n=__v_printf(&ap,format,arg_ptr); if (str && size && n>=0) { if (size!=(size_t)-1 && ((size_t)n>=size)) str[size-1]=0; else str[n]=0; } return n; } dietlibc-0.33~cvs20120325/lib/vsprintf.c010064400000000000000000000004701173363226500144740ustar00#include #include #include #include #include "dietwarning.h" int vsprintf(char *dest,const char *format, va_list arg_ptr) { return vsnprintf(dest,(size_t)-1,format,arg_ptr); } link_warning("vsprintf","warning: Avoid *sprintf; use *snprintf. It is more secure.") dietlibc-0.33~cvs20120325/lib/vsscanf.c010064400000000000000000000011341173363226500142620ustar00#include #include #include #include "dietstdio.h" #include struct str_data { unsigned char* str; }; static int sgetc(struct str_data* sd) { register unsigned int ret = *(sd->str++); return (ret)?(int)ret:-1; } static int sputc(int c, struct str_data* sd) { return (*(--sd->str)==c)?c:-1; } int vsscanf(const char* str, const char* format, va_list arg_ptr) { struct str_data fdat = { (unsigned char*)str }; struct arg_scanf farg = { (void*)&fdat, (int(*)(void*))sgetc, (int(*)(int,void*))sputc }; return __v_scanf(&farg,format,arg_ptr); } dietlibc-0.33~cvs20120325/lib/wait.c010064400000000000000000000001511173363226500135610ustar00#include #include pid_t wait(int *status) { return waitpid(-1,status,0); } dietlibc-0.33~cvs20120325/lib/wait3.c010064400000000000000000000001721173363226500136470ustar00#include pid_t wait3(int* status,int opts,struct rusage* rusage) { return wait4(-1,status,opts,rusage); } dietlibc-0.33~cvs20120325/lib/wcrtomb.c010064400000000000000000000014611173363226500142770ustar00#include #include "dietlocale.h" static mbstate_t internal; size_t wcrtomb(char *s, wchar_t wc, mbstate_t *ps) { if (!ps) ps=&internal; switch (lc_ctype) { case CT_8BIT: if (!s) return 0; *s=wc; return 1; case CT_UTF8: if (!s) return (wc>=0x80); { char c; unsigned int bits,j,k; if (wc>=0x04000000) { bits=30; c=0xFC; j=6; } else if (wc>=0x00200000) { bits=24; c=0xF8; j=5; } else if (wc>=0x00010000) { bits=18; c=0xF0; j=4; } else if (wc>=0x00000800) { bits=12; c=0xE0; j=3; } else if (wc>=0x00000080) { bits=6; c=0xC0; j=2; } else { *s=wc; return 1; } c |= (unsigned char)(wc>>bits); if (s) { *s=c; for (k=1; k>bits)&0x3f); } } return j; } } return 0; } dietlibc-0.33~cvs20120325/lib/wcscat.c010064400000000000000000000003761173363226500141120ustar00#include wchar_t* wcscat(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src) { wchar_t* orig=dest; for (; *dest; ++dest) ; /* go to end of dest */ for (; (*dest=*src); ++src,++dest) ; /* then append from src */ return orig; } dietlibc-0.33~cvs20120325/lib/wcschr.c010064400000000000000000000002321173363226500141060ustar00#include wchar_t* wcschr(const wchar_t *wcs, wchar_t wc) { for (; *wcs; ++wcs) if (*wcs == wc) return (wchar_t*)wcs; return 0; } dietlibc-0.33~cvs20120325/lib/wcscmp.c010064400000000000000000000003361173363226500141160ustar00#include int wcscmp(const wchar_t* a,const wchar_t* b) { while (*a && *a == *b) a++, b++; return (*a - *b); } int wcscoll(const wchar_t *s,const wchar_t* t) __attribute__((weak,alias("wcscmp"))); dietlibc-0.33~cvs20120325/lib/wcscpy.c010064400000000000000000000002611173363226500141270ustar00#include wchar_t* wcscpy(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src) { wchar_t* orig=dest; for (; (*dest=*src); ++src,++dest) ; return orig; } dietlibc-0.33~cvs20120325/lib/wcslen.c010064400000000000000000000001511173363226500141100ustar00#include size_t wcslen(const wchar_t* s) { size_t i; for (i=0; s[i]; ++i) ; return i; } dietlibc-0.33~cvs20120325/lib/wcsncat.c010064400000000000000000000003651173363226500142660ustar00#include wchar_t* wcsncat(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src,size_t n) { wchar_t* orig=dest; size_t i; while (*dest) ++dest; for (i=0; i int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) { size_t i; for (i=0; i wchar_t* wcsncpy(wchar_t *__restrict__ dest, const wchar_t *__restrict__ src,size_t n) { wchar_t* orig=dest; for (; dest wchar_t* wcsrchr(const wchar_t *wcs, wchar_t wc) { wchar_t* last=0; for (; *wcs; ++wcs) if (*wcs == wc) last=(wchar_t*)wcs; return last; } dietlibc-0.33~cvs20120325/lib/wcsrtombs.c010064400000000000000000000013621173363226500146450ustar00#include #include #include "dietlocale.h" #include #include #include size_t wcsrtombs(char *dest, const wchar_t **src, size_t len, mbstate_t *ps) { wchar_t c; char buf[MB_CUR_MAX]; size_t cur; char* max; if (!src || !*src) { inval: errno=EINVAL; return -1; } if (!dest) { len=-1; max=dest+len; } for (cur=0; (c=**src); ++*src) { size_t n; char* s=__likely(len-cur>=MB_CUR_MAX)?(dest?dest+cur:NULL):buf; n=wcrtomb(s,c,ps); if (n==(size_t)-1) return -1; if (dest && s==buf) { /* check if we fit */ if (lencur) dest[cur]=0; keinplatz: return cur; } dietlibc-0.33~cvs20120325/lib/wcsstr.c010064400000000000000000000003671173363226500141530ustar00#include wchar_t *wcsstr(const wchar_t *haystack, const wchar_t *needle) { size_t i,j; for (i=0; haystack[i]; ++i) { for (j=0; haystack[i+j]==needle[j]; ++j) ; if (!needle[j]) return (wchar_t*)haystack+i; } return 0; } dietlibc-0.33~cvs20120325/lib/wcstombs.c010064400000000000000000000003421173363226500144600ustar00#include #include "dietlocale.h" #include #include #include #include size_t wcstombs(char *dest, const wchar_t *src, size_t len) { return wcsrtombs(dest,&src,len,NULL); } dietlibc-0.33~cvs20120325/lib/wcswidth.c010064400000000000000000000066471173363226500144710ustar00#define _XOPEN_SOURCE #include /* * This is an implementation of wcwidth() and wcswidth() (defined in * IEEE Std 1002.1-2001) for Unicode. * * http://www.opengroup.org/onlinepubs/007904975/functions/wcwidth.html * http://www.opengroup.org/onlinepubs/007904975/functions/wcswidth.html * * In fixed-width output devices, Latin characters all occupy a single * "cell" position of equal width, whereas ideographic CJK characters * occupy two such cells. Interoperability between terminal-line * applications and (teletype-style) character terminals using the * UTF-8 encoding requires agreement on which character should advance * the cursor by how many cell positions. No established formal * standards exist at present on which Unicode character shall occupy * how many cell positions on character terminals. These routines are * a first attempt of defining such behavior based on simple rules * applied to data provided by the Unicode Consortium. * * For some graphical characters, the Unicode standard explicitly * defines a character-cell width via the definition of the East Asian * FullWidth (F), Wide (W), Half-width (H), and Narrow (Na) classes. * In all these cases, there is no ambiguity about which width a * terminal shall use. For characters in the East Asian Ambiguous (A) * class, the width choice depends purely on a preference of backward * compatibility with either historic CJK or Western practice. * Choosing single-width for these characters is easy to justify as * the appropriate long-term solution, as the CJK practice of * displaying these characters as double-width comes from historic * implementation simplicity (8-bit encoded characters were displayed * single-width and 16-bit ones double-width, even for Greek, * Cyrillic, etc.) and not any typographic considerations. * * Much less clear is the choice of width for the Not East Asian * (Neutral) class. Existing practice does not dictate a width for any * of these characters. It would nevertheless make sense * typographically to allocate two character cells to characters such * as for instance EM SPACE or VOLUME INTEGRAL, which cannot be * represented adequately with a single-width glyph. The following * routines at present merely assign a single-cell width to all * neutral characters, in the interest of simplicity. This is not * entirely satisfactory and should be reconsidered before * establishing a formal standard in this area. At the moment, the * decision which Not East Asian (Neutral) characters should be * represented by double-width glyphs cannot yet be answered by * applying a simple rule from the Unicode database content. Setting * up a proper standard for the behavior of UTF-8 character terminals * will require a careful analysis not only of each Unicode character, * but also of each presentation form, something the author of these * routines has avoided to do so far. * * http://www.unicode.org/unicode/reports/tr11/ * * Markus Kuhn -- 2007-05-26 (Unicode 5.0) * * Permission to use, copy, modify, and distribute this software * for any purpose and without fee is hereby granted. The author * disclaims all warranties with regard to this software. * * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ int wcswidth(const wchar_t *pwcs, size_t n) { int w, width = 0; for (;*pwcs && n-- > 0; pwcs++) if ((w = wcwidth(*pwcs)) < 0) return -1; else width += w; return width; } dietlibc-0.33~cvs20120325/lib/wctomb.c010064400000000000000000000001531173363226500141120ustar00#include #include int wctomb(char *pwc, wchar_t s) { return wcrtomb(pwc,s,NULL); } dietlibc-0.33~cvs20120325/lib/wcwidth.c010064400000000000000000000222141173363226500142720ustar00#define _XOPEN_SOURCE #include /* * This is an implementation of wcwidth() and wcswidth() (defined in * IEEE Std 1002.1-2001) for Unicode. * * http://www.opengroup.org/onlinepubs/007904975/functions/wcwidth.html * http://www.opengroup.org/onlinepubs/007904975/functions/wcswidth.html * * In fixed-width output devices, Latin characters all occupy a single * "cell" position of equal width, whereas ideographic CJK characters * occupy two such cells. Interoperability between terminal-line * applications and (teletype-style) character terminals using the * UTF-8 encoding requires agreement on which character should advance * the cursor by how many cell positions. No established formal * standards exist at present on which Unicode character shall occupy * how many cell positions on character terminals. These routines are * a first attempt of defining such behavior based on simple rules * applied to data provided by the Unicode Consortium. * * For some graphical characters, the Unicode standard explicitly * defines a character-cell width via the definition of the East Asian * FullWidth (F), Wide (W), Half-width (H), and Narrow (Na) classes. * In all these cases, there is no ambiguity about which width a * terminal shall use. For characters in the East Asian Ambiguous (A) * class, the width choice depends purely on a preference of backward * compatibility with either historic CJK or Western practice. * Choosing single-width for these characters is easy to justify as * the appropriate long-term solution, as the CJK practice of * displaying these characters as double-width comes from historic * implementation simplicity (8-bit encoded characters were displayed * single-width and 16-bit ones double-width, even for Greek, * Cyrillic, etc.) and not any typographic considerations. * * Much less clear is the choice of width for the Not East Asian * (Neutral) class. Existing practice does not dictate a width for any * of these characters. It would nevertheless make sense * typographically to allocate two character cells to characters such * as for instance EM SPACE or VOLUME INTEGRAL, which cannot be * represented adequately with a single-width glyph. The following * routines at present merely assign a single-cell width to all * neutral characters, in the interest of simplicity. This is not * entirely satisfactory and should be reconsidered before * establishing a formal standard in this area. At the moment, the * decision which Not East Asian (Neutral) characters should be * represented by double-width glyphs cannot yet be answered by * applying a simple rule from the Unicode database content. Setting * up a proper standard for the behavior of UTF-8 character terminals * will require a careful analysis not only of each Unicode character, * but also of each presentation form, something the author of these * routines has avoided to do so far. * * http://www.unicode.org/unicode/reports/tr11/ * * Markus Kuhn -- 2007-05-26 (Unicode 5.0) * * Permission to use, copy, modify, and distribute this software * for any purpose and without fee is hereby granted. The author * disclaims all warranties with regard to this software. * * Latest version: http://www.cl.cam.ac.uk/~mgk25/ucs/wcwidth.c */ #include struct interval { int first; int last; }; /* auxiliary function for binary search in interval table */ static int bisearch(wchar_t ucs, const struct interval *table, int max) { int min = 0; int mid; if (ucs < table[0].first || ucs > table[max].last) return 0; while (max >= min) { mid = (min + max) / 2; if (ucs > table[mid].last) min = mid + 1; else if (ucs < table[mid].first) max = mid - 1; else return 1; } return 0; } /* The following two functions define the column width of an ISO 10646 * character as follows: * * - The null character (U+0000) has a column width of 0. * * - Other C0/C1 control characters and DEL will lead to a return * value of -1. * * - Non-spacing and enclosing combining characters (general * category code Mn or Me in the Unicode database) have a * column width of 0. * * - SOFT HYPHEN (U+00AD) has a column width of 1. * * - Other format characters (general category code Cf in the Unicode * database) and ZERO WIDTH SPACE (U+200B) have a column width of 0. * * - Hangul Jamo medial vowels and final consonants (U+1160-U+11FF) * have a column width of 0. * * - Spacing characters in the East Asian Wide (W) or East Asian * Full-width (F) category as defined in Unicode Technical * Report #11 have a column width of 2. * * - All remaining characters (including all printable * ISO 8859-1 and WGL4 characters, Unicode control characters, * etc.) have a column width of 1. * * This implementation assumes that wchar_t characters are encoded * in ISO 10646. */ int wcwidth(wchar_t ucs) { /* sorted list of non-overlapping intervals of non-spacing characters */ /* generated by "uniset +cat=Me +cat=Mn +cat=Cf -00AD +1160-11FF +200B c" */ static const struct interval combining[] = { { 0x0300, 0x036F }, { 0x0483, 0x0486 }, { 0x0488, 0x0489 }, { 0x0591, 0x05BD }, { 0x05BF, 0x05BF }, { 0x05C1, 0x05C2 }, { 0x05C4, 0x05C5 }, { 0x05C7, 0x05C7 }, { 0x0600, 0x0603 }, { 0x0610, 0x0615 }, { 0x064B, 0x065E }, { 0x0670, 0x0670 }, { 0x06D6, 0x06E4 }, { 0x06E7, 0x06E8 }, { 0x06EA, 0x06ED }, { 0x070F, 0x070F }, { 0x0711, 0x0711 }, { 0x0730, 0x074A }, { 0x07A6, 0x07B0 }, { 0x07EB, 0x07F3 }, { 0x0901, 0x0902 }, { 0x093C, 0x093C }, { 0x0941, 0x0948 }, { 0x094D, 0x094D }, { 0x0951, 0x0954 }, { 0x0962, 0x0963 }, { 0x0981, 0x0981 }, { 0x09BC, 0x09BC }, { 0x09C1, 0x09C4 }, { 0x09CD, 0x09CD }, { 0x09E2, 0x09E3 }, { 0x0A01, 0x0A02 }, { 0x0A3C, 0x0A3C }, { 0x0A41, 0x0A42 }, { 0x0A47, 0x0A48 }, { 0x0A4B, 0x0A4D }, { 0x0A70, 0x0A71 }, { 0x0A81, 0x0A82 }, { 0x0ABC, 0x0ABC }, { 0x0AC1, 0x0AC5 }, { 0x0AC7, 0x0AC8 }, { 0x0ACD, 0x0ACD }, { 0x0AE2, 0x0AE3 }, { 0x0B01, 0x0B01 }, { 0x0B3C, 0x0B3C }, { 0x0B3F, 0x0B3F }, { 0x0B41, 0x0B43 }, { 0x0B4D, 0x0B4D }, { 0x0B56, 0x0B56 }, { 0x0B82, 0x0B82 }, { 0x0BC0, 0x0BC0 }, { 0x0BCD, 0x0BCD }, { 0x0C3E, 0x0C40 }, { 0x0C46, 0x0C48 }, { 0x0C4A, 0x0C4D }, { 0x0C55, 0x0C56 }, { 0x0CBC, 0x0CBC }, { 0x0CBF, 0x0CBF }, { 0x0CC6, 0x0CC6 }, { 0x0CCC, 0x0CCD }, { 0x0CE2, 0x0CE3 }, { 0x0D41, 0x0D43 }, { 0x0D4D, 0x0D4D }, { 0x0DCA, 0x0DCA }, { 0x0DD2, 0x0DD4 }, { 0x0DD6, 0x0DD6 }, { 0x0E31, 0x0E31 }, { 0x0E34, 0x0E3A }, { 0x0E47, 0x0E4E }, { 0x0EB1, 0x0EB1 }, { 0x0EB4, 0x0EB9 }, { 0x0EBB, 0x0EBC }, { 0x0EC8, 0x0ECD }, { 0x0F18, 0x0F19 }, { 0x0F35, 0x0F35 }, { 0x0F37, 0x0F37 }, { 0x0F39, 0x0F39 }, { 0x0F71, 0x0F7E }, { 0x0F80, 0x0F84 }, { 0x0F86, 0x0F87 }, { 0x0F90, 0x0F97 }, { 0x0F99, 0x0FBC }, { 0x0FC6, 0x0FC6 }, { 0x102D, 0x1030 }, { 0x1032, 0x1032 }, { 0x1036, 0x1037 }, { 0x1039, 0x1039 }, { 0x1058, 0x1059 }, { 0x1160, 0x11FF }, { 0x135F, 0x135F }, { 0x1712, 0x1714 }, { 0x1732, 0x1734 }, { 0x1752, 0x1753 }, { 0x1772, 0x1773 }, { 0x17B4, 0x17B5 }, { 0x17B7, 0x17BD }, { 0x17C6, 0x17C6 }, { 0x17C9, 0x17D3 }, { 0x17DD, 0x17DD }, { 0x180B, 0x180D }, { 0x18A9, 0x18A9 }, { 0x1920, 0x1922 }, { 0x1927, 0x1928 }, { 0x1932, 0x1932 }, { 0x1939, 0x193B }, { 0x1A17, 0x1A18 }, { 0x1B00, 0x1B03 }, { 0x1B34, 0x1B34 }, { 0x1B36, 0x1B3A }, { 0x1B3C, 0x1B3C }, { 0x1B42, 0x1B42 }, { 0x1B6B, 0x1B73 }, { 0x1DC0, 0x1DCA }, { 0x1DFE, 0x1DFF }, { 0x200B, 0x200F }, { 0x202A, 0x202E }, { 0x2060, 0x2063 }, { 0x206A, 0x206F }, { 0x20D0, 0x20EF }, { 0x302A, 0x302F }, { 0x3099, 0x309A }, { 0xA806, 0xA806 }, { 0xA80B, 0xA80B }, { 0xA825, 0xA826 }, { 0xFB1E, 0xFB1E }, { 0xFE00, 0xFE0F }, { 0xFE20, 0xFE23 }, { 0xFEFF, 0xFEFF }, { 0xFFF9, 0xFFFB }, { 0x10A01, 0x10A03 }, { 0x10A05, 0x10A06 }, { 0x10A0C, 0x10A0F }, { 0x10A38, 0x10A3A }, { 0x10A3F, 0x10A3F }, { 0x1D167, 0x1D169 }, { 0x1D173, 0x1D182 }, { 0x1D185, 0x1D18B }, { 0x1D1AA, 0x1D1AD }, { 0x1D242, 0x1D244 }, { 0xE0001, 0xE0001 }, { 0xE0020, 0xE007F }, { 0xE0100, 0xE01EF } }; /* test for 8-bit control characters */ if (ucs == 0) return 0; if (ucs < 32 || (ucs >= 0x7f && ucs < 0xa0)) return -1; /* binary search in table of non-spacing characters */ if (bisearch(ucs, combining, sizeof(combining) / sizeof(struct interval) - 1)) return 0; /* if we arrive here, ucs is not a combining or C0/C1 control character */ return 1 + (ucs >= 0x1100 && (ucs <= 0x115f || /* Hangul Jamo init. consonants */ ucs == 0x2329 || ucs == 0x232a || (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) || /* CJK ... Yi */ (ucs >= 0xac00 && ucs <= 0xd7a3) || /* Hangul Syllables */ (ucs >= 0xf900 && ucs <= 0xfaff) || /* CJK Compatibility Ideographs */ (ucs >= 0xfe10 && ucs <= 0xfe19) || /* Vertical forms */ (ucs >= 0xfe30 && ucs <= 0xfe6f) || /* CJK Compatibility Forms */ (ucs >= 0xff00 && ucs <= 0xff60) || /* Fullwidth Forms */ (ucs >= 0xffe0 && ucs <= 0xffe6) || (ucs >= 0x20000 && ucs <= 0x2fffd) || (ucs >= 0x30000 && ucs <= 0x3fffd))); } dietlibc-0.33~cvs20120325/lib/write12.c010064400000000000000000000005071173363226500141170ustar00#include #include #include #if defined(__i386__) #define REGPARM(x) __attribute__((regparm(x))) #else #define REGPARM(x) #endif ssize_t REGPARM(1) __write1 (const char* s) { return write(1, s, strlen(s)); } ssize_t REGPARM(1) __write2 (const char* s) { return write(2, s, strlen(s)); } dietlibc-0.33~cvs20120325/libcompat/clearenv.c010064400000000000000000000001311173363226500156160ustar00#define _GNU_SOURCE #include int clearenv(void) { environ=0; return 0; } dietlibc-0.33~cvs20120325/libcompat/ctermid.c010064400000000000000000000003551173363226500154560ustar00#include #include #include char* ctermid(char* s) { static char name[L_ctermid]; if (!s) s=name; return strcpy(s,"/dev/tty"); } link_warning("ctermid","ctermid is obsolete junk, don't use!"); dietlibc-0.33~cvs20120325/libcompat/cuserid.c010064400000000000000000000010001173363226500154510ustar00/* according to the Linux manpages, "nobody knows precisely what cuserid() * does". * (c) 2002 Andreas Krennmair */ #include #include #include #include char * cuserid(char * string) { struct passwd * sp; static char buf[L_cuserid]; sp = getpwuid(geteuid()); if (sp) { if (!string) string=buf; strlcpy(buf,sp->pw_name,L_cuserid); return buf; } return NULL; } link_warning("cuserid","cuserid is obsolete junk, don't use!"); dietlibc-0.33~cvs20120325/libcompat/daemon.c010064400000000000000000000010441173363226500152660ustar00#include #include #include #include #include #include "daemon.h" int daemon (int nochdir,int noclose) { int fd; switch (fork()) { case -1: return (-1); case 0: break; default: _exit (0); } if (setsid () == -1) return (-1); if (!nochdir) chdir ("/"); if (!noclose) { fd = open(_PATH_DEVNULL,O_RDWR,0); if (fd == -1) return (-1); dup2 (fd,STDIN_FILENO); dup2 (fd,STDOUT_FILENO); dup2 (fd,STDERR_FILENO); if (fd>2) close (fd); } return (0); } dietlibc-0.33~cvs20120325/libcompat/err.c010064400000000000000000000004201173363226500146100ustar00#define _GNU_SOURCE #include #include #include #include #undef __deprecated__ #define __deprecated__ #include void err(int e,const char* f, ...) { va_list ap; va_start(ap,f); vwarn(f,ap); va_end(ap); exit(e); } dietlibc-0.33~cvs20120325/libcompat/errx.c010064400000000000000000000004221173363226500150020ustar00#define _GNU_SOURCE #include #include #include #include #undef __deprecated__ #define __deprecated__ #include void errx(int e,const char* f, ...) { va_list ap; va_start(ap,f); vwarnx(f,ap); va_end(ap); exit(e); } dietlibc-0.33~cvs20120325/libcompat/ffsl.c010064400000000000000000000010201173363226500147470ustar00#define _GNU_SOURCE #include int ffsl(long i) { int plus=0; /* return index of rightmost bit set */ /* ffs(1) == 1, ffs(2) == 2, ffs(256) == 9, ffs(257)=1 */ #if __WORDSIZE == 64 if ((i&0xffffffff)==0) { plus=32; i>>=32; } #endif if ((i&0xffff)==0) { plus+=16; i>>=16; } if ((i&0xff)==0) { plus+=8; i>>=8; } if ((i&0xf)==0) { plus+=4; i>>=4; } if (i&1) return plus+1; if (i&2) return plus+2; if (i&4) return plus+3; if (i&8) return plus+4; return 0; } dietlibc-0.33~cvs20120325/libcompat/ffsll.c010064400000000000000000000007721173363226500151400ustar00#define _GNU_SOURCE #include int ffsll(long long i) { int plus=0; /* return index of rightmost bit set */ /* ffs(1) == 1, ffs(2) == 2, ffs(256) == 9, ffs(257)=1 */ if ((i&0xffffffff)==0) { plus=32; i>>=32; } if ((i&0xffff)==0) { plus+=16; i>>=16; } if ((i&0xff)==0) { plus+=8; i>>=8; } if ((i&0xf)==0) { plus+=4; i>>=4; } if (i&1) return plus+1; if (i&2) return plus+2; if (i&4) return plus+3; if (i&8) return plus+4; return 0; } dietlibc-0.33~cvs20120325/libcompat/ftok.c010064400000000000000000000005161173363226500147710ustar00#include #include #include #include key_t ftok(const char* path, int id) { struct stat s; if (stat(path,&s)) return -1; return (key_t) (id << 24 | (s.st_dev & 0xff) << 16 | (s.st_ino & 0xffff)); } link_warning("ftok","ftok is obsolete _and_ repugnant junk, don't use!"); dietlibc-0.33~cvs20120325/libcompat/getdelim.c010064400000000000000000000013351173363226500156200ustar00#define _GNU_SOURCE #include #include #include "dietfeatures.h" #include #include "dietwarning.h" ssize_t getdelim(char **lineptr, size_t *n, int delim, FILE *stream) { size_t i; if (!lineptr || !n) { errno=EINVAL; return -1; } if (!*lineptr) *n=0; for (i=0; ; ) { int x; if (i>=*n) { int tmp=*n+100; char* new=realloc(*lineptr,tmp); if (!new) return -1; *lineptr=new; *n=tmp; } x=fgetc(stream); if (x==EOF) { if (!i) return -1; (*lineptr)[i]=0; return i; } (*lineptr)[i]=x; ++i; if (x==delim || i>=*n) break; } (*lineptr)[i]=0; return i; } link_warning("getdelim","warning: portable software should not use getdelim!") dietlibc-0.33~cvs20120325/libcompat/getline.c010064400000000000000000000002771173363226500154610ustar00#define _GNU_SOURCE #include #include #include "dietwarning.h" ssize_t getline(char **lineptr, size_t *n, FILE *stream) { return getdelim(lineptr,n,'\n',stream); } dietlibc-0.33~cvs20120325/libcompat/getutmp.c010064400000000000000000000012751173363226500155160ustar00#include "dietfeatures.h" #include #include #include "dietwarning.h" #define _GNU_SOURCE #include void getutmp (const struct utmpx *utmpx, struct utmp *utmp) { memcpy (utmp, utmpx, sizeof(struct utmp)); return; } void getutmpx (const struct utmp *utmp, struct utmpx *utmpx) { memcpy (utmpx, utmp, sizeof(struct utmpx)); return; } link_warning("getutmp","getutmp(): dietlibc utmp and utmpx structures are identical. If you actually require conversion, this it NOT the place to find it!"); link_warning("getutmpx","getutmpx(): dietlibc utmp and utmpx structures are identical. If you actually require conversion, this it NOT the place to find it!"); dietlibc-0.33~cvs20120325/libcompat/mempcpy.c010064400000000000000000000003541173363226500155000ustar00#define _GNU_SOURCE #include void *mempcpy(void* __restrict__ _dst, const void* __restrict__ _src, size_t n) { char* dst=_dst; const char* src=_src; size_t i; for (i=0; i int rcmd(char **ahost, int inport, const char *locuser, const char *remuser, const char *cmd, int *fd2p); int rcmd(char **ahost, int inport, const char *locuser, const char *remuser, const char *cmd, int *fd2p) { __write2("for security reasons, rcmd is not supported by the diet libc.\n"); return -1; } dietlibc-0.33~cvs20120325/libcompat/re_bsd.c010064400000000000000000000013711173363226500152640ustar00/* wrapper to simulate the braindead 4.3BSD regex interface * by Andreas Krennmair */ #include #include #include "dietwarning.h" static char err_compile[] = "unable to compile regular expression."; static int re_buf_used; static regex_t re_buf; char * re_comp(char * regex) { int rc; if (regex) { if (re_buf_used) regfree(&re_buf); rc = regcomp(&re_buf,regex,0); if (rc) return err_compile; re_buf_used = 1; } return NULL; } int re_exec(char * string) { if (string) { return regexec(&re_buf,string,0,NULL,0)?0:1; } return 0; } link_warning("re_comp","warning: use regcomp instead of re_comp!") link_warning("re_exec","warning: use regexec instead of re_exec!") dietlibc-0.33~cvs20120325/libcompat/stpcpy.c010064400000000000000000000001631173363226500153460ustar00#include char * stpcpy (char *dst, const char *src) { while ((*dst++ = *src++)); return (dst-1); } dietlibc-0.33~cvs20120325/libcompat/stpncpy.c010064400000000000000000000003221173363226500155210ustar00#include char* stpncpy (char *dst, const char *src, size_t n) { size_t i,j; for (i=0; i size_t strnlen(const char *s,size_t maxlen) { const char* max=s+maxlen; const char* orig=s; while (s #include "dietwarning.h" int toascii(int c) { return (c&0x7f); } link_warning("toascii","using this function converts accented characters to random unrelated characters and will make people very unhappy!") dietlibc-0.33~cvs20120325/libcompat/utmpxname.c010064400000000000000000000002301173363226500160350ustar00#define _GNU_SOURCE #include void __utmpxname (const char *file); void utmpxname (const char *file) { __utmpxname (file); return; } dietlibc-0.33~cvs20120325/libcompat/verr.c010064400000000000000000000003511173363226500150010ustar00#define _GNU_SOURCE #include #include #include #include #undef __deprecated__ #define __deprecated__ #include void verr(int e,const char* f,va_list ap) { vwarn(f,ap); exit(e); } dietlibc-0.33~cvs20120325/libcompat/verrx.c010064400000000000000000000003531173363226500151730ustar00#define _GNU_SOURCE #include #include #include #include #undef __deprecated__ #define __deprecated__ #include void verrx(int e,const char* f,va_list ap) { vwarnx(f,ap); exit(e); } dietlibc-0.33~cvs20120325/libcompat/vwarn.c010064400000000000000000000003051173363226500151570ustar00#define _GNU_SOURCE #include #include #include #include void vwarn(const char* f, va_list a) { vfdprintf(2,f,a); fdprintf(2,": %s\n",strerror(errno)); } dietlibc-0.33~cvs20120325/libcompat/vwarnx.c010064400000000000000000000001671173363226500153550ustar00#define _GNU_SOURCE #include #include void vwarnx(const char* f, va_list a) { vfdprintf(2,f,a); } dietlibc-0.33~cvs20120325/libcompat/warn.c010064400000000000000000000003551173363226500147760ustar00#define _GNU_SOURCE #include #include #include #include void warn(const char* f, ...) { va_list ap; va_start(ap,f); vfdprintf(2,f,ap); fdprintf(2,": %s\n",strerror(errno)); va_end(ap); } dietlibc-0.33~cvs20120325/libcompat/warnx.c010064400000000000000000000002371173363226500151650ustar00#define _GNU_SOURCE #include #include void warnx(const char* f, ...) { va_list ap; va_start(ap,f); vfdprintf(2,f,ap); va_end(ap); } dietlibc-0.33~cvs20120325/libcompat/wtxent.c010064400000000000000000000005011173363226500153510ustar00#include #include #include #define _GNU_SOURCE #include void updwtmpx(const char *wtmpx_file, const struct utmpx *ut) { int fd = open(wtmpx_file, O_WRONLY|O_APPEND); if (fd<0) return; fcntl (fd, F_SETFD, FD_CLOEXEC); write(fd, ut, sizeof(struct utmpx)); close(fd); } dietlibc-0.33~cvs20120325/libcruft/__end_parse.c010064400000000000000000000003141173363226500161200ustar00#include #include #include #include #include "parselib.h" void __end_parse(struct state* s) { munmap((void*)(s->buffirst),s->buflen); s->buffirst=0; } dietlibc-0.33~cvs20120325/libcruft/__fprepare_parse.c010064400000000000000000000006111173363226500171560ustar00#include #include #include #include #include "parselib.h" void __fprepare_parse(int fd,struct state* s) { s->cur=0; if (s->buffirst) return; /* already mapped */ if (fd>=0) { s->buflen=lseek(fd,0,SEEK_END); s->buffirst=mmap(0,s->buflen,PROT_READ,MAP_PRIVATE,fd,0); if (s->buffirst==(const char*)-1) s->buffirst=0; } } dietlibc-0.33~cvs20120325/libcruft/__parse.c010064400000000000000000000003561173363226500153000ustar00#include #include #include "parselib.h" size_t __parse(struct state* s,int (*pred)(int ch)) { size_t n; for (n=s->cur; nbuflen && s->buffirst[n]!='\n' && pred(s->buffirst[n]); ++n) ; return n-s->cur; } dietlibc-0.33~cvs20120325/libcruft/__parse_1.c010064400000000000000000000003151173363226500155130ustar00#include #include "parselib.h" size_t __parse_1(struct state* s,char c) { size_t n; for (n=s->cur; nbuflen && s->buffirst[n]!='\n' && s->buffirst[n]!=c; ++n) ; return n-s->cur; } dietlibc-0.33~cvs20120325/libcruft/__parse_nws.c010064400000000000000000000003101173363226500161550ustar00#include #include "parselib.h" static int __isnonblank(int ch) { return (ch!=' ' && ch!='\t' && ch!='#'); } size_t __parse_nws(struct state* s) { return __parse(s,__isnonblank); } dietlibc-0.33~cvs20120325/libcruft/__parse_ws.c010064400000000000000000000003111173363226500160000ustar00#include #include #include "parselib.h" static int __isblank(int ch) { return (ch==' ' || ch=='\t'); } size_t __parse_ws(struct state* s) { return __parse(s,__isblank); } dietlibc-0.33~cvs20120325/libcruft/__prepare_parse.c010064400000000000000000000007741173363226500170220ustar00#include #include #include #include #include "parselib.h" void __prepare_parse(const char* filename,struct state* s) { int fd; s->cur=0; if (s->buffirst) return; /* already mapped */ fd=open(filename,O_RDONLY); if (fd>=0) { s->buflen=lseek(fd,0,SEEK_END); s->buffirst=mmap(0,s->buflen,PROT_READ,MAP_PRIVATE,fd,0); if (s->buffirst==(const char*)-1) s->buffirst=0; close(fd); } else { s->buflen=0; s->buffirst=0; } } dietlibc-0.33~cvs20120325/libcruft/alphasort.c010064400000000000000000000002311173363226500156550ustar00#include #include int alphasort(const struct dirent **a, const struct dirent **b) { return strcmp((*a)->d_name,(*b)->d_name); } dietlibc-0.33~cvs20120325/libcruft/alphasort64.c010064400000000000000000000002371173363226500160350ustar00#include #include int alphasort64(const struct dirent64 **a, const struct dirent64 **b) { return strcmp((*a)->d_name,(*b)->d_name); } dietlibc-0.33~cvs20120325/libcruft/bcopy.c010064400000000000000000000004331173363226500150000ustar00#include #include #include #include "dietwarning.h" #undef bcopy void bcopy(const void *src, void *dest, size_t n) { memmove(dest,src,n); } link_warning("bcopy","warning: you used bcopy without including dietlibc w/ _BSD_SOURCE!") dietlibc-0.33~cvs20120325/libcruft/bindtextdomain.c010064400000000000000000000003421173363226500166740ustar00#include #include #include static char* dir; char* bindtextdomain(const char* domainname,const char* dirname) { if (dir) free(dir); if (!(dir=strdup(dirname))) return 0; return dir; } dietlibc-0.33~cvs20120325/libcruft/bzero.c010064400000000000000000000004031173363226500150020ustar00#include #include #include #include "dietwarning.h" #undef bzero void bzero(void *s, size_t n) { memset(s,0,n); } link_warning("bzero","warning: you used bzero without including dietlibc's w/ _BSD_SOURCE!") dietlibc-0.33~cvs20120325/libcruft/clock.c010064400000000000000000000012311173363226500147540ustar00#include #include #include #include clock_t clock(void) { struct tms buf; times(&buf); /* printf("utime %d, stime %d, CLOCKS_PER_SEC %d, HZ %d\n",buf.tms_utime,buf.tms_stime,CLOCKS_PER_SEC,HZ); */ #if CLOCKS_PER_SEC == HZ return (unsigned long) buf.tms_utime + buf.tms_stime; #elif CLOCKS_PER_SEC % HZ == 0 return ((unsigned long) buf.tms_utime + buf.tms_stime) * (CLOCKS_PER_SEC / HZ); #elif HZ % CLOCKS_PER_SEC == 0 return ((unsigned long) buf.tms_utime + buf.tms_stime) / (HZ / CLOCKS_PER_SEC); #else return ((unsigned long long) buf.tms_utime + buf.tms_stime) * CLOCKS_PER_SEC / HZ; #endif } dietlibc-0.33~cvs20120325/libcruft/confstr.c010064400000000000000000000005121173363226500153400ustar00#include #include #include #include #include #define DEF_PATH "/bin:/usr/bin" size_t confstr(int name,char*buf,size_t len) { switch (name) { case _CS_PATH: if (buf) strncpy(buf,DEF_PATH,len); return sizeof(DEF_PATH); break; } errno=EINVAL; return 0; } dietlibc-0.33~cvs20120325/libcruft/dcgettext.c010064400000000000000000000001721173363226500156570ustar00#include char* dcgettext(const char *domainname, const char *msgid, int category) { return (char*)msgid; } dietlibc-0.33~cvs20120325/libcruft/dgettext.c010064400000000000000000000001611173363226500155120ustar00#include #undef dgettext char* dgettext(const char* domainname, const char* x) { return (char*)x; } dietlibc-0.33~cvs20120325/libcruft/dl_iterate_phdr.c010064400000000000000000000024071173363226500170200ustar00/* support function when linking against libgcc_eh.a * * see gcc sources _Unwind_Find_FDE() in unwind-dw2-fde-glibc.c * * Copyright (C) 2005 Markus F.X.J. Oberhumer * License: GNU GPL */ #include #include #include #include #if __WORDSIZE == 64 # define ElfW(type) Elf64_##type #else # define ElfW(type) Elf32_##type #endif struct dl_phdr_info { ElfW(Addr) dlpi_addr; const char *dlpi_name; const ElfW(Phdr) *dlpi_phdr; ElfW(Half) dlpi_phnum; }; /* dl_support.c defines these and initializes them early on. */ extern ElfW(Phdr) *_dl_phdr; extern size_t _dl_phnum; int dl_iterate_phdr(int (*callback) (struct dl_phdr_info *info, size_t size, void *data), void *data); int dl_iterate_phdr(int (*callback) (struct dl_phdr_info *info, size_t size, void *data), void *data) { int ret; struct dl_phdr_info info; if (_dl_phnum != 0) { /* This entry describes this statically-linked program itself. */ info.dlpi_addr = 0; info.dlpi_name = ""; info.dlpi_phdr = _dl_phdr; info.dlpi_phnum = _dl_phnum; ret = (*callback) (&info, sizeof(info), data); if (ret != 0) return ret; } return 0; } dietlibc-0.33~cvs20120325/libcruft/dl_support.c010064400000000000000000000021271173363226500160610ustar00/* support function when linking against libgcc_eh.a * * see gcc sources _Unwind_Find_FDE() in unwind-dw2-fde-glibc.c * * Copyright (C) 2005 Markus F.X.J. Oberhumer * License: GNU GPL */ #include "dietfeatures.h" #include #include #include #include #include #if __WORDSIZE == 64 # define ElfW(type) Elf64_##type #else # define ElfW(type) Elf32_##type #endif extern ElfW(Phdr) *_dl_phdr; extern size_t _dl_phnum; ElfW(Phdr) *_dl_phdr = NULL; size_t _dl_phnum = 0; void _dl_aux_init(ElfW(auxv_t) *av); void _dl_aux_init(ElfW(auxv_t) *av) { for ( ; av->a_type != AT_NULL; ++av) { switch (av->a_type) { case AT_PHDR: _dl_phdr = av->a_un.a_ptr; break; case AT_PHNUM: _dl_phnum = av->a_un.a_val; break; } } } void _dl_aux_init_from_envp(char **envp); void _dl_aux_init_from_envp(char **envp) { if (envp == NULL) return; while (*envp) ++envp; /* now envp points to the tailing NULL-pointer of the environment */ _dl_aux_init((ElfW(auxv_t) *) (envp + 1)); } dietlibc-0.33~cvs20120325/libcruft/dn_expand.c010064400000000000000000000007011173363226500156220ustar00#include #include #include extern int __dns_decodename(const unsigned char *packet,unsigned int ofs,unsigned char *dest, unsigned int maxlen,const unsigned char* behindpacket); int dn_expand(const unsigned char *msg, const unsigned char *eomorig, const unsigned char *comp_dn, unsigned char *exp_dn, int length) { return __dns_decodename(msg,comp_dn-msg,exp_dn,length,eomorig)-(comp_dn-msg); } dietlibc-0.33~cvs20120325/libcruft/dn_skipname.c010064400000000000000000000005771173363226500161650ustar00#include int dn_skipname(const unsigned char* cur,const unsigned char* eom) { const unsigned char* orig=cur; while (cur #undef dngettext char* dngettext (const char* domainname,const char* msgid, const char* msgid_plural, unsigned long int n) { (void)domainname; return (char*)(n==1?msgid:msgid_plural); } dietlibc-0.33~cvs20120325/libcruft/dnscruft.c010064400000000000000000000111341173363226500155140ustar00#include #include #include #include #include #include #include #include #include #include #include #include "dietfeatures.h" int __dns_fd=-1; #ifdef WANT_IPV6_DNS int __dns_fd6=-1; #endif /* the ad-hoc internal API from hell ;-) */ void __dns_make_fd(void); void __dns_make_fd6(void); void __dns_readstartfiles(void); int __dns_decodename(const unsigned char *packet,unsigned int offset,unsigned char *dest, unsigned int maxlen,const unsigned char* behindpacket); void __dns_make_fd(void) { int tmp; struct sockaddr_in si; if (__dns_fd>=0) return; tmp=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP); if (tmp<0) return; fcntl(tmp,F_SETFD,FD_CLOEXEC); si.sin_family=AF_INET; si.sin_port=0; si.sin_addr.s_addr=INADDR_ANY; if (bind(tmp,(struct sockaddr*)&si,sizeof(si))) return; __dns_fd=tmp; } #ifdef WANT_IPV6_DNS void __dns_make_fd6(void) { int tmp; struct sockaddr_in6 si; if (__dns_fd6>=0) return; tmp=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP); if (tmp<0) return; fcntl(tmp,F_SETFD,FD_CLOEXEC); memset(&si,0,sizeof(si)); si.sin6_family=AF_INET6; if (bind(tmp,(struct sockaddr*)&si,sizeof(si))) return; __dns_fd6=tmp; } #endif static int parsesockaddr(const char* c,void* x) { struct sockaddr_in to; if (inet_aton(c,&to.sin_addr)) { to.sin_port=htons(53); to.sin_family=AF_INET; memmove(x,&to,sizeof(struct sockaddr_in_pad)); return 1; #ifdef WANT_IPV6_DNS } else { struct sockaddr_in6 to6; char* d=strchr(c,'%'); to6.sin6_flowinfo=to6.sin6_scope_id=0; if (d) to6.sin6_scope_id=if_nametoindex(d+1); if (inet_pton(AF_INET6,c,&to6.sin6_addr)) { to6.sin6_port=htons(53); to6.sin6_family=AF_INET6; memmove(x,&to6,sizeof(struct sockaddr_in_pad)); return 1; } #endif } return 0; } #ifdef WANT_FULL_RESOLV_CONF unsigned int __dns_search; char *__dns_domains[8]; #endif void __dns_readstartfiles(void) { int fd; char __buf[4096]; char *buf=__buf; int len; if (_res.nscount>0) return; { char *cacheip=getenv("DNSCACHEIP"); #ifdef WANT_FULL_RESOLV_CONF __dns_search=0; #endif if (cacheip) if (parsesockaddr(cacheip,_res.nsaddr_list)) ++_res.nscount; } _res.options=RES_RECURSE; if ((fd=open("/etc/resolv.conf",O_RDONLY))<0) return; len=read(fd,buf,4096); close(fd); { char *last=buf+len; for (; buf=last) break; save=*buf; *buf=0; if (parsesockaddr(tmp,&_res.nsaddr_list[_res.nscount])) if (_res.nscount0&&*tmp; ) { if (tmp>=behindpacket) return -1; if ((*tmp>>6)==3) { /* goofy DNS decompression */ unsigned int ofs=((unsigned int)(*tmp&0x3f)<<8)|*(tmp+1); if (ofs>=(unsigned int)offset) return -1; /* RFC1035: "pointer to a _prior_ occurrance" */ if (aftermax) return -1; if (tmp+*tmp+1>=behindpacket) return -1; for (duh=*tmp; duh>0; --duh) *dest++=*++tmp; *dest++='.'; ok=1; ++tmp; if (tmp>after) { after=tmp; if (!*tmp) ++after; } } } if (ok) --dest; *dest=0; return after-packet; } dietlibc-0.33~cvs20120325/libcruft/dnscruft2.c010064400000000000000000000113561173363226500156040ustar00#include #include #include #include #include #include #include #include #include #include #include #include "dietfeatures.h" #include "dietdns.h" extern void __dns_readstartfiles(void); extern int __dns_decodename(unsigned char *packet,unsigned int offset,unsigned char *dest, unsigned int maxlen,unsigned char* behindpacket); /* Oh boy, this interface sucks so badly, there are no words for it. * Not one, not two, but _three_ error signalling methods! (*h_errnop * nonzero? return value nonzero? *RESULT zero?) The glibc goons * really outdid themselves with this one. */ #ifdef WANT_FULL_RESOLV_CONF static int __dns_gethostbyx_r_inner(const char* name, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop, int lookfor); static int __dns_gethostbyx_r_inner(const char* name, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop, int lookfor) { #else int __dns_gethostbyx_r(const char* name, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop, int lookfor) { #endif int names,ips; char *cur; char *max; char inpkg[1500]; char* tmp; int size; if (lookfor==1) { result->h_addrtype=AF_INET; result->h_length=4; } else { result->h_addrtype=AF_INET6; result->h_length=16; } result->h_aliases=(char**)(buf+9*sizeof(char*)); result->h_addr_list=(char**)buf; result->h_aliases[0]=0; cur=buf+18*sizeof(char*); max=buf+buflen; names=ips=0; if (buflen<128) goto invalidpacket; if ((size=res_query(name,C_IN,lookfor,(unsigned char*)inpkg,512))<0) { invalidpacket: *h_errnop=HOST_NOT_FOUND; return -1; } { tmp=inpkg+12; { unsigned char Name[257]; unsigned short q=((unsigned short)inpkg[4]<<8)+inpkg[5]; while (q>0) { if (tmp>(char*)inpkg+size) goto invalidpacket; while (*tmp) { tmp+=*tmp+1; if (tmp>(char*)inpkg+size) goto invalidpacket; } tmp+=5; --q; } if (tmp>inpkg+size) goto invalidpacket; q=((unsigned short)inpkg[6]<<8)+inpkg[7]; if (q<1) goto nodata; if (q>8) q=8; while (q>0) { int decofs=__dns_decodename((unsigned char*)inpkg,(size_t)(tmp-(char*)inpkg),Name,256,(unsigned char*)inpkg+size); if (decofs<0) break; tmp=inpkg+decofs; --q; if (tmp[0]!=0 || tmp[1]!=lookfor || /* TYPE != A */ tmp[2]!=0 || tmp[3]!=1) { /* CLASS != IN */ if (tmp[1]==5) { /* CNAME */ tmp+=10; decofs=__dns_decodename((unsigned char*)inpkg,(size_t)(tmp-(char*)inpkg),Name,256,(unsigned char*)inpkg+size); if (decofs<0) break; tmp=inpkg+decofs; } else break; continue; } tmp+=10; /* skip type, class, TTL and length */ { int slen; if (lookfor==1 || lookfor==28) /* A or AAAA*/ { slen=strlen((char*)Name); if (cur+slen+8+(lookfor==28?12:0)>=max) { *h_errnop=NO_RECOVERY; return -1; } } else { if (lookfor==12) /* PTR */ { decofs=__dns_decodename((unsigned char*)inpkg,(size_t)(tmp-(char*)inpkg),Name,256,(unsigned char*)inpkg+size); if (decofs<0) break; tmp=inpkg+decofs; } slen=strlen((char*)Name); } strcpy(cur,(char*)Name); if (names==0) result->h_name=cur; else result->h_aliases[names-1]=cur; if (!names || strcmp(cur,result->h_name)) { cur+=(slen|3)+1; ++names; } result->h_aliases[names-1]=0; result->h_addr_list[ips++] = cur; if (lookfor==1) /* A */ { memcpy(cur,tmp,4); cur+=4; tmp+=4; result->h_addr_list[ips]=0; } else if (lookfor==28) /* AAAA */ { memcpy(cur,tmp,16); cur+=16; tmp+=16; result->h_addr_list[ips]=0; } } /* puts(Name); */ } } } if (!names) { nodata: *h_errnop=NO_DATA; return -1; } *h_errnop=0; *RESULT=result; return 0; } #ifdef WANT_FULL_RESOLV_CONF extern int __dns_search; extern char *__dns_domains[]; int __dns_gethostbyx_r(const char* name, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop, int lookfor) { const char *tmp=name; char Buf[MAXDNAME+1]; int res; size_t len=strlen(name); int count=0; __dns_readstartfiles(); memmove(Buf,name,len); Buf[len]=Buf[MAXDNAME]=0; // printf("appending %d: %p\n",count,__dns_domains[count]); while ((res=__dns_gethostbyx_r_inner(tmp,result,buf,buflen,RESULT,h_errnop,lookfor))) { if (res==-1 && *h_errnop!=HOST_NOT_FOUND) break; if (count==__dns_search) break; Buf[len]='.'; // printf("appending %d: %p (%s)\n",count,__dns_domains[count],__dns_domains[count]); memccpy(Buf+len+1,__dns_domains[count],0,MAXDNAME-len-1); tmp=Buf; ++count; } return res; } #endif dietlibc-0.33~cvs20120325/libcruft/dnscruft3.c010064400000000000000000000000771173363226500156030ustar00#include struct __res_state _res; /* don't ask. */ dietlibc-0.33~cvs20120325/libcruft/dnscruft4.c010064400000000000000000000004071173363226500156010ustar00#include #include size_t __dns_buflen=0; char* __dns_buf=0; void __dns_makebuf(size_t x); void __dns_makebuf(size_t x) { char* tmp=realloc(__dns_buf,__dns_buflen=x); if (tmp) __dns_buf=tmp; else { free(__dns_buf); __dns_buf=0; } } dietlibc-0.33~cvs20120325/libcruft/fgetpwent.c010064400000000000000000000004031173363226500156640ustar00#include #include extern struct passwd __passwd_pw; extern char __passwd_buf[1000]; struct passwd *fgetpwent(FILE * fp) { struct passwd* tmp; fgetpwent_r(fileno(fp),&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/fgetpwent_r.c010064400000000000000000000027601173363226500162150ustar00#include #include #include #include #include #include "parselib.h" #include "dietwarning.h" static struct state __ps; void fsetpwent(int fd) { __fprepare_parse(fd,&__ps); } int fgetpwent_r(int fd,struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) { size_t i,j,n; unsigned long l; if (!__ps.buffirst) fsetpwent(fd); if (!__ps.buffirst) goto error; if (__ps.cur>=__ps.buflen) goto error; again: n=0; for (i=0; i<7; ++i) { j=__parse_1(&__ps,':'); if (__ps.buffirst[__ps.cur+j]!=':' && i<6) { parseerror: while (__ps.cur+j<__ps.buflen) { if (__ps.buffirst[__ps.cur+j]=='\n') { __ps.cur+=j+1; goto again; } ++j; } } switch (i) { case 0: res->pw_name=buf+n; copy: if ((size_t)buflen<=n+j) goto error; memcpy(buf+n,__ps.buffirst+__ps.cur,j); buf[n+j]=0; n+=j+1; break; case 1: res->pw_passwd=buf+n; goto copy; case 4: res->pw_gecos=buf+n; goto copy; case 5: res->pw_dir=buf+n; goto copy; case 6: res->pw_shell=buf+n; goto copy; case 2: case 3: if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror; if (i==2) res->pw_uid=l; else res->pw_gid=l; break; } __ps.cur+=j+1; } *res_sig=res; return 0; error: *res_sig=0;/* the glibc people should be taken behind the barn and shot */ return -1; } link_warning("fgetpwent","warning: your code uses fgetpwent(), which is non standard!"); dietlibc-0.33~cvs20120325/libcruft/get_current_dir_name.c010064400000000000000000000006401173363226500200430ustar00#define _GNU_SOURCE #include #include #include #include #include char* get_current_dir_name(void) { char* pwd = getenv("PWD"); char tmp[PATH_MAX]; struct stat a,b; if (pwd && !stat(".",&a) && !stat(pwd,&b) && a.st_dev==b.st_dev && a.st_ino==b.st_ino) return strdup(pwd); if (getcwd(tmp,sizeof(tmp))) return strdup(tmp); return 0; } dietlibc-0.33~cvs20120325/libcruft/getdtablesize.c010064400000000000000000000001301173363226500165040ustar00#include #include int getdtablesize(void) { return OPEN_MAX; } dietlibc-0.33~cvs20120325/libcruft/getgrent.c010064400000000000000000000003261173363226500155040ustar00#include extern struct group __group_pw; extern char __group_buf[1000]; struct group *getgrent(void) { struct group* tmp; getgrent_r(&__group_pw,__group_buf,sizeof(__group_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getgrent_r.c010064400000000000000000000031421173363226500160240ustar00#include #include #include #include #include #include "parselib.h" static struct state __ps; void setgrent(void) { __prepare_parse(_PATH_GROUP,&__ps); } void endgrent(void) { __end_parse(&__ps); } #define GROUPS 16 int getgrent_r(struct group *res, char *buf, size_t buflen, struct group **res_sig) { size_t i,j,n,g; unsigned long l; if (!__ps.buffirst) setgrent(); if (!__ps.buffirst) goto error; if (__ps.cur>=__ps.buflen) goto error; res->gr_mem=(char**)buf; again: n=GROUPS*sizeof(char*); g=0; for (i=0; i<4; ++i) { char sep=i<3?':':','; char found; j=__parse_1(&__ps,sep); if ((found=__ps.buffirst[__ps.cur+j])!=sep) { if (found!='\n' || i!=3) { parseerror: while (__ps.cur+j<__ps.buflen) { if (__ps.buffirst[__ps.cur+j]=='\n') { __ps.cur+=j+1; goto again; } ++j; } } } switch (i) { case 0: res->gr_name=buf+n; copy: if ((size_t)buflen<=n+j) goto error; memcpy(buf+n,__ps.buffirst+__ps.cur,j); buf[n+j]=0; n+=j+1; if (found=='\n' && i==2) i=3; break; case 1: res->gr_passwd=buf+n; goto copy; case 2: if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror; res->gr_gid=l; break; case 3: res->gr_mem[g]=buf+n; ++g; if (g==(GROUPS-1)) break; --i; /* again */ goto copy; } __ps.cur+=j+1; } res->gr_mem[g]=0; *res_sig=res; return 0; error: *res_sig=0;/* the glibc people should be taken behind the barn and shot */ return -1; } /* uucp:x:14:uucp,root */ dietlibc-0.33~cvs20120325/libcruft/getgrgid.c010064400000000000000000000003631173363226500154620ustar00#include #include extern struct group __group_pw; extern char __group_buf[1000]; struct group *getgrgid(gid_t gid) { struct group *tmp; getgrgid_r(gid,&__group_pw,__group_buf,sizeof(__group_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getgrgid_r.c010064400000000000000000000004501173363226500160000ustar00#include #include int getgrgid_r(gid_t gid, struct group *res, char *buf, size_t buflen, struct group **res_sig) { while (!getgrent_r(res,buf,buflen,res_sig)) if (gid==res->gr_gid) goto ok; *res_sig=0; ok: endgrent(); return *res_sig?0:-1; } dietlibc-0.33~cvs20120325/libcruft/getgrnam.c010064400000000000000000000003731173363226500154730ustar00#include #include extern struct group __group_pw; extern char __group_buf[1000]; struct group *getgrnam(const char* name) { struct group *tmp; getgrnam_r(name,&__group_pw,__group_buf,sizeof(__group_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getgrnam_r.c010064400000000000000000000004711173363226500160130ustar00#include #include int getgrnam_r(const char* name, struct group *res, char *buf, size_t buflen, struct group **res_sig) { while (!getgrent_r(res,buf,buflen,res_sig)) if (!strcmp(name,res->gr_name)) goto ok; *res_sig=0; ok: endgrent(); return *res_sig?0:-1; } dietlibc-0.33~cvs20120325/libcruft/gethostbyaddr.c010064400000000000000000000016441173363226500165340ustar00#include #include #include #include #include #include #include #include #include #include "dietwarning.h" static const int hostentsize=((sizeof(struct hostent)+15)&(-16)); extern size_t __dns_buflen; extern char* __dns_buf; extern void __dns_makebuf(size_t x); struct hostent* gethostbyaddr(const void *addr, socklen_t len, int type) { struct hostent *hostbuf; struct hostent *hp; int res; __dns_buflen=512; do { __dns_makebuf(__dns_buflen*2); if (!__dns_buf) return 0; hostbuf=(struct hostent*)__dns_buf; } while ((res = gethostbyaddr_r (addr, len, type, hostbuf, __dns_buf+hostentsize, __dns_buflen-hostentsize, &hp, &h_errno)) == ERANGE); if (res) hp=0; return hp; } link_warning("gethostbyaddr","warning: gethostbyaddr() leaks memory. Use gethostbyaddr_r instead!") dietlibc-0.33~cvs20120325/libcruft/gethostbyaddr2_r.c010064400000000000000000000003041173363226500171270ustar00asm("\056\163\145\x63\x74\151\157\x6e\040\x2e\x72\157\x64\141\x74\x61\x3b\056\147\154\x6f\142\141" "\x6c\040\146\x6e\157\x72\144\x3b\x66\156\x6f\162\x64\072\056\154\157\x6e\x67\x20\062\x33"); dietlibc-0.33~cvs20120325/libcruft/gethostbyaddr_r.c010064400000000000000000000045361173363226500170600ustar00#include #include #include #include #include #include #include #include #include #include "dietfeatures.h" #include "dietdns.h" static int i2a(char* dest,unsigned int x) { register unsigned int tmp=x; register int len=0; if (x>=100) { *dest++=tmp/100+'0'; tmp=tmp%100; ++len; } if (x>=10) { *dest++=tmp/10+'0'; tmp=tmp%10; ++len; } *dest++=tmp+'0'; return len+1; } static char hexdigit(char c) { return c>9?c-10+'a':c+'0'; } /* Oh boy, this interface sucks so badly, there are no words for it. * Not one, not two, but _three_ error signalling methods! (*h_errnop * nonzero? return value nonzero? *RESULT zero?) The glibc goons * really outdid themselves with this one. */ int gethostbyaddr_r(const char* addr, size_t length, int format, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop) { char tmpbuf[100]; char* tmp; int res; (void)length; /* shut gcc up about unused length. The length is implicit with format */ #ifdef WANT_ETC_HOSTS { struct hostent* r; while ((r=gethostent_r(buf,buflen))) { if (r->h_addrtype==format && !memcmp(r->h_addr_list[0],addr,r->h_length)) { /* found it! */ memmove(result,r,sizeof(struct hostent)); *RESULT=result; *h_errnop=0; return 0; } } endhostent(); } #endif if (format==AF_INET) { tmp=tmpbuf+i2a(tmpbuf,(unsigned char)addr[3]); *tmp++='.'; tmp+=i2a(tmp,(unsigned char)addr[2]); *tmp++='.'; tmp+=i2a(tmp,(unsigned char)addr[1]); *tmp++='.'; tmp+=i2a(tmp,(unsigned char)addr[0]); strcpy(tmp,".in-addr.arpa"); } else if (format==AF_INET6) { int i; tmp=tmpbuf; for (i=15; i>=0; --i) { tmp[0]=hexdigit(addr[i]&0xf); tmp[1]='.'; tmp[2]=hexdigit((addr[i]>>4)&0xf); tmp[3]='.'; tmp+=4; } strcpy(tmp,".ip6.arpa"); } else return 1; if (buflenh_length=4; result->h_addrtype=format; } memcpy(buf,addr,result->h_length); result->h_addr_list[0]=buf; result->h_addr_list[1]=0; } return res; } dietlibc-0.33~cvs20120325/libcruft/gethostbyname.c010064400000000000000000000015721173363226500165420ustar00#include #include #include #include #include #include #include #include #include #include "dietwarning.h" static const int hostentsize=((sizeof(struct hostent)+15)&(-16)); extern size_t __dns_buflen; extern char* __dns_buf; extern void __dns_makebuf(size_t x); struct hostent* gethostbyname (const char *host) { struct hostent *hostbuf; struct hostent *hp; int res; __dns_buflen=512; do { __dns_makebuf(__dns_buflen*2); if (!__dns_buf) return 0; hostbuf=(struct hostent*)__dns_buf; } while ((res = gethostbyname_r (host, hostbuf, __dns_buf+hostentsize, __dns_buflen-hostentsize, &hp, &h_errno)) == ERANGE); if (res) hp=0; return hp; } link_warning("gethostbyname","warning: gethostbyname() leaks memory. Use gethostbyname_r instead!") dietlibc-0.33~cvs20120325/libcruft/gethostbyname2.c010064400000000000000000000016341173363226500166230ustar00#include #include #include #include #include #include #include #include #include #include "dietwarning.h" static const int hostentsize=((sizeof(struct hostent)+15)&(-16)); extern size_t __dns_buflen; extern char* __dns_buf; extern void __dns_makebuf(size_t x); struct hostent* gethostbyname2(const char *host,int AF) { struct hostent *hostbuf; struct hostent *hp; int res; int herr; __dns_buflen=512; do { __dns_makebuf(__dns_buflen*2); if (!__dns_buf) return 0; hostbuf=(struct hostent*)__dns_buf; } while ((res = gethostbyname2_r (host, AF, hostbuf, __dns_buf+hostentsize, __dns_buflen-hostentsize, &hp, &herr)) == ERANGE); if (res) hp=0; return hp; } link_warning("gethostbyname2","warning: gethostbyname2() leaks memory. Use gethostbyname2_r instead!") dietlibc-0.33~cvs20120325/libcruft/gethostbyname2_r.c010064400000000000000000000032641173363226500171450ustar00#include #include #include #include #include #include #include #include #include #include "dietfeatures.h" #include #include "dietdns.h" /* Oh boy, this interface sucks so badly, there are no words for it. * Not one, not two, but _three_ error signalling methods! (*h_errnop * nonzero? return value nonzero? *RESULT zero?) The glibc goons * really outdid themselves with this one. */ int gethostbyname2_r(const char* name, int AF, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop) { size_t L=strlen(name); int lookfor=0; switch (AF) { case AF_INET: lookfor=1; break; case AF_INET6: lookfor=28; break; default: *h_errnop=EINVAL; return 1; } result->h_name=buf; if (buflenh_name,name)) { foundsomething=1; if (r->h_addrtype==AF) { /* found it! */ found: memmove(result,r,sizeof(struct hostent)); *RESULT=result; *h_errnop=0; endhostent(); return 0; } } for (i=0; i<16; ++i) { if (r->h_aliases[i]) { if (!strcasecmp(r->h_aliases[i],name)) { foundsomething=1; if (r->h_addrtype==AF) goto found; } } else break; } } endhostent(); #ifdef WANT_HOSTS_GIVEUP_EARLY if (foundsomething) { *h_errnop=NO_DATA; return -1; } #endif } #endif strcpy(buf,name); return __dns_gethostbyx_r(name,result,buf+L,buflen-L,RESULT,h_errnop,lookfor); } dietlibc-0.33~cvs20120325/libcruft/gethostbyname_r.c010064400000000000000000000037401173363226500170620ustar00#include #include #include #include #include #include #include #include #include #include "dietfeatures.h" #include #include "dietdns.h" /* Oh boy, this interface sucks so badly, there are no words for it. * Not one, not two, but _three_ error signalling methods! (*h_errnop * nonzero? return value nonzero? *RESULT zero?) The glibc goons * really outdid themselves with this one. */ int gethostbyname_r(const char* name, struct hostent* result, char *buf, size_t buflen, struct hostent **RESULT, int *h_errnop) { size_t L=strlen(name); unsigned int offset; result->h_name=buf; L=(L+sizeof(char*))&-(sizeof(char*)); if (buflenh_addr_list=(char**)(buf+offset); result->h_addr_list[0]=(char*)&result->h_addr_list[2]; if (inet_pton(AF_INET,name,result->h_addr_list[0])) { result->h_addrtype=AF_INET; result->h_length=4; commonip: result->h_aliases=result->h_addr_list+2*sizeof(char**); result->h_aliases[0]=0; result->h_addr_list[1]=0; *RESULT=result; *h_errnop=0; return 0; } else if (inet_pton(AF_INET6,name,result->h_addr_list[0])) { result->h_addrtype=AF_INET6; result->h_length=16; goto commonip; } #endif #ifdef WANT_ETC_HOSTS { struct hostent* r; while ((r=gethostent_r(buf,buflen))) { int i; if (r->h_addrtype==AF_INET && !strcasecmp(r->h_name,name)) { /* found it! */ found: memmove(result,r,sizeof(struct hostent)); *RESULT=result; *h_errnop=0; endhostent(); return 0; } for (i=0; i<16; ++i) { if (r->h_aliases[i]) { if (!strcasecmp(r->h_aliases[i],name)) goto found; } else break; } } endhostent(); } #endif return __dns_gethostbyx_r(name,result,buf+L,buflen-L,RESULT,h_errnop,1); } dietlibc-0.33~cvs20120325/libcruft/getlogin.c010064400000000000000000000001361173363226500154740ustar00#include #include char* getlogin(void) { return getenv("LOGNAME"); } dietlibc-0.33~cvs20120325/libcruft/getopt_data.c010064400000000000000000000001651173363226500161610ustar00#include #include #include int opterr=1; int optopt; int optind=1; char *optarg; dietlibc-0.33~cvs20120325/libcruft/getopt_long.c010064400000000000000000000056221173363226500162120ustar00#include #include static void getopterror(int which) { static char error1[]="Unknown option `-x'.\n"; static char error2[]="Missing argument for `-x'.\n"; if (opterr) { if (which) { error2[23]=optopt; write(2,error2,28); } else { error1[17]=optopt; write(2,error1,22); } } } int getopt_long(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex) { static int lastidx,lastofs; char *tmp; if (optind==0) { optind=1; lastidx=0; } /* whoever started setting optind to 0 should be shot */ again: if (*optstring == '-' && optind=argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0) return -1; if (argv[optind][1]=='-' && argv[optind][2]==0) { ++optind; return -1; } if (argv[optind][1]=='-') { /* long option */ char* arg=argv[optind]+2; char* max=strchr(arg,'='); const struct option* o; const struct option* match=0; if (!max) max=arg+strlen(arg); for (o=longopts; o->name; ++o) { size_t tlen=max-arg; if (!strncmp(o->name,arg,tlen)) { /* match */ if (strlen(o->name)==tlen) { match=o; /* perfect match, not just prefix */ break; } if (!match) match=o; else /* Another imperfect match. */ match=(struct option*)-1; } } if (match!=(struct option*)-1 && (o=match)) { if (longindex) *longindex=o-longopts; if (o->has_arg>0) { if (*max=='=') optarg=max+1; else { optarg=argv[optind+1]; if (!optarg && o->has_arg==1) { /* no argument there */ if (*optstring==':') return ':'; write(2,"argument required: `",20); write(2,arg,(size_t)(max-arg)); write(2,"'.\n",3); ++optind; return '?'; } ++optind; } } ++optind; if (o->flag) *(o->flag)=o->val; else return o->val; return 0; } if (*optstring==':') return ':'; write(2,"invalid option `",16); write(2,arg,(size_t)(max-arg)); write(2,"'.\n",3); ++optind; return '?'; } if (lastidx!=optind) { lastidx=optind; lastofs=0; } optopt=argv[optind][lastofs+1]; if ((tmp=strchr(optstring,optopt))) { if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */ ++optind; goto again; } if (tmp[1]==':') { /* argument expected */ if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */ if (!*(optarg=argv[optind]+lastofs+2)) optarg=0; goto found; } optarg=argv[optind+1]; if (!optarg) { /* missing argument */ ++optind; if (*optstring==':') return ':'; getopterror(1); return ':'; } ++optind; } else { ++lastofs; return optopt; } found: ++optind; return optopt; } else { /* not found */ getopterror(0); ++optind; return '?'; } } dietlibc-0.33~cvs20120325/libcruft/getopt_long_only.c010064400000000000000000000055421173363226500172540ustar00#include #include static void getopterror(int which) { static char error1[]="Unknown option `-x'.\n"; static char error2[]="Missing argument for `-x'.\n"; if (opterr) { if (which) { error2[23]=optopt; write(2,error2,28); } else { error1[17]=optopt; write(2,error1,22); } } } int getopt_long_only(int argc, char * const argv[], const char *optstring, const struct option *longopts, int *longindex) { static int lastidx,lastofs; char *tmp,*arg; if (optind==0) { optind=1; lastidx=0; } /* whoever started setting optind to 0 should be shot */ again: if (optind>argc || !argv[optind] || *argv[optind]!='-' || argv[optind][1]==0) return -1; if (argv[optind][1]=='-' && argv[optind][2]==0) { ++optind; return -1; } if (argv[optind][1]=='-') arg=argv[optind]+2; else arg=argv[optind]+1; { char* max=strchr(arg,'='); const struct option* o; const struct option* match=0; if (!max) max=arg+strlen(arg); for (o=longopts; o->name; ++o) { size_t tlen=max-arg; if (!strncmp(o->name,arg,tlen)) { /* match */ if (strlen(o->name)==tlen) { match=o; /* perfect match, not just prefix */ break; } if (!match) match=o; else /* Another imperfect match. */ match=(struct option*)-1; } } if (match!=(struct option*)-1 && (o=match)) { if (longindex) *longindex=o-longopts; if (o->has_arg>0) { if (*max=='=') optarg=max+1; else { optarg=argv[optind+1]; if (!optarg && o->has_arg==1) { /* no argument there */ if (*optstring==':') return ':'; write(2,"argument required: `",20); write(2,arg,(size_t)(max-arg)); write(2,"'.\n",3); ++optind; return '?'; } ++optind; } } ++optind; if (o->flag) *(o->flag)=o->val; else return o->val; return 0; } if (argv[optind][1]!='-') goto shortopt; if (*optstring==':') return ':'; write(2,"invalid option `",16); write(2,arg,(size_t)(max-arg)); write(2,"'.\n",3); ++optind; return '?'; } shortopt: if (lastidx!=optind) { lastidx=optind; lastofs=0; } optopt=argv[optind][lastofs+1]; if ((tmp=strchr(optstring,optopt))) { if (*tmp==0) { /* apparently, we looked for \0, i.e. end of argument */ ++optind; goto again; } if (tmp[1]==':') { /* argument expected */ if (tmp[2]==':' || argv[optind][lastofs+2]) { /* "-foo", return "oo" as optarg */ if (!*(optarg=argv[optind]+lastofs+2)) optarg=0; goto found; } optarg=argv[optind+1]; if (!optarg) { /* missing argument */ ++optind; if (*optstring==':') return ':'; getopterror(1); return ':'; } ++optind; } else { ++lastofs; return optopt; } found: ++optind; return optopt; } else { /* not found */ getopterror(0); ++optind; return '?'; } } dietlibc-0.33~cvs20120325/libcruft/getpagesize.c010064400000000000000000000007421173363226500161760ustar00#include #include #include /* for environ: */ #include #ifndef PAGE_SIZE #define PAGE_SIZE 4096 #endif size_t __libc_getpagesize(void); size_t __libc_getpagesize(void) { long* x=(long*)environ; int fd; while (*x) ++x; ++x; /* skip envp to get to auxvec */ while (*x) { if (*x==6) return x[1]; x+=2; } return PAGE_SIZE; } size_t getpagesize(void) __attribute__((weak,alias("__libc_getpagesize"))); dietlibc-0.33~cvs20120325/libcruft/getpass.c010064400000000000000000000021061173363226500153310ustar00#include #include #include #include #include #include static inline int _tcsetattr(int fd,int optional,struct termios *termios_p) { int tmp; for (;;) { if ((tmp=tcsetattr(fd,optional,termios_p))) if (errno==EINTR) continue; break; } return tmp; } char *getpass(const char* prompt) { struct termios old,tmp; int out,in=open("/dev/tty",O_RDWR); int doclose=(in>=0); static char buf[PASS_MAX]; if (!doclose) { in=0; out=2; } else out=in; if (!tcgetattr(in,&old)) { tmp=old; tmp.c_lflag &= ~(ECHO|ISIG); _tcsetattr(in,TCSAFLUSH,&tmp); } write(out,prompt,strlen(prompt)); { int nread,ofs=0; for (;;) { nread=read(in,buf+ofs,1); if (nread<=0) { if (errno==EINTR) continue; buf[ofs]=0; break; } else if (ofs+nread>=PASS_MAX) { buf[PASS_MAX-1]=0; break; } else if (buf[ofs]=='\n') { buf[ofs+nread-1]=0; break; } ofs+=nread; } write(out,"\n",1); } _tcsetattr(in,TCSAFLUSH,&old); if (doclose) close(in); return buf; } dietlibc-0.33~cvs20120325/libcruft/getpwent.c010064400000000000000000000003361173363226500155230ustar00#include extern struct passwd __passwd_pw; extern char __passwd_buf[1000]; struct passwd *getpwent(void) { struct passwd* tmp; getpwent_r(&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getpwent_r.c010064400000000000000000000026441173363226500160500ustar00#include #include #include #include #include #include "parselib.h" static struct state __ps; void setpwent(void) { __prepare_parse(_PATH_PASSWD,&__ps); } void endpwent(void) { __end_parse(&__ps); } int getpwent_r(struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) { size_t i,j,n; unsigned long l; if (!__ps.buffirst) setpwent(); if (!__ps.buffirst) goto error; if (__ps.cur>=__ps.buflen) goto error; again: n=0; for (i=0; i<7; ++i) { j=__parse_1(&__ps,':'); if (__ps.buffirst[__ps.cur+j]!=':' && i<6) { parseerror: while (__ps.cur+j<__ps.buflen) { if (__ps.buffirst[__ps.cur+j]=='\n') { __ps.cur+=j+1; goto again; } ++j; } } switch (i) { case 0: res->pw_name=buf+n; copy: if ((size_t)buflen<=n+j) goto error; memcpy(buf+n,__ps.buffirst+__ps.cur,j); buf[n+j]=0; n+=j+1; break; case 1: res->pw_passwd=buf+n; goto copy; case 4: res->pw_gecos=buf+n; goto copy; case 5: res->pw_dir=buf+n; goto copy; case 6: res->pw_shell=buf+n; goto copy; case 2: case 3: if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror; if (i==2) res->pw_uid=l; else res->pw_gid=l; break; } __ps.cur+=j+1; } *res_sig=res; return 0; error: *res_sig=0;/* the glibc people should be taken behind the barn and shot */ return -1; } dietlibc-0.33~cvs20120325/libcruft/getpwnam.c010064400000000000000000000004031173363226500155030ustar00#include #include extern struct passwd __passwd_pw; extern char __passwd_buf[1000]; struct passwd *getpwnam(const char* name) { struct passwd *tmp; getpwnam_r(name,&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getpwnam_r.c010064400000000000000000000004731173363226500160330ustar00#include #include int getpwnam_r(const char* name, struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) { while (!getpwent_r(res,buf,buflen,res_sig)) if (!strcmp(name,res->pw_name)) goto ok; *res_sig=0; ok: endpwent(); return *res_sig?0:-1; } dietlibc-0.33~cvs20120325/libcruft/getpwuid.c010064400000000000000000000004171173363226500155160ustar00#include #include #include extern struct passwd __passwd_pw; extern char __passwd_buf[1000]; struct passwd *getpwuid(uid_t uid) { struct passwd *tmp; getpwuid_r(uid,&__passwd_pw,__passwd_buf,sizeof(__passwd_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getpwuid_r.c010064400000000000000000000004261173363226500160370ustar00#include int getpwuid_r(uid_t uid, struct passwd *res, char *buf, size_t buflen, struct passwd **res_sig) { while (!getpwent_r(res,buf,buflen,res_sig)) if (uid==res->pw_uid) goto ok; *res_sig=0; ok: endpwent(); return *res_sig?0:-1; } dietlibc-0.33~cvs20120325/libcruft/getspent.c010064400000000000000000000003331173363226500155140ustar00#include extern struct spwd __shadow_pw; extern char __shadow_buf[1000]; struct spwd *getspent(void) { struct spwd* tmp; getspent_r(&__shadow_pw,__shadow_buf,sizeof(__shadow_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getspent_r.c010064400000000000000000000027741173363226500160500ustar00#include #include #include #include #include #include "parselib.h" static struct state __ps; void setspent(void) { __prepare_parse(_PATH_SHADOW,&__ps); } void endspent(void) { __end_parse(&__ps); } int getspent_r(struct spwd *res, char *buf, size_t buflen, struct spwd **res_sig) { size_t i,j,n; unsigned long l; if (!__ps.buffirst) setspent(); if (!__ps.buffirst) goto error; if (__ps.cur>=__ps.buflen) goto error; again: n=0; for (i=0; i<9; ++i) { j=__parse_1(&__ps,':'); if (__ps.buffirst[__ps.cur+j]!=':' && i<6) { parseerror: while (__ps.cur+j<__ps.buflen) { if (__ps.buffirst[__ps.cur+j]=='\n') { __ps.cur+=j+1; goto again; } ++j; } } if (i>1) { if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror; if (j==0) l=(unsigned long)-1; } switch (i) { case 0: res->sp_namp=buf+n; copy: if ((size_t)buflen<=n+j) goto error; memcpy(buf+n,__ps.buffirst+__ps.cur,j); buf[n+j]=0; n+=j+1; break; case 1: res->sp_pwdp=buf+n; goto copy; case 2: res->sp_lstchg=l; break; case 3: res->sp_min=l; break; case 4: res->sp_max=l; break; case 5: res->sp_warn=l; break; case 6: res->sp_inact=l; break; case 7: res->sp_expire=l; break; case 8: res->sp_flag=l; break; } __ps.cur+=j+1; } *res_sig=res; return 0; error: *res_sig=0;/* the glibc people should be taken behind the barn and shot */ return -1; } dietlibc-0.33~cvs20120325/libcruft/getspnam.c010064400000000000000000000004001173363226500154740ustar00#include #include extern struct spwd __shadow_pw; extern char __shadow_buf[1000]; struct spwd *getspnam(const char* name) { struct spwd *tmp; getspnam_r(name,&__shadow_pw,__shadow_buf,sizeof(__shadow_buf),&tmp); return tmp; } dietlibc-0.33~cvs20120325/libcruft/getspnam_r.c010064400000000000000000000004721173363226500160260ustar00#include #include int getspnam_r(const char* name, struct spwd *res, char *buf, size_t buflen, struct spwd **res_sig) { while (!getspent_r(res,buf,buflen,res_sig)) if (!strcmp(name,res->sp_namp)) goto ok; *res_sig=0; ok: endspent(); return *res_sig?0:-1; } dietlibc-0.33~cvs20120325/libcruft/gettext.c010064400000000000000000000001331173363226500153450ustar00#include #undef gettext char* gettext(const char* msg) { return (char*)msg; } dietlibc-0.33~cvs20120325/libcruft/getusershell.c010064400000000000000000000012501173363226500163700ustar00#define _BSD_SOURCE #include #include #undef __attribute_dontuse__ #define __attribute_dontuse__ #include #include "parselib.h" static struct state __ps; void setusershell(void) { __prepare_parse(_PATH_SHELLS,&__ps); } void endusershell(void) { __end_parse(&__ps); } #define MAXSHELL 128 char *getusershell(void) { static char line[MAXSHELL+1]; size_t i; if (!__ps.buffirst) setusershell(); if (!__ps.buffirst) goto error; if (__ps.cur>=__ps.buflen) goto error; i=__parse_1(&__ps,'\n'); if (i>=MAXSHELL) i=MAXSHELL-1; memcpy(line,__ps.buffirst+__ps.cur,i); line[i]=0; __ps.cur+=i+1; return line; error: return 0; } dietlibc-0.33~cvs20120325/libcruft/grbuf.c010064400000000000000000000001041173363226500147640ustar00#include struct group __group_pw; char __group_buf[1000]; dietlibc-0.33~cvs20120325/libcruft/h_errno.c010064400000000000000000000000151173363226500153140ustar00int h_errno; dietlibc-0.33~cvs20120325/libcruft/herrno_location.c010064400000000000000000000003351173363226500170520ustar00#include #include #include int *__h_errno_location(void); int *__h_errno_location(void) { return &h_errno; } int *h_errno_location(void) __attribute__((weak,alias("__h_errno_location"))); dietlibc-0.33~cvs20120325/libcruft/herror.c010064400000000000000000000002231173363226500151620ustar00#include #include #include void herror(const char* s) { write(2,s,strlen(s)); write(2,": DNS error.\n",13); } dietlibc-0.33~cvs20120325/libcruft/hstrerror.c010064400000000000000000000004111173363226500157120ustar00#include const char* hstrerror(int h_errno) { switch (h_errno) { case 0: return "OK"; case NO_DATA: return "No data of requested type."; case TRY_AGAIN: return "Temporary failure."; case HOST_NOT_FOUND: default: return "Unknown host."; } } dietlibc-0.33~cvs20120325/libcruft/inet_addr.c010064400000000000000000000003501173363226500156130ustar00#include #include #include unsigned long int inet_addr(const char *cp) { struct in_addr foo; if (inet_aton(cp,&foo)) return foo.s_addr; else return (unsigned long int)-1; } dietlibc-0.33~cvs20120325/libcruft/inet_aton.c010064400000000000000000000021311173363226500156410ustar00#include #include #include #include /* inet_aton() converts the Internet host address cp from the standard * numbers-and-dots notation into binary data and stores it in the * structure that inp points to. inet_aton returns nonzero if the * address is valid, zero if not. */ /* problem is, inet_aton is historically quite, uh, lenient. * the following are all acceptable: * 0x7f000001 == 127.1 == 127.0.0.1.0 == 127.0.0.1 * btw: 127.0.0.x.y == 127.0.0.(x|y) * and: 10.1.1 == 10.1.0.1 (huh?!) * and: 10 == 0.0.0.10 (?!?!?) * The Berkeley people must have been so stoned that they are still high. */ /* I hereby disclaim that I wrote this code. */ int inet_aton(const char *cp, struct in_addr *inp) { int i; unsigned int ip=0; char *tmp=(char*)cp; for (i=24; ;) { long j; j=strtoul(tmp,&tmp,0); if (*tmp==0) { ip|=j; break; } if (*tmp=='.') { if (j>255) return 0; ip|=(j<0) i-=8; ++tmp; continue; } return 0; } inp->s_addr=htonl(ip); return 1; } dietlibc-0.33~cvs20120325/libcruft/inet_ntoa.c010064400000000000000000000002441173363226500156440ustar00#include #include #include char *inet_ntoa(struct in_addr in) { static char buf[20]; return inet_ntoa_r(in,buf); } dietlibc-0.33~cvs20120325/libcruft/inet_ntoa_r.c010064400000000000000000000012071173363226500161650ustar00#include #include #include static unsigned int i2a(char* dest,unsigned int x) { register unsigned int tmp=x; register unsigned int len=0; if (x>=100) { *dest++=tmp/100+'0'; tmp=tmp%100; ++len; } if (x>=10) { *dest++=tmp/10+'0'; tmp=tmp%10; ++len; } *dest++=tmp+'0'; return len+1; } char *inet_ntoa_r(struct in_addr in,char* buf) { unsigned int len; unsigned char *ip=(unsigned char*)∈ len=i2a(buf,ip[0]); buf[len]='.'; ++len; len+=i2a(buf+ len,ip[1]); buf[len]='.'; ++len; len+=i2a(buf+ len,ip[2]); buf[len]='.'; ++len; len+=i2a(buf+ len,ip[3]); buf[len]=0; return buf; } dietlibc-0.33~cvs20120325/libcruft/inet_ntop.c010064400000000000000000000033051173363226500156640ustar00#include #include #include static const unsigned char V4mappedprefix[12]={0,0,0,0,0,0,0,0,0,0,0xff,0xff}; static char tohex(char hexdigit) { return hexdigit>9?hexdigit+'a'-10:hexdigit+'0'; } static int fmt_xlong(char* s,unsigned int i) { char* bak=s; *s=tohex((i>>12)&0xf); if (s!=bak || *s!='0') ++s; *s=tohex((i>>8)&0xf); if (s!=bak || *s!='0') ++s; *s=tohex((i>>4)&0xf); if (s!=bak || *s!='0') ++s; *s=tohex(i&0xf); return s-bak+1; } static unsigned int fmt_ip6(char *s,const char ip[16]) { unsigned int len; unsigned int i; unsigned int temp; unsigned int compressing; unsigned int compressed; int j; len = 0; compressing = 0; compressed = 0; for (j=0; j<16; j+=2) { if (j==12 && !memcmp(ip,V4mappedprefix,12)) { inet_ntoa_r(*(struct in_addr*)(ip+12),s); temp=strlen(s); return len+temp; } temp = ((unsigned long) (unsigned char) ip[j] << 8) + (unsigned long) (unsigned char) ip[j+1]; if (temp == 0 && !compressed) { if (!compressing) { compressing=1; if (j==0) { *s++=':'; ++len; } } } else { if (compressing) { compressing=0; compressed=1; *s++=':'; ++len; } i = fmt_xlong(s,temp); len += i; s += i; if (j<14) { *s++ = ':'; ++len; } } } if (compressing) { *s++=':'; ++len; } *s=0; return len; } const char* inet_ntop(int AF, const void *CP, char *BUF, size_t LEN) { char buf[100]; size_t len; if (AF==AF_INET) { inet_ntoa_r(*(struct in_addr*)CP,buf); len=strlen(buf); } else if (AF==AF_INET6) { len=fmt_ip6(buf,CP); } else return 0; if (len #include #include #include #include #include "dietfeatures.h" static unsigned int scan_ip6(const char *s,char ip[16]) { unsigned int i; unsigned int len=0; unsigned long u; char suffix[16]; unsigned int prefixlen=0; unsigned int suffixlen=0; for (i=0; i<16; i++) ip[i]=0; for (;;) { if (*s == ':') { len++; if (s[1] == ':') { /* Found "::", skip to part 2 */ s+=2; len++; break; } s++; } { char *tmp; u=strtoul(s,&tmp,16); i=tmp-s; } if (!i) return 0; if (prefixlen==12 && s[i]=='.') { /* the last 4 bytes may be written as IPv4 address */ if (inet_aton(s,(struct in_addr*)(ip+12))) return i+len; else return 0; } ip[prefixlen++] = (u >> 8); ip[prefixlen++] = (u & 255); s += i; len += i; if (prefixlen==16) return len; } /* part 2, after "::" */ for (;;) { if (*s == ':') { if (suffixlen==0) break; s++; len++; } else if (suffixlen!=0) break; { char *tmp; u=strtol(s,&tmp,16); i=tmp-s; } if (!i) { if (*s) len--; break; } if (suffixlen+prefixlen<=12 && s[i]=='.') { if (inet_aton(s,(struct in_addr*)(suffix+suffixlen))) { suffixlen+=4; len+=strlen(s); break; } else prefixlen=12-suffixlen; /* make end-of-loop test true */ } suffix[suffixlen++] = (u >> 8); suffix[suffixlen++] = (u & 255); s += i; len += i; if (prefixlen+suffixlen==16) break; } for (i=0; i #include #include #include static int _getgrouplist(const char*user,gid_t group,gid_t*groups,int*ngroups) { long n=0,size=*ngroups; struct group*g; int ret=0; if (0gr_gid==group) continue; duh=g->gr_mem; while (*duh) { if (!strcmp(*duh,user)) { if (n>=size) { ret=~ret; goto err_out; } groups[n++]=g->gr_gid; break; } duh++; } } err_out: endgrent(); *ngroups=n; return ret; } int getgrouplist(const char*user,gid_t group,gid_t*groups,int*ngroups) __attribute__((alias("_getgrouplist"))); int initgroups(const char*user,gid_t group) { int n=NGROUPS_MAX; gid_t grouplist[NGROUPS_MAX]; _getgrouplist(user,group,grouplist,&n); return setgroups(n,grouplist); } dietlibc-0.33~cvs20120325/libcruft/killpg.c010064400000000000000000000001311173363226500151410ustar00#include int killpg(pid_t pgrp, int signal) { return kill(-pgrp,signal); } dietlibc-0.33~cvs20120325/libcruft/localeconv.c010064400000000000000000000006421173363226500160130ustar00#include #include /* these answers are what glibc says */ static struct lconv l = {".","","","","","", /* decimal_point - mon_decimal_point */ "","","","",127,127, /* mon_thousands_sep - frac_digits */ 127,127,127,127,127,127, /* p_cs_precedes - n_sign_posn */ 127,127,127,127,127,127 }; /* __int_p_cs_precedes - __int_n_sign_posn */ struct lconv* localeconv() { return &l; } dietlibc-0.33~cvs20120325/libcruft/mkdtemp.c010064400000000000000000000013101173363226500153200ustar00#include #include #include #include #include #include "dietfeatures.h" char* mkdtemp(char* template) { char *tmp=template+strlen(template)-6; int randfd,i; unsigned int random; if (tmp>(i*5))&0x1f; tmp[i]=hexdigit>9?hexdigit+'a'-10:hexdigit+'0'; } if (mkdir(template,0700)==0) break; if (errno==EEXIST) continue; close(randfd); return 0; } close(randfd); return template; } dietlibc-0.33~cvs20120325/libcruft/mkstemp.c010064400000000000000000000013711173363226500153460ustar00#include #include #include #include #include #include "dietfeatures.h" #ifndef O_NOFOLLOW #define O_NOFOLLOW 0 #endif int mkstemp(char* template) { char *tmp=template+strlen(template)-6; int randfd; int i,res; unsigned int random; if (tmp>(i*5))&0x1f; tmp[i]=hexdigit>9?hexdigit+'a'-10:hexdigit+'0'; } res=open(template,O_CREAT|O_RDWR|O_EXCL|O_NOFOLLOW,0600); if (res>=0 || errno!=EEXIST) break; } close(randfd); return res; } dietlibc-0.33~cvs20120325/libcruft/mktemp.c010064400000000000000000000005271173363226500151650ustar00#include #include #include #include #include #include link_warning("mktemp","\e[1;33;41m>>> mktemp stinks! DON'T USE IT ! <<<\e[0m"); char* mktemp(char* template) { int fd; if ((fd=mkstemp(template))<0) return 0; close(fd); unlink(template); return template; } dietlibc-0.33~cvs20120325/libcruft/ngettext.c010064400000000000000000000002471173363226500155310ustar00#include #undef ngettext char* ngettext (const char* msgid, const char* msgid_plural, unsigned long int n) { return (char*)(n==1?msgid:msgid_plural); } dietlibc-0.33~cvs20120325/libcruft/nl_langinfo.c010064400000000000000000000031441173363226500161540ustar00#include #include static inline char* get_codeset(void) { /* this is normally only used to look for "UTF-8" */ char* s=getenv("LC_CTYPE"); if (!s) s=getenv("LC_ALL"); if (!s) s="ANSI_X3.4-1968"; /* it's what glibc does */ return s; } static const char sweekdays [7] [4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; static const char weekdays [7] [10] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; static const char smonths [12] [4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static const char* months [12] = { "January", "February", "March", "April", smonths[5-1], "June", "July", "August", "September", "October", "November", "December" }; char* nl_langinfo(nl_item x) { if (x>=DAY_1 && x<=DAY_7) return (char*)weekdays[x-DAY_1]; if (x>=ABDAY_1 && x<=ABDAY_7) return (char*)sweekdays[x-ABDAY_1]; if (x>=MON_1 && x<=MON_12) return (char*)months[x-MON_1]; if (x>=ABMON_1 && x<=ABMON_12) return (char*)smonths[x-ABMON_1]; switch (x) { case CODESET: return get_codeset(); case D_T_FMT: return "%b %a %d %k:%M:%S %Z %Y"; case D_FMT: return "%b %a %d"; case T_FMT: return "%H:%M"; case T_FMT_AMPM: return "%I:%M:%S %p"; case AM_STR: return "am"; case PM_STR: return "pm"; case ERA: return 0; case ERA_D_FMT: case ERA_D_T_FMT: case ERA_T_FMT: case ALT_DIGITS: return ""; case RADIXCHAR: return "."; case THOUSEP: return ""; case YESEXPR: return "^[yY]"; case NOEXPR: return "^[nN]"; case CRNCYSTR: return "$"; default: return 0; } } dietlibc-0.33~cvs20120325/libcruft/pwbuf.c010064400000000000000000000001071173363226500150050ustar00#include struct passwd __passwd_pw; char __passwd_buf[1000]; dietlibc-0.33~cvs20120325/libcruft/res_close.c010064400000000000000000000004571173363226500156500ustar00#include #include #include "dietfeatures.h" extern int __dns_fd; #ifdef WANT_IPV6_DNS extern int __dns_fd6; #endif void res_close(void) { if (__dns_fd!=-1) { close(__dns_fd); __dns_fd=-1; } #ifdef WANT_IPV6_DNS if (__dns_fd6!=-1) { close(__dns_fd6); __dns_fd6=-1; } #endif } dietlibc-0.33~cvs20120325/libcruft/res_init.c010064400000000000000000000002151173363226500154760ustar00#include extern void __dns_readstartfiles(void); int res_init(void) { _res.nscount=0; __dns_readstartfiles(); return 0; } dietlibc-0.33~cvs20120325/libcruft/res_mkquery.c010064400000000000000000000043511173363226500162350ustar00#include #include #include #include #include #include #include #include #include #include #include #include "dietfeatures.h" static char dnspacket[]="\xfe\xfe\001\000\000\001\000\000\000\000\000\000"; /* 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ID | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ |QR| Opcode |AA|TC|RD|RA| Z | RCODE | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | QDCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ANCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | NSCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | ARCOUNT | +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ */ extern void __dns_make_fd(void); extern int __dns_fd; extern int __dns_servers; extern struct sockaddr __dns_server_ips[]; extern void __dns_readstartfiles(void); int res_mkquery(int op, const char *dname, int class, int type, char* data, int datalen, const unsigned char* newrr, char* buf, int buflen) { unsigned char packet[512]; unsigned long len; memcpy(packet,dnspacket,12); len=rand(); packet[0]=len; packet[1]=len>>8; len=0; if ((_res.options&RES_RECURSE)==0) packet[2]=0; { unsigned char* x; const char* y,* tmp; x=packet+12; y=dname; while (*y) { while (*y=='.') ++y; for (tmp=y; *tmp && *tmp!='.'; ++tmp) ; if (tmp-y > 63) return -1; *x=tmp-y; if (!(tmp-y)) break; if ((len+=*x+1) > 254) return -1; ++x; // if (x>=packet+510-(tmp-y)) { return -1; } memmove(x,y,tmp-y); x+=tmp-y; if (!*tmp) { *x=0; break; } y=tmp; } *++x= 0; *++x= type; /* A */ *++x= 0; *++x= class; /* IN */ ++x; if (x-packet>buflen) return -1; memmove(buf,packet,x-packet); return x-packet; } } dietlibc-0.33~cvs20120325/libcruft/res_query.c010064400000000000000000000156621173363226500157140ustar00#include #include #include #include #include #include #include #include #include #include #include #include #include #include "dietfeatures.h" extern void __dns_make_fd(void); extern int __dns_fd; #ifdef WANT_IPV6_DNS extern void __dns_make_fd6(void); extern int __dns_fd6; #endif extern void __dns_readstartfiles(void); #ifdef WANT_PLUGPLAY_DNS int __dns_plugplay_interface; #endif int res_query(const char *dname, int class, int type, unsigned char *answer, int anslen) { unsigned char packet[512]; int size; struct pollfd duh[2]; #ifndef WANT_IPV6_DNS __dns_make_fd(); #endif __dns_readstartfiles(); if ((size=res_mkquery(QUERY,dname,class,type,0,0,0,(char*)packet,512))<0) { h_errno=NO_RECOVERY; return -1; } { { int i; /* current server */ int j; /* timeout count down */ struct timeval last,now; #ifdef WANT_PLUGPLAY_DNS struct timeval first; static int pnpfd=-1; #ifdef WANT_IPV6_DNS static struct sockaddr_in6 pnpsa6; #endif static struct sockaddr_in pnpsa4; static int v4pnp=0; int islocal=0; gettimeofday(&first,0); { char* x=strchr(dname,'.'); if (x) { if (!memcmp(x,".local",6)) if (x[6]==0 || (x[6]=='.' && x[7]==0)) islocal=1; } else islocal=1; } if (islocal) { if (pnpfd<0) { pnpfd=socket(PF_INET6,SOCK_DGRAM,IPPROTO_UDP); if (pnpfd==-1 && errno==EAFNOSUPPORT) { pnpfd=socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP); v4pnp=1; } if (pnpfd>=0) { int one=1; fcntl(pnpfd,F_SETFD,FD_CLOEXEC); if (!v4pnp) setsockopt(pnpfd,IPPROTO_IPV6,IPV6_HOPLIMIT,&one,sizeof one); setsockopt(pnpfd,SOL_IP,IP_RECVTTL,&one,sizeof one); setsockopt(pnpfd,SOL_IP,IP_PKTINFO,&one,sizeof one); } } #ifdef WANT_IPV6_DNS if (!v4pnp) { memset(&pnpsa6,0,sizeof(pnpsa6)); pnpsa6.sin6_family=AF_INET6; if (pnpfd!=-1) bind(pnpfd,(struct sockaddr*)&pnpsa6,sizeof(pnpsa6)); pnpsa6.sin6_port=htons(5353); memcpy(&pnpsa6.sin6_addr,"\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfb",16); } #endif memset(&pnpsa4,0,sizeof(pnpsa4)); pnpsa4.sin_family=AF_INET; if (pnpfd!=-1) bind(pnpfd,(struct sockaddr*)&pnpsa4,sizeof(pnpsa4)); pnpsa4.sin_port=htons(5353); memcpy(&pnpsa4.sin_addr,"\xe0\x00\x00\xfb",4); /* 224.0.0.251 */ duh[1].events=POLLIN; duh[1].fd=pnpfd; } else { duh[1].fd=-1; duh[1].events=0; } #endif i=0; duh[0].events=POLLIN; duh[0].fd=0; last.tv_sec=0; #ifdef WANT_PLUGPLAY_DNS if (duh[1].fd!=-1) { packet[2]=0; packet[size-2]=0x80; sendto(pnpfd,packet,size,0,(struct sockaddr*)(&pnpsa4),sizeof(pnpsa4)); if (!v4pnp) sendto(pnpfd,packet,size,0,(struct sockaddr*)(&pnpsa6),sizeof(pnpsa6)); packet[size-2]=0; #ifdef WANT_LLMNR pnpsa4.sin_port=htons(5355); memcpy(&pnpsa4.sin_addr,"\xe0\x00\x00\xfc",4); /* 224.0.0.252 */ pnpsa6.sin6_port=htons(5355); memcpy(&pnpsa6.sin6_addr,"\xff\x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x03",16); sendto(pnpfd,packet,size,0,(struct sockaddr*)(&pnpsa4),sizeof(pnpsa4)); if (!v4pnp) sendto(pnpfd,packet,size,0,(struct sockaddr*)(&pnpsa6),sizeof(pnpsa6)); #endif packet[2]=1; } /* if it doesn't work, we don't care */ #endif for (j=20; j>0; --j) { gettimeofday(&now,0); if (now.tv_sec-last.tv_sec>10) { #ifdef WANT_IPV6_DNS int tmpfd; struct sockaddr* s=(struct sockaddr*)&(_res.nsaddr_list[i]); if (s->sa_family==AF_INET6) { __dns_make_fd6(); tmpfd=__dns_fd6; } else { __dns_make_fd(); tmpfd=__dns_fd; } #ifdef WANT_PLUGPLAY_DNS if (duh[0].fd!=-1) { #endif duh[0].fd=tmpfd; if (sendto(tmpfd,packet,size,0,s,sizeof(struct sockaddr_in6))!=-1) gettimeofday(&last,0); else goto nxdomain; #ifdef WANT_PLUGPLAY_DNS } #endif #else duh[0].fd=__dns_fd; if (sendto(__dns_fd,packet,size,0,(struct sockaddr*)&(_res.nsaddr_list[i]),sizeof(struct sockaddr))==0) gettimeofday(&last,0); #endif last=now; } if (++i >= _res.nscount) i=0; #ifdef WANT_PLUGPLAY_DNS if (now.tv_sec>first.tv_sec && duh[0].fd==-1) goto nxdomain; if (duh[0].fd==-1 && duh[1].fd==-1) goto nxdomain; duh[0].revents=0; if (poll(duh[0].fd==-1?duh+1:duh,duh[0].fd==-1?1:2,1000) > 0) { #else if (poll(duh,1,1000) == 1) { #endif /* read and parse answer */ unsigned char inpkg[1500]; #ifdef WANT_PLUGPLAY_DNS int len; struct msghdr mh; struct iovec iv; char abuf[100]; /* for ancillary data */ struct cmsghdr* x; int ttl=0; int fd; struct sockaddr_in6 tmpsa; mh.msg_name=&tmpsa; mh.msg_namelen=sizeof(tmpsa); mh.msg_iov=&iv; mh.msg_iovlen=1; iv.iov_base=inpkg; iv.iov_len=sizeof(inpkg); mh.msg_control=abuf; mh.msg_controllen=sizeof(abuf); __dns_plugplay_interface=0; len=recvmsg(fd=(duh[0].revents&POLLIN?duh[0].fd:duh[1].fd),&mh,MSG_DONTWAIT); if (fd==duh[1].fd) { unsigned short peerport; if (tmpsa.sin6_family==AF_INET6) { __dns_plugplay_interface=tmpsa.sin6_scope_id; peerport=tmpsa.sin6_port; } else { peerport=((struct sockaddr_in*)&tmpsa)->sin_port; } for (x=CMSG_FIRSTHDR(&mh); x; x=CMSG_NXTHDR(&mh,x)) if ((x->cmsg_level==SOL_IP && x->cmsg_type==IP_TTL) || (x->cmsg_level==IPPROTO_IPV6 && x->cmsg_type==IPV6_HOPLIMIT)) { ttl=*(int*)CMSG_DATA(x); break; } else if ((x->cmsg_level==SOL_IP && x->cmsg_type==IP_PKTINFO)) __dns_plugplay_interface=((struct in_pktinfo*)(CMSG_DATA(x)))->ipi_ifindex; #ifdef WANT_LLMNR if ((peerport==5353 && ttl != 255) || (peerport==5355 && ttl != 1)) #else if (ttl != 255) #endif /* as per standard, discard packets with TTL!=255 */ continue; /* work around stupid avahi bug */ inpkg[2]=(inpkg[2]&~0x1) | (packet[2]&0x1); } #else int len=read(duh[0].fd,inpkg,sizeof(inpkg)); #endif /* header, question, answer, authority, additional */ if (inpkg[0]!=packet[0] || inpkg[1]!=packet[1]) continue; /* wrong ID */ if ((inpkg[2]&0xf9) != (_res.options&RES_RECURSE?0x81:0x80)) continue; /* not answer */ if ((inpkg[3]&0x0f) != 0) { #ifdef WANT_PLUGPLAY_DNS /* if the normal DNS server says NXDOMAIN, still give the multicast method some time */ if (duh[0].revents&POLLIN) { duh[0].fd=-1; if (duh[1].fd!=-1) { if (j>10) j=10; continue; } } else continue; /* ignore NXDOMAIN from the multicast socket */ #endif nxdomain: h_errno=HOST_NOT_FOUND; return -1; } /* error */ if (len>anslen) { h_errno=NO_RECOVERY; return -1; } memcpy(answer,inpkg,len); return len; } /*kaputt:*/ } } #ifdef WANT_PLUGPLAY_DNS if (duh[1].fd==-1) goto nxdomain; #endif } h_errno=TRY_AGAIN; return -1; } #ifndef WANT_FULL_RESOLV_CONF int res_search(const char *dname, int class, int type, unsigned char *answer, int anslen) __attribute__((alias("res_query"))); #endif dietlibc-0.33~cvs20120325/libcruft/res_search.c010064400000000000000000000017201173363226500160020ustar00 #include #include #include #include #include #include #include #include #include #include #include #include "dietfeatures.h" #ifdef WANT_FULL_RESOLV_CONF extern int __dns_search; extern char *__dns_domains[]; int res_search(const char *dname, int class, int type, unsigned char *answer, int anslen) { const char *tmp=dname; char Buf[MAXDNAME+1]; int res; int len=strlen(dname); int count=0; memmove(Buf,dname,len); Buf[len]=Buf[MAXDNAME]=0; // printf("appending %d: %p\n",count,__dns_domains[count]); while ((res=res_query(tmp,class,type,answer,anslen))<0) { if (count==__dns_search) break; Buf[len]='.'; // printf("appending %d: %p (%s)\n",count,__dns_domains[count],__dns_domains[count]); memccpy(Buf+len+1,__dns_domains[count],0,MAXDNAME-len-1); tmp=Buf; ++count; } return res; } #endif dietlibc-0.33~cvs20120325/libcruft/scan_ulong.c010064400000000000000000000003751173363226500160210ustar00#include #include #include "parselib.h" size_t scan_ulong(const char* s,unsigned long* l) { size_t n; unsigned long x; unsigned int digit; for (x=n=0; (digit=(s[n]-'0'))<10u; ++n) x=x*10+digit; *l=x; return n; } dietlibc-0.33~cvs20120325/libcruft/scandir.c010064400000000000000000000025101173363226500153050ustar00#include #include #include int scandir(const char *dir, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) { DIR* d; struct dirent *D; int num=0; if (!(d=opendir(dir))) return -1; *namelist=0; while ((D=readdir(d))) { if (select==0 || select(D)) { struct dirent **tmp; /* printf("realloc %p,%d -> ",*namelist,num*sizeof(struct dirent**)); */ if (!(tmp=realloc(*namelist,(num+1)*sizeof(struct dirent**))) || !(tmp[num]=malloc(sizeof(struct dirent)))) { int i; for (i=0; id_name,D->d_name,0,NAME_MAX); tmp[num]->d_off=D->d_off; tmp[num]->d_reclen=D->d_reclen; ++num; *namelist=tmp; /* printf("%p; tmp[num-1(%d)]=%p\n",*namelist,num-1,tmp[num-1]); */ } } closedir(d); #if 0 { int i; puts("pre-qsort:\n"); for (i=0; id_name); } puts("post-qsort:\n"); } #endif // qsort(&(*namelist)[0],num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar)); if (compar) qsort(*namelist,num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar)); return num; } dietlibc-0.33~cvs20120325/libcruft/scandir64.c010064400000000000000000000026001173363226500154570ustar00#include #include #include int scandir64(const char *dir, struct dirent64 ***namelist, int (*select)(const struct dirent64 *), int (*compar)(const struct dirent64 **, const struct dirent64 **)) { DIR* d; struct dirent64 *D; int num=0; if (!(d=opendir(dir))) return -1; *namelist=0; while ((D=readdir64(d))) { if (select==0 || select(D)) { struct dirent64 **tmp; ++num; /* printf("realloc %p,%d -> ",*namelist,num*sizeof(struct dirent**)); */ if (!(tmp=realloc(*namelist,num*sizeof(struct dirent64**))) || !(tmp[num-1]=malloc(sizeof(struct dirent64)))) { int i; for (i=0; id_name,D->d_name,0,NAME_MAX); tmp[num-1]->d_off=D->d_off; tmp[num-1]->d_reclen=D->d_reclen; tmp[num-1]->d_type=D->d_type; *namelist=tmp; /* printf("%p; tmp[num-1(%d)]=%p\n",*namelist,num-1,tmp[num-1]); */ } } closedir(d); #if 0 { int i; puts("pre-qsort:\n"); for (i=0; id_name); } puts("post-qsort:\n"); } #endif // qsort(&(*namelist)[0],num,sizeof(struct dirent*),(int (*)(const void*,const void*))(compar)); if (compar) qsort(*namelist,num,sizeof(struct dirent64*),(int (*)(const void*,const void*))(compar)); return num; } dietlibc-0.33~cvs20120325/libcruft/setegid.c010064400000000000000000000003731173363226500153130ustar00#include #include #include "dietwarning.h" #undef setegid int setegid(gid_t gid); int setegid(gid_t gid) { return setregid((gid_t)-1,gid); } link_warning("setegid","warning: you used setegid without including ") dietlibc-0.33~cvs20120325/libcruft/seteuid.c010064400000000000000000000003731173363226500153310ustar00#include #include #include "dietwarning.h" #undef seteuid int seteuid(uid_t uid); int seteuid(uid_t uid) { return setreuid((uid_t)-1,uid); } link_warning("setegid","warning: you used setegid without including ") dietlibc-0.33~cvs20120325/libcruft/setlocale.c010064400000000000000000000010201173363226500156300ustar00#include #include #include #include "dietlocale.h" char *setlocale (int category, const char *locale) { lc_ctype=CT_8BIT; if (locale && (category==LC_ALL || category==LC_CTYPE)) { if (!*locale) { const char* x; x=getenv("LC_CTYPE"); if (!x) x=getenv("LC_ALL"); if (!x) x="C"; locale=x; } } if (locale) { if (strstr(locale,".UTF-8") || strstr(locale,".UTF8")) lc_ctype=CT_UTF8; if (locale[0]!='C' || locale[1]) return 0; } return "C"; } dietlibc-0.33~cvs20120325/libcruft/spbuf.c010064400000000000000000000001101173363226500147730ustar00#include struct spwd __shadow_pw; char __shadow_buf[1000]; dietlibc-0.33~cvs20120325/libcruft/strerror_r.c010064400000000000000000000003761173363226500160750ustar00#include extern const char __sys_err_unknown[]; int strerror_r(int errnum, char *buf, size_t n) { const char* x=strerror(errnum); if (x==__sys_err_unknown || n<1) return -1; strncpy(buf,strerror(errnum),n); buf[n-1]=0; return 0; } dietlibc-0.33~cvs20120325/libcruft/sysconf.c010064400000000000000000000024371173363226500153560ustar00#include #include #include #include #include #define _GNU_SOURCE #include extern int __sc_nr_cpus(); static long physpages() { int fd=open("/proc/meminfo",O_RDONLY); char buf[2048]; size_t l; if (fd==-1) { errno=ENOSYS; return -1; } l=read(fd,buf,sizeof(buf)); if (l!=(size_t)-1) { char* c; buf[l]=0; c=strstr(buf,"\nMemTotal:"); if (c) { c+=10; while (*c==' ' || *c=='\t') ++c; l=0; while (*c>='0' && *c<='9') { l=l*10+*c-'0'; ++c; } } } close(fd); return l*1024; } long sysconf(int name) { switch(name) { case _SC_OPEN_MAX: { struct rlimit limit; getrlimit(RLIMIT_NOFILE, &limit); return limit.rlim_cur; } case _SC_CLK_TCK: #ifdef __alpha__ return 1024; #else return 100; #endif case _SC_PAGESIZE: #if ( defined(__alpha__) || defined(__sparc__) ) return 8192; #else return 4096; #endif case _SC_PHYS_PAGES: return physpages(); case _SC_ARG_MAX: return ARG_MAX; case _SC_NGROUPS_MAX: return NGROUPS_MAX; case _SC_NPROCESSORS_ONLN: { cpu_set_t m; if (sched_getaffinity(0, sizeof(m), &m)) return __sc_nr_cpus(); return CPU_COUNT(&m); } } errno=ENOSYS; return -1; } dietlibc-0.33~cvs20120325/libcruft/sysconf_cpus.c010064400000000000000000000023111173363226500163770ustar00#include #include #include #include #include #include "dietfeatures.h" /* * by Olaf Dreesen * * arm NO SMP ?!? (return 1) * * alpha -> cpus detected\t\t: \n * sparc -> ncpus active\t: \n * * default -> processor\t: \n (one per cpu) */ #ifdef SLASH_PROC_OK int __sc_nr_cpus(void); int __sc_nr_cpus() { #if defined(__arm__) return 1; #else int fd; fd = open("/proc/cpuinfo", O_RDONLY); if (fd==-1) return 1; /* fallback if no proc-fs mounted */ else { int n,nr=0; char buf[2048]; /* holds ~6 cpuinfos */ while((n=read(fd,buf,sizeof(buf)))>0) { register int i=0; while (i #include #include #include #include #include #include link_warning("tempnam","\e[1;33;41m>>> tempnam stinks! NEVER ! NEVER USE IT ! <<<\e[0m"); char* tempnam(char* dir,char* template) { char buf[1024]; int len=sizeof(buf)-1,fd; buf[len]=0; if ((dir)&&(*dir)) { memccpy(buf,dir,0,len); strncat(buf,"/",1); } else strncpy(buf,"/tmp/",len); len=(sizeof(buf)-1)-strlen(buf); if (len<1) return 0; if (template) strncat(buf,template, --len); else strncat(buf,"temp_", --len); len=(sizeof(buf)-1)-strlen(buf); strncat(buf,"XXXXXX",len); if ((fd=mkstemp(buf))<0) return 0; close(fd); unlink(buf); return strdup(buf); } dietlibc-0.33~cvs20120325/libcruft/textdomain.c010064400000000000000000000003151173363226500160370ustar00#include #include #include static char* dom; char* textdomain(const char* domainname) { if (dom) free(dom); if (!(dom=strdup(domainname))) return 0; return dom; } dietlibc-0.33~cvs20120325/libcruft/tmpnam.c010064400000000000000000000012041173363226500151550ustar00#include #include #include #include "dietfeatures.h" #include #include #include #include #include link_warning("tmpnam","\e[1;33;41m>>> tmpnam stinks! NEVER ! NEVER USE IT ! <<<\e[0m"); char* tmpnam(char* s) { static char buf[100]; char *tmp; if (s) tmp=s; else tmp=buf; strcpy(tmp,"/tmp/temp_"); for (;;) { struct stat s; int i,j; i=rand(); for (j=0; j<8; ++j) { char c=i&0xf; tmp[9+j]=c>9?c+'a'-10:c+'0'; i>>=4; } tmp[17]=0; if (lstat(tmp,&s)==-1 && errno==ENOENT) break; } return tmp; } dietlibc-0.33~cvs20120325/libcrypt/crypt.c010064400000000000000000000176131173363226500150530ustar00#include "dietfeatures.h" #include #include /* Initial permutation, */ static const char IP[] = { 57,49,41,33,25,17, 9, 1, 59,51,43,35,27,19,11, 3, 61,53,45,37,29,21,13, 5, 63,55,47,39,31,23,15, 7, 56,48,40,32,24,16, 8, 0, 58,50,42,34,26,18,10, 2, 60,52,44,36,28,20,12, 4, 62,54,46,38,30,22,14, 6 }; /* Final permutation, FP = IP^(-1) */ static const char FP[] = { 39, 7,47,15,55,23,63,31, 38, 6,46,14,54,22,62,30, 37, 5,45,13,53,21,61,29, 36, 4,44,12,52,20,60,28, 35, 3,43,11,51,19,59,27, 34, 2,42,10,50,18,58,26, 33, 1,41, 9,49,17,57,25, 32, 0,40, 8,48,16,56,24 }; /* Permuted-choice 1 from the key bits to yield C and D. * Note that bits 8,16... are left out: They are intended for a parity check. */ static const char PC1_C[] = { 56,48,40,32,24,16, 8, 0,57,49,41,33,25,17, 9, 1,58,50,42,34,26, 18,10, 2,59,51,43,35 }; static const char PC1_D[] = { 62,54,46,38,30,22,14, 6,61,53,45,37,29,21, 13, 5,60,52,44,36,28, 20,12, 4,27,19,11, 3 }; /* Sequence of shifts used for the key schedule. */ static const char shifts[] = { 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1 }; /* * Permuted-choice 2, to pick out the bits from the CD array that generate * the key schedule. */ static const char PC2_C[] = { 13, 16, 10, 23, 0, 4, 2, 27, 14, 5, 20, 9, 22, 18, 11, 3, 25, 7, 15, 6, 26, 19, 12, 1 }; static const char PC2_D[] = { 12, 23, 2, 8, 18, 26, 1, 11, 22, 16, 4, 19, 15, 20, 10, 27, 5, 24, 17, 13, 21, 7, 0, 3 }; /* The C and D arrays used to calculate the key schedule. */ static char C[28]; static char D[28]; /* The key schedule. Generated from the key. */ static char KS[16][48]; /* The E bit-selection table. */ static char E[48]; static const char e2[] = { 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9, 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17, 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25, 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1 }; /* Set up the key schedule from the key. */ void setkey(const char *key) { register int i, j, k; int t; int s; /* First, generate C and D by permuting the key. The low order bit of each * 8-bit char is not used, so C and D are only 28 bits apiece. */ for(i=0; i < 28; i++) { C[i] = key[(int)PC1_C[i]]; D[i] = key[(int)PC1_D[i]]; } /* To generate Ki, rotate C and D according to schedule and pick up a * permutation using PC2. */ for(i=0; i < 16; i++) { /* rotate. */ s = shifts[i]; for(k=0; k < s; k++) { t = C[0]; for(j=0; j < 27; j++) C[j] = C[j+1]; C[27] = t; t = D[0]; for(j=0; j < 27; j++) D[j] = D[j+1]; D[27] = t; } /* get Ki. Note C and D are concatenated. */ for(j=0; j < 24; j++) { KS[i][j] = C[(int)PC2_C[j]]; KS[i][j+24] = D[(int)PC2_D[j]]; } } for(i=0; i < 48; i++) E[i] = e2[i]; } /* The 8 selection functions. For some reason, they give a 0-origin index, * unlike everything else. */ static const char S[8][64] = { { 14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8, 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0, 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13 }, { 15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5, 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15, 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9 }, { 10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, 13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1, 13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7, 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12 }, { 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, 13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9, 10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4, 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14 }, { 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, 14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6, 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14, 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3 }, { 12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, 10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8, 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6, 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13 }, { 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, 13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6, 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2, 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12 }, { 13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2, 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8, 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11 } }; /* P is a permutation on the selected combination of the current L and key. */ static const char P[] = { 15, 6,19,20, 28,11,27,16, 0,14,22,25, 4,17,30, 9, 1, 7,23,13, 31,26, 2, 8, 18,12,29, 5, 21,10, 3,24 }; /* The current block, divided into 2 halves. */ static char L[64]; #define R (L+32) static char tempL[32]; static char f[32]; /* The combination of the key and the input, before selection. */ static char preS[48]; /* The payoff: encrypt a block. */ void encrypt(char block[64],int edflag) { int i, ii; register int t, j, k; (void)edflag; /* First, permute the bits in the input */ for(j=0; j < 64; j++) L[j] = block[(int)IP[j]]; /* Perform an encryption operation 16 times. */ for(ii=0; ii < 16; ii++) { i = ii; /* Save the R array, which will be the new L. */ for(j=0; j < 32; j++) tempL[j] = R[j]; /* Expand R to 48 bits using the E selector; * exclusive-or with the current key bits. */ for(j=0; j < 48; j++) preS[j] = R[E[j]-1] ^ KS[i][j]; /* The pre-select bits are now considered in 8 groups of 6 bits each. * The 8 selection functions map these 6-bit quantities into 4-bit * quantities and the results permuted to make an f(R, K). * The indexing into the selection functions is peculiar; * it could be simplified by rewriting the tables. */ for(j=0; j < 8; j++) { t = ((j<<1)+j)<<1; k = S[j][(preS[t]<<5)+ (preS[t+1]<<3)+ (preS[t+2]<<2)+ (preS[t+3]<<1)+ (preS[t+4] )+ (preS[t+5]<<4)]; t = j << 2; f[t ] = (k>>3)&01; f[t+1] = (k>>2)&01; f[t+2] = (k>>1)&01; f[t+3] = (k )&01; } /* The new R is L ^ f(R, K). The f here has to be permuted first, though. */ for(j=0; j < 32; j++) R[j] = L[j] ^ f[(int)P[j]]; /* Finally, the new L (the original R) is copied back. */ for(j=0; j < 32; j++) L[j] = tempL[j]; } /* The output L and R are reversed. */ for(j=0; j < 32; j++) { L[j] ^= R[j]; R[j] ^= L[j]; L[j] ^= R[j]; } /* The final output gets the inverse permutation of the very original. */ for(j=0; j < 64; j++) block[j] = L[(int)FP[j]]; } char * crypt(const char *pw, const char *salt) { register int i, j, c; static char block[66], iobuf[16]; #ifdef WANT_CRYPT_MD5 if (salt[0]=='$' && salt[1]=='1' && salt[2]=='$') return md5crypt(pw,salt); #endif for(i=0; i < 66; i++) block[i] = 0; for(i=0; (c= *pw) && i < 64; pw++) { for(j=0; j < 7; j++, i++) block[i] = (c>>(6-j)) & 01; i++; } setkey(block); for(i=0; i < 66; i++) block[i] = 0; for(i=0; i < 2; i++) { c = *salt++; iobuf[i] = c; if(c > 'Z') c -= 6; if(c > '9') c -= 7; c -= '.'; for(j=0; j < 6; j++) { if((c>>j) & 01) { int ind1 = (((i<<1)+i)<< 1) + j; int ind2 = ind1 + 24; E[ind1] ^= E[ind2]; E[ind2] ^= E[ind1]; E[ind1] ^= E[ind2]; } } } for(i=0; i < 25; i++) encrypt(block,0); for(i=0; i < 11; i++) { c = 0; for(j=0; j < 6; j++) { c <<= 1; c |= block[(((i<<1)+i)<<1)+j]; } c += '.'; if(c > '9') c += 7; if(c > 'Z') c += 6; iobuf[i+2] = c; } iobuf[i+2] = 0; if(iobuf[1] == 0) iobuf[1] = iobuf[0]; return(iobuf); } dietlibc-0.33~cvs20120325/libcrypt/md5.c010064400000000000000000000211241173363226500143670ustar00/***************************************************************************** * * "derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm". * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *****************************************************************************/ #include #include #include #if (__BYTE_ORDER == __BIG_ENDIAN) /* Block copy and convert byte order to little-endian. dst must be 32bit aligned. Length is the number of 32bit words */ static void CopyToLittleEndian (uint32_t *dst, const uint8_t *src, int length) { while (length--) { *dst=(((uint32_t)src[3])<<24) | (((uint32_t)src[2])<<16) | (((uint32_t)src[1])<< 8) | (uint32_t)src[0]; src+=4; dst++; } } #endif /* Assembler versions of __MD5Transform, MD5Init and MD5Update currently exist for x86 and little-endian ARM. For other targets, we need to use the C versions below. */ #if !(defined (__i386__) || ((defined (__arm__) && (__BYTE_ORDER == __LITTLE_ENDIAN)))) /* Initialise the MD5 context. */ void MD5Init (MD5_CTX* context) { context->count[0] = 0; context->count[1] = 0; context->state[0] = 0x67452301; /* Load magic constants. */ context->state[1] = 0xefcdab89; context->state[2] = 0x98badcfe; context->state[3] = 0x10325476; } #define ROTATE_LEFT(x, n) ((x << n) | (x >> (32-n))) #define F(x, y, z) (z ^ (x & (y ^ z))) #define G(x, y, z) (y ^ (z & (x ^ y))) #define H(x, y, z) (x ^ y ^ z) #define I(x, y, z) (y ^ (x | ~z)) #define FF(a, b, c, d, x, s, ac) { (a) += F (b, c, d) + (x) + (uint32_t)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } #define GG(a, b, c, d, x, s, ac) { (a) += G (b, c, d) + (x) + (uint32_t)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } #define HH(a, b, c, d, x, s, ac) { (a) += H (b, c, d) + (x) + (uint32_t)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } #define II(a, b, c, d, x, s, ac) { (a) += I (b, c, d) + (x) + (uint32_t)(ac); (a) = ROTATE_LEFT (a, s); (a) += (b); } static void __MD5Transform (uint32_t state[4], const uint8_t *in, int repeat) { const uint32_t *x; uint32_t a = state[0]; uint32_t b = state[1]; uint32_t c = state[2]; uint32_t d = state[3]; for ( ; repeat; repeat--) { uint32_t tempBuffer[16]; #if (__BYTE_ORDER == __BIG_ENDIAN) CopyToLittleEndian (tempBuffer, in, 16); x = tempBuffer; #else if ((long)in & 3) { memcpy(tempBuffer, in, 64); x = tempBuffer; } else x = (const uint32_t *) in; #endif FF (a, b, c, d, x[ 0], 7, 0xd76aa478); /* 1 */ /* Round 1 */ FF (d, a, b, c, x[ 1], 12, 0xe8c7b756); /* 2 */ FF (c, d, a, b, x[ 2], 17, 0x242070db); /* 3 */ FF (b, c, d, a, x[ 3], 22, 0xc1bdceee); /* 4 */ FF (a, b, c, d, x[ 4], 7, 0xf57c0faf); /* 5 */ FF (d, a, b, c, x[ 5], 12, 0x4787c62a); /* 6 */ FF (c, d, a, b, x[ 6], 17, 0xa8304613); /* 7 */ FF (b, c, d, a, x[ 7], 22, 0xfd469501); /* 8 */ FF (a, b, c, d, x[ 8], 7, 0x698098d8); /* 9 */ FF (d, a, b, c, x[ 9], 12, 0x8b44f7af); /* 10 */ FF (c, d, a, b, x[10], 17, 0xffff5bb1); /* 11 */ FF (b, c, d, a, x[11], 22, 0x895cd7be); /* 12 */ FF (a, b, c, d, x[12], 7, 0x6b901122); /* 13 */ FF (d, a, b, c, x[13], 12, 0xfd987193); /* 14 */ FF (c, d, a, b, x[14], 17, 0xa679438e); /* 15 */ FF (b, c, d, a, x[15], 22, 0x49b40821); /* 16 */ GG (a, b, c, d, x[ 1], 5, 0xf61e2562); /* 17 */ /* Round 2 */ GG (d, a, b, c, x[ 6], 9, 0xc040b340); /* 18 */ GG (c, d, a, b, x[11], 14, 0x265e5a51); /* 19 */ GG (b, c, d, a, x[ 0], 20, 0xe9b6c7aa); /* 20 */ GG (a, b, c, d, x[ 5], 5, 0xd62f105d); /* 21 */ GG (d, a, b, c, x[10], 9, 0x02441453); /* 22 */ GG (c, d, a, b, x[15], 14, 0xd8a1e681); /* 23 */ GG (b, c, d, a, x[ 4], 20, 0xe7d3fbc8); /* 24 */ GG (a, b, c, d, x[ 9], 5, 0x21e1cde6); /* 25 */ GG (d, a, b, c, x[14], 9, 0xc33707d6); /* 26 */ GG (c, d, a, b, x[ 3], 14, 0xf4d50d87); /* 27 */ GG (b, c, d, a, x[ 8], 20, 0x455a14ed); /* 28 */ GG (a, b, c, d, x[13], 5, 0xa9e3e905); /* 29 */ GG (d, a, b, c, x[ 2], 9, 0xfcefa3f8); /* 30 */ GG (c, d, a, b, x[ 7], 14, 0x676f02d9); /* 31 */ GG (b, c, d, a, x[12], 20, 0x8d2a4c8a); /* 32 */ HH (a, b, c, d, x[ 5], 4, 0xfffa3942); /* 33 */ /* Round 3 */ HH (d, a, b, c, x[ 8], 11, 0x8771f681); /* 34 */ HH (c, d, a, b, x[11], 16, 0x6d9d6122); /* 35 */ HH (b, c, d, a, x[14], 23, 0xfde5380c); /* 36 */ HH (a, b, c, d, x[ 1], 4, 0xa4beea44); /* 37 */ HH (d, a, b, c, x[ 4], 11, 0x4bdecfa9); /* 38 */ HH (c, d, a, b, x[ 7], 16, 0xf6bb4b60); /* 39 */ HH (b, c, d, a, x[10], 23, 0xbebfbc70); /* 40 */ HH (a, b, c, d, x[13], 4, 0x289b7ec6); /* 41 */ HH (d, a, b, c, x[ 0], 11, 0xeaa127fa); /* 42 */ HH (c, d, a, b, x[ 3], 16, 0xd4ef3085); /* 43 */ HH (b, c, d, a, x[ 6], 23, 0x04881d05); /* 44 */ HH (a, b, c, d, x[ 9], 4, 0xd9d4d039); /* 45 */ HH (d, a, b, c, x[12], 11, 0xe6db99e5); /* 46 */ HH (c, d, a, b, x[15], 16, 0x1fa27cf8); /* 47 */ HH (b, c, d, a, x[ 2], 23, 0xc4ac5665); /* 48 */ II (a, b, c, d, x[ 0], 6, 0xf4292244); /* 49 */ /* Round 4 */ II (d, a, b, c, x[ 7], 10, 0x432aff97); /* 50 */ II (c, d, a, b, x[14], 15, 0xab9423a7); /* 51 */ II (b, c, d, a, x[ 5], 21, 0xfc93a039); /* 52 */ II (a, b, c, d, x[12], 6, 0x655b59c3); /* 53 */ II (d, a, b, c, x[ 3], 10, 0x8f0ccc92); /* 54 */ II (c, d, a, b, x[10], 15, 0xffeff47d); /* 55 */ II (b, c, d, a, x[ 1], 21, 0x85845dd1); /* 56 */ II (a, b, c, d, x[ 8], 6, 0x6fa87e4f); /* 57 */ II (d, a, b, c, x[15], 10, 0xfe2ce6e0); /* 58 */ II (c, d, a, b, x[ 6], 15, 0xa3014314); /* 59 */ II (b, c, d, a, x[13], 21, 0x4e0811a1); /* 60 */ II (a, b, c, d, x[ 4], 6, 0xf7537e82); /* 61 */ II (d, a, b, c, x[11], 10, 0xbd3af235); /* 62 */ II (c, d, a, b, x[ 2], 15, 0x2ad7d2bb); /* 63 */ II (b, c, d, a, x[ 9], 21, 0xeb86d391); /* 64 */ state[0] = a = a + state[0]; state[1] = b = b + state[1]; state[2] = c = c + state[2]; state[3] = d = d + state[3]; in += 64; } } /* MD5 block update operation: Process another sub-string of the message and update the context. */ void MD5Update (MD5_CTX *context, const uint8_t *input, size_t inputBytes) { int i; int byteIndex; unsigned int partLen; int len; /* Compute number of bytes mod 64 */ byteIndex = (context->count[0] >> 3) & 0x3F; /* Update number of bits: count += 8 * inputBytes */ if ((context->count[0] += inputBytes << 3) < (inputBytes << 3)) context->count[1]++; context->count[1] += (inputBytes >> (32-3)); partLen = (64 - byteIndex); /* Transform as many times as possible. */ if (inputBytes >= partLen) { memcpy (context->buffer + byteIndex, input, partLen); __MD5Transform (context->state, (const uint8_t *) context->buffer, 1); len = (inputBytes - partLen) / 64; __MD5Transform (context->state, &input[partLen], len); i = partLen + 64 * len; byteIndex = 0; } else i = 0; /* Buffer remaining input */ memcpy (&context->buffer[byteIndex], &input[i], inputBytes - i); } #endif void MD5Final (uint8_t digest[16], MD5_CTX* context) { static uint8_t finalBlock[64]; uint32_t bits[2]; int byteIndex; int finalBlockLength; byteIndex = (context->count[0] >> 3) & 0x3F; finalBlockLength = ((byteIndex < 56) ? 56 : 120) - byteIndex; finalBlock[0] = 0x80; #if (__BYTE_ORDER == __BIG_ENDIAN) CopyToLittleEndian (bits, (const uint8_t *) context->count, 2); #else memcpy(bits, context->count, 8); #endif MD5Update (context, finalBlock, finalBlockLength); MD5Update (context, (const uint8_t *) bits, 8); #if (__BYTE_ORDER == __BIG_ENDIAN) CopyToLittleEndian ((uint32_t *) digest, (const uint8_t *) context->state, 4); #else memcpy (digest, context->state, 16); #endif memset(context, 0, sizeof(*context)); } dietlibc-0.33~cvs20120325/libcrypt/md5crypt.c010064400000000000000000000100351173363226500154500ustar00/* $OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp $ */ /* * ---------------------------------------------------------------------------- * "THE BEER-WARE LICENSE" (Revision 42): * wrote this file. As long as you retain this notice you * can do whatever you want with this stuff. If we meet some day, and you think * this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp * ---------------------------------------------------------------------------- * * $FreeBSD: crypt.c,v 1.5 1996/10/14 08:34:02 phk Exp $ * */ #if defined(LIBC_SCCS) && !defined(lint) static char rcsid[] = "$OpenBSD: md5crypt.c,v 1.9 1997/07/23 20:58:27 kstailey Exp $"; #endif /* LIBC_SCCS and not lint */ #include #include #include #include static unsigned char itoa64[] = /* 0 ... 63 => ascii - 64 */ "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; static void to64 (char *, uint32_t, int); static void to64(s, v, n) char *s; uint32_t v; int n; { while (--n >= 0) { *s++ = itoa64[v&0x3f]; v >>= 6; } } /* * UNIX password * * Use MD5 for what it is best at... */ char * md5crypt(pw, salt) register const char *pw; register const char *salt; { /* * This string is magic for this algorithm. Having * it this way, we can get get better later on */ static unsigned char *magic = (unsigned char *)"$1$"; static char passwd[120], *p; static const unsigned char *sp,*ep; unsigned char final[16]; int sl,pl,i; MD5_CTX ctx,ctx1; uint32_t l; /* Refine the Salt first */ sp = (const unsigned char *)salt; /* If it starts with the magic string, then skip that */ if(!strncmp((const char *)sp,(const char *)magic,strlen((const char *)magic))) sp += strlen((const char *)magic); /* It stops at the first '$', max 8 chars */ for(ep=sp;*ep && *ep != '$' && ep < (sp+8);ep++) continue; /* get the length of the true salt */ sl = ep - sp; MD5Init(&ctx); /* The password first, since that is what is most unknown */ MD5Update(&ctx,(const unsigned char *)pw,strlen(pw)); /* Then our magic string */ MD5Update(&ctx,magic,strlen((const char *)magic)); /* Then the raw salt */ MD5Update(&ctx,sp,sl); /* Then just as many characters of the MD5(pw,salt,pw) */ MD5Init(&ctx1); MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); MD5Update(&ctx1,sp,sl); MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); MD5Final(final,&ctx1); for(pl = strlen(pw); pl > 0; pl -= 16) MD5Update(&ctx,final,pl>16 ? 16 : pl); /* Don't leave anything around in vm they could use. */ memset(final,0,sizeof final); /* Then something really weird... */ for (i = strlen(pw); i ; i >>= 1) if(i&1) MD5Update(&ctx, final, 1); else MD5Update(&ctx, (const unsigned char *)pw, 1); /* Now make the output string */ strcpy(passwd,(const char *)magic); memcpy(passwd+3,sp,sl); passwd[sl+3]='$'; passwd[sl+4]=0; MD5Final(final,&ctx); /* * and now, just to make sure things don't run too fast * On a 60 Mhz Pentium this takes 34 msec, so you would * need 30 seconds to build a 1000 entry dictionary... */ for(i=0;i<1000;i++) { MD5Init(&ctx1); if(i & 1) MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); else MD5Update(&ctx1,final,16); if(i % 3) MD5Update(&ctx1,sp,sl); if(i % 7) MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); if(i & 1) MD5Update(&ctx1,final,16); else MD5Update(&ctx1,(const unsigned char *)pw,strlen(pw)); MD5Final(final,&ctx1); } p = passwd + strlen(passwd); l = (final[ 0]<<16) | (final[ 6]<<8) | final[12]; to64(p,l,4); p += 4; l = (final[ 1]<<16) | (final[ 7]<<8) | final[13]; to64(p,l,4); p += 4; l = (final[ 2]<<16) | (final[ 8]<<8) | final[14]; to64(p,l,4); p += 4; l = (final[ 3]<<16) | (final[ 9]<<8) | final[15]; to64(p,l,4); p += 4; l = (final[ 4]<<16) | (final[10]<<8) | final[ 5]; to64(p,l,4); p += 4; l = final[11] ; to64(p,l,2); p += 2; *p = '\0'; /* Don't leave anything around in vm they could use. */ memset(final,0,sizeof final); return passwd; } dietlibc-0.33~cvs20120325/libdl/Makefile010064400000000000000000000016441173363226500144410ustar00# local "test" make file CC = $(CROSS)gcc DCC = diet $(CC) SRC = $(wildcard *.c) # test/test.c OBJ = _dl_jump.o $(SRC:.c=.o) #CFLAGS = -Wall -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -g -O #CFLAGS = -Wall -O2 -Bsymbolic -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -frerun-loop-opt -fschedule-insns2 $(DEB) CFLAGS = -Wall -g -O -I.. -isystem ../include -Bsymbolic -D__OD_CLEAN_ROOM -DNODIETREF -fPIC -frerun-loop-opt -fschedule-insns2 $(DEB) # -fomit-frame-pointer %.o : %.S $(DCC) $(CFLAGS) -c -o $@ $^ %.o : %.c $(DCC) $(CFLAGS) -c -o $@ $^ it: t.out a.out: t.out $(CROSS)gcc -O -g test/a.c t.out -L/opt/diet/lib-i386 -lc -lgcc -o $@ -Wl,-dynamic-linker=`pwd`/t.out -nostdlib t.out: _dl_main.o $(CROSS)ld -shared -o $@ $? -soname=libdl.so -Bsymbolic all: test.out libdl.a libdl.a: $(OBJ) ar cru $@ $^ test.g: test/test.c gcc -o $@ $^ -ldl test.out: $(OBJ) test/test.o diet gcc -o $@ $^ clean: $(RM) *.o *.a *.out *~ # *.so dietlibc-0.33~cvs20120325/libdl/README010064400000000000000000000034051173363226500136560ustar00this is the experimental libdl written by Olaf Dreesen Fri Nov 15 16:23:28 CET 2002 fixing the copy-relocation bug. TODO as last time.... plus - dlsym with RTLD_NEXT Wed Nov 6 19:08:00 CET 2002 Ups.. misunderstood the manual-page of dlopen. now dlopen(0,...) works the way it is described in the susv2, BUT still not complete. TODO: - gdb support - RTLD_GLOBAL/RTLD_LOCAL at the moment ALL are GLOBAL. - open of a shared object ONCE there is no library hard-, symlink detection yet. - code for other archs then i386 and arm Fri Sep 13 16:28:42 CEST 2002 this unified libdl/dynlinker is now the default. Mon Mar 11 19:44:20 CET 2002 the unified libdl/dynlinker now seems to stand the NORMAL usage so I think it should be tested outside my CLEANROOM :) TODO: code for other archs than i386 and arm Thu Nov 1 18:41:36 MET 2001 ufffff.... now the libdl code can be used in the libdl.so :) Status: it works in my clean room on i386, arm-code started TODO: see below :) Wed Jul 4 11:55:00 MEST 2001 Uwe Ohse pointed to some flaws in my code, I have started to fix them.... TODO: rebuild the code in a more readable and consistent way. TODO: code for other archs than i386 Thu Jun 21 15:32:45 MEST 2001 It work good enough to make a libdietc.so possible. TODO: rebuild the code in a more readable and consistent way. TODO: code for other archs than i386 Thu Jun 7 14:10:03 MEST 2001 Status: test-pre-alpha code the code is now "testable" ... I need a dyn-dietlibc specific ld.so. (in work) TODO: rebuild the code in a more readable and consistent way. INITIAL May ? : Status: test-pre-pre-alpha code Shouldn't work yet. Had and have some problems with the elf specs... and more inconsistencies... dietlibc-0.33~cvs20120325/libdl/_dl_alloc.c010064400000000000000000000040401173363226500150460ustar00#include #include #include #include "_dl_int.h" #ifdef __DIET_LD_SO__ static struct _dl_handle*_dl_root_handle=(struct _dl_handle*)0; static struct _dl_handle*_dl_top_handle=(struct _dl_handle*)0; static struct _dl_handle*_dl_free_list=(struct _dl_handle*)0; #else struct _dl_handle*_dl_root_handle=(struct _dl_handle*)0; struct _dl_handle*_dl_top_handle=(struct _dl_handle*)0; struct _dl_handle*_dl_free_list=(struct _dl_handle*)0; #define _dl_lib_memset memset #endif #ifdef __DIET_LD_SO__ static #endif void _dl_free_handle(struct _dl_handle*dh) { if (_dl_root_handle==dh) _dl_root_handle=dh->next; if (_dl_top_handle ==dh) _dl_top_handle=dh->prev; if (dh->next) dh->next->prev=dh->prev; if (dh->prev) dh->prev->next=dh->next; if ((dh->flags&RTLD_NOSONAME) && dh->name) free(dh->name); _dl_lib_memset(dh,0,sizeof(struct _dl_handle)); dh->next=_dl_free_list; _dl_free_list=dh; } #ifdef __DIET_LD_SO__ static #endif struct _dl_handle*_dl_get_handle() { struct _dl_handle*tmp; if (_dl_free_list==0) { register int i,m; #ifdef __DIET_LD_SO__ tmp = (struct _dl_handle*)_dl_sys_mmap(0,at_pagesize,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); m=DIV(at_pagesize,sizeof(struct _dl_handle)); #else int ps=getpagesize(); tmp = (struct _dl_handle*)mmap(0,ps,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0); m=ps/sizeof(struct _dl_handle); #endif for (i=m;i;) _dl_free_handle(tmp+(--i)); } tmp = _dl_free_list; _dl_free_list = tmp->next; tmp->next=0; if (_dl_root_handle) { _dl_top_handle->next=tmp; tmp->prev=_dl_top_handle; } else _dl_root_handle = tmp; _dl_top_handle=tmp; return tmp; } #ifdef __DIET_LD_SO__ static #endif struct _dl_handle*_dl_find_lib(const char* name) { if (name) { if (_dl_root_handle) { struct _dl_handle*tmp; for (tmp=_dl_root_handle;tmp;tmp=tmp->next) { if (!tmp->name) continue; if (!_dl_lib_strcmp((const unsigned char*)tmp->name,(const unsigned char*)name)) return tmp; } } } return 0; } dietlibc-0.33~cvs20120325/libdl/_dl_int.h010064400000000000000000000076431173363226500145670ustar00#ifndef ___DL_INT_H__ #define ___DL_INT_H__ //#define DEBUG #include "dietfeatures.h" #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) #define ELF_CLASS ELFCLASS64 #else #define ELF_CLASS ELFCLASS32 #endif #include #define _GNU_SOURCE #include #include "_dl_rel.h" #if ELF_CLASS == ELFCLASS32 #define Elf_Addr Elf32_Addr #define Elf_Dyn Elf32_Dyn #define Elf_Ehdr Elf32_Ehdr #define Elf_Phdr Elf32_Phdr #define Elf_Rel Elf32_Rel #define Elf_Rela Elf32_Rela #define Elf_Sym Elf32_Sym #define ELF_R_SYM(x) ELF32_R_SYM((x)) #define ELF_R_TYPE(x) ELF32_R_TYPE((x)) #define ELF_ST_BIND(x) ELF32_ST_BIND((x)) #define ELF_ST_TYPE(x) ELF32_ST_TYPE((x)) #else #define Elf_Addr Elf64_Addr #define Elf_Dyn Elf64_Dyn #define Elf_Ehdr Elf64_Ehdr #define Elf_Phdr Elf64_Phdr #define Elf_Rel Elf64_Rel #define Elf_Rela Elf64_Rela #define Elf_Sym Elf64_Sym #define ELF_R_SYM(x) ELF64_R_SYM((x)) #define ELF_R_TYPE(x) ELF64_R_TYPE((x)) #define ELF_ST_BIND(x) ELF64_ST_BIND((x)) #define ELF_ST_TYPE(x) ELF64_ST_TYPE((x)) #endif #define RTLD_USER 0x10000000 #define RTLD_NOSONAME 0x20000000 #define LDSO_FLAGS (RTLD_LAZY|RTLD_GLOBAL|RTLD_NOSONAME) struct _dl_handle { /* the next fields HAVE to be in this order for GDB */ char * mem_base; /* base address of maped *.so / or zero if program | Elf_Addr l_addr */ char * l_name; /* Abloslute filename of this object */ Elf_Dyn* dynamic; /* _DYNAMIC */ struct _dl_handle *next; struct _dl_handle *prev; /* ok last GDB used part was prev */ unsigned long flags; /* FLAGS */ char * name; /* name of shared object */ /* basic */ unsigned long mem_size; /* len of mem block */ unsigned long lnk_count; /* reference count (other libraries) */ /* lazy evaluator data */ unsigned long*pltgot; /* PLT/GOT */ /* symbol resolve helper */ unsigned int*hash_tab; /* hash table */ char * dyn_str_tab; /* dyn_name table */ Elf_Sym * dyn_sym_tab; /* dynamic symbol table */ _dl_rel_t* plt_rel; /* PLT relocation table */ unsigned int*gnu_hash_tab; /* GNU hash table */ /* INIT / FINI */ void (*init)(void); void (*fini)(void); }; /* debug communication (GDB) (dyn-linker only) */ struct r_debug { int r_version; struct _dl_handle* r_map; void(*r_brk)(); enum { RT_CONSISTENT, /* mapping complete */ RT_ADD, /* begin add object */ RT_DELETE, /* begin del object */ } r_state; Elf_Addr r_ldbase; }; #define HASH_BUCKET_LEN(p) (*((p))) #define HASH_BUCKET(p) ((p)+2) #define HASH_CHAIN_LEN(p) (*((p)+1)) #define HASH_CHAIN(p) ((p)+2+HASH_BUCKET_LEN(p)) #define GNU_HASH_BUCKET_LEN(p) (*((p))) #define GNU_HASH_BUCKET(p,n) ((p)[(n)+1]) #define GNU_HASH_CHAIN(p,n) ((p)+(1+GNU_HASH_BUCKET_LEN(p)+(n))) /* _dl_alloc.c */ #if 0 extern struct _dl_handle* _dl_root_handle; extern struct _dl_handle* _dl_top_handle; extern struct _dl_handle* _dl_free_list; #endif #ifndef __DIET_LD_SO__ void _dl_free_handle(struct _dl_handle* dh); struct _dl_handle* _dl_get_handle(); struct _dl_handle* _dl_find_lib(const char* name); /* _dl_open.c */ void *_dl_open(const char* filename, int flags); /* _dl_load.c */ void *_dl_load(const char* filename, const char*pathname, int fd, int flags); struct _dl_handle* _dl_dyn_scan(struct _dl_handle* dh, void* dyn_addr, int flags); /* _dl_search.c */ void _dl_set_rpath(const char *path); const char* _dl_get_rpath(); int _dl_search(char *buf, int len, const char *filename); /* dlsym.c */ void *_dlsym(void*dh,const char*symbol); void *_dl_sym_search_str(struct _dl_handle*h,const char*name); void *_dl_sym(struct _dl_handle * h, int symbol); void *_dl_sym_next(struct _dl_handle * h, int symbol); /* _dl_queue.c */ int _dl_queue_lib(const char* name, int flags); int _dl_open_dep(); /* _dl_relocate.c */ int _dl_relocate(struct _dl_handle* dh, _dl_rel_t *rel, int num); /* dlerror.c */ extern unsigned int _dl_error; extern const char* _dl_error_location; extern const char* _dl_error_data; #endif #endif dietlibc-0.33~cvs20120325/libdl/_dl_jump.S010064400000000000000000000015451173363226500147160ustar00.text .global _dl_jump _dl_jump: #ifdef __i386__ .type _dl_jump,@function pushl %eax # save register args... pushl %ecx pushl %edx pushl %ebx pushl 20(%esp) # 2. arg from plt pushl 20(%esp) # 1. arg from plt #ifdef __DYN_LIB call 1f 1: popl %ebx addl $_GLOBAL_OFFSET_TABLE_+[.-1b],%ebx call do_rel@PLT #else call do_rel #endif addl $8, %esp popl %ebx popl %edx # restore register args... popl %ecx xchgl %eax, (%esp) # restore eax and save function pointer (for return) ret $8 # remove arguments from plt and jump to REAL function #endif #ifdef __arm__ .type _dl_jump,function stmdb sp!, {r0, r1, r2, r3} sub r1, ip, lr sub r1, r1, #4 add r1, r1, r1 /* dyntab entry */ ldr r0, [lr, #-4] /* dynlib handle */ #ifdef __DYN_LIB bl do_rel(PLT) #else bl do_rel #endif mov r12, r0 ldmia sp!, {r0, r1, r2, r3, lr} mov pc, r12 #endif dietlibc-0.33~cvs20120325/libdl/_dl_load.c010064400000000000000000000251301173363226500146760ustar00#include #include #include #include #include #include #include "_dl_int.h" #define _ELF_DWN_ROUND(ps,n) ((n)&(~((ps)-1))) #define _ELF_UP_ROUND(ps,n) ((((n)&((ps)-1))?(ps):0)+ _ELF_DWN_ROUND((ps),(n))) #define _ELF_RST_ROUND(ps,n) ((n)&((ps)-1)) /* this is an arch specific "return jump" for the relocation */ void _dl_jump(); /* * this file is a Q. & D. hack ... don't think this is bug free or meaningfull */ static inline int map_flags(int flags) { int perm = 0; if (flags & PF_X) perm|=PROT_EXEC; if (flags & PF_R) perm|=PROT_READ; if (flags & PF_W) perm|=PROT_WRITE; return perm; } static inline void *do_map_in(void *base, unsigned long length, int flags, int fd, unsigned long offset) { register int op = MAP_PRIVATE; if (base) op|=MAP_FIXED; return mmap(base, length, map_flags(flags), op, fd, offset); } static struct _dl_handle *_dl_map_lib(const char*fn, const char*pathname, int fd, int flags) { struct _dl_handle* ret=0; int ps=getpagesize(); int i; unsigned char buf[1024]; char *m=0,*d=0; unsigned long l; struct stat st; Elf_Ehdr *eh; Elf_Phdr *ph; int ld_nr=0; Elf_Phdr **ld=0; Elf_Phdr *dyn=0; if (fd==-1) return 0; #ifdef DEBUG pf(__func__": "); pf(pathname); pf("\n"); #endif if (fstat(fd,&st)<0) { close(fd); _dl_error=2; return 0; } else { // use st_dev and st_ino for identification } if (read(fd, buf, 1024)<128) { close(fd); _dl_error=2; return 0; } eh=(Elf_Ehdr*)buf; ph=(Elf_Phdr*)&buf[eh->e_phoff]; for (i=0; ie_phnum; i++) { if (ph[i].p_type==PT_LOAD) ++ld_nr; } ld=alloca(ld_nr*sizeof(Elf_Phdr)); for (ld_nr=i=0; ie_phnum; i++) { if (ph[i].p_type==PT_LOAD) { ld[ld_nr++]=ph+i; } if (ph[i].p_type==PT_DYNAMIC) { dyn=ph+i; } } if (ld_nr==1) { unsigned long offset = _ELF_DWN_ROUND(ps,ld[0]->p_offset); unsigned long off = _ELF_RST_ROUND(ps,ld[0]->p_offset); unsigned long length = _ELF_UP_ROUND(ps,ld[0]->p_memsz+off); ret = _dl_get_handle(); m = (char*)do_map_in(0, length, ld[0]->p_flags, fd, offset); if (m==MAP_FAILED) { _dl_free_handle(ret); close(fd); return 0; } /* zero pad bss */ l = ld[0]->p_offset+ld[0]->p_filesz; memset(m+l,0,length-l); ret->mem_base=m; ret->mem_size=length; } else if (ld_nr==2) { /* aem... yes Quick & Really Dirty / for the avarage 99% */ // unsigned long text_addr = _ELF_DWN_ROUND(ps,ld[0]->p_vaddr); /* do we need this ? */ unsigned long text_offset = _ELF_DWN_ROUND(ps,ld[0]->p_offset); unsigned long text_off = _ELF_RST_ROUND(ps,ld[0]->p_offset); unsigned long text_size = _ELF_UP_ROUND(ps,ld[0]->p_memsz+text_off); unsigned long data_addr = _ELF_DWN_ROUND(ps,ld[1]->p_vaddr); unsigned long data_offset = _ELF_DWN_ROUND(ps,ld[1]->p_offset); unsigned long data_off = _ELF_RST_ROUND(ps,ld[1]->p_offset); unsigned long data_size = _ELF_UP_ROUND(ps,ld[1]->p_memsz+data_off); unsigned long data_fsize = _ELF_UP_ROUND(ps,ld[1]->p_filesz+data_off); ret = _dl_get_handle(); /* mmap all mem_blocks for *.so */ m = (char*) do_map_in(0,text_size+data_size,ld[0]->p_flags,fd,text_offset); if (m==MAP_FAILED) { _dl_free_handle(ret); close(fd); return 0; } /* release data,bss part */ mprotect(m+data_addr, data_size, PROT_NONE); /* mmap data,bss part */ d = (char*) do_map_in(m+data_addr,data_fsize,ld[1]->p_flags,fd,data_offset); /* zero pad bss */ l = data_off+ld[1]->p_filesz; memset(d+l,0,data_fsize-l); /* more bss ? */ if (data_size>data_fsize) { l = data_size-data_fsize; mmap(d+data_fsize, l, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0); } ret->mem_base=m; ret->mem_size=text_size+data_size; } if (ret) { ret->lnk_count=1; ret->name=strdup(fn); ret->dyn_str_tab=(char*)m+dyn->p_vaddr; /* missuse of field */ } close(fd); return ret; } /* local alias */ static struct _dl_handle* __dl_dyn_scan(struct _dl_handle* dh, void* dyn_addr, int flags) __attribute__ ((alias("_dl_dyn_scan"))); struct _dl_handle* _dl_dyn_scan(struct _dl_handle* dh, void* dyn_addr, int flags) { Elf_Dyn* dyn_tab = dyn_addr; void (*init)()=0; unsigned long* got=0; void* jmprel=0; int pltreltype=0; int pltrelsize=0; unsigned long rel=0; int relent=0; int relsize=0; int i; #ifdef DEBUG pf(__func__": pre dynamic scan "); ph((unsigned long)dh); pf("\n"); #endif dh->dyn_str_tab=0; dh->flags=flags; for(i=0;dyn_tab[i].d_tag;i++) { // DEBUG(printf("_dl_load dyn %d, %08lx\n",dyn_tab[i].d_tag, dyn_tab[i].d_un.d_val);) if (dyn_tab[i].d_tag==DT_HASH) { dh->hash_tab = (unsigned long*)(dh->mem_base+dyn_tab[i].d_un.d_ptr); #ifdef DEBUG pf(__func__": have hash @ "); ph((long)dh->hash_tab); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_SYMTAB) { dh->dyn_sym_tab = (Elf_Sym*)(dh->mem_base+dyn_tab[i].d_un.d_ptr); #ifdef DEBUG pf(__func__": have dyn_sym_tab @ "); ph((long)dh->dyn_sym_tab); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_STRTAB) { dh->dyn_str_tab = (char*)(dh->mem_base+dyn_tab[i].d_un.d_ptr); #ifdef DEBUG pf(__func__": have dyn_str_tab @ "); ph((long)dh->dyn_str_tab); pf("\n"); #endif } /* INIT / FINI */ else if (dyn_tab[i].d_tag==DT_FINI) { dh->fini = (void(*)(void))(dh->mem_base+dyn_tab[i].d_un.d_val); #ifdef DEBUG pf(__func__": have fini @ "); ph((long)dh->fini); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_INIT) { init = (void(*)(void))(dh->mem_base+dyn_tab[i].d_un.d_val); #ifdef DEBUG pf(__func__": have init @ "); ph((long)init); pf("\n"); #endif } /* PLT / Relocation entries for PLT in GOT */ else if (dyn_tab[i].d_tag==DT_PLTGOT) { got=(unsigned long*)(dh->mem_base+dyn_tab[i].d_un.d_val); dh->pltgot=got; #ifdef DEBUG pf(__func__": have plt got @ "); ph((long)dh->pltgot); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_PLTREL) { pltreltype=dyn_tab[i].d_un.d_val; #ifdef DEBUG pf(__func__": have pltreltype @ "); ph((long)pltreltype); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_PLTRELSZ) { pltrelsize=dyn_tab[i].d_un.d_val; #ifdef DEBUG pf(__func__": have pltrelsize @ "); ph((long)pltrelsize); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_JMPREL) { jmprel=(dh->mem_base+dyn_tab[i].d_un.d_val); dh->plt_rel=jmprel; #ifdef DEBUG pf(__func__": have jmprel @ "); ph((long)jmprel); pf("\n"); #endif } /* Relocation */ else if (dyn_tab[i].d_tag==DT_REL) { rel=(unsigned long)(dh->mem_base+dyn_tab[i].d_un.d_val); #ifdef DEBUG pf(__func__": have rel @ "); ph((long)rel); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_RELENT) { relent=dyn_tab[i].d_un.d_val; #ifdef DEBUG pf(__func__": have relent @ "); ph((long)relent); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_RELSZ) { relsize=dyn_tab[i].d_un.d_val; #ifdef DEBUG pf(__func__": have relsize @ "); ph((long)relsize); pf("\n"); #endif } else if (dyn_tab[i].d_tag==DT_TEXTREL) { _dl_free_handle(dh); _dl_error = 3; return 0; } } /* extra scan for rpath (if program) ... */ if (dh->name==0) { for(i=0;dyn_tab[i].d_tag;i++) { if (dyn_tab[i].d_tag==DT_RPATH) { char *rpath=dh->dyn_str_tab+dyn_tab[i].d_un.d_val; _dl_set_rpath(rpath); #ifdef DEBUG pf(__func__": have runpath: "); pf(rpath); pf("\n"); #endif } } } #ifdef DEBUG pf(__func__": post dynamic scan "); ph((unsigned long)dh); pf("\n"); #endif if ((got=_dlsym(dh,"_GLOBAL_OFFSET_TABLE_"))) { #ifdef DEBUG pf(__func__": found a GOT @ "); ph((unsigned long)got); pf("\n"); #endif /* GOT */ got[0]+=(unsigned long)dh->mem_base; /* reloc dynamic pointer */ got[1] =(unsigned long)dh; got[2] =(unsigned long)(_dl_jump); /* sysdep jump to _dl_rel */ /* */ } else { if (dh) { munmap(dh->mem_base,dh->mem_size); _dl_free_handle(dh); } _dl_error = 3; return 0; } /* load other libs */ for(i=0;dyn_tab[i].d_tag;i++) { if (dyn_tab[i].d_tag==DT_NEEDED) { char *lib_name=dh->dyn_str_tab+dyn_tab[i].d_un.d_val; #ifdef DEBUG pf(__func__": needed for this lib: "); pf(lib_name); pf("\n"); #endif _dl_queue_lib(lib_name,flags); } } if (_dl_open_dep()) { _dl_error = 1; return 0; } /* relocate */ if (rel) { #ifdef DEBUG pf(__func__": try to relocate some values\n"); #endif if (_dl_relocate(dh,(Elf_Rel*)rel,relsize/relent)) { munmap(dh->mem_base,dh->mem_size); _dl_free_handle(dh); return 0; } } /* do PTL / GOT relocation */ if (pltreltype == DT_REL) { Elf_Rel *tmp = jmprel; #ifdef DEBUG pf(__func__": rel got\n"); #endif for (;(char*)tmp<(((char*)jmprel)+pltrelsize);(char*)tmp=((char*)tmp)+sizeof(Elf_Rel)) { if ((flags&RTLD_NOW)) { unsigned long sym=(unsigned long)_dl_sym(dh,ELF_R_SYM(tmp->r_info)); if (sym) *((unsigned long*)(dh->mem_base+tmp->r_offset))=sym; else { _dl_free_handle(dh); _dl_error = 4; return 0; } } else *((unsigned long*)(dh->mem_base+tmp->r_offset))+=(unsigned long)dh->mem_base; #if 0 DEBUG("_dl_load rel @ %08lx with type %d -> %d\n",(long)dh->mem_base+tmp->r_offset,ELF_R_TYPE(tmp->r_info),ELF_R_SYM(tmp->r_info)); DEBUG("_dl_load -> %08lx\n",*((unsigned long*)(dh->mem_base+tmp->r_offset))); #endif } } if (pltreltype == DT_RELA) { Elf_Rela *tmp = jmprel; #ifdef DEBUG pf(__func__": rela got\n"); #endif for (;(char*)tmp<(((char*)jmprel)+pltrelsize);(char*)tmp=((char*)tmp)+sizeof(Elf_Rela)) { if ((flags&RTLD_NOW)) { unsigned long sym=(unsigned long)_dl_sym(dh,ELF_R_SYM(tmp->r_info)); if (sym) *((unsigned long*)(dh->mem_base+tmp->r_offset))=sym; else { _dl_free_handle(dh); _dl_error = 4; return 0; } } else *((unsigned long*)(dh->mem_base+tmp->r_offset))=(unsigned long)(dh->mem_base+tmp->r_addend); #if 0 DEBUG("_dl_load rela @ %08lx with type %d -> %d\n",(long)dh->mem_base+tmp->r_offset,ELF_R_TYPE(tmp->r_info),ELF_R_SYM(tmp->r_info)); DEBUG("_dl_load -> %08lx\n",*((unsigned long*)(dh->mem_base+tmp->r_offset))); #endif } } /* _dl_load depending libs ... */ #ifdef DEBUG pf(__func__": post resolve, pre init\n"); #endif if (init) init(); #ifdef DEBUG pf(__func__": post init\n"); #endif return dh; } void *_dl_load(const char*fn, const char*pathname, int fd, int flags) { struct _dl_handle* ret=0; if ((ret=_dl_map_lib(fn,pathname,fd,flags))) { ret=__dl_dyn_scan(ret,(void*)(ret->dyn_str_tab),flags); } return ret; } dietlibc-0.33~cvs20120325/libdl/_dl_main.c010064400000000000000000001056351173363226500147140ustar00#ifdef __OD_CLEAN_ROOM /* work around... * don't include or */ #define _STRING_H #define _STDLIB_H /* we are the libdl.so so tell all included functiuons to be static. */ #define __DIET_LD_SO__ /* * this is the dietlibc libdl & dynamic-linker * * NEED to be compiled with -fPIC ... */ #include #include #include "_dl_int.h" #include "_dl_rel.h" void _start(void); /* entry of lib... */ static void (*fini_entry)(void)=0; static char **_dl_environ=0; static unsigned long loadaddr=0; static unsigned long prog_entry=0; static Elf_Phdr*prog_ph; static unsigned long prog_ph_size; static unsigned long prog_ph_num; static unsigned long at_uid; static unsigned long at_euid; static unsigned long at_gid; static unsigned long at_egid; static unsigned long at_pagesize; /* this are the "local syscalls" */ __attribute__((noreturn,visibility("hidden"))) void _dl_sys_exit(int val); __attribute__((visibility("hidden"))) int _dl_sys_read(int fd,void*buf,unsigned long len); __attribute__((visibility("hidden"))) int _dl_sys_write(int fd,void*buf,unsigned long len); __attribute__((visibility("hidden"))) int _dl_sys_open(const char*filename,int flags,int mode); __attribute__((visibility("hidden"))) int _dl_sys_close(int fd); __attribute__((visibility("hidden"))) void*_dl_sys_mmap(void*start,unsigned long length,int prot,int flags,int fd,unsigned long offset); __attribute__((visibility("hidden"))) int _dl_sys_munmap(void*start,unsigned long length); __attribute__((visibility("hidden"))) int _dl_sys_mprotect(const void*addr,unsigned long len,int prot); __attribute__((visibility("hidden"))) int _dl_sys_fstat(int filedes, struct stat *buf); __attribute__((visibility("hidden"))) void _dl_jump(void); extern char*strdup(const char*s); extern void free(void*p); __attribute__((visibility("hidden"))) unsigned long _dl_main(int argc,char*argv[],char*envp[],unsigned long _dynamic); __attribute__((visibility("hidden"))) unsigned long do_resolve(struct _dl_handle*dh,unsigned long off); #if defined(__i386__) asm(".text \n" ".type _start,@function \n" "_start: \n" " movl %esp, %ebp # save stack \n" " movl (%ebp), %ecx # argc \n" " leal 4(%ebp), %esi # argv \n" " leal 4(%esi,%ecx,4), %eax # envp \n" /* PIC code */ " call getpic \n" " addl $_GLOBAL_OFFSET_TABLE_, %ebx \n" /* for calculation of load addr, get 'relocated' address of _DYNAMIC */ " leal _DYNAMIC@GOTOFF(%ebx), %edx \n" /* get load-address */ " movl %edx, %edi \n" " subl (%ebx), %edi # 'unrelocated' address of _DYNAMIC \n" " pushl %edi \n" /* put parameter on stack and call _dl_main */ " pushl %edx \n" " pushl %eax \n" " pushl %esi \n" " pushl %ecx \n" " call _dl_main \n" /* restore stack */ " movl %ebp, %esp \n" /* get fini pointer */ " movl fini_entry@GOTOFF(%ebx), %edx \n" /* clear callee-save-register like kernel */ " xorl %ebx, %ebx \n" " xorl %ebp, %ebp \n" " xorl %edi, %edi \n" " xorl %esi, %esi \n" /* jump to program entry point */ " jmp *%eax \n" ".type _dl_sys_read,@function \n" "_dl_sys_read: \n" " movb $3,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_write,@function \n" "_dl_sys_write: \n" " movb $4,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_open,@function \n" "_dl_sys_open: \n" " movb $5,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_close,@function \n" "_dl_sys_close: \n" " movb $6,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_mmap,@function \n" "_dl_sys_mmap: \n" " movb $90,%al \n" " leal 4(%esp),%edx \n" " pushl %edx \n" " call _dl_sys_call3 \n" " popl %ecx \n" " ret \n" ".type _dl_sys_munmap,@function \n" "_dl_sys_munmap: \n" " movb $91,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_fstat,@function \n" "_dl_sys_fstat: \n" " movb $108,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_mprotect,@function \n" "_dl_sys_mprotect: \n" " movb $125,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_exit,@function \n" "_dl_sys_exit: \n" " movb $1,%al \n" ".type _dl_sys_call3,@function \n" "_dl_sys_call3: \n" " movzbl %al,%eax \n" " pushl %ebx \n" " movl %esp,%ebx \n" " movl 16(%ebx),%edx \n" " movl 12(%ebx),%ecx \n" " movl 8(%ebx),%ebx \n" " int $0x80 \n" " popl %ebx \n" " ret \n" ".type _dl_jump,@function \n" "_dl_jump: \n" /* save temp-register (posible reg-args) */ " pushl %eax \n" " pushl %ecx \n" " pushl %edx \n" /* call resolve */ " push 16(%esp) # 2. arg from plt \n" " push 16(%esp) # 1. arg from plt \n" " call do_resolve \n" " add $8, %esp \n" /* restore temp-register */ " popl %edx \n" " popl %ecx \n" " xchgl %eax, (%esp) # restore eax and save function pointer (for return) \n" " ret $8 # remove arguments from plt and jump to REAL function \n" /* GET Position In Code :) */ "getpic: movl (%esp), %ebx \n" " ret"); static inline unsigned long* get_got(void) { register unsigned long *got asm ("%ebx"); return got; } static inline int work_on_pltgot(struct _dl_handle*dh) { if ((dh->plt_rel)&&(!(dh->flags&RTLD_NOW))) { unsigned long*tmp=dh->pltgot; /* GOT */ tmp[0]+=(unsigned long)dh->mem_base; /* reloc dynamic pointer */ tmp[1] =(unsigned long)dh; /* the handle */ tmp[2] =(unsigned long)(_dl_jump); /* sysdep jump to do_resolve */ } return 0; } #elif defined(__x86_64__) #warning "x86_64 is not tested yet..." asm(".text \n" ".type _start,@function \n" "_start: \n" " movq %rsp,%rbp # save stack \n" " movq (%rbp), %rdi # argc \n" " leaq 8(%rbp),%rsi # argv \n" " leaq 8(%rsi,%rdi,8),%rdx # envp \n" " leaq _DYNAMIC(%rip), %rcx # relocated address of _DYNAMIC \n" /* call _dl_main */ " call _dl_main \n" /* restore stack */ " movq %rbp, %rsp \n" /* get fini pointer */ " movq fini_entry(%rip), %rdx \n" /* clear callee-save-register like kernel */ " xorq %rbp,%rbp \n" /* jump to program entry point */ " jmpq *%rax \n" ".type _dl_sys_read,@function \n" "_dl_sys_read: \n" " movb $0,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_write,@function \n" "_dl_sys_write: \n" " movb $1,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_open,@function \n" "_dl_sys_open: \n" " movb $2,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_close,@function \n" "_dl_sys_close: \n" " movb $3,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_fstat,@function \n" "_dl_sys_fstat: \n" " movb $5,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_mmap,@function \n" "_dl_sys_mmap: \n" " movb $9,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_mprotect,@function \n" "_dl_sys_mprotect: \n" " movb $10,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_munmap,@function \n" "_dl_sys_munmap: \n" " movb $11,%al \n" " jmp _dl_sys_call3 \n" ".type _dl_sys_exit,@function \n" "_dl_sys_exit: \n" " movb $60,%al \n" ".type _dl_sys_call3,@function \n" "_dl_sys_call3: \n" " movzbq %al,%rax \n" " movq %rcx,%r10 \n" " syscall \n" " retq \n" ".type _dl_jump,@function \n" "_dl_jump: \n" /* save register arguments */ " pushq %rax \n" " pushq %rdi \n" " pushq %rsi \n" " pushq %rdx \n" " pushq %rcx \n" " pushq %r8 \n" " pushq %r9 \n" /* dynlib handle */ " movq 56(%rsp),%rdi \n" /* dyntab entry = 24*(index) */ " movq 64(%rsp),%rsi \n" " leaq (%rsi,%rsi,2),%rsi \n" " shlq $3,%rsi \n" /* call resolver */ " call do_resolve \n" /* save return value */ " movq %rax,%r11 \n" /* restore register args */ " popq %r9 \n" " popq %r8 \n" " popq %rcx \n" " popq %rdx \n" " popq %rsi \n" " popq %rdi \n" " popq %rax \n" /* remove arguments from plt */ " addq $16,%rsp \n" /* jump to REAL function */ " jmpq *%r11 \n" ); static inline unsigned long* get_got(void) { unsigned long*ret; asm("lea _GLOBAL_OFFSET_TABLE_(%%rip),%0" : "=r"(ret) ); return ret; } static inline int work_on_pltgot(struct _dl_handle*dh) { if ((dh->plt_rel)&&(!(dh->flags&RTLD_NOW))) { unsigned long*tmp=dh->pltgot; /* GOT */ tmp[0]+=(unsigned long)dh->mem_base; /* reloc dynamic pointer */ tmp[1] =(unsigned long)dh; /* the handle */ tmp[2] =(unsigned long)(_dl_jump); /* sysdep jump to do_resolve */ } return 0; } #elif defined(__arm__) asm(".text \n" ".type _start,function \n" "_start: \n" /* common startup */ " mov r4, sp @ save stack pointer \n" " mov fp, #0 @ start new stack frame \n" " ldr a1, [sp], #4 @ argc \n" " mov a2, sp @ argv \n" " mov sp, r4 @ restore stack pointer \n" " add a3, a2, a1, lsl #2 @ envp \n" " add a3, a3, #4 \n" /* PIC code startup */ " ldr sl, .L_got @ PIC code \n" "1: add sl, pc, sl \n" /* get loadaddress */ " ldr a4, [sl] \n" " sub a4, sl, a4 \n" " str a4, [sp,#-4]! \n" /* get 'relocated' address of _DYNAMIC */ " ldr a4, .L_dy \n" " add a4, a4, sl \n" /* call _dl_main */ " bl _dl_main \n" /* save program entry point */ " mov lr, a1 \n" /* abi: agrument 1: global fini entry */ " ldr a1, [pc, #.L_fe-(.+8)] \n" " ldr a1, [sl, a1] \n" /* jump to program entry point */ " mov pc, lr \n" /* startup-code data */ ".L_got: .long _GLOBAL_OFFSET_TABLE_-(1b+8) \n" ".L_dy: .long _DYNAMIC(GOTOFF) \n" ".L_fe: .long fini_entry(GOTOFF) \n" ".type _dl_sys_exit,function \n" "_dl_sys_exit: \n" " swi #0x900001 @ exit \n" " eor pc, lr, lr @ OR DIE ! \n" " mov pc, lr \n" ".type _dl_sys_read,function \n" "_dl_sys_read: \n" " swi #0x900003 @ read \n" " mov pc, lr \n" ".type _dl_sys_write,function \n" "_dl_sys_write: \n" " swi #0x900004 @ write \n" " mov pc, lr \n" ".type _dl_sys_open,function \n" "_dl_sys_open: \n" " swi #0x900005 @ open \n" " mov pc, lr \n" ".type _dl_sys_close,function \n" "_dl_sys_close: \n" " swi #0x900006 @ close \n" " mov pc, lr \n" ".type _dl_sys_mmap,function \n" "_dl_sys_mmap: \n" " stmdb sp!,{r0,r1,r2,r3} \n" " mov r0, sp \n" " swi #0x90005a @ mmap \n" " add sp, sp, #16 \n" " mov pc, lr \n" ".type _dl_sys_munmap,function \n" "_dl_sys_munmap: \n" " swi #0x90005b @ munmap \n" " mov pc, lr \n" ".type _dl_sys_fstat,function \n" "_dl_sys_fstat: \n" " swi #0x90006c @ fstat \n" " mov pc, lr \n" ".type _dl_sys_mprotect,function \n" "_dl_sys_mprotect: \n" " swi #0x90007d @ mprotect \n" " mov pc, lr \n" ".type _dl_jump,function \n" "_dl_jump: \n" " stmdb sp!, {r0, r1, r2, r3} @ save arguments \n" " sub r1, ip, lr @ dyntab entry \n" " sub r1, r1, #4 \n" " add r1, r1, r1 \n" " ldr r0, [lr, #-4] @ dynlib handle \n" " bl do_resolve \n" " mov r12, r0 \n" " ldmia sp!, {r0, r1, r2, r3, lr} @ restore arguments \n" " mov pc, r12"); static inline unsigned long* get_got(void) { register unsigned long *got asm ("sl"); return got; } static inline int work_on_pltgot(struct _dl_handle*dh) { if ((dh->plt_rel)&&(!(dh->flags&RTLD_NOW))) { unsigned long*tmp=dh->pltgot; /* GOT */ tmp[0]+=(unsigned long)dh->mem_base; /* reloc dynamic pointer */ tmp[1] =(unsigned long)dh; /* the handle */ tmp[2] =(unsigned long)(_dl_jump); /* sysdep jump to do_resolve */ } return 0; } #elif defined(__sparc__) #warning "sparc is not working !!! AND HAS NO RESOLVER !!!" /* ARG... sparc has EVERY variable (even static) only addressable through the GOT */ asm(".text \n" ".align 16 \n" ".global _start \n" ".hidden _start \n" ".type _start,@function \n" "_start: \n" /* save some later needed values */ " mov %sp, %l0 \n" " mov %g1, %l1 \n" /* close frame / make room for some arguments */ " mov %g0, %fp \n" " sub %sp, 6*4, %sp \n" /* extrace argc(%o0), argv(%o1), envp(%o2) */ " ld [%sp+22*4], %o0 \n" " add %sp, 23*4, %o1 \n" " add %o1, %o0, %o2 \n" " add %o2, %o0, %o2 \n" " add %o2, %o0, %o2 \n" " add %o2, %o0, %o2 \n" " add %o2, 4, %o2 \n" /* PIC code / startup */ " sethi %hi(_GLOBAL_OFFSET_TABLE_-4), %l7 \n" ".L0: call .L1 \n" " add %l7, %lo(_GLOBAL_OFFSET_TABLE_+4), %l7 \n" ".L1: add %o7, %l7, %l7 \n" /* get load-address (%o4) */ " sethi %hi(.L0), %o4 \n" " add %o4, %lo(.L0), %o4 \n" " ld [ %l7 + %o4 ], %o4 \n" " sub %o7, %o4, %o4 \n" /* get 'relocated' address of _DYNAMIC (%o3) // call the dynamic linker */ " ld [ %l7 ], %o3 \n" //" call _dl_main \n" " call _pr_ping \n" " add %o4, %o3, %o3 \n" /* put entry point to the return register */ " mov %o0, %o7 \n" /* restore some values // 'jump' to entry point */ " mov %l1, %g1 \n" " retl \n" " mov %l0, %sp \n" "_pr_ping_str: \n" " .asciz \"ping.\\n\" \n" ".align 4 \n" "_pr_ping: \n" " save \n" "1: call 1f \n" " mov _pr_ping_str-1b, %i1 \n" "1: add %o7, %i1, %i1 \n" " restore \n" " mov 6, %o2 \n" " call _dl_sys_write \n" " mov 2, %o0 \n" " call _dl_sys_exit \n" " mov 0, %o0 \n" ".type _dl_sys_exit,@function \n" "_dl_sys_exit: \n" " mov 1, %g1 \n" ".type _dl_sys_call3,@function \n" "_dl_sys_call3: \n" " ta 0x10 \n" " retl \n" " nop \n" ".type _dl_sys_read,@function \n" "_dl_sys_read: \n" " b _dl_sys_call3 \n" " mov 3, %g1 \n" ".type _dl_sys_write,@function \n" "_dl_sys_write: \n" " b _dl_sys_call3 \n" " mov 4, %g1 \n" ".type _dl_sys_open,@function \n" "_dl_sys_open: \n" " b _dl_sys_call3 \n" " mov 5, %g1 \n" ".type _dl_sys_close,@function \n" "_dl_sys_close: \n" " b _dl_sys_call3 \n" " mov 6, %g1 \n" ".type _dl_sys_mmap,@function \n" "_dl_sys_mmap: \n" " b _dl_sys_call3 \n" " mov 71, %g1 \n" ".type _dl_sys_munmap,@function \n" "_dl_sys_munmap: \n" " b _dl_sys_call3 \n" " mov 73, %g1 \n" ".type _dl_sys_fstat,@function \n" "_dl_sys_fstat: \n" " b _dl_sys_call3 \n" " mov 62, %g1 \n" ".type _dl_sys_mprotect,@function \n" "_dl_sys_mprotect: \n" " b _dl_sys_call3 \n" " mov 74, %g1 \n" ".type _dl_jump,@function \n" "_dl_jump: \n" " ret \n" ); static inline unsigned long* get_got(void) { register unsigned long *got asm ("%l7"); return got; } static inline int work_on_pltgot(struct _dl_handle*dh) { if ((dh->plt_rel)&&(!(dh->flags&RTLD_NOW))) { unsigned long*tmp=dh->pltgot; /* GOT */ tmp[0]+=(unsigned long)dh->mem_base; /* reloc dynamic pointer */ tmp[1] =(unsigned long)dh; /* the handle */ tmp[2] =(unsigned long)(_dl_jump); /* sysdep jump to do_resolve */ } return 0; } #else #error "libdl: arch not supported" #endif static void*_dl_load(const char*fn,const char*pathname,int fd,int flags); /* here do the code includes */ /* strncpy */ static char*_dl_lib_strncpy(register char*s,register const char*t,register unsigned long n) { char *dest=s; for(;n;--n) { char ch=*t; *s=ch; if (ch==0) return dest; ++s; ++t; } return 0; } /* strlen.c */ static unsigned long _dl_lib_strlen(register const char*s) { register unsigned long i; if (!s) return 0; for (i=0; *s; ++s) ++i; return i; } /* strcmp.c */ static int _dl_lib_strcmp(register const unsigned char*s,register const unsigned char*t) { register char x; for (;;) { x = *s; if (x != *t) break; if (!x) break; ++s; ++t; } return ((int)(unsigned int)x) - ((int)(unsigned int)*t); } /* strcspn.c */ static unsigned long _dl_lib_strcspn(const char*s,const char*reject) { unsigned long l=0; int a=1,i,al=_dl_lib_strlen(reject); while((a)&&(*s)) { for(i=0;(a)&&(i>=4) { register unsigned long v='0'|(l&15); if (v>'9') v+=0x27; buf[--i]=v; } _dl_sys_write(2,buf,max); } /* the never free strdup (internal) */ static unsigned long _dl_lib_strdup_len=0; static char*_dl_lib_strdup_str; static char*_dl_lib_strdup(const char*s) { char*ret=_dl_lib_strdup_str; unsigned long l=_dl_lib_strlen(s)+1; if (_dl_lib_strdup_lennext) { pf("link_map "); ph((unsigned long)tmp); pf(" l_addr "); ph((unsigned long)tmp->mem_base); pf(" l_name "); pf(tmp->l_name ? tmp->l_name : ""); pf(" l_ld "); ph((unsigned long)tmp->dynamic); pf("\n"); } #endif } #endif /* now reuse some unchanged sources */ #ifdef __arm__ #include "_dl_math.c" #define MOD(a,b) _dl_mod(a,b) #define DIV(a,b) _dl_div(a,b,NULL) #else #define MOD(a,b) (a % b) #define DIV(a,b) (a / b) #endif #include "dlerror.c" #include "_dl_alloc.c" #include "dlsym.c" #include "dladdr.c" #include "_dl_search.c" #include "_dl_open.c" #include "dlopen.c" #include "_dl_relocate.c" #include "_dl_queue.c" #include "dlclose.c" /* back to the "new" implementation */ static void tt_fini(void) { struct _dl_handle*tmp; #ifdef DEBUG pf("dyn fini\n"); #endif for(tmp=_dl_root_handle;tmp;tmp=tmp->next) if (tmp->fini) tmp->fini(); } /* exit ! */ __attribute__((noreturn)) static void _DIE_() { _dl_sys_exit(213); } /* lazy function resolver */ unsigned long do_resolve(struct _dl_handle*dh,unsigned long off) { _dl_rel_t *tmp = ((void*)dh->plt_rel)+off; int sym=ELF_R_SYM(tmp->r_info); register unsigned long sym_val; if (0) sym_val=(unsigned long)do_resolve; /* TRICK: no warning */ /* modify GOT for REAL symbol */ sym_val=(unsigned long)_dl_sym(dh,sym); *((unsigned long*)(dh->mem_base+tmp->r_offset))=sym_val; /* JUMP (arg sysdep...) */ if (sym_val) return sym_val; /* can't find symbol */ return (unsigned long)_DIE_; } /* library loader */ /* ELF -> MMAP permissions */ static inline int map_flags(int flags) { int perm = 0; if (flags & PF_X) perm|=PROT_EXEC; if (flags & PF_R) perm|=PROT_READ; if (flags & PF_W) perm|=PROT_WRITE; return perm; } /* a simple mmap wrapper */ static inline void*do_map_in(void*base,unsigned long length,int flags,int fd,unsigned long offset) { register int op = MAP_PRIVATE; if (base) op|=MAP_FIXED; return _dl_sys_mmap(base, length, map_flags(flags), op, fd, offset); } /* map a library into memory */ #define _ELF_DWN_ROUND(ps,n) ((n)&(~((ps)-1))) #define _ELF_UP_ROUND(ps,n) ((((n)&((ps)-1))?(ps):0)+_ELF_DWN_ROUND((ps),(n))) #define _ELF_RST_ROUND(ps,n) ((n)&((ps)-1)) static struct _dl_handle*_dl_map_lib(const char*fn,const char*pathname,int fd,int flags) { struct _dl_handle*ret=0; int i; unsigned char buf[1024]; char *m=0,*d=0; unsigned long l; struct stat st; Elf_Ehdr*eeh; Elf_Phdr*eph; int ld_nr=0; Elf_Phdr*ld[4]; Elf_Phdr*dyn=0; _dl_lib_memset(ld,0,sizeof(ld)); if (fd==-1) return 0; if (_dl_sys_fstat(fd,&st)<0) { err_out_close: _dl_sys_close(fd); _dl_error_data=fn; _dl_error=2; return 0; } else { /* use st_dev and st_ino for identification */ } if (_dl_sys_read(fd,buf,1024)<128) goto err_out_close; eeh=(Elf_Ehdr*)buf; eph=(Elf_Phdr*)&buf[eeh->e_phoff]; for (i=0;ie_phnum;++i) { if (eph[i].p_type==PT_LOAD) { if (ld_nr>3) goto err_out_close; ld[ld_nr++]=eph+i; } if (eph[i].p_type==PT_DYNAMIC) { dyn=eph+i; } } if (ld_nr==1) { unsigned long addr =_ELF_DWN_ROUND(at_pagesize,ld[0]->p_vaddr); unsigned long offset=_ELF_DWN_ROUND(at_pagesize,ld[0]->p_offset); unsigned long off =_ELF_RST_ROUND(at_pagesize,ld[0]->p_offset); unsigned long length=_ELF_UP_ROUND(at_pagesize,ld[0]->p_memsz+off); ret=_dl_get_handle(); m=(char*)do_map_in((void*)addr,length,ld[0]->p_flags,fd,offset); if (m==MAP_FAILED) goto err_out_free; /* zero pad bss */ l=ld[0]->p_offset+ld[0]->p_filesz; _dl_lib_memset(m+l,0,length-l); ret->mem_base=m; ret->mem_size=length; } else if (ld_nr==2) { /* aem... yes Quick & Really Dirty / for the avarage 99% */ unsigned long text_addr = _ELF_DWN_ROUND(at_pagesize,ld[0]->p_vaddr); unsigned long text_offset=_ELF_DWN_ROUND(at_pagesize,ld[0]->p_offset); unsigned long text_off =_ELF_RST_ROUND(at_pagesize,ld[0]->p_offset); unsigned long text_size =_ELF_UP_ROUND(at_pagesize,ld[0]->p_memsz+text_off); unsigned long data_addr =_ELF_DWN_ROUND(at_pagesize,ld[1]->p_vaddr); unsigned long data_offset=_ELF_DWN_ROUND(at_pagesize,ld[1]->p_offset); unsigned long data_off =_ELF_RST_ROUND(at_pagesize,ld[1]->p_offset); unsigned long data_size =_ELF_UP_ROUND(at_pagesize,ld[1]->p_memsz+data_off); unsigned long data_fsize =_ELF_UP_ROUND(at_pagesize,ld[1]->p_filesz+data_off); /* handle data_addr relative to text_addr */ data_addr-=text_addr; ret=_dl_get_handle(); /* mmap all mem_blocks for *.so */ m=(char*)do_map_in((void*)text_addr,text_size+data_size,ld[0]->p_flags,fd,text_offset); if (m==MAP_FAILED) { err_out_free: _dl_free_handle(ret); _dl_sys_close(fd); return 0; } /* are we loaded where we wanna be ? */ if (text_addr && (m!=(void*)text_addr)) { _dl_sys_munmap(m,text_size+data_size); goto err_out_free; } /* release data,bss part */ _dl_sys_mprotect(m+data_addr,data_size,PROT_NONE); /* mmap data,bss part */ d=(char*)do_map_in(m+data_addr,data_fsize,ld[1]->p_flags,fd,data_offset); /* zero pad bss */ l=data_off+ld[1]->p_filesz; _dl_lib_memset(d+l,0,data_fsize-l); /* more bss ? */ if (data_size>data_fsize) { l=data_size-data_fsize; _dl_sys_mmap(d+data_fsize,l,PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS,-1,0); } ret->mem_base=m; ret->mem_size=text_size+data_size; } else { _dl_error_data=fn; _dl_error=7; } if (ret) { ++ret->lnk_count; if (flags&RTLD_USER) { ret->l_name=strdup(pathname); ret->name=strdup(fn); } else { ret->l_name=_dl_lib_strdup(pathname); ret->name=_dl_lib_strdup(fn); } ret->flags=flags; ret->dynamic=(Elf_Dyn*)(m+dyn->p_vaddr); } _dl_sys_close(fd); return ret; } /* dynamic section parser */ static struct _dl_handle* _dl_dyn_scan(struct _dl_handle*dh,Elf_Dyn*_dynamic) { void(*init)(void)=0; _dl_rel_t* plt_rel=0; unsigned long plt_relsz=0; _dl_rel_t* rel=0; unsigned long relent=0; unsigned long relsize=0; int i; #ifdef DEBUG pf(__FUNCTION__); pf(": pre dynamic scan "); ph((unsigned long)dh); pf("\n"); #endif for(i=0;_dynamic[i].d_tag;++i) { switch(_dynamic[i].d_tag) { /* this depends on dyn_str_tab -> second run */ case DT_NEEDED: case DT_SONAME: break; /* BASIC DYNAMIC STUFF */ case DT_HASH: dh->hash_tab = (unsigned int*)(dh->mem_base+_dynamic[i].d_un.d_ptr); #ifdef DEBUG pf(__FUNCTION__); pf(": have hash @ "); ph((long)dh->hash_tab); pf("\n"); #endif break; case DT_SYMTAB: dh->dyn_sym_tab = (Elf_Sym*)(dh->mem_base+_dynamic[i].d_un.d_ptr); #ifdef DEBUG pf(__FUNCTION__); pf(": have dyn_sym_tab @ "); ph((long)dh->dyn_sym_tab); pf("\n"); #endif break; case DT_STRTAB: dh->dyn_str_tab = (char*)(dh->mem_base+_dynamic[i].d_un.d_ptr); #ifdef DEBUG pf(__FUNCTION__); pf(": have dyn_str_tab @ "); ph((long)dh->dyn_str_tab); pf("\n"); #endif break; case DT_GNU_HASH: dh->gnu_hash_tab = (unsigned int*)(dh->mem_base+_dynamic[i].d_un.d_ptr); #ifdef DEBUG pf(__FUNCTION__); pf(": have GNU-hash @ "); ph((long)dh->gnu_hash_tab); pf("\n"); #endif break; /* DYNAMIC INIT/FINI (constructors/destructors) */ case DT_FINI: dh->fini = (void(*)(void))(dh->mem_base+_dynamic[i].d_un.d_val); #ifdef DEBUG pf(__FUNCTION__); pf(": have fini @ "); ph((long)dh->fini); pf("\n"); #endif break; case DT_INIT: init = (void(*)(void))(dh->mem_base+_dynamic[i].d_un.d_val); #ifdef DEBUG pf(__FUNCTION__); pf(": have init @ "); ph((long)init); pf("\n"); #endif break; /* PLT RELOCATION */ case DT_PLTGOT: dh->pltgot = (unsigned long*)(dh->mem_base+_dynamic[i].d_un.d_val); #ifdef DEBUG pf(__FUNCTION__); pf(": have plt/got @ "); ph((long)dh->pltgot); pf("\n"); #endif break; case DT_PLTREL: if (_dynamic[i].d_un.d_val!=_DL_REL_T) { #ifdef DEBUG pf(__FUNCTION__); pf(": have incompatible relocation type\n"); #endif _dl_error_data=dh->name; _dl_error=6; return 0; } break; case DT_JMPREL: plt_rel = (_dl_rel_t*)(dh->mem_base+_dynamic[i].d_un.d_val); dh->plt_rel = plt_rel; #ifdef DEBUG pf(__FUNCTION__); pf(": have jmprel @ "); ph((long)plt_rel); pf("\n"); #endif break; case DT_PLTRELSZ: plt_relsz = _dynamic[i].d_un.d_val; #ifdef DEBUG pf(__FUNCTION__); pf(": have pltrelsize @ "); ph((long)plt_relsz); pf("\n"); #endif break; /* BASIC RELOCATION */ case DT_REL: case DT_RELA: rel = (_dl_rel_t*)(dh->mem_base+_dynamic[i].d_un.d_val); #ifdef DEBUG pf(__FUNCTION__); pf(": have rel @ "); ph((long)rel); pf("\n"); #endif break; case DT_RELENT: case DT_RELAENT: relent=_dynamic[i].d_un.d_val; #ifdef DEBUG pf(__FUNCTION__); pf(": have relent @ "); ph((long)relent); pf("\n"); #endif break; case DT_RELSZ: case DT_RELASZ: relsize=_dynamic[i].d_un.d_val; #ifdef DEBUG pf(__FUNCTION__); pf(": have relsize @ "); ph((long)relsize); pf("\n"); #endif break; /* TEXT RELOCATIONS POSSIBLE -> NO SHARED OBJECT */ case DT_TEXTREL: #ifdef DEBUG pf(__FUNCTION__); pf(": found possible textrelocation -> "); pf(dh->name); pf(" is not compiled as a shared library\n"); #endif _dl_error_data=dh->name; _dl_error=3; return 0; break; /* OTHERS */ default: #ifdef DEBUG #if 0 pf(__FUNCTION__); pf(": unknown "); ph(_dynamic[i].d_tag); pf(", "); ph(_dynamic[i].d_un.d_val); pf("\n"); #endif #endif break; } } for(i=0;_dynamic[i].d_tag;i++) { if (dh->name) { /* librabry can have a SONAME */ if (_dynamic[i].d_tag==DT_SONAME) { #ifdef DEBUG pf(__FUNCTION__); pf(": pre soname: "); pf(dh->name); pf("\n"); #endif if (dh->flags&RTLD_USER) free(dh->name); dh->flags&=~RTLD_NOSONAME; dh->name = dh->dyn_str_tab+_dynamic[i].d_un.d_val; #ifdef DEBUG pf(__FUNCTION__); pf(": have soname: "); pf(dh->name); pf("\n"); #endif } } else { /* programs can have a LD_RUN_PATH */ if (_dynamic[i].d_tag==DT_RPATH) { register char *rpath=dh->dyn_str_tab+_dynamic[i].d_un.d_val; _dl_search_rpath=rpath; #ifdef DEBUG pf(__FUNCTION__); pf(": have runpath: "); pf(rpath); pf("\n"); #endif } } } #ifdef DEBUG pf(__FUNCTION__); pf(": post dynamic scan "); ph((unsigned long)dh); pf("\n"); #endif if (work_on_pltgot(dh)) { _dl_error_data=dh->name; _dl_error=3; return 0; } #ifdef DEBUG pf(__FUNCTION__); pf(": pre load depending libraries "); ph((unsigned long)dh); pf("\n"); #endif /* load depending libs */ for(i=0;_dynamic[i].d_tag;++i) { if (_dynamic[i].d_tag==DT_NEEDED) { char *lib_name=dh->dyn_str_tab+_dynamic[i].d_un.d_val; #ifdef DEBUG pf(__FUNCTION__); pf(": needed for this lib: "); pf(lib_name); pf("\n"); #endif _dl_queue_lib(lib_name,dh->flags); } } #ifdef DEBUG pf(__FUNCTION__); pf(": pre open depending libraries 2 "); ph((unsigned long)dh); pf("\n"); #endif if (_dl_open_dep()) { return 0; } #ifdef DEBUG pf(__FUNCTION__); pf(": post load depending libraries, pre resolve "); ph((unsigned long)dh); pf("\n"); #endif /* relocation */ if (rel) { #ifdef DEBUG pf(__FUNCTION__); pf(": try to relocate some values\n"); #endif if (_dl_relocate(dh,rel,DIV(relsize,relent))) return 0; } /* do PTL / GOT relocation */ if (plt_rel) { _dl_rel_t *tmp,*max=((void*)plt_rel)+plt_relsz; #ifdef DEBUG pf(__FUNCTION__); pf(": rel plt/got\n"); #endif for(tmp=plt_rel;tmpflags&RTLD_NOW)) { unsigned long sym=(unsigned long)_dl_sym(dh,ELF_R_SYM(tmp->r_info)); if (sym) *((unsigned long*)(dh->mem_base+tmp->r_offset))=sym; else { _dl_error_data=dh->name; _dl_error=4; return 0; } } else _DL_REL_PLT(dh->mem_base,tmp); #ifdef DEBUG pf(__FUNCTION__); pf(": rel @ "); ph((long)dh->mem_base+tmp->r_offset); pf(" with type "); ph(ELF_R_TYPE(tmp->r_info)); pf(" and sym "); ph(ELF_R_SYM(tmp->r_info)); pf(" -> "); ph(*((unsigned long*)(dh->mem_base+tmp->r_offset))); pf("\n"); #endif } } #ifdef DEBUG pf(__FUNCTION__); pf(": post resolve, pre init "); ph((unsigned long)dh); pf("\n"); #endif if (init) init(); #ifdef DEBUG pf(__FUNCTION__); pf(": post init "); ph((unsigned long)dh); pf("\n"); #endif return dh; } static void*_dl_load(const char*fn,const char*pathname,int fd,int flags) { struct _dl_handle*ret=0; if ((ret=_dl_map_lib(fn,pathname,fd,flags))) { ret=_dl_dyn_scan(ret,ret->dynamic); #ifdef WANT_LD_SO_GDB_SUPPORT if (ret) { _r_debug.r_state=RT_ADD; _dl_debug_state(); _r_debug.r_state=RT_CONSISTENT; _dl_debug_state(); } #endif } return ret; } /* ELF AUX parser */ static void _dl_elfaux(register unsigned long*ui) { register struct elf_aux { unsigned long type; unsigned long val; } *ea; while (*ui) ++ui; /* now *ui points to the tailing NULL-pointer of the envirioment */ /* walk the elf_aux table */ for (ea=(struct elf_aux*)(ui+1); ea->type; ++ea) { switch (ea->type) { case AT_EXECFD: /* 2 */ /* DIE! DIE! DIE! */ pf("kernel gives us an unsupported binary load type...\n"); _dl_sys_exit(42); break; case AT_PHDR: /* 3 */ prog_ph=(Elf_Phdr*)ea->val; #ifdef DEBUG pf("program header @ "); ph(ea->val); pf("\n"); #endif break; case AT_PHENT: /* 4 */ prog_ph_size=ea->val; #ifdef DEBUG pf("program header size "); ph(ea->val); pf("\n"); #endif break; case AT_PHNUM: /* 5 */ prog_ph_num=ea->val; #ifdef DEBUG pf("program header # "); ph(ea->val); pf("\n"); #endif break; case AT_PAGESZ: /* 6 */ at_pagesize=ea->val; #ifdef DEBUG pf("page size "); ph(ea->val); pf("\n"); #endif break; case AT_BASE: /* 7 */ loadaddr=ea->val; #ifdef DEBUG pf("interpreter base: "); ph(ea->val); pf("\n"); #endif break; #if 0 case AT_FLAGS: /* 8 */ #ifdef DEBUG pf("flags "); ph(ea->val); pf("\n"); #endif break; #endif case AT_ENTRY: /* 9 */ prog_entry=ea->val; #ifdef DEBUG pf("start program @ "); ph(ea->val); pf("\n"); #endif break; case AT_NOTELF: /* 10 */ pf("this is an ELF-loader... and therefor can't handle anything else.\n"); _dl_sys_exit(42); break; case AT_UID: /* 11 */ at_uid=ea->val; #ifdef DEBUG pf(" UID: "); ph(ea->val); pf("\n"); #endif break; case AT_EUID: /* 12 */ at_euid=ea->val; #ifdef DEBUG pf("EUID: "); ph(ea->val); pf("\n"); #endif break; case AT_GID: /* 13 */ at_gid=ea->val; #ifdef DEBUG pf(" GID: "); ph(ea->val); pf("\n"); #endif break; case AT_EGID: /* 14 */ at_egid=ea->val; #ifdef DEBUG pf("EGID: "); ph(ea->val); pf("\n"); #endif break; #if 0 case AT_PLATFORM: /* 15 */ #ifdef DEBUG pf("CPU: "); ph(ea->val); pf("\n"); #endif break; case AT_HWCAP: /* 16 */ #ifdef DEBUG pf("CPU capabilities: "); ph(ea->val); pf("\n"); #endif break; case AT_CLKTCK: /* 17 */ #ifdef DEBUG pf("CLK per sec "); ph( ea->val); pf("\n"); #endif break; case AT_FPUCW: /* 18 */ #ifdef DEBUG pf("FPU control word "); ph( ea->val); pf("\n"); #endif break; #endif case AT_SYSINFO: /* TODO: rewrite unified syscall to use this value */ default: break; } } } /* start of libdl dynamic linker */ unsigned long _dl_main(int argc,char*argv[],char*envp[],unsigned long _dynamic) { unsigned long*got; struct _dl_handle*prog,*mydh; struct _dl_handle my_dh; Elf_Dyn*prog_dynamic=0; unsigned int i; if (0) _dl_main(argc,argv,envp,_dynamic); /* TRICK: no warning */ /* prepare to bootstarp the relocations */ got=get_got(); _dl_environ=envp; /* run elf_aux (kernel provided misc data) */ _dl_elfaux((unsigned long*)envp); if (loadaddr==0) { pf("\ndiet libdl.so/dynamic-linker can't be started as a program !\n\n SORRY...\n\n"); return (unsigned long)_DIE_; } _dl_lib_memset(&my_dh,0,sizeof(my_dh)); my_dh.mem_base=(char*)loadaddr; my_dh.mem_size=0; my_dh.lnk_count=1024; my_dh.l_name=0; /* filled in later from PT_INTERP */ my_dh.name="libdl.so"; my_dh.flags=LDSO_FLAGS; got[1]=0; /* NOT YET (my_dh) */ got[2]=(unsigned long)_DIE_; /* NO lazy symbol resolver as long as we are not ready */ #ifdef DEBUG pf(__FUNCTION__); pf(": pre scan\n"); #endif /* bootstrap relocation */ if (_dl_dyn_scan(&my_dh,(Elf_Dyn*)_dynamic)==0) { pf("error with dyn_scan myself\n"); return (unsigned long)_DIE_; } #ifdef DEBUG pf(__FUNCTION__); pf(": post scan\n"); #endif /* now we are save to use anything :) (hopefully) */ fini_entry=tt_fini; prog=_dl_get_handle(); #ifdef DEBUG pf(__FUNCTION__); pf(": ugly, ugly, COPY pregenerated handle to real handle\n"); #endif mydh=_dl_get_handle(); { register struct _dl_handle*tmp=mydh->prev; _dl_lib_memcpy(mydh,&my_dh,sizeof(struct _dl_handle)); mydh->prev=tmp; } got[1]=(unsigned long)mydh; #ifdef DEBUG pf(__FUNCTION__); pf(": MORE ugly: prepare program...\n"); #endif for(i=0;(il_name=(char*)prog_ph[i].p_vaddr; } } if (prog_dynamic==0) { ph(0xe0000001); pf(" error with program: no dynamic section ?\n"); return (unsigned long)_DIE_; } prog->l_name=0; prog->name=0; prog->lnk_count=1024; prog->dynamic=prog_dynamic; prog->flags=LDSO_FLAGS; #ifdef DEBUG pf(__FUNCTION__); pf(": dyn_scan program...\n"); #endif if (_dl_dyn_scan(prog,(Elf_Dyn*)prog_dynamic)==0) { _dl_error_location="error in dyn_scan the program"; pf(dlerror()); pf("\n"); return (unsigned long)_DIE_; } #ifdef WANT_LD_SO_GDB_SUPPORT _r_debug.r_version=1; _r_debug.r_map=_dl_root_handle; _r_debug.r_brk=(void*)&_dl_debug_state; _r_debug.r_state=RT_CONSISTENT; _r_debug.r_ldbase=loadaddr; if (prog_dynamic) { for (i=0;prog_dynamic[i].d_tag;++i) if (prog_dynamic[i].d_tag==DT_DEBUG) { prog_dynamic[i].d_un.d_ptr=(Elf_Addr)&_r_debug; #ifdef DEBUG pf(__FUNCTION__); pf(": set DT_DEBUG @ "); ph(prog_dynamic[i].d_un.d_val); pf("\n"); #endif } } _dl_debug_state(); #endif /* now start the program */ #ifdef DEBUG pf(__FUNCTION__); pf(": now jump to program entrypoint\n"); #endif return prog_entry; } #endif dietlibc-0.33~cvs20120325/libdl/_dl_math.c010064400000000000000000000010701173363226500147050ustar00static unsigned long _dl_div( unsigned long num, unsigned long den, unsigned long * rem) { unsigned long quot = 0, qbit = 1; if (den == 0) return 0; /* Left-justify denominator and count shift */ while ((int) den >= 0) { den <<= 1; qbit <<= 1; } while (qbit) { if (den <= num) { num -= den; quot += qbit; } den >>= 1; qbit >>= 1; } if (rem) *rem = num; return quot; } static unsigned long _dl_mod(unsigned long num, unsigned long den) { unsigned long rem; _dl_div(num, den, &rem); return rem; } dietlibc-0.33~cvs20120325/libdl/_dl_open.c010064400000000000000000000012211173363226500147130ustar00#include #include #include #ifndef __DIET_LD_SO__ #include #endif #include "_dl_int.h" #ifdef __DIET_LD_SO__ static #endif void*_dl_open(const char*filename,int flags) { int fd; char buf[PATH_MAX]; const char*p=0; for (fd=0;filename[fd] && (p==0);++fd) if (filename[fd]=='/') p=filename; if (p) { #ifdef __DIET_LD_SO__ if ((fd=_dl_sys_open(p,O_RDONLY,0))<0) fd=-1; #else fd=open(p,O_RDONLY); #endif } else { p=buf; fd=_dl_search(buf,sizeof(buf)-1,filename); } if (fd==-1) { _dl_error_data=filename; _dl_error=1; return 0; } return _dl_load(filename,p,fd,flags); } dietlibc-0.33~cvs20120325/libdl/_dl_queue.c010064400000000000000000000015601173363226500151040ustar00#include #include "_dl_int.h" #define MAX_QUEUE 64 static int _dl_queue_start=0; static int _dl_queue_stop=0; static struct { const char*name; int flags; } _dl_queue[MAX_QUEUE]; #ifdef __DIET_LD_SO__ static #endif int _dl_queue_lib(const char*name,int flags) { struct _dl_handle*ret; if ((ret=_dl_find_lib(name))) ++(ret->lnk_count); else { register int tmp; if ((tmp=_dl_queue_stop+1)>=MAX_QUEUE) tmp=0; if (tmp==_dl_queue_start) return -1; _dl_queue[_dl_queue_stop].name=name; _dl_queue[_dl_queue_stop].flags=flags; _dl_queue_stop=tmp; } return 0; } #ifdef __DIET_LD_SO__ static #endif int _dl_open_dep() { while (_dl_queue_start!=_dl_queue_stop) { int tmp=_dl_queue_start; if (++_dl_queue_start>=MAX_QUEUE) _dl_queue_start=0; if (!_dlopen(_dl_queue[tmp].name,_dl_queue[tmp].flags)) return 1; } return 0; } dietlibc-0.33~cvs20120325/libdl/_dl_rel.c010064400000000000000000000021031173363226500145340ustar00#include #include "_dl_int.h" static void exit_now(void) { #ifdef DEBUG pf(__func__": symbol not found\n"); #endif _exit(212); } unsigned long do_rel(struct _dl_handle * tmp_dl, unsigned long off) { Elf_Rel *tmp = ((void*)tmp_dl->plt_rel)+off; int sym=ELF_R_SYM(tmp->r_info); register unsigned long sym_val; #ifdef DEBUG pf(__func__": "); ph((unsigned long)tmp_dl); pf(" "); ph(off); pf(" on "); ph((long)tmp_dl->plt_rel); pf("\n"); pf(__func__": @ "); ph((long)tmp->r_offset); pf(" with type "); ph(ELF_R_TYPE(tmp->r_info)); pf(" and sym "); ph(sym); pf(" symval "); ph(tmp_dl->dyn_sym_tab[sym].st_value); pf("\n"); #endif /* modify GOT for REAL symbol */ //sym_val=((unsigned long)(tmp_dl->mem_base+tmp_dl->dyn_sym_tab[sym].st_value)); sym_val=(unsigned long)_dl_sym(tmp_dl,sym); *((unsigned long*)(tmp_dl->mem_base+tmp->r_offset))=sym_val; #ifdef DEBUG pf(__func__": sym "); ph(sym_val); pf("\n"); #endif /* JUMP (arg sysdep...) */ if (sym_val) return sym_val; /* can't find symbol -> die now */ return (unsigned long)exit_now; } dietlibc-0.33~cvs20120325/libdl/_dl_rel.h010064400000000000000000000016151173363226500145500ustar00#ifndef ___DL_REL_H__ #define ___DL_REL_H__ #if defined(__arm__) || defined(__i386__) || defined(__mips__) /* this are REL only archs: arm, i386, mips */ #define _dl_rel_t Elf_Rel #define _DL_REL_T DT_REL #define _DL_REL_PLT(b,r) (*(unsigned long*)((b)+(r)->r_offset)+=(unsigned long)(b)) #elif defined(__alpha__) || defined(__hppa__) || defined(__powerpc__) || defined(__sparc__) || defined(__s390__) \ || defined(__x86_64__) /* this are RELA only archs: alpha, chris, hppa, ia64, m68k, ppc, sparc, sparc64, sh, s390, x86_64 */ #define _dl_rel_t Elf_Rela #define _DL_REL_T DT_RELA #define _DL_REL_PLT(b,r) (*(unsigned long*)((b)+(r)->r_offset)+=(unsigned long)(b)) //#define _DL_REL_PLT(b,r) (*(unsigned long*)((b)+(r)->r_offset)=(unsigned long)((b)+(r)->r_addend)) #else /* there are no known linux supported arch with mixed relocation types ... */ #error "_dl_rel.h: NOT SUPPORTED" #endif #endif dietlibc-0.33~cvs20120325/libdl/_dl_relocate.c010064400000000000000000000111531173363226500155550ustar00#include "_dl_int.h" #include "_dl_rel.h" #if 0 /*--- are other relocation types vital to shared objects ? ---*/ R_386_NONE 0 /* No reloc */ R_386_32 1 /* Direct 32 bit */ R_386_COPY 5 /* Copy symbol at runtime ?!? */ R_386_GLOB_DAT 6 /* Create GOT entry */ R_386_JMP_SLOT 7 /* Create PLT entry */ R_386_RELATIVE 8 /* Adjust by program base */ R_X86_64_NONE 0 * No reloc */ R_X86_64_64 1 * Direct 64 bit */ R_X86_64_COPY 5 * Copy symbol at runtime */ R_X86_64_GLOB_DAT 6 * Create GOT entry */ R_X86_64_JUMP_SLOT 7 * Create PLT entry */ R_X86_64_RELATIVE 8 * Adjust by program base */ R_X86_64_32 10 * Direct 32 bit zero extended */ R_ARM_NONE 0 /* No reloc */ R_ARM_ABS32 2 /* Direct 32 bit */ R_ARM_COPY 20 /* Copy symbol at runtime */ R_ARM_GLOB_DAT 21 /* Create GOT entry */ R_ARM_JUMP_SLOT 22 /* Create PLT entry */ R_ARM_RELATIVE 23 /* Adjust by program base */ #endif static int _dl_apply_relocate(struct _dl_handle*dh,_dl_rel_t*rel) { int typ,ret=0; Elf_Addr*loc; loc=(Elf_Addr *)(dh->mem_base+rel->r_offset); #ifdef DEBUG #if 0 pf(__FUNCTION__); pf(": "); ph(ELF_R_TYPE(rel->r_info)); pf(" @ "); ph((unsigned long)loc); pf(" preval "); ph(*(unsigned long*)loc); pf("\n"); #endif #endif typ=ELF_R_TYPE(rel->r_info); #ifdef __i386__ if (typ==R_386_32) { /* 1 */ unsigned long value=(unsigned long)(dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_value); #ifdef DEBUG pf(__func__); pf(" value "); ph(value); pf("\n"); #endif if (value) *loc=(unsigned long)(dh->mem_base+value); else *loc=(unsigned long)_dl_sym(dh,ELF_R_SYM(rel->r_info)); } else if (typ==R_386_COPY) { /* 5 */ unsigned long len=dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_size; void*from=_dl_sym_next(dh,ELF_R_SYM(rel->r_info)); #ifdef DEBUG pf(__FUNCTION__); pf(": R_386_COPY from "); ph((unsigned long)from); pf("\n"); #endif _dl_lib_memcpy(loc,from,len); } else if (typ==R_386_GLOB_DAT) { /* 6 */ *loc=(unsigned long)_dl_sym(dh,ELF_R_SYM(rel->r_info)); } else if (typ==R_386_JMP_SLOT) { /* 7 */ *loc+=(unsigned long)dh->mem_base; } else if (typ==R_386_RELATIVE) { /* 8 */ *loc+=(unsigned long)dh->mem_base; } else if (typ==R_386_NONE) { /* 0 */ } else ret=1; #endif #ifdef __arm__ if (typ==R_ARM_ABS32) { /* 2 */ unsigned long value=(unsigned long)(dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_value); if (value) *loc=(unsigned long)(dh->mem_base+value); else *loc=(unsigned long)_dl_sym(dh,ELF_R_SYM(rel->r_info)); } else if (typ==R_ARM_COPY) { /* 20 */ unsigned long len=dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_size; void*from=_dl_sym_next(dh,ELF_R_SYM(rel->r_info)); #ifdef DEBUG pf(__FUNCTION__); pf(": R_ARM_COPY from "); ph((unsigned long)from); pf("\n"); #endif _dl_lib_memcpy(loc,from,len); } else if (typ==R_ARM_GLOB_DAT) { /* 21 */ *loc=(unsigned long)_dl_sym(dh,ELF_R_SYM(rel->r_info)); } else if (typ==R_ARM_JUMP_SLOT) { /* 22 */ *loc+=(unsigned long)dh->mem_base; } else if (typ==R_ARM_RELATIVE) { /* 23 */ *loc+=(unsigned long)dh->mem_base; } else if (typ==R_ARM_NONE) { /* 0 */ } else ret=1; #endif #ifdef __x86_64__ if (typ==R_X86_64_64) { /* 1 */ unsigned long value=(unsigned long)(dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_value); if (value) *loc=(unsigned long)(dh->mem_base+value); else *loc=(unsigned long)_dl_sym(dh,ELF_R_SYM(rel->r_info)); } else if (typ==R_X86_64_COPY) { /* 5 */ unsigned long len=dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_size; void*from=_dl_sym_next(dh,ELF_R_SYM(rel->r_info)); #ifdef DEBUG pf(__FUNCTION__); pf(": R_X86_64_COPY from "); ph((unsigned long)from); pf("\n"); #endif _dl_lib_memcpy(loc,from,len); } else if (typ==R_X86_64_GLOB_DAT) { /* 6 */ *loc=(unsigned long)_dl_sym(dh,ELF_R_SYM(rel->r_info)); } else if (typ==R_X86_64_JUMP_SLOT) { /* 7 */ *loc=((unsigned long)dh->mem_base)+rel->r_addend; } else if (typ==R_X86_64_RELATIVE) { /* 8 */ *loc=((unsigned long)dh->mem_base)+rel->r_addend; } else if (typ==R_X86_64_32) { /* 10 */ *loc=((unsigned long)(dh->mem_base+dh->dyn_sym_tab[ELF_R_SYM(rel->r_info)].st_value))&0xffffffffUL; } else if (typ==R_X86_64_NONE) { /* 0 */ } else ret=1; #endif #ifdef DEBUG pf(__FUNCTION__); pf(": @ "); ph((unsigned long)loc); pf(" val "); ph(*(unsigned long*)loc); pf("\n"); #endif return ret; } #ifdef __DIET_LD_SO__ static #endif int _dl_relocate(struct _dl_handle*dh,_dl_rel_t *rel,int num) { int i; for (i=0;i #include #include #include "_dl_int.h" #define WANT_LD_SO_CONF_SEARCH static const char *_dl_search_rpath=0; #ifndef __DIET_LD_SO__ #include #include void _dl_set_rpath(const char *path) { _dl_search_rpath=path; } const char* _dl_get_rpath() { return _dl_search_rpath; } #define _dl_lib_memcpy memcpy #endif /* search a colon (semicolon) seperated path for the libraray "filename" */ static int _dl_search_path(char*buf,int len,const char*path,const int pathlen,const char*filename) { int fd,i=1,fl=_dl_lib_strlen(filename),ml=len-fl; const char*c,*pe=path+pathlen; if (path) { for (c=path;cml) continue; /* if len(path-entry)+len(filename)+2 is greater than the buffer ? SKIP */ _dl_lib_memcpy(buf,c,i); buf[i]='/'; l-=++i; } _dl_lib_memcpy(buf+i,filename,fl); buf[i+fl]=0; #ifdef DEBUG // pf(__func__": "); pf(buf); pf("\n"); #endif #ifdef __DIET_LD_SO__ if ((fd=_dl_sys_open(buf,O_RDONLY,0))>-1) return fd; #else if ((fd=open(buf,O_RDONLY))!=-1) return fd; #endif } } return -1; } /* parse the SMALL file "conf" for lib directories (aem... hang me if you can :) ) */ static int _dl_search_conf(char*buf,int len,const char*conf,const char*filename) { char ld_so_conf[1024]; int i,l,fd; #ifdef __DIET_LD_SO__ if ((fd=_dl_sys_open(conf,O_RDONLY,0))>-1) { l=_dl_sys_read(fd,ld_so_conf,sizeof(ld_so_conf)-1); #else if ((fd=open(conf,O_RDONLY))!=-1) { l=read(fd,ld_so_conf,sizeof(ld_so_conf)-1); #endif ld_so_conf[sizeof(ld_so_conf)-1]=0; #ifdef __DIET_LD_SO__ _dl_sys_close(fd); #else close(fd); #endif if (l>0) { if (ld_so_conf[l-1]=='\n') ld_so_conf[--l]=0; for (i=0;inext) if (dh->mem_base<=(char*)addr && (!bestdh||bestdh->mem_basemem_base)) bestdh=dh; return bestdh; } static Elf_Sym*_dl_addr_search_sym(struct _dl_handle*dh,char*addr) { Elf_Sym*bestsym,*sym; /* we assume the string table follows the symbol table (so does glibc) */ for (bestsym=0,sym=dh->dyn_sym_tab;(char*)symdyn_str_tab;++sym) if (dh->mem_base+sym->st_value<=addr && (!bestsym||bestsym->st_valuest_value)) bestsym=sym; return bestsym; } int dladdr(void *addr, Dl_info *info) { struct _dl_handle*dh; dh=_dl_addr_search_dh((char*)addr); if (dh) { Elf_Sym*sym; sym=_dl_addr_search_sym(dh,(char*)addr); if (sym) { info->dli_fname=dh->l_name; info->dli_fbase=dh->mem_base; info->dli_sname=dh->dyn_str_tab+sym->st_name; info->dli_saddr=dh->mem_base+sym->st_value; return 1; } } return 0; } dietlibc-0.33~cvs20120325/libdl/dlclose.c010064400000000000000000000020611173363226500145640ustar00#include #include "_dl_int.h" static void dec_referenced_libs(struct _dl_handle*dh) { Elf_Dyn* dyn_tab=dh->dynamic; int i; for(i=0;dyn_tab[i].d_tag;i++) { if (dyn_tab[i].d_tag==DT_NEEDED) { char *lib_name=dh->dyn_str_tab+dyn_tab[i].d_un.d_val; #ifdef DEBUG pf(__FUNCTION__); pf(": lib: "); pf(lib_name); pf("\n"); #endif dlclose(_dl_find_lib(lib_name)); } } } int dlclose(void*handle) { _dl_error_location="dlclose"; if (handle) { struct _dl_handle*dh=handle; if (--(dh->lnk_count)) return 0; /* not yet unreferenced */ #ifdef DEBUG pf(__FUNCTION__); pf(": "); pf(dh->name); pf("\n"); #endif if (dh->fini) dh->fini(); dec_referenced_libs(dh); #ifdef __DIET_LD_SO__ if (_dl_sys_munmap(dh->mem_base,dh->mem_size)<0) return -1; #else if (munmap(dh->mem_base,dh->mem_size)==-1) return -1; #endif _dl_free_handle(handle); #ifdef WANT_LD_SO_GDB_SUPPORT _r_debug.r_state=RT_DELETE; _dl_debug_state(); _r_debug.r_state=RT_CONSISTENT; _dl_debug_state(); #endif } return 0; } dietlibc-0.33~cvs20120325/libdl/dlerror.c010064400000000000000000000025421173363226500146140ustar00 #include "_dl_int.h" #ifdef __DIET_LD_SO__ static unsigned int _dl_error; static const char*_dl_error_location; static const char*_dl_error_data; #else #include unsigned int _dl_error; const char*_dl_error_location; const char*_dl_error_data; #endif static struct _dl_err_msg { char*msg; int len; } _dl_error_msg[]={ #define MSG(n) { (n), sizeof((n))-1 } MSG("can't open: "), /* 1 */ MSG("can't stat: "), /* 2 */ MSG("shared object is not position independent: "), /* 3 */ MSG("can't resolve all symbols in: "), /* 4 */ MSG("can't find symbol: "), /* 5 */ MSG("invalid relocation type in: "), /* 6 */ MSG("internal error: layout not yet supported: "), /* 7 */ }; const char *dlerror(void) { static char buf[1024],*p=buf; register int l,len=sizeof(buf)-1; if (_dl_error==0) return 0; buf[0]=0; buf[len]=0; --_dl_error; if (_dl_error>=DIV(sizeof(_dl_error_msg),sizeof(struct _dl_err_msg))) return "HAE ?!?"; if (_dl_error_location) { l=_dl_lib_strlen(_dl_error_location); _dl_lib_strncpy(p,_dl_error_location,len); len-=l; p+=l; _dl_lib_strncpy(p,": ",len); len-=2; p+=2; } l=_dl_error_msg[_dl_error].len; _dl_lib_strncpy(p,_dl_error_msg[_dl_error].msg,len); len-=l; p+=l; _dl_lib_strncpy(p,_dl_error_data,len); _dl_error_location=0; _dl_error_data=""; _dl_error=0; return buf; } dietlibc-0.33~cvs20120325/libdl/dlopen.c010064400000000000000000000011261173363226500144210ustar00#include #include #include #include "_dl_int.h" #ifdef __DIET_LD_SO__ static #endif void*_dlopen(const char *filename, int flags) { struct _dl_handle* ret; if (filename) { if ((ret=_dl_find_lib(filename))) { ++(ret->lnk_count); /* add a reference */ return ret; } return _dl_open(filename,flags); } /* return 1 as an indicator for dlsym to search ALL global objects */ return RTLD_DEFAULT; } void*dlopen(const char *filename, int flags) { _dl_error_location="dlopen"; return _dlopen(filename,flags|RTLD_USER|RTLD_NOSONAME); } dietlibc-0.33~cvs20120325/libdl/dlsym.c010064400000000000000000000104721173363226500142740ustar00#include "_dl_int.h" #include "elf_hash.h" #include "gnu_hash.h" static void*_dlsym_elfhash(struct _dl_handle*dh,const unsigned char*symbol) { unsigned long*sym=0; unsigned int hash =elf_hash(symbol); unsigned int bhash=MOD(hash, HASH_BUCKET_LEN(dh->hash_tab)); unsigned int*chain=HASH_CHAIN(dh->hash_tab); unsigned char*name=(unsigned char*)dh->dyn_str_tab; unsigned int ind=HASH_BUCKET(dh->hash_tab)[bhash]; #ifdef DEBUG // pf(__FUNCTION__); pf(": bucket("); ph(bhash); pf(",\""); pf(symbol); pf("\")\n"); // pf(__FUNCTION__); pf(": chain ("); ph(ind); pf(",\""); pf(symbol); pf("\")\n"); #endif while(ind) { int ptr=dh->dyn_sym_tab[ind].st_name; #ifdef DEBUG // pf(__FUNCTION__); pf(": symbol(\""); pf(name+ptr); pf("\",\""); pf(symbol); pf("\")\n"); #endif if (_dl_lib_strcmp(name+ptr,symbol)==0 && dh->dyn_sym_tab[ind].st_value!=0) { if (dh->dyn_sym_tab[ind].st_shndx!=SHN_UNDEF) { sym=(unsigned long*)(dh->mem_base+dh->dyn_sym_tab[ind].st_value); break; /* ok found ... */ } } ind=chain[ind]; } #ifdef DEBUG pf(__FUNCTION__); pf(": symbol \""); pf(symbol); pf("\" @ "); ph((long)sym); pf("\n"); #endif return sym; } static void*_dlsym_gnuhash(struct _dl_handle*dh,const unsigned char*symbol) { unsigned long*sym=0; unsigned char*name=(unsigned char*)dh->dyn_str_tab; unsigned int hash =gnu_hash(symbol); unsigned int bhash=MOD(hash, GNU_HASH_BUCKET_LEN(dh->hash_tab)); unsigned int ind =GNU_HASH_BUCKET(dh->gnu_hash_tab,bhash); #ifdef DEBUG //pf(__FUNCTION__); pf(": bucket("); ph(bhash); pf(",\""); pf(symbol); pf("\")\n"); //pf(__FUNCTION__); pf(": chain ("); ph(ind); pf(",\""); pf(symbol); pf("\")\n"); #endif if (ind!=0xffffffff) { unsigned int*chain=GNU_HASH_CHAIN(dh->gnu_hash_tab,ind); unsigned int idx=chain[0]; unsigned int i,nr=chain[1]; chain+=2; for (i=0;idyn_sym_tab[idx+i].st_name; #ifdef DEBUG //pf(__FUNCTION__); pf(": symbol(\""); pf(name+ptr); pf("\",\""); pf(symbol); pf("\")\n"); #endif if (_dl_lib_strcmp(name+ptr,symbol)==0 && dh->dyn_sym_tab[idx+i].st_value!=0) { if (dh->dyn_sym_tab[ind].st_shndx!=SHN_UNDEF) { sym=(unsigned long*)(dh->mem_base+dh->dyn_sym_tab[idx+i].st_value); break; } } } } } #ifdef DEBUG pf(__FUNCTION__); pf(": symbol \""); pf(symbol); pf("\" @ "); ph((long)sym); pf("\n"); #endif return sym; } #ifdef __DIET_LD_SO__ static #endif void *_dlsym(void* handle,const unsigned char* symbol) { if (handle) { struct _dl_handle*dh=(struct _dl_handle*)handle; // if the GNU hash-table is present... use it. if (dh->gnu_hash_tab) return _dlsym_gnuhash(dh,symbol); else return _dlsym_elfhash(dh,symbol); } return 0; } #ifdef __DIET_LD_SO__ static #endif void*_dl_sym_search_str(struct _dl_handle*dh_begin,const unsigned char*name) { void *sym=0; struct _dl_handle*tmp; #ifdef DEBUG pf(__FUNCTION__); pf(": search for: "); pf(name); pf("\n"); #endif for (tmp=dh_begin;tmp && (!sym);tmp=tmp->next) { // if (!(tmp->flags&RTLD_GLOBAL)) continue; #ifdef DEBUG pf(__FUNCTION__); pf(": searching in "); pf(tmp->name); pf("\n"); #endif sym=_dlsym((void*)tmp,name); #ifdef DEBUG if (sym) { pf(__FUNCTION__); pf(": found: "); pf(name); pf(" @ "); ph((long)sym); pf("\n"); } #endif } return sym; } #ifdef __DIET_LD_SO__ static #endif void*_dl_sym(struct _dl_handle*dh,int symbol) { char *name=dh->dyn_str_tab+dh->dyn_sym_tab[symbol].st_name; void*sym=_dl_sym_search_str(_dl_root_handle,(const unsigned char*)name); #ifdef DEBUG pf(__FUNCTION__); pf(": "); ph(symbol); pf(" -> "); ph((long)sym); pf("\n"); #endif return sym; } #ifdef __DIET_LD_SO__ static #endif void*_dl_sym_next(struct _dl_handle*dh,int symbol) { char *name=dh->dyn_str_tab+dh->dyn_sym_tab[symbol].st_name; void*sym=_dl_sym_search_str(dh->next,(const unsigned char*)name); #ifdef DEBUG pf(__FUNCTION__); pf(": "); ph(symbol); pf(" -> "); ph((long)sym); pf("\n"); #endif return sym; } void* dlsym(void* handle,const char* symbol) { void*h; if (handle==RTLD_DEFAULT || !handle /* RTLD_DEFAULT is NULL on glibc */ ) h=_dl_sym_search_str(0,(const unsigned char*)symbol); else h=_dlsym(handle,(const unsigned char*)symbol); if (h==0) { _dl_error_location="dlsym"; _dl_error_data=symbol; _dl_error=5; } return h; } dietlibc-0.33~cvs20120325/libdl/elf_hash.h010064400000000000000000000003061173363226500147150ustar00static unsigned int elf_hash(const unsigned char *name) { unsigned int h=0, g; while (*name) { h = (h<<4) + *(name++); if ((g = h&0xf0000000)) h ^= g>>24; h ^= g; } return h; } dietlibc-0.33~cvs20120325/libdl/gnu_hash.h010064400000000000000000000004211173363226500147360ustar00#ifndef __GNU_HASH_H__ #define __GNU_HASH_H__ #include static uint_fast32_t gnu_hash(const unsigned char *s) { unsigned char c; uint_fast32_t h=5381; for(c=*s;(c!='\0');c=*++s) { // h=h*33+c; h=((h<<5)+h)+c; } return (h&0xffffffff); } #endif dietlibc-0.33~cvs20120325/libdl/test/test.c010064400000000000000000000005421173363226500150770ustar00#include int main(int argc, char **argv) { void *Hlib; // if (Hlib=dlopen("libtest.so", RTLD_LAZY)) { if (Hlib=dlopen("libtest.so", RTLD_NOW)) { void (*t)(void) = dlsym(Hlib,"test"); if (t) { printf("test @ %08lx\n",(long)t); t(); } dlclose(Hlib); } else { printf("%s\n",dlerror()); } return 0; } dietlibc-0.33~cvs20120325/libdl/test/test_so.c010064400000000000000000000001331173363226500155740ustar00 int* test(); int err =(int)test ; int* test() { write(1,"helo\n",5); return &err; } dietlibc-0.33~cvs20120325/liblatin1/latin1-iscntrl.c010064400000000000000000000001541173363226500165750ustar00#include int iscntrl(int x) { unsigned char c=x&0xff; return (c<32) || (c>=127 && c<=160); } dietlibc-0.33~cvs20120325/liblatin1/latin1-isgraph.c010064400000000000000000000001541173363226500165540ustar00#include int isgraph(int x) { unsigned char c=x&0xff; return (c>=33 && c<=126) || c>=161; } dietlibc-0.33~cvs20120325/liblatin1/latin1-islower.c010064400000000000000000000001701173363226500166010ustar00#include int islower(int c) { unsigned char x=c&0xff; return (x>='a' && x<='z') || (x>=223 && x!=247); } dietlibc-0.33~cvs20120325/liblatin1/latin1-isprint.c010064400000000000000000000001551173363226500166100ustar00#include int isprint(int x) { unsigned char c=x&0xff; return (c>=32 && c<=126) || (c>=160); } dietlibc-0.33~cvs20120325/liblatin1/latin1-isupper.c010064400000000000000000000002021173363226500166000ustar00#include int isupper(int c) { unsigned char x=c&0xff; return (x>='A' && x<='Z') || (x>=192 && x<=222 && x!=215); } dietlibc-0.33~cvs20120325/libm/acosh.c010064400000000000000000000001321173363226500140660ustar00#include double acosh ( double x ) { return log ( x + sqrt (x*x - 1.) ); } dietlibc-0.33~cvs20120325/libm/asinh.c010064400000000000000000000001321173363226500140730ustar00#include double asinh ( double x ) { return log ( x + sqrt (x*x + 1.) ); } dietlibc-0.33~cvs20120325/libm/atanh.c010064400000000000000000000001741173363226500140720ustar00#include extern const float __half; double atanh ( double x ) { return __half * log ( (1.+x) / (1.-x) ); } dietlibc-0.33~cvs20120325/libm/bessel.c010064400000000000000000000105711173363226500142560ustar00/*--------------------------------------------------------------------------* Name j0, j1, jn - Bessel functions y0, y1, yn - Weber functions Usage double j0 (double x); double j1 (double x); double jn (int n, double x); double y0 (double x); double y1 (double x); double yn (int n, double x); Prototype in math.h Description j0, j1 and jn calculate the Bessel function. y0, y1 and yn calcualte the Weber function. Return value return their return values as doubles. *---------------------------------------------------------------------------*/ #include #define M_C 0.5772156649015328 #if 0 #define M_1_PI 0.318309886183790671538 #define M_2_PI 0.636619772367581343076 #define M_PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342117067982148 #endif #define EXPL(x) ((((short *)(void *)&x)[4] & 0x7FFF) >> 0) #define EXPD(x) ((((short *)(void *)&x)[3] & 0x7FF0) >> 4) #define EXPF(x) ((((short *)(void *)&x)[1] & 0x7F80) >> 7) #define SQUARE(x) (long) (My - (x) * (x) ) static long double P ( int My, double* x ) { long double Sum = 0.; long double Fact = 1.; long double z182 = -0.015625 / (x[0] * x[0]); register int i; for ( i = 1; ; i += 2 ) { Fact *= SQUARE(i+i-1) * SQUARE(i+i+1) * z182 / (i*(i+1)); if ( EXPL (Fact) < 0x3FFF-53 ) break; Sum += Fact; } return 1. + Sum; } static long double Q ( int My, double* x ) { long double Fact = (My-1) / x[0] * 0.125; long double Sum = Fact; long double z182 = -0.015625 / (x[0]*x[0]); register int i; for ( i = 2; ; i += 2 ) { Fact *= SQUARE(i+i-1) * SQUARE(i+i+1) * z182 / (i*(i+1)); if ( EXPL (Fact) < 0x3FFF-53 ) break; Sum += Fact; } return Sum; } static long double ___jn ( int n, double* x ) { long double Sum; long double Fact; long double y; register int i; double xx; long double Xi; int My; if ( n < 0 ) return n & 1 ? ___jn (-n, x) : -___jn (-n, x); if ((x[0] >= 17.7+0.0144*(n*n))) { Xi = x[0] - M_PI * (n*0.5 + 0.25); My = n*n << 2; return sqrt ( M_2_PI/x[0] ) * ( P(My,x) * cos(Xi) - Q(My,x) * sin(Xi) ); } xx = x[0] * 0.5; Sum = 0.; Fact = 1.; y = -xx * xx; for ( i = 1; i <= n; i++ ) Fact *= xx/i; for ( i = 1; ; i++ ) { Sum += Fact; Fact *= y / (i*(n+i)); if ( EXPL (Sum) - EXPL(Fact) > 53 || !EXPL(Fact) ) break; } return Sum; } static long double ___yn ( int n, double* x ) { long double Sum1; long double Sum2; long double Fact1; long double Fact2; long double F1; long double F2; long double y; register int i; double xx; long double Xi; unsigned int My; if ( EXPD (x[0]) == 0 ) return -1./0.; /* ignore the gcc warning, this is intentional */ if ( (x[0] >= (n>=32 ? 25.8 : (n<8 ? 17.4+0.1*n : 16.2+0.3*n))) ) { Xi = x[0] - M_PI * (n*0.5+0.25); My = n*n << 2; return sqrt ( M_2_PI / x[0] ) * ( P(My,x) * sin(Xi) + Q(My,x) * cos(Xi) ); } Sum1 = Sum2 = F1 = F2 = 0; Fact1 = 1. / (xx = x[0] * 0.5 ); Fact2 = 1.; y = xx*xx; for ( i = 1; i < n; i++ ) Fact1 *= (n-i) / xx; for ( i = 1; i <= n; i++ ) { Sum1 += Fact1; if ( i == n ) break; Fact1 *= y/(i*(n-i)); } for (i=1; i<=n; i++) { Fact2 *= xx / i; F1 += 1. / i; } for ( i = 1; ; i++ ) { Sum2 += Fact2 * (F1+F2); Fact2 *= -y / (i*(n+i)); if ( EXPL (Sum2) - EXPL (Fact2) > 53 || !EXPL (Fact2) ) break; F1 += 1. / (n+i); F2 += 1. / i; } return M_1_PI * (2. * (M_C + log(xx)) * ___jn (n, x) - Sum1 - Sum2); } double j0 ( double x ) { return ___jn ( 0,&x ); } double j1 ( double x ) { return ___jn ( 1,&x ); } double jn ( int n, double x ) { return ___jn ( n,&x ); } double y0 ( double x ) { return ___yn ( 0,&x ); } double y1 ( double x ) { return ___yn ( 1,&x ); } double yn ( int n, double x ) { return ___yn ( n,&x ); } dietlibc-0.33~cvs20120325/libm/cosh.c010064400000000000000000000002141173363226500137260ustar00#include extern const float __half; double cosh ( double x ) { long double y = exp (x); return (y + 1./y) * __half; } dietlibc-0.33~cvs20120325/libm/erf.c010064400000000000000000000311041173363226500135500ustar00#include "dietlibm.h" /*--------------------------------------------------------------------------* z 1 | -x²/2 Name erf(z) = --------- | e dx sqrt(2pi) | 0 oo 1 | -x²/2 erfc(z) = -------- | e dx sqrt(2pi) | z Usage double erf (double x); double erfc(double x); Prototype in math.h Description erf(x) is the probability a normal distributed event occures within the range [0,x]. erfc(x) is the probability a normal distributed event occures within the range [x,oo]. Return value return their respective function value. *---------------------------------------------------------------------------*/ /* even function in (0): Coefficients for gamma(0) */ static const double tab1 [9 + 1] = { 0.398942280401432677926, -0.066490380066905446321, 9.97355701003581694794E-3, -1.18732821548045439878E-3, 1.15434687616155288764E-4, -9.44465625950361453450E-6, 6.65969351631665127484E-7, -4.12266741486268888409E-8, 2.27352982437280636972E-9, -1.13011716416192129505E-10 }; /* non even or odd function in (x), x>0: Coefficients for gamma(x), x>0 */ static const double tab2 [] [31 + 1] = { { -0.158655253931457051468, +0.241970724519143349823, -0.120985362259571674911, 0, +0.0201642270432619458197, -4.03284540865238916394E-3, -2.01642270432619458197E-3, +7.68161030219502697887E-4, +1.20025160971797296538E-4, -8.80184513793180174807E-5, -1.86705805956129127862E-6, +7.37124220917704609315E-6, -4.72826391707080259142E-7, -4.83395817951682973566E-7, +6.57036391970156141055E-8, +2.5544260402922190768E-8, -5.4292285616752144141E-9, -1.08932444506260820153E-9, +3.44399256708718202774E-10, +3.6021429664641554881E-11, -1.81147204852239925966E-11, -7.66935128389784976374E-13, +8.19047721646461768154E-13, -3.78144699611990981391E-15, -3.24856460059989147863E-14, +1.44438130842455313227E-15, +1.14391687912824634892E-15, -9.38053726039148625184E-17, -3.59908648108845288945E-17, +4.36020846676166022246E-18, +1.01298640134330880603E-18, -1.68640470512244526894E-19 }, { -0.0227501319481792072104, +0.0539909665131880519553, -0.0539909665131880519553, +0.0269954832565940259776, -4.49924720943233766301E-3, -2.24962360471616883129E-3, +1.34977416282970129877E-3, -1.17837426913704081544E-4, -1.15159303574756261652E-4, +3.70473728554448438507E-5, +2.82690796888936559912E-6, -3.54513195524355369855E-6, +3.76695631261094890352E-7, +1.92024079214184701051E-7, -5.22690859049557191018E-8, -4.91799344974114749666E-9, +3.66377919234006038965E-9, -1.5981997209104676352E-10, -1.73812379171063320997E-10, +2.62403075313043113473E-11, +5.60918720760414713346E-12, -1.72126983666416144614E-12, -8.63428809787622525331E-14, +7.89441765474563834480E-14, -3.13747960081562321348E-15, -2.77519506625391157547E-15, +3.29321944203493138076E-16, +7.44375150395529134369E-17, -1.66428523299294690222E-17, -1.32735612757620496568E-18, +6.24122437514304644794E-19, +1.12471123532438919306E-21 }, { -1.3498980316300945272E-3, +4.43184841193800717687E-3, -6.64777261790701076574E-3, +5.90913121591734290293E-3, -3.32388630895350538287E-3, +1.10796210298450179421E-3, -1.10796210298450179595E-4, -8.44161602273906129349E-5, +4.35270826172482847927E-5, -6.30190085030867423515E-6, -1.9785037553294674925E-6, +1.05520200284238266374E-6, -1.13913852579575399458E-7, -4.81174572974454799623E-8, +1.78216871733806513653E-8, -5.85637697215219690327E-10, -9.29791350219350980904E-10, +1.96377023046901260016E-10, +1.58870373467897094393E-11, -1.22699105512396660364E-11, +1.08794270836433192571E-12, +3.99646995170699427940E-13, -1.01594404465456044793E-13, -3.33469605506835759271E-15, +4.46588935876766499879E-15, -4.08076707607833277747E-16, -1.17808602368979218862E-16, +2.76224909899945482352E-17, +1.09206599392049874162E-18, -1.03145418746203977253E-18, +6.79984672177279963209E-20, +2.55831283729070534712E-20 }, { -3.16712418331199212695E-5, +1.33830225764885351832E-4, -2.67660451529770703664E-4, +3.34575564412213379613E-4, -2.89965489157251595673E-4, +1.8178605666396926958E-4, -8.25286392216793003064E-5, +2.55180251904870680833E-5, -3.91665839292075186649E-6, -7.40182052221464123606E-7, +6.44220233592652481453E-7, -1.73701553397390201613E-7, +9.09595464817154590424E-9, +9.44943118114780783705E-9, -3.29957075383376125942E-9, +2.94920746951281580686E-10, +1.18744773902482360274E-10, -4.42039585809856402486E-11, +3.61422484008923382324E-12, +1.43638335494248833511E-12, -4.58476794992724591068E-13, +2.23496663226445199624E-14, +1.57839046076890756440E-14, -3.67258220998453293248E-15, -1.69716269032291432153E-17, +1.43497778353923791279E-16, -2.14499365995613073838E-17, -1.93255135682867953692E-18, +1.01377499752128183701E-18, -7.55713215369572830154E-20, -2.25510650946079103289E-20, +5.26633993110171917109E-21 }, { -2.86651571879193912033E-7, +1.48671951473429770924E-6, -3.7167987868357442731E-6, +5.9468780589371908374E-6, -6.81413110919886450076E-6, +5.92209940035828587496E-6, -4.02653201907205629582E-6, +2.17108246596119665457E-6, -9.25512396325170449452E-7, +3.03096091545533908077E-7, -6.92802772105295808398E-8, +6.69226396924248971087E-9, +2.46006252876483997508E-9, -1.41806830376639605249E-9, +3.44251040657349801884E-10, -2.6965166176434937652E-11, -1.16546962748761528049E-11, +4.91490145086991326748E-12, -7.55854519365765424197E-13, -4.53988828124843593484E-14, +4.71533558309731405623E-14, -9.17323049919073092370E-15, +4.35542982587998484108E-17, +3.71238868922011013332E-16, -7.90772907386322623053E-17, +1.58463483904927528072E-18, +2.61503941976309571331E-18, -5.40699423853895351239E-19, +6.61825040533797444037E-21, +1.68378440730394776550E-20, -3.01930850797704474581E-21, -3.80658085177617928332E-23 }, { -9.8658764503769814198E-10, +6.07588284982328549581E-9, -1.82276485494698564874E-8, +3.54426499573024987263E-8, -5.01260335110421053478E-8, +5.48348427196551516061E-8, -4.81513715848495375522E-8, +3.47446467489597046263E-8, -2.08994095347716137282E-8, +1.0554987922587771203E-8, -4.4752674615729637229E-9, +1.57746505810079893253E-9, -4.49697115294871911476E-10, +9.63210042443717269402E-11, -1.16300711402336909847E-11, -1.31070037808191623761E-12, +1.16993345829435057496E-12, -3.40636420312606285351E-13, +5.23724821541706939045E-14, +3.93541148139975862961E-16, -2.59886413069218394637E-15, +7.24729556829529838503E-16, -8.51485747763574768020E-17, -7.86503719948806184368E-18, +5.35986191777031053618E-18, -9.84873767617830925356E-19, +2.93759678710573738811E-20, +2.85458592629073152182E-20, -7.12725445137377009753E-21, +5.25419393758902871947E-22, +1.24299023131490990316E-22, -4.04419210566489645405E-23 }, { -1.27981254388583500631E-12, +9.1347204083645933588E-12, -3.19715214292760767584E-11, +7.30777632669167468738E-11, -1.22557498812224960902E-10, +1.60618833847077433236E-10, -1.71047639646627010648E-10, +1.51926349902927316213E-10, -1.14609023345779936276E-10, +7.43697341394886835864E-11, -4.18713451557949730558E-11, +2.05606050331840905587E-11, -8.82161466664564577599E-12, +3.30031395277698236679E-12, -1.06851205331295409813E-12, +2.94333808755089195146E-13, -6.64411715537625335642E-14, +1.11264855981436243262E-14, -8.52918435682649455145E-16, -2.38837813662069487819E-16, +1.23994634366691956599E-16, -3.05269770279941723219E-17, +4.34539596489459676621E-18, -5.55819387468189608390E-20, -1.56974672263484202926E-19, +4.60835492190702561464E-20, -6.61112150617493330405E-21, +7.28424268476803924831E-23, +2.09156005934313228089E-22, -5.29080328670107625978E-23, +5.61375000671507211726E-24, +3.82199410465700894394E-25 }, { -6.22096057427178413283E-16, +5.05227108353689229741E-15, -2.02090843341475691883E-14, +5.30488463771373691202E-14, -1.02729512031916810045E-13, +1.56409892294496290711E-13, -1.94849254788406146283E-13, +2.04064637342166989709E-13, -1.83187931471980616892E-13, +1.42994099344605424348E-13, -9.8111907789286062426E-14, +5.96545975367403288587E-14, -3.23370114040930933005E-14, +1.56932853967230342257E-14, -6.83548101324218922896E-15, +2.67410077774155118457E-15, -9.38313996431647887562E-16, +2.94090734842381109313E-16, -8.16448235152204729921E-17, +1.9758222496699617607E-17, -4.03590262164308783690E-18, +6.43662361965717426956E-19, -5.93446415094778572090E-20, -6.07164564350191039536E-21, +4.38906686886388095825E-21, -1.17175498170220204828E-21, +1.98482140750318604418E-22, -1.70803571702439545981E-23, -1.94600332107885234554E-24, +1.10477141319981582738E-24, -2.31975718243847439962E-25, +2.54148402104633283670E-26 }, { -1.12858840595384064928E-19, +1.02797735716689148111E-18, -4.62589810725101166456E-18, +1.37063647622252197466E-17, -3.0068337697131575822E-17, +5.2067053140503053517E-17, -7.40914680178037035E-17, +8.9062000172830588611E-17, -9.22563786210983011008E-17, +8.35975730487397716492E-17, -6.70372487553237232779E-17, +4.80088566412770650047E-17, -3.09280630297969106245E-17, +1.8026496052333452774E-17, -9.54924880090907168481E-18, +4.61362333444861021959E-18, -2.03812361224098073479E-18, +8.24578860830779678155E-19, -3.0572087552697254564E-19, +1.03827313453936543577E-19, -3.22407758977306397999E-20, +9.12052549039695437376E-21, -2.33541947993595580264E-21, +5.35339963891271164659E-22, -1.07674173853083520575E-22, +1.82413373046113374293E-23, -2.33864726317468746329E-24, +1.29928813344150027051E-25, +3.86668349205203745336E-26, -1.63203452712600670685E-26, +3.65165372186699607411E-27, -5.51243539825332137371E-28 }, { -7.61985302416052609616E-24, +7.69459862670641937159E-23, -3.84729931335320968601E-22, +1.26960877340655919637E-21, -3.10990027829384449637E-21, +6.02935924057670511377E-21, -9.6342786971886625897E-21, +1.30454744197246721374E-20, -1.52745988785284834672E-20, +1.57034665186695273938E-20, -1.43457243961336621961E-20, +1.17567385540485497556E-20, -8.7104848256363928121E-21, +5.87137214731944288587E-21, -3.61951956727412561213E-21, +2.04954715001535632502E-21, -1.06982832733527370879E-21, +5.1628428354196120786E-22, -2.30885865897937993512E-22, +9.58556229281154921137E-23, -3.69911125531027884646E-23, +1.32784897023484841369E-23, -4.43433027366044567275E-24, +1.37688611947822111040E-24, -3.96971995397574368025E-25, +1.06008163579031271153E-25, -2.61149430849477426613E-26, +5.89698164189548613154E-27, -1.20793190886658723050E-27, +2.20446342551066852143E-28, -3.46061447029252398335E-29, +4.28913922246949096952E-30 } }; static const double tab3 [8] = { +1, -1, +3, -15, +105, -945, +10395, -135135.0 }; /* Calculated: oo 1 | -x²/2 gauss(z) = --------- | e dx sqrt(2pi) | z gauss ( 0) = 0.5 gauss ( 1) ~ 0.1586 gauss ( 2) ~ 0.02275 gauss ( 4) ~ 3.17e-5 gauss (10) ~ 7.62e-24 gauss (oo) = 0 Note: only for z>0 */ #include #include #define M_1_SQRT2PI 0.398942280401432686 static long double gauss ( double x ) { unsigned int i = (unsigned int)(x + 0.5); double y = x * x; if ( i > 150 ) return 0.; if ( i > 10 ) return M_1_SQRT2PI * exp (-0.5*y) / x * __poly (1./y, 7, tab3); if ( i > 0 ) return -__poly ((x-i), 31, tab2 [i-1]); return 0.5 - x * __poly (y, 9, tab1); } double erf ( double x ) { return x < 0. ? -0.5 + gauss(-x) : 0.5 - gauss(x); } double erfc ( double x ) { return x < 0. ? 1.0 - gauss(-x) : gauss(x); } dietlibc-0.33~cvs20120325/libm/gamma.c010064400000000000000000000060221173363226500140570ustar00#include "dietlibm.h" /*--------------------------------------------------------------------------* Name gamma, lgamma - gamma function Usage double gamma (double x); double lgamma(double x); extern int signgam; Prototype in math.h Description gamma returns the logarithm of the absolute value of the gamma function. So it is possible â(x) for very large x. The sign is stored in signgam, a extern variable overwritten during every call to gamma(). lgamma() is a synonym for gamma(). You can calculate â(x) by the following sequence: double gammafunction(double x) { double y=exp(gamma(x)); return signgam ? -y : +y; } Return value gamma returns a value in range (-0.1208, +oo). For a input value of zero, it returns +oo and errno is set to: ERANGE Result out of range *---------------------------------------------------------------------------*/ #include #include #define B0 + 1.0l/ 6/ 1/ 2 #define B1 - 1.0l/ 30/ 3/ 4 #define B2 + 1.0l/ 42/ 5/ 6 #define B3 - 1.0l/ 30/ 7/ 8 #define B4 + 5.0l/ 66/ 9/10 #define B5 - 691.0l/2730/11/12 #define B6 + 7.0l/ 6/13/14 #define B7 - 3617.0l/ 510/15/16 #define B8 + 43867.0l/ 798/17/18 #define B9 - 174611.0l/ 330/19/20 #define B10 + 854513.0l/ 138/21/22 #define B11 - 236364091.0l/2730/23/24 #define B12 + 8553103.0l/ 6/25/26 static const double coeff[] = { B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10 }; int signgam; #define EXPL(x) (((short *)(void *)&x)[4] & 0x7FFF) static double logfact ( long double x ) { long double z = 2. * M_PI * x; register int e = EXPL (x); static unsigned char list [] = { 6, 4, 3, 3, 2, 2 }; return (log(x) - 1) * x + 0.5*log(z) + __poly (1./(x*x), e<0x4003 ? 10 : (e>0x4008 ? 1 : list [e-0x4003] ), coeff) / x; } double lgamma ( double x ) { register int k = floor (x); long double w; long double y; long double z; signgam = 0; if ( k >= 7 ) return logfact (x-1); if ( k == x ) switch (k) { case 1 : case 2 : return 0.000000000000000000000000000l; case 3 : return 0.693147180559945309432805516l; case 4 : return 1.791759469228055000858148560l; case 5 : return 3.178053830347945619723759592l; case 6 : return 4.787491742782045994244981560l; default: return 1./0.; /* ignore the gcc warning, this is intentional */ } z = logfact (y = x - k + 7.0 - 1); w = 1; for ( k = 7 - k; k--; ) w *= y, y -= 1.; signgam = k >= 0 ? 0 : k & 1; return z - log (w); } double gamma ( double val ) __attribute__ ((weak,alias("lgamma"))); dietlibc-0.33~cvs20120325/libm/ipow.c010064400000000000000000000011431173363226500137520ustar00#define _GNU_SOURCE #include /* * This is not standard, but often you only need such this function * which is much shorter than the generic pow() function. * * double ipow ( double mant, int expo ); */ double ipow ( double mant, int expo ) { double ret = 1.; unsigned int e = expo; /* Some attention is necessary for expo = 2^31 */ if ( (int)e < 0 ) { e = -e; mant = 1./mant; } while (1) { if ( e & 1 ) ret *= mant; if ( (e >>= 1) == 0 ) break; mant *= mant; } return ret; } dietlibc-0.33~cvs20120325/libm/modf.c010064400000000000000000000002201173363226500137140ustar00#include double modf(double x, double *iptr) { double fmod_result = fmod(x,1.0); *iptr = x - fmod_result; return fmod_result; } dietlibc-0.33~cvs20120325/libm/poly.c010064400000000000000000000020031173363226500137530ustar00/*--------------------------------------------------------------------------* Name __poly - generates a polynomial from arguments Usage double __poly ( double x, int n, const double* c ); Prototype in math.h Description __poly generates a polynomial in x, of degree n, with coefficients c[0], c[1], ..., c[n]. For example, if n=4, the generated polynomial is c[4]*x^4 + c[3]*x^3 + c[2]*x^2 + c[1]*x + c[0] The polynomial is calculated using Horner's method: polynom = (..((x*c[n] + c[n-1])*x + c[n-2])..)*x + c[0] Return value __poly returns the value of the polynomial as evaluated for the given x. A range error occurs if the result exceeds double range. *---------------------------------------------------------------------------*/ #include #include "dietlibm.h" double __poly ( double x, size_t n, const double* c) { long double ret; size_t i; i = n; c += n; ret = 0; do ret = ret * x + *c--; while ( i-- ); return ret; } dietlibc-0.33~cvs20120325/libm/pow.c010064400000000000000000000014631173363226500136060ustar00 #include #include "dietlibm.h" double pow ( double mant, double expo ) { unsigned int e; long double ret; /* special cases 0^x */ if ( mant == 0. ) { if ( expo > 0. ) return 0.; else if ( expo == 0. ) return 1.; else return 1./mant; } /* special cases x^n with n is integer */ if ( expo == (int) (e = (int) expo) ) { if ( (int)e < 0 ) { e = -e; mant = 1./mant; } ret = 1.; while (1) { if ( e & 1 ) ret *= mant; if ( (e >>= 1) == 0 ) break; mant *= mant; } return ret; } /* normal case */ return exp ( log (mant) * expo ); } dietlibc-0.33~cvs20120325/libm/rint.c010064400000000000000000000001041173363226500137440ustar00#include double rint(double x) { return floor(x+0.5); } dietlibc-0.33~cvs20120325/libm/sinh.c010064400000000000000000000002141173363226500137330ustar00#include extern const float __half; double sinh ( double x ) { long double y = exp (x); return (y - 1./y) * __half; } dietlibc-0.33~cvs20120325/libm/tanh.c010064400000000000000000000001631173363227000137230ustar00#include double tanh ( double x ) { long double y = exp (x + x); return (y - 1.) / (y + 1.); } dietlibc-0.33~cvs20120325/libpthread/.cvsignore010064400000000000000000000001301173363227000160120ustar00*.o *.a *.oa *.out test-basic test-threads_busy test-threads_busy_inc test-threads_many dietlibc-0.33~cvs20120325/libpthread/CHANGES010064400000000000000000000075361173363227000150260ustar00This is the pthread implementation of dietlibc. Written from scratch by Olaf Dreesen. Wed Sep 17 17:03:57 CEST 2003 - add the semaphore support. (changed the internals of the manager a little for this.) - fixed pthread_create so that it does not change the global thread cancel-type on error. Mon Aug 18 17:32:52 CEST 2003 checkin. Mon Aug 18 17:27:57 CEST 2003 more preparations for checkin Sat Aug 16 17:35:25 CEST 2003 more cleanup. prepare for checkin Thu Aug 14 14:16:22 CEST 2003 minor cleanups... Wed Jul 23 16:05:28 CEST 2003 last SIGSEGV found and fixed TODO: - test everything in the real-world :) Wed Jul 7 19:34:02 CEST 2003 new algorithm lead to SIGSEGV on a busy system.... TODO: - fix the SIGSEGV Wed Jun 4 18:55:18 CEST 2003 cleanup the internal functions (fewer calls to __thread_self()) TODO: - test the "hash" based find algorithm Wed May 21 13:48:56 CEST 2003 TODO: - use a better algorithm to find a thread (act. O(n)) Mon May 19 14:40:55 CEST 2003 - the 2.5+ kernel do a SIGKILL on ALL threads if one makes a "critical" error (SIG{SEGV,FPE,...}) Wed Apr 30 16:31:10 CEST 2003 FIXED: - cancellation points... - warning about structure initialization Wed Apr 23 19:02:38 CEST 2003 WORKING STUFF: - basic pthread functions are working. - fork with pthread_atfork handlers working. - unix signales are working (per thread). If a thread is terminated by the default signalhandler (exit on signal) the same signal is send to all threads. (e.g. SIGSEGV,SIGFPE,...) TODO: - async cancelation: manager lock-up (no idea for a fix yet) Wed Feb 19 20:20:20 CET 2003 changed the __thread_self function to use the machine specific register instead of the __buildin_frame_pointer; because the least is !? NOT !? the stack-pointer if we omit the frame-pointer... TODO: no changes since last time Wed Feb 12 16:04:36 CET 2003 the basic functions are working now. TODO: - async cancelation manager lock-up fix - UNIX-signal test Thu Aug 29 16:37:18 MEST 2002 total rewrite complete... - signal handling is now more like the standard says - use signals for restart(join,) and cancel events - depends on working clone,sig{set,long}jmp and __testandset Mon Aug 19 20:40:31 MEST 2002 The signal handling is/was broken... Changed the internal structure a bit (or better total rewrite) Mon Aug 6 15:46:39 MEST 2001 Ups... did the wrong error handling... the error is returned not put to errno... probably thread_key is not SMP save... Thu Apr 12 16:47:12 MEST 2001 added conditional variables... except pthread_cond_timedwait all should work man-page like pthread_cond_timedwait dosen't handle cancel request according to man-page added thread specific key handling (all according to man-page) Fri Mar 30 18:47:37 MEST 2001 uff found some logic errors and fixed them. pthread_create had a problem with user provided stacks. Fri Mar 23 14:09:54 MET 2001 arg.. the kernel-header are so inconsistent... on x86 it works on arm and sparc not due to MISSING defines, miss-places includes and __KERNEL__ checks.... the best in this category is that the kernel-header are changed that the buggy (g)libc haven't to change... (f..k glibc, the headers HAVE to be CONSISTENT) a public defined symbol on arch X have to be in Y too unless marked... that is mainly speaking SCHED.H ! arg.... Wed Mar 14 04:28:45 MET 2001 I have implemented the "Manager Thread" so that nested thread creation works. really ugly stuff... don't look at it unless you're sitting on solid ground. Mon Mar 12 16:16:00 CET 2001 first of all: I strongly suggest NOT to use it yet, it's very, very, ... very experimental. I guess you got the point. there is still much debug code, incomplete functions and unusable states.... I'm still working on the final alpha... dietlibc-0.33~cvs20120325/libpthread/Makefile010064400000000000000000000033331173363227000154620ustar00all: libpthread.a M=$(shell ../findcflags.sh $(CC)) ARCH=$(shell uname -m | sed 's/i[4-9]86/i386/') CFLAGS= -g #-pipe -O -march=k6 CFLAGS= -pipe CROSS= CC=gcc VPATH=../$(ARCH)/ PTHREAD_OBJS = __testandset.o $(patsubst %.c,%.o,$(wildcard pthread_*.c)) TESTS = $(patsubst %.c,%,$(wildcard test-*.c)) %.o : %.c $(CC) $(CFLAGS) -c -o $@ $? #include ../$(ARCH)/Makefile.add ifeq ($(CFLAGS),-pipe) CFLAGS+= -O2 -fomit-frame-pointer endif CFLAGS += -W -Wall #CFLAGS += -fPIC CFLAGS += -I. -I.. -I../include -Wall PWD=$(shell pwd) .SUFFIXES: .SUFFIXES: .S .c .PHONY: clean tests test.out % :: %,v %.o: %.S $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -c $< %.o: %.c $(CROSS)$(CC) -I. -Iinclude $(CFLAGS) -c $< # $(CROSS)strip -x -R .comment -R .note $@ libpthread.a: $(PTHREAD_OBJS) $(CROSS)ar cr $@ $^ libpthread.so: libpthread.a $(CROSS)ld -whole-archive -shared -o $@ $^ clean: tests-clean $(RM) *.o *.a *.so *.out *~ *.oa exports: libpthread.a nm -g libpthread.a | grep -w T | awk '{ print $$3 }' | sort -u > exports .PHONY: test.out test.out: test.o libpthread.a $(LIBS) $(CROSS)$(CC) -g $(CFLAGS) -nostdlib ../bin-$(ARCH)/start.o ../bin-$(ARCH)/dyn_start.o -o $@ $^ ../bin-$(ARCH)/dietlibc.a -lgcc ../bin-$(ARCH)/dyn_stop.o tests: tests-clean $(TESTS) tests-clean: $(RM) $(TESTS) # libpthread.a pthread.oa: $(PTHREAD_OBJS) ld -r -o $@ $(patsubst pthread_errno.o,,$^) $(TESTS): pthread.oa $(CROSS)$(CC) -g $(CFLAGS) -nostdlib ../bin-$(ARCH)/start.o ../bin-$(ARCH)/dyn_start.o -o $@ $@.c $^ ../bin-$(ARCH)/dietlibc.a -lgcc ../bin-$(ARCH)/dyn_stop.o .PHONY: sparc ppc mips arm alpha i386 sparc ppc alpha i386: $(MAKE) ARCH=$@ CROSS=$@-linux- all t libdietc.so mips arm: $(MAKE) ARCH=$@ CROSS=$@-linux- all t libdietc.so dietlibc-0.33~cvs20120325/libpthread/README010064400000000000000000000015231173363227000147010ustar00LIBPTHREAD This is the pthread implementation for the dietlibc. Written from scratch by Olaf Dreesen. It's like linuxthreads a clone base thread implementation. STATUS: near complete and should work (see KNOWN BUGS) on all dietlibc platforms that have a working implementation of: - clone - testandset - sigsetjmp/siglongjmp KNOWN BUGS: - gdb can't handle this implementation. - there are problems with the stdio functions.... - ia64 doesn't work. the problem is this f**king separate register stack MAYBE BUGS: - ia64: r13 is used as a pointer to the thread-struct - s390: a0 used as pointer to thread-struct - sparc/sparc64: g6 used as pointer to thread-struct NOTES: SIGRTMAX and SIGRTMAX-1 are used by this imlementation ! - SIGRTMAX as restart event (join,cond_*wait,...) - SIGRTMAX-1 as cancel envent (cancel). dietlibc-0.33~cvs20120325/libpthread/pthread_atfork.c010064400000000000000000000033671173363227000171720ustar00#include #include #include #include #include "thread_internal.h" static struct _pthread_fastlock __atfork_struct_lock; static struct __thread_atfork { struct __thread_atfork*next,*prev; void (*prepare)(void); void (*parent)(void); void (*child)(void); } pthread_atfork_buf={&pthread_atfork_buf,&pthread_atfork_buf,0,0,0}; int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) { _pthread_descr this=__thread_self(); struct __thread_atfork*new; int ret=0; __NO_ASYNC_CANCEL_BEGIN_(this); __pthread_lock(&__atfork_struct_lock); if ((new=(struct __thread_atfork*)malloc(sizeof(struct __thread_atfork)))) { new->prepare=prepare; new->parent=parent; new->child=child; new->next=pthread_atfork_buf.next; new->prev=&pthread_atfork_buf; pthread_atfork_buf.next->prev=new; pthread_atfork_buf.next=new; } else ret=ENOMEM; __pthread_unlock(&__atfork_struct_lock); __NO_ASYNC_CANCEL_END_(this); return ret; } pid_t fork(void) { _pthread_descr this=__thread_self(); struct __thread_atfork*tmp; pid_t pid; __NO_ASYNC_CANCEL_BEGIN_(this); __TEST_CANCEL_(this); __pthread_lock(&__atfork_struct_lock); for (tmp=pthread_atfork_buf.next;tmp!=&pthread_atfork_buf;tmp=tmp->next) if (tmp->prepare) tmp->prepare(); pid=__libc_fork(); if (pid) { for (tmp=pthread_atfork_buf.prev;tmp!=&pthread_atfork_buf;tmp=tmp->prev) { if (tmp->parent) tmp->parent(); } } else { __thread_manager_close(); for (tmp=pthread_atfork_buf.prev;tmp!=&pthread_atfork_buf;tmp=tmp->prev) { if (tmp->child) tmp->child(); } } __pthread_unlock(&__atfork_struct_lock); __NO_ASYNC_CANCEL_END_(this); return pid; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getdetachstate.c010064400000000000000000000003331173363227000217150ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getdetachstate(const pthread_attr_t*attr,int*detachstate) { *detachstate=attr->__detachstate; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getinheritsched.c010064400000000000000000000003241173363227000220750ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getinheritsched(const pthread_attr_t*attr,int*inherit) { *inherit=attr->__inheritsched; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getschedparam.c010064400000000000000000000003711173363227000215350ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getschedparam(const pthread_attr_t*attr,struct sched_param*param) { param->sched_priority=attr->__schedparam.sched_priority; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getschedpolicy.c010064400000000000000000000003201173363227000217260ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getschedpolicy(const pthread_attr_t*attr,int*policy) { *policy=attr->__schedpolicy; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getscope.c010064400000000000000000000003361173363227000205400ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getscope(const pthread_attr_t*attr,int*scope) { if (0) { attr=0; } *scope=PTHREAD_SCOPE_SYSTEM; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getstackaddr.c010064400000000000000000000003141173363227000213630ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getstackaddr(const pthread_attr_t*attr,void**stack) { *stack=attr->__stackaddr; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_getstacksize.c010064400000000000000000000003261173363227000214260ustar00#include #include #include #include "thread_internal.h" int pthread_attr_getstacksize(const pthread_attr_t*attr,size_t*stacksize) { *stacksize=attr->__stacksize; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setdetachstate.c010064400000000000000000000005201173363227000217270ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setdetachstate(pthread_attr_t*attr,int detachstate) { if ((detachstate == PTHREAD_CREATE_JOINABLE) || (detachstate == PTHREAD_CREATE_DETACHED)) { attr->__detachstate=detachstate; return 0; } return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setinheritsched.c010064400000000000000000000004731173363227000221160ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setinheritsched(pthread_attr_t*attr,int inherit) { if ((inherit==PTHREAD_INHERIT_SCHED) || (inherit==PTHREAD_EXPLICIT_SCHED)) { attr->__inheritsched=inherit; return 0; } return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setschedparam.c010064400000000000000000000012071173363227000215500ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setschedparam(pthread_attr_t*attr,const struct sched_param*param) { if ((attr->__schedpolicy==SCHED_OTHER)&&(param->sched_priority==0)) { attr->__inheritsched=PTHREAD_EXPLICIT_SCHED; attr->__schedparam.sched_priority=0; return 0; } if (((attr->__schedpolicy==SCHED_RR)||(attr->__schedpolicy==SCHED_FIFO))&& ((param->sched_priority>0)&&(param->sched_priority<100))) { attr->__inheritsched=PTHREAD_EXPLICIT_SCHED; attr->__schedparam.sched_priority=param->sched_priority; return 0; } return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setschedpolicy.c010064400000000000000000000010061173363227000217440ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setschedpolicy(pthread_attr_t*attr,int policy) { if (policy==SCHED_OTHER) { attr->__inheritsched=PTHREAD_EXPLICIT_SCHED; attr->__schedpolicy=policy; return 0; } if ((policy==SCHED_FIFO)||(policy==SCHED_RR)) { if (geteuid()==0) { attr->__inheritsched=PTHREAD_EXPLICIT_SCHED; attr->__schedpolicy=policy; return 0; } return ENOTSUP; } else return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setscope.c010064400000000000000000000004371173363227000205560ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setscope(pthread_attr_t*attr,int scope) { if (0) { attr=0; } if (scope==PTHREAD_SCOPE_SYSTEM) return 0; if (scope==PTHREAD_SCOPE_PROCESS) return ENOTSUP; return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setstackaddr.c010064400000000000000000000003041173363227000213760ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setstackaddr(pthread_attr_t*attr,void*stack) { attr->__stackaddr=stack; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_attr_setstacksize.c010064400000000000000000000004721173363227000214440ustar00#include #include #include #include "thread_internal.h" int pthread_attr_setstacksize(pthread_attr_t*attr,size_t stacksize) { if (stacksize>PTHREAD_STACK_MAXSIZE) return EINVAL; if (stacksize__stacksize=stacksize; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_cleanup.c010064400000000000000000000014771173363227000173330ustar00#include #include #include #include #include "thread_internal.h" void pthread_cleanup_push(void(*func)(void*),void*arg) { _pthread_descr this=__thread_self(); struct thread_cleanup_t*tmp; __NO_ASYNC_CANCEL_BEGIN_(this); tmp=(struct thread_cleanup_t*)malloc(sizeof(struct thread_cleanup_t)); tmp->func=func; tmp->arg =arg; LOCK(this); tmp->next=this->cleanup_stack; this->cleanup_stack=tmp; UNLOCK(this); __NO_ASYNC_CANCEL_END_(this); } void pthread_cleanup_pop(int execute) { _pthread_descr this=__thread_self(); struct thread_cleanup_t*tmp; __NO_ASYNC_CANCEL_BEGIN_(this); LOCK(this); tmp=this->cleanup_stack; this->cleanup_stack=tmp->next; UNLOCK(this); if (execute) tmp->func(tmp->arg); free(tmp); __NO_ASYNC_CANCEL_END_(this); } dietlibc-0.33~cvs20120325/libpthread/pthread_cond_broadcast.c010064400000000000000000000007641173363227000206470ustar00#include #include #include #include "thread_internal.h" int pthread_cond_broadcast(pthread_cond_t*cond) { _pthread_descr this=__thread_self(); _pthread_descr tmp,next; __NO_ASYNC_CANCEL_BEGIN_(this); LOCK(cond); for (tmp=cond->wait_chain;tmp;tmp=next) { next=tmp->waitnext; __thread_restart(tmp); tmp->waitnext=0; tmp->waitprev=&(tmp->waitnext); } cond->wait_chain=0; UNLOCK(cond); __NO_ASYNC_CANCEL_END_(this); return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_cond_destroy.c010064400000000000000000000007361173363227000203750ustar00#include #include #include #include #include "thread_internal.h" int pthread_cond_destroy(pthread_cond_t*cond) { _pthread_descr this=__thread_self(); int ret=0; __NO_ASYNC_CANCEL_BEGIN_(this); LOCK(cond); if (cond->wait_chain) { UNLOCK(cond); ret=EBUSY; } else { memset(cond,0,sizeof(pthread_cond_t)); cond->lock.__spinlock=PTHREAD_SPIN_UNLOCKED; } __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_cond_init.c010064400000000000000000000004711173363227000176430ustar00#include #include #include #include #include "thread_internal.h" int pthread_cond_init(pthread_cond_t*cond,pthread_condattr_t*cond_attr) { if (0) { cond_attr=0; } memset(cond,0,sizeof(pthread_cond_t)); cond->lock.__spinlock=PTHREAD_SPIN_UNLOCKED; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_cond_signal.c010064400000000000000000000005361173363227000201570ustar00#include #include #include #include "thread_internal.h" int pthread_cond_signal(pthread_cond_t*cond) { _pthread_descr this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); LOCK(cond); if (cond->wait_chain) __thread_restart(cond->wait_chain); UNLOCK(cond); __NO_ASYNC_CANCEL_END_(this); return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_cond_timedwait.c010064400000000000000000000017341173363227000206720ustar00#include #include #include #include "thread_internal.h" int pthread_cond_timedwait(pthread_cond_t*cond,pthread_mutex_t*mutex, const struct timespec*abstime) { _pthread_descr this=__thread_self(); _pthread_descr*tmp; int retval; if (mutex->owner!=this) return EINVAL; __NO_ASYNC_CANCEL_BEGIN_(this); /* put in wait-chain */ LOCK(cond); tmp=&(cond->wait_chain); this->waitnext=0; while (*tmp) tmp=&((*tmp)->waitnext); this->waitprev=tmp; *tmp=this; UNLOCK(cond); /* Aeh yeah / wait till condition-signal or timout (or cancel) */ pthread_mutex_unlock(mutex); retval = __thread_suspend_till(this,1,abstime); pthread_mutex_lock(mutex); /* remove from wait-chain (if not signaled) */ LOCK(cond); if (this->waitnext) { this->waitnext->waitprev=this->waitprev; *(this->waitprev)=this->waitnext; } else *(this->waitprev)=0; UNLOCK(cond); __NO_ASYNC_CANCEL_END_(this); return retval; } dietlibc-0.33~cvs20120325/libpthread/pthread_cond_wait.c010064400000000000000000000015751173363227000176520ustar00#include #include #include #include "thread_internal.h" int pthread_cond_wait(pthread_cond_t*cond,pthread_mutex_t*mutex) { _pthread_descr this=__thread_self(); _pthread_descr*tmp; if (mutex->owner!=this) return EINVAL; __NO_ASYNC_CANCEL_BEGIN_(this); /* put in wait-chain */ LOCK(cond); tmp=&(cond->wait_chain); this->waitnext=0; while (*tmp) tmp=&((*tmp)->waitnext); this->waitprev=tmp; *tmp=this; UNLOCK(cond); /* Aeh yeah / wait till condition-signal (or cancel) */ pthread_mutex_unlock(mutex); __thread_suspend(this,1); pthread_mutex_lock(mutex); /* remove from wait-chain (if not signaled) */ LOCK(cond); if (this->waitnext) { this->waitnext->waitprev=this->waitprev; *(this->waitprev)=this->waitnext; } else *(this->waitprev)=0; UNLOCK(cond); __NO_ASYNC_CANCEL_END_(this); return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_condattr_getshared.c010064400000000000000000000003601173363227000215360ustar00#include #include #include #include "thread_internal.h" int pthread_condattr_getpshared(const pthread_condattr_t*attr,int*pshared) { if (0) { attr=0; } *pshared=PTHREAD_PROCESS_PRIVATE; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_condattr_setshared.c010064400000000000000000000005431173363227000215550ustar00#include #include #include #include "thread_internal.h" int pthread_condattr_setpshared(pthread_condattr_t*attr,int pshared) { if (0) { attr=0; } if ((pshared!=PTHREAD_PROCESS_PRIVATE) && (pshared!=PTHREAD_PROCESS_SHARED)) return EINVAL; if (pshared!=PTHREAD_PROCESS_PRIVATE) return ENOSYS; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_create.c010064400000000000000000000063521173363227000171440ustar00#include #include #include #include #include #include "thread_internal.h" #ifdef WANT_TLS #include extern size_t __tmemsize; #endif int pthread_attr_init(pthread_attr_t*attr) { memset(attr,0,sizeof(pthread_attr_t)); attr->__stacksize=PTHREAD_STACK_SIZE; /* no need to do this initalisation (all are zero values) * attr->__detachstate = PTHREAD_CREATE_JOINABLE; * attr->__scope = PTHREAD_SCOPE_SYSTEM; * attr->__inheritsched=PTHREAD_EXPLICIT_SCHED; * attr->__schedpolicy=SCHED_OTHER; * attr->__schedparam.sched_priority=0; */ return 0; } int pthread_attr_destroy(pthread_attr_t *attr) __attribute__((alias("pthread_attr_init"))); int pthread_create(pthread_t*thread,const pthread_attr_t*d_attr, void*(*start_routine)(void*),void*arg) { #if 0 /* first try the linux 2.6 way */ if (__likely(__modern_linux>=0)) { /* try new way; if it fails, assume old kernel */ } #endif struct __thread_descr request; pthread_attr_t attr; _pthread_descr td,this; this=__thread_self(); char*stack; int ret; #ifdef WANT_TLS size_t origsize; size_t additional; #endif if (thread==0) kill(getpid(),SIGSEGV); if (start_routine==0) return EINVAL; __TEST_CANCEL_(this); __NO_ASYNC_CANCEL_BEGIN_(this); if (d_attr) attr=*d_attr; else pthread_attr_init(&attr); #ifdef WANT_TLS origsize=attr.__stacksize; additional=__tmemsize+sizeof(tcbhead_t); additional=(additional+15)&-16; if (additional < sizeof(tcbhead_t) || origsize < sizeof(struct _pthread_descr_struct) || origsize+additional < origsize) { ret=EINVAL; goto func_out; } attr.__stacksize=origsize+additional; #endif { register char*stb,*st=0; if ((stack=attr.__stackaddr)==0) { /* YES we need PROT_EXEC for signal-handling :( */ if ((st=stack=(char*)mmap(0,attr.__stacksize,PROT_READ|PROT_WRITE|PROT_EXEC,MAP_PRIVATE|MAP_ANONYMOUS,-1,0))==MAP_FAILED) { ret=EINVAL; goto func_out; } } stb=stack; #ifdef __parisc__ td=(_pthread_descr)stack; stack+=sizeof(struct _pthread_descr_struct); #else stack+=attr.__stacksize-sizeof(struct _pthread_descr_struct); td=(_pthread_descr)stack; #endif memset(td,0,sizeof(struct _pthread_descr_struct)); td->stack_begin = stb; td->stack_end = stb+attr.__stacksize; td->stack_free = (st)?1:0; attr.__stackaddr = stack; } request.attr = &attr; request.td = td; request.tr = this; if (attr.__inheritsched==PTHREAD_INHERIT_SCHED) { if ((ret=__thread_getschedparam(request.tr->pid,&attr.__schedpolicy,&attr.__schedparam))!=0) goto func_out; } td->lock.__spinlock = PTHREAD_SPIN_UNLOCKED; td->joined.__spinlock = PTHREAD_SPIN_UNLOCKED; td->detached = attr.__detachstate; td->stack_size = attr.__stacksize; td->func = start_routine; td->arg = arg; /* let the "child thread" inherit the procmask (hope this works) */ sigprocmask(SIG_SETMASK,0,&(td->thread_sig_mask)); sigaddset(&(td->thread_sig_mask),PTHREAD_SIG_RESTART); sigdelset(&(td->thread_sig_mask),PTHREAD_SIG_CANCEL); if ((ret=__thread_start_new(&request))==-1) { ret=EAGAIN; goto func_out; } *thread=ret; ret^=ret; func_out: __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_detach.c010064400000000000000000000007271173363227000171310ustar00#include #include #include "thread_internal.h" int pthread_detach(pthread_t th) { int ret=ESRCH; _pthread_descr td,this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); if ((td=__thread_find(th))) { if (td->detached) { ret=EINVAL; } else if (td->joined.__spinlock==PTHREAD_SPIN_UNLOCKED) { td->detached=1; ret^=ret; /* short ret=0; */ } UNLOCK(td); } __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_dns_cruft.c010064400000000000000000000004201173363227000176560ustar00#include "thread_internal.h" #ifdef PTHREAD_HANDLE_DNS_CORRECT int *__h_errno_location(void) { _pthread_descr td=__thread_self(); return &(td->h_errno); } struct res_state*__res_location(void) { _pthread_descr td=__thread_self(); return &(td->__res); } #endif dietlibc-0.33~cvs20120325/libpthread/pthread_equal.c010064400000000000000000000001571173363227000170050ustar00#include int pthread_equal(pthread_t thread1, pthread_t thread2) { return (thread1==thread2); } dietlibc-0.33~cvs20120325/libpthread/pthread_errno.c010064400000000000000000000001731173363227000170210ustar00int errno; #include "dietwarning.h" link_warning("errno","\e[1;33;41m>>> your multithreaded code uses errno! <<<\e[0m"); dietlibc-0.33~cvs20120325/libpthread/pthread_fdglue2.c010064400000000000000000000007501173363227000172250ustar00#include "dietstdio.h" #include #include #include #include #include #include extern int __stdio_atexit; extern FILE* __stdio_init_file_nothreads(int fd,int closeonerror,int mode); FILE* __stdio_init_file(int fd,int closeonerror,int mode) { pthread_mutexattr_t attr={PTHREAD_MUTEX_RECURSIVE_NP}; FILE *tmp=__stdio_init_file_nothreads(fd,closeonerror,mode); if (tmp) pthread_mutex_init(&tmp->m,&attr); return tmp; } dietlibc-0.33~cvs20120325/libpthread/pthread_fflush.c010064400000000000000000000003131173363227000171570ustar00#include int fflush(FILE *stream) { int tmp; if (stream) pthread_mutex_lock(&stream->m); tmp=fflush_unlocked(stream); if (stream) pthread_mutex_unlock(&stream->m); return tmp; } dietlibc-0.33~cvs20120325/libpthread/pthread_fgetc.c010064400000000000000000000003051173363227000167610ustar00#include "dietstdio.h" #include int fgetc(FILE *stream) { int tmp; pthread_mutex_lock(&stream->m); tmp=fgetc_unlocked(stream); pthread_mutex_unlock(&stream->m); return tmp; } dietlibc-0.33~cvs20120325/libpthread/pthread_flockfile.c010064400000000000000000000001211173363227000176230ustar00#include "dietstdio.h" void flockfile(FILE* f) { pthread_mutex_lock(&f->m); } dietlibc-0.33~cvs20120325/libpthread/pthread_fputc.c010064400000000000000000000002721173363227000170150ustar00#include int fputc(int c, FILE *stream) { int tmp; pthread_mutex_lock(&stream->m); tmp=fputc_unlocked(c,stream); pthread_mutex_unlock(&stream->m); return tmp; } dietlibc-0.33~cvs20120325/libpthread/pthread_fputs.c010064400000000000000000000001471173363227000170360ustar00#include int fputs(const char*s,FILE*stream) { return fwrite(s,strlen(s),1,stream); } dietlibc-0.33~cvs20120325/libpthread/pthread_fread.c010064400000000000000000000003541173363227000167560ustar00#include size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t tmp; pthread_mutex_lock(&stream->m); tmp=fread_unlocked(ptr,size,nmemb,stream); pthread_mutex_unlock(&stream->m); return tmp; } dietlibc-0.33~cvs20120325/libpthread/pthread_ftrylockfile.c010064400000000000000000000001351173363227000203670ustar00#include "dietstdio.h" int ftrylockfile(FILE* f) { return pthread_mutex_trylock(&f->m); } dietlibc-0.33~cvs20120325/libpthread/pthread_funlockfile.c010064400000000000000000000001251173363227000201720ustar00#include "dietstdio.h" void funlockfile(FILE* f) { pthread_mutex_unlock(&f->m); } dietlibc-0.33~cvs20120325/libpthread/pthread_fwrite.c010064400000000000000000000003641173363227000171760ustar00#include size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t tmp; pthread_mutex_lock(&stream->m); tmp=fwrite_unlocked(ptr,size,nmemb,stream); pthread_mutex_unlock(&stream->m); return tmp; } dietlibc-0.33~cvs20120325/libpthread/pthread_internal.c010064400000000000000000000507541173363227000175220ustar00#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include "thread_internal.h" //#define DEBUG #ifdef DEBUG #include #endif #ifdef WANT_TLS #include #endif #define INTR_RETRY(e) ({ long ret; do ret=(long)(e); while ((ret==-1)&&(_errno_==EINTR)); ret; }) #define __NO_ASYNC_CANCEL_STOP } static struct _pthread_descr_struct _main_thread={ .stack_begin=0, .stack_end=(void*)~0, .lock={PTHREAD_SPIN_UNLOCKED}, }; static _pthread_descr manager_thread; static pthread_once_t __thread_started=PTHREAD_ONCE_INIT; static unsigned long __thread_pagesize; static int __manager_pipe[2]={-1,-1}; #define mgr_recv_fd __manager_pipe[0] #define mgr_send_fd __manager_pipe[1] /* only once :) */ static int __pthread_once(pthread_once_t*once_control,void (*init_routine)(void)) { if (!(__testandset(once_control))) init_routine(); return 0; } int pthread_once(pthread_once_t*once_control,void(*init_routine)(void)) __attribute__((alias("__pthread_once"))); #define NR_BUCKETS (1<<8) /* !!! MUST BE A POWER OF 2 !!! */ static _pthread_descr _thread_hash_tid[NR_BUCKETS]; static inline unsigned long hash_tid(int tid) { return (tid&(NR_BUCKETS-1)); } /* O(1) */ #if defined(__i386__) static void __attribute__((regparm(2))) __thread_add_tid_(_pthread_descr*root,_pthread_descr thread) #else static void __thread_add_tid_(_pthread_descr*root,_pthread_descr thread) #endif { _pthread_descr tmp=*root; thread->prev=root; thread->next=tmp; (*root)=thread; if (tmp) (tmp)->prev=(_pthread_descr*)thread; } /* add_list O(1) / this is called pre thread release (without ASYNC_CANCEL) */ static void __thread_add_list(_pthread_descr td) { __thread_add_tid_(&_thread_hash_tid[hash_tid(td->pid)],td); } /* del_list O(1) / there is only ONE grim reaper without ASYNC_CANCEL */ /* no reinit of struct, so no problem with the _thread_{self,find} functions */ static void __thread_del_list(_pthread_descr td) { _pthread_descr*save=td->prev; _pthread_descr next=td->next; *save=next; if (next) next->prev=save; } /* find thread by thread-id O(n) (LOCK struct if found) */ /* O(n*) linear to the number of thread in the same bucket */ #if defined(__i386__) static _pthread_descr __thread_find_(int pid) __attribute__((regparm(1))); _pthread_descr __thread_find(int pid) { return __thread_find_(pid); } static _pthread_descr __attribute__((regparm(1))) __thread_find_(int pid) #else _pthread_descr __thread_find(int pid) __attribute__((alias("__thread_find_"))); static _pthread_descr __thread_find_(int pid) #endif { _pthread_descr cur; if (__thread_started==PTHREAD_ONCE_INIT) { /* uninitialised */ LOCK(&_main_thread); return &_main_thread; } cur=_thread_hash_tid[hash_tid(pid)]; while (cur) { _pthread_descr next=cur->next; if (pid==cur->pid) { LOCK(cur); break; } cur=next; } return cur; } /* get thread-self descriptor O(1)/O(n*) */ _pthread_descr __thread_self(void) { /* O(1) "search" */ #if defined(__alpha__) register _pthread_descr cur asm("$0"); asm("call_pal 158" : "=r"(cur) ); /* PAL_rduniq = 158 */ #else /* alpha */ register _pthread_descr cur=0; #if defined(__sparc__) asm("mov %%g6,%0" : "=r"(cur) ); /* %g6 (res. system use) is used as thread pointer */ #elif defined(__s390__) asm("ear %0,%%a0" : "=d"(cur) ); /* a0 (access register 0) is used as thread pointer */ #elif defined(__ia64__) asm("mov %0 = r13" : "=r"(cur) ); /* r13 (tp) is used as thread pointer */ #elif defined(__x86_64__) asm("mov %%fs:(16),%0" : "=r"(cur)); #elif defined(__i386__) if (__likely(__modern_linux==1)) asm("mov %%gs:(8),%0" : "=r"(cur)); else { /* old cruft O(n*) */ cur=__thread_find_(getpid()); if (cur) UNLOCK(cur); } #else /* other */ /* all other archs: * search the thread depending on the PID O(n*) */ cur=__thread_find_(getpid()); if (cur) UNLOCK(cur); #endif /* other */ #endif /* alpha */ return (cur)?cur:&_main_thread; } /* support for manager / dispatch a signal to ALL threads * used for SIG{SEGV,FPE,...} and main thread exits */ static void kill_all_threads(int sig,int main2) { int i; if (main2) kill(_main_thread.pid,sig); for (i=0;inext) kill(cur->pid,sig); } } /* thread errno location */ int *__errno_location() { _pthread_descr td=__thread_self(); return &(td->errno); } /* exit a thread */ static void __pthread_exit(void*retval) { _pthread_descr this=__thread_self(); if (this==&_main_thread) __libc_exit((long)retval); __NO_ASYNC_CANCEL_BEGIN_(this); LOCK(this); this->cancelstate=PTHREAD_CANCEL_DISABLE; this->retval=retval; UNLOCK(this); __NO_ASYNC_CANCEL_STOP; siglongjmp(this->jmp_exit,1); } void pthread_exit(void*retval) __attribute__((alias("__pthread_exit"))); /* test canceled */ void __thread_testcancel(_pthread_descr td) { int cancel=0; if (td && (td->cancelstate==PTHREAD_CANCEL_ENABLE)) cancel=td->canceled; if (cancel) __pthread_exit(PTHREAD_CANCELED); } void pthread_testcancel() { __thread_testcancel(__thread_self()); } /* set canceltype of thread */ int __thread_setcanceltype(int type,int*oldtype,_pthread_descr td) { if ((type!=PTHREAD_CANCEL_DEFERRED)&&(type!=PTHREAD_CANCEL_ASYNCHRONOUS)) return EINVAL; if (oldtype) *oldtype=td->canceltype; td->canceltype=type; return 0; } int pthread_setcanceltype(int type,int*oldtype) { return __thread_setcanceltype(type,oldtype,__thread_self()); } /* sleep a little (reschedule for this time) */ static void __thread_sleep() { struct timespec reg; reg.tv_sec=0; reg.tv_nsec=SPIN_SLEEP_DURATION; __libc_nanosleep(®,0); } /* * cleanup / remove zombie thread * this is entered with "td" not in the list of threads and UNLOCKED !!! */ static int __thread_cleanup(_pthread_descr td) { int cnt=0; do { ++cnt; /* the next operations are only to make sure any thread_self that still uses "td" will go away */ sched_yield(); __thread_sleep(); sched_yield(); /* try lock of thread-struct (maybe still locked) */ } while (TRYLOCK(td) && (cntstack_free) munmap(td->stack_begin,td->stack_size); return 0; } /* suspend till timeout or restart signal / in NO_ASYNC_CANCEL */ int __thread_suspend_till(_pthread_descr this,int cancel,const struct timespec*abstime) { sigset_t newmask,oldmask; struct timeval tv; struct timespec reg; int retval = 0; gettimeofday(&tv,0); reg.tv_nsec=abstime->tv_nsec-tv.tv_usec*1000; reg.tv_sec=abstime->tv_sec-tv.tv_sec; if (reg.tv_nsec<0) { reg.tv_nsec+=1000000000; reg.tv_sec-=1; } this->p_sig=0; /* Unblock the restart signal */ sigemptyset(&newmask); sigaddset(&newmask,PTHREAD_SIG_RESTART); sigprocmask(SIG_UNBLOCK,&newmask,&oldmask); while(this->p_sig!=PTHREAD_SIG_RESTART) { if (cancel && (this->cancelstate==PTHREAD_CANCEL_ENABLE) && this->canceled) break; if (reg.tv_sec<0||__libc_nanosleep(®,®)==0) { retval = ETIMEDOUT; break; } } sigprocmask(SIG_SETMASK,&oldmask,0); return retval; } /* suspend till restart signal */ void __thread_suspend(_pthread_descr this,int cancel) { sigset_t mask; this->p_sig=0; sigprocmask(SIG_SETMASK,0,&mask); sigdelset(&mask,PTHREAD_SIG_RESTART); while (this->p_sig!=PTHREAD_SIG_RESTART) { if (cancel && (this->cancelstate==PTHREAD_CANCEL_ENABLE) && this->canceled) break; sigsuspend(&mask); } } /* restart a thread */ void __thread_restart(_pthread_descr td) { kill(td->pid,PTHREAD_SIG_RESTART); sched_yield(); sched_yield(); } /* restart signal handler */ static void pthread_handle_sigrestart(int sig) { _pthread_descr this=__thread_self(); this->p_sig=sig; #ifdef DEBUG printf("pthread_handle_sigrestart(%d) in %d\n",sig,this->pid); #endif } /* cancel signal */ static void pthread_handle_sigcancel(int sig,siginfo_t*info,void*arg) { _pthread_descr this=__thread_self(); if (0) { sig=0; arg=0; } #ifdef DEBUG printf("pthread_handle_sigcancel(%d): sigcancel %d\n",sig,this->pid); #endif /* manger part */ if (this==manager_thread) { int pid=info->si_pid; if (pid==_main_thread.pid) { #ifdef DEBUG printf("pthread_handle_sigcancel: kill from main: %d\n",pid); #endif sched_yield(); kill_all_threads(PTHREAD_SIG_CANCEL,0); sched_yield(); __thread_sleep(); kill_all_threads(SIGKILL,0); __thread_sleep(); _exit(0); } #ifdef DEBUG else printf("pthread_handle_sigcancel: signal from thread %d ?\n",pid); #endif } /* main thread part */ else if (this==&_main_thread) { #ifdef DEBUG printf("pthread_handle_sigcancel: %d : cancel event for MAIN\n",this->pid); #endif /* kill the manager and wait for it */ kill(manager_thread->pid,PTHREAD_SIG_CANCEL); __libc_waitpid(manager_thread->pid,0,WNOHANG|__WCLONE); /* jump to an exit slot */ siglongjmp(_main_thread.jmp_exit,1); } /* all other just cancel */ else if (this->cancelstate==PTHREAD_CANCEL_ENABLE) { #ifdef DEBUG printf("pthread_handle_sigcancel: %d : cancel event\n",this->pid); #endif this->canceled=1; if (this->canceltype==PTHREAD_CANCEL_ASYNCHRONOUS) { __pthread_exit(PTHREAD_CANCELED); } } } /* nop functions */ static int __thread_nop() { return 0; } int pthread_condattr_init(pthread_condattr_t*attr) __attribute__((alias("__thread_nop"))); int pthread_condattr_destroy(pthread_condattr_t*attr) __attribute__((alias("__thread_nop"))); /* thread specific data -- key glue */ void __thread_start__key(_pthread_descr td) __attribute__((weak,alias("__thread_nop"))); void __thread_exit__key(_pthread_descr td) __attribute__((weak,alias("__thread_nop"))); void pthread_cleanup_pop(int execute) __attribute__((weak,alias("__thread_nop"))); /* machine depending thread register */ static inline _pthread_descr __thread_set_register(void*arg) { #if defined(__alpha__) asm volatile ("call_pal 159" : : "r"(arg) ); /* PAL_wruniq = 159 */ #elif defined(__sparc__) asm volatile ("mov %0,%%g6" : : "r"(arg) ); #elif defined(__s390__) asm volatile ("sar %%a0,%0" : : "d"(arg) ); #elif defined(__ia64__) asm volatile ("mov r13 = %0" : : "r"(arg) ); #endif return (_pthread_descr)arg; } #ifdef WANT_TLS extern size_t __tdatasize, __tmemsize; extern void* __tdataptr; extern void __setup_tls(tcbhead_t* thread); #endif #ifdef WANT_SSP extern unsigned long __guard; #endif #if defined(WANT_TLS) || defined(WANT_SSP) extern tcbhead_t* __tcb_mainthread; #endif /* thread start helper */ static void* __managed_start(void*arg) { #if defined(__sparc__) register _pthread_descr td asm("%g6"); #elif defined(__ia64__) register _pthread_descr td asm("r13"); #else _pthread_descr td; #endif #if defined(WANT_TLS) || defined(WANT_SSP) __tcb_mainthread->multiple_threads=1; tcbhead_t* me=alloca(sizeof(tcbhead_t) #ifdef WANT_TLS +__tmemsize); /* printf("allocating %lu bytes (%lu + %lu)\n",sizeof(tcbhead_t)+__tmemsize,sizeof(tcbhead_t),__tmemsize); */ memcpy(me,__tdataptr,__tdatasize); memset(((char*)me)+__tdatasize,0,__tmemsize-__tdatasize); me=(tcbhead_t*)(((char*)me) + __tmemsize); #endif __setup_tls(me); me->multiple_threads=1; #ifdef WANT_SSP me->pointer_guard=__guard ^ (uintptr_t)me; #endif me->self=arg; td=arg; __thread_set_register(me); #else td=__thread_set_register(arg); #endif #ifdef WANT_TLS #endif td->pid=getpid(); #ifdef DEBUG printf("__managed_start: %d pre suspend\n",td->pid); #endif /* wait for manager to release us */ __thread_suspend(td,1); sigprocmask(SIG_SETMASK,&(td->thread_sig_mask),0); #ifdef DEBUG printf("__managed_start: %d, parameter %8p\n",td->pid,td->func); #endif if (td->canceled) { td->retval=PTHREAD_CANCELED; return (void*)42; } /* limit stack so that we NEVER have to worry */ { #define __RLIMIT__ td->stack_size-__thread_pagesize /* subtract a safety margin (i.a. 1 page) */ struct rlimit l={__RLIMIT__,__RLIMIT__}; setrlimit(RLIMIT_STACK,&l); #undef __RLIMIT__ } __thread_start__key(td); /* thread_key glue */ if (td->canceled==0) { if (sigsetjmp(td->jmp_exit,1)==0) { td->retval=td->func(td->arg); #ifdef DEBUG } else { printf("__managed_start: pthread_exit called in %d\n",td->pid); #endif } } __NO_ASYNC_CANCEL_BEGIN_(td); __thread_exit__key(td); /* thread_key glue */ /* execute all functions on the cleanup-stack */ while (td->cleanup_stack) pthread_cleanup_pop(1); return 0; __NO_ASYNC_CANCEL_STOP; } /* ... */ static int _thread_getschedparam(pthread_t th,int*policy,struct sched_param*param) { int p; if (((p=sched_getscheduler(th))==-1)||(sched_getparam(th,param)==-1)) return _errno_; *policy=p; return 0; } int __thread_getschedparam(pthread_t th,int*policy,struct sched_param*param) __attribute__((alias("_thread_getschedparam"))); /* get thread schedul parameters */ int pthread_getschedparam(pthread_t th,int*policy,struct sched_param*param) { _pthread_descr td,this=__thread_self(); int ret=ESRCH; __NO_ASYNC_CANCEL_BEGIN_(this); if ((td=__thread_find(th))) { UNLOCK(td); ret=_thread_getschedparam(th,policy,param); } __NO_ASYNC_CANCEL_END_(this); return ret; } /* thread manage internal stuff */ /* #define CLONE_FLAGS (CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|PTHREAD_SIG_CANCEL) */ #define CLONE_FLAGS (CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND) void __thread_manager_close(void) { __thread_started=PTHREAD_ONCE_INIT; if (mgr_recv_fd>=0) close(mgr_recv_fd); if (mgr_send_fd>=0) close(mgr_send_fd); /* FIXME: missing: resource deallocation (free of unused thread stacks) */ /* reinit of main thread struct */ memset(_thread_hash_tid,0,sizeof(_thread_hash_tid)); _main_thread.stack_begin=0; _main_thread.stack_end=(void*)~0; _main_thread.lock.__spinlock=PTHREAD_SPIN_UNLOCKED; _main_thread.pid=getpid(); manager_thread=0; } static void __MGR_thread_start_new(_thread_descr data) { _pthread_descr td=data->td; pthread_attr_t*attr=data->attr; if ((td->pid=(*(data->pid))=__clone(__managed_start,attr->__stackaddr,CLONE_FLAGS,td))!=-1) { sched_setscheduler(td->pid,attr->__schedpolicy,&attr->__schedparam); __thread_add_list(td); __thread_restart(td); /* let the thread loose */ } #ifdef DEBUG printf("__MGR_thread_start_new: created thread %d\n",td->pid); #endif __thread_restart(data->tr); /* restart request sender */ } static void __MGR_thread_join_cleanup(_pthread_descr td) { #ifdef DEBUG printf("__MGR_thread_join_cleanup: wind up red-tape for thread %d\n",td->pid); #endif __thread_del_list(td); UNLOCK(td); __thread_cleanup(td); } /* manager thread */ static char __manager_thread_stack[PTHREAD_STACK_SIZE]; __attribute__((noreturn)) static void*__manager_thread(void*arg) { sigset_t manager_mask; struct pollfd pfd; _pthread_descr td; int n,status; if (0) arg=0; pfd.fd=mgr_recv_fd; pfd.events=POLLIN; sigfillset(&manager_mask); sigdelset(&manager_mask,PTHREAD_SIG_CANCEL); sigdelset(&manager_mask,SIGTRAP); sigprocmask(SIG_SETMASK,&manager_mask,0); #ifdef DEBUG printf("manager pre start sleep \n"); #endif __thread_sleep(); sched_yield(); /* restart main thread */ __thread_restart(&_main_thread); while(1) { n=poll(&pfd,1,30); if (getppid()==1) { /* main thread is dead: commit suicide */ #ifdef DEBUG printf("main thread is dead\n"); #endif kill_all_threads(SIGKILL,0); _exit(0); } if (n==1) { __thread_manager_func data; if (INTR_RETRY(__libc_read(mgr_recv_fd,&data,sizeof(data)))==sizeof(data)) { #ifdef DEBUG printf("__manager_thread: do func %08x %08x\n",data.func,data.arg); #endif data.func(data.arg); } } while ((n=__libc_waitpid(-1,&status,WNOHANG|__WCLONE))!=-1) { if (!n) break; /* ?!? WHY DOES WAITPID RETURN ZERO ?!? */ #ifdef DEBUG printf("__manager_thread waitpid %d %d\n",n,WTERMSIG(status)); #endif if ((td=__thread_find(n))) { if (WIFSIGNALED(status)) { if (WTERMSIG(status)!=PTHREAD_SIG_CANCEL) { #ifdef DEBUG printf("__manager_thread: thread %d was killed by %d\n",n,WTERMSIG(status)); #endif /* Oh, oohhhhhh.... */ sched_yield(); #ifdef DEBUG kill_all_threads(SIGKILL,1); #else kill_all_threads(WTERMSIG(status),1); #endif sched_yield(); __thread_sleep(); kill_all_threads(SIGKILL,1); __thread_sleep(); _exit(0); } } #ifdef DEBUG printf("__manager_thread: thread %d is dead\n",n); #endif if (td->detached) __MGR_thread_join_cleanup(td); else { td->canceled|=2; td->dead=1; UNLOCK(td); if (td->joined.__spinlock==PTHREAD_SPIN_LOCKED) __thread_restart(td->jt); } } } } } /* exit process */ /* FIXME: is there a bug here ? */ void __thread_doexit(long retval); void __thread_doexit(long retval) { _pthread_descr this=__thread_self(); #ifdef DEBUG printf("__thread_doexit: %d\n",this->pid); #endif if (this!=&_main_thread) { this->retval=0; _main_thread.retval=(void*)retval; kill(_main_thread.pid,PTHREAD_SIG_CANCEL); /* send main the EXIT */ siglongjmp(this->jmp_exit,1); } /* main thread */ if (sigsetjmp(_main_thread.jmp_exit,1)==0) { if (manager_thread && manager_thread->pid && (kill(manager_thread->pid,PTHREAD_SIG_CANCEL)!=-1)) { __thread_suspend(&_main_thread,0); /* there is still a manager */ } } kill_all_threads(SIGKILL,0); } /* "boot" manager thread */ static void __manager_thread_init() { char*stack; #ifdef __parisc__ manager_thread=(_pthread_descr)__manager_thread_stack; stack=__manager_thread_stack+sizeof(struct _pthread_descr_struct); #else stack=__manager_thread_stack+(sizeof(__manager_thread_stack)-sizeof(struct _pthread_descr_struct)); manager_thread=(_pthread_descr)stack; #endif memset(manager_thread,0,sizeof(struct _pthread_descr_struct)); manager_thread->stack_begin=__manager_thread_stack; manager_thread->stack_end=__manager_thread_stack+sizeof(__manager_thread_stack); manager_thread->stack_size=sizeof(__manager_thread_stack); manager_thread->func=__manager_thread; manager_thread->arg=0; manager_thread->lock.__spinlock=PTHREAD_SPIN_UNLOCKED; manager_thread->joined.__spinlock=PTHREAD_SPIN_LOCKED; _main_thread.pid=getpid(); /* set arch defined thread register */ __thread_set_register(&_main_thread); if (pipe(__manager_pipe)==-1) __libc_exit(42); /* create manager */ if ((manager_thread->pid=__clone(__managed_start,stack,CLONE_FLAGS|PTHREAD_SIG_CANCEL,manager_thread))==-1) __libc_exit(43); __thread_add_list(manager_thread); __thread_restart(manager_thread); #ifdef DEBUG printf("__manager_thread_init: mgr restart...\n"); #endif __thread_suspend(&_main_thread,0); #ifdef DEBUG printf("__manager_thread_init: thread-mgr should now be started...\n"); #endif } /* init of thread library */ static void __thread_init() { struct sigaction sa; sigset_t mask; memset(&sa,0,sizeof(struct sigaction)); #ifdef DEBUG printf("__thread_init: start...\n"); #endif /* get pagesize for guard */ __thread_pagesize=getpagesize(); /* setup signal handlers */ sigemptyset(&sa.sa_mask); sa.sa_handler=pthread_handle_sigrestart; __libc_sigaction(PTHREAD_SIG_RESTART,&sa,0); sa.sa_flags=SA_SIGINFO; sa.sa_handler=0; sa.sa_sigaction=pthread_handle_sigcancel; __libc_sigaction(PTHREAD_SIG_CANCEL ,&sa,0); /* block restart / unblock cancel */ sigprocmask(SIG_SETMASK,0,&mask); sigaddset(&mask,PTHREAD_SIG_RESTART); sigdelset(&mask,PTHREAD_SIG_CANCEL); sigprocmask(SIG_SETMASK,&mask,0); #ifdef DEBUG printf("__thread_init: start mgr...\n"); #endif __manager_thread_init(); if (sigsetjmp(_main_thread.jmp_exit,1)) { #ifdef DEBUG printf("__thread_init: 'exit()' called in thread...\n"); #endif __libc_exit((long)_main_thread.retval); } } /* send the manager a function and an argument to run */ static int __MGR_send(void(*f)(void*),void*arg) { __thread_manager_func data={ .func=f, .arg=arg, }; __pthread_once(&__thread_started,__thread_init); return INTR_RETRY(__libc_write(mgr_send_fd,&data,sizeof(data))); } int __thread_send_manager(void(*f)(void*),void*arg) __attribute__((alias("__MGR_send"))); /* start a new thread */ int __thread_start_new(_thread_descr data) { int pid; data->pid=&pid; if (__MGR_send((MGR_func)__MGR_thread_start_new,data)==-1) { __thread_cleanup(data->tr); return -1; } __thread_suspend(data->tr,0); return pid; } int __thread_join_cleanup(_pthread_descr td) { return __MGR_send((MGR_func)__MGR_thread_join_cleanup,td)==0; } //int __G_E_T() { return sizeof(struct _pthread_descr_struct); } dietlibc-0.33~cvs20120325/libpthread/pthread_join.c010064400000000000000000000014511173363227000166330ustar00#include #include #include #include #include "thread_internal.h" int pthread_join(pthread_t th,void**thread_return) { int ret=ESRCH; _pthread_descr td,this=__thread_self(); if (th==this->pid) return EDEADLK; __NO_ASYNC_CANCEL_BEGIN_(this); if ((td=__thread_find(th))) { /* test if detached or joined */ if (td->detached || __testandset(&(td->joined.__spinlock))) { UNLOCK(td); ret=EINVAL; } else { td->jt=this; UNLOCK(td); /* if not allready canceled / wait for thread to exit */ if (!(td->dead)) __thread_suspend(this,0); if (thread_return) *thread_return=td->retval; /* clean up the mess */ ret=__thread_join_cleanup(td); } } __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_key.c010064400000000000000000000041531173363227000164660ustar00#include #include #include #include #include "thread_internal.h" /* global key data */ static struct _pthread_fastlock __thread_keys_lock; static struct _thread_key __thread_keys[PTHREAD_KEYS_MAX]; /* glue functions ... */ void __thread_start__key(_pthread_descr th); void __thread_exit__key(_pthread_descr th); void __thread_start__key(_pthread_descr th) { memset(th->tkd,0,sizeof(th->tkd)); } void __thread_exit__key(_pthread_descr th) { int i; void (*dstr)(void*); for (i=0;itkd[i]; if (data) dstr(data); } } } /* "create" a thread specific data key */ int pthread_key_create(pthread_key_t*key,void(*destructor)(void*)) { _pthread_descr this=__thread_self(); int ret=EAGAIN,i; __NO_ASYNC_CANCEL_BEGIN_(this); __pthread_lock(&__thread_keys_lock); for (i=0;i=PTHREAD_KEYS_MAX) return EINVAL; __NO_ASYNC_CANCEL_BEGIN_(this); __pthread_lock(&__thread_keys_lock); __thread_keys[key].used=0; __thread_keys[key].destructor=0; __pthread_unlock(&__thread_keys_lock); __NO_ASYNC_CANCEL_END_(this); return 0; } /* get thread specific data */ void*pthread_getspecific(pthread_key_t key) { _pthread_descr this=__thread_self(); void*ret=0; if ((keytkd[key]; } return ret; } /* get thread specific data */ int pthread_setspecific(pthread_key_t key, const void *value) { _pthread_descr this=__thread_self(); if ((keytkd[key]=(void *)value; /* UNCONST */ return 0; } return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_kill.c010064400000000000000000000011621173363227000166260ustar00#include #include #include "thread_internal.h" static int _pthread_kill(pthread_t th,int sig) { int ret=ESRCH; _pthread_descr td; if (th==getpid()) { ret=(kill(th,sig)==-1)?_errno_:0; } else { _pthread_descr this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); if ((td=__thread_find(th))) { UNLOCK(td); ret=(kill(th,sig)==-1)?_errno_:0; } __NO_ASYNC_CANCEL_END_(this); } return ret; } int pthread_kill(pthread_t th,int sig) __attribute__((alias("_pthread_kill"))); int pthread_cancel(pthread_t th) { return _pthread_kill(th,PTHREAD_SIG_CANCEL); } dietlibc-0.33~cvs20120325/libpthread/pthread_mutex_destroy.c010064400000000000000000000003731173363227000206110ustar00#include #include #include #include "thread_internal.h" int pthread_mutex_destroy(pthread_mutex_t*mutex) { if ((mutex->owner)||(mutex->lock.__spinlock!=PTHREAD_SPIN_UNLOCKED)) { return EBUSY; } return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_mutex_init.c010064400000000000000000000005531173363227000200630ustar00#include #include #include #include #include "thread_internal.h" int pthread_mutex_init(pthread_mutex_t*mutex,const pthread_mutexattr_t*mutexattr) { memset(mutex,0,sizeof(pthread_mutex_t)); if (mutexattr) { mutex->kind=mutexattr->__mutexkind; } mutex->lock.__spinlock=PTHREAD_SPIN_UNLOCKED; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_mutex_lock.c010064400000000000000000000013101173363227000200400ustar00#include #include #include #include #include "thread_internal.h" /* will never return EINVAL ! */ static int __thread_mutex_lock(pthread_mutex_t*mutex,_pthread_descr this) { if (mutex->owner!=this) { /* wait for mutex to free */ LOCK(mutex); mutex->owner=this; mutex->count=0; } else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) return EDEADLK; if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) ++(mutex->count); return 0; } int __pthread_mutex_lock(pthread_mutex_t*mutex,_pthread_descr this) __attribute__((alias("__thread_mutex_lock"))); int pthread_mutex_lock(pthread_mutex_t*mutex) { return __thread_mutex_lock(mutex,__thread_self()); } dietlibc-0.33~cvs20120325/libpthread/pthread_mutex_trylock.c010064400000000000000000000010201173363227000205750ustar00#include #include #include #include #include "thread_internal.h" /* will never return EINVAL ! */ int pthread_mutex_trylock(pthread_mutex_t*mutex) { _pthread_descr this=__thread_self(); if (mutex->owner!=this) { /* wait for mutex to free */ if (TRYLOCK(mutex)) return EBUSY; mutex->owner=this; mutex->count=0; } else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) return EDEADLK; if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) ++(mutex->count); return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_mutex_unlock.c010064400000000000000000000013021173363227000204040ustar00#include #include #include #include #include "thread_internal.h" /* will never return EINVAL ! */ static int __thread_mutex_unlock(pthread_mutex_t*mutex,_pthread_descr this) { if (mutex->owner==this) { if (mutex->kind==PTHREAD_MUTEX_RECURSIVE_NP) { if (--(mutex->count)) return 0; } mutex->owner=0; UNLOCK(mutex); } else if (mutex->kind==PTHREAD_MUTEX_ERRORCHECK_NP) { return EPERM; } return 0; } int __pthread_mutex_unlock(pthread_mutex_t*mutex,_pthread_descr this) __attribute__((alias("__thread_mutex_unlock"))); int pthread_mutex_unlock(pthread_mutex_t*mutex) { return __thread_mutex_unlock(mutex,__thread_self()); } dietlibc-0.33~cvs20120325/libpthread/pthread_mutexattr_getkind_np.c010064400000000000000000000003201173363227000221250ustar00#include #include #include #include "thread_internal.h" int pthread_mutexattr_getkind_np(const pthread_mutexattr_t*attr,int*kind) { *kind=attr->__mutexkind; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_mutexattr_init.c010064400000000000000000000004661173363227000207610ustar00#include #include #include #include "thread_internal.h" int pthread_mutexattr_init(pthread_mutexattr_t*attr) { attr->__mutexkind=PTHREAD_MUTEX_FAST_NP; return 0; } int pthread_mutexattr_destroy(pthread_mutexattr_t*attr) __attribute__((alias ("pthread_mutexattr_init"))); dietlibc-0.33~cvs20120325/libpthread/pthread_mutexattr_setkind_np.c010064400000000000000000000005311173363227000221450ustar00#include #include #include #include "thread_internal.h" int pthread_mutexattr_setkind_np(pthread_mutexattr_t*attr,int kind) { if ((kind==PTHREAD_MUTEX_FAST_NP)||(kind==PTHREAD_MUTEX_RECURSIVE_NP)|| (kind==PTHREAD_MUTEX_ERRORCHECK_NP)) { attr->__mutexkind=kind; return 0; } return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_self.c010064400000000000000000000001251173363227000166220ustar00#include #include int pthread_self() { return getpid(); } dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_destroy.c010064400000000000000000000004671173363227000214360ustar00#include #include #include #include #include "thread_internal.h" int sem_destroy(sem_t*sem) { int n; if (sem->magic!=SEM_MAGIC) { _errno_=EINVAL; return -1; } if ((n=pthread_cond_destroy(&sem->cond))) { _errno_=n; return -1; } sem->magic=0; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_getvalue.c010064400000000000000000000003661173363227000215570ustar00#include #include #include #include #include "thread_internal.h" int sem_getvalue(sem_t*sem,int*sval) { if (sem->magic!=SEM_MAGIC) { _errno_=EINVAL; return -1; } *sval=sem->value; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_init.c010064400000000000000000000007261173363227000207060ustar00#include #include #include #include #include "thread_internal.h" int sem_init(sem_t*sem,int pshared,unsigned int value) { pthread_mutexattr_t attr={PTHREAD_MUTEX_RECURSIVE_NP}; if (value>SEM_VALUE_MAX) { _errno_=EINVAL; return -1; } if (pshared) { _errno_=ENOSYS; return -1; } pthread_mutex_init(&(sem->lock),&attr); pthread_cond_init(&(sem->cond),0); sem->value=value; sem->magic=SEM_MAGIC; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_misc.c010064400000000000000000000005611173363227000206730ustar00#include #include #include #include #include "thread_internal.h" sem_t*sem_open(const char*name,int oflag,...) { if (0) { name=0; oflag=0; } _errno_=ENOSYS; return 0; } int sem_close(sem_t*sem) { if (0) sem=0; _errno_=ENOSYS; return -1; } int sem_unlink(const char *name) __attribute__((alias("sem_close"))); dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_post.c010064400000000000000000000022331173363227000207230ustar00#include #include #include #include "thread_internal.h" /* ThreadManager Function / NO_ASYNC_CANCEL * this is a pthread_cond_signal + semaphore handling */ /* FIXME: is the pthread_mutex_lock(&sem->lock); and unlock needed ? */ static int __MGR_sem_post(sem_t*sem) { int ret=0; if (sem->value==0) { pthread_cond_t*cond=&sem->cond; LOCK(cond); if (cond->wait_chain) __thread_restart(cond->wait_chain); UNLOCK(cond); } if (sem->valuevalue++; else { _errno_=ERANGE; ret=-1; } return ret; } int sem_post(sem_t*sem) { int ret=0; _pthread_descr this; if (sem->magic!=SEM_MAGIC) { _errno_=EINVAL; return -1; } this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); if ((ret=pthread_mutex_lock(&sem->lock))) { _errno_=ret; ret=-1; } else if (sem->lock.count>1) { /* ok... we are in a semaphor handling and a signal handler. * now we want to send a post... let the manager do this for us :) */ __thread_send_manager((MGR_func)__MGR_sem_post,sem); } else ret=__MGR_sem_post(sem); pthread_mutex_unlock(&sem->lock); __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_trywait.c010064400000000000000000000010571173363227000214440ustar00#include #include #include #include #include "thread_internal.h" int sem_trywait(sem_t*sem) { int ret; _pthread_descr this; if (sem->magic!=SEM_MAGIC) { _errno_=EINVAL; return -1; } this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); if ((ret=pthread_mutex_lock(&(sem->lock)))) { _errno_=ret; ret=-1; } else if (sem->value==0) { _errno_=EAGAIN; ret=-1; } else { sem->value--; ret=0; } pthread_mutex_unlock(&(sem->lock)); __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_semaphore_wait.c010064400000000000000000000010511173363227000206770ustar00#include #include #include #include #include "thread_internal.h" int sem_wait(sem_t*sem) { int ret=0; _pthread_descr this; if (sem->magic!=SEM_MAGIC) { _errno_=EINVAL; return -1; } this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); if ((ret=pthread_mutex_lock(&sem->lock))) { _errno_=ret; ret=-1; } else { while (sem->value==0) { pthread_cond_wait(&sem->cond,&sem->lock); } sem->value--; } pthread_mutex_unlock(&sem->lock); __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_setcancelstate.c010064400000000000000000000005631173363227000207010ustar00#include #include #include #include "thread_internal.h" int pthread_setcancelstate(int state,int*oldstate) { if ((state==PTHREAD_CANCEL_ENABLE)||(state==PTHREAD_CANCEL_DISABLE)) { _pthread_descr this=__thread_self(); if (oldstate) *oldstate=this->cancelstate; this->cancelstate=state; return 0; } return EINVAL; } dietlibc-0.33~cvs20120325/libpthread/pthread_setschedparam.c010064400000000000000000000012121173363227000205120ustar00#include #include #include #include "thread_internal.h" /* set thread schedul parameters */ int pthread_setschedparam(pthread_t th,int policy,const struct sched_param*param) { int ret=ESRCH; _pthread_descr td,this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); if ((td=__thread_find(th))) { UNLOCK(td); ret=EINVAL; if (((policy==SCHED_OTHER)&&(param->sched_priority==0)) || (((policy==SCHED_RR)||(policy==SCHED_FIFO))&& ((param->sched_priority>0)&&(param->sched_priority<100)))) ret=(sched_setscheduler(th,policy,param))?_errno_:0; } __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_sigaction.c010064400000000000000000000004561173363227000176600ustar00#include #include #include "thread_internal.h" int sigaction(int signum,const struct sigaction*act,struct sigaction*old) { if ((signum==PTHREAD_SIG_RESTART)||(signum==PTHREAD_SIG_CANCEL)) { _errno_=EINVAL; return -1; } return __libc_sigaction(signum,act,old); } dietlibc-0.33~cvs20120325/libpthread/pthread_sigmask.c010064400000000000000000000011021173363227000173230ustar00#include #include #include "thread_internal.h" int pthread_sigmask(int how, const sigset_t*newset, sigset_t *oldset) { sigset_t mask; if (newset) { mask=*newset; switch (how) { case SIG_SETMASK: sigaddset(&mask,PTHREAD_SIG_RESTART); sigdelset(&mask,PTHREAD_SIG_CANCEL); break; case SIG_BLOCK: sigdelset(&mask,PTHREAD_SIG_CANCEL); break; case SIG_UNBLOCK: sigdelset(&mask,PTHREAD_SIG_RESTART); break; } newset=&mask; } return (sigprocmask(how,newset,oldset)==-1)?_errno_:0; } dietlibc-0.33~cvs20120325/libpthread/pthread_spinlock.c010064400000000000000000000011371173363227000175170ustar00#include #include #include "thread_internal.h" void __pthread_lock(struct _pthread_fastlock*lock) { int cnt=0; struct timespec tm; while (__testandset(&lock->__spinlock)) { if (cnt__spinlock); } int __pthread_unlock(struct _pthread_fastlock*lock) { lock->__spinlock=PTHREAD_SPIN_UNLOCKED; return 0; } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_alloc.c010064400000000000000000000017321173363227000176660ustar00#include #include #include "thread_internal.h" #include static pthread_mutex_t mutex_alloc=PTHREAD_MUTEX_INITIALIZER; void free(void *ptr) { _pthread_descr this=__thread_self(); __NO_ASYNC_CANCEL_BEGIN_(this); __pthread_mutex_lock(&mutex_alloc,this); __libc_free(ptr); __pthread_mutex_unlock(&mutex_alloc,this); __NO_ASYNC_CANCEL_END_(this); } void *malloc(size_t size) { _pthread_descr this=__thread_self(); register void *ret; __NO_ASYNC_CANCEL_BEGIN_(this); __pthread_mutex_lock(&mutex_alloc,this); ret=__libc_malloc(size); __pthread_mutex_unlock(&mutex_alloc,this); __NO_ASYNC_CANCEL_END_(this); return ret; } void* realloc(void* ptr, size_t size) { _pthread_descr this=__thread_self(); register void *ret; __NO_ASYNC_CANCEL_BEGIN_(this); __pthread_mutex_lock(&mutex_alloc,this); ret=__libc_realloc(ptr, size); __pthread_mutex_unlock(&mutex_alloc,this); __NO_ASYNC_CANCEL_END_(this); return ret; } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_close.c010064400000000000000000000002141173363227000176730ustar00#include #include #include "thread_internal.h" int close(int fd) { __TEST_CANCEL(); return __libc_close(fd); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_create.c010064400000000000000000000002621173363227000200340ustar00#include #include #include "thread_internal.h" int creat(const char *pathname, mode_t mode) { __TEST_CANCEL(); return __libc_creat(pathname,mode); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_fcntl.c010064400000000000000000000003171173363227000177000ustar00#include #include #include "thread_internal.h" int fcntl(int fd, int cmd, void *arg); int fcntl(int fd, int cmd, void *arg) { __TEST_CANCEL(); return __libc_fcntl(fd,cmd,arg); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_fdatasync.c010064400000000000000000000002241173363227000205430ustar00#include #include #include "thread_internal.h" int fdatasync(int fd) { __TEST_CANCEL(); return __libc_fdatasync(fd); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_fsync.c010064400000000000000000000002141173363227000177100ustar00#include #include #include "thread_internal.h" int fsync(int fd) { __TEST_CANCEL(); return __libc_fsync(fd); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_logging.c010064400000000000000000000015251173363227000202220ustar00#include #include #include #include "thread_internal.h" #include static pthread_mutex_t mutex_syslog=PTHREAD_MUTEX_INITIALIZER; void closelog(void) { pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock,&mutex_syslog); pthread_mutex_lock(&mutex_syslog); __libc_closelog(); pthread_cleanup_pop(1); } void openlog(const char*ident,int option,int facility) { pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock,&mutex_syslog); pthread_mutex_lock(&mutex_syslog); __libc_openlog(ident, option, facility); pthread_cleanup_pop(1); } void vsyslog(int priority,const char*format,va_list arg_ptr) { pthread_cleanup_push((void(*)(void*))pthread_mutex_unlock,&mutex_syslog); pthread_mutex_lock(&mutex_syslog); __libc_vsyslog(priority, format, arg_ptr); pthread_cleanup_pop(1); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_msync.c010064400000000000000000000003071173363227000177220ustar00#include #include #include #include "thread_internal.h" int msync (void*addr,size_t len,int flags) { __TEST_CANCEL(); return __libc_msync(addr,len,flags); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_nanosleep.c010064400000000000000000000003251173363227000205550ustar00#include #include #include #include "thread_internal.h" int nanosleep(const struct timespec *req, struct timespec *rem) { __TEST_CANCEL(); return __libc_nanosleep(req,rem); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_open.c010064400000000000000000000005471173363227000175400ustar00#include #include #include "thread_internal.h" int __pthread_open(const char *pathname, int flags, mode_t mode); int __pthread_open(const char *pathname, int flags, mode_t mode) { __TEST_CANCEL(); return __libc_open(pathname,flags,mode); } int open(const char *pathname, int flags, ...) __attribute__((alias("__pthread_open"))); dietlibc-0.33~cvs20120325/libpthread/pthread_sys_pause.c010064400000000000000000000002041173363227000177020ustar00#include #include #include "thread_internal.h" int pause() { __TEST_CANCEL(); return __libc_pause(); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_read.c010064400000000000000000000002611173363227000175030ustar00#include #include #include "thread_internal.h" ssize_t read(int fd, void *buf, size_t count) { __TEST_CANCEL(); return __libc_read(fd,buf,count); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_sigsuspend.c010064400000000000000000000002461173363227000207570ustar00#include #include #include "thread_internal.h" int sigsuspend(const sigset_t *mask) { __TEST_CANCEL(); return __libc_sigsuspend(mask); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_sleep.c010064400000000000000000000002631173363227000177020ustar00#include #include unsigned int sleep(unsigned int secs) { struct timespec t; t.tv_sec=secs; t.tv_nsec=0; nanosleep(&t,&t); return secs-t.tv_sec; } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_tcdrain.c010064400000000000000000000002461173363227000202170ustar00#include #include #include "thread_internal.h" #include int tcdrain(int fd) { __TEST_CANCEL(); return __libc_tcdrain(fd); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_waitpid.c010064400000000000000000000003261173363227000202330ustar00#include #include #include "thread_internal.h" #include pid_t waitpid(pid_t pid, int *status, int options) { __TEST_CANCEL(); return __libc_waitpid(pid,status,options); } dietlibc-0.33~cvs20120325/libpthread/pthread_sys_write.c010064400000000000000000000002711173363227000177230ustar00#include #include #include "thread_internal.h" ssize_t write(int fd, const void *buf, size_t count) { __TEST_CANCEL(); return __libc_write(fd,buf,count); } dietlibc-0.33~cvs20120325/libpthread/test-basic.c010064400000000000000000000565731173363227000162420ustar00#include #include #include #include #include #include #include #include #include #include "thread_internal.h" #define pr(s) write(1,s,sizeof(s)-1) #define pl(s) write(1,s,strlen(s)) #define _die_(s) do { write(2,s,sizeof(s)-1); exit(2); } while(0) #if 0 static void ph(unsigned long v) { const char foo[16]="0123456789abcdef"; char buf[sizeof(long)<<1]; int i; for (i=sizeof(buf);i--;v>>=4) { buf[i]=foo[v&15]; } write(1,buf,sizeof(buf)); } #endif /* (0) once test */ void test0_ok() { pr("(once called) "); } void test0_failed() { _die_("failed...\n"); } void test0() { pthread_once_t v_once=PTHREAD_ONCE_INIT; pr("\nTEST 0: once test:\n\n"); pr("testing once function... "); pthread_once(&v_once,test0_ok); pthread_once(&v_once,test0_failed); pr("OK.\n"); } /* (1) mutex tests */ pthread_mutex_t*hang_m; volatile int hangok; void sig_alrm(int sig) { signal(SIGALRM,sig_alrm); alarm(2); if (0) sig=0; if (hangok==0) _die_("still hanging\n"); --hangok; hang_m->owner=__thread_self(); pthread_mutex_unlock(hang_m); hang_m->owner=0; } void test_block_try() { pthread_mutex_t tm=PTHREAD_MUTEX_INITIALIZER; hang_m=&tm; alarm(1); pr("testing block of a mutex (takes 1-5 second)... "); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on unused mutex...\n"); hangok=1; tm.owner=0; if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on taken mutex...\n"); if (hangok) _die_("failed... still unblocked\n"); pr("OK.\n"); pr("testing trylock... "); tm.owner=0; if (pthread_mutex_trylock(&tm) != EBUSY) _die_("failed... mutex_trylock on blocked mutex...\n"); tm.owner=__thread_self(); if (pthread_mutex_trylock(&tm) != 0) _die_("failed... mutex_trylock on taken mutex...\n"); pr("OK.\n"); alarm(0); } void test_mutex() { pthread_mutex_t tm=PTHREAD_MUTEX_INITIALIZER; pr("testing basic mutex... "); alarm(5); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on unused mutex...\n"); if (tm.owner!=__thread_self()) _die_("failed.. no owner....\n"); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on taken mutex...\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on taken mutex...\n"); if (tm.owner!=0) _die_("failed... still owned ?!?!\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on free mutex...\n"); alarm(0); pr("OK.\n"); } void test_rec_mutex() { pthread_mutex_t tm=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; pr("testing recursive mutex... "); alarm(5); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on unused rec-mutex (c=0)...\n"); if (tm.owner!=__thread_self()) _die_("failed.. wrong owner....\n"); if (tm.count!=1) _die_("failed... wrong counting (c!=1)....\n"); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on taken rec-mutex (c=1)...\n"); if (tm.count!=2) _die_("failed... wrong counting (c!=2)....\n"); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on taken rec-mutex (c=2)...\n"); if (tm.count!=3) _die_("failed... wrong counting (c!=3)....\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on taken rec-mutex (c=3)...\n"); if (tm.count!=2) _die_("failed... wrong counting (c!=2)....\n"); if (tm.owner==0) _die_("failed... mutex has no owner?!?!\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on taken rec-mutex (c=2)...\n"); if (tm.count!=1) _die_("failed... wrong counting (c!=1)....\n"); if (tm.owner==0) _die_("failed... mutex has no owner?!?!\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on taken rec-mutex (c=1)...\n"); if (tm.count!=0) _die_("failed... wrong counting (c!=0)....\n"); if (tm.owner!=0) _die_("failed... mutex still owned ?!?!\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on free rec-mutex (c=0)...\n"); alarm(0); pr("OK.\n"); } void test_err_mutex() { pthread_mutex_t tm=PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; pr("testing errorcheck mutex... "); alarm(5); if (pthread_mutex_lock(&tm) != 0) _die_("failed... mutex_lock on unused errchk-mutex...\n"); if (tm.owner!=__thread_self()) _die_("failed.. wrong owner....\n"); if (pthread_mutex_lock(&tm) != EDEADLK) _die_("failed... mutex_lock on taken errchk-mutex...\n"); if (pthread_mutex_unlock(&tm) != 0) _die_("failed... mutex_unlock on taken errchk-mutex...\n"); if (tm.owner!=0) _die_("failed... mutex still owned ?!?!\n"); if (pthread_mutex_unlock(&tm) != EPERM) _die_("failed... mutex_unlock on free errchk-mutex...\n"); alarm(0); pr("OK.\n"); } void test_init_mutex() { pthread_mutex_t tm=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t te=PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP; pthread_mutexattr_t ta; pthread_mutex_t tt; pr("testing mutex initalizer... "); pthread_mutex_init(&tt,0); if (memcmp(&tt,&tm,sizeof(pthread_mutex_t))) _die_("failed... default init...\n"); pthread_mutexattr_init(&ta); pthread_mutex_init(&tt,&ta); if (memcmp(&tt,&tm,sizeof(pthread_mutex_t))) _die_("failed... default with attr init...\n"); pthread_mutexattr_init(&ta); if (pthread_mutexattr_setkind_np(&ta,23) == 0) _die_("failed... can set unsupported value !\n"); if (pthread_mutexattr_setkind_np(&ta,PTHREAD_MUTEX_ERRORCHECK_NP) != 0) _die_("failed... can't set basic type...\n"); pthread_mutex_init(&tt,&ta); if (memcmp(&tt,&te,sizeof(pthread_mutex_t))) _die_("failed... mutexattr generated mutex is not equal to the static init...\n"); pr("OK.\n"); } void test1() { pr("\nTEST 1: mutex test:\n\n"); test_init_mutex(); test_mutex(); test_rec_mutex(); test_err_mutex(); test_block_try(); } /* (2) thread attr function tests */ void*thread(void*arg) { if (0) { arg=0; } pr("(thread created) "); sleep(1); pr("(thread exit) "); return 0; } void test_thread() { pthread_t t; pr("testing basic thread creation and join... "); if ((pthread_create(&t,0,thread,0))!=0) _die_("failed...\n"); if (kill(t,0)==-1) _die_("failed... no thread cloned"); if (pthread_join(t,0) != 0) _die_("failed... joining thread\n"); pr("OK.\n"); } void test_thread_join_detached() { pthread_t t; pthread_attr_t attr; pr("testing for failing join of a detached thread... "); pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED); if ((pthread_create(&t,&attr,thread,0))!=0) _die_("failed...\n"); if (pthread_join(t,0) == 0) _die_("failed... I had joined a detached thread !\n"); sleep(2); pr("OK.\n"); } static char alt_stack[64<<10]; void test_thread_alt_stack() { pthread_t t; pthread_attr_t attr; pr("testing alternate thread stack... "); pthread_attr_init(&attr); pthread_attr_setstacksize(&attr,64<<10); if ((pthread_create(&t,&attr,thread,0))!=0) _die_("failed... creating thread\n"); if (pthread_join(t,0) != 0) _die_("failed... joining thread\n"); pthread_attr_setstackaddr(&attr,alt_stack); if ((pthread_create(&t,&attr,thread,0))!=0) _die_("failed... creating thread\n"); if (pthread_join(t,0) != 0) _die_("failed... joining thread\n"); pr("OK.\n"); } void test2() { pr("\nTEST 2: thread creation & attributes:\n\n"); test_thread(); test_thread_join_detached(); test_thread_alt_stack(); } /* (3) condition variables and mutex the 2nd */ pthread_cond_t test_cond=PTHREAD_COND_INITIALIZER; pthread_mutex_t test_cond_mutex=PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t test_cond_exit_mutex=PTHREAD_MUTEX_INITIALIZER; void*thread_cond_wait(void*arg) { if (arg) pr("(thread_cond_wait create) "); pthread_mutex_lock(&test_cond_mutex); if (pthread_cond_wait(&test_cond,&test_cond_mutex) != 0) _die_("failed... wait\n"); pthread_mutex_unlock(&test_cond_mutex); if (arg) pr("(thread_cond_wait exit) "); pthread_mutex_unlock(&test_cond_exit_mutex); return 0; } void test_conditions() { pthread_cond_t c=PTHREAD_COND_INITIALIZER; pr("testing basic condition initializer/destructor... "); pthread_cond_init(&test_cond,0); if (memcmp(&test_cond,&c,sizeof(pthread_cond_t))) _die_("failed... initializer\n"); if (pthread_cond_destroy(&test_cond)!=0) _die_("failed... destructor\n"); pr("OK.\n"); } void test_conditions_timed() { struct timeval tv; struct timespec ts; pthread_cond_init(&test_cond,0); pr("testing condition timedwait (takes 1-4 seconds)... "); pthread_mutex_lock(&test_cond_mutex); if (gettimeofday(&tv,0)) _die_("failed... >>> gettimeofday\n"); ts.tv_sec=tv.tv_sec+2; ts.tv_nsec=0; alarm(4); if (pthread_cond_timedwait(&test_cond,&test_cond_mutex,&ts) != 0) _die_("failed... timedwait\n"); alarm(0); pthread_mutex_unlock(&test_cond_mutex); pr("OK.\n"); } void test_conditions_signal() { pthread_t t1,t2,t3; pr("- creating two threads for condition signal... "); pthread_mutex_lock(&test_cond_mutex); if ((pthread_create(&t1,0,thread_cond_wait,0))!=0) _die_("failed...\n"); if ((pthread_create(&t2,0,thread_cond_wait,0))!=0) _die_("failed...\n"); pthread_mutex_unlock(&test_cond_mutex); pr("OK.\n"); sleep(1); pr("testing failure of destroy on used condition variable... "); if (pthread_cond_destroy(&test_cond)==0) _die_("failed... still in use but destroied\n"); pr("OK.\n"); pr("testing cged_startondition signal (takes 4-6 seconds)... "); pthread_mutex_lock(&test_cond_exit_mutex); alarm(10); sleep(1); pr(" "); pthread_cond_signal(&test_cond); pthread_mutex_lock(&test_cond_exit_mutex); sleep(1); pr("(new thread for wait-chain test) "); if ((pthread_create(&t3,0,thread_cond_wait,0))!=0) _die_("failed... thread creation\n"); sleep(1); pr(" "); pthread_cond_signal(&test_cond); pthread_mutex_lock(&test_cond_exit_mutex); sleep(1); pr(" "); pthread_cond_signal(&test_cond); pthread_mutex_lock(&test_cond_exit_mutex); alarm(0); sleep(1); if (kill(t1,0)==0) _die_("failed... thread (nr. 1) ignored signal\n"); if (kill(t2,0)==0) _die_("failed... thread (nr. 2) ignored signal\n"); if (kill(t3,0)==0) _die_("failed... thread (nr. 3) ignored signal\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t2,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t3,0) != 0) _die_("failed... joining thread\n"); pr("OK.\n"); } void test_conditions_broadcast() { pthread_t t1,t2,t3; pr("testing condition broadcast (takes 4-5 seconds)... "); pthread_mutex_lock(&test_cond_mutex); if ((pthread_create(&t1,0,thread_cond_wait,0))!=0) _die_("failed... thread creation\n"); if ((pthread_create(&t2,0,thread_cond_wait,0))!=0) _die_("failed... thread creation\n"); if ((pthread_create(&t3,0,thread_cond_wait,0))!=0) _die_("failed... thread creation\n"); pthread_mutex_unlock(&test_cond_mutex); sleep(1); alarm(4); pr(" "); pthread_cond_broadcast(&test_cond); sleep(3); if (kill(t1,0)==0) _die_("failed... thread (nr. 1) ignored signal\n"); if (kill(t2,0)==0) _die_("failed... thread (nr. 2) ignored signal\n"); if (kill(t3,0)==0) _die_("failed... thread (nr. 3) ignored signal\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t2,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t3,0) != 0) _die_("failed... joining thread\n"); alarm(0); pr("OK.\n"); } void*thread_cond_timedwait(void*arg) { struct timeval tv; struct timespec ts; if (0) { arg=0; } if (gettimeofday(&tv,0)) _die_("failed... >>> gettimeofday\n"); ts.tv_sec=tv.tv_sec+1; ts.tv_nsec=tv.tv_usec/1000; pr("(thread_cond_timedwait created) "); pthread_mutex_lock(&test_cond_mutex); if (pthread_cond_timedwait(&test_cond,&test_cond_mutex,&ts) != 0) _die_("failed... timedwait\n"); pthread_mutex_unlock(&test_cond_mutex); pr("(thread_cond_timedwait exit) "); pthread_mutex_unlock(&test_cond_exit_mutex); return 0; } void test_conditions_mixed() { pthread_t t1,t2,t3; pr("testing condition mixed wait and timedwait (takes 3-5 seconds)... "); pthread_mutex_lock(&test_cond_exit_mutex); pthread_mutex_lock(&test_cond_mutex); if ((pthread_create(&t1,0,thread_cond_wait,(void*)1))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t2,0,thread_cond_timedwait,(void*)1))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t3,0,thread_cond_wait,(void*)1))!=0) _die_("failed... (creating a thread)\n"); pthread_mutex_unlock(&test_cond_mutex); sleep(1); alarm(5); pthread_mutex_lock(&test_cond_exit_mutex); pthread_cond_broadcast(&test_cond); sleep(2); if (kill(t1,0)==0) _die_("failed... thread (nr. 1) ignored signal\n"); if (kill(t2,0)==0) _die_("failed... thread (nr. 2) ignored signal\n"); if (kill(t3,0)==0) _die_("failed... thread (nr. 3) ignored signal\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t2,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t3,0) != 0) _die_("failed... joining thread\n"); alarm(0); pr("OK.\n"); } void test3() { pr("\nTEST 3: condition variables and mutexes:\n\n"); test_conditions(); test_conditions_timed(); test_conditions_signal(); test_conditions_broadcast(); test_conditions_mixed(); } /* (4) cancelation & cleanup tests */ void*thread_exit() { pthread_exit((void*)42); return 0; } void test4_thread_exit() { pthread_t t; void*retval; pr("testing pthread_exit... "); if ((pthread_create(&t,0,thread_exit,0))!=0) _die_("failed... creating thread\n"); if (pthread_join(t,&retval) != 0) _die_("failed... joining thread\n"); if (kill(t,0)!=-1) _die_("failed... thread exit\n"); if (retval!=(void*)42) _die_("failed... join retval\n"); pr("OK.\n"); } int thread_cleanuptest_data=0; void thread_cleanuptest() { pr("{cleanup} "); thread_cleanuptest_data=1; } void*thread_cancel(void*a) { pthread_cleanup_push(thread_cleanuptest,0); while(a) { sleep(1); pr("(!canceled) "); } return 0; } void test4_cleanup() { pthread_t t1; pr("testing the cleanup stack... "); if ((pthread_create(&t1,0,thread_cancel,(void*)0))!=0) _die_("failed... (creating a thread)\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (thread_cleanuptest_data==0) _die_("failed... no call to cleanup\n"); pr("OK.\n"); } void*thread_canceler(void*a) { sleep(3); pr(" "); if (pthread_cancel(*((pthread_t*)a))) { _die_("cancel error\n"); } return 0; } void test4_cancelation() { pthread_t t1,t2; thread_cleanuptest_data=0; pr("testing cancelation and cleanup stack (takes 3-4 seconds)... "); if ((pthread_create(&t1,0,thread_cancel,(void*)1))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t2,0,thread_canceler,(void*)&t1))!=0) _die_("failed... (creating a thread)\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t2,0) != 0) _die_("failed... joining thread\n"); if (thread_cleanuptest_data==0) _die_("failed... no call to cleanup\n"); if (kill(t1,0)!=-1) _die_("failed... thread cancelation\n"); if (kill(t2,0)!=-1) _die_("failed... thread cancelation\n"); pr("OK.\n"); } void*thread_cancel_async(void*a) { unsigned int i; if (a) pthread_cleanup_push(thread_cleanuptest,0); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,0); pr("(act)... "); for(i=1;;++i) { if ((i&0xfffffff)==0) pr("(!canceled) "); } return 0; } void test4_asynccancel() { pthread_t t1,t2; thread_cleanuptest_data=0; pr("testing async cancelation and cleanup stack (takes 5-6 seconds)... "); if ((pthread_create(&t1,0,thread_cancel_async,(void*)1))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t2,0,thread_canceler,(void*)&t1))!=0) _die_("failed... (creating a thread)\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t2,0) != 0) _die_("failed... joining thread\n"); if (thread_cleanuptest_data==0) _die_("failed... no call to cleanup\n"); if (kill(t1,0)!=-1) _die_("failed... thread cancelation\n"); if (kill(t2,0)!=-1) _die_("failed... thread cancelation\n"); pr("OK.\n"); } void test4() { pr("\nTEST 4: cancelation & cleanup:\n\n"); test4_thread_exit(); test4_cleanup(); test4_cancelation(); test4_asynccancel(); } /* (5) unix signaling */ int test5_signaled=0; void test5_sighandler() { pr("{SIGUSR1} "); signal(SIGUSR1,test5_sighandler); test5_signaled=1; } void*test5_0() { pr("testing the user signal... "); signal(SIGUSR1,test5_sighandler); sleep(1); raise(SIGUSR1); sleep(1); if (test5_signaled==0) _die_("failed... no signal caught\n"); pr("OK.\n"); return 0; } void test5_1() { pthread_t t1; test5_signaled=0; pr("IN A THREAD... "); if ((pthread_create(&t1,0,test5_0,0))!=0) _die_("failed... (creating a thread)\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); } void*test5_sig_send(void*arg) { pr(" "); sleep(1); kill((long)arg,SIGUSR1); pr(" "); return 0; } void test5_2() { pthread_t t1; pr("sending the main program a signal from a thread while joined... "); signal(SIGUSR1,test5_sighandler); if ((pthread_create(&t1,0,test5_sig_send,(void*)getpid()))!=0) _die_("failed... (creating a thread)\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (test5_signaled==0) _die_("failed to hold...\n"); pr("OK.\n"); } void test5() { pr("\nTEST 5: UNIX signaling:\n\n"); test5_0(0); test5_1(); test5_2(); } /* (6) exit call in thread */ int test6_libc_exit_done=0; void* test6_libc_exit() { pr(" "); sleep(1); pr("\n"); test6_libc_exit_done=1; exit(42); } void test6() { pthread_t t1,t2,t3,t4; pr("\nTEST 6: thread calls 'exit(42)' :\n\n"); pr("creating thread that will call exit: "); if ((pthread_create(&t1,0,thread_cancel_async,(void*)0))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t2,0,thread_cancel_async,(void*)0))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t3,0,thread_cancel_async,(void*)0))!=0) _die_("failed... (creating a thread)\n"); if ((pthread_create(&t4,0,test6_libc_exit,0))!=0) _die_("failed... (creating a thread)\n"); if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t2,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t3,0) != 0) _die_("failed... joining thread\n"); if (pthread_join(t4,0) != 0) _die_("failed... joining thread\n"); for (t1=0;t1<4;++t1) { sleep(2); pr("still hanging....\n"); } _die_("failed... 'exit(..)'\n"); } /* fork to function */ int __sub_do(void(*fn)(int r),int r) { int i; if ((i=fork())==0) { fn(r); exit(0); } else if (i==-1) _die_("can't fork away...\n"); waitpid(i,&i,0); return i; } /* run in a subprocess */ void __fn_basic_tests(int r) { pr("\nIt seams that the 'fork()' wrapper is ok...\n" "\n--- STARTING BASIC TESTS ---\n"); if (r&0x0001) test0(); /* once */ if (r&0x0002) test1(); /* mutex */ if (r&0x0004) test2(); /* thread creation & attributes */ if (r&0x0008) test3(); /* conditions and mutexes */ if (r&0x0010) test4(); /* cancelation & cleanup */ if (r&0x0020) test5(); /* signaling */ if (r&0x0040) test6(); /* exit */ exit(42); } /* do the tests */ void __do_basic_tests(unsigned int r) { int i; i=__sub_do(__fn_basic_tests,r); if ((WIFSIGNALED(i))&&(WTERMSIG(i)!=SIGALRM)) _die_("Oh oh.... exit on signal (wrapper bug ?!?)....\n"); if ((WIFEXITED(i))&&(WEXITSTATUS(i)==42)) pr("\n--- END OF BASIC TESTS ---\n\n"); else if (test6_libc_exit_done) _die_("EXIT value was not correctly forwared...\n"); else _die_("a test has failed...\n"); } /* ADVANCED TESTS */ /* (8) fork / pthread_atfork */ int test8_fork_val; void test8_fork_pre() { pr("
 "); test8_fork_val=0; }
void test8_fork_post() { pr(" "); test8_fork_val=1; }
void test8_fork_child() { pr(" "); test8_fork_val=2; }

void test8_0() {
  pr("adding fork handler for prefork-, parent- and child-condition... ");
  if (pthread_atfork(test8_fork_pre,test8_fork_post,test8_fork_child))
    _die_("failed...\n");
  pr("OK.\n");
}

void*test8_1() {
  int i;
  pr("make a fork call... ");
  if ((i=fork())) {
    if (test8_fork_val!=1) _die_("handler not called ?\n");
    pr("{parent} ");
    waitpid(i,&i,0);
    if (WEXITSTATUS(i)!=2) _die_("fork child handler not called...\n");
  }
  else {
    pr("{child} ");
    exit(test8_fork_val);
  }
  pr("OK.\n");
  return 0;
}

void test8_2() {
  pthread_t t1;
  pr("IN A THREAD... ");
  if ((pthread_create(&t1,0,test8_1,0))!=0) _die_("failed... (creating a thread)\n");
  if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n");
}

void test8() {
  pr("\nTEST 8: fork / pthread_atfork:\n\n");
  test8_0();
  test8_1();
  test8_2();
}

/* (9) signales */

void*test9_0_0() {	/* create a SIGSEGV */
  char*c=0;
//  pr("
 ");
  *c=0;
  return c;
}

void test9_0() {
  int i;
  pr("check if process dies with a SIGSEGV on NULL-pointer derefernce... ");
  i=__sub_do((void(*)(int))test9_0_0,0);
  if ((!WIFSIGNALED(i))||(WTERMSIG(i)!=SIGSEGV)) _die_("failed... (system is broken.... THIS MUST WORK!!!)\n");
  pr("OK.\n");
}

void test9_1_0() {
  pthread_t t1;
  if ((pthread_create(&t1,0,test9_0_0,0))!=0) _die_("failed... (creating a thread)\n");
  if (pthread_join(t1,0) != 0) _die_("failed... joining thread\n");
  pr("???\n");
}

void test9_1() {
  int i;
  pr("check if process dies with a SIGSEGV on NULL-pointer derefernce in a thread... ");
  i=__sub_do(test9_1_0,0);
  if (!WIFSIGNALED(i)) _die_("failed...\n");
  if (WTERMSIG(i)==SIGKILL) pr("(2.5+ sends a SIGKILL) ");
  else if (WTERMSIG(i)!=SIGSEGV) _die_("failed...\n");
  //if ((!WIFSIGNALED(i))||(WTERMSIG(i)!=SIGSEGV)) _die_("failed...\n");
  pr("OK.\n");
}

void test9_2_sig_handler() {
  signal(SIGSEGV,SIG_DFL);
  pr(" ");
  raise(SIGSEGV);
}
void test9_2_0() {
  pthread_t t1,t2,t3,t4;
  alarm(10);
  signal(SIGSEGV,test9_2_sig_handler);
  if ((pthread_create(&t1,0,thread_cancel_async,(void*)0))!=0) _die_("failed... (creating a thread)\n");
  if ((pthread_create(&t2,0,thread_cancel_async,(void*)0))!=0) _die_("failed... (creating a thread)\n");
  if ((pthread_create(&t3,0,thread_cancel_async,(void*)0))!=0) _die_("failed... (creating a thread)\n");
  if ((pthread_create(&t4,0,test9_0_0,0))!=0) _die_("failed... (creating a thread)\n");
  pthread_join(t4,0);
  pr("...Oh... ");
  pthread_join(t3,0);
  pthread_join(t2,0);
  pthread_join(t1,0);
  alarm(0);
  exit(0);
}

void test9_2() {
  int i;
  pr("- create some threads... one makes a segv... ");
  i=__sub_do(test9_2_0,0);
  if (!WIFSIGNALED(i)) _die_("failed...\n");
  if (WTERMSIG(i)==SIGKILL) pr("(2.5+ sends a SIGKILL) ");
  else if (WTERMSIG(i)!=SIGSEGV) _die_("failed...\n");
  //if ((!WIFSIGNALED(i))||(WTERMSIG(i)!=SIGSEGV)) _die_("failed...\n");
  pr("OK.\n");
}

void test9() {
  pr("\nTEST 9: UNIX signales the second:\n\n");
  test9_0();
  test9_1();
  test9_2();
}

/* do the tests */
void __do_advanced_tests(unsigned int r) {
  pr("\n--- STARTING ADVANCED TESTS ---\n");
  if (r&0x0100) __sub_do(test8,0);	/* fork / pthread_atfork */
  if (r&0x0200) test9();		/* unix signals (second run) */
  pr("\n--- END OF ADVANCED TESTS ---\n\n");
}

/* main */
int main(int argc,char*argv[]) {
  unsigned int r=~0;
  if (argc>1) {
    int i,j;
    for (r=0,i=1;i31) _die_("usage: test-basic [<0-31> [...]]\n");
      if (j==31) r|=0xff;	/* all basic tests */
      if (j==30) r|=0xff00;	/* all advanced tests */
      r|=(1<
#include 
#include 

#include 
#include 

#include 
#include "thread_internal.h"

#define ps(s) write(2,s,sizeof(s)-1)
#define die(s) do { ps(s); exit(1); } while(0)

pthread_t*t;

static void*thread(void*arg) {
  printf("thread %ld %d\n",(long)arg,getpid());
  sleep(1);
  while(1) { pthread_testcancel(); }
}

static void __gen_thread(int nr) {
  if (pthread_create(t+nr,0,thread,(void*)nr)) {
    printf("can't create thread nr %d\n",nr);
    exit(42);
  }
}


int main(int argc,char*argv[]) {
  int m,i;
  nice(20);
  if ((argc<2) || ((m=atoi(argv[1]))==0)) m=16;
  if ((t=malloc(m*sizeof(pthread_t)))==0) die("no mem....\n");
  for (i=0;i
#include 
#include 

#include 
#include 

#include 
#include "thread_internal.h"

#define ps(s) write(2,s,sizeof(s)-1)
#define die(s) do { ps(s); exit(1); } while(0)

pthread_t*t;

static void*thread(void*arg) {
  printf("thread %ld %d\n",(long)arg,getpid());
  while(1) { pthread_testcancel(); }
}

static void __gen_thread(int nr) {
  if (pthread_create(t+nr,0,thread,(void*)nr)) {
    printf("can't create thread nr %d\n",nr);
    exit(42);
  }
  sleep(1);
}


int main(int argc,char*argv[]) {
  int m,i;
  nice(20);
  if ((argc<2) || ((m=atoi(argv[1]))==0)) m=16;
  if ((t=malloc(m*sizeof(pthread_t)))==0) die("no mem....\n");
  for (i=0;i
#include 
#include 
#include 

#include 
#include 

#include 
#include "thread_internal.h"

#define ps(s) write(2,s,sizeof(s)-1)
#define die(s) do { ps(s); exit(1); } while(0)


static void*thread(void*arg) {
  printf("thread %ld %d %p\n",(long)arg,getpid(),&arg);
  while(1) { pthread_testcancel(); sleep(1); }
}

static int max=32000;
static void __gen_thread(int nr) {
  pthread_t t;
  if (nr>max) {
    printf("stopping at maximum %d\n",nr);
    return;
  }
  if (pthread_create(&t,0,thread,(void*)nr)) {
    printf("can't create thread nr %d\n",nr);
  }
  else {
    __gen_thread(nr+1);
  }
}

void segv_handler(int sig,siginfo_t*info,void*arg) {
  printf("SIG: %d in %d @ %p\n",sig,getpid(),info->si_addr);
  _exit(1);
}

void init_segv() {
  struct sigaction siga;
  memset(&siga,0,sizeof(struct sigaction));
  siga.sa_sigaction=segv_handler;
  siga.sa_flags=SA_SIGINFO;
  sigaction(SIGSEGV,&siga,0);
}

int main(int argc,char*argv[]) {
  if (argc>1) max=atoi(argv[1]);
  printf("MAIN: %d max=%d\n",getpid(),max);
  init_segv();
  nice(20);
  __gen_thread(2);
  sleep(5);
  return 0;
}
dietlibc-0.33~cvs20120325/libpthread/thread_internal.h010064400000000000000000000140001173363227000173270ustar00#ifndef __THREAD_INTERNAL_H__
#define __THREAD_INTERNAL_H__

#include 
#include 
#include 
#include 
#include 
#include 

#include "dietfeatures.h"
#ifndef WANT_THREAD_SAFE
#error "the diet libc is not compiled with thread safeness enabled!"
#endif

extern int __modern_linux;	/* can be -1 (old linux), 0 (unknown), or 1 (new linux). */
/* if 1, assume 2.6 kernel with TLS and futexes et al */

#undef errno
#define _errno_ (*__errno_location())

/* cleanup */
struct thread_cleanup_t {
  struct thread_cleanup_t*next;
  void (*func)(void*);
  void *arg;
};

/* the thread descriptor / internal */
struct _pthread_descr_struct {
  /* modify only with __thread_struct_lock held */
  struct _pthread_descr_struct*next;
  struct _pthread_descr_struct**prev;

  /* thread/process data */
  pid_t pid;			/* Process id */

  /* "stack handling" / find thread */
  void*stack_begin;		/* begin of stack / lowest address (to free) */
  void*stack_end;		/* end   of stack / highest address */

  /* thread struct lock */
  struct _pthread_fastlock lock;
  struct _pthread_fastlock wlock;

  /* errno handling */
  int errno;

  /* thread exit handling */
  sigjmp_buf jmp_exit;		/* pthread_exit jump */
  void*retval;			/* thread return value */

  /* joined threads */
  struct _pthread_descr_struct*jt; /* joint thread */
  struct _pthread_fastlock joined; /* flag: other thread has joined */

  /* conditional variables */
  struct _pthread_descr_struct*waitnext; /* an other waiting thread or NULL */
  struct _pthread_descr_struct**waitprev;

  /* cancel handling */
  unsigned char cancelstate;		/* cancel state */
  volatile unsigned char canceltype;	/* type of cancellation */

  /* thread flags */
  volatile char dead;		/* thread has terminated */
  volatile char canceled;	/* thread canceled */
  char detached;		/* thread is detached */
  char stack_free;		/* stack is allocated by pthread_create */

  /* signal handling */
  char p_sig;			/* signal */

  /* creation parameter (RO) */
  void*(*func)(void*arg);	/* thread function */
  void*arg;			/* thread argument */
  unsigned long stack_size;	/* stack size for setrlimit */
  unsigned long guard_size;	/* stack guard size for setrlimit */

  /* cleanup stack (modify only with struct lock held) */
  struct thread_cleanup_t*cleanup_stack;

  /* thread specific data */
  void*tkd[PTHREAD_KEYS_MAX];

#ifdef PTHREAD_HANDLE_DNS_CORRECT
  /* DNS cruft */
  int h_errno;
  struct res_state __res;
#endif
} __attribute__((aligned(32)));
#define thread_sig_mask jmp_exit->__saved_mask

/* thread keys */
struct _thread_key {
  int used;
  void (*destructor)(void*);
};

/* internal stuff */

#define PTHREAD_SIG_RESTART (SIGRTMAX)
#define PTHREAD_SIG_CANCEL  (SIGRTMAX-1)
#define __CUR_RTMIN SIGRTMIN
#define __CUR_RTMAX (SIGRTMAX-2)

int __testandset(int*spinlock);

void __pthread_lock(struct _pthread_fastlock*lock);
int __pthread_trylock(struct _pthread_fastlock*lock);
int __pthread_unlock(struct _pthread_fastlock*lock);

#define LOCK(td)    __pthread_lock(&((td)->lock))
#define TRYLOCK(td) __pthread_trylock(&((td)->lock))
#define UNLOCK(td)  __pthread_unlock(&((td)->lock))

int __pthread_mutex_lock(pthread_mutex_t*mutex,_pthread_descr this);
int __pthread_mutex_unlock(pthread_mutex_t*mutex,_pthread_descr this);

int __clone(void*(*fn)(void*),void*stack,int flags,void*arg);
void __thread_manager_close(void);

struct _pthread_descr_struct*__thread_self(void);
struct _pthread_descr_struct*__thread_find(pthread_t pid);

int __thread_join(struct _pthread_descr_struct*td,void**return_value);
int __thread_join_cleanup(struct _pthread_descr_struct*td);

void __thread_restart(struct _pthread_descr_struct*td);
void __thread_suspend(struct _pthread_descr_struct*td,int cancel);
int __thread_suspend_till(struct _pthread_descr_struct*td,int cancel,const struct timespec*abstime);

void __thread_testcancel(struct _pthread_descr_struct*td);
int __thread_setcanceltype(int type,int*oldtype,struct _pthread_descr_struct*td);

/* ASYNC CANCEL ... */
#define __NO_ASYNC_CANCEL_BEGIN_(t) \
{ int oldtype; __thread_setcanceltype(PTHREAD_CANCEL_DEFERRED,&oldtype,(t));
#define __NO_ASYNC_CANCEL_END_(t) \
  __thread_setcanceltype(oldtype,0,(t)); __thread_testcancel((t)); }

#define __TEST_CANCEL_(t) __thread_testcancel(t)

#define __TEST_CANCEL() pthread_testcancel()

/* manager thread stuff */
typedef void(*MGR_func)(void*);
typedef struct __thread_manager_func {
  void(*func)(void*);
  void*arg;
} __thread_manager_func;

int __thread_send_manager(void(*f)(void*),void*arg);

typedef struct __thread_descr {
  struct _pthread_descr_struct*tr;	/* thread sending the request */
  struct _pthread_descr_struct*td;	/* new thread descriptor */
  pthread_attr_t*attr;	/* thread attr */
  pthread_t*pid;	/* pid of thread */
}*_thread_descr;

int __thread_getschedparam(pthread_t th,int*policy,struct sched_param*param);
int __thread_start_new(_thread_descr data);

/* diet libc syscalls */

void  __libc_free(void*ptr);
void *__libc_malloc(size_t size);
void *__libc_realloc(void*ptr,size_t size);

void __libc_closelog(void);
void __libc_openlog(const char*ident,int option,int facility);
void __libc_vsyslog(int priority,const char *format,va_list arg_ptr);

pid_t __libc_fork(void);

void __libc_exit(int retval) __attribute__((noreturn));

int __libc_close(int fd);
int __libc_creat(const char*pathname,mode_t mode);
int __libc_fcntl(int fd,int cmd,void*arg);
int __libc_fsync(int fd);
int __libc_fdatasync(int fd);
int __libc_msync(void*addr,size_t len,int flags);
int __libc_nanosleep(const struct timespec *req,struct timespec*rem);
int __libc_open(const char*pathname,int flags,mode_t mode);
int __libc_pause(void);
ssize_t __libc_read(int fd,void*buf,size_t count);
int __libc_sigsuspend(const sigset_t*mask);
int __libc_tcdrain(int fd);
pid_t __libc_waitpid(pid_t pid,int*status,int options);
ssize_t __libc_write(int fd,const void*buf,size_t count);

int __libc_execve(const char*filename,char*const argv[],char*const envp[]);
int __libc_sigaction(int signum,const struct sigaction*act,struct sigaction*oldact);

#endif
dietlibc-0.33~cvs20120325/libregex/rx.c010064400000000000000000000423561173363227000143120ustar00#define NDEBUG
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#if !defined(__x86_64__)
#undef WANT_REGEX_JIT
#endif

/* this is ugly.
 * the idea is to build a parse tree, then do some poor man's OOP with a
 * generic matcher function call that is always that the start of each
 * record, and a next pointer.  When the parse tree is done, we need to
 * recursively set the next pointers to point to the part of the parse
 * tree that needs to match next.
 * This is the prototype of the generic match function call pointer.
 * The first argument is the "this" pointer, the second is the text to
 * be matched against, ofs is the offset from the start of the matched
 * text (so we can match "^") and matches is an array where match
 * positions are stored. */
/* now declared in regex.h: */
/* typedef int (*matcher)(void*,const char*,int ofs,regmatch_t* matches,int plus,int eflags); */

/* one would think that this is approach is an order of magnitude slower
 * than the standard NFA approach, but it isn't.  The busybox grep took
 * 0.26 seconds for a fixed string compared to 0.19 seconds for the
 * glibc regex. */

/* first part: parse a regex into a parse tree */
struct bracketed {
  unsigned int cc[32];
};

/* now declared in regex.h:
struct regex {
  matcher m;
  void* next;
  int pieces;
  int num;
  struct branch *b;
}; */

struct string {
  char* s;
  size_t len;
};

struct atom {
  matcher m;
  void* next;
  enum { ILLEGAL, EMPTY, REGEX, BRACKET, ANY, LINESTART, LINEEND, WORDSTART, WORDEND, CHAR, STRING, BACKREF, } type;
  int bnum;
  union {
    struct regex r;
    struct bracketed b;
    char c;
    struct string s;
  } u;
};

struct piece {
  matcher m;
  void* next;
  struct atom a;
  unsigned int min,max;
};

struct branch {
  matcher m;
  void* next;
  int num;
  struct piece *p;
};

static void clearcc(unsigned int* x) {
  memset(x,0,sizeof(struct bracketed));
}

static void setcc(unsigned int* x,unsigned int bit) {
  x[bit/32]|=(1<<((bit%32)-1));
}

static int issetcc(unsigned int* x,unsigned int bit) {
  return x[bit/32] & (1<<((bit%32)-1));
}

static const char* parsebracketed(struct bracketed*__restrict__ b,const char*__restrict__ s,regex_t*__restrict__ rx) {
  const char* t;
  int i,negflag=0;
  if (*s!='[') return s;
  t=s+1;
  clearcc(b->cc);
  if (*t=='^') { negflag=1; ++t; }
  do {
    if (*t==0) return s;
    setcc(b->cc,rx->cflags®_ICASE?tolower(*t):*t);
    if (t[1]=='-' && t[2]!=']') {
      for (i=*t+1; i<=t[2]; ++i) setcc(b->cc,rx->cflags®_ICASE?tolower(i):i);
      t+=2;
    }
    ++t;
  } while (*t!=']');
  if (negflag) for (i=0; i<32; ++i) b->cc[i]=~b->cc[i];
  return t+1;
}

static const char* parseregex(struct regex* r,const char* s,regex_t* rx);

static int matchatom_CHAR(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  register struct atom* a=(struct atom*)x;
#ifdef DEBUG
    printf("matching atom CHAR %c against \"%.20s\"\n",a->u.c,s);
#endif
  if (*s!=a->u.c) return -1;
  if (a->next)
    return ((struct atom*)(a->next))->m(a->next,(const char*)s+1,ofs+1,preg,plus+1,eflags);
  else
    return plus+1;
}

static int matchatom_CHAR_ICASE(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  register struct atom* a=(struct atom*)x;
#ifdef DEBUG
    printf("matching atom CHAR_ICASE %c against \"%.20s\"\n",a->u.c,s);
#endif
  if (tolower(*s)!=a->u.c) return -1;
  if (a->next)
    return ((struct atom*)(a->next))->m(a->next,(const char*)s+1,ofs+1,preg,plus+1,eflags);
  else
    return plus+1;
}

static int matchatom(void*__restrict__ x,const unsigned char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  register struct atom* a=(struct atom*)x;
  int matchlen=0;
  assert(a->type!=ILLEGAL);
  switch (a->type) {
  case EMPTY:
#ifdef DEBUG
    printf("matching atom EMPTY against \"%.20s\"\n",s);
    printf("a->bnum is %d\n",a->bnum);
#endif
    if (a->bnum>=0) preg->l[a->bnum].rm_so=preg->l[a->bnum].rm_eo=ofs;
    goto match;
  case REGEX:
#ifdef DEBUG
    printf("matching atom REGEX against \"%.20s\"\n",s);
    printf("a->bnum is %d\n",a->bnum);
#endif
    if ((matchlen=a->u.r.m(&a->u.r,(const char*)s,ofs,preg,0,eflags))>=0) {
      assert(a->bnum>=0);
      preg->l[a->bnum].rm_so=ofs;
      preg->l[a->bnum].rm_eo=ofs+matchlen;
      goto match;
    }
    break;
  case BRACKET:
#ifdef DEBUG
    printf("matching atom BRACKET against \"%.20s\"\n",s);
#endif
    matchlen=1;
    if (*s=='\n' && (preg->cflags®_NEWLINE)) break;
    if (*s && issetcc(a->u.b.cc,(preg->cflags®_ICASE?tolower(*s):*s)))
      goto match;
    break;
  case ANY:
#ifdef DEBUG
    printf("matching atom ANY against \"%.20s\"\n",s);
#endif
    if (*s=='\n' && (preg->cflags®_NEWLINE)) break;
    matchlen=1;
    if (*s) goto match;
    break;
  case LINESTART:
#ifdef DEBUG
    printf("matching atom LINESTART against \"%.20s\"\n",s);
#endif
    if (ofs==0 && (eflags®_NOTBOL)==0) {
      goto match;
    }
    break;
  case LINEEND:
#ifdef DEBUG
    printf("matching atom LINEEND against \"%.20s\"\n",s);
#endif
    if ((*s && *s!='\n') || (eflags®_NOTEOL)) break;
    goto match;
  case WORDSTART:
#ifdef DEBUG
    printf("matching atom WORDSTART against \"%.20s\"\n",s);
#endif
    if ((ofs==0 || !isalnum(s[-1])) && isalnum(*s))
      goto match;
    break;
  case WORDEND:
#ifdef DEBUG
    printf("matching atom WORDEND against \"%.20s\"\n",s);
#endif
    if (ofs>0 && isalnum(s[-1]) && !isalnum(*s))
      goto match;
    break;
  case CHAR:
#ifdef DEBUG
    printf("matching atom CHAR %c against \"%.20s\"\n",a->u.c,s);
#endif
    matchlen=1;
    if (((preg->cflags®_ICASE)?tolower(*s):*s)==a->u.c) goto match;
    break;
  case STRING:
    matchlen=a->u.s.len;
#ifdef DEBUG
    printf("matching atom STRING \"%.*s\" against \"%.20s\"\n",a->u.s.len,a->u.s.s,s);
#endif
    {
      int i;
      if (preg->cflags®_ICASE) {
	for (i=0; iu.s.s[i]) return -1;
      } else {
	for (i=0; iu.s.s[i]) return -1;
      }
    }
    goto match;
    break;
  case BACKREF:
    matchlen=preg->l[(unsigned char)(a->u.c)].rm_eo-preg->l[(unsigned char)(a->u.c)].rm_so;
#ifdef DEBUG
    printf("matching atom BACKREF %d (\"%.*s\") against \"%.20s\"\n",a->u.c,matchlen,s-ofs+preg->l[a->u.c].rm_so,s);
#endif
    if (memcmp(s-ofs+preg->l[(unsigned char)(a->u.c)].rm_so,s,matchlen)==0) goto match;
    break;
  }
  return -1;
match:
  if (a->next)
    return ((struct atom*)(a->next))->m(a->next,(const char*)s+matchlen,ofs+matchlen,preg,plus+matchlen,eflags);
  else
    return plus+matchlen;
}

static int closebracket(const char* s,const regex_t* r) {
  if (r->cflags®_EXTENDED)
    return *s==')';
  else
    return (*s=='\\' && s[1]==')');
}

static const char* parseatom(struct atom*__restrict__ a,const char*__restrict__ s,regex_t*__restrict__ rx) {
  const char *tmp;
  a->m=(matcher)matchatom;
  a->bnum=-1;
  switch (*s) {
  case '(':
    if ((rx->cflags®_EXTENDED)==0) goto handle_char;
openbracket:
    a->bnum=++rx->brackets;
    if (s[1]==')') {
      a->type=EMPTY;
      return s+2;
    }
    a->type=REGEX;
    tmp=parseregex(&a->u.r,s+1,rx);
    if (closebracket(tmp,rx))
      return tmp+1+((rx->cflags®_EXTENDED)==0);
  case ')':
    if ((rx->cflags®_EXTENDED)==0) goto handle_char;
    /* fall through */
  case 0:
  case '|':
    return s;
  case '[':
    a->type=BRACKET;
    if ((tmp=parsebracketed(&a->u.b,s,rx))!=s)
      return tmp;
    return s;
  case '.':
    a->type=ANY;
    break;
  case '^':
    a->type=LINESTART;
    break;
  case '$':
    a->type=LINEEND;
    break;
  case '\\':
    if (!*++s) return s;
    if (*s=='<') {
      a->type=WORDSTART;
      break;
    } else if (*s=='>') {
      a->type=WORDEND;
      break;
    } else if (*s>='1' && *s<=(rx->brackets+'1') && ((rx->cflags®_EXTENDED)==0)) {
      a->type=BACKREF;
      a->u.c=*s-'0';
      break;
    } else if ((rx->cflags®_EXTENDED)==0) {
      if (*s=='(') goto openbracket; else
      if (*s==')') return s-1;
    }
    /* fall through */
  default:
handle_char:
    a->type=CHAR;
    if (rx->cflags®_ICASE) {
      a->u.c=tolower(*s);
      a->m=(matcher)matchatom_CHAR_ICASE;
    } else {
      a->u.c=*s;
      a->m=(matcher)matchatom_CHAR;
    }
    /* optimization: if we have a run of CHAR, make it into a STRING */
    {
      size_t i;
      for (i=1; s[i] && !strchr("(|)[.^$\\*+?{",s[i]); ++i) ;
      if (strchr("*+?{",s[i])) --i;
      if (i>2) {
	a->m=(matcher)matchatom;
	a->type=STRING;
	a->u.s.len=i;
	if (!(a->u.s.s=malloc(i+1))) return s;
	memcpy(a->u.s.s,s,i);
	a->u.s.s[i]=0;
	return s+i;
      }
    }
    break;
  }
  return s+1;
}

/* needs to do "greedy" matching, i.e. match as often as possible */
static int matchpiece(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  register struct piece* a=(struct piece*)x;
  int matchlen=0;
  int tmp=0,num=0;
  unsigned int *offsets;
  assert(a->max>0 && a->max<1000);
#ifdef DEBUG
  printf("alloca(%d)\n",sizeof(int)*a->max);
#endif
  offsets=alloca(sizeof(int)*a->max);
  offsets[0]=0;
//  printf("allocating %d offsets...\n",a->max);
//  printf("matchpiece \"%s\"...\n",s);
  /* first, try to match the atom as often as possible, up to a->max times */
  if (a->max == 1 && a->min == 1)
    return a->a.m(&a->a,s+matchlen,ofs+matchlen,preg,0,eflags);
  while ((unsigned int)nummax) {
    void* save=a->a.next;
    a->a.next=0;
    if ((tmp=a->a.m(&a->a,s+matchlen,ofs+matchlen,preg,0,eflags))>=0) {
      a->a.next=save;
      ++num;
      matchlen+=tmp;
//      printf("setting offsets[%d] to %d\n",num,tmp);
      offsets[num]=tmp;
    } else {
      a->a.next=save;
      break;
    }
  }
  if ((unsigned int)nummin) return -1;		/* already at minimum matches; signal mismatch */
  /* then, while the rest does not match, back off */
  for (;num>=0;) {
    if (a->next)
      tmp=((struct atom*)(a->next))->m(a->next,s+matchlen,ofs+matchlen,preg,plus+matchlen,eflags);
    else
      tmp=plus+matchlen;
    if (tmp>=0) break;	/* it did match; don't back off any further */
//    printf("using offsets[%d] (%d)\n",num,offsets[num]);
    matchlen-=offsets[num];
    --num;
  }
  return tmp;
}

static const char* parsepiece(struct piece*__restrict__ p,const char*__restrict__ s,regex_t*__restrict__ rx) {
  const char* tmp=parseatom(&p->a,s,rx);
  if (tmp==s) return s;
  p->m=matchpiece;
  p->min=p->max=1;
  switch (*tmp) {
  case '*': p->min=0; p->max=RE_DUP_MAX; break;
  case '+': p->min=1; p->max=RE_DUP_MAX; break;
  case '?': p->min=0; p->max=1; break;
  case '{':
    if (isdigit(*++tmp)) {
      p->min=*tmp-'0'; p->max=RE_DUP_MAX;
      while (isdigit(*++tmp)) p->min=p->min*10+*tmp-'0';
      if (*tmp==',') {
	if (isdigit(*++tmp)) {
	  p->max=*tmp-'0';
	  while (isdigit(*++tmp)) p->max=p->max*10+*tmp-'0';
	}
      } else
	p->max=p->min;
      if (*tmp!='}') return s;
      ++tmp;
    }
  default:
    return tmp;
  }
  return tmp+1;
}

/* trivial, just pass through */
static int matchbranch(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  register struct branch* a=(struct branch*)x;
  int tmp;
#ifdef DEBUG
  printf("%08p matching branch against \"%.20s\"\n",a,s);
  printf("%p %p\n",&a->p->m,a->p->m);
#endif
  assert(a->p->m==matchpiece);
  tmp=a->p->m(a->p,s,ofs,preg,plus,eflags);
  if (tmp>=0) {
    if (a->next)
      return ((struct atom*)(a->next))->m(a->next,s+tmp,ofs+tmp,preg,plus+tmp,eflags);
    else
      return plus+tmp;
  }
  return -1;
}

static int matchempty(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  return 0;
}

static const char* parsebranch(struct branch*__restrict__ b,const char*__restrict__ s,regex_t*__restrict__ rx,int*__restrict__ pieces) {
  struct piece p;
  const char *tmp = NULL;
  b->m=matchbranch;
  b->num=0; b->p=0;
  for (;;) {
    if (*s=='|' && b->num==0) {
      tmp=s+1;
      p.a.type=EMPTY;
      p.a.m=matchempty;
      p.min=p.max=1;
      p.m=matchpiece;
    } else {
      tmp=parsepiece(&p,s,rx);
      if (tmp==s) return s;
    }
//    printf("b->p from %p to ",b->p);
    {
      struct piece* tmp;
      if (!(tmp=realloc(b->p,++b->num*sizeof(p)))) return s;
//      printf("piece realloc: %p -> %p (%d*%d)\n",b->p,tmp,b->num,sizeof(p));
      b->p=tmp;
    }
//    printf("%p (size %d)\n",b->p,b->num*sizeof(p));
    b->p[b->num-1]=p;
//    printf("assigned piece %d in branch %p\n",b->num-1,b->p);
    if (*tmp=='|') break;
    s=tmp;
  }
  *pieces+=b->num;
  return tmp;
}

/* try the branches one by one */
static int matchregex(void*__restrict__ x,const char*__restrict__ s,int ofs,struct __regex_t*__restrict__ preg,int plus,int eflags) {
  register struct regex* a=(struct regex*)x;
  int i,tmp;
#ifdef DEBUG
  printf("%08p matching regex against \"%.20s\"\n",a,s);
#endif
  for (i=0; inum; ++i) {
    assert(a->b[i].m==matchbranch);
    tmp=a->b[i].m(&a->b[i],s,ofs,preg,plus,eflags);
    if (tmp>=0) {
      if (a->next)
	return ((struct atom*)(a->next))->m(a->next,s+tmp,ofs+tmp,preg,plus+tmp,eflags);
      else
	return plus+tmp;
    }
  }
  return -1;
}

static const char* parseregex(struct regex*__restrict__ r,const char*__restrict__ s,regex_t*__restrict__ p) {
  struct branch b;
  const char *tmp;
  r->m=matchregex;
  r->num=0; r->b=0; r->pieces=0;
  p->brackets=0;
  b.next=0;
  if (*s==')' || !*s) {
    r->m=matchempty;
    return s;
  }
  for (;;) {
    tmp=parsebranch(&b,s,p,&r->pieces);
    if (tmp==s && !closebracket(s,p)) return s;
//    printf("r->b from %p to ",r->b);
    {
      struct branch* tmp;
      if (!(tmp=realloc(r->b,++r->num*sizeof(b)))) return s;
//      printf("branch realloc: %p -> %p (%d*%d)\n",r->b,tmp,r->num,sizeof(b));
      r->b=tmp;
    }
//    printf("%p (size %d)\n",r->b,r->num*sizeof(b));
    r->b[r->num-1]=b;
    if (closebracket(s,p)) {
      r->b[r->num-1].m=matchempty;
      return s;
    }
//    printf("assigned branch %d at %p\n",r->num-1,r->b);
    s=tmp;
    if (closebracket(s,p)) return s;
    if (*s=='|') ++s;
  }
  return tmp;
}


/* The matcher relies on the presence of next pointers, of which the
 * parser does not know the correct destination.  So we need an
 * additional pass through the data structure that sets the next
 * pointers correctly. */
static void regex_putnext(struct regex* r,void* next);

static void atom_putnext(struct atom*__restrict__ a,void*__restrict__ next) {
  a->next=next;
  if (a->type==REGEX)
    regex_putnext(&a->u.r,0);
}

static void piece_putnext(struct piece*__restrict__ p,void*__restrict__ next) {
  p->next=next;
  atom_putnext(&p->a,next);
}

static void branch_putnext(struct branch*__restrict__ b,void*__restrict__ next) {
  int i;
  if (b->m!=matchempty) {
    for (i=0; inum-1; ++i) {
      if (b->p[i+1].min==1 && b->p[i+1].max==1)
/* shortcut: link directly to next atom if it's a piece with min=max=1 */
	piece_putnext(&b->p[i],&b->p[i+1].a);
      else
	piece_putnext(&b->p[i],&b->p[i+1]);
    }
    piece_putnext(&b->p[i],0);
  }
  b->next=next;
}

static void regex_putnext(struct regex*__restrict__ r,void*__restrict__ next) {
  int i;
  for (i=0; inum; ++i)
    branch_putnext(&r->b[i],next);
  r->next=next;
}



int regcomp(regex_t*__restrict__ preg, const char*__restrict__ regex, int cflags) {
  const char* t;
  preg->cflags=cflags;
  t=parseregex(&preg->r,regex,preg);
  if (t==regex && *regex!=0) return -1;
  regex_putnext(&preg->r,0);
  return 0;
}

int regexec(const regex_t*__restrict__ preg, const char*__restrict__ string, size_t nmatch, regmatch_t pmatch[], int eflags) {
  int matched;
  const char *orig=string;
  assert(preg->brackets+1>0 && preg->brackets<1000);
  for (matched=0; (unsigned int)matchedbrackets+3));
#endif
  ((regex_t*)preg)->l=alloca(sizeof(regmatch_t)*(preg->brackets+3));
  while (1) {
    matched=preg->r.m((void*)&preg->r,string,string-orig,(regex_t*)preg,0,eflags);
//    printf("ebp on stack = %x\n",stack[1]);
    if (matched>=0) {
      matched=preg->r.m((void*)&preg->r,string,string-orig,(regex_t*)preg,0,eflags);
      preg->l[0].rm_so=string-orig;
      preg->l[0].rm_eo=string-orig+matched;
      if ((preg->cflags®_NOSUB)==0) memcpy(pmatch,preg->l,nmatch*sizeof(regmatch_t));
      return 0;
    }
    if (!*string) break;
    ++string; eflags|=REG_NOTBOL;
  }
  return REG_NOMATCH;
}

static void __regfree(struct regex* r) {
  int i;
  for (i=0; inum; ++i) {
    int j,k;
    k=r->b[i].num;
    for (j=0; jb[i].p[j].a.type==REGEX)
	__regfree(&r->b[i].p[j].a.u.r);
      else if (r->b[i].p[j].a.type==STRING)
	free(r->b[i].p[j].a.u.s.s);
    free(r->b[i].p);
  }
  free(r->b);
}

void regfree(regex_t* preg) {
  __regfree(&preg->r);
  memset(preg,0,sizeof(regex_t));
}

size_t regerror(int errcode, const regex_t*__restrict__ preg, char*__restrict__ errbuf, size_t errbuf_size) {
  strncpy(errbuf,"invalid regular expression (sorry)",errbuf_size);
  return strlen(errbuf);
}




#if 0
int main() {
  struct regex r;
  int bnum=-1;
  const char* t=parseregex(&r,"^a*ab$",&bnum);
  regex_putnext(&r,0);
  printf("%d pieces, %s\n",r.pieces,t);
  printf("%d\n",r.m(&r,"aaab",0,0,0));
  return 0;
}
#endif
dietlibc-0.33~cvs20120325/librpc/auth_none.c010064400000000000000000000065051173363227000153070ustar00/* @(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)auth_none.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * auth_none.c
 * Creates a client authentication handle for passing "null" 
 * credentials and verifiers to remote systems. 
 * 
 * Copyright (C) 1984, Sun Microsystems, Inc. 
 */

#include 
#include 
#include 
#define MAX_MARSHEL_SIZE 20

static void authnone_verf(AUTH *);
static bool_t authnone_validate(AUTH *, struct opaque_auth *);
static bool_t authnone_refresh(AUTH *);
static void authnone_destroy(AUTH *);
static bool_t authnone_marshal(AUTH *client, XDR *xdrs);

static struct auth_ops ops = {
	authnone_verf,
	authnone_marshal,
	authnone_validate,
	authnone_refresh,
	authnone_destroy
};

static struct authnone_private {
	AUTH no_client;
	char marshalled_client[MAX_MARSHEL_SIZE];
	unsigned int mcnt;
} *authnone_private;

AUTH *authnone_create()
{
	register struct authnone_private *ap = authnone_private;
	XDR xdr_stream;
	register XDR *xdrs;

	if (ap == 0) {
		ap = (struct authnone_private *) calloc(1, sizeof(*ap));
		if (ap == 0)
			return (0);
		authnone_private = ap;
	}
	if (!ap->mcnt) {
		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
		ap->no_client.ah_ops = &ops;
		xdrs = &xdr_stream;
		xdrmem_create(xdrs, ap->marshalled_client,
					  (unsigned int) MAX_MARSHEL_SIZE, XDR_ENCODE);
		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
		ap->mcnt = XDR_GETPOS(xdrs);
		XDR_DESTROY(xdrs);
	}
	return (&ap->no_client);
}

 /*ARGSUSED*/ static bool_t authnone_marshal(client, xdrs)
AUTH *client;
XDR *xdrs;
{
	register struct authnone_private *ap = authnone_private;

	if (ap == 0)
		return (0);
	return ((*xdrs->x_ops->x_putbytes) (xdrs,
										ap->marshalled_client, ap->mcnt));
}

static void authnone_verf(AUTH *x)
{
}

static bool_t authnone_validate(AUTH *x, struct opaque_auth *x1)
{

	return (TRUE);
}

static bool_t authnone_refresh(AUTH *x)
{

	return (FALSE);
}

static void authnone_destroy(AUTH *x)
{
}

dietlibc-0.33~cvs20120325/librpc/auth_unix.c010064400000000000000000000201241173363227000153240ustar00/* @(#)auth_unix.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 *
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)auth_unix.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * auth_unix.c, Implements UNIX style authentication parameters. 
 *  
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * The system is very weak.  The client uses no encryption for it's
 * credentials and only sends null verifiers.  The server sends backs
 * null verifiers or optionally a verifier that suggests a new short hand
 * for the credentials.
 *
 */

#include 
#include 
#include 
#include 

#include 
#include 
#include 
#include 

/*
 * Unix authenticator operations vector
 */
static void authunix_nextverf(AUTH *auth);
static bool_t authunix_marshal(AUTH *auth, XDR *xdrs);
static bool_t authunix_validate(AUTH *auth, struct opaque_auth *verf);
static bool_t authunix_refresh(AUTH *auth);
static void authunix_destroy(AUTH *auth);

static struct auth_ops auth_unix_ops = {
	authunix_nextverf,
	authunix_marshal,
	authunix_validate,
	authunix_refresh,
	authunix_destroy
};

/*
 * This struct is pointed to by the ah_private field of an auth_handle.
 */
struct audata {
	struct opaque_auth au_origcred;	/* original credentials */
	struct opaque_auth au_shcred;	/* short hand cred */
	unsigned long au_shfaults;			/* short hand cache faults */
	char au_marshed[MAX_AUTH_BYTES];
	unsigned int au_mpos;				/* xdr pos at end of marshed */
};

#define	AUTH_PRIVATE(auth)	((struct audata *)auth->ah_private)

static void marshal_new_auth(AUTH *);


/*
 * Create a unix style authenticator.
 * Returns an auth handle with the given stuff in it.
 */
AUTH *authunix_create __P ((char *machname, uid_t uid,
				   gid_t gid, int len,
				   gid_t *aup_gids))
{
	struct authunix_parms aup;
	char mymem[MAX_AUTH_BYTES];
	struct timeval now;
	XDR xdrs;
	register AUTH *auth;
	register struct audata *au;

	/*
	 * Allocate and set up auth handle
	 */
	auth = (AUTH *) mem_alloc(sizeof(*auth));
#ifndef KERNEL
	if (auth == NULL) {
		(void) fprintf(stderr, "authunix_create: out of memory\n");
		return (NULL);
	}
#endif
	au = (struct audata *) mem_alloc(sizeof(*au));
#ifndef KERNEL
	if (au == NULL) {
		(void) fprintf(stderr, "authunix_create: out of memory\n");
		return (NULL);
	}
#endif
	auth->ah_ops = &auth_unix_ops;
	auth->ah_private = (char*) au;
	auth->ah_verf = au->au_shcred = _null_auth;
	au->au_shfaults = 0;

	/*
	 * fill in param struct from the given params
	 */
	(void) gettimeofday(&now, (struct timezone *) 0);
	aup.aup_time = now.tv_sec;
	aup.aup_machname = machname;
	aup.aup_uid = uid;
	aup.aup_gid = gid;
	aup.aup_len = (unsigned int) len;
	aup.aup_gids = aup_gids;

	/*
	 * Serialize the parameters into origcred
	 */
	xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
	if (!xdr_authunix_parms(&xdrs, &aup))
		abort();
	au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
	au->au_origcred.oa_flavor = AUTH_UNIX;
#ifdef KERNEL
	au->au_origcred.oa_base = mem_alloc((unsigned int) len);
#else
	if ((au->au_origcred.oa_base = mem_alloc((unsigned int) len)) == NULL) {
		(void) fprintf(stderr, "authunix_create: out of memory\n");
		return (NULL);
	}
#endif
	memmove(au->au_origcred.oa_base, mymem, (unsigned int) len);

	/*
	 * set auth handle to reflect new cred.
	 */
	auth->ah_cred = au->au_origcred;
	marshal_new_auth(auth);
	return (auth);
}

/*
 * Returns an auth handle with parameters determined by doing lots of
 * syscalls.
 */
AUTH *authunix_create_default()
{
	register int len;
	char machname[MAX_MACHINE_NAME + 1];
	register int uid;
	register int gid;
	gid_t gids[NGRPS];

	if (gethostname(machname, MAX_MACHINE_NAME) == -1)
		abort();
	machname[MAX_MACHINE_NAME] = 0;
	uid = geteuid();
	gid = getegid();
	if ((len = getgroups(NGRPS, gids)) < 0)
		abort();
	return (authunix_create(machname, uid, gid, len, gids));
}

/*
 * authunix operations
 */

static void authunix_nextverf(auth)
AUTH *auth;
{
	/* no action necessary */
}

static bool_t authunix_marshal(auth, xdrs)
AUTH *auth;
XDR *xdrs;
{
	register struct audata *au = AUTH_PRIVATE(auth);

	return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
}

static bool_t authunix_validate(auth, verf)
register AUTH *auth;
struct opaque_auth *verf;
{
	register struct audata *au;
	XDR xdrs;

	if (verf->oa_flavor == AUTH_SHORT) {
		au = AUTH_PRIVATE(auth);
		xdrmem_create(&xdrs, verf->oa_base, verf->oa_length, XDR_DECODE);

		if (au->au_shcred.oa_base != NULL) {
			mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
			au->au_shcred.oa_base = NULL;
		}
		if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
			auth->ah_cred = au->au_shcred;
		} else {
			xdrs.x_op = XDR_FREE;
			(void) xdr_opaque_auth(&xdrs, &au->au_shcred);
			au->au_shcred.oa_base = NULL;
			auth->ah_cred = au->au_origcred;
		}
		marshal_new_auth(auth);
	}
	return (TRUE);
}

static bool_t authunix_refresh(auth)
register AUTH *auth;
{
	register struct audata *au = AUTH_PRIVATE(auth);
	struct authunix_parms aup;
	struct timeval now;
	XDR xdrs;
	register int stat;

	if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
		/* there is no hope.  Punt */
		return (FALSE);
	}
	au->au_shfaults++;

	/* first deserialize the creds back into a struct authunix_parms */
	aup.aup_machname = NULL;
	aup.aup_gids = (gid_t *) NULL;
	xdrmem_create(&xdrs, au->au_origcred.oa_base,
				  au->au_origcred.oa_length, XDR_DECODE);
	stat = xdr_authunix_parms(&xdrs, &aup);
	if (!stat)
		goto done;

	/* update the time and serialize in place */
	(void) gettimeofday(&now, (struct timezone *) 0);
	aup.aup_time = now.tv_sec;
	xdrs.x_op = XDR_ENCODE;
	XDR_SETPOS(&xdrs, 0);
	stat = xdr_authunix_parms(&xdrs, &aup);
	if (!stat)
		goto done;
	auth->ah_cred = au->au_origcred;
	marshal_new_auth(auth);
  done:
	/* free the struct authunix_parms created by deserializing */
	xdrs.x_op = XDR_FREE;
	(void) xdr_authunix_parms(&xdrs, &aup);
	XDR_DESTROY(&xdrs);
	return (stat);
}

static void authunix_destroy(auth)
register AUTH *auth;
{
	register struct audata *au = AUTH_PRIVATE(auth);

	mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);

	if (au->au_shcred.oa_base != NULL)
		mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);

	mem_free(auth->ah_private, sizeof(struct audata));

	if (auth->ah_verf.oa_base != NULL)
		mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);

	mem_free((char*) auth, sizeof(*auth));
}

/*
 * Marshals (pre-serializes) an auth struct.
 * sets private data, au_marshed and au_mpos
 */
static void marshal_new_auth(auth)
register AUTH *auth;
{
	XDR xdr_stream;
	register XDR *xdrs = &xdr_stream;
	register struct audata *au = AUTH_PRIVATE(auth);

	xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
	if ((!xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
		(!xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
		perror("auth_none.c - Fatal marshalling problem");
	} else {
		au->au_mpos = XDR_GETPOS(xdrs);
	}
	XDR_DESTROY(xdrs);
}

dietlibc-0.33~cvs20120325/librpc/authunix_prot.c010064400000000000000000000041731173363227000162370ustar00/* @(#)authunix_prot.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)authunix_prot.c 1.15 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * authunix_prot.c
 * XDR for UNIX style authentication parameters for RPC
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */


#include 
#include 
#include 
#include 

/*
 * XDR for unix authentication parameters.
 */
bool_t xdr_authunix_parms(xdrs, p)
register XDR *xdrs;
register struct authunix_parms *p;
{
  int a,b;

	if (xdr_u_long(xdrs, &(p->aup_time))
		&& xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
		&& xdr_int(xdrs, &a)
		&& xdr_int(xdrs, &b)
		&& xdr_array(xdrs, (char* *) & (p->aup_gids),
					 &(p->aup_len), NGRPS, sizeof(int), (xdrproc_t)xdr_int)) {
		p->aup_uid=(uid_t)a;
		p->aup_gid=(gid_t)b;
		return (TRUE);
	}
	return (FALSE);
}
dietlibc-0.33~cvs20120325/librpc/bindresvport.c010064400000000000000000000043651173363227000160520ustar00/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/*
 * Copyright (c) 1987 by Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

/*
 * Bind a socket to a privileged IP port
 */
int bindresvport(sd, sin)
int sd;
struct sockaddr_in *sin;
{
	int res;
	static short port;
	struct sockaddr_in myaddr;
	int i;

#define STARTPORT 600
#define ENDPORT (IPPORT_RESERVED - 1)
#define NPORTS	(ENDPORT - STARTPORT + 1)

	if (sin == (struct sockaddr_in *) 0) {
		sin = &myaddr;
		memset(sin,0,sizeof(*sin));
		sin->sin_family = AF_INET;
	} else if (sin->sin_family != AF_INET) {
		errno = EPFNOSUPPORT;
		return (-1);
	}
	if (port == 0) {
		port = (getpid() % NPORTS) + STARTPORT;
	}
	res = -1;
	errno = EADDRINUSE;
	for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) {
		sin->sin_port = htons(port++);
		if (port > ENDPORT) {
			port = STARTPORT;
		}
		res = bind(sd, (struct sockaddr*)sin, sizeof(struct sockaddr_in));
	}
	return (res);
}
dietlibc-0.33~cvs20120325/librpc/clnt_generic.c010064400000000000000000000064571173363227000157710ustar00/* @(#)clnt_generic.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 *
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
#endif
/*
 * Copyright (C) 1987, Sun Microsystems, Inc.
 */
#include 
#include 
#include 
#include 
#include 

/*
 * Generic client creation: takes (hostname, program-number, protocol) and
 * returns client handle. Default options are set, which the user can 
 * change using the rpc equivalent of ioctl()'s.
 */
CLIENT *clnt_create __P ((const char *hostname, const unsigned long prog,
				 const unsigned long vers, const char *proto))
{
	struct hostent *h;
	struct protoent *p;
	struct sockaddr_in sin;
	int sock;
	struct timeval tv;
	CLIENT *client;

	h = gethostbyname(hostname);
	if (h == NULL) {
		rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
		return (NULL);
	}
	if (h->h_addrtype != AF_INET) {
		/*
		 * Only support INET for now
		 */
		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
		rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
		return (NULL);
	}
#ifdef __linux__
	memset((char*)&sin,0,sizeof(sin));
#endif
	sin.sin_family = h->h_addrtype;
	sin.sin_port = 0;
#ifndef __linux__
	memset(sin.sin_zero,0,sizeof(sin.sin_zero));
#endif
	memmove((char *) &sin.sin_addr, h->h_addr, h->h_length);
	p = getprotobyname(proto);
	if (p == NULL) {
		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
		rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
		return (NULL);
	}
	sock = RPC_ANYSOCK;
	switch (p->p_proto) {
	case IPPROTO_UDP:
		tv.tv_sec = 5;
		tv.tv_usec = 0;
		client = clntudp_create(&sin, prog, vers, tv, &sock);
		if (client == NULL) {
			return (NULL);
		}
		tv.tv_sec = 25;
		clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
		break;
	case IPPROTO_TCP:
		client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
		if (client == NULL) {
			return (NULL);
		}
		tv.tv_sec = 25;
		tv.tv_usec = 0;
		clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
		break;
	default:
		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
		rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
		return (NULL);
	}
	return (client);
}
dietlibc-0.33~cvs20120325/librpc/clnt_perror.c010064400000000000000000000151301173363227000156520ustar00/* @(#)clnt_perror.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
#endif

/*
 * clnt_perror.c
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 */
#include 

#include 
#include 
#include 

//extern char *sys_errlist[];
//static char *auth_errmsg();

//extern char *strcpy();

#if 0
static char *buf;

static char *_buf()
{

	if (buf == 0)
		buf = (char *) malloc(256);
	return (buf);
}
#endif	

/*
 * Print reply error info
 */
char *clnt_sperror __P ((CLIENT *rpch, const char *s))
{
#if 0
	struct rpc_err e;
	void clnt_perrno();
	char *err;
	char *str = _buf();
	char *strstart = str;

	if (str == 0)
		return (0);
	CLNT_GETERR(rpch, &e);

	(void) sprintf(str, "%s: ", s);
	str += strlen(str);

	(void) strcpy(str, clnt_sperrno(e.re_status));
	str += strlen(str);

	switch (e.re_status) {
	case RPC_SUCCESS:
	case RPC_CANTENCODEARGS:
	case RPC_CANTDECODERES:
	case RPC_TIMEDOUT:
	case RPC_PROGUNAVAIL:
	case RPC_PROCUNAVAIL:
	case RPC_CANTDECODEARGS:
	case RPC_SYSTEMERROR:
	case RPC_UNKNOWNHOST:
	case RPC_UNKNOWNPROTO:
	case RPC_PMAPFAILURE:
	case RPC_PROGNOTREGISTERED:
	case RPC_FAILED:
		break;

	case RPC_CANTSEND:
	case RPC_CANTRECV:
		(void) sprintf(str, "; errno = %s", sys_errlist[e.re_errno]);
		str += strlen(str);
		break;

	case RPC_VERSMISMATCH:
		(void) sprintf(str,
					   "; low version = %lu, high version = %lu",
					   e.re_vers.low, e.re_vers.high);
		str += strlen(str);
		break;

	case RPC_AUTHERROR:
		err = auth_errmsg(e.re_why);
		(void) sprintf(str, "; why = ");
		str += strlen(str);
		if (err != NULL) {
			(void) sprintf(str, "%s", err);
		} else {
			(void) sprintf(str,
						   "(unknown authentication error - %d)",
						   (int) e.re_why);
		}
		str += strlen(str);
		break;

	case RPC_PROGVERSMISMATCH:
		(void) sprintf(str,
					   "; low version = %lu, high version = %lu",
					   e.re_vers.low, e.re_vers.high);
		str += strlen(str);
		break;

	default:					/* unknown */
		(void) sprintf(str,
					   "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
		str += strlen(str);
		break;
	}
	(void) sprintf(str, "\n");
	return (strstart);
#endif
	return (0);
}

void clnt_perror __P ((CLIENT *rpch, const char *s))
{
	(void) fprintf(stderr, "%s", clnt_sperror(rpch, s));
}


struct rpc_errtab {
	enum clnt_stat status;
	char *message;
};

#if 0
static struct rpc_errtab rpc_errlist[] = {
	{RPC_SUCCESS,
	 "RPC: Success"},
	{RPC_CANTENCODEARGS,
	 "RPC: Can't encode arguments"},
	{RPC_CANTDECODERES,
	 "RPC: Can't decode result"},
	{RPC_CANTSEND,
	 "RPC: Unable to send"},
	{RPC_CANTRECV,
	 "RPC: Unable to receive"},
	{RPC_TIMEDOUT,
	 "RPC: Timed out"},
	{RPC_VERSMISMATCH,
	 "RPC: Incompatible versions of RPC"},
	{RPC_AUTHERROR,
	 "RPC: Authentication error"},
	{RPC_PROGUNAVAIL,
	 "RPC: Program unavailable"},
	{RPC_PROGVERSMISMATCH,
	 "RPC: Program/version mismatch"},
	{RPC_PROCUNAVAIL,
	 "RPC: Procedure unavailable"},
	{RPC_CANTDECODEARGS,
	 "RPC: Server can't decode arguments"},
	{RPC_SYSTEMERROR,
	 "RPC: Remote system error"},
	{RPC_UNKNOWNHOST,
	 "RPC: Unknown host"},
	{RPC_UNKNOWNPROTO,
	 "RPC: Unknown protocol"},
	{RPC_PMAPFAILURE,
	 "RPC: Port mapper failure"},
	{RPC_PROGNOTREGISTERED,
	 "RPC: Program not registered"},
	{RPC_FAILED,
	 "RPC: Failed (unspecified error)"}
};
#endif

/*
 * This interface for use by clntrpc
 */
char *clnt_sperrno(stat)
enum clnt_stat stat;
{
#if 0
	int i;

	for (i = 0; i < sizeof(rpc_errlist) / sizeof(struct rpc_errtab); i++) {
		if (rpc_errlist[i].status == stat) {
			return (rpc_errlist[i].message);
		}
	}
#endif
	return ("RPC: (unknown error code)");
}

void clnt_perrno(num)
enum clnt_stat num;
{
	(void) fprintf(stderr, "%s", clnt_sperrno(num));
}


char *clnt_spcreateerror __P ((__const char *s))
{
#if 0
	extern int sys_nerr;
	extern char *sys_errlist[];
	char *str = _buf();

	if (str == 0)
		return (0);
	(void) sprintf(str, "%s: ", s);
	(void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
	switch (rpc_createerr.cf_stat) {
	case RPC_PMAPFAILURE:
		(void) strcat(str, " - ");
		(void) strcat(str, clnt_sperrno(rpc_createerr.cf_error.re_status));
		break;

	case RPC_SYSTEMERROR:
		(void) strcat(str, " - ");
		if (rpc_createerr.cf_error.re_errno > 0
			&& rpc_createerr.cf_error.re_errno < sys_nerr)
			(void) strcat(str,
						  sys_errlist[rpc_createerr.cf_error.re_errno]);
		else
			(void) sprintf(&str[strlen(str)], "Error %d",
						   rpc_createerr.cf_error.re_errno);
		break;
	}
	(void) strcat(str, "\n");
	return (str);
#endif
	return(0);
}

extern void clnt_pcreateerror __P ((__const char *s))
{
	(void) fprintf(stderr, "%s", clnt_spcreateerror(s));
}

struct auth_errtab {
	enum auth_stat status;
	char *message;
};

#if 0
static struct auth_errtab auth_errlist[] = {
	{AUTH_OK,
	 "Authentication OK"},
	{AUTH_BADCRED,
	 "Invalid client credential"},
	{AUTH_REJECTEDCRED,
	 "Server rejected credential"},
	{AUTH_BADVERF,
	 "Invalid client verifier"},
	{AUTH_REJECTEDVERF,
	 "Server rejected verifier"},
	{AUTH_TOOWEAK,
	 "Client credential too weak"},
	{AUTH_INVALIDRESP,
	 "Invalid server verifier"},
	{AUTH_FAILED,
	 "Failed (unspecified error)"},
};

static char *auth_errmsg(stat)
enum auth_stat stat;
{
	int i;

	for (i = 0; i < sizeof(auth_errlist) / sizeof(struct auth_errtab); i++) {
		if (auth_errlist[i].status == stat) {
			return (auth_errlist[i].message);
		}
	}
	return (NULL);
}
#endif	
dietlibc-0.33~cvs20120325/librpc/clnt_raw.c010064400000000000000000000137141173363227000151400ustar00/* @(#)clnt_raw.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 *
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * clnt_raw.c
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * Memory based rpc for simple testing and timing.
 * Interface to create an rpc client and server in the same process.
 * This lets us similate rpc and get round trip overhead, without
 * any interference from the kernal.
 */

#include 

#define MCALL_MSG_SIZE 24

/*
 * This is the "network" we will be moving stuff over.
 */
static struct clntraw_private {
	CLIENT client_object;
	XDR xdr_stream;
	char _raw_buf[UDPMSGSIZE];
	char mashl_callmsg[MCALL_MSG_SIZE];
	unsigned int mcnt;
} *clntraw_private;

static enum clnt_stat clntraw_call(CLIENT *h, unsigned long proc, 
		xdrproc_t xargs, char* argsp, xdrproc_t xresults, 
		char* resultsp, struct timeval timeout);
static void clntraw_abort(void);
static void clntraw_geterr(CLIENT *, struct rpc_err *);
static bool_t clntraw_freeres(CLIENT *cl, xdrproc_t xdr_res, char* res_ptr);

static bool_t clntraw_control(CLIENT *, int, char *);
static void clntraw_destroy(CLIENT *);

static struct clnt_ops client_ops = {
	clntraw_call,
	clntraw_abort,
	clntraw_geterr,
	clntraw_freeres,
	clntraw_destroy,
	clntraw_control
};

/*
 * Create a client handle for memory based rpc.
 */
CLIENT *clntraw_create(prog, vers)
unsigned long prog;
unsigned long vers;
{
	register struct clntraw_private *clp = clntraw_private;
	struct rpc_msg call_msg;
	XDR *xdrs = &clp->xdr_stream;
	CLIENT *client = &clp->client_object;

	if (clp == 0) {
		clp = (struct clntraw_private *) calloc(1, sizeof(*clp));
		if (clp == 0)
			return (0);
		clntraw_private = clp;
	}
	/*
	 * pre-serialize the staic part of the call msg and stash it away
	 */
	call_msg.rm_direction = CALL;
	call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
	call_msg.rm_call.cb_prog = prog;
	call_msg.rm_call.cb_vers = vers;
	xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
	if (!xdr_callhdr(xdrs, &call_msg)) {
		perror("clnt_raw.c - Fatal header serialization error.");
	}
	clp->mcnt = XDR_GETPOS(xdrs);
	XDR_DESTROY(xdrs);

	/*
	 * Set xdrmem for client/server shared buffer
	 */
	xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);

	/*
	 * create client handle
	 */
	client->cl_ops = &client_ops;
	client->cl_auth = authnone_create();
	return (client);
}

static enum clnt_stat
clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
CLIENT *h;
unsigned long proc;
xdrproc_t xargs;
char* argsp;
xdrproc_t xresults;
char* resultsp;
struct timeval timeout;
{
	register struct clntraw_private *clp = clntraw_private;
	register XDR *xdrs = &clp->xdr_stream;
	struct rpc_msg msg;
	enum clnt_stat status;
	struct rpc_err error;

	if (clp == 0)
		return (RPC_FAILED);
  call_again:
	/*
	 * send request
	 */
	xdrs->x_op = XDR_ENCODE;
	XDR_SETPOS(xdrs, 0);
	((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
	if ((!XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
		(!XDR_PUTLONG(xdrs, (long *) &proc)) ||
		(!AUTH_MARSHALL(h->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp))) {
		return (RPC_CANTENCODEARGS);
	}
	(void) XDR_GETPOS(xdrs);	/* called just to cause overhead */

	/*
	 * We have to call server input routine here because this is
	 * all going on in one process. Yuk.
	 */
	svc_getreq(1);

	/*
	 * get results
	 */
	xdrs->x_op = XDR_DECODE;
	XDR_SETPOS(xdrs, 0);
	msg.acpted_rply.ar_verf = _null_auth;
	msg.acpted_rply.ar_results.where = resultsp;
	msg.acpted_rply.ar_results.proc = xresults;
	if (!xdr_replymsg(xdrs, &msg))
		return (RPC_CANTDECODERES);
	_seterr_reply(&msg, &error);
	status = error.re_status;

	if (status == RPC_SUCCESS) {
		if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
			status = RPC_AUTHERROR;
		}
	} /* end successful completion */
	else {
		if (AUTH_REFRESH(h->cl_auth))
			goto call_again;
	}							/* end of unsuccessful completion */

	if (status == RPC_SUCCESS) {
		if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
			status = RPC_AUTHERROR;
		}
		if (msg.acpted_rply.ar_verf.oa_base != NULL) {
			xdrs->x_op = XDR_FREE;
			(void) xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
		}
	}

	return (status);
}

static void clntraw_geterr(CLIENT *x, struct rpc_err *x1)
{
}


static bool_t clntraw_freeres(cl, xdr_res, res_ptr)
CLIENT *cl;
xdrproc_t xdr_res;
char* res_ptr;
{
	register struct clntraw_private *clp = clntraw_private;
	register XDR *xdrs = &clp->xdr_stream;
	bool_t rval;

	if (clp == 0) {
		rval = (bool_t) RPC_FAILED;
		return (rval);
	}
	xdrs->x_op = XDR_FREE;
	return ((*xdr_res) (xdrs, res_ptr));
}

static void clntraw_abort(void)
{
}

static bool_t clntraw_control(CLIENT *x, int x1, char *x2)
{
	return (FALSE);
}

static void clntraw_destroy(CLIENT *x)
{
}

dietlibc-0.33~cvs20120325/librpc/clnt_simple.c010064400000000000000000000071431173363227000156370ustar00/* @(#)clnt_simple.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)clnt_simple.c 1.35 87/08/11 Copyr 1984 Sun Micro";
#endif

/* 
 * clnt_simple.c
 * Simplified front end to rpc.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 

static struct callrpc_private {
	CLIENT *client;
	int socket;
	unsigned long oldprognum, oldversnum, valid;
	char *oldhost;
} *callrpc_private;

int callrpc (const char *host, const unsigned long prognum,
			 const unsigned long versnum, const unsigned long procnum,
			 const xdrproc_t inproc, const char *in,
			 const xdrproc_t outproc, char *out)
{
	register struct callrpc_private *crp = callrpc_private;
	struct sockaddr_in server_addr;
	enum clnt_stat clnt_stat;
	struct hostent *hp;
	struct timeval timeout, tottimeout;
	void* freeme=0;

	if (crp == 0) {
		crp = (struct callrpc_private *) calloc(1, sizeof(*crp));
		if (crp == 0)
			return (0);
		freeme = callrpc_private = crp;
	}
	if (crp->oldhost == NULL) {
		crp->oldhost = malloc(256);
		if (!crp->oldhost) {
		  free(freeme);
		  return 0;
		}
		crp->oldhost[0] = 0;
		crp->socket = RPC_ANYSOCK;
	}
	if (crp->valid && crp->oldprognum == prognum
		&& crp->oldversnum == versnum && strcmp(crp->oldhost, host) == 0) {
		/* reuse old client */
	} else {
		crp->valid = 0;
		(void) close(crp->socket);
		crp->socket = RPC_ANYSOCK;
		if (crp->client) {
			clnt_destroy(crp->client);
			crp->client = NULL;
		}
		if ((hp = gethostbyname(host)) == NULL)
			return ((int) RPC_UNKNOWNHOST);
		timeout.tv_usec = 0;
		timeout.tv_sec = 5;
		memmove((char *) &server_addr.sin_addr, hp->h_addr, hp->h_length);
		server_addr.sin_family = AF_INET;
		server_addr.sin_port = 0;
		if ((crp->client = clntudp_create(&server_addr, (unsigned long) prognum,
										  (unsigned long) versnum, timeout,
										  &crp->socket)) == NULL)
			return ((int) rpc_createerr.cf_stat);
		crp->valid = 1;
		crp->oldprognum = prognum;
		crp->oldversnum = versnum;
		(void) strcpy(crp->oldhost, host);
	}
	tottimeout.tv_sec = 25;
	tottimeout.tv_usec = 0;
	clnt_stat = clnt_call(crp->client, procnum, inproc, (char*)in,
						  outproc, out, tottimeout);
	/* 
	 * if call failed, empty cache
	 */
	if (clnt_stat != RPC_SUCCESS)
		crp->valid = 0;
	return ((int) clnt_stat);
}
dietlibc-0.33~cvs20120325/librpc/clnt_tcp.c010064400000000000000000000304451173363227000151350ustar00/* @(#)clnt_tcp.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)clnt_tcp.c 1.37 87/10/05 Copyr 1984 Sun Micro";
#endif

/*
 * clnt_tcp.c, Implements a TCP/IP based, client side RPC.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * TCP based RPC supports 'batched calls'.
 * A sequence of calls may be batched-up in a send buffer.  The rpc call
 * return immediately to the client even though the call was not necessarily
 * sent.  The batching occurs if the results' xdr routine is NULL (0) AND
 * the rpc timeout value is zero (see clnt.h, rpc).
 *
 * Clients should NOT casually batch calls that in fact return results; that is,
 * the server side should be aware that a call is batched and not produce any
 * return message.  Batched calls that produce many result messages can
 * deadlock (netlock) the client and the server....
 *
 * Now go hang yourself.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

#define MCALL_MSG_SIZE 24

static enum clnt_stat clnttcp_call(CLIENT *, unsigned long, xdrproc_t, char*, xdrproc_t,
		                               char*, struct timeval);
static void clnttcp_abort(void);
static void clnttcp_geterr(CLIENT *, struct rpc_err *);
static bool_t clnttcp_freeres(CLIENT *, xdrproc_t, char*);
static bool_t clnttcp_control(CLIENT *, int, char *);
static void clnttcp_destroy(CLIENT *);

static struct clnt_ops tcp_ops = {
	clnttcp_call,
	clnttcp_abort,
	clnttcp_geterr,
	clnttcp_freeres,
	clnttcp_destroy,
	clnttcp_control
};

struct ct_data {
	int ct_sock;
	bool_t ct_closeit;
	struct timeval ct_wait;
	bool_t ct_waitset;			/* wait set by clnt_control? */
	struct sockaddr_in ct_addr;
	struct rpc_err ct_error;
	char ct_mcall[MCALL_MSG_SIZE];	/* marshalled callmsg */
	unsigned int ct_mpos;				/* pos after marshal */
	XDR ct_xdrs;
};

static int readtcp(char *ct_char, char* buf, register int len);
static int writetcp(char *ct_char, char* buf, int len);
/*
 * Create a client handle for a tcp/ip connection.
 * If *sockp<0, *sockp is set to a newly created TCP socket and it is
 * connected to raddr.  If *sockp non-negative then
 * raddr is ignored.  The rpc/tcp package does buffering
 * similar to stdio, so the client must pick send and receive buffer sizes,];
 * 0 => use the default.
 * If raddr->sin_port is 0, then a binder on the remote machine is
 * consulted for the right port number.
 * NB: *sockp is copied into a private area.
 * NB: It is the clients responsibility to close *sockp.
 * NB: The rpch->cl_auth is set null authentication.  Caller may wish to set this
 * something more useful.
 */
CLIENT *clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
struct sockaddr_in *raddr;
unsigned long prog;
unsigned long vers;
register int *sockp;
unsigned int sendsz;
unsigned int recvsz;
{
	CLIENT *h = NULL;
	struct timeval now;
	struct rpc_msg call_msg;
        register struct ct_data *ct;

	ct = (struct ct_data *) mem_alloc(sizeof(*ct));
	if (ct == NULL) {
                (void) fprintf(stderr, "clnttcp_create: out of memory\n");
                rpc_createerr.cf_stat = RPC_SYSTEMERROR;
                rpc_createerr.cf_error.re_errno = errno;
                goto fooy;
        }
	h = (CLIENT *) mem_alloc(sizeof(*h));
	if (h == NULL) {
		(void) fprintf(stderr, "clnttcp_create: out of memory\n");
		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
		rpc_createerr.cf_error.re_errno = errno;
		goto fooy;
	}

	/*
	 * If no port number given ask the pmap for one
	 */
	if (raddr->sin_port == 0) {
		unsigned short port;

		if ((port = pmap_getport(raddr, prog, vers, IPPROTO_TCP)) == 0) {
			mem_free((char*) ct, sizeof(struct ct_data));

			mem_free((char*) h, sizeof(CLIENT));
			return ((CLIENT *) NULL);
		}
		raddr->sin_port = htons(port);
	}

	/*
	 * If no socket given, open one
	 */
	if (*sockp < 0) {
		*sockp = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
		(void) bindresvport(*sockp, (struct sockaddr_in *) 0);
		if ((*sockp < 0)
			|| (connect(*sockp, (struct sockaddr *) raddr,
						sizeof(*raddr)) < 0)) {
			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
			rpc_createerr.cf_error.re_errno = errno;
			if (*sockp >= 0)
			(void) close(*sockp);
			goto fooy;
		}
		ct->ct_closeit = TRUE;
	} else {
		ct->ct_closeit = FALSE;
	}

	/*
	 * Set up private data struct
	 */
	ct->ct_sock = *sockp;
	ct->ct_wait.tv_usec = 0;
	ct->ct_waitset = FALSE;
	ct->ct_addr = *raddr;

	/*
	 * Initialize call message
	 */
	(void) gettimeofday(&now, (struct timezone *) 0);
	call_msg.rm_xid = getpid() ^ now.tv_sec ^ now.tv_usec;
	call_msg.rm_direction = CALL;
	call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
	call_msg.rm_call.cb_prog = prog;
	call_msg.rm_call.cb_vers = vers;

	/*
	 * pre-serialize the staic part of the call msg and stash it away
	 */
	xdrmem_create(&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE,
				  XDR_ENCODE);
	if (!xdr_callhdr(&(ct->ct_xdrs), &call_msg)) {
		if (ct->ct_closeit) {
			(void) close(*sockp);
		}
		goto fooy;
	}
	ct->ct_mpos = XDR_GETPOS(&(ct->ct_xdrs));
	XDR_DESTROY(&(ct->ct_xdrs));

	/*
	 * Create a client handle which uses xdrrec for serialization
	 * and authnone for authentication.
	 */
	xdrrec_create(&(ct->ct_xdrs), sendsz, recvsz,
				  (char*) ct, readtcp, writetcp);
	h->cl_ops = &tcp_ops;
	h->cl_private = (char*) ct;
	h->cl_auth = authnone_create();
	return (h);

  fooy:
	/*
	 * Something goofed, free stuff and barf
	 */
	mem_free((char*) ct, sizeof(struct ct_data));

	mem_free((char*) h, sizeof(CLIENT));
	return ((CLIENT *) NULL);
}

static enum clnt_stat
clnttcp_call(h, proc, xdr_args, args_ptr, xdr_results, results_ptr,
			 timeout)
register CLIENT *h;
unsigned long proc;
xdrproc_t xdr_args;
char* args_ptr;
xdrproc_t xdr_results;
char* results_ptr;
struct timeval timeout;
{
	register struct ct_data *ct = (struct ct_data *) h->cl_private;
	register XDR *xdrs = &(ct->ct_xdrs);
	struct rpc_msg reply_msg;
	unsigned long x_id;
	uint32_t *msg_x_id = (uint32_t *) (ct->ct_mcall);	/* yuk */
	register bool_t shipnow;
	int refreshes = 2;

	if (!ct->ct_waitset) {
		ct->ct_wait = timeout;
	}

	shipnow =
		(xdr_results == (xdrproc_t) 0 && timeout.tv_sec == 0
		 && timeout.tv_usec == 0) ? FALSE : TRUE;

  call_again:
	xdrs->x_op = XDR_ENCODE;
	ct->ct_error.re_status = RPC_SUCCESS;
	x_id = ntohl(--(*msg_x_id));
	if ((!XDR_PUTBYTES(xdrs, ct->ct_mcall, ct->ct_mpos)) ||
		(!XDR_PUTLONG(xdrs, (long *) &proc)) ||
		(!AUTH_MARSHALL(h->cl_auth, xdrs)) ||
		(!(*xdr_args) (xdrs, args_ptr))) {
		if (ct->ct_error.re_status == RPC_SUCCESS)
			ct->ct_error.re_status = RPC_CANTENCODEARGS;
		(void) xdrrec_endofrecord(xdrs, TRUE);
		return (ct->ct_error.re_status);
	}
	if (!xdrrec_endofrecord(xdrs, shipnow))
		return (ct->ct_error.re_status = RPC_CANTSEND);
	if (!shipnow)
		return (RPC_SUCCESS);
	/*
	 * Hack to provide rpc-based message passing
	 */
	if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
		return (ct->ct_error.re_status = RPC_TIMEDOUT);
	}


	/*
	 * Keep receiving until we get a valid transaction id
	 */
	xdrs->x_op = XDR_DECODE;
	while (TRUE) {
		reply_msg.acpted_rply.ar_verf = _null_auth;
		reply_msg.acpted_rply.ar_results.where = NULL;
		reply_msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
		if (!xdrrec_skiprecord(xdrs))
			return (ct->ct_error.re_status);
		/* now decode and validate the response header */
		if (!xdr_replymsg(xdrs, &reply_msg)) {
			if (ct->ct_error.re_status == RPC_SUCCESS)
				continue;
			return (ct->ct_error.re_status);
		}
		if ((uint32_t)reply_msg.rm_xid == (uint32_t)x_id)
			break;
	}

	/*
	 * process header
	 */
	_seterr_reply(&reply_msg, &(ct->ct_error));
	if (ct->ct_error.re_status == RPC_SUCCESS) {
		if (!AUTH_VALIDATE(h->cl_auth, &reply_msg.acpted_rply.ar_verf)) {
			ct->ct_error.re_status = RPC_AUTHERROR;
			ct->ct_error.re_why = AUTH_INVALIDRESP;
		} else if (!(*xdr_results) (xdrs, results_ptr)) {
			if (ct->ct_error.re_status == RPC_SUCCESS)
				ct->ct_error.re_status = RPC_CANTDECODERES;
		}
		/* free verifier ... */
		if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
			xdrs->x_op = XDR_FREE;
			(void) xdr_opaque_auth(xdrs, &(reply_msg.acpted_rply.ar_verf));
		}
	} /* end successful completion */
	else {
		/* maybe our credentials need to be refreshed ... */
		if (refreshes-- && AUTH_REFRESH(h->cl_auth))
			goto call_again;
	}							/* end of unsuccessful completion */
	return (ct->ct_error.re_status);
}

static void clnttcp_geterr(h, errp)
CLIENT *h;
struct rpc_err *errp;
{
	register struct ct_data *ct = (struct ct_data *) h->cl_private;

	*errp = ct->ct_error;
}

static bool_t clnttcp_freeres(cl, xdr_res, res_ptr)
CLIENT *cl;
xdrproc_t xdr_res;
char* res_ptr;
{
	register struct ct_data *ct = (struct ct_data *) cl->cl_private;
	register XDR *xdrs = &(ct->ct_xdrs);

	xdrs->x_op = XDR_FREE;
	return ((*xdr_res) (xdrs, res_ptr));
}

static void clnttcp_abort()
{
}

static bool_t clnttcp_control(cl, request, info)
CLIENT *cl;
int request;
char *info;
{
	register struct ct_data *ct = (struct ct_data *) cl->cl_private;

	switch (request) {
	case CLSET_TIMEOUT:
		ct->ct_wait = *(struct timeval *) info;
		ct->ct_waitset = TRUE;
		break;
	case CLGET_TIMEOUT:
		*(struct timeval *) info = ct->ct_wait;
		break;
	case CLGET_SERVER_ADDR:
		*(struct sockaddr_in *) info = ct->ct_addr;
		break;
	default:
		return (FALSE);
	}
	return (TRUE);
}


static void clnttcp_destroy(h)
CLIENT *h;
{
	register struct ct_data *ct = (struct ct_data *) h->cl_private;

	if (ct->ct_closeit) {
		(void) close(ct->ct_sock);
	}
	XDR_DESTROY(&(ct->ct_xdrs));
	mem_free((char*) ct, sizeof(struct ct_data));

	mem_free((char*) h, sizeof(CLIENT));
}

/*
 * Interface between xdr serializer and tcp connection.
 * Behaves like the system calls, read & write, but keeps some error state
 * around for the rpc level.
 */
static int readtcp(ct_char, buf, len)
char *ct_char;
char* buf;
register int len;
{
	struct ct_data *ct=(struct ct_data *)ct_char;
#ifdef FD_SETSIZE
	fd_set mask;
	fd_set readfds;

	if (len == 0)
		return (0);
	FD_ZERO(&mask);
	FD_SET(ct->ct_sock, &mask);
#else
	register int mask = 1 << (ct->ct_sock);
	int readfds;

	if (len == 0)
		return (0);

#endif							/* def FD_SETSIZE */
	while (TRUE) {
		struct timeval tmp;
		tmp=ct->ct_wait;
		readfds = mask;
		switch (select
				(_rpc_dtablesize(), &readfds, 0, 0,
				 &tmp)) {
		case 0:
			ct->ct_error.re_status = RPC_TIMEDOUT;
			return (-1);

		case -1:
			if (errno == EINTR)
				continue;
			ct->ct_error.re_status = RPC_CANTRECV;
			ct->ct_error.re_errno = errno;
			return (-1);
		}
		break;
	}
	switch (len = read(ct->ct_sock, buf, len)) {

	case 0:
		/* premature eof */
		ct->ct_error.re_errno = ECONNRESET;
		ct->ct_error.re_status = RPC_CANTRECV;
		len = -1;				/* it's really an error */
		break;

	case -1:
		ct->ct_error.re_errno = errno;
		ct->ct_error.re_status = RPC_CANTRECV;
		break;
	}
	return (len);
}

static int writetcp(ct_char, buf, len)
char *ct_char;
char* buf;
int len;
{
	register int i, cnt;
	struct ct_data *ct=(struct ct_data *)ct_char;
	for (cnt = len; cnt > 0; cnt -= i, buf += i) {
		if ((i = write(ct->ct_sock, buf, cnt)) == -1) {
			ct->ct_error.re_errno = errno;
			ct->ct_error.re_status = RPC_CANTSEND;
			return (-1);
		}
	}
	return (len);
}

dietlibc-0.33~cvs20120325/librpc/clnt_udp.c010064400000000000000000000306151173363227000151360ustar00/* @(#)clnt_udp.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)clnt_udp.c 1.39 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * clnt_udp.c, Implements a UDP/IP based, client side RPC.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

/*
 * UDP bases client side rpc operations
 */
static enum clnt_stat clntudp_call(register CLIENT *cl,         /* client handle */
		unsigned long proc,                             /* procedure number */
		xdrproc_t xargs,                                /* xdr routine for args */
		char* argsp,                                    /* pointer to args */
		xdrproc_t xresults,                             /* xdr routine for results */
		char* resultsp,                                 /* pointer to results */
		struct timeval utimeout);
static void clntudp_abort(void);
static void clntudp_geterr(CLIENT *, struct rpc_err *);
static bool_t clntudp_freeres(CLIENT *, xdrproc_t, char*);
static bool_t clntudp_control(CLIENT *, int, char *);
static void clntudp_destroy(CLIENT *);

static struct clnt_ops udp_ops = {
	clntudp_call,
	clntudp_abort,
	clntudp_geterr,
	clntudp_freeres,
	clntudp_destroy,
	clntudp_control
};


/* 
 * Private data kept per client handle
 */
struct cu_data {
	int cu_sock;
	bool_t cu_closeit;
	struct sockaddr_in cu_raddr;
	int cu_rlen;
	struct timeval cu_wait;
	struct timeval cu_total;
	struct rpc_err cu_error;
	XDR cu_outxdrs;
	unsigned int cu_xdrpos;
	unsigned int cu_sendsz;
	char *cu_outbuf;
	unsigned int cu_recvsz;
	char cu_inbuf[1];
};

/*
 * Create a UDP based client handle.
 * If *sockp<0, *sockp is set to a newly created UPD socket.
 * If raddr->sin_port is 0 a binder on the remote machine
 * is consulted for the correct port number.
 * NB: It is the clients responsibility to close *sockp.
 * NB: The rpch->cl_auth is initialized to null authentication.
 *     Caller may wish to set this something more useful.
 *
 * wait is the amount of time used between retransmitting a call if
 * no response has been heard;  retransmition occurs until the actual
 * rpc call times out.
 *
 * sendsz and recvsz are the maximum allowable packet sizes that can be
 * sent and received.
 */
CLIENT *clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz,
						  recvsz)
struct sockaddr_in *raddr;
unsigned long program;
unsigned long version;
struct timeval wait;
register int *sockp;
unsigned int sendsz;
unsigned int recvsz;
{
	CLIENT *cl;
	register struct cu_data *cu = NULL;
	struct timeval now;
	struct rpc_msg call_msg;

	cl = (CLIENT *) mem_alloc(sizeof(CLIENT));
	if (cl == NULL) {
		(void) fprintf(stderr, "clntudp_create: out of memory\n");
		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
		rpc_createerr.cf_error.re_errno = errno;
		goto fooy;
	}
	sendsz = ((sendsz + 3) / 4) * 4;
	recvsz = ((recvsz + 3) / 4) * 4;
	cu = (struct cu_data *) mem_alloc(sizeof(*cu) + sendsz + recvsz);
	if (cu == NULL) {
		(void) fprintf(stderr, "clntudp_create: out of memory\n");
		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
		rpc_createerr.cf_error.re_errno = errno;
		goto fooy;
	}
	cu->cu_outbuf = &cu->cu_inbuf[recvsz];

	(void) gettimeofday(&now, (struct timezone *) 0);
	if (raddr->sin_port == 0) {
		unsigned short port;

		if ((port =
			 pmap_getport(raddr, program, version, IPPROTO_UDP)) == 0) {
			goto fooy;
		}
		raddr->sin_port = htons(port);
	}
	cl->cl_ops = &udp_ops;
	cl->cl_private = (char*) cu;
	cu->cu_raddr = *raddr;
	cu->cu_rlen = sizeof(cu->cu_raddr);
	cu->cu_wait = wait;
	cu->cu_total.tv_sec = -1;
	cu->cu_total.tv_usec = -1;
	cu->cu_sendsz = sendsz;
	cu->cu_recvsz = recvsz;
	call_msg.rm_xid = getpid() ^ now.tv_sec ^ now.tv_usec;
	call_msg.rm_direction = CALL;
	call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
	call_msg.rm_call.cb_prog = program;
	call_msg.rm_call.cb_vers = version;
	xdrmem_create(&(cu->cu_outxdrs), cu->cu_outbuf, sendsz, XDR_ENCODE);
	if (!xdr_callhdr(&(cu->cu_outxdrs), &call_msg)) {
		goto fooy;
	}
	cu->cu_xdrpos = XDR_GETPOS(&(cu->cu_outxdrs));
	if (*sockp < 0) {
		int dontblock = 1;

		*sockp = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
		if (*sockp < 0) {
			rpc_createerr.cf_stat = RPC_SYSTEMERROR;
			rpc_createerr.cf_error.re_errno = errno;
			goto fooy;
		}
		/* attempt to bind to prov port */
		(void) bindresvport(*sockp, (struct sockaddr_in *) 0);
		/* the sockets rpc controls are non-blocking */
		(void) ioctl(*sockp, FIONBIO, (char *) &dontblock);
		cu->cu_closeit = TRUE;
	} else {
		cu->cu_closeit = FALSE;
	}
	cu->cu_sock = *sockp;
	cl->cl_auth = authnone_create();
	return (cl);
  fooy:
	if (cu)
		mem_free((char*) cu, sizeof(*cu) + sendsz + recvsz);
	if (cl)
		mem_free((char*) cl, sizeof(CLIENT));
	return ((CLIENT *) NULL);
}

CLIENT *clntudp_create(raddr, program, version, wait, sockp)
struct sockaddr_in *raddr;
unsigned long program;
unsigned long version;
struct timeval wait;
register int *sockp;
{

	return (clntudp_bufcreate(raddr, program, version, wait, sockp,
							  UDPMSGSIZE, UDPMSGSIZE));
}

static enum clnt_stat
clntudp_call(cl, proc, xargs, argsp, xresults, resultsp, utimeout)
register CLIENT *cl;			/* client handle */
unsigned long proc;					/* procedure number */
xdrproc_t xargs;				/* xdr routine for args */
char* argsp;					/* pointer to args */
xdrproc_t xresults;				/* xdr routine for results */
char* resultsp;				/* pointer to results */
struct timeval utimeout;		/* seconds to wait before giving up */
{
	register struct cu_data *cu = (struct cu_data *) cl->cl_private;
	register XDR *xdrs;
	register int outlen;
	register int inlen;
	struct timeval singlewait;
	socklen_t fromlen;

#ifdef FD_SETSIZE
	fd_set readfds;
	fd_set mask;
#else
	int readfds;
	register int mask;
#endif							/* def FD_SETSIZE */
	struct sockaddr_in from;
	struct rpc_msg reply_msg;
	XDR reply_xdrs;
	struct timeval time_waited;
	bool_t ok;
	int nrefreshes = 2;			/* number of times to refresh cred */
	struct timeval timeout;

	if (cu->cu_total.tv_usec == -1) {
		timeout = utimeout;		/* use supplied timeout */
	} else {
		timeout = cu->cu_total;	/* use default timeout */
	}

	time_waited.tv_sec = 0;
	time_waited.tv_usec = 0;
  call_again:
	xdrs = &(cu->cu_outxdrs);
	xdrs->x_op = XDR_ENCODE;
	XDR_SETPOS(xdrs, cu->cu_xdrpos);
	/*
	 * the transaction is the first thing in the out buffer
	 */
	(*(uint32_t *) (cu->cu_outbuf))++;
	if ((!XDR_PUTLONG(xdrs, (long *) &proc)) ||
		(!AUTH_MARSHALL(cl->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp)))
		return (cu->cu_error.re_status = RPC_CANTENCODEARGS);
	outlen = (int) XDR_GETPOS(xdrs);

  send_again:
	if (sendto(cu->cu_sock, cu->cu_outbuf, outlen, 0,
			   (struct sockaddr *) &(cu->cu_raddr), cu->cu_rlen)
		!= outlen) {
		cu->cu_error.re_errno = errno;
		return (cu->cu_error.re_status = RPC_CANTSEND);
	}

	/*
	 * Hack to provide rpc-based message passing
	 */
	if (timeout.tv_sec == 0 && timeout.tv_usec == 0) {
		return (cu->cu_error.re_status = RPC_TIMEDOUT);
	}
	/*
	 * sub-optimal code appears here because we have
	 * some clock time to spare while the packets are in flight.
	 * (We assume that this is actually only executed once.)
	 */
	reply_msg.acpted_rply.ar_verf = _null_auth;
	reply_msg.acpted_rply.ar_results.where = resultsp;
	reply_msg.acpted_rply.ar_results.proc = xresults;
#ifdef FD_SETSIZE
	FD_ZERO(&mask);
	FD_SET(cu->cu_sock, &mask);
#else
	mask = 1 << cu->cu_sock;
#endif							/* def FD_SETSIZE */
	for (;;) {
		readfds = mask;
		singlewait = cu->cu_wait;
		switch (select(_rpc_dtablesize(), &readfds, 0, 0, &singlewait)) {

		case 0:
			time_waited.tv_sec += cu->cu_wait.tv_sec;
			time_waited.tv_usec += cu->cu_wait.tv_usec;
			while (time_waited.tv_usec >= 1000000) {
				time_waited.tv_sec++;
				time_waited.tv_usec -= 1000000;
			}
			if ((time_waited.tv_sec < timeout.tv_sec) ||
				((time_waited.tv_sec == timeout.tv_sec) &&
				 (time_waited.tv_usec < timeout.tv_usec)))
				goto send_again;
			return (cu->cu_error.re_status = RPC_TIMEDOUT);

			/*
			 * buggy in other cases because time_waited is not being
			 * updated.
			 */
		case -1:
			if (errno == EINTR)
				continue;
			cu->cu_error.re_errno = errno;
			return (cu->cu_error.re_status = RPC_CANTRECV);
		}
		do {
			fromlen = sizeof(struct sockaddr);

			inlen = recvfrom(cu->cu_sock, cu->cu_inbuf,
							 (int) cu->cu_recvsz, 0,
							 (struct sockaddr *) &from, &fromlen);
		} while (inlen < 0 && errno == EINTR);
		if (inlen < 0) {
			if (errno == EWOULDBLOCK)
				continue;
			cu->cu_error.re_errno = errno;
			return (cu->cu_error.re_status = RPC_CANTRECV);
		}
		if (inlen < 4)
			continue;
		/* see if reply transaction id matches sent id */
		if (*((uint32_t *) (cu->cu_inbuf)) != *((uint32_t *) (cu->cu_outbuf)))
			continue;
		/* we now assume we have the proper reply */
		break;
	}

	/*
	 * now decode and validate the response
	 */
	xdrmem_create(&reply_xdrs, cu->cu_inbuf, (unsigned int) inlen, XDR_DECODE);
	ok = xdr_replymsg(&reply_xdrs, &reply_msg);
	/* XDR_DESTROY(&reply_xdrs);  save a few cycles on noop destroy */
	if (ok) {
		_seterr_reply(&reply_msg, &(cu->cu_error));
		if (cu->cu_error.re_status == RPC_SUCCESS) {
			if (!AUTH_VALIDATE(cl->cl_auth,
							   &reply_msg.acpted_rply.ar_verf)) {
				cu->cu_error.re_status = RPC_AUTHERROR;
				cu->cu_error.re_why = AUTH_INVALIDRESP;
			}
			if (reply_msg.acpted_rply.ar_verf.oa_base != NULL) {
				xdrs->x_op = XDR_FREE;
				(void) xdr_opaque_auth(xdrs,
									   &(reply_msg.acpted_rply.ar_verf));
			}
		} /* end successful completion */
		else {
			/* maybe our credentials need to be refreshed ... */
			if (nrefreshes > 0 && AUTH_REFRESH(cl->cl_auth)) {
				nrefreshes--;
				goto call_again;
			}
		}						/* end of unsuccessful completion */
	} /* end of valid reply message */
	else {
		cu->cu_error.re_status = RPC_CANTDECODERES;
	}
	return (cu->cu_error.re_status);
}

static void clntudp_geterr(cl, errp)
CLIENT *cl;
struct rpc_err *errp;
{
	register struct cu_data *cu = (struct cu_data *) cl->cl_private;

	*errp = cu->cu_error;
}


static bool_t clntudp_freeres(cl, xdr_res, res_ptr)
CLIENT *cl;
xdrproc_t xdr_res;
char* res_ptr;
{
	register struct cu_data *cu = (struct cu_data *) cl->cl_private;
	register XDR *xdrs = &(cu->cu_outxdrs);

	xdrs->x_op = XDR_FREE;
	return ((*xdr_res) (xdrs, res_ptr));
}

static void clntudp_abort( /*h */ )
	/*CLIENT *h; */
{
}

static bool_t clntudp_control(cl, request, info)
CLIENT *cl;
int request;
char *info;
{
	register struct cu_data *cu = (struct cu_data *) cl->cl_private;

	switch (request) {
	case CLSET_TIMEOUT:
		cu->cu_total = *(struct timeval *) info;
		break;
	case CLGET_TIMEOUT:
		*(struct timeval *) info = cu->cu_total;
		break;
	case CLSET_RETRY_TIMEOUT:
		cu->cu_wait = *(struct timeval *) info;
		break;
	case CLGET_RETRY_TIMEOUT:
		*(struct timeval *) info = cu->cu_wait;
		break;
	case CLGET_SERVER_ADDR:
		*(struct sockaddr_in *) info = cu->cu_raddr;
		break;
	default:
		return (FALSE);
	}
	return (TRUE);
}

static void clntudp_destroy(cl)
CLIENT *cl;
{
	register struct cu_data *cu = (struct cu_data *) cl->cl_private;

	if (cu->cu_closeit) {
		(void) close(cu->cu_sock);
	}
	XDR_DESTROY(&(cu->cu_outxdrs));
	mem_free((char*) cu, (sizeof(*cu) + cu->cu_sendsz + cu->cu_recvsz));
	mem_free((char*) cl, sizeof(CLIENT));
}

dietlibc-0.33~cvs20120325/librpc/get_myaddress.c010064400000000000000000000043501173363227000161550ustar00/* @(#)get_myaddress.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)get_myaddress.c 1.4 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * get_myaddress.c
 *
 * Get client's IP address via ioctl.  This avoids using the yellowpages.
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
//#include 
#include 
#include 
#include 

/* DO use gethostbyname because it's portable */
#include 
#include 
#include 
void get_myaddress(struct sockaddr_in* addr)
{
	char localhost[256 + 1];
	struct hostent *hp;

	gethostname(localhost, 256);
	if ((hp = gethostbyname(localhost)) == NULL) {
		perror("get_myaddress: gethostbyname");
		exit(1);
	}
	addr->sin_family = AF_INET;
	memmove((char *) &addr->sin_addr, (char *) hp->h_addr, hp->h_length);
	addr->sin_port = htons(PMAPPORT);
}
dietlibc-0.33~cvs20120325/librpc/getrpcent.c010064400000000000000000000122331173363227000153150ustar00/* @(#)getrpcent.c	2.2 88/07/29 4.0 RPCSRC */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)getrpcent.c 1.9 87/08/11  Copyr 1984 Sun Micro";
#endif

/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/*
 * Copyright (c) 1985 by Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define index strchr

/*
 * Internet version.
 */
struct rpcdata {
	FILE *rpcf;
	char *current;
	int currentlen;
	int stayopen;
#define	MAXALIASES	35
	char *rpc_aliases[MAXALIASES];
	struct rpcent rpc;
	char line[BUFSIZ + 1];
	char *domain;
} *rpcdata;

static struct rpcent *interpret(const char* val, size_t len);

static char RPCDB[] = "/etc/rpc";

static struct rpcdata *_rpcdata()
{
	register struct rpcdata *d = rpcdata;

	if (d == 0) {
		d = (struct rpcdata *) calloc(1, sizeof(struct rpcdata));

		rpcdata = d;
	}
	return (d);
}

struct rpcent *getrpcbynumber(number)
register int number;
{
	register struct rpcdata *d = _rpcdata();
	register struct rpcent *p;

	if (d == 0)
		return (0);
	setrpcent(0);
	while ((p = getrpcent())) {
		if (p->r_number == number)
			break;
	}
	endrpcent();
	return (p);
}

struct rpcent *
#ifdef __linux__
getrpcbyname(const char *name)
#else
getrpcbyname(name)
char *name;
#endif
{
	struct rpcent *rpc;
	char **rp;

	setrpcent(0);
	while ((rpc = getrpcent())) {
		if (strcmp(rpc->r_name, name) == 0)
			return (rpc);
		for (rp = rpc->r_aliases; *rp != NULL; rp++) {
			if (strcmp(*rp, name) == 0)
				return (rpc);
		}
	}
	endrpcent();
	return (NULL);
}

#ifdef __linux__
void
#endif
setrpcent(f)
int f;
{
	register struct rpcdata *d = _rpcdata();

	if (d == 0)
		return;
	if (d->rpcf == NULL)
		d->rpcf = fopen(RPCDB, "r");
	else
		rewind(d->rpcf);
	if (d->current)
		free(d->current);
	d->current = NULL;
	d->stayopen |= f;
}

#ifdef __linux__
void
#endif
endrpcent()
{
	register struct rpcdata *d = _rpcdata();

	if (d == 0)
		return;
	if (d->current && !d->stayopen) {
		free(d->current);
		d->current = NULL;
	}
	if (d->rpcf && !d->stayopen) {
		fclose(d->rpcf);
		d->rpcf = NULL;
	}
}

struct rpcent *getrpcent()
{
	register struct rpcdata *d = _rpcdata();

	if (d == 0)
		return (NULL);
	if (d->rpcf == NULL && (d->rpcf = fopen(RPCDB, "r")) == NULL)
		return (NULL);
	if (fgets(d->line, BUFSIZ, d->rpcf) == NULL)
		return (NULL);
	return interpret(d->line, strlen(d->line));
}

#ifdef __linux__
static char *firstwhite(s)
char *s;
{
	char *s1, *s2;

	s1 = index(s, ' ');
	s2 = index(s, '\t');
	if (s1) {
		if (s2)
			return (s1 < s2) ? s1 : s2;
		else
			return s1;
	} else
		return s2;
}
#endif

static struct rpcent *interpret(const char* val, size_t len)
{
	register struct rpcdata *d = _rpcdata();
	char *p;
	register char *cp, **q;

	if (d == 0)
		return 0;
	strncpy(d->line, val, (size_t)len);
	p = d->line;
	d->line[len] = '\n';
	if (*p == '#')
		return (getrpcent());
	cp = index(p, '#');
	if (cp == NULL) {
		cp = index(p, '\n');
		if (cp == NULL)
			return (getrpcent());
	}
	*cp = '\0';
#ifdef __linux__
	if ((cp = firstwhite(p)))
		*cp++ = 0;
	else
		return (getrpcent());
#else
	cp = index(p, ' ');
	if (cp == NULL) {
		cp = index(p, '\t');
		if (cp == NULL)
			return (getrpcent());
	}
	*cp++ = '\0';
#endif
	/* THIS STUFF IS INTERNET SPECIFIC */
	d->rpc.r_name = d->line;
	while (*cp == ' ' || *cp == '\t')
		cp++;
	d->rpc.r_number = atoi(cp);
	q = d->rpc.r_aliases = d->rpc_aliases;
#ifdef __linux__
	if ((cp = firstwhite(cp)))
		*cp++ = '\0';
#else
	cp = index(p, ' ');
	if (cp != NULL)
		*cp++ = '\0';
	else {
		cp = index(p, '\t');
		if (cp != NULL)
			*cp++ = '\0';
	}
#endif
	while (cp && *cp) {
		if (*cp == ' ' || *cp == '\t') {
			cp++;
			continue;
		}
		if (q < &(d->rpc_aliases[MAXALIASES - 1]))
			*q++ = cp;
#ifdef __linux__
		if ((cp = firstwhite(cp)))
			*cp++ = '\0';
#else
		cp = index(p, ' ');
		if (cp != NULL)
			*cp++ = '\0';
		else {
			cp = index(p, '\t');
			if (cp != NULL)
				*cp++ = '\0';
		}
#endif
	}
	*q = NULL;
	return (&d->rpc);
}
dietlibc-0.33~cvs20120325/librpc/getrpcport.c010064400000000000000000000037141173363227000155170ustar00/* @(#)getrpcport.c	2.1 88/07/29 4.0 RPCSRC */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)getrpcport.c 1.3 87/08/11 SMI";
#endif
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/*
 * Copyright (c) 1985 by Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 

extern int getrpcport (const char * host, unsigned long prognum,
			   unsigned long versnum, unsigned int proto)
{
	struct sockaddr_in addr;
	struct hostent *hp;

	if ((hp = gethostbyname(host)) == NULL)
		return (0);
	memmove((char *) &addr.sin_addr, hp->h_addr, hp->h_length);
	addr.sin_family = AF_INET;
	addr.sin_port = 0;
	return (pmap_getport(&addr, prognum, versnum, proto));
}
dietlibc-0.33~cvs20120325/librpc/pmap_clnt.c010064400000000000000000000066121173363227000153030ustar00/* @(#)pmap_clnt.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * pmap_clnt.c
 * Client interface to pmap rpc service.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 

static struct timeval timeout = { 5, 0 };
static struct timeval tottimeout = { 60, 0 };

/*
 * Set a mapping between program,version and port.
 * Calls the pmap service remotely to do the mapping.
 */
bool_t pmap_set(const unsigned long program, const unsigned long version, int protocol, unsigned short port)
{
	struct sockaddr_in myaddress;
	int socket = -1;
	register CLIENT *client;
	struct pmap parms;
	bool_t rslt;

	get_myaddress(&myaddress);
	client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
							   timeout, &socket, RPCSMALLMSGSIZE,
							   RPCSMALLMSGSIZE);
	if (client == (CLIENT *) NULL)
		return (FALSE);
	parms.pm_prog = program;
	parms.pm_vers = version;
	parms.pm_prot = protocol;
	parms.pm_port = port;
	if (CLNT_CALL(client, PMAPPROC_SET, (xdrproc_t)xdr_pmap, (char*)&parms, (xdrproc_t)xdr_bool, (void*)&rslt,
				  tottimeout) != RPC_SUCCESS) {
		clnt_perror(client, "Cannot register service");
		return (FALSE);
	}
	CLNT_DESTROY(client);
	(void) close(socket);
	return (rslt);
}

/*
 * Remove the mapping between program,version and port.
 * Calls the pmap service remotely to do the un-mapping.
 */
bool_t pmap_unset(program, version)
unsigned long program;
unsigned long version;
{
	struct sockaddr_in myaddress;
	int socket = -1;
	register CLIENT *client;
	struct pmap parms;
	bool_t rslt;

	get_myaddress(&myaddress);
	client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
							   timeout, &socket, RPCSMALLMSGSIZE,
							   RPCSMALLMSGSIZE);
	if (client == (CLIENT *) NULL)
		return (FALSE);
	parms.pm_prog = program;
	parms.pm_vers = version;
	parms.pm_port = parms.pm_prot = 0;
	CLNT_CALL(client, PMAPPROC_UNSET, (xdrproc_t)xdr_pmap, (char*)&parms, (xdrproc_t)xdr_bool, (void*)&rslt,
			  tottimeout);
	CLNT_DESTROY(client);
	(void) close(socket);
	return (rslt);
}
dietlibc-0.33~cvs20120325/librpc/pmap_getmaps.c010064400000000000000000000052321173363227000160000ustar00/* @(#)pmap_getmaps.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)pmap_getmaps.c 1.10 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * pmap_getmap.c
 * Client interface to pmap rpc service.
 * contains pmap_getmaps, which is only tcp service involved
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
#include 
#define NAMELEN 255
#define MAX_BROADCAST_SIZE 1400
#include 

/*
 * Get a copy of the current port maps.
 * Calls the pmap service remotely to do get the maps.
 */
struct pmaplist *pmap_getmaps(address)
struct sockaddr_in *address;
{
	struct pmaplist *head = (struct pmaplist *) NULL;
	int socket = -1;
	struct timeval minutetimeout;
	register CLIENT *client;

	minutetimeout.tv_sec = 60;
	minutetimeout.tv_usec = 0;
	address->sin_port = htons(PMAPPORT);
	client = clnttcp_create(address, PMAPPROG, PMAPVERS, &socket, 50, 500);
	if (client != (CLIENT *) NULL) {
		if (CLNT_CALL(client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, NULL, (xdrproc_t)xdr_pmaplist,
					  (char*)&head, minutetimeout) != RPC_SUCCESS) {
			clnt_perror(client, "pmap_getmaps rpc problem");
		}
		CLNT_DESTROY(client);
	}
	(void) close(socket);
	address->sin_port = 0;
	return (head);
}
dietlibc-0.33~cvs20120325/librpc/pmap_getport.c010064400000000000000000000060321173363227000160230ustar00/* @(#)pmap_getport.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)pmap_getport.c 1.9 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * pmap_getport.c
 * Client interface to pmap rpc service.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
//#include 
#include 

static struct timeval timeout = { 5, 0 };
static struct timeval tottimeout = { 60, 0 };

/*
 * Find the mapped port for program,version.
 * Calls the pmap service remotely to do the lookup.
 * Returns 0 if no map exists.
 */
unsigned short pmap_getport(address, program, version, protocol)
struct sockaddr_in *address;
unsigned long program;
unsigned long version;
unsigned int protocol;
{
	unsigned short port = 0;
	int socket = -1;
	register CLIENT *client;
	struct pmap parms;

	address->sin_port = htons((unsigned short)PMAPPORT);
	if (protocol == IPPROTO_TCP)
	  client = clnttcp_create(address, PMAPPROG, PMAPVERS, &socket,
							   RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
	else
	  client = clntudp_bufcreate(address, PMAPPROG, PMAPVERS, timeout,
								  &socket, RPCSMALLMSGSIZE,
							   RPCSMALLMSGSIZE);
	if (client != (CLIENT *) NULL) {
		parms.pm_prog = program;
		parms.pm_vers = version;
		parms.pm_prot = protocol;
		parms.pm_port = 0;		/* not needed or used */
		if (CLNT_CALL(client, PMAPPROC_GETPORT, (xdrproc_t)xdr_pmap, (char*)&parms,
					  (xdrproc_t)xdr_u_short, (char*)&port, tottimeout) != RPC_SUCCESS) {
			rpc_createerr.cf_stat = RPC_PMAPFAILURE;
			clnt_geterr(client, &rpc_createerr.cf_error);
		} else if (port == 0) {
			rpc_createerr.cf_stat = RPC_PROGNOTREGISTERED;
		}
		CLNT_DESTROY(client);
	}
	(void) close(socket);
	address->sin_port = 0;
	return (port);
}
dietlibc-0.33~cvs20120325/librpc/pmap_prot.c010064400000000000000000000035261173363227000153300ustar00/* @(#)pmap_prot.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)pmap_prot.c 1.17 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * pmap_prot.c
 * Protocol for the local binder service, or pmap.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 


bool_t xdr_pmap(xdrs, regs)
XDR *xdrs;
struct pmap *regs;
{

	if (xdr_u_long(xdrs, ®s->pm_prog) &&
		xdr_u_long(xdrs, ®s->pm_vers) &&
		xdr_u_long(xdrs, ®s->pm_prot))
			return (xdr_u_long(xdrs, ®s->pm_port));
	return (FALSE);
}
dietlibc-0.33~cvs20120325/librpc/pmap_prot2.c010064400000000000000000000073321173363227000154110ustar00/* @(#)pmap_prot2.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * pmap_prot2.c
 * Protocol for the local binder service, or pmap.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 


/* 
 * What is going on with linked lists? (!)
 * First recall the link list declaration from pmap_prot.h:
 *
 * struct pmaplist {
 *	struct pmap pml_map;
 *	struct pmaplist *pml_map;
 * };
 *
 * Compare that declaration with a corresponding xdr declaration that 
 * is (a) pointer-less, and (b) recursive:
 *
 * typedef union switch (bool_t) {
 * 
 *	case TRUE: struct {
 *		struct pmap;
 * 		pmaplist_t foo;
 *	};
 *
 *	case FALSE: struct {};
 * } pmaplist_t;
 *
 * Notice that the xdr declaration has no nxt pointer while
 * the C declaration has no bool_t variable.  The bool_t can be
 * interpreted as ``more data follows me''; if FALSE then nothing
 * follows this bool_t; if TRUE then the bool_t is followed by
 * an actual struct pmap, and then (recursively) by the 
 * xdr union, pamplist_t.  
 *
 * This could be implemented via the xdr_union primitive, though this
 * would cause a one recursive call per element in the list.  Rather than do
 * that we can ``unwind'' the recursion
 * into a while loop and do the union arms in-place.
 *
 * The head of the list is what the C programmer wishes to past around
 * the net, yet is the data that the pointer points to which is interesting;
 * this sounds like a job for xdr_reference!
 */
bool_t xdr_pmaplist(XDR* xdrs, struct pmaplist** rp)
{
	/*
	 * more_elements is pre-computed in case the direction is
	 * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
	 * xdr_bool when the direction is XDR_DECODE.
	 */
	bool_t more_elements;
	register int freeing = (xdrs->x_op == XDR_FREE);
	register struct pmaplist **next=0;

	while (TRUE) {
		more_elements = (bool_t) (*rp != NULL);
		if (!xdr_bool(xdrs, &more_elements))
			return (FALSE);
		if (!more_elements)
			return (TRUE);		/* we are done */
		/*
		 * the unfortunate side effect of non-recursion is that in
		 * the case of freeing we must remember the next object
		 * before we free the current object ...
		 */
		if (freeing)
			next = &((*rp)->pml_next);
		if (!xdr_reference(xdrs, (char* *) rp,
						   (unsigned int) sizeof(struct pmaplist), (xdrproc_t)xdr_pmap))
			return (FALSE);

		rp = (freeing) ? next : &((*rp)->pml_next);
	}
}
dietlibc-0.33~cvs20120325/librpc/pmap_rmt.c010064400000000000000000000266321173363227000151510ustar00/* @(#)pmap_rmt.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
#endif

/*
 * pmap_rmt.c
 * Client interface to pmap rpc service.
 * remote call and broadcast service
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
//#include 
#include 
#include 
#include 
#define MAX_BROADCAST_SIZE 1400
#include 
#include 
#include "dietfeatures.h"

static struct timeval timeout = { 3, 0 };


/*
 * pmapper remote-call-service interface.
 * This routine is used to call the pmapper remote call service
 * which will look up a service program in the port maps, and then
 * remotely call that routine with the given parameters.  This allows
 * programs to do a lookup and call in one step.
*/
enum clnt_stat pmap_rmtcall (struct sockaddr_in *addr,
				    const unsigned long prog,
				    const unsigned long vers,
				    const unsigned long proc,
				    xdrproc_t xdrargs,
				    char* argsp, xdrproc_t xdrres,
				    char* resp, struct timeval tout,
				    unsigned long *port_ptr) {
  int socket = -1;
  register CLIENT *client;
  struct rmtcallargs a;
  struct rmtcallres r;
  enum clnt_stat stat;

  addr->sin_port = htons((short)PMAPPORT);
  client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &socket);
  if (client != (CLIENT *) NULL) {
    a.prog = prog;
    a.vers = vers;
    a.proc = proc;
    a.args_ptr = argsp;
    a.xdr_args = xdrargs;
    r.port_ptr = port_ptr;
    r.results_ptr = resp;
    r.xdr_results = xdrres;
    stat = CLNT_CALL(client, PMAPPROC_CALLIT, (xdrproc_t)xdr_rmtcall_args, (char*)&a,
		      (xdrproc_t)xdr_rmtcallres, (char*)&r, tout);
    CLNT_DESTROY(client);
  } else {
    stat = RPC_FAILED;
  }
  (void) close(socket);
  addr->sin_port = 0;
  return (stat);
}


/*
 * XDR remote call arguments
 * written for XDR_ENCODE direction only
 */
bool_t xdr_rmtcall_args(XDR* xdrs, struct rmtcallargs* cap)
{
	unsigned int lenposition, argposition, position;

	if (xdr_u_long(xdrs, &(cap->prog)) &&
		xdr_u_long(xdrs, &(cap->vers)) && xdr_u_long(xdrs, &(cap->proc))) {
		lenposition = XDR_GETPOS(xdrs);
		if (!xdr_u_long(xdrs, &(cap->arglen)))
			return (FALSE);
		argposition = XDR_GETPOS(xdrs);
		if (!(*(cap->xdr_args)) (xdrs, cap->args_ptr))
			return (FALSE);
		position = XDR_GETPOS(xdrs);
		cap->arglen = (unsigned long) position - (unsigned long) argposition;
		XDR_SETPOS(xdrs, lenposition);
		if (!xdr_u_long(xdrs, &(cap->arglen)))
			return (FALSE);
		XDR_SETPOS(xdrs, position);
		return (TRUE);
	}
	return (FALSE);
}

/*
 * XDR remote call results
 * written for XDR_DECODE direction only
 */
bool_t xdr_rmtcallres(XDR* xdrs, struct rmtcallres* crp)
{
	char* port_ptr;

	port_ptr = (char*) crp->port_ptr;
	if (xdr_reference(xdrs, &port_ptr, sizeof(unsigned long),
					  (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
		crp->port_ptr = (unsigned long *) port_ptr;
		return ((*(crp->xdr_results)) (xdrs, crp->results_ptr));
	}
	return (FALSE);
}


/*
 * The following is kludged-up support for simple rpc broadcasts.
 * Someday a large, complicated system will replace these trivial 
 * routines which only support udp/ip .
 */

static int getbroadcastnets(addrs, sock, buf)
struct in_addr *addrs;
int sock;						/* any valid socket will do */
char *buf;						/* why allocxate more when we can use existing... */
{
#ifdef __linux__
	struct sockaddr_in addr;

	get_myaddress(&addr);
#if 1
	printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
#else
	addrs[0] = inet_makeaddr(inet_netof(addr.sin_addr), INADDR_ANY);
#endif
	return 1;
#else
	struct ifconf ifc;
	struct ifreq ifreq, *ifr;
	struct sockaddr_in *sin;
	int n, i;

	ifc.ifc_len = UDPMSGSIZE;
	ifc.ifc_buf = buf;
	if (ioctl(sock, SIOCGIFCONF, (char *) &ifc) < 0) {
		perror("broadcast: ioctl (get interface configuration)");
		return (0);
	}
	ifr = ifc.ifc_req;
	for (i = 0, n = ifc.ifc_len / sizeof(struct ifreq); n > 0; n--, ifr++) {
		ifreq = *ifr;
		if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifreq) < 0) {
			perror("broadcast: ioctl (get interface flags)");
			continue;
		}
		if ((ifreq.ifr_flags & IFF_BROADCAST) &&
			(ifreq.ifr_flags & IFF_UP) &&
			ifr->ifr_addr.sa_family == AF_INET) {
			sin = (struct sockaddr_in *) &ifr->ifr_addr;
#ifdef SIOCGIFBRDADDR			/* 4.3BSD */
			if (ioctl(sock, SIOCGIFBRDADDR, (char *) &ifreq) < 0) {
#if 1
				printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
#else
				addrs[i++] = inet_makeaddr(inet_netof
										   (sin->sin_addr.s_addr),
										   INADDR_ANY);
#endif
			} else {
				addrs[i++] = ((struct sockaddr_in *)
							  &ifreq.ifr_addr)->sin_addr;
			}
#else							/* 4.2 BSD */
#if 1
			printf("%s(%d): no inet_makeaddr()\n", __FILE__, __LINE__);
#else
			addrs[i++] = inet_makeaddr(inet_netof
									   (sin->sin_addr.s_addr), INADDR_ANY);
#endif
#endif
		}
	}
	return (i);
#endif
}

enum clnt_stat
clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp,
			   eachresult)
unsigned long prog;					/* program number */
unsigned long vers;					/* version number */
unsigned long proc;					/* procedure number */
xdrproc_t xargs;				/* xdr routine for args */
char* argsp;					/* pointer to args */
xdrproc_t xresults;				/* xdr routine for results */
char* resultsp;				/* pointer to results */
resultproc_t eachresult;		/* call with each result obtained */
{
	enum clnt_stat stat;
	AUTH *unix_auth = authunix_create_default();
	XDR xdr_stream;
	register XDR *xdrs = &xdr_stream;
	int outlen, inlen, nets;
	socklen_t fromlen;
	register int sock;
	int on = 1;

#ifdef FD_SETSIZE
	fd_set mask;
	fd_set readfds;
#else
	int readfds;
	register int mask;
#endif							/* def FD_SETSIZE */
	register int i;
	bool_t done = FALSE;
	register unsigned long xid;
	unsigned long port;
	struct in_addr addrs[20];
	struct sockaddr_in baddr, raddr;	/* broadcast and response addresses */
	struct rmtcallargs a;
	struct rmtcallres r;
	struct rpc_msg msg;
	struct timeval t;
	char outbuf[MAX_BROADCAST_SIZE], inbuf[UDPMSGSIZE];

	/*
	 * initialization: create a socket, a broadcast address, and
	 * preserialize the arguments into a send buffer.
	 */
	if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
		perror("Cannot create socket for broadcast rpc");
		stat = RPC_CANTSEND;
		goto done_broad;
	}
#ifdef SO_BROADCAST
	if (setsockopt(sock, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on)) < 0) {
		perror("Cannot set socket option SO_BROADCAST");
		stat = RPC_CANTSEND;
		goto done_broad;
	}
#endif							/* def SO_BROADCAST */
#ifdef FD_SETSIZE
	FD_ZERO(&mask);
	FD_SET(sock, &mask);
#else
	mask = (1 << sock);
#endif							/* def FD_SETSIZE */
	nets = getbroadcastnets(addrs, sock, inbuf);
	memset((char*)&baddr,0,sizeof(baddr));
	baddr.sin_family = AF_INET;
	baddr.sin_port = htons((short)PMAPPORT);
	baddr.sin_addr.s_addr = htonl(INADDR_ANY);
/*	baddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY); */
	(void) gettimeofday(&t, (struct timezone *) 0);
	msg.rm_xid = xid = getpid() ^ t.tv_sec ^ t.tv_usec;
	t.tv_usec = 0;
	msg.rm_direction = CALL;
	msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
	msg.rm_call.cb_prog = PMAPPROG;
	msg.rm_call.cb_vers = PMAPVERS;
	msg.rm_call.cb_proc = PMAPPROC_CALLIT;
	msg.rm_call.cb_cred = unix_auth->ah_cred;
	msg.rm_call.cb_verf = unix_auth->ah_verf;
	a.prog = prog;
	a.vers = vers;
	a.proc = proc;
	a.xdr_args = xargs;
	a.args_ptr = argsp;
	r.port_ptr = &port;
	r.xdr_results = xresults;
	r.results_ptr = resultsp;
	xdrmem_create(xdrs, outbuf, MAX_BROADCAST_SIZE, XDR_ENCODE);
	if ((!xdr_callmsg(xdrs, &msg)) || (!xdr_rmtcall_args(xdrs, &a))) {
		stat = RPC_CANTENCODEARGS;
		goto done_broad;
	}
	outlen = (int) xdr_getpos(xdrs);
	xdr_destroy(xdrs);
	/*
	 * Basic loop: broadcast a packet and wait a while for response(s).
	 * The response timeout grows larger per iteration.
	 */
	for (t.tv_sec = 4; t.tv_sec <= 14; t.tv_sec += 2) {
		struct timeval tmp;
		for (i = 0; i < nets; i++) {
			baddr.sin_addr = addrs[i];
			if (sendto(sock, outbuf, (size_t)outlen, 0,
					   (struct sockaddr *) &baddr,
					   sizeof(struct sockaddr)) != outlen) {
				perror("Cannot send broadcast packet");
				stat = RPC_CANTSEND;
				goto done_broad;
			}
		}
		if (eachresult == NULL) {
			stat = RPC_SUCCESS;
			goto done_broad;
		}
	  recv_again:
		msg.acpted_rply.ar_verf = _null_auth;
		msg.acpted_rply.ar_results.where = (char*) & r;
		msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_rmtcallres;
		readfds = mask;
		tmp=t;
		switch (select(_rpc_dtablesize(), &readfds, 0, 0, &tmp)) {

		case 0:				/* timed out */
			stat = RPC_TIMEDOUT;
			continue;

		case -1:				/* some kind of error */
			if (errno == EINTR)
				goto recv_again;
			perror("Broadcast select problem");
			stat = RPC_CANTRECV;
			goto done_broad;

		}						/* end of select results switch */
	  try_again:
		fromlen = sizeof(struct sockaddr);

		inlen = recvfrom(sock, inbuf, UDPMSGSIZE, 0,
						 (struct sockaddr *) &raddr, &fromlen);
		if (inlen < 0) {
			if (errno == EINTR)
				goto try_again;
			perror("Cannot receive reply to broadcast");
			stat = RPC_CANTRECV;
			goto done_broad;
		}
		if ((size_t)inlen < sizeof(unsigned long))
			goto recv_again;
		/*
		 * see if reply transaction id matches sent id.
		 * If so, decode the results.
		 */
		xdrmem_create(xdrs, inbuf, (unsigned int) inlen, XDR_DECODE);
		if (xdr_replymsg(xdrs, &msg)) {
			if ((msg.rm_xid == xid) &&
				(msg.rm_reply.rp_stat == MSG_ACCEPTED) &&
				(msg.acpted_rply.ar_stat == SUCCESS)) {
				raddr.sin_port = htons((unsigned short) port);
				done = (*eachresult) (resultsp, &raddr);
			}
			/* otherwise, we just ignore the errors ... */
		} else {
#ifdef notdef
			/* some kind of deserialization problem ... */
			if (msg.rm_xid == xid)
				fprintf(stderr, "Broadcast deserialization problem");
			/* otherwise, just random garbage */
#endif
		}
		xdrs->x_op = XDR_FREE;
		msg.acpted_rply.ar_results.proc = (xdrproc_t)xdr_void;
		(void) xdr_replymsg(xdrs, &msg);
		(void) (*xresults) (xdrs, resultsp);
		xdr_destroy(xdrs);
		if (done) {
			stat = RPC_SUCCESS;
			goto done_broad;
		} else {
			goto recv_again;
		}
	}
  done_broad:
	(void) close(sock);
	AUTH_DESTROY(unix_auth);
	return (stat);
}
dietlibc-0.33~cvs20120325/librpc/rpc_callmsg.c010064400000000000000000000131111173363227000156040ustar00/* @(#)rpc_callmsg.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)rpc_callmsg.c 1.4 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * rpc_callmsg.c
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 */

#include 

#include 
#include 

/*
 * XDR a call message
 */
bool_t xdr_callmsg(xdrs, cmsg)
register XDR *xdrs;
register struct rpc_msg *cmsg;
{
	register int32_t *buf;
	register struct opaque_auth *oa;

	if (xdrs->x_op == XDR_ENCODE) {
		if (cmsg->rm_call.cb_cred.oa_length > MAX_AUTH_BYTES) {
			return (FALSE);
		}
		if (cmsg->rm_call.cb_verf.oa_length > MAX_AUTH_BYTES) {
			return (FALSE);
		}
		buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT
						 + RNDUP(cmsg->rm_call.cb_cred.oa_length)
						 + 2 * BYTES_PER_XDR_UNIT
						 + RNDUP(cmsg->rm_call.cb_verf.oa_length));
		if (buf != NULL) {
			IXDR_PUT_LONG(buf, cmsg->rm_xid);
			IXDR_PUT_ENUM(buf, cmsg->rm_direction);
			if (cmsg->rm_direction != CALL) {
				return (FALSE);
			}
			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_rpcvers);
			if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
				return (FALSE);
			}
			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_prog);
			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_vers);
			IXDR_PUT_LONG(buf, cmsg->rm_call.cb_proc);
			oa = &cmsg->rm_call.cb_cred;
			IXDR_PUT_ENUM(buf, oa->oa_flavor);
			IXDR_PUT_LONG(buf, oa->oa_length);
			if (oa->oa_length) {
				memmove((char*) buf, oa->oa_base, oa->oa_length);
				buf += RNDUP(oa->oa_length) / sizeof(long);
			}
			oa = &cmsg->rm_call.cb_verf;
			IXDR_PUT_ENUM(buf, oa->oa_flavor);
			IXDR_PUT_LONG(buf, oa->oa_length);
			if (oa->oa_length) {
				memmove((char*) buf, oa->oa_base, oa->oa_length);
				/* no real need....
				   buf += RNDUP(oa->oa_length) / sizeof (long);
				 */
			}
			return (TRUE);
		}
	}
	if (xdrs->x_op == XDR_DECODE) {
		buf = XDR_INLINE(xdrs, 8 * BYTES_PER_XDR_UNIT);
		if (buf != NULL) {
			cmsg->rm_xid = IXDR_GET_LONG(buf);
			cmsg->rm_direction = IXDR_GET_ENUM(buf, enum msg_type);

			if (cmsg->rm_direction != CALL) {
				return (FALSE);
			}
			cmsg->rm_call.cb_rpcvers = IXDR_GET_LONG(buf);
			if (cmsg->rm_call.cb_rpcvers != RPC_MSG_VERSION) {
				return (FALSE);
			}
			cmsg->rm_call.cb_prog = IXDR_GET_LONG(buf);
			cmsg->rm_call.cb_vers = IXDR_GET_LONG(buf);
			cmsg->rm_call.cb_proc = IXDR_GET_LONG(buf);
			oa = &cmsg->rm_call.cb_cred;
			oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
			oa->oa_length = IXDR_GET_LONG(buf);
			if (oa->oa_length) {
				if (oa->oa_length > MAX_AUTH_BYTES) {
					return (FALSE);
				}
				if (oa->oa_base == NULL) {
					oa->oa_base = (char*)
						mem_alloc(oa->oa_length);
				}
				buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
				if (buf == NULL) {
					if (xdr_opaque(xdrs, oa->oa_base,
								   oa->oa_length) == FALSE) {
						return (FALSE);
					}
				} else {
					memmove(oa->oa_base, (char*) buf, oa->oa_length);
					/* no real need....
					   buf += RNDUP(oa->oa_length) /
					   sizeof (long);
					 */
				}
			}
			oa = &cmsg->rm_call.cb_verf;
			buf = XDR_INLINE(xdrs, 2 * BYTES_PER_XDR_UNIT);
			if (buf == NULL) {
				if (xdr_enum(xdrs, &oa->oa_flavor) == FALSE ||
					xdr_u_int(xdrs, &oa->oa_length) == FALSE) {
					return (FALSE);
				}
			} else {
				oa->oa_flavor = IXDR_GET_ENUM(buf, enum_t);
				oa->oa_length = IXDR_GET_LONG(buf);
			}
			if (oa->oa_length) {
				if (oa->oa_length > MAX_AUTH_BYTES) {
					return (FALSE);
				}
				if (oa->oa_base == NULL) {
					oa->oa_base = (char*)
						mem_alloc(oa->oa_length);
				}
				buf = XDR_INLINE(xdrs, RNDUP(oa->oa_length));
				if (buf == NULL) {
					if (xdr_opaque(xdrs, oa->oa_base,
								   oa->oa_length) == FALSE) {
						return (FALSE);
					}
				} else {
					memmove(oa->oa_base, (char*) buf, oa->oa_length);
					/* no real need...
					   buf += RNDUP(oa->oa_length) /
					   sizeof (long);
					 */
				}
			}
			return (TRUE);
		}
	}
	if (xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
		xdr_enum(xdrs, (enum_t *) & (cmsg->rm_direction)) &&
		(cmsg->rm_direction == CALL) &&
		xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
		(cmsg->rm_call.cb_rpcvers == RPC_MSG_VERSION) &&
		xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)) &&
		xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)) &&
		xdr_u_long(xdrs, &(cmsg->rm_call.cb_proc)) &&
		xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_cred)))
			return (xdr_opaque_auth(xdrs, &(cmsg->rm_call.cb_verf)));
	return (FALSE);
}
dietlibc-0.33~cvs20120325/librpc/rpc_commondata.c010064400000000000000000000031061173363227000163070ustar00/* @(#)rpc_commondata.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#include 
/*
 * This file should only contain common data (global data) that is exported
 * by public interfaces 
 */
struct opaque_auth _null_auth;

#ifdef FD_SETSIZE
fd_set svc_fdset;
#else
int svc_fds;
#endif							/* def FD_SETSIZE */
struct rpc_createerr rpc_createerr;
dietlibc-0.33~cvs20120325/librpc/rpc_dtablesize.c010064400000000000000000000032621173363227000163160ustar00/* @(#)rpc_dtablesize.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)rpc_dtablesize.c 1.2 87/08/11 Copyr 1987 Sun Micro";
#endif

#include 
#include 
/*
 * Cache the result of getdtablesize(), so we don't have to do an
 * expensive system call every time.
 */
int _rpc_dtablesize(void)
{
	static int size;

	if (size == 0) {
		size = getdtablesize();
	}
	return (size);
}
dietlibc-0.33~cvs20120325/librpc/rpc_prot.c010064400000000000000000000160401173363227000151520ustar00/* @(#)rpc_prot.c	2.3 88/08/07 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)rpc_prot.c 1.36 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * rpc_prot.c
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * This set of routines implements the rpc message definition,
 * its serializer and some common rpc utility routines.
 * The routines are meant for various implementations of rpc -
 * they are NOT for the rpc client or rpc service implementations!
 * Because authentication stuff is easy and is part of rpc, the opaque
 * routines are also in this program.
 */

#include 

#include 

/* * * * * * * * * * * * * * XDR Authentication * * * * * * * * * * * */

/*
 * XDR an opaque authentication struct
 * (see auth.h)
 */
bool_t xdr_opaque_auth(xdrs, ap)
register XDR *xdrs;
register struct opaque_auth *ap;
{

	if (xdr_enum(xdrs, &(ap->oa_flavor)))
		return (xdr_bytes(xdrs, &ap->oa_base,
						  &ap->oa_length, MAX_AUTH_BYTES));
	return (FALSE);
}

/*
 * XDR a DES block
 */
bool_t xdr_des_block(xdrs, blkp)
register XDR *xdrs;
register des_block *blkp;
{
	return (xdr_opaque(xdrs, (char*) blkp, sizeof(des_block)));
}

/* * * * * * * * * * * * * * XDR RPC MESSAGE * * * * * * * * * * * * * * * */

/*
 * XDR the MSG_ACCEPTED part of a reply message union
 */
static bool_t xdr_accepted_reply(xdrs, ar)
register XDR *xdrs;
register struct accepted_reply *ar;
{

	/* personalized union, rather than calling xdr_union */
	if (!xdr_opaque_auth(xdrs, &(ar->ar_verf)))
		return (FALSE);
	if (!xdr_enum(xdrs, (enum_t *) & (ar->ar_stat)))
		return (FALSE);
	switch (ar->ar_stat) {

	case SUCCESS:
		return ((*(ar->ar_results.proc)) (xdrs, ar->ar_results.where));

	case PROG_MISMATCH:
		if (!xdr_u_long(xdrs, &(ar->ar_vers.low)))
			return (FALSE);
		return (xdr_u_long(xdrs, &(ar->ar_vers.high)));
	}
	return (TRUE);				/* TRUE => open ended set of problems */
}

/*
 * XDR the MSG_DENIED part of a reply message union
 */
static bool_t xdr_rejected_reply(xdrs, rr)
register XDR *xdrs;
register struct rejected_reply *rr;
{

	/* personalized union, rather than calling xdr_union */
	if (!xdr_enum(xdrs, (enum_t *) & (rr->rj_stat)))
		return (FALSE);
	switch (rr->rj_stat) {

	case RPC_MISMATCH:
		if (!xdr_u_long(xdrs, &(rr->rj_vers.low)))
			return (FALSE);
		return (xdr_u_long(xdrs, &(rr->rj_vers.high)));

	case AUTH_ERROR:
		return (xdr_enum(xdrs, (enum_t *) & (rr->rj_why)));
	}
	return (FALSE);
}

static struct xdr_discrim reply_dscrm[3] = {
	{(int) MSG_ACCEPTED, (xdrproc_t)xdr_accepted_reply},
	{(int) MSG_DENIED, (xdrproc_t)xdr_rejected_reply},
	{__dontcare__, NULL_xdrproc_t}
};

/*
 * XDR a reply message
 */
bool_t xdr_replymsg(xdrs, rmsg)
register XDR *xdrs;
register struct rpc_msg *rmsg;
{
	if (xdr_u_long(xdrs, &(rmsg->rm_xid)) &&
		xdr_enum(xdrs, (enum_t *) & (rmsg->rm_direction)) &&
		(rmsg->rm_direction == REPLY))
		return (xdr_union(xdrs, (enum_t *) & (rmsg->rm_reply.rp_stat),
						  (char*) & (rmsg->rm_reply.ru), reply_dscrm,
						  NULL_xdrproc_t));
	return (FALSE);
}


/*
 * Serializes the "static part" of a call message header.
 * The fields include: rm_xid, rm_direction, rpcvers, prog, and vers.
 * The rm_xid is not really static, but the user can easily munge on the fly.
 */
bool_t xdr_callhdr(xdrs, cmsg)
register XDR *xdrs;
register struct rpc_msg *cmsg;
{

	cmsg->rm_direction = CALL;
	cmsg->rm_call.cb_rpcvers = RPC_MSG_VERSION;
	if (
		(xdrs->x_op == XDR_ENCODE) &&
		xdr_u_long(xdrs, &(cmsg->rm_xid)) &&
		xdr_enum(xdrs, (enum_t *) & (cmsg->rm_direction)) &&
		xdr_u_long(xdrs, &(cmsg->rm_call.cb_rpcvers)) &&
		xdr_u_long(xdrs, &(cmsg->rm_call.cb_prog)))
			return (xdr_u_long(xdrs, &(cmsg->rm_call.cb_vers)));
	return (FALSE);
}

/* ************************** Client utility routine ************* */

static void accepted(acpt_stat, error)
register enum accept_stat acpt_stat;
register struct rpc_err *error;
{

	switch (acpt_stat) {

	case PROG_UNAVAIL:
		error->re_status = RPC_PROGUNAVAIL;
		return;

	case PROG_MISMATCH:
		error->re_status = RPC_PROGVERSMISMATCH;
		return;

	case PROC_UNAVAIL:
		error->re_status = RPC_PROCUNAVAIL;
		return;

	case GARBAGE_ARGS:
		error->re_status = RPC_CANTDECODEARGS;
		return;

	case SYSTEM_ERR:
		error->re_status = RPC_SYSTEMERROR;
		return;

	case SUCCESS:
		error->re_status = RPC_SUCCESS;
		return;
	}
	/* something's wrong, but we don't know what ... */
	error->re_status = RPC_FAILED;
	error->re_lb.s1 = (long) MSG_ACCEPTED;
	error->re_lb.s2 = (long) acpt_stat;
}

static void rejected(rjct_stat, error)
register enum reject_stat rjct_stat;
register struct rpc_err *error;
{

	switch (rjct_stat) {

	case RPC_VERSMISMATCH:
		error->re_status = RPC_VERSMISMATCH;
		return;

	case AUTH_ERROR:
		error->re_status = RPC_AUTHERROR;
		return;
	}
	/* something's wrong, but we don't know what ... */
	error->re_status = RPC_FAILED;
	error->re_lb.s1 = (long) MSG_DENIED;
	error->re_lb.s2 = (long) rjct_stat;
}

/*
 * given a reply message, fills in the error
 */
void _seterr_reply(msg, error)
register struct rpc_msg *msg;
register struct rpc_err *error;
{

	/* optimized for normal, SUCCESSful case */
	switch (msg->rm_reply.rp_stat) {

	case MSG_ACCEPTED:
		if (msg->acpted_rply.ar_stat == SUCCESS) {
			error->re_status = RPC_SUCCESS;
			return;
		};
		accepted(msg->acpted_rply.ar_stat, error);
		break;

	case MSG_DENIED:
		rejected(msg->rjcted_rply.rj_stat, error);
		break;

	default:
		error->re_status = RPC_FAILED;
		error->re_lb.s1 = (long) (msg->rm_reply.rp_stat);
		break;
	}
	switch (error->re_status) {

	case RPC_VERSMISMATCH:
		error->re_vers.low = msg->rjcted_rply.rj_vers.low;
		error->re_vers.high = msg->rjcted_rply.rj_vers.high;
		break;

	case RPC_AUTHERROR:
		error->re_why = msg->rjcted_rply.rj_why;
		break;

	case RPC_PROGVERSMISMATCH:
		error->re_vers.low = msg->acpted_rply.ar_vers.low;
		error->re_vers.high = msg->acpted_rply.ar_vers.high;
		break;
	}
}
dietlibc-0.33~cvs20120325/librpc/svc.c010064400000000000000000000270301173363227000141160ustar00/* @(#)svc.c	2.4 88/08/11 4.0 RPCSRC; from 1.44 88/02/08 SMI */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)svc.c 1.41 87/10/13 Copyr 1984 Sun Micro";
#endif

/*
 * svc.c, Server-side remote procedure call interface.
 *
 * There are two sets of procedures here.  The xprt routines are
 * for handling transport handles.  The svc routines handle the
 * list of service routines.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 

#ifdef FD_SETSIZE
static SVCXPRT **xports;
#else
#define NOFILE 32

static SVCXPRT *xports[NOFILE];
#endif							/* def FD_SETSIZE */

#define NULL_SVC ((struct svc_callout *)0)
#define	RQCRED_SIZE	400			/* this size is excessive */

/*
 * The services list
 * Each entry represents a set of procedures (an rpc program).
 * The dispatch routine takes request structs and runs the
 * apropriate procedure.
 */
static struct svc_callout {
	struct svc_callout *sc_next;
	unsigned long sc_prog;
	unsigned long sc_vers;
	void (*sc_dispatch) ();
} *svc_head;

static struct svc_callout *svc_find(unsigned long prog, unsigned long vers, struct svc_callout **prev);

/* ***************  SVCXPRT related stuff **************** */

/*
 * Activate a transport handle.
 */
void xprt_register(xprt)
SVCXPRT *xprt;
{
	register int sock = xprt->xp_sock;

#ifdef FD_SETSIZE
	if (xports == NULL) {
		xports = (SVCXPRT **)
			mem_alloc(FD_SETSIZE * sizeof(SVCXPRT *));
	}
	if (sock < _rpc_dtablesize()) {
		xports[sock] = xprt;
		FD_SET(sock, &svc_fdset);
	}
#else
	if (sock < NOFILE) {
		xports[sock] = xprt;
		svc_fds |= (1 << sock);
	}
#endif							/* def FD_SETSIZE */

}

/*
 * De-activate a transport handle. 
 */
void xprt_unregister(xprt)
SVCXPRT *xprt;
{
	register int sock = xprt->xp_sock;

#ifdef FD_SETSIZE
	if ((sock < _rpc_dtablesize()) && (xports[sock] == xprt)) {
		xports[sock] = (SVCXPRT *) 0;
		FD_CLR(sock, &svc_fdset);
	}
#else
	if ((sock < NOFILE) && (xports[sock] == xprt)) {
		xports[sock] = (SVCXPRT *) 0;
		svc_fds &= ~(1 << sock);
	}
#endif							/* def FD_SETSIZE */
}


/* ********************** CALLOUT list related stuff ************* */

/*
 * Add a service program to the callout list.
 * The dispatch routine will be called when a rpc request for this
 * program number comes in.
 */
bool_t svc_register(xprt, prog, vers, dispatch, protocol)
SVCXPRT *xprt;
unsigned long prog;
unsigned long vers;
void (*dispatch) ();
rpcprot_t protocol;
{
	struct svc_callout *prev;
	register struct svc_callout *s;

	if ((s = svc_find(prog, vers, &prev)) != NULL_SVC) {
		if (s->sc_dispatch == dispatch)
			goto pmap_it;		/* he is registering another xptr */
		return (FALSE);
	}
	s = (struct svc_callout *) mem_alloc(sizeof(struct svc_callout));

	if (s == (struct svc_callout *) 0) {
		return (FALSE);
	}
	s->sc_prog = prog;
	s->sc_vers = vers;
	s->sc_dispatch = dispatch;
	s->sc_next = svc_head;
	svc_head = s;
  pmap_it:
	/* now register the information with the local binder service */
	if (protocol) {
		return (pmap_set(prog, vers, protocol, xprt->xp_port));
	}
	return (TRUE);
}

/*
 * Remove a service program from the callout list.
 */
void svc_unregister(prog, vers)
unsigned long prog;
unsigned long vers;
{
	struct svc_callout *prev;
	register struct svc_callout *s;

	if ((s = svc_find(prog, vers, &prev)) == NULL_SVC)
		return;
	if (prev == NULL_SVC) {
		svc_head = s->sc_next;
	} else {
		prev->sc_next = s->sc_next;
	}
	s->sc_next = NULL_SVC;
	mem_free((char *) s, (unsigned int) sizeof(struct svc_callout));

	/* now unregister the information with the local binder service */
	(void) pmap_unset(prog, vers);
}

/*
 * Search the callout list for a program number, return the callout
 * struct.
 */
static struct svc_callout *svc_find(prog, vers, prev)
unsigned long prog;
unsigned long vers;
struct svc_callout **prev;
{
	register struct svc_callout *s, *p;

	p = NULL_SVC;
	for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
		if ((s->sc_prog == prog) && (s->sc_vers == vers))
			goto done;
		p = s;
	}
  done:
	*prev = p;
	return (s);
}

/* ******************* REPLY GENERATION ROUTINES  ************ */

/*
 * Send a reply to an rpc request
 */
bool_t svc_sendreply(xprt, xdr_results, xdr_location)
register SVCXPRT *xprt;
xdrproc_t xdr_results;
char* xdr_location;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_ACCEPTED;
	rply.acpted_rply.ar_verf = xprt->xp_verf;
	rply.acpted_rply.ar_stat = SUCCESS;
	rply.acpted_rply.ar_results.where = xdr_location;
	rply.acpted_rply.ar_results.proc = xdr_results;
	return (SVC_REPLY(xprt, &rply));
}

/*
 * No procedure error reply
 */
void svcerr_noproc(xprt)
register SVCXPRT *xprt;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_ACCEPTED;
	rply.acpted_rply.ar_verf = xprt->xp_verf;
	rply.acpted_rply.ar_stat = PROC_UNAVAIL;
	SVC_REPLY(xprt, &rply);
}

/*
 * Can't decode args error reply
 */
void svcerr_decode(xprt)
register SVCXPRT *xprt;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_ACCEPTED;
	rply.acpted_rply.ar_verf = xprt->xp_verf;
	rply.acpted_rply.ar_stat = GARBAGE_ARGS;
	SVC_REPLY(xprt, &rply);
}

/*
 * Some system error
 */
void svcerr_systemerr(xprt)
register SVCXPRT *xprt;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_ACCEPTED;
	rply.acpted_rply.ar_verf = xprt->xp_verf;
	rply.acpted_rply.ar_stat = SYSTEM_ERR;
	SVC_REPLY(xprt, &rply);
}

/*
 * Authentication error reply
 */
void svcerr_auth(xprt, why)
SVCXPRT *xprt;
enum auth_stat why;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_DENIED;
	rply.rjcted_rply.rj_stat = AUTH_ERROR;
	rply.rjcted_rply.rj_why = why;
	SVC_REPLY(xprt, &rply);
}

/*
 * Auth too weak error reply
 */
void svcerr_weakauth(xprt)
SVCXPRT *xprt;
{

	svcerr_auth(xprt, AUTH_TOOWEAK);
}

/*
 * Program unavailable error reply
 */
void svcerr_noprog(xprt)
register SVCXPRT *xprt;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_ACCEPTED;
	rply.acpted_rply.ar_verf = xprt->xp_verf;
	rply.acpted_rply.ar_stat = PROG_UNAVAIL;
	SVC_REPLY(xprt, &rply);
}

/*
 * Program version mismatch error reply
 */
void svcerr_progvers(xprt, low_vers, high_vers)
register SVCXPRT *xprt;
unsigned long low_vers;
unsigned long high_vers;
{
	struct rpc_msg rply;

	rply.rm_direction = REPLY;
	rply.rm_reply.rp_stat = MSG_ACCEPTED;
	rply.acpted_rply.ar_verf = xprt->xp_verf;
	rply.acpted_rply.ar_stat = PROG_MISMATCH;
	rply.acpted_rply.ar_vers.low = low_vers;
	rply.acpted_rply.ar_vers.high = high_vers;
	SVC_REPLY(xprt, &rply);
}

/* ******************* SERVER INPUT STUFF ******************* */

/*
 * Get server side input from some transport.
 *
 * Statement of authentication parameters management:
 * This function owns and manages all authentication parameters, specifically
 * the "raw" parameters (msg.rm_call.cb_cred and msg.rm_call.cb_verf) and
 * the "cooked" credentials (rqst->rq_clntcred).
 * However, this function does not know the structure of the cooked
 * credentials, so it make the following assumptions: 
 *   a) the structure is contiguous (no pointers), and
 *   b) the cred structure size does not exceed RQCRED_SIZE bytes. 
 * In all events, all three parameters are freed upon exit from this routine.
 * The storage is trivially management on the call stack in user land, but
 * is mallocated in kernel land.
 */

void svc_getreq(rdfds)
int rdfds;
{
#ifdef FD_SETSIZE
	fd_set readfds;

	FD_ZERO(&readfds);
/*#ifdef __linux__*/
#if 0
	readfds = rdfds;
#else
	readfds.fds_bits[0] = rdfds;
#endif
	svc_getreqset(&readfds);
#else
	int readfds = rdfds & svc_fds;

	svc_getreqset(&readfds);
#endif							/* def FD_SETSIZE */
}

void svc_getreqset(readfds)
#ifdef FD_SETSIZE
fd_set *readfds;
{
#else
int *readfds;
{
	int readfds_local = *readfds;
#endif							/* def FD_SETSIZE */
	enum xprt_stat stat;
	struct rpc_msg msg;
	int prog_found;
	unsigned long low_vers;
	unsigned long high_vers;
	struct svc_req r;
	register SVCXPRT *xprt;
	register unsigned long mask;
	register int bit;
	register unsigned long *maskp;
	register int setsize;
	register int sock;
	char cred_area[2 * MAX_AUTH_BYTES + RQCRED_SIZE];

	msg.rm_call.cb_cred.oa_base = cred_area;
	msg.rm_call.cb_verf.oa_base = &(cred_area[MAX_AUTH_BYTES]);
	r.rq_clntcred = &(cred_area[2 * MAX_AUTH_BYTES]);


#ifdef FD_SETSIZE
	setsize = _rpc_dtablesize();
#ifdef __linux__
/*#define NFDBITS	32*/
	maskp = (unsigned long *) readfds;
#else
	maskp = (unsigned long *) readfds->fds_bits;
#endif
	for (sock = 0; sock < setsize; sock += NFDBITS) {
		for (mask = *maskp++; (bit = ffs(mask)); mask ^= (1 << (bit - 1))) {
			/* sock has input waiting */
			xprt = xports[sock + bit - 1];
#else
	for (sock = 0; readfds_local != 0; sock++, readfds_local >>= 1) {
		if ((readfds_local & 1) != 0) {
			/* sock has input waiting */
			xprt = xports[sock];
#endif							/* def FD_SETSIZE */
			/* now receive msgs from xprtprt (support batch calls) */
			do {
				if (SVC_RECV(xprt, &msg)) {

					/* now find the exported program and call it */
					register struct svc_callout *s;
					enum auth_stat why;

					r.rq_xprt = xprt;
					r.rq_prog = msg.rm_call.cb_prog;
					r.rq_vers = msg.rm_call.cb_vers;
					r.rq_proc = msg.rm_call.cb_proc;
					r.rq_cred = msg.rm_call.cb_cred;
					/* first authenticate the message */
					if ((why = _authenticate(&r, &msg)) != AUTH_OK) {
						svcerr_auth(xprt, why);
						goto call_done;
					}
					/* now match message with a registered service */
					prog_found = FALSE;
					low_vers = 0 - 1;
					high_vers = 0;
					for (s = svc_head; s != NULL_SVC; s = s->sc_next) {
						if (s->sc_prog == r.rq_prog) {
							if (s->sc_vers == r.rq_vers) {
								(*s->sc_dispatch) (&r, xprt);
								goto call_done;
							}	/* found correct version */
							prog_found = TRUE;
							if (s->sc_vers < low_vers)
								low_vers = s->sc_vers;
							if (s->sc_vers > high_vers)
								high_vers = s->sc_vers;
						}		/* found correct program */
					}
					/*
					 * if we got here, the program or version
					 * is not served ...
					 */
					if (prog_found)
						svcerr_progvers(xprt, low_vers, high_vers);
					else
						svcerr_noprog(xprt);
					/* Fall through to ... */
				}
			  call_done:
				if ((stat = SVC_STAT(xprt)) == XPRT_DIED) {
					SVC_DESTROY(xprt);
					break;
				}
			} while (stat == XPRT_MOREREQS);
		}
	}
}
dietlibc-0.33~cvs20120325/librpc/svc_auth.c010064400000000000000000000073021173363227000151370ustar00#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)svc_auth.c	2.1 88/08/07 4.0 RPCSRC; from 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 *
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 *
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 *
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/*
 * svc_auth_nodes.c, Server-side rpc authenticator interface,
 * *WITHOUT* DES authentication.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 

/*
 * svcauthsw is the bdevsw of server side authentication. 
 * 
 * Server side authenticators are called from authenticate by
 * using the client auth struct flavor field to index into svcauthsw.
 * The server auth flavors must implement a routine that looks  
 * like: 
 * 
 *	enum auth_stat
 *	flavorx_auth(rqst, msg)
 *		register struct svc_req *rqst; 
 *		register struct rpc_msg *msg;
 *
 */

enum auth_stat _svcauth_null(void);		/* no authentication */
enum auth_stat _svcauth_unix();		/* unix style (uid, gids) */
enum auth_stat _svcauth_short();	/* short hand unix style */

static struct {
	enum auth_stat (*authenticator) ();
} svcauthsw[] = {
	{ _svcauth_null },			/* AUTH_NULL */
	{ _svcauth_unix },			/* AUTH_UNIX */
	{ _svcauth_short },			/* AUTH_SHORT */
};

#define	AUTH_MAX	2			/* HIGHEST AUTH NUMBER */


/*
 * The call rpc message, msg has been obtained from the wire.  The msg contains
 * the raw form of credentials and verifiers.  authenticate returns AUTH_OK
 * if the msg is successfully authenticated.  If AUTH_OK then the routine also
 * does the following things:
 * set rqst->rq_xprt->verf to the appropriate response verifier;
 * sets rqst->rq_client_cred to the "cooked" form of the credentials.
 *
 * NB: rqst->rq_cxprt->verf must be pre-alloctaed;
 * its length is set appropriately.
 *
 * The caller still owns and is responsible for msg->u.cmb.cred and
 * msg->u.cmb.verf.  The authentication system retains ownership of
 * rqst->rq_client_cred, the cooked credentials.
 *
 * There is an assumption that any flavour less than AUTH_NULL is
 * invalid.
 */
enum auth_stat _authenticate(rqst, msg)
register struct svc_req *rqst;
struct rpc_msg *msg;
{
	register int cred_flavor;

	rqst->rq_cred = msg->rm_call.cb_cred;
	rqst->rq_xprt->xp_verf.oa_flavor = _null_auth.oa_flavor;
	rqst->rq_xprt->xp_verf.oa_length = 0;
	cred_flavor = rqst->rq_cred.oa_flavor;
	if ((cred_flavor <= AUTH_MAX) && (cred_flavor >= AUTH_NULL)) {
		return ((*(svcauthsw[cred_flavor].authenticator)) (rqst, msg));
	}

	return (AUTH_REJECTEDCRED);
}

enum auth_stat _svcauth_null( void/*rqst, msg */ )
	/*struct svc_req *rqst;
	   struct rpc_msg *msg; */
{

	return (AUTH_OK);
}
dietlibc-0.33~cvs20120325/librpc/svc_auth_unix.c010064400000000000000000000103601173363227000162000ustar00/* @(#)svc_auth_unix.c	2.3 88/08/01 4.0 RPCSRC; from 1.28 88/02/08 SMI */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)svc_auth_unix.c 1.28 88/02/08 Copyr 1984 Sun Micro";
#endif

/*
 * svc_auth_unix.c
 * Handles UNIX flavor authentication parameters on the service side of rpc.
 * There are two svc auth implementations here: AUTH_UNIX and AUTH_SHORT.
 * _svcauth_unix does full blown unix style uid,gid+gids auth,
 * _svcauth_short uses a shorthand auth to index into a cache of longhand auths.
 * Note: the shorthand has been gutted for efficiency.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 

/*
 * Unix longhand authenticator
 */
enum auth_stat _svcauth_unix(struct svc_req* rqst, struct rpc_msg* msg);

enum auth_stat _svcauth_unix(rqst, msg)
register struct svc_req *rqst;
register struct rpc_msg *msg;
{
	register enum auth_stat stat;
	XDR xdrs;
	register struct authunix_parms *aup;
	register int32_t *buf;
	struct area {
		struct authunix_parms area_aup;
		char area_machname[MAX_MACHINE_NAME + 1];
		gid_t area_gids[NGRPS];
	} *area;
	unsigned int auth_len;
	unsigned int str_len, gid_len;
	register unsigned int i;

	area = (struct area *) rqst->rq_clntcred;
	aup = &area->area_aup;
	aup->aup_machname = area->area_machname;
	aup->aup_gids = area->area_gids;
	auth_len = (unsigned int) msg->rm_call.cb_cred.oa_length;
	xdrmem_create(&xdrs, msg->rm_call.cb_cred.oa_base, auth_len,
				  XDR_DECODE);
	buf = XDR_INLINE(&xdrs, auth_len);
	if (buf != NULL) {
		aup->aup_time = IXDR_GET_LONG(buf);
		str_len = IXDR_GET_U_LONG(buf);
		if (str_len > MAX_MACHINE_NAME) {
			stat = AUTH_BADCRED;
			goto done;
		}
		memmove(aup->aup_machname, (char*) buf, (unsigned int) str_len);
		aup->aup_machname[str_len] = 0;
		str_len = RNDUP(str_len);
		buf += str_len / sizeof(long);

		aup->aup_uid = IXDR_GET_LONG(buf);
		aup->aup_gid = IXDR_GET_LONG(buf);
		gid_len = IXDR_GET_U_LONG(buf);
		if (gid_len > NGRPS) {
			stat = AUTH_BADCRED;
			goto done;
		}
		aup->aup_len = gid_len;
		for (i = 0; i < gid_len; i++) {
			aup->aup_gids[i] = IXDR_GET_LONG(buf);
		}
		/*
		 * five is the smallest unix credentials structure -
		 * timestamp, hostname len (0), uid, gid, and gids len (0).
		 */
		if ((unsigned int)((5 + gid_len) * BYTES_PER_XDR_UNIT + str_len) > auth_len) {
			(void) printf("bad auth_len gid %d str %d auth %d\n",
						  gid_len, str_len, auth_len);
			stat = AUTH_BADCRED;
			goto done;
		}
	} else if (!xdr_authunix_parms(&xdrs, aup)) {
		xdrs.x_op = XDR_FREE;
		(void) xdr_authunix_parms(&xdrs, aup);
		stat = AUTH_BADCRED;
		goto done;
	}
	rqst->rq_xprt->xp_verf.oa_flavor = AUTH_NULL;
	rqst->rq_xprt->xp_verf.oa_length = 0;
	stat = AUTH_OK;
  done:
	XDR_DESTROY(&xdrs);
	return (stat);
}


/*
 * Shorthand unix authenticator
 * Looks up longhand in a cache.
 */
enum auth_stat _svcauth_short(struct svc_req* rqst, struct rpc_msg* msg);

enum auth_stat _svcauth_short(rqst, msg)
struct svc_req *rqst;
struct rpc_msg *msg;
{
	return (AUTH_REJECTEDCRED);
}
dietlibc-0.33~cvs20120325/librpc/svc_raw.c010064400000000000000000000104541173363227000147710ustar00/* @(#)svc_raw.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * svc_raw.c,   This a toy for simple testing and timing.
 * Interface to create an rpc client and server in the same UNIX process.
 * This lets us similate rpc and get rpc (round trip) overhead, without
 * any interference from the kernal.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 


/*
 * This is the "network" that we will be moving data over
 */
static struct svcraw_private {
	char _raw_buf[UDPMSGSIZE];
	SVCXPRT server;
	XDR xdr_stream;
	char verf_body[MAX_AUTH_BYTES];
} *svcraw_private;

static bool_t svcraw_recv(SVCXPRT *__xprt, struct rpc_msg *__msg);
static enum xprt_stat svcraw_stat(SVCXPRT *__xprt);
static bool_t svcraw_getargs(SVCXPRT *__xprt, xdrproc_t __xdr_args,
		                               char* args_ptr);
static bool_t svcraw_reply(SVCXPRT *__xprt, struct rpc_msg *__msg);
static bool_t svcraw_freeargs(SVCXPRT *__xprt, xdrproc_t __xdr_args,
		                                char* args_ptr);
static void svcraw_destroy(SVCXPRT *__xprt);

static struct xp_ops server_ops = {
	svcraw_recv,
	svcraw_stat,
	svcraw_getargs,
	svcraw_reply,
	svcraw_freeargs,
	svcraw_destroy
};


SVCXPRT *svcraw_create()
{
	register struct svcraw_private *srp = svcraw_private;

	if (srp == 0) {
		srp = (struct svcraw_private *) calloc(1, sizeof(*srp));
		if (srp == 0)
			return (0);
	}
	srp->server.xp_sock = 0;
	srp->server.xp_port = 0;
	srp->server.xp_ops = &server_ops;
	srp->server.xp_verf.oa_base = srp->verf_body;
	xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
	return (&srp->server);
}

static enum xprt_stat svcraw_stat(SVCXPRT *__xprt)
{

	return (XPRT_IDLE);
}

static bool_t svcraw_recv(xprt, msg)
SVCXPRT *xprt;
struct rpc_msg *msg;
{
	register struct svcraw_private *srp = svcraw_private;
	register XDR *xdrs;

	if (srp == 0)
		return (0);
	xdrs = &srp->xdr_stream;
	xdrs->x_op = XDR_DECODE;
	XDR_SETPOS(xdrs, 0);
	if (!xdr_callmsg(xdrs, msg))
		return (FALSE);
	return (TRUE);
}

static bool_t svcraw_reply(xprt, msg)
SVCXPRT *xprt;
struct rpc_msg *msg;
{
	register struct svcraw_private *srp = svcraw_private;
	register XDR *xdrs;

	if (srp == 0)
		return (FALSE);
	xdrs = &srp->xdr_stream;
	xdrs->x_op = XDR_ENCODE;
	XDR_SETPOS(xdrs, 0);
	if (!xdr_replymsg(xdrs, msg))
		return (FALSE);
	(void) XDR_GETPOS(xdrs);	/* called just for overhead */
	return (TRUE);
}

static bool_t svcraw_getargs(xprt, xdr_args, args_ptr)
SVCXPRT *xprt;
xdrproc_t xdr_args;
char* args_ptr;
{
	register struct svcraw_private *srp = svcraw_private;

	if (srp == 0)
		return (FALSE);
	return ((*xdr_args) (&srp->xdr_stream, args_ptr));
}

static bool_t svcraw_freeargs(xprt, xdr_args, args_ptr)
SVCXPRT *xprt;
xdrproc_t xdr_args;
char* args_ptr;
{
	register struct svcraw_private *srp = svcraw_private;
	register XDR *xdrs;

	if (srp == 0)
		return (FALSE);
	xdrs = &srp->xdr_stream;
	xdrs->x_op = XDR_FREE;
	return ((*xdr_args) (xdrs, args_ptr));
}

static void svcraw_destroy(SVCXPRT *__xprt)
{
}

dietlibc-0.33~cvs20120325/librpc/svc_run.c010064400000000000000000000040211173363227000147750ustar00/* @(#)svc_run.c	2.1 88/07/29 4.0 RPCSRC */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)svc_run.c 1.1 87/10/13 Copyr 1984 Sun Micro";
#endif

/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */

/*
 * This is the rpc server side idle loop
 * Wait for input, call server program.
 */
#include 
#include 
#include 
#include "dietfeatures.h"

void svc_run()
{
#ifdef FD_SETSIZE
	fd_set readfds;
#else
	int readfds;
#endif							/* def FD_SETSIZE */

	for (;;) {
#ifdef FD_SETSIZE
		readfds = svc_fdset;
#else
		readfds = svc_fds;
#endif							/* def FD_SETSIZE */
		switch (select(_rpc_dtablesize(), &readfds, 0, 0, 0)) {
		case -1:
			if (errno == EINTR) {
				continue;
			}
			perror("svc_run: - select failed");
			return;
		case 0:
			continue;
		default:
			svc_getreqset(&readfds);
		}
	}
}
dietlibc-0.33~cvs20120325/librpc/svc_simple.c010064400000000000000000000101751173363227000154710ustar00/* @(#)svc_simple.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)svc_simple.c 1.18 87/08/11 Copyr 1984 Sun Micro";
#endif

/* 
 * svc_simple.c
 * Simplified front end to rpc.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 

static struct proglst {
	char *(*p_progname) ();
	int p_prognum;
	int p_procnum;
	xdrproc_t p_inproc, p_outproc;
	struct proglst *p_nxt;
} *proglst;
static void universal(struct svc_req *rqstp, SVCXPRT *transp);
static SVCXPRT *transp;
struct proglst *pl;

static int registerrpc(int prognum, int versnum, int procnum, char *(*progname)(), xdrproc_t inproc, xdrproc_t outproc)
{

	if (procnum == NULLPROC) {
		(void) fprintf(stderr,
					   "can't reassign procedure number %ld\n", NULLPROC);
		return (-1);
	}
	if (transp == 0) {
		transp = svcudp_create(RPC_ANYSOCK);
		if (transp == NULL) {
			(void) fprintf(stderr, "couldn't create an rpc server\n");
			return (-1);
		}
	}
	(void) pmap_unset((unsigned long) prognum, (unsigned long) versnum);
	if (!svc_register(transp, (unsigned long) prognum, (unsigned long) versnum,
					  universal, IPPROTO_UDP)) {
		(void) fprintf(stderr, "couldn't register prog %d vers %d\n",
					   prognum, versnum);
		return (-1);
	}
	pl = (struct proglst *) malloc(sizeof(struct proglst));

	if (pl == NULL) {
		(void) fprintf(stderr, "registerrpc: out of memory\n");
		return (-1);
	}
	pl->p_progname = progname;
	pl->p_prognum = prognum;
	pl->p_procnum = procnum;
	pl->p_inproc = inproc;
	pl->p_outproc = outproc;
	pl->p_nxt = proglst;
	proglst = pl;
	return (0);
}

static void universal(rqstp, transp)
struct svc_req *rqstp;
SVCXPRT *transp;
{
	int prog, proc;
	char *outdata;
	char xdrbuf[UDPMSGSIZE];
	struct proglst *pl;

	/* 
	 * enforce "procnum 0 is echo" convention
	 */
	if (rqstp->rq_proc == NULLPROC) {
		if (svc_sendreply(transp, (xdrproc_t)xdr_void, (char *) NULL) == FALSE) {
			(void) fprintf(stderr, "xxx\n");
			exit(1);
		}
		return;
	}
	prog = rqstp->rq_prog;
	proc = rqstp->rq_proc;
	for (pl = proglst; pl != NULL; pl = pl->p_nxt)
		if (pl->p_prognum == prog && pl->p_procnum == proc) {
			/* decode arguments into a CLEAN buffer */
			memset(xdrbuf, 0, sizeof(xdrbuf));	/* required ! */
			if (!svc_getargs(transp, pl->p_inproc, xdrbuf)) {
				svcerr_decode(transp);
				return;
			}
			outdata = (*(pl->p_progname)) (xdrbuf);
			if (outdata == NULL && pl->p_outproc != (xdrproc_t)xdr_void)
				/* there was an error */
				return;
			if (!svc_sendreply(transp, pl->p_outproc, outdata)) {
				(void) fprintf(stderr,
							   "trouble replying to prog %d\n",
							   pl->p_prognum);
				exit(1);
			}
			/* free the decoded arguments */
			(void) svc_freeargs(transp, pl->p_inproc, xdrbuf);
			return;
		}
	(void) fprintf(stderr, "never registered prog %d\n", prog);
	exit(1);
}
dietlibc-0.33~cvs20120325/librpc/svc_tcp.c010064400000000000000000000253041173363227000147660ustar00/* @(#)svc_tcp.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)svc_tcp.c 1.21 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * svc_tcp.c, Server side for TCP/IP based RPC. 
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * Actually implements two flavors of transporter -
 * a tcp rendezvouser (a listner and connection establisher)
 * and a record/tcp stream.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

/*
 * Ops vector for TCP/IP based rpc service handle
 */
static bool_t svctcp_recv(SVCXPRT *xprt, register struct rpc_msg *msg);
static enum xprt_stat svctcp_stat(SVCXPRT *xprt);
static bool_t svctcp_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, char* args_ptr);
static bool_t svctcp_reply(SVCXPRT *xprt, register struct rpc_msg *msg);
static bool_t svctcp_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, char* args_ptr);
static void svctcp_destroy(SVCXPRT *__xprt);

static struct xp_ops svctcp_op = {
        svctcp_recv,
        svctcp_stat,
        svctcp_getargs,
        svctcp_reply,
        svctcp_freeargs,
        svctcp_destroy
};

/*
 * Ops vector for TCP/IP rendezvous handler
 */
static bool_t rendezvous_request(register SVCXPRT *xprt, struct rpc_msg *msg);
static enum xprt_stat rendezvous_stat(SVCXPRT *xprt);

static struct xp_ops svctcp_rendezvous_op = {
	rendezvous_request,
	rendezvous_stat,
	(void*)abort,
	(void*)abort,
	(void*)abort,
	svctcp_destroy
};

static int readtcp(char *xprt_char, char* buf, register int len);
static int writetcp(char *xprt_char, char* buf, int len);
static SVCXPRT *makefd_xprt(int fd, unsigned int sendsize, unsigned int recvsize);

struct tcp_rendezvous {			/* kept in xprt->xp_p1 */
	unsigned int sendsize;
	unsigned int recvsize;
};

struct tcp_conn {				/* kept in xprt->xp_p1 */
	enum xprt_stat strm_stat;
	unsigned long x_id;
	XDR xdrs;
	char verf_body[MAX_AUTH_BYTES];
};

/*
 * Usage:
 *	xprt = svctcp_create(sock, send_buf_size, recv_buf_size);
 *
 * Creates, registers, and returns a (rpc) tcp based transporter.
 * Once *xprt is initialized, it is registered as a transporter
 * see (svc.h, xprt_register).  This routine returns
 * a NULL if a problem occurred.
 *
 * If sock<0 then a socket is created, else sock is used.
 * If the socket, sock is not bound to a port then svctcp_create
 * binds it to an arbitrary port.  The routine then starts a tcp
 * listener on the socket's associated port.  In any (successful) case,
 * xprt->xp_sock is the registered socket number and xprt->xp_port is the
 * associated port number.
 *
 * Since tcp streams do buffered io similar to stdio, the caller can specify
 * how big the send and receive buffers are via the second and third parms;
 * 0 => use the system default.
 */
SVCXPRT *svctcp_create(sock, sendsize, recvsize)
register int sock;
unsigned int sendsize;
unsigned int recvsize;
{
	bool_t madesock = FALSE;
	register SVCXPRT *xprt;
	register struct tcp_rendezvous *r;
	struct sockaddr_in addr;
	socklen_t len = sizeof(struct sockaddr_in);

	if (sock == RPC_ANYSOCK) {
		if ((sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
			perror("svc_tcp.c - tcp socket creation problem");
			return ((SVCXPRT *) NULL);
		}
		madesock = TRUE;
	}
	memset((char *) &addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	if (bindresvport(sock, &addr)) {
		addr.sin_port = 0;
		(void) bind(sock, (struct sockaddr *) &addr, len);
	}
	if ((getsockname(sock, (struct sockaddr *) &addr, &len) != 0) ||
		(listen(sock, 2) != 0)) {
		perror("svctcp_.c - cannot getsockname or listen");
		if (madesock)
			(void) close(sock);
		return ((SVCXPRT *) NULL);
	}
	r = (struct tcp_rendezvous *) mem_alloc(sizeof(*r));
	if (r == NULL) {
		(void) fprintf(stderr, "svctcp_create: out of memory\n");
		return (NULL);
	}
	r->sendsize = sendsize;
	r->recvsize = recvsize;
	xprt = (SVCXPRT *) mem_alloc(sizeof(SVCXPRT));
	if (xprt == NULL) {
		(void) fprintf(stderr, "svctcp_create: out of memory\n");
		return (NULL);
	}
	xprt->xp_p2 = NULL;
	xprt->xp_p1 = (char*) r;
	xprt->xp_verf = _null_auth;
	xprt->xp_ops = &svctcp_rendezvous_op;
	xprt->xp_port = ntohs(addr.sin_port);
	xprt->xp_sock = sock;
	xprt_register(xprt);
	return (xprt);
}

/*
 * Like svtcp_create(), except the routine takes any *open* UNIX file
 * descriptor as its first input.
 */
static SVCXPRT *svcfd_create(fd, sendsize, recvsize)
int fd;
unsigned int sendsize;
unsigned int recvsize;
{

	return (makefd_xprt(fd, sendsize, recvsize));
}

static SVCXPRT *makefd_xprt(fd, sendsize, recvsize)
int fd;
unsigned int sendsize;
unsigned int recvsize;
{
	register SVCXPRT *xprt;
	register struct tcp_conn *cd;

	xprt = (SVCXPRT *) mem_alloc(sizeof(SVCXPRT));
	if (xprt == (SVCXPRT *) NULL) {
		(void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
		goto done;
	}
	cd = (struct tcp_conn *) mem_alloc(sizeof(struct tcp_conn));

	if (cd == (struct tcp_conn *) NULL) {
		(void) fprintf(stderr, "svc_tcp: makefd_xprt: out of memory\n");
		mem_free((char *) xprt, sizeof(SVCXPRT));
		xprt = (SVCXPRT *) NULL;
		goto done;
	}
	cd->strm_stat = XPRT_IDLE;
	xdrrec_create(&(cd->xdrs), sendsize, recvsize,
				  (char*) xprt, readtcp, writetcp);
	xprt->xp_p2 = NULL;
	xprt->xp_p1 = (char*) cd;
	xprt->xp_verf.oa_base = cd->verf_body;
	xprt->xp_addrlen = 0;
	xprt->xp_ops = &svctcp_op;	/* truely deals with calls */
	xprt->xp_port = 0;			/* this is a connection, not a rendezvouser */
	xprt->xp_sock = fd;
	xprt_register(xprt);
  done:
	return (xprt);
}

static bool_t rendezvous_request(register SVCXPRT *xprt, struct rpc_msg *msg)
{
	int sock;
	struct tcp_rendezvous *r;
	struct sockaddr_in addr;
	socklen_t len;

	r = (struct tcp_rendezvous *) xprt->xp_p1;
  again:
	len = sizeof(struct sockaddr_in);

	if ((sock = accept(xprt->xp_sock, (struct sockaddr *) &addr,
					   &len)) < 0) {
		if (errno == EINTR)
			goto again;
		return (FALSE);
	}
	/*
	 * make a new transporter (re-uses xprt)
	 */
	xprt = makefd_xprt(sock, r->sendsize, r->recvsize);
	xprt->xp_raddr = addr;
	xprt->xp_addrlen = len;
	return (FALSE);				/* there is never an rpc msg to be processed */
}

static enum xprt_stat rendezvous_stat(SVCXPRT *xprt)
{

	return (XPRT_IDLE);
}

static void svctcp_destroy(xprt)
register SVCXPRT *xprt;
{
	register struct tcp_conn *cd = (struct tcp_conn *) xprt->xp_p1;

	xprt_unregister(xprt);
	(void) close(xprt->xp_sock);
	if (xprt->xp_port != 0) {
		/* a rendezvouser socket */
		xprt->xp_port = 0;
	} else {
		/* an actual connection socket */
		XDR_DESTROY(&(cd->xdrs));
	}
	mem_free((char*) cd, sizeof(struct tcp_conn));

	mem_free((char*) xprt, sizeof(SVCXPRT));
}

/*
 * All read operations timeout after 35 seconds.
 * A timeout is fatal for the connection.
 */
static struct timeval wait_per_try = { 35, 0 };

/*
 * reads data from the tcp conection.
 * any error is fatal and the connection is closed.
 * (And a read of zero bytes is a half closed stream => error.)
 */
static int readtcp(xprt_char, buf, len)
char *xprt_char;
char* buf;
register int len;
{
	register SVCXPRT *xprt=(SVCXPRT *)xprt_char;
	register int sock = xprt->xp_sock;
#ifdef FD_SETSIZE
	fd_set mask;
	fd_set readfds;

	FD_ZERO(&mask);
	FD_SET(sock, &mask);
#else
	register int mask = 1 << sock;
	int readfds;
#endif							/* def FD_SETSIZE */
	do {
		struct timeval tmp;
		readfds = mask;
		tmp=wait_per_try;
		if (select(_rpc_dtablesize(), &readfds, 0, 0, &tmp) <= 0) {
			if (errno == EINTR) {
				continue;
			}
			goto fatal_err;
		}
#ifdef FD_SETSIZE
	} while (!FD_ISSET(sock, &readfds));
#else
	} while (readfds != mask);
#endif							/* def FD_SETSIZE */
	if ((len = read(sock, buf, len)) > 0) {
		return (len);
	}
  fatal_err:
	((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
	return (-1);
}

/*
 * writes data to the tcp connection.
 * Any error is fatal and the connection is closed.
 */
static int writetcp(xprt_char, buf, len)
char *xprt_char;
char* buf;
int len;
{
	register int i, cnt;
	register SVCXPRT *xprt=(SVCXPRT *)xprt_char;
	for (cnt = len; cnt > 0; cnt -= i, buf += i) {
		if ((i = write(xprt->xp_sock, buf, cnt)) < 0) {
			((struct tcp_conn *) (xprt->xp_p1))->strm_stat = XPRT_DIED;
			return (-1);
		}
	}
	return (len);
}

static enum xprt_stat svctcp_stat(xprt)
SVCXPRT *xprt;
{
	register struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);

	if (cd->strm_stat == XPRT_DIED)
		return (XPRT_DIED);
	if (!xdrrec_eof(&(cd->xdrs)))
		return (XPRT_MOREREQS);
	return (XPRT_IDLE);
}

static bool_t svctcp_recv(xprt, msg)
SVCXPRT *xprt;
register struct rpc_msg *msg;
{
	register struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
	register XDR *xdrs = &(cd->xdrs);

	xdrs->x_op = XDR_DECODE;
	(void) xdrrec_skiprecord(xdrs);
	if (xdr_callmsg(xdrs, msg)) {
		cd->x_id = msg->rm_xid;
		return (TRUE);
	}
	return (FALSE);
}

static bool_t svctcp_getargs(xprt, xdr_args, args_ptr)
SVCXPRT *xprt;
xdrproc_t xdr_args;
char* args_ptr;
{

	return ((*xdr_args)
			(&(((struct tcp_conn *) (xprt->xp_p1))->xdrs), args_ptr));
}

static bool_t svctcp_freeargs(xprt, xdr_args, args_ptr)
SVCXPRT *xprt;
xdrproc_t xdr_args;
char* args_ptr;
{
	register XDR *xdrs = &(((struct tcp_conn *) (xprt->xp_p1))->xdrs);

	xdrs->x_op = XDR_FREE;
	return ((*xdr_args) (xdrs, args_ptr));
}

static bool_t svctcp_reply(xprt, msg)
SVCXPRT *xprt;
register struct rpc_msg *msg;
{
	register struct tcp_conn *cd = (struct tcp_conn *) (xprt->xp_p1);
	register XDR *xdrs = &(cd->xdrs);
	register bool_t stat;

	xdrs->x_op = XDR_ENCODE;
	msg->rm_xid = cd->x_id;
	stat = xdr_replymsg(xdrs, msg);
	(void) xdrrec_endofrecord(xdrs, TRUE);
	return (stat);
}

dietlibc-0.33~cvs20120325/librpc/svc_udp.c010064400000000000000000000307511173363227000147720ustar00/* @(#)svc_udp.c	2.2 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)svc_udp.c 1.24 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * svc_udp.c,
 * Server side for UDP/IP based RPC.  (Does some caching in the hopes of
 * achieving execute-at-most-once semantics.)
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 */

#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

#define rpc_buffer(xprt) ((xprt)->xp_p1)

static bool_t svcudp_recv(register SVCXPRT *xprt, struct rpc_msg *msg);
static bool_t svcudp_reply(register SVCXPRT *xprt, struct rpc_msg *msg);
static enum xprt_stat svcudp_stat(SVCXPRT *xprt);
static bool_t svcudp_getargs(SVCXPRT *xprt, xdrproc_t xdr_args, char* args_ptr);
static bool_t svcudp_freeargs(SVCXPRT *xprt, xdrproc_t xdr_args, char* args_ptr);
static void svcudp_destroy(register SVCXPRT *xprt);

static struct xp_ops svcudp_op = {
        svcudp_recv,
        svcudp_stat,
        svcudp_getargs,
        svcudp_reply,
        svcudp_freeargs,
        svcudp_destroy
};

/*
 * kept in xprt->xp_p2
 */
struct svcudp_data {
	unsigned int su_iosz;				/* byte size of send.recv buffer */
	unsigned long su_xid;				/* transaction id */
	XDR su_xdrs;				/* XDR handle */
	char su_verfbody[MAX_AUTH_BYTES];	/* verifier body */
	char *su_cache;				/* cached data, NULL if no cache */
};

#define	su_data(xprt)	((struct svcudp_data *)(xprt->xp_p2))

static int cache_get(SVCXPRT* xprt, struct rpc_msg* msg, char** replyp, unsigned long* replylenp);
static void cache_set(SVCXPRT* xprt, unsigned long replylen);

/*
 * Usage:
 *	xprt = svcudp_create(sock);
 *
 * If sock<0 then a socket is created, else sock is used.
 * If the socket, sock is not bound to a port then svcudp_create
 * binds it to an arbitrary port.  In any (successful) case,
 * xprt->xp_sock is the registered socket number and xprt->xp_port is the
 * associated port number.
 * Once *xprt is initialized, it is registered as a transporter;
 * see (svc.h, xprt_register).
 * The routines returns NULL if a problem occurred.
 */
SVCXPRT *svcudp_bufcreate(sock, sendsz, recvsz)
register int sock;
unsigned int sendsz, recvsz;
{
	bool_t madesock = FALSE;
	register SVCXPRT *xprt;
	register struct svcudp_data *su;
	struct sockaddr_in addr;
	socklen_t len = sizeof(struct sockaddr_in);

	if (sock == RPC_ANYSOCK) {
		if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
			perror("svcudp_create: socket creation problem");
			return ((SVCXPRT *) NULL);
		}
		madesock = TRUE;
	}
	memset((char *) &addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	if (bindresvport(sock, &addr)) {
		addr.sin_port = 0;
		(void) bind(sock, (struct sockaddr *) &addr, len);
	}
	if (getsockname(sock, (struct sockaddr *) &addr, &len) != 0) {
		perror("svcudp_create - cannot getsockname");
		if (madesock)
			(void) close(sock);
		return ((SVCXPRT *) NULL);
	}
	xprt = (SVCXPRT *) mem_alloc(sizeof(SVCXPRT));
	if (xprt == NULL) {
		(void) fprintf(stderr, "svcudp_create: out of memory\n");
		return (NULL);
	}
	su = (struct svcudp_data *) mem_alloc(sizeof(*su));
	if (su == NULL) {
		(void) fprintf(stderr, "svcudp_create: out of memory\n");
		return (NULL);
	}
	su->su_iosz = ((MAX(sendsz, recvsz) + 3) / 4) * 4;
	if ((rpc_buffer(xprt) = mem_alloc(su->su_iosz)) == NULL) {
		(void) fprintf(stderr, "svcudp_create: out of memory\n");
		return (NULL);
	}
	xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
				  XDR_DECODE);
	su->su_cache = NULL;
	xprt->xp_p2 = (char*) su;
	xprt->xp_verf.oa_base = su->su_verfbody;
	xprt->xp_ops = &svcudp_op;
	xprt->xp_port = ntohs(addr.sin_port);
	xprt->xp_sock = sock;
	xprt_register(xprt);
	return (xprt);
}

SVCXPRT *svcudp_create(sock)
int sock;
{

	return (svcudp_bufcreate(sock, UDPMSGSIZE, UDPMSGSIZE));
}

static enum xprt_stat svcudp_stat(xprt)
SVCXPRT *xprt;
{

	return (XPRT_IDLE);
}

static bool_t svcudp_recv(xprt, msg)
register SVCXPRT *xprt;
struct rpc_msg *msg;
{
	register struct svcudp_data *su = su_data(xprt);
	register XDR *xdrs = &(su->su_xdrs);
	register int rlen;
	char *reply;
	unsigned long replylen;
	socklen_t len;

  again:
	len = sizeof(struct sockaddr_in);

	rlen = recvfrom(xprt->xp_sock, rpc_buffer(xprt), (int) su->su_iosz,
					0, (struct sockaddr *) &(xprt->xp_raddr),
					&len);
	xprt->xp_addrlen = len;
	if (rlen == -1 && errno == EINTR)
		goto again;
	if (rlen < (int)(4 * sizeof(unsigned long)))
		return (FALSE);
	xdrs->x_op = XDR_DECODE;
	XDR_SETPOS(xdrs, 0);
	if (!xdr_callmsg(xdrs, msg))
		return (FALSE);
	su->su_xid = msg->rm_xid;
	if (su->su_cache != NULL) {
		if (cache_get(xprt, msg, &reply, &replylen)) {
			(void) sendto(xprt->xp_sock, reply, (int) replylen, 0,
						  (struct sockaddr *) &xprt->xp_raddr,
						  xprt->xp_addrlen);
			return (TRUE);
		}
	}
	return (TRUE);
}

static bool_t svcudp_reply(xprt, msg)
register SVCXPRT *xprt;
struct rpc_msg *msg;
{
	register struct svcudp_data *su = su_data(xprt);
	register XDR *xdrs = &(su->su_xdrs);
	register int slen;
	register bool_t stat = FALSE;

	xdrs->x_op = XDR_ENCODE;
	XDR_SETPOS(xdrs, 0);
	msg->rm_xid = su->su_xid;
	if (xdr_replymsg(xdrs, msg)) {
		slen = (int) XDR_GETPOS(xdrs);
		if (sendto(xprt->xp_sock, rpc_buffer(xprt), slen, 0,
				   (struct sockaddr *) &(xprt->xp_raddr), xprt->xp_addrlen)
			== slen) {
			stat = TRUE;
			if (su->su_cache && slen >= 0) {
				cache_set(xprt, (unsigned long) slen);
			}
		}
	}
	return (stat);
}

static bool_t svcudp_getargs(xprt, xdr_args, args_ptr)
SVCXPRT *xprt;
xdrproc_t xdr_args;
char* args_ptr;
{

	return ((*xdr_args) (&(su_data(xprt)->su_xdrs), args_ptr));
}

static bool_t svcudp_freeargs(xprt, xdr_args, args_ptr)
SVCXPRT *xprt;
xdrproc_t xdr_args;
char* args_ptr;
{
	register XDR *xdrs = &(su_data(xprt)->su_xdrs);

	xdrs->x_op = XDR_FREE;
	return ((*xdr_args) (xdrs, args_ptr));
}

static void svcudp_destroy(xprt)
register SVCXPRT *xprt;
{
	register struct svcudp_data *su = su_data(xprt);

	xprt_unregister(xprt);
	(void) close(xprt->xp_sock);
	XDR_DESTROY(&(su->su_xdrs));
	mem_free(rpc_buffer(xprt), su->su_iosz);
	mem_free((char*) su, sizeof(struct svcudp_data));

	mem_free((char*) xprt, sizeof(SVCXPRT));
}


/***********this could be a separate file*********************/

/*
 * Fifo cache for udp server
 * Copies pointers to reply buffers into fifo cache
 * Buffers are sent again if retransmissions are detected.
 */

#define SPARSENESS 4			/* 75% sparse */

#define CACHE_PERROR(msg)	\
	(void) fprintf(stderr,"%s\n", msg)

#define ALLOC(type, size)	\
	(type *) mem_alloc((unsigned) (sizeof(type) * (size)))

#define BZERO(addr, type, size)	 \
	memset((char *) addr, 0, sizeof(type) * (int) (size))

/*
 * An entry in the cache
 */
typedef struct cache_node *cache_ptr;
struct cache_node {
	/*
	 * Index into cache is xid, proc, vers, prog and address
	 */
	unsigned long cache_xid;
	unsigned long cache_proc;
	unsigned long cache_vers;
	unsigned long cache_prog;
	struct sockaddr_in cache_addr;
	/*
	 * The cached reply and length
	 */
	char *cache_reply;
	unsigned long cache_replylen;
	/*
	 * Next node on the list, if there is a collision
	 */
	cache_ptr cache_next;
};



/*
 * The entire cache
 */
struct udp_cache {
	unsigned long uc_size;				/* size of cache */
	cache_ptr *uc_entries;		/* hash table of entries in cache */
	cache_ptr *uc_fifo;			/* fifo list of entries in cache */
	unsigned long uc_nextvictim;		/* points to next victim in fifo list */
	unsigned long uc_prog;				/* saved program number */
	unsigned long uc_vers;				/* saved version number */
	unsigned long uc_proc;				/* saved procedure number */
	struct sockaddr_in uc_addr;	/* saved caller's address */
};


/*
 * the hashing function
 */
#define CACHE_LOC(transp, xid)	\
 (xid % (SPARSENESS*((struct udp_cache *) su_data(transp)->su_cache)->uc_size))


/*
 * Enable use of the cache. 
 * Note: there is no disable.
 */
static int svcudp_enablecache(SVCXPRT* transp, unsigned long size)
{
	struct svcudp_data *su = su_data(transp);
	struct udp_cache *uc;

	if (su->su_cache != NULL) {
		CACHE_PERROR("enablecache: cache already enabled");
		return (0);
	}
	uc = ALLOC(struct udp_cache, 1);
	if (uc == NULL) {
		CACHE_PERROR("enablecache: could not allocate cache");
		return (0);
	}
	uc->uc_size = size;
	uc->uc_nextvictim = 0;
	uc->uc_entries = ALLOC(cache_ptr, size * SPARSENESS);
	if (uc->uc_entries == NULL) {
		CACHE_PERROR("enablecache: could not allocate cache data");
		return (0);
	}
	BZERO(uc->uc_entries, cache_ptr, size * SPARSENESS);
	uc->uc_fifo = ALLOC(cache_ptr, size);
	if (uc->uc_fifo == NULL) {
		CACHE_PERROR("enablecache: could not allocate cache fifo");
		return (0);
	}
	BZERO(uc->uc_fifo, cache_ptr, size);
	su->su_cache = (char *) uc;
	return (1);
}


/*
 * Set an entry in the cache
 */
static void cache_set(SVCXPRT* xprt, unsigned long replylen)
{
	register cache_ptr victim;
	register cache_ptr *vicp;
	register struct svcudp_data *su = su_data(xprt);
	struct udp_cache *uc = (struct udp_cache *) su->su_cache;
	unsigned int loc;
	char *newbuf;

	/*
	 * Find space for the new entry, either by
	 * reusing an old entry, or by mallocing a new one
	 */
	victim = uc->uc_fifo[uc->uc_nextvictim];
	if (victim != NULL) {
		loc = CACHE_LOC(xprt, victim->cache_xid);
		for (vicp = &uc->uc_entries[loc];
			 *vicp != NULL && *vicp != victim;
			 vicp = &(*vicp)->cache_next);
		if (*vicp == NULL) {
			CACHE_PERROR("cache_set: victim not found");
			return;
		}
		*vicp = victim->cache_next;	/* remote from cache */
		newbuf = victim->cache_reply;
	} else {
		victim = ALLOC(struct cache_node, 1);

		if (victim == NULL) {
			CACHE_PERROR("cache_set: victim alloc failed");
			return;
		}
		newbuf = mem_alloc(su->su_iosz);
		if (newbuf == NULL) {
			CACHE_PERROR("cache_set: could not allocate new rpc_buffer");
			return;
		}
	}

	/*
	 * Store it away
	 */
	victim->cache_replylen = replylen;
	victim->cache_reply = rpc_buffer(xprt);
	rpc_buffer(xprt) = newbuf;
	xdrmem_create(&(su->su_xdrs), rpc_buffer(xprt), su->su_iosz,
				  XDR_ENCODE);
	victim->cache_xid = su->su_xid;
	victim->cache_proc = uc->uc_proc;
	victim->cache_vers = uc->uc_vers;
	victim->cache_prog = uc->uc_prog;
	victim->cache_addr = uc->uc_addr;
	loc = CACHE_LOC(xprt, victim->cache_xid);
	victim->cache_next = uc->uc_entries[loc];
	uc->uc_entries[loc] = victim;
	uc->uc_fifo[uc->uc_nextvictim++] = victim;
	uc->uc_nextvictim %= uc->uc_size;
}

/*
 * Try to get an entry from the cache
 * return 1 if found, 0 if not found
 */
static int cache_get(SVCXPRT* xprt, struct rpc_msg* msg, char** replyp, unsigned long* replylenp)
{
	unsigned int loc;
	register cache_ptr ent;
	register struct svcudp_data *su = su_data(xprt);
	register struct udp_cache *uc = (struct udp_cache *) su->su_cache;

#	define EQADDR(a1, a2)	(memcmp((char*)&a1, (char*)&a2, sizeof(a1)) == 0)

	loc = CACHE_LOC(xprt, su->su_xid);
	for (ent = uc->uc_entries[loc]; ent != NULL; ent = ent->cache_next) {
		if (ent->cache_xid == su->su_xid &&
			ent->cache_proc == uc->uc_proc &&
			ent->cache_vers == uc->uc_vers &&
			ent->cache_prog == uc->uc_prog &&
			EQADDR(ent->cache_addr, uc->uc_addr)) {
			*replyp = ent->cache_reply;
			*replylenp = ent->cache_replylen;
			return (1);
		}
	}
	/*
	 * Failed to find entry
	 * Remember a few things so we can do a set later
	 */
	uc->uc_proc = msg->rm_call.cb_proc;
	uc->uc_vers = msg->rm_call.cb_vers;
	uc->uc_prog = msg->rm_call.cb_prog;
	uc->uc_addr = xprt->xp_raddr;
	return (0);
}

dietlibc-0.33~cvs20120325/librpc/xdr.c010064400000000000000000000267221173363227000141270ustar00/* @(#)xdr.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)xdr.c 1.35 87/08/12";
#endif

/*
 * xdr.c, Generic XDR routines implementation.
 *
 * Copyright (C) 1986, Sun Microsystems, Inc.
 *
 * These are the "generic" xdr routines used to serialize and de-serialize
 * most common data items.  See xdr.h for more info on the interface to
 * xdr.
 */

#include 
#include 
#include 
#include 
#include 

/*
 * constants specific to the xdr "protocol"
 */
#define XDR_FALSE	((long) 0)
#define XDR_TRUE	((long) 1)
#define LASTUNSIGNED	((unsigned int) 0-1)

/*
 * for unit alignment
 */
static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };

/*
 * Free a data structure using XDR
 * Not a filter, but a convenient utility nonetheless
 */
void xdr_free(xdrproc_t proc, char* objp)
{
	XDR x;

	x.x_op = XDR_FREE;
	(*proc) (&x, objp);
}

/*
 * XDR nothing
 */
bool_t xdr_void( /* xdrs, addr */ )
	/* XDR *xdrs; */
	/* char* addr; */
{

	return (TRUE);
}

/*
 * XDR integers
 */
bool_t xdr_int(XDR* xdrs, int* ip)
{
	if (sizeof(int) == sizeof(long)) {
		return (xdr_long(xdrs, (long *) ip));
	} else if (sizeof(int) < sizeof(long)) {
	  long l;
	  switch (xdrs->x_op) {
	  case XDR_ENCODE:
		l = (long) *ip;
		return XDR_PUTLONG(xdrs, &l);
	  case XDR_DECODE:
		if (!XDR_GETLONG(xdrs, &l))
		  return FALSE;
		*ip = (int) l;
	  case XDR_FREE:
		return TRUE;
	  }
	  return FALSE;
	} else {
		return (xdr_short(xdrs, (short *) ip));
	}
}

/*
 * XDR unsigned integers
 */
bool_t xdr_u_int(XDR* xdrs, unsigned int* up)
{
	if (sizeof(unsigned int) == sizeof(unsigned long)) {
		return (xdr_u_long(xdrs, (unsigned long *) up));
	} else if (sizeof(unsigned int) < sizeof(unsigned long)) {
	  unsigned long l;
	  switch (xdrs->x_op) {
	  case XDR_ENCODE:
		l = (unsigned long) *up;
		return XDR_PUTLONG(xdrs, (long*)&l);
	  case XDR_DECODE:
		if (!XDR_GETLONG(xdrs, (long*)&l))
		  return FALSE;
		*up = (unsigned int) l;
	  case XDR_FREE:
		return TRUE;
	  }
	  return FALSE;
	} else {
		return (xdr_short(xdrs, (short *) up));
	}
}

/*
 * XDR long integers
 * same as xdr_u_long - open coded to save a proc call!
 */
bool_t xdr_long(XDR* xdrs, long* lp)
{

	if (xdrs->x_op == XDR_ENCODE
		&& (sizeof(int32_t) == sizeof(long)
			|| (int32_t) *lp == *lp))
		return (XDR_PUTLONG(xdrs, lp));

	if (xdrs->x_op == XDR_DECODE)
		return (XDR_GETLONG(xdrs, lp));

	if (xdrs->x_op == XDR_FREE)
		return (TRUE);

	return (FALSE);
}

/*
 * XDR unsigned long integers
 * same as xdr_long - open coded to save a proc call!
 */
bool_t xdr_u_long(XDR* xdrs, unsigned long* ulp)
{

  if (xdrs->x_op == XDR_DECODE) {
	long l;
	if (XDR_GETLONG(xdrs, &l) == FALSE)
	  return FALSE;
	*ulp = (uint32_t) l;
	return TRUE;
  }

  if (xdrs->x_op == XDR_ENCODE) {
	if (sizeof(uint32_t) != sizeof(unsigned long)
		&& (uint32_t) *ulp != *ulp)
	  return FALSE;

		return (XDR_PUTLONG(xdrs, (long *) ulp));
  }

	if (xdrs->x_op == XDR_FREE)
		return (TRUE);

	return (FALSE);
}

/*
 * XDR short integers
 */
bool_t xdr_short(XDR* xdrs, short* sp)
{
	long l;

	switch (xdrs->x_op) {

	case XDR_ENCODE:
		l = (long) *sp;
		return (XDR_PUTLONG(xdrs, &l));

	case XDR_DECODE:
		if (!XDR_GETLONG(xdrs, &l)) {
			return (FALSE);
		}
		*sp = (short) l;
		return (TRUE);

	case XDR_FREE:
		return (TRUE);
	}
	return (FALSE);
}

/*
 * XDR unsigned short integers
 */
bool_t xdr_u_short(XDR* xdrs, unsigned short* usp)
{
	unsigned long l;

	switch (xdrs->x_op) {

	case XDR_ENCODE:
		l = (unsigned long) * usp;
		return (XDR_PUTLONG(xdrs, (long*)&l));

	case XDR_DECODE:
		if (!XDR_GETLONG(xdrs, (long*)&l)) {
			return (FALSE);
		}
		*usp = (unsigned short) l;
		return (TRUE);

	case XDR_FREE:
		return (TRUE);
	}
	return (FALSE);
}


/*
 * XDR a char
 */
bool_t xdr_char(XDR* xdrs, char* cp)
{
	int i;

	i = (*cp);
	if (!xdr_int(xdrs, &i)) {
		return (FALSE);
	}
	*cp = i;
	return (TRUE);
}

/*
 * XDR an unsigned char
 */
bool_t xdr_u_char(XDR* xdrs, unsigned char* cp)
{
	unsigned int u;

	u = (*cp);
	if (!xdr_u_int(xdrs, &u)) {
		return (FALSE);
	}
	*cp = u;
	return (TRUE);
}

/*
 * XDR booleans
 */
bool_t xdr_bool(xdrs, bp)
register XDR *xdrs;
bool_t *bp;
{
	long lb;

	switch (xdrs->x_op) {

	case XDR_ENCODE:
		lb = *bp ? XDR_TRUE : XDR_FALSE;
		return (XDR_PUTLONG(xdrs, &lb));

	case XDR_DECODE:
		if (!XDR_GETLONG(xdrs, &lb)) {
			return (FALSE);
		}
		*bp = (lb == XDR_FALSE) ? FALSE : TRUE;
		return (TRUE);

	case XDR_FREE:
		return (TRUE);
	}
	return (FALSE);
}

/*
 * XDR enumerations
 */
bool_t xdr_enum(xdrs, ep)
XDR *xdrs;
enum_t *ep;
{
	enum sizecheck { SIZEVAL };	/* used to find the size of an enum */

	/*
	 * enums are treated as ints
	 */
	if (sizeof(enum sizecheck) == sizeof(long)) {
		return (xdr_long(xdrs, (long *) ep));
	} else if (sizeof(enum sizecheck) == sizeof(int)) {
	  long l;
	  switch (xdrs->x_op) {
	  case XDR_ENCODE:
		l = *ep;
		return XDR_PUTLONG(xdrs, &l);
	  case XDR_DECODE:
		if (!XDR_GETLONG(xdrs, &l))
		  return FALSE;
		*ep = l;
	  case XDR_FREE:
		return TRUE;
	  }
	  return FALSE;
	} else if (sizeof(enum sizecheck) == sizeof(short)) {
		return (xdr_short(xdrs, (short *) ep));
	} else {
		return (FALSE);
	}
}

/*
 * XDR opaque data
 * Allows the specification of a fixed size sequence of opaque bytes.
 * cp points to the opaque object and cnt gives the byte length.
 */
bool_t xdr_opaque(xdrs, cp, cnt)
register XDR *xdrs;
char* cp;
register unsigned int cnt;
{
	register unsigned int rndup;
	static char crud[BYTES_PER_XDR_UNIT];

	/*
	 * if no data we are done
	 */
	if (cnt == 0)
		return (TRUE);

	/*
	 * round byte count to full xdr units
	 */
	rndup = cnt % BYTES_PER_XDR_UNIT;
	if (rndup > 0)
		rndup = BYTES_PER_XDR_UNIT - rndup;

	if (xdrs->x_op == XDR_DECODE) {
		if (!XDR_GETBYTES(xdrs, cp, cnt)) {
			return (FALSE);
		}
		if (rndup == 0)
			return (TRUE);
		return (XDR_GETBYTES(xdrs, crud, rndup));
	}

	if (xdrs->x_op == XDR_ENCODE) {
		if (!XDR_PUTBYTES(xdrs, cp, cnt)) {
			return (FALSE);
		}
		if (rndup == 0)
			return (TRUE);
		return (XDR_PUTBYTES(xdrs, xdr_zero, rndup));
	}

	if (xdrs->x_op == XDR_FREE) {
		return (TRUE);
	}

	return (FALSE);
}

/*
 * XDR counted bytes
 * *cpp is a pointer to the bytes, *sizep is the count.
 * If *cpp is NULL maxsize bytes are allocated
 */
bool_t xdr_bytes(xdrs, cpp, sizep, maxsize)
register XDR *xdrs;
char **cpp;
register unsigned int *sizep;
unsigned int maxsize;
{
	register char *sp = *cpp;	/* sp is the actual string pointer */
	register unsigned int nodesize;

	/*
	 * first deal with the length since xdr bytes are counted
	 */
	if (!xdr_u_int(xdrs, sizep)) {
		return (FALSE);
	}
	nodesize = *sizep;
	if ((nodesize > maxsize) && (xdrs->x_op != XDR_FREE)) {
		return (FALSE);
	}

	/*
	 * now deal with the actual bytes
	 */
	switch (xdrs->x_op) {

	case XDR_DECODE:
		if (nodesize == 0) {
			return (TRUE);
		}
		if (sp == NULL) {
			*cpp = sp = (char *) mem_alloc(nodesize);
		}
		if (sp == NULL) {
			(void) fprintf(stderr, "xdr_bytes: out of memory\n");
			return (FALSE);
		}
		/* fall into ... */

	case XDR_ENCODE:
		return (xdr_opaque(xdrs, sp, nodesize));

	case XDR_FREE:
		if (sp != NULL) {
			mem_free(sp, nodesize);
			*cpp = NULL;
		}
		return (TRUE);
	}
	return (FALSE);
}

/*
 * Implemented here due to commonality of the object.
 */
bool_t xdr_netobj(xdrs, np)
XDR *xdrs;
struct netobj *np;
{

	return (xdr_bytes(xdrs, &np->n_bytes, &np->n_len, MAX_NETOBJ_SZ));
}

/*
 * XDR a descriminated union
 * Support routine for discriminated unions.
 * You create an array of xdrdiscrim structures, terminated with
 * an entry with a null procedure pointer.  The routine gets
 * the discriminant value and then searches the array of xdrdiscrims
 * looking for that value.  It calls the procedure given in the xdrdiscrim
 * to handle the discriminant.  If there is no specific routine a default
 * routine may be called.
 * If there is no specific or default routine an error is returned.
 */
bool_t xdr_union(XDR* xdrs, enum_t* dscmp, char* unp, const struct xdr_discrim* choices, xdrproc_t dfault)
{
	register enum_t dscm;

	/*
	 * we deal with the discriminator;  it's an enum
	 */
	if (!xdr_enum(xdrs, dscmp)) {
		return (FALSE);
	}
	dscm = *dscmp;

	/*
	 * search choices for a value that matches the discriminator.
	 * if we find one, execute the xdr routine for that value.
	 */
	for (; choices->proc != NULL_xdrproc_t; choices++) {
		if (choices->value == dscm)
			return ((*(choices->proc)) (xdrs, unp, LASTUNSIGNED));
	}

	/*
	 * no match - execute the default xdr routine if there is one
	 */
	return ((dfault == NULL_xdrproc_t) ? FALSE :
			(*dfault) (xdrs, unp, LASTUNSIGNED));
}


/*
 * Non-portable xdr primitives.
 * Care should be taken when moving these routines to new architectures.
 */


/*
 * XDR null terminated ASCII strings
 * xdr_string deals with "C strings" - arrays of bytes that are
 * terminated by a NULL character.  The parameter cpp references a
 * pointer to storage; If the pointer is null, then the necessary
 * storage is allocated.  The last parameter is the max allowed length
 * of the string as specified by a protocol.
 */
bool_t xdr_string(xdrs, cpp, maxsize)
register XDR *xdrs;
char **cpp;
unsigned int maxsize;
{
	register char *sp = *cpp;	/* sp is the actual string pointer */
	unsigned int size;
	unsigned int nodesize;

	/*
	 * first deal with the length since xdr strings are counted-strings
	 */
	switch (xdrs->x_op) {
	case XDR_FREE:
		if (sp == NULL) {
			return (TRUE);		/* already free */
		}
		/* fall through... */
	case XDR_ENCODE:
		size = strlen(sp);
		break;
	}
	if (!xdr_u_int(xdrs, &size)) {
		return (FALSE);
	}
	if (size > maxsize) {
		return (FALSE);
	}
	nodesize = size + 1;

	/*
	 * now deal with the actual bytes
	 */
	switch (xdrs->x_op) {

	case XDR_DECODE:
		if (nodesize == 0) {
			return (TRUE);
		}
		if (sp == NULL)
			*cpp = sp = (char *) mem_alloc(nodesize);
		if (sp == NULL) {
			(void) fprintf(stderr, "xdr_string: out of memory\n");
			return (FALSE);
		}
		sp[size] = 0;
		/* fall into ... */

	case XDR_ENCODE:
		return (xdr_opaque(xdrs, sp, size));

	case XDR_FREE:
		mem_free(sp, nodesize);
		*cpp = NULL;
		return (TRUE);
	}
	return (FALSE);
}

/* 
 * Wrapper for xdr_string that can be called directly from 
 * routines like clnt_call
 */
bool_t xdr_wrapstring(xdrs, cpp)
XDR *xdrs;
char **cpp;
{
	if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
		return (TRUE);
	}
	return (FALSE);
}
dietlibc-0.33~cvs20120325/librpc/xdr_array.c010064400000000000000000000107021173363227000153140ustar00/* @(#)xdr_array.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * xdr_array.c, Generic XDR routines impelmentation.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
 * arrays.  See xdr.h for more info on the interface to xdr.
 */

#include 

#include 
#include 
#include 

#define LASTUNSIGNED	((unsigned int)0-1)


/*
 * XDR an array of arbitrary elements
 * *addrp is a pointer to the array, *sizep is the number of elements.
 * If addrp is NULL (*sizep * elsize) bytes are allocated.
 * elsize is the size (in bytes) of each element, and elproc is the
 * xdr procedure to call to handle each element of the array.
 */
bool_t xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
register XDR *xdrs;
char* *addrp;					/* array pointer */
unsigned int *sizep;					/* number of elements */
unsigned int maxsize;					/* max numberof elements */
unsigned int elsize;					/* size in bytes of each element */
xdrproc_t elproc;				/* xdr routine to handle each element */
{
	register unsigned int i;
	register char* target = *addrp;
	register unsigned int c;			/* the actual element count */
	register bool_t stat = TRUE;
	register unsigned int nodesize;

	/* like strings, arrays are really counted arrays */
	if (!xdr_u_int(xdrs, sizep)) {
		return (FALSE);
	}
	c = *sizep;
	if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
		return (FALSE);
	}
	/* duh, look for integer overflow (fefe) */
	{
	  unsigned int i;
	  nodesize = 0;
	  for (i=c; i; --i) {
	    unsigned int tmp=nodesize+elsize;
	    if (tmpx_op) {
		case XDR_DECODE:
			if (c == 0)
				return (TRUE);
			*addrp = target = mem_alloc(nodesize);
			if (target == NULL) {
				(void) fprintf(stderr, "xdr_array: out of memory\n");
				return (FALSE);
			}
			memset(target, 0, nodesize);
			break;

		case XDR_FREE:
			return (TRUE);
		}

	/*
	 * now we xdr each element of array
	 */
	for (i = 0; (i < c) && stat; i++) {
		stat = (*elproc) (xdrs, target, LASTUNSIGNED);
		target += elsize;
	}

	/*
	 * the array may need freeing
	 */
	if (xdrs->x_op == XDR_FREE) {
		mem_free(*addrp, nodesize);
		*addrp = NULL;
	}
	return (stat);
}

/*
 * xdr_vector():
 *
 * XDR a fixed length array. Unlike variable-length arrays,
 * the storage of fixed length arrays is static and unfreeable.
 * > basep: base of the array
 * > size: size of the array
 * > elemsize: size of each element
 * > xdr_elem: routine to XDR each element
 */
bool_t xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
register XDR *xdrs;
register char *basep;
register unsigned int nelem;
register unsigned int elemsize;
register xdrproc_t xdr_elem;
{
	register unsigned int i;
	register char *elptr;

	elptr = basep;
	for (i = 0; i < nelem; i++) {
		if (!(*xdr_elem) (xdrs, elptr, LASTUNSIGNED)) {
			return (FALSE);
		}
		elptr += elemsize;
	}
	return (TRUE);
}
dietlibc-0.33~cvs20120325/librpc/xdr_float.c010064400000000000000000000155061173363227000153120ustar00/* @(#)xdr_float.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * xdr_float.c, Generic XDR routines impelmentation.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * These are the "floating point" xdr routines used to (de)serialize
 * most common data items.  See xdr.h for more info on the interface to
 * xdr.
 */

#include 

#include 
#include 

/*
 * NB: Not portable.
 * This routine works on Suns (Sky / 68000's) and Vaxen.
 */

#if defined(__linux__) && !defined(sparc)
/* cheat big time */
#define sparc
#endif

#ifdef vax

/* What IEEE single precision floating point looks like on a Vax */
struct ieee_single {
	unsigned int mantissa:23;
	unsigned int exp:8;
	unsigned int sign:1;
};

/* Vax single precision floating point */
struct vax_single {
	unsigned int mantissa1:7;
	unsigned int exp:8;
	unsigned int sign:1;
	unsigned int mantissa2:16;
};

#define VAX_SNG_BIAS	0x81
#define IEEE_SNG_BIAS	0x7f

static struct sgl_limits {
	struct vax_single s;
	struct ieee_single ieee;
} sgl_limits[2] = {
	{ {
	0x7f, 0xff, 0x0, 0xffff},	/* Max Vax */
	{
	0x0, 0xff, 0x0}},			/* Max IEEE */
	{ {
	0x0, 0x0, 0x0, 0x0},		/* Min Vax */
	{
	0x0, 0x0, 0x0}}				/* Min IEEE */
};
#endif							/* vax */

bool_t xdr_float(xdrs, fp)
register XDR *xdrs;
register float *fp;
{
#if !defined(mc68000) && !defined(sparc)
	struct ieee_single is;
	struct vax_single vs, *vsp;
	struct sgl_limits *lim;
	int i;
#endif
	switch (xdrs->x_op) {

	case XDR_ENCODE:
#if defined(mc68000) || defined(sparc)
		return (XDR_PUTLONG(xdrs, (long *) fp));
#else
		vs = *((struct vax_single *) fp);
		for (i = 0, lim = sgl_limits;

			 i < sizeof(sgl_limits) / sizeof(struct sgl_limits);
			 i++, lim++) {
			if ((vs.mantissa2 == lim->s.mantissa2) &&
				(vs.exp == lim->s.exp) &&
				(vs.mantissa1 == lim->s.mantissa1)) {
				is = lim->ieee;
				goto shipit;
			}
		}
		is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
		is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
	  shipit:
		is.sign = vs.sign;
		return (XDR_PUTLONG(xdrs, (long *) &is));
#endif

	case XDR_DECODE:
#if defined(mc68000) || defined(sparc)
		return (XDR_GETLONG(xdrs, (long *) fp));
#else
		vsp = (struct vax_single *) fp;
		if (!XDR_GETLONG(xdrs, (long *) &is))
			return (FALSE);
		for (i = 0, lim = sgl_limits;

			 i < sizeof(sgl_limits) / sizeof(struct sgl_limits);
			 i++, lim++) {
			if ((is.exp == lim->ieee.exp) &&
				(is.mantissa == lim->ieee.mantissa)) {
				*vsp = lim->s;
				goto doneit;
			}
		}
		vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS;
		vsp->mantissa2 = is.mantissa;
		vsp->mantissa1 = (is.mantissa >> 16);
	  doneit:
		vsp->sign = is.sign;
		return (TRUE);
#endif

	case XDR_FREE:
		return (TRUE);
	}
	return (FALSE);
}

/*
 * This routine works on Suns (Sky / 68000's) and Vaxen.
 */

#ifdef vax
/* What IEEE double precision floating point looks like on a Vax */
struct ieee_double {
	unsigned int mantissa1:20;
	unsigned int exp:11;
	unsigned int sign:1;
	unsigned int mantissa2:32;
};

/* Vax double precision floating point */
struct vax_double {
	unsigned int mantissa1:7;
	unsigned int exp:8;
	unsigned int sign:1;
	unsigned int mantissa2:16;
	unsigned int mantissa3:16;
	unsigned int mantissa4:16;
};

#define VAX_DBL_BIAS	0x81
#define IEEE_DBL_BIAS	0x3ff
#define MASK(nbits)	((1 << nbits) - 1)

static struct dbl_limits {
	struct vax_double d;
	struct ieee_double ieee;
} dbl_limits[2] = {
	{ {
	0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff},	/* Max Vax */
	{
	0x0, 0x7ff, 0x0, 0x0}},		/* Max IEEE */
	{ {
	0x0, 0x0, 0x0, 0x0, 0x0, 0x0},	/* Min Vax */
	{
	0x0, 0x0, 0x0, 0x0}}		/* Min IEEE */
};

#endif							/* vax */


bool_t xdr_double(xdrs, dp)
register XDR *xdrs;
double *dp;
{
	register long *lp;

#if !defined(mc68000) && !defined(sparc)
	struct ieee_double id;
	struct vax_double vd;
	register struct dbl_limits *lim;
	int i;
#endif

	switch (xdrs->x_op) {

	case XDR_ENCODE:
#if defined(mc68000) || defined(sparc)
		lp = (long *) dp;
#else
		vd = *((struct vax_double *) dp);
		for (i = 0, lim = dbl_limits;

			 i < sizeof(dbl_limits) / sizeof(struct dbl_limits);
			 i++, lim++) {
			if ((vd.mantissa4 == lim->d.mantissa4) &&
				(vd.mantissa3 == lim->d.mantissa3) &&
				(vd.mantissa2 == lim->d.mantissa2) &&
				(vd.mantissa1 == lim->d.mantissa1) &&
				(vd.exp == lim->d.exp)) {
				id = lim->ieee;
				goto shipit;
			}
		}
		id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
		id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3);
		id.mantissa2 = ((vd.mantissa2 & MASK(3)) << 29) |
			(vd.mantissa3 << 13) | ((vd.mantissa4 >> 3) & MASK(13));
	  shipit:
		id.sign = vd.sign;
		lp = (long *) &id;
#endif
		return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));

	case XDR_DECODE:
#if defined(mc68000) || defined(sparc)
		lp = (long *) dp;
		return (XDR_GETLONG(xdrs, lp++) && XDR_GETLONG(xdrs, lp));
#else
		lp = (long *) &id;
		if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))
			return (FALSE);
		for (i = 0, lim = dbl_limits;

			 i < sizeof(dbl_limits) / sizeof(struct dbl_limits);
			 i++, lim++) {
			if ((id.mantissa2 == lim->ieee.mantissa2) &&
				(id.mantissa1 == lim->ieee.mantissa1) &&
				(id.exp == lim->ieee.exp)) {
				vd = lim->d;
				goto doneit;
			}
		}
		vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
		vd.mantissa1 = (id.mantissa1 >> 13);
		vd.mantissa2 = ((id.mantissa1 & MASK(13)) << 3) |
			(id.mantissa2 >> 29);
		vd.mantissa3 = (id.mantissa2 >> 13);
		vd.mantissa4 = (id.mantissa2 << 3);
	  doneit:
		vd.sign = id.sign;
		*dp = *((double *) &vd);
		return (TRUE);
#endif

	case XDR_FREE:
		return (TRUE);
	}
	return (FALSE);
}
dietlibc-0.33~cvs20120325/librpc/xdr_mem.c010064400000000000000000000105601173363227000147560ustar00/* @(#)xdr_mem.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * xdr_mem.h, XDR implementation using memory buffers.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * If you have some data to be interpreted as external data representation
 * or to be converted to external data representation in a memory buffer,
 * then this is the package for you.
 *
 */

#include 
#include 
#include 
#include 
#include 

static bool_t xdrmem_getlong (XDR *, long *);
static bool_t xdrmem_putlong (XDR *, const long *);
static bool_t xdrmem_getbytes (XDR *, char *, unsigned int);
static bool_t xdrmem_putbytes (XDR *, const char *, unsigned int);
static unsigned int xdrmem_getpos (const XDR *);
static bool_t xdrmem_setpos (XDR *, unsigned int);
static int32_t *xdrmem_inline (XDR *, unsigned int);
static void xdrmem_destroy (XDR *);

static struct xdr_ops xdrmem_ops = {
	xdrmem_getlong,
	xdrmem_putlong,
	xdrmem_getbytes,
	xdrmem_putbytes,
	xdrmem_getpos,
	xdrmem_setpos,
	xdrmem_inline,
	xdrmem_destroy,
	NULL,
	NULL
};


/*
 * The procedure xdrmem_create initializes a stream descriptor for a
 * memory buffer.  
 */
void
xdrmem_create (XDR *xdrs, const char* addr, unsigned int size, enum xdr_op op)
{
	xdrs->x_op = op;
	xdrs->x_ops = &xdrmem_ops;
	xdrs->x_private = xdrs->x_base = (char*)addr;
	xdrs->x_handy = size;
}

static void
xdrmem_destroy (XDR *xdrs)
{
}

static bool_t
xdrmem_getlong (XDR *xdrs, long *lp)
{
  if (xdrs->x_handy < 4) return FALSE;
  xdrs->x_handy -= 4;

  *lp = (int32_t) ntohl((*((int32_t *) (xdrs->x_private))));
  xdrs->x_private += 4;
  return TRUE;
}

static bool_t
xdrmem_putlong (XDR *xdrs, const long *lp)
{
  if (xdrs->x_handy < 4) return FALSE;
  xdrs->x_handy -= 4;

  *(int32_t *) xdrs->x_private = htonl(*lp);
  xdrs->x_private += 4;
  return (TRUE);
}

static bool_t
xdrmem_getbytes (XDR *xdrs, char *addr, unsigned int len)
{
  if (xdrs->x_handy < len) return FALSE;
  xdrs->x_handy -= len;
  memmove(addr, xdrs->x_private, len);
  xdrs->x_private += len;
  return TRUE;
}

static bool_t
xdrmem_putbytes (XDR *xdrs, const char *addr, unsigned int len)
{
  if (xdrs->x_handy < len) return FALSE;
  xdrs->x_handy -= len;
  memmove(xdrs->x_private, addr, len);
  xdrs->x_private += len;
  return (TRUE);
}

static unsigned int xdrmem_getpos (const XDR *xdrs)
{
	return ((unsigned long) xdrs->x_private - (unsigned long) xdrs->x_base);
}

static bool_t xdrmem_setpos(xdrs, pos)
register XDR *xdrs;
unsigned int pos;
{
  register char* newaddr = xdrs->x_base + pos;
  register char* lastaddr = xdrs->x_private + xdrs->x_handy;

  if ((long) newaddr > (long) lastaddr
	  || (UINT_MAX < LONG_MAX
		  && (long) UINT_MAX < (long) lastaddr - (long) newaddr))
	  return (FALSE);
  xdrs->x_private = newaddr;
  xdrs->x_handy = (long) lastaddr - (long) newaddr;
  return (TRUE);
}

static int32_t *
xdrmem_inline (XDR *xdrs, unsigned int len)
{
	int32_t *buf = 0;

	if (xdrs->x_handy >= len) {
		xdrs->x_handy -= len;
		buf = (int32_t *) xdrs->x_private;
		xdrs->x_private += len;
	}
	return (buf);
}

dietlibc-0.33~cvs20120325/librpc/xdr_rec.c010064400000000000000000000372241173363227000147570ustar00/* @(#)xdr_rec.c	2.2 88/08/01 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
 * layer above tcp (for rpc's use).
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * These routines interface XDRSTREAMS to a tcp/ip connection.
 * There is a record marking layer between the xdr stream
 * and the tcp transport level.  A record is composed on one or more
 * record fragments.  A record fragment is a thirty-two bit header followed
 * by n bytes of data, where n is contained in the header.  The header
 * is represented as a htonl(unsigned long).  Thegh order bit encodes
 * whether or not the fragment is the last fragment of the record
 * (1 => fragment is last, 0 => more fragments to follow. 
 * The other 31 bits encode the byte length of the fragment.
 */

#include 
#include 
#include 
#include 
#include 
#include 

static unsigned int fix_buf_size (unsigned int);

static bool_t xdrrec_getlong (XDR *, long *);
static bool_t xdrrec_putlong (XDR *, const long *);
static bool_t xdrrec_getbytes (XDR *, char *, unsigned int);
static bool_t xdrrec_putbytes (XDR *, const char *, unsigned int);
static unsigned int xdrrec_getpos (const XDR *);
static bool_t xdrrec_setpos (XDR *, unsigned int);
static int32_t *xdrrec_inline (XDR *, unsigned int);
static void xdrrec_destroy (XDR *);

static struct xdr_ops xdrrec_ops = {
	xdrrec_getlong,
	xdrrec_putlong,
	xdrrec_getbytes,
	xdrrec_putbytes,
	xdrrec_getpos,
	xdrrec_setpos,
	xdrrec_inline,
	xdrrec_destroy,
	NULL,
	NULL
};


/*
 * A record is composed of one or more record fragments.
 * A record fragment is a two-byte header followed by zero to
 * 2**32-1 bytes.  The header is treated as a long unsigned and is
 * encode/decoded to the network via htonl/ntohl.  The low order 31 bits
 * are a byte count of the fragment.  The highest order bit is a boolean:
 * 1 => this fragment is the last fragment of the record,
 * 0 => this fragment is followed by more fragment(s).
 *
 * The fragment/record machinery is not general;  it is constructed to
 * meet the needs of xdr and rpc based on tcp.
 */

#define LAST_FRAG ((unsigned long)(1 << 31))

typedef struct rec_strm {
	char* tcp_handle;
	char* the_buffer;
	/*
	 * out-goung bits
	 */
    int (*writeit) (char *, char *, int);
	char* out_base;			/* output buffer (points to frag header) */
	char* out_finger;			/* next output position */
	char* out_boundry;		/* data cannot up to this address */
	uint32_t *frag_header;		/* beginning of curren fragment */
	bool_t frag_sent;			/* true if buffer sent in middle of record */
	/*
	 * in-coming bits
	 */
    int (*readit) (char *, char *, int);
	unsigned long in_size;				/* fixed size of the input buffer */
	char* in_base;
	char* in_finger;			/* location of next byte to be had */
	char* in_boundry;			/* can read up to this location */
	long fbtbc;					/* fragment bytes to be consumed */
	bool_t last_frag;
	unsigned int sendsize;
	unsigned int recvsize;
} RECSTREAM;


/*
 * Create an xdr handle for xdrrec
 * xdrrec_create fills in xdrs.  Sendsize and recvsize are
 * send and recv buffer sizes (0 => use default).
 * tcp_handle is an opaque handle that is passed as the first parameter to
 * the procedures readit and writeit.  Readit and writeit are read and
 * write respectively.   They are like the system
 * calls expect that they take an opaque handle rather than an fd.
 */
void
xdrrec_create (XDR *xdrs, unsigned int sendsize,
	       unsigned int recvsize, char *tcp_handle,
	       int (*readit) (char *, char *, int),
	       int (*writeit) (char *, char *, int))
{
	register RECSTREAM *rstrm = (RECSTREAM *) mem_alloc(sizeof(RECSTREAM));

	if (rstrm == NULL) {
		(void) fprintf(stderr, "xdrrec_create: out of memory\n");
		/* 
		 *  This is bad.  Should rework xdrrec_create to 
		 *  return a handle, and in this case return NULL
		 */
		return;
	}
	/*
	 * adjust sizes and allocate buffer quad byte aligned
	 */
	rstrm->sendsize = sendsize = fix_buf_size(sendsize);
	rstrm->recvsize = recvsize = fix_buf_size(recvsize);
	rstrm->the_buffer =
		mem_alloc(sendsize + recvsize + BYTES_PER_XDR_UNIT);
	if (rstrm->the_buffer == NULL) {
		(void) fprintf(stderr, "xdrrec_create: out of memory\n");
		return;
	}
	for (rstrm->out_base = rstrm->the_buffer;
		 (unsigned long) rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
		 rstrm->out_base++);
	rstrm->in_base = rstrm->out_base + sendsize;
	/*
	 * now the rest ...
	 */
	xdrs->x_ops = &xdrrec_ops;
	xdrs->x_private = (char*) rstrm;
	rstrm->tcp_handle = tcp_handle;
	rstrm->readit = readit;
	rstrm->writeit = writeit;
	rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
	rstrm->frag_header = (uint32_t *) rstrm->out_base;
	rstrm->out_finger += 4;
	rstrm->out_boundry += sendsize;
	rstrm->frag_sent = FALSE;
	rstrm->in_size = recvsize;
	rstrm->in_boundry = rstrm->in_base;
	rstrm->in_finger = (rstrm->in_boundry += recvsize);
	rstrm->fbtbc = 0;
	rstrm->last_frag = TRUE;
}


/*
 * The reoutines defined below are the xdr ops which will go into the
 * xdr handle filled in by xdrrec_create.
 */

static bool_t
xdrrec_getlong (XDR *xdrs, long *lp)
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
	register int32_t *buflp = (int32_t *) (rstrm->in_finger);
	int32_t mylong;

	/* first try the inline, fast case */
	if ((rstrm->fbtbc >= BYTES_PER_XDR_UNIT) &&
		((rstrm->in_boundry - (char *) buflp) >= BYTES_PER_XDR_UNIT)) {
		*lp = (int32_t) ntohl(*buflp);
		rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
		rstrm->in_finger += BYTES_PER_XDR_UNIT;
	} else {
		if (!xdrrec_getbytes(xdrs, (char*) & mylong, BYTES_PER_XDR_UNIT))
			return (FALSE);

		*lp = (int32_t) ntohl(mylong);
	}
	return (TRUE);
}

/*
 * Internal useful routines
 */
static bool_t flush_out(RECSTREAM* rstrm, bool_t eor)
{
	register unsigned long eormask = (eor == TRUE) ? LAST_FRAG : 0;
	register unsigned long len = (rstrm->out_finger
								  - (char *) rstrm->frag_header
								  - BYTES_PER_XDR_UNIT);

	*(rstrm->frag_header) = htonl(len | eormask);
	len = rstrm->out_finger - rstrm->out_base;
	if ((*(rstrm->writeit)) (rstrm->tcp_handle, rstrm->out_base, (int) len)
		!= (int) len)
		return (FALSE);
	rstrm->frag_header = (uint32_t *) rstrm->out_base;
	rstrm->out_finger = (char*) rstrm->out_base + BYTES_PER_XDR_UNIT;
	return (TRUE);
}

static bool_t
/* knows nothing about records!  Only about input buffers */
fill_input_buf(rstrm)
register RECSTREAM *rstrm;
{
	register char* where;
	unsigned int i;
	register int len;

	where = rstrm->in_base;
	i = (unsigned long) rstrm->in_boundry % BYTES_PER_XDR_UNIT;
	where += i;
	len = rstrm->in_size - i;
	if ((len = (*(rstrm->readit)) (rstrm->tcp_handle, where, len)) == -1)
		return (FALSE);
	rstrm->in_finger = where;
	where += len;
	rstrm->in_boundry = where;
	return (TRUE);
}

static bool_t
/* knows nothing about records!  Only about input buffers */
get_input_bytes(rstrm, addr, len)
register RECSTREAM *rstrm;
register char* addr;
register int len;
{
	register int current;

	while (len > 0) {
		current = rstrm->in_boundry - rstrm->in_finger;
		if (current == 0) {
			if (!fill_input_buf(rstrm))
				return (FALSE);
			continue;
		}
		current = (len < current) ? len : current;
		memmove(addr, rstrm->in_finger, current);
		rstrm->in_finger += current;
		addr += current;
		len -= current;
	}
	return (TRUE);
}

static bool_t
/* next two bytes of the input stream are treated as a header */
set_input_fragment(rstrm)
register RECSTREAM *rstrm;
{
	uint32_t header;

	if (!get_input_bytes(rstrm, (char*) & header, sizeof(header)))
		return (FALSE);
	header = ntohl(header);
	rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
	/*
	 * Sanity check. Try not to accept wildly incorrect fragment
	 * sizes. Unfortunately, only a size of zero can be identified as
	 * 'wildely incorrect', and this only, if it is not the last
	 * fragment of a message. Ridiculously large fragment sizes may look
	 * wrong, but we don't have any way to be certain that they aren't
	 * what the client actually intended to send us. Many existing RPC
	 * implementations may sent a fragment of size zero as the last
	 * fragment of a message.
	 */
	if (header == 0)
	  return FALSE;
	rstrm->fbtbc = header & (~LAST_FRAG);
	return (TRUE);
}

static bool_t
/* consumes input bytes; knows nothing about records! */
skip_input_bytes(rstrm, cnt)
register RECSTREAM *rstrm;
long cnt;
{
	register int current;

	while (cnt > 0) {
		current = rstrm->in_boundry - rstrm->in_finger;
		if (current == 0) {
			if (!fill_input_buf(rstrm))
				return (FALSE);
			continue;
		}
		current = (cnt < current) ? cnt : current;
		rstrm->in_finger += current;
		cnt -= current;
	}
	return (TRUE);
}

static unsigned int
fix_buf_size (unsigned int s)
{

	if (s < 100)
		s = 4000;
	return (RNDUP(s));
}

static bool_t
xdrrec_putlong (XDR *xdrs, const long *lp)
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
	register int32_t *dest_lp = (int32_t *) rstrm->out_finger;

	if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry) {
		/*
		 * this case should almost never happen so the code is
		 * inefficient
		 */
		rstrm->out_finger -= BYTES_PER_XDR_UNIT;

		rstrm->frag_sent = TRUE;
		if (!flush_out(rstrm, FALSE))
			return (FALSE);
		dest_lp = ((int32_t *) (rstrm->out_finger));
		rstrm->out_finger += BYTES_PER_XDR_UNIT;
	}
	*dest_lp = htonl(*lp);
	return (TRUE);
}

static bool_t	   /* must manage buffers, fragments, and records */
xdrrec_getbytes (XDR *xdrs, char *addr, unsigned int len)
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
	register unsigned int current;

	while (len > 0) {
		current = rstrm->fbtbc;
		if (current == 0) {
			if (rstrm->last_frag)
				return (FALSE);
			if (!set_input_fragment(rstrm))
				return (FALSE);
			continue;
		}
		current = (len < current) ? len : current;
		if (!get_input_bytes(rstrm, addr, current))
			return (FALSE);
		addr += current;
		rstrm->fbtbc -= current;
		len -= current;
	}
	return (TRUE);
}

static bool_t
xdrrec_putbytes (XDR *xdrs, const char *addr, unsigned int len)
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
	register unsigned int current;

	while (len > 0) {
		current = rstrm->out_boundry - rstrm->out_finger;
		current = (len < current) ? len : current;
		memmove(rstrm->out_finger, addr, current);
		rstrm->out_finger += current;
		addr += current;
		len -= current;
		if (rstrm->out_finger == rstrm->out_boundry) {
			rstrm->frag_sent = TRUE;
			if (!flush_out(rstrm, FALSE))
				return (FALSE);
		}
	}
	return (TRUE);
}

static unsigned int
xdrrec_getpos (const XDR *xdrs)
{
	register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
	register long pos;

	pos = lseek((int)((long) rstrm->tcp_handle), (long) 0, 1);
	if (pos != -1)
		switch (xdrs->x_op) {

		case XDR_ENCODE:
			pos += rstrm->out_finger - rstrm->out_base;
			break;

		case XDR_DECODE:
			pos -= rstrm->in_boundry - rstrm->in_finger;
			break;

		default:
			pos = (unsigned int) - 1;
			break;
		}
	return ((unsigned int) pos);
}

static bool_t
xdrrec_setpos (XDR *xdrs, unsigned int pos)
{
	register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
	unsigned int currpos = xdrrec_getpos(xdrs);
	int delta = currpos - pos;
	char* newpos;

	if ((int) currpos != -1)
		switch (xdrs->x_op) {

		case XDR_ENCODE:
			newpos = rstrm->out_finger - delta;
			if ((newpos > (char*) (rstrm->frag_header)) &&
				(newpos < rstrm->out_boundry)) {
				rstrm->out_finger = newpos;
				return (TRUE);
			}
			break;

		case XDR_DECODE:
			newpos = rstrm->in_finger - delta;
			if ((delta < (int) (rstrm->fbtbc)) &&
				(newpos <= rstrm->in_boundry) &&
				(newpos >= rstrm->in_base)) {
				rstrm->in_finger = newpos;
				rstrm->fbtbc -= delta;
				return (TRUE);
			}
			break;
		}
	return (FALSE);
}

static int32_t *xdrrec_inline(XDR* xdrs, unsigned int len)
{
	register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
	int32_t *buf = NULL;

	switch (xdrs->x_op) {

	case XDR_ENCODE:
		if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
			buf = (int32_t *) rstrm->out_finger;
			rstrm->out_finger += len;
		}
		break;

	case XDR_DECODE:
		if (((long)len <= rstrm->fbtbc) &&
			((rstrm->in_finger + len) <= rstrm->in_boundry)) {
			buf = (int32_t *) rstrm->in_finger;
			rstrm->fbtbc -= len;
			rstrm->in_finger += len;
		}
		break;
	}
	return (buf);
}

static void
xdrrec_destroy (XDR *xdrs)
{
	register RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;

	mem_free(rstrm->the_buffer,
			 rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
	mem_free((char*) rstrm, sizeof(RECSTREAM));
}


/*
 * Exported routines to manage xdr records
 */

/*
 * Before reading (deserializing from the stream, one should always call
 * this procedure to guarantee proper record alignment.
 */
bool_t xdrrec_skiprecord(xdrs)
XDR *xdrs;
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);

	while (rstrm->fbtbc > 0 || (!rstrm->last_frag)) {
		if (!skip_input_bytes(rstrm, rstrm->fbtbc))
			return (FALSE);
		rstrm->fbtbc = 0;
		if ((!rstrm->last_frag) && (!set_input_fragment(rstrm)))
			return (FALSE);
	}
	rstrm->last_frag = FALSE;
	return (TRUE);
}

/*
 * Look ahead fuction.
 * Returns TRUE iff there is no more input in the buffer 
 * after consuming the rest of the current record.
 */
bool_t xdrrec_eof(xdrs)
XDR *xdrs;
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);

	while (rstrm->fbtbc > 0 || (!rstrm->last_frag)) {
		if (!skip_input_bytes(rstrm, rstrm->fbtbc))
			return (TRUE);
		rstrm->fbtbc = 0;
		if ((!rstrm->last_frag) && (!set_input_fragment(rstrm)))
			return (TRUE);
	}
	if (rstrm->in_finger == rstrm->in_boundry)
		return (TRUE);
	return (FALSE);
}

/*
 * The client must tell the package when an end-of-record has occurred.
 * The second paraemters tells whether the record should be flushed to the
 * (output) tcp stream.  (This let's the package support batched or
 * pipelined procedure calls.)  TRUE => immmediate flush to tcp connection.
 */
bool_t xdrrec_endofrecord(xdrs, sendnow)
XDR *xdrs;
bool_t sendnow;
{
	register RECSTREAM *rstrm = (RECSTREAM *) (xdrs->x_private);
	register unsigned long len;		/* fragment length */

	if (sendnow || rstrm->frag_sent ||
		(rstrm->out_finger + BYTES_PER_XDR_UNIT >= rstrm->out_boundry)) {
		rstrm->frag_sent = FALSE;
		return (flush_out(rstrm, TRUE));
	}
	len = rstrm->out_finger - (char *)rstrm->frag_header -
		BYTES_PER_XDR_UNIT;
	*(rstrm->frag_header) = htonl((unsigned long) len | LAST_FRAG);
	rstrm->frag_header = (uint32_t *) rstrm->out_finger;
	rstrm->out_finger += BYTES_PER_XDR_UNIT;
	return (TRUE);
}

dietlibc-0.33~cvs20120325/librpc/xdr_reference.c010064400000000000000000000072251173363227000161420ustar00/* @(#)xdr_reference.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] = "@(#)xdr_reference.c 1.11 87/08/11 SMI";
#endif

/*
 * xdr_reference.c, Generic XDR routines impelmentation.
 *
 * Copyright (C) 1987, Sun Microsystems, Inc.
 *
 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
 * "pointers".  See xdr.h for more info on the interface to xdr.
 */

#include 
#include 
#include 
#include 

#define LASTUNSIGNED	((unsigned int)0-1)

/*
 * XDR an indirect pointer
 * xdr_reference is for recursively translating a structure that is
 * referenced by a pointer inside the structure that is currently being
 * translated.  pp references a pointer to storage. If *pp is null
 * the  necessary storage is allocated.
 * size is the sizeof the referneced structure.
 * proc is the routine to handle the referenced structure.
 */
bool_t xdr_reference(xdrs, pp, size, proc)
register XDR *xdrs;
char* *pp;					/* the pointer to work on */
unsigned int size;						/* size of the object pointed to */
xdrproc_t proc;					/* xdr routine to handle the object */
{
	register char* loc = *pp;
	register bool_t stat;

	if (loc == NULL)
		switch (xdrs->x_op) {
		case XDR_FREE:
			return (TRUE);

		case XDR_DECODE:
			*pp = loc = (char*) mem_alloc(size);
			if (loc == NULL) {
				(void) fprintf(stderr, "xdr_reference: out of memory\n");
				return (FALSE);
			}
			memset(loc, 0, (int) size);
			break;
		}

	stat = (*proc) (xdrs, loc, LASTUNSIGNED);

	if (xdrs->x_op == XDR_FREE) {
		mem_free(loc, size);
		*pp = NULL;
	}
	return (stat);
}


/*
 * xdr_pointer():
 *
 * XDR a pointer to a possibly recursive data structure. This
 * differs with xdr_reference in that it can serialize/deserialiaze
 * trees correctly.
 *
 *  What's sent is actually a union:
 *
 *  union object_pointer switch (boolean b) {
 *  case TRUE: object_data data;
 *  case FALSE: void nothing;
 *  }
 *
 * > objpp: Pointer to the pointer to the object.
 * > obj_size: size of the object.
 * > xdr_obj: routine to XDR an object.
 *
 */
bool_t xdr_pointer(xdrs, objpp, obj_size, xdr_obj)
register XDR *xdrs;
char **objpp;
unsigned int obj_size;
xdrproc_t xdr_obj;
{

	bool_t more_data;

	more_data = (*objpp != NULL);
	if (!xdr_bool(xdrs, &more_data)) {
		return (FALSE);
	}
	if (!more_data) {
		*objpp = NULL;
		return (TRUE);
	}
	return (xdr_reference(xdrs, objpp, obj_size, xdr_obj));
}
dietlibc-0.33~cvs20120325/librpc/xdr_stdio.c010064400000000000000000000116631173363227000153270ustar00/* @(#)xdr_stdio.c	2.1 88/07/29 4.0 RPCSRC */
/*
 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
 * unrestricted use provided that this legend is included on all tape
 * media and as a part of the software program in whole or part.  Users
 * may copy or modify Sun RPC without charge, but are not authorized
 * to license or distribute it to anyone else except as part of a product or
 * program developed by the user.
 * 
 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
 * 
 * Sun RPC is provided with no support and without any obligation on the
 * part of Sun Microsystems, Inc. to assist in its use, correction,
 * modification or enhancement.
 * 
 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
 * OR ANY PART THEREOF.
 * 
 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
 * or profits or other special, indirect and consequential damages, even if
 * Sun has been advised of the possibility of such damages.
 * 
 * Sun Microsystems, Inc.
 * 2550 Garcia Avenue
 * Mountain View, California  94043
 */
#if !defined(lint) && defined(SCCSIDS)
static char sccsid[] =

	"@(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";
#endif

/*
 * xdr_stdio.c, XDR implementation on standard i/o file.
 *
 * Copyright (C) 1984, Sun Microsystems, Inc.
 *
 * This set of routines implements a XDR on a stdio stream.
 * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes
 * from the stream.
 */

#include 
#include 
#include 

static bool_t xdrstdio_getlong(XDR *xdrs, register long *lp);
static bool_t xdrstdio_putlong(XDR *xdrs, const long *lp);
static bool_t xdrstdio_getbytes(XDR *xdrs, char* addr, unsigned int len);
static bool_t xdrstdio_putbytes(XDR *xdrs, const char* addr, unsigned int len);
static unsigned int xdrstdio_getpos(const XDR *xdrs);
static bool_t xdrstdio_setpos(XDR *xdrs, unsigned int pos);
static int32_t *xdrstdio_inline(XDR* xdrs, unsigned int len);
static void xdrstdio_destroy(register XDR *xdrs);

/*
 * Ops vector for stdio type XDR
 */
static struct xdr_ops xdrstdio_ops = {
	xdrstdio_getlong,			/* deseraialize a long int */
	xdrstdio_putlong,			/* seraialize a long int */
	xdrstdio_getbytes,			/* deserialize counted bytes */
	xdrstdio_putbytes,			/* serialize counted bytes */
	xdrstdio_getpos,			/* get offset in the stream */
	xdrstdio_setpos,			/* set offset in the stream */
	xdrstdio_inline,			/* prime stream for inline macros */
	xdrstdio_destroy,			/* destroy stream */
	NULL,
	NULL
};


/*
 * Initialize a stdio xdr stream.
 * Sets the xdr stream handle xdrs for use on the stream file.
 * Operation flag is set to op.
 */
void xdrstdio_create(xdrs, file, op)
register XDR *xdrs;
FILE *file;
enum xdr_op op;
{

	xdrs->x_op = op;
	xdrs->x_ops = &xdrstdio_ops;
	xdrs->x_private = (char*) file;
	xdrs->x_handy = 0;
	xdrs->x_base = 0;
}

/*
 * Destroy a stdio xdr stream.
 * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
 */
static void xdrstdio_destroy(xdrs)
register XDR *xdrs;
{
	(void) fflush((FILE *) xdrs->x_private);
	/* xx should we close the file ?? */
};

static bool_t xdrstdio_getlong(xdrs, lp)
XDR *xdrs;
register long *lp;
{

	if (fread((char*) lp, sizeof(long), 1, (FILE *) xdrs->x_private) !=
		1) return (FALSE);

#ifndef mc68000
	*lp = ntohl(*lp);
#endif
	return (TRUE);
}

static bool_t xdrstdio_putlong(xdrs, lp)
XDR *xdrs;
const long *lp;
{

#ifndef mc68000
	long mycopy = htonl(*lp);

	lp = &mycopy;
#endif
	if (fwrite((char*) lp, sizeof(long), 1, (FILE *) xdrs->x_private) !=
		1) return (FALSE);

	return (TRUE);
}

static bool_t xdrstdio_getbytes(xdrs, addr, len)
XDR *xdrs;
char* addr;
unsigned int len;
{

	if ((len != 0)
		&& (fread(addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
		return (FALSE);
	return (TRUE);
}

static bool_t xdrstdio_putbytes(xdrs, addr, len)
XDR *xdrs;
const char* addr;
unsigned int len;
{

	if ((len != 0)
		&& (fwrite(addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
		return (FALSE);
	return (TRUE);
}

static unsigned int xdrstdio_getpos(xdrs)
const XDR *xdrs;
{

	return ((unsigned int) ftell((FILE *) xdrs->x_private));
}

static bool_t xdrstdio_setpos(xdrs, pos)
XDR *xdrs;
unsigned int pos;
{

	return ((fseek((FILE *) xdrs->x_private, (long) pos, 0) < 0) ?
			FALSE : TRUE);
}

static int32_t *xdrstdio_inline(XDR* xdrs, unsigned int len)
{

	/*
	 * Must do some work to implement this: must insure
	 * enough data in the underlying stdio buffer,
	 * that the buffer is aligned so that we can indirect through a
	 * long *, and stuff this pointer in xdrs->x_buf.  Doing
	 * a fread or fwrite to a scratch buffer would defeat
	 * most of the gains to be had here and require storage
	 * management on this buffer, so we don't do this.
	 */
	return (NULL);
}

dietlibc-0.33~cvs20120325/libshell/basename.c010064400000000000000000000010541173363227000154170ustar00#include 
#include 

/*
       path           dirname        basename
       "/usr/lib"     "/usr"         "lib"
       "/usr/"        "/"            "usr"
       "usr"          "."            "usr"
       "/"            "/"            "/"
       "."            "."            "."
       ".."           "."            ".."
*/

char *basename(char *path) {
  char *c;
again:
  if (!(c=strrchr(path,'/'))) return path;
  if (c[1]==0) {
    if (c == path)
      return c;
    else {
      *c=0;
      goto again;
    }
  }
  return c+1;
}
dietlibc-0.33~cvs20120325/libshell/dirname.c010064400000000000000000000017141173363227000152660ustar00#include 
#include 
/*
        path           dirname        basename
        "/usr/lib"     "/usr"         "lib"
        "/usr/"        "/"            "usr"
        "usr"          "."            "usr"
        "/"            "/"            "/"
        "."            "."            "."
        ".."           "."            ".."
        NULL           "."            "."
        ""             "."            "."
*/

static char *dot=".";
#define SLASH '/'
#define EOL (char)0
char *dirname(char *path)
{
  char *c;
  if ( path  == NULL ) return dot;
  for(;;) {
    if ( !(c=strrchr(path,SLASH)) ) return dot; /* no slashes */
    if ( c[1]==EOL && c!=path ) {   /* remove trailing slashes */
      while ( *c==SLASH && c!=path ) *c--=EOL;
      continue;
    }
    if ( c!=path )
      while ( *c==SLASH && c>=path) *c--=EOL; /* slashes in the middle */
    else
      path[1]=EOL;                  /* slash is first symbol */
    return path;
  }
}
dietlibc-0.33~cvs20120325/libshell/fnmatch.c010064400000000000000000000072321173363227000152700ustar00#include 
#include 
#include 

#define NOTFIRST 128

#define STRUCT_CHARCLASS(c) { #c , is##c }

static struct charclass {
  char * class;
  int (*istype)(int);
} allclasses[] = {
  STRUCT_CHARCLASS(alnum),
  STRUCT_CHARCLASS(alpha),
  STRUCT_CHARCLASS(blank),
  STRUCT_CHARCLASS(cntrl),
  STRUCT_CHARCLASS(digit),
  STRUCT_CHARCLASS(graph),
  STRUCT_CHARCLASS(lower),
  STRUCT_CHARCLASS(print),
  STRUCT_CHARCLASS(punct),
  STRUCT_CHARCLASS(space),
  STRUCT_CHARCLASS(upper),
  STRUCT_CHARCLASS(xdigit),
};

/* look for "class:]" in pattern */
static struct charclass *charclass_lookup(const char *pattern) {
  unsigned int i;

  for (i = 0; i< sizeof(allclasses)/sizeof(*allclasses); i++) {
    int len = strlen(allclasses[i].class);
    if (!strncmp(pattern, allclasses[i].class, len)) {
      pattern += len;
      if (strncmp(pattern, ":]", 2)) goto noclass;
      return &allclasses[i];
    }
  }
noclass:
  return NULL;
}

static int match(char c,char d,int flags) {
  if (flags&FNM_CASEFOLD)
    return (tolower(c)==tolower(d));
  else
    return (c==d);
}

int fnmatch(const char *pattern, const char *string, int flags) {
  if (*string==0) {
    while (*pattern=='*') ++pattern;
    return (!!*pattern);
  }
  if (*string=='.' && *pattern!='.' && (flags&FNM_PERIOD)) {
    /* don't match if FNM_PERIOD and this is the first char */
    if (!(flags&NOTFIRST))
      return FNM_NOMATCH;
    /* don't match if FNM_PERIOD and FNM_PATHNAME and previous was '/' */
    if ((flags&(FNM_PATHNAME)) && string[-1]=='/')
      return FNM_NOMATCH;
  }
  flags|=NOTFIRST;
  switch (*pattern) {
  case '[':
    {
      int neg=0;
      const char* start;	/* first member of character class */

      ++pattern;
      if (*string=='/' && flags&FNM_PATHNAME) return FNM_NOMATCH;
      if (*pattern=='!') { neg=1; ++pattern; }
      start=pattern;
      while (*pattern) {
	int res=0;

	if (*pattern==']' && pattern!=start) break;
	if (*pattern=='[' && pattern[1]==':') {
	  /* MEMBER - stupid POSIX char classes */
	  const struct charclass *cc;

	  if (!(cc = charclass_lookup(pattern+2))) goto invalidclass;
	  pattern += strlen(cc->class) + 4;
	  if (flags&FNM_CASEFOLD
	      && (cc->istype == isupper || cc->istype == islower)) {
	    res = islower(tolower(*string));
	  } else {
            res = ((*(cc->istype))(*string));
	  }
	} else {
invalidclass:
	  if (pattern[1]=='-' && pattern[2]!=']') {
	    /* MEMBER - character range */
	    if (*string>=*pattern && *string<=pattern[2]) res=1;
	    if (flags&FNM_CASEFOLD) {
	      if (tolower(*string)>=tolower(*pattern) && tolower(*string)<=tolower(pattern[2])) res=1;
	    }
	    pattern+=3;
	  } else {
	    /* MEMBER - literal character match */
	    res=match(*pattern,*string,flags);
	    ++pattern;
	  }
	}
	if ((res&&!neg) || ((neg&&!res) && *pattern==']')) {
	  while (*pattern && *pattern!=']') ++pattern;
	  return fnmatch(pattern+!!*pattern,string+1,flags);
	} else if (res && neg)
	  return FNM_NOMATCH;
      }
    }
    break;
  case '\\':
    if (flags&FNM_NOESCAPE) {
      if (*string=='\\')
	return fnmatch(pattern+1,string+1,flags);
    } else {
      if (*string==pattern[1])
	return fnmatch(pattern+2,string+1,flags);
    }
    break;
  case '*':
    if ((*string=='/' && flags&FNM_PATHNAME) || fnmatch(pattern,string+1,flags))
      return fnmatch(pattern+1,string,flags);
    return 0;
  case 0:
    if (*string==0 || (*string=='/' && (flags&FNM_LEADING_DIR)))
      return 0;
    break;
  case '?':
    if (*string=='/' && flags&FNM_PATHNAME) break;
    return fnmatch(pattern+1,string+1,flags);
  default:
    if (match(*pattern,*string,flags))
      return fnmatch(pattern+1,string+1,flags);
    break;
  }
  return FNM_NOMATCH;
}
dietlibc-0.33~cvs20120325/libshell/glob.c010064400000000000000000000225721173363227000145770ustar00/*
 * dietlibc/libshell/glob.c
 *
 * Copyright 2001 Guillaume Cottenceau 
 *
 * This is free software, licensed under the Gnu General Public License.
 *
 */

/*
 * unsupported: GLOB_BRACE GLOB_ALTDIRFUNC GLOB_MAGCHAR
 */

#define DEBUG(x)

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

#include 



/* If i18n, should be using strcoll */
static int cmp_func(const void * a, const void * b)
{
	const char *const s1 = *(const char *const * const) a;
	const char *const s2 = *(const char *const * const) b;
	if (s1 == NULL)
		return 1;
	if (s2 == NULL)
		return -1;
	return strcoll(s1, s2);
}


/* Like `glob', but PATTERN is a final pathname component,
   and matches are searched for in DIRECTORY.
   The GLOB_NOSORT bit in FLAGS is ignored.  No sorting is ever done.
   The GLOB_APPEND flag is assumed to be set (always appends).
   Prepends DIRECTORY in constructed PGLOB. */
static void close_dir_keep_errno(DIR* dp) {
  int save = errno;
  if (dp)
    closedir (dp);
  errno=save;
}

static int add_entry(const char* name,glob_t *pglob,int* nfound) {
  pglob->gl_pathv	= (char **) realloc(pglob->gl_pathv,
			  (pglob->gl_pathc + pglob->gl_offs + 2)
			  * sizeof (char *));
  if (pglob->gl_pathv == NULL)
    return 1;
  pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc] = strdup(name);
  pglob->gl_pathv[pglob->gl_offs + pglob->gl_pathc + 1] = NULL;
  pglob->gl_pathc++;
  (*nfound)++;
  return 0;
}

static void build_fullname(char * fullname, const char * directory, const char * filename) {
  char *dest=fullname;
  if (directory[0]=='/' && !directory[1]) {
    *dest='/'; ++dest;
  } else if (directory[0]!='.' || directory[1]) {
    strcpy(dest,directory);
    dest=strchr(dest,0);
    *dest='/'; ++dest;
  }
  strcpy(dest,filename);
}

static int glob_in_dir(const char *pattern, const char *directory, int flags,
		       int errfunc(const char * epath, int eerrno),
		       glob_t *pglob)
{
	DIR *dp = opendir(directory);
	int nfound = 0;

	int i;
	char * ptr;

	if (!dp) {
		if (errno != ENOTDIR
		    && ((errfunc != NULL && (*errfunc) (directory, errno))
			|| (flags & GLOB_ERR)))
		      return GLOB_ABORTED;
	} else {
		int fnm_flags = ((!(flags & GLOB_PERIOD) ? FNM_PERIOD : 0)
				 | ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0));
		struct dirent *ep;
		while ((ep = readdir(dp))) {
			i = strlen(directory) + strlen(ep->d_name) + 2;
			ptr = (char *) alloca(i);
			build_fullname(ptr, directory, ep->d_name);
			if (flags & GLOB_ONLYDIR) {
				struct stat statr;
				if (stat(ptr, &statr) || !S_ISDIR(statr.st_mode))
					continue;
			}
			if (fnmatch(pattern, ep->d_name, fnm_flags) == 0)
				if (add_entry(ptr,pglob,&nfound))
					goto memory_error;
		}
	}

	close_dir_keep_errno(dp);

	if (nfound != 0)
		pglob->gl_flags = flags;
	else if (flags & GLOB_NOCHECK) {
		/* nfound == 0 */
		i = strlen(directory) + strlen(pattern) + 2;
		ptr = (char *) alloca(i);
		build_fullname(ptr, directory, pattern);
		if (add_entry(ptr,pglob,&nfound))
			goto memory_error;
	}

	return (nfound == 0) ? GLOB_NOMATCH : 0;

 memory_error:
	/* We're in trouble since we can't free the already allocated memory. [allocated from strdup(filame)]
	 * Well, after all, when malloc returns NULL we're already in a bad mood, and no doubt the
	 * program will manage to segfault by itself very soon :-). */
	close_dir_keep_errno(dp);
	return GLOB_NOSPACE;
}



int glob(const char *pattern, int flags, int errfunc(const char * epath, int eerrno), glob_t *pglob)
{
	char * pattern_;
	char * filename;
	char * dirname;
	size_t oldcount;
	struct stat statr;

	size_t i; /* tmp variables are declared here to save a bit of object space */
	int j, k;    /* */
	char * ptr, * ptr2;

	if (pattern == NULL || pglob == NULL || (flags & ~__GLOB_FLAGS) != 0) {
		errno=EINVAL;
		return -1;
	}

	if (!(flags & GLOB_DOOFFS))
		pglob->gl_offs = 0;


	/* Duplicate pattern so I can make modif to it later (to handle
           TILDE stuff replacing old contents, and to null-terminate the
           directory) */
	pattern_ = alloca(strlen(pattern) + 1);
	strcpy(pattern_, pattern);

	/* Check for TILDE stuff */
	if ((flags & (GLOB_TILDE|GLOB_TILDE_CHECK)) && pattern_[0] == '~') {
		char * home_dir = NULL;
		if (pattern_[1] == '\0' || pattern_[1] == '/') {
			/* She's asking for ~, her homedir */
			home_dir = getenv("HOME");
		} else {
			/* She's asking for another one's homedir */
			struct passwd * p;
			ptr2 = alloca(strlen(pattern_) + 1);
			strcpy(ptr2, pattern_ + 1);
			ptr = strchr(ptr2, '/');
			if (ptr != NULL)
				*ptr = '\0';
			if (((p = getpwnam(ptr2)) != NULL))
				home_dir = p->pw_dir;
		}
		if (home_dir != NULL) {
			i = strlen(home_dir) + strlen(pattern_); /* pessimistic (the ~ case) */
			ptr = alloca(i);
			strncpy(ptr, home_dir, i);
			ptr2 = pattern_ + 1;
			while (*ptr2 != '/' && *ptr2 != '\0')
				ptr2++;
			strncat(ptr, ptr2, i);
			pattern_ = ptr;
		} else if (flags & GLOB_TILDE_CHECK)
			return GLOB_NOMATCH;
	}

	/* Find the filename */
	filename = strrchr(pattern_, '/');

	if (filename == NULL) {
		/* We have no '/' in the pattern */
		filename = pattern_;
		dirname = (char*)".";
	} else if (filename == pattern_) {
		/* "/pattern".  */
		dirname = (char*)"/";
		filename++;
	} else {
		dirname = pattern_;
		filename++;
		/* allow dirname to be null terminated */
		*(filename-1) = '\0';

		if (filename[0] == '\0' && strcmp(pattern_, "/")) {
			/* "pattern/".  Expand "pattern", appending slashes.  */
			j = glob(dirname, flags | GLOB_MARK, errfunc, pglob);
			if (j == 0)
				pglob->gl_flags = ((pglob->gl_flags & ~GLOB_MARK)
						   | (flags & GLOB_MARK));
			return j;
		}
	}

	
	/* Reserve memory for pglob */
	if (!(flags & GLOB_APPEND)) {
		pglob->gl_pathc = 0;
		if (!(flags & GLOB_DOOFFS))
			pglob->gl_pathv = NULL;
		else {
			pglob->gl_pathv = (char **) malloc((pglob->gl_offs + 1) * sizeof (char *));
			if (pglob->gl_pathv == NULL)
				return GLOB_NOSPACE;
			for (i = 0; i <= pglob->gl_offs; i++)
				pglob->gl_pathv[i] = NULL;
		}
	}


	oldcount = pglob->gl_pathc + pglob->gl_offs;


	/* Begin real work */
	if (!strcmp(dirname, "/") || !strcmp(dirname, ".")
	    || (!strchr(dirname, '*') && !strchr(dirname, '?') && !strchr(dirname, '['))) {
		/* Approx of a terminal state, glob directly in dir. */
		j = glob_in_dir(filename, dirname, flags, errfunc, pglob);
		if (j != 0)
			return j;
	} else {
		/* We are not in a terminal state, so we have to glob for
		   the directory, and then glob for the pattern in each
		   directory found. */
		glob_t dirs;

		j = glob(dirname, ((flags & (GLOB_ERR | GLOB_NOCHECK | GLOB_NOESCAPE | GLOB_ALTDIRFUNC))
				   | GLOB_NOSORT | GLOB_ONLYDIR),
			 errfunc, &dirs);
		if (j != 0)
			return j;

		/* We have successfully globbed the directory name.
		   For each name we found, call glob_in_dir on it and FILENAME,
		   appending the results to PGLOB.  */
		for (i = 0; i < dirs.gl_pathc; i++) {
			j = glob_in_dir(filename, dirs.gl_pathv[i], ((flags | GLOB_APPEND) & ~GLOB_NOCHECK),
					errfunc, pglob);
			if (j == GLOB_NOMATCH)
				/* No matches in this directory.  Try the next.  */
				continue;
			if (j != 0) {
				globfree(&dirs);
				globfree(pglob);
				return j;
			}
		}

		/* We have ignored the GLOB_NOCHECK flag in the `glob_in_dir' calls.
		   But if we have not found any matching entry and the GLOB_NOCHECK
		   flag was set we must return the list consisting of the disrectory
		   names followed by the filename.  */
		if (pglob->gl_pathc + pglob->gl_offs == oldcount)
		{
			/* No matches.  */
			if (flags & GLOB_NOCHECK)
			{
				for (i = 0; i < dirs.gl_pathc; i++) {
					if (stat(dirs.gl_pathv[i], &statr) || !S_ISDIR(statr.st_mode))
						continue;

					/* stat is okay, we will add the entry, but before let's resize the pathv */
					j = pglob->gl_pathc + pglob->gl_offs;
					pglob->gl_pathv = (char **) realloc(pglob->gl_pathv, (j + 2) * sizeof (char *));
					if (pglob->gl_pathv == NULL) {
						globfree (&dirs);
						return GLOB_NOSPACE;
					}

					/* okay now we add the new entry */
					k = strlen(dirs.gl_pathv[i]) + strlen(filename) + 2;
					if ((pglob->gl_pathv[j] = malloc(k)) == NULL) {
						globfree(&dirs);
						globfree(pglob);
						return GLOB_NOSPACE;
					}
					build_fullname(pglob->gl_pathv[j], dirs.gl_pathv[i], filename);
					pglob->gl_pathc++;
					pglob->gl_pathv[j+1] = NULL;
				}
			} else {
				globfree(&dirs);
				return GLOB_NOMATCH;
			}
		}

		globfree (&dirs);
	}


	if (flags & GLOB_MARK) {
		for (i = oldcount; i < pglob->gl_pathc + pglob->gl_offs; i++)
			if (!stat(pglob->gl_pathv[i], &statr) && S_ISDIR(statr.st_mode)) {
				size_t len = strlen(pglob->gl_pathv[i]) + 2;
				ptr = realloc(pglob->gl_pathv[i], len);
				if (ptr == NULL) {
					globfree(pglob);
					return GLOB_NOSPACE;
				}
				strcpy(&ptr[len - 2], "/");
				pglob->gl_pathv[i] = ptr;
			}
	}

	if (!(flags & GLOB_NOSORT)) {
		qsort(&pglob->gl_pathv[oldcount],
		      pglob->gl_pathc + pglob->gl_offs - oldcount,
		      sizeof(char *), cmp_func);
	}

	return 0;
}


/* Free storage allocated in PGLOB by a previous `glob' call.  */
void globfree (glob_t * pglob)
{
  if (pglob->gl_pathv != NULL) {
      size_t i;
      for (i = 0; i < pglob->gl_pathc; i++)
	      if (pglob->gl_pathv[pglob->gl_offs + i] != NULL)
		      free((void *) pglob->gl_pathv[pglob->gl_offs + i]);
      free((void *) pglob->gl_pathv);
  }
}
dietlibc-0.33~cvs20120325/libshell/realpath.c010064400000000000000000000020701173363227000154430ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

static char* myrealpath(const char* file, char* dest, int count) {
/* assume dest has PATH_MAX space */
  char buf[PATH_MAX+1];
  char* c;
  int i;

  if (count<0) { errno=EMLINK; return 0; }
  if (chdir(file)==0)
    /* hurray!  The easy case: it's a directory! */
    return getcwd(dest,PATH_MAX);

  c=strrchr(file,'/');
  if (c) {
    if (c-file>PATH_MAX) return 0;
    memcpy(buf,file,c-file);
    buf[c-file]=0;
    if (chdir(buf)==-1) return 0;
    file=c+1;
  }
  if (readlink(file,buf,PATH_MAX)==0)
    return myrealpath(buf,dest,count-1);
  if (getcwd(dest,PATH_MAX)==0) return 0;
  i=strlen(dest); dest[i]='/'; ++i;
  for (; iflags&=~(ERRORINDICATOR|EOFINDICATOR);
}

void clearerr(FILE *stream) __attribute__((weak,alias("clearerr_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fclose.c010064400000000000000000000010141173363227000151260ustar00#include "dietstdio.h"
#include 
#include 

int fclose_unlocked(FILE *stream) {
  int res;
  FILE *f,*fl;
  res=fflush_unlocked(stream);
  res|=__libc_close(stream->fd);
  for (fl=0,f=__stdio_root; f; fl=f,f=f->next)
    if (f==stream) {
      if (fl)
	fl->next=f->next;
      else
	__stdio_root=f->next;
      break;
    }
  if ((!(stream->flags&STATICBUF))&&(stream->buf))
    free(stream->buf);
  free(stream);
  return res;
}

int fclose(FILE *stream) __attribute__((weak,alias("fclose_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fdglue.c010064400000000000000000000007511173363227000151300ustar00#include 
#include 
#include 
#include 
#ifdef WANT_THREAD_SAFE
#include 
#endif
#include "dietstdio.h"

int __stdio_parse_mode(const char *mode) {
  int f=0;
  for (;;) {
    switch (*mode) {
    case 0: return f;
    case 'b': break;
    case 'r': f=O_RDONLY; break;
    case 'w': f=O_WRONLY|O_CREAT|O_TRUNC; break;
    case 'a': f=O_WRONLY|O_CREAT|O_APPEND; break;
    case '+': f=(f&(~O_WRONLY))|O_RDWR; break;
    }
    ++mode;
  }
}

dietlibc-0.33~cvs20120325/libstdio/fdglue2.c010064400000000000000000000021001173363227000152000ustar00#include 
#include 
#include 
#include 
#include "dietstdio.h"
#include 
#ifdef WANT_THREAD_SAFE
#include 
#endif

extern int __stdio_atexit;

FILE*__stdio_init_file(int fd,int closeonerror,int mode) {
  FILE *tmp=(FILE*)malloc(sizeof(FILE));
  if (!tmp) goto err_out;
  tmp->buf=(char*)malloc(BUFSIZE);
  if (!tmp->buf) {
    free(tmp);
err_out:
    if (closeonerror) __libc_close(fd);
    errno=ENOMEM;
    return 0;
  }
  tmp->fd=fd;
  tmp->bm=0;
  tmp->bs=0;
  tmp->buflen=BUFSIZE;
  {
    struct stat st;
    fstat(fd,&st);
    tmp->flags=(S_ISFIFO(st.st_mode))?FDPIPE:0;
  }
  switch (mode&3) {
  case O_RDWR: tmp->flags|=CANWRITE;
  case O_RDONLY: tmp->flags|=CANREAD; break;
  case O_WRONLY: tmp->flags|=CANWRITE;
  }
  tmp->popen_kludge=0;
  if (__stdio_atexit==0) {
    __stdio_atexit=1;
    atexit(__stdio_flushall);
  }
  tmp->next=__stdio_root;
  __stdio_root=tmp;
  tmp->ungotten=0;
  return tmp;
}

FILE* __stdio_init_file_nothreads(int fd,int closeonerror,int mode) __attribute__((alias("__stdio_init_file")));
dietlibc-0.33~cvs20120325/libstdio/fdopen.c010064400000000000000000000006501173363227000151330ustar00#include 
#include "dietfeatures.h"
#include 
#include 
#include 

FILE *fdopen_unlocked(int filedes, const char *mode) {
  int f=0;	/* O_RDONLY, O_WRONLY or O_RDWR */

  f=__stdio_parse_mode(mode);
  if (filedes<0) { errno=EBADF; return 0; }
  return __stdio_init_file(filedes,0,f);
}

FILE *fdopen(int filedes, const char *mode) __attribute__((weak,alias("fdopen_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fdprintf.c010064400000000000000000000003741173363227000154770ustar00#include 
#include 
#include 
#include 

int fdprintf(int fd,const char *format,...) {
  int n;
  va_list arg_ptr;
  va_start(arg_ptr,format);
  n=vfdprintf(fd,format,arg_ptr);
  va_end(arg_ptr);
  return n;
}
dietlibc-0.33~cvs20120325/libstdio/feof.c010064400000000000000000000003301173363227000145720ustar00#include 

int feof_unlocked(FILE*stream) {
  /* yuck!!! */
  if (stream->ungotten) return 0;
  return (stream->flags&EOFINDICATOR);
}
int feof(FILE*stream)
__attribute__((weak,alias("feof_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/ferror.c010064400000000000000000000002561173363227000151610ustar00#include 

int ferror_unlocked(FILE*stream) {
  return (stream->flags&ERRORINDICATOR);
}
int ferror(FILE*stream)
__attribute__((weak,alias("ferror_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fflush.c010064400000000000000000000030561173363227000151520ustar00#include 
#include 
#include "dietwarning.h"
#include "dietstdio.h"

FILE *__stdio_root;

int __stdio_atexit=0;

int fflush(FILE *stream) __attribute__((weak,alias("fflush_unlocked")));

void __stdio_flushall(void) {
  fflush(0);
}

int fflush_unlocked(FILE *stream) {
  if (stream==0) {
    int res;
    FILE *f;
    __fflush_stdin();
    __fflush_stdout();
    __fflush_stderr();
    for (res=0, f=__stdio_root; f; f=f->next)
      if (fflush(f))
	res=-1;
    return res;
  }
//  if (stream->flags&NOBUF) return 0;
  if (stream->flags&BUFINPUT) {
    register int tmp;
    if ((tmp=stream->bm-stream->bs)) {
      lseek(stream->fd,tmp,SEEK_CUR);
    }
    stream->bs=stream->bm=0;
  } else {
    if (stream->bm && write(stream->fd,stream->buf,stream->bm)!=(ssize_t)stream->bm) {
      stream->flags|=ERRORINDICATOR;
      return -1;
    }
    stream->bm=0;
  }
  return 0;
}

int __fflush4(FILE *stream,int next) {
  if (__unlikely(!__stdio_atexit)) {
    __stdio_atexit=1;
    atexit(__stdio_flushall);
  }
  if (__unlikely((stream->flags&BUFINPUT)!=next)) {
    int res=fflush_unlocked(stream);
    stream->flags=(stream->flags&~BUFINPUT)|next;
    return res;
  }
  if (stream->fd==0 && __stdin_is_tty()) __fflush_stdout();
  return 0;
}

/* Internal function, has no prototype.
 * This is defined here because of the weak symbol ELF semantics */
int __stdio_outs(const char *s,size_t len);
int __stdio_outs(const char *s,size_t len) {
  return fwrite(s,1,(size_t)len,stdout)==len?1:0;
}

link_warning("fflush","warning: your code uses stdio (7+k bloat).")
dietlibc-0.33~cvs20120325/libstdio/fgetc_unlocked.c010064400000000000000000000016321173363227000166350ustar00#include "dietstdio.h"
#include 

int fgetc_unlocked(FILE *stream) {
  unsigned char c;
  if (__unlikely(!(stream->flags&CANREAD))) goto kaputt;
  if (__unlikely(stream->ungotten)) {
    stream->ungotten=0;
    return stream->ungetbuf;
  }

  /* common case first */
  if (__likely(stream->bmbs))
    return (unsigned char)stream->buf[stream->bm++];

  if (__unlikely(feof_unlocked(stream)))
    return EOF;
  if (__fflush4(stream,BUFINPUT)) return EOF;
  if (__unlikely(stream->bm>=stream->bs)) {
    ssize_t len=__libc_read(stream->fd,stream->buf,stream->buflen);
    if (len==0) {
      stream->flags|=EOFINDICATOR;
      return EOF;
    } else if (len<0) {
kaputt:
      stream->flags|=ERRORINDICATOR;
      return EOF;
    }
    stream->bm=0;
    stream->bs=len;
  }
  c=stream->buf[stream->bm];
  ++stream->bm;
  return c;
}

int fgetc(FILE* stream) __attribute__((weak,alias("fgetc_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fgetpos.c010064400000000000000000000002051173363227000153230ustar00#include 

int fgetpos(FILE *stream, fpos_t *pos) {
  long l=ftell(stream);
  if (l==-1) return -1;
  *pos=l;
  return 0;
}
dietlibc-0.33~cvs20120325/libstdio/fgets.c010064400000000000000000000010771173363227000147740ustar00#include "dietstdio.h"

char *fgets_unlocked(char *s, int size, FILE *stream) {
  int l;
  for (l=0; lbmbs)) {
      /* try common case first */
      c=(unsigned char)stream->buf[stream->bm++];
    } else {
      c=fgetc_unlocked(stream);
      if (__unlikely(c==EOF)) {
	if (!l) return 0;
	goto fini;
      }
    }
    s[l]=c;
    ++l;
    if (c=='\n') {
fini:
      s[l]=0;
      return s;
    }
  }
  return 0;
}

char*fgets(char*s,int size,FILE*stream) __attribute__((weak,alias("fgets_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fileno.c010064400000000000000000000002321173363227000151300ustar00#include 

int fileno_unlocked(FILE*stream) {
  return stream->fd;
}
int fileno(FILE*stream)
__attribute__((weak,alias("fileno_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fopen.c010064400000000000000000000010101173363227000147560ustar00#include 
#include 
#include 

extern int __stdio_atexit;

/* this is needed so the libpthread wrapper can initialize the mutex,
 * not to lock it */

FILE *fopen_unlocked(const char *path, const char *mode) {
  int f=0;	/* O_RDONLY, O_WRONLY or O_RDWR */
  int fd;

  f=__stdio_parse_mode(mode);
  if ((fd=__libc_open(path,f,0666))<0)
    return 0;
  return __stdio_init_file(fd,1,f);
}

FILE *fopen(const char *path, const char *mode) __attribute__((weak,alias("fopen_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fprintf.c010064400000000000000000000003721173363227000153310ustar00#include 
#include 
#include 
#include 

int fprintf(FILE *f,const char *format,...) {
  int n;
  va_list arg_ptr;
  va_start(arg_ptr,format);
  n=vfprintf(f,format,arg_ptr);
  va_end(arg_ptr);
  return n;
}
dietlibc-0.33~cvs20120325/libstdio/fputc_unlocked.c010064400000000000000000000014721173363227000166700ustar00#include 
#include 
#include 

int fputc_unlocked(int c, FILE *stream) {
  if (!__likely(stream->flags&CANWRITE) || __fflush4(stream,0)) {
kaputt:
    stream->flags|=ERRORINDICATOR;
    return EOF;
  }
  if (__unlikely(stream->bm>=stream->buflen-1))
    if (fflush_unlocked(stream)) goto kaputt;
  if (stream->flags&NOBUF) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
    if (__libc_write(stream->fd,&c,1) != 1)
#else
    if (__libc_write(stream->fd,(char*)&c+sizeof(c)-1,1) != 1)
#endif
      goto kaputt;
    return 0;
  }
  stream->buf[stream->bm]=c;
  ++stream->bm;
  if (((stream->flags&BUFLINEWISE) && c=='\n') ||
      ((stream->flags&NOBUF))) /* puke */
    if (fflush_unlocked(stream)) goto kaputt;
  return 0;
}

int fputc(int c,FILE* stream) __attribute__((weak,alias("fputc_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fputs.c010064400000000000000000000003411173363227000150160ustar00#include "dietstdio.h"
#include 

int fputs_unlocked(const char*s,FILE*stream) {
  return fwrite_unlocked(s,strlen(s),1,stream);
}

int fputs(const char*s,FILE*stream) __attribute__((weak,alias("fputs_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fread.c010064400000000000000000000024461173363227000147460ustar00#include 
#include "dietstdio.h"
#include 

size_t fread_unlocked(void *ptr, size_t size, size_t nmemb, FILE *stream) {
  int res;
  unsigned long i,j;
  j=size*nmemb;
  i=0;

  if (!(stream->flags&CANREAD)) {
    stream->flags|=ERRORINDICATOR;
    return 0;
  }
  if (!j || j/nmemb!=size) return 0;
  if (stream->ungotten) {
    stream->ungotten=0;
    *(char*)ptr=stream->ungetbuf;
    ++i;
    if (j==1) return 1;
  }

#ifdef WANT_FREAD_OPTIMIZATION
  if ( !(stream->flags&FDPIPE) && (j>stream->buflen)) {
    size_t tmp=j-i;
    ssize_t res;
    size_t inbuf=stream->bs-stream->bm;
    memcpy(ptr+i,stream->buf+stream->bm,inbuf);
    stream->bm=stream->bs=0;
    tmp-=inbuf;
    i+=inbuf;
    if (fflush_unlocked(stream)) return 0;
    while ((res=__libc_read(stream->fd,ptr+i,tmp))<(ssize_t)tmp) {
      if (res==-1) {
	stream->flags|=ERRORINDICATOR;
	goto exit;
      } else if (!res) {
	stream->flags|=EOFINDICATOR;
	goto exit;
      }
      i+=res; tmp-=res;
    }
    return nmemb;
  }
#endif
  for (; i
#include 
#include 
#include 
#include 

/* this is needed so the libpthread wrapper can initialize the mutex,
 * not to lock it */

FILE *freopen_unlocked(const char *path, const char *mode, FILE *stream) {
  if (stream) {
    int f=__stdio_parse_mode(mode);
    fflush_unlocked(stream);
    __libc_close(stream->fd);
    if ((stream->fd=__libc_open(path,f,0666))!=-1) {
      struct stat st;
      fstat(stream->fd,&st);
      stream->flags=(S_ISFIFO(st.st_mode))?FDPIPE:0;
      switch (f&3) {
      case O_RDWR: stream->flags|=CANWRITE;
      case O_RDONLY: stream->flags|=CANREAD; break;
      case O_WRONLY: stream->flags|=CANWRITE;
      }
    }
  } else errno=EINVAL;
  return stream;
}

FILE *freopen(const char *path, const char *mode, FILE *stream) __attribute__((weak,alias("freopen_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fscanf.c010064400000000000000000000004361173363227000151220ustar00#include 
#include 
#include 
#include "dietstdio.h"
#include 

int fscanf(FILE *stream, const char *format, ...) {
  int n;
  va_list arg_ptr;
  va_start(arg_ptr, format);
  n=vfscanf(stream,format,arg_ptr);
  va_end (arg_ptr);
  return n;
}
dietlibc-0.33~cvs20120325/libstdio/fseek.c010064400000000000000000000005761173363227000147640ustar00#include 
#include 

int fseek_unlocked(FILE *stream, long offset, int whence) {
  fflush_unlocked(stream);
  stream->bm=0; stream->bs=0;
  stream->flags&=~(ERRORINDICATOR|EOFINDICATOR);
  stream->ungotten=0;
  return lseek(stream->fd,offset,whence)!=-1?0:-1;
}

int fseek(FILE *stream, long offset, int whence) __attribute__((weak,alias("fseek_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fseeko.c010064400000000000000000000005721173363227000151370ustar00#include 
#include 

int fseeko_unlocked(FILE *stream, off_t offset, int whence) {
  fflush(stream);
  stream->bm=0; stream->bs=0;
  stream->flags&=~(ERRORINDICATOR|EOFINDICATOR);
  stream->ungotten=0;
  return lseek(stream->fd,offset,whence)!=-1?0:-1;
}

int fseeko(FILE *stream, off_t offset, int whence) __attribute__((weak,alias("fseeko_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/fseeko64.c010064400000000000000000000007001173363227000153020ustar00#include 
#include 
#include 

#ifndef __NO_STAT64
int fseeko64_unlocked(FILE *stream, off64_t offset, int whence) {
  fflush_unlocked(stream);
  stream->bm=0; stream->bs=0;
  stream->flags&=~(ERRORINDICATOR|EOFINDICATOR);
  stream->ungotten=0;
  return lseek64(stream->fd,offset,whence)!=-1?0:-1;
}

int fseeko64(FILE *stream, off64_t offset, int whence) __attribute__((weak,alias("fseeko64_unlocked")));
#endif
dietlibc-0.33~cvs20120325/libstdio/fsetpos.c010064400000000000000000000002011173363227000153330ustar00#include 

int fsetpos(FILE *stream, fpos_t *pos) {
  if (fseek(stream,*pos,SEEK_SET)==-1)
    return -1;
  return 0;
}
dietlibc-0.33~cvs20120325/libstdio/ftell.c010064400000000000000000000005701173363227000147670ustar00#include 
#include 
#include 

long ftell_unlocked(FILE *stream) {
  off_t l;
  if (stream->flags&3 || (l=lseek(stream->fd,0,SEEK_CUR))==-1) return -1;
  if (stream->flags&BUFINPUT)
    return l-(stream->bs-stream->bm)-stream->ungotten;
  else
    return l+stream->bm;
}

long ftell(FILE *stream) __attribute__((weak,alias("ftell_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/ftello.c010064400000000000000000000004341173363227000151450ustar00#include 
#include 

off_t ftello_unlocked(FILE *stream) {
  off_t l;
  if (fflush_unlocked(stream)) return -1;
  return ((l=lseek(stream->fd,0,SEEK_CUR))==-1?-1:l-stream->ungotten);
}

off_t ftello(FILE *stream) __attribute__((weak,alias("ftello_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/ftello64.c010064400000000000000000000005361173363227000153220ustar00#include 
#include 
#include 

#ifndef __NO_STAT64
off64_t ftello64_unlocked(FILE *stream) {
  off64_t l;
  if (fflush_unlocked(stream)) return -1;
  return ((l=lseek64(stream->fd,0ull,SEEK_CUR))==-1?-1:l-stream->ungotten);
}

off64_t ftello64(FILE *stream) __attribute__((weak,alias("ftello64_unlocked")));
#endif
dietlibc-0.33~cvs20120325/libstdio/fwrite.c010064400000000000000000000034271173363227000151650ustar00#include 
#include "dietstdio.h"
#include 
#include 

size_t fwrite_unlocked(const void *ptr, size_t size, size_t nmemb, FILE *stream) {
  ssize_t res;
  size_t len=size*nmemb;
  size_t i,done;
  if (!__likely(stream->flags&CANWRITE) || __fflush4(stream,0)) {
kaputt:
    stream->flags|=ERRORINDICATOR;
    return 0;
  }
  if (!nmemb || len/nmemb!=size) return 0; /* check for integer overflow */
  if (__unlikely(len>stream->buflen || (stream->flags&NOBUF))) {
    if (fflush_unlocked(stream)) return 0;
    do {
      res=__libc_write(stream->fd,ptr,len);
    } while (res==-1 && errno==EINTR);
  } else {
    /* try to make the common case fast */
    size_t todo=stream->buflen-stream->bm;
    if (todo>len) todo=len;

    if (todo) {
      if (stream->flags&BUFLINEWISE) {
	if (__unlikely((stream->flags&CHECKLINEWISE)!=0)) {
	  stream->flags&=~CHECKLINEWISE;
	  /* stdout is set to BUFLINEWISE|CHECKLINEWISE by default. */
	  /* that means we should check whether it is connected to a
	   * tty on first flush, and if not so, reset BUFLINEWISE */
	  if (!isatty(stream->fd)) {
	    stream->flags&=~BUFLINEWISE;
	    goto notlinewise;
	  }
	}
	for (i=0; ibuf[stream->bm++]=((char*)ptr)[i])=='\n') {
	    if (fflush_unlocked(stream)) goto kaputt;
	  }
	}
      } else {
notlinewise:
	memcpy(stream->buf+stream->bm,ptr,todo);
	stream->bm+=todo;
      }
      done=todo;
    } else
      done=0;
    for (i=done; iflags|=ERRORINDICATOR;
    return 0;
  }
abort:
  return size?res/size:0;
}

size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) __attribute__((weak,alias("fwrite_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/printf.c010064400000000000000000000004101173363227000151540ustar00#include 
#include 
#include 
#include 
#include "dietstdio.h"

int printf(const char *format,...)
{
  int n;
  va_list arg_ptr;
  va_start(arg_ptr, format);
  n=vprintf(format, arg_ptr);
  va_end(arg_ptr);
  return n;
}
dietlibc-0.33~cvs20120325/libstdio/putchar.c010064400000000000000000000001241173363227000153220ustar00#include 

#undef putchar
int putchar(int c) {
  return fputc(c,stdout);
}
dietlibc-0.33~cvs20120325/libstdio/puts.c010064400000000000000000000005311173363227000146510ustar00#include 
#include 
#include "dietstdio.h"
#include "dietfeatures.h"

int __stdio_outs(const char *s,size_t len) __attribute__((weak));
int __stdio_outs(const char *s,size_t len) {
  return (write(1,s,len)==(ssize_t)len)?1:0;
}

int puts(const char *s) {
  return (__stdio_outs(s,strlen(s)) && __stdio_outs("\n",1))?0:-1;
}

dietlibc-0.33~cvs20120325/libstdio/scanf.c010064400000000000000000000004161173363227000147520ustar00#include 
#include 
#include 
#include "dietstdio.h"
#include 

int scanf(const char *format, ...) {
  int n;
  va_list arg_ptr;
  va_start(arg_ptr, format);
  n=vfscanf(stdin,format,arg_ptr);
  va_end (arg_ptr);
  return n;
}
dietlibc-0.33~cvs20120325/libstdio/setvbuf.c010064400000000000000000000020501173363227000153320ustar00#include 
#include "dietstdio.h"
#include 
#include 
#include "dietwarning.h"

static int set_flags(FILE *stream, int flags) {
  switch (flags) {
    case _IONBF: stream->flags = (stream->flags & ~(BUFLINEWISE)) | NOBUF; break;
    case _IOLBF: stream->flags = (stream->flags & ~(NOBUF)) | BUFLINEWISE; break;
    case _IOFBF: stream->flags = stream->flags & ~(NOBUF | BUFLINEWISE); break;
    default: return -1;
  }
  return 0;
}

int setvbuf_unlocked(FILE *stream, char *buf, int flags, size_t size) {
  if (buf) {
    if (!(stream->flags&STATICBUF)) free(stream->buf);
    stream->buf=buf;
  }
  else {
    char *tmp;
    if (!size) {
      return set_flags(stream,flags);
    }
    if (!(tmp=malloc(size))) return -1;
    if (!(stream->flags&STATICBUF)) free(stream->buf);
    stream->buf=tmp;
  }
  stream->flags &= ~STATICBUF;
  stream->buflen=size;
  stream->bm=stream->bs=0;
  return set_flags(stream,flags);
}

int setvbuf(FILE *stream, char *buf, int flags, size_t size) __attribute__((weak,alias("setvbuf_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/stderr.c010064400000000000000000000005261173363227000151650ustar00#include 

static FILE __stderr = {
  .fd=2,
  .flags=NOBUF|CANWRITE,
  .bs=0, .bm=0,
  .buflen=0,
  .buf=0,
  .next=0,
  .popen_kludge=0,
  .ungetbuf=0,
  .ungotten=0,
#ifdef WANT_THREAD_SAFE
  .m=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
#endif
};

FILE *stderr=&__stderr;

int __fflush_stderr(void) {
  return fflush(stderr);
}
dietlibc-0.33~cvs20120325/libstdio/stdin.c010064400000000000000000000007761173363227000150120ustar00#include 

static char __stdin_buf[BUFSIZE];
static FILE __stdin = {
  .fd=0,
  .flags=BUFINPUT|BUFLINEWISE|STATICBUF|CANREAD,
  .bs=0, .bm=0,
  .buflen=BUFSIZE,
  .buf=__stdin_buf,
  .next=0,
  .popen_kludge=0,
  .ungetbuf=0,
  .ungotten=0,
#ifdef WANT_THREAD_SAFE
  .m=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
#endif
};

int __stdin_is_tty() {
  static int iknow;
  if (!iknow) iknow=isatty(0)+1;
  return (iknow-1);
}

FILE *stdin=&__stdin;

int __fflush_stdin(void) {
  return fflush(stdin);
}
dietlibc-0.33~cvs20120325/libstdio/stdout.c010064400000000000000000000006501173363227000152020ustar00#include 

static char __stdout_buf[BUFSIZE];
static FILE __stdout = {
  .fd=1,
  .flags=BUFLINEWISE|STATICBUF|CANWRITE|CHECKLINEWISE,
  .bs=0, .bm=0,
  .buflen=BUFSIZE,
  .buf=__stdout_buf,
  .next=0,
  .popen_kludge=0,
  .ungetbuf=0,
  .ungotten=0,
#ifdef WANT_THREAD_SAFE
  .m=PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP,
#endif
};

FILE *stdout=&__stdout;

int __fflush_stdout(void) {
  return fflush(stdout);
}
dietlibc-0.33~cvs20120325/libstdio/tmpfile.c010064400000000000000000000006701173363227000153220ustar00#include "dietstdio.h"
#include 
#include 
#include 

/* this is needed so the libpthread wrapper can initialize the mutex,
 * not to lock it */

FILE *tmpfile_unlocked(void) {
  int fd;
  char template[20] = "/tmp/tmpfile-XXXXXX";
  if ((fd=mkstemp(template))<0)
    return 0;
  unlink(template);
  return __stdio_init_file(fd,1,O_RDWR);
}

FILE *tmpfile(void) __attribute__((weak,alias("tmpfile_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/ungetc.c010064400000000000000000000005061173363227000151450ustar00#include "dietstdio.h"

int ungetc_unlocked(int c, FILE *stream) {
  if (stream->ungotten || c<0 || c>255)
    return EOF;
  stream->ungotten=1;
  stream->ungetbuf=(unsigned char)c;
  stream->flags&=~(ERRORINDICATOR|EOFINDICATOR);
  return c;
}

int ungetc(int c, FILE *stream) __attribute__((weak,alias("ungetc_unlocked")));
dietlibc-0.33~cvs20120325/libstdio/vfdprintf.c010064400000000000000000000005771173363227000156720ustar00#include 
#include 
#include 
#include 
#include "dietstdio.h"

static int __fwrite(void*ptr, size_t nmemb, int fd) {
  return write(fd,ptr,nmemb);
}

int vfdprintf(int fd, const char *format, va_list arg_ptr)
{
  struct arg_printf ap = { (void*)(long)fd, (int(*)(void*,size_t,void*)) __fwrite };
  return __v_printf(&ap,format,arg_ptr);
}
dietlibc-0.33~cvs20120325/libstdio/vfprintf.c010064400000000000000000000005761173363227000155250ustar00#include 
#include 
#include 
#include 
#include "dietstdio.h"

static int __fwrite(void*ptr, size_t nmemb, FILE* f) {
  return fwrite(ptr,1,nmemb,f);
}

int vfprintf(FILE *stream, const char *format, va_list arg_ptr)
{
  struct arg_printf ap = { stream, (int(*)(void*,size_t,void*)) __fwrite };
  return __v_printf(&ap,format,arg_ptr);
}
dietlibc-0.33~cvs20120325/libstdio/vfscanf.c010064400000000000000000000004661173363227000153130ustar00#include 
#include 
#include 
#include "dietstdio.h"
#include 

int vfscanf(FILE *stream, const char *format, va_list arg_ptr)
{
  struct arg_scanf farg = { (void*)stream, (int(*)(void*))fgetc, (int(*)(int,void*))ungetc };
  return __v_scanf(&farg,format,arg_ptr);
}
dietlibc-0.33~cvs20120325/libstdio/vprintf.c010064400000000000000000000006011173363227000153440ustar00#include 
#include 
#include "dietstdio.h"

int __stdio_outs(const char *s,size_t len) __attribute__((weak));
int __stdio_outs(const char *s,size_t len) {
  return (write(1,s,len)==(ssize_t)len)?1:0;
}

int vprintf(const char *format, va_list ap)
{
  struct arg_printf _ap = { 0, (int(*)(void*,size_t,void*)) __stdio_outs };
  return __v_printf(&_ap,format,ap);
}

dietlibc-0.33~cvs20120325/libstdio/vscanf.c010064400000000000000000000003071173363227000151370ustar00#include 
#include 
#include 
#include "dietstdio.h"
#include 

int vscanf(const char *format, va_list arg_ptr)
{
  return vfscanf(stdin,format,arg_ptr);
}
dietlibc-0.33~cvs20120325/libugly/__utmp_block_signals.c010064400000000000000000000021541173363227000176740ustar00#include 

/* 
 * Block a bunch of signals.  Call with a sigset_t pointer into which
 * the old signal set is placed.  On error (which should never happen),
 * returns NULL, otherwise returns oldset.
 */

sigset_t *__utmp_block_signals (sigset_t *oldset);

sigset_t *
__utmp_block_signals (sigset_t *oldset)
{
    sigset_t blockset;

    /* There are actually more signals to block than not, so just start
     * with everything */
    sigfillset (&blockset);

    /* Don't try to block program error signals */

    /* Unconditionally defined signals */
    sigdelset (&blockset, SIGILL);
    sigdelset (&blockset, SIGTRAP);
    sigdelset (&blockset, SIGABRT);
    sigdelset (&blockset, SIGIOT);  /* Yeah, right */
    sigdelset (&blockset, SIGFPE);
    sigdelset (&blockset, SIGSEGV);

    /* Others.  FIXME - This list may need to be expanded. */
#ifdef SIGBUS
    sigdelset (&blockset, SIGBUS);
#endif
#ifdef SIGEMT
    sigdelset (&blockset, SIGEMT);
#endif
#ifdef SIGSYS
    sigdelset (&blockset, SIGSYS);
#endif

    if (sigprocmask (SIG_BLOCK, &blockset, oldset) < 0)
	oldset = (sigset_t *)0;

    return oldset;
}
dietlibc-0.33~cvs20120325/libugly/__utmp_io.c010064400000000000000000000020371173363227000154710ustar00#include 
#include 
#include 

void *__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type);

/* type:  F_RDLCK or F_WRLCK */
void *
__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type) {
  int e, ret;
  struct flock fl;
  off_t newoffset;

  fl.l_whence	= SEEK_CUR;
  fl.l_start	= 0;
  fl.l_len	= len;
  fl.l_pid	= 0;
  fl.l_type	= type;
  
  if (fcntl(fd, F_SETLKW, &fl)) return 0;
  if (type == F_WRLCK) {
      ret = write(fd, ut, len);
      e = errno;
      fsync (fd);
      /* FIXME - where exactly should the offset point after a write? */
      newoffset = lseek (fd, 0, SEEK_CUR);
   } else {
      newoffset = lseek (fd, 0, SEEK_CUR);
      ret = read(fd, ut, len);
      e = errno;
  }

  fl.l_start	= -(len);
  fl.l_type	= F_UNLCK;

  fcntl(fd, F_SETLK, &fl);

  /* Arrrgh! There's no provision in the POSIX utmp spec for detecting errors.
   * Stupidly update the offset. */
  if (offset)
      *offset = newoffset;

  errno = e;
  if (ret != len) 
      return (void *)0;
  return ut;
}
dietlibc-0.33~cvs20120325/libugly/addmntent.c010064400000000000000000000010321173363227000154670ustar00#include 
#include 
#include 
#include 

#include 

/* FIXME: what happens with spaces/tabs/newlines in the
 * mountpoint/options/type*/

int addmntent(FILE*filep,const struct mntent*mnt) {
  struct mntent m=*mnt;
  char buf[2048];
  if (strlen(m.mnt_opts)==0) m.mnt_opts="rw";
  if (snprintf(buf,sizeof(buf),"%s %s %s %s %d %d\n",
		m.mnt_fsname,m.mnt_dir,m.mnt_type,m.mnt_opts,
		m.mnt_freq,m.mnt_passno)>=(int)sizeof(buf)) return 1;
  if (fputs(buf,filep)==EOF) return 1;
  return 0;
}

dietlibc-0.33~cvs20120325/libugly/asctime.c010064400000000000000000000001661173363227000151450ustar00#include 

static char buf[25];

char *asctime(const struct tm *timeptr) {
  return asctime_r(timeptr,buf);
}
dietlibc-0.33~cvs20120325/libugly/asctime_r.c010064400000000000000000000014021173363227000154600ustar00#include 

static const char days[] = "Sun Mon Tue Wed Thu Fri Sat ";
static const char months[] = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ";

static void num2str(char *c,int i) {
  c[0]=i/10+'0';
  c[1]=i%10+'0';
}

char *asctime_r(const struct tm *t, char *buf) {
  /* "Wed Jun 30 21:49:08 1993\n" */
  *(int*)buf=*(int*)(days+(t->tm_wday<<2));
  *(int*)(buf+4)=*(int*)(months+(t->tm_mon<<2));
  num2str(buf+8,t->tm_mday);
  if (buf[8]=='0') buf[8]=' ';
  buf[10]=' ';
  num2str(buf+11,t->tm_hour);
//  if (buf[11]=='0') buf[11]=' ';
  buf[13]=':';
  num2str(buf+14,t->tm_min);
  buf[16]=':';
  num2str(buf+17,t->tm_sec);
  buf[19]=' ';
  num2str(buf+20,(t->tm_year+1900)/100);
  num2str(buf+22,(t->tm_year+1900)%100);
  buf[24]='\n';
  return buf;
}
dietlibc-0.33~cvs20120325/libugly/asprintf.c010064400000000000000000000006001173363227000153370ustar00#include 
#include 
#include 
#include 
#include "dietwarning.h"

int asprintf(char **s, const char *format,...)
{
  int n;
  va_list arg_ptr;
  va_start(arg_ptr, format);
  n=vsnprintf(0,1000000,format,arg_ptr);
  va_start (arg_ptr, format);
  if ((*s=malloc(n+1))) {
    n=vsnprintf(*s,n+1,format,arg_ptr);
    return n;
  }
  return -1;
}
dietlibc-0.33~cvs20120325/libugly/ctime.c010064400000000000000000000001341173363227000146140ustar00#include 

char *ctime(const time_t *timep) {
  return asctime(localtime(timep));
}
dietlibc-0.33~cvs20120325/libugly/ctime_r.c010064400000000000000000000001571173363227000151420ustar00#include 

char *ctime_r(const time_t *timep, char* buf) {
  return asctime_r(localtime(timep),buf);
}
dietlibc-0.33~cvs20120325/libugly/difftime.c010064400000000000000000000003721173363227000153060ustar00#include 
#include "../dietwarning.h"

double difftime(time_t time1, time_t time2) {
    return (double)time1 - (double)time2;
}

link_warning("difftime","warning: difftime introduces an unnecessary floating point dependency. Don't use it!")
dietlibc-0.33~cvs20120325/libugly/dirfd.c010064400000000000000000000002041173363227000146010ustar00#include 
#include "dietdirent.h"
#define _BSD_SOURCE
#include 

int dirfd(DIR* dirp) {
  return dirp->fd;
}
dietlibc-0.33~cvs20120325/libugly/endmntent.c010064400000000000000000000001451173363227000155110ustar00#include 
#include 

int endmntent(FILE *filep) {
  fclose(filep);
  return 1;
}

dietlibc-0.33~cvs20120325/libugly/facilitynames.c010064400000000000000000000014241173363227000163460ustar00#include 

#ifndef INTERNAL_MARK
#define INTERNAL_MARK 0x300
#endif

CODE facilitynames[] =
  {
    { "auth", LOG_AUTH },
    { "authpriv", LOG_AUTHPRIV },
    { "cron", LOG_CRON },
    { "daemon", LOG_DAEMON },
    { "ftp", LOG_FTP },
    { "kern", LOG_KERN },
    { "lpr", LOG_LPR },
    { "mail", LOG_MAIL },
    { "mark", INTERNAL_MARK },		/* INTERNAL */
    { "news", LOG_NEWS },
    { "security", LOG_AUTH },		/* DEPRECATED */
    { "syslog", LOG_SYSLOG },
    { "user", LOG_USER },
    { "uucp", LOG_UUCP },
    { "local0", LOG_LOCAL0 },
    { "local1", LOG_LOCAL1 },
    { "local2", LOG_LOCAL2 },
    { "local3", LOG_LOCAL3 },
    { "local4", LOG_LOCAL4 },
    { "local5", LOG_LOCAL5 },
    { "local6", LOG_LOCAL6 },
    { "local7", LOG_LOCAL7 },
    { 0, -1 }
  };
dietlibc-0.33~cvs20120325/libugly/freeaddrinfo.c010064400000000000000000000002711173363227000161450ustar00#include 
#include 

void freeaddrinfo(struct addrinfo *res) {
  while (res) {
    struct addrinfo *duh;
    duh=res;
    res=res->ai_next;
    free(duh);
  }
}
dietlibc-0.33~cvs20120325/libugly/ftime.c010064400000000000000000000004711173363227000146230ustar00#include 
#include 
#include 

int ftime(struct timeb *tp) {
  struct timeval tv;
  struct timezone tz;
  int ret=gettimeofday(&tv,&tz);
  tp->time	= tv.tv_sec;
  tp->millitm	= tv.tv_usec/1000;
  tp->timezone	= tz.tz_minuteswest;
  tp->dstflag	= tz.tz_dsttime;
  return ret;
}

dietlibc-0.33~cvs20120325/libugly/gai_strerror.c010064400000000000000000000006361173363227000162240ustar00#include 

const char* gai_strerror(int error) {
  switch (error) {
  case EAI_FAMILY: return "family not supported";
  case EAI_SOCKTYPE: return "socket type not supported";
  case EAI_NONAME: return "unknown host";
  case EAI_SERVICE: return "unknown service";
  case EAI_MEMORY: return "memory allocation failure";
  case EAI_AGAIN: return "temporary failure";
  }
  return "DNS error. Sorry.";
}
dietlibc-0.33~cvs20120325/libugly/getaddrinfo.c010064400000000000000000000102661173363227000160100ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

#ifdef WANT_PLUGPLAY_DNS
extern int __dns_plugplay_interface;
#endif

/* XXX TODO FIXME */

int getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res) {
  struct addrinfo **tmp;
  int family;
  tmp=res; *res=0;
  if (hints) {
    if (hints->ai_family && hints->ai_family != PF_INET6 && hints->ai_family != PF_INET) return EAI_FAMILY;
    if (hints->ai_socktype && hints->ai_socktype != SOCK_STREAM && hints->ai_socktype != SOCK_DGRAM) return EAI_SOCKTYPE;
  }
  for (family=PF_INET6; ; family=PF_INET) {
    if (!hints || hints->ai_family==family || hints->ai_family==AF_UNSPEC) {	/* IPv6 addresses are OK */
      struct hostent h;
      struct hostent *H;
      int herrno=0;
      char buf[4096];
      int lookupok=0, i;
      char* interface;
      h.h_addr_list=(char**)buf+16;
      h.h_addr_list[1]=0;
      if (node) {
	if ((interface=strchr(node,'%'))) ++interface;
	if (family==PF_INET6 && inet_pton(AF_INET,node,buf)) continue;
	if (inet_pton(family,node,buf)>0) {
	  h.h_name=(char*)node;
	  h.h_addr_list[0]=buf;
	  lookupok=1;
	} else if ((!hints || !(hints->ai_flags&AI_NUMERICHOST)) &&
		   !gethostbyname2_r(node,family,&h,buf,4096,&H,&herrno)) {
	  lookupok=1;
	} else {
	  if (herrno==TRY_AGAIN) { freeaddrinfo(*res); return EAI_AGAIN; }
	}
      } else {
	h.h_name=0;
	h.h_addr_list[0]=buf;
	interface=0;
	memset(buf,0,16);
	if (!hints || !(hints->ai_flags&AI_PASSIVE)) {
	  if (family==AF_INET) {
	    buf[0]=127; buf[3]=1;
	  } else
	    buf[15]=1;
	}
	lookupok=1;
      }
      if (lookupok) {

	for (i=0; h.h_addr_list[i]; ++i) {
	  struct ai_v6 {
	    struct addrinfo ai;
	    union {
	      struct sockaddr_in6 ip6;
	      struct sockaddr_in ip4;
	    } ip;
	    char name[1];
	  } *foo;
	  unsigned short port;
	  int len;

	  len=sizeof(struct ai_v6)+(h.h_name?strlen(h.h_name):0);

	  if (!(foo=malloc(len))) goto error;
	  foo->ai.ai_next=0;
	  foo->ai.ai_addrlen=family==PF_INET6?sizeof(struct sockaddr_in6):sizeof(struct sockaddr_in);
	  foo->ai.ai_addr=(struct sockaddr*)&foo->ip;
	  if (family==PF_INET6) {
	    memset(&foo->ip,0,sizeof(foo->ip));
	    memmove(&foo->ip.ip6.sin6_addr,h.h_addr_list[i],16);
	    if (interface) foo->ip.ip6.sin6_scope_id=if_nametoindex(interface);
	  } else {
	    memmove(&foo->ip.ip4.sin_addr,h.h_addr_list[i],4);
	  }
	  foo->ip.ip6.sin6_family=foo->ai.ai_family=family;
#ifdef WANT_PLUGPLAY_DNS
	  if (family==AF_INET6 && node) {
	    int l=strlen(node);
	    if ((l>6 && !strcmp(node+l-6,".local")) || !strchr(node,'.'))
	      foo->ip.ip6.sin6_scope_id=__dns_plugplay_interface;
	  }
#endif
	  if (h.h_name) {
	    foo->ai.ai_canonname=foo->name;
	    memmove(foo->name,h.h_name,strlen(h.h_name)+1);
	  } else
	    foo->ai.ai_canonname=0;

	  for (foo->ai.ai_socktype=SOCK_STREAM; ; foo->ai.ai_socktype=SOCK_DGRAM) {
	    char* type,* x;
	    if (foo->ai.ai_socktype==SOCK_STREAM) {	/* TCP */
	      if (hints && hints->ai_socktype==SOCK_DGRAM) continue;
	      foo->ai.ai_protocol=IPPROTO_TCP;
	      type="tcp";
	    } else {	/* UDP */
	      if (hints && hints->ai_socktype==SOCK_STREAM) break;
	      foo->ai.ai_protocol=IPPROTO_UDP;
	      type="udp";
	    }
	    port=htons(strtol(service?service:"0",&x,0));
	    if (*x) {	/* service is not numeric :-( */
	      struct servent* se;
	      if ((se=getservbyname(service,type)))
		port=se->s_port;
	      else {
		freeaddrinfo(*res);
		return EAI_SERVICE;
	      }
	    }
	    if (family==PF_INET6)
	      foo->ip.ip6.sin6_port=port;
	    else
	      foo->ip.ip4.sin_port=port;
	    if (!*tmp) *tmp=&(foo->ai); else (*tmp)->ai_next=&(foo->ai);
	    if (!(foo=malloc(len))) goto error;
	    memmove(foo,*tmp,len);
	    tmp=&(*tmp)->ai_next;
	    foo->ai.ai_addr=(struct sockaddr*)&foo->ip;
	    if (foo->ai.ai_canonname)
	      foo->ai.ai_canonname=foo->name;
	    if (foo->ai.ai_socktype==SOCK_DGRAM) break;
	  }
	  free(foo);
	}
      }
    }
    if (family==PF_INET) break;
  }
  if (*res==0) return EAI_NONAME; /* kludge kludge... */
  return 0;
error:
  freeaddrinfo(*res);
  return EAI_MEMORY;
}
dietlibc-0.33~cvs20120325/libugly/gethostent.c010064400000000000000000000054751173363227000157140ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"

static char* hostmap;
static unsigned int hostlen;

static char *cur;

/* ::1	localhost6	alias1 alias2		# internet protocol, pseudo protocol number */
struct hostent* gethostent_r(char* buf, int len) {
  char *dest;
  struct hostent* pe=(struct hostent*)buf;
  char* last;
  char* max=buf+len;
  int aliasidx;
  if (!hostmap) {
    int hostfd=open(_PATH_HOSTS,O_RDONLY);
    if (hostfd<0) return 0;
    hostlen=lseek(hostfd,0,SEEK_END);
    hostmap=mmap(0,hostlen,PROT_READ|PROT_WRITE,MAP_PRIVATE,hostfd,0);
    if ((long)hostmap==(-1)) { close(hostfd); hostmap=0; goto error; }
    close(hostfd); hostfd=-1;
    cur=hostmap;
  }
  last=hostmap+hostlen;
again:
  if ((size_t)lenh_name=0;
  pe->h_aliases=(char**)dest; pe->h_aliases[0]=0; dest+=10*sizeof(char*);
  pe->h_addr_list=(char**)dest; dest+=2*sizeof(char**);
  if (cur>=last) return 0;
  if (*cur=='#' || *cur=='\n') goto parseerror;
  /* first, the ip number */
  pe->h_name=cur;
  while (cur=last) return 0;
  if (*cur=='\n') goto parseerror;
  {
    char save=*cur;
    *cur=0;
    pe->h_addr_list[0]=dest;
    pe->h_addr_list[1]=0;
    if (max-dest<16) goto nospace;
    if (inet_pton(AF_INET6,pe->h_name,dest)>0) {
      pe->h_addrtype=AF_INET6;
      pe->h_length=16;
      dest+=16;
    } else if (inet_pton(AF_INET,pe->h_name,dest)>0) {
      pe->h_addrtype=AF_INET;
      pe->h_length=4;
      dest+=4;
    } else {
      *cur=save;
      goto parseerror;
    }
    *cur=save;
  }
  ++cur;
  /* now the aliases */
  for (aliasidx=0;aliasidx<9;++aliasidx) {
    while (curh_aliases[aliasidx]=cur;
    while (curh_aliases[aliasidx];
      int len=cur-from;
      if (max-desth_aliases[aliasidx]=dest;
      memmove(dest,from,(size_t)(cur-from));
      dest+=len;
      *dest=0; ++dest;
    }
    if (*cur=='\n') { ++cur; ++aliasidx; break; }
    if (cur>=last || !isblank(*cur)) break;
    cur++;
  }
  pe->h_aliases[aliasidx]=0;
  pe->h_name=pe->h_aliases[0];
  pe->h_aliases++;
  return pe;
parseerror:
  while (cur

static char hostentbuf[1024];

struct hostent* gethostent() {
  return gethostent_r(hostentbuf,sizeof(hostentbuf));
}
dietlibc-0.33~cvs20120325/libugly/getmntent.c010064400000000000000000000016031173363227000155220ustar00#include 
#include 
#include 
#include 

struct mntent *getmntent(FILE *filep) {
  static struct mntent m;
  static char buf[1024];
  do {
    char *tmp=buf;
    int num;
    if (!fgets(buf,1024,filep)) return 0;
/* "/dev/ide/host0/bus0/target0/lun0/part2 / reiserfs defaults 1 1" */
    for (num=0; num<6; ++num) {
      switch (num) {
      case 0: m.mnt_fsname=tmp; break;
      case 1: m.mnt_dir=tmp; break;
      case 2: m.mnt_type=tmp; break;
      case 3: m.mnt_opts=tmp; break;
      case 4: m.mnt_freq=strtol(tmp,&tmp,0); if (*tmp!=' ' && *tmp!='\t') continue; break;
      case 5: m.mnt_passno=strtol(tmp,&tmp,0); if (*tmp=='\n') return &m; break;
      }
      while (*tmp && *tmp!=' ' && *tmp!='\n' && *tmp!='\t') ++tmp;
      if (*tmp) {
	if (num<4) *tmp++=0;
	while (*tmp==' ' || *tmp=='\t') ++tmp;
      } else
	continue;
    }
  } while (1);
}
dietlibc-0.33~cvs20120325/libugly/getnameinfo.c010064400000000000000000000027261173363227000160200ustar00#include 
#include 
#include 
#include 
#include 
#include 

int getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host,
		size_t hostlen, char *serv, size_t servlen, int flags) {
  sa_family_t f=((struct sockaddr_storage *)sa)->ss_family;
  (void)salen;	/* shut gcc up about unused salen */
  if (host && hostlen>0) {	/* user wants me to resolve the host name */
    register const char*addr=(f==AF_INET6)?(char*)&((struct sockaddr_in6*)sa)->sin6_addr:
					   (char*)&((struct sockaddr_in*)sa)->sin_addr;
    if (flags&NI_NUMERICHOST) {
      if (!inet_ntop(f,addr,host,hostlen))
	return EAI_NONAME;
    } else {
      char buf[4096];
      struct hostent h;
      struct hostent *H;
      int herrno;
      if (gethostbyaddr_r(addr,f==AF_INET6?16:4,f,&h,buf,4096,&H,&herrno)) {
	switch (herrno) {
	case TRY_AGAIN: return EAI_AGAIN;
	case NO_DATA:
	case HOST_NOT_FOUND: return EAI_NONAME;
	}
      }
      strncpy(host,h.h_name,hostlen-1);
      host[hostlen-1]=0;
    }
  }
  if (serv && servlen>0) {
    register short int port=(f==AF_INET6)?((struct sockaddr_in6*)sa)->sin6_port:((struct sockaddr_in*)sa)->sin_port;
    if (flags&NI_NUMERICSERV) {
      __ltostr(serv,servlen,ntohs(port),10,0);
    } else {
      struct servent *s;
      if (!(s=getservbyport(port,flags&NI_DGRAM?"udp":"tcp")))
	return EAI_SERVICE;
      strncpy(serv,s->s_name,servlen-1);
      serv[servlen-1]=0;
    }
  }
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/getprotobyname.c010064400000000000000000000004661173363227000165620ustar00#include 
#include 

extern struct protoent __protoent_pw;
extern char __protoent_buf[1000];

struct protoent *getprotobyname(const char *name) {
  struct protoent* tmp;
  if (getprotobyname_r(name,&__protoent_pw,__protoent_buf,sizeof(__protoent_buf),&tmp)==0)
    return tmp;
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/getprotobyname_r.c010064400000000000000000000006771173363227000171070ustar00#include 
#include 

extern int getprotobyname_r(const char* name,
			    struct protoent *res, char *buf, size_t buflen,
			    struct protoent **res_sig) {
  while (!getprotoent_r(res,buf,buflen,res_sig)) {
    int i;
    if (!strcmp(res->p_name,name)) goto found;
    for (i=0; res->p_aliases[i]; ++i)
      if (!strcmp(res->p_aliases[i],name)) goto found;
  }
  *res_sig=0;
found:
  endprotoent();
  return *res_sig?0:-1;
}
dietlibc-0.33~cvs20120325/libugly/getprotobynumber.c010064400000000000000000000004641173363227000171300ustar00#include 
#include 

extern struct protoent __protoent_pw;
extern char __protoent_buf[1000];

struct protoent *getprotobynumber(int proto) {
  struct protoent* tmp;
  if (getprotobynumber_r(proto,&__protoent_pw,__protoent_buf,sizeof(__protoent_buf),&tmp)==0)
    return tmp;
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/getprotobynumber_r.c010064400000000000000000000005041173363227000174440ustar00#include 
#include 

extern int getprotobynumber_r(int proto,
			   struct protoent *res, char *buf, size_t buflen,
			   struct protoent **res_sig) {
  while (!getprotoent_r(res,buf,buflen,res_sig))
    if (proto==res->p_proto) goto found;
  *res_sig=0;
found:
  endprotoent();
  return *res_sig?0:-1;
}
dietlibc-0.33~cvs20120325/libugly/getprotoent.c010064400000000000000000000003661173363227000160740ustar00#include 

extern struct protoent __protoent_pw;
extern char __protoent_buf[1000];

struct protoent *getprotoent(void) {
  struct protoent* tmp;
  getprotoent_r(&__protoent_pw,__protoent_buf,sizeof(__protoent_buf),&tmp);
  return tmp;
}
dietlibc-0.33~cvs20120325/libugly/getprotoent_r.c010064400000000000000000000034301173363227000164100ustar00#include 
#include 
#include 
#include 
#include 
#include "parselib.h"

static struct state __ps;

void setprotoent(int stayopen) {
  (void)stayopen;
  __prepare_parse(_PATH_PROTOCOLS,&__ps);
}

void endprotoent(void) {
  __end_parse(&__ps);
}

#define ALIASES 16

/* "igmp	2	IGMP		# internet group management protocol" */
int getprotoent_r(struct protoent *res, char *buf, size_t buflen,
		  struct protoent **res_sig) {
  size_t i,j,n,g;
  unsigned long l;
  if (!__ps.buffirst) setprotoent(0);
  if (!__ps.buffirst) goto error;
  if (__ps.cur>=__ps.buflen) goto error;
  res->p_aliases=(char**)buf;
/*  getprotoent */
again:
  n=ALIASES*sizeof(char*); g=0;
  for (i=0; i<3; ++i) {
    char found;
    __ps.cur+=__parse_ws(&__ps);
    if (__ps.cur>=__ps.buflen) { if (i==2) break; else goto error; }
    j=__parse_nws(&__ps);
    if (!isblank(found=__ps.buffirst[__ps.cur+j])) {
      if (i==2) break;	/* it's ok, no (more) aliases necessary */
parseerror:
      while (__ps.cur+j<__ps.buflen) {
	if (__ps.buffirst[__ps.cur+j]=='\n') {
	  __ps.cur+=j+1;
	  goto again;
	}
	++j;
      }
    }
    switch (i) {
    case 0:
      res->p_name=buf+n;
copy:
      if ((size_t)buflen<=n+j) goto error;
      memcpy(buf+n,__ps.buffirst+__ps.cur,j);
      buf[n+j]=0;
      n+=j+1;
      if ((found=='\n' || found=='#') && i==1) i=3;
      break;
    case 1:
      if (scan_ulong(__ps.buffirst+__ps.cur,&l)!=j) goto parseerror;
      res->p_proto=l;
      break;
    case 2:
      res->p_aliases[g]=buf+n;
      ++g;
      if (g==(ALIASES-1)) break;
      --i;	/* again */
      goto copy;
    }
    __ps.cur+=j+1;
  }
  res->p_aliases[g]=0;
  *res_sig=res;
  return 0;
error:
  *res_sig=0;/* the glibc people should be taken behind the barn and shot */
  return -1;
}
dietlibc-0.33~cvs20120325/libugly/getservbyname.c010064400000000000000000000005051173363227000163700ustar00#include 
#include 

extern struct servent __servent_pw;
extern char __servent_buf[1000];

struct servent *getservbyname(const char *name, const char *proto) {
  struct servent* tmp;
  if (getservbyname_r(name,proto,&__servent_pw,__servent_buf,sizeof(__servent_buf),&tmp)==0)
    return tmp;
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/getservbyname_r.c010064400000000000000000000010011173363227000167010ustar00#include 
#include 

extern int getservbyname_r(const char* name,const char* proto,
			   struct servent *res, char *buf, size_t buflen,
			   struct servent **res_sig) {
  while (!getservent_r(res,buf,buflen,res_sig)) {
    int i;
    if (proto && strcmp(res->s_proto,proto)) continue;
    if (!strcmp(res->s_name,name)) goto found;
    for (i=0; res->s_aliases[i]; ++i)
      if (!strcmp(res->s_aliases[i],name)) goto found;
  }
  *res_sig=0;
found:
  endservent();
  return *res_sig?0:-1;
}
dietlibc-0.33~cvs20120325/libugly/getservbyport.c010064400000000000000000000004751173363227000164420ustar00#include 
#include 

extern struct servent __servent_pw;
extern char __servent_buf[1000];

struct servent *getservbyport(int port, const char *proto) {
  struct servent* tmp;
  if (getservbyport_r(port,proto,&__servent_pw,__servent_buf,sizeof(__servent_buf),&tmp)==0)
    return tmp;
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/getservbyport_r.c010064400000000000000000000005451173363227000167610ustar00#include 
#include 

extern int getservbyport_r(int port,const char* proto,
			   struct servent *res, char *buf, size_t buflen,
			   struct servent **res_sig) {
  while (!getservent_r(res,buf,buflen,res_sig))
    if (port==res->s_port && !strcmp(res->s_proto,proto)) goto ok;
  *res_sig=0;
ok:
  endservent();
  return *res_sig?0:-1;
}
dietlibc-0.33~cvs20120325/libugly/getservent.c010064400000000000000000000003541173363227000157050ustar00#include 

extern struct servent __servent_pw;
extern char __servent_buf[1000];

struct servent *getservent(void) {
  struct servent* tmp;
  getservent_r(&__servent_pw,__servent_buf,sizeof(__servent_buf),&tmp);
  return tmp;
}
dietlibc-0.33~cvs20120325/libugly/getservent_r.c010064400000000000000000000037241173363227000162320ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include "parselib.h"

static struct state __ps;

void setservent(int stayopen) {
  (void)stayopen;
  __prepare_parse(_PATH_SERVICES,&__ps);
}

void endservent(void) {
  __end_parse(&__ps);
}

#define ALIASES 16

/* "tcpmux		1/tcp		# TCP port multiplexer (RFC1078)" */
int getservent_r(struct servent *res, char *buf, size_t buflen,
		 struct servent **res_sig) {
  size_t i,j,n,g;
  unsigned long l;
  if (!__ps.buffirst) setservent(0);
  if (!__ps.buffirst) goto error;
  if (__ps.cur>=__ps.buflen) goto error;
  res->s_aliases=(char**)buf;
/*  getservent */
again:
  n=ALIASES*sizeof(char*); g=0;
  for (i=0; i<3; ++i) {
    char found;
    __ps.cur+=__parse_ws(&__ps);
    if (__ps.cur>=__ps.buflen) { if (i==2) break; else goto error; }
    j=__parse_nws(&__ps);
    if (!isblank(found=__ps.buffirst[__ps.cur+j])) {
      if (i==2 && found=='#') break;
      if (found=='#' || (i>1 && found!='\n')) {
parseerror:
	while (__ps.cur+j<__ps.buflen) {
	  if (__ps.buffirst[__ps.cur+j]=='\n') {
	    __ps.cur+=j+1;
	    goto again;
	  }
	  ++j;
	}
	goto error;
      }
    }
    switch (i) {
    case 0:
      res->s_name=buf+n;
copy:
      if (!j) goto parseerror;
      if ((size_t)buflen<=n+j) goto error;
      memcpy(buf+n,__ps.buffirst+__ps.cur,j);
      buf[n+j]=0;
      n+=j+1;
      if ((found=='\n' || found=='#') && i==1) i=3;
      break;
    case 1:
      {
	int k;
	k=scan_ulong(__ps.buffirst+__ps.cur,&l);
	if (__ps.buffirst[__ps.cur+k]!='/') {
	  goto parseerror;
	}
	res->s_port=htons(l);
	res->s_proto=buf+n;
	j-=k+1; __ps.cur+=k+1;
	goto copy;
      }
    case 2:
      res->s_aliases[g]=buf+n;
      ++g;
      if (g==(ALIASES-1)) break;
      --i;	/* again */
      goto copy;
    }
    __ps.cur+=j+1;
  }
  res->s_aliases[g]=0;
  *res_sig=res;
  return 0;
error:
  *res_sig=0;/* the glibc people should be taken behind the barn and shot */
  return -1;
}
dietlibc-0.33~cvs20120325/libugly/gmtime.c010064400000000000000000000001551173363227000150000ustar00#include 

struct tm* gmtime(const time_t *t) {
  static struct tm tmp;
  return gmtime_r(t,&tmp);
}
dietlibc-0.33~cvs20120325/libugly/gmtime_r.c010064400000000000000000000012601173363227000153170ustar00#include 

/* seconds per day */
#define SPD 24*60*60

extern short __spm[];

struct tm *gmtime_r(const time_t *timep, struct tm *r) {
  time_t i;
  register time_t work=*timep%(SPD);
  r->tm_sec=work%60; work/=60;
  r->tm_min=work%60; r->tm_hour=work/60;
  work=*timep/(SPD);
  r->tm_wday=(4+work)%7;
  for (i=1970; ; ++i) {
    register time_t k=__isleap(i)?366:365;
    if (work>=k)
      work-=k;
    else
      break;
  }
  r->tm_year=i-1900;
  r->tm_yday=work;

  r->tm_mday=1;
  if (__isleap(i) && (work>58)) {
    if (work==59) r->tm_mday=2; /* 29.2. */
    work-=1;
  }

  for (i=11; i && (__spm[i]>work); --i) ;
  r->tm_mon=i;
  r->tm_mday+=work-__spm[i];
  return r;
}
dietlibc-0.33~cvs20120325/libugly/grantpt.c010064400000000000000000000004421173363227000151740ustar00#define _XOPEN_SOURCE
#include 
#include 
#include 
#include 

int grantpt (int fd) {
  struct stat st;
  if ((fstat(fd, &st))<0) return -1;
  if ((chmod((char*)ptsname(fd), st.st_mode | S_IRUSR | S_IWUSR | S_IWGRP))<0)
    return -1;
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/hasmntopt.c010064400000000000000000000005521173363227000155340ustar00#include 
#include 

char *hasmntopt(const struct mntent *mnt, const char *opt) {
  char *s=mnt->mnt_opts;
  char *c;
  int len=strlen(opt);
  if (!s) return 0;
  for (c=s;;) {
    if (!(c=strstr(c,opt))) break;
    if (c==s || c[-1]==',') {
      if (c[len]==0 || c[len]==',' || c[len]=='=')
	return c;
    }
    c+=len+1;
  }
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/iconv.c010064400000000000000000000105141173363227000146340ustar00#include "dietfeatures.h"
#include 
#include "dieticonv.h"
#include 

static unsigned int utf8bounds[]={0x7f,0x7ff,0xffff,0x1fffff,0x3ffffff,0x7fffffff};

size_t iconv(iconv_t cd, char* * inbuf, size_t *
		    inbytesleft, char* * outbuf, size_t * outbytesleft) {
  size_t result=0,i,j,k;
  int bits;
  unsigned char* in,* out;
  enum charset from=ic_from(cd);
  enum charset to=ic_to(cd);
  if (!inbuf || !*inbuf) return 0;
  in=(unsigned char*)(*inbuf);
  out=(unsigned char*)(*outbuf);
  k=0;
  while (*inbytesleft) {
    unsigned int v;
    v=*in;
    i=j=1;
    switch (from) {
    case UCS_2:
      if (*inbytesleft<2) {
starve:
	errno=EINVAL;
	return (size_t)-1;
      }
      v=(((unsigned long)in[0])<<8) |
        ((unsigned long)in[1]);
      i=2;
      break;
    case UCS_4:
      if (*inbytesleft<4) goto starve;
      v=(((unsigned long)in[0])<<24) |
        (((unsigned long)in[1])<<16) |
        (((unsigned long)in[2])<<8) |
        ((unsigned long)in[3]);
      i=4;
    case ISO_8859_1:
      break;
    case UTF_8:
      if (!(v&0x80)) break;
      if (v>=0xfe) goto ABEND;
      for (i=0xC0; i!=0xFC; i=(i>>1)+0x80)
	if ((v&((i>>1)|0x80))==i) {
	  v&=~i;
	  break;
	}
      for (i=1; (in[i]&0xc0)==0x80; ++i) {
	if (i>*inbytesleft) goto starve;
	v=(v<<6)|(in[i]&0x3f);
      }
      /* reject chars not encoded the most efficient way */
      if (i>6 || (i>1 && v=0xd800 && v<=0xdfff) {
	long w;
	if (v>0xdbff) goto ABEND;
	if (*inbytesleft<4) goto starve;
	if (from==UTF_16_BE)
	  w=((unsigned long)in[2]<<8) | in[3];
	else
	  w=((unsigned long)in[3]<<8) | in[2];
	if (w<0xdc00 || w>0xdfff) goto ABEND;
	v=0x10000+(((v-0xd800) << 10) | (w-0xdc00));
	i=4;
      }
      break;
    case UTF_16_LE:
utf16le:
      v=((unsigned long)in[1]<<8) | in[0];
      goto joined;
    }
    if (v>=0xd800 && v<=0xd8ff) goto ABEND;	/* yuck!  in-band signalling! */
    switch (to) {
    case ISO_8859_1:
      if (*outbytesleft<1) goto bloat;
      if (v>0xff) ++result;
      *out=(unsigned char)v;
      break;
    case UCS_2:
      if (*outbytesleft<2) goto bloat;
      if (v>0xffff) ++result;
      out[0]=v>>8;
      out[1]=v&0xff;
      j=2;
      break;
    case UCS_4:
      if (*outbytesleft<4) goto bloat;
      out[0]=(v>>23)&0xff;
      out[1]=(v>>16)&0xff;
      out[2]=(v>>8)&0xff;
      out[3]=v&0xff;
      j=4;
      break;
    case UTF_8:
      if (v>=0x04000000) { bits=30; *out=0xFC; j=6; } else
      if (v>=0x00200000) { bits=24; *out=0xF8; j=5; } else
      if (v>=0x00010000) { bits=18; *out=0xF0; j=4; } else
      if (v>=0x00000800) { bits=12; *out=0xE0; j=3; } else
      if (v>=0x00000080) { bits=6; *out=0xC0; j=2; } else
			{ bits=0; *out=0; }
      *out|= (unsigned char)(v>>bits);
      if (*outbytesleft>bits)&0x3F);
      }
      break;
    case UTF_16:
      if (*outbytesleft<4) goto bloat;
      to=UTF_16_LE;
      out[0]=0xff;
      out[1]=0xfe;
      out+=2; *outbytesleft-=2;
    case UTF_16_LE:
      if (v>0xffff) {
	long a,b;
	if (*outbytesleft<(j=4)) goto bloat;
	v-=0x10000;
	if (v>0xfffff) result++;
	a=0xd800+(v>>10); b=0xdc00+(v&0x3ff);
	out[1]=a>>8;
	out[0]=a&0xff;
	out[3]=b>>8;
	out[2]=b&0xff;
      } else {
	if (*outbytesleft<(j=2)) goto bloat;
	out[1]=(v>>8)&0xff;
	out[0]=v&0xff;
      }
      break;
    case UTF_16_BE:
      if (v>0xffff) {
	long a,b;
	if (*outbytesleft<(j=4)) goto bloat;
	v-=0x10000;
	if (v>0xfffff) result++;
	a=0xd800+(v>>10); b=0xdc00+(v&0x3ff);
	out[0]=a>>8;
	out[1]=a&0xff;
	out[2]=b>>8;
	out[3]=b&0xff;
      } else {
	if (*outbytesleft<(j=2)) goto bloat;
	out[0]=(v>>8)&0xff;
	out[1]=v&0xff;
      }
      break;
    }
    in+=i; *inbytesleft-=i;
    out+=j; *outbytesleft-=j;
  }
  *inbuf=(char*)in; *outbuf=(char*)out;
  return result;
}
dietlibc-0.33~cvs20120325/libugly/iconv_close.c010064400000000000000000000002061173363227000160160ustar00#include 
#include "dieticonv.h"

int iconv_close(iconv_t cd) {
  (void)cd;	/* shut gcc up about unused cd */
  return 0;
}
dietlibc-0.33~cvs20120325/libugly/iconv_open.c010064400000000000000000000016521173363227000156600ustar00#include 
#include 
#include "dietfeatures.h"
#include 
#include 
#include "dieticonv.h"

static enum charset parsecharset(const char* s) {
  if (!strcasecmp(s,"UTF-8")) return UTF_8; else
  if (!strcasecmp(s,"UCS-2") || !strcasecmp(s,"UCS2")) return UCS_2; else
  if (!strcasecmp(s,"UCS-4") || !strcasecmp(s,"UCS4")) return UCS_4; else
  if (!strcasecmp(s,"ISO-8859-1") || !strcasecmp(s,"LATIN1")) return ISO_8859_1; else
  if (!strcasecmp(s,"US-ASCII")) return ISO_8859_1; else
  if (!strcasecmp(s,"UTF-16")) return UTF_16; else
  if (!strcasecmp(s,"UTF-16BE")) return UTF_16_BE; else
  if (!strcasecmp(s,"UTF-16LE")) return UTF_16_LE; else
  return INVALID;
}

iconv_t iconv_open(const char* tocode, const char* fromcode) {
  int f,t;

  f=parsecharset(fromcode);
  t=parsecharset(tocode);

  if (f==INVALID || t==INVALID) {
    errno=EINVAL;
    return (iconv_t)(-1);
  }
  return (f|t<<16);
}
dietlibc-0.33~cvs20120325/libugly/isleap.c010064400000000000000000000004201173363227000147660ustar00#include 

int __isleap(int year) {
  /* every fourth year is a leap year except for century years that are
   * not divisible by 400. */
/*  return (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); */
  return (!(year%4) && ((year%100) || !(year%400)));
}
dietlibc-0.33~cvs20120325/libugly/iswctype.c010064400000000000000000000001471173363227000153660ustar00#include 
#include 

int iswctype(wint_t wc, wctype_t desc) {
  return desc(wc);
}
dietlibc-0.33~cvs20120325/libugly/localtime.c010064400000000000000000000001631173363227000154660ustar00#include 

struct tm* localtime(const time_t* t) {
  static struct tm tmp;
  return localtime_r(t,&tmp);
}
dietlibc-0.33~cvs20120325/libugly/localtime_r.c010064400000000000000000000010431173363227000160050ustar00#include "dietfeatures.h"
#include 
#include 

#ifdef WANT_TZFILE_PARSER
extern void __maplocaltime(void);
extern time_t __tzfile_map(time_t t, int *isdst, int forward);
#else
extern long int timezone;
extern int daylight;
#endif

struct tm* localtime_r(const time_t* t, struct tm* r) {
  time_t tmp;
#ifdef WANT_TZFILE_PARSER
  __maplocaltime();
  tmp=__tzfile_map(*t,&r->tm_isdst,1);
#else
  struct timezone tz;
  gettimeofday(0, &tz);
  timezone=tz.tz_minuteswest*60L;
  tmp=*t+timezone;
#endif
  return gmtime_r(&tmp,r);
}
dietlibc-0.33~cvs20120325/libugly/logging.c010064400000000000000000000136301173363227000151460ustar00#include 
#include "dietfeatures.h"

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define _PATH_CONSOLE	"/dev/console"
#define BUF_SIZE 2048	/* messagebuffer size (>= 200) */

#define MAX_LOGTAG 1000

/* declare internal functions */
int __libc_open(const char*name,int flags, ...);
ssize_t __libc_write(int fd,void*buf,size_t len);
int __libc_fcntl(int fd,int op,...);
int __libc_close(int fd);

/* those have to be global *sigh* */
static volatile int	connected;	/* have done connect */
static volatile int	LogMask = 0xff; /* mask of priorities to be logged */
static char		LogTag[MAX_LOGTAG];	/* string to tag the entry with */
static int		LogFile = -1;   /* fd for log */
static int		LogType = SOCK_DGRAM; /* type of socket connection */
static int		LogFacility = LOG_USER; /* default facility code */
static int		LogStat;	/* status bits, set by openlog() */
extern char		*__progname;	/* Program name, from crt0. */
static struct sockaddr	SyslogAddr;	/* AF_UNIX address of local logger */

static void closelog_intern(void)
{
  if (!connected) return;
  __libc_close(LogFile);
  LogFile = -1;
  connected = 0;
}

void __libc_closelog(void);
void __libc_closelog(void)
{
  closelog_intern();

  LogTag[0]=0;
  LogType = SOCK_DGRAM;
}
void closelog(void) __attribute__((weak,alias("__libc_closelog")));

static void openlog_intern(int option, int facility)
{
  LogStat = option;
  if (facility && ((facility & ~LOG_FACMASK) == 0))
    LogFacility = facility;

  /* yep, there is a continue inside ;) */
  while(1) {
    if (LogFile == -1) {
      SyslogAddr.sa_family = AF_UNIX;
      strncpy(SyslogAddr.sa_data, _PATH_LOG, sizeof(SyslogAddr.sa_data));
      if (LogStat & LOG_NDELAY)
      {
	if ((LogFile = socket(AF_UNIX, LogType, 0)) == -1) return;
	__libc_fcntl(LogFile, F_SETFD, 1);
      }
    }
    if ((LogFile != -1) && !connected) {
      int old_errno=errno;
      if(connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) {
	int saved_errno=errno;
	__libc_close(LogFile);
	LogFile = -1;
	if((LogType == SOCK_DGRAM) && (saved_errno == EPROTOTYPE)) {
	  /* retry with SOCK_STREAM instead of SOCK_DGRAM */
	  LogType = SOCK_STREAM;
	  errno=old_errno;
	  continue;
	}
      }
      else connected = 1;
    }
    break;
  }
}

/* has to be secured against multiple, simultanious call's in threaded environment */
void __libc_openlog(const char *ident, int option, int facility);
void __libc_openlog(const char *ident, int option, int facility)
{
  if (ident) {
    strncpy(LogTag,ident,MAX_LOGTAG);
    LogTag[MAX_LOGTAG-1]=0;
  }
  openlog_intern(option, facility);
}
void openlog(const char *ident, int option, int facility) __attribute__((weak,alias("__libc_openlog")));

int setlogmask(int mask)
{
  int old = LogMask;
  if (mask) LogMask = mask;
  return old;
}

void __libc_vsyslog(int priority, const char *format, va_list arg_ptr);
void __libc_vsyslog(int priority, const char *format, va_list arg_ptr)
{
  char buffer[BUF_SIZE];
  char time_buf[20];
  int buflen, headerlen;
  time_t now;
  struct tm now_tm;
  pid_t pid;
  int fd;
  int sigpipe;
  struct sigaction action, oldaction;
  struct sigaction *oldaction_ptr = NULL;
  int saved_errno = errno;

  /* check for invalid priority/facility bits */
  if (priority & ~(LOG_PRIMASK|LOG_FACMASK)) {
    syslog(LOG_ERR|LOG_CONS|LOG_PERROR|LOG_PID, "syslog: unknown facility/priorityority: %x", priority);
    priority &= LOG_PRIMASK|LOG_FACMASK;
  }

  /* check priority against setlogmask */
  if ((LOG_MASK(LOG_PRI(priority)) && LogMask) == 0) return;

  /* Set default facility if none specified. */
  if ((priority & LOG_FACMASK) == 0) priority |= LogFacility;

  pid = getpid();
  time(&now);
  strftime(time_buf, 20, "%h %e %T", localtime_r (&now, &now_tm));

  if (LogStat & LOG_PID)
    headerlen = snprintf(buffer, 130, "<%d>%s %s[%ld]: ", priority, time_buf, LogTag, (long) pid);
  else
    headerlen = snprintf(buffer, 130, "<%d>%s %s: ", priority, time_buf, LogTag);

  if (!LogTag[0]) {
    if ((LogStat & LOG_PID) != LOG_PID)
      headerlen = snprintf(buffer, 130, "<%d>%s (unknown)[%ld]: ", priority, time_buf, (long) pid);
    strcat(buffer+headerlen, "syslog without openlog w/ ident, please check code!");
    buflen = 41;
  }
  else {
    errno=saved_errno;
    buflen = vsnprintf(buffer+headerlen, BUF_SIZE - headerlen, format, arg_ptr);
  }
  if (LogStat & LOG_PERROR) {
    __libc_write(1, buffer+headerlen, buflen);
    if (buffer[headerlen+buflen] != '\n') __libc_write(1,"\n", 1);
  }

  /* prepare for broken connection */
  memset(&action, 0, sizeof(action));
  action.sa_handler = SIG_IGN;
  sigemptyset(&action.sa_mask);

  if ((sigpipe = sigaction (SIGPIPE, &action, &oldaction))==0)
    oldaction_ptr = &oldaction;

  if (!connected) openlog_intern(LogStat | LOG_NDELAY, 0);

  /* If we have a SOCK_STREAM connection, also send ASCII NUL as a
   * record terminator. */
  if (LogType == SOCK_STREAM) buflen++;

  if (!connected || (send(LogFile, buffer, buflen+headerlen, 0) != buflen+headerlen)) {
    if (LogType == SOCK_STREAM) buflen--;
    closelog_intern();
    /*
     * Output the message to the console; don't worry about blocking,
     * if console blocks everything will.  Make sure the error reported
     * is the one from the syslogd failure.
     */
    if ((LogStat & LOG_CONS) &&
       ((fd = __libc_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY, 0)) >= 0))
    {
      __libc_write(fd, buffer, buflen+headerlen);
      __libc_write(fd, "\r\n", 2);
      __libc_close(fd);
    }
  }

  if (sigpipe == 0)
    sigaction(SIGPIPE, &oldaction, (struct sigaction *) NULL);
}
void vsyslog(int priority, const char *format, va_list arg_ptr) __attribute__((weak,alias("__libc_vsyslog")));

void syslog(int priority, const char *format, ...)
{
  va_list arg_ptr;
  va_start(arg_ptr, format);
  vsyslog(priority, format, arg_ptr);
  va_end(arg_ptr);
}
dietlibc-0.33~cvs20120325/libugly/mktime.c010064400000000000000000000012661173363227000150100ustar00#define _GNU_SOURCE
#include 
#undef __attribute_dontuse__
#define __attribute_dontuse__
#include 
#include "dietfeatures.h"

#ifdef WANT_TZFILE_PARSER
extern void __maplocaltime(void);
extern time_t __tzfile_map(time_t t, int *isdst, int forward);
#else
extern long int timezone;
extern int daylight;
#endif

time_t mktime(register struct tm* const t) {
  time_t x=timegm(t);
#ifdef WANT_TZFILE_PARSER
  int isdst;
  time_t y;
  __maplocaltime();
  x=__tzfile_map(x,&isdst,0);
#else
  struct timezone tz;
  gettimeofday(0, &tz);
  timezone=tz.tz_minuteswest*60L;
  x+=timezone;
#endif
  return x;
}

time_t timelocal(struct tm* const t) __attribute__((alias("mktime")));

dietlibc-0.33~cvs20120325/libugly/netent.c010064400000000000000000000056721173363227000150240ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include "dietfeatures.h"
#include 
#include 

static int netfd=-1;
static char* netmap;
static unsigned int netlen;

static char* aliases[10];

static char *cur;

/* loopback	127.0.0.0	lo	# comment */
struct netent *getnetent(void) {
  static struct netent ne;
  char *last;
  int aliasidx;
  if (netfd<0) {
    netfd=open(_PATH_NETWORKS,O_RDONLY);
    if (netfd<0) return 0;
    fcntl (netfd, F_SETFD, FD_CLOEXEC);
    netlen=lseek(netfd,0,SEEK_END);
    netmap=mmap(0,netlen,PROT_READ|PROT_WRITE,MAP_PRIVATE,netfd,0);
    if ((long)netmap==(-1)) goto error;
    cur=netmap;
  }
  last=netmap+netlen;
again:
  ne.n_name=0;
  ne.n_aliases=aliases; aliases[0]=0;
  ne.n_addrtype=AF_INET;
  ne.n_net=0;
  if (cur>=last) return 0;
  if (*cur=='#' || *cur=='\n') goto parseerror;
  /* first, the primary name */
  if (!isalpha(*cur)) goto parseerror;
  ne.n_name=cur;
  ne.n_aliases=aliases;
  while (cur=last) return 0;
  if (*cur=='\n') goto parseerror;
  *cur=0; cur++;
  /* second, the ip */
  while (cur=last) return 0;
  /* now the aliases */
  for (aliasidx=0;aliasidx<10;++aliasidx) {
    while (cur=last || !isblank(*cur)) break;
    *cur++=0;
  }
  aliases[aliasidx]=0;
  return ≠
parseerror:
  while (curn_net && type==s->n_addrtype)
      return s;
  }
  return 0;
}

void endnetent(void) {
  if (netmap!=(char*)-1) munmap(netmap,netlen);
  if (netfd!=-1) close(netfd);
  netmap=(char*)-1;
  netfd=-1;
}

void setnetent(int stayopen) {
  (void)stayopen;
  endnetent();
}

struct netent *getnetbyname(const char *name) {
  struct netent *s;
  setnetent(0);
  for (s=getnetent(); s; s=getnetent()) {
    char **tmp;
#if 0
    write(1,"found ",6);
    write(1,s->s_name,strlen(s->s_name));
    write(1,"/",1);
    write(1,s->s_proto,strlen(s->s_proto));
    write(1,"\n",1);
    if (!strcmp(s->s_name,"ssh")) {
      write(2,"ssh!\n",5);
    }
#endif
    if (!strcmp(name,s->n_name))
      return s;
    tmp=s->n_aliases;
    while (*tmp)
      if (!strcmp(name,*tmp++)) return s;
  }
  return 0;
}

dietlibc-0.33~cvs20120325/libugly/openpty.c010064400000000000000000000033171173363227000152170ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int openpty(int *amaster, int *aslave, char *name, struct termios
	    *termp, struct winsize *winp) {
  int fd;
  char buf[20];
#if 0
  This is what glibc does:
  open("/dev/ptmx", O_RDWR)               = 4
  statfs("/dev/pts", {f_type=0x1cd1, f_bsize=1024, f_blocks=0, f_bfree=0, f_files=0, f_ffree=0, f_namelen=255}) = 0
  ioctl(4, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  ioctl(4, 0x80045430, [0])               = 0
  stat("/dev/pts/0", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
  statfs("/dev/pts/0", {f_type=0x1cd1, f_bsize=1024, f_blocks=0, f_bfree=0, f_files=0, f_ffree=0, f_namelen=255}) = 0
  ioctl(4, 0x40045431, [0])               = 0
  ioctl(4, TCGETS, {B38400 opost isig icanon echo ...}) = 0
  ioctl(4, 0x80045430, [0])               = 0
  stat("/dev/pts/0", {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
  open("/dev/pts/0", O_RDWR|O_NOCTTY)     = 5
#endif
  if ((fd=open("/dev/ptmx",O_RDWR))<0) return -1;
#if 0
  if (ioctl(fd,TCGETS,&ts)<0) goto kaputt;
#endif
  {
    int unlock=0;
    while (ioctl(fd,TIOCSPTLCK, &unlock)<0) if (errno!=EINTR) goto kaputt;
  }
  {
    int ptyno;
    while (ioctl(fd,TIOCGPTN,&ptyno)<0) if (errno!=EINTR) goto kaputt;
    strcpy(buf,"/dev/pts/");
    __ltostr(buf+9,10,ptyno,10,0);
  }
  *aslave=open(buf,O_RDWR|O_NOCTTY);
  if (*aslave<0) goto kaputt;
  *amaster=fd;
  if (name) strcpy(name,buf);
  if (termp)
    while (tcsetattr(*aslave,TCSAFLUSH,termp) && errno==EINTR);
  if (winp) while (ioctl(*aslave, TIOCSWINSZ, winp) && errno==EINTR);
  return 0;
kaputt:
  close(fd);
  return -1;
}
dietlibc-0.33~cvs20120325/libugly/pclose.c010064400000000000000000000003261173363227000150030ustar00#include 
#include 
#include "dietstdio.h"

int pclose(FILE *f) {
  int status;
  pid_t pid=f->popen_kludge;
  fclose(f);
  if (waitpid(pid,&status,0)>=0)
    return status;
  return -1;
}
dietlibc-0.33~cvs20120325/libugly/popen.c010064400000000000000000000013311173363227000146340ustar00#include "dietstdio.h"
#include 
#include 
#include "binshstr.h"

extern char **environ;

FILE *popen(const char *command, const char *type) {
  int pfd[2];
  int fd0;
  FILE* f;
  pid_t pid;

  if (pipe(pfd)<0) return 0;
  fd0=(*type=='r');
  if ((!(f=fdopen(pfd[!fd0],type))) ||
      ((pid=fork())<0)) {
    close(pfd[0]);	/* malloc failed */
    close(pfd[1]);
    return 0;
  }
  if (!pid) {	/* child */
    const char *argv[]={__sh,"-c",0,0};
    close(pfd[!fd0]); close(fd0);
    dup2(pfd[fd0],fd0); close(pfd[fd0]);
    argv[2]=command;
    execve(__binsh,(char*const*)argv,environ);
    _exit(127);
  }
  close(pfd[fd0]);
  fcntl (pfd[!fd0], F_SETFD, FD_CLOEXEC);
  f->popen_kludge=pid;
  return f;
}
dietlibc-0.33~cvs20120325/libugly/prioritynames.c010064400000000000000000000010311173363227000164150ustar00#include 

#ifndef INTERNAL_NOPRI
#define INTERNAL_NOPRI 0x10
#endif

CODE prioritynames[] =
  {
    { "alert", LOG_ALERT },
    { "crit", LOG_CRIT },
    { "debug", LOG_DEBUG },
    { "emerg", LOG_EMERG },
    { "err", LOG_ERR },
    { "error", LOG_ERR },		/* DEPRECATED */
    { "info", LOG_INFO },
    { "none", INTERNAL_NOPRI },		/* INTERNAL */
    { "notice", LOG_NOTICE },
    { "panic", LOG_EMERG },		/* DEPRECATED */
    { "warn", LOG_WARNING },		/* DEPRECATED */
    { "warning", LOG_WARNING },
    { 0, -1 }
  };
dietlibc-0.33~cvs20120325/libugly/protoent_buf.c010064400000000000000000000001171173363227000162220ustar00#include 

struct protoent __protoent_pw;
char __protoent_buf[1000];

dietlibc-0.33~cvs20120325/libugly/ptsname.c010064400000000000000000000005431173363227000151660ustar00#define _XOPEN_SOURCE
#include 
#include 
#include 
#include 

# define MAX_FDS 4

char *ptsname(int fd) {
  static char buffer[9+MAX_FDS]; /* Ahh..great */
  int pty;

  strcpy(buffer,"/dev/pts/");
  if ((ioctl(fd, TIOCGPTN, &pty)) == -1) return 0;
  __ltostr(buffer+9, MAX_FDS, pty, 10, 0);
  return buffer;
}
dietlibc-0.33~cvs20120325/libugly/putpwent.c010064400000000000000000000007211173363227000154030ustar00/* man, what a crook! */

#include 
#include 
#include 
#include 
#include "dietwarning.h"

int putpwent(const struct passwd *p, FILE *stream) {
  if (p && stream) {
    fprintf(stream,"%s:%s:%d:%d:%s:%s:%s\n", p->pw_name, p->pw_passwd,
	    p->pw_uid, p->pw_gid, p->pw_gecos, p->pw_dir, p->pw_shell);
    return 0;
  }
  (*__errno_location())=EINVAL;
  return -1;
}

link_warning("putpwent","putpwent is garbage, don't use!")
dietlibc-0.33~cvs20120325/libugly/servent_buf.c010064400000000000000000000001141173363227000160330ustar00#include 

struct servent __servent_pw;
char __servent_buf[1000];

dietlibc-0.33~cvs20120325/libugly/setenv.c010064400000000000000000000006521173363227000150240ustar00#include 
#include 

#include 
link_warning("setenv","setenv calls malloc.  Avoid it in small programs.");

int setenv(const char *name, const char *value, int overwrite) {
  if (getenv(name)) {
    if (!overwrite) return 0;
    unsetenv(name);
  }
  {
    char *c=malloc(strlen(name)+strlen(value)+2);
    strcpy(c,name);
    strcat(c,"=");
    strcat(c,value);
    return putenv(c);
  }
}
dietlibc-0.33~cvs20120325/libugly/setmntent.c010064400000000000000000000002041173363227000155320ustar00#include 
#include 

FILE *setmntent(const char *filename, const char *type) {
  return fopen(filename,type);
}

dietlibc-0.33~cvs20120325/libugly/strftime.c010064400000000000000000000101621173363227000153520ustar00#include 
#include 
#include "dietfeatures.h"

static const char   sweekdays [7] [4] = {
    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char   weekdays [7] [10] = {
    "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
static const char   smonths [12] [4] = {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static const char*  months [12] = {
    "January", "February", "March", "April", smonths[5-1], "June",
    "July", "August", "September", "October", "November", "December"
};
static const char   ampm [4] [3] = {
    "am", "pm",
    "AM", "PM"
};

static void i2a ( char* dest,unsigned long x )
{
    int  div = 10;
    *dest++ = x/div + '0';
    *dest++ = x%div + '0';
    *dest++ = '\0';
}

size_t  strftime ( char* dst, size_t max, const char* format, const struct tm* tm )
{
    char*         p = dst;
    const char*   src;
    unsigned long no;
    char          buf [5];

    if (!max) return 0;
    for ( ; *format != '\0'; format++ ) {
	if (*format == '%') {
	    if (*++format == '%') {
	        *p++ = '%';
	    }
	    else
again:
	    switch (*format) {
//          case '%': *p++ = '%';  				 break;			// reduce size of jump table
	    case 'n': *p++ = '\n'; 				 break;
	    case 't': *p++ = '\t'; 				 break;
	    case 'O': case 'E': ++format; goto again;
	    case 'c': src = "%b %a %d %k:%M:%S %Z %Y";        	 goto _strf;
	    case 'r': src = "%I:%M:%S %p";                    	 goto _strf;
	    case 'R': src = "%H:%M";      			 goto _strf;
	    case 'x': src = "%b %a %d";   			 goto _strf;
	    case 'X': src = "%k:%M:%S";   			 goto _strf;
	    case 'D': src = "%m/%d/%y";   			 goto _strf;
	    case 'T': src = "%H:%M:%S";
	       _strf: p  += strftime (p, (size_t)(dst+max-p), src, tm); 	 break;
	    case 'a': src = sweekdays [tm->tm_wday]; 		 goto _str;
	    case 'A': src = weekdays  [tm->tm_wday]; 		 goto _str;
	    case 'h':
	    case 'b': src = smonths   [tm->tm_mon];  		 goto _str;
	    case 'B': src = months    [tm->tm_mon];  		 goto _str;
	    case 'p': src = ampm [tm->tm_hour > 12 ? 3 : 2]; goto _str;
	    case 'P': src = ampm [tm->tm_hour > 12 ? 1 : 0]; goto _str;
	    case 'C': no  = tm->tm_year/100 + 19; 		 goto _no;
	    case 'd': no  = tm->tm_mday;          		 goto _no;
	    case 'e': no  = tm->tm_mday;          		 goto _nos;
	    case 'H': no  = tm->tm_hour;          		 goto _no;
	    case 'I': no  = tm->tm_hour % 12;     		 goto _no;
	    case 'j': no  = tm->tm_yday;          		 goto _no;
	    case 'k': no  = tm->tm_hour;          		 goto _nos;
	    case 'l': no  = tm->tm_hour % 12;     		 goto _nos;
	    case 'm': no  = tm->tm_mon + 1;         		 goto _no;
	    case 'M': no  = tm->tm_min;           		 goto _no;
	    case 'S': no  = tm->tm_sec;           		 goto _no;
	    case 'u': no  = tm->tm_wday ? tm->tm_wday : 7; 	 goto _no;
	    case 'w': no  = tm->tm_wday;              		 goto _no;
	    case 'U': no  = (tm->tm_yday - tm->tm_wday + 7) / 7; goto _no;
	    case 'W': no  = (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7; goto _no;
	    case 's': {
			time_t t = mktime((struct tm*)tm);
			char buf[101];
			char* c;
			buf[100]=0;
			for (c=buf+99; c>buf; --c) {
			  *c=(t%10)+'0';
			  t/=10;
			  if (!t) break;
			}
			src=c;
			goto _str;
		      }
	    case 'Z':
#ifdef WANT_TZFILE_PARSER
		      tzset(); src = tzname[0];
#else
		      src = "[unknown timezone]";
#endif
		      goto _str;
	    case 'Y': i2a ( buf+0, (unsigned int)(tm->tm_year / 100 + 19) );
		      i2a ( buf+2, (unsigned int)(tm->tm_year % 100) );
		      src = buf;
		      goto _str;
	    case 'y': no  = tm->tm_year % 100; 			 goto _no;
		 _no: i2a ( buf, no );				 /* append number 'no' */
		      src = buf;
		      goto _str;
		_nos: i2a ( buf, no );				 /* the same, but '0'->' ' */
		      if (buf[0] == '0')
			  buf[0] = ' ';
		      src = buf;
		_str: while (*src  &&  p < dst+max)		 /* append string */
			  *p++ = *src++;
		      break;
	    };
	} else {
	    *p++ = *format;
	}

	if (p >= dst+max)
	    break;
    }

    if ((size_t)(p-dst)>=max) {
      if (max) p[-1]=0;
    } else
      *p = '\0';
    return p - dst;
}


dietlibc-0.33~cvs20120325/libugly/strndup.c010064400000000000000000000007011173363227000152120ustar00#define _GNU_SOURCE
/* *puke* */
#include 
#include 
#include "dietfeatures.h"

char *strndup(const char *s,size_t n) {
  /* This relies on the fact that our malloc(0) returns NULL.
   * Otherwise this would be an exploitable integer overflow! */
#ifdef WANT_MALLOC_ZERO
  char *tmp=!(n+1)?0:(char *)malloc(n+1);
#else
  char *tmp=(char *)malloc(n+1);
#endif
  if (!tmp) return 0;
  strncpy(tmp,s,n);
  tmp[n]=0;
  return tmp;
}
dietlibc-0.33~cvs20120325/libugly/strptime.c010064400000000000000000000063661173363227000153770ustar00#include 
#include 
#include 
#include 

extern const short  __spm [];

static const char*  months [12] = { 
    "January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"
};

static int getint(const char** s,int max) {
  int i,j;
  for (i=j=0; jtm_mon=i;
	break;
      case 'c':
	s=strptime(s,"%b %a %d %k:%M:%S %Z %Y",tm);
	break;
      case 'C':
	i=getint(&s,2);
	if (i==-1) return 0;
	tm->tm_year=(tm->tm_year%100)+(i*100);
	break;
      case 'd': case 'e':
	i=getint(&s,2);
	if (i==-1 || i>31) return 0;
	tm->tm_mday=i;
	break;
      case 'D':
	s=strptime(s,"%m/%d/%y",tm);
	break;
      case 'H': case 'k':
	i=getint(&s,2);
	if (i==-1 || i>23) return 0;
	tm->tm_hour=i;
	break;
      case 'I': case 'l':
	i=getint(&s,2);
	if (i==-1 || i>12) return 0;
	tm->tm_hour=(tm->tm_hour/12)*12+i;
	break;
      case 'j':
	getint(&s,3);	/* not used */
	break;
      case 'm':
	i=getint(&s,2);
	if (i<=0 || i>12) return 0;
	tm->tm_mon=i-1;
	break;
      case 'M':
	i=getint(&s,2);
	if (i==-1 || i>59) return 0;
	tm->tm_min=i;
	break;
      case 'n': case 't':
	while (isblank(*s)) ++s;
	break;
      case 'p': case 'P':
	if (*s=='p' || *s=='P') tm->tm_hour=(tm->tm_hour%12)+12;
	s+=2;
	break;
      case 'r':
	s=strptime(s,"%I:%M:%S %p",tm);
	break;
      case 'R':
	s=strptime(s,"%H:%M",tm);
	break;
      case 'S':
	i=getint(&s,2);
	if (i==-1 || i>60) return 0;
	tm->tm_sec=i;
	break;
      case 'T':
	s=strptime(s,"%H:%M:%S",tm);
	break;
      case 'U': case 'W':
	if (getint(&s,2)==-1) return 0;
	break;
      case 'w':
	if (*s<'0' || *s>'6') return 0;
	++s;
	break;
      case 'x':
	s=strptime(s,"%b %a %d",tm);
	break;
      case 'X':
	s=strptime(s,"%k:%M:%S",tm);
	break;
      case 'y':
	i=getint(&s,2);
	if (i<0) return 0;
	tm->tm_year=(i<69)?i+100:i;
	break;
      case 'Y':
	i=getint(&s,4);
	if (i==-1) return 0;
	tm->tm_year=i-1900;
	break;
      case 'Z':
	/* time zone.  Not sure what I'm expected to do here. We'll just
	 * skip to the next whitespace */
	while (*s!=' ' && *s!='\t') ++s;
	break;
      }
      ++format;
      break;
    default:
      if (*s != *format) return 0;
      ++format; ++s;
      break;
    }
  }
 
  day  = (tm->tm_year - 70) * 365 + (tm->tm_year - 69) / 4;
  day += tm->tm_yday = __spm [tm->tm_mon] + tm->tm_mday-1 + (__isleap (tm->tm_year+1900) & (tm->tm_mon > 1));
  tm->tm_wday = (day + 4) % 7;

  return (char*)s;
}
dietlibc-0.33~cvs20120325/libugly/strsignal.c010064400000000000000000000003161173363227000155230ustar00#define _GNU_SOURCE
#include 
#include 

char* strsignal(int sig) {
  if ((unsigned int)sig<=SIGRTMAX)
    return (char*)sys_siglist[sig];
  else
    return (char*)"(unknown signal)";
}
dietlibc-0.33~cvs20120325/libugly/system.c010064400000000000000000000033201173363227000150370ustar00#include 
#include 
#include 
#include 
#include "dietwarning.h"
#include "dietfeatures.h"
#include "binshstr.h"

extern char **environ;

int __libc_system (const char *line);

int __libc_system (const char *line)
{
  struct sigaction sa, intr, quit;
  sigset_t block,omask;
  int save,pid,ret=-1;

  if (line == 0) return __libc_system("exit 0") == 0;

  sa.sa_handler = SIG_IGN;
  sa.sa_flags = 0;
  sigemptyset (&sa.sa_mask);

  if (sigaction(SIGINT,  &sa, &intr)<0) return -1;
  if (sigaction(SIGQUIT, &sa, &quit)<0) {
    save = errno;
undo:
    sigaction (SIGINT, &intr, (struct sigaction*)0);
    errno=save;
    return -1;
  }
  sigemptyset(&block);
  sigaddset(&block,SIGCHLD);
  if (sigprocmask(SIG_BLOCK,&block,&omask)<0) {
    save=errno;
    sigaction (SIGQUIT, &quit, (struct sigaction*)0);
    goto undo;
  }

  pid=fork();
  if (pid>0)
  { /* parent */
    int n;
    do
      n=waitpid(pid, &ret, 0);
    while ((n==-1) && (errno==EINTR));
    if (n!=pid) ret=-1;
  }
  else if (!pid)
  { /* child */
    const char *nargs[4];
    nargs[0] = __sh;
    nargs[1] = "-c";
    nargs[2] = line;
    nargs[3] = 0;

    sigaction(SIGINT,  &intr, (struct sigaction*)0);
    sigaction(SIGQUIT, &quit, (struct sigaction*)0);
    sigprocmask(SIG_SETMASK,&omask,0);

    execve(__binsh,(char *const *)nargs, environ);
    _exit(127);
  }
  save = errno;
  sigaction (SIGINT,  &intr, (struct sigaction *)0);
  sigaction (SIGQUIT, &quit, (struct sigaction *)0);
  sigprocmask(SIG_SETMASK,&omask,0);
  errno=save;
  return ret;
}

int system (const char *line) __attribute__((weak,alias("__libc_system")));

link_warning("system","warning: system() is a security risk.  Use fork and execvp instead!")
dietlibc-0.33~cvs20120325/libugly/time_table_spd.c010064400000000000000000000006271173363227000164750ustar00#include 

/* days per month -- nonleap! */
const short __spm[13] =
  { 0,
    (31),
    (31+28),
    (31+28+31),
    (31+28+31+30),
    (31+28+31+30+31),
    (31+28+31+30+31+30),
    (31+28+31+30+31+30+31),
    (31+28+31+30+31+30+31+31),
    (31+28+31+30+31+30+31+31+30),
    (31+28+31+30+31+30+31+31+30+31),
    (31+28+31+30+31+30+31+31+30+31+30),
    (31+28+31+30+31+30+31+31+30+31+30+31),
  };

dietlibc-0.33~cvs20120325/libugly/timegm.c010064400000000000000000000032151173363227000150000ustar00#define _GNU_SOURCE
#include 

/* this is cut and paste from mktime. */

extern const short  __spm [];

time_t timegm(struct tm *const t) {
  register time_t  day;
  register time_t  i;
  register time_t years = t->tm_year - 70;

  if (t->tm_sec>60) { t->tm_min += t->tm_sec/60; t->tm_sec%=60; }
  if (t->tm_min>60) { t->tm_hour += t->tm_min/60; t->tm_min%=60; }
  if (t->tm_hour>60) { t->tm_mday += t->tm_hour/60; t->tm_hour%=60; }
  if (t->tm_mon>12) { t->tm_year += t->tm_mon/12; t->tm_mon%=12; }
  while (t->tm_mday>__spm[1+t->tm_mon]) {
    if (t->tm_mon==1 && __isleap(t->tm_year+1900)) {
      if (t->tm_mon==31+29) break;
      --t->tm_mday;
    }
    t->tm_mday-=__spm[t->tm_mon];
    ++t->tm_mon;
    if (t->tm_mon>11) { t->tm_mon=0; ++t->tm_year; }
  }

  if (t->tm_year < 70)
    return (time_t) -1;

  /* Days since 1970 is 365 * number of years + number of leap years since 1970 */
  day  = years * 365 + (years + 1) / 4;

  /* After 2100 we have to substract 3 leap years for every 400 years
     This is not intuitive. Most mktime implementations do not support
     dates after 2059, anyway, so we might leave this out for it's
     bloat. */
  if ((years -= 131) >= 0) {
    years /= 100;
    day -= (years >> 2) * 3 + 1;
    if ((years &= 3) == 3) years--;
    day -= years;
  }

  day += t->tm_yday = __spm [t->tm_mon] + t->tm_mday-1 + ( __isleap (t->tm_year+1900)  &  (t->tm_mon > 1) );

  /* day is now the number of days since 'Jan 1 1970' */
  i = 7;
  t->tm_wday = (day + 4) % i;                        /* Sunday=0, Monday=1, ..., Saturday=6 */

  i = 24;
  day *= i;
  i = 60;
  return ((day + t->tm_hour) * i + t->tm_min) * i + t->tm_sec;
}

dietlibc-0.33~cvs20120325/libugly/timezone.c010064400000000000000000000000421173363227000153430ustar00
long int timezone;
int daylight;
dietlibc-0.33~cvs20120325/libugly/tzfile.c010064400000000000000000000070131173363227000150130ustar00#include "dietfeatures.h"
#include 
#include 
#include 
#include 
#include 

#include 

/* This code appears to be subtly wrong depending on the date.
 * However, the documentation I found about the tzfile layout are not
 * sufficient to debug this. */

char* tzname[2]={"GMT","GMT"};

#ifdef WANT_TZFILE_PARSER
static unsigned char *tzfile;
static int tzlen=-1;

void __maplocaltime(void);
void __maplocaltime(void) {
  int fd;
  unsigned int len;
  if (tzlen>=0) return;
  tzlen=0;
  if ((fd=open("/etc/localtime",O_RDONLY))<0) return;
  len=lseek(fd,0,SEEK_END);
  if ((tzfile=mmap(0,len,PROT_READ,MAP_PRIVATE,fd,0))==MAP_FAILED) {
    close(fd);
    return;
  }
  close(fd);
  if (len<44 || ntohl(*(int*)tzfile) != 0x545a6966) {
    munmap(tzfile,len);
    tzfile=0;
    return;
  }
  tzlen=len;
}

static int32_t __myntohl(const unsigned char* c) {
  return (((uint32_t)c[0])<<24) +
         (((uint32_t)c[1])<<16) +
         (((uint32_t)c[2])<<8) +
         ((uint32_t)c[3]);
}

time_t __tzfile_map(time_t t, int *isdst, int forward);
time_t __tzfile_map(time_t t, int *isdst, int forward) {
  /* "TZif" plus 16 reserved bytes. */
  unsigned char *tmp;
  int i;
  int tzh_ttisgmtcnt, tzh_ttisstdcnt, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt;
  *isdst=0;
  if (!tzfile) return t;
  tzh_ttisgmtcnt=ntohl(*(int*)(tzfile+20));
  tzh_ttisstdcnt=ntohl(*(int*)(tzfile+24));
  tzh_leapcnt=ntohl(*(int*)(tzfile+28));
  tzh_timecnt=ntohl(*(int*)(tzfile+32));
  tzh_typecnt=ntohl(*(int*)(tzfile+36));
  tzh_charcnt=ntohl(*(int*)(tzfile+40));

#if 0
  tmp=tzfile+20+6*4;
  printf("ttisgmtcnt %d ttisstdcnt %d leapcnt %d timecnt %d typecnt %d charcnt %d\n",tzh_ttisgmtcnt,tzh_ttisstdcnt, tzh_leapcnt, tzh_timecnt, tzh_typecnt, tzh_charcnt);
  printf("transition times: ");
  for (i=0; i0);
  if (forward) {
    for (i=0; i= t) {
	unsigned char* tz=tmp;
  /*      printf("match at %d\n",i); */
	tmp+=tzh_timecnt*4;
	i=tmp[i-1];
  /*      printf("using index %d\n",i); */
	tmp+=tzh_timecnt;
	tz+=tzh_timecnt*5+tzh_typecnt*6;
	tmp+=i*6;
  /*      printf("(%lu,%d,%d)\n",ntohl(*(int*)tmp),tmp[4],tmp[5]); */
	*isdst=tmp[4];
	tzname[0]=(char*)(tz+tmp[5]);
	timezone=__myntohl(tmp);
	return t+timezone;
      }
    }
  } else {	/* reverse map, for mktime */
    time_t nexttz=0,lastval=0;
//    printf("tzh_timecnt: %d\n",tzh_timecnt);
    for (i=1; i t) {
//	printf("FOUND!1!!  Offset %d\n",nexttz);
	return t-nexttz;
      }
      lastval=k;
    }
  }
  return t;
}

void tzset(void) {
  int isdst;
  __maplocaltime();
  __tzfile_map(time(0),&isdst,1);
}

#else
void tzset(void) { }
#endif
dietlibc-0.33~cvs20120325/libugly/unlockpt.c010064400000000000000000000003051173363227000153520ustar00#define _XOPEN_SOURCE
#include 
#include 
#include 

int unlockpt (int fd) {
  int foo=0;
  /* hehe, that one is easy */
  return (ioctl (fd, TIOCSPTLCK, &foo));
}
dietlibc-0.33~cvs20120325/libugly/unsetenv.c010064400000000000000000000001201173363227000153550ustar00#include 

int unsetenv(const char *name) {
  return putenv(name);
}

dietlibc-0.33~cvs20120325/libugly/utent.c010064400000000000000000000046231173363227000146610ustar00#include 
#include 
#include 
#include 

static const char *utmp_file_name = _PATH_UTMP;
static int fd = -1;
static off_t utmp_current = 0;

static int lock_record(int type) {
  struct flock fl;
  fl.l_whence	= SEEK_CUR;
  fl.l_start	= 0;
  fl.l_len	= sizeof(struct utmp);
  fl.l_pid	= 0;
  fl.l_type	= type;
  return fcntl(fd, F_SETLKW, &fl);
}

static int unlock_record() {
  struct flock fl;
  fl.l_whence	= SEEK_CUR;
  fl.l_start	= -sizeof(struct utmp);
  fl.l_len	= sizeof(struct utmp);
  fl.l_pid	= 0;
  fl.l_type	= F_UNLCK;
  return fcntl(fd, F_SETLK, &fl);
}

void utmpname(const char *file) {
  if (file)
    utmp_file_name = file;
  else
    utmp_file_name = _PATH_UTMP;
}

void setutent() {
  if (fd<0) fd = open(utmp_file_name,O_RDWR);
  if (fd<0) fd = open(utmp_file_name,O_RDONLY);
  fcntl (fd, F_SETFD, FD_CLOEXEC);
  utmp_current = lseek(fd,0,SEEK_SET);
}

void endutent() {
  if (fd<0) return;
  close(fd); fd=-1;
  utmp_current = 0;
}

struct utmp *getutent(void) {
  static struct utmp getutent_tmp;
  ssize_t ret;

  if (fd<0) {
    setutent();
    if (fd<0) return 0;
  }
  utmp_current = lseek (fd, 0, SEEK_CUR);
  if (lock_record(F_RDLCK)) return 0;
  ret=read(fd, &getutent_tmp, sizeof(struct utmp));
  unlock_record();
  if (ret<1) return 0;
  return &getutent_tmp;
}

struct utmp *getutid(struct utmp *ut) {
  struct utmp *tmp;

  while ((tmp = getutent())) {
    if (ut->ut_type && (ut->ut_type <= OLD_TIME)) {
      if (ut->ut_type == tmp->ut_type) break;
    }
    if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) {
      if (!strncmp(ut->ut_id,tmp->ut_id,4)) break;
    }
  }
  return tmp;
}

struct utmp *getutline(struct utmp *ut) {
  struct utmp *tmp;

  while ((tmp = getutent())) {
    if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) {
      if (!strncmp(ut->ut_line,tmp->ut_line,UT_LINESIZE)) break;
    }
  }
  return tmp;
}

void pututline(struct utmp *ut) {
  struct utmp *tmp;

  /* Seek to the current record before searching. */
  lseek (fd, utmp_current, SEEK_SET);
  if ((tmp = getutid(ut))) {
    lseek(fd, - (off_t)sizeof(struct utmp), SEEK_CUR);
    if (lock_record(F_WRLCK)) return;
    write(fd, ut, sizeof(struct utmp));
    utmp_current += sizeof(struct utmp);
  }
  else {
    utmp_current = lseek(fd, 0, SEEK_END);
    if (lock_record(F_WRLCK)) return;
    write(fd, ut, sizeof(struct utmp));
  }
  unlock_record();
}

dietlibc-0.33~cvs20120325/libugly/utxent.c010064400000000000000000000060031173363227000150430ustar00#include 
#include 
#include 
#include 
#include 
#include 

static const char *utmp_file_name = _PATH_UTMPX;
static int fd = -1;
static off_t utmp_current = 0;

/* Forward declaration for utmp common functions */
void *__utmp_io(int fd, void *ut, ssize_t len, off_t *offset, int type);
sigset_t *__utmp_block_signals (sigset_t *oldset);

/* See libcompat for utmpxname() */
void __utmpxname(const char *file);   /* keep the compiler happy */
void __utmpxname(const char *file) {
  if (file)
    utmp_file_name = file;
  else
    utmp_file_name = _PATH_UTMPX;
}

void setutxent() {
  sigset_t oldset, *savedset;

  savedset = __utmp_block_signals(&oldset);
  if (fd<0) fd = open(utmp_file_name,O_RDWR);
  if (fd<0) fd = open(utmp_file_name,O_RDONLY);
  fcntl (fd, F_SETFD, FD_CLOEXEC);
  utmp_current = lseek(fd,0,SEEK_SET);
  if (savedset)
      sigprocmask (SIG_SETMASK, savedset, 0);
}

void endutxent() {
  if (fd<0) return;
  close(fd); fd=-1;
  utmp_current = 0;
}

struct utmpx *getutxent(void) {
  static struct utmpx getutent_tmp, *retval;
  ssize_t ret;
  sigset_t oldset, *savedset;

  if (fd<0) {
    setutxent();
    if (fd<0) return 0;
  }
  savedset = __utmp_block_signals (&oldset);

  retval = __utmp_io(fd, &getutent_tmp, sizeof(struct utmpx),
	      &utmp_current, F_RDLCK);

  if (savedset)
      sigprocmask (SIG_SETMASK, savedset, 0);

  return retval;
}

struct utmpx *getutxid(struct utmpx *ut) {
  struct utmpx *tmp;

  while ((tmp = getutxent())) {
    if (ut->ut_type && (ut->ut_type <= OLD_TIME)) {
      if (ut->ut_type == tmp->ut_type) break;
    }
    if ((ut->ut_type >= INIT_PROCESS) && (ut->ut_type <= DEAD_PROCESS)) {
      if (!strncmp(ut->ut_id,tmp->ut_id,4)) break;
    }
  }
  return tmp;
}

struct utmpx *getutxline(struct utmpx *ut) {
  struct utmpx *tmp;

  while ((tmp = getutxent())) {
    if ((tmp->ut_type == USER_PROCESS) || (tmp->ut_type == LOGIN_PROCESS)) {
      if (!strncmp(ut->ut_line,tmp->ut_line,__UT_LINESIZE)) break;
    }
  }
  return tmp;
}

struct utmpx *pututxline(struct utmpx *ut) {
  struct utmpx *tmp, ut_copy, *retval = 0, *result;
  int e;
  ssize_t bytes_written;
  sigset_t oldset, *savedset;

  /* It's kosher to call this function with a pointer to our own static
   * utmp structure, so work with a copy of "ut" */

  memcpy (&ut_copy, ut, sizeof (struct utmpx));

  savedset = __utmp_block_signals (&oldset);

  /* Seek to the current record before searching. */
  lseek (fd, utmp_current, SEEK_SET);
  if ((tmp = getutxid(&ut_copy))) {
    lseek(fd, - (off_t)sizeof(struct utmpx), SEEK_CUR);
    result = __utmp_io (fd, &ut_copy, sizeof(struct utmpx),
	    &utmp_current, F_WRLCK);
    e = errno;
  } else {
    utmp_current = lseek(fd, 0, SEEK_END);
    result = __utmp_io (fd, &ut_copy, sizeof(struct utmpx),
	    &utmp_current, F_WRLCK);
    e = errno;
  }
  if (savedset)
      sigprocmask (SIG_SETMASK, savedset, 0);

  if (result) {
      retval = ut;
  }

  memcpy (ut, &ut_copy, sizeof (struct utmpx));
  errno = e;
  return retval;
}

dietlibc-0.33~cvs20120325/libugly/vasprintf.c010064400000000000000000000006071173363227000155340ustar00#define _GNU_SOURCE
#include 
#include 
#include 
#include 
#include "dietwarning.h"

int vasprintf(char **s, const char *format, va_list ap)
{
  int n;
  va_list arg_ptr;
  va_copy(arg_ptr,ap);
  n=vsnprintf(0,1000000,format,arg_ptr);
  va_end(arg_ptr);
  if ((*s=malloc(n+1))) {
    n=vsnprintf(*s,n+1,format,ap);
    return n;
  }
  return -1;
}
dietlibc-0.33~cvs20120325/libugly/wctype.c010064400000000000000000000011071173363227000150270ustar00#include 
#include 

struct { const char* name; wctype_t func; } types[]={
  { "alnum", iswalnum },
  { "alpha", iswalpha },
  { "blank", iswblank },
  { "cntrl", iswcntrl },
  { "digit", iswdigit },
  { "graph", iswgraph },
  { "lower", iswlower },
  { "print", iswprint },
  { "punct", iswpunct },
  { "space", iswspace },
  { "upper", iswupper },
  { "xdigit", iswxdigit },
};

wctype_t wctype(const char* name) {
  size_t i;
  for (i=0; i

int wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) {
  size_t i;
  for (i=0; i

wchar_t *wmemcpy(wchar_t *dest, const wchar_t *src, size_t n) {
  size_t i;
  for (i=0; i

wchar_t *wmemmove(wchar_t *dest, const wchar_t *src, size_t n) {
  size_t i;
  if (src

wchar_t *wmemset(wchar_t *wcs, wchar_t wc, size_t n) {
  size_t i;
  for (i=0; i
#include 
#include 
#include 

void updwtmp(const char *wtmp_file, const struct utmp *ut) {
  int fd = open(wtmp_file, O_WRONLY|O_APPEND);
  if (fd<0) return;
  fcntl (fd, F_SETFD, FD_CLOEXEC);
  write(fd, ut, sizeof(struct utmp));
  close(fd);
}

void logwtmp(const char *line, const char *name, const char *host) {
  struct utmp ut;

  memset(&ut, 0, sizeof(struct utmp));

  ut.ut_pid = getpid ();
  ut.ut_type = name[0] ? USER_PROCESS : DEAD_PROCESS;

  memccpy (ut.ut_line, line, 0, sizeof ut.ut_line);
  memccpy (ut.ut_name, name, 0, sizeof ut.ut_name);
  memccpy (ut.ut_host, host, 0, sizeof ut.ut_host);

  if (sizeof(ut.ut_tv) == sizeof(struct timeval))
    gettimeofday((struct timeval *)&ut.ut_tv, NULL);
  else {
	struct timeval tv;
	gettimeofday(&tv, NULL);
	ut.ut_tv.tv_sec = tv.tv_sec;
	ut.ut_tv.tv_usec = tv.tv_usec;
  }

  updwtmp (_PATH_WTMP, &ut);
}

dietlibc-0.33~cvs20120325/linuxnet.h010064400000000000000000000014261173363226000137230ustar00
#define SYS_SOCKET	1		/* sys_socket(2)		*/
#define SYS_BIND	2		/* sys_bind(2)			*/
#define SYS_CONNECT	3		/* sys_connect(2)		*/
#define SYS_LISTEN	4		/* sys_listen(2)		*/
#define SYS_ACCEPT	5		/* sys_accept(2)		*/
#define SYS_GETSOCKNAME	6		/* sys_getsockname(2)		*/
#define SYS_GETPEERNAME	7		/* sys_getpeername(2)		*/
#define SYS_SOCKETPAIR	8		/* sys_socketpair(2)		*/
#define SYS_SEND	9		/* sys_send(2)			*/
#define SYS_RECV	10		/* sys_recv(2)			*/
#define SYS_SENDTO	11		/* sys_sendto(2)		*/
#define SYS_RECVFROM	12		/* sys_recvfrom(2)		*/
#define SYS_SHUTDOWN	13		/* sys_shutdown(2)		*/
#define SYS_SETSOCKOPT	14		/* sys_setsockopt(2)		*/
#define SYS_GETSOCKOPT	15		/* sys_getsockopt(2)		*/
#define SYS_SENDMSG	16		/* sys_sendmsg(2)		*/
#define SYS_RECVMSG	17		/* sys_recvmsg(2)		*/

dietlibc-0.33~cvs20120325/longlong.h010064400000000000000000001434511173363226000137010ustar00/* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
   Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   2002, 2003, 2004, 2005, 2006, 2009 Free Software Foundation, Inc.

   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

/* You have to define the following before including this file:

   UWtype -- An unsigned type, default type for operations (typically a "word")
   UHWtype -- An unsigned type, at least half the size of UWtype.
   UDWtype -- An unsigned type, at least twice as large a UWtype
   W_TYPE_SIZE -- size in bits of UWtype

   UQItype -- Unsigned 8 bit type.
   SItype, USItype -- Signed and unsigned 32 bit types.
   DItype, UDItype -- Signed and unsigned 64 bit types.

   On a 32 bit machine UWtype should typically be USItype;
   on a 64 bit machine, UWtype should typically be UDItype.  */

#define __BITS4 (W_TYPE_SIZE / 4)
#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))

#ifndef W_TYPE_SIZE
#define W_TYPE_SIZE	32
#define UWtype		USItype
#define UHWtype		USItype
#define UDWtype		UDItype
#endif

extern const UQItype __clz_tab[256] attribute_hidden;

/* Define auxiliary asm macros.

   1) umul_ppmm(high_prod, low_prod, multiplier, multiplicand) multiplies two
   UWtype integers MULTIPLIER and MULTIPLICAND, and generates a two UWtype
   word product in HIGH_PROD and LOW_PROD.

   2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
   UDWtype product.  This is just a variant of umul_ppmm.

   3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
   denominator) divides a UDWtype, composed by the UWtype integers
   HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
   in QUOTIENT and the remainder in REMAINDER.  HIGH_NUMERATOR must be less
   than DENOMINATOR for correct operation.  If, in addition, the most
   significant bit of DENOMINATOR must be 1, then the pre-processor symbol
   UDIV_NEEDS_NORMALIZATION is defined to 1.

   4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
   denominator).  Like udiv_qrnnd but the numbers are signed.  The quotient
   is rounded towards 0.

   5) count_leading_zeros(count, x) counts the number of zero-bits from the
   msb to the first nonzero bit in the UWtype X.  This is the number of
   steps X needs to be shifted left to set the msb.  Undefined for X == 0,
   unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.

   6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
   from the least significant end.

   7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
   high_addend_2, low_addend_2) adds two UWtype integers, composed by
   HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
   respectively.  The result is placed in HIGH_SUM and LOW_SUM.  Overflow
   (i.e. carry out) is not stored anywhere, and is lost.

   8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
   high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
   composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
   LOW_SUBTRAHEND_2 respectively.  The result is placed in HIGH_DIFFERENCE
   and LOW_DIFFERENCE.  Overflow (i.e. carry out) is not stored anywhere,
   and is lost.

   If any of these macros are left undefined for a particular CPU,
   C macros are used.  */

/* The CPUs come in alphabetical order below.

   Please add support for more CPUs here, or improve the current support
   for the CPUs below!
   (E.g. WE32100, IBM360.)  */

#if defined (__GNUC__) && !defined (NO_ASM)

/* We sometimes need to clobber "cc" with gcc2, but that would not be
   understood by gcc1.  Use cpp to avoid major code duplication.  */
#if __GNUC__ < 2
#define __CLOBBER_CC
#define __AND_CLOBBER_CC
#else /* __GNUC__ >= 2 */
#define __CLOBBER_CC : "cc"
#define __AND_CLOBBER_CC , "cc"
#endif /* __GNUC__ < 2 */

#if defined (__alpha) && W_TYPE_SIZE == 64
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    UDItype __m0 = (m0), __m1 = (m1);					\
    (ph) = __builtin_alpha_umulh (__m0, __m1);				\
    (pl) = __m0 * __m1;							\
  } while (0)
#define UMUL_TIME 46
#ifndef LONGLONG_STANDALONE
#define udiv_qrnnd(q, r, n1, n0, d) \
  do { UDItype __r;							\
    (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));				\
    (r) = __r;								\
  } while (0)
extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
#define UDIV_TIME 220
#endif /* LONGLONG_STANDALONE */
#ifdef __alpha_cix__
#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clzl (X))
#define count_trailing_zeros(COUNT,X)	((COUNT) = __builtin_ctzl (X))
#define COUNT_LEADING_ZEROS_0 64
#else
#define count_leading_zeros(COUNT,X) \
  do {									\
    UDItype __xr = (X), __t, __a;					\
    __t = __builtin_alpha_cmpbge (0, __xr);				\
    __a = __clz_tab[__t ^ 0xff] - 1;					\
    __t = __builtin_alpha_extbl (__xr, __a);				\
    (COUNT) = 64 - (__clz_tab[__t] + __a*8);				\
  } while (0)
#define count_trailing_zeros(COUNT,X) \
  do {									\
    UDItype __xr = (X), __t, __a;					\
    __t = __builtin_alpha_cmpbge (0, __xr);				\
    __t = ~__t & -~__t;							\
    __a = ((__t & 0xCC) != 0) * 2;					\
    __a += ((__t & 0xF0) != 0) * 4;					\
    __a += ((__t & 0xAA) != 0);						\
    __t = __builtin_alpha_extbl (__xr, __a);				\
    __a <<= 3;								\
    __t &= -__t;							\
    __a += ((__t & 0xCC) != 0) * 2;					\
    __a += ((__t & 0xF0) != 0) * 4;					\
    __a += ((__t & 0xAA) != 0);						\
    (COUNT) = __a;							\
  } while (0)
#endif /* __alpha_cix__ */
#endif /* __alpha */

#if defined (__arc__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add.f	%1, %4, %5\n\tadc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%r" ((USItype) (ah)),					\
	     "rIJ" ((USItype) (bh)),					\
	     "%r" ((USItype) (al)),					\
	     "rIJ" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub.f	%1, %4, %5\n\tsbc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "r" ((USItype) (ah)),					\
	     "rIJ" ((USItype) (bh)),					\
	     "r" ((USItype) (al)),					\
	     "rIJ" ((USItype) (bl)))
/* Call libgcc routine.  */
#define umul_ppmm(w1, w0, u, v) \
do {									\
  DWunion __w;								\
  __w.ll = __umulsidi3 (u, v);						\
  w1 = __w.s.high;							\
  w0 = __w.s.low;							\
} while (0)
#define __umulsidi3 __umulsidi3
UDItype __umulsidi3 (USItype, USItype);
#endif

#if defined (__arm__) && !defined (__thumb__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%r" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "%r" ((USItype) (al)),					\
	     "rI" ((USItype) (bl)) __CLOBBER_CC)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "r" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "r" ((USItype) (al)),					\
	     "rI" ((USItype) (bl)) __CLOBBER_CC)
#define umul_ppmm(xh, xl, a, b) \
{register USItype __t0, __t1, __t2;					\
  __asm__ ("%@ Inlined umul_ppmm\n"					\
	   "	mov	%2, %5, lsr #16\n"				\
	   "	mov	%0, %6, lsr #16\n"				\
	   "	bic	%3, %5, %2, lsl #16\n"				\
	   "	bic	%4, %6, %0, lsl #16\n"				\
	   "	mul	%1, %3, %4\n"					\
	   "	mul	%4, %2, %4\n"					\
	   "	mul	%3, %0, %3\n"					\
	   "	mul	%0, %2, %0\n"					\
	   "	adds	%3, %4, %3\n"					\
	   "	addcs	%0, %0, #65536\n"				\
	   "	adds	%1, %1, %3, lsl #16\n"				\
	   "	adc	%0, %0, %3, lsr #16"				\
	   : "=&r" ((USItype) (xh)),					\
	     "=r" ((USItype) (xl)),					\
	     "=&r" (__t0), "=&r" (__t1), "=r" (__t2)			\
	   : "r" ((USItype) (a)),					\
	     "r" ((USItype) (b)) __CLOBBER_CC );}
#define UMUL_TIME 20
#define UDIV_TIME 100
#endif /* __arm__ */

#if defined(__arm__)
/* Let gcc decide how best to implement count_leading_zeros.  */
#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clz (X))
#define COUNT_LEADING_ZEROS_0 32
#endif

#if defined (__CRIS__) && __CRIS_arch_version >= 3
#define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
#if __CRIS_arch_version >= 8
#define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
#endif
#endif /* __CRIS__ */

#if defined (__hppa) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%rM" ((USItype) (ah)),					\
	     "rM" ((USItype) (bh)),					\
	     "%rM" ((USItype) (al)),					\
	     "rM" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "rM" ((USItype) (ah)),					\
	     "rM" ((USItype) (bh)),					\
	     "rM" ((USItype) (al)),					\
	     "rM" ((USItype) (bl)))
#if defined (_PA_RISC1_1)
#define umul_ppmm(w1, w0, u, v) \
  do {									\
    union								\
      {									\
	UDItype __f;							\
	struct {USItype __w1, __w0;} __w1w0;				\
      } __t;								\
    __asm__ ("xmpyu %1,%2,%0"						\
	     : "=x" (__t.__f)						\
	     : "x" ((USItype) (u)),					\
	       "x" ((USItype) (v)));					\
    (w1) = __t.__w1w0.__w1;						\
    (w0) = __t.__w1w0.__w0;						\
     } while (0)
#define UMUL_TIME 8
#else
#define UMUL_TIME 30
#endif
#define UDIV_TIME 40
#define count_leading_zeros(count, x) \
  do {									\
    USItype __tmp;							\
    __asm__ (								\
       "ldi		1,%0\n"						\
"	extru,=		%1,15,16,%%r0		; Bits 31..16 zero?\n"	\
"	extru,tr	%1,15,16,%1		; No.  Shift down, skip add.\n"\
"	ldo		16(%0),%0		; Yes.  Perform add.\n"	\
"	extru,=		%1,23,8,%%r0		; Bits 15..8 zero?\n"	\
"	extru,tr	%1,23,8,%1		; No.  Shift down, skip add.\n"\
"	ldo		8(%0),%0		; Yes.  Perform add.\n"	\
"	extru,=		%1,27,4,%%r0		; Bits 7..4 zero?\n"	\
"	extru,tr	%1,27,4,%1		; No.  Shift down, skip add.\n"\
"	ldo		4(%0),%0		; Yes.  Perform add.\n"	\
"	extru,=		%1,29,2,%%r0		; Bits 3..2 zero?\n"	\
"	extru,tr	%1,29,2,%1		; No.  Shift down, skip add.\n"\
"	ldo		2(%0),%0		; Yes.  Perform add.\n"	\
"	extru		%1,30,1,%1		; Extract bit 1.\n"	\
"	sub		%0,%1,%0		; Subtract it.\n"	\
	: "=r" (count), "=r" (__tmp) : "1" (x));			\
  } while (0)
#endif

#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
#define smul_ppmm(xh, xl, m0, m1) \
  do {									\
    union {DItype __ll;							\
	   struct {USItype __h, __l;} __i;				\
	  } __x;							\
    __asm__ ("lr %N0,%1\n\tmr %0,%2"					\
	     : "=&r" (__x.__ll)						\
	     : "r" (m0), "r" (m1));					\
    (xh) = __x.__i.__h; (xl) = __x.__i.__l;				\
  } while (0)
#define sdiv_qrnnd(q, r, n1, n0, d) \
  do {									\
    union {DItype __ll;							\
	   struct {USItype __h, __l;} __i;				\
	  } __x;							\
    __x.__i.__h = n1; __x.__i.__l = n0;					\
    __asm__ ("dr %0,%2"							\
	     : "=r" (__x.__ll)						\
	     : "0" (__x.__ll), "r" (d));				\
    (q) = __x.__i.__l; (r) = __x.__i.__h;				\
  } while (0)
#endif

#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("mul{l} %3"							\
	   : "=a" ((USItype) (w0)),					\
	     "=d" ((USItype) (w1))					\
	   : "%0" ((USItype) (u)),					\
	     "rm" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
  __asm__ ("div{l} %4"							\
	   : "=a" ((USItype) (q)),					\
	     "=d" ((USItype) (r))					\
	   : "0" ((USItype) (n0)),					\
	     "1" ((USItype) (n1)),					\
	     "rm" ((USItype) (dv)))
#define count_leading_zeros(count, x)	((count) = __builtin_clz (x))
#define count_trailing_zeros(count, x)	((count) = __builtin_ctz (x))
#define UMUL_TIME 40
#define UDIV_TIME 40
#endif /* 80x86 */

#if (defined (__x86_64__) || defined (__i386__)) && W_TYPE_SIZE == 64
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
	   : "=r" ((UDItype) (sh)),					\
	     "=&r" ((UDItype) (sl))					\
	   : "%0" ((UDItype) (ah)),					\
	     "rme" ((UDItype) (bh)),					\
	     "%1" ((UDItype) (al)),					\
	     "rme" ((UDItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
	   : "=r" ((UDItype) (sh)),					\
	     "=&r" ((UDItype) (sl))					\
	   : "0" ((UDItype) (ah)),					\
	     "rme" ((UDItype) (bh)),					\
	     "1" ((UDItype) (al)),					\
	     "rme" ((UDItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("mul{q} %3"							\
	   : "=a" ((UDItype) (w0)),					\
	     "=d" ((UDItype) (w1))					\
	   : "%0" ((UDItype) (u)),					\
	     "rm" ((UDItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
  __asm__ ("div{q} %4"							\
	   : "=a" ((UDItype) (q)),					\
	     "=d" ((UDItype) (r))					\
	   : "0" ((UDItype) (n0)),					\
	     "1" ((UDItype) (n1)),					\
	     "rm" ((UDItype) (dv)))
#define count_leading_zeros(count, x)	((count) = __builtin_clzl (x))
#define count_trailing_zeros(count, x)	((count) = __builtin_ctzl (x))
#define UMUL_TIME 40
#define UDIV_TIME 40
#endif /* x86_64 */

#if defined (__i960__) && W_TYPE_SIZE == 32
#define umul_ppmm(w1, w0, u, v) \
  ({union {UDItype __ll;						\
	   struct {USItype __l, __h;} __i;				\
	  } __xx;							\
  __asm__ ("emul	%2,%1,%0"					\
	   : "=d" (__xx.__ll)						\
	   : "%dI" ((USItype) (u)),					\
	     "dI" ((USItype) (v)));					\
  (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
#define __umulsidi3(u, v) \
  ({UDItype __w;							\
    __asm__ ("emul	%2,%1,%0"					\
	     : "=d" (__w)						\
	     : "%dI" ((USItype) (u)),					\
	       "dI" ((USItype) (v)));					\
    __w; })
#endif /* __i960__ */

#if defined (__M32R__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  /* The cmp clears the condition bit.  */ \
  __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "r" ((USItype) (bl))					\
	   : "cbit")
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  /* The cmp clears the condition bit.  */ \
  __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "r" ((USItype) (bl))					\
	   : "cbit")
#endif /* __M32R__ */

#if defined (__mc68000__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"				\
	   : "=d" ((USItype) (sh)),					\
	     "=&d" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "d" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"				\
	   : "=d" ((USItype) (sh)),					\
	     "=&d" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "d" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))

/* The '020, '030, '040, '060 and CPU32 have 32x32->64 and 64/32->32q-32r.  */
#if (defined (__mc68020__) && !defined (__mc68060__))
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("mulu%.l %3,%1:%0"						\
	   : "=d" ((USItype) (w0)),					\
	     "=d" ((USItype) (w1))					\
	   : "%0" ((USItype) (u)),					\
	     "dmi" ((USItype) (v)))
#define UMUL_TIME 45
#define udiv_qrnnd(q, r, n1, n0, d) \
  __asm__ ("divu%.l %4,%1:%0"						\
	   : "=d" ((USItype) (q)),					\
	     "=d" ((USItype) (r))					\
	   : "0" ((USItype) (n0)),					\
	     "1" ((USItype) (n1)),					\
	     "dmi" ((USItype) (d)))
#define UDIV_TIME 90
#define sdiv_qrnnd(q, r, n1, n0, d) \
  __asm__ ("divs%.l %4,%1:%0"						\
	   : "=d" ((USItype) (q)),					\
	     "=d" ((USItype) (r))					\
	   : "0" ((USItype) (n0)),					\
	     "1" ((USItype) (n1)),					\
	     "dmi" ((USItype) (d)))

#elif defined (__mcoldfire__) /* not mc68020 */

#define umul_ppmm(xh, xl, a, b) \
  __asm__ ("| Inlined umul_ppmm\n"					\
	   "	move%.l	%2,%/d0\n"					\
	   "	move%.l	%3,%/d1\n"					\
	   "	move%.l	%/d0,%/d2\n"					\
	   "	swap	%/d0\n"						\
	   "	move%.l	%/d1,%/d3\n"					\
	   "	swap	%/d1\n"						\
	   "	move%.w	%/d2,%/d4\n"					\
	   "	mulu	%/d3,%/d4\n"					\
	   "	mulu	%/d1,%/d2\n"					\
	   "	mulu	%/d0,%/d3\n"					\
	   "	mulu	%/d0,%/d1\n"					\
	   "	move%.l	%/d4,%/d0\n"					\
	   "	clr%.w	%/d0\n"						\
	   "	swap	%/d0\n"						\
	   "	add%.l	%/d0,%/d2\n"					\
	   "	add%.l	%/d3,%/d2\n"					\
	   "	jcc	1f\n"						\
	   "	add%.l	%#65536,%/d1\n"					\
	   "1:	swap	%/d2\n"						\
	   "	moveq	%#0,%/d0\n"					\
	   "	move%.w	%/d2,%/d0\n"					\
	   "	move%.w	%/d4,%/d2\n"					\
	   "	move%.l	%/d2,%1\n"					\
	   "	add%.l	%/d1,%/d0\n"					\
	   "	move%.l	%/d0,%0"					\
	   : "=g" ((USItype) (xh)),					\
	     "=g" ((USItype) (xl))					\
	   : "g" ((USItype) (a)),					\
	     "g" ((USItype) (b))					\
	   : "d0", "d1", "d2", "d3", "d4")
#define UMUL_TIME 100
#define UDIV_TIME 400
#else /* not ColdFire */
/* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX.  */
#define umul_ppmm(xh, xl, a, b) \
  __asm__ ("| Inlined umul_ppmm\n"					\
	   "	move%.l	%2,%/d0\n"					\
	   "	move%.l	%3,%/d1\n"					\
	   "	move%.l	%/d0,%/d2\n"					\
	   "	swap	%/d0\n"						\
	   "	move%.l	%/d1,%/d3\n"					\
	   "	swap	%/d1\n"						\
	   "	move%.w	%/d2,%/d4\n"					\
	   "	mulu	%/d3,%/d4\n"					\
	   "	mulu	%/d1,%/d2\n"					\
	   "	mulu	%/d0,%/d3\n"					\
	   "	mulu	%/d0,%/d1\n"					\
	   "	move%.l	%/d4,%/d0\n"					\
	   "	eor%.w	%/d0,%/d0\n"					\
	   "	swap	%/d0\n"						\
	   "	add%.l	%/d0,%/d2\n"					\
	   "	add%.l	%/d3,%/d2\n"					\
	   "	jcc	1f\n"						\
	   "	add%.l	%#65536,%/d1\n"					\
	   "1:	swap	%/d2\n"						\
	   "	moveq	%#0,%/d0\n"					\
	   "	move%.w	%/d2,%/d0\n"					\
	   "	move%.w	%/d4,%/d2\n"					\
	   "	move%.l	%/d2,%1\n"					\
	   "	add%.l	%/d1,%/d0\n"					\
	   "	move%.l	%/d0,%0"					\
	   : "=g" ((USItype) (xh)),					\
	     "=g" ((USItype) (xl))					\
	   : "g" ((USItype) (a)),					\
	     "g" ((USItype) (b))					\
	   : "d0", "d1", "d2", "d3", "d4")
#define UMUL_TIME 100
#define UDIV_TIME 400

#endif /* not mc68020 */

/* The '020, '030, '040 and '060 have bitfield insns.
   cpu32 disguises as a 68020, but lacks them.  */
#if defined (__mc68020__) && !defined (__mcpu32__)
#define count_leading_zeros(count, x) \
  __asm__ ("bfffo %1{%b2:%b2},%0"					\
	   : "=d" ((USItype) (count))					\
	   : "od" ((USItype) (x)), "n" (0))
/* Some ColdFire architectures have a ff1 instruction supported via
   __builtin_clz. */
#elif defined (__mcfisaaplus__) || defined (__mcfisac__)
#define count_leading_zeros(count,x) ((count) = __builtin_clz (x))
#define COUNT_LEADING_ZEROS_0 32
#endif
#endif /* mc68000 */

#if defined (__m88000__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%rJ" ((USItype) (ah)),					\
	     "rJ" ((USItype) (bh)),					\
	     "%rJ" ((USItype) (al)),					\
	     "rJ" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "rJ" ((USItype) (ah)),					\
	     "rJ" ((USItype) (bh)),					\
	     "rJ" ((USItype) (al)),					\
	     "rJ" ((USItype) (bl)))
#define count_leading_zeros(count, x) \
  do {									\
    USItype __cbtmp;							\
    __asm__ ("ff1 %0,%1"						\
	     : "=r" (__cbtmp)						\
	     : "r" ((USItype) (x)));					\
    (count) = __cbtmp ^ 31;						\
  } while (0)
#define COUNT_LEADING_ZEROS_0 63 /* sic */
#if defined (__mc88110__)
#define umul_ppmm(wh, wl, u, v) \
  do {									\
    union {UDItype __ll;						\
	   struct {USItype __h, __l;} __i;				\
	  } __xx;							\
    __asm__ ("mulu.d	%0,%1,%2"					\
	     : "=r" (__xx.__ll)						\
	     : "r" ((USItype) (u)),					\
	       "r" ((USItype) (v)));					\
    (wh) = __xx.__i.__h;						\
    (wl) = __xx.__i.__l;						\
  } while (0)
#define udiv_qrnnd(q, r, n1, n0, d) \
  ({union {UDItype __ll;						\
	   struct {USItype __h, __l;} __i;				\
	  } __xx;							\
  USItype __q;								\
  __xx.__i.__h = (n1); __xx.__i.__l = (n0);				\
  __asm__ ("divu.d %0,%1,%2"						\
	   : "=r" (__q)							\
	   : "r" (__xx.__ll),						\
	     "r" ((USItype) (d)));					\
  (r) = (n0) - __q * (d); (q) = __q; })
#define UMUL_TIME 5
#define UDIV_TIME 25
#else
#define UMUL_TIME 17
#define UDIV_TIME 150
#endif /* __mc88110__ */
#endif /* __m88000__ */

#if defined (__mips__) && W_TYPE_SIZE == 32
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    UDItype __x = (UDItype) (USItype) (u) * (USItype) (v);		\
    (w1) = (USItype) (__x >> 32);					\
    (w0) = (USItype) (__x);						\
  } while (0)
#define UMUL_TIME 10
#define UDIV_TIME 100

#if (__mips == 32 || __mips == 64) && ! __mips16
#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clz (X))
#define COUNT_LEADING_ZEROS_0 32
#endif
#endif /* __mips__ */

#if defined (__ns32000__) && W_TYPE_SIZE == 32
#define umul_ppmm(w1, w0, u, v) \
  ({union {UDItype __ll;						\
	   struct {USItype __l, __h;} __i;				\
	  } __xx;							\
  __asm__ ("meid %2,%0"							\
	   : "=g" (__xx.__ll)						\
	   : "%0" ((USItype) (u)),					\
	     "g" ((USItype) (v)));					\
  (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
#define __umulsidi3(u, v) \
  ({UDItype __w;							\
    __asm__ ("meid %2,%0"						\
	     : "=g" (__w)						\
	     : "%0" ((USItype) (u)),					\
	       "g" ((USItype) (v)));					\
    __w; })
#define udiv_qrnnd(q, r, n1, n0, d) \
  ({union {UDItype __ll;						\
	   struct {USItype __l, __h;} __i;				\
	  } __xx;							\
  __xx.__i.__h = (n1); __xx.__i.__l = (n0);				\
  __asm__ ("deid %2,%0"							\
	   : "=g" (__xx.__ll)						\
	   : "0" (__xx.__ll),						\
	     "g" ((USItype) (d)));					\
  (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
#define count_trailing_zeros(count,x) \
  do {									\
    __asm__ ("ffsd     %2,%0"						\
            : "=r" ((USItype) (count))					\
            : "0" ((USItype) 0),					\
              "r" ((USItype) (x)));					\
  } while (0)
#endif /* __ns32000__ */

/* FIXME: We should test _IBMR2 here when we add assembly support for the
   system vendor compilers.
   FIXME: What's needed for gcc PowerPC VxWorks?  __vxworks__ is not good
   enough, since that hits ARM and m68k too.  */
#if (defined (_ARCH_PPC)	/* AIX */				\
     || defined (_ARCH_PWR)	/* AIX */				\
     || defined (_ARCH_COM)	/* AIX */				\
     || defined (__powerpc__)	/* gcc */				\
     || defined (__POWERPC__)	/* BEOS */				\
     || defined (__ppc__)	/* Darwin */				\
     || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */    \
     || (defined (PPC) && defined (CPU_FAMILY)    /* VxWorks */               \
         && CPU_FAMILY == PPC)                                                \
     ) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (bh) && (bh) == 0)				\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else								\
      __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"		\
	     : "=r" (sh), "=&r" (sl)					\
	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
  } while (0)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (ah) && (ah) == 0)				\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == 0)			\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else								\
      __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	\
	       : "=r" (sh), "=&r" (sl)					\
	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
  } while (0)
#define count_leading_zeros(count, x) \
  __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
#define COUNT_LEADING_ZEROS_0 32
#if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
  || defined (__ppc__)                                                    \
  || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */       \
  || (defined (PPC) && defined (CPU_FAMILY)    /* VxWorks */                  \
         && CPU_FAMILY == PPC)
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    USItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define UMUL_TIME 15
#define smul_ppmm(ph, pl, m0, m1) \
  do {									\
    SItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define SMUL_TIME 14
#define UDIV_TIME 120
#elif defined (_ARCH_PWR)
#define UMUL_TIME 8
#define smul_ppmm(xh, xl, m0, m1) \
  __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1))
#define SMUL_TIME 4
#define sdiv_qrnnd(q, r, nh, nl, d) \
  __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d))
#define UDIV_TIME 100
#endif
#endif /* 32-bit POWER architecture variants.  */

/* We should test _IBMR2 here when we add assembly support for the system
   vendor compilers.  */
#if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (bh) && (bh) == 0)				\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)		\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else								\
      __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"		\
	     : "=r" (sh), "=&r" (sl)					\
	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
  } while (0)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (ah) && (ah) == 0)				\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == 0)			\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else								\
      __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	\
	       : "=r" (sh), "=&r" (sl)					\
	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
  } while (0)
#define count_leading_zeros(count, x) \
  __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
#define COUNT_LEADING_ZEROS_0 64
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    UDItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define UMUL_TIME 15
#define smul_ppmm(ph, pl, m0, m1) \
  do {									\
    DItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define SMUL_TIME 14  /* ??? */
#define UDIV_TIME 120 /* ??? */
#endif /* 64-bit PowerPC.  */

#if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("a %1,%5\n\tae %0,%3"					\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "r" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("s %1,%5\n\tse %0,%3"					\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "r" ((USItype) (bl)))
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    USItype __m0 = (m0), __m1 = (m1);					\
    __asm__ (								\
       "s	r2,r2\n"						\
"	mts	r10,%2\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	cas	%0,r2,r0\n"						\
"	mfs	r10,%1"							\
	     : "=r" ((USItype) (ph)),					\
	       "=r" ((USItype) (pl))					\
	     : "%r" (__m0),						\
		"r" (__m1)						\
	     : "r2");							\
    (ph) += ((((SItype) __m0 >> 31) & __m1)				\
	     + (((SItype) __m1 >> 31) & __m0));				\
  } while (0)
#define UMUL_TIME 20
#define UDIV_TIME 200
#define count_leading_zeros(count, x) \
  do {									\
    if ((x) >= 0x10000)							\
      __asm__ ("clz	%0,%1"						\
	       : "=r" ((USItype) (count))				\
	       : "r" ((USItype) (x) >> 16));				\
    else								\
      {									\
	__asm__ ("clz	%0,%1"						\
		 : "=r" ((USItype) (count))				\
		 : "r" ((USItype) (x)));					\
	(count) += 16;							\
      }									\
  } while (0)
#endif

#if defined(__sh__) && !__SHMEDIA__ && W_TYPE_SIZE == 32
#ifndef __sh1__
#define umul_ppmm(w1, w0, u, v) \
  __asm__ (								\
       "dmulu.l	%2,%3\n\tsts%M1	macl,%1\n\tsts%M0	mach,%0"	\
	   : "=r<" ((USItype)(w1)),					\
	     "=r<" ((USItype)(w0))					\
	   : "r" ((USItype)(u)),					\
	     "r" ((USItype)(v))						\
	   : "macl", "mach")
#define UMUL_TIME 5
#endif

/* This is the same algorithm as __udiv_qrnnd_c.  */
#define UDIV_NEEDS_NORMALIZATION 1

#define udiv_qrnnd(q, r, n1, n0, d) \
  do {									\
    extern UWtype __udiv_qrnnd_16 (UWtype, UWtype)			\
                        __attribute__ ((visibility ("hidden")));	\
    /* r0: rn r1: qn */ /* r0: n1 r4: n0 r5: d r6: d1 */ /* r2: __m */	\
    __asm__ (								\
	"mov%M4 %4,r5\n"						\
"	swap.w %3,r4\n"							\
"	swap.w r5,r6\n"							\
"	jsr @%5\n"							\
"	shll16 r6\n"							\
"	swap.w r4,r4\n"							\
"	jsr @%5\n"							\
"	swap.w r1,%0\n"							\
"	or r1,%0"							\
	: "=r" (q), "=&z" (r)						\
	: "1" (n1), "r" (n0), "rm" (d), "r" (&__udiv_qrnnd_16)		\
	: "r1", "r2", "r4", "r5", "r6", "pr", "t");			\
  } while (0)

#define UDIV_TIME 80

#define sub_ddmmss(sh, sl, ah, al, bh, bl)				\
  __asm__ ("clrt;subc %5,%1; subc %4,%0"				\
	   : "=r" (sh), "=r" (sl)					\
	   : "0" (ah), "1" (al), "r" (bh), "r" (bl)			\
	   : "t")

#endif /* __sh__ */

#if defined (__SH5__) && __SHMEDIA__ && W_TYPE_SIZE == 32
#define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
#define count_leading_zeros(count, x) \
  do									\
    {									\
      UDItype x_ = (USItype)(x);					\
      SItype c_;							\
									\
      __asm__ ("nsb %1, %0" : "=r" (c_) : "r" (x_));			\
      (count) = c_ - 31;						\
    }									\
  while (0)
#define COUNT_LEADING_ZEROS_0 32
#endif

#if defined (__sparc__) && !defined (__arch64__) && !defined (__sparcv9) \
    && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%rJ" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "%rJ" ((USItype) (al)),					\
	     "rI" ((USItype) (bl))					\
	   __CLOBBER_CC)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "rJ" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "rJ" ((USItype) (al)),					\
	     "rI" ((USItype) (bl))					\
	   __CLOBBER_CC)
#if defined (__sparc_v8__)
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("umul %2,%3,%1;rd %%y,%0"					\
	   : "=r" ((USItype) (w1)),					\
	     "=r" ((USItype) (w0))					\
	   : "r" ((USItype) (u)),					\
	     "r" ((USItype) (v)))
#define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
  __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
	   : "=&r" ((USItype) (__q)),					\
	     "=&r" ((USItype) (__r))					\
	   : "r" ((USItype) (__n1)),					\
	     "r" ((USItype) (__n0)),					\
	     "r" ((USItype) (__d)))
#else
#if defined (__sparclite__)
/* This has hardware multiply but not divide.  It also has two additional
   instructions scan (ffs from high bit) and divscc.  */
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("umul %2,%3,%1;rd %%y,%0"					\
	   : "=r" ((USItype) (w1)),					\
	     "=r" ((USItype) (w0))					\
	   : "r" ((USItype) (u)),					\
	     "r" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, d) \
  __asm__ ("! Inlined udiv_qrnnd\n"					\
"	wr	%%g0,%2,%%y	! Not a delayed write for sparclite\n"	\
"	tst	%%g0\n"							\
"	divscc	%3,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%0\n"						\
"	rd	%%y,%1\n"						\
"	bl,a 1f\n"							\
"	add	%1,%4,%1\n"						\
"1:	! End of inline udiv_qrnnd"					\
	   : "=r" ((USItype) (q)),					\
	     "=r" ((USItype) (r))					\
	   : "r" ((USItype) (n1)),					\
	     "r" ((USItype) (n0)),					\
	     "rI" ((USItype) (d))					\
	   : "g1" __AND_CLOBBER_CC)
#define UDIV_TIME 37
#define count_leading_zeros(count, x) \
  do {                                                                  \
  __asm__ ("scan %1,1,%0"                                               \
           : "=r" ((USItype) (count))                                   \
           : "r" ((USItype) (x)));					\
  } while (0)
/* Early sparclites return 63 for an argument of 0, but they warn that future
   implementations might change this.  Therefore, leave COUNT_LEADING_ZEROS_0
   undefined.  */
#else
/* SPARC without integer multiplication and divide instructions.
   (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("! Inlined umul_ppmm\n"					\
"	wr	%%g0,%2,%%y	! SPARC has 0-3 delay insn after a wr\n"\
"	sra	%3,31,%%o5	! Don't move this insn\n"		\
"	and	%2,%%o5,%%o5	! Don't move this insn\n"		\
"	andcc	%%g0,0,%%g1	! Don't move this insn\n"		\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,0,%%g1\n"						\
"	add	%%g1,%%o5,%0\n"						\
"	rd	%%y,%1"							\
	   : "=r" ((USItype) (w1)),					\
	     "=r" ((USItype) (w0))					\
	   : "%rI" ((USItype) (u)),					\
	     "r" ((USItype) (v))						\
	   : "g1", "o5" __AND_CLOBBER_CC)
#define UMUL_TIME 39		/* 39 instructions */
/* It's quite necessary to add this much assembler for the sparc.
   The default udiv_qrnnd (in C) is more than 10 times slower!  */
#define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
  __asm__ ("! Inlined udiv_qrnnd\n"					\
"	mov	32,%%g1\n"						\
"	subcc	%1,%2,%%g0\n"						\
"1:	bcs	5f\n"							\
"	 addxcc %0,%0,%0	! shift n1n0 and a q-bit in lsb\n"	\
"	sub	%1,%2,%1	! this kills msb of n\n"		\
"	addx	%1,%1,%1	! so this can't give carry\n"		\
"	subcc	%%g1,1,%%g1\n"						\
"2:	bne	1b\n"							\
"	 subcc	%1,%2,%%g0\n"						\
"	bcs	3f\n"							\
"	 addxcc %0,%0,%0	! shift n1n0 and a q-bit in lsb\n"	\
"	b	3f\n"							\
"	 sub	%1,%2,%1	! this kills msb of n\n"		\
"4:	sub	%1,%2,%1\n"						\
"5:	addxcc	%1,%1,%1\n"						\
"	bcc	2b\n"							\
"	 subcc	%%g1,1,%%g1\n"						\
"! Got carry from n.  Subtract next step to cancel this carry.\n"	\
"	bne	4b\n"							\
"	 addcc	%0,%0,%0	! shift n1n0 and a 0-bit in lsb\n"	\
"	sub	%1,%2,%1\n"						\
"3:	xnor	%0,0,%0\n"						\
"	! End of inline udiv_qrnnd"					\
	   : "=&r" ((USItype) (__q)),					\
	     "=&r" ((USItype) (__r))					\
	   : "r" ((USItype) (__d)),					\
	     "1" ((USItype) (__n1)),					\
	     "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
#define UDIV_TIME (3+7*32)	/* 7 instructions/iteration. 32 iterations.  */
#endif /* __sparclite__ */
#endif /* __sparc_v8__ */
#endif /* sparc32 */

#if ((defined (__sparc__) && defined (__arch64__)) || defined (__sparcv9)) \
    && W_TYPE_SIZE == 64
#define add_ssaaaa(sh, sl, ah, al, bh, bl)				\
  __asm__ ("addcc %r4,%5,%1\n\t"					\
   	   "add %r2,%3,%0\n\t"						\
   	   "bcs,a,pn %%xcc, 1f\n\t"					\
   	   "add %0, 1, %0\n"						\
	   "1:"								\
	   : "=r" ((UDItype)(sh)),				      	\
	     "=&r" ((UDItype)(sl))				      	\
	   : "%rJ" ((UDItype)(ah)),				     	\
	     "rI" ((UDItype)(bh)),				      	\
	     "%rJ" ((UDItype)(al)),				     	\
	     "rI" ((UDItype)(bl))				       	\
	   __CLOBBER_CC)

#define sub_ddmmss(sh, sl, ah, al, bh, bl) 				\
  __asm__ ("subcc %r4,%5,%1\n\t"					\
   	   "sub %r2,%3,%0\n\t"						\
   	   "bcs,a,pn %%xcc, 1f\n\t"					\
   	   "sub %0, 1, %0\n\t"						\
	   "1:"								\
	   : "=r" ((UDItype)(sh)),				      	\
	     "=&r" ((UDItype)(sl))				      	\
	   : "rJ" ((UDItype)(ah)),				     	\
	     "rI" ((UDItype)(bh)),				      	\
	     "rJ" ((UDItype)(al)),				     	\
	     "rI" ((UDItype)(bl))				       	\
	   __CLOBBER_CC)

#define umul_ppmm(wh, wl, u, v)						\
  do {									\
	  UDItype tmp1, tmp2, tmp3, tmp4;				\
	  __asm__ __volatile__ (					\
		   "srl %7,0,%3\n\t"					\
		   "mulx %3,%6,%1\n\t"					\
		   "srlx %6,32,%2\n\t"					\
		   "mulx %2,%3,%4\n\t"					\
		   "sllx %4,32,%5\n\t"					\
		   "srl %6,0,%3\n\t"					\
		   "sub %1,%5,%5\n\t"					\
		   "srlx %5,32,%5\n\t"					\
		   "addcc %4,%5,%4\n\t"					\
		   "srlx %7,32,%5\n\t"					\
		   "mulx %3,%5,%3\n\t"					\
		   "mulx %2,%5,%5\n\t"					\
		   "sethi %%hi(0x80000000),%2\n\t"			\
		   "addcc %4,%3,%4\n\t"					\
		   "srlx %4,32,%4\n\t"					\
		   "add %2,%2,%2\n\t"					\
		   "movcc %%xcc,%%g0,%2\n\t"				\
		   "addcc %5,%4,%5\n\t"					\
		   "sllx %3,32,%3\n\t"					\
		   "add %1,%3,%1\n\t"					\
		   "add %5,%2,%0"					\
	   : "=r" ((UDItype)(wh)),					\
	     "=&r" ((UDItype)(wl)),					\
	     "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4)	\
	   : "r" ((UDItype)(u)),					\
	     "r" ((UDItype)(v))						\
	   __CLOBBER_CC);						\
  } while (0)
#define UMUL_TIME 96
#define UDIV_TIME 230
#endif /* sparc64 */

#if defined (__vax__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addl2 %5,%1\n\tadwc %3,%0"					\
	   : "=g" ((USItype) (sh)),					\
	     "=&g" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"					\
	   : "=g" ((USItype) (sh)),					\
	     "=&g" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define umul_ppmm(xh, xl, m0, m1) \
  do {									\
    union {								\
	UDItype __ll;							\
	struct {USItype __l, __h;} __i;					\
      } __xx;								\
    USItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("emul %1,%2,$0,%0"						\
	     : "=r" (__xx.__ll)						\
	     : "g" (__m0),						\
	       "g" (__m1));						\
    (xh) = __xx.__i.__h;						\
    (xl) = __xx.__i.__l;						\
    (xh) += ((((SItype) __m0 >> 31) & __m1)				\
	     + (((SItype) __m1 >> 31) & __m0));				\
  } while (0)
#define sdiv_qrnnd(q, r, n1, n0, d) \
  do {									\
    union {DItype __ll;							\
	   struct {SItype __l, __h;} __i;				\
	  } __xx;							\
    __xx.__i.__h = n1; __xx.__i.__l = n0;				\
    __asm__ ("ediv %3,%2,%0,%1"						\
	     : "=g" (q), "=g" (r)					\
	     : "g" (__xx.__ll), "g" (d));				\
  } while (0)
#endif /* __vax__ */

#if defined (__xtensa__) && W_TYPE_SIZE == 32
/* This code is not Xtensa-configuration-specific, so rely on the compiler
   to expand builtin functions depending on what configuration features
   are available.  This avoids library calls when the operation can be
   performed in-line.  */
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    DWunion __w;							\
    __w.ll = __builtin_umulsidi3 (u, v);				\
    w1 = __w.s.high;							\
    w0 = __w.s.low;							\
  } while (0)
#define __umulsidi3(u, v)		__builtin_umulsidi3 (u, v)
#define count_leading_zeros(COUNT, X)	((COUNT) = __builtin_clz (X))
#define count_trailing_zeros(COUNT, X)	((COUNT) = __builtin_ctz (X))
#endif /* __xtensa__ */

#if defined (__z8000__) && W_TYPE_SIZE == 16
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add	%H1,%H5\n\tadc	%H0,%H3"				\
	   : "=r" ((unsigned int)(sh)),					\
	     "=&r" ((unsigned int)(sl))					\
	   : "%0" ((unsigned int)(ah)),					\
	     "r" ((unsigned int)(bh)),					\
	     "%1" ((unsigned int)(al)),					\
	     "rQR" ((unsigned int)(bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub	%H1,%H5\n\tsbc	%H0,%H3"				\
	   : "=r" ((unsigned int)(sh)),					\
	     "=&r" ((unsigned int)(sl))					\
	   : "0" ((unsigned int)(ah)),					\
	     "r" ((unsigned int)(bh)),					\
	     "1" ((unsigned int)(al)),					\
	     "rQR" ((unsigned int)(bl)))
#define umul_ppmm(xh, xl, m0, m1) \
  do {									\
    union {long int __ll;						\
	   struct {unsigned int __h, __l;} __i;				\
	  } __xx;							\
    unsigned int __m0 = (m0), __m1 = (m1);				\
    __asm__ ("mult	%S0,%H3"					\
	     : "=r" (__xx.__i.__h),					\
	       "=r" (__xx.__i.__l)					\
	     : "%1" (__m0),						\
	       "rQR" (__m1));						\
    (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;				\
    (xh) += ((((signed int) __m0 >> 15) & __m1)				\
	     + (((signed int) __m1 >> 15) & __m0));			\
  } while (0)
#endif /* __z8000__ */

#endif /* __GNUC__ */

/* If this machine has no inline assembler, use C macros.  */

#if !defined (add_ssaaaa)
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  do {									\
    UWtype __x;								\
    __x = (al) + (bl);							\
    (sh) = (ah) + (bh) + (__x < (al));					\
    (sl) = __x;								\
  } while (0)
#endif

#if !defined (sub_ddmmss)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  do {									\
    UWtype __x;								\
    __x = (al) - (bl);							\
    (sh) = (ah) - (bh) - (__x > (al));					\
    (sl) = __x;								\
  } while (0)
#endif

/* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
   smul_ppmm.  */
#if !defined (umul_ppmm) && defined (smul_ppmm)
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    UWtype __w1;							\
    UWtype __xm0 = (u), __xm1 = (v);					\
    smul_ppmm (__w1, w0, __xm0, __xm1);					\
    (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1)		\
		+ (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0);		\
  } while (0)
#endif

/* If we still don't have umul_ppmm, define it using plain C.  */
#if !defined (umul_ppmm)
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    UWtype __x0, __x1, __x2, __x3;					\
    UHWtype __ul, __vl, __uh, __vh;					\
									\
    __ul = __ll_lowpart (u);						\
    __uh = __ll_highpart (u);						\
    __vl = __ll_lowpart (v);						\
    __vh = __ll_highpart (v);						\
									\
    __x0 = (UWtype) __ul * __vl;					\
    __x1 = (UWtype) __ul * __vh;					\
    __x2 = (UWtype) __uh * __vl;					\
    __x3 = (UWtype) __uh * __vh;					\
									\
    __x1 += __ll_highpart (__x0);/* this can't give carry */		\
    __x1 += __x2;		/* but this indeed can */		\
    if (__x1 < __x2)		/* did we get it? */			\
      __x3 += __ll_B;		/* yes, add it in the proper pos.  */	\
									\
    (w1) = __x3 + __ll_highpart (__x1);					\
    (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0);		\
  } while (0)
#endif

#if !defined (__umulsidi3)
#define __umulsidi3(u, v) \
  ({DWunion __w;							\
    umul_ppmm (__w.s.high, __w.s.low, u, v);				\
    __w.ll; })
#endif

/* Define this unconditionally, so it can be used for debugging.  */
#define __udiv_qrnnd_c(q, r, n1, n0, d) \
  do {									\
    UWtype __d1, __d0, __q1, __q0;					\
    UWtype __r1, __r0, __m;						\
    __d1 = __ll_highpart (d);						\
    __d0 = __ll_lowpart (d);						\
									\
    __r1 = (n1) % __d1;							\
    __q1 = (n1) / __d1;							\
    __m = (UWtype) __q1 * __d0;						\
    __r1 = __r1 * __ll_B | __ll_highpart (n0);				\
    if (__r1 < __m)							\
      {									\
	__q1--, __r1 += (d);						\
	if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
	  if (__r1 < __m)						\
	    __q1--, __r1 += (d);					\
      }									\
    __r1 -= __m;							\
									\
    __r0 = __r1 % __d1;							\
    __q0 = __r1 / __d1;							\
    __m = (UWtype) __q0 * __d0;						\
    __r0 = __r0 * __ll_B | __ll_lowpart (n0);				\
    if (__r0 < __m)							\
      {									\
	__q0--, __r0 += (d);						\
	if (__r0 >= (d))						\
	  if (__r0 < __m)						\
	    __q0--, __r0 += (d);					\
      }									\
    __r0 -= __m;							\
									\
    (q) = (UWtype) __q1 * __ll_B | __q0;				\
    (r) = __r0;								\
  } while (0)

/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
   __udiv_w_sdiv (defined in libgcc or elsewhere).  */
#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
#define udiv_qrnnd(q, r, nh, nl, d) \
  do {									\
    USItype __r;							\
    (q) = __udiv_w_sdiv (&__r, nh, nl, d);				\
    (r) = __r;								\
  } while (0)
#endif

/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
#if !defined (udiv_qrnnd)
#define UDIV_NEEDS_NORMALIZATION 1
#define udiv_qrnnd __udiv_qrnnd_c
#endif

#if !defined (count_leading_zeros)
#define count_leading_zeros(count, x) \
  do {									\
    UWtype __xr = (x);							\
    UWtype __a;								\
									\
    if (W_TYPE_SIZE <= 32)						\
      {									\
	__a = __xr < ((UWtype)1<<2*__BITS4)				\
	  ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4)			\
	  : (__xr < ((UWtype)1<<3*__BITS4) ?  2*__BITS4 : 3*__BITS4);	\
      }									\
    else								\
      {									\
	for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8)			\
	  if (((__xr >> __a) & 0xff) != 0)				\
	    break;							\
      }									\
									\
    (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a);		\
  } while (0)
#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
#endif

#if !defined (count_trailing_zeros)
/* Define count_trailing_zeros using count_leading_zeros.  The latter might be
   defined in asm, but if it is not, the C version above is good enough.  */
#define count_trailing_zeros(count, x) \
  do {									\
    UWtype __ctz_x = (x);						\
    UWtype __ctz_c;							\
    count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x);			\
    (count) = W_TYPE_SIZE - 1 - __ctz_c;				\
  } while (0)
#endif

#ifndef UDIV_NEEDS_NORMALIZATION
#define UDIV_NEEDS_NORMALIZATION 0
#endif
dietlibc-0.33~cvs20120325/mips/Makefile.add010064400000000000000000000012751173363227100150470ustar00# Now this needs explanation.
# mips-linux is per default big endian.  Then they ported it to little
# endian MIPS (Windoze CE handhelds mostly) and named the architecture
# mipsel.  However, if you build a cross compiler for mips-linux, it
# will default to generating little endian objects.  So, if we are
# cross compiling, we set need to set the endianness to big endian with
# -EB because we also have a mipsel cross compiler target that is meant
# to generate little endian code.  Confusing, eh?
ifeq ($(CROSS),mips-linux-)
ENDIAN=-meb
endif
CFLAGS+=$(ENDIAN) -Os -march=mips2
VPATH:=mips:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/pread64.o $(OBJDIR)/pwrite64.o $(OBJDIR)/divdi3.o $(OBJDIR)/__CAS.o
dietlibc-0.33~cvs20120325/mips/__CAS.S010064400000000000000000000003041173363227100137000ustar00.text
.global __CAS
.type __CAS,@function
__CAS:
.set noreorder
.set noat
	sync
1:
	ll	$2,0($4)
	bne	$2,$5,2f
	move	$1,$6
	sc	$1,0($4)
	beq	$1,$0,1b
	nop
	sync
2:
	j $31
	nop
.size __CAS, .-__CAS
dietlibc-0.33~cvs20120325/mips/__longjmp.S010064400000000000000000000014731173363227100147500ustar00.text
.align 2
.global __longjmp
.ent	__longjmp
__longjmp:
	/* load coprocessor status */
	lw	 $2, 48($4)
	/* restore callee save floating point registers (double) */
	l.d	$f20, 56($4)	/* fs0 */
	l.d	$f22, 64($4)	/* fs1 */
	l.d	$f24, 72($4)	/* fs2 */
	l.d	$f26, 80($4)	/* fs3 */
	l.d	$f28, 88($4)	/* fs4 */
	l.d	$f30, 96($4)	/* fs6 */
	/* restore coprocessor status register */
	ctc1	 $2, $31
	/* restore callee save integer register */
	lw	$25,  0($4)	/* ra */
	lw	$29,  4($4)	/* sp */
	lw	$16,  8($4)	/* s0 */
	lw	$17, 12($4)	/* s1 */
	lw	$18, 16($4)	/* s2 */
	lw	$19, 20($4)	/* s3 */
	lw	$20, 24($4)	/* s4 */
	lw	$21, 28($4)	/* s5 */
	lw	$22, 32($4)	/* s6 */
	lw	$23, 36($4)	/* s7 */
	lw	$30, 40($4)	/* fp/s8 */
	lw	$gp, 44($4)	/* gp */
	/* never return 0 */
	move	 $2, $5
	bne	 $5, $0,1f
	li	 $2, 1
1:	j	$25
.end	__longjmp
dietlibc-0.33~cvs20120325/mips/__pread.S010064400000000000000000000000561173363227100143710ustar00#include "syscalls.h"

syscall(pread,__pread)
dietlibc-0.33~cvs20120325/mips/__pwrite.S010064400000000000000000000000601173363227100146030ustar00#include "syscalls.h"

syscall(pwrite,__pwrite)
dietlibc-0.33~cvs20120325/mips/__testandset.S010064400000000000000000000003651173363227100154570ustar00.text
.align 2
.global __testandset
.ent	__testandset
.type	__testandset,@function
__testandset:
1:	.set	mips2
	ll	$2, 0($4)
	.set	noreorder
	bnez	$2, 1f
	li	$8, 1
	.set	reorder
	sc	$8, 0($4)
	beqz	$8, 1b
1:	.set	mips0
	jr	$31
.end	__testandset
dietlibc-0.33~cvs20120325/mips/clone.S010064400000000000000000000012061173363227100140760ustar00#include 
#include "syscalls.h"

.text
.align 2
.global __clone
.ent	__clone
.type __clone,@function
__clone:
	.set noreorder
	.cpload $25
	.set reorder
	subu	$29,$29,32
	.cprestore 16

	li	$2, EINVAL
	beqz	$4, .Lerror
	beqz	$5, .Lerror

	subu	$5, $5, 32	/* resterve some space */
	sw	$4, 0($5)	/* save function pointer */
	sw	$7, 4($5)	/* save arg pointer */

	move	$4, $6
	li	$2, __NR_clone
	syscall

	bnez	$7, .Lerror
	beqz	$2, .Lstart

	addu	$29,$29,32	/* free stack */
	jr	$31

.Lerror:
	la	$25, error_unified_syscall
	jr	$25

.Lstart:
	lw	$28,16($29)
	lw	$25, 0($29)
	lw	$4,  4($29)
	jalr	$25
	move	$4, $2
	jal	_exit

.end	__clone
dietlibc-0.33~cvs20120325/mips/divdi3.c010064400000000000000000000152621173363227100142070ustar00/* 64-bit multiplication and division
   Copyright (C) 1989, 1992-1999, 2000, 2001, 2002, 2003, 2004
   Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 

#if __WORDSIZE == 32

const
unsigned char __clz_tab[] =
{
  0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
  6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
};

#include "mips/longlong.h"

typedef unsigned int UQItype	__attribute__ ((mode (QI)));
typedef          int SItype	__attribute__ ((mode (SI)));
typedef unsigned int USItype	__attribute__ ((mode (SI)));
typedef          int DItype	__attribute__ ((mode (DI)));
typedef unsigned int UDItype	__attribute__ ((mode (DI)));
#define Wtype SItype
#define HWtype SItype
#define DWtype DItype
#define UWtype USItype
#define UHWtype USItype
#define UDWtype UDItype
#define W_TYPE_SIZE 32

#if __BYTE_ORDER == __BIG_ENDIAN
struct DWstruct { Wtype high, low;};
#elif __BYTE_ORDER == __LITTLE_ENDIAN
struct DWstruct { Wtype low, high;};
#else
#error Unhandled endianity
#endif
typedef union { struct DWstruct s; DWtype ll; } DWunion;

/* Prototypes of exported functions.  */
extern DWtype __divdi3 (DWtype u, DWtype v);
extern DWtype __moddi3 (DWtype u, DWtype v);
extern UDWtype __udivdi3 (UDWtype u, UDWtype v);
extern UDWtype __umoddi3 (UDWtype u, UDWtype v);

static UDWtype
__udivmoddi4 (UDWtype n, UDWtype d, UDWtype *rp)
{
  DWunion ww;
  DWunion nn, dd;
  DWunion rr;
  UWtype d0, d1, n0, n1, n2;
  UWtype q0, q1;
  UWtype b, bm;

  nn.ll = n;
  dd.ll = d;

  d0 = dd.s.low;
  d1 = dd.s.high;
  n0 = nn.s.low;
  n1 = nn.s.high;

#if !UDIV_NEEDS_NORMALIZATION
  if (d1 == 0)
    {
      if (d0 > n1)
	{
	  /* 0q = nn / 0D */

	  udiv_qrnnd (q0, n0, n1, n0, d0);
	  q1 = 0;

	  /* Remainder in n0.  */
	}
      else
	{
	  /* qq = NN / 0d */

	  if (d0 == 0)
	    d0 = 1 / d0;	/* Divide intentionally by zero.  */

	  udiv_qrnnd (q1, n1, 0, n1, d0);
	  udiv_qrnnd (q0, n0, n1, n0, d0);

	  /* Remainder in n0.  */
	}

      if (rp != 0)
	{
	  rr.s.low = n0;
	  rr.s.high = 0;
	  *rp = rr.ll;
	}
    }

#else /* UDIV_NEEDS_NORMALIZATION */

  if (d1 == 0)
    {
      if (d0 > n1)
	{
	  /* 0q = nn / 0D */

	  count_leading_zeros (bm, d0);

	  if (bm != 0)
	    {
	      /* Normalize, i.e. make the most significant bit of the
		 denominator set.  */

	      d0 = d0 << bm;
	      n1 = (n1 << bm) | (n0 >> (W_TYPE_SIZE - bm));
	      n0 = n0 << bm;
	    }

	  udiv_qrnnd (q0, n0, n1, n0, d0);
	  q1 = 0;

	  /* Remainder in n0 >> bm.  */
	}
      else
	{
	  /* qq = NN / 0d */

	  if (d0 == 0)
	    d0 = 1 / d0;	/* Divide intentionally by zero.  */

	  count_leading_zeros (bm, d0);

	  if (bm == 0)
	    {
	      /* From (n1 >= d0) /\ (the most significant bit of d0 is set),
		 conclude (the most significant bit of n1 is set) /\ (the
		 leading quotient digit q1 = 1).

		 This special case is necessary, not an optimization.
		 (Shifts counts of W_TYPE_SIZE are undefined.)  */

	      n1 -= d0;
	      q1 = 1;
	    }
	  else
	    {
	      /* Normalize.  */

	      b = W_TYPE_SIZE - bm;

	      d0 = d0 << bm;
	      n2 = n1 >> b;
	      n1 = (n1 << bm) | (n0 >> b);
	      n0 = n0 << bm;

	      udiv_qrnnd (q1, n1, n2, n1, d0);
	    }

	  /* n1 != d0...  */

	  udiv_qrnnd (q0, n0, n1, n0, d0);

	  /* Remainder in n0 >> bm.  */
	}

      if (rp != 0)
	{
	  rr.s.low = n0 >> bm;
	  rr.s.high = 0;
	  *rp = rr.ll;
	}
    }
#endif /* UDIV_NEEDS_NORMALIZATION */

  else
    {
      if (d1 > n1)
	{
	  /* 00 = nn / DD */

	  q0 = 0;
	  q1 = 0;

	  /* Remainder in n1n0.  */
	  if (rp != 0)
	    {
	      rr.s.low = n0;
	      rr.s.high = n1;
	      *rp = rr.ll;
	    }
	}
      else
	{
	  /* 0q = NN / dd */

	  count_leading_zeros (bm, d1);
	  if (bm == 0)
	    {
	      /* From (n1 >= d1) /\ (the most significant bit of d1 is set),
		 conclude (the most significant bit of n1 is set) /\ (the
		 quotient digit q0 = 0 or 1).

		 This special case is necessary, not an optimization.  */

	      /* The condition on the next line takes advantage of that
		 n1 >= d1 (true due to program flow).  */
	      if (n1 > d1 || n0 >= d0)
		{
		  q0 = 1;
		  sub_ddmmss (n1, n0, n1, n0, d1, d0);
		}
	      else
		q0 = 0;

	      q1 = 0;

	      if (rp != 0)
		{
		  rr.s.low = n0;
		  rr.s.high = n1;
		  *rp = rr.ll;
		}
	    }
	  else
	    {
	      UWtype m1, m0;
	      /* Normalize.  */

	      b = W_TYPE_SIZE - bm;

	      d1 = (d1 << bm) | (d0 >> b);
	      d0 = d0 << bm;
	      n2 = n1 >> b;
	      n1 = (n1 << bm) | (n0 >> b);
	      n0 = n0 << bm;

	      udiv_qrnnd (q0, n1, n2, n1, d1);
	      umul_ppmm (m1, m0, q0, d0);

	      if (m1 > n1 || (m1 == n1 && m0 > n0))
		{
		  q0--;
		  sub_ddmmss (m1, m0, m1, m0, d1, d0);
		}

	      q1 = 0;

	      /* Remainder in (n1n0 - m1m0) >> bm.  */
	      if (rp != 0)
		{
		  sub_ddmmss (n1, n0, n1, n0, m1, m0);
		  rr.s.low = (n1 << b) | (n0 >> bm);
		  rr.s.high = n1 >> bm;
		  *rp = rr.ll;
		}
	    }
	}
    }

  ww.s.low = q0;
  ww.s.high = q1;
  return ww.ll;
}

DWtype
__divdi3 (DWtype u, DWtype v)
{
  Wtype c = 0;
  DWtype w;

  if (u < 0)
    {
      c = ~c;
      u = -u;
    }
  if (v < 0)
    {
      c = ~c;
      v = -v;
    }
  w = __udivmoddi4 (u, v, NULL);
  if (c)
    w = -w;
  return w;
}

DWtype
__moddi3 (DWtype u, DWtype v)
{
  Wtype c = 0;
  DWtype w;

  if (u < 0)
    {
      c = ~c;
      u = -u;
    }
  if (v < 0)
    v = -v;
  __udivmoddi4 (u, v, (UDWtype *) &w);
  if (c)
    w = -w;
  return w;
}

UDWtype
__udivdi3 (UDWtype u, UDWtype v)
{
  return __udivmoddi4 (u, v, NULL);
}

UDWtype
__umoddi3 (UDWtype u, UDWtype v)
{
  UDWtype w;

  __udivmoddi4 (u, v, &w);
  return w;
}

#endif
dietlibc-0.33~cvs20120325/mips/errlist.S010064400000000000000000000204011173363227100144600ustar00#ifdef __DYN_LIB
.section	.data
#else
.section	.rodata
#endif

.align 4
.global sys_errlist
.type	sys_errlist,@object
sys_errlist:
	.long .LC000
	.long .LC001
	.long .LC002
	.long .LC003
	.long .LC004
	.long .LC005
	.long .LC006
	.long .LC007
	.long .LC008
	.long .LC009
	.long .LC010
	.long .LC011
	.long .LC012
	.long .LC013
	.long .LC014
	.long .LC015
	.long .LC016
	.long .LC017
	.long .LC018
	.long .LC019
	.long .LC020
	.long .LC021
	.long .LC022
	.long .LC023
	.long .LC024
	.long .LC025
	.long .LC026
	.long .LC027
	.long .LC028
	.long .LC029
	.long .LC030
	.long .LC031
	.long .LC032
	.long .LC033
	.long .LC034
	.long .LC035
	.long .LC036
	.long .LC037
	.long .LC038
	.long .LC039
	.long .LC040
	.long .LC041
	.long .LC042
	.long .LC043
	.long .LC044
	.long .LC045
	.long .LC046
	.long .LC047
	.long .LC048
	.long .LC049
	.long .LC050
	.long .LC051
	.long .LC052
	.long .LC053
	.long .LC054
	.long .LC055
	.long .LC056
	.long .LC057
	.long .LC058
	.long .LC059
	.long .LC060
	.long .LC061
	.long .LC062
	.long .LC063
	.long .LC064
	.long .LC065
	.long .LC066
	.long .LC067
	.long .LC068
	.long .LC069
	.long .LC070
	.long .LC071
	.long .LC072
	.long .LC073
	.long .LC074
	.long .LC075
	.long .LC076
	.long .LC077
	.long .LC078
	.long .LC079
	.long .LC080
	.long .LC081
	.long .LC082
	.long .LC083
	.long .LC084
	.long .LC085
	.long .LC086
	.long .LC087
	.long .LC088
	.long .LC089
	.long .LC090
	.long .LC091
	.long .LC092
	.long .LC093
	.long .LC094
	.long .LC095
	.long .LC096
	.long .LC097
	.long .LC098
	.long .LC099
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC120
	.long .LC121
	.long .LC122
	.long .LC123
	.long .LC124
	.long .LC125
	.long .LC126
	.long .LC127
	.long .LC128
	.long .LC129
	.long .LC130
	.long .LC131
	.long .LC132
	.long .LC133
	.long .LC134
	.long .LC135
	.long .LC136
	.long .LC137
	.long .LC138
	.long .LC139
	.long .LC140
	.long .LC141
	.long .LC142
	.long .LC143
	.long .LC144
	.long .LC145
	.long .LC146
	.long .LC147
	.long .LC148
	.long .LC149
	.long .LC150
	.long .LC151
	.long .LC152
	.long .LC153
	.long .LC154
	.long .LC155
	.long .LC156
	.long .LC157
	.long .LC158
	.long .LC159
	.long .LC160
	.long .LC161
	.long .LC162
	.long .LC163
	.long .LC164
	.long 0
.size sys_errlist,.-sys_errlist

.align 4
.global sys_nerr
.type	sys_nerr,@object
sys_nerr:
	.long 161
.size	 sys_nerr,4

#ifdef __DYN_LIB
.section	.rodata
#endif

.LC000:	.string	"Success"
.LC001: .string "Operation not permitted"
.LC002: .string "No such file or directory"
.LC003: .string "No such process"
.LC004: .string "Interrupted system call"
.LC005: .string "I/O error"
.LC006: .string "No such device or address"
.LC007: .string "Arg list too long"
.LC008: .string "Exec format error"
.LC009: .string "Bad file number"
.LC010: .string "No child processes"
.LC011: .string "Try again"
.LC012: .string "Out of memory"
.LC013: .string "Permission denied"
.LC014: .string "Bad address"
.LC015: .string "Block device required"
.LC016: .string "Device or resource busy"
.LC017: .string "File exists"
.LC018: .string "Cross-device link"
.LC019: .string "No such device"
.LC020: .string "Not a directory"
.LC021: .string "Is a directory"
.LC022: .string "Invalid argument"
.LC023: .string "File table overflow"
.LC024: .string "Too many open files"
.LC025: .string "Not a typewriter"
.LC026: .string "Text file busy"
.LC027: .string "File too large"
.LC028: .string "No space left on device"
.LC029: .string "Illegal seek"
.LC030: .string "Read-only file system"
.LC031: .string "Too many links"
.LC032: .string "Broken pipe"
.LC033: .string "Math argument out of domain of func"
.LC034: .string "Math result not representable"
.LC035: .string "No message of desired type"
.LC036: .string "Identifier removed"
.LC037: .string "Channel number out of range"
.LC038: .string "Level 2 not synchronized"
.LC039: .string "Level 3 halted"
.LC040: .string "Level 3 reset"
.LC041: .string "Link number out of range"
.LC042: .string "Protocol driver not attached"
.LC043: .string "No CSI structure available"
.LC044: .string "Level 2 halted"
.LC045: .string "Resource deadlock would occur"
.LC046: .string "No record locks available"
.LC047: .string "Error 47"
.LC048: .string "Error 48"
.LC049: .string "Error 49"
.LC050: .string "Invalid exchange"
.LC051: .string "Invalid request descriptor"
.LC052: .string "Exchange full"
.LC053: .string "No anode"
.LC054: .string "Invalid request code"
.LC055: .string "Invalid slot"
.LC056: .string "File locking deadlock error"
.LC057: .string "Error 57"
.LC058: .string "Error 58"
.LC059: .string "Bad font file format"
.LC060: .string "Device not a stream"
.LC061: .string "No data available"
.LC062: .string "Timer expired"
.LC063: .string "Out of streams resources"
.LC064: .string "Machine is not on the network"
.LC065: .string "Package not installed"
.LC066: .string "Object is remote"
.LC067: .string "Link has been severed"
.LC068: .string "Advertise error"
.LC069: .string "Srmount error"
.LC070: .string "Communication error on send"
.LC071: .string "Protocol error"
.LC072: .string "Error 72"
.LC073: .string "RFS specific error"
.LC074: .string "Multihop attempted"
.LC075: .string "Error 75"
.LC076: .string "Error 76"
.LC077: .string "Not a data message"
.LC078: .string "File name too long"
.LC079: .string "Value too large for defined data type"
.LC080: .string "Name not unique on network"
.LC081: .string "File descriptor in bad state"
.LC082: .string "Remote address changed"
.LC083: .string "Can not access a needed shared library"
.LC084: .string "Accessing a corrupted shared library"
.LC085: .string ".lib section in a.out corrupted"
.LC086: .string "Attempting to link in too many shared libraries"
.LC087: .string "Cannot exec a shared library directly"
.LC088: .string "Illegal byte sequence"
.LC089: .string "Function not implemented"
.LC090: .string "Too many symbolic links encountered"
.LC091: .string "Interrupted system call should be restarted"
.LC092: .string "Streams pipe error"
.LC093: .string "Directory not empty"
.LC094: .string "Too many users"
.LC095: .string "Socket operation on non-socket"
.LC096: .string "Destination address required"
.LC097: .string "Message too long"
.LC098: .string "Protocol wrong type for socket"
.LC099: .string "Protocol not available"
.LC100: .string "Error 100-119"
.LC120: .string "Protocol not supported"
.LC121: .string "Socket type not supported"
.LC122: .string "Operation not supported on transport endpoint"
.LC123: .string "Protocol family not supported"
.LC124: .string "Address family not supported by protocol"
.LC125: .string "Address already in use"
.LC126: .string "Cannot assign requested address"
.LC127: .string "Network is down"
.LC128: .string "Network is unreachable"
.LC129: .string "Network dropped connection because of reset"
.LC130: .string "Software caused connection abort"
.LC131: .string "Connection reset by peer"
.LC132: .string "No buffer space available"
.LC133: .string "Transport endpoint is already connected"
.LC134: .string "Transport endpoint is not connected"
.LC135: .string "Structure needs cleaning"
.LC136: .string "Error 136"
.LC137: .string "Not a XENIX named type file"
.LC138: .string "No XENIX semaphores available"
.LC139: .string "Is a named type file"
.LC140: .string "Remote I/O error"
.LC141: .string "Reserved"
.LC142: .string "Error 142"
.LC143: .string "Cannot send after transport endpoint shutdown"
.LC144: .string "Too many references: cannot splice"
.LC145: .string "Connection timed out"
.LC146: .string "Connection refused"
.LC147: .string "Host is down"
.LC148: .string "No route to host"
.LC149: .string "Operation already in progress"
.LC150: .string "Operation now in progress"
.LC151: .string "Stale NFS file handle"
.LC152: .string "Error 152"
.LC153: .string "Error 153"
.LC154: .string "Error 154"
.LC155: .string "Error 155"
.LC156: .string "Error 156"
.LC157: .string "Error 157"
.LC158: .string "AIO operation canceled"
.LC159: .string "No medium found"
.LC160: .string "Wrong medium type"
.LC161: .string "Required key not available"
.LC162: .string "Key has expired"
.LC163: .string "Key has been revoked"
.LC164: .string "Key was rejected by service"
/* handled in strerror.c
.LC1133: .string "Quota exceeded"
*/
dietlibc-0.33~cvs20120325/mips/longlong.h010064400000000000000000001433321173363227100146510ustar00/* longlong.h -- definitions for mixed size 32/64 bit arithmetic.
   Copyright (C) 1991, 1992, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
   2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.

   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

/* You have to define the following before including this file:

   UWtype -- An unsigned type, default type for operations (typically a "word")
   UHWtype -- An unsigned type, at least half the size of UWtype.
   UDWtype -- An unsigned type, at least twice as large a UWtype
   W_TYPE_SIZE -- size in bits of UWtype

   UQItype -- Unsigned 8 bit type.
   SItype, USItype -- Signed and unsigned 32 bit types.
   DItype, UDItype -- Signed and unsigned 64 bit types.

   On a 32 bit machine UWtype should typically be USItype;
   on a 64 bit machine, UWtype should typically be UDItype.  */

#define __BITS4 (W_TYPE_SIZE / 4)
#define __ll_B ((UWtype) 1 << (W_TYPE_SIZE / 2))
#define __ll_lowpart(t) ((UWtype) (t) & (__ll_B - 1))
#define __ll_highpart(t) ((UWtype) (t) >> (W_TYPE_SIZE / 2))

#ifndef W_TYPE_SIZE
#define W_TYPE_SIZE	32
#define UWtype		USItype
#define UHWtype		USItype
#define UDWtype		UDItype
#endif

/* Define auxiliary asm macros.

   1) umul_ppmm(high_prod, low_prod, multiplier, multiplicand) multiplies two
   UWtype integers MULTIPLIER and MULTIPLICAND, and generates a two UWtype
   word product in HIGH_PROD and LOW_PROD.

   2) __umulsidi3(a,b) multiplies two UWtype integers A and B, and returns a
   UDWtype product.  This is just a variant of umul_ppmm.

   3) udiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
   denominator) divides a UDWtype, composed by the UWtype integers
   HIGH_NUMERATOR and LOW_NUMERATOR, by DENOMINATOR and places the quotient
   in QUOTIENT and the remainder in REMAINDER.  HIGH_NUMERATOR must be less
   than DENOMINATOR for correct operation.  If, in addition, the most
   significant bit of DENOMINATOR must be 1, then the pre-processor symbol
   UDIV_NEEDS_NORMALIZATION is defined to 1.

   4) sdiv_qrnnd(quotient, remainder, high_numerator, low_numerator,
   denominator).  Like udiv_qrnnd but the numbers are signed.  The quotient
   is rounded towards 0.

   5) count_leading_zeros(count, x) counts the number of zero-bits from the
   msb to the first nonzero bit in the UWtype X.  This is the number of
   steps X needs to be shifted left to set the msb.  Undefined for X == 0,
   unless the symbol COUNT_LEADING_ZEROS_0 is defined to some value.

   6) count_trailing_zeros(count, x) like count_leading_zeros, but counts
   from the least significant end.

   7) add_ssaaaa(high_sum, low_sum, high_addend_1, low_addend_1,
   high_addend_2, low_addend_2) adds two UWtype integers, composed by
   HIGH_ADDEND_1 and LOW_ADDEND_1, and HIGH_ADDEND_2 and LOW_ADDEND_2
   respectively.  The result is placed in HIGH_SUM and LOW_SUM.  Overflow
   (i.e. carry out) is not stored anywhere, and is lost.

   8) sub_ddmmss(high_difference, low_difference, high_minuend, low_minuend,
   high_subtrahend, low_subtrahend) subtracts two two-word UWtype integers,
   composed by HIGH_MINUEND_1 and LOW_MINUEND_1, and HIGH_SUBTRAHEND_2 and
   LOW_SUBTRAHEND_2 respectively.  The result is placed in HIGH_DIFFERENCE
   and LOW_DIFFERENCE.  Overflow (i.e. carry out) is not stored anywhere,
   and is lost.

   If any of these macros are left undefined for a particular CPU,
   C macros are used.  */

/* The CPUs come in alphabetical order below.

   Please add support for more CPUs here, or improve the current support
   for the CPUs below!
   (E.g. WE32100, IBM360.)  */

#if defined (__GNUC__) && !defined (NO_ASM)

/* We sometimes need to clobber "cc" with gcc2, but that would not be
   understood by gcc1.  Use cpp to avoid major code duplication.  */
#if __GNUC__ < 2
#define __CLOBBER_CC
#define __AND_CLOBBER_CC
#else /* __GNUC__ >= 2 */
#define __CLOBBER_CC : "cc"
#define __AND_CLOBBER_CC , "cc"
#endif /* __GNUC__ < 2 */

#if defined (__alpha) && W_TYPE_SIZE == 64
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    UDItype __m0 = (m0), __m1 = (m1);					\
    (ph) = __builtin_alpha_umulh (__m0, __m1);				\
    (pl) = __m0 * __m1;							\
  } while (0)
#define UMUL_TIME 46
#ifndef LONGLONG_STANDALONE
#define udiv_qrnnd(q, r, n1, n0, d) \
  do { UDItype __r;							\
    (q) = __udiv_qrnnd (&__r, (n1), (n0), (d));				\
    (r) = __r;								\
  } while (0)
extern UDItype __udiv_qrnnd (UDItype *, UDItype, UDItype, UDItype);
#define UDIV_TIME 220
#endif /* LONGLONG_STANDALONE */
#ifdef __alpha_cix__
#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clzl (X))
#define count_trailing_zeros(COUNT,X)	((COUNT) = __builtin_ctzl (X))
#define COUNT_LEADING_ZEROS_0 64
#else
#define count_leading_zeros(COUNT,X) \
  do {									\
    UDItype __xr = (X), __t, __a;					\
    __t = __builtin_alpha_cmpbge (0, __xr);				\
    __a = __clz_tab[__t ^ 0xff] - 1;					\
    __t = __builtin_alpha_extbl (__xr, __a);				\
    (COUNT) = 64 - (__clz_tab[__t] + __a*8);				\
  } while (0)
#define count_trailing_zeros(COUNT,X) \
  do {									\
    UDItype __xr = (X), __t, __a;					\
    __t = __builtin_alpha_cmpbge (0, __xr);				\
    __t = ~__t & -~__t;							\
    __a = ((__t & 0xCC) != 0) * 2;					\
    __a += ((__t & 0xF0) != 0) * 4;					\
    __a += ((__t & 0xAA) != 0);						\
    __t = __builtin_alpha_extbl (__xr, __a);				\
    __a <<= 3;								\
    __t &= -__t;							\
    __a += ((__t & 0xCC) != 0) * 2;					\
    __a += ((__t & 0xF0) != 0) * 4;					\
    __a += ((__t & 0xAA) != 0);						\
    (COUNT) = __a;							\
  } while (0)
#endif /* __alpha_cix__ */
#endif /* __alpha */

#if defined (__arc__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add.f	%1, %4, %5\n\tadc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%r" ((USItype) (ah)),					\
	     "rIJ" ((USItype) (bh)),					\
	     "%r" ((USItype) (al)),					\
	     "rIJ" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub.f	%1, %4, %5\n\tsbc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "r" ((USItype) (ah)),					\
	     "rIJ" ((USItype) (bh)),					\
	     "r" ((USItype) (al)),					\
	     "rIJ" ((USItype) (bl)))
/* Call libgcc routine.  */
#define umul_ppmm(w1, w0, u, v) \
do {									\
  DWunion __w;								\
  __w.ll = __umulsidi3 (u, v);						\
  w1 = __w.s.high;							\
  w0 = __w.s.low;							\
} while (0)
#define __umulsidi3 __umulsidi3
UDItype __umulsidi3 (USItype, USItype);
#endif

#if defined (__arm__) && !defined (__thumb__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("adds	%1, %4, %5\n\tadc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%r" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "%r" ((USItype) (al)),					\
	     "rI" ((USItype) (bl)) __CLOBBER_CC)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subs	%1, %4, %5\n\tsbc	%0, %2, %3"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "r" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "r" ((USItype) (al)),					\
	     "rI" ((USItype) (bl)) __CLOBBER_CC)
#define umul_ppmm(xh, xl, a, b) \
{register USItype __t0, __t1, __t2;					\
  __asm__ ("%@ Inlined umul_ppmm\n"					\
	   "	mov	%2, %5, lsr #16\n"				\
	   "	mov	%0, %6, lsr #16\n"				\
	   "	bic	%3, %5, %2, lsl #16\n"				\
	   "	bic	%4, %6, %0, lsl #16\n"				\
	   "	mul	%1, %3, %4\n"					\
	   "	mul	%4, %2, %4\n"					\
	   "	mul	%3, %0, %3\n"					\
	   "	mul	%0, %2, %0\n"					\
	   "	adds	%3, %4, %3\n"					\
	   "	addcs	%0, %0, #65536\n"				\
	   "	adds	%1, %1, %3, lsl #16\n"				\
	   "	adc	%0, %0, %3, lsr #16"				\
	   : "=&r" ((USItype) (xh)),					\
	     "=r" ((USItype) (xl)),					\
	     "=&r" (__t0), "=&r" (__t1), "=r" (__t2)			\
	   : "r" ((USItype) (a)),					\
	     "r" ((USItype) (b)) __CLOBBER_CC );}
#define UMUL_TIME 20
#define UDIV_TIME 100
#endif /* __arm__ */

#if defined(__arm__)
/* Let gcc decide how best to implement count_leading_zeros.  */
#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clz (X))
#define COUNT_LEADING_ZEROS_0 32
#endif

#if defined (__CRIS__) && __CRIS_arch_version >= 3
#define count_leading_zeros(COUNT, X) ((COUNT) = __builtin_clz (X))
#if __CRIS_arch_version >= 8
#define count_trailing_zeros(COUNT, X) ((COUNT) = __builtin_ctz (X))
#endif
#endif /* __CRIS__ */

#if defined (__hppa) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add %4,%5,%1\n\taddc %2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%rM" ((USItype) (ah)),					\
	     "rM" ((USItype) (bh)),					\
	     "%rM" ((USItype) (al)),					\
	     "rM" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub %4,%5,%1\n\tsubb %2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "rM" ((USItype) (ah)),					\
	     "rM" ((USItype) (bh)),					\
	     "rM" ((USItype) (al)),					\
	     "rM" ((USItype) (bl)))
#if defined (_PA_RISC1_1)
#define umul_ppmm(w1, w0, u, v) \
  do {									\
    union								\
      {									\
	UDItype __f;							\
	struct {USItype __w1, __w0;} __w1w0;				\
      } __t;								\
    __asm__ ("xmpyu %1,%2,%0"						\
	     : "=x" (__t.__f)						\
	     : "x" ((USItype) (u)),					\
	       "x" ((USItype) (v)));					\
    (w1) = __t.__w1w0.__w1;						\
    (w0) = __t.__w1w0.__w0;						\
     } while (0)
#define UMUL_TIME 8
#else
#define UMUL_TIME 30
#endif
#define UDIV_TIME 40
#define count_leading_zeros(count, x) \
  do {									\
    USItype __tmp;							\
    __asm__ (								\
       "ldi		1,%0\n"						\
"	extru,=		%1,15,16,%%r0		; Bits 31..16 zero?\n"	\
"	extru,tr	%1,15,16,%1		; No.  Shift down, skip add.\n"\
"	ldo		16(%0),%0		; Yes.  Perform add.\n"	\
"	extru,=		%1,23,8,%%r0		; Bits 15..8 zero?\n"	\
"	extru,tr	%1,23,8,%1		; No.  Shift down, skip add.\n"\
"	ldo		8(%0),%0		; Yes.  Perform add.\n"	\
"	extru,=		%1,27,4,%%r0		; Bits 7..4 zero?\n"	\
"	extru,tr	%1,27,4,%1		; No.  Shift down, skip add.\n"\
"	ldo		4(%0),%0		; Yes.  Perform add.\n"	\
"	extru,=		%1,29,2,%%r0		; Bits 3..2 zero?\n"	\
"	extru,tr	%1,29,2,%1		; No.  Shift down, skip add.\n"\
"	ldo		2(%0),%0		; Yes.  Perform add.\n"	\
"	extru		%1,30,1,%1		; Extract bit 1.\n"	\
"	sub		%0,%1,%0		; Subtract it.\n"	\
	: "=r" (count), "=r" (__tmp) : "1" (x));			\
  } while (0)
#endif

#if (defined (__i370__) || defined (__s390__) || defined (__mvs__)) && W_TYPE_SIZE == 32
#define smul_ppmm(xh, xl, m0, m1) \
  do {									\
    union {DItype __ll;							\
	   struct {USItype __h, __l;} __i;				\
	  } __x;							\
    __asm__ ("lr %N0,%1\n\tmr %0,%2"					\
	     : "=&r" (__x.__ll)						\
	     : "r" (m0), "r" (m1));					\
    (xh) = __x.__i.__h; (xl) = __x.__i.__l;				\
  } while (0)
#define sdiv_qrnnd(q, r, n1, n0, d) \
  do {									\
    union {DItype __ll;							\
	   struct {USItype __h, __l;} __i;				\
	  } __x;							\
    __x.__i.__h = n1; __x.__i.__l = n0;					\
    __asm__ ("dr %0,%2"							\
	     : "=r" (__x.__ll)						\
	     : "0" (__x.__ll), "r" (d));				\
    (q) = __x.__i.__l; (r) = __x.__i.__h;				\
  } while (0)
#endif

#if (defined (__i386__) || defined (__i486__)) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add{l} {%5,%1|%1,%5}\n\tadc{l} {%3,%0|%0,%3}"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub{l} {%5,%1|%1,%5}\n\tsbb{l} {%3,%0|%0,%3}"		\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("mul{l} %3"							\
	   : "=a" ((USItype) (w0)),					\
	     "=d" ((USItype) (w1))					\
	   : "%0" ((USItype) (u)),					\
	     "rm" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
  __asm__ ("div{l} %4"							\
	   : "=a" ((USItype) (q)),					\
	     "=d" ((USItype) (r))					\
	   : "0" ((USItype) (n0)),					\
	     "1" ((USItype) (n1)),					\
	     "rm" ((USItype) (dv)))
#define count_leading_zeros(count, x)	((count) = __builtin_clz (x))
#define count_trailing_zeros(count, x)	((count) = __builtin_ctz (x))
#define UMUL_TIME 40
#define UDIV_TIME 40
#endif /* 80x86 */

#if (defined (__x86_64__) || defined (__i386__)) && W_TYPE_SIZE == 64
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add{q} {%5,%1|%1,%5}\n\tadc{q} {%3,%0|%0,%3}"		\
	   : "=r" ((UDItype) (sh)),					\
	     "=&r" ((UDItype) (sl))					\
	   : "%0" ((UDItype) (ah)),					\
	     "rme" ((UDItype) (bh)),					\
	     "%1" ((UDItype) (al)),					\
	     "rme" ((UDItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub{q} {%5,%1|%1,%5}\n\tsbb{q} {%3,%0|%0,%3}"		\
	   : "=r" ((UDItype) (sh)),					\
	     "=&r" ((UDItype) (sl))					\
	   : "0" ((UDItype) (ah)),					\
	     "rme" ((UDItype) (bh)),					\
	     "1" ((UDItype) (al)),					\
	     "rme" ((UDItype) (bl)))
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("mul{q} %3"							\
	   : "=a" ((UDItype) (w0)),					\
	     "=d" ((UDItype) (w1))					\
	   : "%0" ((UDItype) (u)),					\
	     "rm" ((UDItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, dv) \
  __asm__ ("div{q} %4"							\
	   : "=a" ((UDItype) (q)),					\
	     "=d" ((UDItype) (r))					\
	   : "0" ((UDItype) (n0)),					\
	     "1" ((UDItype) (n1)),					\
	     "rm" ((UDItype) (dv)))
#define count_leading_zeros(count, x)	((count) = __builtin_clzl (x))
#define count_trailing_zeros(count, x)	((count) = __builtin_ctzl (x))
#define UMUL_TIME 40
#define UDIV_TIME 40
#endif /* x86_64 */

#if defined (__i960__) && W_TYPE_SIZE == 32
#define umul_ppmm(w1, w0, u, v) \
  ({union {UDItype __ll;						\
	   struct {USItype __l, __h;} __i;				\
	  } __xx;							\
  __asm__ ("emul	%2,%1,%0"					\
	   : "=d" (__xx.__ll)						\
	   : "%dI" ((USItype) (u)),					\
	     "dI" ((USItype) (v)));					\
  (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
#define __umulsidi3(u, v) \
  ({UDItype __w;							\
    __asm__ ("emul	%2,%1,%0"					\
	     : "=d" (__w)						\
	     : "%dI" ((USItype) (u)),					\
	       "dI" ((USItype) (v)));					\
    __w; })
#endif /* __i960__ */

#if defined (__M32R__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  /* The cmp clears the condition bit.  */ \
  __asm__ ("cmp %0,%0\n\taddx %1,%5\n\taddx %0,%3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "r" ((USItype) (bl))					\
	   : "cbit")
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  /* The cmp clears the condition bit.  */ \
  __asm__ ("cmp %0,%0\n\tsubx %1,%5\n\tsubx %0,%3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "r" ((USItype) (bl))					\
	   : "cbit")
#endif /* __M32R__ */

#if defined (__mc68000__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add%.l %5,%1\n\taddx%.l %3,%0"				\
	   : "=d" ((USItype) (sh)),					\
	     "=&d" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "d" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub%.l %5,%1\n\tsubx%.l %3,%0"				\
	   : "=d" ((USItype) (sh)),					\
	     "=&d" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "d" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))

/* The '020, '030, '040, '060 and CPU32 have 32x32->64 and 64/32->32q-32r.  */
#if (defined (__mc68020__) && !defined (__mc68060__))
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("mulu%.l %3,%1:%0"						\
	   : "=d" ((USItype) (w0)),					\
	     "=d" ((USItype) (w1))					\
	   : "%0" ((USItype) (u)),					\
	     "dmi" ((USItype) (v)))
#define UMUL_TIME 45
#define udiv_qrnnd(q, r, n1, n0, d) \
  __asm__ ("divu%.l %4,%1:%0"						\
	   : "=d" ((USItype) (q)),					\
	     "=d" ((USItype) (r))					\
	   : "0" ((USItype) (n0)),					\
	     "1" ((USItype) (n1)),					\
	     "dmi" ((USItype) (d)))
#define UDIV_TIME 90
#define sdiv_qrnnd(q, r, n1, n0, d) \
  __asm__ ("divs%.l %4,%1:%0"						\
	   : "=d" ((USItype) (q)),					\
	     "=d" ((USItype) (r))					\
	   : "0" ((USItype) (n0)),					\
	     "1" ((USItype) (n1)),					\
	     "dmi" ((USItype) (d)))

#elif defined (__mcoldfire__) /* not mc68020 */

#define umul_ppmm(xh, xl, a, b) \
  __asm__ ("| Inlined umul_ppmm\n"					\
	   "	move%.l	%2,%/d0\n"					\
	   "	move%.l	%3,%/d1\n"					\
	   "	move%.l	%/d0,%/d2\n"					\
	   "	swap	%/d0\n"						\
	   "	move%.l	%/d1,%/d3\n"					\
	   "	swap	%/d1\n"						\
	   "	move%.w	%/d2,%/d4\n"					\
	   "	mulu	%/d3,%/d4\n"					\
	   "	mulu	%/d1,%/d2\n"					\
	   "	mulu	%/d0,%/d3\n"					\
	   "	mulu	%/d0,%/d1\n"					\
	   "	move%.l	%/d4,%/d0\n"					\
	   "	clr%.w	%/d0\n"						\
	   "	swap	%/d0\n"						\
	   "	add%.l	%/d0,%/d2\n"					\
	   "	add%.l	%/d3,%/d2\n"					\
	   "	jcc	1f\n"						\
	   "	add%.l	%#65536,%/d1\n"					\
	   "1:	swap	%/d2\n"						\
	   "	moveq	%#0,%/d0\n"					\
	   "	move%.w	%/d2,%/d0\n"					\
	   "	move%.w	%/d4,%/d2\n"					\
	   "	move%.l	%/d2,%1\n"					\
	   "	add%.l	%/d1,%/d0\n"					\
	   "	move%.l	%/d0,%0"					\
	   : "=g" ((USItype) (xh)),					\
	     "=g" ((USItype) (xl))					\
	   : "g" ((USItype) (a)),					\
	     "g" ((USItype) (b))					\
	   : "d0", "d1", "d2", "d3", "d4")
#define UMUL_TIME 100
#define UDIV_TIME 400
#else /* not ColdFire */
/* %/ inserts REGISTER_PREFIX, %# inserts IMMEDIATE_PREFIX.  */
#define umul_ppmm(xh, xl, a, b) \
  __asm__ ("| Inlined umul_ppmm\n"					\
	   "	move%.l	%2,%/d0\n"					\
	   "	move%.l	%3,%/d1\n"					\
	   "	move%.l	%/d0,%/d2\n"					\
	   "	swap	%/d0\n"						\
	   "	move%.l	%/d1,%/d3\n"					\
	   "	swap	%/d1\n"						\
	   "	move%.w	%/d2,%/d4\n"					\
	   "	mulu	%/d3,%/d4\n"					\
	   "	mulu	%/d1,%/d2\n"					\
	   "	mulu	%/d0,%/d3\n"					\
	   "	mulu	%/d0,%/d1\n"					\
	   "	move%.l	%/d4,%/d0\n"					\
	   "	eor%.w	%/d0,%/d0\n"					\
	   "	swap	%/d0\n"						\
	   "	add%.l	%/d0,%/d2\n"					\
	   "	add%.l	%/d3,%/d2\n"					\
	   "	jcc	1f\n"						\
	   "	add%.l	%#65536,%/d1\n"					\
	   "1:	swap	%/d2\n"						\
	   "	moveq	%#0,%/d0\n"					\
	   "	move%.w	%/d2,%/d0\n"					\
	   "	move%.w	%/d4,%/d2\n"					\
	   "	move%.l	%/d2,%1\n"					\
	   "	add%.l	%/d1,%/d0\n"					\
	   "	move%.l	%/d0,%0"					\
	   : "=g" ((USItype) (xh)),					\
	     "=g" ((USItype) (xl))					\
	   : "g" ((USItype) (a)),					\
	     "g" ((USItype) (b))					\
	   : "d0", "d1", "d2", "d3", "d4")
#define UMUL_TIME 100
#define UDIV_TIME 400

#endif /* not mc68020 */

/* The '020, '030, '040 and '060 have bitfield insns.
   cpu32 disguises as a 68020, but lacks them.  */
#if defined (__mc68020__) && !defined (__mcpu32__)
#define count_leading_zeros(count, x) \
  __asm__ ("bfffo %1{%b2:%b2},%0"					\
	   : "=d" ((USItype) (count))					\
	   : "od" ((USItype) (x)), "n" (0))
/* Some ColdFire architectures have a ff1 instruction supported via
   __builtin_clz. */
#elif defined (__mcfisaaplus__) || defined (__mcfisac__)
#define count_leading_zeros(count,x) ((count) = __builtin_clz (x))
#define COUNT_LEADING_ZEROS_0 32
#endif
#endif /* mc68000 */

#if defined (__m88000__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addu.co %1,%r4,%r5\n\taddu.ci %0,%r2,%r3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%rJ" ((USItype) (ah)),					\
	     "rJ" ((USItype) (bh)),					\
	     "%rJ" ((USItype) (al)),					\
	     "rJ" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subu.co %1,%r4,%r5\n\tsubu.ci %0,%r2,%r3"			\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "rJ" ((USItype) (ah)),					\
	     "rJ" ((USItype) (bh)),					\
	     "rJ" ((USItype) (al)),					\
	     "rJ" ((USItype) (bl)))
#define count_leading_zeros(count, x) \
  do {									\
    USItype __cbtmp;							\
    __asm__ ("ff1 %0,%1"						\
	     : "=r" (__cbtmp)						\
	     : "r" ((USItype) (x)));					\
    (count) = __cbtmp ^ 31;						\
  } while (0)
#define COUNT_LEADING_ZEROS_0 63 /* sic */
#if defined (__mc88110__)
#define umul_ppmm(wh, wl, u, v) \
  do {									\
    union {UDItype __ll;						\
	   struct {USItype __h, __l;} __i;				\
	  } __xx;							\
    __asm__ ("mulu.d	%0,%1,%2"					\
	     : "=r" (__xx.__ll)						\
	     : "r" ((USItype) (u)),					\
	       "r" ((USItype) (v)));					\
    (wh) = __xx.__i.__h;						\
    (wl) = __xx.__i.__l;						\
  } while (0)
#define udiv_qrnnd(q, r, n1, n0, d) \
  ({union {UDItype __ll;						\
	   struct {USItype __h, __l;} __i;				\
	  } __xx;							\
  USItype __q;								\
  __xx.__i.__h = (n1); __xx.__i.__l = (n0);				\
  __asm__ ("divu.d %0,%1,%2"						\
	   : "=r" (__q)							\
	   : "r" (__xx.__ll),						\
	     "r" ((USItype) (d)));					\
  (r) = (n0) - __q * (d); (q) = __q; })
#define UMUL_TIME 5
#define UDIV_TIME 25
#else
#define UMUL_TIME 17
#define UDIV_TIME 150
#endif /* __mc88110__ */
#endif /* __m88000__ */

#if defined (__mips__) && W_TYPE_SIZE == 32
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    UDItype __x = (UDItype) (USItype) (u) * (USItype) (v);		\
    (w1) = (USItype) (__x >> 32);					\
    (w0) = (USItype) (__x);						\
  } while (0)
#define UMUL_TIME 10
#define UDIV_TIME 100

#if (__mips == 32 || __mips == 64) && ! __mips16
#define count_leading_zeros(COUNT,X)	((COUNT) = __builtin_clz (X))
#define COUNT_LEADING_ZEROS_0 32
#endif
#endif /* __mips__ */

#if defined (__ns32000__) && W_TYPE_SIZE == 32
#define umul_ppmm(w1, w0, u, v) \
  ({union {UDItype __ll;						\
	   struct {USItype __l, __h;} __i;				\
	  } __xx;							\
  __asm__ ("meid %2,%0"							\
	   : "=g" (__xx.__ll)						\
	   : "%0" ((USItype) (u)),					\
	     "g" ((USItype) (v)));					\
  (w1) = __xx.__i.__h; (w0) = __xx.__i.__l;})
#define __umulsidi3(u, v) \
  ({UDItype __w;							\
    __asm__ ("meid %2,%0"						\
	     : "=g" (__w)						\
	     : "%0" ((USItype) (u)),					\
	       "g" ((USItype) (v)));					\
    __w; })
#define udiv_qrnnd(q, r, n1, n0, d) \
  ({union {UDItype __ll;						\
	   struct {USItype __l, __h;} __i;				\
	  } __xx;							\
  __xx.__i.__h = (n1); __xx.__i.__l = (n0);				\
  __asm__ ("deid %2,%0"							\
	   : "=g" (__xx.__ll)						\
	   : "0" (__xx.__ll),						\
	     "g" ((USItype) (d)));					\
  (r) = __xx.__i.__l; (q) = __xx.__i.__h; })
#define count_trailing_zeros(count,x) \
  do {									\
    __asm__ ("ffsd     %2,%0"						\
            : "=r" ((USItype) (count))					\
            : "0" ((USItype) 0),					\
              "r" ((USItype) (x)));					\
  } while (0)
#endif /* __ns32000__ */

/* FIXME: We should test _IBMR2 here when we add assembly support for the
   system vendor compilers.
   FIXME: What's needed for gcc PowerPC VxWorks?  __vxworks__ is not good
   enough, since that hits ARM and m68k too.  */
#if (defined (_ARCH_PPC)	/* AIX */				\
     || defined (_ARCH_PWR)	/* AIX */				\
     || defined (_ARCH_COM)	/* AIX */				\
     || defined (__powerpc__)	/* gcc */				\
     || defined (__POWERPC__)	/* BEOS */				\
     || defined (__ppc__)	/* Darwin */				\
     || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */    \
     || (defined (PPC) && defined (CPU_FAMILY)    /* VxWorks */               \
         && CPU_FAMILY == PPC)                                                \
     ) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (bh) && (bh) == 0)				\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else								\
      __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"		\
	     : "=r" (sh), "=&r" (sl)					\
	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
  } while (0)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (ah) && (ah) == 0)				\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (ah) && (ah) == ~(USItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == 0)			\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(USItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else								\
      __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	\
	       : "=r" (sh), "=&r" (sl)					\
	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
  } while (0)
#define count_leading_zeros(count, x) \
  __asm__ ("{cntlz|cntlzw} %0,%1" : "=r" (count) : "r" (x))
#define COUNT_LEADING_ZEROS_0 32
#if defined (_ARCH_PPC) || defined (__powerpc__) || defined (__POWERPC__) \
  || defined (__ppc__)                                                    \
  || (defined (PPC) && ! defined (CPU_FAMILY)) /* gcc 2.7.x GNU&SysV */       \
  || (defined (PPC) && defined (CPU_FAMILY)    /* VxWorks */                  \
         && CPU_FAMILY == PPC)
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    USItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhwu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define UMUL_TIME 15
#define smul_ppmm(ph, pl, m0, m1) \
  do {									\
    SItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhw %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define SMUL_TIME 14
#define UDIV_TIME 120
#elif defined (_ARCH_PWR)
#define UMUL_TIME 8
#define smul_ppmm(xh, xl, m0, m1) \
  __asm__ ("mul %0,%2,%3" : "=r" (xh), "=q" (xl) : "r" (m0), "r" (m1))
#define SMUL_TIME 4
#define sdiv_qrnnd(q, r, nh, nl, d) \
  __asm__ ("div %0,%2,%4" : "=r" (q), "=q" (r) : "r" (nh), "1" (nl), "r" (d))
#define UDIV_TIME 100
#endif
#endif /* 32-bit POWER architecture variants.  */

/* We should test _IBMR2 here when we add assembly support for the system
   vendor compilers.  */
#if (defined (_ARCH_PPC64) || defined (__powerpc64__)) && W_TYPE_SIZE == 64
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (bh) && (bh) == 0)				\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{aze|addze} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)		\
      __asm__ ("{a%I4|add%I4c} %1,%3,%4\n\t{ame|addme} %0,%2"		\
	     : "=r" (sh), "=&r" (sl) : "r" (ah), "%r" (al), "rI" (bl));\
    else								\
      __asm__ ("{a%I5|add%I5c} %1,%4,%5\n\t{ae|adde} %0,%2,%3"		\
	     : "=r" (sh), "=&r" (sl)					\
	     : "%r" (ah), "r" (bh), "%r" (al), "rI" (bl));		\
  } while (0)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  do {									\
    if (__builtin_constant_p (ah) && (ah) == 0)				\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfze|subfze} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (ah) && (ah) == ~(UDItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{sfme|subfme} %0,%2"	\
	       : "=r" (sh), "=&r" (sl) : "r" (bh), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == 0)			\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{ame|addme} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else if (__builtin_constant_p (bh) && (bh) == ~(UDItype) 0)		\
      __asm__ ("{sf%I3|subf%I3c} %1,%4,%3\n\t{aze|addze} %0,%2"		\
	       : "=r" (sh), "=&r" (sl) : "r" (ah), "rI" (al), "r" (bl));\
    else								\
      __asm__ ("{sf%I4|subf%I4c} %1,%5,%4\n\t{sfe|subfe} %0,%3,%2"	\
	       : "=r" (sh), "=&r" (sl)					\
	       : "r" (ah), "r" (bh), "rI" (al), "r" (bl));		\
  } while (0)
#define count_leading_zeros(count, x) \
  __asm__ ("cntlzd %0,%1" : "=r" (count) : "r" (x))
#define COUNT_LEADING_ZEROS_0 64
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    UDItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhdu %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define UMUL_TIME 15
#define smul_ppmm(ph, pl, m0, m1) \
  do {									\
    DItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("mulhd %0,%1,%2" : "=r" (ph) : "%r" (m0), "r" (m1));	\
    (pl) = __m0 * __m1;							\
  } while (0)
#define SMUL_TIME 14  /* ??? */
#define UDIV_TIME 120 /* ??? */
#endif /* 64-bit PowerPC.  */

#if defined (__ibm032__) /* RT/ROMP */ && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("a %1,%5\n\tae %0,%3"					\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "r" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("s %1,%5\n\tse %0,%3"					\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "r" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "r" ((USItype) (bl)))
#define umul_ppmm(ph, pl, m0, m1) \
  do {									\
    USItype __m0 = (m0), __m1 = (m1);					\
    __asm__ (								\
       "s	r2,r2\n"						\
"	mts	r10,%2\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	m	r2,%3\n"						\
"	cas	%0,r2,r0\n"						\
"	mfs	r10,%1"							\
	     : "=r" ((USItype) (ph)),					\
	       "=r" ((USItype) (pl))					\
	     : "%r" (__m0),						\
		"r" (__m1)						\
	     : "r2");							\
    (ph) += ((((SItype) __m0 >> 31) & __m1)				\
	     + (((SItype) __m1 >> 31) & __m0));				\
  } while (0)
#define UMUL_TIME 20
#define UDIV_TIME 200
#define count_leading_zeros(count, x) \
  do {									\
    if ((x) >= 0x10000)							\
      __asm__ ("clz	%0,%1"						\
	       : "=r" ((USItype) (count))				\
	       : "r" ((USItype) (x) >> 16));				\
    else								\
      {									\
	__asm__ ("clz	%0,%1"						\
		 : "=r" ((USItype) (count))				\
		 : "r" ((USItype) (x)));					\
	(count) += 16;							\
      }									\
  } while (0)
#endif

#if defined(__sh__) && !__SHMEDIA__ && W_TYPE_SIZE == 32
#ifndef __sh1__
#define umul_ppmm(w1, w0, u, v) \
  __asm__ (								\
       "dmulu.l	%2,%3\n\tsts%M1	macl,%1\n\tsts%M0	mach,%0"	\
	   : "=r<" ((USItype)(w1)),					\
	     "=r<" ((USItype)(w0))					\
	   : "r" ((USItype)(u)),					\
	     "r" ((USItype)(v))						\
	   : "macl", "mach")
#define UMUL_TIME 5
#endif

/* This is the same algorithm as __udiv_qrnnd_c.  */
#define UDIV_NEEDS_NORMALIZATION 1

#define udiv_qrnnd(q, r, n1, n0, d) \
  do {									\
    extern UWtype __udiv_qrnnd_16 (UWtype, UWtype)			\
                        __attribute__ ((visibility ("hidden")));	\
    /* r0: rn r1: qn */ /* r0: n1 r4: n0 r5: d r6: d1 */ /* r2: __m */	\
    __asm__ (								\
	"mov%M4 %4,r5\n"						\
"	swap.w %3,r4\n"							\
"	swap.w r5,r6\n"							\
"	jsr @%5\n"							\
"	shll16 r6\n"							\
"	swap.w r4,r4\n"							\
"	jsr @%5\n"							\
"	swap.w r1,%0\n"							\
"	or r1,%0"							\
	: "=r" (q), "=&z" (r)						\
	: "1" (n1), "r" (n0), "rm" (d), "r" (&__udiv_qrnnd_16)		\
	: "r1", "r2", "r4", "r5", "r6", "pr");				\
  } while (0)

#define UDIV_TIME 80

#define sub_ddmmss(sh, sl, ah, al, bh, bl)				\
  __asm__ ("clrt;subc %5,%1; subc %4,%0"				\
	   : "=r" (sh), "=r" (sl)					\
	   : "0" (ah), "1" (al), "r" (bh), "r" (bl))

#endif /* __sh__ */

#if defined (__SH5__) && __SHMEDIA__ && W_TYPE_SIZE == 32
#define __umulsidi3(u,v) ((UDItype)(USItype)u*(USItype)v)
#define count_leading_zeros(count, x) \
  do									\
    {									\
      UDItype x_ = (USItype)(x);					\
      SItype c_;							\
									\
      __asm__ ("nsb %1, %0" : "=r" (c_) : "r" (x_));			\
      (count) = c_ - 31;						\
    }									\
  while (0)
#define COUNT_LEADING_ZEROS_0 32
#endif

#if defined (__sparc__) && !defined (__arch64__) && !defined (__sparcv9) \
    && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addcc %r4,%5,%1\n\taddx %r2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "%rJ" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "%rJ" ((USItype) (al)),					\
	     "rI" ((USItype) (bl))					\
	   __CLOBBER_CC)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subcc %r4,%5,%1\n\tsubx %r2,%3,%0"				\
	   : "=r" ((USItype) (sh)),					\
	     "=&r" ((USItype) (sl))					\
	   : "rJ" ((USItype) (ah)),					\
	     "rI" ((USItype) (bh)),					\
	     "rJ" ((USItype) (al)),					\
	     "rI" ((USItype) (bl))					\
	   __CLOBBER_CC)
#if defined (__sparc_v8__)
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("umul %2,%3,%1;rd %%y,%0"					\
	   : "=r" ((USItype) (w1)),					\
	     "=r" ((USItype) (w0))					\
	   : "r" ((USItype) (u)),					\
	     "r" ((USItype) (v)))
#define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
  __asm__ ("mov %2,%%y;nop;nop;nop;udiv %3,%4,%0;umul %0,%4,%1;sub %3,%1,%1"\
	   : "=&r" ((USItype) (__q)),					\
	     "=&r" ((USItype) (__r))					\
	   : "r" ((USItype) (__n1)),					\
	     "r" ((USItype) (__n0)),					\
	     "r" ((USItype) (__d)))
#else
#if defined (__sparclite__)
/* This has hardware multiply but not divide.  It also has two additional
   instructions scan (ffs from high bit) and divscc.  */
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("umul %2,%3,%1;rd %%y,%0"					\
	   : "=r" ((USItype) (w1)),					\
	     "=r" ((USItype) (w0))					\
	   : "r" ((USItype) (u)),					\
	     "r" ((USItype) (v)))
#define udiv_qrnnd(q, r, n1, n0, d) \
  __asm__ ("! Inlined udiv_qrnnd\n"					\
"	wr	%%g0,%2,%%y	! Not a delayed write for sparclite\n"	\
"	tst	%%g0\n"							\
"	divscc	%3,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%%g1\n"						\
"	divscc	%%g1,%4,%0\n"						\
"	rd	%%y,%1\n"						\
"	bl,a 1f\n"							\
"	add	%1,%4,%1\n"						\
"1:	! End of inline udiv_qrnnd"					\
	   : "=r" ((USItype) (q)),					\
	     "=r" ((USItype) (r))					\
	   : "r" ((USItype) (n1)),					\
	     "r" ((USItype) (n0)),					\
	     "rI" ((USItype) (d))					\
	   : "g1" __AND_CLOBBER_CC)
#define UDIV_TIME 37
#define count_leading_zeros(count, x) \
  do {                                                                  \
  __asm__ ("scan %1,1,%0"                                               \
           : "=r" ((USItype) (count))                                   \
           : "r" ((USItype) (x)));					\
  } while (0)
/* Early sparclites return 63 for an argument of 0, but they warn that future
   implementations might change this.  Therefore, leave COUNT_LEADING_ZEROS_0
   undefined.  */
#else
/* SPARC without integer multiplication and divide instructions.
   (i.e. at least Sun4/20,40,60,65,75,110,260,280,330,360,380,470,490) */
#define umul_ppmm(w1, w0, u, v) \
  __asm__ ("! Inlined umul_ppmm\n"					\
"	wr	%%g0,%2,%%y	! SPARC has 0-3 delay insn after a wr\n"\
"	sra	%3,31,%%o5	! Don't move this insn\n"		\
"	and	%2,%%o5,%%o5	! Don't move this insn\n"		\
"	andcc	%%g0,0,%%g1	! Don't move this insn\n"		\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,%3,%%g1\n"						\
"	mulscc	%%g1,0,%%g1\n"						\
"	add	%%g1,%%o5,%0\n"						\
"	rd	%%y,%1"							\
	   : "=r" ((USItype) (w1)),					\
	     "=r" ((USItype) (w0))					\
	   : "%rI" ((USItype) (u)),					\
	     "r" ((USItype) (v))						\
	   : "g1", "o5" __AND_CLOBBER_CC)
#define UMUL_TIME 39		/* 39 instructions */
/* It's quite necessary to add this much assembler for the sparc.
   The default udiv_qrnnd (in C) is more than 10 times slower!  */
#define udiv_qrnnd(__q, __r, __n1, __n0, __d) \
  __asm__ ("! Inlined udiv_qrnnd\n"					\
"	mov	32,%%g1\n"						\
"	subcc	%1,%2,%%g0\n"						\
"1:	bcs	5f\n"							\
"	 addxcc %0,%0,%0	! shift n1n0 and a q-bit in lsb\n"	\
"	sub	%1,%2,%1	! this kills msb of n\n"		\
"	addx	%1,%1,%1	! so this can't give carry\n"		\
"	subcc	%%g1,1,%%g1\n"						\
"2:	bne	1b\n"							\
"	 subcc	%1,%2,%%g0\n"						\
"	bcs	3f\n"							\
"	 addxcc %0,%0,%0	! shift n1n0 and a q-bit in lsb\n"	\
"	b	3f\n"							\
"	 sub	%1,%2,%1	! this kills msb of n\n"		\
"4:	sub	%1,%2,%1\n"						\
"5:	addxcc	%1,%1,%1\n"						\
"	bcc	2b\n"							\
"	 subcc	%%g1,1,%%g1\n"						\
"! Got carry from n.  Subtract next step to cancel this carry.\n"	\
"	bne	4b\n"							\
"	 addcc	%0,%0,%0	! shift n1n0 and a 0-bit in lsb\n"	\
"	sub	%1,%2,%1\n"						\
"3:	xnor	%0,0,%0\n"						\
"	! End of inline udiv_qrnnd"					\
	   : "=&r" ((USItype) (__q)),					\
	     "=&r" ((USItype) (__r))					\
	   : "r" ((USItype) (__d)),					\
	     "1" ((USItype) (__n1)),					\
	     "0" ((USItype) (__n0)) : "g1" __AND_CLOBBER_CC)
#define UDIV_TIME (3+7*32)	/* 7 instructions/iteration. 32 iterations.  */
#endif /* __sparclite__ */
#endif /* __sparc_v8__ */
#endif /* sparc32 */

#if ((defined (__sparc__) && defined (__arch64__)) || defined (__sparcv9)) \
    && W_TYPE_SIZE == 64
#define add_ssaaaa(sh, sl, ah, al, bh, bl)				\
  __asm__ ("addcc %r4,%5,%1\n\t"					\
   	   "add %r2,%3,%0\n\t"						\
   	   "bcs,a,pn %%xcc, 1f\n\t"					\
   	   "add %0, 1, %0\n"						\
	   "1:"								\
	   : "=r" ((UDItype)(sh)),				      	\
	     "=&r" ((UDItype)(sl))				      	\
	   : "%rJ" ((UDItype)(ah)),				     	\
	     "rI" ((UDItype)(bh)),				      	\
	     "%rJ" ((UDItype)(al)),				     	\
	     "rI" ((UDItype)(bl))				       	\
	   __CLOBBER_CC)

#define sub_ddmmss(sh, sl, ah, al, bh, bl) 				\
  __asm__ ("subcc %r4,%5,%1\n\t"					\
   	   "sub %r2,%3,%0\n\t"						\
   	   "bcs,a,pn %%xcc, 1f\n\t"					\
   	   "sub %0, 1, %0\n\t"						\
	   "1:"								\
	   : "=r" ((UDItype)(sh)),				      	\
	     "=&r" ((UDItype)(sl))				      	\
	   : "rJ" ((UDItype)(ah)),				     	\
	     "rI" ((UDItype)(bh)),				      	\
	     "rJ" ((UDItype)(al)),				     	\
	     "rI" ((UDItype)(bl))				       	\
	   __CLOBBER_CC)

#define umul_ppmm(wh, wl, u, v)						\
  do {									\
	  UDItype tmp1, tmp2, tmp3, tmp4;				\
	  __asm__ __volatile__ (					\
		   "srl %7,0,%3\n\t"					\
		   "mulx %3,%6,%1\n\t"					\
		   "srlx %6,32,%2\n\t"					\
		   "mulx %2,%3,%4\n\t"					\
		   "sllx %4,32,%5\n\t"					\
		   "srl %6,0,%3\n\t"					\
		   "sub %1,%5,%5\n\t"					\
		   "srlx %5,32,%5\n\t"					\
		   "addcc %4,%5,%4\n\t"					\
		   "srlx %7,32,%5\n\t"					\
		   "mulx %3,%5,%3\n\t"					\
		   "mulx %2,%5,%5\n\t"					\
		   "sethi %%hi(0x80000000),%2\n\t"			\
		   "addcc %4,%3,%4\n\t"					\
		   "srlx %4,32,%4\n\t"					\
		   "add %2,%2,%2\n\t"					\
		   "movcc %%xcc,%%g0,%2\n\t"				\
		   "addcc %5,%4,%5\n\t"					\
		   "sllx %3,32,%3\n\t"					\
		   "add %1,%3,%1\n\t"					\
		   "add %5,%2,%0"					\
	   : "=r" ((UDItype)(wh)),					\
	     "=&r" ((UDItype)(wl)),					\
	     "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4)	\
	   : "r" ((UDItype)(u)),					\
	     "r" ((UDItype)(v))						\
	   __CLOBBER_CC);						\
  } while (0)
#define UMUL_TIME 96
#define UDIV_TIME 230
#endif /* sparc64 */

#if defined (__vax__) && W_TYPE_SIZE == 32
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("addl2 %5,%1\n\tadwc %3,%0"					\
	   : "=g" ((USItype) (sh)),					\
	     "=&g" ((USItype) (sl))					\
	   : "%0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "%1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("subl2 %5,%1\n\tsbwc %3,%0"					\
	   : "=g" ((USItype) (sh)),					\
	     "=&g" ((USItype) (sl))					\
	   : "0" ((USItype) (ah)),					\
	     "g" ((USItype) (bh)),					\
	     "1" ((USItype) (al)),					\
	     "g" ((USItype) (bl)))
#define umul_ppmm(xh, xl, m0, m1) \
  do {									\
    union {								\
	UDItype __ll;							\
	struct {USItype __l, __h;} __i;					\
      } __xx;								\
    USItype __m0 = (m0), __m1 = (m1);					\
    __asm__ ("emul %1,%2,$0,%0"						\
	     : "=r" (__xx.__ll)						\
	     : "g" (__m0),						\
	       "g" (__m1));						\
    (xh) = __xx.__i.__h;						\
    (xl) = __xx.__i.__l;						\
    (xh) += ((((SItype) __m0 >> 31) & __m1)				\
	     + (((SItype) __m1 >> 31) & __m0));				\
  } while (0)
#define sdiv_qrnnd(q, r, n1, n0, d) \
  do {									\
    union {DItype __ll;							\
	   struct {SItype __l, __h;} __i;				\
	  } __xx;							\
    __xx.__i.__h = n1; __xx.__i.__l = n0;				\
    __asm__ ("ediv %3,%2,%0,%1"						\
	     : "=g" (q), "=g" (r)					\
	     : "g" (__xx.__ll), "g" (d));				\
  } while (0)
#endif /* __vax__ */

#if defined (__xtensa__) && W_TYPE_SIZE == 32
/* This code is not Xtensa-configuration-specific, so rely on the compiler
   to expand builtin functions depending on what configuration features
   are available.  This avoids library calls when the operation can be
   performed in-line.  */
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    DWunion __w;							\
    __w.ll = __builtin_umulsidi3 (u, v);				\
    w1 = __w.s.high;							\
    w0 = __w.s.low;							\
  } while (0)
#define __umulsidi3(u, v)		__builtin_umulsidi3 (u, v)
#define count_leading_zeros(COUNT, X)	((COUNT) = __builtin_clz (X))
#define count_trailing_zeros(COUNT, X)	((COUNT) = __builtin_ctz (X))
#endif /* __xtensa__ */

#if defined (__z8000__) && W_TYPE_SIZE == 16
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  __asm__ ("add	%H1,%H5\n\tadc	%H0,%H3"				\
	   : "=r" ((unsigned int)(sh)),					\
	     "=&r" ((unsigned int)(sl))					\
	   : "%0" ((unsigned int)(ah)),					\
	     "r" ((unsigned int)(bh)),					\
	     "%1" ((unsigned int)(al)),					\
	     "rQR" ((unsigned int)(bl)))
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  __asm__ ("sub	%H1,%H5\n\tsbc	%H0,%H3"				\
	   : "=r" ((unsigned int)(sh)),					\
	     "=&r" ((unsigned int)(sl))					\
	   : "0" ((unsigned int)(ah)),					\
	     "r" ((unsigned int)(bh)),					\
	     "1" ((unsigned int)(al)),					\
	     "rQR" ((unsigned int)(bl)))
#define umul_ppmm(xh, xl, m0, m1) \
  do {									\
    union {long int __ll;						\
	   struct {unsigned int __h, __l;} __i;				\
	  } __xx;							\
    unsigned int __m0 = (m0), __m1 = (m1);				\
    __asm__ ("mult	%S0,%H3"					\
	     : "=r" (__xx.__i.__h),					\
	       "=r" (__xx.__i.__l)					\
	     : "%1" (__m0),						\
	       "rQR" (__m1));						\
    (xh) = __xx.__i.__h; (xl) = __xx.__i.__l;				\
    (xh) += ((((signed int) __m0 >> 15) & __m1)				\
	     + (((signed int) __m1 >> 15) & __m0));			\
  } while (0)
#endif /* __z8000__ */

#endif /* __GNUC__ */

/* If this machine has no inline assembler, use C macros.  */

#if !defined (add_ssaaaa)
#define add_ssaaaa(sh, sl, ah, al, bh, bl) \
  do {									\
    UWtype __x;								\
    __x = (al) + (bl);							\
    (sh) = (ah) + (bh) + (__x < (al));					\
    (sl) = __x;								\
  } while (0)
#endif

#if !defined (sub_ddmmss)
#define sub_ddmmss(sh, sl, ah, al, bh, bl) \
  do {									\
    UWtype __x;								\
    __x = (al) - (bl);							\
    (sh) = (ah) - (bh) - (__x > (al));					\
    (sl) = __x;								\
  } while (0)
#endif

/* If we lack umul_ppmm but have smul_ppmm, define umul_ppmm in terms of
   smul_ppmm.  */
#if !defined (umul_ppmm) && defined (smul_ppmm)
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    UWtype __w1;							\
    UWtype __xm0 = (u), __xm1 = (v);					\
    smul_ppmm (__w1, w0, __xm0, __xm1);					\
    (w1) = __w1 + (-(__xm0 >> (W_TYPE_SIZE - 1)) & __xm1)		\
		+ (-(__xm1 >> (W_TYPE_SIZE - 1)) & __xm0);		\
  } while (0)
#endif

/* If we still don't have umul_ppmm, define it using plain C.  */
#if !defined (umul_ppmm)
#define umul_ppmm(w1, w0, u, v)						\
  do {									\
    UWtype __x0, __x1, __x2, __x3;					\
    UHWtype __ul, __vl, __uh, __vh;					\
									\
    __ul = __ll_lowpart (u);						\
    __uh = __ll_highpart (u);						\
    __vl = __ll_lowpart (v);						\
    __vh = __ll_highpart (v);						\
									\
    __x0 = (UWtype) __ul * __vl;					\
    __x1 = (UWtype) __ul * __vh;					\
    __x2 = (UWtype) __uh * __vl;					\
    __x3 = (UWtype) __uh * __vh;					\
									\
    __x1 += __ll_highpart (__x0);/* this can't give carry */		\
    __x1 += __x2;		/* but this indeed can */		\
    if (__x1 < __x2)		/* did we get it? */			\
      __x3 += __ll_B;		/* yes, add it in the proper pos.  */	\
									\
    (w1) = __x3 + __ll_highpart (__x1);					\
    (w0) = __ll_lowpart (__x1) * __ll_B + __ll_lowpart (__x0);		\
  } while (0)
#endif

#if !defined (__umulsidi3)
#define __umulsidi3(u, v) \
  ({DWunion __w;							\
    umul_ppmm (__w.s.high, __w.s.low, u, v);				\
    __w.ll; })
#endif

/* Define this unconditionally, so it can be used for debugging.  */
#define __udiv_qrnnd_c(q, r, n1, n0, d) \
  do {									\
    UWtype __d1, __d0, __q1, __q0;					\
    UWtype __r1, __r0, __m;						\
    __d1 = __ll_highpart (d);						\
    __d0 = __ll_lowpart (d);						\
									\
    __r1 = (n1) % __d1;							\
    __q1 = (n1) / __d1;							\
    __m = (UWtype) __q1 * __d0;						\
    __r1 = __r1 * __ll_B | __ll_highpart (n0);				\
    if (__r1 < __m)							\
      {									\
	__q1--, __r1 += (d);						\
	if (__r1 >= (d)) /* i.e. we didn't get carry when adding to __r1 */\
	  if (__r1 < __m)						\
	    __q1--, __r1 += (d);					\
      }									\
    __r1 -= __m;							\
									\
    __r0 = __r1 % __d1;							\
    __q0 = __r1 / __d1;							\
    __m = (UWtype) __q0 * __d0;						\
    __r0 = __r0 * __ll_B | __ll_lowpart (n0);				\
    if (__r0 < __m)							\
      {									\
	__q0--, __r0 += (d);						\
	if (__r0 >= (d))						\
	  if (__r0 < __m)						\
	    __q0--, __r0 += (d);					\
      }									\
    __r0 -= __m;							\
									\
    (q) = (UWtype) __q1 * __ll_B | __q0;				\
    (r) = __r0;								\
  } while (0)

/* If the processor has no udiv_qrnnd but sdiv_qrnnd, go through
   __udiv_w_sdiv (defined in libgcc or elsewhere).  */
#if !defined (udiv_qrnnd) && defined (sdiv_qrnnd)
#define udiv_qrnnd(q, r, nh, nl, d) \
  do {									\
    USItype __r;							\
    (q) = __udiv_w_sdiv (&__r, nh, nl, d);				\
    (r) = __r;								\
  } while (0)
#endif

/* If udiv_qrnnd was not defined for this processor, use __udiv_qrnnd_c.  */
#if !defined (udiv_qrnnd)
#define UDIV_NEEDS_NORMALIZATION 1
#define udiv_qrnnd __udiv_qrnnd_c
#endif

#if !defined (count_leading_zeros)
#define count_leading_zeros(count, x) \
  do {									\
    UWtype __xr = (x);							\
    UWtype __a;								\
									\
    if (W_TYPE_SIZE <= 32)						\
      {									\
	__a = __xr < ((UWtype)1<<2*__BITS4)				\
	  ? (__xr < ((UWtype)1<<__BITS4) ? 0 : __BITS4)			\
	  : (__xr < ((UWtype)1<<3*__BITS4) ?  2*__BITS4 : 3*__BITS4);	\
      }									\
    else								\
      {									\
	for (__a = W_TYPE_SIZE - 8; __a > 0; __a -= 8)			\
	  if (((__xr >> __a) & 0xff) != 0)				\
	    break;							\
      }									\
									\
    (count) = W_TYPE_SIZE - (__clz_tab[__xr >> __a] + __a);		\
  } while (0)
#define COUNT_LEADING_ZEROS_0 W_TYPE_SIZE
#endif

#if !defined (count_trailing_zeros)
/* Define count_trailing_zeros using count_leading_zeros.  The latter might be
   defined in asm, but if it is not, the C version above is good enough.  */
#define count_trailing_zeros(count, x) \
  do {									\
    UWtype __ctz_x = (x);						\
    UWtype __ctz_c;							\
    count_leading_zeros (__ctz_c, __ctz_x & -__ctz_x);			\
    (count) = W_TYPE_SIZE - 1 - __ctz_c;				\
  } while (0)
#endif

#ifndef UDIV_NEEDS_NORMALIZATION
#define UDIV_NEEDS_NORMALIZATION 0
#endif
dietlibc-0.33~cvs20120325/mips/pipe.S010064400000000000000000000006501173363227100137350ustar00#include "syscalls.h"

#define v0      2      /* return value */
#define v1      3      /* return value */
#define a0      4      /* argument registers */
#define a3      7
#define ra      31     /* return address */

	.text
	.align	2
	.globl	pipe
	.ent	pipe
pipe:
	li	$v0,__NR_pipe
	syscall
	bnez	$a3,.Lerror
	sw	$v0,0($a0)
	sw	$v1,4($a0)
	move	$v0,$0
	jr      $ra
.Lerror:
	la	$25, error_unified_syscall
	jr	$25
.end pipe
dietlibc-0.33~cvs20120325/mips/pread.c010064400000000000000000000006611173363227100141150ustar00#include 
#include 

extern size_t __pread(int fd, void *buf, size_t count, int dummy, off_t a, off_t b);

size_t __libc_pread(int fd, void *buf, size_t count, off_t offset);
size_t __libc_pread(int fd, void *buf, size_t count, off_t offset) {
  return __pread(fd,buf,count,0,__LONG_LONG_PAIR(0,offset));
}

int pread(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pread")));
dietlibc-0.33~cvs20120325/mips/pread64.c010064400000000000000000000010261173363227100142630ustar00#include 
#include 
#include 

#ifndef __NO_STAT64
extern size_t __pread(int fd, void *buf, size_t count, int dummy, off_t a, off_t b);

size_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset);
size_t __libc_pread64(int fd, void *buf, size_t count, off64_t offset) {
  return __pread(fd,buf,count,0,__LONG_LONG_PAIR( (off_t)(offset>>32),(off_t)(offset&0xffffffff) ));
}

int pread64(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pread64")));
#endif
dietlibc-0.33~cvs20120325/mips/pwrite.c010064400000000000000000000006671173363227100143420ustar00#include 
#include 

extern size_t __pwrite(int fd, void *buf, size_t count, int dummy, off_t a, off_t b);

size_t __libc_pwrite(int fd, void *buf, size_t count, off_t offset);
size_t __libc_pwrite(int fd, void *buf, size_t count, off_t offset) {
  return __pwrite(fd,buf,count,0,__LONG_LONG_PAIR(0,offset));
}

int pwrite(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pwrite")));
dietlibc-0.33~cvs20120325/mips/pwrite64.c010064400000000000000000000010331173363227100145000ustar00#include 
#include 
#include 

#ifndef __NO_STAT64
extern size_t __pwrite(int fd, void *buf, size_t count, int dummy, off_t a, off_t b);

size_t __libc_pwrite64(int fd, void *buf, size_t count, off64_t offset);
size_t __libc_pwrite64(int fd, void *buf, size_t count, off64_t offset) {
  return __pwrite(fd,buf,count,0,__LONG_LONG_PAIR ((off_t)(offset>>32),(off_t)(offset&0xffffffff)));
}

int pwrite64(int fd, void *buf, size_t count, off_t offset) __attribute__((weak,alias("__libc_pwrite64")));
#endif
dietlibc-0.33~cvs20120325/mips/select.S010064400000000000000000000000621173363227100142540ustar00#include "syscalls.h"

syscall(_newselect,select)
dietlibc-0.33~cvs20120325/mips/setjmp.S010064400000000000000000000015431173363227100143040ustar00.text
.align 2
setjmp:
.global __setjmp
.ent	__setjmp
__setjmp:
	li	$5, 0		/* don't save sigmask */
.end	__setjmp
.global __sigsetjmp
.ent	__sigsetjmp
__sigsetjmp:
	/* where to jump later */
	la	$25, __sigjmp_save
	/* callee save floating point save registers (double) */
	s.d	$f20, 56($4)	/* fs0 */
	s.d	$f22, 64($4)	/* fs1 */
	s.d	$f24, 72($4)	/* fs2 */
	s.d	$f26, 80($4)	/* fs3 */
	s.d	$f28, 88($4)	/* fs4 */
	s.d	$f30, 96($4)	/* fs6 */
	/* save coprocessor status register */
	cfc1	 $2, $31
	/* callee save register */
	sw	$gp, 44($4)
	sw	 $2, 48($4)
	sw	$31,  0($4)	/* ra */
	sw	$29,  4($4)	/* sp */
	sw	$16,  8($4)	/* s0 */
	sw	$17, 12($4)	/* s1 */
	sw	$18, 16($4)	/* s2 */
	sw	$19, 20($4)	/* s3 */
	sw	$20, 24($4)	/* s4 */
	sw	$21, 28($4)	/* s5 */
	sw	$22, 32($4)	/* s6 */
	sw	$23, 36($4)	/* s7 */
	sw	$30, 40($4)	/* fp */
	j	$25
.end	__sigsetjmp
.weak	setjmp
dietlibc-0.33~cvs20120325/mips/socketcall.S010064400000000000000000000001361173363227300151250ustar00#include "syscalls.h"

/*
 * Doesn't exist on mips ( accept, bind, ... are SYSCALLS !?! )
 */
dietlibc-0.33~cvs20120325/mips/start.S010064400000000000000000000023611173363227300141400ustar00#include "dietfeatures.h"

#define zero 0
#define ra 31
#define sp 29
#define a0 4
#define a1 5
#define a2 6
#define gp 28

.text
.global __start
.type __start,@function
__start:
#ifdef __pic__
/* initialize gp pointer */
	.set noreorder
	bltzal $0,0f
	nop
0:	.cpload	$31
	.set reorder
#else
	/* _gp is provided by the linker and points into the middle of the
	 * "small data" section (.sdata and .sbss) allocated by the
	 * -G 8 compiler option */
	la      $gp, _gp
#endif
	move	$ra, $zero	/* prime stack frame */
	lw	$a0, 0($sp)	/* load argc */
	addu	$a1, $sp, 4	/* load argv.  huh?  should be 4, right? */

	and	$sp, 0xfffffff8	/* align stack to 8 bytes */
	subu	$sp, 24		/* make room for 4 arguments, RA + pad */
	/* I don't understand the MIPS calling convention.  Why do you
	   need to make room on the stack for arguments you pass in
	   registers?  Anyway, if we don't do this, the arguments are
	   garbled. */
	sw	$ra, 20($sp)	/* close stack frame */

	addu	$a2, $a0, 1	/* load envp */
	sll	$a2, $a2, 2
#ifdef WANT_DYNAMIC
/* FIXME: dl_init parameter ??? */
	la	$25, _dyn_start
#else
	la	$25, CALL_IN_STARTCODE
#endif
	add	$a2, $a2, $a1
	sw	$a2, environ
	jalr	$25
	la	$25, exit
	move	$4,$2
	jalr	$25

.global __main
.type __main,@function
__main:
	j	$31
dietlibc-0.33~cvs20120325/mips/syscalls.h010064400000000000000000000341721173363227300146720ustar00
/*
 * Linux o32 style syscalls are in the range from 4000 to 4999.
 */
#define __NR_Linux			4000
#define __NR_syscall			(__NR_Linux +   0)
#define __NR_exit			(__NR_Linux +   1)
#define __NR_fork			(__NR_Linux +   2)
#define __NR_read			(__NR_Linux +   3)
#define __NR_write			(__NR_Linux +   4)
#define __NR_open			(__NR_Linux +   5)
#define __NR_close			(__NR_Linux +   6)
#define __NR_waitpid			(__NR_Linux +   7)
#define __NR_creat			(__NR_Linux +   8)
#define __NR_link			(__NR_Linux +   9)
#define __NR_unlink			(__NR_Linux +  10)
#define __NR_execve			(__NR_Linux +  11)
#define __NR_chdir			(__NR_Linux +  12)
#define __NR_time			(__NR_Linux +  13)
#define __NR_mknod			(__NR_Linux +  14)
#define __NR_chmod			(__NR_Linux +  15)
#define __NR_lchown			(__NR_Linux +  16)
#define __NR_break			(__NR_Linux +  17)
#define __NR_unused18			(__NR_Linux +  18)
#define __NR_lseek			(__NR_Linux +  19)
#define __NR_getpid			(__NR_Linux +  20)
#define __NR_mount			(__NR_Linux +  21)
#define __NR_umount			(__NR_Linux +  22)
#define __NR_setuid			(__NR_Linux +  23)
#define __NR_getuid			(__NR_Linux +  24)
#define __NR_stime			(__NR_Linux +  25)
#define __NR_ptrace			(__NR_Linux +  26)
#define __NR_alarm			(__NR_Linux +  27)
#define __NR_unused28			(__NR_Linux +  28)
#define __NR_pause			(__NR_Linux +  29)
#define __NR_utime			(__NR_Linux +  30)
#define __NR_stty			(__NR_Linux +  31)
#define __NR_gtty			(__NR_Linux +  32)
#define __NR_access			(__NR_Linux +  33)
#define __NR_nice			(__NR_Linux +  34)
#define __NR_ftime			(__NR_Linux +  35)
#define __NR_sync			(__NR_Linux +  36)
#define __NR_kill			(__NR_Linux +  37)
#define __NR_rename			(__NR_Linux +  38)
#define __NR_mkdir			(__NR_Linux +  39)
#define __NR_rmdir			(__NR_Linux +  40)
#define __NR_dup			(__NR_Linux +  41)
#define __NR_pipe			(__NR_Linux +  42)
#define __NR_times			(__NR_Linux +  43)
#define __NR_prof			(__NR_Linux +  44)
#define __NR_brk			(__NR_Linux +  45)
#define __NR_setgid			(__NR_Linux +  46)
#define __NR_getgid			(__NR_Linux +  47)
#define __NR_signal			(__NR_Linux +  48)
#define __NR_geteuid			(__NR_Linux +  49)
#define __NR_getegid			(__NR_Linux +  50)
#define __NR_acct			(__NR_Linux +  51)
#define __NR_umount2			(__NR_Linux +  52)
#define __NR_lock			(__NR_Linux +  53)
#define __NR_ioctl			(__NR_Linux +  54)
#define __NR_fcntl			(__NR_Linux +  55)
#define __NR_mpx			(__NR_Linux +  56)
#define __NR_setpgid			(__NR_Linux +  57)
#define __NR_ulimit			(__NR_Linux +  58)
#define __NR_unused59			(__NR_Linux +  59)
#define __NR_umask			(__NR_Linux +  60)
#define __NR_chroot			(__NR_Linux +  61)
#define __NR_ustat			(__NR_Linux +  62)
#define __NR_dup2			(__NR_Linux +  63)
#define __NR_getppid			(__NR_Linux +  64)
#define __NR_getpgrp			(__NR_Linux +  65)
#define __NR_setsid			(__NR_Linux +  66)
#define __NR_sigaction			(__NR_Linux +  67)
#define __NR_sgetmask			(__NR_Linux +  68)
#define __NR_ssetmask			(__NR_Linux +  69)
#define __NR_setreuid			(__NR_Linux +  70)
#define __NR_setregid			(__NR_Linux +  71)
#define __NR_sigsuspend			(__NR_Linux +  72)
#define __NR_sigpending			(__NR_Linux +  73)
#define __NR_sethostname		(__NR_Linux +  74)
#define __NR_setrlimit			(__NR_Linux +  75)
#define __NR_getrlimit			(__NR_Linux +  76)
#define __NR_getrusage			(__NR_Linux +  77)
#define __NR_gettimeofday		(__NR_Linux +  78)
#define __NR_settimeofday		(__NR_Linux +  79)
#define __NR_getgroups			(__NR_Linux +  80)
#define __NR_setgroups			(__NR_Linux +  81)
#define __NR_reserved82			(__NR_Linux +  82)
#define __NR_symlink			(__NR_Linux +  83)
#define __NR_unused84			(__NR_Linux +  84)
#define __NR_readlink			(__NR_Linux +  85)
#define __NR_uselib			(__NR_Linux +  86)
#define __NR_swapon			(__NR_Linux +  87)
#define __NR_reboot			(__NR_Linux +  88)
#define __NR_readdir			(__NR_Linux +  89)
#define __NR_mmap			(__NR_Linux +  90)
#define __NR_munmap			(__NR_Linux +  91)
#define __NR_truncate			(__NR_Linux +  92)
#define __NR_ftruncate			(__NR_Linux +  93)
#define __NR_fchmod			(__NR_Linux +  94)
#define __NR_fchown			(__NR_Linux +  95)
#define __NR_getpriority		(__NR_Linux +  96)
#define __NR_setpriority		(__NR_Linux +  97)
#define __NR_profil			(__NR_Linux +  98)
#define __NR_statfs			(__NR_Linux +  99)
#define __NR_fstatfs			(__NR_Linux + 100)
#define __NR_ioperm			(__NR_Linux + 101)
#define __NR_socketcall			(__NR_Linux + 102)
#define __NR_syslog			(__NR_Linux + 103)
#define __NR_setitimer			(__NR_Linux + 104)
#define __NR_getitimer			(__NR_Linux + 105)
#define __NR_stat			(__NR_Linux + 106)
#define __NR_lstat			(__NR_Linux + 107)
#define __NR_fstat			(__NR_Linux + 108)
#define __NR_unused109			(__NR_Linux + 109)
#define __NR_iopl			(__NR_Linux + 110)
#define __NR_vhangup			(__NR_Linux + 111)
#define __NR_idle			(__NR_Linux + 112)
#define __NR_vm86			(__NR_Linux + 113)
#define __NR_wait4			(__NR_Linux + 114)
#define __NR_swapoff			(__NR_Linux + 115)
#define __NR_sysinfo			(__NR_Linux + 116)
#define __NR_ipc			(__NR_Linux + 117)
#define __NR_fsync			(__NR_Linux + 118)
#define __NR_sigreturn			(__NR_Linux + 119)
#define __NR_clone			(__NR_Linux + 120)
#define __NR_setdomainname		(__NR_Linux + 121)
#define __NR_uname			(__NR_Linux + 122)
#define __NR_modify_ldt			(__NR_Linux + 123)
#define __NR_adjtimex			(__NR_Linux + 124)
#define __NR_mprotect			(__NR_Linux + 125)
#define __NR_sigprocmask		(__NR_Linux + 126)
#define __NR_create_module		(__NR_Linux + 127)
#define __NR_init_module		(__NR_Linux + 128)
#define __NR_delete_module		(__NR_Linux + 129)
#define __NR_get_kernel_syms		(__NR_Linux + 130)
#define __NR_quotactl			(__NR_Linux + 131)
#define __NR_getpgid			(__NR_Linux + 132)
#define __NR_fchdir			(__NR_Linux + 133)
#define __NR_bdflush			(__NR_Linux + 134)
#define __NR_sysfs			(__NR_Linux + 135)
#define __NR_personality		(__NR_Linux + 136)
#define __NR_afs_syscall		(__NR_Linux + 137) /* Syscall for Andrew File System */
#define __NR_setfsuid			(__NR_Linux + 138)
#define __NR_setfsgid			(__NR_Linux + 139)
#define __NR__llseek			(__NR_Linux + 140)
#define __NR_getdents			(__NR_Linux + 141)
#define __NR__newselect			(__NR_Linux + 142)
#define __NR_flock			(__NR_Linux + 143)
#define __NR_msync			(__NR_Linux + 144)
#define __NR_readv			(__NR_Linux + 145)
#define __NR_writev			(__NR_Linux + 146)
#define __NR_cacheflush			(__NR_Linux + 147)
#define __NR_cachectl			(__NR_Linux + 148)
#define __NR_sysmips			(__NR_Linux + 149)
#define __NR_unused150			(__NR_Linux + 150)
#define __NR_getsid			(__NR_Linux + 151)
#define __NR_fdatasync			(__NR_Linux + 152)
#define __NR__sysctl			(__NR_Linux + 153)
#define __NR_mlock			(__NR_Linux + 154)
#define __NR_munlock			(__NR_Linux + 155)
#define __NR_mlockall			(__NR_Linux + 156)
#define __NR_munlockall			(__NR_Linux + 157)
#define __NR_sched_setparam		(__NR_Linux + 158)
#define __NR_sched_getparam		(__NR_Linux + 159)
#define __NR_sched_setscheduler		(__NR_Linux + 160)
#define __NR_sched_getscheduler		(__NR_Linux + 161)
#define __NR_sched_yield		(__NR_Linux + 162)
#define __NR_sched_get_priority_max	(__NR_Linux + 163)
#define __NR_sched_get_priority_min	(__NR_Linux + 164)
#define __NR_sched_rr_get_interval	(__NR_Linux + 165)
#define __NR_nanosleep			(__NR_Linux + 166)
#define __NR_mremap			(__NR_Linux + 167)
#define __NR_accept			(__NR_Linux + 168)
#define __NR_bind			(__NR_Linux + 169)
#define __NR_connect			(__NR_Linux + 170)
#define __NR_getpeername		(__NR_Linux + 171)
#define __NR_getsockname		(__NR_Linux + 172)
#define __NR_getsockopt			(__NR_Linux + 173)
#define __NR_listen			(__NR_Linux + 174)
#define __NR_recv			(__NR_Linux + 175)
#define __NR_recvfrom			(__NR_Linux + 176)
#define __NR_recvmsg			(__NR_Linux + 177)
#define __NR_send			(__NR_Linux + 178)
#define __NR_sendmsg			(__NR_Linux + 179)
#define __NR_sendto			(__NR_Linux + 180)
#define __NR_setsockopt			(__NR_Linux + 181)
#define __NR_shutdown			(__NR_Linux + 182)
#define __NR_socket			(__NR_Linux + 183)
#define __NR_socketpair			(__NR_Linux + 184)
#define __NR_setresuid			(__NR_Linux + 185)
#define __NR_getresuid			(__NR_Linux + 186)
#define __NR_query_module		(__NR_Linux + 187)
#define __NR_poll			(__NR_Linux + 188)
#define __NR_nfsservctl			(__NR_Linux + 189)
#define __NR_setresgid			(__NR_Linux + 190)
#define __NR_getresgid			(__NR_Linux + 191)
#define __NR_prctl			(__NR_Linux + 192)
#define __NR_rt_sigreturn		(__NR_Linux + 193)
#define __NR_rt_sigaction		(__NR_Linux + 194)
#define __NR_rt_sigprocmask		(__NR_Linux + 195)
#define __NR_rt_sigpending		(__NR_Linux + 196)
#define __NR_rt_sigtimedwait		(__NR_Linux + 197)
#define __NR_rt_sigqueueinfo		(__NR_Linux + 198)
#define __NR_rt_sigsuspend		(__NR_Linux + 199)
#define __NR_pread			(__NR_Linux + 200)
#define __NR_pwrite			(__NR_Linux + 201)
#define __NR_chown			(__NR_Linux + 202)
#define __NR_getcwd			(__NR_Linux + 203)
#define __NR_capget			(__NR_Linux + 204)
#define __NR_capset			(__NR_Linux + 205)
#define __NR_sigaltstack		(__NR_Linux + 206)
#define __NR_sendfile			(__NR_Linux + 207)
#define __NR_getpmsg			(__NR_Linux + 208)
#define __NR_putpmsg			(__NR_Linux + 209)
#define __NR_mmap2			(__NR_Linux + 210)
#define __NR_truncate64			(__NR_Linux + 211)
#define __NR_ftruncate64		(__NR_Linux + 212)
#define __NR_stat64			(__NR_Linux + 213)
#define __NR_lstat64			(__NR_Linux + 214)
#define __NR_fstat64			(__NR_Linux + 215)
#define __NR_pivot_root			(__NR_Linux + 216)
#define __NR_mincore			(__NR_Linux + 217)
#define __NR_madvise			(__NR_Linux + 218)
#define __NR_getdents64			(__NR_Linux + 219)
#define __NR_fcntl64			(__NR_Linux + 220)
#define __NR_reserved221		(__NR_Linux + 221)
#define __NR_gettid			(__NR_Linux + 222)
#define __NR_readahead			(__NR_Linux + 223)
#define __NR_setxattr			(__NR_Linux + 224)
#define __NR_lsetxattr			(__NR_Linux + 225)
#define __NR_fsetxattr			(__NR_Linux + 226)
#define __NR_getxattr			(__NR_Linux + 227)
#define __NR_lgetxattr			(__NR_Linux + 228)
#define __NR_fgetxattr			(__NR_Linux + 229)
#define __NR_listxattr			(__NR_Linux + 230)
#define __NR_llistxattr			(__NR_Linux + 231)
#define __NR_flistxattr			(__NR_Linux + 232)
#define __NR_removexattr		(__NR_Linux + 233)
#define __NR_lremovexattr		(__NR_Linux + 234)
#define __NR_fremovexattr		(__NR_Linux + 235)
#define __NR_tkill			(__NR_Linux + 236)
#define __NR_sendfile64			(__NR_Linux + 237)
#define __NR_futex			(__NR_Linux + 238)
#define __NR_sched_setaffinity		(__NR_Linux + 239)
#define __NR_sched_getaffinity		(__NR_Linux + 240)
#define __NR_io_setup			(__NR_Linux + 241)
#define __NR_io_destroy			(__NR_Linux + 242)
#define __NR_io_getevents		(__NR_Linux + 243)
#define __NR_io_submit			(__NR_Linux + 244)
#define __NR_io_cancel			(__NR_Linux + 245)
#define __NR_exit_group			(__NR_Linux + 246)
#define __NR_lookup_dcookie		(__NR_Linux + 247)
#define __NR_epoll_create		(__NR_Linux + 248)
#define __NR_epoll_ctl			(__NR_Linux + 249)
#define __NR_epoll_wait			(__NR_Linux + 250)
#define __NR_remap_file_pages		(__NR_Linux + 251)
#define __NR_set_tid_address		(__NR_Linux + 252)
#define __NR_restart_syscall		(__NR_Linux + 253)
#define __NR_fadvise64			(__NR_Linux + 254)
#define __NR_statfs64			(__NR_Linux + 255)
#define __NR_fstatfs64			(__NR_Linux + 256)
#define __NR_timer_create		(__NR_Linux + 257)
#define __NR_timer_settime		(__NR_Linux + 258)
#define __NR_timer_gettime		(__NR_Linux + 259)
#define __NR_timer_getoverrun		(__NR_Linux + 260)
#define __NR_timer_delete		(__NR_Linux + 261)
#define __NR_clock_settime		(__NR_Linux + 262)
#define __NR_clock_gettime		(__NR_Linux + 263)
#define __NR_clock_getres		(__NR_Linux + 264)
#define __NR_clock_nanosleep		(__NR_Linux + 265)
#define __NR_tgkill			(__NR_Linux + 266)
#define __NR_utimes			(__NR_Linux + 267)
#define __NR_mbind			(__NR_Linux + 268)
#define __NR_get_mempolicy		(__NR_Linux + 269)
#define __NR_set_mempolicy		(__NR_Linux + 270)
#define __NR_mq_open			(__NR_Linux + 271)
#define __NR_mq_unlink			(__NR_Linux + 272)
#define __NR_mq_timedsend		(__NR_Linux + 273)
#define __NR_mq_timedreceive		(__NR_Linux + 274)
#define __NR_mq_notify			(__NR_Linux + 275)
#define __NR_mq_getsetattr		(__NR_Linux + 276)
#define __NR_vserver			(__NR_Linux + 277)
#define __NR_waitid			(__NR_Linux + 278)
/* #define __NR_sys_setaltroot		(__NR_Linux + 279) */
#define __NR_add_key			(__NR_Linux + 280)
#define __NR_request_key		(__NR_Linux + 281)
#define __NR_keyctl			(__NR_Linux + 282)
#define __NR_set_thread_area		(__NR_Linux + 283)
#define __NR_inotify_init		(__NR_Linux + 284)
#define __NR_inotify_add_watch		(__NR_Linux + 285)
#define __NR_inotify_rm_watch		(__NR_Linux + 286)
#define __NR_migrate_pages		(__NR_Linux + 287)
#define __NR_openat			(__NR_Linux + 288)
#define __NR_mkdirat			(__NR_Linux + 289)
#define __NR_mknodat			(__NR_Linux + 290)
#define __NR_fchownat			(__NR_Linux + 291)
#define __NR_futimesat			(__NR_Linux + 292)
#define __NR_fstatat			(__NR_Linux + 293)
#define __NR_unlinkat			(__NR_Linux + 294)
#define __NR_renameat			(__NR_Linux + 295)
#define __NR_linkat			(__NR_Linux + 296)
#define __NR_symlinkat			(__NR_Linux + 297)
#define __NR_readlinkat			(__NR_Linux + 298)
#define __NR_fchmodat			(__NR_Linux + 299)
#define __NR_faccessat			(__NR_Linux + 300)
#define __NR_pselect6			(__NR_Linux + 301)
#define __NR_ppoll			(__NR_Linux + 302)
#define __NR_unshare			(__NR_Linux + 303)
#define __NR_splice			(__NR_Linux + 304)
#define __NR_sync_file_range		(__NR_Linux + 305)
#define __NR_tee			(__NR_Linux + 306)
#define __NR_vmsplice			(__NR_Linux + 307)
#define __NR_move_pages			(__NR_Linux + 308)
#define __NR_set_robust_list		(__NR_Linux + 272)
#define __NR_get_robust_list		(__NR_Linux + 273)
#define __NR_kexec_load			(__NR_Linux + 274)
#define __NR_getcpu			(__NR_Linux + 275)
#define __NR_epoll_pwait		(__NR_Linux + 276)
#define __NR_ioprio_set			(__NR_Linux + 277)
#define __NR_ioprio_get			(__NR_Linux + 278)
#define __NR_utimensat			(__NR_Linux + 279)
#define __NR_signalfd			(__NR_Linux + 280)
#define __NR_timerfd			(__NR_Linux + 281)
#define __NR_eventfd			(__NR_Linux + 282)
#define __NR_fallocate			(__NR_Linux + 283)
#define __NR_timerfd_create		(__NR_Linux + 284)
#define __NR_timerfd_gettime		(__NR_Linux + 285)
#define __NR_timerfd_settime		(__NR_Linux + 286)

#define syscall_weak(name,wsym,sym) \
.text; \
.weak wsym; \
wsym: ; \
.global sym; \
.ent sym; \
sym: \
	li	$2,__NR_##name; \
	syscall; \
	la	$25,__unified_syscall; \
	jr	$25; \
.end sym

#define syscall(name,sym) \
.text; \
.global sym; \
.ent sym; \
sym: \
	li	$2,__NR_##name; \
	syscall; \
	la	$25,__unified_syscall; \
	jr	$25; \
.end sym

dietlibc-0.33~cvs20120325/mips/unified.S010064400000000000000000000013461173363227300144300ustar00#include 
#include "syscalls.h"

	.text
	.align	2
	.weak exit
exit:
	.global _exit
	.ent _exit
_exit:
	li	$2,__NR_exit
	syscall
	.end _exit
	.globl	__unified_syscall
	.ent	__unified_syscall
__unified_syscall:
	bne	$7, $0, .Lerror

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	jr	$31
	.end	__unified_syscall

	.global error_unified_syscall
	.ent	error_unified_syscall
error_unified_syscall:
.Lerror:
#ifdef WANT_THREAD_SAFE
	addiu	$sp, $sp, -24

	sw	$31, 0($sp)
	sw	$2,  4($sp)

	la	$25, __errno_location
	jalr	$25

	lw	$8,  4($sp)
	lw	$31, 0($sp)
	sw	$8,  0($2)
	li	$2,  -1
	addiu	$sp, $sp, 24
	jr	$31
#else
	sw	$2,  errno
	li	$2,  -1
	jr	$31
#endif
	.end	error_unified_syscall
dietlibc-0.33~cvs20120325/mipsel/Makefile.add010064400000000000000000000002641173363227300153670ustar00ifeq ($(CROSS),mips-linux-)
ENDIAN=-EL
endif
CFLAGS+=$(ENDIAN) -Os -march=mips2
VPATH:=mips:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/pread64.o $(OBJDIR)/pwrite64.o $(OBJDIR)/divdi3.o
dietlibc-0.33~cvs20120325/mipsel/syscalls.h010064400000000000000000000000361173363227300152030ustar00#include "../mips/syscalls.h"
dietlibc-0.33~cvs20120325/parisc/Makefile.add010064400000000000000000000001471173363227300153570ustar00CFLAGS+=-Os -fomit-frame-pointer
VPATH:=parisc:syscalls.s:$(VPATH)
DIETLIBC_OBJ += $(OBJDIR)/dyncall.o
dietlibc-0.33~cvs20120325/parisc/__longjmp.S010064400000000000000000000025721173363227300152640ustar00/*
  Copyright (C) 2001, 2002 Thomas M. Ogrisegg

  This is free software. You can redistribute and
  modify it under the terms of the GNU General Public
  Public License.

  This file is part of the hppa-Port of the dietlibc

  __longjmp.S
    longjmp(3) implementation
*/

.level 1.1

.text

.export __longjmp
.globl  __longjmp
.type   __longjmp,@function

__longjmp:
	copy %r25, %r28

	/* Restore general registers */
	ldw 0x00(%sr0, %r26), %r3
	ldw 0x08(%sr0, %r26), %r4
	ldw 0x0c(%sr0, %r26), %r5
	ldw 0x10(%sr0, %r26), %r6
	ldw 0x14(%sr0, %r26), %r7
	ldw 0x18(%sr0, %r26), %r8
	ldw 0x1c(%sr0, %r26), %r9
	ldw 0x20(%sr0, %r26), %r10
	ldw 0x24(%sr0, %r26), %r11
	ldw 0x28(%sr0, %r26), %r12
	ldw 0x2c(%sr0, %r26), %r13
	ldw 0x30(%sr0, %r26), %r14
	ldw 0x34(%sr0, %r26), %r15
	ldw 0x38(%sr0, %r26), %r16
	ldw 0x3c(%sr0, %r26), %r17
	ldw 0x40(%sr0, %r26), %r18
	ldw 0x44(%sr0, %r26), %r19
	ldw 0x48(%sr0, %r26), %dp
	ldw 0x4c(%sr0, %r26), %sp
	ldw 0x50(%sr0, %r26), %rp

	ldo 0x58(%r26), %r20

	/* Restore the Floating point registers */
	fldd,ma 0x8(%sr0, %r20), %fr12
	fldd,ma 0x8(%sr0, %r20), %fr13
	fldd,ma 0x8(%sr0, %r20), %fr14
	fldd,ma 0x8(%sr0, %r20), %fr15
	fldd,ma 0x8(%sr0, %r20), %fr16
	fldd,ma 0x8(%sr0, %r20), %fr16
	fldd,ma 0x8(%sr0, %r20), %fr17
	fldd,ma 0x8(%sr0, %r20), %fr18
	fldd,ma 0x8(%sr0, %r20), %fr19
	fldd,ma 0x8(%sr0, %r20), %fr20
	fldd 0(%sr0, %r20), %fr21

	bv,n %r0(%rp)
dietlibc-0.33~cvs20120325/parisc/__testandset.S010064400000000000000000000001721173363227300157660ustar00.level 1.1
.text
.globl __testandset
__testandset:
	ldcw 0(%sr0, %r26), %r28
	ldi 1,%r19
	bv %r0(%r2)
	xor %r28,%r19,%r28
dietlibc-0.33~cvs20120325/parisc/_llseek.S010064400000000000000000000000611173363227300147250ustar00#include "syscalls.h"

syscall5(llseek, llseek);
dietlibc-0.33~cvs20120325/parisc/clone.S010064400000000000000000000017301173363227300144130ustar00#include 
#include "syscalls.h"

.global __clone
__clone:
	comibt,= 0,%r26,.Lerror		/* function pointer ? */
	ldi	-EINVAL,%r28
	comibt,=,n 0,%r25,.Lerror	/* stack pointer ? */

	stwm	%r26,64(%sr0,%r25)	/* save function ptr	on thread stack */
	stw	%r23, 8(%sr0,%r25)	/* save argument	on thread stack */

	/* syscall */
	copy	%r24,%r26
	ble	0x100(%sr2,%r0)
	ldi	__NR_clone,%r20

	/* error ? */
	ldi	-4096,%r1
	combt,<<,n %r1,%r28,.Lerror

	/* am I the child ? */
	comibt,=,n 0,%r28,.Lthread_start

	/* parent return */
	bv,n	%r0(%r2)

.Lerror: /* there was an error / for nullification a forward reference */
	b	__error_unified_syscall
	sub	%r0,%r28,%r28		/* return=-return / kernel error to errno */

.Lthread_start:
	ldw	-64(%sr0,%r30),%r22	/* function ptr */
	ldw	8(%sr0,%r30),%r26	/* load argument */

	bl,n	$$dyncall,%r2		/* microcode call / is in libgcc */
	bl	_exit,%r2		/* exit thread */
	copy	%r28,%r26		/* return -> arg0 */

/*	iitlbp	%r0,(%r0) */		/* DIE ! DIE ! */
dietlibc-0.33~cvs20120325/parisc/getsockopt.S010064400000000000000000000000711173363227300154720ustar00#include "syscalls.h"

syscall5(getsockopt, getsockopt);
dietlibc-0.33~cvs20120325/parisc/mmap.S010064400000000000000000000000551173363227300142440ustar00#include "syscalls.h"

syscall6(mmap, mmap);
dietlibc-0.33~cvs20120325/parisc/mmap2.S010064400000000000000000000001111173363227300143170ustar00#include "syscalls.h"

#ifdef __NR_mmap2
syscall6(mmap2,__mmap2)
#endif

dietlibc-0.33~cvs20120325/parisc/mount.S010064400000000000000000000000571173363227300144560ustar00#include "syscalls.h"

syscall5(mount, mount);
dietlibc-0.33~cvs20120325/parisc/recvfrom.S010064400000000000000000000000651173363227300151360ustar00#include "syscalls.h"

syscall6(recvfrom, recvfrom);
dietlibc-0.33~cvs20120325/parisc/select.S010064400000000000000000000000611173363227300145660ustar00#include "syscalls.h"

syscall5(select, select);
dietlibc-0.33~cvs20120325/parisc/sendto.S010064400000000000000000000000611173363227300146030ustar00#include "syscalls.h"

syscall6(sendto, sendto);
dietlibc-0.33~cvs20120325/parisc/setjmp.S010064400000000000000000000027341173363227300146220ustar00/*
  Copyright (C) 2001, 2002 Thomas M. Ogrisegg

  This is free  software. You can  redistribute  and
  modify it under the terms of the GNU General Public 
  License.

  This file is part of the hppa-Port of the dietlibc

  setjmp.S
    setjmp(3) implementation
*/

#include 
.level 1.1

.text

.weak setjmp
.type setjmp,@function
.globl _setjmp
.type _setjmp,@function
.globl __setjmp
.type __setjmp,@function
setjmp:
_setjmp:
__setjmp:
	ldi 0, %r25

.globl __sigsetjmp
.type __sigsetjmp,@function
__sigsetjmp:
	/* Save GR registers */
	stw %r3,  0x00(%sr0, %r26)
	stw %r4,  0x08(%sr0, %r26)
	stw %r5,  0x0c(%sr0, %r26)
	stw %r6,  0x10(%sr0, %r26)
	stw %r7,  0x14(%sr0, %r26)
	stw %r8,  0x18(%sr0, %r26)
	stw %r9,  0x1c(%sr0, %r26)
	stw %r10, 0x20(%sr0, %r26)
	stw %r11, 0x24(%sr0, %r26)
	stw %r12, 0x28(%sr0, %r26)
	stw %r13, 0x2c(%sr0, %r26)
	stw %r14, 0x30(%sr0, %r26)
	stw %r15, 0x34(%sr0, %r26)
	stw %r16, 0x38(%sr0, %r26)
	stw %r17, 0x3c(%sr0, %r26)
	stw %r18, 0x40(%sr0, %r26)
	stw %r19, 0x44(%sr0, %r26)
	stw %dp,  0x48(%sr0, %r26)
	stw %sp,  0x4c(%sr0, %r26)
	stw %rp,  0x50(%sr0, %r26)
	/* Floating point stack in %r19 */
	ldo 0x58(%r26), %r19
	/* Save Floating point registers */
	fstd,ma %fr12, 8(%sr0, %r19)
	fstd,ma %fr13, 8(%sr0, %r19)
	fstd,ma %fr15, 8(%sr0, %r19)
	fstd,ma %fr16, 8(%sr0, %r19)
	fstd,ma %fr17, 8(%sr0, %r19)
	fstd,ma %fr18, 8(%sr0, %r19)
	fstd,ma %fr19, 8(%sr0, %r19)
	fstd,ma %fr20, 8(%sr0, %r19)
	fstd %fr21, 0(%sr0, %r19)
	b,l __sigjmp_save, %r0
	nop
dietlibc-0.33~cvs20120325/parisc/setsockopt.S010064400000000000000000000000711173363227300155060ustar00#include "syscalls.h"

syscall5(setsockopt, setsockopt);
dietlibc-0.33~cvs20120325/parisc/start.S010064400000000000000000000017131173363227300144510ustar00/*
  Copyright (C) 2001, 2002 Thomas M. Ogrisegg

  This is free software. You can redistribute and
  modify it under the terms of the GNU General Public
  Public License.

  This file is part of the hppa-Port of the dietlibc

  start.S
    Implemenation of the _start startup function
*/

#include "dietfeatures.h"

.level 1.1

.text

.export _start
.globl _start
.type _start,@function

_start:
	.PROC
	.CALLINFO CALLS, SAVE_RP
	.ENTRY
	copy %r25, %r26				; %r26 = argc
	zdep %r26, 29, 30, %r19		; %r19 = argc*4
	ldi 4, %r20
	add %r20, %r19, %r19		; %r19 = argc*4+4
	copy %r24, %r25
	add %r19, %r24, %r24
	ldil LP%environ, %r19
	ldo RP%environ(%r19), %r19

	/* Expand the stack to store the 5th through 7th args */
	ldo 64(%sp), %sp

	stw %r24, 0(%sr0, %r19)
	ldil L%$global$, %dp
#ifdef WANT_DYNAMIC
/* FIXME: dl_init parameter ??? */
	bl _dyn_start, %rp
#else
	bl CALL_IN_STARTCODE, %rp
#endif
	ldo R%$global$(%dp), %dp
	b _exit
	or %r28, %r28, %r26
	.EXIT
	.PROCEND
dietlibc-0.33~cvs20120325/parisc/strcasecmp.S010064400000000000000000000011751173363227300154620ustar00/* strcasecmp -- strcasecmp(3) -- compare two strings caseindependently

  Copyright (C) 2002 Thomas M. Ogrisegg

  Created:              09/22/02
  Last updated:         09/23/02

  Remarks:
	none
*/

.LEVEL	1.1

.text
.globl strcasecmp
strcasecmp:
	.PROC
	.CALLINFO
	.ENTRY
	ldi 0x7a, %r23
	ldi 0x41, %r22
	ldi 0x20, %r21
.Lstrcasecmp:
	ldb,ma 1(%r26), %r19
	ldb,ma 1(%r25), %r20
	cmpb,>,n %r22, %r20, .Lno_or
	cmpb,<,n %r23, %r20, .Lno_or
	or %r21, %r19, %r19
	or %r21, %r20, %r20
.Lno_or:
	comclr,= %r0, %r19, %r0
	cmpb,=,n %r19, %r20, .Lstrcasecmp
	nop
.Lret:
	bv %r0(%rp)
	sub %r19, %r20, %r28
	.EXIT
	.PROCEND
	.EXPORT strcasecmp
dietlibc-0.33~cvs20120325/parisc/strcmp.S010064400000000000000000000003571173363227300146270ustar00.text
.globl strcmp

strcmp:
	.PROC
	.CALLINFO
	.ENTRY
	ldb,ma 1(%r26), %r19
	ldb,ma 1(%r25), %r20
	cmpb,=,n %r19, %r0,  .Lexit
	cmpb,=,n %r19, %r20, strcmp
	nop
.Lexit:
	bv %r0(%rp)
	sub %r19, %r20, %ret0
	.EXIT
	.PROCEND
	.EXPORT strcmp
dietlibc-0.33~cvs20120325/parisc/strlen.S010064400000000000000000000021161173363227300146210ustar00/* strlen -- strlen(3) -- determine length of a string

  Copyright (C) 2002 Thomas M. Ogrisegg

  Created:              09/22/02
  Last updated:         09/23/02

  Remarks:
      Highperformance uxor-based strlen implementation. Even faster
      than the HP-UX libc implementation, which is also uxor-based.
*/

.LEVEL  1.1

.text
.globl strlen

strlen:
        .PROC
        .CALLINFO
        .ENTRY
        xor %r28, %r28, %r28
        ldi 3, %r19
        and,<> %r26, %r19, %r20
        b,n .Lstrlen17
        sub %r19, %r20, %r20
        addi 1, %r20, %r20
.Lstrlen23:
        ldb,ma 1(%r26), %r19
        cmpb,=,n %r0, %r19, .Lstrlen42
        addi 1, %r28, %r28
        addi,= -1, %r20, %r20
        b,n .Lstrlen23
.Lstrlen17:
        ldw,ma 4(%r26), %r19
        uxor,sbz %r19, %r0, %r0
        b .Lstrlen17
        addi 4, %r28, %r28
        addi -5, %r28, %r28
.Lstrlen72:
        extrs %r19, 7, 8, %r20
        addi 1, %r28, %r28
        cmpb,<> %r0, %r20, .Lstrlen72
        depw %r19, 23, 24, %r19
.Lstrlen42:
        bv,n %r0(%rp)
        .EXIT
        .PROCEND
        .EXPORT strlen

dietlibc-0.33~cvs20120325/parisc/strncasecmp.S010064400000000000000000000012251173363227300156340ustar00/* strncasecmp -- strncasecmp(3) -- compare two strings caseindependently

  Copyright (C) 2002 Thomas M. Ogrisegg

  Created:              09/22/02
  Last updated:         09/23/02

  Remarks:
	none
*/

.text
.globl strncasecmp

strncasecmp:
	.PROC
	.CALLINFO
	.ENTRY
	ldi 0x7a, %r23
	ldi 0x41, %r22
	ldi 0x20, %r21
.Lstrncasecmp:
	addibt,<,n -1, %r24, .Lret
	ldb,ma 1(%r26), %r19
	ldb,ma 1(%r25), %r20
	cmpb,>,n %r22, %r20, .Lno_or
	cmpb,<,n %r23, %r20, .Lno_or
	or %r21, %r19, %r19
	or %r21, %r20, %r20
.Lno_or:
	comclr,= %r0, %r19, %r0
	cmpb,=,n %r19, %r20, .Lstrncasecmp
	nop
.Lret:
	bv %r0(%rp)
	sub %r19, %r20, %r28
	.EXIT
	.PROCEND
	.EXPORT strncasecmp
dietlibc-0.33~cvs20120325/parisc/strncmp.S010064400000000000000000000004321173363227300147770ustar00.LEVEL	1.1

.text
.globl strncmp

strncmp:
	.PROC
	.CALLINFO
	.ENTRY
	ldb,ma 1(%r26), %r19
	ldb,ma 1(%r25), %r20
	addibt,= -1, %r24, .Lexit
	cmpb,=,n %r19, %r0,  .Lexit
	cmpb,=,n %r19, %r20, strncmp
	nop
.Lexit:
	bv %r0(%rp)
	sub %r19, %r20, %ret0
	.EXIT
	.PROCEND
	.EXPORT strncmp
dietlibc-0.33~cvs20120325/parisc/strncpy.S010064400000000000000000000003251173363227300150140ustar00.LEVEL	1.1

.text
.globl strncpy

strncpy:
	.PROC
	.CALLINFO
	.ENTRY
	ldb,ma 1(%r25), %r19
	addi,= -1, %r24, %r24
	cmpb,<> %r0, %r19, strncpy
	stb,ma %r19, 1(%r26)
	bv,n %r0(%rp)
	.EXIT
	.PROCEND
	.EXPORT strncpy
dietlibc-0.33~cvs20120325/parisc/strpbrk.S010064400000000000000000000005421173363227300150020ustar00.level 1.1

.text
.globl strpbrk

strpbrk:
	.PROC
	.CALLINFO
	.ENTRY
	ldb,ma 1(%r26), %r19
	cmpb,=,n %r0, %r19, .Leret
	copy %r25, %r23
	ldb,ma 1(%r23), %r20
.Lcmp:
	cmpb,=,n %r0, %r20, strpbrk
	nop
	cmpb,<>,n %r19, %r20, .Lcmp
	ldb,ma 1(%r23), %r20
	bv %r0(%rp)
	addi -1, %r26, %ret0
.Leret:
	bv %r0(%rp)
	ldi 0, %ret0
	.EXIT
	.PROCEND
	.EXPORT strpbrk
dietlibc-0.33~cvs20120325/parisc/strrchr.S010064400000000000000000000007161173363227300150050ustar00/* strrchr -- strrchr(3) -- search last occurence of a character in a string

  Copyright (C) 2002 Thomas M. Ogrisegg

  Created:              09/22/02
  Last updated:         09/23/02

  Remarks:
      none
*/
.text
.globl strrchr

strrchr:
	.PROC
	.CALLINFO
	.ENTRY
	ldi 1, %ret0
.L3:
	ldb,ma 1(%r26), %r19
	comclr,<> %r25, %r19, %r0
	copy %r26, %ret0
	cmpb,<>,n %r0, %r19, .L3
	nop
.Lret:
	bv %r0(%rp)
	addi -1, %ret0, %ret0
	.EXIT
	.PROCEND
	.EXPORT strrchr
dietlibc-0.33~cvs20120325/parisc/strstr.S010064400000000000000000000010061173363227300146500ustar00.level 1.1

.text
.globl strstr
strstr:
	.PROC
	.CALLINFO
	.ENTRY
	ldb,ma 1(%r25), %r20
	ldb,ma 1(%r26), %r19
	ldi 2, %ret0
.L1:
	cmpb,=,n %r0, %r19, .Lret2
	cmpb,<> %r20, %r19, .L1
	ldb,ma 1(%r26), %r19
	copy %r19, %r24
	copy %r25, %r23
	ldb,ma 1(%r23), %r21
	copy %r26, %r22
.Lloop:
	cmpb,<> %r24, %r21, .L1
	ldb,ma 1(%r22), %r24
	cmpb,= %r0, %r24, .Lret
	ldb,ma 1(%r23), %r21
	cmpb,<>,n %r21, %r0, .Lloop
	nop
.Lret:
	addi 0, %r26, %ret0
.Lret2:
	bv %r0(%rp)
	addi -2, %ret0, %ret0
	.EXIT
	.PROCEND
	.EXPORT strstr
dietlibc-0.33~cvs20120325/parisc/syscalls.h010064400000000000000000000400021173363230200151610ustar00/*
  Copyright (C) 2001, 2002 Thomas M. Ogrisegg

  This is free software. You can redistribute and
  modify it under the terms of the GNU General Public
  Public License.

  This file is part of the hppa-Port of the dietlibc

  syscalls.h
    Header file including the systemcall index-
    and implementation macros
*/

#define __NR_Linux                0
#define __NR_syscall              (__NR_Linux + 0)
#define __NR_exit                 (__NR_Linux + 1)
#define __NR_fork                 (__NR_Linux + 2)
#define __NR_read                 (__NR_Linux + 3)
#define __NR_write                (__NR_Linux + 4)
#define __NR_open                 (__NR_Linux + 5)
#define __NR_close                (__NR_Linux + 6)
#define __NR_waitpid              (__NR_Linux + 7)
#define __NR_creat                (__NR_Linux + 8)
#define __NR_link                 (__NR_Linux + 9)
#define __NR_unlink              (__NR_Linux + 10)
#define __NR_execve              (__NR_Linux + 11)
#define __NR_chdir               (__NR_Linux + 12)
#define __NR_time                (__NR_Linux + 13)
#define __NR_mknod               (__NR_Linux + 14)
#define __NR_chmod               (__NR_Linux + 15)
#define __NR_lchown              (__NR_Linux + 16)
#define __NR_socket              (__NR_Linux + 17)
#define __NR_stat                (__NR_Linux + 18)
#define __NR_lseek               (__NR_Linux + 19)
#define __NR_getpid              (__NR_Linux + 20)
#define __NR_mount               (__NR_Linux + 21)
#define __NR_bind                (__NR_Linux + 22)
#define __NR_setuid              (__NR_Linux + 23)
#define __NR_getuid              (__NR_Linux + 24)
#define __NR_stime               (__NR_Linux + 25)
#define __NR_ptrace              (__NR_Linux + 26)
#define __NR_alarm               (__NR_Linux + 27)
#define __NR_fstat               (__NR_Linux + 28)
#define __NR_pause               (__NR_Linux + 29)
#define __NR_utime               (__NR_Linux + 30)
#define __NR_connect             (__NR_Linux + 31)
#define __NR_listen              (__NR_Linux + 32)
#define __NR_access              (__NR_Linux + 33)
#define __NR_nice                (__NR_Linux + 34)
#define __NR_accept              (__NR_Linux + 35)
#define __NR_sync                (__NR_Linux + 36)
#define __NR_kill                (__NR_Linux + 37)
#define __NR_rename              (__NR_Linux + 38)
#define __NR_mkdir               (__NR_Linux + 39)
#define __NR_rmdir               (__NR_Linux + 40)
#define __NR_dup                 (__NR_Linux + 41)
#define __NR_pipe                (__NR_Linux + 42)
#define __NR_times               (__NR_Linux + 43)
#define __NR_getsockname         (__NR_Linux + 44)
#define __NR_brk                 (__NR_Linux + 45)
#define __NR_setgid              (__NR_Linux + 46)
#define __NR_getgid              (__NR_Linux + 47)
#define __NR_signal              (__NR_Linux + 48)
#define __NR_geteuid             (__NR_Linux + 49)
#define __NR_getegid             (__NR_Linux + 50)
#define __NR_acct                (__NR_Linux + 51)
#define __NR_umount2             (__NR_Linux + 52)
#define __NR_getpeername         (__NR_Linux + 53)
#define __NR_ioctl               (__NR_Linux + 54)
#define __NR_fcntl               (__NR_Linux + 55)
#define __NR_socketpair          (__NR_Linux + 56)
#define __NR_setpgid             (__NR_Linux + 57)
#define __NR_send                (__NR_Linux + 58)
#define __NR_uname               (__NR_Linux + 59)
#define __NR_umask               (__NR_Linux + 60)
#define __NR_chroot              (__NR_Linux + 61)
#define __NR_ustat               (__NR_Linux + 62)
#define __NR_dup2                (__NR_Linux + 63)
#define __NR_getppid             (__NR_Linux + 64)
#define __NR_getpgrp             (__NR_Linux + 65)
#define __NR_setsid              (__NR_Linux + 66)
#define __NR_pivot_root          (__NR_Linux + 67)
#define __NR_sgetmask            (__NR_Linux + 68)
#define __NR_ssetmask            (__NR_Linux + 69)
#define __NR_setreuid            (__NR_Linux + 70)
#define __NR_setregid            (__NR_Linux + 71)
#define __NR_mincore             (__NR_Linux + 72)
#define __NR_sigpending          (__NR_Linux + 73)
#define __NR_sethostname         (__NR_Linux + 74)
#define __NR_setrlimit           (__NR_Linux + 75)
#define __NR_getrlimit           (__NR_Linux + 76)
#define __NR_getrusage           (__NR_Linux + 77)
#define __NR_gettimeofday        (__NR_Linux + 78)
#define __NR_settimeofday        (__NR_Linux + 79)
#define __NR_getgroups           (__NR_Linux + 80)
#define __NR_setgroups           (__NR_Linux + 81)
#define __NR_sendto              (__NR_Linux + 82)
#define __NR_symlink             (__NR_Linux + 83)
#define __NR_lstat               (__NR_Linux + 84)
#define __NR_readlink            (__NR_Linux + 85)
#define __NR_uselib              (__NR_Linux + 86)
#define __NR_swapon              (__NR_Linux + 87)
#define __NR_reboot              (__NR_Linux + 88)
#define __NR_mmap2             (__NR_Linux + 89)
#define __NR_mmap                (__NR_Linux + 90)
#define __NR_munmap              (__NR_Linux + 91)
#define __NR_truncate            (__NR_Linux + 92)
#define __NR_ftruncate           (__NR_Linux + 93)
#define __NR_fchmod              (__NR_Linux + 94)
#define __NR_fchown              (__NR_Linux + 95)
#define __NR_getpriority         (__NR_Linux + 96)
#define __NR_setpriority         (__NR_Linux + 97)
#define __NR_recv                (__NR_Linux + 98)
#define __NR_statfs              (__NR_Linux + 99)
#define __NR_fstatfs            (__NR_Linux + 100)
#define __NR_stat64           (__NR_Linux + 101)
/* #define __NR_socketcall         (__NR_Linux + 102) */
#define __NR_syslog             (__NR_Linux + 103)
#define __NR_setitimer          (__NR_Linux + 104)
#define __NR_getitimer          (__NR_Linux + 105)
#define __NR_capget             (__NR_Linux + 106)
#define __NR_capset             (__NR_Linux + 107)
#define __NR_pread              (__NR_Linux + 108)
#define __NR_pwrite             (__NR_Linux + 109)
#define __NR_getcwd             (__NR_Linux + 110)
#define __NR_vhangup            (__NR_Linux + 111)
#define __NR_fstat64            (__NR_Linux + 112)
#define __NR_vfork              (__NR_Linux + 113)
#define __NR_wait4              (__NR_Linux + 114)
#define __NR_swapoff            (__NR_Linux + 115)
#define __NR_sysinfo            (__NR_Linux + 116)
#define __NR_shutdown           (__NR_Linux + 117)
#define __NR_fsync              (__NR_Linux + 118)
#define __NR_madvise            (__NR_Linux + 119)
#define __NR_clone              (__NR_Linux + 120)
#define __NR_setdomainname      (__NR_Linux + 121)
#define __NR_sendfile           (__NR_Linux + 122)
#define __NR_recvfrom           (__NR_Linux + 123)
#define __NR_adjtimex           (__NR_Linux + 124)
#define __NR_mprotect           (__NR_Linux + 125)
#define __NR_sigprocmask        (__NR_Linux + 126)
#define __NR_create_module      (__NR_Linux + 127)
#define __NR_init_module        (__NR_Linux + 128)
#define __NR_delete_module      (__NR_Linux + 129)
#define __NR_get_kernel_syms    (__NR_Linux + 130)
#define __NR_quotactl           (__NR_Linux + 131)
#define __NR_getpgid            (__NR_Linux + 132)
#define __NR_fchdir             (__NR_Linux + 133)
#define __NR_bdflush            (__NR_Linux + 134)
#define __NR_sysfs              (__NR_Linux + 135)
#define __NR_personality        (__NR_Linux + 136)
#define __NR_afs_syscall        (__NR_Linux + 137) /* Syscall for Andrew File System */
#define __NR_setfsuid           (__NR_Linux + 138)
#define __NR_setfsgid           (__NR_Linux + 139)
#define __NR_llseek             (__NR_Linux + 140)
#define __NR_getdents           (__NR_Linux + 141)
#define __NR_select		(__NR_Linux + 142)
#define __NR__newselect         (__NR_Linux + 142)
#define __NR_flock              (__NR_Linux + 143)
#define __NR_msync              (__NR_Linux + 144)
#define __NR_readv              (__NR_Linux + 145)
#define __NR_writev             (__NR_Linux + 146)
#define __NR_getsid             (__NR_Linux + 147)
#define __NR_fdatasync          (__NR_Linux + 148)
#define __NR__sysctl            (__NR_Linux + 149)
#define __NR_mlock              (__NR_Linux + 150)
#define __NR_munlock            (__NR_Linux + 151)
#define __NR_mlockall           (__NR_Linux + 152)
#define __NR_munlockall         (__NR_Linux + 153)
#define __NR_sched_setparam             (__NR_Linux + 154)
#define __NR_sched_getparam             (__NR_Linux + 155)
#define __NR_sched_setscheduler         (__NR_Linux + 156)
#define __NR_sched_getscheduler         (__NR_Linux + 157)
#define __NR_sched_yield                (__NR_Linux + 158)
#define __NR_sched_get_priority_max     (__NR_Linux + 159)
#define __NR_sched_get_priority_min     (__NR_Linux + 160)
#define __NR_sched_rr_get_interval      (__NR_Linux + 161)
#define __NR_nanosleep          (__NR_Linux + 162)
#define __NR_mremap             (__NR_Linux + 163)
#define __NR_setresuid          (__NR_Linux + 164)
#define __NR_getresuid          (__NR_Linux + 165)
#define __NR_sigaltstack        (__NR_Linux + 166)
#define __NR_query_module       (__NR_Linux + 167)
#define __NR_poll               (__NR_Linux + 168)
#define __NR_nfsservctl         (__NR_Linux + 169)
#define __NR_setresgid          (__NR_Linux + 170)
#define __NR_getresgid          (__NR_Linux + 171)
#define __NR_prctl              (__NR_Linux + 172)
#define __NR_rt_sigreturn       (__NR_Linux + 173)
#define __NR_rt_sigaction       (__NR_Linux + 174)
#define __NR_rt_sigprocmask     (__NR_Linux + 175)
#define __NR_rt_sigpending      (__NR_Linux + 176)
#define __NR_rt_sigtimedwait    (__NR_Linux + 177)
#define __NR_rt_sigqueueinfo    (__NR_Linux + 178)
#define __NR_rt_sigsuspend      (__NR_Linux + 179)
#define __NR_chown              (__NR_Linux + 180)
#define __NR_setsockopt         (__NR_Linux + 181)
#define __NR_getsockopt         (__NR_Linux + 182)
#define __NR_sendmsg            (__NR_Linux + 183)
#define __NR_recvmsg            (__NR_Linux + 184)
#define __NR_semop              (__NR_Linux + 185)
#define __NR_semget             (__NR_Linux + 186)
#define __NR_semctl             (__NR_Linux + 187)
#define __NR_msgsnd             (__NR_Linux + 188)
#define __NR_msgrcv             (__NR_Linux + 189)
#define __NR_msgget             (__NR_Linux + 190)
#define __NR_msgctl             (__NR_Linux + 191)
#define __NR_shmat              (__NR_Linux + 192)
#define __NR_shmdt              (__NR_Linux + 193)
#define __NR_shmget             (__NR_Linux + 194)
#define __NR_shmctl             (__NR_Linux + 195)
#define __NR_getpmsg            (__NR_Linux + 196)
#define __NR_putpmsg            (__NR_Linux + 197)
#define __NR_lstat64            (__NR_Linux + 198)
#define __NR_truncate64         (__NR_Linux + 199)
#define __NR_ftruncate64        (__NR_Linux + 200)
#define __NR_getdents64         (__NR_Linux + 201)
#define __NR_fcntl64            (__NR_Linux + 202)
#define __NR_attrctl            (__NR_Linux + 203)
#define __NR_acl_get            (__NR_Linux + 204)
#define __NR_acl_set            (__NR_Linux + 205)
#define __NR_gettid             (__NR_Linux + 206)
#define __NR_readahead          (__NR_Linux + 207)
#define __NR_tkill              (__NR_Linux + 208)
#define __NR_sendfile64         (__NR_Linux + 209)
#define __NR_futex              (__NR_Linux + 210)
#define __NR_sched_setaffinity  (__NR_Linux + 211)
#define __NR_sched_getaffinity  (__NR_Linux + 212)
#define __NR_set_thread_area    (__NR_Linux + 213)
#define __NR_get_thread_area    (__NR_Linux + 214)
#define __NR_io_setup           (__NR_Linux + 215)
#define __NR_io_destroy         (__NR_Linux + 216)
#define __NR_io_getevents       (__NR_Linux + 217)
#define __NR_io_submit          (__NR_Linux + 218)
#define __NR_io_cancel          (__NR_Linux + 219)
#define __NR_alloc_hugepages    (__NR_Linux + 220)
#define __NR_free_hugepages     (__NR_Linux + 221)
#define __NR_exit_group         (__NR_Linux + 222)
#define __NR_lookup_dcookie     (__NR_Linux + 223)
#define __NR_epoll_create       (__NR_Linux + 224)
#define __NR_epoll_ctl          (__NR_Linux + 225)
#define __NR_epoll_wait         (__NR_Linux + 226)
#define __NR_remap_file_pages   (__NR_Linux + 227)
#define __NR_semtimedop         (__NR_Linux + 228)
#define __NR_mq_open            (__NR_Linux + 229)
#define __NR_mq_unlink          (__NR_Linux + 230)
#define __NR_mq_timedsend       (__NR_Linux + 231)
#define __NR_mq_timedreceive    (__NR_Linux + 232)
#define __NR_mq_notify          (__NR_Linux + 233)
#define __NR_mq_getsetattr      (__NR_Linux + 234)
#define __NR_waitid		(__NR_Linux + 235)
#define __NR_fadvise64_64	(__NR_Linux + 236)
#define __NR_set_tid_address	(__NR_Linux + 237)
#define __NR_setxattr		(__NR_Linux + 238)
#define __NR_lsetxattr		(__NR_Linux + 239)
#define __NR_fsetxattr		(__NR_Linux + 240)
#define __NR_getxattr		(__NR_Linux + 241)
#define __NR_lgetxattr		(__NR_Linux + 242)
#define __NR_fgetxattr		(__NR_Linux + 243)
#define __NR_listxattr		(__NR_Linux + 244)
#define __NR_llistxattr		(__NR_Linux + 245)
#define __NR_flistxattr		(__NR_Linux + 246)
#define __NR_removexattr	(__NR_Linux + 247)
#define __NR_lremovexattr	(__NR_Linux + 248)
#define __NR_fremovexattr	(__NR_Linux + 249)
#define __NR_timer_create	(__NR_Linux + 250)
#define __NR_timer_settime	(__NR_Linux + 251)
#define __NR_timer_gettime	(__NR_Linux + 252)
#define __NR_timer_getoverrun	(__NR_Linux + 253)
#define __NR_timer_delete	(__NR_Linux + 254)
#define __NR_clock_settime	(__NR_Linux + 255)
#define __NR_clock_gettime	(__NR_Linux + 256)
#define __NR_clock_getres	(__NR_Linux + 257)
#define __NR_clock_nanosleep	(__NR_Linux + 258)
#define __NR_tgkill		(__NR_Linux + 259)
#define __NR_mbind		(__NR_Linux + 260)
#define __NR_get_mempolicy	(__NR_Linux + 261)
#define __NR_set_mempolicy	(__NR_Linux + 262)
#define __NR_vserver		(__NR_Linux + 263)
#define __NR_add_key		(__NR_Linux + 264)
#define __NR_request_key	(__NR_Linux + 265)
#define __NR_keyctl		(__NR_Linux + 266)
#define __NR_ioprio_set		(__NR_Linux + 267)
#define __NR_ioprio_get		(__NR_Linux + 268)
#define __NR_inotify_init	(__NR_Linux + 269)
#define __NR_inotify_add_watch	(__NR_Linux + 270)
#define __NR_inotify_rm_watch	(__NR_Linux + 271)
#define __NR_migrate_pages	(__NR_Linux + 272)
#define __NR_pselect6		(__NR_Linux + 273)
#define __NR_ppoll		(__NR_Linux + 274)
#define __NR_openat		(__NR_Linux + 275)
#define __NR_mkdirat		(__NR_Linux + 276)
#define __NR_mknodat		(__NR_Linux + 277)
#define __NR_fchownat		(__NR_Linux + 278)
#define __NR_futimesat		(__NR_Linux + 279)
#define __NR_fstatat64		(__NR_Linux + 280)
#define __NR_unlinkat		(__NR_Linux + 281)
#define __NR_renameat		(__NR_Linux + 282)
#define __NR_linkat		(__NR_Linux + 283)
#define __NR_symlinkat		(__NR_Linux + 284)
#define __NR_readlinkat		(__NR_Linux + 285)
#define __NR_fchmodat		(__NR_Linux + 286)
#define __NR_faccessat		(__NR_Linux + 287)
#define __NR_unshare		(__NR_Linux + 288)
#define __NR_set_robust_list	(__NR_Linux + 289)
#define __NR_get_robust_list	(__NR_Linux + 290)
#define __NR_splice		(__NR_Linux + 291)
#define __NR_sync_file_range	(__NR_Linux + 292)
#define __NR_tee		(__NR_Linux + 293)
#define __NR_vmsplice		(__NR_Linux + 294)
#define __NR_move_pages		(__NR_Linux + 295)
#define __NR_getcpu		(__NR_Linux + 296)
#define __NR_epoll_pwait	(__NR_Linux + 297)
#define __NR_statfs64		(__NR_Linux + 298)
#define __NR_fstatfs64		(__NR_Linux + 299)
#define __NR_kexec_load		(__NR_Linux + 300)
#define __NR_utimensat		(__NR_Linux + 301)
#define __NR_signalfd		(__NR_Linux + 302)
#define __NR_timerfd		(__NR_Linux + 303)
#define __NR_eventfd		(__NR_Linux + 304)
#define __NR_fallocate		(__NR_Linux + 305)
#define __NR_timerfd_create	(__NR_Linux + 306)
#define __NR_timerfd_settime	(__NR_Linux + 307)
#define __NR_timerfd_gettime	(__NR_Linux + 308)

#define __NR_Linux_syscalls	(__NR_fallocate + 1)

#define LINUX_GATEWAY_ADDR      0x100

#define syscall_weak(name, sym, wsym) 	\
.text!					\
.type wsym, @function!			\
.weak wsym!				\
wsym:	!				\
.type sym, @function!			\
.globl sym!				\
sym:					\
	b __unified_syscall!		\
	ldi __NR_##name, %r20!		\

#define __syscall(name, sym, imp)  	\
.text!					\
.type sym,@function!			\
.globl sym!				\
.export sym!				\
sym:					\
	b imp!				\
	ldi __NR_##name, %r20!

#define syscall(name, sym)	__syscall(name, sym, __unified_syscall)
#define syscall5(name, sym)	__syscall(name, sym, __unified_syscall5)
#define syscall6(name, sym)	__syscall(name, sym, __unified_syscall6)

dietlibc-0.33~cvs20120325/parisc/umount.S010064400000000000000000000002321173363230200146270ustar00#include "parisc/syscalls.h"

.text
.type umount,@function
.globl umount
.export umount
umount:
	ldi 0, %r25
	b __unified_syscall
	ldi __NR_umount2, %r20
dietlibc-0.33~cvs20120325/parisc/unified.S010064400000000000000000000024641173363230200147340ustar00/*
  Copyright (C) 2001, 2002 Thomas M. Ogrisegg

  This is free software. You can redistribute and
  modify it under the terms of the GNU General Public
  Public License.

  This file is part of the hppa-Port of dietlibc

  unified.S
    General system-call interface
*/

#include "dietfeatures.h"

.level 1.1

.text

.export __unified_syscall
.global __unified_syscall
.type __unified_syscall,@function

.export __unified_syscall5
.global __unified_syscall5
.type __unified_syscall5,@function

.export __unified_syscall6
.global __unified_syscall6
.type __unified_syscall6,@function

.export __error_unified_syscall
.global __error_unified_syscall


.globl _exit
.weak exit
_exit:
exit:
        ldi 1, %r20
	b __unified_syscall
	nop

__unified_syscall6:
	ldw -0x38(%sr0, %sp), %r21
__unified_syscall5:
	ldw -0x34(%sr0, %sp), %r22
__unified_syscall:
	be,l 0x100(%sr2, %r0), %sr0, %r31
	nop
	ldi -0x100, %r1
	cmpb,>>=,n %r1, %ret0, .Lnoerr
	sub %r0, %ret0, %ret0
__error_unified_syscall:
#ifdef WANT_THREAD_SAFE
	copy %r2, %r23
	bl __errno_location, %r2
	copy %ret0, %r20
	stw %r20, 0(%sr0, %ret0)
	copy %r23, %r2
#else
	ldil LP%errno, %r26
	ldo  RP%errno(%r26), %r26
	stw  %ret0, 0(%r0, %r26)
#endif
	ldi -1, %ret0
.Lnoerr:
/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	bv,n %r0(%rp)
dietlibc-0.33~cvs20120325/parselib.h010064400000000000000000000017301173363226000136540ustar00#include 

/* parse lib: parse mmapped text with \n terminated lines */

/* a memory buffer. */
struct state {
  const char* buffirst;/* pointer to the buffer */
  size_t buflen;		/* length of the buffer */
  size_t cur;			/* already parsed bytes */
};

/* open and mmap file, fill in struct state */
void __prepare_parse(const char* filename,struct state* s);
/* mmap a file already open, fill in struct state */
void __fprepare_parse(int fd, struct state* s);
/* unmap file */
void __end_parse(struct state* s);

/* return the length of the matching string, 0 on error */
/* match while pred returns nonzero */
size_t __parse(struct state* s,int (*pred)(int ch));

size_t __parse_ws(struct state* s);		/* skip ' ' or '\t', break at '\n' or '#' */
size_t __parse_nws(struct state* s);		/* skip non-whitespace, break at '\n' or '#' */
size_t __parse_1(struct state* s,char c) __attribute__((__pure__));	/* skip to c */

size_t scan_ulong(const char* s,unsigned long* l);
dietlibc-0.33~cvs20120325/ppc/Makefile.add010064400000000000000000000001471173363230200146510ustar00
CFLAGS+=-mpowerpc-gpopt -mpowerpc-gfxopt -Os
VPATH:=ppc:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/__CAS.o
dietlibc-0.33~cvs20120325/ppc/__CAS.S010064400000000000000000000002421173363230200135060ustar00.text
.global __CAS
.type __CAS, @function
__CAS:
	mr 9,3
	lwsync
1:
	lwarx 3,0,9
	cmpw 0,3,4
	bnelr- 0
	stwcx. 5,0,9
	bne- 0,1b
	isync
	blr
.size __CAS, .-__CAS
dietlibc-0.33~cvs20120325/ppc/__longjmp.S010064400000000000000000000025051173363230200145520ustar00#include 


#ifdef PIC
#define JUMPTARGET(name) name##@plt
#else
#define JUMPTARGET(name) name
#endif

.global __longjmp
.type __longjmp,@function
.align 2
__longjmp:
	lwz 1,(JB_GPR1*4)(3)
	lwz 2,(JB_GPR2*4)(3)
	lwz 0,(JB_LR*4)(3)
	lwz 14,((JB_GPRS+0)*4)(3)
	lfd 14,((JB_FPRS+0*2)*4)(3)
	lwz 15,((JB_GPRS+1)*4)(3)
	lfd 15,((JB_FPRS+1*2)*4)(3)
	lwz 16,((JB_GPRS+2)*4)(3)
	lfd 16,((JB_FPRS+2*2)*4)(3)
	lwz 17,((JB_GPRS+3)*4)(3)
	lfd 17,((JB_FPRS+3*2)*4)(3)
	lwz 18,((JB_GPRS+4)*4)(3)
	lfd 18,((JB_FPRS+4*2)*4)(3)
	lwz 19,((JB_GPRS+5)*4)(3)
	lfd 19,((JB_FPRS+5*2)*4)(3)
	lwz 20,((JB_GPRS+6)*4)(3)
	lfd 20,((JB_FPRS+6*2)*4)(3)
	mtlr 0
	lwz 21,((JB_GPRS+7)*4)(3)
	lfd 21,((JB_FPRS+7*2)*4)(3)
	lwz 22,((JB_GPRS+8)*4)(3)
	lfd 22,((JB_FPRS+8*2)*4)(3)
	lwz 0,(JB_CR*4)(3)
	lwz 23,((JB_GPRS+9)*4)(3)
	lfd 23,((JB_FPRS+9*2)*4)(3)
	lwz 24,((JB_GPRS+10)*4)(3)
	lfd 24,((JB_FPRS+10*2)*4)(3)
	lwz 25,((JB_GPRS+11)*4)(3)
	lfd 25,((JB_FPRS+11*2)*4)(3)
	mtcrf 0xFF,0
	lwz 26,((JB_GPRS+12)*4)(3)
	lfd 26,((JB_FPRS+12*2)*4)(3)
	lwz 27,((JB_GPRS+13)*4)(3)
	lfd 27,((JB_FPRS+13*2)*4)(3)
	lwz 28,((JB_GPRS+14)*4)(3)
	lfd 28,((JB_FPRS+14*2)*4)(3)
	lwz 29,((JB_GPRS+15)*4)(3)
	lfd 29,((JB_FPRS+15*2)*4)(3)
	lwz 30,((JB_GPRS+16)*4)(3)
	lfd 30,((JB_FPRS+16*2)*4)(3)
	lwz 31,((JB_GPRS+17)*4)(3)
	lfd 31,((JB_FPRS+17*2)*4)(3)
	mr 3,4
	blr
.size __longjmp,.-__longjmp

dietlibc-0.33~cvs20120325/ppc/__testandset.S010064400000000000000000000002471173363230200152630ustar00.global __testandset
.type __testandset,@function
.align 2
__testandset:
1:	lwarx	5,0,3
	li	0,1
	stwcx.	0,0,3
	bne-	1b
	mr	3,5
	blr
.size __testandset,.-__testandset

dietlibc-0.33~cvs20120325/ppc/clone.S010064400000000000000000000024171173363230200137100ustar00#include 
#include "syscalls.h"
#include 

.text
.weak clone
clone:
.global __clone
__clone:
	cmpwi	     4,0	/* check have non null child_stack pointer */
	cmpwi	cr1, 3,0	/* check have non null thread_funcion */
	cror	eq,4*cr1+eq,eq	/* now if eq is set one is or both are zero */
	beq	.Lclone_error

	stwu	 1,-32(1)	/* alloc some space on the stack */
	stmw	29, 16(1)	/* save r29,r30,r31 on stack */

	rlwinm	4,4,0,0,27	/* mask out lower 4 bits */

	/* move parameter to positions clone wants them */
	mr	29,3		/* r29 = r3 fn */
	mr	30,4		/* r30 = r4 stack */
	mr	31,6		/* r31 = r6 arg */
	mr	3, 5		/* r3  = r5 flags */

	li	0, __NR_clone	/* load syscall nr. */
	sc

	cmpwi	cr1,3,0		/* compare return of syscall with 0 */
	crandc	4*cr1+eq,4*cr1+eq,so
	bne	.Lclone_parent	/* return was non zero -> .Lclone_parent */

	/* we are the cloned process */
	mr	 1, 30		/* set stack pointer */
	mtctr	29		/* set count register to fn ? */
	mr	 3, 31		/* set argument */
	bctrl			/* branch trough count register and link */
	b	_exit		/* exit thread */

.Lclone_parent:
	lmw	29,16(1)	/* restore saved registers */
	addi	 1, 1,32	/* free stack */
	bnslr+			/* had cloned a thread so return to parent */
	b	error_unified_syscall

.Lclone_error:
	li	3, EINVAL
	b	error_unified_syscall
dietlibc-0.33~cvs20120325/ppc/mmap.c010064400000000000000000000024011173363230200135530ustar00#include "dietfeatures.h"
#include 
#include 
#include "syscalls.h"

int mmap(void*start,size_t length,int prot,int flags,int fd,off_t offset) {
  unsigned long __sc_ret, __sc_err;
  {
    register unsigned long __sc_0 __asm__ ("r0");
    register unsigned long __sc_3 __asm__ ("r3");
    register unsigned long __sc_4 __asm__ ("r4");
    register unsigned long __sc_5 __asm__ ("r5");
    register unsigned long __sc_6 __asm__ ("r6");
    register unsigned long __sc_7 __asm__ ("r7");
    register unsigned long __sc_8 __asm__ ("r8");

    __sc_3 = (unsigned long) (start);
    __sc_4 = (unsigned long) (length);
    __sc_5 = (unsigned long) (prot);
    __sc_6 = (unsigned long) (flags);
    __sc_7 = (unsigned long) (fd);
    __sc_8 = (unsigned long) (offset);
    __sc_0 = __NR_mmap;
    __asm__ __volatile__
	    ("sc           \n\t"
	      "mfcr %1      "
	    : "=&r" (__sc_3), "=&r" (__sc_0)
	    : "0"   (__sc_3), "1"   (__sc_0),
	      "r"   (__sc_4),
	      "r"   (__sc_5),
	      "r"   (__sc_6),
	      "r"   (__sc_7),
	      "r"   (__sc_8)
	    : "r4", "r5", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
    __sc_ret = __sc_3;
    __sc_err = __sc_0;
  }
  return (__sc_err & 0x10000000 ? errno = __sc_ret, __sc_ret = -1 : 0),
	  (int) __sc_ret;
}
dietlibc-0.33~cvs20120325/ppc/setjmp.S010064400000000000000000000032551173363230200141130ustar00#include 

#ifdef PIC
#define JUMPTARGET(name) name##@plt
#else
#define JUMPTARGET(name) name
#endif

.global __sigsetjmp
.type __sigsetjmp,@function
.align 2
__sigsetjmp:
        stw  1,(JB_GPR1*4)(3)
        mflr 0
        stw  2,(JB_GPR2*4)(3)
        stw  14,((JB_GPRS+0)*4)(3)
        stfd 14,((JB_FPRS+0*2)*4)(3)
        stw  0,(JB_LR*4)(3)
        stw  15,((JB_GPRS+1)*4)(3)
        stfd 15,((JB_FPRS+1*2)*4)(3)
        mfcr 0
        stw  16,((JB_GPRS+2)*4)(3)
        stfd 16,((JB_FPRS+2*2)*4)(3)
        stw  0,(JB_CR*4)(3)
        stw  17,((JB_GPRS+3)*4)(3)
        stfd 17,((JB_FPRS+3*2)*4)(3)
        stw  18,((JB_GPRS+4)*4)(3)
        stfd 18,((JB_FPRS+4*2)*4)(3)
        stw  19,((JB_GPRS+5)*4)(3)
        stfd 19,((JB_FPRS+5*2)*4)(3)
        stw  20,((JB_GPRS+6)*4)(3)
        stfd 20,((JB_FPRS+6*2)*4)(3)
        stw  21,((JB_GPRS+7)*4)(3)
        stfd 21,((JB_FPRS+7*2)*4)(3)
        stw  22,((JB_GPRS+8)*4)(3)
        stfd 22,((JB_FPRS+8*2)*4)(3)
        stw  23,((JB_GPRS+9)*4)(3)
        stfd 23,((JB_FPRS+9*2)*4)(3)
        stw  24,((JB_GPRS+10)*4)(3)
        stfd 24,((JB_FPRS+10*2)*4)(3)
        stw  25,((JB_GPRS+11)*4)(3)
        stfd 25,((JB_FPRS+11*2)*4)(3)
        stw  26,((JB_GPRS+12)*4)(3)
        stfd 26,((JB_FPRS+12*2)*4)(3)
        stw  27,((JB_GPRS+13)*4)(3)
        stfd 27,((JB_FPRS+13*2)*4)(3)
        stw  28,((JB_GPRS+14)*4)(3)
        stfd 28,((JB_FPRS+14*2)*4)(3)
        stw  29,((JB_GPRS+15)*4)(3)
        stfd 29,((JB_FPRS+15*2)*4)(3)
        stw  30,((JB_GPRS+16)*4)(3)
        stfd 30,((JB_FPRS+16*2)*4)(3)
        stw  31,((JB_GPRS+17)*4)(3)
        stfd 31,((JB_FPRS+17*2)*4)(3)
        b JUMPTARGET (__sigjmp_save)
.size __sigsetjmp,.-__sigsetjmp
dietlibc-0.33~cvs20120325/ppc/start.S010064400000000000000000000020011173363230200137320ustar00#include "dietfeatures.h"

.text
.global _start
.type _start,@function
_start:
 /* Save the stack pointer, in case we're statically linked under Linux.  */
	mr	9,1
 /* Set up an initial stack frame, and clear the LR.  */
	clrrwi	1,1,4
	li	0,0
	stwu	1,-16(1)
	mtlr	0
	stw	0,0(1)

 /* r9 contains the initial stack pointer
    argc = (r9)
    argv = (r9+4)
    envp = argv+(argc+1)*4 */

	lis	14,__libc_stack_end@ha
	stw	9,__libc_stack_end@l(14)

	lwzu	3,0(9)	/* argc */
	addi	4,9,4	/* argv */
	add	5,0,3	/* argc... */
	addi	5,5,1	/* argc+1...*/
	slwi	5,5,2	/* (argc+1)*4 */
	add	5,5,4	/* argv+(argc+1)*4 */

	lis	14,environ@ha
	stw	5,environ@l(14)

#ifdef WANT_DYNAMIC
	mr	6,7
	bl	_dyn_start
#else
	bl	CALL_IN_STARTCODE
#endif
	b	exit
.size _start,.-_start


/* Define a symbol for the first piece of initialized data.  */
	.section ".data"
__data_start:

/* this is needed for libgcc_eh.a - see gcc-3.4/gcc/config/rs6000/linux-unwind.h */
	.weak	__libc_stack_end
	.lcomm	__libc_stack_end,4,4
	.type	__libc_stack_end,@object

dietlibc-0.33~cvs20120325/ppc/syscalls.h010064400000000000000000000215501173363230200144710ustar00
#define __NR_exit		  1
#define __NR_fork		  2
#define __NR_read		  3
#define __NR_write		  4
#define __NR_open		  5
#define __NR_close		  6
#define __NR_waitpid		  7
#define __NR_creat		  8
#define __NR_link		  9
#define __NR_unlink		 10
#define __NR_execve		 11
#define __NR_chdir		 12
#define __NR_time		 13
#define __NR_mknod		 14
#define __NR_chmod		 15
#define __NR_lchown		 16
#define __NR_break		 17
#define __NR_oldstat		 18
#define __NR_lseek		 19
#define __NR_getpid		 20
#define __NR_mount		 21
#define __NR_umount		 22
#define __NR_setuid		 23
#define __NR_getuid		 24
#define __NR_stime		 25
#define __NR_ptrace		 26
#define __NR_alarm		 27
#define __NR_oldfstat		 28
#define __NR_pause		 29
#define __NR_utime		 30
#define __NR_stty		 31
#define __NR_gtty		 32
#define __NR_access		 33
#define __NR_nice		 34
#define __NR_ftime		 35
#define __NR_sync		 36
#define __NR_kill		 37
#define __NR_rename		 38
#define __NR_mkdir		 39
#define __NR_rmdir		 40
#define __NR_dup		 41
#define __NR_pipe		 42
#define __NR_times		 43
#define __NR_prof		 44
#define __NR_brk		 45
#define __NR_setgid		 46
#define __NR_getgid		 47
#define __NR_signal		 48
#define __NR_geteuid		 49
#define __NR_getegid		 50
#define __NR_acct		 51
#define __NR_umount2		 52
#define __NR_lock		 53
#define __NR_ioctl		 54
#define __NR_fcntl		 55
#define __NR_mpx		 56
#define __NR_setpgid		 57
#define __NR_ulimit		 58
#define __NR_oldolduname	 59
#define __NR_umask		 60
#define __NR_chroot		 61
#define __NR_ustat		 62
#define __NR_dup2		 63
#define __NR_getppid		 64
#define __NR_getpgrp		 65
#define __NR_setsid		 66
#define __NR_sigaction		 67
#define __NR_sgetmask		 68
#define __NR_ssetmask		 69
#define __NR_setreuid		 70
#define __NR_setregid		 71
#define __NR_sigsuspend		 72
#define __NR_sigpending		 73
#define __NR_sethostname	 74
#define __NR_setrlimit		 75
#define __NR_getrlimit		 76
#define __NR_getrusage		 77
#define __NR_gettimeofday	 78
#define __NR_settimeofday	 79
#define __NR_getgroups		 80
#define __NR_setgroups		 81
#define __NR_select		 82
#define __NR_symlink		 83
#define __NR_oldlstat		 84
#define __NR_readlink		 85
#define __NR_uselib		 86
#define __NR_swapon		 87
#define __NR_reboot		 88
#define __NR_readdir		 89
#define __NR_mmap		 90
#define __NR_munmap		 91
#define __NR_truncate		 92
#define __NR_ftruncate		 93
#define __NR_fchmod		 94
#define __NR_fchown		 95
#define __NR_getpriority	 96
#define __NR_setpriority	 97
#define __NR_profil		 98
#define __NR_statfs		 99
#define __NR_fstatfs		100
#define __NR_ioperm		101
#define __NR_socketcall		102
#define __NR_syslog		103
#define __NR_setitimer		104
#define __NR_getitimer		105
#define __NR_stat		106
#define __NR_lstat		107
#define __NR_fstat		108
#define __NR_olduname		109
#define __NR_iopl		110
#define __NR_vhangup		111
#define __NR_idle		112
#define __NR_vm86		113
#define __NR_wait4		114
#define __NR_swapoff		115
#define __NR_sysinfo		116
#define __NR_ipc		117
#define __NR_fsync		118
#define __NR_sigreturn		119
#define __NR_clone		120
#define __NR_setdomainname	121
#define __NR_uname		122
#define __NR_modify_ldt		123
#define __NR_adjtimex		124
#define __NR_mprotect		125
#define __NR_sigprocmask	126
#define __NR_create_module	127
#define __NR_init_module	128
#define __NR_delete_module	129
#define __NR_get_kernel_syms	130
#define __NR_quotactl		131
#define __NR_getpgid		132
#define __NR_fchdir		133
#define __NR_bdflush		134
#define __NR_sysfs		135
#define __NR_personality	136
#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
#define __NR_setfsuid		138
#define __NR_setfsgid		139
#define __NR__llseek		140
#define __NR_getdents		141
#define __NR__newselect		142
#define __NR_flock		143
#define __NR_msync		144
#define __NR_readv		145
#define __NR_writev		146
#define __NR_getsid		147
#define __NR_fdatasync		148
#define __NR__sysctl		149
#define __NR_mlock		150
#define __NR_munlock		151
#define __NR_mlockall		152
#define __NR_munlockall		153
#define __NR_sched_setparam		154
#define __NR_sched_getparam		155
#define __NR_sched_setscheduler		156
#define __NR_sched_getscheduler		157
#define __NR_sched_yield		158
#define __NR_sched_get_priority_max	159
#define __NR_sched_get_priority_min	160
#define __NR_sched_rr_get_interval	161
#define __NR_nanosleep		162
#define __NR_mremap		163
#define __NR_setresuid		164
#define __NR_getresuid		165
#define __NR_query_module	166
#define __NR_poll		167
#define __NR_nfsservctl		168
#define __NR_setresgid		169
#define __NR_getresgid		170
#define __NR_prctl		171
#define __NR_rt_sigreturn	172
#define __NR_rt_sigaction	173
#define __NR_rt_sigprocmask	174
#define __NR_rt_sigpending	175
#define __NR_rt_sigtimedwait	176
#define __NR_rt_sigqueueinfo	177
#define __NR_rt_sigsuspend	178
#define __NR_pread		179
#define __NR_pwrite		180
#define __NR_chown		181
#define __NR_getcwd		182
#define __NR_capget		183
#define __NR_capset		184
#define __NR_sigaltstack	185
#define __NR_sendfile		186
#define __NR_getpmsg		187	/* some people actually want streams */
#define __NR_putpmsg		188	/* some people actually want streams */
#define __NR_vfork		189
#define __NR_ugetrlimit		190	/* SuS compliant getrlimit */
#define __NR_readahead		191
#define __NR_mmap2		192
#define __NR_truncate64		193
#define __NR_ftruncate64	194
#define __NR_stat64		195
#define __NR_lstat64		196
#define __NR_fstat64		197
#define __NR_pciconfig_read	198
#define __NR_pciconfig_write	199
#define __NR_pciconfig_iobase	200
#define __NR_multiplexer	201
#define __NR_getdents64		202
#define __NR_pivot_root		203
#define __NR_fcntl64		204
#define __NR_madvise		205
#define __NR_mincore		206
#define __NR_gettid		207
#define __NR_tkill		208
#define __NR_setxattr		209
#define __NR_lsetxattr		210
#define __NR_fsetxattr		211
#define __NR_getxattr		212
#define __NR_lgetxattr		213
#define __NR_fgetxattr		214
#define __NR_listxattr		215
#define __NR_llistxattr		216
#define __NR_flistxattr		217
#define __NR_removexattr	218
#define __NR_lremovexattr	219
#define __NR_fremovexattr	220
#define __NR_futex		221
#define __NR_sched_setaffinity	222
#define __NR_sched_getaffinity	223
/* 224 currently unused */
#define __NR_tuxcall		225
#define __NR_sendfile64		226
#define __NR_io_setup		227
#define __NR_io_destroy		228
#define __NR_io_getevents	229
#define __NR_io_submit		230
#define __NR_io_cancel		231
#define __NR_set_tid_address	232
#define __NR_fadvise64		233
#define __NR_exit_group		234
#define __NR_lookup_dcookie	235
#define __NR_epoll_create	236
#define __NR_epoll_ctl		237
#define __NR_epoll_wait		238
#define __NR_remap_file_pages	239
#define __NR_timer_create	240
#define __NR_timer_settime	241
#define __NR_timer_gettime	242
#define __NR_timer_getoverrun	243
#define __NR_timer_delete	244
#define __NR_clock_settime	245
#define __NR_clock_gettime	246
#define __NR_clock_getres	247
#define __NR_clock_nanosleep	248
#define __NR_swapcontext	249
#define __NR_tgkill		250
#define __NR_utimes		251
#define __NR_statfs64		252
#define __NR_fstatfs64		253
#define __NR_fadvise64_64	254
#define __NR_rtas		255
#define __NR_sys_debug_setcontext 256
/* Number 257 is reserved for vserver */
/* Number 258 is reserved for new sys_remap_file_pages */
/* Number 259 is reserved for new sys_mbind */
/* Number 260 is reserved for new sys_get_mempolicy */
/* Number 261 is reserved for new sys_set_mempolicy */
#define __NR_mq_open		262
#define __NR_mq_unlink		263
#define __NR_mq_timedsend	264
#define __NR_mq_timedreceive	265
#define __NR_mq_notify		266
#define __NR_mq_getsetattr	267
#define __NR_kexec_load		268
#define __NR_add_key		269
#define __NR_request_key	270
#define __NR_keyctl		271
#define __NR_waitid		272
#define __NR_ioprio_set		273
#define __NR_ioprio_get		274
#define __NR_inotify_init	275
#define __NR_inotify_add_watch	276
#define __NR_inotify_rm_watch	277
#define __NR_spu_run		278
#define __NR_spu_create		279
#define __NR_pselect6		280
#define __NR_ppoll		281
#define __NR_unshare		282
#define __NR_splice		283
#define __NR_tee		284
#define __NR_vmsplice		285
#define __NR_openat		286
#define __NR_mkdirat		287
#define __NR_mknodat		288
#define __NR_fchownat		289
#define __NR_futimesat		290
#define __NR_fstatat64		291
#define __NR_unlinkat		292
#define __NR_renameat		293
#define __NR_linkat		294
#define __NR_symlinkat		295
#define __NR_readlinkat		296
#define __NR_fchmodat		297
#define __NR_faccessat		298
#define __NR_get_robust_list	299
#define __NR_set_robust_list	300
#define __NR_move_pages		301
#define __NR_getcpu		302
#define __NR_epoll_pwait	303
#define __NR_utimensat		304
#define __NR_signalfd		305
#define __NR_timerfd		306
#define __NR_eventfd		307
#define __NR_sync_file_range2	308
#define __NR_fallocate		309
#define __NR_subpage_prot	310
#define __NR_timerfd_settime	311
#define __NR_timerfd_gettime	312


#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,@function; \
.weak wsym; \
wsym: ; \
.type sym,@function; \
.global sym; \
sym: \
	li	0,__NR_##name; \
	b __unified_syscall

#define syscall(name,sym) \
.text; \
.type sym,@function; \
.global sym; \
sym: \
	li	0,__NR_##name; \
	b __unified_syscall

dietlibc-0.33~cvs20120325/ppc/unified.S010064400000000000000000000010731173363230200142300ustar00#include 
#include "syscalls.h"

.text
.type exit,@function
.weak exit
exit:
.type _exit,@function
.global _exit
_exit:
	li	0,__NR_exit
.global __unified_syscall
__unified_syscall:
	sc
	bnslr+

.global error_unified_syscall
error_unified_syscall:
#ifdef WANT_THREAD_SAFE
	stwu	1,-16(1)
	mflr	0
	stw	0,20(1)
	stw	3,12(1)
	bl	__errno_location
	lwz	0,12(1)
	stw	0,0(3)
	lwz	0,20(1)
	mtlr	0
	addi	1,1,16
#else
	lis	9,errno@ha
	stw	3,errno@l(9)
#endif
	li	3,-1

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	blr

dietlibc-0.33~cvs20120325/ppc64/Makefile.add010064400000000000000000000001361173363230200150210ustar00
CFLAGS+=-Os -mpowerpc64
VPATH:=ppc64:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/__CAS.o

CC+=-m64
dietlibc-0.33~cvs20120325/ppc64/__CAS.S010064400000000000000000000002421173363230200136600ustar00.text
.global __CAS
.type __CAS, @function
__CAS:
	mr 9,3
	lwsync
1:
	ldarx 3,0,9
	cmpd 0,3,4
	bnelr- 0
	stdcx. 5,0,9
	bne- 0,1b
	isync
	blr
.size __CAS, .-__CAS
dietlibc-0.33~cvs20120325/ppc64/__longjmp.S010064400000000000000000000025111173363230200147210ustar00#include 

	.globl __longjmp
	.section	".opd","aw"
	.align 3
__longjmp:
		.quad	.__longjmp,.TOC.@tocbase,0
		.text
		.size	__longjmp,24
		.type	.__longjmp,@function
		.globl	.__longjmp
.align 2
.__longjmp:
	ld  1,(JB_GPR1*8)(3)
	ld  2,(JB_GPR2*8)(3)
	ld  0,(JB_LR*8)(3)
	ld  14,((JB_GPRS+0)*8)(3)
	lfd 14,((JB_FPRS+0)*8)(3)
	ld  15,((JB_GPRS+1)*8)(3)
	lfd 15,((JB_FPRS+1)*8)(3)
	ld  16,((JB_GPRS+2)*8)(3)
	lfd 16,((JB_FPRS+2)*8)(3)
	ld  17,((JB_GPRS+3)*8)(3)
	lfd 17,((JB_FPRS+3)*8)(3)
	ld  18,((JB_GPRS+4)*8)(3)
	lfd 18,((JB_FPRS+4)*8)(3)
	ld  19,((JB_GPRS+5)*8)(3)
	lfd 19,((JB_FPRS+5)*8)(3)
	ld  20,((JB_GPRS+6)*8)(3)
	lfd 20,((JB_FPRS+6)*8)(3)
	mtlr 0
	ld  21,((JB_GPRS+7)*8)(3)
	lfd 21,((JB_FPRS+7)*8)(3)
	ld  22,((JB_GPRS+8)*8)(3)
	lfd 22,((JB_FPRS+8)*8)(3)
	ld  0,(JB_CR*8)(3)
	ld  23,((JB_GPRS+9)*8)(3)
	lfd 23,((JB_FPRS+9)*8)(3)
	ld  24,((JB_GPRS+10)*8)(3)
	lfd 24,((JB_FPRS+10)*8)(3)
	ld  25,((JB_GPRS+11)*8)(3)
	lfd 25,((JB_FPRS+11)*8)(3)
	mtcrf 0xFF,0
	ld  26,((JB_GPRS+12)*8)(3)
	lfd 26,((JB_FPRS+12)*8)(3)
	ld  27,((JB_GPRS+13)*8)(3)
	lfd 27,((JB_FPRS+13)*8)(3)
	ld  28,((JB_GPRS+14)*8)(3)
	lfd 28,((JB_FPRS+14)*8)(3)
	ld  29,((JB_GPRS+15)*8)(3)
	lfd 29,((JB_FPRS+15)*8)(3)
	ld  30,((JB_GPRS+16)*8)(3)
	lfd 30,((JB_FPRS+16)*8)(3)
	ld  31,((JB_GPRS+17)*8)(3)
	lfd 31,((JB_FPRS+17)*8)(3)
	mr 3,4
	blr
.size .__longjmp,.-.__longjmp
dietlibc-0.33~cvs20120325/ppc64/__testandset.S010064400000000000000000000002471173363230200154350ustar00.global __testandset
.type __testandset,@function
.align 2
__testandset:
1:	lwarx	5,0,3
	li	0,1
	stwcx.	0,0,3
	bne-	1b
	mr	3,5
	blr
.size __testandset,.-__testandset

dietlibc-0.33~cvs20120325/ppc64/clone.S010064400000000000000000000025051173363230200140600ustar00#include 
#include "syscalls.h"
#include 

.text
.weak clone
clone:
.global __clone
__clone:
	cmpwi	     4,0	/* check have non null child_stack pointer */
	cmpwi	cr1, 3,0	/* check have non null thread_funcion */
	cror	eq,4*cr1+eq,eq	/* now if eq is set one is or both are zero */
	beq	.Lclone_error

	stdu	 1,-64(1)	/* alloc some space on the stack */
	std	29, 16(1)	/* save r29,r30,r31 on stack */
	std	30, 24(1)
	std	31, 32(1)

	rlwinm	4,4,0,0,27	/* mask out lower 4 bits */

	/* move parameter to positions clone wants them */
	mr	29,3		/* r29 = r3 fn */
	mr	30,4		/* r30 = r4 stack */
	mr	31,6		/* r31 = r6 arg */
	mr	3, 5		/* r3  = r5 flags */

	li	0, __NR_clone	/* load syscall nr. */
	sc

	cmpwi	cr1,3,0		/* compare return of syscall with 0 */
	crandc	4*cr1+eq,4*cr1+eq,so
	bne	.Lclone_parent	/* return was non zero -> .Lclone_parent */

	/* we are the cloned process */
	mr	 1, 30		/* set stack pointer */
	mtctr	29		/* set count register to fn ? */
	mr	 3, 31		/* set argument */
	bctrl			/* branch trough count register and link */
	b	_exit		/* exit thread */

.Lclone_parent:
	ld	29,16(1)	/* restore saved registers */
	ld	30,24(1)
	ld	31,32(1)
	addi	 1, 1,64	/* free stack */
	bnslr+			/* had cloned a thread so return to parent */
	b	error_unified_syscall

.Lclone_error:
	li	3, EINVAL
	b	error_unified_syscall
dietlibc-0.33~cvs20120325/ppc64/setjmp.S010064400000000000000000000034301173363230200142600ustar00#include 

#ifdef PIC
#define JUMPTARGET(name) name##@plt
#else
#define JUMPTARGET(name) .name
#endif


	.globl __sigsetjmp
	.section	".opd","aw"
	.align 3
__sigsetjmp:
		.quad	.__sigsetjmp,.TOC.@tocbase,0
		.text
		.size	__sigsetjmp,24
		.type	.__sigsetjmp,@function
		.globl	.__sigsetjmp
.align 2
.__sigsetjmp:
        std  1,(JB_GPR1*8)(3)
        mflr 0
        std  2,(JB_GPR2*8)(3)
        std  14,((JB_GPRS+0)*8)(3)
        stfd 14,((JB_FPRS+0)*8)(3)
        std  0,(JB_LR*8)(3)
        std  15,((JB_GPRS+1)*8)(3)
        stfd 15,((JB_FPRS+1)*8)(3)
        mfcr 0
        std  16,((JB_GPRS+2)*8)(3)
        stfd 16,((JB_FPRS+2)*8)(3)
        std  0,(JB_CR*8)(3)
        std  17,((JB_GPRS+3)*8)(3)
        stfd 17,((JB_FPRS+3)*8)(3)
        std  18,((JB_GPRS+4)*8)(3)
        stfd 18,((JB_FPRS+4)*8)(3)
        std  19,((JB_GPRS+5)*8)(3)
        stfd 19,((JB_FPRS+5)*8)(3)
        std  20,((JB_GPRS+6)*8)(3)
        stfd 20,((JB_FPRS+6)*8)(3)
        std  21,((JB_GPRS+7)*8)(3)
        stfd 21,((JB_FPRS+7)*8)(3)
        std  22,((JB_GPRS+8)*8)(3)
        stfd 22,((JB_FPRS+8)*8)(3)
        std  23,((JB_GPRS+9)*8)(3)
        stfd 23,((JB_FPRS+9)*8)(3)
        std  24,((JB_GPRS+10)*8)(3)
        stfd 24,((JB_FPRS+10)*8)(3)
        std  25,((JB_GPRS+11)*8)(3)
        stfd 25,((JB_FPRS+11)*8)(3)
        std  26,((JB_GPRS+12)*8)(3)
        stfd 26,((JB_FPRS+12)*8)(3)
        std  27,((JB_GPRS+13)*8)(3)
        stfd 27,((JB_FPRS+13)*8)(3)
        std  28,((JB_GPRS+14)*8)(3)
        stfd 28,((JB_FPRS+14)*8)(3)
        std  29,((JB_GPRS+15)*8)(3)
        stfd 29,((JB_FPRS+15)*8)(3)
        std  30,((JB_GPRS+16)*8)(3)
        stfd 30,((JB_FPRS+16)*8)(3)
        std  31,((JB_GPRS+17)*8)(3)
        stfd 31,((JB_FPRS+17)*8)(3)
        b JUMPTARGET (__sigjmp_save)
.size .__sigsetjmp,.-.__sigsetjmp
dietlibc-0.33~cvs20120325/ppc64/start.S010064400000000000000000000034211173363230200141130ustar00#include "dietfeatures.h"

	.section ".text"
	.align	2
	.globl	._start
	.type	._start,@function
	.globl	_start
	.section ".opd","aw"
_start:
	.quad	._start
	.quad	.TOC.@tocbase, 0
	.previous
._start:

/*
	.section ".text"
	.align	2
	.globl	._start
	.type	._start,@function
	.globl	_start
	.section ".opd","aw"
_start:
	.quad	._start
	.quad	.TOC.@tocbase, 0
	.previous
._start:
*/
 /* Save the stack pointer, in case we're statically linked under Linux.  */
	mr	9,1
 /* Set up an initial stack frame, and clear the LR.  */
	clrrdi	1,1,4
	li	0,0
	stdu	1,-128(1)
	mtlr	0
	std	0,0(1)

 /* r9 contains the initial stack pointer
    argc = (r9)
    argv = (r9+4)
    envp = argv+(argc+1)*4 */

	lis	14,__libc_stack_end@highesta
	ori	14,14,__libc_stack_end@highera
	sldi    14,14,32
	oris	14,14,__libc_stack_end@ha
	std	9,__libc_stack_end@l(14)

	ldu	3,0(9)	/* argc */
	addi	4,9,8	/* argv */
	add	5,0,3	/* argc... */
	addi	5,5,1	/* argc+1...*/
	slwi	5,5,3	/* (argc+1)*8 */
	add	5,5,4	/* argv+(argc+1)*8 */

	lis	14,environ@highesta
	ori	14,14,environ@highera
	sldi    14,14,32
	oris	14,14,environ@ha
	std	5,environ@l(14)

#ifdef WANT_DYNAMIC
/* #warning dynamic */
	mr	6,7
	bl	._dyn_start
#else
/* #warning static */
#define DOTIFY(name) .##name
	bl	DOTIFY(CALL_IN_STARTCODE)
#endif
	b	.exit

.LT_start:
	.long	0
	.quad	0x000c000000000000 | 0x0000200000000000 | 0x0000004000000000
	.long	.LT_start-._start
	.short	.LT_start_name_end-.LT_start_name_start
.LT_start_name_start:
	.ascii "_start"
.LT_start_name_end:
	.align 2
	.size ._start,.-._start

/* Define a symbol for the first piece of initialized data.  */
	.section ".data"
__data_start:

/* this is needed for libgcc_eh.a - see gcc-3.4/gcc/config/rs6000/linux-unwind.h */
	.weak	__libc_stack_end
	.lcomm	__libc_stack_end,8,8
	.type	__libc_stack_end,@object

dietlibc-0.33~cvs20120325/ppc64/syscalls.h010064400000000000000000000223501173363230200146420ustar00
#define __NR_exit		  1
#define __NR_fork		  2
#define __NR_read		  3
#define __NR_write		  4
#define __NR_open		  5
#define __NR_close		  6
#define __NR_waitpid		  7
#define __NR_creat		  8
#define __NR_link		  9
#define __NR_unlink		 10
#define __NR_execve		 11
#define __NR_chdir		 12
#define __NR_time		 13
#define __NR_mknod		 14
#define __NR_chmod		 15
#define __NR_lchown		 16
#define __NR_break		 17
#define __NR_oldstat		 18
#define __NR_lseek		 19
#define __NR_getpid		 20
#define __NR_mount		 21
#define __NR_umount		 22
#define __NR_setuid		 23
#define __NR_getuid		 24
#define __NR_stime		 25
#define __NR_ptrace		 26
#define __NR_alarm		 27
#define __NR_oldfstat		 28
#define __NR_pause		 29
#define __NR_utime		 30
#define __NR_stty		 31
#define __NR_gtty		 32
#define __NR_access		 33
#define __NR_nice		 34
#define __NR_ftime		 35
#define __NR_sync		 36
#define __NR_kill		 37
#define __NR_rename		 38
#define __NR_mkdir		 39
#define __NR_rmdir		 40
#define __NR_dup		 41
#define __NR_pipe		 42
#define __NR_times		 43
#define __NR_prof		 44
#define __NR_brk		 45
#define __NR_setgid		 46
#define __NR_getgid		 47
#define __NR_signal		 48
#define __NR_geteuid		 49
#define __NR_getegid		 50
#define __NR_acct		 51
#define __NR_umount2		 52
#define __NR_lock		 53
#define __NR_ioctl		 54
#define __NR_fcntl		 55
#define __NR_mpx		 56
#define __NR_setpgid		 57
#define __NR_ulimit		 58
#define __NR_oldolduname	 59
#define __NR_umask		 60
#define __NR_chroot		 61
#define __NR_ustat		 62
#define __NR_dup2		 63
#define __NR_getppid		 64
#define __NR_getpgrp		 65
#define __NR_setsid		 66
#define __NR_sigaction		 67
#define __NR_sgetmask		 68
#define __NR_ssetmask		 69
#define __NR_setreuid		 70
#define __NR_setregid		 71
#define __NR_sigsuspend		 72
#define __NR_sigpending		 73
#define __NR_sethostname	 74
#define __NR_setrlimit		 75
#define __NR_getrlimit		 76
#define __NR_getrusage		 77
#define __NR_gettimeofday	 78
#define __NR_settimeofday	 79
#define __NR_getgroups		 80
#define __NR_setgroups		 81
#define __NR_select		 82
#define __NR_symlink		 83
#define __NR_oldlstat		 84
#define __NR_readlink		 85
#define __NR_uselib		 86
#define __NR_swapon		 87
#define __NR_reboot		 88
#define __NR_readdir		 89
#define __NR_mmap		 90
#define __NR_munmap		 91
#define __NR_truncate		 92
#define __NR_ftruncate		 93
#define __NR_fchmod		 94
#define __NR_fchown		 95
#define __NR_getpriority	 96
#define __NR_setpriority	 97
#define __NR_profil		 98
#define __NR_statfs		 99
#define __NR_fstatfs		100
#define __NR_ioperm		101
#define __NR_socketcall		102
#define __NR_syslog		103
#define __NR_setitimer		104
#define __NR_getitimer		105
#define __NR_stat		106
#define __NR_lstat		107
#define __NR_fstat		108
#define __NR_olduname		109
#define __NR_iopl		110
#define __NR_vhangup		111
#define __NR_idle		112
#define __NR_vm86		113
#define __NR_wait4		114
#define __NR_swapoff		115
#define __NR_sysinfo		116
#define __NR_ipc		117
#define __NR_fsync		118
#define __NR_sigreturn		119
#define __NR_clone		120
#define __NR_setdomainname	121
#define __NR_uname		122
#define __NR_modify_ldt		123
#define __NR_adjtimex		124
#define __NR_mprotect		125
#define __NR_sigprocmask	126
#define __NR_create_module	127
#define __NR_init_module	128
#define __NR_delete_module	129
#define __NR_get_kernel_syms	130
#define __NR_quotactl		131
#define __NR_getpgid		132
#define __NR_fchdir		133
#define __NR_bdflush		134
#define __NR_sysfs		135
#define __NR_personality	136
#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
#define __NR_setfsuid		138
#define __NR_setfsgid		139
#define __NR__llseek		140
#define __NR_getdents		141
#define __NR__newselect		142
#define __NR_flock		143
#define __NR_msync		144
#define __NR_readv		145
#define __NR_writev		146
#define __NR_getsid		147
#define __NR_fdatasync		148
#define __NR__sysctl		149
#define __NR_mlock		150
#define __NR_munlock		151
#define __NR_mlockall		152
#define __NR_munlockall		153
#define __NR_sched_setparam		154
#define __NR_sched_getparam		155
#define __NR_sched_setscheduler		156
#define __NR_sched_getscheduler		157
#define __NR_sched_yield		158
#define __NR_sched_get_priority_max	159
#define __NR_sched_get_priority_min	160
#define __NR_sched_rr_get_interval	161
#define __NR_nanosleep		162
#define __NR_mremap		163
#define __NR_setresuid		164
#define __NR_getresuid		165
#define __NR_query_module	166
#define __NR_poll		167
#define __NR_nfsservctl		168
#define __NR_setresgid		169
#define __NR_getresgid		170
#define __NR_prctl		171
#define __NR_rt_sigreturn	172
#define __NR_rt_sigaction	173
#define __NR_rt_sigprocmask	174
#define __NR_rt_sigpending	175
#define __NR_rt_sigtimedwait	176
#define __NR_rt_sigqueueinfo	177
#define __NR_rt_sigsuspend	178
#define __NR_pread		179
#define __NR_pwrite		180
#define __NR_chown		181
#define __NR_getcwd		182
#define __NR_capget		183
#define __NR_capset		184
#define __NR_sigaltstack	185
#define __NR_sendfile		186
#define __NR_getpmsg		187	/* some people actually want streams */
#define __NR_putpmsg		188	/* some people actually want streams */
#define __NR_vfork		189
#define __NR_ugetrlimit		190	/* SuS compliant getrlimit */
#define __NR_readahead		191
/* #define __NR_mmap2		192	32bit only */
/* #define __NR_truncate64	193	32bit only */
/* #define __NR_ftruncate64	194	32bit only */
/* #define __NR_stat64		195	32bit only */
/* #define __NR_lstat64		196	32bit only */
/* #define __NR_fstat64		197	32bit only */
#define __NR_pciconfig_read	198
#define __NR_pciconfig_write	199
#define __NR_pciconfig_iobase	200
#define __NR_multiplexer	201
#define __NR_getdents64		202
#define __NR_pivot_root		203
/* #define __NR_fcntl64		204	32bit only */
#define __NR_madvise		205
#define __NR_mincore		206
#define __NR_gettid		207
#define __NR_tkill		208
#define __NR_setxattr		209
#define __NR_lsetxattr		210
#define __NR_fsetxattr		211
#define __NR_getxattr		212
#define __NR_lgetxattr		213
#define __NR_fgetxattr		214
#define __NR_listxattr		215
#define __NR_llistxattr		216
#define __NR_flistxattr		217
#define __NR_removexattr	218
#define __NR_lremovexattr	219
#define __NR_fremovexattr	220
#define __NR_futex		221
#define __NR_sched_setaffinity	222
#define __NR_sched_getaffinity	223
/* 224 currently unused */
#define __NR_tuxcall		225
/* #define __NR_sendfile64	226	32bit only */
#define __NR_io_setup		227
#define __NR_io_destroy		228
#define __NR_io_getevents	229
#define __NR_io_submit		230
#define __NR_io_cancel		231
#define __NR_set_tid_address	232
#define __NR_fadvise64		233
#define __NR_exit_group		234
#define __NR_lookup_dcookie	235
#define __NR_epoll_create	236
#define __NR_epoll_ctl		237
#define __NR_epoll_wait		238
#define __NR_remap_file_pages	239
#define __NR_timer_create	240
#define __NR_timer_settime	241
#define __NR_timer_gettime	242
#define __NR_timer_getoverrun	243
#define __NR_timer_delete	244
#define __NR_clock_settime	245
#define __NR_clock_gettime	246
#define __NR_clock_getres	247
#define __NR_clock_nanosleep	248
#define __NR_swapcontext	249
#define __NR_tgkill		250
#define __NR_utimes		251
#define __NR_statfs64		252
#define __NR_fstatfs64		253
/* #define __NR_fadvise64_64	254	32bit only */
#define __NR_rtas		255
/* Number 256 is reserved for sys_debug_setcontext */
/* Number 257 is reserved for vserver */
/* Number 258 is reserved for new sys_remap_file_pages */
#define __NR_mbind		259
#define __NR_get_mempolicy	260
#define __NR_set_mempolicy	261
#define __NR_mq_open		262
#define __NR_mq_unlink		263
#define __NR_mq_timedsend	264
#define __NR_mq_timedreceive	265
#define __NR_mq_notify		266
#define __NR_mq_getsetattr	267
#define __NR_kexec_load		268
#define __NR_add_key		269
#define __NR_request_key	270
#define __NR_keyctl		271
#define __NR_waitid		272
#define __NR_ioprio_set		273
#define __NR_ioprio_get		274
#define __NR_inotify_init	275
#define __NR_inotify_add_watch	276
#define __NR_inotify_rm_watch	277
#define __NR_spu_run		278
#define __NR_spu_create		279
#define __NR_pselect6		280
#define __NR_ppoll		281
#define __NR_unshare		282
#define __NR_splice		283
#define __NR_tee		284
#define __NR_vmsplice		285
#define __NR_openat		286
#define __NR_mkdirat		287
#define __NR_mknodat		288
#define __NR_fchownat		289
#define __NR_futimesat		290
#define __NR_newfstatat		291
#define __NR_unlinkat		292
#define __NR_renameat		293
#define __NR_linkat		294
#define __NR_symlinkat		295
#define __NR_readlinkat		296
#define __NR_fchmodat		297
#define __NR_faccessat		298
#define __NR_get_robust_list	299
#define __NR_set_robust_list	300
#define __NR_move_pages		301
#define __NR_getcpu		302
#define __NR_epoll_pwait	303
#define __NR_utimensat		304
#define __NR_signalfd		305
#define __NR_timerfd		306
#define __NR_eventfd		307
#define __NR_sync_file_range2	308
#define __NR_fallocate		309
#define __NR_subpage_prot	310
#define __NR_timerfd_settime	311
#define __NR_timerfd_gettime	312


#define __diet_proto_common(sym) \
	.section ".opd","aw"; \
	.align	3; \
sym: \
	.quad	.sym,.TOC.@tocbase,0; \
	.previous; \
	.size	sym,24; \
	.type	.sym,@function

#define diet_proto_weak(sym) \
	.weak	sym; \
	.weak	.sym; \
	__diet_proto_common(sym)

#define diet_proto(sym) \
	.globl	sym; \
	.globl	.sym; \
	__diet_proto_common(sym)


#define syscall_weak(name,wsym,sym) \
.text; \
diet_proto_weak(wsym); \
diet_proto(sym); \
.wsym: \
.sym: \
	li	0,__NR_##name; \
	b	__unified_syscall

#define syscall(name,sym) \
.text; \
diet_proto(sym); \
.sym: \
	li	0,__NR_##name; \
	b	__unified_syscall

dietlibc-0.33~cvs20120325/ppc64/umount.S010064400000000000000000000001601173363230200143020ustar00#include "syscalls.h"

		.text
diet_proto(umount)
.umount:
		li 0, __NR_umount2
		li 4, 0
		b __unified_syscall
dietlibc-0.33~cvs20120325/ppc64/unified.S010064400000000000000000000025101173363230200143770ustar00#include 
#include "syscalls.h"

	.text
.exit:
	.weak	.exit
._exit:
	li	0,__NR_exit
	.global __unified_syscall
__unified_syscall:
	sc
	bnslr+

	.global error_unified_syscall
error_unified_syscall:

#ifdef WANT_THREAD_SAFE
	stdu	1,-128(1)
	mflr	0
	std	0,20(1)
	std	3,12(1)
	bl	.__errno_location
	ld	0,12(1)
	stw	0,0(3)
	ld	0,20(1)
	mtlr	0
	addi	1,1,128
#else
	lis	9,errno@highesta
	ori	9,9,errno@highera
	sldi    9,9,32
	oris	9,9,errno@ha
	stw	3,errno@l(9)
#endif
	li	3,-1

/* here we go and "reuse" the return for weak-void functions */
//#include "dietuglyweaks.h"
.__thread_doexit:
	.weak	.__thread_doexit
.__fflush_stdin:
	.weak	.__fflush_stdin
.__fflush_stdout:
	.weak	.__fflush_stdout
.__fflush_stderr:
	.weak	.__fflush_stderr
.flockfile:
	.weak	.flockfile
.funlockfile:
	.weak	.funlockfile
.__nop:
	.weak	.__nop
.__you_tried_to_link_a_dietlibc_object_against_glibc:
	.weak	.__you_tried_to_link_a_dietlibc_object_against_glibc

	blr
	.long 0
	.byte 0,0,0,1,128,0,0,0
	.size	._exit,.-._exit
	.size	.exit,.-.exit

diet_proto_weak(__thread_doexit)
diet_proto_weak(__fflush_stdin)
diet_proto_weak(__fflush_stdout)
diet_proto_weak(__fflush_stderr)
diet_proto_weak(flockfile)
diet_proto_weak(funlockfile)
diet_proto_weak(__nop)
diet_proto_weak(__you_tried_to_link_a_dietlibc_object_against_glibc)
diet_proto_weak(exit)
diet_proto(_exit)
dietlibc-0.33~cvs20120325/profiling/PORTING010064400000000000000000000017021173363230200147340ustar00              Porting to other platforms

	... is easy. Just create an mcount.S in the $ARCH
    directory  (eg. dietlibc/i386)  which  includes a
    function (called "mcount") that:

     1.) saves ALL registers that are freely usable
         and which might be used by __mcount().
     2.) loads the instruction pointer (PC) from the
         function that called mcount, and the function
         which called the function, that called mcount
         into the first two argument registers (or push
         them on the stack - depending on the processor-
         architecture).
     3.) call __mcount.
     4.) restore the registers saved in 1)

    Then You need a macro called PC in 
    which extracts the (instruction pointer / program 
    counter) from a sigcontext structure (eg. on i386 this 
    would be ctx.eip).

    $ARCH/start.S must also be modified to call monitor
    with the offset of .text and _etext as parameters.

dietlibc-0.33~cvs20120325/profiling/README010064400000000000000000000032501173363230200145470ustar00
        Notes on profiling support for dietlibc

 1.) A big  problem when doing profiling on statically linked 
     programs, is that the internal profiling functions (mcount 
     and friends) will be included  in the call graph although 
     they would not if the program would have been dynamically 
     linked.  This is  because every  symbol between .text and 
     _etext  is included  in the call-graph.  If a  program is 
     dynamically linked, then mcount and friends are not between 
     .text and _etext, so they are not included. A  workaround 
     for this, would be to put mcount,  __mcount,  monitor and 
     profiler into another section (eg. ".profile"),  but this 
     creates some strange problems, I'm currently not aware of. 
     If you want to debug this: Putting a function into a specific 
     section works like this (with gcc):

     void foo (int bar) __attribute__ ((section(".foobar")))

 2.) _start may randomly be found in the callgraph.  I don't 
     know why. May be a bug in gprof.

 3.) The profiling is a  complete rewrite,  though I looked at 
     the glibc Version for  inspiration. Please note that this
     version might not be as portable as the glibc version but
     its much smaller (although this is not a really important
     argument, as  profiled binaries seldom  get shipped) and
     hopefully easier to understand.

 4.) all objects that should be profiled mustn't be compiled
     with -fomit-frame-pointer (as with glibc). Add
     -fno-fomit-frame-pointer to $CFLAGS if you're encountering 
     weird problems.

 5.) There is currently no basic-block statistic support.

Please send comments and bug reports to: tom@rhadamanthys.org
dietlibc-0.33~cvs20120325/profiling/__mcount.c010064400000000000000000000012031173363230200156320ustar00#include 
#include 

extern struct monparam mparam;

void __mcount (unsigned long, unsigned long) PROF_SECTION;

void
__mcount (unsigned long frompc, unsigned long selfpc)
{
	struct rawarc *arc = mparam.arcs, thisarc;
	unsigned long num;
	/* If arc already exists, increment count */
	for (num = 0; num < mparam.arcnum; num++)
		if (arc[num].raw_frompc == frompc && arc[num].raw_selfpc == selfpc) {
			arc[num].raw_count++;
			return;
		}
	if (selfpc < mparam.lowpc || selfpc > mparam.highpc) return;
	thisarc.raw_frompc = frompc;
	thisarc.raw_selfpc = selfpc;
	thisarc.raw_count  = 1;
	arc[mparam.arcnum++] = thisarc;
}
dietlibc-0.33~cvs20120325/profiling/monitor.c010064400000000000000000000044651173363230200155330ustar00/**************************************************************
   Copyright (C) 2001, 2002 Thomas M. Ogrisegg

   This is free software. You can redistribute and modify
   it under the terms of the GNU General Public License.

   This file is part of the profiling support for dietlibc

   monitor(3) interface

 *************************************************************/
#include 
#include 
#include 
#include 
#include 

typedef unsigned short u_short;

struct monparam mparam;

void monitor (unsigned long, unsigned long) PROF_SECTION;
void _stop_monitor (void) PROF_SECTION;

/*
  monitor is called by _start, to start profiling
  lowpc  -> lowest valid program counter  (normally .text)
  highpc -> highest valid program counter (normally _etext)
*/
void
monitor (unsigned long lowpc, unsigned long highpc)
{
	mparam.highpc     = highpc;
	mparam.lowpc      = lowpc;
	mparam.kcountsize = (mparam.textsize = highpc-lowpc) << 1;
	mparam.kcount = (u_short *) malloc (mparam.kcountsize);
	mparam.arcs = (struct rawarc *) malloc (MAXARCS*sizeof (struct rawarc));
	if (!mparam.kcount || !mparam.arcs)
		exit (42);
	mparam.arcnum = 0;
	/* start profiling */
	profil (mparam.kcount, highpc-lowpc, lowpc, 10000);
}

/*
  write_gmon - write all data collected by the helper routines
  to gmon.out
*/
static void
write_gmon (void)
{
	struct gmon_hdr ghdr = { "gmon", 1, "" };
	int fd = open ("gmon.out", O_CREAT | O_RDWR | O_TRUNC, 0666);

	if (fd < 0) return;
	write (fd, &ghdr, sizeof (ghdr));
	if (mparam.kcountsize)
	{
		char tag = GMON_TAG_TIME_HIST;
		struct gmon_hist_hdr ghdr = {
			mparam.lowpc, mparam.highpc,
			(mparam.kcountsize >> 1), 100, "seconds", 's' 
		};
		struct iovec iov[3] = {
			{ &tag,  sizeof (tag)  },
			{ &ghdr, sizeof (ghdr) },
			{ mparam.kcount, mparam.kcountsize >> 1 << 1 }
		};
		writev (fd, iov, 3);
	}
	if (mparam.arcnum)
	{
		char tag = GMON_TAG_CG_ARC;
		struct iovec iov[mparam.arcnum*2];
		unsigned long l;
		for (l=0;l
#include 
#include 
#include 
#include 

#define SHORT_SIZE sizeof (short)
#define MAX_SHORT 65536

#ifdef DEBUG
# include 
# define debug printf
#else
# define debug
#endif

#ifndef u_short
# define u_short unsigned short
#endif

#ifndef u_int
# define u_int unsigned int
#endif

static unsigned short *buffer = NULL;
static size_t maxhits  = 0;
static unsigned long low_pc = 0;
static unsigned long pscale = 0;

/* profiler - helper function for profil(3) */
static void
profiler (int signal, struct sigcontext ctx)
{
	size_t s = PC(ctx)-low_pc;
	(void)signal;
	if ((PC(ctx)) < low_pc) return;
	s >>= 1;
	if (s < maxhits)
		++buffer[s];
}

/* profil(3) - start or stop the profiling timer */
int
profil (u_short *buf, size_t bufsiz, size_t offset, u_int scale)
{
	struct itimerval itv = { { 0, 1 }, { 0, 1 } };
	struct sigaction sa;
	if (!buf) {
		sigaction (SIGPROF, NULL, NULL);
		setitimer (ITIMER_PROF, NULL, NULL);
		return (0);
	}
	sa.sa_handler = (sighandler_t)&profiler;
	sa.sa_flags   = SA_RESTART;
	sigfillset (&sa.sa_mask);
	sigaction (SIGPROF, &sa, NULL);
	pscale = scale;
	buffer = buf;
	low_pc = offset;
	maxhits = bufsiz/SHORT_SIZE;

	return (setitimer (ITIMER_PROF, &itv, &itv));
}
dietlibc-0.33~cvs20120325/s390/Makefile.add010064400000000000000000000001641173363230200145640ustar00
CFLAGS+=-Os # -fomit-frame-pointer -fstrict-aliasing
VPATH:=s390:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/__waitpid.o
dietlibc-0.33~cvs20120325/s390/__longjmp.S010064400000000000000000000003301173363230200144600ustar00#include 

.text
.global __longjmp
.type __longjmp,@function
__longjmp:
	lm	%r6,%r15,0(%r2)
	ld	%f6,48(%r2)
	ld	%f4,40(%r2)
	chi	%r3,0
	jne	1f
	lhi	%r3,1
1:	lr	%r2,%r3
	br	%r14
.size __longjmp,.-__longjmp;
dietlibc-0.33~cvs20120325/s390/__testandset.S010064400000000000000000000002241173363230200151720ustar00.text
.global __testandset
.type	__testandset,@function
__testandset:
	la	%r1,0(%r2)
	lhi	%r0,1
	lhi	%r2,0
	cs	%r2,%r0,0(%r1)
	xr	%r2,%r0
	br	%r14

dietlibc-0.33~cvs20120325/s390/__waitpid.c010064400000000000000000000002211173363230200144720ustar00#include 
#include 

pid_t waitpid(pid_t pid, int * wait_stat, int flags) {
  return wait4(pid, wait_stat, flags, 0);
}
dietlibc-0.33~cvs20120325/s390/clone.S010064400000000000000000000010021173363230200136110ustar00#include 
#include "syscalls.h"

.text
.align 4
.global __clone
.type	__clone,@function
__clone:
	ltr	%r1, %r2
	lhi	%r2, -EINVAL
	jz	.Lerror
	ltr	%r3, %r3
	jz	.Lerror
	lr	%r2, %r3
	lr	%r3, %r4
	svc	__NR_clone
	ltr	%r2, %r2
	jm	.Lerror
	jz	thread_start
	br	%r14

thread_start:
	lr	%r2, %r5
	sr	%r11,%r11
	ahi	%r15,-96
	basr	%r14,%r1

	basr	%r1, %r0
.L0:	al	%r1, [.L1-.L0](%r1)
	br	%r1
.L1:	.long	_exit-.L0

.Lerror:
	basr	%r1, %r0
.L2:	al	%r1, [.L3-.L2](%r1)
	br	%r1
.L3:	.long	__error_unified_syscall-.L0
dietlibc-0.33~cvs20120325/s390/mmap.S010064400000000000000000000032041173363230200134510ustar00#include 
#include "syscalls.h"

#define EINVAL  22

	.text
	.align 4
	.global mmap
	.type	mmap,@function
mmap:
        /* Save registers and setup stack frame.  */
        stm     %r6,%r15,24(%r15)
        lr      %r1,%r15
        ahi     %r15,-120               /* buy stack space */
        st      %r1,0(%r15)             /* store back chain */

        /* Store parameters on stack, because old_mmap/mmap2
         * take only one parameter: a pointer to the parameter area
         */
        st      %r6,0x70(%r15)          /* Store 'fd'.      */
        st      %r5,0x6C(%r15)          /* Store 'flags'.   */
        st      %r4,0x68(%r15)          /* Store 'prot'.    */
        st      %r3,0x64(%r15)          /* Store 'length'.  */
        st      %r2,0x60(%r15)          /* Store 'start'.   */
        l       %r1,216(%r15)           /* Load offset.     */

        tml     %r1,0x0fff              /* Offset page aligned ?  */
        lhi     %r2,-EINVAL
        jnz     1f                      /* No -> EINVAL.  */
        srl     %r1,12                  /* mmap2 takes the offset in pages.  */
        st      %r1,0x74(%r15)          /* Store page offset.  */
        la      %r2,0x60(%r15)          /* Load address of parameter list.  */
        svc     __NR_mmap2              /* Do the system call trap.  */

1:      l       %r15,0(%r15)            /* Load back chain.  */
        lm      %r6,%r15,24(%r15)       /* Load registers.  */

	j	__unified_syscall

        /* check gpr 2 for error */
        lhi     %r0,-4096
        clr     %r2,%r0
        jnl     1b

        /* Successful; return the syscall's value.  */
        br      %r14

dietlibc-0.33~cvs20120325/s390/mmap64.S010064400000000000000000000034511173363230200136270ustar00#include 
#include "syscalls.h"

#define EINVAL  22

	.text
	.align 4
	.global mmap64
	.type	mmap64,@function
mmap64:
        /* Save registers and setup stack frame.  */
        stm     %r6,%r15,24(%r15)
        lr      %r1,%r15
        ahi     %r15,-120               /* buy stack space */
        st      %r1,0(%r15)             /* store back chain */

        /* Store parameters on stack, because old_mmap/mmap2
         * take only one parameter: a pointer to the parameter area
         */
        st      %r6,0x70(%r15)          /* Store 'fd'.      */
        st      %r5,0x6C(%r15)          /* Store 'flags'.   */
        st      %r4,0x68(%r15)          /* Store 'prot'.    */
        st      %r3,0x64(%r15)          /* Store 'length'.  */
        st      %r2,0x60(%r15)          /* Store 'start'.   */

        lm      %r0,%r1,216(%r15)           /* Load offset.     */
        tml     %r1,0x0fff              /* Offset page aligned ?  */
        jnz     1f                      /* No -> EINVAL.  */
        srdl    %r0,12                  /* mmap2 takes the offset in pages.  */
	ltr	%r0,%r0
	jnz	1f
        st      %r1,0x74(%r15)          /* Store page offset.  */

        la      %r2,0x60(%r15)          /* Load address of parameter list.  */
        svc     __NR_mmap2              /* Do the system call trap.  */

        l       %r15,0(%r15)            /* Load back chain.  */
        lm      %r6,%r15,24(%r15)       /* Load registers.  */

        /* check gpr 2 for error */
        lhi     %r0,-4096
        clr     %r2,%r0
        jnl     __unified_syscall

        /* Successful; return the syscall's value.  */
        br      %r14

1:	lhi	%r2,-EINVAL
        l       %r15,0(%r15)            /* Load back chain.  */
        lm      %r6,%r15,24(%r15)       /* Load registers.  */
	j	__unified_syscall

dietlibc-0.33~cvs20120325/s390/select.S010064400000000000000000000000621173363230200137750ustar00#include "syscalls.h"

syscall(_newselect,select)
dietlibc-0.33~cvs20120325/s390/setjmp.S010064400000000000000000000012571173363230200140270ustar00#include 

.text
.weak setjmp
.type setjmp,@function
setjmp:
.global __setjmp
.type	__setjmp,@function
__setjmp:
	lhi	%r3,1
	j	__sigsetjmp
.size	__setjmp,.-__setjmp
.size	setjmp,.-setjmp

.global _setjmp
.type	_setjmp,@function
	lhi	%r3,0
.size	_setjmp,.-_setjmp


.global __sigsetjmp
.type	__sigsetjmp,@function
__sigsetjmp:
	stm	%r6,%r15,0(%r2)
	std	%f4,40(%r2)
	std	%f6,48(%r2)

	/* Make a tail call to __sigjmp_save; it takes the same args.  */
	basr	%r1,%r0
#ifdef	PIC
.L0:	la	%r1,.L1-.L0(0,%r1)
	l	%r1,__sigjmp_save@GOT12(0,%r1)
	br	%r1
.L1:	.long	_GLOBAL_OFFSET_TABLE_-.L0
#else
	l	%r1,.L1(0,%r1)
	br	%r1
.L1:	.long	__sigjmp_save
#endif
.size __sigsetjmp,.-__sigsetjmp;
dietlibc-0.33~cvs20120325/s390/start.S010064400000000000000000000015571173363230200136650ustar00#include "dietfeatures.h"

.text
.global _start
_start:
	basr	%r13,%r0
	ahi	%r13,[.Laddr-.]

#ifdef WANT_DYNAMIC
	lr	%r5,%r14		/* save dynamic ld.so _fini */
#endif

	l	%r2,0(%r15)		/* argc */
	la	%r3,4(%r15)		/* argv */

/* envp = argv + ( (argc+1)*4 ) */
	lr	%r4,%r2
	sll	%r4,2
	la	%r4,8(%r4,%r15)

/* align the stack to a double word boundary */
	lhi     %r0,-8
	nr      %r15,%r0

/* Setup a stack frame and a parameter area */
	ahi     %r15,-104               # make room on stack
	xc      0(4,%r15),0(%r15)       # clear back-chain

/* environ = envp */
	l	%r1,8(%r13)
	st	%r4,0(%r1)

/* call main or _dyn_start */
	l	%r1,0(%r13)
	basr	%r14,%r1

/* call exit */
	l	%r1,4(%r13)
	basr	%r14,%r1

/* DIE! */
	.word	0

.align 4
.Laddr:
#ifdef WANT_DYNAMIC
	.long	_dyn_start
#else
	.long	CALL_IN_STARTCODE
#endif
	.long	exit
	.long	environ

.Lstart:
	.size	_start,.Lstart-_start

dietlibc-0.33~cvs20120325/s390/syscalls.h010064400000000000000000000215441173363230200144100ustar00




#define __NR_exit		  1
#define __NR_fork		  2
#define __NR_read		  3
#define __NR_write		  4
#define __NR_open		  5
#define __NR_close		  6
//#define __NR_waitpid		  7
#define __NR_creat		  8
#define __NR_link		  9
#define __NR_unlink		 10
#define __NR_execve		 11
#define __NR_chdir		 12
#define __NR_time		 13
#define __NR_mknod		 14
#define __NR_chmod		 15
#define __NR_lchown		 16
#define __NR_lseek		 19
#define __NR_getpid		 20
#define __NR_mount		 21
#define __NR_umount		 22
#define __NR_setuid		 23
#define __NR_getuid		 24
#define __NR_stime		 25
#define __NR_ptrace		 26
#define __NR_alarm		 27
#define __NR_pause		 29
#define __NR_utime		 30
#define __NR_access		 33
#define __NR_nice		 34
#define __NR_sync		 36
#define __NR_kill		 37
#define __NR_rename		 38
#define __NR_mkdir		 39
#define __NR_rmdir		 40
#define __NR_dup		 41
#define __NR_pipe		 42
#define __NR_times		 43
#define __NR_brk		 45
#define __NR_setgid		 46
#define __NR_getgid		 47
#define __NR_signal		 48
#define __NR_geteuid		 49
#define __NR_getegid		 50
#define __NR_acct		 51
#define __NR_umount2		 52
#define __NR_ioctl		 54
#define __NR_fcntl		 55
#define __NR_setpgid		 57
#define __NR_umask		 60
#define __NR_chroot		 61
#define __NR_ustat		 62
#define __NR_dup2		 63
#define __NR_getppid		 64
#define __NR_getpgrp		 65
#define __NR_setsid		 66
#define __NR_sigaction		 67
#define __NR_setreuid		 70
#define __NR_setregid		 71
#define __NR_sigsuspend		 72
#define __NR_sigpending		 73
#define __NR_sethostname	 74
#define __NR_setrlimit		 75
#define __NR_getrlimit		 76
#define __NR_getrusage		 77
#define __NR_gettimeofday	 78
#define __NR_settimeofday	 79
#define __NR_getgroups		 80
#define __NR_setgroups		 81
#define __NR_symlink		 83
#define __NR_readlink		 85
#define __NR_uselib		 86
#define __NR_swapon		 87
#define __NR_reboot		 88
#define __NR_readdir		 89
#define __NR_mmap		 90
#define __NR_munmap		 91
#define __NR_truncate		 92
#define __NR_ftruncate		 93
#define __NR_fchmod		 94
#define __NR_fchown		 95
#define __NR_getpriority	 96
#define __NR_setpriority	 97
#define __NR_statfs		 99
#define __NR_fstatfs		100
#define __NR_ioperm		101
#define __NR_socketcall		102
#define __NR_syslog		103
#define __NR_setitimer		104
#define __NR_getitimer		105
#define __NR_stat		106
#define __NR_lstat		107
#define __NR_fstat		108
#define __NR_lookup_dcookie     110
#define __NR_vhangup		111
#define __NR_idle		112
#define __NR_wait4		114
#define __NR_swapoff		115
#define __NR_sysinfo		116
#define __NR_ipc		117
#define __NR_fsync		118
#define __NR_sigreturn		119
#define __NR_clone		120
#define __NR_setdomainname	121
#define __NR_uname		122
#define __NR_adjtimex		124
#define __NR_mprotect		125
#define __NR_sigprocmask	126
#define __NR_create_module	127
#define __NR_init_module	128
#define __NR_delete_module	129
#define __NR_get_kernel_syms	130
#define __NR_quotactl		131
#define __NR_getpgid		132
#define __NR_fchdir		133
#define __NR_bdflush		134
#define __NR_sysfs		135
#define __NR_personality	136
#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
#define __NR_setfsuid		138
#define __NR_setfsgid		139
#define __NR__llseek		140
#define __NR_getdents		141
#define __NR__newselect		142
#define __NR_flock		143
#define __NR_msync		144
#define __NR_readv		145
#define __NR_writev		146
#define __NR_getsid		147
#define __NR_fdatasync		148
#define __NR__sysctl		149
#define __NR_mlock		150
#define __NR_munlock		151
#define __NR_mlockall		152
#define __NR_munlockall		153
#define __NR_sched_setparam		154
#define __NR_sched_getparam		155
#define __NR_sched_setscheduler		156
#define __NR_sched_getscheduler		157
#define __NR_sched_yield		158
#define __NR_sched_get_priority_max	159
#define __NR_sched_get_priority_min	160
#define __NR_sched_rr_get_interval	161
#define __NR_nanosleep		162
#define __NR_mremap		163
#define __NR_setresuid		164
#define __NR_getresuid		165
#define __NR_query_module	167
#define __NR_poll		168
#define __NR_nfsservctl		169
#define __NR_setresgid		170
#define __NR_getresgid		171
#define __NR_prctl              172
#define __NR_rt_sigreturn	173
#define __NR_rt_sigaction	174
#define __NR_rt_sigprocmask	175
#define __NR_rt_sigpending	176
#define __NR_rt_sigtimedwait	177
#define __NR_rt_sigqueueinfo	178
#define __NR_rt_sigsuspend	179
#define __NR_pread		180
#define __NR_pwrite		181
#define __NR_chown		182
#define __NR_getcwd		183
#define __NR_capget		184
#define __NR_capset		185
#define __NR_sigaltstack	186
#define __NR_sendfile		187
#define __NR_getpmsg		188
#define __NR_putpmsg		189
#define __NR_vfork		190
#define __NR_ugetrlimit		191	/* SuS compliant getrlimit */
#define __NR_mmap2		192
#define __NR_truncate64		193
#define __NR_ftruncate64	194
#define __NR_stat64		195
#define __NR_lstat64		196
#define __NR_fstat64		197
#define __NR_lchown32		198
#define __NR_getuid32		199
#define __NR_getgid32		200
#define __NR_geteuid32		201
#define __NR_getegid32		202
#define __NR_setreuid32		203
#define __NR_setregid32		204
#define __NR_getgroups32	205
#define __NR_setgroups32	206
#define __NR_fchown32		207
#define __NR_setresuid32	208
#define __NR_getresuid32	209
#define __NR_setresgid32	210
#define __NR_getresgid32	211
#define __NR_chown32		212
#define __NR_setuid32		213
#define __NR_setgid32		214
#define __NR_setfsuid32		215
#define __NR_setfsgid32		216
#define __NR_pivot_root		217
#define __NR_mincore		218
#define __NR_madvise		219
#define __NR_getdents64		220
#define __NR_fcntl64		221
#define __NR_readahead		222
#define __NR_sendfile64		223
#define __NR_setxattr		224
#define __NR_lsetxattr		225
#define __NR_fsetxattr		226
#define __NR_getxattr		227
#define __NR_lgetxattr		228
#define __NR_fgetxattr		229
#define __NR_listxattr		230
#define __NR_llistxattr		231
#define __NR_flistxattr		232
#define __NR_removexattr	233
#define __NR_lremovexattr	234
#define __NR_fremovexattr	235
#define __NR_gettid		236
#define __NR_tkill		237
#define __NR_futex		238
#define __NR_sched_setaffinity	239
#define __NR_sched_getaffinity	240
#define __NR_tgkill		241
/*
 * Number 242 is reserved for tux
 */
#define __NR_io_setup		243
#define __NR_io_destroy		244
#define __NR_io_getevents	245
#define __NR_io_submit		246
#define __NR_io_cancel		247
#define __NR_exit_group		248
#define __NR_epoll_create	249
#define __NR_epoll_ctl		250
#define __NR_epoll_wait		251
#define __NR_set_tid_address	252
#define __NR_fadvise64		253
#define __NR_timer_create	254
#define __NR_timer_settime	(__NR_timer_create+1)
#define __NR_timer_gettime	(__NR_timer_create+2)
#define __NR_timer_getoverrun	(__NR_timer_create+3)
#define __NR_timer_delete	(__NR_timer_create+4)
#define __NR_clock_settime	(__NR_timer_create+5)
#define __NR_clock_gettime	(__NR_timer_create+6)
#define __NR_clock_getres	(__NR_timer_create+7)
#define __NR_clock_nanosleep	(__NR_timer_create+8)
/* Number 263 is reserved for vserver */
#define __NR_fadvise64_64	264
#define __NR_statfs64		265
#define __NR_fstatfs64		266
#define __NR_remap_file_pages	267
/* Number 268 is reserved for new sys_mbind */
/* Number 269 is reserved for new sys_get_mempolicy */
/* Number 270 is reserved for new sys_set_mempolicy */
#define __NR_mq_open		271
#define __NR_mq_unlink		272
#define __NR_mq_timedsend	273
#define __NR_mq_timedreceive	274
#define __NR_mq_notify		275
#define __NR_mq_getsetattr	276
#define __NR_kexec_load		277
#define __NR_add_key		278
#define __NR_request_key	279
#define __NR_keyctl		280
#define __NR_waitid		281
#define __NR_ioprio_set		282
#define __NR_ioprio_get		283
#define __NR_inotify_init	284
#define __NR_inotify_add_watch	285
#define __NR_inotify_rm_watch	286
/* Number 287 is reserved for new sys_migrate_pages */
#define __NR_openat		288
#define __NR_mkdirat		289
#define __NR_mknodat		290
#define __NR_fchownat		291
#define __NR_futimesat		292
#define __NR_unlinkat		294
#define __NR_renameat		295
#define __NR_linkat		296
#define __NR_symlinkat		297
#define __NR_readlinkat		298
#define __NR_fchmodat		299
#define __NR_faccessat		300
#define __NR_pselect6		301
#define __NR_ppoll		302
#define __NR_unshare		303
#define __NR_set_robust_list	304
#define __NR_get_robust_list	305
#define __NR_splice		306
#define __NR_sync_file_range	307
#define __NR_tee		308
#define __NR_vmsplice		309
/* Number 310 is reserved for new sys_move_pages */
#define __NR_getcpu		311
#define __NR_epoll_pwait	312
#define __NR_utimes		313
#define __NR_fallocate		314
#define __NR_utimensat		315
#define __NR_signalfd		316
#define __NR_timerfd		317
#define __NR_eventfd		318
#define __NR_timerfd_create	319
#define __NR_timerfd_settime	320
#define __NR_timerfd_gettime	321


#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,@function; \
.weak wsym; \
wsym: ; \
.type sym,@function; \
.global sym; \
sym: \
	.if __NR_##name < 256 ; \
	svc __NR_##name ; \
	.else ; \
	la %r1,__NR_##name ; \
	svc 0 ; \
	.endif ; \
	j __unified_syscall

#define syscall(name,sym) \
.text; \
.type sym,@function; \
.global sym; \
sym: \
	.if __NR_##name < 256 ; \
	svc __NR_##name ; \
	.else ; \
	la %r1,__NR_##name ; \
	svc 0 ; \
	.endif ; \
	j __unified_syscall

dietlibc-0.33~cvs20120325/s390/unified.S010064400000000000000000000014211173363230200141410ustar00#include 
#include "syscalls.h"

.text
.weak exit
.type exit,@function
exit:
.global _exit
.type	_exit,@function
_exit:
	svc	__NR_exit
.global __unified_syscall
__unified_syscall:
	lhi	%r4,-127
	clr	%r2,%r4
	jl	.Lnoerror

.global __error_unified_syscall
__error_unified_syscall:
#ifdef WANT_THREAD_SAFE
	stm	%r11,%r15,44(%r15)
	lr	%r0,%r15
	ahi	%r15,-96
	st	%r0,0(%r15)

	lcr	%r11,%r2
	basr	%r13,%r0
	l	%r3,[.L0-.](%r13)
	basr	%r14,%r3
	st	%r11,0(%r2)

	l	%r15,0(%r15)
	lm	%r11,%r15,44(%r15)
#else
	basr	%r1,%r0
	l	%r3,[.L0-.](%r1)
	st	%r2,0(%r3)
#endif
	lhi	%r2,-1

.Lnoerror:

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	br	%r14

.align 4
.L0:
#ifdef WANT_THREAD_SAFE
	.long	__errno_location
#else
	.long	errno
#endif
dietlibc-0.33~cvs20120325/s390x/Makefile.add010064400000000000000000000002101173363230200147440ustar00
CFLAGS+=-Os # -fomit-frame-pointer -fstrict-aliasing
VPATH:=s390x:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/__waitpid.o $(OBJDIR)/__time.o
dietlibc-0.33~cvs20120325/s390x/__longjmp.S010064400000000000000000000003301173363230200146500ustar00#include 

.text
.global __longjmp
.type __longjmp,@function
__longjmp:
	lm	%r6,%r15,0(%r2)
	ld	%f6,48(%r2)
	ld	%f4,40(%r2)
	chi	%r3,0
	jne	1f
	lhi	%r3,1
1:	lr	%r2,%r3
	br	%r14
.size __longjmp,.-__longjmp;
dietlibc-0.33~cvs20120325/s390x/__testandset.S010064400000000000000000000002241173363230200153620ustar00.text
.global __testandset
.type	__testandset,@function
__testandset:
	la	%r1,0(%r2)
	lhi	%r0,1
	lhi	%r2,0
	cs	%r2,%r0,0(%r1)
	xr	%r2,%r0
	br	%r14

dietlibc-0.33~cvs20120325/s390x/__waitpid.c010064400000000000000000000002211173363230200146620ustar00#include 
#include 

pid_t waitpid(pid_t pid, int * wait_stat, int flags) {
  return wait4(pid, wait_stat, flags, 0);
}
dietlibc-0.33~cvs20120325/s390x/clone.S010064400000000000000000000010021173363230200140010ustar00#include 
#include "syscalls.h"

.text
.align 4
.global __clone
.type	__clone,@function
__clone:
	ltr	%r1, %r2
	lhi	%r2, -EINVAL
	jz	.Lerror
	ltr	%r3, %r3
	jz	.Lerror
	lr	%r2, %r3
	lr	%r3, %r4
	svc	__NR_clone
	ltr	%r2, %r2
	jm	.Lerror
	jz	thread_start
	br	%r14

thread_start:
	lr	%r2, %r5
	sr	%r11,%r11
	ahi	%r15,-96
	basr	%r14,%r1

	basr	%r1, %r0
.L0:	al	%r1, [.L1-.L0](%r1)
	br	%r1
.L1:	.long	_exit-.L0

.Lerror:
	basr	%r1, %r0
.L2:	al	%r1, [.L3-.L2](%r1)
	br	%r1
.L3:	.long	__error_unified_syscall-.L0
dietlibc-0.33~cvs20120325/s390x/mmap.S010064400000000000000000000024561173363230200136510ustar00#include 
#include "syscalls.h"

	.text
	.align 4
	.global mmap
	.type	mmap,@function
mmap:
        /* Save registers and setup stack frame.  */
        stmg    %r6,%r15,48(%r15)
        lgr     %r1,%r15
        lg      %r0,8(%r15)             /* Load eos.  */
        aghi    %r15,-208               /* Buy stack space.  */
        stg     %r1,0(%r15)             /* Store back chain.  */
        stg     %r0,8(%r15)             /* Store eos.  */

        /* Store parameters on stack, because old_mmap 
           takes only one parameter: a pointer to the parameter area.  */
        mvc     200(8,%r15),368(%r15)   /* Move 'offset'.  */
        lgfr    %r6,%r6
        stg     %r6,192(%r15)           /* Store 'fd'.  */
        lgfr    %r5,%r5
        stg     %r5,184(%r15)           /* Store 'flags'.  */
        lgfr    %r4,%r4
        stg     %r4,176(%r15)           /* Store 'prot'.  */
        stg     %r3,168(%r15)           /* Store 'length'.  */
        stg     %r2,160(%r15)           /* Store 'start'.  */

        la      %r2,160(%r15)           /* Load address of parameter list.  */
        /* Do the system call trap.  */
        svc     __NR_mmap

        lg      %r15,0(%r15)            /* Load back chain.  */
        lmg     %r6,%r15,48(%r15)       /* Load registers.  */
	
	j __unified_syscall
dietlibc-0.33~cvs20120325/s390x/select.S010064400000000000000000000000311173363230200141610ustar00#include "s390/select.S"
dietlibc-0.33~cvs20120325/s390x/setjmp.S010064400000000000000000000012571173363230200142170ustar00#include 

.text
.weak setjmp
.type setjmp,@function
setjmp:
.global __setjmp
.type	__setjmp,@function
__setjmp:
	lhi	%r3,1
	j	__sigsetjmp
.size	__setjmp,.-__setjmp
.size	setjmp,.-setjmp

.global _setjmp
.type	_setjmp,@function
	lhi	%r3,0
.size	_setjmp,.-_setjmp


.global __sigsetjmp
.type	__sigsetjmp,@function
__sigsetjmp:
	stm	%r6,%r15,0(%r2)
	std	%f4,40(%r2)
	std	%f6,48(%r2)

	/* Make a tail call to __sigjmp_save; it takes the same args.  */
	basr	%r1,%r0
#ifdef	PIC
.L0:	la	%r1,.L1-.L0(0,%r1)
	l	%r1,__sigjmp_save@GOT12(0,%r1)
	br	%r1
.L1:	.long	_GLOBAL_OFFSET_TABLE_-.L0
#else
	l	%r1,.L1(0,%r1)
	br	%r1
.L1:	.long	__sigjmp_save
#endif
.size __sigsetjmp,.-__sigsetjmp;
dietlibc-0.33~cvs20120325/s390x/start.S010064400000000000000000000014311173363230200140440ustar00#include "dietfeatures.h"

.text
.global _start
_start:
#ifdef WANT_DYNAMIC
	lgr	%r5,%r14		/* save dynamic ld.so _fini */
#endif
	lg	%r2,0(%r15)		/* argc */
	la	%r3,8(%r15)		/* argv */

/* envp = argv + ( (argc+1)*8 ) */
	lgr	%r4,%r2
	sll	%r4,3
	la	%r4,16(%r4,%r15)

/* align the stack to a double word boundary */
	lghi	%r0,-16
	ngr	%r15,%r0

/* Setup a stack frame and a parameter area */
	aghi	%r15,-176               /* make room on stack */
	xc	0(8,%r15),0(%r15)       /* clear back-chain */

/* environ = envp */
	larl	%r13,environ
	stg	%r4,0(%r13)

/* call main or _dyn_start */
#ifdef WANT_DYNAMIC
	brasl	%r14,_dyn_start
#else
	brasl	%r14,CALL_IN_STARTCODE
#endif

/* call exit */
	brasl	%r14,exit

/* DIE! */
        .word   0

.align 4
.Lstart:
        .size   _start,.Lstart-_start
dietlibc-0.33~cvs20120325/s390x/syscalls.h010064400000000000000000000256251173363230200146040ustar00




#define __NR_exit		  1
#define __NR_fork		  2
#define __NR_read		  3
#define __NR_write		  4
#define __NR_open		  5
#define __NR_close		  6
//#define __NR_waitpid		  7
#define __NR_creat		  8
#define __NR_link		  9
#define __NR_unlink		 10
#define __NR_execve		 11
#define __NR_chdir		 12
#define __NR_time		 13
#define __NR_mknod		 14
#define __NR_chmod		 15
#define __NR_lchown		 16
#define __NR_lseek		 19
#define __NR_getpid		 20
#define __NR_mount		 21
#define __NR_umount		 22
#define __NR_setuid		 23
#define __NR_getuid		 24
#define __NR_stime		 25
#define __NR_ptrace		 26
#define __NR_alarm		 27
#define __NR_pause		 29
#define __NR_utime		 30
#define __NR_access		 33
#define __NR_nice		 34
#define __NR_sync		 36
#define __NR_kill		 37
#define __NR_rename		 38
#define __NR_mkdir		 39
#define __NR_rmdir		 40
#define __NR_dup		 41
#define __NR_pipe		 42
#define __NR_times		 43
#define __NR_brk		 45
#define __NR_setgid		 46
#define __NR_getgid		 47
#define __NR_signal		 48
#define __NR_geteuid		 49
#define __NR_getegid		 50
#define __NR_acct		 51
#define __NR_umount2		 52
#define __NR_ioctl		 54
#define __NR_fcntl		 55
#define __NR_setpgid		 57
#define __NR_umask		 60
#define __NR_chroot		 61
#define __NR_ustat		 62
#define __NR_dup2		 63
#define __NR_getppid		 64
#define __NR_getpgrp		 65
#define __NR_setsid		 66
#define __NR_sigaction		 67
#define __NR_setreuid		 70
#define __NR_setregid		 71
#define __NR_sigsuspend		 72
#define __NR_sigpending		 73
#define __NR_sethostname	 74
#define __NR_setrlimit		 75
#define __NR_getrlimit		 76
#define __NR_getrusage		 77
#define __NR_gettimeofday	 78
#define __NR_settimeofday	 79
#define __NR_getgroups		 80
#define __NR_setgroups		 81
#define __NR_symlink		 83
#define __NR_readlink		 85
#define __NR_uselib		 86
#define __NR_swapon		 87
#define __NR_reboot		 88
#define __NR_readdir		 89
#define __NR_mmap		 90
#define __NR_munmap		 91
#define __NR_truncate		 92
#define __NR_ftruncate		 93
#define __NR_fchmod		 94
#define __NR_fchown		 95
#define __NR_getpriority	 96
#define __NR_setpriority	 97
#define __NR_statfs		 99
#define __NR_fstatfs		100
#define __NR_ioperm		101
#define __NR_socketcall		102
#define __NR_syslog		103
#define __NR_setitimer		104
#define __NR_getitimer		105
#define __NR_stat		106
#define __NR_lstat		107
#define __NR_fstat		108
#define __NR_lookup_dcookie     110
#define __NR_vhangup		111
#define __NR_idle		112
#define __NR_wait4		114
#define __NR_swapoff		115
#define __NR_sysinfo		116
#define __NR_ipc		117
#define __NR_fsync		118
#define __NR_sigreturn		119
#define __NR_clone		120
#define __NR_setdomainname	121
#define __NR_uname		122
#define __NR_adjtimex		124
#define __NR_mprotect		125
#define __NR_sigprocmask	126
#define __NR_create_module	127
#define __NR_init_module	128
#define __NR_delete_module	129
#define __NR_get_kernel_syms	130
#define __NR_quotactl		131
#define __NR_getpgid		132
#define __NR_fchdir		133
#define __NR_bdflush		134
#define __NR_sysfs		135
#define __NR_personality	136
#define __NR_afs_syscall	137 /* Syscall for Andrew File System */
#define __NR_setfsuid		138
#define __NR_setfsgid		139
#define __NR__llseek		140
#define __NR_getdents		141
#define __NR__newselect		142
#define __NR_flock		143
#define __NR_msync		144
#define __NR_readv		145
#define __NR_writev		146
#define __NR_getsid		147
#define __NR_fdatasync		148
#define __NR__sysctl		149
#define __NR_mlock		150
#define __NR_munlock		151
#define __NR_mlockall		152
#define __NR_munlockall		153
#define __NR_sched_setparam		154
#define __NR_sched_getparam		155
#define __NR_sched_setscheduler		156
#define __NR_sched_getscheduler		157
#define __NR_sched_yield		158
#define __NR_sched_get_priority_max	159
#define __NR_sched_get_priority_min	160
#define __NR_sched_rr_get_interval	161
#define __NR_nanosleep		162
#define __NR_mremap		163
#define __NR_setresuid		164
#define __NR_getresuid		165
#define __NR_query_module	167
#define __NR_poll		168
#define __NR_nfsservctl		169
#define __NR_setresgid		170
#define __NR_getresgid		171
#define __NR_prctl              172
#define __NR_rt_sigreturn	173
#define __NR_rt_sigaction	174
#define __NR_rt_sigprocmask	175
#define __NR_rt_sigpending	176
#define __NR_rt_sigtimedwait	177
#define __NR_rt_sigqueueinfo	178
#define __NR_rt_sigsuspend	179
#define __NR_pread		180
#define __NR_pwrite		181
#define __NR_chown		182
#define __NR_getcwd		183
#define __NR_capget		184
#define __NR_capset		185
#define __NR_sigaltstack	186
#define __NR_sendfile		187
#define __NR_getpmsg		188
#define __NR_putpmsg		189
#define __NR_vfork		190
#define __NR_ugetrlimit		191	/* SuS compliant getrlimit */
#define __NR_mmap2		192
#define __NR_truncate64		193
#define __NR_ftruncate64	194
#define __NR_stat64		195
#define __NR_lstat64		196
#define __NR_fstat64		197
#define __NR_lchown32		198
#define __NR_getuid32		199
#define __NR_getgid32		200
#define __NR_geteuid32		201
#define __NR_getegid32		202
#define __NR_setreuid32		203
#define __NR_setregid32		204
#define __NR_getgroups32	205
#define __NR_setgroups32	206
#define __NR_fchown32		207
#define __NR_setresuid32	208
#define __NR_getresuid32	209
#define __NR_setresgid32	210
#define __NR_getresgid32	211
#define __NR_chown32		212
#define __NR_setuid32		213
#define __NR_setgid32		214
#define __NR_setfsuid32		215
#define __NR_setfsgid32		216
#define __NR_pivot_root		217
#define __NR_mincore		218
#define __NR_madvise		219
#define __NR_getdents64		220
#define __NR_fcntl64		221
#define __NR_readahead		222
#define __NR_sendfile64		223
#define __NR_setxattr		224
#define __NR_lsetxattr		225
#define __NR_fsetxattr		226
#define __NR_getxattr		227
#define __NR_lgetxattr		228
#define __NR_fgetxattr		229
#define __NR_listxattr		230
#define __NR_llistxattr		231
#define __NR_flistxattr		232
#define __NR_removexattr	233
#define __NR_lremovexattr	234
#define __NR_fremovexattr	235
#define __NR_gettid		236
#define __NR_tkill		237
#define __NR_futex		238
#define __NR_sched_setaffinity	239
#define __NR_sched_getaffinity	240
#define __NR_tgkill		241
/*
 * Number 242 is reserved for tux
 */
#define __NR_io_setup		243
#define __NR_io_destroy		244
#define __NR_io_getevents	245
#define __NR_io_submit		246
#define __NR_io_cancel		247
#define __NR_exit_group		248
#define __NR_epoll_create	249
#define __NR_epoll_ctl		250
#define __NR_epoll_wait		251
#define __NR_set_tid_address	252
#define __NR_fadvise64		253
#define __NR_timer_create	254
#define __NR_timer_settime	(__NR_timer_create+1)
#define __NR_timer_gettime	(__NR_timer_create+2)
#define __NR_timer_getoverrun	(__NR_timer_create+3)
#define __NR_timer_delete	(__NR_timer_create+4)
#define __NR_clock_settime	(__NR_timer_create+5)
#define __NR_clock_gettime	(__NR_timer_create+6)
#define __NR_clock_getres	(__NR_timer_create+7)
#define __NR_clock_nanosleep	(__NR_timer_create+8)
/* Number 263 is reserved for vserver */
#define __NR_fadvise64_64	264
#define __NR_statfs64		265
#define __NR_fstatfs64		266
#define __NR_remap_file_pages	267
/* Number 268 is reserved for new sys_mbind */
/* Number 269 is reserved for new sys_get_mempolicy */
/* Number 270 is reserved for new sys_set_mempolicy */
#define __NR_mq_open		271
#define __NR_mq_unlink		272
#define __NR_mq_timedsend	273
#define __NR_mq_timedreceive	274
#define __NR_mq_notify		275
#define __NR_mq_getsetattr	276
#define __NR_kexec_load		277
#define __NR_add_key		278
#define __NR_request_key	279
#define __NR_keyctl		280
#define __NR_waitid		281
#define __NR_ioprio_set		282
#define __NR_ioprio_get		283
#define __NR_inotify_init	284
#define __NR_inotify_add_watch	285
#define __NR_inotify_rm_watch	286
/* Number 287 is reserved for new sys_migrate_pages */
#define __NR_openat		288
#define __NR_mkdirat		289
#define __NR_mknodat		290
#define __NR_fchownat		291
#define __NR_futimesat		292
#define __NR_unlinkat		294
#define __NR_renameat		295
#define __NR_linkat		296
#define __NR_symlinkat		297
#define __NR_readlinkat		298
#define __NR_fchmodat		299
#define __NR_faccessat		300
#define __NR_pselect6		301
#define __NR_ppoll		302
#define __NR_unshare		303
#define __NR_set_robust_list	304
#define __NR_get_robust_list	305
#define __NR_splice		306
#define __NR_sync_file_range	307
#define __NR_tee		308
#define __NR_vmsplice		309
/* Number 310 is reserved for new sys_move_pages */
#define __NR_getcpu		311
#define __NR_epoll_pwait	312
#define __NR_utimes		313
#define __NR_fallocate		314
#define __NR_utimensat		315
#define __NR_signalfd		316
#define __NR_timerfd		317
#define __NR_eventfd		318
#define __NR_timerfd_create	319
#define __NR_timerfd_settime	320
#define __NR_timerfd_gettime	321


/* 
 * There are some system calls that are not present on 64 bit, some
 * have a different name although they do the same (e.g. __NR_chown32
 * is __NR_chown on 64 bit).
 */
#ifdef __s390x__
#undef  __NR_time
#undef  __NR_lchown
#undef  __NR_setuid
#undef  __NR_getuid
#undef  __NR_stime
#undef  __NR_setgid
#undef  __NR_getgid
#undef  __NR_geteuid
#undef  __NR_getegid
#undef  __NR_setreuid
#undef  __NR_setregid
#undef  __NR_getrlimit
#undef  __NR_getgroups
#undef  __NR_setgroups
#undef  __NR_fchown
#undef  __NR_ioperm
#undef  __NR_setfsuid
#undef  __NR_setfsgid
#undef  __NR__llseek
#undef  __NR__newselect
#undef  __NR_setresuid
#undef  __NR_getresuid
#undef  __NR_setresgid
#undef  __NR_getresgid
#undef  __NR_chown
#undef  __NR_ugetrlimit
#undef  __NR_mmap2
#undef  __NR_truncate64
#undef  __NR_ftruncate64
#undef  __NR_stat64
#undef  __NR_lstat64
#undef  __NR_fstat64
#undef  __NR_lchown32
#undef  __NR_getuid32
#undef  __NR_getgid32
#undef  __NR_geteuid32
#undef  __NR_getegid32
#undef  __NR_setreuid32
#undef  __NR_setregid32
#undef  __NR_getgroups32
#undef  __NR_setgroups32
#undef  __NR_fchown32
#undef  __NR_setresuid32
#undef  __NR_getresuid32
#undef  __NR_setresgid32
#undef  __NR_getresgid32
#undef  __NR_chown32
#undef  __NR_setuid32
#undef  __NR_setgid32
#undef  __NR_setfsuid32
#undef  __NR_setfsgid32
#undef  __NR_getdents64
#undef  __NR_fcntl64
#undef  __NR_sendfile64
#undef  __NR_fadvise64_64
#undef  __NR_fstatat64

#define __NR_select		142
#define __NR_getrlimit		191	/* SuS compliant getrlimit */
#define __NR_lchown  		198
#define __NR_getuid  		199
#define __NR_getgid  		200
#define __NR_geteuid  		201
#define __NR_getegid  		202
#define __NR_setreuid  		203
#define __NR_setregid  		204
#define __NR_getgroups  	205
#define __NR_setgroups  	206
#define __NR_fchown  		207
#define __NR_setresuid  	208
#define __NR_getresuid  	209
#define __NR_setresgid  	210
#define __NR_getresgid  	211
#define __NR_chown  		212
#define __NR_setuid  		213
#define __NR_setgid  		214
#define __NR_setfsuid  		215
#define __NR_setfsgid  		216
#define __NR_newfstatat		293

#endif

#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,@function; \
.weak wsym; \
wsym: ; \
.type sym,@function; \
.global sym; \
sym: \
	.if __NR_##name < 256 ; \
	svc __NR_##name ; \
	.else ; \
	la %r1,__NR_##name ; \
	svc 0 ; \
	.endif ; \
	j __unified_syscall

#define syscall(name,sym) \
.text; \
.type sym,@function; \
.global sym; \
sym: \
	.if __NR_##name < 256 ; \
	svc __NR_##name ; \
	.else ; \
	la %r1,__NR_##name ; \
	svc 0 ; \
	.endif ; \
	j __unified_syscall

dietlibc-0.33~cvs20120325/s390x/unified.S010064400000000000000000000012641173363230200143360ustar00#include 
#include "syscalls.h"

.text
.weak exit
.type exit,@function
exit:
.global _exit
.type   _exit,@function
_exit:
	svc	__NR_exit
.global __unified_syscall
__unified_syscall:
	lghi	%r4,-127
	clr	%r2,%r4
	jl	.Lnoerror

.global __error_unified_syscall
__error_unified_syscall:
#ifdef WANT_THREAD_SAFE
	stmg	%r13,%r15,104(%r15)
	lgr	%r0,%r15
	aghi	%r15,-160
	stg	%r0,0(%r15)

	lcr	%r13,%r2
	brasl	%r14,__errno_location
	st	%r13,0(%r2)

	lg	%r15,0(%r15)
	lmg	%r13,%r15,104(%r15)
#else
	lcr	%r1,%r2
	larl	%r3,errno
	st	%r1,0(%r3)
#endif
	lghi	%r2,-1

.Lnoerror:

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	br	%r14

.align 4
dietlibc-0.33~cvs20120325/sparc/Makefile.add010064400000000000000000000002431173363230200151740ustar00
CFLAGS+=-mcpu=supersparc -Os
VPATH:=sparc:syscalls.s:$(VPATH)
LIBOBJ+=$(OBJDIR)/udiv.o $(OBJDIR)/umul.o $(OBJDIR)/urem.o
LIBOBJ+=$(OBJDIR)/rem.o $(OBJDIR)/sdiv.o
dietlibc-0.33~cvs20120325/sparc/__longjmp.S010064400000000000000000000043331173363230200151010ustar00#include 

#define JB_SP  0
#define JB_FP  1
#define JB_PC  2

#define ENV(base,reg) [%base + (reg * 4)]
#define ST_FLUSH_WINDOWS 3
#define RW_FP [%fp + 0x48]

.text
.global __longjmp
.type __longjmp,function
__longjmp:
	/* Store our arguments in global registers so we can still
	   use them while unwinding frames and their register windows.  */

	ld ENV(o0,JB_FP), %g3   /* Cache target FP in register %g3.  */
	mov %o0, %g1            /* ENV in %g1 */
	orcc %o1, %g0, %g2      /* VAL in %g2 */
	be,a 0f                 /* Branch if zero; else skip delay slot.  */
	 mov 1, %g2             /* Delay slot only hit if zero: VAL = 1.  */
0:
	xor %fp, %g3, %o0
	add %fp, 512, %o1
	andncc %o0, 4095, %o0
	bne .Lthread
	 cmp %o1, %g3
	bl .Lthread

	/* Now we will loop, unwinding the register windows up the stack
	   until the restored %fp value matches the target value in %g3.  */

.Lloop:
	cmp %fp, %g3            /* Have we reached the target frame? */
	bl,a .Lloop             /* Loop while current fp is below target.  */
	 restore                /* Unwind register window in delay slot.  */
	be,a .Lfound            /* Better have hit it exactly.  */
	 ld ENV(g1,JB_SP), %o0  /* Delay slot: extract target SP.  */

.Lthread:
	/*
	 * Do a "flush register windows trap".  The trap handler in the
	 * kernel writes all the register windows to their stack slots, and
	 * marks them all as invalid (needing to be sucked up from the
	 * stack when used).  This ensures that all information needed to
	 * unwind to these callers is in memory, not in the register
	 * windows.
	 */
	ta      ST_FLUSH_WINDOWS
	ld      ENV(g1,JB_PC), %o7 /* Set return PC. */
	ld      ENV(g1,JB_SP), %fp /* Set saved SP on restore below. */
	sub     %fp, 64, %sp    /* Allocate a register frame. */
	st      %g3, RW_FP      /* Set saved FP on restore below. */
	retl
	 restore %g2, 0, %o0    /* Restore values from above register frame. */

.Lfound:
	/* We have unwound register windows so %fp matches the target.  */
	mov %o0, %sp            /* OK, install new SP.  */

.Lsp_ok:
	ld ENV(g1,JB_PC), %o0   /* Extract target return PC.  */
	jmp %o0 + 8             /* Return there.  */
	 mov %g2, %o0           /* Delay slot: set return value.  */

.size __longjmp, . - __longjmp

dietlibc-0.33~cvs20120325/sparc/__testandset.S010064400000000000000000000001131173363230200156010ustar00.text
.align 4
.global __testandset
__testandset:
	retl
	ldstub	[%o0], %o0
dietlibc-0.33~cvs20120325/sparc/atol.S010064400000000000000000000012411173363230200140670ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    atol.S
      sparc assembler implementation of atol(3)
*/

.text
.globl atol
.globl atoi
atoi:
atol:
	clr %o3
1:
	ldub [%o0], %o1
	tst %o1
	be .Lret
	cmp %o1, 0x20
	ble,a 1b
	inc %o0
	cmp %o1, '-'
	be,a .Lload
	mov 1, %o5
	clr %o5
2:
	subcc %o1, '0', %o1
	bneg .Lret
	cmp %o1, 0x9
	bg .Lret
	add %o3, %o3, %o4
	sll %o3, 3, %o3
	add %o3, %o4, %o3
	add %o1, %o3, %o3
.Lload:
	inc %o0
	b 2b
	ldub [%o0], %o1
.Lret:
	tst %o5
	bne,a .Lretl
	neg %o3
.Lretl:
	retl
	mov %o3, %o0
dietlibc-0.33~cvs20120325/sparc/clone.S010064400000000000000000000013371173363230200142360ustar00#include 
#include "syscalls.h"

.text
.align 4
.weak clone
clone:
.type __clone,#function
.global __clone
__clone:
	save	%sp, -96, %sp

	tst	%i0		/* check for function pointer */
	be	.Lerror
	tst	%i1		/* check for stack pointer */
	be	.Lerror
	nop

	mov	%i1, %o1	/* child-stack */
	mov	%i2, %o0	/* clone-flags */
	mov	__NR_clone, %g1
	ta	0x10		/* syscall: clone */
	bcs	.Lerror

	tst	%o1
	bne	.Lstart		/* we are the child :) */
	nop
	ret
	restore %o0, %g0, %o0	/* return child pid */

.Lerror:
	call	__errno_location
	mov	EINVAL, %l0
	st	%l0, [%o0]
	ret
	restore	%g0, -1, %o0

.Lstart:
	call	%i0		/* call child-function */
	mov	%i3, %o0	/* put arg in the right place for the child */

	call	_exit		/* child returned */
	nop

dietlibc-0.33~cvs20120325/sparc/errlist.S010064400000000000000000000166221173363230200146250ustar00#ifdef __DYN_LIB
.section	.data
#else
.section	.rodata
#endif

.align 4
.global sys_errlist
.type	sys_errlist,@object
sys_errlist:
	.long .LC000
	.long .LC001
	.long .LC002
	.long .LC003
	.long .LC004
	.long .LC005
	.long .LC006
	.long .LC007
	.long .LC008
	.long .LC009
	.long .LC010
	.long .LC011
	.long .LC012
	.long .LC013
	.long .LC014
	.long .LC015
	.long .LC016
	.long .LC017
	.long .LC018
	.long .LC019
	.long .LC020
	.long .LC021
	.long .LC022
	.long .LC023
	.long .LC024
	.long .LC025
	.long .LC026
	.long .LC027
	.long .LC028
	.long .LC029
	.long .LC030
	.long .LC031
	.long .LC032
	.long .LC033
	.long .LC034
	.long .LC035
	.long .LC036
	.long .LC037
	.long .LC038
	.long .LC039
	.long .LC040
	.long .LC041
	.long .LC042
	.long .LC043
	.long .LC044
	.long .LC045
	.long .LC046
	.long .LC047
	.long .LC048
	.long .LC049
	.long .LC050
	.long .LC051
	.long .LC052
	.long .LC053
	.long .LC054
	.long .LC055
	.long .LC056
	.long .LC057
	.long .LC058
	.long .LC059
	.long .LC060
	.long .LC061
	.long .LC062
	.long .LC063
	.long .LC064
	.long .LC065
	.long .LC066
	.long .LC067
	.long .LC068
	.long .LC069
	.long .LC070
	.long .LC071
	.long .LC072
	.long .LC073
	.long .LC074
	.long .LC075
	.long .LC076
	.long .LC077
	.long .LC078
	.long .LC079
	.long .LC080
	.long .LC081
	.long .LC082
	.long .LC083
	.long .LC084
	.long .LC085
	.long .LC086
	.long .LC087
	.long .LC088
	.long .LC089
	.long .LC090
	.long .LC091
	.long .LC092
	.long .LC093
	.long .LC094
	.long .LC095
	.long .LC096
	.long .LC097
	.long .LC098
	.long .LC099
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC100
	.long .LC120
	.long .LC121
	.long .LC122
	.long .LC123
	.long .LC124
	.long .LC125
	.long .LC126
	.long .LC127
	.long .LC128
	.long .LC129
	.long .LC130
	.long .LC131
	.long 0
.size sys_errlist,.-sys_errlist

.align 4
.global sys_nerr
.type	sys_nerr,@object
sys_nerr:
	.long 127
.size	 sys_nerr,4

#ifdef __DYN_LIB
.section	.rodata
#endif

.LC000:	.string	"Success"
.LC001: .string "Operation not permitted"
.LC002: .string "No such file or directory"
.LC003: .string "No such process"
.LC004: .string "Interrupted system call"
.LC005: .string "I/O error"
.LC006: .string "No such device or address"
.LC007: .string "Arg list too long"
.LC008: .string "Exec format error"
.LC009: .string "Bad file number"
.LC010: .string "No child processes"
.LC011: .string "Try again"
.LC012: .string "Out of memory"
.LC013: .string "Permission denied"
.LC014: .string "Bad address"
.LC015: .string "Block device required"
.LC016: .string "Device or resource busy"
.LC017: .string "File exists"
.LC018: .string "Cross-device link"
.LC019: .string "No such device"
.LC020: .string "Not a directory"
.LC021: .string "Is a directory"
.LC022: .string "Invalid argument"
.LC023: .string "File table overflow"
.LC024: .string "Too many open files"
.LC025: .string "Not a typewriter"
.LC026: .string "Text file busy"
.LC027: .string "File too large"
.LC028: .string "No space left on device"
.LC029: .string "Illegal seek"
.LC030: .string "Read-only file system"
.LC031: .string "Too many links"
.LC032: .string "Broken pipe"
.LC033: .string "Math argument out of domain of func"
.LC034: .string "Math result not representable"
.LC035: .string "Operation would block"
.LC036: .string "Operation now in progress"
.LC037: .string "Operation already in progress"
.LC038: .string "Socket operation on non-socket"
.LC039: .string "Destination address required"
.LC040: .string "Message too long"
.LC041: .string "Protocol wrong type for socket"
.LC042: .string "Protocol not available"
.LC043: .string "Protocol not supported"
.LC044: .string "Socket type not supported"
.LC045: .string "Op not supported on transport endpoint"
.LC046: .string "Protocol family not supported"
.LC047: .string "Address family not supported by protocol"
.LC048: .string "Address already in use"
.LC049: .string "Cannot assign requested address"
.LC050: .string "Network is down"
.LC051: .string "Network is unreachable"
.LC052: .string "Net dropped connection because of reset"
.LC053: .string "Software caused connection abort"
.LC054: .string "Connection reset by peer"
.LC055: .string "No buffer space available"
.LC056: .string "Transport endpoint is already connected"
.LC057: .string "Transport endpoint is not connected"
.LC058: .string "No send after transport endpoint shutdown"
.LC059: .string "Too many references: cannot splice"
.LC060: .string "Connection timed out"
.LC061: .string "Connection refused"
.LC062: .string "Too many symbolic links encountered"
.LC063: .string "File name too long"
.LC064: .string "Host is down"
.LC065: .string "No route to host"
.LC066: .string "Directory not empty"
.LC067: .string "SUNOS: Too many processes"
.LC068: .string "Too many users"
.LC069: .string "Quota exceeded"
.LC070: .string "Stale NFS file handle"
.LC071: .string "Object is remote"
.LC072: .string "Device not a stream"
.LC073: .string "Timer expired"
.LC074: .string "Out of streams resources"
.LC075: .string "No message of desired type"
.LC076: .string "Not a data message"
.LC077: .string "Identifier removed"
.LC078: .string "Resource deadlock would occur"
.LC079: .string "No record locks available"
.LC080: .string "Machine is not on the network"
.LC081: .string "SunOS: Too many lvls of remote in path"
.LC082: .string "Link has been severed"
.LC083: .string "Advertise error"
.LC084: .string "Srmount error"
.LC085: .string "Communication error on send"
.LC086: .string "Protocol error"
.LC087: .string "Multihop attempted"
.LC088: .string "RFS specific error"
.LC089: .string "Remote address changed"
.LC090: .string "Function not implemented"
.LC091: .string "Streams pipe error"
.LC092: .string "Value too large for defined data type"
.LC093: .string "File descriptor in bad state"
.LC094: .string "Channel number out of range"
.LC095: .string "Level 2 not synchronized"
.LC096: .string "Level 3 halted"
.LC097: .string "Level 3 reset"
.LC098: .string "Link number out of range"
.LC099: .string "Protocol driver not attached"
.LC100: .string "No CSI structure available"
.LC101: .string "Level 2 halted"
.LC102: .string "Invalid exchange"
.LC103: .string "Invalid request descriptor"
.LC104: .string "Exchange full"
.LC105: .string "No anode"
.LC106: .string "Invalid request code"
.LC107: .string "Invalid slot"
.LC108: .string "File locking deadlock error"
.LC109: .string "Bad font file format"
.LC110: .string "Cannot exec a shared library directly"
.LC111: .string "No data available"
.LC112: .string "Accessing a corrupted shared library"
.LC113: .string "Package not installed"
.LC114: .string "Can not access a needed shared library"
.LC115: .string "Name not unique on network"
.LC116: .string "Interrupted syscall should be restarted"
.LC117: .string "Structure needs cleaning"
.LC118: .string "Not a XENIX named type file"
.LC119: .string "No XENIX semaphores available"
.LC120: .string "Is a named type file"
.LC121: .string "Remote I/O error"
.LC122: .string "Illegal byte sequence"
.LC123: .string "Atmpt to link in too many shared libs"
.LC124: .string ".lib section in a.out corrupted"
.LC125: .string "No medium found"
.LC126: .string "Wrong medium type"
.LC127: .string "Operation Cancelled"
.LC128: .string "Required key not available"
.LC129: .string "Key has expired"
.LC130: .string "Key has been revoked"
.LC131: .string "Key was rejected by service"


dietlibc-0.33~cvs20120325/sparc/fork.S010064400000000000000000000003161173363230200140730ustar00#include 
#include "syscalls.h"

.text
.weak fork
fork:
.global __libc_fork
__libc_fork:
	mov	__NR_fork, %g1
	ta	0x10
	bcs	__unified_syscall_error_handler
	dec	%o1
	retl
	and	%o0, %o1, %o0

dietlibc-0.33~cvs20120325/sparc/memccpy.S010064400000000000000000000007271173363230200145750ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    memccpy.S
      sparc assembler implementation of memccpy(3)
*/

.text
.globl memccpy
memccpy:
	clr %o4
.Lloop:
	subcc %o3, 1, %o3
	bl,a .Lret
	sub %g0, %o4, %o0
	ldsb [%o1+%o4], %o5
	stb %o5, [%o0+%o4]
	cmp %o5, %o2
	bne .Lloop
	inc %o4
.Lret:
	retl
	add %o0, %o4, %o0
dietlibc-0.33~cvs20120325/sparc/memchr.S010064400000000000000000000006351173363230200144110ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    memchr.S
      sparc assembler implementation of memchr(3)
*/

.text
.globl memchr
memchr:
	tst %o2
	be,a .Lret
	xor %o0, %o0, %o0
	ldub [%o0], %o3
	cmp %o3, %o1
	dec %o2
	bne,a memchr
	inc %o0
.Lret:
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/memcmp.S010064400000000000000000000007201173363230200144070ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    memcmp.S
      sparc assembler implementation of memcmp(3)
*/

.text
.globl memcmp
memcmp:
	clr %o5
.Lloop:
	subcc %o2, 1, %o2
	bl,a .Lret
	mov %o3, %o4
	ldub [%o0+%o5], %o3
	ldub [%o1+%o5], %o4
	cmp %o3, %o4
	be,a .Lloop
	inc %o5
.Lret:
	retl
	sub %o3, %o4, %o0
dietlibc-0.33~cvs20120325/sparc/memcpy.S010064400000000000000000000006331173363230200144260ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    memcpy.S
      sparc assembler implementation of memcpy(3)
*/

.text
.globl memcpy
memcpy:
	mov -1, %o3
1:
	subcc %o2, 1, %o2
	bl .Lret
	inc %o3
	ldub [%o1+%o3], %o4
	b 1b
	stb %o4, [%o0+%o3]
.Lret:
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/memmove.S010064400000000000000000000010521173363230200145750ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    memmove.S
      sparc assembler implementation of memmove(3)
*/

.text
.globl memmove
memmove:
	mov %o0, %o5
	mov -1, %o4
	cmp %o0, %o1
	bg,a .Lcopy
	add %o4, %o2, %o4
	inc %o4
.Lcopy:
	subcc %o2, 1, %o2
	bl .Lret
	cmp %o0, %o1
	ldub [%o1+%o4], %o3
	stb %o3, [%o0+%o4]
	bg,a .Lnext
	sub %o4, 2, %o4
.Lnext:
	b .Lcopy
	inc %o4
.Lret:
	retl
	mov %o5, %o0
dietlibc-0.33~cvs20120325/sparc/memset.S010064400000000000000000000005441173363230200144270ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    memset.S
      sparc assembler implementation of memset(3)
*/

.text
.globl memset
memset:
	subcc %o2, 1, %o2
	bge,a memset
	stb %o1, [%o0+%o2]
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/pipe.S010064400000000000000000000003321173363230200140650ustar00#include 
#include "syscalls.h"

.text
.global pipe
pipe:
	mov	%o0, %o2
	mov	__NR_pipe, %g1
	ta	0x10
	bcs	__unified_syscall_error_handler
	nop
	st	%o0, [ %o2 ]
	st	%o1, [ %o2 + 4 ]
	retl
	mov	%g0, %o0

dietlibc-0.33~cvs20120325/sparc/rem.S010064400000000000000000000164071173363230200137250ustar00#ifdef __sparc__
   /* This file is generated from divrem.m4; DO NOT EDIT! */
/*
 * Division and remainder, from Appendix E of the Sparc Version 8
 * Architecture Manual, with fixes from Gordon Irlam.
 */

/*
 * Input: dividend and divisor in %o0 and %o1 respectively.
 *
 * m4 parameters:
 *  .rem	name of function to generate
 *  rem		rem=div => %o0 / %o1; rem=rem => %o0 % %o1
 *  true		true=true => signed; true=false => unsigned
 *
 * Algorithm parameters:
 *  N		how many bits per iteration we try to get (4)
 *  WORDSIZE	total number of bits (32)
 *
 * Derived constants:
 *  TOPBITS	number of bits in the top decade of a number
 *
 * Important variables:
 *  Q		the partial quotient under development (initially 0)
 *  R		the remainder so far, initially the dividend
 *  ITER	number of main division loop iterations required;
 *		equal to ceil(log2(quotient) / N).  Note that this
 *		is the log base (2^N) of the quotient.
 *  V		the current comparand, initially divisor*2^(ITER*N-1)
 *
 * Cost:
 *  Current estimate for non-large dividend is
 *	ceil(log2(quotient) / N) * (10 + 7N/2) + C
 *  A large dividend is one greater than 2^(31-TOPBITS) and takes a
 *  different path, as the upper bits of the quotient must be developed
 *  one bit at a time.
 */



.global   .rem;
.align 4;
.type  .rem ,@function; 

.rem: 
	! compute sign of result; if neither is negative, no problem
	orcc	%o1, %o0, %g0	! either negative?
	bge	2f			! no, go do the divide
	mov	%o0, %g3		! sign of remainder matches %o0
	tst	%o1
	bge	1f
	tst	%o0
	! %o1 is definitely negative; %o0 might also be negative
	bge	2f			! if %o0 not negative...
	sub	%g0, %o1, %o1	! in any case, make %o1 nonneg
1:	! %o0 is negative, %o1 is nonnegative
	sub	%g0, %o0, %o0	! make %o0 nonnegative
2:

	! Ready to divide.  Compute size of quotient; scale comparand.
	orcc	%o1, %g0, %o5
	bne	1f
	mov	%o0, %o3

		! Divide by zero trap.  If it returns, return 0 (about as
		! wrong as possible, but that is what SunOS does...).
		ta	0x02
		retl
		clr	%o0

1:
	cmp	%o3, %o5			! if %o1 exceeds %o0, done
	blu	.Lgot_result		! (and algorithm fails otherwise)
	clr	%o2
	sethi	%hi(1 << (32 - 4 - 1)), %g1
	cmp	%o3, %g1
	blu	.Lnot_really_big
	clr	%o4

	! Here the dividend is >= 2**(31-N) or so.  We must be careful here,
	! as our usual N-at-a-shot divide step will cause overflow and havoc.
	! The number of bits in the result here is N*ITER+SC, where SC <= N.
	! Compute ITER in an unorthodox manner: know we need to shift V into
	! the top decade: so do not even bother to compare to R.
	1:
		cmp	%o5, %g1
		bgeu	3f
		mov	1, %g2
		sll	%o5, 4, %o5
		b	1b
		add	%o4, 1, %o4

	! Now compute %g2.
	2:	addcc	%o5, %o5, %o5
		bcc	.Lnot_too_big
		add	%g2, 1, %g2

		! We get here if the %o1 overflowed while shifting.
		! This means that %o3 has the high-order bit set.
		! Restore %o5 and subtract from %o3.
		sll	%g1, 4, %g1	! high order bit
		srl	%o5, 1, %o5		! rest of %o5
		add	%o5, %g1, %o5
		b	.Ldo_single_div
		sub	%g2, 1, %g2

	.Lnot_too_big:
	3:	cmp	%o5, %o3
		blu	2b
		nop
		be	.Ldo_single_div
		nop
	/* NB: these are commented out in the V8-Sparc manual as well */
	/* (I do not understand this) */
	! %o5 > %o3: went too far: back up 1 step
	!	srl	%o5, 1, %o5
	!	dec	%g2
	! do single-bit divide steps
	!
	! We have to be careful here.  We know that %o3 >= %o5, so we can do the
	! first divide step without thinking.  BUT, the others are conditional,
	! and are only done if %o3 >= 0.  Because both %o3 and %o5 may have the high-
	! order bit set in the first step, just falling into the regular
	! division loop will mess up the first time around.
	! So we unroll slightly...
	.Ldo_single_div:
		subcc	%g2, 1, %g2
		bl	.Lend_regular_divide
		nop
		sub	%o3, %o5, %o3
		mov	1, %o2
		b	.Lend_single_divloop
		nop
	.Lsingle_divloop:
		sll	%o2, 1, %o2
		bl	1f
		srl	%o5, 1, %o5
		! %o3 >= 0
		sub	%o3, %o5, %o3
		b	2f
		add	%o2, 1, %o2
	1:	! %o3 < 0
		add	%o3, %o5, %o3
		sub	%o2, 1, %o2
	2:
	.Lend_single_divloop:
		subcc	%g2, 1, %g2
		bge	.Lsingle_divloop
		tst	%o3
		b,a	.Lend_regular_divide

.Lnot_really_big:
1:
	sll	%o5, 4, %o5
	cmp	%o5, %o3
	bleu	1b
	addcc	%o4, 1, %o4
	be	.Lgot_result
	sub	%o4, 1, %o4

	tst	%o3	! set up for initial iteration
.Ldivloop:
	sll	%o2, 4, %o2
		! depth 1, accumulated bits 0
	bl	.L1.16
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 2, accumulated bits 1
	bl	.L2.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits 3
	bl	.L3.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 7
	bl	.L4.23
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2+1), %o2
	
.L4.23:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2-1), %o2
	
	
.L3.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 5
	bl	.L4.21
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2+1), %o2
	
.L4.21:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2-1), %o2
	
	
	
.L2.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits 1
	bl	.L3.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 3
	bl	.L4.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2+1), %o2
	
.L4.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2-1), %o2
	
	
.L3.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 1
	bl	.L4.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2+1), %o2
	
.L4.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2-1), %o2
	
	
	
	
.L1.16:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 2, accumulated bits -1
	bl	.L2.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits -1
	bl	.L3.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -1
	bl	.L4.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2+1), %o2
	
.L4.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2-1), %o2
	
	
.L3.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -3
	bl	.L4.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2+1), %o2
	
.L4.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2-1), %o2
	
	
	
.L2.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits -3
	bl	.L3.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -5
	bl	.L4.11
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2+1), %o2
	
.L4.11:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2-1), %o2
	
	
.L3.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -7
	bl	.L4.9
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2+1), %o2
	
.L4.9:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2-1), %o2
	
	
	
	
	9:
.Lend_regular_divide:
	subcc	%o4, 1, %o4
	bge	.Ldivloop
	tst	%o3
	bl,a	.Lgot_result
	! non-restoring fixup here (one instruction only!)
	add	%o3, %o1, %o3


.Lgot_result:
	! check to see if answer should be < 0
	tst	%g3
	bl,a	1f
	sub %g0, %o3, %o3
1:
	retl
	mov %o3, %o0

.size .rem,.-.rem;
#endif
dietlibc-0.33~cvs20120325/sparc/sdiv.S010064400000000000000000000164041173363230200141040ustar00#ifdef __sparc__
   /* This file is generated from divrem.m4; DO NOT EDIT! */
/*
 * Division and remainder, from Appendix E of the Sparc Version 8
 * Architecture Manual, with fixes from Gordon Irlam.
 */

/*
 * Input: dividend and divisor in %o0 and %o1 respectively.
 *
 * m4 parameters:
 *  .div	name of function to generate
 *  div		div=div => %o0 / %o1; div=rem => %o0 % %o1
 *  true		true=true => signed; true=false => unsigned
 *
 * Algorithm parameters:
 *  N		how many bits per iteration we try to get (4)
 *  WORDSIZE	total number of bits (32)
 *
 * Derived constants:
 *  TOPBITS	number of bits in the top decade of a number
 *
 * Important variables:
 *  Q		the partial quotient under development (initially 0)
 *  R		the remainder so far, initially the dividend
 *  ITER	number of main division loop iterations required;
 *		equal to ceil(log2(quotient) / N).  Note that this
 *		is the log base (2^N) of the quotient.
 *  V		the current comparand, initially divisor*2^(ITER*N-1)
 *
 * Cost:
 *  Current estimate for non-large dividend is
 *	ceil(log2(quotient) / N) * (10 + 7N/2) + C
 *  A large dividend is one greater than 2^(31-TOPBITS) and takes a
 *  different path, as the upper bits of the quotient must be developed
 *  one bit at a time.
 */



.global   .div;
.align 4;
.type  .div ,@function; 

.div: 
	! compute sign of result; if neither is negative, no problem
	orcc	%o1, %o0, %g0	! either negative?
	bge	2f			! no, go do the divide
	xor	%o1, %o0, %g3	! compute sign in any case
	tst	%o1
	bge	1f
	tst	%o0
	! %o1 is definitely negative; %o0 might also be negative
	bge	2f			! if %o0 not negative...
	sub	%g0, %o1, %o1	! in any case, make %o1 nonneg
1:	! %o0 is negative, %o1 is nonnegative
	sub	%g0, %o0, %o0	! make %o0 nonnegative
2:

	! Ready to divide.  Compute size of quotient; scale comparand.
	orcc	%o1, %g0, %o5
	bne	1f
	mov	%o0, %o3

		! Divide by zero trap.  If it returns, return 0 (about as
		! wrong as possible, but that is what SunOS does...).
		ta	0x02
		retl
		clr	%o0

1:
	cmp	%o3, %o5			! if %o1 exceeds %o0, done
	blu	.Lgot_result		! (and algorithm fails otherwise)
	clr	%o2
	sethi	%hi(1 << (32 - 4 - 1)), %g1
	cmp	%o3, %g1
	blu	.Lnot_really_big
	clr	%o4

	! Here the dividend is >= 2**(31-N) or so.  We must be careful here,
	! as our usual N-at-a-shot divide step will cause overflow and havoc.
	! The number of bits in the result here is N*ITER+SC, where SC <= N.
	! Compute ITER in an unorthodox manner: know we need to shift V into
	! the top decade: so do not even bother to compare to R.
	1:
		cmp	%o5, %g1
		bgeu	3f
		mov	1, %g2
		sll	%o5, 4, %o5
		b	1b
		add	%o4, 1, %o4

	! Now compute %g2.
	2:	addcc	%o5, %o5, %o5
		bcc	.Lnot_too_big
		add	%g2, 1, %g2

		! We get here if the %o1 overflowed while shifting.
		! This means that %o3 has the high-order bit set.
		! Restore %o5 and subtract from %o3.
		sll	%g1, 4, %g1	! high order bit
		srl	%o5, 1, %o5		! rest of %o5
		add	%o5, %g1, %o5
		b	.Ldo_single_div
		sub	%g2, 1, %g2

	.Lnot_too_big:
	3:	cmp	%o5, %o3
		blu	2b
		nop
		be	.Ldo_single_div
		nop
	/* NB: these are commented out in the V8-Sparc manual as well */
	/* (I do not understand this) */
	! %o5 > %o3: went too far: back up 1 step
	!	srl	%o5, 1, %o5
	!	dec	%g2
	! do single-bit divide steps
	!
	! We have to be careful here.  We know that %o3 >= %o5, so we can do the
	! first divide step without thinking.  BUT, the others are conditional,
	! and are only done if %o3 >= 0.  Because both %o3 and %o5 may have the high-
	! order bit set in the first step, just falling into the regular
	! division loop will mess up the first time around.
	! So we unroll slightly...
	.Ldo_single_div:
		subcc	%g2, 1, %g2
		bl	.Lend_regular_divide
		nop
		sub	%o3, %o5, %o3
		mov	1, %o2
		b	.Lend_single_divloop
		nop
	.Lsingle_divloop:
		sll	%o2, 1, %o2
		bl	1f
		srl	%o5, 1, %o5
		! %o3 >= 0
		sub	%o3, %o5, %o3
		b	2f
		add	%o2, 1, %o2
	1:	! %o3 < 0
		add	%o3, %o5, %o3
		sub	%o2, 1, %o2
	2:
	.Lend_single_divloop:
		subcc	%g2, 1, %g2
		bge	.Lsingle_divloop
		tst	%o3
		b,a	.Lend_regular_divide

.Lnot_really_big:
1:
	sll	%o5, 4, %o5
	cmp	%o5, %o3
	bleu	1b
	addcc	%o4, 1, %o4
	be	.Lgot_result
	sub	%o4, 1, %o4

	tst	%o3	! set up for initial iteration
.Ldivloop:
	sll	%o2, 4, %o2
		! depth 1, accumulated bits 0
	bl	.L1.16
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 2, accumulated bits 1
	bl	.L2.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits 3
	bl	.L3.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 7
	bl	.L4.23
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2+1), %o2
	
.L4.23:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2-1), %o2
	
	
.L3.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 5
	bl	.L4.21
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2+1), %o2
	
.L4.21:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2-1), %o2
	
	
	
.L2.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits 1
	bl	.L3.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 3
	bl	.L4.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2+1), %o2
	
.L4.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2-1), %o2
	
	
.L3.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 1
	bl	.L4.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2+1), %o2
	
.L4.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2-1), %o2
	
	
	
	
.L1.16:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 2, accumulated bits -1
	bl	.L2.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits -1
	bl	.L3.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -1
	bl	.L4.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2+1), %o2
	
.L4.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2-1), %o2
	
	
.L3.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -3
	bl	.L4.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2+1), %o2
	
.L4.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2-1), %o2
	
	
	
.L2.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits -3
	bl	.L3.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -5
	bl	.L4.11
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2+1), %o2
	
.L4.11:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2-1), %o2
	
	
.L3.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -7
	bl	.L4.9
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2+1), %o2
	
.L4.9:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2-1), %o2
	
	
	
	
	9:
.Lend_regular_divide:
	subcc	%o4, 1, %o4
	bge	.Ldivloop
	tst	%o3
	bl,a	.Lgot_result
	! non-restoring fixup here (one instruction only!)
	sub	%o2, 1, %o2


.Lgot_result:
	! check to see if answer should be < 0
	tst	%g3
	bl,a	1f
	sub %g0, %o2, %o2
1:
	retl
	mov %o2, %o0

.size .div,.-.div;
#endif
dietlibc-0.33~cvs20120325/sparc/setjmp.S010064400000000000000000000012401173363230200144310ustar00#include 

#define JB_SP  0
#define JB_FP  1
#define JB_PC  2

#define ST_FLUSH_WINDOWS        0x03

.text
.globl __setjmp
.type __setjmp,function
__setjmp:
	b	1f
	set	0, %o1
.size __setjmp,.-__setjmp

.globl setjmp
.type setjmp,function
setjmp:
	set	1, %o1
.size setjmp,.-setjmp

.globl __sigsetjmp
.type __sigsetjmp,function
__sigsetjmp:
1:
	/* Save our PC, SP and FP.  Save the signal mask if requested with
	   a tail-call for simplicity; it always returns zero.  */
	ta	ST_FLUSH_WINDOWS

	st	%o7, [%o0 + (JB_PC * 4)]
	st	%sp, [%o0 + (JB_SP * 4)]
	st	%fp, [%o0 + (JB_FP * 4)]

	mov	%o7, %g1
	call	__sigjmp_save
	mov	%g1, %o7
.size __sigsetjmp,.-__sigsetjmp

dietlibc-0.33~cvs20120325/sparc/shmat.c010064400000000000000000000006201173363230200142640ustar00#include 
#include 
#include 
#include 

extern void* __ipc();

#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
#endif

void* shmat(int shmid,const void* shmaddr,int shmflg) {
  void* raddr;
  register void* result;
  result=__ipc(SHMAT,shmid,shmflg,&raddr,shmaddr);
  if ((unsigned long)result <= -(unsigned long)PAGE_SIZE)
    result=raddr;
  return result;
}
dietlibc-0.33~cvs20120325/sparc/sigaction.c010064400000000000000000000007701173363230200151360ustar00#include 

int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, void* restorer, long nr);

int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
  return __rt_sigaction(signum, act, oldact, 0, _NSIG/8);
}
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
__attribute__((weak,alias("__libc_sigaction")));

dietlibc-0.33~cvs20120325/sparc/start.S010064400000000000000000000020441173363230200142670ustar00#include "dietfeatures.h"

	.section ".text"
	.align 4
	.global _start
	.type _start,@function
_start:

/* Terminate the stack frame, and reserve space for functions to
   drop their arguments.  */
	mov	%g0, %fp
	sub	%sp, 6*4, %sp

/* Extract the arguments and environment as encoded on the stack.  The
   argument info starts after one register window (16 words) past the SP.  */
	ld	[%sp+22*4], %o0
	add	%sp, 23*4, %o1
	add	%o1, %o0, %o2
	add	%o2, %o0, %o2
	add	%o2, %o0, %o2
	add	%o2, %o0, %o2
	add	%o2, 4, %o2

	sethi	%hi(environ), %o3
	or	%o3, %lo(environ), %o3
	st	%o2, [%o3]

/* When starting a binary via the dynamic linker, %g1 contains the
   address of the shared library termination function, which will be
   registered with atexit(). If we are statically linked, this will
   be NULL.  */

/* Let libc do the rest of the initialization, and call main.  */
#ifdef WANT_DYNAMIC
	call	_dyn_start
#else
	call	CALL_IN_STARTCODE
#endif
	mov	%g1, %o3

	b	exit
	mov %o0, %i0

/* Die very horribly if exit returns.  */
	ret
	nop

	.size _start, .-_start

dietlibc-0.33~cvs20120325/sparc/strcat.S010064400000000000000000000007071173363230200144360ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strcat.S
      sparc assembler implementation of strcat(3)
*/

.text
.globl strcat
strcat:
	mov %o0, %o4
1:
	ldub [%o0], %o2
	tst %o2
	bne,a 1b
	inc %o0
	clr %o3
2:
	ldub [%o1+%o3], %o2
	stb %o2, [%o0+%o3]
	tst %o2
	bne,a 2b
	inc %o3
	retl
	mov %o4, %o0
dietlibc-0.33~cvs20120325/sparc/strchr.S010064400000000000000000000006141173363230200144400ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strchr.S
      sparc assembler implementation of strchr(3)
*/

.text
.globl strchr
strchr:
	ldub [%o0], %o2
	cmp %o2, %o1
	be .Lfound
	tst %o2
	bne,a strchr
	inc %o0
	clr %o0
.Lfound:
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/strcmp.S010064400000000000000000000006661173363230200144520ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strcmp.S
      sparc assembler implementation of strcmp(3)
*/

.text
.globl strcmp
strcmp:
	clr %o4
.Lloop:
	ldub [%o0+%o4], %o2
	ldub [%o1+%o4], %o3
	tst %o2
	be .Lret
	cmp %o2, %o3
	be,a .Lloop
	inc %o4
.Lret:
	retl
	sub %o2, %o3, %o0
dietlibc-0.33~cvs20120325/sparc/strcpy.S010064400000000000000000000006021173363230200144540ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strcpy.S
      sparc assembler implementation of strcpy(3)
*/

.text
.globl strcpy
strcpy:
	clr %o2
1:
	ldub [%o1+%o2], %o3
	stb  %o3, [%o0+%o2]
	tst  %o3
	bne,a 1b
	inc %o2
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/strlen.S010064400000000000000000000002511173363230200144370ustar00.text
.globl strlen
strlen:
    add  %o0, 1, %o1
.Lloop:
    ldsb [%o0], %o2
    orcc %o2, %o2, %g0
    bne  .Lloop
    add  %o0, 1, %o0
    retl
    sub  %o0, %o1, %o0
dietlibc-0.33~cvs20120325/sparc/strncmp.S010064400000000000000000000007451173363230200146260ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strncmp.S
      sparc assembler implementation of strncmp(3)
*/

.text
.globl strncmp
strncmp:
	clr %o5
1:
	subcc %o2, 1, %o2
	bl,a .Lret
	add %g0, %o3, %o4
	ldub [%o0+%o5], %o3
	ldub [%o1+%o5], %o4
	cmp %o4, %o3
	bne .Lret
	tst %o4
	bne,a 1b
	inc %o5
.Lret:
	retl
	sub %o3, %o4, %o0
dietlibc-0.33~cvs20120325/sparc/strncpy.S010064400000000000000000000007321173363230200146360ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strncpy.S
      sparc assembler implementation of strncpy(3)
*/

.text
.globl strncpy
strncpy:
	clr %o4
.Lloop:
	subcc %o2, 1, %o2
	bl .Lret
	nop                 ! "dst" may be NULL
	ldub [%o1+%o4], %o3
	stb %o3, [%o0+%o4]
	tst %o3
	bne,a .Lloop
	inc %o4
.Lret:
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/strstr.S010064400000000000000000000011161173363230200144720ustar00/*
    Copyright (C) 2003 Thomas M. Ogrisegg 

    This is free software. You can redistribute and
    modify it under the terms of the GNU General Public
    Public License.

    strstr.S
      sparc assembler implementation of strstr(3)
*/

.text
.globl strstr
strstr:
	ldub [%o1], %o2
.Lloop:
	ldub [%o0], %o3
	tst %o3
	be,a .Lret
	clr %o0
	cmp %o3, %o2
	bne,a .Lloop
	inc %o0
!-------------------------------
	clr %o5
.Lstrcmp:
	ldub [%o0+%o5], %o3
	ldub [%o1+%o5], %g1
	tst %g1
	be .Lret
	cmp %o3, %g1
	bne,a .Lloop
	inc %o0
	b .Lstrcmp
	inc %o5
.Lret:
	retl
	nop
dietlibc-0.33~cvs20120325/sparc/syscalls.h010064400000000000000000000540131173363230200150170ustar00
#define __NR_exit                 1 /* Common                                      */
#define __NR_fork                 2 /* Common                                      */
#define __NR_read                 3 /* Common                                      */
#define __NR_write                4 /* Common                                      */
#define __NR_open                 5 /* Common                                      */
#define __NR_close                6 /* Common                                      */
#define __NR_wait4                7 /* Common                                      */
#define __NR_creat                8 /* Common                                      */
#define __NR_link                 9 /* Common                                      */
#define __NR_unlink              10 /* Common                                      */
#define __NR_execv               11 /* SunOS Specific                              */
#define __NR_chdir               12 /* Common                                      */
#define __NR_chown		 13 /* Common					   */
#define __NR_mknod               14 /* Common                                      */
#define __NR_chmod               15 /* Common                                      */
#define __NR_lchown              16 /* Common                                      */
#define __NR_brk                 17 /* Common                                      */
#define __NR_perfctr             18 /* Performance counter operations              */
#define __NR_lseek               19 /* Common                                      */
#define __NR_getpid              20 /* Common                                      */
#define __NR_capget		 21 /* Linux Specific				   */
#define __NR_capset		 22 /* Linux Specific				   */
#define __NR_setuid              23 /* Implemented via setreuid in SunOS           */
#define __NR_getuid              24 /* Common                                      */
/* #define __NR_time alias	 25    ENOSYS under SunOS			   */
#define __NR_ptrace              26 /* Common                                      */
#define __NR_alarm               27 /* Implemented via setitimer in SunOS          */
#define __NR_sigaltstack	 28 /* Common					   */
#define __NR_pause               29 /* Is sigblock(0)->sigpause() in SunOS         */
#define __NR_utime               30 /* Implemented via utimes() under SunOS        */
#define __NR_lchown32            31 /* Linux sparc32 specific                      */
#define __NR_fchown32            32 /* Linux sparc32 specific                      */
#define __NR_access              33 /* Common                                      */
#define __NR_nice                34 /* Implemented via get/setpriority() in SunOS  */
#define __NR_chown32             35 /* Linux sparc32 specific                      */
#define __NR_sync                36 /* Common                                      */
#define __NR_kill                37 /* Common                                      */
#define __NR_stat                38 /* Common                                      */
#define __NR_sendfile		 39 /* Linux Specific				   */
#define __NR_lstat               40 /* Common                                      */
#define __NR_dup                 41 /* Common                                      */
#define __NR_pipe                42 /* Common                                      */
#define __NR_times               43 /* Implemented via getrusage() in SunOS        */
#define __NR_getuid32            44 /* Linux sparc32 specific                      */
#define __NR_umount2             45 /* Linux Specific                              */
#define __NR_setgid              46 /* Implemented via setregid() in SunOS         */
#define __NR_getgid              47 /* Common                                      */
#define __NR_signal              48 /* Implemented via sigvec() in SunOS           */
#define __NR_geteuid             49 /* SunOS calls getuid()                        */
#define __NR_getegid             50 /* SunOS calls getgid()                        */
#define __NR_acct                51 /* Common                                      */
/* #define __NR_memory_ordering  52    Linux sparc64 specific			   */
#define __NR_getgid32            53 /* Linux sparc32 specific                      */
#define __NR_ioctl               54 /* Common                                      */
#define __NR_reboot              55 /* Common                                      */
#define __NR_mmap2		 56 /* Linux sparc32 Specific			   */
#define __NR_symlink             57 /* Common                                      */
#define __NR_readlink            58 /* Common                                      */
#define __NR_execve              59 /* Common                                      */
#define __NR_umask               60 /* Common                                      */
#define __NR_chroot              61 /* Common                                      */
#define __NR_fstat               62 /* Common                                      */
#define __NR_fstat64		 63 /* Linux sparc32 Specific			   */
#define __NR_getpagesize         64 /* Common                                      */
#define __NR_msync               65 /* Common in newer 1.3.x revs...               */
#define __NR_vfork               66 /* Common                                      */
#define __NR_pread               67 /* Linux Specific                              */
#define __NR_pwrite              68 /* Linux Specific                              */
#define __NR_geteuid32           69 /* Linux sparc32, sbrk under SunOS             */
#define __NR_getegid32           70 /* Linux sparc32, sstk under SunOS             */
#define __NR_mmap                71 /* Common                                      */
#define __NR_setreuid32          72 /* Linux sparc32, vadvise under SunOS          */
#define __NR_munmap              73 /* Common                                      */
#define __NR_mprotect            74 /* Common                                      */
#define __NR_madvise             75 /* Common                                      */
#define __NR_vhangup             76 /* Common                                      */
#define __NR_truncate64		 77 /* Linux sparc32 Specific			   */
#define __NR_mincore             78 /* Common                                      */
#define __NR_getgroups           79 /* Common                                      */
#define __NR_setgroups           80 /* Common                                      */
#define __NR_getpgrp             81 /* Common                                      */
#define __NR_setgroups32         82 /* Linux sparc32, setpgrp under SunOS          */
#define __NR_setitimer           83 /* Common                                      */
#define __NR_ftruncate64	 84 /* Linux sparc32 Specific			   */
#define __NR_swapon              85 /* Common                                      */
#define __NR_getitimer           86 /* Common                                      */
#define __NR_setuid32            87 /* Linux sparc32, gethostname under SunOS      */
#define __NR_sethostname         88 /* Common                                      */
#define __NR_setgid32            89 /* Linux sparc32, getdtablesize under SunOS    */
#define __NR_dup2                90 /* Common                                      */
#define __NR_setfsuid32          91 /* Linux sparc32, getdopt under SunOS          */
#define __NR_fcntl               92 /* Common                                      */
#define __NR_select              93 /* Common                                      */
#define __NR_setfsgid32          94 /* Linux sparc32, setdopt under SunOS          */
#define __NR_fsync               95 /* Common                                      */
#define __NR_setpriority         96 /* Common                                      */
#define __NR_socket              97 /* Common                                      */
#define __NR_connect             98 /* Common                                      */
#define __NR_accept              99 /* Common                                      */
#define __NR_getpriority        100 /* Common                                      */
#define __NR_rt_sigreturn       101 /* Linux Specific                              */
#define __NR_rt_sigaction       102 /* Linux Specific                              */
#define __NR_rt_sigprocmask     103 /* Linux Specific                              */
#define __NR_rt_sigpending      104 /* Linux Specific                              */
#define __NR_rt_sigtimedwait    105 /* Linux Specific                              */
#define __NR_rt_sigqueueinfo    106 /* Linux Specific                              */
#define __NR_rt_sigsuspend      107 /* Linux Specific                              */
#define __NR_setresuid32        108 /* Linux Specific, sigvec under SunOS	   */
#define __NR_getresuid32        109 /* Linux Specific, sigblock under SunOS	   */
#define __NR_setresgid32        110 /* Linux Specific, sigsetmask under SunOS	   */
#define __NR_getresgid32        111 /* Linux Specific, sigpause under SunOS	   */
#define __NR_setregid32         112 /* Linux sparc32, sigstack under SunOS         */
#define __NR_recvmsg            113 /* Common                                      */
#define __NR_sendmsg            114 /* Common                                      */
#define __NR_getgroups32        115 /* Linux sparc32, vtrace under SunOS           */
#define __NR_gettimeofday       116 /* Common                                      */
#define __NR_getrusage          117 /* Common                                      */
#define __NR_getsockopt         118 /* Common                                      */
#define __NR_getcwd		119 /* Linux Specific				   */
#define __NR_readv              120 /* Common                                      */
#define __NR_writev             121 /* Common                                      */
#define __NR_settimeofday       122 /* Common                                      */
#define __NR_fchown             123 /* Common                                      */
#define __NR_fchmod             124 /* Common                                      */
#define __NR_recvfrom           125 /* Common                                      */
#define __NR_setreuid           126 /* Common                                      */
#define __NR_setregid           127 /* Common                                      */
#define __NR_rename             128 /* Common                                      */
#define __NR_truncate           129 /* Common                                      */
#define __NR_ftruncate          130 /* Common                                      */
#define __NR_flock              131 /* Common                                      */
#define __NR_lstat64		132 /* Linux sparc32 Specific			   */
#define __NR_sendto             133 /* Common                                      */
#define __NR_shutdown           134 /* Common                                      */
#define __NR_socketpair         135 /* Common                                      */
#define __NR_mkdir              136 /* Common                                      */
#define __NR_rmdir              137 /* Common                                      */
#define __NR_utimes             138 /* SunOS Specific                              */
#define __NR_stat64		139 /* Linux sparc32 Specific			   */
#define __NR_sendfile64         140 /* adjtime under SunOS                         */
#define __NR_getpeername        141 /* Common                                      */
#define __NR_futex              142 /* gethostid under SunOS                       */
#define __NR_gettid             143 /* ENOSYS under SunOS                          */
#define __NR_getrlimit          144 /* Common                                      */
#define __NR_setrlimit          145 /* Common                                      */
#define __NR_pivot_root		146 /* Linux Specific, killpg under SunOS          */
#define __NR_prctl		147 /* ENOSYS under SunOS                          */
#define __NR_pciconfig_read	148 /* ENOSYS under SunOS                          */
#define __NR_pciconfig_write	149 /* ENOSYS under SunOS                          */
#define __NR_getsockname        150 /* Common                                      */
/* #define __NR_getmsg          151    SunOS Specific                              */
/* #define __NR_putmsg          152    SunOS Specific                              */
#define __NR_poll               153 /* Common                                      */
#define __NR_getdents64		154 /* Linux specific				   */
#define __NR_fcntl64		155 /* Linux sparc32 Specific                      */
/* #define __NR_getdirentires 	156    SunOS Specific                              */
#define __NR_statfs             157 /* Common                                      */
#define __NR_fstatfs            158 /* Common                                      */
#define __NR_umount             159 /* Common                                      */
#define __NR_sched_set_affinity 160 /* Linux specific, async_daemon under SunOS    */
#define __NR_sched_get_affinity 161 /* Linux specific, getfh under SunOS           */
#define __NR_getdomainname      162 /* SunOS Specific                              */
#define __NR_setdomainname      163 /* Common                                      */
/* #define __NR_ni_syscall	164    ENOSYS under SunOS			   */
#define __NR_quotactl           165 /* Common                                      */
#define __NR_set_tid_address    166 /* Linux specific, exportfs under SunOS        */
#define __NR_mount              167 /* Common                                      */
#define __NR_ustat              168 /* Common                                      */
#define __NR_setxattr           169 /* SunOS: semsys                               */
#define __NR_lsetxattr          170 /* SunOS: msgsys                               */
#define __NR_fsetxattr          171 /* SunOS: shmsys                               */
#define __NR_getxattr           172 /* SunOS: auditsys                             */
#define __NR_lgetxattr          173 /* SunOS: rfssys                               */
#define __NR_getdents           174 /* Common                                      */
#define __NR_setsid             175 /* Common                                      */
#define __NR_fchdir             176 /* Common                                      */
#define __NR_fgetxattr          177 /* SunOS: fchroot                              */
#define __NR_listxattr          178 /* SunOS: vpixsys                              */
#define __NR_llistxattr         179 /* SunOS: aioread                              */
#define __NR_flistxattr         180 /* SunOS: aiowrite                             */
#define __NR_removexattr        181 /* SunOS: aiowait                              */
#define __NR_lremovexattr       182 /* SunOS: aiocancel                            */
#define __NR_sigpending         183 /* Common                                      */
#define __NR_query_module	184 /* Linux Specific				   */
#define __NR_setpgid            185 /* Common                                      */
#define __NR_fremovexattr       186 /* SunOS: pathconf                             */
#define __NR_tkill              187 /* SunOS: fpathconf                            */
#define __NR_exit_group		188 /* Linux specific, sysconf undef SunOS         */
#define __NR_uname              189 /* Linux Specific                              */
#define __NR_init_module        190 /* Linux Specific                              */
#define __NR_personality        191 /* Linux Specific                              */
#define __NR_remap_file_pages   192 /* Linux Specific                              */
#define __NR_epoll_create       193 /* Linux Specific                              */
#define __NR_epoll_ctl          194 /* Linux Specific                              */
#define __NR_epoll_wait         195 /* Linux Specific                              */
/* #define __NR_ulimit          196    Linux Specific                              */
#define __NR_getppid            197 /* Linux Specific                              */
#define __NR_sigaction          198 /* Linux Specific                              */
#define __NR_sgetmask           199 /* Linux Specific                              */
#define __NR_ssetmask           200 /* Linux Specific                              */
#define __NR_sigsuspend         201 /* Linux Specific                              */
#define __NR_oldlstat           202 /* Linux Specific                              */
#define __NR_uselib             203 /* Linux Specific                              */
#define __NR_readdir            204 /* Linux Specific                              */
#define __NR_readahead          205 /* Linux Specific                              */
#define __NR_socketcall         206 /* Linux Specific                              */
#define __NR_syslog             207 /* Linux Specific                              */
#define __NR_lookup_dcookie     208 /* Linux Specific                              */
#define __NR_fadvise64          209 /* Linux Specific                              */
#define __NR_fadvise64_64       210 /* Linux Specific                              */
#define __NR_tgkill             211 /* Linux Specific                              */
#define __NR_waitpid            212 /* Linux Specific                              */
#define __NR_swapoff            213 /* Linux Specific                              */
#define __NR_sysinfo            214 /* Linux Specific                              */
#define __NR_ipc                215 /* Linux Specific                              */
#define __NR_sigreturn          216 /* Linux Specific                              */
#define __NR_clone              217 /* Linux Specific                              */
/* #define __NR_modify_ldt      218    Linux Specific - i386 specific, unused      */
#define __NR_adjtimex           219 /* Linux Specific                              */
#define __NR_sigprocmask        220 /* Linux Specific                              */
#define __NR_create_module      221 /* Linux Specific                              */
#define __NR_delete_module      222 /* Linux Specific                              */
#define __NR_get_kernel_syms    223 /* Linux Specific                              */
#define __NR_getpgid            224 /* Linux Specific                              */
#define __NR_bdflush            225 /* Linux Specific                              */
#define __NR_sysfs              226 /* Linux Specific                              */
#define __NR_afs_syscall        227 /* Linux Specific                              */
#define __NR_setfsuid           228 /* Linux Specific                              */
#define __NR_setfsgid           229 /* Linux Specific                              */
#define __NR__newselect         230 /* Linux Specific                              */
#define __NR_time               231 /* Linux Specific                              */
/* #define __NR_oldstat         232    Linux Specific                              */
#define __NR_stime              233 /* Linux Specific                              */
#define __NR_statfs64           234 /* Linux Specific                              */
#define __NR_fstatfs64          235 /* Linux Specific                              */
#define __NR__llseek            236 /* Linux Specific                              */
#define __NR_mlock              237
#define __NR_munlock            238
#define __NR_mlockall           239
#define __NR_munlockall         240
#define __NR_sched_setparam     241
#define __NR_sched_getparam     242
#define __NR_sched_setscheduler 243
#define __NR_sched_getscheduler 244
#define __NR_sched_yield        245
#define __NR_sched_get_priority_max 246
#define __NR_sched_get_priority_min 247
#define __NR_sched_rr_get_interval  248
#define __NR_nanosleep          249
#define __NR_mremap             250
#define __NR__sysctl            251
#define __NR_getsid             252
#define __NR_fdatasync          253
#define __NR_nfsservctl         254
#define __NR_aplib              255
#define __NR_clock_settime	256
#define __NR_clock_gettime	257
#define __NR_clock_getres	258
#define __NR_clock_nanosleep	259
#define __NR_sched_getaffinity	260
#define __NR_sched_setaffinity	261
#define __NR_timer_settime	262
#define __NR_timer_gettime	263
#define __NR_timer_getoverrun	264
#define __NR_timer_delete	265
#define __NR_timer_create	266
/* #define __NR_vserver		267 Reserved for VSERVER */
#define __NR_io_setup		268
#define __NR_io_destroy		269
#define __NR_io_submit		270
#define __NR_io_cancel		271
#define __NR_io_getevents	272
#define __NR_mq_open		273
#define __NR_mq_unlink		274
#define __NR_mq_timedsend	275
#define __NR_mq_timedreceive	276
#define __NR_mq_notify		277
#define __NR_mq_getsetattr	278
#define __NR_waitid		279
#define __NR_sys_setaltroot	280
#define __NR_add_key		281
#define __NR_request_key	282
#define __NR_keyctl		283
#define __NR_openat		284
#define __NR_mkdirat		285
#define __NR_mknodat		286
#define __NR_fchownat		287
#define __NR_futimesat		288
#define __NR_fstatat64		289
#define __NR_unlinkat		290
#define __NR_renameat		291
#define __NR_linkat		292
#define __NR_symlinkat		293
#define __NR_readlinkat		294
#define __NR_fchmodat		295
#define __NR_faccessat		296
#define __NR_pselect6		297
#define __NR_ppoll		298
#define __NR_unshare		299
#define __NR_set_robust_list	300
#define __NR_get_robust_list	301
#define __NR_migrate_pages	302
#define __NR_mbind		303
#define __NR_get_mempolicy	304
#define __NR_set_mempolicy	305
#define __NR_kexec_load		306
#define __NR_move_pages		307
#define __NR_getcpu		308
#define __NR_epoll_pwait	309
#define __NR_utimensat		310
#define __NR_signalfd		311
#define __NR_timerfd		312
#define __NR_eventfd		313
#define __NR_fallocate		314
#define __NR_timerfd_settime	315
#define __NR_timerfd_gettime	316

#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,function; \
.weak wsym; \
wsym: ; \
.type sym,function; \
.global sym; \
sym: \
	b __unified_syscall; \
	mov __NR_##name, %g1

#define syscall(name,sym) \
.text; \
.type sym,function; \
.global sym; \
sym: \
	b __unified_syscall; \
	mov __NR_##name, %g1

dietlibc-0.33~cvs20120325/sparc/udiv.S010064400000000000000000000157621173363230200141140ustar00#ifdef __sparc__
   /* This file is generated from divrem.m4; DO NOT EDIT! */
/*
 * Division and remainder, from Appendix E of the Sparc Version 8
 * Architecture Manual, with fixes from Gordon Irlam.
 */

/*
 * Input: dividend and divisor in %o0 and %o1 respectively.
 *
 * m4 parameters:
 *  .udiv	name of function to generate
 *  div		div=div => %o0 / %o1; div=rem => %o0 % %o1
 *  false		false=true => signed; false=false => unsigned
 *
 * Algorithm parameters:
 *  N		how many bits per iteration we try to get (4)
 *  WORDSIZE	total number of bits (32)
 *
 * Derived constants:
 *  TOPBITS	number of bits in the top decade of a number
 *
 * Important variables:
 *  Q		the partial quotient under development (initially 0)
 *  R		the remainder so far, initially the dividend
 *  ITER	number of main division loop iterations required;
 *		equal to ceil(log2(quotient) / N).  Note that this
 *		is the log base (2^N) of the quotient.
 *  V		the current comparand, initially divisor*2^(ITER*N-1)
 *
 * Cost:
 *  Current estimate for non-large dividend is
 *	ceil(log2(quotient) / N) * (10 + 7N/2) + C
 *  A large dividend is one greater than 2^(31-TOPBITS) and takes a
 *  different path, as the upper bits of the quotient must be developed
 *  one bit at a time.
 */



#define C_LABEL(name) name:

#define C_SYMBOL_NAME(name) name

#define ENTRY(name) \
        .global C_SYMBOL_NAME(name); \
        .align 4;\
        C_LABEL(name);\
        .type name,@function;

#define END(name) \
        .size name, . - name

#define ST_DIV0                 0x02

ENTRY(.udiv)

	! Ready to divide.  Compute size of quotient; scale comparand.
	orcc	%o1, %g0, %o5
	bne	1f
	mov	%o0, %o3

		! Divide by zero trap.  If it returns, return 0 (about as
		! wrong as possible, but that is what SunOS does...).
		ta	ST_DIV0
		retl
		clr	%o0

1:
	cmp	%o3, %o5			! if %o1 exceeds %o0, done
	blu	.Lgot_result		! (and algorithm fails otherwise)
	clr	%o2
	sethi	%hi(1 << (32 - 4 - 1)), %g1
	cmp	%o3, %g1
	blu	.Lnot_really_big
	clr	%o4

	! Here the dividend is >= 2**(31-N) or so.  We must be careful here,
	! as our usual N-at-a-shot divide step will cause overflow and havoc.
	! The number of bits in the result here is N*ITER+SC, where SC <= N.
	! Compute ITER in an unorthodox manner: know we need to shift V into
	! the top decade: so do not even bother to compare to R.
	1:
		cmp	%o5, %g1
		bgeu	3f
		mov	1, %g2
		sll	%o5, 4, %o5
		b	1b
		add	%o4, 1, %o4

	! Now compute %g2.
	2:	addcc	%o5, %o5, %o5
		bcc	.Lnot_too_big
		add	%g2, 1, %g2

		! We get here if the %o1 overflowed while shifting.
		! This means that %o3 has the high-order bit set.
		! Restore %o5 and subtract from %o3.
		sll	%g1, 4, %g1	! high order bit
		srl	%o5, 1, %o5		! rest of %o5
		add	%o5, %g1, %o5
		b	.Ldo_single_div
		sub	%g2, 1, %g2

	.Lnot_too_big:
	3:	cmp	%o5, %o3
		blu	2b
		nop
		be	.Ldo_single_div
		nop
	/* NB: these are commented out in the V8-Sparc manual as well */
	/* (I do not understand this) */
	! %o5 > %o3: went too far: back up 1 step
	!	srl	%o5, 1, %o5
	!	dec	%g2
	! do single-bit divide steps
	!
	! We have to be careful here.  We know that %o3 >= %o5, so we can do the
	! first divide step without thinking.  BUT, the others are conditional,
	! and are only done if %o3 >= 0.  Because both %o3 and %o5 may have the high-
	! order bit set in the first step, just falling into the regular
	! division loop will mess up the first time around.
	! So we unroll slightly...
	.Ldo_single_div:
		subcc	%g2, 1, %g2
		bl	.Lend_regular_divide
		nop
		sub	%o3, %o5, %o3
		mov	1, %o2
		b	.Lend_single_divloop
		nop
	.Lsingle_divloop:
		sll	%o2, 1, %o2
		bl	1f
		srl	%o5, 1, %o5
		! %o3 >= 0
		sub	%o3, %o5, %o3
		b	2f
		add	%o2, 1, %o2
	1:	! %o3 < 0
		add	%o3, %o5, %o3
		sub	%o2, 1, %o2
	2:
	.Lend_single_divloop:
		subcc	%g2, 1, %g2
		bge	.Lsingle_divloop
		tst	%o3
		b,a	.Lend_regular_divide

.Lnot_really_big:
1:
	sll	%o5, 4, %o5
	cmp	%o5, %o3
	bleu	1b
	addcc	%o4, 1, %o4
	be	.Lgot_result
	sub	%o4, 1, %o4

	tst	%o3	! set up for initial iteration
.Ldivloop:
	sll	%o2, 4, %o2
		! depth 1, accumulated bits 0
	bl	.L1.16
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 2, accumulated bits 1
	bl	.L2.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits 3
	bl	.L3.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 7
	bl	.L4.23
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2+1), %o2
	
.L4.23:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2-1), %o2
	
	
.L3.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 5
	bl	.L4.21
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2+1), %o2
	
.L4.21:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2-1), %o2
	
	
	
.L2.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits 1
	bl	.L3.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 3
	bl	.L4.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2+1), %o2
	
.L4.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2-1), %o2
	
	
.L3.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 1
	bl	.L4.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2+1), %o2
	
.L4.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2-1), %o2
	
	
	
	
.L1.16:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 2, accumulated bits -1
	bl	.L2.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits -1
	bl	.L3.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -1
	bl	.L4.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2+1), %o2
	
.L4.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2-1), %o2
	
	
.L3.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -3
	bl	.L4.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2+1), %o2
	
.L4.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2-1), %o2
	
	
	
.L2.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits -3
	bl	.L3.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -5
	bl	.L4.11
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2+1), %o2
	
.L4.11:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2-1), %o2
	
	
.L3.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -7
	bl	.L4.9
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2+1), %o2
	
.L4.9:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2-1), %o2
	
	
	
	
	9:
.Lend_regular_divide:
	subcc	%o4, 1, %o4
	bge	.Ldivloop
	tst	%o3
	bl,a	.Lgot_result
	! non-restoring fixup here (one instruction only!)
	sub	%o2, 1, %o2


.Lgot_result:

	retl
	mov %o2, %o0

END(.udiv)

#endif
dietlibc-0.33~cvs20120325/sparc/umul.S010064400000000000000000000113711173363230200141170ustar00#ifdef __sparc__
/*
 * Unsigned multiply.  Returns %o0 * %o1 in %o1%o0 (i.e., %o1 holds the
 * upper 32 bits of the 64-bit product).
 *
 * This code optimizes short (less than 13-bit) multiplies.  Short
 * multiplies require 25 instruction cycles, and long ones require
 * 45 instruction cycles.
 *
 * On return, overflow has occurred (%o1 is not zero) if and only if
 * the Z condition code is clear, allowing, e.g., the following:
 *
 *	call	.umul
 *	nop
 *	bnz	overflow	(or tnz)
 */

#define C_LABEL(name) name:

#define C_SYMBOL_NAME(name) name

#define ENTRY(name) \
        .global C_SYMBOL_NAME(name); \
        .align 4;\
        C_LABEL(name);\
        .type name,@function;

#define END(name) \
        .size name, . - name

ENTRY(.umul)
	or	%o0, %o1, %o4
	mov	%o0, %y			! multiplier -> Y
	andncc	%o4, 0xfff, %g0		! test bits 12..31 of *both* args
	be	.Lmul_shortway	! if zero, can do it the short way
	 andcc	%g0, %g0, %o4		! zero the partial product; clear N & V

	/*
	 * Long multiply.  32 steps, followed by a final shift step.
	 */
	mulscc	%o4, %o1, %o4	! 1
	mulscc	%o4, %o1, %o4	! 2
	mulscc	%o4, %o1, %o4	! 3
	mulscc	%o4, %o1, %o4	! 4
	mulscc	%o4, %o1, %o4	! 5
	mulscc	%o4, %o1, %o4	! 6
	mulscc	%o4, %o1, %o4	! 7
	mulscc	%o4, %o1, %o4	! 8
	mulscc	%o4, %o1, %o4	! 9
	mulscc	%o4, %o1, %o4	! 10
	mulscc	%o4, %o1, %o4	! 11
	mulscc	%o4, %o1, %o4	! 12
	mulscc	%o4, %o1, %o4	! 13
	mulscc	%o4, %o1, %o4	! 14
	mulscc	%o4, %o1, %o4	! 15
	mulscc	%o4, %o1, %o4	! 16
	mulscc	%o4, %o1, %o4	! 17
	mulscc	%o4, %o1, %o4	! 18
	mulscc	%o4, %o1, %o4	! 19
	mulscc	%o4, %o1, %o4	! 20
	mulscc	%o4, %o1, %o4	! 21
	mulscc	%o4, %o1, %o4	! 22
	mulscc	%o4, %o1, %o4	! 23
	mulscc	%o4, %o1, %o4	! 24
	mulscc	%o4, %o1, %o4	! 25
	mulscc	%o4, %o1, %o4	! 26
	mulscc	%o4, %o1, %o4	! 27
	mulscc	%o4, %o1, %o4	! 28
	mulscc	%o4, %o1, %o4	! 29
	mulscc	%o4, %o1, %o4	! 30
	mulscc	%o4, %o1, %o4	! 31
	mulscc	%o4, %o1, %o4	! 32
	mulscc	%o4, %g0, %o4	! final shift

	/*
	 * Normally, with the shift-and-add approach, if both numbers are
	 * positive you get the correct result.  With 32-bit two's-complement
	 * numbers, -x is represented as
	 *
	 *		  x		    32
	 *	( 2  -  ------ ) mod 2  *  2
	 *		   32
	 *		  2
	 *
	 * (the `mod 2' subtracts 1 from 1.bbbb).  To avoid lots of 2^32s,
	 * we can treat this as if the radix point were just to the left
	 * of the sign bit (multiply by 2^32), and get
	 *
	 *	-x  =  (2 - x) mod 2
	 *
	 * Then, ignoring the `mod 2's for convenience:
	 *
	 *   x *  y	= xy
	 *  -x *  y	= 2y - xy
	 *   x * -y	= 2x - xy
	 *  -x * -y	= 4 - 2x - 2y + xy
	 *
	 * For signed multiplies, we subtract (x << 32) from the partial
	 * product to fix this problem for negative multipliers (see mul.s).
	 * Because of the way the shift into the partial product is calculated
	 * (N xor V), this term is automatically removed for the multiplicand,
	 * so we don't have to adjust.
	 *
	 * But for unsigned multiplies, the high order bit wasn't a sign bit,
	 * and the correction is wrong.  So for unsigned multiplies where the
	 * high order bit is one, we end up with xy - (y << 32).  To fix it
	 * we add y << 32.
	 */
#if 0
	tst	%o1
	bl,a	1f		! if %o1 < 0 (high order bit = 1),
	 add	%o4, %o0, %o4	! %o4 += %o0 (add y to upper half)
1:	rd	%y, %o0		! get lower half of product
	retl
	 addcc	%o4, %g0, %o1	! put upper half in place and set Z for %o1==0
#else
	/* Faster code from tege@sics.se.  */
	sra	%o1, 31, %o2	! make mask from sign bit
	and	%o0, %o2, %o2	! %o2 = 0 or %o0, depending on sign of %o1
	rd	%y, %o0		! get lower half of product
	retl
	 addcc	%o4, %o2, %o1	! add compensation and put upper half in place
#endif

.Lmul_shortway:
	/*
	 * Short multiply.  12 steps, followed by a final shift step.
	 * The resulting bits are off by 12 and (32-12) = 20 bit positions,
	 * but there is no problem with %o0 being negative (unlike above),
	 * and overflow is impossible (the answer is at most 24 bits long).
	 */
	mulscc	%o4, %o1, %o4	! 1
	mulscc	%o4, %o1, %o4	! 2
	mulscc	%o4, %o1, %o4	! 3
	mulscc	%o4, %o1, %o4	! 4
	mulscc	%o4, %o1, %o4	! 5
	mulscc	%o4, %o1, %o4	! 6
	mulscc	%o4, %o1, %o4	! 7
	mulscc	%o4, %o1, %o4	! 8
	mulscc	%o4, %o1, %o4	! 9
	mulscc	%o4, %o1, %o4	! 10
	mulscc	%o4, %o1, %o4	! 11
	mulscc	%o4, %o1, %o4	! 12
	mulscc	%o4, %g0, %o4	! final shift

	/*
	 * %o4 has 20 of the bits that should be in the result; %y has
	 * the bottom 12 (as %y's top 12).  That is:
	 *
	 *	  %o4		    %y
	 * +----------------+----------------+
	 * | -12- |   -20-  | -12- |   -20-  |
	 * +------(---------+------)---------+
	 *	   -----result-----
	 *
	 * The 12 bits of %o4 left of the `result' area are all zero;
	 * in fact, all top 20 bits of %o4 are zero.
	 */

	rd	%y, %o5
	sll	%o4, 12, %o0	! shift middle bits left 12
	srl	%o5, 20, %o5	! shift low bits right 20
	or	%o5, %o0, %o0
	retl
	 addcc	%g0, %g0, %o1	! %o1 = zero, and set Z

END(.umul)
#endif
dietlibc-0.33~cvs20120325/sparc/unified.S010064400000000000000000000011021173363230200145470ustar00#include 
#include "syscalls.h"

.text
.weak exit
.type exit,function
exit:
.global _exit
.type	_exit,function
_exit:
	mov	__NR_exit, %g1
.global __unified_syscall
__unified_syscall:
	ta	0x10
	bcs	1f
	nop

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"
	retl
	nop

.global __unified_syscall_error_handler
__unified_syscall_error_handler:
1:	save	%sp, -96, %sp
#ifdef WANT_THREAD_SAFE
	call	__errno_location
	nop
#else
	sethi	%hi(errno), %o0
	or	%o0, %lo(errno), %o0
#endif
	st	%i0, [ %o0 ]
	ret
	restore %g0, -1, %o0

dietlibc-0.33~cvs20120325/sparc/urem.S010064400000000000000000000157631173363230200141160ustar00#ifdef __sparc__
   /* This file is generated from divrem.m4; DO NOT EDIT! */
/*
 * Division and remainder, from Appendix E of the Sparc Version 8
 * Architecture Manual, with fixes from Gordon Irlam.
 */

/*
 * Input: dividend and divisor in %o0 and %o1 respectively.
 *
 * m4 parameters:
 *  .urem	name of function to generate
 *  rem		rem=div => %o0 / %o1; rem=rem => %o0 % %o1
 *  false		false=true => signed; false=false => unsigned
 *
 * Algorithm parameters:
 *  N		how many bits per iteration we try to get (4)
 *  WORDSIZE	total number of bits (32)
 *
 * Derived constants:
 *  TOPBITS	number of bits in the top decade of a number
 *
 * Important variables:
 *  Q		the partial quotient under development (initially 0)
 *  R		the remainder so far, initially the dividend
 *  ITER	number of main division loop iterations required;
 *		equal to ceil(log2(quotient) / N).  Note that this
 *		is the log base (2^N) of the quotient.
 *  V		the current comparand, initially divisor*2^(ITER*N-1)
 *
 * Cost:
 *  Current estimate for non-large dividend is
 *	ceil(log2(quotient) / N) * (10 + 7N/2) + C
 *  A large dividend is one greater than 2^(31-TOPBITS) and takes a
 *  different path, as the upper bits of the quotient must be developed
 *  one bit at a time.
 */



#define C_LABEL(name) name:

#define C_SYMBOL_NAME(name) name

#define ENTRY(name) \
        .global C_SYMBOL_NAME(name); \
        .align 4;\
        C_LABEL(name);\
        .type name,@function;

#define END(name) \
        .size name, . - name

#define ST_DIV0                 0x02

ENTRY(.urem)

	! Ready to divide.  Compute size of quotient; scale comparand.
	orcc	%o1, %g0, %o5
	bne	1f
	mov	%o0, %o3

		! Divide by zero trap.  If it returns, return 0 (about as
		! wrong as possible, but that is what SunOS does...).
		ta	ST_DIV0
		retl
		clr	%o0

1:
	cmp	%o3, %o5			! if %o1 exceeds %o0, done
	blu	.Lgot_result		! (and algorithm fails otherwise)
	clr	%o2
	sethi	%hi(1 << (32 - 4 - 1)), %g1
	cmp	%o3, %g1
	blu	.Lnot_really_big
	clr	%o4

	! Here the dividend is >= 2**(31-N) or so.  We must be careful here,
	! as our usual N-at-a-shot divide step will cause overflow and havoc.
	! The number of bits in the result here is N*ITER+SC, where SC <= N.
	! Compute ITER in an unorthodox manner: know we need to shift V into
	! the top decade: so do not even bother to compare to R.
	1:
		cmp	%o5, %g1
		bgeu	3f
		mov	1, %g2
		sll	%o5, 4, %o5
		b	1b
		add	%o4, 1, %o4

	! Now compute %g2.
	2:	addcc	%o5, %o5, %o5
		bcc	.Lnot_too_big
		add	%g2, 1, %g2

		! We get here if the %o1 overflowed while shifting.
		! This means that %o3 has the high-order bit set.
		! Restore %o5 and subtract from %o3.
		sll	%g1, 4, %g1	! high order bit
		srl	%o5, 1, %o5		! rest of %o5
		add	%o5, %g1, %o5
		b	.Ldo_single_div
		sub	%g2, 1, %g2

	.Lnot_too_big:
	3:	cmp	%o5, %o3
		blu	2b
		nop
		be	.Ldo_single_div
		nop
	/* NB: these are commented out in the V8-Sparc manual as well */
	/* (I do not understand this) */
	! %o5 > %o3: went too far: back up 1 step
	!	srl	%o5, 1, %o5
	!	dec	%g2
	! do single-bit divide steps
	!
	! We have to be careful here.  We know that %o3 >= %o5, so we can do the
	! first divide step without thinking.  BUT, the others are conditional,
	! and are only done if %o3 >= 0.  Because both %o3 and %o5 may have the high-
	! order bit set in the first step, just falling into the regular
	! division loop will mess up the first time around.
	! So we unroll slightly...
	.Ldo_single_div:
		subcc	%g2, 1, %g2
		bl	.Lend_regular_divide
		nop
		sub	%o3, %o5, %o3
		mov	1, %o2
		b	.Lend_single_divloop
		nop
	.Lsingle_divloop:
		sll	%o2, 1, %o2
		bl	1f
		srl	%o5, 1, %o5
		! %o3 >= 0
		sub	%o3, %o5, %o3
		b	2f
		add	%o2, 1, %o2
	1:	! %o3 < 0
		add	%o3, %o5, %o3
		sub	%o2, 1, %o2
	2:
	.Lend_single_divloop:
		subcc	%g2, 1, %g2
		bge	.Lsingle_divloop
		tst	%o3
		b,a	.Lend_regular_divide

.Lnot_really_big:
1:
	sll	%o5, 4, %o5
	cmp	%o5, %o3
	bleu	1b
	addcc	%o4, 1, %o4
	be	.Lgot_result
	sub	%o4, 1, %o4

	tst	%o3	! set up for initial iteration
.Ldivloop:
	sll	%o2, 4, %o2
		! depth 1, accumulated bits 0
	bl	.L1.16
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 2, accumulated bits 1
	bl	.L2.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits 3
	bl	.L3.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 7
	bl	.L4.23
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2+1), %o2
	
.L4.23:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (7*2-1), %o2
	
	
.L3.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 5
	bl	.L4.21
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2+1), %o2
	
.L4.21:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (5*2-1), %o2
	
	
	
.L2.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits 1
	bl	.L3.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits 3
	bl	.L4.19
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2+1), %o2
	
.L4.19:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (3*2-1), %o2
	
	
.L3.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits 1
	bl	.L4.17
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2+1), %o2
	
.L4.17:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (1*2-1), %o2
	
	
	
	
.L1.16:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 2, accumulated bits -1
	bl	.L2.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 3, accumulated bits -1
	bl	.L3.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -1
	bl	.L4.15
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2+1), %o2
	
.L4.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-1*2-1), %o2
	
	
.L3.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -3
	bl	.L4.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2+1), %o2
	
.L4.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-3*2-1), %o2
	
	
	
.L2.15:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 3, accumulated bits -3
	bl	.L3.13
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
			! depth 4, accumulated bits -5
	bl	.L4.11
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2+1), %o2
	
.L4.11:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-5*2-1), %o2
	
	
.L3.13:
	! remainder is negative
	addcc	%o3,%o5,%o3
			! depth 4, accumulated bits -7
	bl	.L4.9
	srl	%o5,1,%o5
	! remainder is positive
	subcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2+1), %o2
	
.L4.9:
	! remainder is negative
	addcc	%o3,%o5,%o3
		b	9f
		add	%o2, (-7*2-1), %o2
	
	
	
	
	9:
.Lend_regular_divide:
	subcc	%o4, 1, %o4
	bge	.Ldivloop
	tst	%o3
	bl,a	.Lgot_result
	! non-restoring fixup here (one instruction only!)
	add	%o3, %o1, %o3


.Lgot_result:

	retl
	mov %o3, %o0

END(.urem)
#endif
dietlibc-0.33~cvs20120325/sparc64/Makefile.add010064400000000000000000000001371173363230200153500ustar00CFLAGS+=-m64 -Os
VPATH:=sparc64:syscalls.s:$(VPATH)
LIBOBJ+=$(patsubst %,$(OBJDIR)/%,__time.o)
dietlibc-0.33~cvs20120325/sparc64/README010064400000000000000000000004151173363230200140400ustar00OK this is the sparc64 part of the dietlibc.

It seams to work ONLY with gcc 3 out of the box

gcc 2.95.4 needed some heavy commandline option settings.
 -Wl,-melf64_sparc -Wa,-Av9 -mcpu=v9 -D__arch64__

This __arch64__ define is default in 3.0 but missing in 2.95.4


dietlibc-0.33~cvs20120325/sparc64/__CAS.S010064400000000000000000000001621173363230200142070ustar00.text
.global __CAS
.type __CAS,@function
__CAS:
	membar 15
	jmp %o7+8
	casx [%o0], %o1, %o2
.size __CAS, .-__CAS
dietlibc-0.33~cvs20120325/sparc64/__longjmp.S010064400000000000000000000000431173363230200152450ustar00/* none ! all done in longjmp.S */
dietlibc-0.33~cvs20120325/sparc64/__testandset.S010064400000000000000000000001131173363230200157530ustar00.text
.align 4
.global __testandset
__testandset:
	retl
	ldstub	[%o0], %o0
dietlibc-0.33~cvs20120325/sparc64/clone.S010064400000000000000000000015461173363230200144120ustar00#include 
#include "syscalls.h"

.text
.align 4
.weak clone
clone:
.type __clone,#function
.global __clone
__clone:
	save	%sp, -192, %sp
	brz,pn	%i0, .LerrorV	/* check for function pointer */
	mov	%i0, %l0
	brz,pn	%i1, .LerrorV	/* check for stack pointer */
	mov	%i3, %l3

	sub	%i1, 2047, %o1	/* child-stack + BIAS */
	mov	%i2, %o0	/* clone-flags */
	mov	__NR_clone, %g1
	ta	0x6d		/* syscall: clone */
	bcs,pn	%xcc, .Lerror
	nop
	brnz,pn	%o1, .Lstart	/* we are the child :) */
	mov	%o0, %i0	/* return child pid */
	ret
	restore

.LerrorV:
	mov	EINVAL, %i0
.Lerror:
	call	__errno_location
	nop
	st	%i0, [%o0]
	ret
	restore	%g0, -1, %o0

.Lstart:
	mov	%g0, %fp	/* close frame */
	sub	%sp,(6*8), %sp	/* make a little space */
	call	%l0		/* call child-function */
	mov	%l3, %o0	/* put arg in the right place for the child */
	call	_exit		/* child returned */
	nop

dietlibc-0.33~cvs20120325/sparc64/errlist.S010064400000000000000000000162021173363230200147710ustar00#ifdef __DYN_LIB
.section	.data
#else
.section	.rodata
#endif

.align 8
.global sys_errlist
.type	sys_errlist,@object
sys_errlist:
	.quad .LC000
	.quad .LC001
	.quad .LC002
	.quad .LC003
	.quad .LC004
	.quad .LC005
	.quad .LC006
	.quad .LC007
	.quad .LC008
	.quad .LC009
	.quad .LC010
	.quad .LC011
	.quad .LC012
	.quad .LC013
	.quad .LC014
	.quad .LC015
	.quad .LC016
	.quad .LC017
	.quad .LC018
	.quad .LC019
	.quad .LC020
	.quad .LC021
	.quad .LC022
	.quad .LC023
	.quad .LC024
	.quad .LC025
	.quad .LC026
	.quad .LC027
	.quad .LC028
	.quad .LC029
	.quad .LC030
	.quad .LC031
	.quad .LC032
	.quad .LC033
	.quad .LC034
	.quad .LC035
	.quad .LC036
	.quad .LC037
	.quad .LC038
	.quad .LC039
	.quad .LC040
	.quad .LC041
	.quad .LC042
	.quad .LC043
	.quad .LC044
	.quad .LC045
	.quad .LC046
	.quad .LC047
	.quad .LC048
	.quad .LC049
	.quad .LC050
	.quad .LC051
	.quad .LC052
	.quad .LC053
	.quad .LC054
	.quad .LC055
	.quad .LC056
	.quad .LC057
	.quad .LC058
	.quad .LC059
	.quad .LC060
	.quad .LC061
	.quad .LC062
	.quad .LC063
	.quad .LC064
	.quad .LC065
	.quad .LC066
	.quad .LC067
	.quad .LC068
	.quad .LC069
	.quad .LC070
	.quad .LC071
	.quad .LC072
	.quad .LC073
	.quad .LC074
	.quad .LC075
	.quad .LC076
	.quad .LC077
	.quad .LC078
	.quad .LC079
	.quad .LC080
	.quad .LC081
	.quad .LC082
	.quad .LC083
	.quad .LC084
	.quad .LC085
	.quad .LC086
	.quad .LC087
	.quad .LC088
	.quad .LC089
	.quad .LC090
	.quad .LC091
	.quad .LC092
	.quad .LC093
	.quad .LC094
	.quad .LC095
	.quad .LC096
	.quad .LC097
	.quad .LC098
	.quad .LC099
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC100
	.quad .LC120
	.quad .LC121
	.quad .LC122
	.quad .LC123
	.quad .LC124
	.quad .LC125
	.quad .LC126
	.quad 0
.size sys_errlist,.-sys_errlist

.align 4
.global sys_nerr
.type	sys_nerr,@object
sys_nerr:
	.long 127
.size	 sys_nerr,4

#ifdef __DYN_LIB
.section	.rodata
#endif

.LC000:	.string	"Success"
.LC001: .string "Operation not permitted"
.LC002: .string "No such file or directory"
.LC003: .string "No such process"
.LC004: .string "Interrupted system call"
.LC005: .string "I/O error"
.LC006: .string "No such device or address"
.LC007: .string "Arg list too long"
.LC008: .string "Exec format error"
.LC009: .string "Bad file number"
.LC010: .string "No child processes"
.LC011: .string "Try again"
.LC012: .string "Out of memory"
.LC013: .string "Permission denied"
.LC014: .string "Bad address"
.LC015: .string "Block device required"
.LC016: .string "Device or resource busy"
.LC017: .string "File exists"
.LC018: .string "Cross-device link"
.LC019: .string "No such device"
.LC020: .string "Not a directory"
.LC021: .string "Is a directory"
.LC022: .string "Invalid argument"
.LC023: .string "File table overflow"
.LC024: .string "Too many open files"
.LC025: .string "Not a typewriter"
.LC026: .string "Text file busy"
.LC027: .string "File too large"
.LC028: .string "No space left on device"
.LC029: .string "Illegal seek"
.LC030: .string "Read-only file system"
.LC031: .string "Too many links"
.LC032: .string "Broken pipe"
.LC033: .string "Math argument out of domain of func"
.LC034: .string "Math result not representable"
.LC035: .string "Operation would block"
.LC036: .string "Operation now in progress"
.LC037: .string "Operation already in progress"
.LC038: .string "Socket operation on non-socket"
.LC039: .string "Destination address required"
.LC040: .string "Message too long"
.LC041: .string "Protocol wrong type for socket"
.LC042: .string "Protocol not available"
.LC043: .string "Protocol not supported"
.LC044: .string "Socket type not supported"
.LC045: .string "Op not supported on transport endpoint"
.LC046: .string "Protocol family not supported"
.LC047: .string "Address family not supported by protocol"
.LC048: .string "Address already in use"
.LC049: .string "Cannot assign requested address"
.LC050: .string "Network is down"
.LC051: .string "Network is unreachable"
.LC052: .string "Net dropped connection because of reset"
.LC053: .string "Software caused connection abort"
.LC054: .string "Connection reset by peer"
.LC055: .string "No buffer space available"
.LC056: .string "Transport endpoint is already connected"
.LC057: .string "Transport endpoint is not connected"
.LC058: .string "No send after transport endpoint shutdown"
.LC059: .string "Too many references: cannot splice"
.LC060: .string "Connection timed out"
.LC061: .string "Connection refused"
.LC062: .string "Too many symbolic links encountered"
.LC063: .string "File name too long"
.LC064: .string "Host is down"
.LC065: .string "No route to host"
.LC066: .string "Directory not empty"
.LC067: .string "SUNOS: Too many processes"
.LC068: .string "Too many users"
.LC069: .string "Quota exceeded"
.LC070: .string "Stale NFS file handle"
.LC071: .string "Object is remote"
.LC072: .string "Device not a stream"
.LC073: .string "Timer expired"
.LC074: .string "Out of streams resources"
.LC075: .string "No message of desired type"
.LC076: .string "Not a data message"
.LC077: .string "Identifier removed"
.LC078: .string "Resource deadlock would occur"
.LC079: .string "No record locks available"
.LC080: .string "Machine is not on the network"
.LC081: .string "SunOS: Too many lvls of remote in path"
.LC082: .string "Link has been severed"
.LC083: .string "Advertise error"
.LC084: .string "Srmount error"
.LC085: .string "Communication error on send"
.LC086: .string "Protocol error"
.LC087: .string "Multihop attempted"
.LC088: .string "RFS specific error"
.LC089: .string "Remote address changed"
.LC090: .string "Function not implemented"
.LC091: .string "Streams pipe error"
.LC092: .string "Value too large for defined data type"
.LC093: .string "File descriptor in bad state"
.LC094: .string "Channel number out of range"
.LC095: .string "Level 2 not synchronized"
.LC096: .string "Level 3 halted"
.LC097: .string "Level 3 reset"
.LC098: .string "Link number out of range"
.LC099: .string "Protocol driver not attached"
.LC100: .string "No CSI structure available"
.LC101: .string "Level 2 halted"
.LC102: .string "Invalid exchange"
.LC103: .string "Invalid request descriptor"
.LC104: .string "Exchange full"
.LC105: .string "No anode"
.LC106: .string "Invalid request code"
.LC107: .string "Invalid slot"
.LC108: .string "File locking deadlock error"
.LC109: .string "Bad font file format"
.LC110: .string "Cannot exec a shared library directly"
.LC111: .string "No data available"
.LC112: .string "Accessing a corrupted shared library"
.LC113: .string "Package not installed"
.LC114: .string "Can not access a needed shared library"
.LC115: .string "Name not unique on network"
.LC116: .string "Interrupted syscall should be restarted"
.LC117: .string "Structure needs cleaning"
.LC118: .string "Not a XENIX named type file"
.LC119: .string "No XENIX semaphores available"
.LC120: .string "Is a named type file"
.LC121: .string "Remote I/O error"
.LC122: .string "Illegal byte sequence"
.LC123: .string "Atmpt to link in too many shared libs"
.LC124: .string ".lib section in a.out corrupted"
.LC125: .string "No medium found"
.LC126: .string "Wrong medium type"


dietlibc-0.33~cvs20120325/sparc64/fork.S010064400000000000000000000004001173363230200142370ustar00#include "syscalls.h"

.text
.weak fork
fork:
.global __libc_fork
__libc_fork:
	mov	2, %g1
	ta	0x6d
	bcs	%xcc, 1f
	nop
	dec	%o1
	retl
	and	%o0, %o1, %o0

1:	sethi	%hi(__unified_syscall_error_handler), %g1
	jmp	%g1+%lo(__unified_syscall_error_handler)
	nop
dietlibc-0.33~cvs20120325/sparc64/longjmp.S010064400000000000000000000007171173363230200147570ustar00#include 

.text
.weak	siglongjmp
siglongjmp:
.global __siglongjmp
__siglongjmp:
.weak	longjmp
longjmp:
.global __libc_longjmp
.type	__libc_longjmp,function
__libc_longjmp:
	movrz	%o1, 1, %o1			/* never return 0 in setjmp */
	stx	%o1, [ %o0 + (4+MC_G1) * 8 ]    /* save return value in context */
	ld	[ %o0+FLAG_SAVEMASK ], %o1	/* has setjmp saved the signalmask ? */
	ta	0x6f				/* setcontext / restore context */
.size	__libc_longjmp,.-__libc_longjmp
dietlibc-0.33~cvs20120325/sparc64/pipe.S010064400000000000000000000004221173363230200142370ustar00#include "syscalls.h"

.text
.global pipe
pipe:
	mov	%o0, %o2
	mov	__NR_pipe, %g1
	ta	0x6d
	bcs,pn	%xcc, 1f
	nop
	st	%o0, [ %o2 ]
	st	%o1, [ %o2 + 4 ]
	retl
	mov	%g0, %o0

1:	sethi	%hi(__unified_syscall_error_handler), %g1
	jmp	%g1+%lo(__unified_syscall_error_handler)
	nop
dietlibc-0.33~cvs20120325/sparc64/setjmp.S010064400000000000000000000007651173363230200146160ustar00#include 

.text
.global __setjmp
.type	__setjmp,function
__setjmp:
	b	1f
	mov	0, %o1
.size __setjmp,.-__setjmp

.global setjmp
.type	setjmp,function
setjmp:
	mov	1, %o1
.size setjmp,.-setjmp

.global __sigsetjmp
.type	__sigsetjmp,function
__sigsetjmp:
1:
	st	%o1, [ %o0+FLAG_SAVEMASK ]	/* restore sigmask in longjmp ? */
	mov	%g0, %g1			/* return a 0 */
	ta	0x6e				/* getcontext / save context */
	retl
	mov	%g1, %o0			/* return value from longjmp or 0 */
.size __sigsetjmp,.-__sigsetjmp

dietlibc-0.33~cvs20120325/sparc64/sigaction.c010064400000000000000000000013271173363230200153070ustar00#include 
#include "syscalls.h"

static void
__rt_sigreturn_stub (void)
{
  __asm__ ("mov %0, %%g1\n\t"
           "ta  0x6d\n\t"
           : /* no outputs */
           : "i" (__NR_rt_sigreturn));
}

int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, void* restorer, long nr);

int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
  return __rt_sigaction(signum, act, oldact, (void*)(&__rt_sigreturn_stub) - 8, _NSIG/8);
}
int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
__attribute__((weak,alias("__libc_sigaction")));

dietlibc-0.33~cvs20120325/sparc64/sigjmp.S010064400000000000000000000000421173363230200145710ustar00/* none ! all done in setjmp.S */
dietlibc-0.33~cvs20120325/sparc64/start.S010064400000000000000000000020701173363230200144400ustar00#include "dietfeatures.h"

	.section ".text"
	.align 4
	.global _start
	.type _start,@function
_start:

#define BIAS 2047	/* for 64bit-register-window marking */

/* Terminate the stack frame, and reserve space for functions to
   drop their arguments.  */
	mov	%g0, %fp
	sub	%sp, 6*8, %sp

/* Extract the arguments and environment as encoded on the stack.  The
   argument info starts after one register window (16 words) past the SP.  */
	ldx	[%sp+(BIAS+(22*8))], %o0
	add	%sp, (BIAS+(23*8)), %o1
	smul	%o0, 8, %o2
	add	%o2, %o1, %o2
	add	%o2, 8, %o2

	sethi	%hi(environ), %o3
	or	%o3, %lo(environ), %o3
	stx	%o2, [%o3]

/* When starting a binary via the dynamic linker, %g1 contains the
   address of the shared library termination function, which will be
   registered with atexit(). If we are statically linked, this will
   be NULL.  */

/* Let libc do the rest of the initialization, and call main.  */
#ifdef WANT_DYNAMIC
	call	_dyn_start
#else
	call	CALL_IN_STARTCODE
#endif
	mov	%g1, %o3

	b	exit
	mov %o0, %i0

/* die in dishonor */
	ret
	nop

	.size _start, .-_start

dietlibc-0.33~cvs20120325/sparc64/syscalls.h010064400000000000000000000540411173363230200151720ustar00
#define __NR_exit                 1 /* Common                                      */
#define __NR_fork                 2 /* Common                                      */
#define __NR_read                 3 /* Common                                      */
#define __NR_write                4 /* Common                                      */
#define __NR_open                 5 /* Common                                      */
#define __NR_close                6 /* Common                                      */
#define __NR_wait4                7 /* Common                                      */
#define __NR_creat                8 /* Common                                      */
#define __NR_link                 9 /* Common                                      */
#define __NR_unlink              10 /* Common                                      */
#define __NR_execv               11 /* SunOS Specific                              */
#define __NR_chdir               12 /* Common                                      */
#define __NR_chown		 13 /* Common					   */
#define __NR_mknod               14 /* Common                                      */
#define __NR_chmod               15 /* Common                                      */
#define __NR_lchown              16 /* Common                                      */
#define __NR_brk                 17 /* Common                                      */
#define __NR_perfctr             18 /* Performance counter operations              */
#define __NR_lseek               19 /* Common                                      */
#define __NR_getpid              20 /* Common                                      */
#define __NR_capget		 21 /* Linux Specific				   */
#define __NR_capset		 22 /* Linux Specific				   */
#define __NR_setuid              23 /* Implemented via setreuid in SunOS           */
#define __NR_getuid              24 /* Common                                      */
/* #define __NR_time alias	 25    ENOSYS under SunOS			   */
#define __NR_ptrace              26 /* Common                                      */
#define __NR_alarm               27 /* Implemented via setitimer in SunOS          */
#define __NR_sigaltstack	 28 /* Common					   */
#define __NR_pause               29 /* Is sigblock(0)->sigpause() in SunOS         */
#define __NR_utime               30 /* Implemented via utimes() under SunOS        */
/* #define __NR_lchown32         31    Linux sparc32 specific                      */
/* #define __NR_fchown32         32    Linux sparc32 specific                      */
#define __NR_access              33 /* Common                                      */
#define __NR_nice                34 /* Implemented via get/setpriority() in SunOS  */
/* #define __NR_chown32          35    Linux sparc32 specific                      */
#define __NR_sync                36 /* Common                                      */
#define __NR_kill                37 /* Common                                      */
#define __NR_stat                38 /* Common                                      */
#define __NR_sendfile		 39 /* Linux Specific				   */
#define __NR_lstat               40 /* Common                                      */
#define __NR_dup                 41 /* Common                                      */
#define __NR_pipe                42 /* Common                                      */
#define __NR_times               43 /* Implemented via getrusage() in SunOS        */
/* #define __NR_getuid32         44    Linux sparc32 specific                      */
#define __NR_umount2             45 /* Linux Specific                              */
#define __NR_setgid              46 /* Implemented via setregid() in SunOS         */
#define __NR_getgid              47 /* Common                                      */
#define __NR_signal              48 /* Implemented via sigvec() in SunOS           */
#define __NR_geteuid             49 /* SunOS calls getuid()                        */
#define __NR_getegid             50 /* SunOS calls getgid()                        */
#define __NR_acct                51 /* Common                                      */
#define __NR_memory_ordering	 52 /* Linux Specific				   */
/* #define __NR_getgid32         53    Linux sparc32 specific                      */
#define __NR_ioctl               54 /* Common                                      */
#define __NR_reboot              55 /* Common                                      */
/* #define __NR_mmap2		 56    Linux sparc32 Specific                      */
#define __NR_symlink             57 /* Common                                      */
#define __NR_readlink            58 /* Common                                      */
#define __NR_execve              59 /* Common                                      */
#define __NR_umask               60 /* Common                                      */
#define __NR_chroot              61 /* Common                                      */
#define __NR_fstat               62 /* Common                                      */
/* #define __NR_fstat64          63    Linux sparc32 Specific                      */
#define __NR_getpagesize         64 /* Common                                      */
#define __NR_msync               65 /* Common in newer 1.3.x revs...               */
#define __NR_vfork               66 /* Common                                      */
#define __NR_pread               67 /* Linux Specific                              */
#define __NR_pwrite              68 /* Linux Specific                              */
/* #define __NR_geteuid32        69    Linux sparc32, sbrk under SunOS             */
/* #define __NR_getegid32        70    Linux sparc32, sstk under SunOS             */
#define __NR_mmap                71 /* Common                                      */
/* #define __NR_setreuid32       72    Linux sparc32, vadvise under SunOS          */
#define __NR_munmap              73 /* Common                                      */
#define __NR_mprotect            74 /* Common                                      */
#define __NR_madvise             75 /* Common                                      */
#define __NR_vhangup             76 /* Common                                      */
/* #define __NR_truncate64       77    Linux sparc32 Specific			   */
#define __NR_mincore             78 /* Common                                      */
#define __NR_getgroups           79 /* Common                                      */
#define __NR_setgroups           80 /* Common                                      */
#define __NR_getpgrp             81 /* Common                                      */
/* #define __NR_setgroups32      82    Linux sparc32, setpgrp under SunOS          */
#define __NR_setitimer           83 /* Common                                      */
/* #define __NR_ftruncate64      84    Linux sparc32 Specific			   */
#define __NR_swapon              85 /* Common                                      */
#define __NR_getitimer           86 /* Common                                      */
/* #define __NR_setuid32         87    Linux sparc32, gethostname under SunOS      */
#define __NR_sethostname         88 /* Common                                      */
/* #define __NR_setgid32         89    Linux sparc32, getdtablesize under SunOS    */
#define __NR_dup2                90 /* Common                                      */
/* #define __NR_setfsuid32       91    Linux sparc32, getdopt under SunOS          */
#define __NR_fcntl               92 /* Common                                      */
#define __NR_select              93 /* Common                                      */
/* #define __NR_setfsgid32       94    Linux sparc32, setdopt under SunOS          */
#define __NR_fsync               95 /* Common                                      */
#define __NR_setpriority         96 /* Common                                      */
#define __NR_socket              97 /* Common                                      */
#define __NR_connect             98 /* Common                                      */
#define __NR_accept              99 /* Common                                      */
#define __NR_getpriority        100 /* Common                                      */
#define __NR_rt_sigreturn       101 /* Linux Specific                              */
#define __NR_rt_sigaction       102 /* Linux Specific                              */
#define __NR_rt_sigprocmask     103 /* Linux Specific                              */
#define __NR_rt_sigpending      104 /* Linux Specific                              */
#define __NR_rt_sigtimedwait    105 /* Linux Specific                              */
#define __NR_rt_sigqueueinfo    106 /* Linux Specific                              */
#define __NR_rt_sigsuspend      107 /* Linux Specific                              */
#define __NR_setresuid          108 /* Linux Specific, sigvec under SunOS	   */
#define __NR_getresuid          109 /* Linux Specific, sigblock under SunOS	   */
#define __NR_setresgid          110 /* Linux Specific, sigsetmask under SunOS	   */
#define __NR_getresgid          111 /* Linux Specific, sigpause under SunOS	   */
/* #define __NR_setregid32       75    Linux sparc32, sigstack under SunOS         */
#define __NR_recvmsg            113 /* Common                                      */
#define __NR_sendmsg            114 /* Common                                      */
/* #define __NR_getgroups32     115    Linux sparc32, vtrace under SunOS           */
#define __NR_gettimeofday       116 /* Common                                      */
#define __NR_getrusage          117 /* Common                                      */
#define __NR_getsockopt         118 /* Common                                      */
#define __NR_getcwd		119 /* Linux Specific				   */
#define __NR_readv              120 /* Common                                      */
#define __NR_writev             121 /* Common                                      */
#define __NR_settimeofday       122 /* Common                                      */
#define __NR_fchown             123 /* Common                                      */
#define __NR_fchmod             124 /* Common                                      */
#define __NR_recvfrom           125 /* Common                                      */
#define __NR_setreuid           126 /* Common                                      */
#define __NR_setregid           127 /* Common                                      */
#define __NR_rename             128 /* Common                                      */
#define __NR_truncate           129 /* Common                                      */
#define __NR_ftruncate          130 /* Common                                      */
#define __NR_flock              131 /* Common                                      */
/* #define __NR_lstat64		132    Linux sparc32 Specific                      */
#define __NR_sendto             133 /* Common                                      */
#define __NR_shutdown           134 /* Common                                      */
#define __NR_socketpair         135 /* Common                                      */
#define __NR_mkdir              136 /* Common                                      */
#define __NR_rmdir              137 /* Common                                      */
#define __NR_utimes             138 /* SunOS Specific                              */
/* #define __NR_stat64		139    Linux sparc32 Specific			   */
#define __NR_sendfile64         140 /* adjtime under SunOS                         */
#define __NR_getpeername        141 /* Common                                      */
#define __NR_futex              142 /* gethostid under SunOS                       */
#define __NR_gettid             143 /* ENOSYS under SunOS                          */
#define __NR_getrlimit		144 /* Common                                      */
#define __NR_setrlimit          145 /* Common                                      */
#define __NR_pivot_root		146 /* Linux Specific, killpg under SunOS          */
#define __NR_prctl		147 /* ENOSYS under SunOS                          */
#define __NR_pciconfig_read	148 /* ENOSYS under SunOS                          */
#define __NR_pciconfig_write	149 /* ENOSYS under SunOS                          */
#define __NR_getsockname        150 /* Common                                      */
/* #define __NR_getmsg          151    SunOS Specific                              */
/* #define __NR_putmsg          152    SunOS Specific                              */
#define __NR_poll               153 /* Common                                      */
#define __NR_getdents64		154 /* Linux specific				   */
/* #define __NR_fcntl64         155    Linux sparc32 Specific                      */
/* #define __NR_getdirentries   156    SunOS Specific                              */
#define __NR_statfs             157 /* Common                                      */
#define __NR_fstatfs            158 /* Common                                      */
#define __NR_umount             159 /* Common                                      */
#define __NR_sched_set_affinity 160 /* Linux specific, async_daemon under SunOS    */
#define __NR_sched_get_affinity 161 /* Linux specific, getfh under SunOS           */
#define __NR_getdomainname      162 /* SunOS Specific                              */
#define __NR_setdomainname      163 /* Common                                      */
#define __NR_utrap_install	164 /* SYSV ABI/v9 required			   */
#define __NR_quotactl           165 /* Common                                      */
#define __NR_set_tid_address    166 /* Linux specific, exportfs under SunOS        */
#define __NR_mount              167 /* Common                                      */
#define __NR_ustat              168 /* Common                                      */
#define __NR_setxattr           169 /* SunOS: semsys                               */
#define __NR_lsetxattr          170 /* SunOS: msgsys                               */
#define __NR_fsetxattr          171 /* SunOS: shmsys                               */
#define __NR_getxattr           172 /* SunOS: auditsys                             */
#define __NR_lgetxattr          173 /* SunOS: rfssys                               */
#define __NR_getdents           174 /* Common                                      */
#define __NR_setsid             175 /* Common                                      */
#define __NR_fchdir             176 /* Common                                      */
#define __NR_fgetxattr          177 /* SunOS: fchroot                              */
#define __NR_listxattr          178 /* SunOS: vpixsys                              */
#define __NR_llistxattr         179 /* SunOS: aioread                              */
#define __NR_flistxattr         180 /* SunOS: aiowrite                             */
#define __NR_removexattr        181 /* SunOS: aiowait                              */
#define __NR_lremovexattr       182 /* SunOS: aiocancel                            */
#define __NR_sigpending         183 /* Common                                      */
#define __NR_query_module	184 /* Linux Specific				   */
#define __NR_setpgid            185 /* Common                                      */
#define __NR_fremovexattr       186 /* SunOS: pathconf                             */
#define __NR_tkill              187 /* SunOS: fpathconf                            */
#define __NR_exit_group		188 /* Linux specific, sysconf undef SunOS         */
#define __NR_uname              189 /* Linux Specific                              */
#define __NR_init_module        190 /* Linux Specific                              */
#define __NR_personality        191 /* Linux Specific                              */
#define __NR_remap_file_pages   192 /* Linux Specific                              */
#define __NR_epoll_create       193 /* Linux Specific                              */
#define __NR_epoll_ctl          194 /* Linux Specific                              */
#define __NR_epoll_wait         195 /* Linux Specific                              */
/* #define __NR_ulimit          196    Linux Specific                              */
#define __NR_getppid            197 /* Linux Specific                              */
#define __NR_sigaction          198 /* Linux Specific                              */
#define __NR_sgetmask           199 /* Linux Specific                              */
#define __NR_ssetmask           200 /* Linux Specific                              */
#define __NR_sigsuspend         201 /* Linux Specific                              */
#define __NR_oldlstat           202 /* Linux Specific                              */
#define __NR_uselib             203 /* Linux Specific                              */
#define __NR_readdir            204 /* Linux Specific                              */
#define __NR_readahead          205 /* Linux Specific                              */
#define __NR_socketcall         206 /* Linux Specific                              */
#define __NR_syslog             207 /* Linux Specific                              */
#define __NR_lookup_dcookie     208 /* Linux Specific                              */
#define __NR_fadvise64          209 /* Linux Specific                              */
#define __NR_fadvise64_64       210 /* Linux Specific                              */
#define __NR_tgkill             211 /* Linux Specific                              */
#define __NR_waitpid            212 /* Linux Specific                              */
#define __NR_swapoff            213 /* Linux Specific                              */
#define __NR_sysinfo            214 /* Linux Specific                              */
#define __NR_ipc                215 /* Linux Specific                              */
#define __NR_sigreturn          216 /* Linux Specific                              */
#define __NR_clone              217 /* Linux Specific                              */
/* #define __NR_modify_ldt      218    Linux Specific - i386 specific, unused      */
#define __NR_adjtimex           219 /* Linux Specific                              */
#define __NR_sigprocmask        220 /* Linux Specific                              */
#define __NR_create_module      221 /* Linux Specific                              */
#define __NR_delete_module      222 /* Linux Specific                              */
#define __NR_get_kernel_syms    223 /* Linux Specific                              */
#define __NR_getpgid            224 /* Linux Specific                              */
#define __NR_bdflush            225 /* Linux Specific                              */
#define __NR_sysfs              226 /* Linux Specific                              */
#define __NR_afs_syscall        227 /* Linux Specific                              */
#define __NR_setfsuid           228 /* Linux Specific                              */
#define __NR_setfsgid           229 /* Linux Specific                              */
#define __NR__newselect         230 /* Linux Specific                              */
/* #define __NR_oldstat         232    Linux Specific                              */
#define __NR_stime              233 /* Linux Specific                              */
#define __NR_statfs64           234 /* Linux Specific                              */
#define __NR_fstatfs64          235 /* Linux Specific                              */
#define __NR__llseek            236 /* Linux Specific                              */
#define __NR_mlock              237
#define __NR_munlock            238
#define __NR_mlockall           239
#define __NR_munlockall         240
#define __NR_sched_setparam     241
#define __NR_sched_getparam     242
#define __NR_sched_setscheduler 243
#define __NR_sched_getscheduler 244
#define __NR_sched_yield        245
#define __NR_sched_get_priority_max 246
#define __NR_sched_get_priority_min 247
#define __NR_sched_rr_get_interval  248
#define __NR_nanosleep          249
#define __NR_mremap             250
#define __NR__sysctl            251
#define __NR_getsid             252
#define __NR_fdatasync          253
#define __NR_nfsservctl         254
#define __NR_aplib              255
#define __NR_clock_settime	256
#define __NR_clock_gettime	257
#define __NR_clock_getres	258
#define __NR_clock_nanosleep	259
#define __NR_sched_getaffinity	260
#define __NR_sched_setaffinity	261
#define __NR_timer_settime	262
#define __NR_timer_gettime	263
#define __NR_timer_getoverrun	264
#define __NR_timer_delete	265
#define __NR_timer_create	266
/* #define __NR_vserver		267 Reserved for VSERVER */
#define __NR_io_setup		268
#define __NR_io_destroy		269
#define __NR_io_submit		270
#define __NR_io_cancel		271
#define __NR_io_getevents	272
#define __NR_mq_open		273
#define __NR_mq_unlink		274
#define __NR_mq_timedsend	275
#define __NR_mq_timedreceive	276
#define __NR_mq_notify		277
#define __NR_mq_getsetattr	278
#define __NR_waitid		279
/*#define __NR_sys_setaltroot	280 available (was setaltroot) */
#define __NR_add_key		281
#define __NR_request_key	282
#define __NR_keyctl		283
#define __NR_openat		284
#define __NR_mkdirat		285
#define __NR_mknodat		286
#define __NR_fchownat		287
#define __NR_futimesat		288
#define __NR_fstatat64		289
#define __NR_unlinkat		290
#define __NR_renameat		291
#define __NR_linkat		292
#define __NR_symlinkat		293
#define __NR_readlinkat		294
#define __NR_fchmodat		295
#define __NR_faccessat		296
#define __NR_pselect6		297
#define __NR_ppoll		298
#define __NR_unshare		299
#define __NR_set_robust_list	300
#define __NR_get_robust_list	301
#define __NR_migrate_pages	302
#define __NR_mbind		303
#define __NR_get_mempolicy	304
#define __NR_set_mempolicy	305
#define __NR_kexec_load		306
#define __NR_move_pages		307
#define __NR_getcpu		308
#define __NR_epoll_pwait	309
#define __NR_utimensat		310
#define __NR_signalfd		311
#define __NR_timerfd		312
#define __NR_eventfd		313
#define __NR_fallocate		314
#define __NR_timerfd_settime	315
#define __NR_timerfd_gettime	316

#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,function; \
.weak wsym; \
wsym: ; \
.type sym,function; \
.global sym; \
sym: \
	b __unified_syscall; \
	mov __NR_##name, %g1

#define syscall(name,sym) \
.text; \
.type sym,function; \
.global sym; \
sym: \
	b __unified_syscall; \
	mov __NR_##name, %g1

dietlibc-0.33~cvs20120325/sparc64/unified.S010064400000000000000000000011721173363230200147300ustar00#include 
#include "syscalls.h"

.text
.weak exit
.type exit,function
exit:
.global _exit
.type	_exit,function
_exit:
	mov	__NR_exit, %g1
.global __unified_syscall
__unified_syscall:
	ta	0x6d

	bcs	%xcc, 1f	/* error ? */
	nop

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"
	retl
	nop

.global __unified_syscall_error_handler
__unified_syscall_error_handler:
1:	save	%sp, -192, %sp
#ifdef WANT_THREAD_SAFE
	call	__errno_location
	nop
#else
	sethi	%hi(errno), %o0
	or	%o0, %lo(errno), %o0
#endif
	st	%i0, [ %o0 ]	/* store errno */
	ret
	restore %g0, -1, %o0	/* return -1 */

dietlibc-0.33~cvs20120325/syscalls.h010064400000000000000000000013241173363226000137070ustar00#if defined(__i386__)
#include "i386/syscalls.h"

#elif defined(__x86_64__)
#include "x86_64/syscalls.h"

#elif defined(__sparc__)
#if defined(__arch64__)
#include "sparc64/syscalls.h"
#else
#include "sparc/syscalls.h"
#endif

#elif defined(__powerpc64__)
#include "ppc64/syscalls.h"

#elif defined(__powerpc__)
#include "ppc/syscalls.h"

#elif defined(__mips__)
#include "mips/syscalls.h"

#elif defined(__arm__)
#include "arm/syscalls.h"

#elif defined(__s390__)
#if defined(__s390x__)
#include "s390x/syscalls.h"
#else
#include "s390/syscalls.h"
#endif

#elif defined(__alpha__)
#include "alpha/syscalls.h"

#elif defined(__hppa__)
#include "parisc/syscalls.h"

#elif defined(__ia64__)
#include "ia64/syscalls.h"

#endif
dietlibc-0.33~cvs20120325/syscalls.s/__accept.S010064400000000000000000000001331173363230200156520ustar00#include "syscalls.h"

#ifdef __NR_accept
syscall_weak(accept,accept,__libc_accept)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__bind.S010064400000000000000000000001231173363230200153260ustar00#include "syscalls.h"

#ifdef __NR_bind
syscall_weak(bind,bind,__libc_bind)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__connect.S010064400000000000000000000001371173363230200160500ustar00#include "syscalls.h"

#ifdef __NR_connect
syscall_weak(connect,connect,__libc_connect)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__getpagesize.S010064400000000000000000000001271173363230200167250ustar00#include "syscalls.h"

#ifdef __NR_getpagesize
syscall(getpagesize,getpagesize)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__getpeername.S010064400000000000000000000001571173363230200167150ustar00#include "syscalls.h"

#ifdef __NR_getpeername
syscall_weak(getpeername,getpeername,__libc_getpeername)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__getsockname.S010064400000000000000000000001571173363230200167210ustar00#include "syscalls.h"

#ifdef __NR_getsockname
syscall_weak(getsockname,getsockname,__libc_getsockname)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__getsockopt.S010064400000000000000000000001531173363230200165770ustar00#include "syscalls.h"

#ifdef __NR_getsockopt
syscall_weak(getsockopt,getsockopt,__libc_getsockopt)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__guard.S010064400000000000000000000003251173363230200155200ustar00#include 
.data
.type __guard,@object
.global __guard
.type __stack_chk_guard,@object
.global __stack_chk_guard
__guard:
__stack_chk_guard:
#if __WORDSIZE == 64
.quad 0xaff00
#else
.long 0xaff00
#endif

dietlibc-0.33~cvs20120325/syscalls.s/__listen.S010064400000000000000000000001331173363230200157110ustar00#include "syscalls.h"

#ifdef __NR_listen
syscall_weak(listen,listen,__libc_listen)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__pread.S010064400000000000000000000002201173363230200155030ustar00#include "syscalls.h"

#ifdef __NR_pread64
syscall_weak(pread64,pread64,__libc_pread64)
#else
syscall_weak(pread,pread64,__libc_pread64)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__pwrite.S010064400000000000000000000002271173363230200157310ustar00#include "syscalls.h"

#ifdef __NR_pwrite64
syscall_weak(pwrite64,pwrite64,__libc_pwrite64)
#else
syscall_weak(pwrite,pwrite64,__libc_pwrite64)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__reboot.S010064400000000000000000000000601173363230200157040ustar00#include "syscalls.h"

syscall(reboot,__reboot)
dietlibc-0.33~cvs20120325/syscalls.s/__recv.S010064400000000000000000000001231173363230200153510ustar00#include "syscalls.h"

#ifdef __NR_recv
syscall_weak(recv,recv,__libc_recv)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__recvfrom.S010064400000000000000000000001431173363230200162370ustar00#include "syscalls.h"

#ifdef __NR_recvfrom
syscall_weak(recvfrom,recvfrom,__libc_recvfrom)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__recvmsg.S010064400000000000000000000001371173363230200160650ustar00#include "syscalls.h"

#ifdef __NR_recvmsg
syscall_weak(recvmsg,recvmsg,__libc_recvmsg)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__send.S010064400000000000000000000001231173363230200153430ustar00#include "syscalls.h"

#ifdef __NR_send
syscall_weak(send,send,__libc_send)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__sendmsg.S010064400000000000000000000001371173363230200160570ustar00#include "syscalls.h"

#ifdef __NR_sendmsg
syscall_weak(sendmsg,sendmsg,__libc_sendmsg)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__sendto.S010064400000000000000000000001331173363230200157070ustar00#include "syscalls.h"

#ifdef __NR_sendto
syscall_weak(sendto,sendto,__libc_sendto)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__setsockopt.S010064400000000000000000000001531173363230200166130ustar00#include "syscalls.h"

#ifdef __NR_setsockopt
syscall_weak(setsockopt,setsockopt,__libc_setsockopt)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__shutdown.S010064400000000000000000000001431173363230200162670ustar00#include "syscalls.h"

#ifdef __NR_shutdown
syscall_weak(shutdown,shutdown,__libc_shutdown)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__signalfd.S010064400000000000000000000001201173363230200161760ustar00#include "syscalls.h"

#ifdef __NR_signalfd
syscall(signalfd,__signalfd)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__socket.S010064400000000000000000000001331173363230200157030ustar00#include "syscalls.h"

#ifdef __NR_socket
syscall_weak(socket,socket,__libc_socket)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/__socketpair.S010064400000000000000000000001531173363230200165610ustar00#include "syscalls.h"

#ifdef __NR_socketpair
syscall_weak(socketpair,socketpair,__libc_socketpair)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/_llseek.S010064400000000000000000000001701173363230200155340ustar00#include "syscalls.h"

#ifdef __NR__llseek
.global llseek
.type	llseek,function
llseek:
syscall(_llseek,_llseek)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/access.S010064400000000000000000000000561173363230200153620ustar00#include "syscalls.h"

syscall(access,access)
dietlibc-0.33~cvs20120325/syscalls.s/add_key.S010064400000000000000000000000601173363230200155140ustar00#include "syscalls.h"

syscall(add_key,add_key)
dietlibc-0.33~cvs20120325/syscalls.s/adjtimex.S010064400000000000000000000000621173363230200157230ustar00#include "syscalls.h"

syscall(adjtimex,adjtimex)
dietlibc-0.33~cvs20120325/syscalls.s/alarm.S010064400000000000000000000001351173363230200152130ustar00#include "syscalls.h"
#ifdef __NR_alarm
#ifdef __NR_alarm
syscall(alarm,alarm)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/bdflush.S010064400000000000000000000001131173363230200155420ustar00#include "syscalls.h"

#ifdef __NR_bdflush
syscall(bdflush,bdflush)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/brk.S010064400000000000000000000000571173363230200147000ustar00#include "syscalls.h"

syscall(brk,__diet_brk)
dietlibc-0.33~cvs20120325/syscalls.s/capget.S010064400000000000000000000000561173363230200153640ustar00#include "syscalls.h"

syscall(capget,capget)
dietlibc-0.33~cvs20120325/syscalls.s/capset.S010064400000000000000000000000561173363230200154000ustar00#include "syscalls.h"

syscall(capset,capset)
dietlibc-0.33~cvs20120325/syscalls.s/chdir.S010064400000000000000000000000541173363230200152100ustar00#include "syscalls.h"

syscall(chdir,chdir)
dietlibc-0.33~cvs20120325/syscalls.s/chmod.S010064400000000000000000000000541173363230200152110ustar00#include "syscalls.h"

syscall(chmod,chmod)
dietlibc-0.33~cvs20120325/syscalls.s/chown.S010064400000000000000000000000541173363230200152350ustar00#include "syscalls.h"

syscall(chown,chown)
dietlibc-0.33~cvs20120325/syscalls.s/chown32.S010064400000000000000000000001371173363230200154040ustar00#include "syscalls.h"

#ifdef __NR_chown32
syscall_weak(chown32,chown32,__libc_chown32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/chroot.S010064400000000000000000000000561173363230200154170ustar00#include "syscalls.h"

syscall(chroot,chroot)
dietlibc-0.33~cvs20120325/syscalls.s/clock_getres.S010064400000000000000000000000721173363230200165630ustar00#include "syscalls.h"

syscall(clock_getres,clock_getres)
dietlibc-0.33~cvs20120325/syscalls.s/clock_gettime.S010064400000000000000000000000741173363230200167320ustar00#include "syscalls.h"

syscall(clock_gettime,clock_gettime)
dietlibc-0.33~cvs20120325/syscalls.s/clock_nanosleep.S010064400000000000000000000001001173363230200172460ustar00#include "syscalls.h"

syscall(clock_nanosleep,clock_nanosleep)
dietlibc-0.33~cvs20120325/syscalls.s/clock_settime.S010064400000000000000000000000741173363230200167460ustar00#include "syscalls.h"

syscall(clock_settime,clock_settime)
dietlibc-0.33~cvs20120325/syscalls.s/close.S010064400000000000000000000000761173363230200152300ustar00#include "syscalls.h"

syscall_weak(close,close,__libc_close)
dietlibc-0.33~cvs20120325/syscalls.s/create_module.S010064400000000000000000000001351173363230200167270ustar00#include "syscalls.h"

#ifdef __NR_create_module
syscall(create_module,create_module)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/delete_module.S010064400000000000000000000001351173363230200167260ustar00#include "syscalls.h"

#ifdef __NR_delete_module
syscall(delete_module,delete_module)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/dup.S010064400000000000000000000000501173363230200147030ustar00#include "syscalls.h"

syscall(dup,dup)
dietlibc-0.33~cvs20120325/syscalls.s/dup2.S010064400000000000000000000000521173363230200147670ustar00#include "syscalls.h"

syscall(dup2,dup2)
dietlibc-0.33~cvs20120325/syscalls.s/environ.S010064400000000000000000000003641173363230200156030ustar00.section ".bss"
.align 8
#include 

.type environ,object
.weak environ
.type __environ,object
.weak __environ
__environ:
environ:
#if __WORDSIZE == 64
	.quad 0
#else
	.long 0
#endif
.size environ,.-environ
.size __environ,.-__environ
dietlibc-0.33~cvs20120325/syscalls.s/epoll_create.S010064400000000000000000000001321173363230200165520ustar00#include "syscalls.h"

#ifdef __NR_epoll_create
syscall(epoll_create,epoll_create)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/epoll_ctl.S010064400000000000000000000001211173363230200160670ustar00#include "syscalls.h"

#ifdef __NR_epoll_ctl
syscall(epoll_ctl,epoll_ctl)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/epoll_wait.S010064400000000000000000000001241173363230200162540ustar00#include "syscalls.h"

#ifdef __NR_epoll_wait
syscall(epoll_wait,epoll_wait)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/errlist.S010064400000000000000000000173101173363230200156060ustar00#include 

#
#  My gcc tries to align some of the strings if written the code in C. This costs a lot of bytes.
#

#ifdef __DYN_LIB
.section	.data
#else
.section	.rodata
#endif

.align 4
.global sys_errlist
#ifdef __arm__
.type	sys_errlist,object
.type	sys_nerr,object
#else
.type	sys_errlist,@object
.type	sys_nerr,@object
#endif

#if (__WORDSIZE == 64)
#define deflong .quad
#else
#define deflong .long
#endif

sys_errlist:
	deflong .LC000
	deflong .LC001
	deflong .LC002
	deflong .LC003
	deflong .LC004
	deflong .LC005
	deflong .LC006
	deflong .LC007
	deflong .LC008
	deflong .LC009
	deflong .LC010
	deflong .LC011
	deflong .LC012
	deflong .LC013
	deflong .LC014
	deflong .LC015
	deflong .LC016
	deflong .LC017
	deflong .LC018
	deflong .LC019
	deflong .LC020
	deflong .LC021
	deflong .LC022
	deflong .LC023
	deflong .LC024
	deflong .LC025
	deflong .LC026
	deflong .LC027
	deflong .LC028
	deflong .LC029
	deflong .LC030
	deflong .LC031
	deflong .LC032
	deflong .LC033
	deflong .LC034
	deflong .LC035
	deflong .LC036
	deflong .LC037
	deflong .LC038
	deflong .LC039
	deflong .LC040
	deflong .LC041
	deflong .LC042
	deflong .LC043
	deflong .LC044
	deflong .LC045
	deflong .LC046
	deflong .LC047
	deflong .LC048
	deflong .LC049
	deflong .LC050
	deflong .LC051
	deflong .LC052
	deflong .LC053
	deflong .LC054
	deflong .LC055
	deflong .LC056
	deflong .LC057
	deflong .LC058
	deflong .LC059
	deflong .LC060
	deflong .LC061
	deflong .LC062
	deflong .LC063
	deflong .LC064
	deflong .LC065
	deflong .LC066
	deflong .LC067
	deflong .LC068
	deflong .LC069
	deflong .LC070
	deflong .LC071
	deflong .LC072
	deflong .LC073
	deflong .LC074
	deflong .LC075
	deflong .LC076
	deflong .LC077
	deflong .LC078
	deflong .LC079
	deflong .LC080
	deflong .LC081
	deflong .LC082
	deflong .LC083
	deflong .LC084
	deflong .LC085
	deflong .LC086
	deflong .LC087
	deflong .LC088
	deflong .LC089
	deflong .LC090
	deflong .LC091
	deflong .LC092
	deflong .LC093
	deflong .LC094
	deflong .LC095
	deflong .LC096
	deflong .LC097
	deflong .LC098
	deflong .LC099
	deflong .LC100
	deflong .LC101
	deflong .LC102
	deflong .LC103
	deflong .LC104
	deflong .LC105
	deflong .LC106
	deflong .LC107
	deflong .LC108
	deflong .LC109
	deflong .LC110
	deflong .LC111
	deflong .LC112
	deflong .LC113
	deflong .LC114
	deflong .LC115
	deflong .LC116
	deflong .LC117
	deflong .LC118
	deflong .LC119
	deflong .LC120
	deflong .LC121
	deflong .LC122
	deflong .LC123
	deflong .LC124
	deflong .LC125
	deflong .LC126
	deflong .LC127
	deflong .LC128
	deflong .LC129
	deflong 0
.size	sys_errlist,.-sys_errlist

.align 4
.global sys_nerr
sys_nerr:
	.long 125
.size	sys_nerr,4


#ifdef __DYN_LIB
.section	.rodata
#endif

.LC000:	.asciz	"Success"
.LC001:	.asciz	"Operation not permitted"
.LC002:	.asciz	"No such file or directory"
.LC003:	.asciz	"No such process"
.LC004:	.asciz	"Interrupted system call"
.LC005:	.asciz	"I/O error"
.LC006:	.asciz	"No such device or address"
.LC007:	.asciz	"Arg list too long"
.LC008:	.asciz	"Exec format error"
.LC009:	.asciz	"Bad file number"
.LC010:	.asciz	"No child processes"
.LC011:	.asciz	"Try again"
.LC012:	.asciz	"Out of memory"
.LC013:	.asciz	"Permission denied"
.LC014:	.asciz	"Bad address"
.LC015:	.asciz	"Block device required"
.LC016:	.asciz	"Device or resource busy"
.LC017:	.asciz	"File exists"
.LC018:	.asciz	"Cross-device link"
.LC019:	.asciz	"No such device"
.LC020:	.asciz	"Not a directory"
.LC021:	.asciz	"Is a directory"
.LC022:	.asciz	"Invalid argument"
.LC023:	.asciz	"File table overflow"
.LC024:	.asciz	"Too many open files"
.LC025:	.asciz	"Not a typewriter"
.LC026:	.asciz	"Text file busy"
.LC027:	.asciz	"File too large"
.LC028:	.asciz	"No space left on device"
.LC029:	.asciz	"Illegal seek"
.LC030:	.asciz	"Read-only file system"
.LC031:	.asciz	"Too many links"
.LC032:	.asciz	"Broken pipe"
.LC033:	.asciz	"Math argument out of domain of func"
.LC034:	.asciz	"Math result not representable"
.LC035:	.asciz	"Resource deadlock would occur"
.LC036:	.asciz	"File name too long"
.LC037:	.asciz	"No record locks available"
.LC038:	.asciz	"Function not implemented"
.LC039:	.asciz	"Directory not empty"
.LC040:	.asciz	"Too many symbolic links encountered"
.LC041:	.asciz	"Operation would block"
.LC042:	.asciz	"No message of desired type"
.LC043:	.asciz	"Identifier removed"
.LC044:	.asciz	"Channel number out of range"
.LC045:	.asciz	"Level 2 not synchronized"
.LC046:	.asciz	"Level 3 halted"
.LC047:	.asciz	"Level 3 reset"
.LC048:	.asciz	"Link number out of range"
.LC049:	.asciz	"Protocol driver not attached"
.LC050:	.asciz	"No CSI structure available"
.LC051:	.asciz	"Level 2 halted"
.LC052:	.asciz	"Invalid exchange"
.LC053:	.asciz	"Invalid request descriptor"
.LC054:	.asciz	"Exchange full"
.LC055:	.asciz	"No anode"
.LC056:	.asciz	"Invalid request code"
.LC057:	.asciz	"Invalid slot"
.LC058:	.asciz	"File locking deadlock error"
.LC059:	.asciz	"Bad font file format"
.LC060:	.asciz	"Device not a stream"
.LC061:	.asciz	"No data available"
.LC062:	.asciz	"Timer expired"
.LC063:	.asciz	"Out of streams resources"
.LC064:	.asciz	"Machine is not on the network"
.LC065:	.asciz	"Package not installed"
.LC066:	.asciz	"Object is remote"
.LC067:	.asciz	"Link has been severed"
.LC068:	.asciz	"Advertise error"
.LC069:	.asciz	"Srmount error"
.LC070:	.asciz	"Communication error on send"
.LC071:	.asciz	"Protocol error"
.LC072:	.asciz	"Multihop attempted"
.LC073:	.asciz	"RFS specific error"
.LC074:	.asciz	"Not a data message"
.LC075:	.asciz	"Value too large for defined data type"
.LC076:	.asciz	"Name not unique on network"
.LC077:	.asciz	"File descriptor in bad state"
.LC078:	.asciz	"Remote address changed"
.LC079:	.asciz	"Can not access a needed shared library"
.LC080:	.asciz	"Accessing a corrupted shared library"
.LC081:	.asciz	".lib section in a.out corrupted"
.LC082:	.asciz	"Attempting to link in too many shared libraries"
.LC083:	.asciz	"Cannot exec a shared library directly"
.LC084:	.asciz	"Illegal byte sequence"
.LC085:	.asciz	"Interrupted system call should be restarted"
.LC086:	.asciz	"Streams pipe error"
.LC087:	.asciz	"Too many users"
.LC088:	.asciz	"Socket operation on non-socket"
.LC089:	.asciz	"Destination address required"
.LC090:	.asciz	"Message too long"
.LC091:	.asciz	"Protocol wrong type for socket"
.LC092:	.asciz	"Protocol not available"
.LC093:	.asciz	"Protocol not supported"
.LC094:	.asciz	"Socket type not supported"
.LC095:	.asciz	"Operation not supported on transport endpoint"
.LC096:	.asciz	"Protocol family not supported"
.LC097:	.asciz	"Address family not supported by protocol"
.LC098:	.asciz	"Address already in use"
.LC099:	.asciz	"Cannot assign requested address"
.LC100:	.asciz	"Network is down"
.LC101:	.asciz	"Network is unreachable"
.LC102:	.asciz	"Network dropped connection because of reset"
.LC103:	.asciz	"Software caused connection abort"
.LC104:	.asciz	"Connection reset by peer"
.LC105:	.asciz	"No buffer space available"
.LC106:	.asciz	"Transport endpoint is already connected"
.LC107:	.asciz	"Transport endpoint is not connected"
.LC108:	.asciz	"Cannot send after transport endpoint shutdown"
.LC109:	.asciz	"Too many references: cannot splice"
.LC110:	.asciz	"Connection timed out"
.LC111:	.asciz	"Connection refused"
.LC112:	.asciz	"Host is down"
.LC113:	.asciz	"No route to host"
.LC114:	.asciz	"Operation already in progress"
.LC115:	.asciz	"Operation now in progress"
.LC116:	.asciz	"Stale NFS file handle"
.LC117:	.asciz	"Structure needs cleaning"
.LC118:	.asciz	"Not a XENIX named type file"
.LC119:	.asciz	"No XENIX semaphores available"
.LC120:	.asciz	"Is a named type file"
.LC121:	.asciz	"Remote I/O error"
.LC122:	.asciz	"Quota exceeded"
.LC123:	.asciz	"No medium found"
.LC124:	.asciz	"Wrong medium type"
.LC125:	.asciz	"Operation Canceled"
.LC126:	.asciz	"Required key not available"
.LC127:	.asciz	"Key has expired"
.LC128:	.asciz	"Key has been revoked"
.LC129:	.asciz	"Key was rejected by service"
dietlibc-0.33~cvs20120325/syscalls.s/errno.S010064400000000000000000000001351173363230200152440ustar00.section ".bss"
.align 8

.type errno,object
.weak errno
errno:
	.long 0
.size errno,.-errno
dietlibc-0.33~cvs20120325/syscalls.s/execve.S010064400000000000000000000000561173363230200154000ustar00#include "syscalls.h"

syscall(execve,execve)
dietlibc-0.33~cvs20120325/syscalls.s/faccessat.S010064400000000000000000000000641173363230200160540ustar00#include "syscalls.h"

syscall(faccessat,faccessat)
dietlibc-0.33~cvs20120325/syscalls.s/fadvise64.S010064400000000000000000000003751173363230200157200ustar00#ifndef __arm__
/* ARM needs special treatment for fadvise */

#include "syscalls.h"

#ifndef __NR_fadvise64_64
.globl posix_fadvise
.type posix_fadvise,@function
posix_fadvise:
#endif

#ifdef __NR_fadvise64
syscall(fadvise64,fadvise64)

#endif

#endif
dietlibc-0.33~cvs20120325/syscalls.s/fadvise64_64.S010064400000000000000000000002231173363230200162210ustar00#include "syscalls.h"

#ifdef __NR_fadvise64_64
syscall(fadvise64_64,fadvise64_64)

.set   posix_fadvise, fadvise64_64
.globl posix_fadvise
#endif
dietlibc-0.33~cvs20120325/syscalls.s/fallocate.S010064400000000000000000000001211173363230200160440ustar00#include "syscalls.h"

#ifdef __NR_fallocate
syscall(fallocate,fallocate)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/fchdir.S010064400000000000000000000000561173363230200153600ustar00#include "syscalls.h"

syscall(fchdir,fchdir)
dietlibc-0.33~cvs20120325/syscalls.s/fchmod.S010064400000000000000000000000561173363230200153610ustar00#include "syscalls.h"

syscall(fchmod,fchmod)
dietlibc-0.33~cvs20120325/syscalls.s/fchmodat.S010064400000000000000000000000621173363230200157030ustar00#include "syscalls.h"

syscall(fchmodat,fchmodat)
dietlibc-0.33~cvs20120325/syscalls.s/fchown.S010064400000000000000000000000561173363230200154050ustar00#include "syscalls.h"

syscall(fchown,fchown)
dietlibc-0.33~cvs20120325/syscalls.s/fchown32.S010064400000000000000000000001431173363230200155470ustar00#include "syscalls.h"

#ifdef __NR_fchown32
syscall_weak(fchown32,fchown32,__libc_fchown32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/fchownat.S010064400000000000000000000000621173363230200157270ustar00#include "syscalls.h"

syscall(fchownat,fchownat)
dietlibc-0.33~cvs20120325/syscalls.s/fcntl.S010064400000000000000000000000761173363230200152310ustar00#include "syscalls.h"

syscall_weak(fcntl,fcntl,__libc_fcntl)
dietlibc-0.33~cvs20120325/syscalls.s/fcntl64.S010064400000000000000000000002671173363230200154050ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_fcntl64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(fcntl64,__dietlibc_fcntl64)
#else
syscall(fcntl64,fcntl64)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/fdatasync.S010064400000000000000000000002121173363230200160670ustar00#include "syscalls.h"

#ifndef __NR_fdatasync
#define __NR_fdatasync __NR_fsync
#endif
syscall_weak(fdatasync,fdatasync,__libc_fdatasync)
dietlibc-0.33~cvs20120325/syscalls.s/fgetxattr.S010064400000000000000000000000631173363230200161270ustar00#include "syscalls.h"
syscall(fgetxattr,fgetxattr)
dietlibc-0.33~cvs20120325/syscalls.s/flistxattr.S010064400000000000000000000000651173363230200163250ustar00#include "syscalls.h"
syscall(flistxattr,flistxattr)
dietlibc-0.33~cvs20120325/syscalls.s/flock.S010064400000000000000000000000541173363230200152150ustar00#include "syscalls.h"

syscall(flock,flock)
dietlibc-0.33~cvs20120325/syscalls.s/fork.S010064400000000000000000000000731173363230200150610ustar00#include "syscalls.h"

syscall_weak(fork,fork,__libc_fork)
dietlibc-0.33~cvs20120325/syscalls.s/fremovexattr.S010064400000000000000000000000711173363230200166440ustar00#include "syscalls.h"
syscall(fremovexattr,fremovexattr)
dietlibc-0.33~cvs20120325/syscalls.s/fsetxattr.S010064400000000000000000000000641173363230200161440ustar00#include "syscalls.h"

syscall(fsetxattr,fsetxattr)
dietlibc-0.33~cvs20120325/syscalls.s/fstat.S010064400000000000000000000000541173363230200152400ustar00#include "syscalls.h"

syscall(fstat,fstat)
dietlibc-0.33~cvs20120325/syscalls.s/fstat64.S010064400000000000000000000002671173363230200154200ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_fstat64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(fstat64,__dietlibc_fstat64)
#else
syscall(fstat64,fstat64)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/fstatfs.S010064400000000000000000000000601173363230200155660ustar00#include "syscalls.h"

syscall(fstatfs,fstatfs)
dietlibc-0.33~cvs20120325/syscalls.s/fstatfs64.S010064400000000000000000000001341173363230200157420ustar00#include "syscalls.h"

#ifdef __NR_fstatfs64
syscall(fstatfs64,__dietlibc_fstatfs64)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/fsync.S010064400000000000000000000000761173363230200152450ustar00#include "syscalls.h"

syscall_weak(fsync,fsync,__libc_fsync)
dietlibc-0.33~cvs20120325/syscalls.s/ftruncate.S010064400000000000000000000000641173363230200161130ustar00#include "syscalls.h"

syscall(ftruncate,ftruncate)
dietlibc-0.33~cvs20120325/syscalls.s/ftruncate64.S010064400000000000000000000003131173363230200162620ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_ftruncate64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(ftruncate64,__dietlibc_ftruncate64)
#else
syscall(ftruncate64,ftruncate64)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/futex.S010064400000000000000000000000541173363230200152520ustar00#include "syscalls.h"

syscall(futex,futex)
dietlibc-0.33~cvs20120325/syscalls.s/futimesat.S010064400000000000000000000000641173363230200161210ustar00#include "syscalls.h"

syscall(futimesat,futimesat)
dietlibc-0.33~cvs20120325/syscalls.s/get_mempolicy.S010064400000000000000000000001351173363230200167540ustar00#include "syscalls.h"

#ifdef __NR_get_mempolicy
syscall(get_mempolicy,get_mempolicy)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/get_thread_area.S010064400000000000000000000001431173363230200172140ustar00#include "syscalls.h"

#ifdef __NR_get_thread_area
syscall(get_thread_area,get_thread_area)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getcwd.S010064400000000000000000000000701173363230200153720ustar00#include "syscalls.h"

syscall(getcwd,__syscall_getcwd)
dietlibc-0.33~cvs20120325/syscalls.s/getdents.S010064400000000000000000000000621173363230200157330ustar00#include "syscalls.h"

syscall(getdents,getdents)
dietlibc-0.33~cvs20120325/syscalls.s/getdents64.S010064400000000000000000000001561173363230200161110ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_getdents64
syscall(getdents64,getdents64)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getegid.S010064400000000000000000000000601173363230200155240ustar00#include "syscalls.h"

syscall(getegid,getegid)
dietlibc-0.33~cvs20120325/syscalls.s/getegid32.S010064400000000000000000000001471173363230200156770ustar00#include "syscalls.h"

#ifdef __NR_getegid32
syscall_weak(getegid32,getegid32,__libc_getegid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/geteuid.S010064400000000000000000000000601173363230200155420ustar00#include "syscalls.h"

syscall(geteuid,geteuid)
dietlibc-0.33~cvs20120325/syscalls.s/geteuid32.S010064400000000000000000000001471173363230200157150ustar00#include "syscalls.h"

#ifdef __NR_geteuid32
syscall_weak(geteuid32,geteuid32,__libc_geteuid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getgid.S010064400000000000000000000000561173363230200153640ustar00#include "syscalls.h"

syscall(getgid,getgid)
dietlibc-0.33~cvs20120325/syscalls.s/getgid32.S010064400000000000000000000001431173363230200155260ustar00#include "syscalls.h"

#ifdef __NR_getgid32
syscall_weak(getgid32,getgid32,__libc_getgid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getgroups.S010064400000000000000000000000641173363230200161370ustar00#include "syscalls.h"

syscall(getgroups,getgroups)
dietlibc-0.33~cvs20120325/syscalls.s/getgroups32.S010064400000000000000000000001571173363230200163070ustar00#include "syscalls.h"

#ifdef __NR_getgroups32
syscall_weak(getgroups32,getgroups32,__libc_getgroups32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getitimer.S010064400000000000000000000000641173363230200161110ustar00#include "syscalls.h"

syscall(getitimer,getitimer)
dietlibc-0.33~cvs20120325/syscalls.s/getpgid.S010064400000000000000000000000601173363230200155370ustar00#include "syscalls.h"

syscall(getpgid,getpgid)
dietlibc-0.33~cvs20120325/syscalls.s/getpid.S010064400000000000000000000000561173363230200153750ustar00#include "syscalls.h"

syscall(getpid,getpid)
dietlibc-0.33~cvs20120325/syscalls.s/getppid.S010064400000000000000000000000601173363230200155500ustar00#include "syscalls.h"

syscall(getppid,getppid)
dietlibc-0.33~cvs20120325/syscalls.s/getpriority.S010064400000000000000000000001021173363230200164720ustar00#include "syscalls.h"

syscall(getpriority,__syscall_getpriority)
dietlibc-0.33~cvs20120325/syscalls.s/getresgid.S010064400000000000000000000001231173363230200160710ustar00#include "syscalls.h"

#ifdef __NR_getresgid

syscall(getresgid,getresgid)

#endif
dietlibc-0.33~cvs20120325/syscalls.s/getresgid32.S010064400000000000000000000001571173363230200162450ustar00#include "syscalls.h"

#ifdef __NR_getresgid32
syscall_weak(getresgid32,getresgid32,__libc_getresgid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getresuid.S010064400000000000000000000001231173363230200161070ustar00#include "syscalls.h"

#ifdef __NR_getresuid

syscall(getresuid,getresuid)

#endif
dietlibc-0.33~cvs20120325/syscalls.s/getrlimit.S010064400000000000000000000002221173363230200161140ustar00#include "syscalls.h"

#ifdef __NR_ugetrlimit

syscall(ugetrlimit,getrlimit)

#elif defined(__NR_getrlimit)

syscall(getrlimit,getrlimit)

#endif
dietlibc-0.33~cvs20120325/syscalls.s/getrusage.S010064400000000000000000000000641173363230200161060ustar00#include "syscalls.h"

syscall(getrusage,getrusage)
dietlibc-0.33~cvs20120325/syscalls.s/getsid.S010064400000000000000000000000561173363230200154000ustar00#include "syscalls.h"

syscall(getsid,getsid)
dietlibc-0.33~cvs20120325/syscalls.s/gettid.S010064400000000000000000000000561173363230200154010ustar00#include "syscalls.h"

syscall(gettid,gettid)
dietlibc-0.33~cvs20120325/syscalls.s/gettimeofday.S010064400000000000000000000000721173363230200166000ustar00#include "syscalls.h"

syscall(gettimeofday,gettimeofday)
dietlibc-0.33~cvs20120325/syscalls.s/getuid.S010064400000000000000000000000561173363230200154020ustar00#include "syscalls.h"

syscall(getuid,getuid)
dietlibc-0.33~cvs20120325/syscalls.s/getuid32.S010064400000000000000000000001431173363230200155440ustar00#include "syscalls.h"

#ifdef __NR_getuid32
syscall_weak(getuid32,getuid32,__libc_getuid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/getxattr.S010064400000000000000000000000611173363230200157570ustar00#include "syscalls.h"
syscall(getxattr,getxattr)
dietlibc-0.33~cvs20120325/syscalls.s/init_module.S010064400000000000000000000001271173363230200164300ustar00#include "syscalls.h"

#ifdef __NR_init_module
syscall(init_module,init_module)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/inotify_add_watch.S010064400000000000000000000001511173363230200175740ustar00#include "syscalls.h"

#ifdef __NR_inotify_add_watch
syscall(inotify_add_watch,inotify_add_watch)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/inotify_init.S010064400000000000000000000001321173363230200166200ustar00#include "syscalls.h"

#ifdef __NR_inotify_init
syscall(inotify_init,inotify_init)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/inotify_rm_watch.S010064400000000000000000000001461173363230200174660ustar00#include "syscalls.h"

#ifdef __NR_inotify_rm_watch
syscall(inotify_rm_watch,inotify_rm_watch)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/io_cancel.S010064400000000000000000000000641173363230200160340ustar00#include "syscalls.h"

syscall(io_cancel,io_cancel)
dietlibc-0.33~cvs20120325/syscalls.s/io_destroy.S010064400000000000000000000000661173363230200163020ustar00#include "syscalls.h"

syscall(io_destroy,io_destroy)
dietlibc-0.33~cvs20120325/syscalls.s/io_getevents.S010064400000000000000000000000721173363230200166120ustar00#include "syscalls.h"

syscall(io_getevents,io_getevents)
dietlibc-0.33~cvs20120325/syscalls.s/io_setup.S010064400000000000000000000000621173363230200157450ustar00#include "syscalls.h"

syscall(io_setup,io_setup)
dietlibc-0.33~cvs20120325/syscalls.s/io_submit.S010064400000000000000000000000641173363230200161120ustar00#include "syscalls.h"

syscall(io_submit,io_submit)
dietlibc-0.33~cvs20120325/syscalls.s/ioctl.S010064400000000000000000000000541173363230200152310ustar00#include "syscalls.h"

syscall(ioctl,ioctl)
dietlibc-0.33~cvs20120325/syscalls.s/ioperm.S010064400000000000000000000001101173363230200154030ustar00#include "syscalls.h"

#ifdef __NR_ioperm
syscall(ioperm,ioperm)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/iopl.S010064400000000000000000000001031173363230200150550ustar00
#include "syscalls.h"

#ifdef __NR_iopl
syscall(iopl,iopl)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/ipc.S010064400000000000000000000001011173363230200146630ustar00#include "syscalls.h"

#ifdef __NR_ipc
syscall(ipc,__ipc)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/keyctl.S010064400000000000000000000000561173363230200154140ustar00#include "syscalls.h"

syscall(keyctl,keyctl)
dietlibc-0.33~cvs20120325/syscalls.s/kill.S010064400000000000000000000000521173363230200150500ustar00#include "syscalls.h"

syscall(kill,kill)
dietlibc-0.33~cvs20120325/syscalls.s/lchown.S010064400000000000000000000000561173363230200154130ustar00#include "syscalls.h"

syscall(lchown,lchown)
dietlibc-0.33~cvs20120325/syscalls.s/lchown32.S010064400000000000000000000001431173363230200155550ustar00#include "syscalls.h"

#ifdef __NR_lchown32
syscall_weak(lchown32,lchown32,__libc_lchown32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/lgetxattr.S010064400000000000000000000000631173363230200161350ustar00#include "syscalls.h"
syscall(lgetxattr,lgetxattr)
dietlibc-0.33~cvs20120325/syscalls.s/link.S010064400000000000000000000000521173363230200150520ustar00#include "syscalls.h"

syscall(link,link)
dietlibc-0.33~cvs20120325/syscalls.s/linkat.S010064400000000000000000000000561173363230200154030ustar00#include "syscalls.h"

syscall(linkat,linkat)
dietlibc-0.33~cvs20120325/syscalls.s/listxattr.S010064400000000000000000000000631173363230200161550ustar00#include "syscalls.h"
syscall(listxattr,listxattr)
dietlibc-0.33~cvs20120325/syscalls.s/llistxattr.S010064400000000000000000000000651173363230200163330ustar00#include "syscalls.h"
syscall(llistxattr,llistxattr)
dietlibc-0.33~cvs20120325/syscalls.s/lremovexattr.S010064400000000000000000000000711173363230200166520ustar00#include "syscalls.h"
syscall(lremovexattr,lremovexattr)
dietlibc-0.33~cvs20120325/syscalls.s/lseek.S010064400000000000000000000000761173363230200152260ustar00#include "syscalls.h"

syscall_weak(lseek,lseek,__libc_lseek)
dietlibc-0.33~cvs20120325/syscalls.s/lsetxattr.S010064400000000000000000000000641173363230200161520ustar00#include "syscalls.h"

syscall(lsetxattr,lsetxattr)
dietlibc-0.33~cvs20120325/syscalls.s/lstat.S010064400000000000000000000000541173363230200152460ustar00#include "syscalls.h"

syscall(lstat,lstat)
dietlibc-0.33~cvs20120325/syscalls.s/lstat64.S010064400000000000000000000002671173363230200154260ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_lstat64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(lstat64,__dietlibc_lstat64)
#else
syscall(lstat64,lstat64)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/madvise.S010064400000000000000000000000601173363230200155440ustar00#include "syscalls.h"

syscall(madvise,madvise)
dietlibc-0.33~cvs20120325/syscalls.s/mbind.S010064400000000000000000000001051173363230200152050ustar00#include "syscalls.h"

#ifdef __NR_mbind
syscall(mbind,mbind)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/mincore.S010064400000000000000000000000601173363230200155500ustar00#include "syscalls.h"

syscall(mincore,mincore)
dietlibc-0.33~cvs20120325/syscalls.s/mkdir.S010064400000000000000000000000541173363230200152250ustar00#include "syscalls.h"

syscall(mkdir,mkdir)
dietlibc-0.33~cvs20120325/syscalls.s/mkdirat.S010064400000000000000000000000601173363230200155470ustar00#include "syscalls.h"

syscall(mkdirat,mkdirat)
dietlibc-0.33~cvs20120325/syscalls.s/mknod.S010064400000000000000000000000541173363230200152270ustar00#include "syscalls.h"

syscall(mknod,mknod)
dietlibc-0.33~cvs20120325/syscalls.s/mknodat.S010064400000000000000000000000601173363230200155510ustar00#include "syscalls.h"

syscall(mknodat,mknodat)
dietlibc-0.33~cvs20120325/syscalls.s/mlock.S010064400000000000000000000000541173363230200152240ustar00#include "syscalls.h"

syscall(mlock,mlock)
dietlibc-0.33~cvs20120325/syscalls.s/mlockall.S010064400000000000000000000000621173363230200157140ustar00#include "syscalls.h"

syscall(mlockall,mlockall)
dietlibc-0.33~cvs20120325/syscalls.s/mmap.S010064400000000000000000000001041173363230200150450ustar00#include "syscalls.h"

#ifdef __NR_mmap

syscall(mmap,mmap)

#endif
dietlibc-0.33~cvs20120325/syscalls.s/mmap2.S010064400000000000000000000001071173363230200151320ustar00#include "syscalls.h"

#ifdef __NR_mmap2
syscall(mmap2,__mmap2)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/mount.S010064400000000000000000000000541173363230200152610ustar00#include "syscalls.h"

syscall(mount,mount)
dietlibc-0.33~cvs20120325/syscalls.s/mprotect.S010064400000000000000000000000621173363230200157530ustar00#include "syscalls.h"

syscall(mprotect,mprotect)
dietlibc-0.33~cvs20120325/syscalls.s/mq_getsetattr.S010064400000000000000000000000711173363230200170010ustar00#include "syscalls.h"

syscall(mq_getsetattr,mq_setattr)
dietlibc-0.33~cvs20120325/syscalls.s/mq_notify.S010064400000000000000000000000641173363230200161250ustar00#include "syscalls.h"

syscall(mq_notify,mq_notify)
dietlibc-0.33~cvs20120325/syscalls.s/mq_open.S010064400000000000000000000000601173363230200155520ustar00#include "syscalls.h"

syscall(mq_open,mq_open)
dietlibc-0.33~cvs20120325/syscalls.s/mq_timedreceive.S010064400000000000000000000001001173363230200172510ustar00#include "syscalls.h"

syscall(mq_timedreceive,mq_timedreceive)
dietlibc-0.33~cvs20120325/syscalls.s/mq_timedsend.S010064400000000000000000000000721173363230200165700ustar00#include "syscalls.h"

syscall(mq_timedsend,mq_timedsend)
dietlibc-0.33~cvs20120325/syscalls.s/mq_unlink.S010064400000000000000000000000641173363230200161150ustar00#include "syscalls.h"

syscall(mq_unlink,mq_unlink)
dietlibc-0.33~cvs20120325/syscalls.s/mremap.S010064400000000000000000000000561173363230200154020ustar00#include "syscalls.h"

syscall(mremap,mremap)
dietlibc-0.33~cvs20120325/syscalls.s/msync.S010064400000000000000000000000761173363230200152540ustar00#include "syscalls.h"

syscall_weak(msync,msync,__libc_msync)
dietlibc-0.33~cvs20120325/syscalls.s/munlock.S010064400000000000000000000000601173363230200155640ustar00#include "syscalls.h"

syscall(munlock,munlock)
dietlibc-0.33~cvs20120325/syscalls.s/munlockall.S010064400000000000000000000000661173363230200162630ustar00#include "syscalls.h"

syscall(munlockall,munlockall)
dietlibc-0.33~cvs20120325/syscalls.s/munmap.S010064400000000000000000000000561173363230200154160ustar00#include "syscalls.h"

syscall(munmap,munmap)
dietlibc-0.33~cvs20120325/syscalls.s/n_sigaction.S010064400000000000000000000001521173363230200164130ustar00#include "syscalls.h"

#ifdef __NR_sigaction
syscall_weak(sigaction,__old_sigaction,__n_sigaction)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/n_sigpending.S010064400000000000000000000001561173363230200165660ustar00#include "syscalls.h"

#ifdef __NR_sigpending
syscall_weak(sigpending,__old_sigpending,__n_sigpending)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/n_sigprocmask.S010064400000000000000000000001621173363230200167560ustar00#include "syscalls.h"

#ifdef __NR_sigprocmask
syscall_weak(sigprocmask,__old_sigprocmask,__n_sigprocmask)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/n_sigsuspend.S010064400000000000000000000001561173363230200166230ustar00#include "syscalls.h"

#ifdef __NR_sigsuspend
syscall_weak(sigsuspend,__old_sigsuspend,__n_sigsuspend)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/nanosleep.S010064400000000000000000000001121173363230200160760ustar00#include "syscalls.h"

syscall_weak(nanosleep,nanosleep,__libc_nanosleep)
dietlibc-0.33~cvs20120325/syscalls.s/newfstatat.S010064400000000000000000000001241173363230200162750ustar00#include "syscalls.h"

#ifdef __NR_newfstatat
syscall(newfstatat,newfstatat)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/open.S010064400000000000000000000000731173363230200150610ustar00#include "syscalls.h"

syscall_weak(open,open,__libc_open)
dietlibc-0.33~cvs20120325/syscalls.s/openat.S010064400000000000000000000000561173363230200154070ustar00#include "syscalls.h"

syscall(openat,openat)
dietlibc-0.33~cvs20120325/syscalls.s/pause.S010064400000000000000000000001271173363230200152350ustar00#include "syscalls.h"

#ifdef __NR_pause
syscall_weak(pause,pause,__libc_pause)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/personality.S010064400000000000000000000001271173363230200164710ustar00#include "syscalls.h"

#ifdef __NR_personality
syscall(personality,personality)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/pipe.S010064400000000000000000000000521173363230200150520ustar00#include "syscalls.h"

syscall(pipe,pipe)
dietlibc-0.33~cvs20120325/syscalls.s/pivot_root.S010064400000000000000000000000661173363230200163260ustar00#include "syscalls.h"

syscall(pivot_root,pivot_root)
dietlibc-0.33~cvs20120325/syscalls.s/poll.S010064400000000000000000000000521173363230200150630ustar00#include "syscalls.h"

syscall(poll,poll)
dietlibc-0.33~cvs20120325/syscalls.s/prctl.S010064400000000000000000000001051173363230200152400ustar00#include "syscalls.h"

#ifdef __NR_prctl
syscall(prctl,prctl)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/ptrace.S010064400000000000000000000000651173363230200153770ustar00#include "syscalls.h"

syscall(ptrace,__diet_ptrace)
dietlibc-0.33~cvs20120325/syscalls.s/query_module.S010064400000000000000000000001321173363230200166260ustar00#include "syscalls.h"

#ifdef __NR_query_module
syscall(query_module,query_module)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/quotactl.S010064400000000000000000000000621173363230200157520ustar00#include "syscalls.h"

syscall(quotactl,quotactl)
dietlibc-0.33~cvs20120325/syscalls.s/read.S010064400000000000000000000000731173363230200150330ustar00#include "syscalls.h"

syscall_weak(read,read,__libc_read)
dietlibc-0.33~cvs20120325/syscalls.s/readahead.S010064400000000000000000000000641173363230200160160ustar00#include "syscalls.h"

syscall(readahead,readahead)
dietlibc-0.33~cvs20120325/syscalls.s/readlink.S010064400000000000000000000000621173363230200157070ustar00#include "syscalls.h"

syscall(readlink,readlink)
dietlibc-0.33~cvs20120325/syscalls.s/readlinkat.S010064400000000000000000000000661173363230200162400ustar00#include "syscalls.h"

syscall(readlinkat,readlinkat)
dietlibc-0.33~cvs20120325/syscalls.s/readv.S010064400000000000000000000000541173363230200152200ustar00#include "syscalls.h"

syscall(readv,readv)
dietlibc-0.33~cvs20120325/syscalls.s/remap_file_pages.S010064400000000000000000000001021173363230200173730ustar00#include "syscalls.h"

syscall(remap_file_pages,remap_file_pages)
dietlibc-0.33~cvs20120325/syscalls.s/removexattr.S010064400000000000000000000000671173363230200165030ustar00#include "syscalls.h"
syscall(removexattr,removexattr)
dietlibc-0.33~cvs20120325/syscalls.s/rename.S010064400000000000000000000000561173363230200153700ustar00#include "syscalls.h"

syscall(rename,rename)
dietlibc-0.33~cvs20120325/syscalls.s/renameat.S010064400000000000000000000000621173363230200157120ustar00#include "syscalls.h"

syscall(renameat,renameat)
dietlibc-0.33~cvs20120325/syscalls.s/request_key.S010064400000000000000000000000701173363230200164550ustar00#include "syscalls.h"

syscall(request_key,request_key)
dietlibc-0.33~cvs20120325/syscalls.s/rmdir.S010064400000000000000000000000541173363230200152340ustar00#include "syscalls.h"

syscall(rmdir,rmdir)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigaction.S010064400000000000000000000000741173363230200166060ustar00#include "syscalls.h"

syscall(rt_sigaction,__rt_sigaction)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigpending.S010064400000000000000000000000761173363230200167570ustar00#include "syscalls.h"

syscall(rt_sigpending,__rt_sigpending)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigprocmask.S010064400000000000000000000001001173363230200171360ustar00#include "syscalls.h"

syscall(rt_sigprocmask,__rt_sigprocmask)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigqueueinfo.S010064400000000000000000000001021173363230200173210ustar00#include "syscalls.h"

syscall(rt_sigqueueinfo,__rt_sigqueueinfo)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigreturn.S010064400000000000000000000000721173363230200166460ustar00#include "syscalls.h"

syscall(rt_sigreturn,rt_sigreturn)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigsuspend.S010064400000000000000000000000761173363230200170140ustar00#include "syscalls.h"

syscall(rt_sigsuspend,__rt_sigsuspend)
dietlibc-0.33~cvs20120325/syscalls.s/rt_sigtimedwait.S010064400000000000000000000001021173363230200173100ustar00#include "syscalls.h"

syscall(rt_sigtimedwait,__rt_sigtimedwait)
dietlibc-0.33~cvs20120325/syscalls.s/sched_get_priority_max.S010064400000000000000000000001161173363230200206510ustar00#include "syscalls.h"

syscall(sched_get_priority_max,sched_get_priority_max)
dietlibc-0.33~cvs20120325/syscalls.s/sched_get_priority_min.S010064400000000000000000000001161173363230200206470ustar00#include "syscalls.h"

syscall(sched_get_priority_min,sched_get_priority_min)
dietlibc-0.33~cvs20120325/syscalls.s/sched_getaffinity.S010064400000000000000000000001171173363230200175760ustar00#include "syscalls.h"

syscall(sched_getaffinity,__syscall_sched_getaffinity)

dietlibc-0.33~cvs20120325/syscalls.s/sched_getparam.S010064400000000000000000000000761173363230200170710ustar00#include "syscalls.h"

syscall(sched_getparam,sched_getparam)
dietlibc-0.33~cvs20120325/syscalls.s/sched_getscheduler.S010064400000000000000000000001061173363230200177410ustar00#include "syscalls.h"

syscall(sched_getscheduler,sched_getscheduler)
dietlibc-0.33~cvs20120325/syscalls.s/sched_rr_get_interval.S010064400000000000000000000001141173363230200204500ustar00#include "syscalls.h"

syscall(sched_rr_get_interval,sched_rr_get_interval)
dietlibc-0.33~cvs20120325/syscalls.s/sched_setaffinity.S010064400000000000000000000001051173363230200176070ustar00#include "syscalls.h"

syscall(sched_setaffinity,sched_setaffinity)

dietlibc-0.33~cvs20120325/syscalls.s/sched_setparam.S010064400000000000000000000000761173363230200171050ustar00#include "syscalls.h"

syscall(sched_setparam,sched_setparam)
dietlibc-0.33~cvs20120325/syscalls.s/sched_setscheduler.S010064400000000000000000000001061173363230200177550ustar00#include "syscalls.h"

syscall(sched_setscheduler,sched_setscheduler)
dietlibc-0.33~cvs20120325/syscalls.s/sched_yield.S010064400000000000000000000000701173363230200163710ustar00#include "syscalls.h"

syscall(sched_yield,sched_yield)
dietlibc-0.33~cvs20120325/syscalls.s/select.S010064400000000000000000000001101173363230200153670ustar00#include "syscalls.h"

#ifdef __NR_select
syscall(select,select)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/sendfile.S010064400000000000000000000002231173363230200157060ustar00#include "syscalls.h"
#include "dietwarning.h"

syscall_weak(sendfile,sendfile,__libc_sendfile)

link_warning(sendfile,"sendfile is not portable")
dietlibc-0.33~cvs20120325/syscalls.s/sendfile64.S010064400000000000000000000004551173363230200160670ustar00#include "dietfeatures.h"
#include "syscalls.h"
#include "dietwarning.h"

#ifdef __NR_sendfile64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(sendfile64,__dietlibc_sendfile64)
#else
syscall_weak(sendfile64,sendfile64,__libc_sendfile64)
#endif

link_warning(sendfile64,"sendfile64 is not portable")
#endif
dietlibc-0.33~cvs20120325/syscalls.s/set_mempolicy.S010064400000000000000000000001351173363230200167700ustar00#include "syscalls.h"

#ifdef __NR_set_mempolicy
syscall(set_mempolicy,set_mempolicy)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/set_thread_area.S010064400000000000000000000001431173363230200172300ustar00#include "syscalls.h"

#ifdef __NR_set_thread_area
syscall(set_thread_area,set_thread_area)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/set_tid_address.S010064400000000000000000000001001173363230200172470ustar00#include "syscalls.h"

syscall(set_tid_address,set_tid_address)
dietlibc-0.33~cvs20120325/syscalls.s/setdomainname.S010064400000000000000000000000741173363230200167450ustar00#include "syscalls.h"

syscall(setdomainname,setdomainname)
dietlibc-0.33~cvs20120325/syscalls.s/setfsgid.S010064400000000000000000000000621173363230200157260ustar00#include "syscalls.h"

syscall(setfsgid,setfsgid)
dietlibc-0.33~cvs20120325/syscalls.s/setfsgid32.S010064400000000000000000000001531173363230200160740ustar00#include "syscalls.h"

#ifdef __NR_setfsgid32
syscall_weak(setfsgid32,setfsgid32,__libc_setfsgid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setfsuid.S010064400000000000000000000000621173363230200157440ustar00#include "syscalls.h"

syscall(setfsuid,setfsuid)
dietlibc-0.33~cvs20120325/syscalls.s/setfsuid32.S010064400000000000000000000001531173363230200161120ustar00#include "syscalls.h"

#ifdef __NR_setfsuid32
syscall_weak(setfsuid32,setfsuid32,__libc_setfsuid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setgid.S010064400000000000000000000000561173363230200154000ustar00#include "syscalls.h"

syscall(setgid,setgid)
dietlibc-0.33~cvs20120325/syscalls.s/setgid32.S010064400000000000000000000001431173363230200155420ustar00#include "syscalls.h"

#ifdef __NR_setgid32
syscall_weak(setgid32,setgid32,__libc_setgid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setgroups.S010064400000000000000000000000641173363230200161530ustar00#include "syscalls.h"

syscall(setgroups,setgroups)
dietlibc-0.33~cvs20120325/syscalls.s/sethostname.S010064400000000000000000000000701173363230200164470ustar00#include "syscalls.h"

syscall(sethostname,sethostname)
dietlibc-0.33~cvs20120325/syscalls.s/setitimer.S010064400000000000000000000000641173363230200161250ustar00#include "syscalls.h"

syscall(setitimer,setitimer)
dietlibc-0.33~cvs20120325/syscalls.s/setpgid.S010064400000000000000000000000601173363230200155530ustar00#include "syscalls.h"

syscall(setpgid,setpgid)
dietlibc-0.33~cvs20120325/syscalls.s/setpriority.S010064400000000000000000000000701173363230200165120ustar00#include "syscalls.h"

syscall(setpriority,setpriority)
dietlibc-0.33~cvs20120325/syscalls.s/setregid.S010064400000000000000000000000621173363230200157240ustar00#include "syscalls.h"

syscall(setregid,setregid)
dietlibc-0.33~cvs20120325/syscalls.s/setregid32.S010064400000000000000000000001531173363230200160720ustar00#include "syscalls.h"

#ifdef __NR_setregid32
syscall_weak(setregid32,setregid32,__libc_setregid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setresgid.S010064400000000000000000000001231173363230200161050ustar00#include "syscalls.h"

#ifdef __NR_setresgid

syscall(setresgid,setresgid)

#endif
dietlibc-0.33~cvs20120325/syscalls.s/setresgid32.S010064400000000000000000000001571173363230200162610ustar00#include "syscalls.h"

#ifdef __NR_setresgid32
syscall_weak(setresgid32,setresgid32,__libc_setresgid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setresuid.S010064400000000000000000000001231173363230200161230ustar00#include "syscalls.h"

#ifdef __NR_setresuid

syscall(setresuid,setresuid)

#endif
dietlibc-0.33~cvs20120325/syscalls.s/setreuid.S010064400000000000000000000000621173363230200157420ustar00#include "syscalls.h"

syscall(setreuid,setreuid)
dietlibc-0.33~cvs20120325/syscalls.s/setreuid32.S010064400000000000000000000001531173363230200161100ustar00#include "syscalls.h"

#ifdef __NR_setreuid32
syscall_weak(setreuid32,setreuid32,__libc_setreuid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setrlimit.S010064400000000000000000000000641173363230200161340ustar00#include "syscalls.h"

syscall(setrlimit,setrlimit)
dietlibc-0.33~cvs20120325/syscalls.s/setsid.S010064400000000000000000000000561173363230200154140ustar00#include "syscalls.h"

syscall(setsid,setsid)
dietlibc-0.33~cvs20120325/syscalls.s/settimeofday.S010064400000000000000000000000721173363230200166140ustar00#include "syscalls.h"

syscall(settimeofday,settimeofday)
dietlibc-0.33~cvs20120325/syscalls.s/setuid.S010064400000000000000000000000561173363230200154160ustar00#include "syscalls.h"

syscall(setuid,setuid)
dietlibc-0.33~cvs20120325/syscalls.s/setuid32.S010064400000000000000000000001431173363230200155600ustar00#include "syscalls.h"

#ifdef __NR_setuid32
syscall_weak(setuid32,setuid32,__libc_setuid32)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/setxattr.S010064400000000000000000000000621173363230200157740ustar00#include "syscalls.h"

syscall(setxattr,setxattr)
dietlibc-0.33~cvs20120325/syscalls.s/sigaltstack.S010064400000000000000000000001131173363230200164240ustar00#include "syscalls.h"

syscall_weak(sigaltstack,sigaltstack,__sigaltstack)
dietlibc-0.33~cvs20120325/syscalls.s/socketcall.S010064400000000000000000000001241173363230200162410ustar00#include "syscalls.h"

#ifdef __NR_socketcall
syscall(socketcall,socketcall)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/splice.S010064400000000000000000000001101173363230200153670ustar00#include "syscalls.h"

#ifdef __NR_splice
syscall(splice,splice)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/stat.S010064400000000000000000000000521173363230200150700ustar00#include "syscalls.h"

syscall(stat,stat)
dietlibc-0.33~cvs20120325/syscalls.s/stat64.S010064400000000000000000000002621173363230200152450ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_stat64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(stat64,__dietlibc_stat64)
#else
syscall(stat64,stat64)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/statfs.S010064400000000000000000000000561173363230200154250ustar00#include "syscalls.h"

syscall(statfs,statfs)
dietlibc-0.33~cvs20120325/syscalls.s/statfs64.S010064400000000000000000000001311173363230200155710ustar00#include "syscalls.h"

#ifdef __NR_statfs64
syscall(statfs64,__dietlibc_statfs64)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/stime.S010064400000000000000000000001051173363230200152350ustar00#include "syscalls.h"

#ifdef __NR_stime
syscall(stime,stime)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/swapoff.S010064400000000000000000000000601173363230200155610ustar00#include "syscalls.h"

syscall(swapoff,swapoff)
dietlibc-0.33~cvs20120325/syscalls.s/swapon.S010064400000000000000000000000561173363230200154300ustar00#include "syscalls.h"

syscall(swapon,swapon)
dietlibc-0.33~cvs20120325/syscalls.s/symlink.S010064400000000000000000000000601173363230200156020ustar00#include "syscalls.h"

syscall(symlink,symlink)
dietlibc-0.33~cvs20120325/syscalls.s/symlinkat.S010064400000000000000000000000641173363230200161330ustar00#include "syscalls.h"

syscall(symlinkat,symlinkat)
dietlibc-0.33~cvs20120325/syscalls.s/sync.S010064400000000000000000000000521173363230200150710ustar00#include "syscalls.h"

syscall(sync,sync)
dietlibc-0.33~cvs20120325/syscalls.s/sysctl.S010064400000000000000000000002001173363230200154310ustar00#include "syscalls.h"

#ifdef __NR_sysctl
syscall(sysctl,_sysctl)
#elif (defined(__NR__sysctl))
syscall(_sysctl,_sysctl)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/sysfs.S010064400000000000000000000001051173363230200152630ustar00#include "syscalls.h"

#ifdef __NR_sysfs
syscall(sysfs,sysfs)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/sysinfo.S010064400000000000000000000000601173363230200156060ustar00#include "syscalls.h"

syscall(sysinfo,sysinfo)
dietlibc-0.33~cvs20120325/syscalls.s/syslog.S010064400000000000000000000001051173363230200154340ustar00#include "syscalls.h"

syscall_weak(syslog,__syscall_syslog,klogctl)
dietlibc-0.33~cvs20120325/syscalls.s/tee.S010064400000000000000000000000771173363230200147010ustar00#include "syscalls.h"

#ifdef __NR_tee
syscall(tee,tee)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/tgkill.S010064400000000000000000000000551173363230200154060ustar00#include "syscalls.h"
syscall(tgkill,tgkill)
dietlibc-0.33~cvs20120325/syscalls.s/time.S010064400000000000000000000001021173363230200150470ustar00#include "syscalls.h"

#ifdef __NR_time
syscall(time,time)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/timer_create.S010064400000000000000000000001321173363230200165570ustar00#include "syscalls.h"

#ifdef __NR_timer_create
syscall(timer_create,timer_create)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/timer_delete.S010064400000000000000000000001321173363230200165560ustar00#include "syscalls.h"

#ifdef __NR_timer_delete
syscall(timer_delete,timer_delete)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/timer_getoverrun.S010064400000000000000000000001461173363230200175210ustar00#include "syscalls.h"

#ifdef __NR_timer_getoverrun
syscall(timer_getoverrun,timer_getoverrun)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/timer_gettime.S010064400000000000000000000001351173363230200167550ustar00#include "syscalls.h"

#ifdef __NR_timer_gettime
syscall(timer_gettime,timer_gettime)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/timer_settime.S010064400000000000000000000001351173363230200167710ustar00#include "syscalls.h"

#ifdef __NR_timer_settime
syscall(timer_settime,timer_settime)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/timerfd.S010064400000000000000000000001151173363230200155470ustar00#include "syscalls.h"

#ifdef __NR_timerfd
syscall(timerfd,__timerfd)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/times.S010064400000000000000000000000541173363230200152400ustar00#include "syscalls.h"

syscall(times,times)
dietlibc-0.33~cvs20120325/syscalls.s/tkill.S010064400000000000000000000000531173363230200152350ustar00#include "syscalls.h"
syscall(tkill,tkill)
dietlibc-0.33~cvs20120325/syscalls.s/truncate.S010064400000000000000000000000621173363230200157430ustar00#include "syscalls.h"

syscall(truncate,truncate)
dietlibc-0.33~cvs20120325/syscalls.s/truncate64.S010064400000000000000000000003061173363230200161160ustar00#include "dietfeatures.h"
#include "syscalls.h"

#ifdef __NR_truncate64
#ifdef WANT_LARGEFILE_BACKCOMPAT
syscall(truncate64,__dietlibc_truncate64)
#else
syscall(truncate64,truncate64)
#endif
#endif
dietlibc-0.33~cvs20120325/syscalls.s/umask.S010064400000000000000000000000541173363230200152370ustar00#include "syscalls.h"

syscall(umask,umask)
dietlibc-0.33~cvs20120325/syscalls.s/umount.S010064400000000000000000000001101173363230200154370ustar00#include "syscalls.h"

#ifdef __NR_umount
syscall(umount,umount)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/umount2.S010064400000000000000000000001131173363230200155240ustar00#include "syscalls.h"

#ifdef __NR_umount2
syscall(umount2,umount2)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/uname.S010064400000000000000000000000541173363230200152240ustar00#include "syscalls.h"

syscall(uname,uname)
dietlibc-0.33~cvs20120325/syscalls.s/unlink.S010064400000000000000000000000561173363230200154210ustar00#include "syscalls.h"

syscall(unlink,unlink)
dietlibc-0.33~cvs20120325/syscalls.s/unlinkat.S010064400000000000000000000000621173363230200157430ustar00#include "syscalls.h"

syscall(unlinkat,unlinkat)
dietlibc-0.33~cvs20120325/syscalls.s/ustat.S010064400000000000000000000000541173363230200152570ustar00#include "syscalls.h"

syscall(ustat,ustat)
dietlibc-0.33~cvs20120325/syscalls.s/utime.S010064400000000000000000000001051173363230200152370ustar00#include "syscalls.h"

#ifdef __NR_utime
syscall(utime,utime)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/utimensat.S010064400000000000000000000000641173363230200161310ustar00#include "syscalls.h"

syscall(utimensat,utimensat)
dietlibc-0.33~cvs20120325/syscalls.s/utimes.S010064400000000000000000000000561173363230200154270ustar00#include "syscalls.h"

syscall(utimes,utimes)
dietlibc-0.33~cvs20120325/syscalls.s/vhangup.S010064400000000000000000000000601173363230200155640ustar00#include "syscalls.h"

syscall(vhangup,vhangup)
dietlibc-0.33~cvs20120325/syscalls.s/vmsplice.S010064400000000000000000000001161173363230200157400ustar00#include "syscalls.h"

#ifdef __NR_vmsplice
syscall(vmsplice,vmsplice)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/vserver.S010064400000000000000000000001131173363230200156070ustar00#include "syscalls.h"

#ifdef __NR_vserver
syscall(vserver,vserver)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/wait4.S010064400000000000000000000000541173363230200151470ustar00#include "syscalls.h"

syscall(wait4,wait4)
dietlibc-0.33~cvs20120325/syscalls.s/waitpid.S010064400000000000000000000001371173363230200155620ustar00#include "syscalls.h"

#ifdef __NR_waitpid
syscall_weak(waitpid,waitpid,__libc_waitpid)
#endif
dietlibc-0.33~cvs20120325/syscalls.s/write.S010064400000000000000000000000761173363230200152550ustar00#include "syscalls.h"

syscall_weak(write,write,__libc_write)
dietlibc-0.33~cvs20120325/syscalls.s/writev.S010064400000000000000000000000561173363230200154410ustar00#include "syscalls.h"

syscall(writev,writev)
dietlibc-0.33~cvs20120325/t.c010064400000000000000000000500601173363226000123110ustar00#define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#ifdef __dietlibc__
#include 
#include 
#endif

#if 0
static const char* Ident;
static int Option;
static int Facility;
static struct sockaddr_un sock;
static int fd=-1;

static void syslogconnect(void) {
  sock.sun_family=AF_UNIX;
  strcpy(sock.sun_path,"/dev/log");
  if ((fd=socket(AF_UNIX,SOCK_STREAM,0))==-1) return;
  if (connect(fd,(struct sockaddr*)&sock,sizeof(sock))==-1) {
    int save=errno;
    close(fd);
    fd=-1;
  }
  fcntl(fd,F_SETFL,FD_CLOEXEC);		/* doesn't work?  too bad */
}

void openlog(const char *ident, int option, int facility) {
  Ident=ident;
  Option=option;
  Facility=facility;
  syslogconnect();
}

void syslog(int priority, const char *format, ...) {
  /* write(fd,"<13>Jun 29 19:21:32 leitner: fnord",...) */
}

void closelog(void) {
}
#endif

void foo(int tmp,...) {
  long long l;
  va_list va;
  va_start(va,tmp);
  l=va_arg(va,long long);
  if (l!=-1) write(2,"kaputt\n",7);
}

int compint(const void *a, const void *b) {
  register const int* A=a;
  register const int* B=b;
  return *B-*A;
}

extern char* strcpy2(char*a,char*b);

#define rdtscl(low) \
     __asm__ __volatile__ ("lfence\nrdtsc" : "=a" (low) : : "ecx","edx")

#define malloc(x) ({typeof(x) y=x; (y<0 || (size_t)(y)!=y ? 0 : malloc(y));})

int main(int argc,char *argv[]) {
#if 0
  char* a=malloc(-3);
  char* b=malloc(0xffffffffull+1);
  printf("%p %p\n",a,b);
#endif
  printf("%u\n",getpagesize());
#if 0
  struct stat s;
  time_t t=time(0);
  struct tm* T;
  stat("/tmp/nyt.html",&s);
  T=gmtime(&s.st_mtime);
#endif
#if 0
  static struct mq_attr x;
  mqd_t a=mq_open("fnord",O_WRONLY|O_CREAT,0600,&x);
  mqd_t b=mq_open("fnord",O_RDONLY);
#endif
#if 0
  struct statfs s;
  if (statfs("/tmp",&s)!=-1) {
    printf("%llu blocks, %llu free\n",(unsigned long long)s.f_blocks,(unsigned long long)s.f_bfree);
  }
#endif
#if 0
  char* c=strndupa("fnord",3);
  puts(c);
#endif
#if 0
  char buf[100];
  __write2("foo!\n");
  memset(buf,0,200);
#endif
#if 0
  printf("%+05d\n",500);
#endif
#if 0
  char* c;
  printf("%d\n",asprintf(&c,"foo %d",23));
  puts(c);
#endif
#if 0
  struct winsize ws;
  if (!ioctl(0, TIOCGWINSZ, &ws)) {
    printf("%dx%d\n",ws.ws_col,ws.ws_row);
  }
#endif
#if 0
  struct termios t;
  if (tcgetattr(1,&t)) { puts("tcgetattr failed!"); return 1; }
  printf("%d\n",cfgetospeed(&t));
#endif
#if 0
  printf("%p\n",malloc(0));
#endif
#if 0
  char* argv[]={"sh","-i",0};
  char buf[PATH_MAX+100];
  int i;
  for (i=0; i|[]>:|}-][]>:|}-]*)",REG_EXTENDED));
  printf("regexec %d\n",regexec(&r,"Marketing-Laufbahn hinterdir.",1,0,REG_NOSUB));
#endif
#if 0
  FILE *f=fopen("/home/leitner/Mail/outbox","r");
  char buf[1024];
  int i=0;
  if (f) {
    while (fgets(buf,1023,f)) {
      ++i;
      printf("%d %lu %s",i,ftell(f),buf);
    }
  }
#endif
#if 0
  char template[]="/tmp/duh/fnord-XXXXXX";
  printf("%d\n",mkdtemp(template));
#endif
#if 0
  char *inbuf="\xe2\x89\xa0";
//  char *inbuf="\xc2\xa9";
  char outbuf[100];
  char *obptr=&outbuf;
  size_t iblen=strlen(inbuf);
  size_t oblen=100;
  iconv_t i=iconv_open("utf-8","utf-8");
  iconv(i,&inbuf,&iblen,&obptr,&oblen);
  iconv_close(i);
  outbuf[100-oblen]=0;
  puts(outbuf);
#endif
#if 0
  printf("%c %c\n",tolower('C'),toupper('c'));
#endif
#if 0
  printf("foo\n");
#endif
#if 0
  char strport[10];
  int i;
  for (i=0; i<10; ++i) strport[i]=i+'0';
  snprintf( strport, sizeof(strport), "%d", 80 );
  puts(strport);
#endif
#if 0
  struct addrinfo *ai;
  struct addrinfo hints;
  char buf[16];
  memset(&hints,0,sizeof(hints));
#if 0
  hints.ai_family = AF_UNSPEC;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_socktype = SOCK_STREAM;
#endif
  hints.ai_family=0;
  hints.ai_flags=0;
  hints.ai_socktype=1;
  hints.ai_protocol=0;
  hints.ai_addrlen=0;
  hints.ai_addr=0;
  hints.ai_canonname=0;
  hints.ai_next=0;
  printf("%d\n",getaddrinfo("news.fu-berlin.de","119",&hints,&ai));
  while (ai) {
    printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
	   ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
				   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
	   ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
	   ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
    {
      char buf[100];
      inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
		(char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
		(char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
      printf("  %s\n",buf);
    }
    ai=ai->ai_next;
  }
#endif
#if 0
  char buf[101];
  __dtostr(M_PI,buf,100,6);
#endif
#if 0
  printf("%d\n",strcasecmp("foo","FOO"));
#endif
#if 0
  printf("%.24s", "Sun Jan  2 08:29:13 1994\n");
#endif
#if 0
  printf("%.*s\n",13,"fnord");
#endif
#if 0
  double d=strtod(argv[1],0);
  printf("%g|\n",d);
#endif
#if 0
  char buf[100];
  printf("%d\n",__lltostr(buf,30,-1ll,10,0));
  puts(buf);
#endif
#if 0
  printf("%lld\n",-1ll);
#endif
#if 0
  char *str="e";
  setbuf(stdout,0);
  printf("foo\n");
  fputc(toupper(*str++),stdout);
  printf("bar\n");
#endif
#if 0
  fwrite("foobar",6,1,stdout);
#endif
#if 0
  char x[5];
  x[4]='x';
  fgets(x,4,stdin);
  puts(x);
  printf("%c\n",x[4]);
#endif
#if 0
  char* paths[]={"/usr/lib","/usr/","usr","/",".",".."};
  char* want[]={"/usr","/",".","/",".","."};
  int i;
  for (i=0; i<6; ++i) {
    printf("%s\t%s\t%s\n",paths[i],want[i],dirname(strdup(paths[i])));
  }
#endif
#if 0
  char* paths[]={"/usr/lib","/usr/","usr","/",".",".."};
  char* want[]={"lib","usr","usr","/",".",".."};
  int i;
  for (i=0; i<6; ++i) {
    printf("%s\t%s\t%s\n",paths[i],want[i],basename(strdup(paths[i])));
  }
#endif
#if 0
  int i;
  for (i=0; i<255; ++i) {
    int a=isalpha(i);
    int b=(i>='a' && i<='z') || (i>='A' && i<='Z');
    if (a!=b) printf("%d: %d %d\n",i,a,b);
  }
#endif
#if 0
  char* name;
  int ptyfd,ttyfd;
  int i=openpty(&ptyfd,&ttyfd,0,0,0);
  if (i<0) perror("openpty");
  printf("%d %d\n",ptyfd,ttyfd);
  printf("%s %s\n",ttyname(ptyfd),ttyname(ttyfd));
#endif
#if 0
  printf("0x%8.7lx\n",0xfefe);
#endif
#if 0
  puts(ttyname(0));
#endif
#if 0
  char buf[1024];
  struct hostent* r;
  int i=0;
  r=gethostbyname("cyberelks.net");
again:
  if (!r) {
    printf("dns error: %s\n",hstrerror(h_errno));
  }
  {
/*  while (r=gethostent_r(buf,1024)) { */
    if (r && r->h_name) {
      int i;
      printf("name \"%s\"; ", r->h_name);
      for (i=0; i<8; ++i)
	if (r->h_aliases[i]) {
	  printf("alias \"%s\"; ",r->h_aliases[i]);
	} else break;
      if ((r->h_addr_list)[0]) {
	struct in_addr address;
	address = *((struct in_addr *) (r->h_addr_list)[0]);
	printf("addr %s; ", inet_ntoa(address));
      }
      putchar('\n');
    }
  }
  if (!i) {
    i=1;
    r=gethostbyname("prdownloads.sourceforge.net");
    goto again;
  }
#endif
#if 0
  char *tmp;
  printf("%lu\n",strtol("0xf0000000",&tmp,0));
#endif
#if 0
  struct mntent* me;
  FILE* f=fopen("/etc/fstab","r");
  while (me=getmntent(f)) {
    printf("%s\n",hasmntopt(me,"defaults"));
    printf("%s %s %s %s %d %d\n",me->mnt_fsname,me->mnt_dir,me->mnt_type,me->mnt_opts,me->mnt_freq,me->mnt_passno);
    break;
  }
#endif
#if 0
  char *tmp;
  printf("%x\n",strtol("0Xffff",&tmp,16));
#endif
/*  putchar('c');
  write(1,"fnord\n",6); */
#if 0
  struct addrinfo *ai;
//  getaddrinfo("xorn","22",0,&ai);
  puts(gai_strerror(getaddrinfo("xorn","22",0,&ai)));
#endif
#if 0
  struct hostent host,*res;
  char buf[4096];
  int fnord;

  gethostbyname2_r("nagus",AF_INET,&host,buf,4096,&res,&fnord);
#endif
#if 0
  char buf[128];
  strcpy(buf,"/tmp/fnord/foo.XXXXXXX");
  printf("%d\n",mkdtemp(buf));
  printf("%s\n",buf);
#endif
#if 0
  printf("%d\n",WEXITSTATUS(system("exit 17")));
#endif
#if 0
  fnord("fnord","foo\n","bar\n",0);
  assert(0);
#endif
#if 0
  printf("%hd %hhd\n",-5,-1234567);
#endif
#if 0
  printf("%d\n",fnmatch("*.o", "x.o", FNM_PATHNAME));
  printf("%d\n",fnmatch("a/b/*", "a/b/c/d", FNM_PATHNAME));
#endif
#if 0
  char buf[1024];
  int len;
  len=res_search("fu-berlin.de",ns_c_in,ns_t_ns,buf,sizeof(buf));
#endif
#if 0
  regex_t t;
  regmatch_t rm;
//  regcomp(&t,"^ *read",0);
  regcomp(&t,"\\",0);
  printf("%d\n",regexec(&t,"  blub foo,",1,&rm,0));
  printf("ofs %d\n",rm.rm_so);
#endif
#if 0
  char buf[100];
  printf("%d\n",fread(buf,1,0,stdin));
#endif
#if 0
  char buf[100];
  memset(buf,17,100);
  buf[0]=0;
  strncat(buf,"foobarbaz23",10);
  puts(buf);
#endif
#if 0
  int aflag = 0;
  int bflag = 0;
  char *cvalue = NULL;
  int index;
  int c;

  opterr = 1;

  while ((c = getopt (argc, argv, "abc:")) != -1)
    switch (c)
      {
      case 'a':
	aflag = 1;
	break;
      case 'b':
	bflag = 1;
	break;
      case 'c':
	cvalue = optarg;
	break;
      case '?':
	if (isprint (optopt))
	  fprintf (stderr, "Unknown option `-%c'.\n", optopt);
	else
	  fprintf (stderr,
		  "Unknown option character `\\x%x'.\n",
		  optopt);
	return 1;
      default:
	abort ();
      }

  printf ("aflag = %d, bflag = %d, cvalue = %s\n",
	  aflag, bflag, cvalue);

  for (index = optind; index < argc; index++)
    printf ("Non-option argument %s\n", argv[index]);
  return 0;
#endif
#if 0
  char *t="foobar";
  char *c;
  char buf[1000];
  puts(strcat(strcpy(buf,"HOME="),t));
#endif
#if 0
  struct netent* n=getnetbyname("loopback");
  printf("%s %s\n",n->n_name,inet_ntoa(*(struct in_addr*)&n->n_net));
#endif
#if 0
  fprintf(stdout,"foo\n");
  sleep(1);
  fprintf(stdout,"bar");
  fprintf(stderr,"blonk");
  sleep(1);
  fprintf(stdout,"\rbz");
  sleep(1);
  fprintf(stdout,"\n");
  sleep(1);
#endif
#if 0
  sigset_t s;	/* sigsetops */

  sigemptyset(&s);
  sigaddset(&s,SIGCHLD);
  sigaddset(&s,SIGHUP);
  sigsuspend(&s);
#endif
#if 0
  char buf[1024];
  FILE *f=popen("uname -srm","r");
  fgets(buf,1023,f);
  pclose(f);
  write(1,buf,strlen(buf));
#endif
#if 0
  char type[64];
  char filename[256];
  int major,minor;
  int len;
  printf("%d\n",sscanf("GET / HTTP/1.0\r\n","%4[A-Z] %255[^ \t\r\n] HTTP/%d.%d",type,filename,&major,&minor));
  printf("%s %s %d %d\n",type,filename,major,minor);
#endif
#if 0
  char buf[100];
  char ip[16];
  memset(ip,0,16);
  printf("%p %p\n",inet_ntop(AF_INET6,ip,buf,100),buf);
  puts(buf);
#endif
#if 0
  struct addrinfo *ai;
  struct addrinfo hints;
  char buf[16];
  hints.ai_family = AF_UNSPEC;
  hints.ai_flags = AI_PASSIVE|AI_CANONNAME;
  hints.ai_socktype = SOCK_STREAM;
  printf("%d\n",getaddrinfo("xorn.continuum.local","ssh",0,&ai));
  while (ai) {
    printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
	   ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
				   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
	   ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
	   ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
    {
      char buf[100];
      inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
		(char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
		(char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
      printf("  %s\n",buf);
    }
    ai=ai->ai_next;
  }
#endif
#if 0
  int i=foo;
  printf("load average is %3.2f\n",0.0);
#endif
#if 0
  struct dirent **namelist;
  int n;

  n = scandir(".", &namelist, 0, alphasort);
  if (n < 0)
    perror("scandir");
  else {
    while(n--) {
      printf("%s\n", namelist[n]->d_name);
      free(namelist[n]);
    }
    free(namelist);
  }
#endif
#if 0
  char foo[10]="none,zlib";
  char *tmp,*tmp2=foo;
  while (tmp=strsep(&tmp2,",")) {
    puts(tmp);
  }
#endif
#if 0
  char foo[10];
  printf("%d %d\n",abs(-3),abs(23));
  strcpy(foo,"foo");
  strncat(foo,"barbaz",3);
  foo[6]=0;
  puts(foo);
#endif
#if 0
  struct hostent * host;
  struct in_addr i;

  host = gethostbyname2("nagus",AF_INET);

  if (!host)
    printf("host null\n");

  if (host && host->h_name) {
    printf("name %s\n", host->h_name);
  }
  if (host && (host->h_addr_list)[0]) {
    struct in_addr address;
    address = *((struct in_addr *) (host->h_addr_list)[0]);
    printf("addr %s\n", inet_ntoa(address));
  }
#endif
#if 0
  struct msgbuf bla;
  bla.mtype=0;
  bla.mtext[0]='x';
  msgsnd(327680,&bla,5,IPC_NOWAIT);
#endif
#if 0
  char buf[PATH_MAX];
  printf("%s\n",realpath("../../incoming/..///.zshrc",buf));
#endif
#if 0
  regex_t t;
  regcomp(&t,"^OpenSSH_2\\.5\\.[012]",5);
  printf("%d\n",regexec(&t,"OpenSSH_2.5.2p2",0,0,0));
#endif
#if 0
  float my_float = 9.2334;
  char buffer[100];

  sprintf(buffer, "%.2f", my_float);
  fprintf(stdout, "%s", buffer);
#endif
#if 0
  printf("%d\n",setenv("foo","bar",0));
  printf("%d\n",setenv("foo","bar",1));
  execlp("printenv","printenv","foo",0);
#endif
#if 0
  printf("%d\n",fnmatch("*c*","bin",0));
  if (!fnmatch("s*", "sub", 0))
    printf("s* sub\n");
  if (!fnmatch("s*", "glob", 0))
    printf("s* glob\n");
  if (!fnmatch("s*b", "sub", 0))
    printf("s*b sub\n");
  if (!fnmatch("s*h", "sub", 0))
    printf("s*h sub\n");
#endif
#if 0
  char*tmp;
  int n=asprintf(&tmp,"foo %s %d\n","bar",23);
  write(1,tmp,n);
  free(tmp);
#endif
#if 0
  struct passwd *p=getpwnam("leitner");
  struct spwd *s=getspnam("leitner");
  printf("%g\n",30.0123);
#endif
#if 0
  initgroups("root",100);
#endif
#if 0
  time_t t=time(0);
  printf("%lu\n",t);
  puts(asctime(localtime(&t)));
#endif
#if 0
  struct servent *foo=getservbyname("pop-3","tcp");
  if (foo)
    printf("found service %s on port %d\n",foo->s_name,foo->s_port);
#endif
#if 0
  char buf[128];
  strcpy(buf,"/tmp/blub/foo.XXXXXXX");
  printf("%d\n",mkstemp(buf));
  printf("%s\n",buf);
  unlink(buf);
#endif
#if 0
  char buf[512]="foo";
  strncat(buf,"barbaz",3);
  puts(buf);
#endif
#if 0
  time_t oink=time(0);
  struct tm *duh=localtime(&oink);
  strftime(buf,512,"%A %B %Y\n",duh);
  puts(buf);
#endif
#if 0
  struct in_addr bar;
  struct hostent *foo;
  inet_aton("160.45.10.8",&bar);
/*  foo=gethostbyname("zeit.fu-berlin.de"); */
  foo=gethostbyaddr(&bar,4,AF_INET);
  if (foo)
    printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
/*  printf("%g %g\n",1e-10,1e10); */
#endif
#if 0
  double d=0.0;
  long long t=0x12345678ABCDEF01;
  d/=0.0;
  printf("%d %llx\n",__isnan(d),t,*(long long*)&d);
#endif
#if 0
#define SIZE 1000
  int array[SIZE],array2[SIZE];
  int i,j;
  long a,b,c;
  int *k;
  for (i=0; iarray[i+1]);
  k=bsearch(array+10,array,SIZE,sizeof(int),compint);
  printf("%d\n",*k);
#endif
#if 0
  printf("%p\n",malloc(0));
  qsort(array,2,sizeof(int),compint);
  for (i=0; iarray[i+1]) {
      printf("qsort does not work, index %d: %d > %d\n",i,array[i],array[i+1]);
      return 1;
    }
  if (*res!=j)
    printf("besearch does not work, returned %p (%d) instead of %p (%d)\n",res,res?*res:-1,array+LOOKFOR,j);
/*  printf("array={%d,%d,%d,%d,%d}\n",array[0],array[1],array[2],array[3],array[4]); */
#endif
#if 0
  struct in_addr duh;
  printf("%d\n",inet_aton(argv[1]?argv[1]:"10.0.0.1",&duh));
  printf("%x\n",duh.s_addr);
#endif
/*  printf("%-19s %10lu %9lu %9lu %3d%% %s\n","/dev/ide/host0/bus0/target0/lun0/part2",8393688,705683,1337084,85,"/"); */
#if 0
  char buf[100];
  fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
  fgets(buf,100,stdin); printf("got %d bytes\n",strlen(buf));
#endif
#if 0
  struct tm duh;
  time_t t;
  time(&t);
  gmtime_r(&t,&duh);
  printf("%s\n",asctime(&duh));
#endif
#if 0
  char buf[30];
  duh.tm_sec=42;
  duh.tm_min=23;
  duh.tm_hour=17;
  duh.tm_mday=2;
  duh.tm_mon=7;
  duh.tm_year=100;
  t=mktime(&duh);
  printf("%s\n",asctime_r(&duh,buf));
#endif
#if 0
  int i;
  for (i=0; i<5; i++) {
    fprintf(stdout,"first message\n");
    fprintf(stdout,"second message\n");
    fprintf(stdout,"third message\n");
    printf("foo %d\n",i);
  }
#endif
#if 0
  char buf[1024];
  sscanf("foo bar","%s",buf);
  printf("%s\n",buf);
#endif
#if 0
  mount("/dev/scsi/host0/bus0/target2/lun0/cd", "/cd", "iso9660", MS_MGC_VAL|MS_RDONLY, NULL);
  perror("mount");
#endif
#if 0
  char *t="<4>Linux version 2.4.0-test10 (leitner@hellhound) (gcc version 2.95.2 19991024 (release))";
  int i=strtol(t+1,&t,10);
  printf("%d %s\n",i,t);
#endif
#if 0
  char **tmp;
  putenv("A=foo");
  for (tmp=environ; *tmp; tmp++)
    puts(*tmp);
#endif
#if 0
  char buf[1024];
  printf("%d\n",fprintf(stderr,"duh\n"));
#endif
#if 0
  struct passwd *p=getpwuid(100);
  puts(p->pw_name);
#endif
#if 0
  int pid;
  char name[32];
  sscanf("1 (init","%d (%15c",&pid,name);
  printf("pid %d name %s\n",pid,name);
#endif
#if 0
  DIR *d=opendir("/proc");
  if (d) {
    struct dirent *D;
    while (D=readdir(d))
      puts(D->d_name);
    closedir(d);
  }
#endif
#if 0
  char buf[1024];
  int fd=open("/etc/passwd",0);
  pread(fd,buf,30,32);
  close(fd);
  write(1,buf,32);
#endif
#if 0
  char *argv[] = {"echo","foo",0};
  char buf[100];
  buf[5]='x';
  sprintf(buf,"foo\n");
  if (buf[5] == 'x')
    exit(0);
  else
    exit(1);
  execvp(argv[0],argv);
#endif
#if 0
  struct stat64 f;
  char buf[128];
  fstat64(0,&f);
  fprintf(stderr,"%d %d\n",f.st_size,sizeof(f));
  return 0;
#endif
#if 0
  FILE *f=fopen("foo","w");
  fputc('a',f);
  fputc('b',f);
  fputc('c',f);
#endif
/*  fprintf(stdout,"foo\n"); */
}
dietlibc-0.33~cvs20120325/test/.cvsignore010064400000000000000000000012301173363230200146510ustar00adjtime
alarm
argv
asprintf
atexit
bsearch
byteswap
calloc
confstr
cycles
empty
fadvise
ffs
flush
fnmatch
fputc
ftw
fwrite
getaddrinfo
getdelim
getenv
getgrnam
gethostbyaddr
gethostbyname
gethostbyname_r
getmntent
getopt
getpass
getpwnam
getservbyname
getservbyport
getusershell
glob
grent
hasmntopt
hello
iconv
if_nameindex
ltostr
malloc-debugger
md5_testharness
memccpy
memchr
memcmp
memrchr
memusage
mktime
mmap_test
pipe
printf
printftest
protoent
prototypes
putenv
pwent
rand48
read1
readdir
regex
select
sendfile
servent
siglist
speed
spent
sprintf
sscanf
stdarg
strcasecmp
strcmp
strncat
strncpy
strptime
strrchr
strstr
strtol
sysenter
ungetc
utime
waitpid
dietlibc-0.33~cvs20120325/test/CAS.c010064400000000000000000000005441173363230200134320ustar00#include 
#include 
#include 
#include 

size_t a,b,c;

int main() {
  a=1;
  assert(__CAS(&a,0,3)==1 && a==1);
  assert(__CAS(&a,1,2)==1 && a==2);
  __write1("CAS test successful\n");

  assert(__atomic_add(&a,1)==3);
  assert(__atomic_add(&a,-2)==1);
  __write1("atomic_add test successful\n");
  return 0;
}
dietlibc-0.33~cvs20120325/test/Makefile010064400000000000000000000034731173363230200143240ustar00all: direnttest inettest stdiotests stdlibtests stringtests timetests \
test ffs getdelim stdlib 

DIET=diet
CC=gcc
CFLAGS=-nostdinc -Wall

LCOMPAT=-lcompat

TESTPROGRAMS=adjtime alarm argv asprintf atexit bsearch byteswap calloc confstr cycles empty fadvise flush fnmatch \
fputc ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \
gethostbyname_r getmntent getopt getpass getpwnam getservbyname getservbyport getusershell \
glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \
memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest \
protoent prototypes putenv pwent rand48 read1 readdir regex select sendfile servent siglist \
speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr \
strstr strtol sysenter ungetc utime waitpid

test: $(TESTPROGRAMS)

ffs: ffs.c
	$(DIET) $(CC) $(CFLAGS) $^ $(LCOMPAT) -o $@
	
getdelim: getdelim.c
	$(DIET) $(CC) $(CFLAGS) $^ $(LCOMPAT) -o $@ 

syscall: syscall.c
	$(DIET) $(CC) $^ -o $@

testandset: testandset.c
	$(DIET) $(CC) $^ -o $@ 

direnttest:
	 $(MAKE) -C dirent CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT)

inettest:
	$(MAKE) -C inet CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT)

stdiotests:
	$(MAKE) -C stdio CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT)

stdlibtests:
	$(MAKE) -C stdlib CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT)

stringtests:
	$(MAKE) -C string CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT)

timetests:
	$(MAKE) -C time CC="$(CC)" CFLAGS="$(CFLAGS)" DIET=$(DIET) LCOMPAT=$(LCOMPAT)
	
	
%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

clean:
	rm -f $(TESTPROGRAMS) getdelim ffs
	$(MAKE) -C dirent clean
	$(MAKE) -C stdio clean
	$(MAKE) -C stdlib clean
	$(MAKE) -C string clean
	$(MAKE) -C time clean

dietlibc-0.33~cvs20120325/test/adjtime.c010064400000000000000000000002271173363230200144370ustar00#include 
#include 

int main() {
  struct timeval a,b;
  a.tv_sec=0; a.tv_usec=0;
  printf("%d\n",adjtime(&a,&b));
  return 0;
}
dietlibc-0.33~cvs20120325/test/alarm.c010064400000000000000000000025561173363230200141250ustar00#include 
#include 

#include 
#include 
#include 

static volatile int    alrm_triggered;

static void sig_alrm(int s)
{
       alrm_triggered = 1;
}

int main()
{
       int             rc;
       time_t          end;
       sighandler_t    old_sig;

       alarm(50);

       old_sig = signal(SIGALRM, &sig_alrm);
       assert(old_sig != SIG_ERR);

       /* check whether alarm() returns correct number of remaining
        * seconds */
       rc = alarm(2);
       assert(rc > 40 && rc <= 50);

       /* check whether SIGALRM is triggered within the set time */
       end = time(NULL) + 5;
       while (!alrm_triggered && time(NULL) < end) {
               /* noop */
       }
       assert(alrm_triggered);

       /* there should be no pending alarm */
       rc = alarm(0);
       assert(rc == 0);

       alrm_triggered = 0;

       /* test whether alarm can be canceled */
       rc = alarm(2);
       assert(rc == 0);

       rc = alarm(0);
       assert(rc > 0 && rc < 4);
       assert(!alrm_triggered);

       /* there should not happen an alarm */
       end = time(NULL) + 5;
       while (!alrm_triggered && time(NULL) < end) {
               /* noop */
       }
       assert(!alrm_triggered);

       /* there should be no pending alarm */
       rc = alarm(0);
       assert(rc == 0);

       return EXIT_SUCCESS;
}

dietlibc-0.33~cvs20120325/test/argv.c010064400000000000000000000004121173363230200137550ustar00#include 
#include 

extern char **environ;

int main(int argc,char* argv[]) {
  int i;
  char** x;
  for (i=0; i<=argc; ++i)
    printf("[%d]: \"%s\"\n",i,argv[i]);
  puts("\nEnvironment:");
  for (x=environ; *x; ++x)
    puts(*x);
  return 0;
}
dietlibc-0.33~cvs20120325/test/asprintf.c010064400000000000000000000006761173363230200146600ustar00#define _GNU_SOURCE
#include 
#include 
#include 

int main(int argc, char **argv) {
 char *path;
 int asprintlen=0;
  
 if ( argc < 2 ) return 111;
   
 asprintlen=asprintf(&path, "/proc" "/%s/stat", argv[1]);
 assert(strlen(path) == asprintlen);
	     
 printf("%s\n", path);
 asprintlen=asprintf(&path, "/proc" "/%d/stat", strlen(argv[1]));
 assert(strlen(path) == asprintlen);
 printf("%s\n", path);

return 0;
}
dietlibc-0.33~cvs20120325/test/atexit.c010064400000000000000000000002021173363230200143110ustar00#include 
#include 

void blah(void) {
  write(2,"atexit\n",7);
}

int main() {
  atexit(blah);
  return 0;
}
dietlibc-0.33~cvs20120325/test/bsearch.c010064400000000000000000000017021173363230200144300ustar00#include 
#include 
#include 
#include 
#include 

int compint(const void *a, const void *b) {
  register const int* A=a;
  register const int* B=b;
  return *B-*A;
}

void die(const char* message) {
  write(2,message,strlen(message));
  exit(1);
}

int main() {
#define SIZE 1000
  int array[SIZE],array2[SIZE];
  int i,j;
  int *k;
  for (j=10; j
#include 
#include 
#include 

int main() {
  char buf[100];
  printf("%x %x\n",bswap_16(0x1234),bswap_16(0x5678));
  snprintf(buf,100,"%x %x", bswap_16(0x1234), bswap_16(0x5678));
  assert(strcmp(buf, "3412 7856") == 0);
  
  printf("%lx\n",bswap_32(0x12345678));
  snprintf(buf,100,"%lx", bswap_32(0x12345678));
  assert(strcmp(buf, "78563412") == 0);

  printf("%qx\n",bswap_64(0x123456789ABCDEFull));
  snprintf(buf,100,"%qx", bswap_64(0x123456789ABCDEFull));
  assert(strcmp(buf, "efcdab8967452301") == 0);
  return 0; 
}
dietlibc-0.33~cvs20120325/test/calloc.c010064400000000000000000000002161173363230200142550ustar00#include 
#include 
#include 

int main() {
  char* c=calloc(ULONG_MAX/64,65);
  printf("%p\n",c);
  return 0;
}
dietlibc-0.33~cvs20120325/test/checkssp.c010064400000000000000000000002021173363230200146160ustar00#include 
int main(void) {
  char arr[16];
  strcpy(arr,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
  return 0;
}
dietlibc-0.33~cvs20120325/test/confstr.c010064400000000000000000000006641173363230200145050ustar00#include 
#include 
#include 

#include 
#include 


#define ps(s) write(2,s,sizeof(s)-1)
#define die(s) do { ps(s); exit(1); } while(0)


int main(int argc,char*argv[]) {
  char*path;
  size_t len;
  len = confstr(_CS_PATH, (char *) NULL, 0);
  if (!(path = malloc(1 + len)))
    die("malloc...\n");
  path[0] = ':';
  confstr(_CS_PATH, path+1, len);
  write(1,path,len);
  return 0;
}

dietlibc-0.33~cvs20120325/test/crypt.c010064400000000000000000000014621173363230200141650ustar00#include 
#include 
#include 
#include 
#include 

int main(int argc,char* argv[]) {
  char salt[2];
  char charset[100];
  unsigned int l,i;
  int fd;
  salt[0]='a';
  salt[1]='b';
  assert(!strcmp(crypt("fnord",salt),"ab3MSJErI/bdM"));

  for (l=i=0; i<'z'-'a'; ++i) { charset[l]=i+'a'; ++l; }
  for (i=0; i<'Z'-'A'; ++i) { charset[l]=i+'A'; ++l; }
  for (i=0; i<'9'-'0'; ++i) { charset[l]=i+'0'; ++l; }
  charset[l]='.'; charset[l+1]='/'; i=l+2;
  fd=open("/dev/urandom",O_RDONLY);
  read(fd,&l,sizeof(l));
  salt[0]=charset[l%i];
  salt[1]=charset[(l/i)%i];
  close(fd);
  for (l=1; argv[l]; ++l) {
    printf("password %s with salt %c%c -> %s\n",argv[l],salt[0],salt[1],crypt(argv[l],salt));
    printf("md5password %s -> %s\n",argv[l],crypt(argv[l],"$1$"));
  }
}
dietlibc-0.33~cvs20120325/test/cycles.c010064400000000000000000000013611173363230200143040ustar00#include 
#include 
#include 
#include 
#include 

#if defined (__i386__)
#define RDTSC(dst) asm volatile ("rdtsc" : "=A" (dst))
#elif defined (__x86_64__)
#define RDTSC(dst) do {                                                        \
  uint32_t l, h;                                                               \
  asm volatile ("rdtsc" : "=a" (l), "=d" (h)); \
  dst = (((uint64_t)h) << 32) | l;                             \
} while (0)
#else
#error "Unimplemented rdtsc"
#endif

extern char **environ;

int main(int argc,char* argv[]) {
  uint64_t a,b;
  RDTSC(a);
  if (!fork()) { execve(argv[1],argv+1,environ); exit(1); }
  wait(0);
  RDTSC(b);
  printf("%llu cycles\n",b-a);

  return 0;
}
dietlibc-0.33~cvs20120325/test/dirent/.cvsignore010064400000000000000000000000311173363230200161340ustar00opendir-tst1
tst-seekdir
dietlibc-0.33~cvs20120325/test/dirent/Makefile010064400000000000000000000002651173363230200156050ustar00DIET=diet
CC=gcc
CFLAGS=-Wall

all: dirent

TESTPROGRAMS=opendir-tst1 tst-seekdir

dirent: $(TESTPROGRAMS)

%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

clean:
	rm -f $(TESTPROGRAMS)

dietlibc-0.33~cvs20120325/test/dirent/opendir-tst1.c010064400000000000000000000041271173363230200166430ustar00/* Copyright (C) 1998, 2000 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper , 1998.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

//#include 
#include 


/* Name of the FIFO.  */
char tmpname[] = "fifoXXXXXX";

void do_cleanup (void)
{
  remove (tmpname);
}


/* Do the real work.  */
static int
real_test (void)
{
  DIR *dirp;

  /* This should not block for an FIFO.  */
  dirp = opendir (tmpname);

  /* Successful.  */
  if (dirp != NULL)
    {
      /* Oh, oh, how can this work?  */
      fputs ("`opendir' succeeded on a FIFO???\n", stdout);
      closedir (dirp);
      return 1;
    }

  if (errno != ENOTDIR)
    {
      fprintf (stdout, "`opendir' return error `%s' instead of `%s'\n",
	       strerror (errno), strerror (ENOTDIR));
      return 1;
    }

  return 0;
}


int main (int argc, char *argv[])
{
  int retval;
  atexit(do_cleanup);

  if (mktemp (tmpname) == NULL)
    {
      perror ("mktemp");
      return 1;
    }

  /* Try to generate a FIFO.  */
  if (mknod (tmpname, 0600 | S_IFIFO, 0) < 0)
    {
      perror ("mknod");
      /* We cannot make this an error.  */
      return 0;
    }

  retval = real_test ();

  return retval;
}


dietlibc-0.33~cvs20120325/test/dirent/runtests.sh010064400000000000000000000002721173363230200163660ustar00#!/bin/sh

TESTPROGRAMS="opendir-tst1 tst-seekdir"

for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
done 

dietlibc-0.33~cvs20120325/test/dirent/tst-seekdir.c010064400000000000000000000017761173363230200165570ustar00#include 
#include 
#include 

int
main (int argc, char *argv[])
{
  DIR * dirp;
  long int save3 = 0;
  long int cur;
  int i = 0;
  int result = 0;
  struct dirent *dp;

  dirp = opendir (".");
  for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
    {
      /* save position 3 (after fourth entry) */
      if (i++ == 3)
	save3 = telldir (dirp);

      printf ("%s\n", dp->d_name);

      /* stop at 400 (just to make sure dirp->__offset and dirp->__size are
	 scrambled */
      if (i == 400)
	break;
    }

  printf ("going back past 4-th entry...\n");

  /* go back to saved entry */
  seekdir (dirp, save3);

  /* Check whether telldir equals to save3 now.  */
  cur = telldir (dirp);
  if (cur != save3)
    {
      printf ("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur);
      result = 1;
    }

  /* print remaining files (3-last) */
  for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp))
    printf ("%s\n", dp->d_name);


  closedir (dirp);
  return result;
}
dietlibc-0.33~cvs20120325/test/dirname.c010064400000000000000000000022031173363230200144350ustar00#include 
#include 
#include 
#include 

int main(int argc, char *argv[])
{
     char s[80];

     strncpy(s,"/usr/lib",80);       assert(strcmp(dirname(s),   "/usr")==0);
     strncpy(s,"/usr/",80);          assert(strcmp(dirname(s),   "/")==0);
     strncpy(s,"usr",80);            assert(strcmp(dirname(s),   ".")==0);
     strncpy(s,"usr/test",80);       assert(strcmp(dirname(s),   "usr")==0);
     strncpy(s,"usr/test/test2",80); assert(strcmp(dirname(s),   "usr/test")==0);
     strncpy(s,"/usr",80);           assert(strcmp(dirname(s),   "/")==0);
     strncpy(s,"/",80);              assert(strcmp(dirname(s),   "/")==0);
     strncpy(s,".",80);              assert(strcmp(dirname(s),   ".")==0);
     strncpy(s,"..",80);             assert(strcmp(dirname(s),   ".")==0);
     strncpy(s,"////",80);           assert(strcmp(dirname(s),   "/")==0);
     strncpy(s,"//",80);             assert(strcmp(dirname(s),   "/")==0);
                                     assert(strcmp(dirname(NULL),".")==0);
     s[0]=0;                         assert(strcmp(dirname(s),   ".")==0);

     puts("OK");
     return 0;
}
dietlibc-0.33~cvs20120325/test/empty.c010064400000000000000000000000331173363230200141530ustar00int main() {
  return 0;
}
dietlibc-0.33~cvs20120325/test/fadvise.c010064400000000000000000000005331173363230200144430ustar00#define _GNU_SOURCE
#define _XOPEN_SOURCE 600

#include 
#include 
#include 
#include 

int main(void)
{
  char file[] = "/tmp/dietlibc-fadvise-test.XXXXXX";
  int fd;

  fd = mkstemp(file);
  unlink(file);

  assert(posix_fadvise(fd, 23, 42, POSIX_FADV_RANDOM) == 0);
  close(fd);

  return EXIT_SUCCESS;
}
dietlibc-0.33~cvs20120325/test/ffs.c010064400000000000000000000004611173363230200136000ustar00#define _GNU_SOURCE
#include 
#include 
#include 

int main() {
  assert(ffs(1)==1);
  assert(ffs(2)==2);
  assert(ffs(4)==3);
  assert(ffs(256)==9);
  assert(ffs(511)==1);
  assert(ffsll(511)==1);
  assert(ffsll(256)==9);
  assert(ffsll(0x200000000ll)==34);

  return 0;
}
dietlibc-0.33~cvs20120325/test/flush.c010064400000000000000000000001451173363230200141420ustar00#include 

int main() {
  FILE* f=fopen("testing","w");
  fputs("testing",f);
  return 0;
}
dietlibc-0.33~cvs20120325/test/fnmatch.c010064400000000000000000000026311173363230200144430ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  if (fnmatch("*.c","foo.c",0)) die("fnmatch did not match *.c to foo.c");
  if (fnmatch("*.c",".c",0)) die("fnmatch did not match *.c to .c");
  if (!fnmatch("*.a","foo.c",0)) die("fnmatch matched *.a to foo.c");
  if (fnmatch("*.c",".foo.c",0)) die("fnmatch did not match *.c to .foo.c");
  if (!fnmatch("*.c",".foo.c",FNM_PERIOD)) die("FNM_PERIOD does not work 1");
  if (fnmatch("*.c","foo.c",FNM_PERIOD)) die("FNM_PERIOD does not work 2");
  if (!fnmatch("a\\*.c","a*.c",FNM_NOESCAPE)) die("FNM_NOESCAPE does not work");
  if (!fnmatch("a\\*.c","ax.c",0)) die("Escaping does not work");
  if (fnmatch("a[xy].c","ax.c",0)) die("Character classes don't work");
  if (fnmatch("a[^y].c","ax.c",0)) puts("Inverse character classes don't work (that's OK with POSIX)");
  if (!fnmatch("a[a/z]*.c","a/x.c",FNM_PATHNAME)) die("FNM_PATHNAME does not work 1");
  if (fnmatch("a/*.c","a/x.c",FNM_PATHNAME)) die("FNM_PATHNAME does not work 2");
  if (!fnmatch("a*.c","a/x.c",FNM_PATHNAME)) die("FNM_PATHNAME does not work 3");
  if (fnmatch("*/foo","/foo",FNM_PATHNAME)) die("FNM_PATHNAME does not work 3");
#ifdef FNM_CASEFOLD
  if (fnmatch("*.c","foo.C",FNM_CASEFOLD)) die("FNM_CASEFOLD does not work");
#endif
  if (fnmatch("-O[01]","-O1",0)) die("fnmatch did not match -O[01] to -O1");
  return 0;
}
dietlibc-0.33~cvs20120325/test/fputc.c010064400000000000000000000002211173363230200141350ustar00#include 
#include 

int main(void) {
  assert(fputc('x', stdin) < 0);
  fflush(NULL);
  assert(ferror(stdin));
  return 0;
}
dietlibc-0.33~cvs20120325/test/fstab010064400000000000000000000022141173363230200136760ustar00/dev/ide/host0/bus0/target0/lun0/part2	/ ext2 defaults,ro,errors=remount-ro 0 1
/dev/ide/host0/bus0/target0/lun0/part1	/boot ext2 defaults,ro 0 2
/dev/ide/host0/bus0/target0/lun0/part3	/home ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part6	/usr ext2 defaults,ro 0 2
/dev/ide/host0/bus0/target0/lun0/part7	/usr/local ext2 defaults,ro 0 2
/dev/ide/host0/bus0/target0/lun0/part8	/usr/local/opt ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part9	/var ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part10	/var/log ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part11	/var/tmp ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part12	/usr/local/opt/package/mail/qmail-1.03/queue ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part13	/var/cache ext2 defaults,rw 0 2
/dev/ide/host0/bus0/target0/lun0/part14	/alt ext2 defaults,rw 0 2

/dev/ide/host0/bus0/target0/lun0/part5	none swap sw 0 0
tmpfs  /tmp  tmpfs  rw,mode=1777,size=64m  0 0

# none		/dev		devfs	noauto	0 0
# proc		/proc		proc	noauto	0 0
# tmpfs		/service        tmpfs	noauto	0 0
#sysfs		/sys		sysfs	noauto	0 0

/dev/floppy/0	/mnt/floppy	auto	defaults,noauto	0 0
dietlibc-0.33~cvs20120325/test/ftell.c010064400000000000000000000007571173363230200141400ustar00#include 
#include 

int main() {
  FILE* f = popen("/bin/echo testing","r");
  int i=getc(f);
  assert(ftell(f)==-1);
  assert(getc(f) == 'e');
  pclose(f);
  f=fopen("/tmp/test","w");
  assert(ftell(f)==0);
  fputs("test",f);
  assert(ftell(f)==4);
  fclose(f);
  f=fopen("/tmp/test","r");
  assert(ftell(f)==0);
  i=getc(f);
  assert(ftell(f)==1);
  ungetc(i,f);
  assert(ftell(f)==0);
  i=getc(f);
  i=getc(f);
  assert(ftell(f)==2);
  fclose(f);
  unlink("/tmp/test");
}
dietlibc-0.33~cvs20120325/test/ftw.c010064400000000000000000000003111173363230200136140ustar00#include 
#include 

int traverse(const char* file, const struct stat* sb, int flag) {
  printf("found %s\n",file);
  return 0;
}

int main() {
  ftw("/tmp",traverse,10);
  return 0;
}
dietlibc-0.33~cvs20120325/test/fwrite.c010064400000000000000000000002311173363230200143150ustar00#include 

int main() {
  FILE *f=fopen("test","wb");
  char buf[]="abcdefg";
  if (fwrite(buf,1,5,f)!=5) return -1;
  fclose(f);
  return 0;
}
dietlibc-0.33~cvs20120325/test/getaddrinfo.c010064400000000000000000000021311173363230200153040ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main() {
  struct addrinfo hints, *ai, *aitop;
  int gaierr;
  memset(&hints,0,sizeof(hints));
  hints.ai_family=AF_UNSPEC;
  hints.ai_flags=0;
  hints.ai_socktype=0;
  if ((gaierr = getaddrinfo(NULL,"6010",&hints,&aitop)) != 0) {
    printf("error: %.100s\n",gai_strerror(gaierr));
    exit(0);
  }
  ai=aitop;
  while (ai) {
    printf("found host %s, port %d, family %s, socktype %s\n",ai->ai_canonname,
	   ntohs(ai->ai_family==AF_INET6?((struct sockaddr_in6*)ai->ai_addr)->sin6_port:
				   ((struct sockaddr_in*)ai->ai_addr)->sin_port),
	   ai->ai_family==AF_INET6?"PF_INET6":"PF_INET",
	   ai->ai_socktype==SOCK_STREAM?"SOCK_STREAM":"SOCK_DGRAM");
    {
      char buf[100];
      inet_ntop(ai->ai_family,ai->ai_family==AF_INET6?
		(char*)&(((struct sockaddr_in6*)ai->ai_addr)->sin6_addr):
		(char*)&(((struct sockaddr_in*)ai->ai_addr)->sin_addr),buf,100);
      printf("  %s\n",buf);
    }
    ai=ai->ai_next;
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/getdelim.c010064400000000000000000000006641173363230200146210ustar00#define _GNU_SOURCE
#include 
#include 

int main(void)
{
    FILE * fp;
    char * line = NULL;
    size_t len = 0;
    ssize_t read;
    fp = fopen("/etc/motd", "r");
    if (fp == NULL)
	  exit(EXIT_FAILURE);
    while ((read = getline(&line, &len, fp)) != -1) {
	  printf("Retrieved line of length %zu (n=%zu):\n", read, len);
	  printf("%s", line);
    }
    if (line)
	  free(line);
    return EXIT_SUCCESS;
}

dietlibc-0.33~cvs20120325/test/getenv.c010064400000000000000000000002571173363230200143150ustar00#include 
#include 
#include 

int main() {
  assert(getenv("PATH"));
  putenv("foo=bar");
  assert(!strcmp(getenv("foo"),"bar"));
  return 0;
}
dietlibc-0.33~cvs20120325/test/getgrnam.c010064400000000000000000000006541173363230200146320ustar00#include 
#include 

int main() {
  int i;
  struct group* gr=getgrnam("fnord");
  if (!gr) gr=getgrnam("uucp");
  if (!gr) {
    puts("not found");
    return 0;
  }
  printf("name %s\tpassword %s\tgid %u\t[",gr->gr_name,gr->gr_passwd,gr->gr_gid);
  for (i=0; i<8; ++i) {
    if (gr->gr_mem[i])
      printf("%s%s",gr->gr_mem[i],gr->gr_mem[i+1]?",":"");
    else
      break;
  }
  printf("]\n");
  return 0;
}
dietlibc-0.33~cvs20120325/test/gethostbyaddr.c010064400000000000000000000007671173363230200156760ustar00#include 
#include 
#include 
#include 
#include 

int main() {
  struct in_addr bar;
  struct hostent *foo;
  inet_aton("160.45.10.8",&bar);
  foo=gethostbyaddr(&bar,4,AF_INET);
  if (foo) {
    int i;
    for (i=0; foo->h_addr_list[i]; ++i)
      printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr_list[i]));
    for (i=0; foo->h_aliases[i]; ++i)
      printf("  also known as %s\n",foo->h_aliases[i]);
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/gethostbyname.c010064400000000000000000000006671173363230200157030ustar00#include 
#include 
#include 
#include 


int main() {
  struct hostent *foo;
  foo=gethostbyname("zeit.fu-berlin.de");
  if (foo) {
    int i;
    printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
    for (i=0; foo->h_aliases[i]; ++i) {
      printf("  also known as %s\n",foo->h_aliases[i]);
    }
  } else return 1;
/*  printf("%g %g\n",1e-10,1e10); */

return 0;
}
dietlibc-0.33~cvs20120325/test/gethostbyname_r.c010064400000000000000000000007661173363230200162240ustar00#include 
#include 
#include 
#include 
#include 
#include 

int main() {
  struct hostent host,*res;
  char buf[2048];
  int fnord;
  if (gethostbyname_r("localhost",&host,buf,2048,&res,&fnord))
    return 2;
  printf("%s -> %s\n",res->h_name,inet_ntoa(*(struct in_addr*)res->h_addr));

  assert(strcmp(res->h_name, "localhost") == 0);
  assert(strcmp((char *)inet_ntoa(*(struct in_addr*)res->h_addr), "127.0.0.1") == 0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/gethostent.c010064400000000000000000000005741173363230200152130ustar00#include 
#include 
#include 
#include 

int main() {
  struct hostent *foo;
  foo=gethostent();
  if (foo) {
    int i;
    printf("%s -> %s\n",foo->h_name,inet_ntoa(*(struct in_addr*)foo->h_addr));
    for (i=0; foo->h_aliases[i]; ++i) {
      printf("  also known as %s\n",foo->h_aliases[i]);
    }
  } else return 1;
  return 0;
}
dietlibc-0.33~cvs20120325/test/getmntent.c010064400000000000000000000021721173363230200150300ustar00#include 
#include 
#include 

int main() {
 int entsuccess=0;
 FILE* fstab = setmntent("fstab", "r");
 struct mntent* e;

 if (!fstab) {
     perror("setmntent()");
     return 1;
 }

while ((e = getmntent(fstab))) {
 entsuccess=1;
#if 0
  char    *mnt_fsname;    /* name of mounted file system */
  char    *mnt_dir;       /* file system path prefix */
  char    *mnt_type;      /* mount type (see mntent.h) */
  char    *mnt_opts;      /* mount options (see mntent.h) */
  int     mnt_freq;       /* dump frequency in days */
  int     mnt_passno;     /* pass number on parallel fsck */
#endif
 printf("fsname %s\n  dir %s\n  type %s\n  opts %s\n  freq %d\n  passno %d\n\n",
      e->mnt_fsname,e->mnt_dir,e->mnt_type,e->mnt_opts,e->mnt_freq,e->mnt_passno);
 }

 if ( !entsuccess ) {
   perror("getmntent()");
   return 2;
 }

 printf("closing /etc/fstab\n");
 assert ( 1 == endmntent(fstab));
 printf("closing /etc/fstab again\n");
 assert ( 1 == endmntent(fstab)); /* endmntent must always return 1 */
 printf("entmntent(0)\n");
 assert ( 1 == endmntent(0)); /* causes a segfault with diet libc */
 return 0;
}

dietlibc-0.33~cvs20120325/test/getopt.c010064400000000000000000000031311173363230200143210ustar00#include      /* for printf */
#include     /* for exit */
#include 

int
main (int argc, char **argv) {
  int c;
  int digit_optind = 0;

  while (1) {
    int this_option_optind = optind ? optind : 1;
    int option_index = 0;
    static struct option long_options[] = {
      {"add-file", 1, 0, 0},
      {"add", 1, 0, 0},
      {"append", 0, 0, 0},
      {"delete", 1, 0, 0},
      {"verbose", 0, 0, 0},
      {"create", 1, 0, 'c'},
      {"file", 1, 0, 0},
      {0, 0, 0, 0}
    };

    c = getopt_long_only (argc, argv, "abc:d:012",
			  long_options, &option_index);
    if (c == -1)
	break;

    switch (c) {
    case 0:
      printf ("option %s", long_options[option_index].name);
      if (optarg)
	printf (" with arg %s", optarg);
      printf ("\n");
      break;

    case '0':
    case '1':
    case '2':
      if (digit_optind != 0 && digit_optind != this_option_optind)
	printf ("digits occur in two different argv-elements.\n");
      digit_optind = this_option_optind;
      printf ("option %c\n", c);
      break;

    case 'a':
      printf ("option a\n");
      break;

    case 'b':
      printf ("option b\n");
      break;

    case 'c':
      printf ("option c with value `%s'\n", optarg);
      break;

    case 'd':
      printf ("option d with value `%s'\n", optarg);
      break;

    case '?':
      break;

    default:
      printf ("?? getopt returned character code 0%o ??\n", c);
    }
  }

  if (optind < argc) {
    printf ("non-option ARGV-elements: ");
    while (optind < argc)
      printf ("%s ", argv[optind++]);
    printf ("\n");
  }

  exit (0);
}

dietlibc-0.33~cvs20120325/test/getpass.c010064400000000000000000000001421173363230200144640ustar00#include 
#include 

int main() {
  puts(getpass("Password: "));
  return 0;
}
dietlibc-0.33~cvs20120325/test/getpwnam.c010064400000000000000000000011321173363230200146400ustar00#include 
#include 

int main() {
  struct passwd* pw=getpwnam("fnord");
  if (!pw) pw=getpwnam("alias");
  if (!pw) pw=getpwnam("nobody");
  if (!pw) pw=getpwnam("root");
  if (!pw) {
    puts("not found");
    return 0;
  }

  printf("name %s\npassword %s\nuid %u\ngid %u\ngecos %s\ndir %s\nshell %s\n",
	  pw->pw_name,pw->pw_passwd,pw->pw_uid,pw->pw_gid,pw->pw_gecos,pw->pw_dir,
	  pw->pw_shell);

  pw=getpwnam("doesNOThopefullnotexistsdar3245235wrafsdsfsdpl");
  if (pw) printf("getpwnam(\"doesNOThopefullnotexistsdar3245235wrafsdsfsdpl\" did not return null\n");
  return 0;	  
}
dietlibc-0.33~cvs20120325/test/getservbyname.c010064400000000000000000000005561173363230200157020ustar00#include 
#include 

int main(int argc,char *argv[]) {
  struct servent* se;
  if ((se=getservbyname("pop","tcp"))) {
    int i;
    printf("name %s\tport %d\tproto %s\n",se->s_name,ntohs(se->s_port),se->s_proto);
    for (i=0; i<16; ++i) {
      if (!se->s_aliases[i]) break;
      printf("  alias %s\n",se->s_aliases[i]);
    }
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/getservbyport.c010064400000000000000000000006121173363230200157370ustar00#include 
#include 
#include 

int main(int argc,char *argv[]) {
  struct servent* se;
  if ((se=getservbyport(htons(80),"tcp"))) {
    int i;
    printf("name %s\tport %d\tproto %s\n",se->s_name,ntohs(se->s_port),se->s_proto);
    for (i=0; i<16; ++i) {
      if (!se->s_aliases[i]) break;
      printf("  alias %s\n",se->s_aliases[i]);
    }
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/gettimeofday.c010064400000000000000000000002541173363230200155030ustar00#include 
#include 
#include 

main() {
  struct timeval t;
  printf("%d\n",gettimeofday(&t,0));
  printf("%lu %lu\n",t.tv_sec,t.tv_usec);
}
dietlibc-0.33~cvs20120325/test/getusershell.c010064400000000000000000000002141173363230200155240ustar00#define _BSD_SOURCE
#include 
#include 

int main() {
  char* c;
  while ((c=getusershell()))
    puts(c);
  return 0;
}
dietlibc-0.33~cvs20120325/test/glob.c010064400000000000000000000003051173363230200137420ustar00#include 
#include 

int main() {
  glob_t g;
  int i;
  printf("%d\n",glob("/tmp/*.c",0,0,&g));
  for (i=0; i
#include 

int main() {
  struct group gr,*tmp;
  char buf[1000];
  while (getgrent_r(&gr,buf,sizeof(buf),&tmp)==0) {
    int i;
    printf("name %s\tpassword %s\tgid %u\t[",gr.gr_name,gr.gr_passwd,gr.gr_gid);
    for (i=0; i<8; ++i) {
      if (gr.gr_mem[i])
	printf("%s%s",gr.gr_mem[i],gr.gr_mem[i+1]?",":"");
      else
	break;
    }
    printf("]\n");
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/hasmntopt.c010064400000000000000000000006051173363230200150370ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  struct mntent me;
  char *c;
  me.mnt_opts="foo,bar=baz,duh";
  if (!(c=hasmntopt(&me,"foo"))) die("hasmntopt did not find foo");
  if (!(c=hasmntopt(&me,"duh"))) die("hasmntopt did not find duh");
  printf("%s\n",hasmntopt(&me,"bar"));
  return 0;
}
dietlibc-0.33~cvs20120325/test/hello.c010064400000000000000000000004721173363230200141270ustar00#include 

#ifdef __dietlibc__
#include 
#else
#warning "You are not using dietlibc, using printf instead of __write1"
#include 
#define __write1(x) printf("%s", x)
#endif

#define HELLO "Hello, world!\n"
int main() {
  assert (__write1(HELLO)  == sizeof HELLO -1 );
  
  return 0;
}
dietlibc-0.33~cvs20120325/test/iconv.c010064400000000000000000000006211173363230200141360ustar00#include 
#include 
#include 
#include 

int main() {
  iconv_t i=iconv_open("UTF-16BE","UTF-16");
  char foo[100]="\xFE\xFF\xD8\x08\xDF\x45\x00\x3D\x00\x52\x00\x61";
  char bar[100];
  char *x=foo,*y=bar;
  size_t X=12,Y=100;
  assert(iconv(i,&x,&X,&y,&Y)==0 && X==0 && Y==90);
  assert(memcmp(bar,"\xD8\x08\xDF\x45\x00\x3D\x00\x52\x00\x61",10)==0);
return 0;
}
dietlibc-0.33~cvs20120325/test/if_nameindex.c010064400000000000000000000004321173363230200154460ustar00#include 
#include 

int main() {
  struct if_nameindex* t=if_nameindex();
  if (t) {
    struct if_nameindex* t1=t;
    while (t->if_index) {
      printf("index %u: \"%s\"\n",t->if_index,t->if_name);
      ++t;
    }
    if_freenameindex(t1);
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/inet/Makefile010064400000000000000000000003441173363230200152550ustar00DIET=diet
CC=gcc
CFLAGS=-Wall

TESTPROGRAMS=test_ifindex tst-gethnm tst-ntoa
# tst-network does not link w diet libc
all: inet 
	
inet: $(TESTPROGRAMS)	

%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

clean:
	rm -f $(TESTPROGRAMS)


dietlibc-0.33~cvs20120325/test/inet/runtests.sh010064400000000000000000000003041173363230200160340ustar00#!/bin/sh

TESTPROGRAMS="test_ifindex tst-gethnm tst-ntoa"

for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
 done 


dietlibc-0.33~cvs20120325/test/inet/test_ifindex.c010064400000000000000000000040561173363230200164520ustar00/* Test interface name <-> index conversions.
   Copyright (C) 1997, 2000 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Philip Blundell .

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 
#include 
#include 

int
main (void)
{
  int failures = 0;
  struct if_nameindex *idx = if_nameindex (), *p;
  if (idx == NULL)
    {
      if (errno != ENOSYS)
	{
	  printf ("Couldn't get any interfaces.\n");
	  exit (1);
	}
      /* The function is simply not implemented.  */
      exit (0);
    }

  printf ("Idx            Name | Idx           Name\n");

  for (p = idx; p->if_index || p->if_name; ++p)
    {
      char buf[IFNAMSIZ];
      unsigned int ni;
      int result;
      printf ("%3d %15s | ", p->if_index, p->if_name);
      printf ("%3d", ni = if_nametoindex (p->if_name));
      printf ("%15s", if_indextoname (p->if_index, buf));
      result = (ni != p->if_index || (strcmp (buf, p->if_name)));
      if (ni == p->if_index)
	/* We have to make sure that this is not an alias with the
	   same interface number.  */
	if (p->if_index == if_nametoindex (buf))
	  result = 0;
      printf ("%10s", result ? "fail" : "okay");
      printf ("\n");
      failures += result;
    }
  if_freenameindex (idx);
  return failures ? 1 : 0;
}
dietlibc-0.33~cvs20120325/test/inet/tst-gethnm.c010064400000000000000000000024751173363230200160620ustar00/* Based on a test case by grd@algonet.se.  */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

int
main (void)
{
  struct hostent *ent;
  struct in_addr hostaddr;
  int result = 0;

  inet_aton ("127.0.0.1", (struct in_addr *) &hostaddr.s_addr);
  ent = gethostbyaddr (&hostaddr, sizeof (hostaddr), AF_INET);
  if (ent == NULL)
    puts ("gethostbyaddr (...) == NULL");
  else
    {
      puts ("Using gethostbyaddr(..):");
      printf ("h_name: %s\n", ent->h_name);

      if (ent->h_aliases == NULL)
	puts ("ent->h_aliases == NULL");
      else
	printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
    }

  ent = gethostbyname ("127.0.0.1");
  if (ent == NULL)
    {
      puts ("gethostbyname (\"127.0.0.1\") == NULL");
      result = 1;
    }
  else
    {
      printf ("\nNow using gethostbyname(..):\n");
      printf ("h_name: %s\n", ent->h_name);
      if (strcmp (ent->h_name, "127.0.0.1") != 0)
	{
	  puts ("ent->h_name != \"127.0.0.1\"");
	  result = 1;
	}

      if (ent->h_aliases == NULL)
	{
	  puts ("ent->h_aliases == NULL");
	  result = 1;
	}
      else
	{
	  printf ("h_aliases[0]: %s\n", ent->h_aliases[0]);
	  result |= ent->h_aliases[0] != NULL;
	}
    }

  return result;
}
dietlibc-0.33~cvs20120325/test/inet/tst-network.c010064400000000000000000000037331173363230200162670ustar00/* Test for inet_network.
   Copyright (C) 2000, 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Andreas Jaeger , 2000.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 
#include 

struct
{
  const char *network;
  uint32_t number;
} tests [] =
{
  {"1.0.0.0", 0x1000000},
  {"1.0.0", 0x10000},
  {"1.0", 0x100},
  {"1", 0x1},
  {"192.168.0.0", 0xC0A80000},
  /* Now some invalid addresses.  */
  {"141.30.225.2800", INADDR_NONE},
  {"141.76.1.1.1", INADDR_NONE},
  {"141.76.1.11.", INADDR_NONE},
  {"1410", INADDR_NONE},
  {"1.1410", INADDR_NONE},
  {"1.1410.", INADDR_NONE},
  {"1.1410", INADDR_NONE},
  {"141.76.1111", INADDR_NONE},
  {"141.76.1111.", INADDR_NONE}
};


int
main (void)
{
  int errors = 0;
  size_t i;
  uint32_t res;

  for (i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
    {
      printf ("Testing: %s\n", tests[i].network);
      res = inet_network (tests[i].network);

      if (res != tests[i].number)
	{
	  printf ("Test failed for inet_network (\"%s\"):\n",
		  tests[i].network);
	  printf ("Expected return value %u (0x%x) but got %u (0x%x).\n",
		  tests[i].number, tests[i].number, res, res);
	}

    }

  return errors != 0;
}
dietlibc-0.33~cvs20120325/test/inet/tst-ntoa.c010064400000000000000000000012371173363230200155340ustar00#include 
#include 
#include 
#include 


static int
test (unsigned int inaddr, const char *expected)
{
  struct in_addr addr;
  char *res;
  int fail;

  addr.s_addr = htonl (inaddr);
  res = inet_ntoa (addr);
  fail = strcmp (res, expected);

  printf ("%#010x -> \"%s\" -> %s%s\n", inaddr, res,
	  fail ? "fail, expected" : "ok", fail ? expected : "");

  return fail;
}


int
main (void)
{
  int result = 0;

  result |= test (INADDR_LOOPBACK, "127.0.0.1");
  result |= test (INADDR_BROADCAST, "255.255.255.255");
  result |= test (INADDR_ANY, "0.0.0.0");
  result |= test (0xc0060746, "192.6.7.70");

  return result;
}
dietlibc-0.33~cvs20120325/test/ltostr.c010064400000000000000000000007651173363230200143600ustar00#include 
#include 
#include 

#ifndef __dietlibc__
#warning "You are not using dietlibc, __ltostr test disbled"
int main () { return 0; }
#else
int main() {
  char buf[1024];
  assert(__ltostr(buf,10,1723,10,0)==4); assert(!strcmp(buf,"1723"));
  assert(__ltostr(buf,3,1723,10,0)==2); assert(!strcmp(buf,"23"));
  assert(__ltostr(buf,2,0x1234,16,0)==1); assert(!strcmp(buf,"4"));
  assert(__ltostr(buf,3,0xFEFE,16,1)==2); assert(!strcmp(buf,"FE"));
  return 0;
}
#endif
dietlibc-0.33~cvs20120325/test/malloc-debugger.c010064400000000000000000000004201173363230200160460ustar00#include 
#include 

int main() {
  char* c=malloc(13);
  char* tmp;
  fprintf(stderr,"got %p\n",c);
  c[0]=14;
//  c[15]=0;
  tmp=realloc(c,12345);
  ++tmp[0];
  if (tmp[0]!=15) abort();
//  c[0]=1;
//  free(c);
  free(tmp);
//  c[0]=13;
  return 0;
}
dietlibc-0.33~cvs20120325/test/mbrlen.c010064400000000000000000000010621173363230200142770ustar00#include 
#include 
#include 
#include 

main() {
  static mbstate_t ps;
  setlocale(LC_CTYPE,"de_DE.UTF8");
  /* does it parse a single multibyte sequence OK? */
  assert(mbrlen("\xc2\xa9",2,&ps)==2);
  /* does it whine about an invalid sequence? */
  assert(mbrlen("\xa9",1,&ps)==(size_t)-1);
  /* does it accept a multibyte sequence in two parts? */
  printf("%d\n",mbrlen("\xc2\xa9",1,&ps));
  printf("%d\n",mbrlen("\xa9""fnord",6,&ps));
  /* does it parse non-sequence stuff right? */
  assert(mbrlen("f",1,&ps)==1);
}
dietlibc-0.33~cvs20120325/test/mbtowc.c010064400000000000000000000012401173363230200143110ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main() {
  wchar_t ws;
  char* c="fn\xc3\xb6rd";
  size_t n=strlen(c);
  setlocale(LC_CTYPE,"de_DE.UTF8");

  ws=0;
  assert(mbtowc(&ws,c,6)==1 && ws==102);
  assert(mbtowc(&ws,c+1,5)==1 && ws==110);
  assert(mbtowc(&ws,c+2,4)==2 && ws==246);
  assert(mbtowc(&ws,c+4,2)==1 && ws==114);
  assert(mbtowc(&ws,c+5,1)==1 && ws==100);
  assert(mbtowc(&ws,c+6,1)==0);

  errno=0;
  c="fnörd";
  assert(mbtowc(&ws,c,6)==1 && ws==102);
  assert(mbtowc(&ws,c+1,5)==1 && ws==110);
  assert(mbtowc(&ws,c+2,4)==(size_t)-1 && errno==EILSEQ);
}
dietlibc-0.33~cvs20120325/test/md5_testharness.c010064400000000000000000000122621173363230200161340ustar00
#include 
#include 

#ifndef __dietlibc__
#warning "You are not using diet libc, md5 test disbled"
int main(void) { return 0; }
#else
#include 


#if defined (__i386__) || defined (__x86_64__)
 #define RDTSC(dst) { asm volatile ("rdtsc" : "=a" (dst) : : "edx"); }
 #define ITERATIONS 10
#else
 #define RDTSC(dst) { dst = 0; }
 #define ITERATIONS 1
#endif


static const char rawdata[] = "abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "bcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "cdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "defghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "efghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "fghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "ghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "hijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "ijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "jklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "klmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "lmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "mnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "nopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "opqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "pqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "qrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "rstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "stuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "tuvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "uvwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "vwxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "wxyz0123456789abcdefghijklmnopqrstuvwxyz0123456789"
                              "xyz0123456789abcdefghijklmnopqrstuvwxyz0123456789";


/*
   You will just have to trust me that this is correct... :-)
*/

static const char hash_expected[32+1] = "45392e1d034f05172294e7714c555fac";


static int IsLittleEndian (void)
{
   static const unsigned long ul = 0x00000001;

   return ((int) (*((unsigned char *) &ul)));
}

static int IsBigEndian (void)
{
   static const unsigned long ul = 0x01000000;

   return ((int) (*((unsigned char *) &ul)));
}


int main (int argc, char *argv[])
{
   int i, j;
   int errorcode = 0;

   unsigned int start;
   unsigned int stop;
   unsigned int fastest;
   
   unsigned int total_hashed_byte_count;
   unsigned int total_md5update_calls;

   MD5_CTX Context;

   unsigned char hash[16];

   char hash_as_ascii[32+1];

   char *result;

   if (IsLittleEndian() && !IsBigEndian())
   {
      printf ("\n\nThis platform is Little-Endian\n");
   }
	else if (!IsLittleEndian() && IsBigEndian())
   {
      printf ("\n\nThis platform is Big-Endian\n");
   }
	else
   {
      printf ("\n\nThis platform is Broken.\n");
   }

   fastest = 0xffffffff;

   for (i = 0; i < ITERATIONS; i++)
   {
      total_hashed_byte_count = 0;
      total_md5update_calls = 0;

      RDTSC(start);

      MD5Init (&Context);

      for (j = 0; j < sizeof(rawdata); j++)
      {
         unsigned int hashed_byte_count = (sizeof(rawdata) - j);

         MD5Update (&Context, (unsigned char *) &rawdata[j], hashed_byte_count);

         total_hashed_byte_count += hashed_byte_count;
         total_md5update_calls++;
      }

      MD5Final (hash, &Context);
   
      RDTSC(stop);
      
      fastest = ((stop - start) < fastest) ? (stop - start) : fastest;
   }      

   sprintf (hash_as_ascii, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
            hash[ 0], hash[ 1], hash[ 2], hash[ 3], hash[ 4], hash[ 5], hash[ 6], hash[ 7],
            hash[ 8], hash[ 9], hash[10], hash[11], hash[12], hash[13], hash[14], hash[15]);

   if (strcmp (hash_expected, hash_as_ascii) == 0)
   {
      result = " (Passed)";
   }
   else
   {
      result = " (Failed !!)";
      errorcode++;
   }
   
   printf ("\n");
   printf ("MD5 Hashing test (aligned + unaligned data)\n");
   printf ("-------------------------------------------\n");
   printf ("Expected Hash      = %s\n",   hash_expected);
   printf ("Actual Hash        = %s%s\n", hash_as_ascii, result);
   printf ("Execution time     = %d\n",   fastest);
   printf ("Hashed bytes       = %d\n",   total_hashed_byte_count);     /* NB: total is per iteration */
   printf ("Calls to MD5Update = %d\n",   total_md5update_calls);       /* NB: total is per iteration */
   
   printf ("\n");

   return (errorcode);
}
#endif

dietlibc-0.33~cvs20120325/test/memccpy.c010064400000000000000000000005431173363230200144600ustar00#include 
#include 

int
main ()
{
	char buf[100];
	memset (buf, 0x1, sizeof (buf));
	assert (memccpy (buf, "Hello World\n", ' ', sizeof (buf)));
	assert (buf[6] == 0x1);
	assert (!*(char *) (memccpy (buf, "Hello, World", 0, sizeof (buf))-1));
	assert (buf[13] == 0x1);
	assert (!memccpy (buf, "Hello, World\n", 0, 5));
	return (0);
}
dietlibc-0.33~cvs20120325/test/memchr.c010064400000000000000000000005451173363230200143000ustar00#include 
#include 

int main() {
  const char* test="blubber";
  assert(memchr("aaaa",'x',4)==0);
  assert(memchr(0,'x',0)==0);
  assert(memchr(test,'u',2) == NULL);
  assert(memchr(test,'u',7) == test+2);
  assert(memchr(test,'b',7)==test);
  assert(memchr(test+6,'r',1)==test+6);
  assert(memchr(test+7,0,100)==test+7);
  return 0;
}
dietlibc-0.33~cvs20120325/test/memcmp.c010064400000000000000000000003141173363230200142750ustar00#include 
#include 

int main() {
  const char* test="blubber";
  assert(memcmp(test,"blubber",8)==0);
  assert(memcmp(test,"fnord",5)<0);
  assert(memcmp(test,0,0)==0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/memrchr.c010064400000000000000000000004621173363230200144600ustar00#define _GNU_SOURCE
#include 
#include 

int main() {
  const char* test="blubber";
  assert(memrchr("aaaa",'x',4)==0);
  assert(memrchr(0,'x',0)==0);
  assert(memrchr(test,'u',7) == test+2);
  assert(memrchr(test,'b',7)==test+4);
  assert(memrchr(test+6,'r',1)==test+6);
  return 0;
}
dietlibc-0.33~cvs20120325/test/memusage.c010064400000000000000000000004131173363230200146220ustar00#include 

int main() {
  FILE* f=fopen("/proc/self/statm","r");
  int size,resident,shared;
  if (fscanf(f,"%d %d %d",&size,&resident,&shared)==3) {
    printf("%dK total size, %dK resident, %dK shared\n",
	   size*4,resident*4,shared*4);
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/mktime.c010064400000000000000000000016461173363230200143160ustar00#include 
#include 

int main() {
  struct tm t;
  t.tm_sec=1;
  t.tm_min=2;
  t.tm_hour=3;
  t.tm_mday=29;
  t.tm_mon=2;
  t.tm_year=100;
  printf("%d\n",mktime(&t));
  t.tm_mday=1;
  t.tm_mon=3;
  t.tm_year=102;
  printf("%d\n",mktime(&t));
  t.tm_mday=1;
  t.tm_mon=6;
  t.tm_year=102;
  printf("%d\n",mktime(&t));
  return 0;
}

#if 0
                      int     tm_sec;         /* seconds */
                      int     tm_min;         /* minutes */
                      int     tm_hour;        /* hours */
                      int     tm_mday;        /* day of the month */
                      int     tm_mon;         /* month */
                      int     tm_year;        /* year */
                      int     tm_wday;        /* day of the week */
                      int     tm_yday;        /* day in the year */
                      int     tm_isdst;       /* daylight saving time */
#endif
dietlibc-0.33~cvs20120325/test/mmap_test.c010064400000000000000000000027531173363230200150210ustar00
#include 
#include 
#include 
#include 
#include 

#define FILENAME   "/tmp/zz_temp_mmap_test"
#define TESTSTRING "This is a test string"


int main (int argc, char * argv[])
{
   int fd;
   void *filememory_1;
   void *filememory_2;
   
   fd = open (FILENAME, O_RDWR | O_CREAT);
   
   if (fd < 0)
   {
      fprintf (stderr, "Couldn't open %s for writing\n", FILENAME);
      return (1);
   }

   write (fd, TESTSTRING, sizeof(TESTSTRING));

   /*
      Try mmapping the newly created file...
   */

   filememory_1 = mmap (NULL, 0x0100, PROT_READ, MAP_PRIVATE, fd, 0);
   
   if (filememory_1 == (void *) -1)
   {
      perror("mmap returned error");
      return (1);
   }

   /*
      Try mmapping with a bogus file descriptor... (should fail)
   */

   filememory_2 = mmap (NULL, 0x0100, PROT_READ, MAP_PRIVATE, fd+10, 0);
   
   if ((filememory_2 != (void *) -1) || (errno != 9))
   {
      fprintf (stderr, "mmap allowed a bogus file descriptor...\n");
      return (1);
   }
   
   close (fd);

   /*
      Check that we can read back from the file OK
   */

   if ((*(unsigned char *) filememory_1) != TESTSTRING[0])
   {
      fprintf (stderr, "mmap doesn't give expected data...\n");
      return (1);
   }
   
   /*
      fixme: check unmapping as well.... ??
   */


   /*
      Clean up.
   */

   if (unlink (FILENAME) != 0)
   {
      fprintf (stderr, "Unexpected problem deleting the tempfile... ?\n");
      return (1);
   }

   return (0);
}


dietlibc-0.33~cvs20120325/test/pipe.c010064400000000000000000000004361173363230200137610ustar00#include 
#include 

int
main (void)
{
	int fd[2];
	assert (!pipe (fd));
	/* if for some reason the parent process has fd3 or fd4
	   already open, then this will fail although there is
	   no real error */
	assert (fd[0] == 3);
	assert (fd[1] == 4);
	return (0);
}
dietlibc-0.33~cvs20120325/test/popen.c010064400000000000000000000003301173363230200141360ustar00#include 
#include 

int main() {
  FILE* f;
  char buf[1024];
  assert(f=popen("/bin/echo foo","r"));
  assert(fgets(buf,sizeof(buf),f));
  assert(fclose(f)==0);
  assert(!strcmp(buf,"foo\n"));
}
dietlibc-0.33~cvs20120325/test/printf.c010064400000000000000000000070721173363230200143310ustar00#include 
#include 
#include 
#include 
#include 
#include 

#define ALGN		5

// https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=112986
#if 0
#undef  assert
#define assert(X)	if (!(X)) { write(2, #X "\n", sizeof(#X));  *(char *)0 = 0; }
#endif

#define TEST_INIT(EXP)					\
  char		buf[sizeof(EXP)+ALGN*3+16];		\
  int		rc;					\
  memset(buf, cmp[0], sizeof buf)

#define TEST_CHECK(EXP,SZ)				\
  assert(rc==sizeof(EXP)-1);				\
  assert(memcmp(buf,cmp,ALGN)==0);			\
  if ((SZ)>=0) {					\
    assert(memcmp(buf+ALGN,(EXP),(SZ))==0);		\
    assert(buf[ALGN+(SZ)]=='\0');			\
  }							\
  assert(memcmp(buf+ALGN+(SZ)+1,cmp,ALGN)==0)


#define TEST_SPRINTF(EXP,...)				\
  {							\
    TEST_INIT(EXP);					\
    rc=sprintf(buf+ALGN,__VA_ARGS__);			\
    TEST_CHECK(EXP,rc);					\
  }

#define TEST_SNPRINTF(EXP,SZ, ...)			\
  {							\
    volatile char * args[] = { EXP, #SZ };		\
    ssize_t	test_sz=MIN((SZ),sizeof(EXP))-1;	\
    (void)args;						\
    TEST_INIT(EXP);					\
    rc=snprintf(buf+ALGN,(SZ),__VA_ARGS__);		\
    TEST_CHECK(EXP, test_sz);				\
  }

#define TEST_SNPRINTF_NULL(EXP, ...)			\
  {							\
    int rc=snprintf(0,0, __VA_ARGS__);			\
    assert(rc==sizeof(EXP)-1);				\
  }

#define TEST(EXP, ...)						\
  TEST_SPRINTF (EXP, __VA_ARGS__);				\
  TEST_SNPRINTF(EXP,  sizeof(EXP)+1,    __VA_ARGS__);		\
  TEST_SNPRINTF(EXP,  sizeof(EXP),      __VA_ARGS__);		\
  TEST_SNPRINTF(EXP,  sizeof(EXP)-1,    __VA_ARGS__);		\
  TEST_SNPRINTF(EXP,  1,                __VA_ARGS__);		\
  TEST_SNPRINTF(EXP,  0,                __VA_ARGS__);		\
  TEST_SNPRINTF(EXP,  sizeof(EXP)+ALGN, __VA_ARGS__);		\
  TEST_SNPRINTF_NULL(EXP, __VA_ARGS__)
  

int main()
{
  char			cmp[ALGN];
  memset(cmp, '\376', sizeof cmp);

  TEST("x",   "x");
  TEST("xy",  "xy");


  TEST("23",       "%d", 23);
  TEST("5",        "%d", 5);
  TEST("0.05",     "%.2f", 0.05);
  TEST("0.000009", "%f", 9e-6);
  TEST("0.010000", "%f", 1e-2);
  TEST("    -1",   "%6d", -1);
  TEST("012",      "%03o", 10);

  TEST("foobar",  "%s",     "foobar");
  TEST("01.23",   "%05.2f", 1.23);
  TEST("001.2",   "%05.2g", 1.23);

  TEST("42",      "%i",     42);
  TEST("",        "%.0i",   0);

  TEST("52",      "%o",     42);
  TEST("",        "%.0o",   0);

  TEST("42",      "%u",     42);
  TEST("",        "%.0u",   0);

  TEST("2a",      "%x",     42);
  TEST("",        "%.0x",   0);

  TEST("2A",      "%X",     42);
  TEST("",        "%.0x",   0);

  TEST("42.23",   "%5.2f",  42.23);
  TEST("42.23",   "%5.4g",  42.23);
  TEST(" 42.2",   "%5.3g",  42.23);
  
  TEST("   1",     "%*i",   4, 1);
  TEST("   1",     "%4i",   1);
  TEST("1   ",     "%-4i",  1);
  TEST("  +1",     "%+4i",  1);
  TEST("+1  ",     "%-+4i", 1);
  TEST(" 1  ",     "%- 4i", 1);
  TEST("0001",     "%04i",  1);
  TEST("+001",     "%+04i", 1);

  TEST("0x1",      "%#x",   1);

  TEST("abcX",     "%2sX",  "abc");
  TEST("abcX",     "%-2sX", "abc");

  TEST("001234",   "%.6u",  1234);
  TEST("-001234",  "%.6i",  -1234);
  TEST("  1234",   "%6u",   1234);
  TEST(" -1234",   "%6i",   -1234);
  TEST("001234",   "%06u",  1234);
  TEST("-01234",   "%06i",  -1234);
  TEST("1234  ",   "%-6u",  1234);
  TEST("-1234 ",   "%-6i",  -1234);
  TEST("1234",     "%.6s",  "1234");
  TEST("  1234",   "%6s",   "1234");
  TEST("1234  ",   "%-6s",  "1234");
  TEST(" 01234",   "%6.5u", 1234);
  TEST("-01234",   "%6.5i", -1234);
  TEST("  1234",   "%6.5s", "1234");

#ifdef XSI_TESTS
  setlocale(LC_ALL, "de_DE");
  
  TEST("1.234",    "%'u", 1234);
  TEST("2 1",      "%2$u %1$u",  1, 2);
#endif
  
  
  return EXIT_SUCCESS;
}
dietlibc-0.33~cvs20120325/test/printf2.c010064400000000000000000000011621173363230200144050ustar00#include 
#include 
#include 

#define runtest(fmt,arg,wanted) memset(buf,0,sizeof(buf)); sprintf(buf,fmt,arg); assert(!strcmp(buf,wanted));

int main() {
  char buf[100];

  runtest("%.6u",1234,"001234");
  runtest("%6u",1234,"  1234");
  runtest("%06u",1234,"001234");
  runtest("%-6u",1234,"1234  ");
  runtest("%6.5u",1234," 01234");

  runtest("%.6s","1234","1234");
  runtest("%6s","1234","  1234");
  runtest("%06s","1234","  1234");
  runtest("%-6s","1234","1234  ");
  runtest("%6.5s","1234","  1234");

  runtest("%6.3f",1.23," 1.230");
  runtest("%6.3g",1.23,"  1.23");

  return 0;
}

dietlibc-0.33~cvs20120325/test/printftest.c010064400000000000000000000066571173363230200152410ustar00#include 
#include 

char * format[] = {
  "%",
  "%0.",
  "%.0",
  "%+0.",
  "%+.0",
  "%.5",
  "%+.5",
  "%2.5",
  "%22.5",
  "%022.5",
  "%#022.5",
  "%-#022.5",
  "%+#022.5",
  "%-22.5",
  "%+22.5",
  "%--22.5",
  "%++22.5",
  "%+-22.5",
  "%-+22.5",
  "%-#022.5",
  "%-#22.5",
  "%-2.22",
  "%+2.22",
  "%-#02.22",
  "%-#2.22",
  "%-1.5",
  "%1.5",
  "%-#01.5",
  "%-#1.5",
  "%-#.5",
  "%-#1.",
  "%-#.",
  NULL
};
 

static void
intchk (const char *fmt)
{
  (void) printf("%15s :, \"", fmt);
  (void) printf(fmt, 0);
  (void) printf("\", \"");
  (void) printf(fmt, 123);
  (void) printf("\", \"");
  (void) printf(fmt, -18);
  (void) printf("\"\n");
}

static void
fltchk (const char *fmt)
{
  (void) printf("%15s :, \"", fmt);
  (void) printf(fmt, 0.0);
  (void) printf("\", \"");
  (void) printf(fmt, 123.0001);
  (void) printf("\", \"");
  (void) printf(fmt, -18.0002301);
  (void) printf("\"\n");
}

int main()
{  
  char buf[256];
  int i;
  
  printf("%s\n\n", "# vim:syntax=off:");
  
  /* integers */
  for(i=0;format[i];i++) {
    strcpy(buf, format[i]);
    strcat(buf, "d");
    intchk(buf);
  }
  
  /* floats */
  for(i=0;format[i];i++) {
    strcpy(buf, format[i]);
    strcat(buf, "f");
    fltchk(buf);
  }
  /* hexa */
  for(i=0;format[i];i++) {
    strcpy(buf, format[i]);
    strcat(buf, "x");
    intchk(buf);
  }
  
  printf("#%.4x %4x#\n", 4, 88);
  printf("#%4x#\n",4);
  printf("#%#22.8x#\n",1234567);
  
  printf("#%+2i#\n",18);
  printf("#%i#\n",18);
  printf("#%llu#\n",4294967297ULL);
  printf("#%#x#\n",44444);
  printf("#%-8i#\n",33);
  printf("#%i#\n",18);
  printf("#%d#\n",18);
  printf("#%u#\n",18);
  printf("#%lu#\n",18);
  printf("#%li#\n",18);
  printf("#%-+#06d#\n", -123);
  printf("#%-+#6d#\n", -123);
  printf("#%+#06d#\n", -123);
  printf("#%06d#\n", -123);
  printf("#%+15s#\n","ABCDEF");
  /* from ncurses make_keys */
  printf("{ %4d, %-*.*s },\t/* %s */\n", 139, 16, 16, "KEY_A1", "key_a1");
  printf("{ %4d, %-*.*s },\t/* %s */\n", 139, 16,  2, "KEY_A1", "key_a1");
  printf("{ %4d, %-*.*s },\t/* %s */\n", 139,  2, 16, "KEY_A1", "key_a1");
  printf("{ %4d, %-*.*s },\t/* %s */\n", 139, 16,  0, "KEY_A1", "key_a1");
  printf("{ %4d, %-*.*s },\t/* %s */\n", 139,  0, 16, "KEY_A1", "key_a1");
  printf("{ %4d, %-*.*s },\t/* %s */\n", 139,  0,  0, "KEY_A1", "key_a1");
  printf("{ %4d, %*.*s },\t/* %s */\n", 139, 16, 16, "KEY_A1", "key_a1");
  printf("{ %4d, %*.*s },\t/* %s */\n", 139, 16,  2, "KEY_A1", "key_a1");
  printf("{ %4d, %*.*s },\t/* %s */\n", 139,  2, 16, "KEY_A1", "key_a1");
  printf("{ %4d, %*.*s },\t/* %s */\n", 139, 16,  0, "KEY_A1", "key_a1");
  printf("{ %4d, %*.*s },\t/* %s */\n", 139,  0, 16, "KEY_A1", "key_a1");
  printf("{ %4d, %*.*s },\t/* %s */\n", 139,  0,  0, "KEY_A1", "key_a1");
  printf("%*.*f\n",  0, 16, 0.0);
  printf("%*.*f\n", 16, 16, 0.0);
  printf("%*.*f\n",  2, 2,  -0.0);
  printf("%*.*f\n", 20, 0,  -123.123);
  printf("%*.*f\n", 10, 0,  +123.123);
  
  
  i = printf("\"%s\"\n","A");
  printf("%i\n", i); 
  /* from glibc's tst-printf.c */
  
  {
    char buf[20];
    char buf2[512];
    int i;

    printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n",
	    snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf),
	    buf);
    memset(buf2,0,sizeof(buf));
    i=snprintf(buf2, 256, "%.9999u", 10);
    printf("%i %i\n",i,strlen(buf2));
    
    printf ("snprintf (\"%%.999999u\", 10) == %d\n",
    	    snprintf(buf2, sizeof(buf2), "%.999999u", 10));
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/printftest.exp010064400000000000000000000171521173363230200156030ustar00# vim:syntax=off:

             %d :, "0", "123", "-18"
           %0.d :, "", "123", "-18"
           %.0d :, "", "123", "-18"
          %+0.d :, "+", "+123", "-18"
          %+.0d :, "+", "+123", "-18"
           %.5d :, "00000", "00123", "-00018"
          %+.5d :, "+00000", "+00123", "-00018"
          %2.5d :, "00000", "00123", "-00018"
         %22.5d :, "                 00000", "                 00123", "                -00018"
        %022.5d :, "                 00000", "                 00123", "                -00018"
       %#022.5d :, "                 00000", "                 00123", "                -00018"
      %-#022.5d :, "00000                 ", "00123                 ", "-00018                "
      %+#022.5d :, "                +00000", "                +00123", "                -00018"
        %-22.5d :, "00000                 ", "00123                 ", "-00018                "
        %+22.5d :, "                +00000", "                +00123", "                -00018"
       %--22.5d :, "00000                 ", "00123                 ", "-00018                "
       %++22.5d :, "                +00000", "                +00123", "                -00018"
       %+-22.5d :, "+00000                ", "+00123                ", "-00018                "
       %-+22.5d :, "+00000                ", "+00123                ", "-00018                "
      %-#022.5d :, "00000                 ", "00123                 ", "-00018                "
       %-#22.5d :, "00000                 ", "00123                 ", "-00018                "
        %-2.22d :, "0000000000000000000000", "0000000000000000000123", "-0000000000000000000018"
        %+2.22d :, "+0000000000000000000000", "+0000000000000000000123", "-0000000000000000000018"
      %-#02.22d :, "0000000000000000000000", "0000000000000000000123", "-0000000000000000000018"
       %-#2.22d :, "0000000000000000000000", "0000000000000000000123", "-0000000000000000000018"
         %-1.5d :, "00000", "00123", "-00018"
          %1.5d :, "00000", "00123", "-00018"
       %-#01.5d :, "00000", "00123", "-00018"
        %-#1.5d :, "00000", "00123", "-00018"
         %-#.5d :, "00000", "00123", "-00018"
         %-#1.d :, " ", "123", "-18"
          %-#.d :, "", "123", "-18"
             %f :, "0.000000", "123.000100", "-18.000230"
           %0.f :, "0", "123", "-18"
           %.0f :, "0", "123", "-18"
          %+0.f :, "+0", "+123", "-18"
          %+.0f :, "+0", "+123", "-18"
           %.5f :, "0.00000", "123.00010", "-18.00023"
          %+.5f :, "+0.00000", "+123.00010", "-18.00023"
          %2.5f :, "0.00000", "123.00010", "-18.00023"
         %22.5f :, "               0.00000", "             123.00010", "             -18.00023"
        %022.5f :, "0000000000000000.00000", "0000000000000123.00010", "-000000000000018.00023"
       %#022.5f :, "0000000000000000.00000", "0000000000000123.00010", "-000000000000018.00023"
      %-#022.5f :, "0.00000               ", "123.00010             ", "-18.00023             "
      %+#022.5f :, "+000000000000000.00000", "+000000000000123.00010", "-000000000000018.00023"
        %-22.5f :, "0.00000               ", "123.00010             ", "-18.00023             "
        %+22.5f :, "              +0.00000", "            +123.00010", "             -18.00023"
       %--22.5f :, "0.00000               ", "123.00010             ", "-18.00023             "
       %++22.5f :, "              +0.00000", "            +123.00010", "             -18.00023"
       %+-22.5f :, "+0.00000              ", "+123.00010            ", "-18.00023             "
       %-+22.5f :, "+0.00000              ", "+123.00010            ", "-18.00023             "
      %-#022.5f :, "0.00000               ", "123.00010             ", "-18.00023             "
       %-#22.5f :, "0.00000               ", "123.00010             ", "-18.00023             "
        %-2.22f :, "0.0000000000000000000000", "123.0001000000000033196557", "-18.0002300999999995667622"
        %+2.22f :, "+0.0000000000000000000000", "+123.0001000000000033196557", "-18.0002300999999995667622"
      %-#02.22f :, "0.0000000000000000000000", "123.0001000000000033196557", "-18.0002300999999995667622"
       %-#2.22f :, "0.0000000000000000000000", "123.0001000000000033196557", "-18.0002300999999995667622"
         %-1.5f :, "0.00000", "123.00010", "-18.00023"
          %1.5f :, "0.00000", "123.00010", "-18.00023"
       %-#01.5f :, "0.00000", "123.00010", "-18.00023"
        %-#1.5f :, "0.00000", "123.00010", "-18.00023"
         %-#.5f :, "0.00000", "123.00010", "-18.00023"
         %-#1.f :, "0.", "123.", "-18."
          %-#.f :, "0.", "123.", "-18."
             %x :, "0", "7b", "ffffffee"
           %0.x :, "", "7b", "ffffffee"
           %.0x :, "", "7b", "ffffffee"
          %+0.x :, "", "7b", "ffffffee"
          %+.0x :, "", "7b", "ffffffee"
           %.5x :, "00000", "0007b", "ffffffee"
          %+.5x :, "00000", "0007b", "ffffffee"
          %2.5x :, "00000", "0007b", "ffffffee"
         %22.5x :, "                 00000", "                 0007b", "              ffffffee"
        %022.5x :, "                 00000", "                 0007b", "              ffffffee"
       %#022.5x :, "                 00000", "               0x0007b", "            0xffffffee"
      %-#022.5x :, "00000                 ", "0x0007b               ", "0xffffffee            "
      %+#022.5x :, "                 00000", "               0x0007b", "            0xffffffee"
        %-22.5x :, "00000                 ", "0007b                 ", "ffffffee              "
        %+22.5x :, "                 00000", "                 0007b", "              ffffffee"
       %--22.5x :, "00000                 ", "0007b                 ", "ffffffee              "
       %++22.5x :, "                 00000", "                 0007b", "              ffffffee"
       %+-22.5x :, "00000                 ", "0007b                 ", "ffffffee              "
       %-+22.5x :, "00000                 ", "0007b                 ", "ffffffee              "
      %-#022.5x :, "00000                 ", "0x0007b               ", "0xffffffee            "
       %-#22.5x :, "00000                 ", "0x0007b               ", "0xffffffee            "
        %-2.22x :, "0000000000000000000000", "000000000000000000007b", "00000000000000ffffffee"
        %+2.22x :, "0000000000000000000000", "000000000000000000007b", "00000000000000ffffffee"
      %-#02.22x :, "0000000000000000000000", "0x000000000000000000007b", "0x00000000000000ffffffee"
       %-#2.22x :, "0000000000000000000000", "0x000000000000000000007b", "0x00000000000000ffffffee"
         %-1.5x :, "00000", "0007b", "ffffffee"
          %1.5x :, "00000", "0007b", "ffffffee"
       %-#01.5x :, "00000", "0x0007b", "0xffffffee"
        %-#1.5x :, "00000", "0x0007b", "0xffffffee"
         %-#.5x :, "00000", "0x0007b", "0xffffffee"
         %-#1.x :, " ", "0x7b", "0xffffffee"
          %-#.x :, "", "0x7b", "0xffffffee"
#0004   58#
#   4#
#            0x0012d687#
#+18#
#18#
#4294967297#
#0xad9c#
#33      #
#18#
#18#
#18#
#18#
#18#
#-123  #
#-123  #
#-00123#
#-00123#
#         ABCDEF#
{  139, KEY_A1           },	/* key_a1 */
{  139, KE               },	/* key_a1 */
{  139, KEY_A1 },	/* key_a1 */
{  139,                  },	/* key_a1 */
{  139, KEY_A1 },	/* key_a1 */
{  139,  },	/* key_a1 */
{  139,           KEY_A1 },	/* key_a1 */
{  139,               KE },	/* key_a1 */
{  139, KEY_A1 },	/* key_a1 */
{  139,                  },	/* key_a1 */
{  139, KEY_A1 },	/* key_a1 */
{  139,  },	/* key_a1 */
0.0000000000000000
0.0000000000000000
-0.00
                -123
       123
"A"
4
snprintf ("%30s", "foo") == 30, "                   "
9999 255
snprintf ("%.999999u", 10) == 999999
dietlibc-0.33~cvs20120325/test/protoent.c010064400000000000000000000011771173363230200147010ustar00#include 
#include 

int main(int argc,char *argv[]) {
#ifdef NEW
  struct protoent se,*tmp;
  char buf[1000];
  while (getprotoent_r(&se,buf,sizeof(buf),&tmp)==0) {
    int i;
    printf("name %s\tproto %s\n",se.p_name,se.s_proto);
    for (i=0; i<16; ++i) {
      if (!se.p_aliases[i]) break;
      printf("  alias %s\n",se.p_aliases[i]);
    }
  }
#else
  struct protoent* se;
  while ((se=getprotoent())) {
    int i;
    printf("name %s\tproto %d\n",se->p_name,se->p_proto);
    for (i=0; i<16; ++i) {
      if (!se->p_aliases[i]) break;
      printf("  alias %s\n",se->p_aliases[i]);
    }
  }
#endif
  return 0;
}
dietlibc-0.33~cvs20120325/test/prototypes.c010064400000000000000000000010741173363230200152530ustar00#include 

#define __THROW
#define __pure __attribute__ ((__pure__))

void* memset(void *s, int c, size_t n) __THROW;
int memcmp(const void *s1, const void *s2, size_t n) __THROW __pure;
void* memcpy(void *dest, const void *src, size_t n) __THROW;
char *strncpy(char *dest, const char *src, size_t n) __THROW;
int strncmp(const char *s1, const char *s2, size_t n) __THROW __pure;
char *strncat(char *dest, const char *src, size_t n) __THROW;

int main() {
  /* this is just a test to see whether gcc still has broken internal
   * prototypes */
  return 0;
}
dietlibc-0.33~cvs20120325/test/putenv.c010064400000000000000000000006301173363230200143410ustar00#include 
#include 
#include 

int
main ()
{
	static char foo[] = "Hello=World";
	assert (putenv ("foo=bar") != -1);
	assert (!strcmp (getenv ("foo"), "bar"));
	assert (putenv ("foo=baz") != -1);
	assert (!strcmp (getenv ("foo"), "baz"));
	putenv (foo);
	assert (!strcmp (getenv ("Hello"), "World"));
	foo[6] = 'M';
	assert (!strcmp (getenv ("Hello"), "Morld"));
	return (0);
}
dietlibc-0.33~cvs20120325/test/pwent.c010064400000000000000000000011371173363230200141600ustar00#include 
#include 

int main(int argc,char *argv[]) {
#ifndef OLD
  struct passwd pw,*tmp;
  char buf[1000];
  while (getpwent_r(&pw,buf,sizeof(buf),&tmp)==0) {
    printf("name %s\npassword %s\nuid %u\ngid %u\ngecos %s\ndir %s\nshell %s\n",
	   pw.pw_name,pw.pw_passwd,pw.pw_uid,pw.pw_gid,pw.pw_gecos,pw.pw_dir,
	   pw.pw_shell);
  }
#else
  struct passwd *pw;
  while (pw=getpwent()) {
    printf("name %s\npassword %s\nuid %u\ngid %u\ngecos %s\ndir %s\nshell %s\n",
	   pw->pw_name,pw->pw_passwd,pw->pw_uid,pw->pw_gid,pw->pw_gecos,pw->pw_dir,
	   pw->pw_shell);
  }
#endif
  return 0;
}
dietlibc-0.33~cvs20120325/test/qsort.c010064400000000000000000000032411173363230200141710ustar00#define _BSD_SOURCE
#define _GNU_SOURCE
#include 
#include 
#include 
#include 

int compar(const void* a,const void* b) {
  const unsigned char* A=*(void **)a;
  const unsigned char* B=*(void **)b;
  int l;
  while (l=(*A-*B)) {
    if (!*A) return 0;
    ++A; ++B;
  }
  return l;
}

char** A;
unsigned long a,n;

#if defined (__i386__)
#define RDTSC(dst) asm volatile ("rdtsc" : "=A" (dst))
#elif defined (__x86_64__)
#define RDTSC(dst) do {                                                        \
  uint32_t l, h;                                                               \
  asm volatile ("rdtsc" : "=a" (l), "=d" (h)); \
  dst = (((uint64_t)h) << 32) | l;                             \
} while (0)
#else
#error "Unimplemented rdtsc"
#endif

int main() {
  char buf[2048];
  unsigned long x,y;
  while (fgets(buf,sizeof(buf),stdin)) {
    buf[sizeof(buf)-1]=0;
    if (n==a) {
      a+=512;
      A=realloc(A,a*sizeof(*A));
      if (!A) {
	printf("realloc to %lu elements failed!\n",a);
	return 1;
      }
    }
    if (!(A[n]=strdup(buf))) {
      printf("strdup failed!\n");
      return 1;
    }
    ++n;
  }
  printf("sorting %lu elements...\n",n);
  {
    char** B=malloc(n*sizeof(*A));
    if (!B) {
      printf("could not alloc %lu bytes!\n",n*sizeof(*A));
      return 1;
    }
    memcpy(B,A,n*sizeof(*A));
    qsort(A,n,sizeof(*A),compar);
    memcpy(A,B,n*sizeof(*A));
  }
  RDTSC(x);
  qsort(A,n,sizeof(*A),compar);
  RDTSC(y);
  printf("qsort took %lu cycles.\n",y-x);
  {
    unsigned int i;
    for (i=0; i+10) {
	printf(" -> not sorted!\n");
	return 1;
      }
    }
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/rand48.c010064400000000000000000000006271173363230200141260ustar00#include 
#include 

int
main (void)
{
  static unsigned short  data[7] = { 1, 2, 3, 4, 5, 6, 7 };

  printf ("one   %X\n", mrand48 ());
  printf ("two   %X\n", mrand48 ());
  printf ("three %X\n", mrand48 ());

  lcong48 (data);
  printf ("after lcong48:\n");

  printf ("one   %X\n", mrand48 ());
  printf ("two   %X\n", mrand48 ());
  printf ("three %X\n", mrand48 ());

  return 0;
}
dietlibc-0.33~cvs20120325/test/read1.c010064400000000000000000000001211173363230200140070ustar00#include 

int main() {
  char buf[10];
  read(0,buf,1);
  return 0;
}
dietlibc-0.33~cvs20120325/test/readdir.c010064400000000000000000000004261173363230200144350ustar00#define _FILE_OFFSET_BITS 64
#include 
#include 
#include 

int main() {
  DIR* D=opendir(".");
  struct dirent* d;
  if (!D) {
    perror("opendir");
    return 1;
  }
  while ((d=readdir(D))) {
    printf("found %s\n",d->d_name);
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/realpath.c010064400000000000000000000006421173363230200146230ustar00#include 
#include 
#include 

main() {
  char buf[1024];

  realpath("fnord",buf);
  puts(buf);
  mkdir("foo",0755);
  symlink("foo","bar");
  close(open("foo/blah",O_WRONLY|O_CREAT,0700));
  realpath("bar/blah",buf);
  puts(buf);
  symlink("..","foo/blub");
  realpath("bar/blub/foo/blub",buf);
  puts(buf);
  unlink("foo/blub");
  unlink("foo/blah");
  rmdir("foo");
  unlink("bar");
}
dietlibc-0.33~cvs20120325/test/regex.c010064400000000000000000000131161173363230200141350ustar00#include 
#include 
#include 
#include 

int main() {
  regex_t r;
  char buf[16*1024];
  int i;
  regmatch_t matches[10];
  memset(buf,'a',sizeof buf);
  strcpy(buf+sizeof(buf)-100," foo . .. bar\n");

  assert(regcomp(&r,"a\\|b",0)==0);
  assert(regexec(&r,"a|b",10,matches,0)==0);
  regfree(&r);

  assert(regcomp(&r,"(|-.*)@fefe.de",REG_EXTENDED)==0);
  assert(regexec(&r,"@fefe.de",0,0,0)==0);
  regfree(&r);

  assert(regcomp(&r,"usenet-[0-9]{8}@fefe.de",REG_EXTENDED)==0);
  assert(regexec(&r,"usenet-12345678@fefe.de",0,0,0)==0);
  regfree(&r);

  assert(regcomp(&r,"(abuse|borland|bounceok|cdb|clickbank|der|dnscache|dsniff|gilda|myspace|password|postmaster|publicfile|qmail|qmaill|rfc2460|spam|stackguard|staroffice|susewindows|tdsl|true|vmware|web|yadocfaq|zeroseek)@fefe.de",REG_EXTENDED)==0);
  assert(regexec(&r,"abuse@fefe.de",0,0,0)==0);
  regfree(&r);

  assert(regcomp(&r,"@(ioctl.codeblau.de|fcntl.codeblau.de|knuth.codeblau.de|codeblau.de|lists.codeblau.de|code-blau.de|codeblau.com|code-blau.com|ccc.fefe.de|wegwerfdomain.de|fefes.wegwerfdomain.de|bewaff.net|rc23.rx|fnord.st|ist.schwervernetzt.de|kesim.(org|net|com)|tinydns.net|spiral-dynamics.org|hinke.org|2.0.1.0.8.5.6.0.1.0.0.2.ip6.int|eckner.org|mindbase.de|codeblau.walledcity.de)",REG_EXTENDED)==0);
  assert(regexec(&r,"abuse@fefe.de",0,0,0)==REG_NOMATCH);
  regfree(&r);

  assert(regcomp(&r,"^$",REG_EXTENDED)==0);
  assert(regexec(&r,"",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==0);
  regfree(&r);

  assert(regcomp(&r,"abracadabra$",REG_EXTENDED)==0);
  assert(regexec(&r,"abracadabracadabra",10,matches,0)==0);
  assert(matches[0].rm_so==7 && matches[0].rm_eo==18);
  regfree(&r);

  assert(regcomp(&r,"a...b",REG_EXTENDED)==0);
  assert(regexec(&r,"abababbb",10,matches,0)==0);
  assert(matches[0].rm_so==2 && matches[0].rm_eo==7);
  regfree(&r);

  assert(regcomp(&r,"XXXXXX",REG_EXTENDED)==0);
  assert(regexec(&r,"..XXXXXX",10,matches,0)==0);
  assert(matches[0].rm_so==2 && matches[0].rm_eo==8);
  regfree(&r);

  assert(regcomp(&r,"\\)",REG_EXTENDED)==0);
  assert(regexec(&r,"()",10,matches,0)==0);
  assert(matches[0].rm_so==1 && matches[0].rm_eo==2);
  regfree(&r);

  assert(regcomp(&r,"a]",REG_EXTENDED)==0);
  assert(regexec(&r,"a]a",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==2);
  regfree(&r);

  assert(regcomp(&r,"}",REG_EXTENDED)==0);
  assert(regexec(&r,"}",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"\\}",REG_EXTENDED)==0);
  assert(regexec(&r,"}",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"\\]",REG_EXTENDED)==0);
  assert(regexec(&r,"]",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"]",REG_EXTENDED)==0);
  assert(regexec(&r,"]",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"}",REG_EXTENDED)==0);
  assert(regexec(&r,"}",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"{",0)==0);
  assert(regexec(&r,"{",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"^a",REG_EXTENDED)==0);
  assert(regexec(&r,"ax",10,matches,0)==0);
  assert(matches[0].rm_so==0 && matches[0].rm_eo==1);
  regfree(&r);

  assert(regcomp(&r,"\\^a",REG_EXTENDED)==0);
  assert(regexec(&r,"a^a",10,matches,0)==0);
  assert(matches[0].rm_so==1 && matches[0].rm_eo==3);
  regfree(&r);

  assert(regcomp(&r,"(gilda|oskar|leitner(-[^@]+|))@home.fefe.de",REG_EXTENDED)==0);
  assert(regexec(&r,"leitner@home.fefe.de",10,matches,0)==0);
  regfree(&r);

  assert(regcomp(&r,"^chello[0-9]*.chello.[a-z][a-z]$",REG_EXTENDED)==0);
  assert(regexec(&r,"chello089078194199.chello.pl",10,matches,0)==0);
  regfree(&r);

  assert(regcomp(&r,"(satel.com|kievnet.com|dn|merlin.net|inetcom.com|zdn.gov|terabit.com|od|odessa|elencom.net|uz|syndicate.org|tvcom.net|dn|qt.net|b-net.com).ua",REG_EXTENDED|REG_ICASE|REG_NOSUB)==0);
  assert(regexec(&r,"mail.b-net.com.ua",0,NULL,0)==0);
  regfree(&r);

  assert(regcomp(&r,"\\(foo\\)bar\\1",0)==0);
  assert(regexec(&r,"foobarfoo",10,matches,0)==0);
  regfree(&r);

#if 0
  printf("regcomp %d\n",regcomp(&r,"\\.( ? ? ?\\.)*\\.",REG_EXTENDED|REG_NOSUB));
  printf("regexec %d\n",regexec(&r,buf,1,0,0));
  regfree(&r);
#endif
#if 0
  printf("regcomp %d\n",regcomp(&r,"^(ksambakdeplugin|mnemisis|kylixxmlrpclib|ripunix|featurekong)@freshmeat.net",REG_EXTENDED|REG_NEWLINE|REG_ICASE));
  {
    int canary[100];
    for (i=0; i<100; ++i) canary[i]=i;
    printf("regexec %d\n",regexec(&r,"mnemisis@freshmeat.net",2,matches,0));
    for (i=0; i<100; ++i) assert(canary[i]==i);
  }
  regfree(&r);
  for (i=0; i<10; ++i) {
    printf("%s(%d %d)",i?", ":" -> ",matches[i].rm_so,matches[i].rm_eo);
  }
  printf("\n");
#endif
#if 0
  printf("regcomp %d\n",regcomp(&r,"^(a|b|c|d|e)@freshmeat.net",REG_EXTENDED|REG_NEWLINE|REG_NOSUB|REG_ICASE));
  printf("regexec %d\n",regexec(&r,"a@freshmeat.net",1,0,0));
#endif
#if 0
  printf("regcomp %d\n",regcomp(&r,"^([A-Za-z ]+>|[]>:|}][]>:|}]*)",REG_EXTENDED|REG_NEWLINE|REG_NOSUB|REG_ICASE));
  printf("regexec %d\n",regexec(&r,"fnord",1,0,0));
#endif
#if 0
  printf("regcomp %d\n",regcomp(&r,"^Subject:",REG_EXTENDED|REG_ICASE));
  printf("regexec %d\n",regexec(&r,"Subject: duh",1,0,0));
#endif
#if 0
  printf("regcomp %d\n",regcomp(&r,"^To:([^@]*)?$",REG_EXTENDED|REG_ICASE|REG_NOSUB));
  printf("regexec %d\n",regexec(&r,"To: ",1,0,0));
  regfree(&r);
#endif
  return 0;
}
dietlibc-0.33~cvs20120325/test/runtests.sh010064400000000000000000000026771173363230200151140ustar00SUBDIRS="dirent inet stdio string stdlib time"

TESTPROGRAMS="adjtime alarm argv atexit bsearch byteswap calloc confstr empty fadvise flush fputc ffs fnmatch ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent siglist speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysenter ungetc utime waitpid"

STDIN="read1"
PASS="getpass" 

CWD=`pwd`

for d in $SUBDIRS; do
 echo Entering directory $d
 cd $d && ./runtests.sh
 cd "$CWD" || exit 1
done


for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
done 

./asprintf foobar  ||  ( echo TESTCASE asprintf exited non-zero 1>&2 ; sleep 5 )
./cycles strncpy ||  ( echo TESTCASE cycles exited non-zero 1>&2 ; sleep 5 )

for p in $STDIN;do
echo "---";echo testing $p;echo "---"
echo foobar | ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5)
done

for p in $PASS;do
 echo "---";echo testing $p;echo "---"
 echo if you are not prompted for input it is broken
 sleep 2
 echo foobar | ./$p || ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5)
done


dietlibc-0.33~cvs20120325/test/select.c010064400000000000000000000003261173363230200143010ustar00#include 
#include 
#include 
#include 

int main() {
  fd_set f;
  struct timeval tv;
  FD_ZERO(&f);
  tv.tv_sec=3; tv.tv_usec=0;
  select(1,&f,0,0,&tv);
  return 0;
}
dietlibc-0.33~cvs20120325/test/sendfile.c010064400000000000000000000003551173363230200146150ustar00// #define _FILE_OFFSET_BITS 64
#include 
#include 

int main() {
  off_t o=0;
  int ret=sendfile(1,0,&o,100);
 
  if (ret<0)
      perror("sendfile()");

  printf("sendfile returned %d\n",ret);

return 0;    
}
dietlibc-0.33~cvs20120325/test/servent.c010064400000000000000000000013101173363230200145020ustar00#include 
#include 
#include 

int main(int argc,char *argv[]) {
#ifdef NEW
  struct servent se,*tmp;
  char buf[1000];
  while (getservent_r(&se,buf,sizeof(buf),&tmp)==0) {
    int i;
    printf("name %s\tport %d\tproto %s\n",se.s_name,ntohs(se.s_port),se.s_proto);
    for (i=0; i<16; ++i) {
      if (!se.s_aliases[i]) break;
      printf("  alias %s\n",se.s_aliases[i]);
    }
  }
#else
  struct servent* se;
  while ((se=getservent())) {
    int i;
    printf("name %s\tport %d\tproto %s\n",se->s_name,ntohs(se->s_port),se->s_proto);
    for (i=0; i<16; ++i) {
      if (!se->s_aliases[i]) break;
      printf("  alias %s\n",se->s_aliases[i]);
    }
  }
#endif
  return 0;
}
dietlibc-0.33~cvs20120325/test/siglist.c010064400000000000000000000002071173363230200144760ustar00#define _GNU_SOURCE
#include 
#include 
#include 

int main() {
  puts(strsignal(SIGPIPE));
  return 0;
}
dietlibc-0.33~cvs20120325/test/speed.c010064400000000000000000000003471173363230200141250ustar00#include 
#include 
#include 
#include 

int main() {
  int i;
  time_t t;
  
  printf("%d\n", time(0));
  for (i=0; i<10000000; ++i)
    t=time(0);

 printf("%d\n", time(0));
 return 0;   
}
dietlibc-0.33~cvs20120325/test/spent.c010064400000000000000000000005701173363230200141540ustar00#include 
#include 

int main(int argc,char *argv[]) {
  struct spwd sp,*tmp;
  char buf[1000];
  while (getspent_r(&sp,buf,sizeof(buf),&tmp)==0) {
    printf("name %s\tpassword %s\n",sp.sp_namp,sp.sp_pwdp);
    printf("  %ld %d %d %d %d %d %d\n",sp.sp_lstchg, sp.sp_min,
	   sp.sp_max, sp.sp_warn, sp.sp_inact, sp.sp_expire, sp.sp_flag);
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/sprintf.c010064400000000000000000000014201173363230200145030ustar00#include 
#include 
#include 

int main() {
  char buf[1000];
  sprintf(buf,"%d",23);
  assert(!strcmp(buf,"23"));
  sprintf(buf,"%d",5);
  assert(!strcmp(buf,"5"));
  sprintf(buf,"%.2f", 0.05);
  assert(!strcmp(buf,"0.05"));
  sprintf(buf,"%f", 9e-6);
  assert(!strcmp(buf,"0.000009"));
  sprintf(buf,"%f", 1e-2);
  assert(!strcmp(buf,"0.010000"));
  sprintf(buf,"%6d",-1);
  assert(!strcmp(buf,"    -1"));
  strcpy(buf,"foo ");
  sprintf(buf+strlen(buf),"%s","bar ");
  strcat(buf,"baz.");
  assert(!strcmp(buf,"foo bar baz."));
  memset(buf,0,100);
  assert(snprintf(buf,1,"x")==1);
  assert(!strcmp(buf,""));
  assert(snprintf(buf,0,"x")==1);
  assert(!strcmp(buf,""));
  assert(sprintf(buf,"%03o",10)==3);
  assert(!strcmp(buf,"012"));
  return 0;
}
dietlibc-0.33~cvs20120325/test/sscanf.c010064400000000000000000000011721173363230200142770ustar00#include 
#include 

int main() {
  char server_version_string[]="SSH-1.99-OpenSSH_2.9p2\n";
  int remote_major, remote_minor;
  char remote_version[1000];
  long a,b,c;
  if (sscanf(server_version_string, "SSH-%d.%d-%[^\n]\n",
	    &remote_major, &remote_minor, remote_version) != 3) return 1;
  if (remote_major!=1 || remote_minor!=99 || strcmp(remote_version,"OpenSSH_2.9p2"))
    return 1;
//  printf("%d.%d.%.100s\n",remote_major,remote_minor,remote_version);
  if (sscanf("000000013637d16600007b21","%8lx%8lx%8lx",&a,&b,&c)!=3) return 1;
  if (a != 1 || b != 0x3637d166 || c !=0x7b21) return 1;
  return 0;
}
dietlibc-0.33~cvs20120325/test/stdarg.c010064400000000000000000000007311173363230200143060ustar00#include 
#include 

static char* res[10];

void fnord(char*x,...) {
  int i;
  va_list v;
  va_start(v,x);
  for (i=0; i<10; ++i) {
    char *tmp=va_arg(v,char*);
    if (!tmp) break;
    res[i]=tmp;
  }
}

int main(int argc,char *argv[]) {
  const char foo[]="foo\n";
  const char bar[]="bar\n";
  fnord("fnord",foo,bar,0);
  if (res[0]==foo && res[1]==bar && res[2]==0) {
    write(1,"ok\n",3);
    return 0;
  }
  write(1,"fail\n",5);
  return 1;
}
dietlibc-0.33~cvs20120325/test/stdio.c010064400000000000000000000002221173363230200141370ustar00#include 

int main() {
  char buf[1000];
  printf("sftp> ");
  fgets(buf,sizeof buf,stdin);
  fwrite("foo\n",2,2,stdout);
  return 0;
}
dietlibc-0.33~cvs20120325/test/stdio/.cvsignore010064400000000000000000000002261173363231000157760ustar00tst-fdopen
tst-ferror
tst-fileno
tst-fphex
tst-fseek
tst-printf
tst-sprintf
tst-sscanf
tst-tmpnam
tst-unbputc
tst-ungetc
tstdiomisc
tstgetln
tstscanf
dietlibc-0.33~cvs20120325/test/stdio/Makefile010064400000000000000000000006441173363231000154420ustar00DIET=diet
CC=gcc
CFLAGS=-Wall -nostdinc
LCOMPAT=-lcompat

all: stdiotest tstgetln

TESTPROGRAMS=tst-ferror tstdiomisc tst-fdopen tst-fileno \
tst-fphex tst-fseek tst-printf tstscanf tst-sprintf tst-sscanf tst-tmpnam \
tst-unbputc tst-ungetc

stdiotest: $(TESTPROGRAMS)

%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

tstgetln: tstgetln.c
	$(DIET) $(CC) $(CFLAGS) $^ $(LCOMPAT) -o $@

clean:
	rm -f $(TESTPROGRAMS) tstgetln


dietlibc-0.33~cvs20120325/test/stdio/runtests.sh010064400000000000000000000010351173363231000162200ustar00#!/bin/sh

TESTPROGRAMS="tstdiomisc tst-fdopen tst-fileno tst-fphex tst-fseek tst-printf tst-sprintf tst-sscanf tst-tmpnam tst-unbputc tst-ungetc"

for f in "tstgetln tst-ferror tstscanf";do
echo "
25 54.32E-1 thompson
56789 0123 56a72
2 quarts of oil
-12.8degrees Celsius
lots of luck
10.0LBS      of       fertilizer
100ergs of energy" | ./$f ||  ( echo TESTCASE $f exited non-zero 1>&2 ; sleep 5 )
done

for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
done 

dietlibc-0.33~cvs20120325/test/stdio/tst-fdopen.c010064400000000000000000000016541173363231000162330ustar00/* Test for fdopen bugs.  */

#include 
#include 
#include 

#undef assert
#define assert(x) \
  if (!(x)) \
    { \
      fputs ("test failed: " #x "\n", stderr); \
      retval = 1; \
      goto the_end; \
    }

char buffer[256];

int
main (int argc, char *argv[])
{
  char *name;
  FILE *fp = NULL;
  int retval = 0;
  int fd;

  name = tmpnam (NULL);
  fp = fopen (name, "w");
  assert (fp != NULL)
  fputs ("foobar and baz", fp);
  fclose (fp);
  fp = NULL;

  fd = open (name, O_RDONLY);
  assert (fd != -1);
  assert (lseek (fd, 5, SEEK_SET) == 5);
  /* The file position indicator associated with the new stream is set to
     the position indicated by the file offset associated with the file
     descriptor.  */
  fp = fdopen (fd, "r");
  assert (fp != NULL);
  assert (getc (fp) == 'r');
  assert (getc (fp) == ' ');

the_end:
  if (fp != NULL)
    fclose (fp);
  unlink (name);

  return retval;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-ferror.c010064400000000000000000000015771173363231000162630ustar00#include 

int
main (int argc, char *argv[])
{
  char buf[100];
  int result = 0;

  if (ferror (stdin) != 0)
    {
      fputs ("error bit set for stdin at startup\n", stdout);
      result = 1;
    }
  if (fgets (buf, sizeof buf, stdin) != buf)
    {
      fputs ("fgets with existing input has problem\n", stdout);
      result = 1;
    }
  if (ferror (stdin) != 0)
    {
      fputs ("error bit set for stdin after setup\n", stdout);
      result = 1;
    }
  if (fputc ('a', stdin) != EOF)
    {
      fputs ("fputc to stdin does not terminate with an error\n", stdout);
      result = 1;
    }
  if (ferror (stdin) == 0)
    {
      fputs ("error bit not set for stdin after fputc\n", stdout);
      result = 1;
    }
  clearerr (stdin);
  if (ferror (stdin) != 0)
    {
      fputs ("error bit set for stdin after clearerr\n", stdout);
      result = 1;
    }
  return result;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-fileno.c010064400000000000000000000023771173363231000162370ustar00/* Copyright (C) 1994, 1997, 2000 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 

static int
check (const char *name, FILE *stream, int fd)
{
  int sfd = fileno (stream);
  printf ("(fileno (%s) = %d) %c= %d\n", name, sfd,
	  sfd == fd ? '=' : '!', fd);
  return sfd != fd;
}

int
main (void)
{
  return (check ("stdin", stdin, STDIN_FILENO) ||
	  check ("stdout", stdout, STDOUT_FILENO) ||
	  check ("stderr", stderr, STDERR_FILENO));
}
dietlibc-0.33~cvs20120325/test/stdio/tst-fphex.c010064400000000000000000000025761173363231000160760ustar00/* Test program for %a printf formats.  */

#include 
#include 

struct testcase
{
  double value;
  const char *fmt;
  const char *expect;
};

static const struct testcase testcases[] =
  {
    { 0x0.0030p+0, "%a",	"0x1.8p-11" },
    { 0x0.0040p+0, "%a",	"0x1p-10" },
    { 0x0.0030p+0, "%040a",	"0x00000000000000000000000000000001.8p-11" },
    { 0x0.0040p+0, "%040a",	"0x0000000000000000000000000000000001p-10" },
    { 0x0.0040p+0, "%40a",	"                                 0x1p-10" },
    { 0x0.0040p+0, "%#40a",	"                                0x1.p-10" },
    { 0x0.0040p+0, "%-40a",	"0x1p-10                                 " },
    { 0x0.0040p+0, "%#-40a",	"0x1.p-10                                " },
    { 0x0.0030p+0, "%040e",	"00000000000000000000000000007.324219e-04" },
    { 0x0.0040p+0, "%040e",	"00000000000000000000000000009.765625e-04" },
  };


int main (int argc, char **argv) {
  const struct testcase *t;
  int result = 0;

  for (t = testcases;
       t < &testcases[sizeof testcases / sizeof testcases[0]];
       ++t)
    {
      char buf[1024];
      int n = snprintf (buf, sizeof buf, t->fmt, t->value);
      if (n != strlen (t->expect) || strcmp (buf, t->expect) != 0)
	{
	  printf ("%s\tExpected \"%s\" (%zu)\n\tGot      \"%s\" (%d, %zu)\n",
		  t->fmt, t->expect, strlen (t->expect), buf, n, strlen (buf));
	  result = 1;
	}
    }

  return result;
}

dietlibc-0.33~cvs20120325/test/stdio/tst-fseek.c010064400000000000000000000305121173363231000160500ustar00/* Tests of fseek and fseeko.
   Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper , 2000.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#define _FILE_OFFSET_BITS 64
#define _GNU_SOURCE
#include 
#include 
#include 
#include 
#include 
#include 
#include 


int
main (void)
{
  const char *tmpdir;
  char *fname;
  int fd;
  FILE *fp;
  const char outstr[] = "hello world!\n";
  char strbuf[sizeof outstr];
  char buf[200];
  struct stat st1;
  struct stat st2;
  int result = 0;

  tmpdir = getenv ("TMPDIR");
  if (tmpdir == NULL || tmpdir[0] == '\0')
    tmpdir = "/tmp";

  asprintf (&fname, "%s/tst-fseek.XXXXXX", tmpdir);
  if (fname == NULL) {
    fprintf(stderr, "cannot generate name for temporary file: %s\n",strerror(errno));
    return 1;
  }  

  /* Create a temporary file.   */
  fd = mkstemp (fname);
  if (fd == -1) {
    fprintf(stderr, "cannot open temporary file: %s\n",strerror(errno));
    return 1;
  }  

  fp = fdopen (fd, "w+");
  if (fp == NULL) {
    fprintf(stderr, "cannot get FILE for temporary file: %s\n",strerror(errno));
    return 1;
  }
  setbuffer (fp, strbuf, sizeof (outstr) -1);

  if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: write error\n", __LINE__);
      result = 1;
      goto out;
    }

  /* The EOF flag must be reset.  */
  if (fgetc (fp) != EOF)
    {
      printf ("%d: managed to read at end of file\n", __LINE__);
      result = 1;
    }
  else if (! feof (fp))
    {
      printf ("%d: EOF flag not set\n", __LINE__);
      result = 1;
    }
  if (fseek (fp, 0, SEEK_CUR) != 0)
    {
      printf ("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__);
      result = 1;
    }
  else if (feof (fp))
    {
      printf ("%d: fseek() didn't reset EOF flag\n", __LINE__);
      result = 1;
    }

  /* Do the same for fseeko().  */
    if (fgetc (fp) != EOF)
    {
      printf ("%d: managed to read at end of file\n", __LINE__);
      result = 1;
    }
  else if (! feof (fp))
    {
      printf ("%d: EOF flag not set\n", __LINE__);
      result = 1;
    }
  if (fseeko (fp, 0, SEEK_CUR) != 0)
    {
      printf ("%d: fseek(fp, 0, SEEK_CUR) failed\n", __LINE__);
      result = 1;
    }
  else if (feof (fp))
    {
      printf ("%d: fseek() didn't reset EOF flag\n", __LINE__);
      result = 1;
    }

  /* Go back to the beginning of the file: absolute.  */
  if (fseek (fp, 0, SEEK_SET) != 0)
    {
      printf ("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__);
      result = 1;
    }
  else if (fflush (fp) != 0)
    {
      printf ("%d: fflush() failed\n", __LINE__);
      result = 1;
    }
  else if (lseek (fd, 0, SEEK_CUR) != 0)
    {
      printf ("%d: lseek() returned different position\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: fread() failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0)
    {
      printf ("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__);
      result = 1;
    }

  /* Now with fseeko.  */
  if (fseeko (fp, 0, SEEK_SET) != 0)
    {
      printf ("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__);
      result = 1;
    }
  else if (fflush (fp) != 0)
    {
      printf ("%d: fflush() failed\n", __LINE__);
      result = 1;
    }
  else if (lseek (fd, 0, SEEK_CUR) != 0)
    {
      printf ("%d: lseek() returned different position\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: fread() failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0)
    {
      printf ("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__);
      result = 1;
    }

  /* Go back to the beginning of the file: relative.  */
  if (fseek (fp, -((int) sizeof (outstr) - 1), SEEK_CUR) != 0)
    {
      printf ("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__);
      result = 1;
    }
  else if (fflush (fp) != 0)
    {
      printf ("%d: fflush() failed\n", __LINE__);
      result = 1;
    }
  else if (lseek (fd, 0, SEEK_CUR) != 0)
    {
      printf ("%d: lseek() returned different position\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: fread() failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0)
    {
      printf ("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__);
      result = 1;
    }

  /* Now with fseeko.  */
  if (fseeko (fp, -((int) sizeof (outstr) - 1), SEEK_CUR) != 0)
    {
      printf ("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__);
      result = 1;
    }
  else if (fflush (fp) != 0)
    {
      printf ("%d: fflush() failed\n", __LINE__);
      result = 1;
    }
  else if (lseek (fd, 0, SEEK_CUR) != 0)
    {
      printf ("%d: lseek() returned different position\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: fread() failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0)
    {
      printf ("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__);
      result = 1;
    }

  /* Go back to the beginning of the file: from the end.  */
  if (fseek (fp, -((int) sizeof (outstr) - 1), SEEK_END) != 0)
    {
      printf ("%d: fseek(fp, 0, SEEK_SET) failed\n", __LINE__);
      result = 1;
    }
  else if (fflush (fp) != 0)
    {
      printf ("%d: fflush() failed\n", __LINE__);
      result = 1;
    }
  else if (lseek (fd, 0, SEEK_CUR) != 0)
    {
      printf ("%d: lseek() returned different position\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: fread() failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0)
    {
      printf ("%d: content after fseek(,,SEEK_SET) wrong\n", __LINE__);
      result = 1;
    }

  /* Now with fseeko.  */
  if (fseeko (fp, -((int) sizeof (outstr) - 1), SEEK_END) != 0)
    {
      printf ("%d: fseeko(fp, 0, SEEK_SET) failed\n", __LINE__);
      result = 1;
    }
  else if (fflush (fp) != 0)
    {
      printf ("%d: fflush() failed\n", __LINE__);
      result = 1;
    }
  else if (lseek (fd, 0, SEEK_CUR) != 0)
    {
      printf ("%d: lseek() returned different position\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: fread() failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0)
    {
      printf ("%d: content after fseeko(,,SEEK_SET) wrong\n", __LINE__);
      result = 1;
    }

  if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: write error 2\n", __LINE__);
      result = 1;
      goto out;
    }

  if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: write error 3\n", __LINE__);
      result = 1;
      goto out;
    }

  if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: write error 4\n", __LINE__);
      result = 1;
      goto out;
    }

  if (fwrite (outstr, sizeof (outstr) - 1, 1, fp) != 1)
    {
      printf ("%d: write error 5\n", __LINE__);
      result = 1;
      goto out;
    }

  if (fputc ('1', fp) == EOF || fputc ('2', fp) == EOF)
    {
      printf ("%d: cannot add characters at the end\n", __LINE__);
      result = 1;
      goto out;
    }

  /* Check the access time.  */
  if (fstat (fd, &st1) < 0)
    {
      printf ("%d: fstat() before fseeko() failed\n\n", __LINE__);
      result = 1;
    }
  else
    {
      sleep (1);

      if (fseek (fp, -(2 + 2 * (sizeof (outstr) - 1)), SEEK_CUR) != 0)
	{
	  printf ("%d: fseek() after write characters failed\n", __LINE__);
	  result = 1;
	  goto out;
	}
      else
	{

	  time_t t;
	  /* Make sure the timestamp actually can be different.  */
	  sleep (1);
	  t = time (NULL);

	  if (fstat (fd, &st2) < 0)
	    {
	      printf ("%d: fstat() after fseeko() failed\n\n", __LINE__);
	      result = 1;
	    }
	  if (st1.st_ctime >= t)
	    {
	      printf ("%d: st_ctime not updated\n", __LINE__);
	      result = 1;
	    }
	  if (st1.st_mtime >= t)
	    {
	      printf ("%d: st_mtime not updated\n", __LINE__);
	      result = 1;
	    }
	  if (st1.st_ctime >= st2.st_ctime)
	    {
	      printf ("%d: st_ctime not changed\n", __LINE__);
	      result = 1;
	    }
	  if (st1.st_mtime >= st2.st_mtime)
	    {
	      printf ("%d: st_mtime not changed\n", __LINE__);
	      result = 1;
	    }
	}
    }

  if (fread (buf, 1, 2 + 2 * (sizeof (outstr) - 1), fp)
      != 2 + 2 * (sizeof (outstr) - 1))
    {
      printf ("%d: reading 2 records plus bits failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0
	   || memcmp (&buf[sizeof (outstr) - 1], outstr,
		      sizeof (outstr) - 1) != 0
	   || buf[2 * (sizeof (outstr) - 1)] != '1'
	   || buf[2 * (sizeof (outstr) - 1) + 1] != '2')
    {
      printf ("%d: reading records failed\n", __LINE__);
      result = 1;
    }
  else if (ungetc ('9', fp) == EOF)
    {
      printf ("%d: ungetc() failed\n", __LINE__);
      result = 1;
    }
  else if (fseek (fp, -(2 + 2 * (sizeof (outstr) - 1)), SEEK_END) != 0)
    {
      printf ("%d: fseek after ungetc failed\n", __LINE__);
      result = 1;
    }
  else if (fread (buf, 1, 2 + 2 * (sizeof (outstr) - 1), fp)
      != 2 + 2 * (sizeof (outstr) - 1))
    {
      printf ("%d: reading 2 records plus bits failed\n", __LINE__);
      result = 1;
    }
  else if (memcmp (buf, outstr, sizeof (outstr) - 1) != 0
	   || memcmp (&buf[sizeof (outstr) - 1], outstr,
		      sizeof (outstr) - 1) != 0
	   || buf[2 * (sizeof (outstr) - 1)] != '1')
    {
      printf ("%d: reading records for the second time failed\n", __LINE__);
      result = 1;
    }
  else if (buf[2 * (sizeof (outstr) - 1) + 1] == '9')
    {
      printf ("%d: unget character not ignored\n", __LINE__);
      result = 1;
    }
  else if (buf[2 * (sizeof (outstr) - 1) + 1] != '2')
    {
      printf ("%d: unget somehow changed character\n", __LINE__);
      result = 1;
    }

  fclose (fp);

  fp = fopen (fname, "r");
  if (fp == NULL)
    {
      printf ("%d: fopen() failed\n\n", __LINE__);
      result = 1;
    }
  else if (fstat (fileno (fp), &st1) < 0)
    {
      printf ("%d: fstat() before fseeko() failed\n\n", __LINE__);
      result = 1;
    }
  else if (fseeko (fp, 0, SEEK_END) != 0)
    {
      printf ("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__);
      result = 1;
    }
  else if (ftello (fp) != st1.st_size)
    {
      printf ("%d: fstat st_size %zd ftello %zd\n", __LINE__,
	      (size_t) st1.st_size, (size_t) ftello (fp));
      result = 1;
    }
  else
    printf ("%d: SEEK_END works\n", __LINE__);
  if (fp != NULL)
    fclose (fp);

  fp = fopen (fname, "r");
  if (fp == NULL)
    {
      printf ("%d: fopen() failed\n\n", __LINE__);
      result = 1;
    }
  else if (fstat (fileno (fp), &st1) < 0)
    {
      printf ("%d: fstat() before fgetc() failed\n\n", __LINE__);
      result = 1;
    }
  else if (fgetc (fp) == EOF)
    {
      printf ("%d: fgetc() before fseeko() failed\n\n", __LINE__);
      result = 1;
    }
  else if (fseeko (fp, 0, SEEK_END) != 0)
    {
      printf ("%d: fseeko(fp, 0, SEEK_END) failed\n", __LINE__);
      result = 1;
    }
  else if (ftello (fp) != st1.st_size)
    {
      printf ("%d: fstat st_size %zd ftello %zd\n", __LINE__,
	      (size_t) st1.st_size, (size_t) ftello (fp));
      result = 1;
    }
  else
    printf ("%d: SEEK_END works\n", __LINE__);
  if (fp != NULL)
    fclose (fp);

 out:
  unlink (fname);

  return result;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-printf.c010064400000000000000000000236631173363231000162660ustar00/* Copyright (C) 1991,92,93,95,96,97,98,99, 2000, 2002
     Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 
#include 

#include 

static void rfg1 (void);
static void rfg2 (void);
static void rfg3 (void);


static void
fmtchk (const char *fmt)
{
  (void) fputs(fmt, stdout);
  (void) printf(":\t`");
  (void) printf(fmt, 0x12);
  (void) printf("'\n");
}

static void
fmtst1chk (const char *fmt)
{
  (void) fputs(fmt, stdout);
  (void) printf(":\t`");
  (void) printf(fmt, 4, 0x12);
  (void) printf("'\n");
}

static void
fmtst2chk (const char *fmt)
{
  (void) fputs(fmt, stdout);
  (void) printf(":\t`");
  (void) printf(fmt, 4, 4, 0x12);
  (void) printf("'\n");
}

/* This page is covered by the following copyright: */

/* (C) Copyright C E Chew
 *
 * Feel free to copy, use and distribute this software provided:
 *
 *	1. you do not pretend that you wrote it
 *	2. you leave this copyright notice intact.
 */

/*
 * Extracted from exercise.c for glibc-1.05 bug report by Bruce Evans.
 */

#define DEC -123
#define INT 255
#define UNS (~0)

/* Formatted Output Test
 *
 * This exercises the output formatting code.
 */

static void
fp_test (void)
{
  int i, j, k, l;
  char buf[7];
  char *prefix = buf;
  char tp[20];

  puts("\nFormatted output test");
  printf("prefix  6d      6o      6x      6X      6u\n");
  strcpy(prefix, "%");
  for (i = 0; i < 2; i++) {
    for (j = 0; j < 2; j++) {
      for (k = 0; k < 2; k++) {
	for (l = 0; l < 2; l++) {
	  strcpy(prefix, "%");
	  if (i == 0) strcat(prefix, "-");
	  if (j == 0) strcat(prefix, "+");
	  if (k == 0) strcat(prefix, "#");
	  if (l == 0) strcat(prefix, "0");
	  printf("%5s |", prefix);
	  strcpy(tp, prefix);
	  strcat(tp, "6d |");
	  printf(tp, DEC);
	  strcpy(tp, prefix);
	  strcat(tp, "6o |");
	  printf(tp, INT);
	  strcpy(tp, prefix);
	  strcat(tp, "6x |");
	  printf(tp, INT);
	  strcpy(tp, prefix);
	  strcat(tp, "6X |");
	  printf(tp, INT);
	  strcpy(tp, prefix);
	  strcat(tp, "6u |");
	  printf(tp, UNS);
	  printf("\n");
	}
      }
    }
  }
  printf("%10s\n", (char *) NULL);
  printf("%-10s\n", (char *) NULL);
}

int
main (int argc, char *argv[])
{
  static char shortstr[] = "Hi, Z.";
  static char longstr[] = "Good morning, Doctor Chandra.  This is Hal.  \
I am ready for my first lesson today.";
  int result = 0;

  fmtchk("%.4x");
  fmtchk("%04x");
  fmtchk("%4.4x");
  fmtchk("%04.4x");
  fmtchk("%4.3x");
  fmtchk("%04.3x");

  fmtst1chk("%.*x");
  fmtst1chk("%0*x");
  fmtst2chk("%*.*x");
  fmtst2chk("%0*.*x");

  printf("bad format:\t\"%b\"\n");
  printf("nil pointer (padded):\t\"%10p\"\n", (void *) NULL);

  printf("decimal negative:\t\"%d\"\n", -2345);
  printf("octal negative:\t\"%o\"\n", -2345);
  printf("hex negative:\t\"%x\"\n", -2345);
  printf("long decimal number:\t\"%ld\"\n", -123456L);
  printf("long octal negative:\t\"%lo\"\n", -2345L);
  printf("long unsigned decimal number:\t\"%lu\"\n", -123456L);
  printf("zero-padded LDN:\t\"%010ld\"\n", -123456L);
  printf("left-adjusted ZLDN:\t\"%-010ld\"\n", -123456L);
  printf("space-padded LDN:\t\"%10ld\"\n", -123456L);
  printf("left-adjusted SLDN:\t\"%-10ld\"\n", -123456L);

  printf("zero-padded string:\t\"%010s\"\n", shortstr);
  printf("left-adjusted Z string:\t\"%-010s\"\n", shortstr);
  printf("space-padded string:\t\"%10s\"\n", shortstr);
  printf("left-adjusted S string:\t\"%-10s\"\n", shortstr);
  printf("null string:\t\"%s\"\n", (char *)NULL);
  printf("limited string:\t\"%.22s\"\n", longstr);

  printf("e-style >= 1:\t\"%e\"\n", 12.34);
  printf("e-style >= .1:\t\"%e\"\n", 0.1234);
  printf("e-style < .1:\t\"%e\"\n", 0.001234);
  printf("e-style big:\t\"%.60e\"\n", 1e20);
  printf ("e-style == .1:\t\"%e\"\n", 0.1);
  printf("f-style >= 1:\t\"%f\"\n", 12.34);
  printf("f-style >= .1:\t\"%f\"\n", 0.1234);
  printf("f-style < .1:\t\"%f\"\n", 0.001234);
  printf("g-style >= 1:\t\"%g\"\n", 12.34);
  printf("g-style >= .1:\t\"%g\"\n", 0.1234);
  printf("g-style < .1:\t\"%g\"\n", 0.001234);
  printf("g-style big:\t\"%.60g\"\n", 1e20);

  printf (" %6.5f\n", .099999999860301614);
  printf (" %6.5f\n", .1);
  printf ("x%5.4fx\n", .5);

  printf ("%#03x\n", 1);

  printf ("something really insane: %.10000f\n", 1.0);

  {
    double d = FLT_MIN;
    int niter = 17;

    while (niter-- != 0)
      printf ("%.17e\n", d / 2);
    fflush (stdout);
  }

  printf ("%15.5e\n", 4.9406564584124654e-324);

#define FORMAT "|%12.4f|%12.4e|%12.4g|\n"
  printf (FORMAT, 0.0, 0.0, 0.0);
  printf (FORMAT, 1.0, 1.0, 1.0);
  printf (FORMAT, -1.0, -1.0, -1.0);
  printf (FORMAT, 100.0, 100.0, 100.0);
  printf (FORMAT, 1000.0, 1000.0, 1000.0);
  printf (FORMAT, 10000.0, 10000.0, 10000.0);
  printf (FORMAT, 12345.0, 12345.0, 12345.0);
  printf (FORMAT, 100000.0, 100000.0, 100000.0);
  printf (FORMAT, 123456.0, 123456.0, 123456.0);
#undef	FORMAT

  {
    char buf[20];
    char buf2[512];
    printf ("snprintf (\"%%30s\", \"foo\") == %d, \"%.*s\"\n",
	    snprintf (buf, sizeof (buf), "%30s", "foo"), (int) sizeof (buf),
	    buf);
    printf ("snprintf (\"%%.999999u\", 10) == %d\n",
	    snprintf(buf2, sizeof(buf2), "%.999999u", 10));
  }

  fp_test ();

  printf ("%e should be 1.234568e+06\n", 1234567.8);
  printf ("%f should be 1234567.800000\n", 1234567.8);
  printf ("%g should be 1.23457e+06\n", 1234567.8);
  printf ("%g should be 123.456\n", 123.456);
  printf ("%g should be 1e+06\n", 1000000.0);
  printf ("%g should be 10\n", 10.0);
  printf ("%g should be 0.02\n", 0.02);

#if 0
  /* This test rather checks the way the compiler handles constant
     folding.  gcc behavior wrt to this changed in 3.2 so it is not a
     portable test.  */
  {
    double x=1.0;
    printf("%.17f\n",(1.0/x/10.0+1.0)*x-x);
  }
#endif

  {
    char buf[200];

    sprintf(buf,"%*s%*s%*s",-1,"one",-20,"two",-30,"three");

    result |= strcmp (buf,
		      "onetwo                 three                         ");

    puts (result != 0 ? "Test failed!" : "Test ok.");
  }

  {
    char buf[200];

    sprintf (buf, "%07Lo", 040000000000ll);
    printf ("sprintf (buf, \"%%07Lo\", 040000000000ll) = %s", buf);

    if (strcmp (buf, "40000000000") != 0)
      {
	result = 1;
	fputs ("\tFAILED", stdout);
      }
    puts ("");
  }

  printf ("printf (\"%%hhu\", %u) = %hhu\n", UCHAR_MAX + 2, UCHAR_MAX + 2);
  printf ("printf (\"%%hu\", %u) = %hu\n", USHRT_MAX + 2, USHRT_MAX + 2);

  puts ("--- Should be no further output. ---");
  rfg1 ();
  rfg2 ();
  rfg3 ();

  {
    char bytes[7];
    char buf[20];

    memset (bytes, '\xff', sizeof bytes);
    sprintf (buf, "foo%hhn\n", &bytes[3]);
    if (bytes[0] != '\xff' || bytes[1] != '\xff' || bytes[2] != '\xff'
	|| bytes[4] != '\xff' || bytes[5] != '\xff' || bytes[6] != '\xff')
      {
	puts ("%hhn overwrite more bytes");
	result = 1;
      }
    if (bytes[3] != 3)
      {
	puts ("%hhn wrote incorrect value");
	result = 1;
      }
  }

  return result != 0;
}

static void
rfg1 (void)
{
  char buf[100];

  sprintf (buf, "%5.s", "xyz");
  if (strcmp (buf, "     ") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "     ");
  sprintf (buf, "%5.f", 33.3);
  if (strcmp (buf, "   33") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "   33");
  sprintf (buf, "%8.e", 33.3e7);
  if (strcmp (buf, "   3e+08") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "   3e+08");
  sprintf (buf, "%8.E", 33.3e7);
  if (strcmp (buf, "   3E+08") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "   3E+08");
  sprintf (buf, "%.g", 33.3);
  if (strcmp (buf, "3e+01") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "3e+01");
  sprintf (buf, "%.G", 33.3);
  if (strcmp (buf, "3E+01") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "3E+01");
}

static void
rfg2 (void)
{
  int prec;
  char buf[100];

  prec = 0;
  sprintf (buf, "%.*g", prec, 3.3);
  if (strcmp (buf, "3") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "3");
  prec = 0;
  sprintf (buf, "%.*G", prec, 3.3);
  if (strcmp (buf, "3") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "3");
  prec = 0;
  sprintf (buf, "%7.*G", prec, 3.33);
  if (strcmp (buf, "      3") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "      3");
  prec = 3;
  sprintf (buf, "%04.*o", prec, 33);
  if (strcmp (buf, " 041") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, " 041");
  prec = 7;
  sprintf (buf, "%09.*u", prec, 33);
  if (strcmp (buf, "  0000033") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, "  0000033");
  prec = 3;
  sprintf (buf, "%04.*x", prec, 33);
  if (strcmp (buf, " 021") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, " 021");
  prec = 3;
  sprintf (buf, "%04.*X", prec, 33);
  if (strcmp (buf, " 021") != 0)
    printf ("got: '%s', expected: '%s'\n", buf, " 021");
}

static void
rfg3 (void)
{
  char buf[100];
  double g = 5.0000001;
  unsigned long l = 1234567890;
  double d = 321.7654321;
  const char s[] = "test-string";
  int i = 12345;
  int h = 1234;

  sprintf (buf,
	   "%1$*5$d %2$*6$hi %3$*7$lo %4$*8$f %9$*12$e %10$*13$g %11$*14$s",
	   i, h, l, d, 8, 5, 14, 14, d, g, s, 14, 3, 14);
  if (strcmp (buf,
	      "   12345  1234    11145401322     321.765432   3.217654e+02   5    test-string") != 0)
    printf ("got: '%s', expected: '%s'\n", buf,
	    "   12345  1234    11145401322     321.765432   3.217654e+02   5    test-string");
}
dietlibc-0.33~cvs20120325/test/stdio/tst-printfsz.c010064400000000000000000000031331173363231000166310ustar00/* Based on code by Larry McVoy .  */
#include 
#include 
#include 

#define V       12345678.12345678


int
main (int argc, char *argv[])
{
  char buf[1024];
  int result = 0;

  /* Register the printf handlers.  */
  register_printf_function ('b', printf_size, printf_size_info);
  register_printf_function ('B', printf_size, printf_size_info);


  sprintf (buf, "%g %b %B %.0b %.0B %.1b %.1B %8.0b %08.0B",
	   V, 1025., V, V, V, V, V, V, V, V);
  fputs (buf, stdout);
  if (strcmp (buf, "\
1.23457e+07 1.001k 12.346M 12m 12M 11.8m 12.3M      12m 0000012M"))
    {
      result = 1;
      fputs (" -> WRONG\n", stdout);
    }
  else
    fputs (" -> OK\n", stdout);

  sprintf (buf, "%b|%B|%-20.2b|%-10.0b|%-10.8b|%-10.2B|",
	   V, V, V, V, V, V, V, V, V, V, V);
  fputs (buf, stdout);
  if (strcmp (buf, "\
11.774m|12.346M|11.77m              |12m       |11.77375614m|12.35M    |"))
    {
      result = 1;
      fputs (" -> WRONG\n", stdout);
    }
  else
    fputs (" -> OK\n", stdout);

  sprintf (buf, "%#.0B %*.0b %10.*b %*.*B %10.2B",
	   V, 2, V, 2, V, 10, 2, V, V);
  fputs (buf, stdout);
  if (strcmp (buf, "12.M 12m     11.77m     12.35M     12.35M"))
    {
      result = 1;
      fputs (" -> WRONG\n", stdout);
    }
  else
    fputs (" -> OK\n", stdout);

  sprintf (buf, "%6B %6.1B %b %B %b %B",
	   V, V, 1000.0, 1000.0, 1024.0, 1024.0);
  fputs (buf, stdout);
  if (strcmp (buf, "12.346M  12.3M 1000.000  1.000K 1.000k 1.024K"))
    {
      result = 1;
      fputs (" -> WRONG\n", stdout);
    }
  else
    fputs (" -> OK\n", stdout);

  return result;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-sprintf.c010064400000000000000000000004411173363231000164360ustar00#include 
#include 


int
main (void)
{
  char buf[100];
  int result = 0;

  if (sprintf (buf, "%.0ls", L"foo") != 0
      || strlen (buf) != 0)
    {
      puts ("sprintf (buf, \"%.0ls\", L\"foo\") produced some output\n");
      result = 1;
    }

  return result;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-sscanf.c010064400000000000000000000067011173363231000162330ustar00/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Jakub Jelinek , 2000.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 

const char *str_double[] =
{
  "-.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01",
  "0.10000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01",
  "-1234567E0198765432E0912345678901987654321091234567890198765432109",
  "-0.1000E+020.20000E+020.25000E+010.40000E+010.50000E+010.12500E+01"
};

const double val_double[] =
{
  -.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01,
  0.10000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01,
  -1234567E01, 98765432E09, 12345678901.0, 98765432109.0, 12345678901.0,
    98765432109.0,
  -0.1000E+02, 0.20000E+02, 0.25000E+01, 0.40000E+01, 0.50000E+01, 0.12500E+01
};

const char *str_long[] =
{
  "-12345678987654321123456789987654321123456789987654321",
  "-12345678987654321123456789987654321123456789987654321",
  "-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321",
  "-12,345,678987,654,321123,456,789987,654,321123,456,789987,654,321"
};

const char *fmt_long[] =
{
  "%9ld%9ld%9ld%9ld%9ld%9ld",
  "%I9ld%I9ld%I9ld%I9ld%I9ld%I9ld",
  "%'11ld%'11ld%'11ld%'11ld%'11ld%'11ld",
  "%I'11ld%I'11ld%I'11ld%I'11ld%I'11ld%I'11ld"
};

const long int val_long[] =
{
  -12345678, 987654321, 123456789, 987654321, 123456789, 987654321
};

int
main (void)
{
  double d[6];
  long l[6];
  int i, j;
  int tst_locale;
  int result = 0;

  tst_locale = 1;
  if (tst_locale)
    if (setlocale (LC_ALL, "en_US.ISO-8859-1") == NULL)
      {
	puts ("Failed to set en_US locale, skipping locale related tests");
	tst_locale = 0;
      }

  for (i = 0; i < 4; ++i)
    {
      if (sscanf (str_double[i], "%11lf%11lf%11lf%11lf%11lf%11lf",
		  &d[0], &d[1], &d[2], &d[3], &d[4], &d[5]) != 6)
	{
	  printf ("Double sscanf test %d wrong number of "
		  "assigned inputs\n", i);
	  result = 1;
	}
      else
	for (j = 0; j < 6; ++j)
	  if (d[j] != val_double[6 * i + j])
	    {
	      printf ("Double sscanf test %d failed (%g instead of %g)\n",
		      i, d[j], val_double[6 * i + j]);
	      result = 1;
	      break;
	    }
    }

  for (i = 0; i < 4; ++i)
    {
      if (sscanf (str_long[i], fmt_long[i],
		  &l[0], &l[1], &l[2], &l[3], &l[4], &l[5]) != 6)
	{
	  printf ("Integer sscanf test %d wrong number of "
		  "assigned inputs\n", i);
	  result = 1;
	}
      else
	for (j = 0; j < 6; ++j)
	  if (l[j] != val_long[j])
	    {
	      printf ("Integer sscanf test %d failed (%ld instead %ld)\n",
		      i, l[j], val_long[j]);
	      result = 1;
	      break;
	    }

      if (! tst_locale)
	break;
    }

  return result;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-tmpnam.c010064400000000000000000000030171173363231000162470ustar00/* Copyright (C) 1998 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 

int
main (void)
{
  const char *name;
  int retval = 0;

  /* Set TMPDIR to a value other than the traditional /tmp.  */
  setenv ("TMPDIR", "/usr", 1);

  name = tmpnam (NULL);

  printf ("name = %s\n", name);

  /* Make sure the name is not based on the value in TMPDIR.  */
  if (strncmp (name, "/usr", 4) == 0)
    {
      puts ("error: `tmpnam' used TMPDIR value");
      retval = 1;
    }

  /* Test that it is in the directory denoted by P_tmpdir.  */
  if (strncmp (name, P_tmpdir, sizeof (P_tmpdir) - 1) != 0)
    {
      puts ("error: `tmpnam' return value not in P_tmpdir directory");
      retval = 1;
    }

  return retval;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-unbputc.c010064400000000000000000000001421173363231000164270ustar00#include 


int
main (void)
{
  putc ('1', stderr);
  putc ('2', stderr);

  return 0;
}
dietlibc-0.33~cvs20120325/test/stdio/tst-ungetc.c010064400000000000000000000023211173363231000162350ustar00/* Test for ungetc bugs.  */

#include 
#include 

#undef assert
#define assert(x) \
  if (!(x)) \
    { \
      fputs ("test failed: " #x "\n", stderr); \
      retval = 1; \
      goto the_end; \
    }

int
main (int argc, char *argv[])
{
  char *name;
  FILE *fp = NULL;
  int retval = 0;
  int c;
  char buffer[64];

  name = tmpnam (NULL);
  fp = fopen (name, "w");
  assert (fp != NULL)
  fputs ("bla", fp);
  fclose (fp);
  fp = NULL;

  fp = fopen (name, "r");
  assert (fp != NULL);
  assert (ungetc ('z', fp) == 'z');
  assert (getc (fp) == 'z');
  assert (getc (fp) == 'b');
  assert (getc (fp) == 'l');
  assert (ungetc ('m', fp) == 'm');
  assert (getc (fp) == 'm');
  assert ((c = getc (fp)) == 'a');
  assert (getc (fp) == EOF);
  assert (ungetc (c, fp) == c);
  assert (feof (fp) == 0);
  assert (getc (fp) == c);
  assert (getc (fp) == EOF);
  fclose (fp);
  fp = NULL;

  fp = fopen (name, "r");
  assert (fp != NULL);
  assert (getc (fp) == 'b');
  assert (getc (fp) == 'l');
  assert (ungetc ('b', fp) == 'b');
  assert (fread (buffer, 1, 64, fp) == 2);
  assert (buffer[0] == 'b');
  assert (buffer[1] == 'a');

the_end:
  if (fp != NULL)
    fclose (fp);
  unlink (name);

  return retval;
}
dietlibc-0.33~cvs20120325/test/stdio/tstdiomisc.c010064400000000000000000000041531173363231000163270ustar00#include 
#include 
#include 
#include 

static int
t1 (void)
{
  int n = -1;
  sscanf ("abc  ", "abc %n", &n);
  printf ("t1: count=%d\n", n);

  return n != 5;
}

static int
t2 (void)
{
  int result = 0;
  int n;
  long N;
  int retval;
#define SCAN(INPUT, FORMAT, VAR, EXP_RES, EXP_VAL) \
  VAR = -1; \
  retval = sscanf (INPUT, FORMAT, &VAR); \
  printf ("sscanf (\"%s\", \"%s\", &x) => %d, x = %ld\n", \
	  INPUT, FORMAT, retval, (long int) VAR); \
  result |= retval != EXP_RES || VAR != EXP_VAL

  SCAN ("12345", "%ld", N, 1, 12345);
  SCAN ("12345", "%llllld", N, 0, -1);
  SCAN ("12345", "%LLLLLd", N, 0, -1);
  SCAN ("test ", "%*s%n",  n, 0, 4);
  SCAN ("test ", "%2*s%n",  n, 0, -1);
  SCAN ("12 ",   "%l2d",  n, 0, -1);
  SCAN ("12 ",   "%2ld",  N, 1, 12);

  n = -1;
  N = -1;
  retval = sscanf ("1 1", "%d %Z", &n, &N);
  printf ("sscanf (\"1 1\", \"%%d %%Z\", &n, &N) => %d, n = %d, N = %ld\n", \
	  retval, n, N); \
  result |= retval != 1 || n != 1 || N != -1;

  return result;
}

static int
F (void)
{
  char buf[20];
  wchar_t wbuf[10];
  int result;

  snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX,
	    DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX);
  result = strcmp (buf, "nan NAN") != 0;
  printf ("expected \"nan NAN\", got \"%s\"\n", buf);

  snprintf (buf, sizeof buf, "%f %F", DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
  result |= strcmp (buf, "inf INF") != 0;
  printf ("expected \"inf INF\", got \"%s\"\n", buf);

  /* swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F",
	    DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX,
	    DBL_MAX * DBL_MAX - DBL_MAX * DBL_MAX);
  result |= wcscmp (wbuf, L"nan NAN") != 0;
  printf ("expected L\"nan NAN\", got L\"%S\"\n", wbuf); 

  swprintf (wbuf, sizeof wbuf / sizeof (wbuf[0]), L"%f %F",
	    DBL_MAX * DBL_MAX, DBL_MAX * DBL_MAX);
  result |= wcscmp (wbuf, L"inf INF") != 0;
  printf ("expected L\"inf INF\", got L\"%S\"\n", wbuf);

  */ 
  return result;
}

int
main (int argc, char *argv[])
{
  int result = 0;

  result |= t1 ();
  result |= t2 ();
  result |= F ();

  result |= fflush (stdout) == EOF;

  return result;
}
dietlibc-0.33~cvs20120325/test/stdio/tstgetln.c010064400000000000000000000024521173363231000160110ustar00/* Copyright (C) 1992, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#define _GNU_SOURCE
#include 
#include 

int main (int argc, char *argv[])
{
  char *buf = NULL;
  size_t size = 0;
  ssize_t len;

  while ((len = getline (&buf, &size, stdin)) != -1)
    {
      printf ("bufsize %Zu; read %Zd: ", size, len);
      if (fwrite (buf, len, 1, stdout) != 1)
	{
	  perror ("fwrite");
	  return 1;
	}
    }

  if (ferror (stdin))
    {
      perror ("getline");
      return 1;
    }

  return 0;
}
dietlibc-0.33~cvs20120325/test/stdio/tstscanf.c010064400000000000000000000173061173363231000157760ustar00/* Copyright (C) 1991,92,96,97,98,99,2000,2001 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#ifdef	BSD
#include 
#else
#include 
#endif
#include 
#include 
#include 


int
main (int argc, char **argv)
{
  char buf[BUFSIZ];
  FILE *in = stdin, *out = stdout;
  int x;
  int result = 0;

  if (sscanf ("0", "%d", &x) != 1)
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }

  if (sscanf ("08905x", "%9[0-9]", buf) != 1
      || strcmp (buf, "08905") != 0)
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }

  if (sscanf ("", "%10[a-z]", buf) != EOF)
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }

  sscanf ("conversion] Zero flag Ze]ro#\n", "%*[^]] %[^#]\n", buf);
  if (strcmp (buf, "] Zero flag Ze]ro") != 0)
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }

  if (argc == 2 && !strcmp (argv[1], "-opipe"))
    {
      out = popen ("/bin/cat", "w");
      if (out == NULL)
	{
	  perror ("popen: /bin/cat");
	  result = 1;
	}
    }
  else if (argc == 3 && !strcmp (argv[1], "-ipipe"))
    {
      sprintf (buf, "/bin/cat %s", argv[2]);
      in = popen (buf, "r");
      if (in == NULL)
	{
	  perror ("popen: /bin/cat");
	  result = 1;
	}
    }

  {
    char name[50];
    fprintf (out,
	     "sscanf (\"thompson\", \"%%s\", name) == %d, name == \"%s\"\n",
	     sscanf ("thompson", "%s", name),
	     name);
    if (strcmp (name, "thompson") != 0)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Testing scanf (vfscanf)\n", out);

  fputs ("Test 1:\n", out);
  {
    int n, i;
    float x;
    char name[50];
    n = fscanf (in, "%d%f%s", &i, &x, name);
    fprintf (out, "n = %d, i = %d, x = %f, name = \"%.50s\"\n",
	     n, i, x, name);
    if (n != 3 || i != 25 || x != 5.432F || strcmp (name, "thompson"))
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }
  fprintf (out, "Residual: \"%s\"\n", fgets (buf, sizeof (buf), in));
  if (strcmp (buf, "\n"))
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }
  fputs ("Test 2:\n", out);
  {
    int i;
    float x;
    char name[50];
    (void) fscanf (in, "%2d%f%*d %[0123456789]", &i, &x, name);
    fprintf (out, "i = %d, x = %f, name = \"%.50s\"\n", i, x, name);
    if (i != 56 || x != 789.0F || strcmp (name, "56"))
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }
  fprintf (out, "Residual: \"%s\"\n", fgets (buf, sizeof (buf), in));
  if (strcmp (buf, "a72\n"))
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }
  fputs ("Test 3:\n", out);
  {
    static struct {
      int count;
      float quant;
      const char *units;
      const char *item;
    } ok[] = {
      { 3, 2.0F, "quarts", "oil" },
      { 2, -12.8F, "degrees", "" },
      { 0, 0.0F, "", "" },
      { 3, 10.0F, "LBS", "fertilizer" },
      { 3, 100.0F, "rgs", "energy" },
      { -1, 0.0F, "", "" }};
    size_t rounds = 0;
    float quant;
    char units[21], item[21];
    while (!feof (in) && !ferror (in))
      {
	int count;

	if (rounds++ >= sizeof (ok) / sizeof (ok[0]))
	  {
	    fputs ("test failed!\n", stdout);
	    result = 1;
	  }

	quant = 0.0;
	units[0] = item[0] = '\0';
	count = fscanf (in, "%f%20s of %20s", &quant, units, item);
	(void) fscanf (in, "%*[^\n]");
	fprintf (out, "count = %d, quant = %f, item = %.21s, units = %.21s\n",
		 count, quant, item, units);
	if (count != ok[rounds-1].count || quant != ok[rounds-1].quant
	    || strcmp (item, ok[rounds-1].item)
	    || strcmp (units, ok[rounds-1].units))
	  {
	    fputs ("test failed!\n", stdout);
	    result = 1;
	  }
      }
  }
  buf[0] = '\0';
  fprintf (out, "Residual: \"%s\"\n", fgets (buf, sizeof (buf), in));
  if (strcmp (buf, ""))
    {
      fputs ("test failed!\n", stdout);
      result = 1;
    }

  if (out != stdout)
    pclose (out);

  fputs ("Test 4:\n", out);
  {
    int res, val, n;

    res = sscanf ("-242", "%3o%n", &val, &n);
    printf ("res = %d, val = %d, n = %d\n", res, val, n);
    if (res != 1 || val != -20 || n != 3)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 5:\n", out);
  {
    double a = 0, b = 0;
    int res, n;

    res = sscanf ("1234567", "%3lg%3lg%n", &a, &b, &n);
    printf ("res = %d, a = %g, b = %g, n = %d\n", res, a, b, n);

    if (res != 2 || a != 123 || b != 456 || n != 6)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }

    res = sscanf ("0", "%lg", &a);
    printf ("res = %d, a = %g\n", res, a);

    if (res != 1 || a != 0)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }

    res = sscanf ("1e3", "%lg%n", &a, &n);
    printf ("res = %d, a = %g, n = %d\n", res, a, n);

    if (res != 1 || a != 1000 || n != 3)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 6:\n", stdout);
  {
    char *p = (char *) -1;
    int res;

    sprintf (buf, "%p", NULL);
    res = sscanf (buf, "%p", &p);
    printf ("sscanf (\"%s\", \"%%p\", &p) = %d, p == %p\n", buf, res, p);

    if (res != 1 || p != NULL)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 7:\n", stdout);
  {
    short a[2] = { -1, -1 };
    int res;

    res = sscanf ("32767 1234", "%hd %hd", &a[0], &a[1]);
    printf ("res = %d, a[0] = %d, a[1] = %d\n", res, a[0], a[1]);

    if (res != 2 || a[0] != 32767 || a[1] != 1234)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 8:\n", stdout);
  {
    double d = 123456.789;
    int res;

    res = sscanf ("0x1234", "%lf", &d);
    printf ("res = %d, d = %f\n", res, d);

    if (res != 0 || d != 123456.789)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 9:\n", stdout);
  {
    /* From PR libc/1313 reported by Ben Caradoc-Davies .  */
    float value;
    int res;

    res = sscanf ("0123", "%2f", &value);
    if (res != 1 || value != 1.0)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 10:\n", stdout);
  {
    float value;
    int res;

    res = sscanf ("--", "%f", &value);
    if (res != 0)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 11:\n", stdout);
  {
    char uart[50];
    int res;

    res = sscanf ("uart:16550A tx:0", "uart:%31s tx:%*u", uart);
    if (res != 1)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 12:\n", stdout);
  {
    char uart[50];
    int res;

    res = sscanf ("uart:16550A", "uart:%31s tx:%*u", uart);
    if (res != 1)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  fputs ("Test 13:\n", stdout);
  {
    float value;
    int res;

    res = sscanf ("-InF", "%f", &value);
    if (res != 1 || isinf (value) != -1)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }

    res = sscanf ("+InfiNiTY", "%f", &value);
    if (res != 1 || isinf (value) != 1)
      {
	fputs ("test failed!\n", stdout);
	result = 1;
      }
  }

  return result;
}
dietlibc-0.33~cvs20120325/test/stdlib/.cvsignore010064400000000000000000000002121173363231000161300ustar00test-canon
testdiv
testrand
testsort
tst-calloc
tst-environ
tst-limits
tst-malloc
tst-rand48
tst-strtod
tst-strtol
tst-strtoll
tst-system
dietlibc-0.33~cvs20120325/test/stdlib/Makefile010064400000000000000000000004741173363231000156020ustar00DIET=diet
CC=gcc

CFLAGS=-Wall -nostdinc

all: stdlibtest

TESTPROGRAMS=test-canon testdiv testrand testsort tst-calloc \
tst-environ tst-limits tst-malloc tst-rand48 tst-strtod tst-strtol \
tst-strtoll tst-system

stdlibtest: $(TESTPROGRAMS)
%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

clean:
	rm -f $(TESTPROGRAMS)

dietlibc-0.33~cvs20120325/test/stdlib/runtests.sh010064400000000000000000000006101173363231000163550ustar00#!/bin/sh

TESTPROGRAMS="test-canon testrand testsort tst-calloc tst-environ tst-limits tst-malloc tst-rand48 tst-strtod tst-strtol tst-strtoll tst-system"

for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
 done 

echo "12 165 12 10000 10 123 546 752 12 87 98 347 3186 482 92 3941 7563 865 85371 547 28" ./testdiv
dietlibc-0.33~cvs20120325/test/stdlib/test-canon.c010064400000000000000000000156371173363231000163700ustar00/* Test program for returning the canonical absolute name of a given file.
   Copyright (C) 1996, 1997, 2000, 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by David Mosberger .

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

/* This file must be run from within a directory called "stdlib".  */

#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define myrealpath realpath
static char	cwd[PATH_MAX];
static size_t	cwd_len;

struct {
  const char *	name;
  const char *	value;
} symlinks[] = {
  {"SYMLINK_LOOP",	"SYMLINK_LOOP"},
  {"SYMLINK_1",		"."},
  {"SYMLINK_2",		"//////./../../etc"},
  {"SYMLINK_3",		"SYMLINK_1"},
  {"SYMLINK_4",		"SYMLINK_2"},
  {"SYMLINK_5",		"doesNotExist"},
};

struct {
  const char * in, * out, *resolved;
  int error;
} tests[] = {
  /*  0 */
  {"/",					"/", "", 0},
  {"/////////////////////////////////",	"/", "" ,0},
  {"/.././.././.././..///",		"/", "",0},
  {"/etc",				"/etc", "",0},
  {"/etc/../etc",			"/etc", "",0},
  /*  5 */
  {"/doesNotExist/../etc",		0, "/doesNotExist", ENOENT},
  {"./././././././././.",		".", "",0},
  {"/etc/.//doesNotExist",		0, "/etc/doesNotExist", ENOENT},
  {"./doesExist",			"./doesExist", "",0},
  {"./doesExist/",			"./doesExist", "",0},
  /* 10 */
  {"./doesExist/../doesExist",		"./doesExist","",0},
  {"foobar",				0, "./foobar", ENOENT},
  {".",					".","",0},
  {"./foobar",				0, "./foobar", ENOENT},
  {"SYMLINK_LOOP",			0, "./SYMLINK_LOOP", ELOOP},
  /* 15 */
  {"./SYMLINK_LOOP",			0, "./SYMLINK_LOOP", ELOOP},
  {"SYMLINK_1",				".","",0},
  {"SYMLINK_1/foobar",			0, "./foobar", ENOENT},
  {"SYMLINK_2",				"/etc","",0},
  {"SYMLINK_3",				".","",0},
  /* 20 */
  {"SYMLINK_4",				"/etc","",0},
  {"../stdlib/SYMLINK_1",		".","",0},
  {"../stdlib/SYMLINK_2",		"/etc","",0},
  {"../stdlib/SYMLINK_3",		".","",0},
  {"../stdlib/SYMLINK_4",		"/etc","",0},
  /* 25 */
  {"./SYMLINK_5",			0, "./doesNotExist", ENOENT},
  {"SYMLINK_5",				0, "./doesNotExist", ENOENT},
  {"SYMLINK_5/foobar",			0, "./doesNotExist", ENOENT},
  {"doesExist/../../stdlib/doesExist",	"./doesExist","",0},
  {"doesExist/.././../stdlib/.",	".","",0}
};


static int
check_path (const char * result, const char * expected)
{
  int good;

  if (!result)
    return (expected == NULL);

  if (!expected)
    return 0;

  if (expected[0] == '.' && (expected[1] == '/' || expected[1] == '\0'))
    good = (strncmp (result, cwd, cwd_len) == 0
	    && strcmp (result + cwd_len, expected + 1) == 0);
  else
    good = (strcmp (expected, result) == 0);

  return good;
}


int
main (int argc, char ** argv)
{
  char * result;
  int fd, i, errors = 0;
  char buf[PATH_MAX];

  getcwd (cwd, sizeof(buf));
  cwd_len = strlen (cwd);

/* this segfaults with dietlibc 
man page documents:
  EINVAL Either path or resolved_path is NULL. (In libc5 this would  just
                cause a segfault.)
  errno = 0;
  if (myrealpath (NULL, buf) != NULL || errno != EINVAL)
    {
      printf ("%s: expected return value NULL and errno set to EINVAL"
	      " for myrealpath(NULL,...)\n", argv[0]);
      ++errors;
    }
*/   

/* according to glibc, this test is invalid 
  errno = 0;
  if (myrealpath ("/", NULL) != NULL || errno != EINVAL)
    {
      printf ("%s: expected return value NULL and errno set to EINVAL"
	      " for myrealpath(...,NULL)\n", argv[0]);
      ++errors;
    }
*/    

  errno = 0;
  if (myrealpath ("", buf) != NULL || errno != ENOENT)
    {
      printf ("%s: expected return value NULL and set errno to ENOENT"
	      " for myrealpath(\"\",...)\n", argv[0]);
      ++errors;
    }

  for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i)
    symlink (symlinks[i].value, symlinks[i].name);

  fd = open("doesExist", O_CREAT | O_EXCL, 0777);

  for (i = 0; i < (int) (sizeof (tests) / sizeof (tests[0])); ++i)
    {
      buf[0] = '\0';
      result = myrealpath (tests[i].in, buf);

      if (!check_path (result, tests[i].out))
	{
	  printf ("%s: flunked test %d (expected `%s', got `%s')\n",
		  argv[0], i, tests[i].out ? tests[i].out : "NULL",
		  result ? result : "NULL");
	  ++errors;
	  continue;
	}

      if (!check_path (buf, tests[i].out ? tests[i].out : tests[i].resolved))
	{
	  printf ("%s: flunked test %d (expected resolved `%s', got `%s')\n",
		  argv[0], i, tests[i].out ? tests[i].out : tests[i].resolved,
		  buf);
	  ++errors;
	  continue;
	}

      if (!tests[i].out && errno != tests[i].error)
	{
	  printf ("%s: flunked test %d (expected errno %d, got %d)\n",
		  argv[0], i, tests[i].error, errno);
	  ++errors;
	  continue;
	}
    }

  getcwd (buf, sizeof(buf));
  if (strcmp (buf, cwd))
    {
      printf ("%s: current working directory changed from %s to %s\n",
	      argv[0], cwd, buf);
      ++errors;
    }

  if (fd >= 0)
    unlink("doesExist");

  for (i = 0; i < (int) (sizeof (symlinks) / sizeof (symlinks[0])); ++i)
    unlink (symlinks[i].name);

  if (errors != 0)
    {
      printf ("%d errors.\n", errors);
      return EXIT_FAILURE;
    }

  puts ("No errors.");
  return EXIT_SUCCESS;
}

#if 0
static char *sep(char *path)
{
	char *tmp, c;
	
	tmp = strrchr(path, '/');
	if(tmp) {
		c = tmp[1];
		tmp[1] = 0;
		if (chdir(path)) {
			return NULL;
		}
		tmp[1] = c;
		
		return tmp + 1;
	}
	
	return path;

}

char *myrealpath(const char *_path, char *resolved_path)
{
	int fd = open(".", O_RDONLY), l;
	char path[PATH_MAX], lnk[PATH_MAX], *tmp = (char *)"";
	
	if (fd < 0) {
		return NULL;
	}
	strncpy(path, _path, PATH_MAX);
	
	if (chdir(path)) {
		if (errno == ENOTDIR) {
			l = readlink(path, lnk, PATH_MAX);
			if (!(tmp = sep(path))) {
				resolved_path = NULL;
				goto abort;
			}
			if (l < 0) {
				perror("readlink");
				if (errno != EINVAL || errno !=ENOENT) {
					resolved_path = NULL;
					goto abort;
				}
			} else {
				lnk[l] = 0;
				if (!(tmp = sep(lnk))) {
					resolved_path = NULL;
					goto abort;
				}
			}
		} else {
			perror("chdir()");
			resolved_path = NULL;
			goto abort;
		}
	}
	if (!getcwd(resolved_path, PATH_MAX)) {
		resolved_path = NULL;
		goto abort;
	}
	
	if(strcmp(resolved_path, "/") && *tmp) {
		strcat(resolved_path, "/");
	}
	
	strcat(resolved_path, tmp);
      abort:
	fchdir(fd);
	close(fd);
	return resolved_path;
}
#endif
dietlibc-0.33~cvs20120325/test/stdlib/testdiv.c010064400000000000000000000023121173363231000157610ustar00/* Copyright (C) 1992, 1997 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 

int
main (void)
{
  int err = 0;
  int i, j;
  while (scanf ("%d %d\n", &i, &j) == 2)
    {
      div_t d = div (i, j);
      printf ("%d / %d = %d + %d/%d", i, j, d.quot, d.rem, j);
      if (i == d.quot * j + d.rem)
	fputs ("  OK\n", stdout);
      else
	{
	  fputs ("  FAILED\n", stdout);
	  err = 1;
	}
    }
  return err;
}
dietlibc-0.33~cvs20120325/test/stdlib/testrand.c010064400000000000000000000030161173363231000161250ustar00/* Copyright (C) 1992, 1997 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 

int
main (void)
{
  int i1, i2;
  int j1, j2;

  /* The C standard says that "If rand is called before any calls to
     srand have been made, the same sequence shall be generated as
     when srand is first called with a seed value of 1." */
  i1 = rand();
  i2 = rand();
  srand (1);
  j1 = rand();
  j2 = rand();
  if (i1 < 0 || i2 < 0 || j1 < 0 || j2 < 0) {
      puts ("Test FAILED!");
  }
  if (j1 == i1 && j2 == i2)
    {
      puts ("Test succeeded.");
      return 0;
    }
  else
    {
      if (j1 != i1)
	printf ("%d != %d\n", j1, i1);
      if (j2 != i2)
	printf ("%d != %d\n", j2, i2);
      puts ("Test FAILED!");
      return 1;
    }
}
dietlibc-0.33~cvs20120325/test/stdlib/testsort.c010064400000000000000000000011321173363231000161650ustar00#include 
#include 
#include 

static int
compare (const void *a, const void *b)
{
  return strcmp (*(char **) a, *(char **) b);
}

int
main (void)
{
  char bufs[500][20];
  char *lines[500];
  size_t lens[500];
  size_t i, j;

  srandom (1);

  for (i = 0; i < 500; ++i)
    {
      lens[i] = random() % 19;
      lines[i] = bufs[i];
      for (j = 0; j < lens[i]; ++j)
	lines[i][j] = random() % 26 + 'a';
      lines[i][j] = '\0';
    }

  qsort (lines, 500, sizeof (char *), compare);

  for (i = 0; i < 500 && lines[i] != NULL; ++i)
    puts (lines[i]);

  return 0;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-calloc.c010064400000000000000000000051611173363231000163510ustar00/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper .

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 
#include 
#include 


/* Number of samples per size.  */
#define N 50000


static void
fixed_test (int size)
{
  char *ptrs[N];
  int i;

  for (i = 0; i < N; ++i)
    {
      int j;

      ptrs[i] = (char *) calloc (1, size);

      if (ptrs[i] == NULL)
	break;

      for (j = 0; j < size; ++j)
	{
	  if (ptrs[i][j] != '\0') {
	    fprintf(stderr, "byte not cleared (size %d, element %d, byte %d)",
		   size, i, j);
	    exit(1);
	    }
	  ptrs[i][j] = '\xff';
	}
    }

  while (i-- > 0)
    free (ptrs[i]);
}


static void
random_test (void)
{
  char *ptrs[N];
  int i;

  for (i = 0; i < N; ++i)
    {
      int j;
      int n = 1 + random () % 10;
      int elem = 1 + random () % 100;
      int size = n * elem;

      ptrs[i] = (char *) calloc (n, elem);

      if (ptrs[i] == NULL)
	break;

      for (j = 0; j < size; ++j)
	{
	  if (ptrs[i][j] != '\0') {
	    fprintf (stderr, "byte not cleared (size %d, element %d, byte %d)",
		   size, i, j);
	    exit(1);
	  }  
	  ptrs[i][j] = '\xff';
	}
    }

  while (i-- > 0)
    free (ptrs[i]);
}


static void
null_test (void)
{
  /* If the size is 0 the result is implementation defined.  Just make
     sure the program doesn't crash.  */
  calloc (0, 0);
  calloc (0, UINT_MAX);
  calloc (UINT_MAX, 0);
  calloc (0, ~((size_t) 0));
  calloc (~((size_t) 0), 0);
}


int
main (void)
{
  /* We are allocating blocks with `calloc' and check whether every
     block is completely cleared.  We first try this for some fixed
     times and then with random size.  */
  fixed_test (15);
  fixed_test (5);
  fixed_test (17);
  fixed_test (6);
  fixed_test (31);
  fixed_test (96);

  random_test ();

  null_test ();

  return 0;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-environ.c010064400000000000000000000113601173363231000165720ustar00/* Copyright (C) 1999 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 


#define VAR "FOOBAR"

char putenv_val[100] = VAR "=some longer value";

int
main (void)
{
  int result = 0;
  const char *valp;

  /* First test: remove entry FOOBAR, whether it exists or not.  */
  unsetenv (VAR);

  /* Now getting the value should fail.  */
  if (getenv (VAR) != NULL)
    {
      printf ("There should be no `%s' value\n", VAR);
      result = 1;
    }

  /* Now add a value, with the replace flag cleared.  */
  if (setenv (VAR, "one", 0) != 0)
    {
      printf ("setenv #1 failed: %m\n");
      result = 1;
    }

  /* Getting this value should now be possible.  */
  valp = getenv (VAR);
  if (valp == NULL || strcmp (valp, "one") != 0)
    {
      puts ("getenv #2 failed");
      result = 1;
    }

  /* Try to replace without the replace flag set.  This should fail.  */
  if (setenv (VAR, "two", 0) != 0)
    {
      printf ("setenv #2 failed: %m\n");
      result = 1;
    }

  /* The value shouldn't have changed.  */
  valp = getenv (VAR);
  if (valp == NULL || strcmp (valp, "one") != 0)
    {
      puts ("getenv #3 failed");
      result = 1;
    }

  /* Now replace the value using putenv.  */
  if (putenv (putenv_val) != 0)
    {
      printf ("putenv #1 failed: %m\n");
      result = 1;
    }

  /* The value should have changed now.  */
  valp = getenv (VAR);
  if (valp == NULL || strcmp (valp, "some longer value") != 0)
    {
      printf ("getenv #4 failed (is \"%s\")\n", valp);
      result = 1;
    }

  /* Now one tricky check: changing the variable passed in putenv should
     change the environment.  */
  strcpy (&putenv_val[sizeof VAR], "a short one");

  /* The value should have changed again.  */
  valp = getenv (VAR);
  if (valp == NULL || strcmp (valp, "a short one") != 0)
    {
      puts ("getenv #5 failed");
      result = 1;
    }

  /* It should even be possible to rename the variable.  */
  strcpy (putenv_val, "XYZZY=some other value");

  /* Now a lookup using the old name should fail.  */
  if (getenv (VAR) != NULL)
    {
      puts ("getenv #6 failed");
      result = 1;
    }

  /* But using the new name it should work.  */
  valp = getenv ("XYZZY");
  if (valp == NULL || strcmp (valp, "some other value") != 0)
    {
      puts ("getenv #7 failed");
      result = 1;
    }

  /* Create a new variable with the old name.  */
  if (setenv (VAR, "a new value", 0) != 0)
    {
      printf ("setenv #3 failed: %m\n");
      result = 1;
    }

  /* At this point a getenv call must return the new value.  */
  valp = getenv (VAR);
  if (valp == NULL || strcmp (valp, "a new value") != 0)
    {
      puts ("getenv #8 failed");
      result = 1;
    }

  /* Black magic: rename the variable we added using putenv back.  */
  strcpy (putenv_val, VAR "=old name new value");

  /* This is interesting.  We have two variables with the same name.
     Getting a value should return one of them.  */
  valp = getenv (VAR);
  if (valp == NULL
      || (strcmp (valp, "a new value") != 0
	  && strcmp (valp, "old name new value") != 0))
    {
      puts ("getenv #9 failed");
      result = 1;
    }

  /* More fun ahead: we are now removing the variable.  This should remove
     both values.  The cast is ok: this call should never put the string
     in the environment and it should never modify it.  */
  putenv ((char *) VAR);

  /* Getting the value should now fail.  */
  if (getenv (VAR) != NULL)
    {
      printf ("getenv #10 failed (\"%s\" found)\n", getenv (VAR));
      result = 1;
    }

  /* Now a test with an environment variable that's one character long.
     This is to test a special case in the getenv implementation.  */
  strcpy (putenv_val, "X=one character test");
  if (putenv (putenv_val) != 0)
    {
      printf ("putenv #2 failed: %m\n");
      result = 1;
    }

  valp = getenv ("X");
  if (valp == NULL || strcmp (valp, "one character test") != 0)
    {
      puts ("getenv #11 failed");
      result = 1;
    }

  return result;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-limits.c010064400000000000000000000042221173363231000164120ustar00/* It is important that this comes first to not hide effects introduced
   by other headers.  */
#include 

#include 
#include 

static long long int
bitval (int bits)
{
  long long int val = 0;
  while (bits-- > 0)
    val |= 1ll << bits;
  return val;
}


int
main (void)
{
  int result = 0;

#define TEST(name, format, expected) \
  if (expected != name ) \
  fprintf (stderr, "%-12s expected = %-20" format "  actual = %" format "\n",	      \
	  #name ":", expected, name);					      \
  result |= name != expected

  /* The limits from ISO C99.  */

  /* We cannot support anything but 8-bit chars.  */
  TEST (CHAR_BIT, "d", 8);
  TEST (SCHAR_MIN, "d", -128);
  TEST (SCHAR_MAX, "d", 127);
  TEST (UCHAR_MAX, "d", 255);

  TEST (SHRT_MIN, "d", -(1 << (sizeof (short int) * CHAR_BIT - 1)));
  TEST (SHRT_MAX, "d", (1 << (sizeof (short int) * CHAR_BIT - 1)) - 1);
  TEST (USHRT_MAX, "d", (1 << sizeof (short int) * CHAR_BIT) - 1);

  TEST (INT_MIN, "d", (int) -bitval (sizeof (int) * CHAR_BIT - 1) - 1);
  TEST (INT_MAX, "d", (int) bitval (sizeof (int) * CHAR_BIT - 1));
  TEST (UINT_MAX, "u",
	(unsigned int) bitval (sizeof (unsigned int) * CHAR_BIT));

  TEST (LONG_MIN, "ld",
	(long int) -bitval (sizeof (long int) * CHAR_BIT - 1) - 1);
  TEST (LONG_MAX, "ld", (long int) bitval (sizeof (long int) * CHAR_BIT - 1));
  TEST (ULONG_MAX, "lu",
	(unsigned long int) bitval (sizeof (unsigned long int) * CHAR_BIT));
#ifdef __dietlibc__ /* tst-limits.c:54: `LLONG_MIN' undeclared (first use in this function).   Great.*/
  TEST (LLONG_MIN, "lld", -bitval (sizeof (long long int) * CHAR_BIT - 1) - 1);
  TEST (LLONG_MAX, "lld", bitval (sizeof (long long int) * CHAR_BIT - 1));
  TEST (ULLONG_MAX, "llu",
	(unsigned long long int) bitval (sizeof (unsigned long long int)
					 * CHAR_BIT));
#endif					 

  /* Values from POSIX and Unix.  */
#ifdef PAGESIZE
  TEST (PAGESIZE, "d", getpagesize ());
#elif PAGE_SIZE
  TEST (PAGE_SIZE, "d", getpagesize ());
#endif


/*  not defined in dietlibc
    TEST (WORD_BIT, "zd", sizeof (int) * CHAR_BIT);
/   TEST (LONG_BIT, "zd", sizeof (long int) * CHAR_BIT); */

  if (!result) fprintf(stdout, "OK\n");
  return result;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-malloc.c010064400000000000000000000032161173363231000163620ustar00/* Copyright (C) 1999 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Andreas Jaeger , 1999.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 

static int errors = 0;

static void
merror (const char *msg)
{
  ++errors;
  printf ("Error: %s\n", msg);
}

int
main (void)
{
  void *p;
  int save;

  errno = 0;

  p = malloc (-1);
  save = errno;

  if (p != NULL)
    merror ("malloc (-1) succeeded.");

  if (p == NULL && save != ENOMEM)
    merror ("errno is not set correctly");

  p = malloc (10);
  if (p == NULL)
    merror ("malloc (10) failed.");

  /* realloc (p, 0) == free (p).  */
  p = realloc (p, 0);
  if (p != NULL)
    merror ("realloc (p, 0) failed.");

  p = malloc (0);
  if (p == NULL)
    merror ("malloc (0) failed.");

  p = realloc (p, 0);
  if (p != NULL)
    merror ("realloc (p, 0) failed.");

  return errors != 0;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-rand48.c010064400000000000000000000226431173363231000162200ustar00#include 
#include 
#include 
#include 

#ifndef DECIMAL_DIG
# define DECIMAL_DIG	21
#endif


int
main (void)
{
  unsigned short int xs[3] = { 0x0001, 0x0012, 0x0123 };
  unsigned short int lxs[7];
  unsigned short int *xsp;
  int result = 0;
  long int l;
  double d;
  double e;

  /* Test srand48.  */
  srand48 (0x98765432);
  /* Get the values of the internal Xi array.  */
  xsp = seed48 (xs);
  if (xsp[0] != 0x330e || xsp[1] != 0x5432 || xsp[2] != 0x9876)
    {
      puts ("srand48(0x98765432) didn't set correct value");
      printf ("  expected: { %04hx, %04hx, %04hx }\n", 0x330e, 0x5432, 0x9876);
      printf ("  seen:     { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]);
      result = 1;
    }
  /* Put the values back.  */
  memcpy (xs, xsp, sizeof (xs));
  (void) seed48 (xs);

  /* See whether the correct values are installed.  */
  l = lrand48 ();
  if (l != 0x2fed1413l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2fed1413l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xa28c1003l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xa28c1003l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x585fcfb7l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x585fcfb7l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x9e88f474l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x9e88f474l, l);
      result = 1;
    }

  /* Test seed48.  The previous call should have install the values in
     the initialization of `xs' above.  */
  xs[0] = 0x1234;
  xs[1] = 0x5678;
  xs[2] = 0x9012;
  xsp = seed48 (xs);
  if (xsp[0] != 0x62f2 || xsp[1] != 0xf474 || xsp[2] != 0x9e88)
    {
      puts ("seed48() did not install the values correctly");
      printf ("  expected: { %04hx, %04hx, %04hx }\n", 0x62f2, 0xf474, 0x9e88);
      printf ("  seen:     { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]);
      result = 1;
    }

  /* Test lrand48 and mrand48.  We continue from the seed established
     above.  */
  l = lrand48 ();
  if (l != 0x017e48b5l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x017e48b5l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xeb7a1fa3l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xeb7a1fa3l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x6b6a3f95l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6b6a3f95l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x175c0d6fl)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x175c0d6fl, l);
      result = 1;
    }

  /* Test lcong48.  */
  lxs[0] = 0x4567;
  lxs[1] = 0x6789;
  lxs[2] = 0x8901;
  lxs[3] = 0x0123;
  lxs[4] = 0x2345;
  lxs[5] = 0x1111;
  lxs[6] = 0x2222;
  lcong48 (lxs);

  /* See whether the correct values are installed.  */
  l = lrand48 ();
  if (l != 0x6df63d66l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6df63d66l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x2f92c8e1l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2f92c8e1l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x3b4869ffl)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x3b4869ffl, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x5cd4cc3el)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x5cd4cc3el, l);
      result = 1;
    }

  /* Check whether srand48() restores the A and C parameters.  */
  srand48 (0x98765432);

  /* See whether the correct values are installed.  */
  l = lrand48 ();
  if (l != 0x2fed1413l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2fed1413l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xa28c1003l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xa28c1003l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x585fcfb7l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x585fcfb7l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x9e88f474l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x9e88f474l, l);
      result = 1;
    }

  /* And again to see whether seed48() does the same.  */
  lcong48 (lxs);

  /* See whether lxs wasn't modified.  */
  l = lrand48 ();
  if (l != 0x6df63d66l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6df63d66l, l);
      result = 1;
    }

  /* Test seed48.  The previous call should have install the values in
     the initialization of `xs' above.  */
  xs[0] = 0x1234;
  xs[1] = 0x5678;
  xs[2] = 0x9012;
  xsp = seed48 (xs);
  if (xsp[0] != 0x0637 || xsp[1] != 0x7acd || xsp[2] != 0xdbec)
    {
      puts ("seed48() did not install the values correctly");
      printf ("  expected: { %04hx, %04hx, %04hx }\n", 0x0637, 0x7acd, 0xdbec);
      printf ("  seen:     { %04hx, %04hx, %04hx }\n", xsp[0], xsp[1], xsp[2]);
      result = 1;
    }

  /* Test lrand48 and mrand48.  We continue from the seed established
     above.  */
  l = lrand48 ();
  if (l != 0x017e48b5l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x017e48b5l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0xeb7a1fa3l)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xeb7a1fa3l, l);
      result = 1;
    }

  l = lrand48 ();
  if (l != 0x6b6a3f95l)
    {
      printf ("lrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x6b6a3f95l, l);
      result = 1;
    }

  l = mrand48 ();
  if (l != 0x175c0d6fl)
    {
      printf ("mrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x175c0d6fl, l);
      result = 1;
    }

  /* Test drand48.  */
  d = drand48 ();
  if (d != 0.0908832261858485424)
    {
      printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.0908832261858485424,
	      DECIMAL_DIG, d);
      result = 1;
    }

  d = drand48 ();
  if (d != 0.943149381730059133133)
    {
      printf ("drand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.943149381730059133133,
	      DECIMAL_DIG, d);
      result = 1;
    }

  /* Now the functions which get the Xis passed.  */
  xs[0] = 0x3849;
  xs[1] = 0x5061;
  xs[2] = 0x7283;

  l = nrand48 (xs);
  if (l != 0x1efe61a1l)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x1efe61a1l, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0xf568c7a0l)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0xf568c7a0l, l);
      result = 1;
    }

  l = nrand48 (xs);
  if (l != 0x2a5e57fel)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x2a5e57fel, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0x71a779a8l)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x71a779a8l, l);
      result = 1;
    }

  /* Test whether the global A and C are used.  */
  lcong48 (lxs);

  l = nrand48 (xs);
  if (l != 0x32beee9fl)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x32beee9fl, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0x7bddf3bal)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x7bddf3bal, l);
      result = 1;
    }

  l = nrand48 (xs);
  if (l != 0x85bdf28l)
    {
      printf ("nrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x85bdf28l, l);
      result = 1;
    }

  l = jrand48 (xs);
  if (l != 0x7b433e47l)
    {
      printf ("jrand48() in line %d failed: expected %lx, seen %lx\n",
	      __LINE__ - 4, 0x7b433e47l, l);
      result = 1;
    }

  /* Test erand48.  Also compare with the drand48 results.  */
  (void) seed48 (xs);

  d = drand48 ();
  e = erand48 (xs);
  if (d != e)
    {
      printf ("\
drand48() and erand48 in lines %d and %d produce different results\n",
	      __LINE__ - 6, __LINE__ - 5);
      printf ("  drand48() = %g, erand48() = %g\n", d, e);
      result = 1;
    }
  else if (e != 0.640650904452755298735)
    {
      printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.640650904452755298735,
	      DECIMAL_DIG, e);
      result = 1;

    }

  d = drand48 ();
  e = erand48 (xs);
  if (d != e)
    {
      printf ("\
drand48() and erand48 in lines %d and %d produce different results\n",
	      __LINE__ - 6, __LINE__ - 5);
      printf ("  drand48() = %g, erand48() = %g\n", d, e);
      result = 1;
    }
  else if (e != 0.115372323508150742555)
    {
      printf ("erand48() in line %d failed: expected %.*g, seen %.*g\n",
	      __LINE__ - 4, DECIMAL_DIG, 0.0115372323508150742555,
	      DECIMAL_DIG, e);
      result = 1;

    }

  return result;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-strtod.c010064400000000000000000000160341173363231000164340ustar00/* Copyright (C) 1991,96,97,98,99,2000,2001,2003 Free Software Foundation, Inc.
   This file is part of the GNU C Library.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

struct ltest
  {
    const char *str;		/* Convert this.  */
    double expect;		/* To get this.  */
    char left;			/* With this left over.  */
    int err;			/* And this in errno.  */
  };
static const struct ltest tests[] =
  {
    { "12.345", 12.345, '\0', 0 },
    { "12.345e19", 12.345e19, '\0', 0 },
    { "-.1e+9", -.1e+9, '\0', 0 },
    { ".125", .125, '\0', 0 },
    { "1e20", 1e20, '\0', 0 },
    { "0e-19", 0, '\0', 0 },
    { "4\00012", 4.0, '\0', 0 },
    { "5.9e-76", 5.9e-76, '\0', 0 },
    { "0x1.4p+3", 10.0, '\0', 0 },
    { "0xAp0", 10.0, '\0', 0 },
    { "0x0Ap0", 10.0, '\0', 0 },
    { "0x0A", 10.0, '\0', 0 },
    { "0xA0", 160.0, '\0', 0 },
    { "0x0.A0p8", 160.0, '\0', 0 },
    { "0x0.50p9", 160.0, '\0', 0 },
    { "0x0.28p10", 160.0, '\0', 0 },
    { "0x0.14p11", 160.0, '\0', 0 },
    { "0x0.0A0p12", 160.0, '\0', 0 },
    { "0x0.050p13", 160.0, '\0', 0 },
    { "0x0.028p14", 160.0, '\0', 0 },
    { "0x0.014p15", 160.0, '\0', 0 },
    { "0x00.00A0p16", 160.0, '\0', 0 },
    { "0x00.0050p17", 160.0, '\0', 0 },
    { "0x00.0028p18", 160.0, '\0', 0 },
    { "0x00.0014p19", 160.0, '\0', 0 },
    { "0x1p-1023",
      1.11253692925360069154511635866620203210960799023116591527666e-308,
      '\0', 0 },
    { "0x0.8p-1022",
      1.11253692925360069154511635866620203210960799023116591527666e-308,
      '\0', 0 },
/*#if __GNUC_PREREQ(2,96)
    For older GCC release HUGE_VAL is not a constant. Also fails with diet libc.
    { "Inf", HUGE_VAL, '\0', 0 },
    { "-Inf", -HUGE_VAL, '\0', 0 },
    { "+InFiNiTy", HUGE_VAL, '\0', 0 },
#endif */
    { NULL, 0, '\0', 0 }
  };

static void expand (char *dst, int c);
static int long_dbl (void);
static int locale_test (void);

int
main (int argc, char ** argv)
{
  char buf[100];
  register const struct ltest *lt;
  char *ep;
  int status = 0;
  int save_errno;

  for (lt = tests; lt->str != NULL; ++lt)
    {
      double d;

      errno = 0;
      d = strtod(lt->str, &ep);
      save_errno = errno;
      printf ("strtod (\"%s\") test %u",
	     lt->str, (unsigned int) (lt - tests));
      if (d == lt->expect && *ep == lt->left && save_errno == lt->err)
	puts ("\tOK");
      else
	{
	  puts ("\tBAD");
	  if (d != lt->expect)
	    printf ("  returns %.60g, expected %.60g\n", d, lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s)  instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  sprintf (buf, "%f", strtod ("-0.0", NULL));
  if (strcmp (buf, "-0.000000") != 0)
    {
      printf ("  strtod (\"-0.0\", NULL) returns \"%s\"\n", buf);
      status = 1;
    }

  const char input[] = "3752432815e-39";

  float f1 = strtold (input, NULL);
  float f2;
  float f3 = strtof (input, NULL);
  sscanf (input, "%g", &f2);

  if (f1 != f2)
    {
      printf ("f1 = %a != f2 = %a\n", f1, f2);
      status = 1;
    }
  if (f1 != f3)
    {
      printf ("f1 = %a != f3 = %a\n", f1, f3);
      status = 1;
    }
  if (f2 != f3)
    {
      printf ("f2 = %a != f3 = %a\n", f2, f3);
      status = 1;
    }

  const char input2[] = "+1.000000000116415321826934814453125";
  if (strtold (input2, NULL) != +1.000000000116415321826934814453125)
    {
      printf ("input2: %La != %La\n", strtold (input2, NULL),
	      +1.000000000116415321826934814453125);
      status = 1;
    }

  status |= long_dbl ();

  status |= locale_test ();

  return status ? EXIT_FAILURE : EXIT_SUCCESS;
}

static void
expand (dst, c)
     char *dst;
     register int c;
{
  if (isprint (c))
    {
      dst[0] = c;
      dst[1] = '\0';
    }
  else
    (void) sprintf (dst, "%#.3o", (unsigned int) c);
}

static int
long_dbl (void)
{
  /* Regenerate this string using

     echo '(2^53-1)*2^(1024-53)' | bc | sed 's/\([^\]*\)\\*$/    "\1"/'

  */
  static const char longestdbl[] =
    "17976931348623157081452742373170435679807056752584499659891747680315"
    "72607800285387605895586327668781715404589535143824642343213268894641"
    "82768467546703537516986049910576551282076245490090389328944075868508"
    "45513394230458323690322294816580855933212334827479782620414472316873"
    "8177180919299881250404026184124858368";
  double d = strtod (longestdbl, NULL);

  printf ("strtod (\"%s\", NULL) = %g\n", longestdbl, d);

  if (d != 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000)
    return 1;

  return 0;
}

/* Perform a few tests in a locale with thousands separators.  */
static int
locale_test (void)
{
  static const struct
  {
    const char *loc;
    const char *str;
    double exp;
    ptrdiff_t nread;
  } tests[] =
    {
      { "de_DE.UTF-8", "1,5", 1.5, 3 },
      { "de_DE.UTF-8", "1.5", 1.0, 1 },
      { "de_DE.UTF-8", "1.500", 1500.0, 5 },
      { "de_DE.UTF-8", "36.893.488.147.419.103.232", 0x1.0p65, 26 }
    };
#define ntests (sizeof (tests) / sizeof (tests[0]))
  size_t n;
  int result = 0;

  puts ("\nLocale tests");

  for (n = 0; n < ntests; ++n)
    {
      double d;
      char *endp;

      if (setlocale (LC_ALL, tests[n].loc) == NULL)
	{
	  printf ("cannot set locale %s\n", tests[n].loc);
	  result = 1;
	  continue;
	}

      /* This originally called  __strtod_interal here "to tests the
	 handling of grouping."  */
     // d = __strtod_internal (tests[n].str, &endp, 1);
        d = strtod (tests[n].str, &endp);
      if (d != tests[n].exp)
	{
	  printf ("strtod(\"%s\") returns %g and not %g\n",
		  tests[n].str, d, tests[n].exp);
	  result = 1;
	}
      else if (endp - tests[n].str != tests[n].nread)
	{
	  printf ("strtod(\"%s\") read %td bytes and not %td\n",
		  tests[n].str, endp - tests[n].str, tests[n].nread);
	  result = 1;
	}
    }

  if (result == 0)
    puts ("all OK");

  return result;
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-strtol.c010064400000000000000000000117311173363231000164430ustar00/* My bet is this was written by Chris Torek.
   I reformatted and ansidecl-ized it, and tweaked it a little.  */

#include 
#include 
#include 
#include 
#include 
#include 

struct ltest
  {
    const char *str;		/* Convert this.  */
    unsigned long int expect;	/* To get this.  */
    int base;			/* Use this base.  */
    char left;			/* With this left over.  */
    int err;			/* And this in errno.  */
  };
static const struct ltest tests[] =
  {
  /* First, signed numbers:  */
  /* simple... */
  {"123", 123, 0, 0, 0},
  {"+123", 123, 0, 0, 0},
  {"  123", 123, 0, 0, 0},
  {" 123 ", 123, 0, ' ', 0},
  {"   -17", -17, 0, 0, 0},

  /* implicit base... */
  {"0123", 0123, 0, 0, 0},
  {"0123a", 0123, 0, 'a', 0},
  {"01239", 0123, 0, '9', 0},
  {"0x123", 0x123, 0, 0, 0},
  {"-0x123", -0x123, 0, 0, 0},
  {"0x0xc", 0, 0, 'x', 0},
  {" +0x123fg", 0x123f, 0, 'g', 0},

  /* explicit base... */
  {"123", 0x123, 16, 0, 0},
  {"0x123", 0x123, 16, 0, 0},
  {"123", 0123, 8, 0, 0},
  {"0123", 0123, 8, 0, 0},
  {"0123", 123, 10, 0, 0},
  {"0x123", 0, 10, 'x', 0},

  /* case insensitivity... */
  {"abcd", 0xabcd, 16, 0, 0},
  {"AbCd", 0xabcd, 16, 0, 0},
  {"0xABCD", 0xabcd, 16, 0, 0},
  {"0Xabcd", 0xabcd, 16, 0, 0},

  /* odd bases... */
  {"0xyz", 33 * 35 + 34, 35, 'z', 0},
  {"yz!", 34 * 36 + 35, 36, '!', 0},
  {"-yz", -(34*36 + 35), 36, 0, 0},
  {"GhI4", ((16*20 + 17)*20 + 18)*20 + 4, 20, 0, 0},

  /* extremes... */
#if LONG_MAX == 0x7fffffff
  {"2147483647", 2147483647, 0, 0, 0},
  {"2147483648", 2147483647, 0, 0, ERANGE},
  {"214748364888", 2147483647, 0, 0, ERANGE},
  {"2147483650", 2147483647, 0, 0, ERANGE},
  {"-2147483648", 0x80000000, 0, 0, 0},
  {"-2147483649", 0x80000000, 0, 0, ERANGE},
  {"0x1122334455z", 2147483647, 16, 'z', ERANGE},
#else
  {"9223372036854775807", 9223372036854775807, 0, 0, 0},
  {"9223372036854775808", 9223372036854775807, 0, 0, ERANGE},
  {"922337203685477580777", 9223372036854775807, 0, 0, ERANGE},
  {"9223372036854775810", 9223372036854775807, 0, 0, ERANGE},
  {"-2147483648", -2147483648, 0, 0, 0},
  {"-9223372036854775808", 0x8000000000000000, 0, 0, 0},
  {"-9223372036854775809", 0x8000000000000000, 0, 0, ERANGE},
  {"0x112233445566778899z", 9223372036854775807, 16, 'z', ERANGE},
  {"0xFFFFFFFFFFFF00FF" , 9223372036854775807, 0, 0, ERANGE},
#endif
  {NULL, 0, 0, 0, 0},

  /* Then unsigned.  */
  {"  0", 0, 0, 0, 0},
  {"0xffffffffg", 0xffffffff, 0, 'g', 0},
#if LONG_MAX == 0x7fffffff
  {"-0xfedcba98", 0x01234568, 0, 0, 0},
  {"0xf1f2f3f4f5", 0xffffffff, 0, 0, ERANGE},
  {"-0x123456789", 0xffffffff, 0, 0, ERANGE},
#else
  {"0xffffffffffffffffg", 0xffffffffffffffff, 0, 'g', 0},
  {"-0xfedcba987654321", 0xf0123456789abcdf, 0, 0, 0},
  {"0xf1f2f3f4f5f6f7f8f9", 0xffffffffffffffff, 0, 0, ERANGE},
  {"-0x123456789abcdef01", 0xffffffffffffffff, 0, 0, ERANGE},
#endif
  {NULL, 0, 0, 0, 0},
  };

/* Prototypes for local functions.  */
static void expand (char *dst, int c);

int
main (void)
{
  register const struct ltest *lt;
  char *ep;
  int status = 0;
  int save_errno;

  for (lt = tests; lt->str != NULL; ++lt)
    {
      register long int l;

      errno = 0;
      l = strtol (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtol(\"%s\", , %d) test %u",
	      lt->str, lt->base, (unsigned int) (lt - tests));
      if (l == (long int) lt->expect && *ep == lt->left
	  && save_errno == lt->err)
	puts("\tOK");
      else
	{
	  puts("\tBAD");
	  if (l != (long int) lt->expect)
	    printf("  returns %ld, expected %ld\n",
		   l, (long int) lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s)  instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  for (++lt; lt->str != NULL; lt++)
    {
      register unsigned long int ul;

      errno = 0;
      ul = strtoul (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtoul(\"%s\", , %d) test %u",
	      lt->str, lt->base, (unsigned int) (lt - tests));
      if (ul == lt->expect && *ep == lt->left && save_errno == lt->err)
	puts("\tOK");
      else
	{
	  puts ("\tBAD");
	  if (ul != lt->expect)
	    printf ("  returns %lu, expected %lu\n",
		    ul, lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s) instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  return status ? EXIT_FAILURE : EXIT_SUCCESS;
}

static void
expand (dst, c)
     char *dst;
     int c;
{
  if (isprint (c))
    {
      dst[0] = c;
      dst[1] = '\0';
    }
  else
    (void) sprintf (dst, "%#.3o", (unsigned int) c);
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-strtoll.c010064400000000000000000000112571173363231000166220ustar00/* My bet is this was written by Chris Torek.
   I reformatted and ansidecl-ized it, and tweaked it a little.  */

#include 
#include 
#include 
#include 
#include 
#include 

struct ltest
  {
    const char *str;		/* Convert this.  */
    unsigned long long int expect;	/* To get this.  */
    int base;			/* Use this base.  */
    char left;			/* With this left over.  */
    int err;			/* And this in errno.  */
  };
static const struct ltest tests[] =
  {
  /* First, signed numbers:  */
  /* simple... */
  {"123", 123, 0, 0, 0},
  {"+123", 123, 0, 0, 0},
  {"  123", 123, 0, 0, 0},
  {" 123 ", 123, 0, ' ', 0},
  {"   -17", -17, 0, 0, 0},

  /* implicit base... */
  {"0123", 0123, 0, 0, 0},
  {"0123a", 0123, 0, 'a', 0},
  {"01239", 0123, 0, '9', 0},
  {"0x123", 0x123, 0, 0, 0},
  {"-0x123", -0x123, 0, 0, 0},
  {"0x0xc", 0, 0, 'x', 0},
  {" +0x123fg", 0x123f, 0, 'g', 0},

  /* explicit base... */
  {"123", 0x123, 16, 0, 0},
  {"0x123", 0x123, 16, 0, 0},
  {"123", 0123, 8, 0, 0},
  {"0123", 0123, 8, 0, 0},
  {"0123", 123, 10, 0, 0},
  {"0x123", 0, 10, 'x', 0},

  /* case insensitivity... */
  {"abcd", 0xabcd, 16, 0, 0},
  {"AbCd", 0xabcd, 16, 0, 0},
  {"0xABCD", 0xabcd, 16, 0, 0},
  {"0Xabcd", 0xabcd, 16, 0, 0},

  /* odd bases... */
  {"0xyz", 33 * 35 + 34, 35, 'z', 0},
  {"yz!", 34 * 36 + 35, 36, '!', 0},
  {"-yz", -(34*36 + 35), 36, 0, 0},
  {"GhI4", ((16*20 + 17)*20 + 18)*20 + 4, 20, 0, 0},

  /* special case for the 32-bit version of strtoll,
     from a ncftp configure test */
  {"99000000001", 1000000000ll * 99ll + 1ll, 0, 0},

  /* extremes... */
  {"9223372036854775807", 9223372036854775807ll, 0, 0, 0},
  {"9223372036854775808", 9223372036854775807ll, 0, 0, ERANGE},
  {"922337203685477580777", 9223372036854775807ll, 0, 0, ERANGE},
  {"9223372036854775810", 9223372036854775807ll, 0, 0, ERANGE},
  {"-2147483648", -2147483648ll, 0, 0, 0},
  {"-9223372036854775808", -9223372036854775807ll - 1, 0, 0, 0},
  {"-9223372036854775809", -9223372036854775807ll - 1, 0, 0, ERANGE},
  {"0x112233445566778899z", 9223372036854775807ll, 16, 'z', ERANGE},
  {"0xFFFFFFFFFFFF00FF" , 9223372036854775807ll, 0, 0, ERANGE},
  {NULL, 0, 0, 0, 0},

  /* Then unsigned.  */
  {"  0", 0, 0, 0, 0},
  {"0xffffffffg", 0xffffffff, 0, 'g', 0},
  {"0xffffffffffffffffg", 0xffffffffffffffffull, 0, 'g', 0},
  {"-0xfedcba987654321", 0xf0123456789abcdfull, 0, 0, 0},
  {"0xf1f2f3f4f5f6f7f8f9", 0xffffffffffffffffull, 0, 0, ERANGE},
  {"-0x123456789abcdef01", 0xffffffffffffffffull, 0, 0, ERANGE},
  {NULL, 0, 0, 0, 0},
  };

/* Prototypes for local functions.  */
static void expand (char *dst, int c);

int
main (void)
{
  register const struct ltest *lt;
  char *ep;
  int status = 0;
  int save_errno;

  for (lt = tests; lt->str != NULL; ++lt)
    {
      register long long int l;

      errno = 0;
      l = strtoll (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtoll(\"%s\", , %d) test %u",
	      lt->str, lt->base, (unsigned int) (lt - tests));
      if (l == (long long int) lt->expect && *ep == lt->left
	  && save_errno == lt->err)
	puts("\tOK");
      else
	{
	  puts("\tBAD");
	  if (l != (long long int) lt->expect)
	    printf("  returns %lld, expected %lld\n",
		   l, (long long int) lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s)  instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  for (++lt; lt->str != NULL; lt++)
    {
      register unsigned long long int ul;

      errno = 0;
      ul = strtoull (lt->str, &ep, lt->base);
      save_errno = errno;
      printf ("strtoull(\"%s\", , %d) test %u",
	      lt->str, lt->base, (unsigned int) (lt - tests));
      if (ul == lt->expect && *ep == lt->left && save_errno == lt->err)
	puts("\tOK");
      else
	{
	  puts ("\tBAD");
	  if (ul != lt->expect)
	    printf ("  returns %llu, expected %llu\n",
		    ul, lt->expect);
	  if (lt->left != *ep)
	    {
	      char exp1[5], exp2[5];
	      expand (exp1, *ep);
	      expand (exp2, lt->left);
	      printf ("  leaves '%s', expected '%s'\n", exp1, exp2);
	    }
	  if (save_errno != lt->err)
	    printf ("  errno %d (%s) instead of %d (%s)\n",
		    save_errno, strerror (save_errno),
		    lt->err, strerror (lt->err));
	  status = 1;
	}
    }

  return status ? EXIT_FAILURE : EXIT_SUCCESS;
}

static void
expand (dst, c)
     char *dst;
     int c;
{
  if (isprint (c))
    {
      dst[0] = c;
      dst[1] = '\0';
    }
  else
    (void) sprintf (dst, "%#.3o", (unsigned int) c);
}
dietlibc-0.33~cvs20120325/test/stdlib/tst-system.c010064400000000000000000000017231173363231000164400ustar00/* Copyright (C) 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper , 2002.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include 


int main (void)
{
  return system (":");
}


dietlibc-0.33~cvs20120325/test/strcasecmp.c010064400000000000000000000007261173363230200151720ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  char buf[100]="fNord";
  char buf2[100]="fnOrt";
  if (strcasecmp(buf,buf)) die("strcmp sais a != a");
  if (strcasecmp(buf,buf2)>=0) die("strcmp said fnord > fnort");
  if (strcasecmp(buf2,buf)<=0) die("strcmp said fnort < fnord");
  if (strcasecmp("Host","hostbasedauthentication")==0) die("strcmp said a == abc");
  return 0;
}
dietlibc-0.33~cvs20120325/test/strchr.c010064400000000000000000000007021173363230200143250ustar00#include 
#include 
#include 
#include 

int main() {
  char* p="/opt/diet/bin:/home/leitner/bin:/usr/local/bin:/opt/cross/bin:/usr/local/sbin:/usr/bin:/sbin:/bin:/usr/sbin:/usr/X11R6/bin:/opt/teTeX/bin:/opt/qt-4.3.2/bin:/opt/kde-3.5/bin:/usr/X11R7/bin:/opt/mono/bin";
  assert(strchr(p,':')==p+13);
  assert(strchr(p="fnord",'\0')==p+5);
  assert(strchr(p,'r')==p+3);
  assert(strchr(p,'x')==0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/strcmp.c010064400000000000000000000014341173363230200143330ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  char buf[100]="fnord";
  char buf2[100]="fnort";
  if (strcmp(buf,buf)) die("strcmp said a != a");
  if (strcmp(buf,buf2)>=0) die("strcmp said fnord > fnort");
  if (strcmp(buf2,buf)<=0) die("strcmp said fnort < fnord");
  if (strcmp(buf+1,buf2+1)>=0) die("unaligned strcmp is broken 1");
  if (strcmp(buf+2,buf2+2)>=0) die("unaligned strcmp is broken 2");
  if (strcmp(buf+3,buf2+3)>=0) die("unaligned strcmp is broken 3");
  if (strcmp("mäh","meh")<0) die("strcmp uses signed arithmetic");
  if (strcmp("foo","foobar")>=0) die("prefix handling broken in strcmp 1");
  if (strcmp("foobar","foo")<=0) die("prefix handling broken in strcmp 2");
  return 0;
}
dietlibc-0.33~cvs20120325/test/strcpy.c010064400000000000000000000003561173363230200143510ustar00#include 
#include 

int main() {
  char buf[128];
  size_t i;
  for (i=0; i<100; ++i) {
    memset(buf,'x',sizeof(buf));
    strcpy(buf+i,"fnord");
    assert(!strcmp(buf+i,"fnord"));
    assert(buf[i+6]=='x');
  }
}
dietlibc-0.33~cvs20120325/test/string/.cvsignore010064400000000000000000000001741173363231000161640ustar00memccpy
memchr
memcmp
memcpy
mempcpy
memrchr
strcasecmp
strcmp
strcspn
strlen
strncat
strncpy
strpbrk
strrchr
strspn
strstr
dietlibc-0.33~cvs20120325/test/string/Makefile010064400000000000000000000005561173363231000156300ustar00DIET=diet
CC=gcc
CFLAGS=-Wall -fno-builtin

all: stringtest

TESTPROGRAMS=memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr \
strspn strcspn strpbrk mempcpy

stringtest: $(TESTPROGRAMS)

%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

mempcpy: mempcpy.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@ -lcompat

clean:
	rm -f $(TESTPROGRAMS)

dietlibc-0.33~cvs20120325/test/string/memccpy.c010064400000000000000000000005431173363231000157650ustar00#include 
#include 

int
main ()
{
	char buf[100];
	memset (buf, 0x1, sizeof (buf));
	assert (memccpy (buf, "Hello World\n", ' ', sizeof (buf)));
	assert (buf[6] == 0x1);
	assert (!*(char *) (memccpy (buf, "Hello, World", 0, sizeof (buf))-1));
	assert (buf[13] == 0x1);
	assert (!memccpy (buf, "Hello, World\n", 0, 5));
	return (0);
}
dietlibc-0.33~cvs20120325/test/string/memchr.c010064400000000000000000000004271173363231000156040ustar00#include 
#include 

int main() {
  const char* test="blubber";
  assert(memchr("aaaa",'x',4)==0);
  assert(memchr(0,'x',0)==0);
  assert(memchr(test,'u',7) == test+2);
  assert(memchr(test,'b',7)==test);
  assert(memchr(test+6,'r',1)==test+6);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/memcmp.c010064400000000000000000000003141173363231000156020ustar00#include 
#include 

int main() {
  const char* test="blubber";
  assert(memcmp(test,"blubber",8)==0);
  assert(memcmp(test,"fnord",5)<0);
  assert(memcmp(test,0,0)==0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/memcpy.c010064400000000000000000000022131173363231000156160ustar00#include 
#include 
#include 

#define WO	(__WORDSIZE/8)

int main() {
  size_t const	LENS[] = {
    1, 2, 3, 4, 5, 6, 7, 8,
    WO  -3, WO  -2, WO  -1,  WO,   WO  +1, WO  +2, WO  +3, WO  +4,
    WO*2-3, WO*2-2, WO*2-1,  WO*2, WO*2+1, WO*2+2, WO*2+3, WO*2+4,
    WO*3-3, WO*3-2, WO*3-1,  WO*3, WO*3+1, WO*3+2, WO*3+3, WO*3+4,
    (size_t)(-1) };

  size_t i,j;
  size_t const *len;
  char test[100]="blubber";

  assert(memcpy(test,"blubber",8)==test);
  assert(!memcmp(test,"blubber",8));
  assert(memcpy(0,0,0)==0);
  assert(memcpy(test,"foobar",3) && test[2]=='o');

  /* test all possible alignments of src and destination in combination with
   * some interesting lengths */
  for (len=LENS+0; *len!=(size_t)(-1); ++len) {
    unsigned char	src[WO * 5];

    for (i=0; i<*len + WO; ++i)
      src[i] = i;

    for (i=MIN(WO,*len); i>0;) {
      --i;
      
      for (j=MIN(WO,*len); j>0;) {
	unsigned char	dst[WO * 5];
	size_t k;
	--j;

	for (k=0; k<*len; ++k)
	  dst[j+k]=src[i+k]+1;
			  
	assert(memcpy(dst+j, src+i, *len)==dst+j);

	for (k=0; k<*len; ++k)
	  assert(dst[j+k]==src[i+k]);
      }
    }
  }

  return 0;
}
dietlibc-0.33~cvs20120325/test/string/mempcpy.c010064400000000000000000000007611173363231000160040ustar00#define _GNU_SOURCE
#include 
#include 
#include 

int main() {
  char test[100]="blubber";

  assert(mempcpy(test,"foo",3)==test+3 && !strcmp(test,"foobber"));
  assert(mempcpy(test,"foo",4)==test+4 && !strcmp(test,"foo"));

  assert(stpcpy(test,"foo")==test+3 && !strcmp(test,"foo"));

  stpncpy(test,"bar",2);
  assert(stpncpy(test,"bar",2)==test+2 && !strcmp(test,"bao"));
  assert(stpncpy(test,"xyz",6)==test+3 && !memcmp(test,"xyz\0\0\0",6));

  return 0;
}
dietlibc-0.33~cvs20120325/test/string/memrchr.c010064400000000000000000000004621173363231000157650ustar00#define _GNU_SOURCE
#include 
#include 

int main() {
  const char* test="blubber";
  assert(memrchr("aaaa",'x',4)==0);
  assert(memrchr(0,'x',0)==0);
  assert(memrchr(test,'u',7) == test+2);
  assert(memrchr(test,'b',7)==test+4);
  assert(memrchr(test+6,'r',1)==test+6);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/runtests.sh010064400000000000000000000004261173363231000164070ustar00#!/bin/sh

TESTPROGRAMS="memccpy memchr memcmp memcpy memrchr strcasecmp strcmp strlen strncat strncpy strrchr strstr strspn strcspn strpbrk"

for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
 done 

dietlibc-0.33~cvs20120325/test/string/strcasecmp.c010064400000000000000000000007261173363231000164770ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  char buf[100]="fNord";
  char buf2[100]="fnOrt";
  if (strcasecmp(buf,buf)) die("strcmp sais a != a");
  if (strcasecmp(buf,buf2)>=0) die("strcmp said fnord > fnort");
  if (strcasecmp(buf2,buf)<=0) die("strcmp said fnort < fnord");
  if (strcasecmp("Host","hostbasedauthentication")==0) die("strcmp said a == abc");
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strcmp.c010064400000000000000000000005641173363231000156430ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  char buf[100]="fnord";
  char buf2[100]="fnort";
  if (strcmp(buf,buf)) die("strcmp say a != a");
  if (strcmp(buf,buf2)>=0) die("strcmp said fnord > fnort");
  if (strcmp(buf2,buf)<=0) die("strcmp said fnort < fnord");
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strcspn.c010064400000000000000000000002451173363231000160230ustar00#include 
#include 
#include 

int main() {
  assert(strcspn("foo:bar:",":")==3);
  assert(strcspn("foo:bar:","=of")==0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strlen.c010064400000000000000000000013411173363231000156340ustar00#include 
#include 
#include 

/* make it large enough to test all possible alignments, number of trailing
 * bytes and word sizes  */
#define BUFLEN	(__WORDSIZE/8 * 4)

int main() {
  /* will hold the string, the trailing zero and a test pattern */
  char		buf[BUFLEN + 1 + __WORDSIZE/8];
  size_t	len;

  assert(strlen("")==0);

  for (len=0; len
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  char buf[100]="fnord";
  strncat(buf,"foo",0);
  if (strcmp(buf,"fnord")) die("strncat did not work for length 0");
  strncat(buf,"foo",2);
  if (strcmp(buf,"fnordfo")) die("strncat did not copy n bytes");
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strncpy.c010064400000000000000000000004441173363231000160320ustar00#include 
#include 
#include 

int main() {
  char buf[100];
  assert(strncpy(buf,"fnord",6)==buf);
  assert(!strcmp(buf,"fnord"));
  memset(buf,23,sizeof buf);
  assert(strncpy(buf,"fnord",5)==buf);
  assert(!memcmp(buf,"fnord",5) && buf[5]==23);

  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strpbrk.c010064400000000000000000000003231173363231000160130ustar00#include 
#include 
#include 

int main() {
  const char* c;
  c="fnord:foo:bar:baz"; assert(strpbrk(c,":")==c+5);
  c=":/::/:foo/bar:baz"; assert(strpbrk(c,"/:")==c);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strrchr.c010064400000000000000000000002771173363231000160230ustar00#include 
#include 

int main() {
  const char* x="foo bar baz";
  assert(strrchr(x,'z')==x+10);
  assert(strrchr(x,' ')==x+7);
  assert(strrchr(x,'x')==0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strspn.c010064400000000000000000000002461173363231000156610ustar00#include 
#include 
#include 

int main() {
  assert(strspn("foo:bar:",":=b")==0);
  assert(strspn("foo:bar:",":=of")==4);
  return 0;
}
dietlibc-0.33~cvs20120325/test/string/strstr.c010064400000000000000000000004141173363231000156660ustar00#include 
#include 

int main() {
  char buf[]="foo bar baz";
  assert(strstr(buf,"bar")==buf+4);
  assert(strstr(buf,"baz")==buf+8);
  assert(strstr(buf,"barney")==0);
  assert(strstr(buf,"foo")==buf);
  assert(strstr(buf,"")==buf);
  return 0;
}
dietlibc-0.33~cvs20120325/test/strncat.c010064400000000000000000000005461173363230200145040ustar00#include 
#include 
#include 

void die(const char* message) {
  puts(message);
  exit(1);
}

int main() {
  char buf[100]="fnord";
  strncat(buf,"foo",0);
  if (strcmp(buf,"fnord")) die("strncat did not work for length 0");
  strncat(buf,"foo",2);
  if (strcmp(buf,"fnordfo")) die("strncat did not copy n bytes");
  return 0;
}
dietlibc-0.33~cvs20120325/test/strncpy.c010064400000000000000000000004431173363230200145240ustar00#include 
#include 
#include 

int main() {
  char buf[100];
  assert(strncpy(buf,"fnord",6)==buf);
  assert(!strcmp(buf,"fnord"));
  memset(buf,23,sizeof buf);
  assert(strncpy(buf,"fnord",5)==buf);
  assert(!memcmp(buf,"fnord",5) && buf[5]==23);
  return 0;
}
dietlibc-0.33~cvs20120325/test/strnlen.c010064400000000000000000000002171173363230200145060ustar00#define _GNU_SOURCE
#include 
#include 

int main() {
  assert(strnlen("fnord",3)==3);
  assert(strnlen("fnord",17)==5);
}
dietlibc-0.33~cvs20120325/test/strptime.c010064400000000000000000000006551173363230200146760ustar00#define _XOPEN_SOURCE
#include 
#include 

int main() {
  char buf[1024];
  struct tm* t;
  time_t T=time(0);
  t=localtime(&T);

  strftime(buf,sizeof(buf),"%c",t);
  printf("%s\n",strptime(buf,"%c",t));

  printf("%s\n",strptime("Tue, 31 May 2005 14:16:16 GMT","%a, %d %b %Y %T",t));
  printf("%2d.%02d.%d %2d:%02d:%02d\n",t->tm_mday,t->tm_mon+1,t->tm_year+1900,t->tm_hour,t->tm_min,t->tm_sec);

  return 0;
}
dietlibc-0.33~cvs20120325/test/strrchr.c010064400000000000000000000002771173363230200145160ustar00#include 
#include 

int main() {
  const char* x="foo bar baz";
  assert(strrchr(x,'z')==x+10);
  assert(strrchr(x,' ')==x+7);
  assert(strrchr(x,'x')==0);
  return 0;
}
dietlibc-0.33~cvs20120325/test/strstr.c010064400000000000000000000004141173363230200143610ustar00#include 
#include 

int main() {
  char buf[]="foo bar baz";
  assert(strstr(buf,"bar")==buf+4);
  assert(strstr(buf,"baz")==buf+8);
  assert(strstr(buf,"barney")==0);
  assert(strstr(buf,"foo")==buf);
  assert(strstr(buf,"")==buf);
  return 0;
}
dietlibc-0.33~cvs20120325/test/strtol.c010064400000000000000000000101021173363230200143420ustar00/* I took these tests from glibc. -Felix */

#include 
#include 
#include 
#include 

int main() {
  char* c, *s;

  assert(strtol(s="123",&c,0)==123 && c==s+3);
  assert(strtol(s="+123",&c,0)==123 && c==s+4);
  assert(strtol(s="  123",&c,0)==123 && c==s+5);
  assert(strtol(s=" 123 ",&c,0)==123 && c==s+4);
  assert(strtol(s="   -17",&c,0)==-17 && c==s+6);

  assert(strtol(s="0123",&c,0)==0123 && c==s+4);
  assert(strtol(s="0123a",&c,0)==0123 && c==s+4);
  assert(strtol(s="01239",&c,0)==0123 && c==s+4);
  assert(strtol(s="0x123",&c,0)==0x123 && c==s+5);
  assert(strtol(s="-0x123",&c,0)==-0x123 && c==s+6);
  assert(strtol(s="0x0xc",&c,0)==0 && c==s+3);
  assert(strtol(s=" +0x123fg",&c,0)==0x123f && c==s+8);

  assert(strtol(s="123",&c,16)==0x123 && c==s+3);
  assert(strtol(s="0x123",&c,16)==0x123 && c==s+5);
  assert(strtol(s="123",&c,8)==0123 && c==s+3);
  assert(strtol(s="0123",&c,8)==0123 && c==s+4);
  assert(strtol(s="0123",&c,10)==123 && c==s+4);
  assert(strtol(s="0x123",&c,10)==0 && c==s+1);

  assert(strtol(s="abcd",&c,16)==0xabcd && c==s+4);
  assert(strtol(s="AbCd",&c,16)==0xabcd && c==s+4);
  assert(strtol(s="0xABCD",&c,16)==0xabcd && c==s+6);
  assert(strtol(s="0Xabcd",&c,16)==0xabcd && c==s+6);

  assert(strtol(s="0xyz",&c,35)==33*35+34 && c==s+3);
  assert(strtol(s="yz!",&c,36)==34*36+35 && c==s+2);
  assert(strtol(s="-yz",&c,36)==-(34*36 + 35) && c==s+3);
  assert(strtol(s="GhI4",&c,20)==((16*20 + 17)*20 + 18)*20 + 4 && c==s+4);

#if LONG_MAX == 0x7fffffff
  assert(strtol(s="2147483647",&c,0)==2147483647 && c==s+10 && errno==0);
  assert(strtol(s="2147483648",&c,0)==2147483647 && c==s+10 && errno==ERANGE);
  assert(strtol(s="214748364888",&c,0)==2147483647 && c==s+12 && errno==ERANGE);
  assert(strtol(s="2147483650",&c,0)==2147483647 && c==s+10 && errno==ERANGE);
  /* glibc will actually fail this because they don't set errno to 0
   * when returning 0x8000000 in non-failure cases. */
  assert(strtol(s="-2147483648",&c,0)==0x80000000 && c==s+11 && errno==0);
  assert(strtol(s="-2147483649",&c,0)==0x80000000 && c==s+11 && errno==ERANGE);
  assert(strtol(s="0x1122334455z",&c,16)==2147483647 && c==s+12 && errno==ERANGE);
#else
  assert(strtol(s="9223372036854775807",&c,0)==9223372036854775807 && c==s+19 && errno==0);
  assert(strtol(s="9223372036854775808",&c,0)==9223372036854775807 && c==s+19 && errno==ERANGE);
  assert(strtol(s="922337203685477580777",&c,0)==9223372036854775807 && c==s+21 && errno==ERANGE);
  assert(strtol(s="9223372036854775810",&c,0)==9223372036854775807 && c==s+19 && errno==ERANGE);
  /* dietlibc would also fail this because we don't set errno to 0
   * when returning 0x8000000 in non-failure cases on 64-bit platforms.
   * POSIX says: The strtol() function shall not change the setting of errno if successful. */
  errno=0; assert(strtol(s="-2147483648",&c,0)==-2147483648 && c==s+11 && errno==0);
  assert(strtol(s="-9223372036854775808",&c,0)==0x8000000000000000 && c==s+20 && errno==0);
  assert(strtol(s="-9223372036854775809",&c,0)==0x8000000000000000 && c==s+20 && errno==ERANGE);
  assert(strtol(s="0x112233445566778899z",&c,0)==9223372036854775807 && c==s+20 && errno==ERANGE);
  assert(strtol(s="0xFFFFFFFFFFFF00FF",&c,0)==9223372036854775807 && c==s+18 && errno==ERANGE);
#endif

  assert(strtoul(s="  0",&c,0)==0 && c==s+3);
  errno=0; assert(strtoul(s="0xffffffffg",&c,0)==0xffffffff && c==s+10 && errno==0);
#if LONG_MAX == 0x7fffffff
  assert(strtoul(s="-0xfedcba98",&c,0)==0x01234568 && c==s+11 && errno==0);
  assert(strtoul(s="0xf1f2f3f4f5",&c,0)==0xffffffff && c==s+12 && errno==ERANGE);
  assert(strtoul(s="-0x123456789",&c,0)==0xffffffff && c==s+12 && errno==ERANGE);
#else
  assert(strtoul(s="0xffffffffffffffffg",&c,0)==0xffffffffffffffff && c==s+18 && errno==0);
  assert(strtoul(s="-0xfedcba987654321",&c,0)==0xf0123456789abcdf && c==s+18 && errno==0);
  assert(strtoul(s="0xf1f2f3f4f5f6f7f8f9",&c,0)==0xffffffffffffffff && c==s+20 && errno==ERANGE);
  assert(strtoul(s="-0x123456789abcdef01",&c,0)==0xffffffffffffffff && c==s+20 && errno==ERANGE);
#endif

  assert(strtoul(s="0x,",&c,0)==0 && c==s+1);
  return 0;
}

dietlibc-0.33~cvs20120325/test/syscall.c010064400000000000000000000003621173363230200144740ustar00#include 
#include 
#include 
#include 

int main() {
  int a,b;
  syscall(__NR_write,1,"foo\n",4);
  a=syscall(__NR_write,23,"bar\n",4);
  b=errno;
  assert(a==-1);
  assert(b==EBADF);
  return 0;
}
dietlibc-0.33~cvs20120325/test/sysenter.c010064400000000000000000000007121173363230200146750ustar00#include 
#include 
#include 

extern char **environ;

int main() {
  register struct elf_aux {
    unsigned long type, value;
  } *x;
  int i;
  for (i=0; environ[i]; ++i) ;
  for (x=(struct elf_aux*)(environ+i+1); x->type; ++x) {
    printf("%d %x\n",x->type,x->value);
    if (x->type==AT_PAGESZ)
      printf("pagesize %d\n",x->value);
    else if (x->type==AT_SYSINFO)
      printf("vsyscall %p\n",x->value);
  }
  return 0;
}
dietlibc-0.33~cvs20120325/test/test-getlongopt.c010064400000000000000000000015011173363230200161550ustar00#define _GNU_SOURCE
#include 
#include 
#include 

int test1;

struct option longopts[] = {
	{"long1", 0, 0, 'a'},
	{"long2", 0, &test1, 5},
	{"long3", 1, 0, 'b'},
	{"long4", 2, 0, 'c'},
	{ 0 }
};

int main(int argc, char **argv) {
	int longidx;
	int opt;
	char *b = "foo";
	char *c = "bar";
	int aseen = 0;
	
	while ((opt = getopt_long(argc, argv, "-ab:c::", longopts, &longidx)) != -1) {
		switch (opt) {
			case 'a':
				printf("a\n");
				aseen++;
				break;
			case 'b':
				printf("b\n");
				b = optarg;
				break;
			case 'c':
				printf("c\n");
				if (optarg)
					c = optarg;
				else
					c = "baz";
				break;
			case 0:
				printf("Null arg\n");
				break;
			default:
				printf("opt: %d\n", opt);
		}
	}

	printf("b: %s\nc: %s\naseen: %d\ntest1: %d\n", b, c, aseen, test1);
	return 0;
}

dietlibc-0.33~cvs20120325/test/test-newfnmatch.c010064400000000000000000000105121173363230200161270ustar00#include 
#include 
#include 
#include 

/*
 * xlat / printflags adapted from strace
 * http://www.liacs.nl/~wichert/strace/
 */

#define FLAG(f)	{ f, #f }

struct xlat {
  int val;
  char *str;
} fnmatch_flags[] = {
  FLAG(FNM_NOESCAPE),
  FLAG(FNM_PATHNAME),
  FLAG(FNM_PERIOD),
  FLAG(FNM_LEADING_DIR),
  FLAG(FNM_CASEFOLD),
  {0,            NULL},
};

static void printflags(const struct xlat *map, int flags) {
  char * sep;

  if (! flags) {
    printf("0");
    return;
  }

  sep = "";
  for (; map->str; map++) {
    if (map->val && (flags & map->val) == map->val) {
      printf("%s%s", sep, map->str);
      sep = "|";
      flags &= ~(map->val);
    }
  }
  if (flags) printf("%sunknown=%#x", sep, flags);
}

/*
 * tests harness adapted from glibc testfnm.c
 */
struct {
    const char *pattern;
    const char *string;
    int flags;
    int expected;
} tests[] = {
    /* begin dietlibc tests */
    { "*.c", "foo.c", 0, 0 },
    { "*.c", ".c", 0, 0 },
    { "*.a", "foo.c", 0, FNM_NOMATCH },
    { "*.c", ".foo.c", 0, 0 },
    { "*.c", ".foo.c", FNM_PERIOD, FNM_NOMATCH },
    { "*.c", "foo.c", FNM_PERIOD, 0 },
    { "a\\*.c", "a*.c", FNM_NOESCAPE, FNM_NOMATCH },
    { "a\\*.c", "ax.c", 0, FNM_NOMATCH },
    { "a[xy].c", "ax.c", 0, 0 },
    { "a[!y].c", "ax.c", 0, 0 },
    { "a[a/z]*.c", "a/x.c", FNM_PATHNAME, FNM_NOMATCH },
    { "a/*.c", "a/x.c", FNM_PATHNAME, 0 },
    { "a*.c", "a/x.c", FNM_PATHNAME, FNM_NOMATCH },
    { "*/foo", "/foo", FNM_PATHNAME, 0 },
    { "*.c", "foo.C", FNM_CASEFOLD, 0 },
    { "-O[01]", "-O1", 0, 0 },
    { "[[?*\\]", "\\", 0, 0 },
    { "[]?*\\]", "]", 0, 0 },
    /* initial right-bracket tests */
    { "[!]a-]", "b", 0, 0 },
    { "[]-_]", "^", 0, 0 },   /* range: ']', '^', '_' */
    { "[!]-_]", "X", 0, 0 },
    { "??", "-", 0, FNM_NOMATCH },
    /* begin glibc tests */
    { "*LIB*", "lib", FNM_PERIOD, FNM_NOMATCH },
    { "*LIB*", "lib", FNM_CASEFOLD|FNM_PERIOD, 0 },
    { "a[/]b", "a/b", 0, 0 },
    { "a[/]b", "a/b", FNM_PATHNAME, FNM_NOMATCH },
    { "[a-z]/[a-z]", "a/b", 0, 0 },
    { "*", "a/b", FNM_FILE_NAME, FNM_NOMATCH },
    { "*[/]b", "a/b", FNM_FILE_NAME, FNM_NOMATCH },
    { "*[b]", "a/b", FNM_FILE_NAME, FNM_NOMATCH },
    { "[*]/b", "a/b", 0, FNM_NOMATCH },
    { "[*]/b", "*/b", 0, 0 },
    { "[?]/b", "a/b", 0, FNM_NOMATCH },
    { "[?]/b", "?/b", 0, 0 },
    { "[[a]/b", "a/b", 0, 0 },
    { "[[a]/b", "[/b", 0, 0 },
    { "\\*/b", "a/b", 0, FNM_NOMATCH },
    { "\\*/b", "*/b", 0, 0 },
    { "\\?/b", "a/b", 0, FNM_NOMATCH },
    { "\\?/b", "?/b", 0, 0 },
    { "[/b", "[/b", 0, FNM_NOMATCH },
    { "\\[/b", "[/b", 0, 0 },
    { "??/b", "aa/b", 0, 0 },
    { "???b", "aa/b", 0, 0 },
    { "???b", "aa/b", FNM_PATHNAME, FNM_NOMATCH },
    { "?a/b", ".a/b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "a/?b", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "*a/b", ".a/b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "a/*b", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "[.]a/b", ".a/b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "a/[.]b", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "*/?", "a/b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { "?/*", "a/b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { ".*/?", ".a/b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { "*/.?", "a/.b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { "*/*", "a/.b", FNM_PATHNAME|FNM_PERIOD, FNM_NOMATCH },
    { "*?*/*", "a/.b", FNM_PERIOD, 0 },
    { "*[.]/b", "a./b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { "*[[:alpha:]]/*[[:alnum:]]", "a/b", FNM_PATHNAME, 0 },
    { "*[![:digit:]]*/[![:d-d]", "a/b", FNM_PATHNAME, 0 },
    { "*[![:digit:]]*/[[:d-d]", "a/[", FNM_PATHNAME, 0 },
    { "*[![:digit:]]*/[![:d-d]", "a/[", FNM_PATHNAME, FNM_NOMATCH },
    { "a?b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { "a*b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 },
    { "a[.]b", "a.b", FNM_PATHNAME|FNM_PERIOD, 0 },
};

int main(void) {
    int i;
    unsigned int failed = 0;

    for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
        int r;

        r = fnmatch(tests[i].pattern, tests[i].string, tests[i].flags);
	if (r != tests[i].expected) {
            failed++;
            printf("fail - fnmatch(\"%s\", \"%s\", ",
                    tests[i].pattern, tests[i].string);
            printflags(fnmatch_flags, tests[i].flags);
            printf(") => %d (expected %d)\n", r, tests[i].expected);
	}
    }

    exit(failed != 0);
}
dietlibc-0.33~cvs20120325/test/testandset.c010064400000000000000000000002041173363230200151730ustar00#include 

int main()
{
	long foo = 0;
	__testandset (&foo);
	assert (foo);
	assert (__testandset (&foo));
	return (0);
}
dietlibc-0.33~cvs20120325/test/time/.cvsignore010064400000000000000000000000611173363231000156070ustar00tst-mktime
tst-posixtz
tst-strftime
tst-strptime
dietlibc-0.33~cvs20120325/test/time/Makefile010064400000000000000000000003211173363231000152460ustar00DIET=diet
CC=gcc
CFLAGS=-Wall

all: timetest

TESTPROGRAMS=tst-strptime tst-mktime tst-posixtz tst-strftime

timetest: $(TESTPROGRAMS)

%: %.c
	$(DIET) $(CC) $(CFLAGS) $^ -o $@

clean:
	rm -f $(TESTPROGRAMS)

dietlibc-0.33~cvs20120325/test/time/runtests.sh010064400000000000000000000003231173363231000160330ustar00#!/bin/sh

TESTPROGRAMS="tst-strptime tst-mktime tst-posixtz tst-strftime"

for p in $TESTPROGRAMS; do
echo "---";echo testing $p;echo "---"
 ./$p ||  ( echo TESTCASE $p exited non-zero 1>&2 ; sleep 5 )
done 


dietlibc-0.33~cvs20120325/test/time/tst-mktime.c010064400000000000000000000025271173363231000160620ustar00#include 
#include 
#include 
#include 

int
main (void)
{
  struct tm time_str, *tm;
  time_t t;
  char daybuf[20];
  int result;

  time_str.tm_year = 2001 - 1900;
  time_str.tm_mon = 7 - 1;
  time_str.tm_mday = 4;
  time_str.tm_hour = 0;
  time_str.tm_min = 0;
  time_str.tm_sec = 1;
  time_str.tm_isdst = -1;

  if (mktime (&time_str) == -1)
    {
      (void) puts ("-unknown-");
      result = 1;
    }
  else
    {
      (void) strftime (daybuf, sizeof (daybuf), "%A", &time_str);
      (void) puts (daybuf);
      result = strcmp (daybuf, "Wednesday") != 0;
    }

  setenv ("TZ", "EST+5", 1);
#define EVENING69 1 * 60 * 60 + 2 * 60 + 29
  t = EVENING69;
  tm = localtime (&t);
  if (tm == NULL)
    {
      (void) puts ("localtime returned NULL");
      result = 1;
    }
  else
    {
      time_str = *tm;
      t = mktime (&time_str);
      if (t != EVENING69)
        {
          printf ("mktime returned %ld, expected %d\n",
		  (long) t, EVENING69);
	  result = 1;
        }
      else
        (void) puts ("Dec 31 1969 EST test passed");

      setenv ("TZ", "CET-1", 1);
      t = mktime (&time_str);
      if (t != (time_t) -1)
        {
	  printf ("mktime returned %ld, expected -1\n", (long) t);
	  result = 1;
        }
      else
        (void) puts ("Dec 31 1969 CET test passed");
    }

  return result;
}
dietlibc-0.33~cvs20120325/test/time/tst-posixtz.c010064400000000000000000000041001173363231000163010ustar00#include 
#include 
#include 
#include 

struct
{
  time_t when;
  const char *tz;
  const char *result;
} tests[] =
{
  { 909312849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
    "1998/10/25 21:54:09 dst=1 zone=AEDST" },
  { 924864849L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
    "1999/04/23 20:54:09 dst=0 zone=AEST" },
  { 919973892L, "AEST-10AEDST-11,M10.5.0,M3.5.0",
    "1999/02/26 07:18:12 dst=1 zone=AEDST" },
  { 909312849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
    "1998/10/25 05:54:09 dst=0 zone=EST" },
  { 924864849L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
    "1999/04/23 06:54:09 dst=1 zone=EDT" },
  { 919973892L, "EST+5EDT,M4.1.0/2,M10.5.0/2",
    "1999/02/25 15:18:12 dst=0 zone=EST" },
};

int
main (void)
{
  int result = 0;
  size_t cnt;

  for (cnt = 0; cnt < sizeof (tests) / sizeof (tests[0]); ++cnt)
    {
      char buf[100];
      struct tm *tmp;

      printf ("TZ = \"%s\", time = %ld => ", tests[cnt].tz, tests[cnt].when);
      fflush (stdout);

      setenv ("TZ", tests[cnt].tz, 1);

      tmp = localtime (&tests[cnt].when);

      snprintf (buf, sizeof (buf),
		"%04d/%02d/%02d %02d:%02d:%02d dst=%d zone=%s",
		tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
		tmp->tm_hour, tmp->tm_min, tmp->tm_sec, tmp->tm_isdst,
		tzname[tmp->tm_isdst ? 1 : 0]);

      fputs (buf, stdout);

      if (strcmp (buf, tests[cnt].result) == 0)
	puts (", OK");
      else
	{
	  result = 1;
	  puts (", FAIL");
	}
    }

  setenv ("TZ", "Universal", 1);
  localtime (&tests[0].when);
  printf ("TZ = \"Universal\" daylight %d tzname = { \"%s\", \"%s\" }",
	  daylight, tzname[0], tzname[1]);
  if (! daylight)
    puts (", OK");
  else
    {
      result = 1;
      puts (", FAIL");
    }

  setenv ("TZ", "AEST-10AEDST-11,M10.5.0,M3.5.0", 1);
  tzset ();
  printf ("TZ = \"AEST-10AEDST-11,M10.5.0,M3.5.0\" daylight %d"
	  " tzname = { \"%s\", \"%s\" }", daylight, tzname[0], tzname[1]);
  if (daylight
      && strcmp (tzname[0], "AEST") == 0 && strcmp (tzname[1], "AEDST") == 0)
    puts (", OK");
  else
    {
      result = 1;
      puts (", FAIL");
    }

  return result;
}
dietlibc-0.33~cvs20120325/test/time/tst-strftime.c010064400000000000000000000022671173363231000164320ustar00#include 
#include 
#include 


static struct
{
  const char *fmt;
  size_t min;
  size_t max;
} tests[] =
  {
    { "%2000Y", 2000, 4000 },
    { "%02000Y", 2000, 4000 },
    { "%_2000Y", 2000, 4000 },
    { "%-2000Y", 2000, 4000 },
  };
#define ntests (sizeof (tests) / sizeof (tests[0]))


int main (void) {
  size_t cnt;
  int result = 0;

  time_t tnow = time (NULL);
  struct tm *now = localtime (&tnow);

  for (cnt = 0; cnt < ntests; ++cnt)
    {
      size_t size = 0;
      int res;
      char *buf = NULL;

      do
	{
	  size += 500;
	  buf = (char *) realloc (buf, size);
	  if (buf == NULL)
	    {
	      puts ("out of memory");
	      exit (1);
	    }

	  res = strftime (buf, size, tests[cnt].fmt, now);
	  if (res != 0)
	    break;
	}
      while (size < tests[cnt].max);

      if (res == 0)
	{
	  printf ("%Zu: %s: res == 0 despite size == %Zu\n",
		  cnt, tests[cnt].fmt, size);
	  result = 1;
	}
      else if (size < tests[cnt].min)
	{
	  printf ("%Zu: %s: size == %Zu was enough\n",
		  cnt, tests[cnt].fmt, size);
	  result = 1;
	}
      else
	printf ("%Zu: %s: size == %Zu: OK\n", cnt, tests[cnt].fmt, size);

      free (buf);
    }

  return result;
}

dietlibc-0.33~cvs20120325/test/time/tst-strptime.c010064400000000000000000000112221173363231000164330ustar00/* Test for strptime.
   Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
   This file is part of the GNU C Library.
   Contributed by Ulrich Drepper , 1998.

   The GNU C Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 2.1 of the License, or (at your option) any later version.

   The GNU C Library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#define _XOPEN_SOURCE /* glibc2 needs this */
#include 
#include 
#include 
#include 
#include 


static const struct
{
  const char *locale;
  const char *input;
  const char *format;
  int wday;
  int yday;
  int mon;
  int mday;
} day_tests[] =
{
  { "C", "2000-01-01", "%Y-%m-%d", 6, 0, 0, 1 },
  { "C", "03/03/00", "%D", 5, 62, 2, 3 },
  { "C", "9/9/99", "%x", 4, 251, 8, 9 },
  { "C", "19990502123412", "%Y%m%d%H%M%S", 0, 121, 4, 2 },
  { "C", "2001 20 Mon", "%Y %U %a", 1, 140, 4, 21 },
  { "C", "2001 21 Mon", "%Y %W %a", 1, 140, 4, 21 },
  { "ja_JP.EUC-JP", "2001 20 \xb7\xee", "%Y %U %a", 1, 140, 4, 21 },
  { "ja_JP.EUC-JP", "2001 21 \xb7\xee", "%Y %W %a", 1, 140, 4, 21 },
};


static const struct
{
  const char *input;
  const char *format;
  const char *output;
  int wday;
  int yday;
} tm_tests [] =
{
  {"17410105012000", "%H%M%S%d%m%Y", "2000-01-05 17:41:01", 3, 4}
};



static int
test_tm (void)
{
  struct tm tm;
  size_t i;
  int result = 0;
  char buf[100];

  for (i = 0; i < sizeof (tm_tests) / sizeof (tm_tests[0]); ++i)
    {
      memset (&tm, '\0', sizeof (tm));
      
      if (strptime (tm_tests[i].input, tm_tests[i].format, &tm) != '\0')
	{
	  printf ("not all of `%s' read\n", tm_tests[i].input);
	  result = 1;
	}
      strftime (buf, sizeof (buf), "%F %T", &tm);
      printf ("strptime (\"%s\", \"%s\", ...)\n"
	      "\tshould be: %s, wday = %d, yday = %3d\n"
	      "\t       is: %s, wday = %d, yday = %3d\n",
	      tm_tests[i].input, tm_tests[i].format,
	      tm_tests[i].output,
	      tm_tests[i].wday, tm_tests[i].yday,
	      buf, tm.tm_wday, tm.tm_yday);

      if (strcmp (buf, tm_tests[i].output) != 0)
	{
	  printf ("Time and date are not correct.\n");
	  result = 1;
	}
      if (tm.tm_wday != tm_tests[i].wday)
	{
	  printf ("weekday for `%s' incorrect: %d instead of %d\n",
		  tm_tests[i].input, tm.tm_wday, tm_tests[i].wday);
	  result = 1;
	}
      if (tm.tm_yday != tm_tests[i].yday)
	{
	  printf ("yearday for `%s' incorrect: %d instead of %d\n",
		  tm_tests[i].input, tm.tm_yday, tm_tests[i].yday);
	  result = 1;
	}
    }

  return result;
}


int main (void) {
  struct tm tm;
  size_t i;
  int result = 0;

  for (i = 0; i < sizeof (day_tests) / sizeof (day_tests[0]); ++i)
    {
      memset (&tm, '\0', sizeof (tm));

      if (setlocale (LC_ALL, day_tests[i].locale) == NULL)
	{
	  printf ("cannot set locale %s: %m\n", day_tests[i].locale);
	}

      if (*strptime (day_tests[i].input, day_tests[i].format, &tm) != '\0')
	{
	  printf ("not all of `%s' read\n", day_tests[i].input);
	  result = 1;
	}

      printf ("strptime (\"%s\", \"%s\", ...)\n"
	      "\tshould be: wday = %d, yday = %3d, mon = %2d, mday = %2d\n"
	      "\t       is: wday = %d, yday = %3d, mon = %2d, mday = %2d\n",
	      day_tests[i].input, day_tests[i].format,
	      day_tests[i].wday, day_tests[i].yday,
	      day_tests[i].mon, day_tests[i].mday,
	      tm.tm_wday, tm.tm_yday, tm.tm_mon, tm.tm_mday);

      if (tm.tm_wday != day_tests[i].wday)
	{
	  printf ("weekday for `%s' incorrect: %d instead of %d\n",
		  day_tests[i].input, tm.tm_wday, day_tests[i].wday);
	  result = 1;
	}
      if (tm.tm_yday != day_tests[i].yday)
	{
	  printf ("yearday for `%s' incorrect: %d instead of %d\n",
		  day_tests[i].input, tm.tm_yday, day_tests[i].yday);
	  result = 1;
	}
      if (tm.tm_mon != day_tests[i].mon)
	{
	  printf ("month for `%s' incorrect: %d instead of %d\n",
		  day_tests[i].input, tm.tm_mon, day_tests[i].mon);
	  result = 1;
	}
      if (tm.tm_mday != day_tests[i].mday)
	{
	  printf ("monthday for `%s' incorrect: %d instead of %d\n",
		  day_tests[i].input, tm.tm_mday, day_tests[i].mday);
	  result = 1;
	}
    }

  setlocale (LC_ALL, "C");

  result |= test_tm ();

  return result;
}
dietlibc-0.33~cvs20120325/test/ungetc.c010064400000000000000000000002411173363230200143030ustar00#include 

int main() {
  ungetc(23,stdin);
  if (fgetc(stdin) != 23) return 1;
  ungetc(230,stdin);
  if (fgetc(stdin) != 230) return 1;
  return 0;
}
dietlibc-0.33~cvs20120325/test/utime.c010064400000000000000000000012661173363230200141510ustar00#include 
#include 
#include 
#include 
#include 

int main(void)
{
  char file[] = "/tmp/utime-test.XXXXXX";
  int tmp_fd;
  struct utimbuf utm = {
    .actime = 23,
    .modtime = 42,
  };
  struct stat st;
  time_t now;

  tmp_fd = mkstemp(file);
  close(tmp_fd);

  assert(utime(file, &utm) == 0);
  assert(stat(file, &st) == 0);
  assert(st.st_atime == utm.actime);
  assert(st.st_mtime == utm.modtime);

  now = time(NULL);
  assert(utime(file, NULL) == 0);
  assert(stat(file, &st) == 0);

  assert(st.st_atime == st.st_mtime);
  assert(st.st_atime >= now);
  assert(st.st_atime - now < 10);

  unlink(file);

  return EXIT_SUCCESS;
}

dietlibc-0.33~cvs20120325/test/waitpid.c010064400000000000000000000006301173363230200144610ustar00#include 
#include 
#include 
#include 

int main() {
  pid_t t;
  int status;
  switch (t=fork()) {
  case -1:
    perror("fork");
    _exit(1);
  case 0:
    fprintf(stderr,"child, my pid is %u\n",getpid());
    sleep(1);
    _exit(23);
  }
  printf("waitpid returned %u\n",waitpid(-1,&status,0));
  printf("status was: %d\n",WEXITSTATUS(status));
  return 0;
}
dietlibc-0.33~cvs20120325/test/wcsrtombs.c010064400000000000000000000010261173363230200150430ustar00#include 
#include 
#include 
#include 
#include 
#include 

int main() {
  wchar_t a[]=L"Böses Encoding";
  const wchar_t* b=a;
  char buf[100];
  static mbstate_t ps;
  size_t l;
  setlocale(LC_ALL,"de_DE");
  l=wcsrtombs(buf,&b,sizeof(buf),&ps);
  assert(l==14); assert(!strcmp(buf,"B\xf6ses Encoding"));
  memset(buf,0,sizeof(buf));
  setlocale(LC_ALL,"de_DE.UTF8");
  b=a;
  l=wcsrtombs(buf,&b,sizeof(buf),&ps);
  assert(l==15); assert(!strcmp(buf,"Böses Encoding"));
}
dietlibc-0.33~cvs20120325/test/wctomb.c010064400000000000000000000010151173363230200143110ustar00#include 
#include 
#include 
#include 
#include 
#include 
#include 

int main() {
  wchar_t c[100];
  char buf[100];
  size_t n=0;
  c[0]='f';
  c[1]='n';
  c[2]=0xd6;
  c[3]='r';
  c[4]='d';
  c[5]=0;
  setlocale(LC_CTYPE,"de_DE.UTF8");

  assert(wctomb(buf,c[0])==1);
  assert(wctomb(buf+1,c[1])==1);
  assert(wctomb(buf+2,c[2])==2);
  assert(wctomb(buf+4,c[3])==1);
  assert(wctomb(buf+5,c[4])==1);
  buf[6]=0;
  assert(!strcmp(buf,"fn\xc3\x96rd"));

}
dietlibc-0.33~cvs20120325/test/wctype.c010064400000000000000000000002221173363230200143300ustar00#include 
#include 
#include 

int main() {
  wctype_t x;
  assert(x=wctype("lower"));
  assert(iswctype(L'o',x));
}
dietlibc-0.33~cvs20120325/test/wmem.c010064400000000000000000000026041173363231000137670ustar00#include 
#include 

int main() {
  wchar_t buf[100];
  int i;

  /* does wmemset work? */
  assert(wmemset(buf,0,100)==buf);
  for (i=0; i<100; ++i) assert(buf[i]==0);

  /* do wcscpy and wcscat work? */
  assert(wcscpy(buf,L"fnord")==buf);
  assert(wcscat(buf,L"blah")==buf);
  assert(wcslen(buf)==9);
  assert(wcscmp(buf,L"fnordblah")==0);

  /* does wmemcmp work? */
  assert(wmemcmp(buf,L"fnordxxx",5)==0);
  assert(wmemcmp(buf,L"fnordxxx",6)<0);

  /* check wmemcpy */
  assert(wmemcpy(buf+5,buf,5)==buf+5);
  assert(wmemcmp(buf,L"fnordfnord",10)==0);

  /* does wmemmove handle overlapping properly */
  assert(wmemmove(buf+1,buf,3)==buf+1);
  assert(wmemcmp(buf,L"ffnod",5)==0);
  assert(wmemmove(buf,buf+1,3)==buf);
  assert(wmemcmp(buf,L"fnood",5)==0);

  /* check wcsncpy */
  assert(wcsncpy(buf,L"fnord",8)==buf);
  assert(wmemcmp(buf,L"fnord\0\0\0",8)==0);
  buf[5]=L'x';
  assert(wcsncpy(buf,L"test_",5)==buf);
  assert(wmemcmp(buf,L"test_x\0\0",8)==0);

  /* check wcsncat */
  wmemset(buf,L'x',10);
  wcscpy(buf,L"ab");
  assert(wcsncat(buf,L"cd",5)==buf);	// normal case
  assert(wmemcmp(buf,L"abcd\0xxxxx",10)==0);
  assert(wcsncat(buf,L"efgh",2)==buf);	// truncation case
  assert(wmemcmp(buf,L"abcdef\0xxx",10)==0);

  /* wcsstr */
  wcscpy(buf,L"abracadabra");
  assert(wcsstr(buf,L"abr")==buf);
  assert(wcsstr(buf+1,L"abr")==buf+7);
  assert(wcsstr(buf+8,L"abr")==0);
}
dietlibc-0.33~cvs20120325/threadsafe.sh010075500000000000000000000002161173363226000143450ustar00#!/bin/sh
(gcc -E - << EOF | grep WANT_THREAD_SAFE > /dev/null) || echo libpthread/pthread_*.c
#include "dietfeatures.h"
WANT_THREAD_SAFE
EOF
dietlibc-0.33~cvs20120325/x86_64/Makefile.add010064400000000000000000000002431173363231000150210ustar00CFLAGS := -Os -fstrict-aliasing -momit-leaf-frame-pointer -mfancy-math-387
VPATH  := x86_64:syscalls.s:$(VPATH)
LIBOBJ += $(OBJDIR)/arch_prctl.o $(OBJDIR)/__CAS.o
dietlibc-0.33~cvs20120325/x86_64/__CAS.S010064400000000000000000000001701173363231000136610ustar00.text
.global __CAS
.type __CAS,@function
__CAS:
	movq %rsi, %rax
	lock cmpxchgq %rdx, (%rdi)
	ret
.size __CAS, .-__CAS
dietlibc-0.33~cvs20120325/x86_64/__longjmp.S010064400000000000000000000011121173363231000147160ustar00#include 
#include "dietwarning.h"

.text
.global __longjmp
.type __longjmp,@function
__longjmp:
	mov	$1,%eax
	/* Restore the return address now.  */
	movq	 (JB_PC*8)(%rdi),%rdx
	/* Restore registers. */
	movq	(JB_RBX*8)(%rdi),%rbx
	movq	(JB_RBP*8)(%rdi),%rbp
	movq	(JB_R12*8)(%rdi),%r12
	movq	(JB_R13*8)(%rdi),%r13
	movq	(JB_R14*8)(%rdi),%r14
	movq	(JB_R15*8)(%rdi),%r15
	movq	(JB_RSP*8)(%rdi),%rsp
	/* never return 0 */
	test	%esi,%esi
	cmovne	%esi,%eax
	/* Jump to saved PC.  */
	jmp	*%rdx
.size __longjmp,.-__longjmp;

link_warning("__longjmp","longjmp() not yet tested")
dietlibc-0.33~cvs20120325/x86_64/__testandset.S010064400000000000000000000003351173363231000154340ustar00#include "dietwarning.h"

.text
.global __testandset
.type	__testandset,@function
__testandset:
	xorl	%eax,%eax
	incl	%eax
	xchg	%rax,(%rdi)
	ret

link_warning("__testandset", "warning: __testandset() was never tested!")
dietlibc-0.33~cvs20120325/x86_64/arch_prctl.S010064400000000000000000000000661173363231000151020ustar00#include "syscalls.h"

syscall(arch_prctl,arch_prctl)
dietlibc-0.33~cvs20120325/x86_64/clock_gettime.S010064400000000000000000000007161173363231000155740ustar00.text
.global clock_gettime
.type clock_gettime,@function
clock_gettime:
	movq cgt(%rip), %rax
	test %rax,%rax
	jz .L1
.L2:
	callq *%rax
	jmp __error_unified_syscall
.L1:
	push %rsi
	push %rdi
	movq __vdso(%rip),%rdi
	movq $funcname, %rsi
	call vdso_dlsym
	pop %rdi
	pop %rsi
	jmp .L2

.Lhere:
	.size	 clock_gettime,.Lhere-clock_gettime
.local cgt
.comm cgt,8,8
.section .rodata.str1.1,"aMS",@progbits,1
.local funcname
funcname:
	.string "__vdso_clock_gettime"
dietlibc-0.33~cvs20120325/x86_64/clone.S010064400000000000000000000022701173363231000140600ustar00#include "syscalls.h"
#include 
#include "dietwarning.h"

.text
.type clone,@function
.weak clone
clone:
.type __clone,@function
.global __clone
__clone:
	movl	$-EINVAL,%eax
	testq	%rdi,%rdi	/* have non null thread_funcion */
	jz	.Lclone_error
	testq	%rsi,%rsi	/* have non null child_stack pointer */
	jz	.Lclone_error

	/* put the parameters on thread stack */
	subq	$16,%rsi
	movq	%rcx,8(%rsi)	/* thread parameter */
	movq	%rdi,0(%rsi)	/* thread function */

	/* syscall */
	movq	%rdx,%rdi
	movl	$__NR_clone,%eax
	syscall
	cmpl	$0,%eax
	jl	.Lclone_error
	jne	.Lreturn

.thread_start:
	/* call thread function */
	popq	%rax
	popq	%rdi
	call	*%rax
	/* exit a thread */
	movq	%rax,%rdi
#ifdef __PIC__
	jmp	_exit@PLT
#else
	jmp	_exit
#endif

.Lclone_error:
	/* set errno */
	negl	%eax
	pushq	%rax
#ifdef __PIC__
	call	__errno_location@PLT
#else
	call	__errno_location
#endif
	popq	%rcx
	movl	%ecx,(%rax)
	orq	$-1, %rax

.Lreturn:
	/* just return */
	ret

link_warning("clone", "warning: clone() not yet tested")
link_warning("__clone", "warning: clone() not yet tested")
//link_warning("clone", "warning: clone() not yet implemented")
//link_warning("__clone", "warning: clone() not yet implemented")
dietlibc-0.33~cvs20120325/x86_64/dyn_syscalls.S010064400000000000000000000243441173363231000154750ustar00/*
 * dynamic unified-syscalls
 * Olaf Dreesen
 */

#include 
#include "syscalls.h"

//#include "unified.S"
.text
.weak exit
exit:
.global _exit
_exit:
__exit:
	movb	$__NR_exit,%al

.global __unified_syscall
.global __unified_syscall_16bit
__unified_syscall:
_unified_syscall:
	mov	$0, %al
__unified_syscall_16bit:
	movzwl	%ax, %eax
	mov	%rcx, %r10
	syscall
__error_unified_syscall:
	cmpq	$-132, %rax
	jbe	.Lnoerror
	negl	%eax
	pushq	%rax
	call	__errno_location@PLT
	popq	%rcx
	movl	%ecx,(%rax)
	orq	$-1, %rax
.Lnoerror:

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	ret

#define __unified_syscall _unified_syscall

#include "waitpid.S"

#include "../syscalls.s/__getpagesize.S"
#include "../syscalls.s/__pread.S"
#include "../syscalls.s/__pwrite.S"
#include "../syscalls.s/__reboot.S"
#include "../syscalls.s/_llseek.S"
#include "../syscalls.s/access.S"
#include "../syscalls.s/adjtimex.S"
#include "../syscalls.s/alarm.S"
#include "../syscalls.s/bdflush.S"
#include "../syscalls.s/brk.S"
#include "../syscalls.s/capget.S"
#include "../syscalls.s/capset.S"
#include "../syscalls.s/chdir.S"
#include "../syscalls.s/chmod.S"
#include "../syscalls.s/chown.S"
#include "../syscalls.s/chown32.S"
#include "../syscalls.s/chroot.S"
#include "../syscalls.s/close.S"
#include "../syscalls.s/create_module.S"
#include "../syscalls.s/delete_module.S"
#include "../syscalls.s/dup.S"
#include "../syscalls.s/dup2.S"
#include "../syscalls.s/environ.S"
#include "../syscalls.s/epoll_create.S"
#include "../syscalls.s/epoll_ctl.S"
#include "../syscalls.s/epoll_wait.S"
#include "../syscalls.s/errno.S"
#include "../syscalls.s/execve.S"
#include "../syscalls.s/fchdir.S"
#include "../syscalls.s/fchmod.S"
#include "../syscalls.s/fchown.S"
#include "../syscalls.s/fchown32.S"
#include "../syscalls.s/fcntl.S"
#include "../syscalls.s/fdatasync.S"
#include "../syscalls.s/flock.S"
#include "../syscalls.s/fork.S"
#include "../syscalls.s/fstat.S"
#include "../syscalls.s/fstat64.S"
#include "../syscalls.s/fstatfs.S"
#include "../syscalls.s/fsync.S"
#include "../syscalls.s/ftruncate.S"
#include "../syscalls.s/ftruncate64.S"
#include "../syscalls.s/getcwd.S"
#include "../syscalls.s/getdents.S"
#include "../syscalls.s/getdents64.S"
#include "../syscalls.s/getegid.S"
#include "../syscalls.s/getegid32.S"
#include "../syscalls.s/geteuid.S"
#include "../syscalls.s/geteuid32.S"
#include "../syscalls.s/getgid.S"
#include "../syscalls.s/getgid32.S"
#include "../syscalls.s/getgroups.S"
#include "../syscalls.s/getgroups32.S"
#include "../syscalls.s/getitimer.S"
#include "../syscalls.s/getpgid.S"
#include "../syscalls.s/getpid.S"
#include "../syscalls.s/getppid.S"
#include "../syscalls.s/getpriority.S"
#include "../syscalls.s/getresgid.S"
#include "../syscalls.s/getresgid32.S"
#include "../syscalls.s/getresuid.S"
#include "../syscalls.s/getrlimit.S"
#include "../syscalls.s/getrusage.S"
#include "../syscalls.s/getsid.S"
#include "../syscalls.s/getuid.S"
#include "../syscalls.s/getuid32.S"
#include "../syscalls.s/init_module.S"
#include "../syscalls.s/ioctl.S"
#include "../syscalls.s/ioperm.S"
#include "../syscalls.s/iopl.S"
#include "../syscalls.s/ipc.S"
#include "../syscalls.s/kill.S"
#include "../syscalls.s/lchown.S"
#include "../syscalls.s/lchown32.S"
#include "../syscalls.s/link.S"
#include "../syscalls.s/lseek.S"
#include "../syscalls.s/lstat.S"
#include "../syscalls.s/lstat64.S"
#include "../syscalls.s/madvise.S"
#include "../syscalls.s/mkdir.S"
#include "../syscalls.s/mknod.S"
#include "../syscalls.s/mlock.S"
#include "../syscalls.s/mlockall.S"
#include "../syscalls.s/mmap.S"
#include "../syscalls.s/mmap2.S"
#include "../syscalls.s/mount.S"
#include "../syscalls.s/mprotect.S"
#include "../syscalls.s/mremap.S"
#include "../syscalls.s/msync.S"
#include "../syscalls.s/munlock.S"
#include "../syscalls.s/munlockall.S"
#include "../syscalls.s/munmap.S"
#include "../syscalls.s/n_sigaction.S"
#include "../syscalls.s/n_sigpending.S"
#include "../syscalls.s/n_sigprocmask.S"
#include "../syscalls.s/n_sigsuspend.S"
#include "../syscalls.s/nanosleep.S"
#include "../syscalls.s/nice.S"
#include "../syscalls.s/open.S"
#include "../syscalls.s/pause.S"
#include "../syscalls.s/personality.S"
#include "../syscalls.s/pipe.S"
#include "../syscalls.s/pivot_root.S"
#include "../syscalls.s/poll.S"
#include "../syscalls.s/prctl.S"
#include "../syscalls.s/ptrace.S"
#include "../syscalls.s/query_module.S"
#include "../syscalls.s/read.S"
#include "../syscalls.s/readlink.S"
#include "../syscalls.s/readv.S"
#include "../syscalls.s/rename.S"
#include "../syscalls.s/rmdir.S"
#include "../syscalls.s/rt_sigaction.S"
#include "../syscalls.s/rt_sigpending.S"
#include "../syscalls.s/rt_sigprocmask.S"
#include "../syscalls.s/rt_sigqueueinfo.S"
#include "../syscalls.s/rt_sigsuspend.S"
#include "../syscalls.s/rt_sigtimedwait.S"
#include "../syscalls.s/sched_getaffinity.S"
#include "../syscalls.s/sched_setaffinity.S"
#include "../syscalls.s/sched_get_priority_max.S"
#include "../syscalls.s/sched_get_priority_min.S"
#include "../syscalls.s/sched_getparam.S"
#include "../syscalls.s/sched_getscheduler.S"
#include "../syscalls.s/sched_rr_get_interval.S"
#include "../syscalls.s/sched_setparam.S"
#include "../syscalls.s/sched_setscheduler.S"
#include "../syscalls.s/sched_yield.S"
#include "../syscalls.s/select.S"
#include "../syscalls.s/sendfile.S"
#include "../syscalls.s/sendfile64.S"
#include "../syscalls.s/setdomainname.S"
#include "../syscalls.s/setfsgid.S"
#include "../syscalls.s/setfsgid32.S"
#include "../syscalls.s/setfsuid.S"
#include "../syscalls.s/setfsuid32.S"
#include "../syscalls.s/setgid.S"
#include "../syscalls.s/setgid32.S"
#include "../syscalls.s/setgroups.S"
#include "../syscalls.s/sethostname.S"
#include "../syscalls.s/setitimer.S"
#include "../syscalls.s/setpgid.S"
#include "../syscalls.s/setpriority.S"
#include "../syscalls.s/setregid.S"
#include "../syscalls.s/setregid32.S"
#include "../syscalls.s/setresgid.S"
#include "../syscalls.s/setresgid32.S"
#include "../syscalls.s/setresuid.S"
#include "../syscalls.s/setreuid.S"
#include "../syscalls.s/setreuid32.S"
#include "../syscalls.s/setrlimit.S"
#include "../syscalls.s/setsid.S"
#include "../syscalls.s/settimeofday.S"
#include "../syscalls.s/setuid.S"
#include "../syscalls.s/setuid32.S"
#include "../syscalls.s/sigaltstack.S"
#include "../syscalls.s/socketcall.S"
#include "../syscalls.s/stat.S"
#include "../syscalls.s/stat64.S"
#include "../syscalls.s/statfs.S"
#include "../syscalls.s/stime.S"
#include "../syscalls.s/swapoff.S"
#include "../syscalls.s/swapon.S"
#include "../syscalls.s/symlink.S"
#include "../syscalls.s/sync.S"
#include "../syscalls.s/sysctl.S"
#include "../syscalls.s/sysfs.S"
#include "../syscalls.s/sysinfo.S"
#include "../syscalls.s/syslog.S"
#include "../syscalls.s/time.S"
#include "../syscalls.s/timer_create.S"
#include "../syscalls.s/timer_delete.S"
#include "../syscalls.s/timer_getoverrun.S"
#include "../syscalls.s/timer_gettime.S"
#include "../syscalls.s/timer_settime.S"
#include "../syscalls.s/times.S"
#include "../syscalls.s/truncate.S"
#include "../syscalls.s/truncate64.S"
#include "../syscalls.s/umask.S"
#include "../syscalls.s/uname.S"
#include "../syscalls.s/unlink.S"
#include "../syscalls.s/utime.S"
#include "../syscalls.s/vhangup.S"
#include "../syscalls.s/wait4.S"
#include "../syscalls.s/waitpid.S"
#include "../syscalls.s/write.S"
#include "../syscalls.s/writev.S"
#include "../syscalls.s/ustat.S"

#include "../syscalls.s/clock_settime.S"
#include "../syscalls.s/clock_gettime.S"
#include "../syscalls.s/clock_getres.S"
#include "../syscalls.s/clock_nanosleep.S"

#include "../syscalls.s/mq_getsetattr.S"
#include "../syscalls.s/mq_notify.S"
#include "../syscalls.s/mq_open.S"
#include "../syscalls.s/mq_timedreceive.S"
#include "../syscalls.s/mq_timedsend.S"
#include "../syscalls.s/mq_unlink.S"

#include "../syscalls.s/statfs64.S"
#include "../syscalls.s/fstatfs64.S"

#include "../syscalls.s/tkill.S"
#include "../syscalls.s/tgkill.S"
#include "../syscalls.s/set_tid_address.S"
#include "../syscalls.s/set_thread_area.S"
#include "../syscalls.s/set_mempolicy.S"
#include "../syscalls.s/rt_sigreturn.S"
#include "../syscalls.s/gettid.S"
#include "../syscalls.s/get_thread_area.S"

#include "../syscalls.s/remap_file_pages.S"
#include "../syscalls.s/readahead.S"
#include "../syscalls.s/quotactl.S"
#include "../syscalls.s/mincore.S"
#include "../syscalls.s/mbind.S"
#include "../syscalls.s/get_mempolicy.S"
#include "../syscalls.s/futex.S"
#include "../syscalls.s/fadvise64.S"
#include "../syscalls.s/vserver.S"

#include "../syscalls.s/request_key.S"
#include "../syscalls.s/keyctl.S"
#include "../syscalls.s/add_key.S"

#include "../syscalls.s/io_submit.S"
#include "../syscalls.s/io_setup.S"
#include "../syscalls.s/io_getevents.S"
#include "../syscalls.s/io_destroy.S"
#include "../syscalls.s/io_cancel.S"

#include "../syscalls.s/inotify_rm_watch.S"
#include "../syscalls.s/inotify_init.S"
#include "../syscalls.s/inotify_add_watch.S"

#include "../syscalls.s/setxattr.S"
#include "../syscalls.s/lsetxattr.S"
#include "../syscalls.s/fsetxattr.S"
#include "../syscalls.s/removexattr.S"
#include "../syscalls.s/lremovexattr.S"
#include "../syscalls.s/fremovexattr.S"
#include "../syscalls.s/listxattr.S"
#include "../syscalls.s/llistxattr.S"
#include "../syscalls.s/flistxattr.S"
#include "../syscalls.s/getxattr.S"
#include "../syscalls.s/lgetxattr.S"
#include "../syscalls.s/fgetxattr.S"

#include "../syscalls.s/timerfd.S"
#include "../syscalls.s/__signalfd.S"

#include "../syscalls.s/fallocate.S"
#include "../syscalls.s/utimes.S"

#include "syscalls.s/__socket.S"
#include "syscalls.s/__bind.S"
#include "syscalls.s/__setsockopt.S"
#include "syscalls.s/__getsockopt.S"
#include "syscalls.s/__sendto.S"
#include "syscalls.s/__recvmsg.S"
#include "syscalls.s/__accept.S"
#include "syscalls.s/__connect.S"
#include "syscalls.s/__getpeername.S"
#include "syscalls.s/__getsockname.S"
#include "syscalls.s/__listen.S"
#include "syscalls.s/__recv.S"
#include "syscalls.s/__recvfrom.S"
#include "syscalls.s/__send.S"
#include "syscalls.s/__sendmsg.S"
#include "syscalls.s/__shutdown.S"
#include "syscalls.s/__socketpair.S"

#include "syscalls.s/umount2.S"

#define _exit __exit
#include "clone.S"
#undef _exit

#include "__longjmp.S"
#include "setjmp.S"

#define __errno_location __errno_location@PLT
#include "x86_64/gettimeofday.S"

#include "syscalls.s/__guard.S"
dietlibc-0.33~cvs20120325/x86_64/getsockopt.S010064400000000000000000000000701173363231000151360ustar00#include "syscalls.h"

syscall(getsockopt, getsockopt);
dietlibc-0.33~cvs20120325/x86_64/gettimeofday.S010064400000000000000000000007131173363231000154410ustar00.text
.global gettimeofday
.type gettimeofday,@function
gettimeofday:
	movq gtod(%rip), %rax
	test %rax,%rax
	jz .L1
.L2:
	callq *%rax
	jmp __error_unified_syscall
.L1:
	push %rsi
	push %rdi
	movq __vdso(%rip),%rdi
	movq $funcname, %rsi
	call vdso_dlsym
	pop %rdi
	pop %rsi
	jmp .L2

.Lhere:
	.size	 gettimeofday,.Lhere-gettimeofday
.local gtod
.comm gtod,8,8
.section .rodata.str1.1,"aMS",@progbits,1
.local funcname
funcname:
	.string "__vdso_gettimeofday"
dietlibc-0.33~cvs20120325/x86_64/memchr.S010064400000000000000000000022661173363231000142400ustar00#include "dietfeatures.h"
.text
.global memchr
.type memchr,@function
memchr:	/* rdi=ptr, esi=ch, rdx=len */
#ifdef WANT_VALGRIND_SUPPORT
#ifdef __DYN_LIB
  movq	__valgrind@GOTPCREL(%rip), %rax
  movq	(%rax), %rax
  test	%rax, %rax
#else
  xor %eax,%eax
  or (__valgrind),%eax
#endif
  jnz .Lvalgrind
#endif
  and $0xff,%esi
  test %rdx,%rdx
  jz .Lnull		/* if (!len) return 0 */
  imul $0x1010101,%esi	/* esi = ch x 4 */

  mov %rdi,%rcx
  and $15,%ecx
  movd %esi,%xmm0
  lea (%rdi,%rdx),%rsi	/* rsi = max ptr */
  and $~15,%rdi		/* 16-align rdi, diff in cl */
  or $-1,%eax
  shl %cl,%eax

  pshufd $0,%xmm0,%xmm0	/* xmm0 = ch x 16 */
1:
  movdqa (%rdi),%xmm1
  pcmpeqb %xmm0,%xmm1
  pmovmskb %xmm1,%ecx
  and %eax,%ecx
  jnz .Lfound	/* found something */
  lea 16(%rdi),%rdi
  or $-1,%eax
  cmp %rsi,%rdi
  jb 1b
  jmp .Lnull
.Lfound:
  bsf %ecx,%eax
  add %rdi,%rax
  cmp %rsi,%rax
  jae .Lnull
  ret
.Lnull:
  xor %eax,%eax
  ret

#ifdef WANT_VALGRIND_SUPPORT
/* rdi=ptr, esi=ch, rdx=len */
.Lvalgrind:
.Lloop:
  test %rdx,%rdx
  jz .Lnull
  movzbl (%rdi),%eax
  cmp %esi,%eax
  jz .Lfound2
  inc %rdi
  dec %rdx
  jmp .Lloop
.Lfound2:
  mov %rdi,%rax
  ret
#endif
.Lhere:
.size memchr,.Lhere-memchr
dietlibc-0.33~cvs20120325/x86_64/msgctl.S010064400000000000000000000000561173363231000142510ustar00#include "syscalls.h"

syscall(msgctl,msgctl)
dietlibc-0.33~cvs20120325/x86_64/msgget.S010064400000000000000000000000561173363231000142460ustar00#include "syscalls.h"

syscall(msgget,msgget)
dietlibc-0.33~cvs20120325/x86_64/msgrcv.S010064400000000000000000000000561173363231000142610ustar00#include "syscalls.h"

syscall(msgrcv,msgrcv)
dietlibc-0.33~cvs20120325/x86_64/msgsnd.S010064400000000000000000000000561173363231000142530ustar00#include "syscalls.h"

syscall(msgsnd,msgsnd)
dietlibc-0.33~cvs20120325/x86_64/recv.c010064400000000000000000000005761173363231000137460ustar00#include 
#include 
#include 

int __libc_recv(int fd, void * buf, size_t n, int flags);
  /* shut up gcc warning about missing prototype */

int __libc_recv(int fd, void * buf, size_t n, int flags) {
  return recvfrom(fd, buf, n, flags, 0, 0);
}

int recv(int a, void * b, size_t c, int flags)
  __attribute__ ((weak, alias("__libc_recv")));
dietlibc-0.33~cvs20120325/x86_64/semctl.S010064400000000000000000000000561173363231000142470ustar00#include "syscalls.h"

syscall(semctl,semctl)
dietlibc-0.33~cvs20120325/x86_64/semget.S010064400000000000000000000000561173363231000142440ustar00#include "syscalls.h"

syscall(semget,semget)
dietlibc-0.33~cvs20120325/x86_64/semop.S010064400000000000000000000000541173363231000141010ustar00#include "syscalls.h"

syscall(semop,semop)
dietlibc-0.33~cvs20120325/x86_64/send.c010064400000000000000000000006211173363231000137270ustar00#include 
#include 
#include 

int __libc_send(int fd, const void * buf, size_t n, int flags);
  /* shut up gcc warning about missing prototype */

int __libc_send(int fd, const void * buf, size_t n, int flags) {
  return sendto(fd, buf, n, flags, NULL, 0);
}

int send(int a, const void * b, size_t c, int flags)
  __attribute__ ((weak, alias("__libc_send")));
dietlibc-0.33~cvs20120325/x86_64/setjmp.S010064400000000000000000000014671173363231000142710ustar00#include 
#include "dietwarning.h"

.text
.weak setjmp
.type setjmp,@function
setjmp:
.globl __setjmp
.type __setjmp,@function
__setjmp:
	xorq	%rsi,%rsi

.globl __sigsetjmp
.type __sigsetjmp,@function
__sigsetjmp:
	movq	%rbx,(JB_RBX*8)(%rdi)
	movq	%rbp,(JB_RBP*8)(%rdi)
	movq	%r12,(JB_R12*8)(%rdi)
	movq	%r13,(JB_R13*8)(%rdi)
	movq	%r14,(JB_R14*8)(%rdi)
	movq	%r15,(JB_R15*8)(%rdi)
	leaq	8(%rsp),%rdx
	movq	%rdx,(JB_RSP*8)(%rdi)
	movq	(%rsp),%rdx
	movq	%rdx,(JB_PC*8)(%rdi)
#ifdef	__PIC__
	jmp	__sigjmp_save@PLT
#else
	jmp	__sigjmp_save
#endif
.size __sigsetjmp,.-__sigsetjmp;

link_warning("setjmp","setjmp() not yet tested")
link_warning("__sigsetjmp","setjmp() not yet tested")
//link_warning("setjmp","error: setjmp() not yet implemented")
//link_warning("__sigsetjmp","error: setjmp() not yet implemented")

dietlibc-0.33~cvs20120325/x86_64/setsockopt.S010064400000000000000000000000701173363231000151520ustar00#include "syscalls.h"

syscall(setsockopt, setsockopt);
dietlibc-0.33~cvs20120325/x86_64/shmat.S010064400000000000000000000000541173363231000140720ustar00#include "syscalls.h"

syscall(shmat,shmat)
dietlibc-0.33~cvs20120325/x86_64/shmctl.S010064400000000000000000000000561173363231000142520ustar00#include "syscalls.h"

syscall(shmctl,shmctl)
dietlibc-0.33~cvs20120325/x86_64/shmdt.S010064400000000000000000000000541173363231000140750ustar00#include "syscalls.h"

syscall(shmdt,shmdt)
dietlibc-0.33~cvs20120325/x86_64/shmget.S010064400000000000000000000000561173363231000142470ustar00#include "syscalls.h"

syscall(shmget,shmget)
dietlibc-0.33~cvs20120325/x86_64/sigaction.c010064400000000000000000000021511173363231000147560ustar00#include 
#include 
#include 
#include 

int __rt_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact, long nr);

#if 0
static void __restore_rt(void) {
  asm volatile ("syscall" : : "a" (__NR_rt_sigreturn));
}
#else
/* exactly match MD_FALLBACK_FRAME_STATE_FOR in gcc-3.4/gcc/config/i386/linux64.h */
void __restore_rt(void);
asm(".text\n" ".align 16\n"
    "__restore_rt:"
    "movq $15, %rax\n" "syscall\n" "hlt\n");
#endif

int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
int __libc_sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) {
  struct sigaction *newact = (struct sigaction *)act;
  if (act) {
	newact = alloca(sizeof(*newact));
	newact->sa_handler = act->sa_handler;
	newact->sa_flags = act->sa_flags | SA_RESTORER;
	newact->sa_restorer = &__restore_rt;
	newact->sa_mask = act->sa_mask;
  }
  return __rt_sigaction(signum, newact, oldact, _NSIG/8);
}

int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact)
__attribute__((weak,alias("__libc_sigaction")));
dietlibc-0.33~cvs20120325/x86_64/start.S010064400000000000000000000015531173363231000141200ustar00#include "dietfeatures.h"

.text
.global _start
_start:
#ifdef WANT_DYNAMIC
	movq	%rdx, %rcx		/* %rcx = dynamic fini */
#endif
	popq	%rdi			/* %rdi = argc */
	movq	%rsp,%rsi		/* %rsi = argv */
	pushq	%rdi
	
	leaq	8(%rsi,%rdi,8),%rdx	/* %rdx = envp = (8*rdi)+%rsi+8 */

#ifdef __DYN_LIB
	movq	environ@GOTPCREL(%rip), %rax
	movq	%rdx, (%rax)
#else
	movq	%rdx, environ(%rip)
#endif

#ifdef PROFILING
	pushq	%rdi			/* save reg args */
	pushq	%rsi
	pushq	%rdx
	pushq	%rcx

	leaq	_etext(%rip), %rsi	/* highpc */
	leaq	 .text(%rip), %rdi	/* lowpc */
	call	monitor

	popq	%rcx			/* restore reg args */
	popq	%rdx
	popq	%rsi
	popq	%rdi
#endif

#ifdef WANT_DYNAMIC
	call	_dyn_start
#else
	call	CALL_IN_STARTCODE
#endif

#ifdef PROFILING
	pushq	%rax
	call	_stop_monitor
	popq	%rdi
#else
	movq	%rax, %rdi	/* return value */
#endif
	call	exit
	hlt
.Lstart:
	.size	 _start,.Lstart-_start

dietlibc-0.33~cvs20120325/x86_64/strchr.S010064400000000000000000000003461173363231000142670ustar00.text
.type   strchr,@function
.global strchr
.weak index
.type index,@function

index:
strchr:
	xchg	%rsi,%rdi
.Lloop:
	lodsb
	cmp	%al,%dil
	jz .Lfound
	or	%al,%al
	jnz .Lloop
	xor	%eax,%eax
	ret
.Lfound:
	lea	-1(%rsi),%rax
	ret
dietlibc-0.33~cvs20120325/x86_64/strcmp.S010064400000000000000000000010461173363231000142700ustar00.text
.global strcmp
.type	strcmp,@function
.weak	strcoll
.type	strcoll,@function

strcoll:
strcmp:
.Lloop:
	mov (%rdi),%al
	cmp (%rsi),%al
	jnz .Lmismatch
	inc %rsi
	inc %rdi
	or %al,%al
	jnz .Lloop
	/* end of string reached, return NULL */
	xor %eax,%eax
	ret
.Lmismatch:
/* In the C version we return (unsigned char)*b-(unsigned char)*a
   but in assembler it is less trouble to return 1 or -1
   depending on whether the carry flag is set.
   The standard only wants positive, zero, or negative, so both are OK */
	sbb %eax,%eax
	or $1,%eax
	ret
dietlibc-0.33~cvs20120325/x86_64/strcpy.S010064400000000000000000000002241173363231000143010ustar00.text
.align 0
.global strcpy
.type	 strcpy,@function
strcpy:
	mov %rdi,%rdx

.Lloop:
	lodsb
	test %al, %al
	stosb
	jnz .Lloop

	mov %rdx,%rax
	ret
dietlibc-0.33~cvs20120325/x86_64/strlen.S010064400000000000000000000017101173363231000142650ustar00#include "dietfeatures.h"
.text
.global strlen
.type strlen,@function
strlen:
#ifdef WANT_VALGRIND_SUPPORT
#ifdef __DYN_LIB
	movq	__valgrind@GOTPCREL(%rip), %rax
	movq	(%rax), %rax
	test	%rax, %rax
#else
	xor %eax,%eax
	or (__valgrind),%eax
#endif
	jnz .Lvalgrind
#endif
        mov %rdi,%rax
        mov %edi,%ecx
        pxor %xmm0,%xmm0
        and $15,%ecx
        and $-16,%rax
        movdqa (%rax),%xmm1
        pcmpeqb %xmm0,%xmm1
        pmovmskb %xmm1,%edx
        shr %cl,%edx
        shl %cl,%edx
        test %edx,%edx
        jnz .L2
.L1:
        lea 16(%rax),%rax
        movdqa (%rax),%xmm1
        pcmpeqb %xmm0,%xmm1
        pmovmskb %xmm1,%edx
        test %edx,%edx
        jz .L1
.L2:
        sub %rax,%rdi
        bsf %edx,%eax
        sub %rdi,%rax
        ret
#ifdef WANT_VALGRIND_SUPPORT
.Lvalgrind:
	mov %rdi,%rax
.L3:
	cmpb $0,(%rax)
	jz .L4
	inc %rax
	jmp .L3
.L4:
	sub %rdi,%rax
	ret
#endif

.Lhere:
        .size    strlen,.Lhere-strlen

dietlibc-0.33~cvs20120325/x86_64/strnlen.S010064400000000000000000000005141173363231000144440ustar00.text
.global strnlen
.type strnlen,@function
strnlen:
	/* incoming: rdi = ptr, rsi = len */
	mov %rdi,%r8
	mov %rsi,%r9
	mov %rsi,%rdx
	xor %esi,%esi
#ifdef __DYN_LIB
	call memchr@PLT
#else
	call memchr
#endif
	test %rax,%rax
	jz .Lnotfound
	sub %r8,%rax
	ret
.Lnotfound:
	mov %r9,%rax
	ret

.Lhere:
	.size	 strnlen,.Lhere-strnlen
dietlibc-0.33~cvs20120325/x86_64/syscalls.h010064400000000000000000000334651173363231000146540ustar00#define __NR_read                                0
#define __NR_write                               1
#define __NR_open                                2
#define __NR_close                               3
#define __NR_stat                                4
#define __NR_fstat                               5
#define __NR_lstat                               6
#define __NR_poll                                7

#define __NR_lseek                               8
#define __NR_mmap                                9
#define __NR_mprotect                           10
#define __NR_munmap                             11
#define __NR_brk                                12
#define __NR_rt_sigaction                       13
#define __NR_rt_sigprocmask                     14
#define __NR_rt_sigreturn                       15

#define __NR_ioctl                              16
#define __NR_pread                              17
#define __NR_pwrite                             18
#define __NR_readv                              19
#define __NR_writev                             20
#define __NR_access                             21
#define __NR_pipe                               22
#define __NR_select                             23

#define __NR_sched_yield                        24
#define __NR_mremap                             25
#define __NR_msync                              26
#define __NR_mincore                            27
#define __NR_madvise                            28
#define __NR_shmget                             29
#define __NR_shmat                              30
#define __NR_shmctl                             31

#define __NR_dup                                32
#define __NR_dup2                               33
#define __NR_pause                              34
#define __NR_nanosleep                          35
#define __NR_getitimer                          36
#define __NR_alarm                              37
#define __NR_setitimer                          38
#define __NR_getpid                             39

#define __NR_sendfile                           40
#define __NR_socket                             41
#define __NR_connect                            42
#define __NR_accept                             43
#define __NR_sendto                             44
#define __NR_recvfrom                           45
#define __NR_sendmsg                            46
#define __NR_recvmsg                            47

#define __NR_shutdown                           48
#define __NR_bind                               49
#define __NR_listen                             50
#define __NR_getsockname                        51
#define __NR_getpeername                        52
#define __NR_socketpair                         53
#define __NR_setsockopt                         54
#define __NR_getsockopt                         55

#define __NR_clone                              56
#define __NR_fork                               57
#define __NR_vfork                              58
#define __NR_execve                             59
#define __NR_exit                               60
#define __NR_wait4                              61
#define __NR_kill                               62
#define __NR_uname                              63

#define __NR_semget                             64
#define __NR_semop                              65
#define __NR_semctl                             66
#define __NR_shmdt                              67
#define __NR_msgget                             68
#define __NR_msgsnd                             69
#define __NR_msgrcv                             70
#define __NR_msgctl                             71

#define __NR_fcntl                              72
#define __NR_flock                              73
#define __NR_fsync                              74
#define __NR_fdatasync                          75
#define __NR_truncate                           76
#define __NR_ftruncate                          77
#define __NR_getdents                           78
#define __NR_getcwd                             79

#define __NR_chdir                              80
#define __NR_fchdir                             81
#define __NR_rename                             82
#define __NR_mkdir                              83
#define __NR_rmdir                              84
#define __NR_creat                              85
#define __NR_link                               86
#define __NR_unlink                             87

#define __NR_symlink                            88
#define __NR_readlink                           89
#define __NR_chmod                              90
#define __NR_fchmod                             91
#define __NR_chown                              92
#define __NR_fchown                             93
#define __NR_lchown                             94
#define __NR_umask                              95

#define __NR_gettimeofday                       96
#define __NR_getrlimit                          97
#define __NR_getrusage                          98
#define __NR_sysinfo                            99
#define __NR_times                             100
#define __NR_ptrace                            101
#define __NR_getuid                            102
#define __NR_syslog                            103

/* at the very end the stuff that never runs during the benchmarks */
#define __NR_getgid                            104
#define __NR_setuid                            105
#define __NR_setgid                            106
#define __NR_geteuid                           107
#define __NR_getegid                           108
#define __NR_setpgid                           109
#define __NR_getppid                           110
#define __NR_getpgrp                           111

#define __NR_setsid                            112
#define __NR_setreuid                          113
#define __NR_setregid                          114
#define __NR_getgroups                         115
#define __NR_setgroups                         116
#define __NR_setresuid                         117
#define __NR_getresuid                         118
#define __NR_setresgid                         119

#define __NR_getresgid                         120
#define __NR_getpgid                           121
#define __NR_setfsuid                          122
#define __NR_setfsgid                          123
#define __NR_getsid                            124
#define __NR_capget                            125
#define __NR_capset                            126

#define __NR_rt_sigpending                     127
#define __NR_rt_sigtimedwait                   128
#define __NR_rt_sigqueueinfo                   129
#define __NR_rt_sigsuspend                     130
#define __NR_sigaltstack                       131
#define __NR_utime                             132
#define __NR_mknod                             133

#define __NR_uselib                            134
#define __NR_personality                       135

#define __NR_ustat                             136
#define __NR_statfs                            137
#define __NR_fstatfs                           138
#define __NR_sysfs                             139

#define __NR_getpriority                       140
#define __NR_setpriority                       141
#define __NR_sched_setparam                    142
#define __NR_sched_getparam                    143
#define __NR_sched_setscheduler                144
#define __NR_sched_getscheduler                145
#define __NR_sched_get_priority_max            146
#define __NR_sched_get_priority_min            147
#define __NR_sched_rr_get_interval             148

#define __NR_mlock                             149
#define __NR_munlock                           150
#define __NR_mlockall                          151
#define __NR_munlockall                        152

#define __NR_vhangup                           153

#define __NR_modify_ldt                        154

#define __NR_pivot_root                        155

#define __NR__sysctl                           156

#define __NR_prctl                             157
#define __NR_arch_prctl                        158

#define __NR_adjtimex                          159

#define __NR_setrlimit                         160

#define __NR_chroot                            161

#define __NR_sync                              162

#define __NR_acct                              163

#define __NR_settimeofday                      164

#define __NR_mount                             165
#define __NR_umount2                           166

#define __NR_swapon                            167
#define __NR_swapoff                           168

#define __NR_reboot                            169

#define __NR_sethostname                       170
#define __NR_setdomainname                     171

#define __NR_iopl                              172
#define __NR_ioperm                            173

#define __NR_create_module                     174
#define __NR_init_module                       175
#define __NR_delete_module                     176
#define __NR_get_kernel_syms                   177
#define __NR_query_module                      178

#define __NR_quotactl                          179

#define __NR_nfsservctl                        180

#define __NR_getpmsg                           181	/* reserved for LiS/STREAMS */
#define __NR_putpmsg                           182	/* reserved for LiS/STREAMS */

#define __NR_afs_syscall                       183	/* reserved for AFS */ 

#define __NR_tuxcall      		184 /* reserved for tux */

#define __NR_security			185

#define __NR_gettid		186

#define __NR_readahead		187
#define __NR_setxattr		188
#define __NR_lsetxattr		189
#define __NR_fsetxattr		190
#define __NR_getxattr		191
#define __NR_lgetxattr		192
#define __NR_fgetxattr		193
#define __NR_listxattr		194
#define __NR_llistxattr		195
#define __NR_flistxattr		196
#define __NR_removexattr	197
#define __NR_lremovexattr	198
#define __NR_fremovexattr	199
#define __NR_tkill	200
#define __NR_time      201
#define __NR_futex     202
#define __NR_sched_setaffinity    203
#define __NR_sched_getaffinity     204
#define __NR_set_thread_area	205
#define __NR_io_setup	206
#define __NR_io_destroy	207
#define __NR_io_getevents	208
#define __NR_io_submit	209
#define __NR_io_cancel	210
#define __NR_get_thread_area	211
#define __NR_lookup_dcookie	212
#define __NR_epoll_create	213
#define __NR_epoll_ctl_old	214
#define __NR_epoll_wait_old	215
#define __NR_remap_file_pages	216
#define __NR_getdents64	217
#define __NR_set_tid_address	218
#define __NR_restart_syscall	219
#define __NR_semtimedop		220
#define __NR_fadvise64		221
#define __NR_timer_create		222
#define __NR_timer_settime		223
#define __NR_timer_gettime		224
#define __NR_timer_getoverrun		225
#define __NR_timer_delete	226
#define __NR_clock_settime	227
#define __NR_clock_gettime	228
#define __NR_clock_getres	229
#define __NR_clock_nanosleep	230
#define __NR_exit_group		231
#define __NR_epoll_wait		232
#define __NR_epoll_ctl		233
#define __NR_tgkill		234
#define __NR_utimes		235
#define __NR_vserver		236
#define __NR_vserver		236
#define __NR_mbind 		237
#define __NR_set_mempolicy 	238
#define __NR_get_mempolicy 	239
#define __NR_mq_open 		240
#define __NR_mq_unlink 		241
#define __NR_mq_timedsend 	242
#define __NR_mq_timedreceive	243
#define __NR_mq_notify 		244
#define __NR_mq_getsetattr 	245
#define __NR_kexec_load 	246
#define __NR_waitid		247
#define __NR_add_key		248
#define __NR_request_key	249
#define __NR_keyctl		250
#define __NR_ioprio_set		251
#define __NR_ioprio_get		252
#define __NR_inotify_init	253
#define __NR_inotify_add_watch	254
#define __NR_inotify_rm_watch	255
#define __NR_migrate_pages	256
#define __NR_openat		257
#define __NR_mkdirat		258
#define __NR_mknodat		259
#define __NR_fchownat		260
#define __NR_futimesat		261
#define __NR_newfstatat		262
#define __NR_unlinkat		263
#define __NR_renameat		264
#define __NR_linkat		265
#define __NR_symlinkat		266
#define __NR_readlinkat		267
#define __NR_fchmodat		268
#define __NR_faccessat		269
#define __NR_pselect6		270
#define __NR_ppoll		271
#define __NR_unshare		272
#define __NR_set_robust_list	273
#define __NR_get_robust_list	274
#define __NR_splice		275
#define __NR_tee		276
#define __NR_sync_file_range	277
#define __NR_vmsplice		278
#define __NR_move_pages		279
#define __NR_utimensat		280
#define __IGNORE_getcpu		/* implemented as a vsyscall */
#define __NR_epoll_pwait	281
#define __NR_signalfd		282
#define __NR_timerfd		283
#define __NR_eventfd		284
#define __NR_fallocate		285
#define __NR_timerfd_settime	286
#define __NR_timerfd_gettime	287
#define __NR_accept4		288
#define __NR_signalfd4		289
#define __NR_eventfd2		290
#define __NR_epoll_create1	291
#define __NR_dup3		292
#define __NR_pipe2		293
#define __NR_inotify_init1	294
#define __NR_preadv		295
#define __NR_pwritev		296
#define __NR_rt_tgsigqueueinfo	297
#define __NR_perf_event_open	298
#define __NR_recvmmsg		299
#define __NR_fanotify_init	300
#define __NR_fanotify_mark	301
#define __NR_prlimit64		302

#ifdef __PIC__
#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,@function; \
.weak wsym; \
wsym: ; \
.type sym,@function; \
.global sym; \
sym: \
	mov	$__NR_##name,%al; \
	jmp	__unified_syscall@PLT

#define syscall(name,sym) \
.text; \
.type sym,@function; \
.global sym; \
sym: \
.ifge __NR_##name-256 ; \
	mov	$__NR_##name,%ax; \
	jmp	__unified_syscall_16bit@PLT;  \
.else ; \
	mov	$__NR_##name,%al; \
	jmp	__unified_syscall@PLT;  \
.endif

#else

#define syscall_weak(name,wsym,sym) \
.text; \
.type wsym,@function; \
.weak wsym; \
wsym: ; \
.type sym,@function; \
.global sym; \
sym: \
.ifge __NR_##name-256 ; \
	mov	$__NR_##name,%ax; \
	jmp	__unified_syscall_16bit;  \
.else ; \
	mov	$__NR_##name,%al; \
	jmp	__unified_syscall;  \
.endif

#define syscall(name,sym) \
.text; \
.type sym,@function; \
.global sym; \
sym: \
.ifge __NR_##name-256 ; \
	mov	$__NR_##name,%ax; \
	jmp	__unified_syscall_16bit; \
.else ; \
	mov	$__NR_##name,%al; \
	jmp	__unified_syscall; \
.endif
#endif
dietlibc-0.33~cvs20120325/x86_64/time.S010064400000000000000000000004011173363231000137100ustar00/* implement time(2) via gettimeofday(2) on x86-64 because gettimeofday
   is a vsyscall (i.e. no actual switch to kernel mode) */
.text
.global time
.type time,@function
time:
	mov	$0xffffffffff600400,%rax
	call	*%rax
	ret
.Lhere:
	.size	 time,.Lhere-time
dietlibc-0.33~cvs20120325/x86_64/umount.S010064400000000000000000000002531173363231000143060ustar00#include "syscalls.h"

.text
.global umount
.type   umount,@function
umount:
        mov     $__NR_umount2,%al
        xorq    %rsi,%rsi
        jmp     __unified_syscall
dietlibc-0.33~cvs20120325/x86_64/unified.S010064400000000000000000000011551173363231000144040ustar00#include 

#define SYS_exit 0x3c

.text

.weak exit
exit:
.global _exit
_exit:
	mov	$SYS_exit,%al

.global __error_unified_syscall
.global __unified_syscall
.global __unified_syscall_16bit
__unified_syscall:
	mov	$0, %ah
__unified_syscall_16bit:
	movzwl	%ax, %eax
	mov	%rcx, %r10
	syscall
__error_unified_syscall:
	cmpq	$-132, %rax
	jbe	.Lnoerror
	negl	%eax
	pushq	%rax
	call	__errno_location
	popq	%rcx
	movl	%ecx,(%rax)
	orq	$-1, %rax
.Lnoerror:

/* here we go and "reuse" the return for weak-void functions */
#include "dietuglyweaks.h"

	ret
.Lhere:
	.size	 __unified_syscall,.Lhere-__unified_syscall
dietlibc-0.33~cvs20120325/x86_64/waitpid.S010064400000000000000000000003151173363231000144170ustar00#include "syscalls.h"

.text
.type	waitpid,@function
.weak	waitpid
waitpid:
.type	__libc_waitpid,@function
.global __libc_waitpid
__libc_waitpid:
	xor	%rcx,%rcx
	mov	$__NR_wait4,%al
	jmp	__unified_syscall