#!/bin/sh # # $RuOBSD: chktypes,v 1.6 2007/04/11 05:56:53 form Exp $ # # Copyright (c) 2005 Oleg Safiullin # 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 unmodified, 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. # AFILE=`mktemp /tmp/chktypes.XXXXXXXXXX` || exit $? trap "rm -f ${AFILE}" 0 1 2 3 15 CFILE=`mktemp ${AFILE}.c` || exit $? trap "rm -f ${AFILE} ${CFILE}" 0 1 2 3 15 cat > ${CFILE} << EOF #include #include #include #define S(t) ((t)(-1) < (t)0 ? 's' : 'u') int main(void); int main(void) { char buf1[128], buf2[128], buf3[128], buf4[128]; int mib1[2] = { CTL_KERN, KERN_OSTYPE }; int mib2[2] = { CTL_KERN, KERN_OSRELEASE }; int mib3[2] = { CTL_HW, HW_MACHINE }, mib4[2] = { CTL_HW, HW_MODEL }; size_t len1 = sizeof(buf1), len2 = sizeof(buf2); size_t len3 = sizeof(buf3), len4 = sizeof(buf4); if (sysctl(mib1, 2, buf1, &len1, NULL, 0) == 0 && sysctl(mib2, 2, buf2, &len2, NULL, 0) == 0 && sysctl(mib3, 2, buf3, &len3, NULL, 0) == 0 && sysctl(mib4, 2, buf4, &len4, NULL, 0) == 0) printf("%.*s %.*s %.*s %.*s\n\n", len1, buf1, len2, buf2, len3, buf3, len4, buf4); printf("sizeof(char) = %u (%c) sizeof(long double) = %u (%c)\n", sizeof(char), S(char), sizeof(long double), S(long double)); printf("sizeof(double) = %u (%c) sizeof(long long) = %u (%c)\n", sizeof(double), S(double), sizeof(long long), S(long long)); printf("sizeof(float) = %u (%c) sizeof(short) = %u (%c)\n", sizeof(float), S(float), sizeof(short), S(short)); printf("sizeof(int) = %u (%c) sizeof(void *) = %u (%c)\n", sizeof(int), S(int), sizeof(void *), S(void *)); printf("sizeof(long) = %u (%c)\n", sizeof(long), S(long)); printf("\n"); printf("sizeof(caddr_t) = %u (%c) sizeof(pid_t) = %u (%c)\n", sizeof(caddr_t), S(caddr_t), sizeof(pid_t), S(pid_t)); printf("sizeof(clock_t) = %u (%c) sizeof(quad_t) = %u (%c)\n", sizeof(clock_t), S(clock_t), sizeof(quad_t), S(quad_t)); printf("sizeof(clockid_t) = %u (%c) sizeof(rlim_t) = %u (%c)\n", sizeof(clockid_t), S(clockid_t), sizeof(rlim_t), S(rlim_t)); printf("sizeof(daddr_t) = %u (%c) sizeof(segsz_t) = %u (%c)\n", sizeof(daddr_t), S(daddr_t), sizeof(segsz_t), S(segsz_t)); printf("sizeof(dev_t) = %u (%c) sizeof(size_t) = %u (%c)\n", sizeof(dev_t), S(dev_t), sizeof(size_t), S(size_t)); printf("sizeof(fixpt_t) = %u (%c) sizeof(ssize_t) = %u (%c)\n", sizeof(fixpt_t), S(fixpt_t), sizeof(ssize_t), S(ssize_t)); printf("sizeof(gid_t) = %u (%c) sizeof(suseconds_t) = %u (%c)\n", sizeof(gid_t), S(gid_t), sizeof(suseconds_t), S(suseconds_t)); printf("sizeof(id_t) = %u (%c) sizeof(swblk_t) = %u (%c)\n", sizeof(id_t), S(id_t), sizeof(swblk_t), S(swblk_t)); printf("sizeof(ino_t) = %u (%c) sizeof(time_t) = %u (%c)\n", sizeof(ino_t), S(ino_t), sizeof(time_t), S(time_t)); printf("sizeof(key_t) = %u (%c) sizeof(timer_t) = %u (%c)\n", sizeof(key_t), S(key_t), sizeof(timer_t), S(timer_t)); printf("sizeof(mode_t) = %u (%c) sizeof(uid_t) = %u (%c)\n", sizeof(mode_t), S(mode_t), sizeof(uid_t), S(uid_t)); printf("sizeof(nlink_t) = %u (%c) sizeof(useconds_t) = %u (%c)\n", sizeof(nlink_t), S(nlink_t), sizeof(useconds_t), S(useconds_t)); printf("sizeof(off_t) = %u (%c)\n", sizeof(off_t), S(off_t)); } EOF cc -o ${AFILE} ${CFILE} || exit $? ${AFILE}