]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - programming/gccrun
kdo: Upstream krb5 now supports kswitch
[Scripts/git/.git] / programming / gccrun
CommitLineData
bd204af8
GT
1#!/bin/sh
2
3if [ "$#" = 0 ]; then
4 echo "usage: $0 [-w wrapper] <C code...>" >&2
5 exit 1
6fi
7
8if [ "$1" = -w ]; then
9 wrapper="$2"
10 shift 2
11fi
12
13f=$(mktemp -d -t gccrun.XXXXXXXX) || exit 1
14cat > "$f/command.c" << EOF
15#define _GNU_SOURCE
16#include <sys/types.h>
17#include <sys/stat.h>
18#include <sys/mman.h>
19#include <sys/ptrace.h>
20#include <sys/syscall.h>
ad03eb63
GT
21#include <arpa/inet.h>
22#include <errno.h>
bd204af8
GT
23#include <fcntl.h>
24#include <signal.h>
25#include <stdio.h>
26#include <stdlib.h>
27#include <string.h>
28#include <unistd.h>
29
30int
31main(int argc, char *argv[], char *envp[])
32{
ad03eb63 33 $1;
bd204af8
GT
34 return 0;
35}
36EOF
ad03eb63
GT
37shift
38if ! gcc -o "$f/command" "$f/command.c" $@; then
bd204af8
GT
39 exit 1
40fi
41if [ -n "$wrapper" ]; then
ad03eb63 42 $wrapper "$f/command"
bd204af8
GT
43else
44 "$f/command"
45fi
46r=$?
47rm -r "$f"
48exit $r