Added a few previously unversioned utils.
[utils.git] / sztest
CommitLineData
1c2fdcc2
FT
1#!/bin/sh
2
3if [ $# -lt 1 ]; then
4 echo "usage: sztest [-H HEADER] TYPE [CCFLAGS...]" >&2
5 exit 1
6fi
7
8headers=
9while [ "${1:0:1}" = "-" ]; do
10 opt="$1"
11 shift
12 case "$opt" in
13 "-H")
14 headers="$headers $1"
15 shift
16 ;;
17 esac
18done
19type="$1"
20shift
21file="$(mktemp /tmp/sztestXXXXXX)"
22cat >"$file.c" <<EOF
23#include <stdio.h>
24#include <stdint.h>
25#include <sys/types.h>
26#include <unistd.h>
27#include <sys/stat.h>
28EOF
29for header in $headers; do
30 echo "#include <$header>" >>"$file.c"
31done
32cat >>"$file.c" <<EOF
33int main(int argc, char **argv)
34{
35 printf("%zi\n", sizeof($type));
36 return(0);
37}
38EOF
39
40if ! gcc "$@" -g -Wall -o "$file" "$file.c"; then
41 rm -f "$file" "$file.c"
42 exit 1
43fi
44"$file"
45rm "$file" "$file.c"